/**
  * Returns string representing the name of the item the browse will return
  *
  * If $ps_mode is 'singular' [default] then the singular version of the name is returned, otherwise the plural is returned
  */
 public function browseName($ps_mode = 'singular')
 {
     $vb_type_restriction_has_changed = false;
     $vn_type_id = $this->opo_result_context->getTypeRestriction($vb_type_restriction_has_changed);
     $t_list = new ca_lists();
     $t_list->load(array('list_code' => 'occurrence_types'));
     $t_list_item = new ca_list_items();
     $t_list_item->load(array('list_id' => $t_list->getPrimaryKey(), 'parent_id' => null));
     $va_hier = caExtractValuesByUserLocale($t_list_item->getHierarchyWithLabels());
     if (!($vs_name = $ps_mode == 'singular' ? $va_hier[$vn_type_id]['name_singular'] : $va_hier[$vn_type_id]['name_plural'])) {
         $vs_name = '???';
     }
     return $vs_name;
 }
 /**
  *
  */
 public function getTypeMenu()
 {
     $t_list = new ca_lists();
     $t_list->load(array('list_code' => $this->getTypeListCode()));
     $t_list_item = new ca_list_items();
     $t_list_item->load(array('list_id' => $t_list->getPrimaryKey(), 'parent_id' => null));
     $va_hierarchy = caExtractValuesByUserLocale($t_list_item->getHierarchyWithLabels());
     $va_types = array();
     if (is_array($va_hierarchy)) {
         $va_types_by_parent_id = array();
         $vn_root_id = null;
         foreach ($va_hierarchy as $vn_item_id => $va_item) {
             if (!$vn_root_id) {
                 $vn_root_id = $va_item['parent_id'];
                 continue;
             }
             $va_types_by_parent_id[$va_item['parent_id']][] = $va_item;
         }
         foreach ($va_hierarchy as $vn_item_id => $va_item) {
             if ($va_item['parent_id'] != $vn_root_id) {
                 continue;
             }
             // does this item have sub-items?
             if (isset($va_types_by_parent_id[$va_item['item_id']]) && is_array($va_types_by_parent_id[$va_item['item_id']])) {
                 $va_subtypes = $this->_getSubTypes($va_types_by_parent_id[$va_item['item_id']], $va_types_by_parent_id);
             } else {
                 $va_subtypes = array();
             }
             $va_types[] = array('displayName' => $va_item['name_singular'], 'parameters' => array('type_id' => $va_item['item_id']), 'navigation' => $va_subtypes);
         }
     }
     return $va_types;
 }
 public function _genTypeNav($pa_params)
 {
     $t_subject = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true);
     $t_list = new ca_lists();
     $t_list->load(array('list_code' => $t_subject->getTypeListCode()));
     $t_list_item = new ca_list_items();
     $t_list_item->load(array('list_id' => $t_list->getPrimaryKey(), 'parent_id' => null));
     $va_hier = caExtractValuesByUserLocale($t_list_item->getHierarchyWithLabels());
     $va_restrict_to_types = null;
     if ($t_subject->getAppConfig()->get('perform_type_access_checking')) {
         $va_restrict_to_types = caGetTypeRestrictionsForUser($this->ops_tablename, array('access' => __CA_BUNDLE_ACCESS_READONLY__));
     }
     $va_types = array();
     if (is_array($va_hier)) {
         $va_types_by_parent_id = array();
         $vn_root_id = $t_list->getRootItemIDForList($t_subject->getTypeListCode());
         // organize items by parent id, exclude root
         foreach ($va_hier as $vn_item_id => $va_item) {
             if ($vn_item_id == $vn_root_id) {
                 continue;
             }
             // skip root
             if (is_array($va_restrict_to_types) && !in_array($vn_item_id, $va_restrict_to_types)) {
                 continue;
             }
             $va_types_by_parent_id[$va_item['parent_id']][] = $va_item;
         }
         foreach ($va_hier as $vn_item_id => $va_item) {
             if (is_array($va_restrict_to_types) && !in_array($vn_item_id, $va_restrict_to_types)) {
                 continue;
             }
             if ($va_item['parent_id'] != $vn_root_id) {
                 continue;
             }
             // does this item have sub-items?
             if (isset($va_item['item_id']) && isset($va_types_by_parent_id[$va_item['item_id']]) && is_array($va_types_by_parent_id[$va_item['item_id']])) {
                 $va_subtypes = $this->_getSubTypes($va_types_by_parent_id[$va_item['item_id']], $va_types_by_parent_id, $va_restrict_to_types);
             } else {
                 $va_subtypes = array();
             }
             $va_types[] = array('displayName' => $va_item['name_plural'], 'parameters' => array('type_id' => $va_item['item_id']), 'is_enabled' => $va_item['is_enabled'], 'navigation' => $va_subtypes);
         }
     }
     return $va_types;
 }
 /**
  * Returns navigation fragment for types and subtypes of a given primary item type (Eg. ca_objects). Used to generate dynamic type menus 
  * from database by AppNavigation class. 
  *
  * @param array $pa_params Array of parameters used to generate menu
  * @return array List of types with subtypes ready for inclusion in a menu spec
  */
 public function _genTypeNav($pa_params)
 {
     $t_subject = $this->opo_datamodel->getInstanceByTableName($this->ops_table_name, true);
     $t_list = new ca_lists();
     $t_list->load(array('list_code' => $t_subject->getTypeListCode()));
     $t_list_item = new ca_list_items();
     $t_list_item->load(array('list_id' => $t_list->getPrimaryKey(), 'parent_id' => null));
     $va_hier = caExtractValuesByUserLocale($t_list_item->getHierarchyWithLabels());
     $vn_sort_type = $t_list->get('default_sort');
     $va_restrict_to_types = null;
     if ($t_subject->getAppConfig()->get('perform_type_access_checking')) {
         $va_restrict_to_types = caGetTypeRestrictionsForUser($this->ops_table_name, array('access' => __CA_BUNDLE_ACCESS_EDIT__));
     }
     $va_types = array();
     if (is_array($va_hier)) {
         $va_types_by_parent_id = array();
         $vn_root_id = $t_list->getRootItemIDForList($t_subject->getTypeListCode());
         foreach ($va_hier as $vn_item_id => $va_item) {
             if ($vn_item_id == $vn_root_id) {
                 continue;
             }
             // skip root
             $va_types_by_parent_id[$va_item['parent_id']][] = $va_item;
         }
         foreach ($va_hier as $vn_item_id => $va_item) {
             if (is_array($va_restrict_to_types) && !in_array($vn_item_id, $va_restrict_to_types)) {
                 continue;
             }
             if ($va_item['parent_id'] != $vn_root_id) {
                 continue;
             }
             // does this item have sub-items?
             $va_subtypes = array();
             if (!(bool) $this->getRequest()->config->get($this->ops_table_name . '_navigation_new_menu_shows_top_level_types_only') && !(bool) $this->getRequest()->config->get($this->ops_table_name . '_enforce_strict_type_hierarchy')) {
                 if (isset($va_item['item_id']) && isset($va_types_by_parent_id[$va_item['item_id']]) && is_array($va_types_by_parent_id[$va_item['item_id']])) {
                     $va_subtypes = $this->_getSubTypes($va_types_by_parent_id[$va_item['item_id']], $va_types_by_parent_id, $vn_sort_type, $va_restrict_to_types);
                 }
             }
             switch ($vn_sort_type) {
                 case 0:
                     // label
                 // label
                 default:
                     $vs_key = $va_item['name_singular'];
                     break;
                 case 1:
                     // rank
                     $vs_key = sprintf("%08d", (int) $va_item['rank']);
                     break;
                 case 2:
                     // value
                     $vs_key = $va_item['item_value'];
                     break;
                 case 3:
                     // identifier
                     $vs_key = $va_item['idno_sort'];
                     break;
             }
             $va_types[$vs_key][] = array('displayName' => $va_item['name_singular'], 'parameters' => array('type_id' => $va_item['item_id']), 'is_enabled' => $va_item['is_enabled'], 'navigation' => $va_subtypes);
         }
         ksort($va_types);
     }
     $va_types_proc = array();
     foreach ($va_types as $vs_sort_key => $va_items) {
         foreach ($va_items as $vn_i => $va_item) {
             $va_types_proc[] = $va_item;
         }
     }
     return $va_types_proc;
 }