From bd0e0abc584a208c585a2dd0a2b99ef1efaecf46 Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Mon, 20 Oct 2014 02:47:02 +0200 Subject: [PATCH 1/2] Added possibility to hide elements from indexation. --- HideElementsPlugin.php | 40 +++++++++++++++++++++++++++++++++++++++- README.md | 2 +- config-form.php | 21 +++++++++++++++++---- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/HideElementsPlugin.php b/HideElementsPlugin.php index bff5b71..bee1121 100644 --- a/HideElementsPlugin.php +++ b/HideElementsPlugin.php @@ -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( + 'index_elements', + 'display_elements', + 'elements_select_options', + ); public function hookInstall() { $defaults = array( 'override' => array(), + 'index' => array(), 'form' => array(), 'admin' => array(), 'public' => array(), @@ -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(), @@ -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 filterIndexElements($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()) { diff --git a/README.md b/README.md index ed68d6f..e4669fb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config-form.php b/config-form.php index efcc11f..380e2eb 100644 --- a/config-form.php +++ b/config-form.php @@ -24,16 +24,20 @@ formCheckbox('override[]', 'contributor', array( 'disableHidden' => true, 'checked' => in_array('contributor', $settings['override']), - )); ?> + )); ?> +

+ +

- + + @@ -48,13 +52,22 @@ $current_element_set = $element->set_name; ?> - + - +
+
name); ?> + formCheckbox( + "index[{$element->set_name}][{$element->id}]", + '1', array( + 'disableHidden' => true, + 'checked' => isset($settings['index'][$element->set_name][$element->id]), + ) + ); ?> + formCheckbox( "form[{$element->set_name}][{$element->name}]", @@ -92,6 +105,6 @@ ); ?>
From 1b0c4acecc15ab2cbccd88f915a0faf859a4cfb6 Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Tue, 21 Oct 2014 06:47:03 +0200 Subject: [PATCH 2/2] Renamed "search_element_texts" the filter used for full text indexation. --- HideElementsPlugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HideElementsPlugin.php b/HideElementsPlugin.php index bee1121..0480619 100644 --- a/HideElementsPlugin.php +++ b/HideElementsPlugin.php @@ -11,7 +11,7 @@ class HideElementsPlugin extends Omeka_Plugin_AbstractPlugin 'install', 'uninstall', 'upgrade'); protected $_filters = array( - 'index_elements', + 'search_element_texts', 'display_elements', 'elements_select_options', ); @@ -103,7 +103,7 @@ public function hookConfig($args) * * @param array $elementTexts */ - public function filterIndexElements($elementTexts) + public function filterSearchElementTexts($elementTexts) { // Full text indexation can't be overridden because the same field is // used for all users.