Beispiel #1
0
 /**
  * Given a item_id (request parameter 'id') returns a list of ancestors for use in the hierarchy browser
  * Returned data is JSON format
  */
 public function getFacetHierarchyAncestorList()
 {
     $pn_id = $this->request->getParameter('id', pInteger);
     $va_access_values = caGetUserAccessValues($this->request);
     $ps_facet_name = $this->request->getParameter('facet', pString);
     $this->view->setVar("facet_name", $ps_facet_name);
     $this->view->setVar("key", $this->request->getParameter('key', pString));
     $ps_browse_type = $this->request->getParameter('browseType', pString);
     if (!($va_browse_info = caGetInfoForBrowseType($ps_browse_type))) {
         // invalid browse type – throw error
         die("Invalid browse type");
     }
     $this->view->setVar("browse_type", $ps_browse_type);
     $vs_class = $va_browse_info['table'];
     $o_browse = caGetBrowseInstance($vs_class);
     if (!is_array($va_facet_info = $o_browse->getInfoForFacet($ps_facet_name))) {
         return null;
     }
     if ($ps_cache_key = $this->request->getParameter('key', pString)) {
         $o_browse->reload($ps_cache_key);
     }
     $va_ancestors = array();
     switch ($va_facet_info['type']) {
         case 'attribute':
             // is it a list attribute?
             $t_element = new ca_metadata_elements();
             if ($t_element->load(array('element_code' => $va_facet_info['element_code']))) {
                 if ($t_element->get('datatype') == 3) {
                     // 3=list
                     if (!$pn_id) {
                         $t_list = new ca_lists();
                         $pn_id = $t_list->getRootListItemID($t_element->get('list_id'));
                     }
                     $t_item = new ca_list_items($pn_id);
                     if ($t_item->getPrimaryKey()) {
                         $vs_primary_key = $t_item->primaryKey();
                         $this->view->setVar("primary_key", $vs_primary_key);
                         $vs_display_fld = $t_item->getLabelDisplayField();
                         $this->view->setVar("display_field", $vs_display_fld);
                         $vs_label_table_name = $t_item->getLabelTableName();
                         $va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'additionalTableToJoin' => $vs_label_table_name, 'additionalTableJoinType' => 'LEFT', 'additionalTableSelectFields' => array($vs_display_fld, 'locale_id'), 'additionalTableWheres' => array('(' . $vs_label_table_name . '.is_preferred = 1 OR ' . $vs_label_table_name . '.is_preferred IS NULL)'))));
                         array_shift($va_ancestors);
                     }
                 }
             }
             break;
         case 'label':
             // label facet
             $va_facet_info['table'] = $this->ops_tablename;
             // fall through to default case
         // fall through to default case
         default:
             $t_item = $this->request->datamodel->getInstanceByTableName($va_facet_info['table']);
             $t_item->load($pn_id);
             if (method_exists($t_item, "getHierarchyList")) {
                 $va_access_values = caGetUserAccessValues($this->request);
                 $va_facet = $o_browse->getFacet($ps_facet_name, array('sort' => 'name', 'checkAccess' => $va_access_values));
                 $va_hierarchy_list = $t_item->getHierarchyList(true);
                 $vn_hierarchies_in_use = 0;
                 foreach ($va_hierarchy_list as $vn_i => $va_item) {
                     if (isset($va_facet[$va_item[$t_item->primaryKey()]])) {
                         $vn_hierarchies_in_use++;
                         if ($vn_hierarchies_in_use > 1) {
                             break;
                         }
                     }
                 }
             }
             if ($t_item->getPrimaryKey()) {
                 $vs_primary_key = $t_item->primaryKey();
                 $this->view->setVar("primary_key", $vs_primary_key);
                 $vs_display_fld = $t_item->getLabelDisplayField();
                 $this->view->setVar("display_field", $vs_display_fld);
                 $vs_label_table_name = $t_item->getLabelTableName();
                 $va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'additionalTableToJoin' => $vs_label_table_name, 'additionalTableJoinType' => 'LEFT', 'additionalTableSelectFields' => array($vs_display_fld, 'locale_id'), 'additionalTableWheres' => array('(' . $vs_label_table_name . '.is_preferred = 1 OR ' . $vs_label_table_name . '.is_preferred IS NULL)'))));
             }
             if ($vn_hierarchies_in_use <= 1) {
                 array_shift($va_ancestors);
             }
             break;
     }
     $this->view->setVar('ancestors', $va_ancestors);
     switch ($this->request->getParameter('returnAs', pString)) {
         case "json":
             return $this->render('Browse/facet_hierarchy_ancestors_json.php');
             break;
             # ------------------------------------------------
         # ------------------------------------------------
         case "html":
         default:
             return $this->render('Browse/facet_hierarchy_ancestors_html.php');
             break;
             # ------------------------------------------------
     }
 }