diff --git a/CollectionTreePlugin.php b/CollectionTreePlugin.php index 8bcfe5c..e724f17 100644 --- a/CollectionTreePlugin.php +++ b/CollectionTreePlugin.php @@ -1,14 +1,14 @@ 0, - 'collection_tree_browse_only_root' => 0, 'collection_tree_show_subcollections' => 0, + 'collection_tree_hide_orphans' => 0, + 'collection_tree_treeview_style' => 0, + 'collection_tree_treeview_expanded' => '', + 'collection_tree_browse_only_root' => 0, 'collection_tree_search_descendant' => 0, ); @@ -65,7 +70,7 @@ public function hookInstall() { // collection_id must be unique to satisfy the AT MOST ONE parent // collection constraint. - $sql = " + $sql = " CREATE TABLE IF NOT EXISTS `{$this->_db->CollectionTree}` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `parent_collection_id` int(10) unsigned NOT NULL, @@ -90,7 +95,7 @@ public function hookInstall() $collectionTree->save(); } } - + /** * Uninstall the plugin. */ @@ -101,7 +106,7 @@ public function hookUninstall() $this->_uninstallOptions(); } - + /** * Initialize the plugin. */ @@ -110,22 +115,22 @@ public function hookInitialize() // Add translation. add_translation_source(dirname(__FILE__) . '/languages'); } - + /** * Upgrade from earlier versions. */ public function hookUpgrade($args) { - // Prior to Omeka 2.0, collection names were stored in the collections - // table; now they are stored as Dublin Core Title. This upgrade - // compensates for this by moving the collection names to the + // Prior to Omeka 2.0, collection names were stored in the collections + // table; now they are stored as Dublin Core Title. This upgrade + // compensates for this by moving the collection names to the // collection_trees table. if (version_compare($args['old_version'], '2.0', '<')) { - + // Add the name column to the collection_trees table. $sql = "ALTER TABLE {$this->_db->CollectionTree} ADD `name` TEXT NULL"; $this->_db->query($sql); - + // Assign names to their corresponding collection_tree rows. $collectionTreeTable = $this->_db->getTable('CollectionTree'); $collectionTable = $this->_db->getTable('Collection'); @@ -182,7 +187,7 @@ public function hookBeforeSaveCollection($args) } } } - + /** * Save the parent/child relationship. */ @@ -196,18 +201,18 @@ public function hookAfterSaveCollection($args) $collectionTree->collection_id = $collection->id; $collectionTree->parent_collection_id = 0; } - + // Only save 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']; } - + $collectionTree->name = metadata($args['record'], array('Dublin Core', 'Title')); - + // Fail silently if the record does not validate. $collectionTree->save(); } - + /** * Handle collection deletions. * @@ -220,13 +225,13 @@ public function hookAfterDeleteCollection($args) { $collection = $args['record']; $collectionTreeTable = $this->_db->getTable('CollectionTree'); - + // Delete the relationship with the parent collection. $collectionTree = $collectionTreeTable->findByCollectionId($collection->id); if ($collectionTree) { $collectionTree->delete(); } - + // Move child collections to root level by deleting their relationships. $collectionTrees = $collectionTreeTable->findByParentCollectionId($collection->id); foreach ($collectionTrees as $collectionTree) { @@ -273,7 +278,7 @@ public function hookItemsBrowseSql($args) // Collection can be an object when not called from search form. ? $params['descendant_or_self']->id // Else this should be an integer. - : (integer) $params['descendant_or_self']; + : (int) $params['descendant_or_self']; if (empty($collection)) { return; @@ -288,7 +293,8 @@ public function hookItemsBrowseSql($args) $select->joinInner( array('collection_tree_collections' => $this->_db->Collection), 'items.collection_id = collection_tree_collections.id', - array()); + array() + ); // There are descendants. if (count($collections) > 1) { @@ -321,7 +327,7 @@ public function hookPublicItemsSearch($args) } /** - * Append items search checkbox to the advanced search page. + * Append items search checkbox to the advanced search page. * * @return string HTML */ @@ -342,7 +348,7 @@ protected function _itemsSearch($args) */ public function hookAdminCollectionsShow($args) { - $this->_appendToCollectionsShow($args['collection']); + $this->_appendToCollectionsShow($args['collection'], 'admin'); } /** @@ -350,18 +356,43 @@ public function hookAdminCollectionsShow($args) */ public function hookPublicCollectionsShow($args) { - $this->_appendToCollectionsShow($args['collection']); + $this->_appendToCollectionsShow($args['collection'], 'public'); } - - protected function _appendToCollectionsShow($collection) + + protected function _appendToCollectionsShow($collection, $side) { $collectionTree = $this->_db->getTable('CollectionTree')->getCollectionTree($collection->id); - echo get_view()->partial( - 'collections/collection-tree-list.php', - array('collection_tree' => $collectionTree) - ); + + if (count($collectionTree[0]['children']) > 0 || !(bool)get_Option('collection_tree_hide_orphans')) { + echo get_view()->partial( + 'collections/collection-tree-list.php', + array('collection_tree' => $collectionTree, 'side' => $side) + ); + } } - + + /** + * Sets css and js in case treeview style is chosen + */ + public function hookPublicHead($args) + { + if (get_option('collection_tree_treeview_style')) { + queue_css_file('file-explore'); + queue_js_file('file-explore'); + } + } + + /** + * Sets css and js in case treeview style is chosen + */ + public function hookAdminHead($args) + { + if (get_option('collection_tree_treeview_style')) { + queue_css_file('file-explore'); + queue_js_file('file-explore'); + } + } + /** * Add the collection tree page to the admin navigation. */ @@ -370,7 +401,7 @@ public function filterAdminNavigationMain($nav) $nav[] = array('label' => __('Collection Tree'), 'uri' => url('collection-tree')); return $nav; } - + /** * Add the collection tree page to the public navigation. */ @@ -379,7 +410,7 @@ public function filterPublicNavigationMain($nav) $nav[] = array('label' => __('Collection Tree'), 'uri' => url('collection-tree')); return $nav; } - + /** * Display the parent collection form. */ @@ -387,7 +418,7 @@ public function filterAdminCollectionsFormTabs($tabs, $args) { $collection = $args['collection']; $collectionTreeTable = $this->_db->getTable('CollectionTree'); - + $options = $collectionTreeTable->findPairsForSelectForm(); $options = array('0' => __('No parent collection')) + $options; @@ -398,13 +429,12 @@ public function filterAdminCollectionsFormTabs($tabs, $args) $parentCollectionId = 0; } $tabs['Parent Collection'] = get_view()->partial( - 'collections/collection-tree-parent-form.php', + 'collections/collection-tree-parent-form.php', array('options' => $options, 'parent_collection_id' => $parentCollectionId) ); return $tabs; } - /** * Filter items browse params to broaden the search to subcollections. * @@ -418,7 +448,7 @@ public function filterItemsBrowseParams($params) && !isset($params['subcollections']) && get_option('collection_tree_show_subcollections') ) { - $params['subcollections'] = 1; + $params['subcollections'] = 1; } if (!empty($params['subcollections'])) { @@ -439,7 +469,6 @@ public function filterItemsBrowseParams($params) return $params; } - /** * Manage search options for collections. * diff --git a/views/admin/plugins/collection-tree-config-form.php b/views/admin/plugins/collection-tree-config-form.php index 6798c10..219d2cc 100644 --- a/views/admin/plugins/collection-tree-config-form.php +++ b/views/admin/plugins/collection-tree-config-form.php @@ -1,49 +1,116 @@ +

+
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')) + ); ?>
+
- formLabel('collection_tree_browse_only_root', __('Browse root-level collections only')); ?> + formLabel('collection_tree_show_subcollections', __('Show subcollection items')); ?>

- formCheckbox('collection_tree_browse_only_root', null, - array('checked' => (bool) get_option('collection_tree_browse_only_root'))); ?> + formCheckbox( + 'collection_tree_show_subcollections', + null, + array('checked' => (bool) get_option('collection_tree_show_subcollections')) + ); ?>
+
- formLabel('collection_tree_show_subcollections', __('Show subcollection items')); ?> + formLabel('collection_tree_hide_orphans', __('Hide orphan collections')); ?> +
+
+

+ formCheckbox( + 'collection_tree_hide_orphans', + null, + array('checked' => (bool) get_option('collection_tree_hide_orphans')) + ); ?> +
+
+ +
+
+ formLabel('collection_tree_treeview_style', __('Treeview style')); ?> +
+
+

+ formCheckbox( + 'collection_tree_treeview_style', + null, + array('checked' => (bool) get_option('collection_tree_treeview_style')) + ); ?> +
+
+ +
+
+ formLabel('collection_tree_treeview_expanded', __('Treeview expanded')); ?> +
+
+

+ formSelect( + 'collection_tree_treeview_expanded', + get_option('collection_tree_treeview_expanded'), + null, + array('nowhere' => __('Nowhere'), 'admin' => __('Only Admin side'), 'public' => __('Only Public side'), 'everywhere' => __('Both Admin and Public sides')) + ); ?> +
+
+ +

+ +
+
+ formLabel('collection_tree_browse_only_root', __('Browse root-level collections only')); ?>

- formCheckbox('collection_tree_show_subcollections', null, - array('checked' => (bool) get_option('collection_tree_show_subcollections'))); ?> + formCheckbox( + 'collection_tree_browse_only_root', + null, + array('checked' => (bool) get_option('collection_tree_browse_only_root')) + ); ?>
+
formLabel('collection_tree_search_descendant', __('Expand search to subcollection items by default')); ?>

- formCheckbox('collection_tree_search_descendant', null, - array('checked' => (bool) get_option('collection_tree_search_descendant'))); ?> + formCheckbox( + 'collection_tree_search_descendant', + null, + array('checked' => (bool) get_option('collection_tree_search_descendant')) + ); ?>
diff --git a/views/shared/collections/collection-tree-list.php b/views/shared/collections/collection-tree-list.php index 93f012b..29d5d9d 100644 --- a/views/shared/collections/collection-tree-list.php +++ b/views/shared/collections/collection-tree-list.php @@ -1,4 +1,12 @@

-
+ +
> collectionTreeList($collection_tree); ?>
diff --git a/views/shared/css/file-explore.css b/views/shared/css/file-explore.css new file mode 100644 index 0000000..eb86fd0 --- /dev/null +++ b/views/shared/css/file-explore.css @@ -0,0 +1,54 @@ +#collection-tree ul { + list-style-type: none; + font-size: 1em; + line-height: 1.8em; + margin-top: 0; + margin-left: 10px; + padding-left: 18px; + border-left: 1px dotted #aaa; +} + +#collection-tree li { + position: relative; +} + +#collection-tree li a{ + text-decoration: none; +} + +#collection-tree li:before{ + position: absolute; + display: block; + content: " "; + width: 10px; + height: 1px; + border-bottom: 1px dotted #aaa; + top: .6em; + left: -14px; +} + +.collection-tree-icon { + display: block; + font-family: FontAwesome; + font-size: 1.2em; +} + +.handle:before { + margin-right: .2em; + content: '\f0f6'; + float: left; +} + +.collapsed:before { + margin-right: .2em; + color: #FFD04E; + content: "\f07b"; + cursor: pointer; +} + +.expanded:before { + margin-right: .2em; + color: #FFD04E; + content: "\f07c"; + cursor: pointer; +} diff --git a/views/shared/index/index.php b/views/shared/index/index.php index 9ad45ae..abb2f72 100644 --- a/views/shared/index/index.php +++ b/views/shared/index/index.php @@ -1,7 +1,8 @@ __('Collection Tree'))); ?> full_collection_tree): ?> +

full_collection_tree; ?>

- \ No newline at end of file + diff --git a/views/shared/javascripts/file-explore.js b/views/shared/javascripts/file-explore.js new file mode 100644 index 0000000..b0e880a --- /dev/null +++ b/views/shared/javascripts/file-explore.js @@ -0,0 +1,20 @@ +jQuery(document).ready(function () { + var treeExpanded = (jQuery("#collection-tree").hasClass("treeExpanded")); + + init(); + + function init() { + if (!treeExpanded) { + jQuery("#collection-tree ul:not(:first)").hide(); + } + + jQuery("#collection-tree li").prepend(""); + + jQuery("#collection-tree li:has(ul)") + .children(":first-child").addClass("collapsed") + .click(function(){ + jQuery(this).toggleClass("collapsed expanded") + .siblings("ul").toggle(); + }); + } +});