From cd231aad7cb2b987e19de95c292e6e5b3a64e608 Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Thu, 29 May 2014 02:47:02 +0200 Subject: [PATCH 1/4] Added a filter to display the select dropdown of collections to be hierarchical. --- CollectionTreePlugin.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CollectionTreePlugin.php b/CollectionTreePlugin.php index 38e8b96..f6c3b8d 100644 --- a/CollectionTreePlugin.php +++ b/CollectionTreePlugin.php @@ -13,6 +13,9 @@ */ class CollectionTreePlugin extends Omeka_Plugin_AbstractPlugin { + /** + * @var array Hooks for the plugin. + */ protected $_hooks = array( 'install', 'uninstall', @@ -28,10 +31,14 @@ class CollectionTreePlugin extends Omeka_Plugin_AbstractPlugin 'public_collections_show', ); + /** + * @var array Filters for the plugin. + */ protected $_filters = array( 'admin_navigation_main', 'public_navigation_main', 'admin_collections_form_tabs', + 'collections_select_options', ); /** @@ -285,4 +292,17 @@ public function filterAdminCollectionsFormTabs($tabs, $args) ); return $tabs; } + + /** + * Manage search options for collections. + * + * @param array Search options for collections. + * @return array Filtered search options for collections. + */ + public function filterCollectionsSelectOptions($options) + { + $treeOptions = $this->_db->getTable('CollectionTree')->findPairsForSelectForm(); + // Keep only chosen collections, in case another filter removed some. + return array_intersect_key($treeOptions, $options); + } } From 773fa85240e27623d6b929ab3038dfe2cb71bcf2 Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Wed, 18 Jun 2014 02:47:02 +0200 Subject: [PATCH 2/4] Fixed collections browse hook. --- CollectionTreePlugin.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/CollectionTreePlugin.php b/CollectionTreePlugin.php index f6c3b8d..5fe48a3 100644 --- a/CollectionTreePlugin.php +++ b/CollectionTreePlugin.php @@ -26,7 +26,7 @@ class CollectionTreePlugin extends Omeka_Plugin_AbstractPlugin 'before_save_collection', 'after_save_collection', 'after_delete_collection', - 'collection_browse_sql', + 'collections_browse_sql', 'admin_collections_show', 'public_collections_show', ); @@ -213,20 +213,22 @@ public function hookAfterDeleteCollection($args) } /** - * Omit all child collections from the collection browse. + * Hook for collections browse: omit all child collections from the collection + * browse. */ - public function hookCollectionBrowseSql($args) + public function hookCollectionsBrowseSql($args) { if (!is_admin_theme()) { $sql = " - c.id NOT IN ( + collections.id NOT IN ( SELECT ct.collection_id FROM {$this->_db->CollectionTree} ct + WHERE ct.parent_collection_id != 0 )"; $args['select']->where($sql); } } - + /** * Display the collection's parent collection and child collections. */ From a2b8f43e076bfa49a6340f6d1380a01d55af5584 Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Sat, 21 Jun 2014 02:47:02 +0200 Subject: [PATCH 3/4] Normalized config. --- CollectionTreePlugin.php | 43 ++++++++++++------- .../plugins/collection-tree-config-form.php | 14 +++--- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/CollectionTreePlugin.php b/CollectionTreePlugin.php index 5fe48a3..ba1dd25 100644 --- a/CollectionTreePlugin.php +++ b/CollectionTreePlugin.php @@ -40,7 +40,14 @@ class CollectionTreePlugin extends Omeka_Plugin_AbstractPlugin 'admin_collections_form_tabs', 'collections_select_options', ); - + + /** + * @var array Options and their default values. + */ + protected $_options = array( + 'collection_tree_alpha_order' => 0, + ); + /** * Install the plugin. * @@ -61,9 +68,9 @@ public function hookInstall() UNIQUE KEY `collection_id` (`collection_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $this->_db->query($sql); - - set_option('collection_tree_alpha_order', '0'); - + + $this->_installOptions(); + // Save all collections in the collection_trees table. $collectionTable = $this->_db->getTable('Collection'); $collections = $this->_db->fetchAll("SELECT id FROM {$this->_db->Collection}"); @@ -84,8 +91,8 @@ public function hookUninstall() { $sql = "DROP TABLE IF EXISTS {$this->_db->CollectionTree}"; $this->_db->query($sql); - - delete_option('collection_tree_alpha_order'); + + $this->_uninstallOptions(); } /** @@ -129,30 +136,34 @@ public function hookUpgrade($args) } } } - + /** * Display the config form. */ - public function hookConfigForm() + public function hookConfigForm($args) { - echo get_view()->partial('plugins/collection-tree-config-form.php'); + $view = get_view(); + echo $view->partial('plugins/collection-tree-config-form.php'); } - + /** * Handle the config form. */ - public function hookConfig() + public function hookConfig($args) { - set_option('collection_tree_alpha_order', $_POST['collection_tree_alpha_order']); + $post = $args['post']; + foreach ($post as $key => $value) { + set_option($key, $value); + } } - + public function hookBeforeSaveCollection($args) { $collectionTree = $this->_db->getTable('CollectionTree')->findByCollectionId($args['record']->id); if (!$collectionTree) { return; } - + // Only validate the relationship during a form submission. if (isset($args['post']['collection_tree_parent_collection_id'])) { $collectionTree->parent_collection_id = $args['post']['collection_tree_parent_collection_id']; @@ -240,9 +251,9 @@ public function hookAdminCollectionsShow($args) /** * Display the collection's parent collection and child collections. */ - public function hookPublicCollectionsShow() + public function hookPublicCollectionsShow($args) { - $this->_appendToCollectionsShow(get_current_record('collection')); + $this->_appendToCollectionsShow($args['collection']); } protected function _appendToCollectionsShow($collection) diff --git a/views/admin/plugins/collection-tree-config-form.php b/views/admin/plugins/collection-tree-config-form.php index 772c4bc..76af50e 100644 --- a/views/admin/plugins/collection-tree-config-form.php +++ b/views/admin/plugins/collection-tree-config-form.php @@ -1,11 +1,13 @@
-
- +
+ formLabel('collection_tree_alpha_order', __('Order alphabetically')); ?>
-

- formCheckbox('collection_tree_alpha_order', null, - array('checked' => (bool) get_option('collection_tree_alpha_order'))); ?> +

+ formCheckbox('collection_tree_alpha_order', null, + array('checked' => (bool) get_option('collection_tree_alpha_order'))); ?>
From 33b352c9c93fe5154f7332b9a3dca8fbb108122a Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Sat, 21 Jun 2014 02:47:02 +0200 Subject: [PATCH 4/4] Added an option to display only root collections in collections/browse page. --- CollectionTreePlugin.php | 4 ++++ views/admin/plugins/collection-tree-config-form.php | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CollectionTreePlugin.php b/CollectionTreePlugin.php index ba1dd25..921abea 100644 --- a/CollectionTreePlugin.php +++ b/CollectionTreePlugin.php @@ -46,6 +46,7 @@ class CollectionTreePlugin extends Omeka_Plugin_AbstractPlugin */ protected $_options = array( 'collection_tree_alpha_order' => 0, + 'collection_tree_browse_only_root' => 0, ); /** @@ -230,6 +231,9 @@ public function hookAfterDeleteCollection($args) public function hookCollectionsBrowseSql($args) { if (!is_admin_theme()) { + if (!get_option('collection_tree_browse_only_root')) { + return; + } $sql = " collections.id NOT IN ( SELECT ct.collection_id diff --git a/views/admin/plugins/collection-tree-config-form.php b/views/admin/plugins/collection-tree-config-form.php index 76af50e..541b19b 100644 --- a/views/admin/plugins/collection-tree-config-form.php +++ b/views/admin/plugins/collection-tree-config-form.php @@ -11,3 +11,15 @@ array('checked' => (bool) get_option('collection_tree_alpha_order'))); ?>
+
+
+ formLabel('collection_tree_browse_only_root', __('Browse collections')); ?> +
+
+

+ formCheckbox('collection_tree_browse_only_root', null, + array('checked' => (bool) get_option('collection_tree_browse_only_root'))); ?> +
+