Skip to content
Open
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
38 changes: 34 additions & 4 deletions models/Table/CollectionTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class Table_CollectionTree extends Omeka_Db_Table
*/
protected $_collections;

/**
* Cache of children of a collection.
*
* It's an associative array where keys are collection ids and values are
* arrays of children ids.
*/
protected $_collectionsChildren;

/**
* Cache of variables needed for some use.
*
Expand Down Expand Up @@ -271,12 +279,14 @@ public function getCollection($collectionId)
public function getChildCollections($collectionId)
{
$childCollections = array();
$collections = $this->_getCollections();
foreach ($collections as $collection) {
if ($collectionId == $collection['parent_collection_id']) {
$childCollections[$collection['id']] = $collection;
$collectionsChildren = $this->_getCollectionsChildren();

if (isset($collectionsChildren[$collectionId])) {
foreach ($collectionsChildren[$collectionId] as $childId) {
$childCollections[$childId] = $this->getCollection($childId);
}
}

return $childCollections;
}

Expand Down Expand Up @@ -365,6 +375,26 @@ protected function _getCollections()
return $this->_collections;
}

/**
* Cache collections children data in an associative array.
*/
protected function _getCollectionsChildren()
{
if (is_null($this->_collectionsChildren)) {
$collections = $this->_getCollections();

$this->_collectionsChildren = array();
foreach ($collections as $id => $collection) {
if ($collection['parent_collection_id']) {
$parent_collection_id = $collection['parent_collection_id'];
$this->_collectionsChildren[$parent_collection_id][] = $id;
}
}
}

return $this->_collectionsChildren;
}

/**
* Reset the cache property.
*/
Expand Down