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
59 changes: 29 additions & 30 deletions CollectionTreePlugin.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
/**
* Collection Tree
*
*
* @copyright Copyright 2007-2012 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/

/**
* The Collection Tree plugin.
*
*
* @package Omeka\Plugins\CollectionTree
*/
class CollectionTreePlugin extends Omeka_Plugin_AbstractPlugin
Expand Down Expand Up @@ -65,7 +65,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,
Expand All @@ -90,7 +90,7 @@ public function hookInstall()
$collectionTree->save();
}
}

/**
* Uninstall the plugin.
*/
Expand All @@ -101,7 +101,7 @@ public function hookUninstall()

$this->_uninstallOptions();
}

/**
* Initialize the plugin.
*/
Expand All @@ -110,22 +110,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');
Expand Down Expand Up @@ -182,7 +182,7 @@ public function hookBeforeSaveCollection($args)
}
}
}

/**
* Save the parent/child relationship.
*/
Expand All @@ -196,18 +196,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.
*
Expand All @@ -220,13 +220,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) {
Expand Down Expand Up @@ -273,7 +273,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;
Expand All @@ -288,7 +288,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) {
Expand Down Expand Up @@ -352,16 +353,16 @@ public function hookPublicCollectionsShow($args)
{
$this->_appendToCollectionsShow($args['collection']);
}

protected function _appendToCollectionsShow($collection)
{
$collectionTree = $this->_db->getTable('CollectionTree')->getCollectionTree($collection->id);
echo get_view()->partial(
'collections/collection-tree-list.php',
'collections/collection-tree-list.php',
array('collection_tree' => $collectionTree)
);
}

/**
* Add the collection tree page to the admin navigation.
*/
Expand All @@ -370,7 +371,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.
*/
Expand All @@ -379,15 +380,15 @@ public function filterPublicNavigationMain($nav)
$nav[] = array('label' => __('Collection Tree'), 'uri' => url('collection-tree'));
return $nav;
}

/**
* Display the parent collection form.
*/
public function filterAdminCollectionsFormTabs($tabs, $args)
{
$collection = $args['collection'];
$collectionTreeTable = $this->_db->getTable('CollectionTree');

$options = $collectionTreeTable->findPairsForSelectForm();
$options = array('0' => __('No parent collection')) + $options;

Expand All @@ -398,13 +399,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.
*
Expand All @@ -418,7 +418,7 @@ public function filterItemsBrowseParams($params)
&& !isset($params['subcollections'])
&& get_option('collection_tree_show_subcollections')
) {
$params['subcollections'] = 1;
$params['subcollections'] = 1;
}

if (!empty($params['subcollections'])) {
Expand All @@ -439,7 +439,6 @@ public function filterItemsBrowseParams($params)
return $params;
}


/**
* Manage search options for collections.
*
Expand Down
4 changes: 2 additions & 2 deletions controllers/IndexController.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
/**
* Collection Tree
*
*
* @copyright Copyright 2007-2012 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/

/**
* The Collection Tree controller.
*
*
* @package Omeka\Plugins\CollectionTree
*/
class CollectionTree_IndexController extends Omeka_Controller_AbstractActionController
Expand Down
12 changes: 6 additions & 6 deletions models/CollectionTree.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
<?php
/**
* Collection Tree
*
*
* @copyright Copyright 2007-2012 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/

/**
* A collection_trees row.
*
*
* @package Omeka\Plugins\CollectionTree
*/
class CollectionTree extends Omeka_Record_AbstractRecord
{
public $parent_collection_id;
public $collection_id;
public $name;

/**
* Validate the record.
*/
protected function _validate()
{
if ($this->collection_id == $this->parent_collection_id) {
$this->addError(
__('Parent Collection'),
__('Parent Collection'),
__('A collection cannot be a parent to itself.')
);
}

$unassignableCollectionIds = $this->getTable()->getUnassignableCollectionIds($this->collection_id);
if (in_array($this->parent_collection_id, $unassignableCollectionIds)) {
$this->addError(
__('Parent Collection'),
__('Parent Collection'),
__('A collection cannot be assigned to a collection in its descendant tree.')
);
}
Expand Down
Loading