Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion HideElementsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ class HideElementsPlugin extends Omeka_Plugin_AbstractPlugin
protected $_hooks = array('initialize', 'config', 'config_form',
'install', 'uninstall', 'upgrade');

protected $_filters = array('display_elements', 'elements_select_options');
protected $_filters = array(
'search_element_texts',
'display_elements',
'elements_select_options',
);

public function hookInstall()
{
$defaults = array(
'override' => array(),
'index' => array(),
'form' => array(),
'admin' => array(),
'public' => array(),
Expand Down Expand Up @@ -84,6 +89,7 @@ public function hookConfig($args)
$post = $args['post'];
$settings = array(
'override' => isset($post['override']) ? $post['override'] : array(),
'index' => isset($post['index']) ? $post['index'] : array(),
'form' => isset($post['form']) ? $post['form'] : array(),
'admin' => isset($post['admin']) ? $post['admin'] : array(),
'public' => isset($post['public']) ? $post['public'] : array(),
Expand All @@ -92,6 +98,38 @@ public function hookConfig($args)
set_option('hide_elements_settings', json_encode($settings));
}

/**
* Filter to alter element texts to save in the full text index.
*
* @param array $elementTexts
*/
public function filterSearchElementTexts($elementTexts)
{
// Full text indexation can't be overridden because the same field is
// used for all users.
if (!isset($this->_settings['index'])) {
return $elementTexts;
}

// Flat the list of element texts to simplify the process.
$elementIds = array();
foreach ($elementTexts as $key => $elementText) {
$elementIds[$elementText->element_id][] = $key;
}

foreach ($this->_settings['index'] as $elementSet => $elements) {
foreach ($elements as $id => $hidden) {
if (isset($elementIds[$id])) {
foreach ($elementIds[$id] as $key) {
unset($elementTexts[$key]);
}
}
}
}

return $elementTexts;
}

public function filterDisplayElements($elementsBySet)
{
if ($this->_overrideFilter()) {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## A plugin for Omeka ##

This plugin lets administrators choose metadata elements to hide.
Elements can separately be hidden from the edit form, display on the
Elements can separately be hidden from indexation, edit form, display on the
admin side, display on the public side, and the search form.

### Version History
Expand Down
21 changes: 17 additions & 4 deletions config-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@
<?php echo $view->formCheckbox('override[]', 'contributor', array(
'disableHidden' => true,
'checked' => in_array('contributor', $settings['override']),
)); ?> <?php echo __('Contributor'); ?>
)); ?> <?php echo __('Contributor'); ?>
<p class="explanation">
<?php echo __("Note: Full text indexation can't be overridden because the same field is used for all users."); ?>
</p>
</div>
</div>
<table id="hide-elements-table">
<thead>
<tr>
<th class="hide-boxes" rowspan="2"><?php echo __('Element'); ?></th>
<th class="hide-boxes" colspan="4"><?php echo __('Hide on:'); ?></th>
<th class="hide-boxes" colspan="5"><?php echo __('Hide on:'); ?></th>
</tr>
<tr>
<th class="hide-boxes"><?php echo __('Index'); ?></th>
<th class="hide-boxes"><?php echo __('Form'); ?></th>
<th class="hide-boxes"><?php echo __('Admin'); ?></th>
<th class="hide-boxes"><?php echo __('Public'); ?></th>
Expand All @@ -48,13 +52,22 @@
$current_element_set = $element->set_name;
?>
<tr>
<th colspan="5">
<th colspan="6">
<strong><?php echo __($current_element_set); ?></strong>
</th>
</tr>
<?php endif; ?>
<tr>
<td><?php echo __($element->name); ?></td>
<td class="hide-boxes">
<?php echo $view->formCheckbox(
"index[{$element->set_name}][{$element->id}]",
'1', array(
'disableHidden' => true,
'checked' => isset($settings['index'][$element->set_name][$element->id]),
)
); ?>
</td>
<td class="hide-boxes">
<?php echo $view->formCheckbox(
"form[{$element->set_name}][{$element->name}]",
Expand Down Expand Up @@ -92,6 +105,6 @@
); ?>
</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>