Esempio n. 1
0
 /**
  * Return array containing information about all hierarchies, including their root_id's
  * For non-adhoc hierarchies such as occurrences, this call returns the contents of the occurrence_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 occurrence hierarchy
  */
 public function getHierarchyList($pb_dummy = false)
 {
     $vn_pk = $this->getPrimaryKey();
     $vs_template = $this->getAppConfig()->get('ca_occurrences_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.occurrence_id, count(*) c\n\t\t\t\t\tFROM ca_occurrences o\n\t\t\t\t\tINNER JOIN ca_occurrences AS p ON p.parent_id = o.occurrence_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.occurrence_id\n\t\t\t\t", array($va_type_ids));
         } else {
             $qr_res = $o_db->query("\n\t\t\t\t\tSELECT o.occurrence_id, count(*) c\n\t\t\t\t\tFROM ca_occurrences o\n\t\t\t\t\tINNER JOIN ca_occurrences AS p ON p.parent_id = o.occurrence_id\n\t\t\t\t\tWHERE o.parent_id IS NULL\n\t\t\t\t\tGROUP BY o.occurrence_id\n\t\t\t\t");
         }
         $va_hiers = array();
         $va_occurrence_ids = $qr_res->getAllFieldValues('occurrence_id');
         $qr_res->seek(0);
         $va_labels = $this->getPreferredDisplayLabelsForIDs($va_occurrence_ids);
         while ($qr_res->nextRow()) {
             $va_hiers[$vn_occurrence_id = $qr_res->get('occurrence_id')] = array('occurrence_id' => $vn_occurrence_id, 'name' => caProcessTemplateForIDs($vs_template, 'ca_occurrences', array($vn_occurrence_id)), 'hierarchy_id' => $vn_occurrence_id, 'children' => (int) $qr_res->get('c'));
         }
         return $va_hiers;
     } else {
         // return specific occurrence 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_occurrence = new ca_occurrences($va_ancestors[0]);
         } else {
             $t_occurrence =& $this;
         }
         $va_children = $t_occurrence->getHierarchyChildren(null, array('idsOnly' => true));
         $va_occurrence_hierarchy_root = array($t_occurrence->get($vs_hier_fld) => array('occurrence_id' => $vn_pk, 'item_id' => $vn_pk, 'name' => $vs_name = caProcessTemplateForIDs($vs_template, 'ca_occurrences', array($vn_pk)), 'hierarchy_id' => $vn_hier_id, 'children' => sizeof($va_children)));
         return $va_occurrence_hierarchy_root;
     }
 }