Beispiel #1
0
 /**
  * Return array containing information about all hierarchies, including their root_id's
  * For non-adhoc hierarchies such as places, this call returns the contents of the place_hierarchies list
  * with some extra information such as the # of top-level items in each hierarchy.
  *
  * For an ad-hoc hierarchy like that of an collection, there is only ever one hierarchy to display - that of the current collection.
  * So for adhoc hierarchies we just return a single entry corresponding to the root of the current collection hierarchy
  */
 public function getHierarchyList($pb_dummy = false)
 {
     $vn_pk = $this->getPrimaryKey();
     $vs_template = $this->getAppConfig()->get('ca_collections_hierarchy_browser_display_settings');
     if (!$vn_pk) {
         $o_db = new Db();
         if (is_array($va_type_ids = caMergeTypeRestrictionLists($this, array())) && sizeof($va_type_ids)) {
             $qr_res = $o_db->query("\n\t\t\t\t\tSELECT o.collection_id, count(*) c\n\t\t\t\t\tFROM ca_collections o\n\t\t\t\t\tINNER JOIN ca_collections AS p ON p.parent_id = o.collection_id\n\t\t\t\t\tWHERE o.parent_id IS NULL AND o.type_id IN (?)\n\t\t\t\t\tGROUP BY o.collection_id\n\t\t\t\t", array($va_type_ids));
         } else {
             $qr_res = $o_db->query("\n\t\t\t\t\tSELECT o.collection_id, count(*) c\n\t\t\t\t\tFROM ca_collections o\n\t\t\t\t\tINNER JOIN ca_collections AS p ON p.parent_id = o.collection_id\n\t\t\t\t\tWHERE o.parent_id IS NULL\n\t\t\t\t\tGROUP BY o.collection_id\n\t\t\t\t");
         }
         $va_hiers = array();
         $va_collection_ids = $qr_res->getAllFieldValues('collection_id');
         $qr_res->seek(0);
         $va_labels = $this->getPreferredDisplayLabelsForIDs($va_collection_ids);
         while ($qr_res->nextRow()) {
             $va_hiers[$vn_collection_id = $qr_res->get('collection_id')] = array('item_id' => $vn_collection_id, 'collection_id' => $vn_collection_id, 'name' => caProcessTemplateForIDs($vs_template, 'ca_collections', array($vn_collection_id)), 'hierarchy_id' => $vn_collection_id, 'children' => (int) $qr_res->get('c'));
         }
         return $va_hiers;
     } else {
         // return specific collection as root of hierarchy
         $vs_label = $this->getLabelForDisplay(false);
         $vs_hier_fld = $this->getProperty('HIERARCHY_ID_FLD');
         $vs_parent_fld = $this->getProperty('PARENT_ID_FLD');
         $vn_hier_id = $this->get($vs_hier_fld);
         if ($this->get($vs_parent_fld)) {
             // currently loaded row is not the root so get the root
             $va_ancestors = $this->getHierarchyAncestors();
             if (!is_array($va_ancestors) || sizeof($va_ancestors) == 0) {
                 return null;
             }
             $t_collection = new ca_collections($va_ancestors[0]);
         } else {
             $t_collection =& $this;
         }
         $va_children = $t_collection->getHierarchyChildren(null, array('idsOnly' => true));
         $va_collection_hierarchy_root = array($t_collection->get($vs_hier_fld) => array('item_id' => $vn_pk, 'collection_id' => $vn_pk, 'name' => caProcessTemplateForIDs($vs_template, 'ca_collections', array($vn_pk)), 'hierarchy_id' => $vn_hier_id, 'children' => sizeof($va_children)));
         return $va_collection_hierarchy_root;
     }
 }