Example #1
0
 /**
  * Fetch list of fields to index for the subject table
  *
  * @param mixed $pm_subject_table Name or number of table indexing is to be applied to
  * @param mixed $pm_content_table Name or number of table containing content being indexed. [Default is $pm_subject_table]
  *
  * @return array
  */
 public function getFieldsToIndex($pm_subject_table, $pm_content_table = null, $pa_options = null)
 {
     $vs_key = caMakeCacheKeyFromOptions($pa_options);
     if (isset(SearchBase::$s_fields_to_index_cache[$pm_subject_table . '/' . $pm_content_table . '/' . $vs_key])) {
         return SearchBase::$s_fields_to_index_cache[$pm_subject_table . '/' . $pm_content_table . '/' . $vs_key];
     }
     if (is_numeric($pm_subject_table)) {
         $vs_subject_table = $this->opo_datamodel->getTableName($pm_subject_table);
     } else {
         $vs_subject_table = $pm_subject_table;
     }
     if ($pm_content_table == null) {
         $vs_content_table = $vs_subject_table;
     } else {
         if (is_numeric($pm_content_table)) {
             $vs_content_table = $this->opo_datamodel->getTableName($pm_content_table);
         } else {
             $vs_content_table = $pm_content_table;
         }
     }
     if (!($va_info = $this->opo_search_indexing_config->getAssoc($vs_subject_table))) {
         return SearchBase::$s_fields_to_index_cache[$pm_subject_table . '/' . $pm_content_table . '/' . $vs_key] = SearchBase::$s_fields_to_index_cache[$vs_subject_table . '/' . $vs_content_table . '/' . $vs_key] = null;
     }
     $va_fields_to_index = $va_info[$vs_content_table]['fields'];
     $t_subject = $this->opo_datamodel->getInstanceByTableName($vs_content_table, false);
     if (caGetOption('intrinsicOnly', $pa_options, false)) {
         unset($va_fields_to_index['_metadata']);
         foreach ($va_fields_to_index as $vs_f => $va_data) {
             if (substr($vs_f, 0, 14) === '_ca_attribute_') {
                 unset($va_fields_to_index[$vs_f]);
                 continue;
             }
             if (!$t_subject->hasField($vs_f)) {
                 unset($va_fields_to_index[$vs_f]);
                 continue;
             }
             if ($vs_start = $t_subject->getFieldInfo($vs_f, 'START') && ($vs_end = $t_subject->getFieldInfo($vs_f, 'END'))) {
                 $va_fields_to_index[$vs_start] = $va_data;
                 $va_fields_to_index[$vs_end] = $va_data;
                 unset($va_fields_to_index[$vs_f]);
             }
         }
         return $va_fields_to_index;
     }
     // Expand "_metadata" to all available metadata elements
     if (isset($va_fields_to_index['_metadata'])) {
         $va_data = $va_fields_to_index['_metadata'];
         unset($va_fields_to_index['_metadata']);
         $va_field_data = $t_subject->getApplicableElementCodes(null, false, false);
         foreach ($va_field_data as $vn_element_id => $vs_element_code) {
             $va_fields_to_index['_ca_attribute_' . $vn_element_id] = $va_data;
         }
     }
     // Convert specific attribute codes to element_ids
     if (is_array($va_fields_to_index)) {
         foreach ($va_fields_to_index as $vs_f => $va_info) {
             if (substr($vs_f, 0, 14) === '_ca_attribute_' && preg_match('!^_ca_attribute_([A-Za-z]+[A-Za-z0-9_]*)$!', $vs_f, $va_matches)) {
                 $vn_element_id = $t_subject->_getElementID($va_matches[1]);
                 unset($va_fields_to_index[$vs_f]);
                 $va_fields_to_index['_ca_attribute_' . $vn_element_id] = $va_info;
             }
         }
     }
     // always index type id if applicable and not already indexed
     if (method_exists($t_subject, 'getTypeFieldName') && ($vs_type_field = $t_subject->getTypeFieldName()) && !isset($va_fields_to_index[$vs_type_field])) {
         $va_fields_to_index[$vs_type_field] = array('STORE', 'DONT_TOKENIZE');
     }
     return SearchBase::$s_fields_to_index_cache[$pm_subject_table . '/' . $pm_content_table . '/' . $vs_key] = SearchBase::$s_fields_to_index_cache[$vs_subject_table . '/' . $vs_content_table . '/' . $vs_key] = $va_fields_to_index;
 }
 /** 
  * Returns labels associated with this row. By default all labels - preferred and non-preferred, and from all locales -
  * are returned. You can limit the returned labels to specified locales by passing a list of locale_ids (numeric ids, *not* locale codes)
  * in $pn_locale_ids. Similarly you can limit return labels to preferred on non-preferred by setting $pn_mode to __CA_LABEL_TYPE_PREFERRED__
  * or __CA_LABEL_TYPE_NONPREFERRED__
  *
  * getLabels() returns an associated array keyed by the primary key of the item the label is attached to; each value is an array keyed by locale_id, the values of which
  * is a list of associative arrays with the label table data. This return format is designed to be digested by the displayHelper function caExtractValuesByUserLocale()
  *
  * @param array $pa_locale_ids
  * @param int $pn_mode
  * @param boolean $pb_dont_cache
  * @param array $pa_options Array of options. Supported options are:
  *			row_id = The row_id to return labels for. If omitted the id of the currently loaded row is used. If row_id is not set and now row is loaded then getLabels() will return null.
  *			restrict_to_types = an optional array of numeric type ids or alphanumeric type identifiers to restrict the returned labels to. The types are list items in a list specified in app.conf (or, if not defined there, by hardcoded constants in the model)
  *			restrictToTypes = synonym for restrict_to_types
  *			extractValuesByUserLocale = if set returned array of values is filtered to include only values appropriate for the current user's locale
  *			forDisplay = if true, a simple list of labels ready for display is returned; implies the extractValuesByUserLocale option
  *
  * @return array List of labels
  */
 public function getLabels($pa_locale_ids = null, $pn_mode = __CA_LABEL_TYPE_ANY__, $pb_dont_cache = true, $pa_options = null)
 {
     if (isset($pa_options['restrictToTypes']) && (!isset($pa_options['restrict_to_types']) || !$pa_options['restrict_to_types'])) {
         $pa_options['restrict_to_types'] = $pa_options['restrictToTypes'];
     }
     if (!($vn_id = $this->getPrimaryKey()) && !(isset($pa_options['row_id']) && ($vn_id = $pa_options['row_id']))) {
         return null;
     }
     if (isset($pa_options['forDisplay']) && $pa_options['forDisplay']) {
         $pa_options['extractValuesByUserLocale'] = true;
     }
     if ($pn_mode == __CA_LABEL_TYPE_ANY__ && caGetBundleAccessLevel($this->tableName(), 'preferred_labels') == __CA_BUNDLE_ACCESS_NONE__) {
         $pn_mode = __CA_LABEL_TYPE_NONPREFERRED__;
     }
     if ($pn_mode == __CA_LABEL_TYPE_ANY__ && caGetBundleAccessLevel($this->tableName(), 'nonpreferred_labels') == __CA_BUNDLE_ACCESS_NONE__) {
         $pn_mode = __CA_LABEL_TYPE_PREFERRED__;
     }
     if ($pn_mode == __CA_LABEL_TYPE_PREFERRED__ && caGetBundleAccessLevel($this->tableName(), 'preferred_labels') == __CA_BUNDLE_ACCESS_NONE__) {
         return null;
     }
     if ($pn_mode == __CA_LABEL_TYPE_NONPREFERRED__ && caGetBundleAccessLevel($this->tableName(), 'nonpreferred_labels') == __CA_BUNDLE_ACCESS_NONE__) {
         return null;
     }
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     $vs_cache_key = caMakeCacheKeyFromOptions(array_merge($pa_options, array('table_name' => $this->tableName(), 'id' => $vn_id, 'mode' => (int) $pn_mode)));
     if (!$pb_dont_cache && is_array($va_tmp = LabelableBaseModelWithAttributes::$s_label_cache[$this->tableName()][$vn_id][$vs_cache_key])) {
         return $va_tmp;
     }
     if (!($t_label = $this->_DATAMODEL->getInstanceByTableName($this->getLabelTableName(), true))) {
         return null;
     }
     if ($this->inTransaction()) {
         $o_trans = $this->getTransaction();
         $t_label->setTransaction($o_trans);
     }
     $vs_label_where_sql = 'WHERE (l.' . $this->primaryKey() . ' = ?)';
     $vs_locale_join_sql = '';
     if ($pa_locale_ids) {
         $vs_label_where_sql .= ' AND (l.locale_id IN (' . join(',', $pa_locale_ids) . '))';
     }
     $vs_locale_join_sql = 'INNER JOIN ca_locales AS loc ON loc.locale_id = l.locale_id';
     $vs_list_code = null;
     if ($t_label->hasField('is_preferred')) {
         switch ($pn_mode) {
             case __CA_LABEL_TYPE_PREFERRED__:
                 $vs_list_code = $this->_CONFIG->get($this->tableName() . '_preferred_label_type_list');
                 $vs_label_where_sql .= ' AND (l.is_preferred = 1)';
                 break;
             case __CA_LABEL_TYPE_NONPREFERRED__:
                 $vs_list_code = $this->_CONFIG->get($this->tableName() . '_nonpreferred_label_type_list');
                 $vs_label_where_sql .= ' AND (l.is_preferred = 0)';
                 break;
             default:
                 $vs_list_code = $this->_CONFIG->get($this->tableName() . '_preferred_label_type_list');
                 break;
         }
         if (!$vs_list_code) {
             if ($t_label_instance = $this->getLabelTableInstance()) {
                 $vs_list_code = $t_label_instance->getFieldInfo('type_id', 'LIST_CODE');
             }
         }
     }
     // limit related items to a specific type
     $vs_restrict_to_type_sql = '';
     if (isset($pa_options['restrict_to_type']) && $pa_options['restrict_to_type']) {
         if (!isset($pa_options['restrict_to_types']) || !is_array($pa_options['restrict_to_types'])) {
             $pa_options['restrict_to_types'] = array();
         }
         $pa_options['restrict_to_types'][] = $pa_options['restrict_to_type'];
     }
     if (isset($pa_options['restrict_to_types']) && $pa_options['restrict_to_types'] && is_array($pa_options['restrict_to_types']) && $vs_list_code) {
         $t_list = new ca_lists();
         $t_list_item = new ca_list_items();
         $va_ids = array();
         foreach ($pa_options['restrict_to_types'] as $vs_type) {
             if (!($vn_restrict_to_type_id = (int) $t_list->getItemIDFromList($vs_list_code, $vs_type))) {
                 $vn_restrict_to_type_id = (int) $vs_type;
             }
             if ($vn_restrict_to_type_id) {
                 $va_children = $t_list_item->getHierarchyChildren($vn_restrict_to_type_id, array('idsOnly' => true));
                 $va_ids = array_merge($va_ids, $va_children);
                 $va_ids[] = $vn_restrict_to_type_id;
             }
         }
         if (sizeof($va_ids) > 0) {
             $vs_restrict_to_type_sql = ' AND l.type_id IN (' . join(',', $va_ids) . ')';
         }
     }
     $o_db = $this->getDb();
     $qr_res = $o_db->query("\n \t\t\t\tSELECT l.*, loc.country locale_country, loc.language locale_language, loc.dialect locale_dialect, loc.name locale_name\n \t\t\t\tFROM " . $this->getLabelTableName() . " l\n \t\t\t\t{$vs_locale_join_sql}\n \t\t\t\t{$vs_label_where_sql}\n \t\t\t\t{$vs_restrict_to_type_sql}\n \t\t\t\tORDER BY\n \t\t\t\t\tloc.name\n \t\t\t", (int) $vn_id);
     $va_labels = array();
     $t_label->clear();
     while ($qr_res->nextRow()) {
         $va_labels[$vn_id][$qr_res->get('locale_id')][] = array_merge($qr_res->getRow(), array('form_element' => $t_label->htmlFormElement($this->getLabelDisplayField(), null)));
     }
     if (isset($pa_options['extractValuesByUserLocale']) && $pa_options['extractValuesByUserLocale']) {
         $va_labels = caExtractValuesByUserLocale($va_labels);
     }
     if (isset($pa_options['forDisplay']) && $pa_options['forDisplay']) {
         $vs_display_field = $this->getLabelDisplayField();
         $va_flattened_labels = array();
         foreach ($va_labels as $vn_id => $va_label_list) {
             foreach ($va_label_list as $vn_i => $va_label) {
                 $va_flattened_labels[] = $va_label[$vs_display_field];
             }
         }
         $va_labels = $va_flattened_labels;
     }
     LabelableBaseModelWithAttributes::$s_label_cache[$this->tableName()][$vn_id][$vs_cache_key] = $va_labels;
     return $va_labels;
 }
Example #3
0
 /**
  * Returns list of screens for a given UI. 
  *
  * @param RequestHTTP $po_request The current request
  * @param int $pn_type_id Optional type to restrict screens to
  * @param array $pa_options Options include:
  *		showAll = Include screens that do not have placements. Default is false.
  *
  * @return array List of screens for this user interface
  */
 public function getScreens($po_request = null, $pn_type_id = null, $pa_options = null)
 {
     if (!$this->getPrimaryKey()) {
         return false;
     }
     $vs_opts_md5 = caMakeCacheKeyFromOptions($pa_options);
     if (!($t_instance = $this->_DATAMODEL->getInstanceByTableNum($this->get('editor_type')))) {
         return null;
     }
     if ($t_instance instanceof BaseRelationshipModel) {
         $va_types = $t_instance->getRelationshipTypes();
     } else {
         $va_types = $t_instance->getTypeList();
     }
     $o_db = $this->getDb();
     $va_type_list = caMakeTypeIDList($this->get('editor_type'), array($pn_type_id), array('dontIncludeSubtypesInTypeRestriction' => true));
     if (!sizeof($va_type_list)) {
         $va_type_list = array($pn_type_id);
     }
     $vs_type_sql = (int) $pn_type_id ? "AND (ceustr.type_id IS NULL OR ceustr.type_id IN (" . join(",", $va_type_list) . "))" : '';
     $qr_res = $o_db->query("\n\t\t\tSELECT ceus.*, ceusl.*, ceustr.type_id restriction_type_id\n\t\t\tFROM ca_editor_ui_screens ceus\n\t\t\tINNER JOIN ca_editor_ui_screen_labels AS ceusl ON ceus.screen_id = ceusl.screen_id\n\t\t\tLEFT JOIN ca_editor_ui_screen_type_restrictions AS ceustr ON ceus.screen_id = ceustr.screen_id\n\t\t\tWHERE\n\t\t\t\t(ceus.ui_id = ?) {$vs_type_sql}\n\t\t\tORDER BY \n\t\t\t\tceus.rank, ceus.screen_id\n\t\t", (int) $this->getPrimaryKey());
     $va_screens = array();
     while ($qr_res->nextRow()) {
         if (!$va_screens[$vn_screen_id = $qr_res->get('screen_id')][$vn_screen_locale_id = $qr_res->get('locale_id')]) {
             $va_screens[$vn_screen_id][$vn_screen_locale_id] = $qr_res->getRow();
             if ((bool) $va_screens[$vn_screen_id][$vn_screen_locale_id]['is_default']) {
                 $va_screens[$vn_screen_id][$vn_screen_locale_id]['isDefault'] = "◉";
             }
             $va_screens[$vn_screen_id][$vn_screen_locale_id]['numPlacements'] = sizeof($this->getScreenBundlePlacements($vn_screen_id));
         }
         if ($qr_res->get('restriction_type_id')) {
             $vs_key_to_add = $t_instance instanceof BaseRelationshipModel ? 'type_code' : 'name_plural';
             $va_screens[$vn_screen_id][$vn_screen_locale_id]['typeRestrictions'][$qr_res->get('restriction_type_id')] = $va_types[$qr_res->get('restriction_type_id')][$vs_key_to_add];
         }
     }
     $va_screens_with_bundles = null;
     if ((!isset($pa_options['showAll']) || !$pa_options['showAll']) && sizeof($va_screens)) {
         // Get placements for all screens, so we can filter screens without placements
         $qr_res = $o_db->query("\n\t\t\t\tSELECT screen_id, placement_id, bundle_name\n\t\t\t\tFROM ca_editor_ui_bundle_placements\n\t\t\t\tWHERE\n\t\t\t\t\tscreen_id IN (?)\n\t\t\t", array(array_keys($va_screens)));
         $vs_table = $t_instance->tableName();
         $va_screens_with_bundles = array();
         while ($qr_res->nextRow()) {
             $vn_screen_id = $qr_res->get('screen_id');
             if (isset($va_screens_with_bundles[$vn_screen_id])) {
                 continue;
             }
             if (caGetBundleAccessLevel($vs_table, $qr_res->get('bundle_name')) != __CA_BUNDLE_ACCESS_NONE__) {
                 $va_screens_with_bundles[$vn_screen_id] = true;
             }
         }
     }
     foreach ($va_screens as $vn_screen_id => $va_screen_labels_by_locale) {
         if (is_array($va_screens_with_bundles) && !isset($va_screens_with_bundles[$vn_screen_id])) {
             unset($va_screens[$vn_screen_id]);
             continue;
         }
         foreach ($va_screen_labels_by_locale as $vn_locale_id => $va_restriction_info) {
             if (!is_array($va_screens[$vn_screen_id][$vn_locale_id]['typeRestrictions'])) {
                 continue;
             }
             $va_screens[$vn_screen_id][$vn_locale_id]['typeRestrictionsForDisplay'] = join(', ', $va_screens[$vn_screen_id][$vn_locale_id]['typeRestrictions']);
         }
     }
     return caExtractValuesByUserLocale($va_screens);
 }
Example #4
0
 /**
  *
  *
  * @param array $pa_source_codes_or_ids List of source codes or ids 
  * @param array $pa_options Options include
  *		includeSubsources = include any child sources in the restriction. Default is true.
  * @return array List of source_ids
  */
 private function _convertSourceCodesToIDs($pa_source_codes_or_ids, $pa_options = null)
 {
     $vs_md5 = caMakeCacheKeyFromOptions($pa_source_codes_or_ids);
     if (isset(BrowseEngine::$s_source_id_cache[$vs_md5])) {
         return BrowseEngine::$s_source_id_cache[$vs_md5];
     }
     if (isset($pa_options['instance']) && is_object($pa_options['instance'])) {
         $t_instance = $pa_options['instance'];
     } else {
         $t_instance = $this->getSubjectInstance();
     }
     $va_source_ids = array();
     if (!$pa_source_codes_or_ids) {
         return false;
     }
     if (is_array($pa_source_codes_or_ids) && !sizeof($pa_source_codes_or_ids)) {
         return false;
     }
     if (!is_array($pa_source_codes_or_ids)) {
         $pa_source_codes_or_ids = array($pa_source_codes_or_ids);
     }
     $t_list = new ca_lists();
     if (!method_exists($t_instance, 'getSourceListCode')) {
         return false;
     }
     if (!($vs_list_name = $t_instance->getSourceListCode())) {
         return false;
     }
     $va_source_list = $t_instance->getSourceList();
     foreach ($pa_source_codes_or_ids as $vs_code_or_id) {
         if (!trim($vs_code_or_id)) {
             continue;
         }
         if (!is_numeric($vs_code_or_id)) {
             $vn_source_id = $t_list->getItemIDFromList($vs_list_name, $vs_code_or_id);
         } else {
             $vn_source_id = (int) $vs_code_or_id;
         }
         if (!$vn_source_id) {
             return false;
         }
         if (isset($va_source_list[$vn_source_id]) && $va_source_list[$vn_source_id]) {
             // is valid source for this subject
             // See if there are any child sources
             if (caGetOption('includeSubsources', $pa_options, true) && $this->opb_dont_expand_source_restrictions) {
                 $t_item = new ca_list_items($vn_source_id);
                 $va_ids = $t_item->getHierarchyChildren(null, array('idsOnly' => true));
             }
             $va_ids[] = $vn_source_id;
             $va_source_ids = array_merge($va_source_ids, $va_ids);
         }
     }
     $va_source_ids = array_keys(array_flip($va_source_ids));
     BrowseEngine::$s_source_id_cache[$vs_md5] = $va_source_ids;
     return $va_source_ids;
 }
Example #5
0
 /**
  * Implementation of core get() logic
  *
  * @param string $ps_field bundle specifier
  * @param null|array $pa_options options array
  * @return array|null|string
  */
 private function _get($ps_field, $pa_options = null)
 {
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     $vb_return_as_array = isset($pa_options['returnAsArray']) ? (bool) $pa_options['returnAsArray'] : false;
     $vb_return_all_locales = isset($pa_options['returnAllLocales']) ? (bool) $pa_options['returnAllLocales'] : false;
     $vb_return_with_structure = isset($pa_options['returnWithStructure']) ? (bool) $pa_options['returnWithStructure'] : false;
     if ($vb_return_with_structure) {
         $pa_options['returnAsArray'] = $vb_return_as_array = true;
     }
     // returnWithStructure implies returnAsArray
     $vs_delimiter = isset($pa_options['delimiter']) ? $pa_options['delimiter'] : ';';
     $vb_unserialize = isset($pa_options['unserialize']) ? (bool) $pa_options['unserialize'] : false;
     $vb_return_url = isset($pa_options['returnURL']) ? (bool) $pa_options['returnURL'] : false;
     $vb_return_path = isset($pa_options['returnPath']) ? (bool) $pa_options['returnPAth'] : false;
     $vb_convert_codes_to_display_text = isset($pa_options['convertCodesToDisplayText']) ? (bool) $pa_options['convertCodesToDisplayText'] : false;
     $vb_convert_codes_to_idno = isset($pa_options['convertCodesToIdno']) ? (bool) $pa_options['convertCodesToIdno'] : false;
     $vb_use_locale_codes = isset($pa_options['useLocaleCodes']) ? (bool) $pa_options['useLocaleCodes'] : false;
     if (!($vs_output = isset($pa_options['output']) ? (string) $pa_options['output'] : null)) {
         if ($vb_convert_codes_to_display_text) {
             $vs_output = "text";
         }
         if (!$vs_output && $vb_convert_codes_to_idno) {
             $vs_output = "idno";
         }
     }
     if (!in_array($vs_output, array('text', 'idno', 'value'))) {
         $vs_output = 'value';
     }
     $pa_options['output'] = $vs_output;
     if (!($vb_return_as_link = isset($pa_options['makeLink']) ? (bool) $pa_options['makeLink'] : false)) {
         $vb_return_as_link = isset($pa_options['returnAsLink']) ? (bool) $pa_options['returnAsLink'] : false;
     }
     $pa_options['makeLink'] = $vb_return_as_link;
     $vn_max_levels_from_top = isset($pa_options['maxLevelsFromTop']) ? (int) $pa_options['maxLevelsFromTop'] : null;
     $vn_max_levels_from_bottom = isset($pa_options['maxLevelsFromBottom']) ? (int) $pa_options['maxLevelsFromBottom'] : null;
     $vn_remove_first_items = isset($pa_options['removeFirstItems']) ? (int) $pa_options['removeFirstItems'] : 0;
     $va_check_access = isset($pa_options['checkAccess']) ? is_array($pa_options['checkAccess']) ? $pa_options['checkAccess'] : array($pa_options['checkAccess']) : null;
     $vs_template = isset($pa_options['template']) ? (string) $pa_options['template'] : null;
     $va_path_components = isset(SearchResult::$s_parsed_field_component_cache[$this->ops_table_name . '/' . $ps_field]) ? SearchResult::$s_parsed_field_component_cache[$this->ops_table_name . '/' . $ps_field] : $this->parseFieldPathComponents($ps_field);
     $va_val_opts = array_merge($pa_options, array('returnAsArray' => $vb_return_as_array, 'returnAllLocales' => $vb_return_all_locales, 'returnWithStructure' => $vb_return_with_structure, 'pathComponents' => $va_path_components, 'delimiter' => $vs_delimiter, 'makeLink' => $vb_return_as_link, 'returnURL' => $vb_return_url, 'returnPath' => $vb_return_path, 'unserialize' => $vb_unserialize, 'convertCodesToDisplayText' => $vb_convert_codes_to_display_text, 'convertCodesToIdno' => $vb_convert_codes_to_idno, 'checkAccess' => $va_check_access, 'template' => $vs_template, 'useLocaleCodes' => $vb_use_locale_codes));
     if ($va_path_components['table_name'] != $this->ops_table_name) {
         $vs_access_chk_key = $va_path_components['table_name'] . ($va_path_components['field_name'] ? '.' . $va_path_components['field_name'] : '');
     } else {
         $vs_access_chk_key = $va_path_components['field_name'];
     }
     if ($va_path_components['field_name'] !== 'access' && caGetBundleAccessLevel($va_path_components['table_name'], $vs_access_chk_key) == __CA_BUNDLE_ACCESS_NONE__) {
         return null;
     }
     if (!(($vs_value = $this->opo_engine_result->get($ps_field, $pa_options)) === false)) {
         if ($vb_return_as_array) {
             if ($vb_return_all_locales) {
                 return array(1 => $vs_value);
             } else {
                 return array($vs_value);
             }
         } else {
             return $vs_value;
         }
     }
     if (!($t_instance = SearchResult::$s_instance_cache[$va_path_components['table_name']])) {
         $t_instance = SearchResult::$s_instance_cache[$va_path_components['table_name']] = $this->opo_datamodel->getInstanceByTableName($va_path_components['table_name'], true);
     }
     if (!$t_instance) {
         return null;
     }
     // Bad table
     $vn_row_id = $this->opo_engine_result->get($this->ops_table_pk);
     $va_val_opts['primaryKey'] = $t_instance->primaryKey();
     if ($va_path_components['hierarchical_modifier']) {
         if (in_array($va_path_components['field_name'], array('preferred_labels', 'nonpreferred_labels')) && !$va_path_components['subfield_name']) {
             $va_path_components['subfield_name'] = $va_path_components['components'][2] = $t_instance->getLabelDisplayField();
         }
         switch ($va_path_components['hierarchical_modifier']) {
             case 'parent':
                 if ($va_path_components['related']) {
                     // [RELATED TABLE PARENT]
                     if (!isset(SearchResult::$opa_hierarchy_parent_prefetch_cache_index[$this->ops_table_name][$vn_row_id][$va_path_components['table_name']])) {
                         $this->prefetchHierarchyParents($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
                     }
                     $va_ids = SearchResult::$opa_hierarchy_parent_prefetch_cache_index[$this->ops_table_name][$vn_row_id][$va_path_components['table_name']];
                 } else {
                     // [PRIMARY TABLE PARENT]
                     if (!isset(SearchResult::$opa_hierarchy_parent_prefetch_cache[$va_path_components['table_name']][$vn_row_id])) {
                         $this->prefetchHierarchyParents($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
                     }
                     $va_ids = array($vn_row_id);
                 }
                 if (!sizeof($va_ids)) {
                     return $pa_options['returnAsArray'] ? array() : null;
                 }
                 $va_hiers = array();
                 foreach ($va_ids as $vn_id) {
                     $va_parent_ids = array();
                     if (isset(SearchResult::$opa_hierarchy_parent_prefetch_cache[$va_path_components['table_name']][$vn_id]) && is_array(SearchResult::$opa_hierarchy_parent_prefetch_cache[$va_path_components['table_name']][$vn_id])) {
                         if (!is_array($va_parent_ids = SearchResult::$opa_hierarchy_parent_prefetch_cache[$va_path_components['table_name']][$vn_id])) {
                             return $pa_options['returnAsArray'] ? array() : null;
                         }
                     }
                     $va_parent_ids = array_slice($va_parent_ids, 0, 1);
                     if (!($qr_hier = $t_instance->makeSearchResult($va_path_components['table_name'], $va_parent_ids))) {
                         return $pa_options['returnAsArray'] ? array() : null;
                     }
                     $va_tmp = array($va_path_components['table_name']);
                     if ($va_path_components['field_name']) {
                         $va_tmp[] = $va_path_components['field_name'];
                     }
                     if ($va_path_components['subfield_name']) {
                         $va_tmp[] = $va_path_components['subfield_name'];
                     }
                     $vs_hier_fld_name = join(".", $va_tmp);
                     $vs_pk = $t_instance->primaryKey();
                     $vm_val = null;
                     if ($qr_hier->nextHit()) {
                         $vm_val = $qr_hier->get($vs_hier_fld_name, $pa_options);
                     }
                     if ($vm_val) {
                         $va_hiers[] = $vb_return_as_array ? array_shift($vm_val) : $vm_val;
                     }
                 }
                 return $vb_return_as_array ? $va_hiers : join($vs_delimiter, $va_hiers);
                 break;
             case 'hierarchy':
                 // generate the hierarchy
                 if ($va_path_components['related']) {
                     // [RELATED TABLE HIERARCHY]
                     if (!isset(SearchResult::$opa_hierarchy_parent_prefetch_cache_index[$this->ops_table_name][$vn_row_id][$va_path_components['table_name']])) {
                         $this->prefetchHierarchyParents($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
                     }
                     // ids of related items
                     $va_ids = array_values(SearchResult::$opa_hierarchy_parent_prefetch_cache_index[$this->ops_table_name][$vn_row_id][$va_path_components['table_name']]);
                 } else {
                     // [PRIMARY TABLE HIERARCHY]
                     if (!isset(SearchResult::$opa_hierarchy_parent_prefetch_cache[$va_path_components['table_name']][$vn_row_id])) {
                         $this->prefetchHierarchyParents($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
                     }
                     $va_ids = array($vn_row_id);
                 }
                 if (!sizeof($va_ids)) {
                     return $pa_options['returnAsArray'] ? array() : null;
                 }
                 $vs_hier_pk_fld = $t_instance->primaryKey();
                 $va_hiers = $va_hier_ids = array();
                 $vs_hierarchy_direction = isset($pa_options['hierarchyDirection']) ? strtolower($pa_options['hierarchyDirection']) : 'asc';
                 if ($t_instance->isHierarchical()) {
                     if ($va_path_components['field_name'] === $vs_hier_pk_fld) {
                         if ($va_path_components['related']) {
                             foreach ($va_ids as $vn_id) {
                                 if (is_array(SearchResult::$opa_hierarchy_parent_prefetch_cache[$va_path_components['table_name']][$vn_id])) {
                                     $va_hier_id_list = array_merge(array($vn_id), SearchResult::$opa_hierarchy_parent_prefetch_cache[$va_path_components['table_name']][$vn_id]);
                                     $va_hier_id_list = array_filter($va_hier_id_list, function ($v) {
                                         return $v > 0;
                                     });
                                     if ($vs_hierarchy_direction === 'asc') {
                                         $va_hier_id_list = array_reverse($va_hier_id_list);
                                     }
                                     if (!is_null($vn_max_levels_from_top)) {
                                         $va_hier_id_list = array_slice($va_hier_id_list, 0, $vn_max_levels_from_top, true);
                                     } elseif (!is_null($vn_max_levels_from_bottom)) {
                                         if (($vn_start = sizeof($va_hier_id_list) - $vn_max_levels_from_bottom) < 0) {
                                             $vn_start = 0;
                                         }
                                         $va_hier_id_list = array_slice($va_hier_id_list, $vn_start, $vn_max_levels_from_bottom, true);
                                     }
                                     $va_hier_ids[] = $va_hier_id_list;
                                 }
                             }
                         } else {
                             // Return ids from hierarchy in order
                             if (is_array(SearchResult::$opa_hierarchy_parent_prefetch_cache[$va_path_components['table_name']][$vn_row_id])) {
                                 $va_hier_ids = array_merge(array($vn_row_id), SearchResult::$opa_hierarchy_parent_prefetch_cache[$va_path_components['table_name']][$vn_row_id]);
                             } else {
                                 $va_hier_ids = array($vn_row_id);
                             }
                             if (!is_null($vn_max_levels_from_top)) {
                                 $va_hier_ids = array_slice($va_hier_ids, 0, $vn_max_levels_from_top, true);
                             } elseif (!is_null($vn_max_levels_from_bottom)) {
                                 if (($vn_start = sizeof($va_hier_ids) - $vn_max_levels_from_bottom) < 0) {
                                     $vn_start = 0;
                                 }
                                 $va_hier_ids = array_slice($va_hier_ids, $vn_start, $vn_max_levels_from_bottom, true);
                             }
                             if ($vs_hierarchy_direction === 'asc') {
                                 $va_hier_ids = array_reverse($va_hier_ids);
                             }
                         }
                         return $vb_return_as_array ? $va_hier_ids : join($vs_delimiter, $va_hier_ids);
                     } else {
                         $vs_field_spec = join('.', array_values($va_path_components['components']));
                         $va_ancestor_id_list = $this->get($va_path_components['table_name'] . '.hierarchy.' . $vs_hier_pk_fld, array_merge($pa_options, array('returnAsArray' => true, 'returnAsLink' => false, 'returnAllLocales' => false)));
                         if (!is_array($va_ancestor_id_list)) {
                             return $vb_return_as_array ? array() : null;
                         }
                         if (!$va_path_components['related']) {
                             $va_ancestor_id_list = array($va_ancestor_id_list);
                         }
                         $va_hier_list = array();
                         foreach ($va_ancestor_id_list as $va_ancestor_ids) {
                             if ($vn_remove_first_items > 0) {
                                 $va_ancestor_ids = array_slice($va_ancestor_ids, $vn_remove_first_items);
                             }
                             $va_hier_item = array();
                             if ($qr_hier = caMakeSearchResult($va_path_components['table_name'], $va_ancestor_ids)) {
                                 while ($qr_hier->nextHit()) {
                                     $va_hier_item += $qr_hier->get($vs_field_spec, array('returnWithStructure' => true, 'returnAllLocales' => true, 'useLocaleCodes' => $pa_options['useLocaleCodes']));
                                 }
                                 if (!is_null($vn_max_levels_from_top)) {
                                     $va_hier_item = array_slice($va_hier_item, 0, $vn_max_levels_from_top, true);
                                 } elseif (!is_null($vn_max_levels_from_bottom)) {
                                     if (($vn_start = sizeof($va_hier_item) - $vn_max_levels_from_bottom) < 0) {
                                         $vn_start = 0;
                                     }
                                     $va_hier_item = array_slice($va_hier_item, $vn_start, $vn_max_levels_from_bottom, true);
                                 }
                                 $va_hier_list[] = $va_hier_item;
                             }
                         }
                     }
                 }
                 $va_acc = array();
                 foreach ($va_hier_list as $vn_h => $va_hier_item) {
                     if (!$vb_return_all_locales) {
                         $va_hier_item = caExtractValuesByUserLocale($va_hier_item);
                     }
                     if ($vb_return_with_structure) {
                         $va_acc[] = $va_hier_item;
                     } else {
                         $va_acc = $this->_flattenArray($va_hier_item, $pa_options);
                     }
                 }
                 return $pa_options['returnAsArray'] ? $va_acc : join($vs_delimiter, $va_acc);
                 break;
             case 'children':
                 // grab children
                 if ($va_path_components['related']) {
                     // [RELATED TABLE CHILDREN]
                     if (!isset(SearchResult::$opa_hierarchy_children_prefetch_cache_index[$this->ops_table_name][$vn_row_id][$va_path_components['table_name']])) {
                         $this->prefetchHierarchyChildren($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
                     }
                     $va_ids = SearchResult::$opa_hierarchy_children_prefetch_cache_index[$this->ops_table_name][$vn_row_id][$va_path_components['table_name']];
                 } else {
                     // [PRIMARY TABLE CHILDREN]
                     if (!isset(SearchResult::$opa_hierarchy_children_prefetch_cache[$this->ops_table_name][$vn_row_id])) {
                         $this->prefetchHierarchyChildren($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
                     }
                     $va_ids = array($vn_row_id);
                 }
                 $va_hier_list = array();
                 foreach ($va_ids as $vn_id) {
                     if (!is_array(SearchResult::$opa_hierarchy_children_prefetch_cache[$va_path_components['table_name']][$vn_id]) || !sizeof(SearchResult::$opa_hierarchy_children_prefetch_cache[$va_path_components['table_name']][$vn_id])) {
                         continue;
                     }
                     $qr_hier = $t_instance->makeSearchResult($va_path_components['table_name'], SearchResult::$opa_hierarchy_children_prefetch_cache[$va_path_components['table_name']][$vn_id]);
                     $va_tmp = array($va_path_components['table_name']);
                     if ($va_path_components['field_name']) {
                         $va_tmp[] = $va_path_components['field_name'];
                     }
                     if ($va_path_components['subfield_name']) {
                         $va_tmp[] = $va_path_components['subfield_name'];
                     }
                     $vs_hier_fld_name = join(".", $va_tmp);
                     $vs_pk = $t_instance->primaryKey();
                     while ($qr_hier->nextHit()) {
                         $vm_val = $qr_hier->get($vs_hier_fld_name, $pa_options);
                         $va_hier_list[$qr_hier->get($va_path_components['table_name'] . '.' . $vs_pk)] = $vb_return_as_array ? array_shift($vm_val) : $vm_val;
                     }
                 }
                 if (!$vb_return_as_array) {
                     return join($vs_delimiter, $va_hier_list);
                 }
                 return $va_hier_list;
                 break;
             case 'siblings':
                 // grab siblings
                 if ($va_path_components['related']) {
                     // [RELATED TABLE SIBLINGS]
                     if (!isset(SearchResult::$opa_hierarchy_siblings_prefetch_cache_index[$this->ops_table_name][$vn_row_id][$va_path_components['table_name']])) {
                         $this->prefetchHierarchySiblings($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
                     }
                     $va_ids = SearchResult::$opa_hierarchy_siblings_prefetch_cache_index[$this->ops_table_name][$vn_row_id][$va_path_components['table_name']];
                 } else {
                     // [PRIMARY TABLE SIBLINGS]
                     if (!isset(SearchResult::$opa_hierarchy_siblings_prefetch_cache[$this->ops_table_name][$vn_row_id])) {
                         $this->prefetchHierarchySiblings($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
                     }
                     $va_ids = array($vn_row_id);
                 }
                 $va_hier_list = array();
                 foreach ($va_ids as $vn_id) {
                     if (!is_array(SearchResult::$opa_hierarchy_siblings_prefetch_cache[$va_path_components['table_name']][$vn_id]) || !sizeof(SearchResult::$opa_hierarchy_siblings_prefetch_cache[$va_path_components['table_name']][$vn_id])) {
                         continue;
                     }
                     $qr_hier = $t_instance->makeSearchResult($va_path_components['table_name'], SearchResult::$opa_hierarchy_siblings_prefetch_cache[$va_path_components['table_name']][$vn_id]);
                     $va_tmp = array($va_path_components['table_name']);
                     if ($va_path_components['field_name']) {
                         $va_tmp[] = $va_path_components['field_name'];
                     }
                     if ($va_path_components['subfield_name']) {
                         $va_tmp[] = $va_path_components['subfield_name'];
                     }
                     $vs_hier_fld_name = join(".", $va_tmp);
                     $vs_pk = $t_instance->primaryKey();
                     while ($qr_hier->nextHit()) {
                         $vm_val = $qr_hier->get($vs_hier_fld_name, $pa_options);
                         $va_hier_list[$qr_hier->get($va_path_components['table_name'] . '.' . $vs_pk)] = $vb_return_as_array ? array_shift($vm_val) : $vm_val;
                     }
                 }
                 if (!$vb_return_as_array) {
                     return join($vs_delimiter, $va_hier_list);
                 }
                 return $va_hier_list;
                 break;
         }
         return;
     }
     if ($va_path_components['related']) {
         //
         // [RELATED TABLE]
         //
         $vs_opt_md5 = caMakeCacheKeyFromOptions(array_merge($pa_options, array('dontReturnLabels' => false)));
         if (!isset(self::$s_rel_prefetch_cache[$this->ops_table_name][$vn_row_id][$va_path_components['table_name']][$vs_opt_md5])) {
             $this->prefetchRelated($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), array_merge($pa_options, array('dontReturnLabels' => false)));
         }
         $va_related_items = self::$s_rel_prefetch_cache[$this->ops_table_name][$vn_row_id][$va_path_components['table_name']][$vs_opt_md5];
         if (!is_array($va_related_items)) {
             return $vb_return_with_structure || $vb_return_as_array ? array() : null;
         }
         return $this->_getRelatedValue($va_related_items, $va_val_opts);
     } else {
         if (!$va_path_components['hierarchical_modifier']) {
             //
             // [PRIMARY TABLE] Created on
             //
             if ($va_path_components['field_name'] == 'created') {
                 if (!isset(self::$s_timestamp_cache['created_on'][$this->ops_table_name][$vn_row_id])) {
                     $this->prefetchChangeLogData($this->ops_table_name, $this->opo_engine_result->currentRow(), $this->getOption('prefetch'));
                 }
                 if ($vb_return_as_array) {
                     return self::$s_timestamp_cache['created_on'][$this->ops_table_name][$vn_row_id];
                 } else {
                     $vs_subfield = $va_path_components['subfield_name'] ? $va_path_components['subfield_name'] : 'timestamp';
                     $vm_val = self::$s_timestamp_cache['created_on'][$this->ops_table_name][$vn_row_id][$vs_subfield];
                     if ($vs_subfield == 'timestamp') {
                         $this->opo_tep->init();
                         $this->opo_tep->setUnixTimestamps($vm_val, $vm_val);
                         $vm_val = $this->opo_tep->getText($pa_options);
                     }
                     return $vm_val;
                 }
             }
             //
             // [PRIMARY TABLE] Last modified on
             //
             if ($va_path_components['field_name'] == 'lastModified') {
                 if (!isset(self::$s_timestamp_cache['last_changed'][$this->ops_table_name][$vn_row_id])) {
                     $this->prefetchChangeLogData($this->ops_table_name, $this->opo_engine_result->currentRow(), $this->getOption('prefetch'));
                 }
                 if ($vb_return_as_array) {
                     return self::$s_timestamp_cache['last_changed'][$this->ops_table_name][$vn_row_id];
                 } else {
                     $vs_subfield = $va_path_components['subfield_name'] ? $va_path_components['subfield_name'] : 'timestamp';
                     $vm_val = self::$s_timestamp_cache['last_changed'][$this->ops_table_name][$vn_row_id][$vs_subfield];
                     if ($vs_subfield == 'timestamp') {
                         $this->opo_tep->init();
                         $this->opo_tep->setUnixTimestamps($vm_val, $vm_val);
                         $vm_val = $this->opo_tep->getText($pa_options);
                     }
                     return $vm_val;
                 }
             }
             $vs_opt_md5 = caMakeCacheKeyFromOptions($pa_options);
             //
             // [PRIMARY TABLE] Preferred/nonpreferred labels
             //
             if (in_array($va_path_components['field_name'], array('preferred_labels', 'nonpreferred_labels')) && $t_instance instanceof LabelableBaseModelWithAttributes) {
                 $vs_label_table_name = $t_instance->getLabelTableName();
                 if (!isset(self::$s_prefetch_cache[$vs_label_table_name][$vn_row_id][$vs_opt_md5])) {
                     $this->prefetchLabels($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
                 }
                 return $this->_getLabelValue(self::$s_prefetch_cache[$vs_label_table_name][$vn_row_id][$vs_opt_md5], $t_instance, $va_val_opts);
             }
             if ($t_instance->hasField($va_path_components['field_name'])) {
                 $va_val_opts['fieldInfo'] = $t_instance->getFieldInfo($va_path_components['field_name']);
                 //
                 // [PRIMARY TABLE] Plain old intrinsic
                 //
                 if (!isset(self::$s_prefetch_cache[$va_path_components['table_name']][$vn_row_id][$vs_opt_md5])) {
                     $this->prefetch($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
                 }
                 return $this->_getIntrinsicValue(self::$s_prefetch_cache[$va_path_components['table_name']][$vn_row_id][$vs_opt_md5], $t_instance, $va_val_opts);
             } elseif (method_exists($t_instance, 'isValidBundle') && !$t_instance->hasElement($va_path_components['field_name']) && $t_instance->isValidBundle($va_path_components['field_name'])) {
                 //
                 // [PRIMARY TABLE] Special bundle
                 //
                 return $t_instance->renderBundleForDisplay($va_path_components['field_name'], $vn_row_id, self::$s_prefetch_cache[$va_path_components['table_name']][$vn_row_id][$vs_opt_md5], $va_val_opts);
             } else {
                 //
                 // [PRIMARY TABLE] Metadata attribute
                 //
                 if ($t_instance instanceof BaseModelWithAttributes && isset($va_path_components['field_name']) && $va_path_components['field_name'] && ($t_element = $t_instance->_getElementInstance($va_path_components['field_name']))) {
                     $vn_element_id = $t_element->getPrimaryKey();
                 } else {
                     return $pa_options['returnAsArray'] ? array() : null;
                 }
                 if (!isset(ca_attributes::$s_get_attributes_cache[(int) $this->opn_table_num . '/' . (int) $vn_row_id][(int) $vn_element_id])) {
                     ca_attributes::prefetchAttributes($this->opo_subject_instance->getDb(), $this->opn_table_num, $this->getRowIDsToPrefetch($this->opo_engine_result->currentRow(), $this->getOption('prefetch')), $vn_element_id ? array($vn_element_id) : null, array('dontFetchAlreadyCachedValues' => true));
                 }
                 $va_attributes = ca_attributes::getAttributes($this->opo_subject_instance->getDb(), $this->opn_table_num, $vn_row_id, array($vn_element_id), array());
                 return $this->_getAttributeValue($va_attributes[$vn_element_id], $t_instance, $va_val_opts);
             }
         }
     }
     return null;
 }
/**
 * @param $ps_type
 * @param $ps_template
 * @param null $pa_options
 * @return array|bool|false|mixed
 */
function caGetPrintTemplateDetails($ps_type, $ps_template, $pa_options = null)
{
    $vs_template_path = caGetPrintTemplateDirectoryPath($ps_type);
    if (file_exists("{$vs_template_path}/local/{$ps_template}.php")) {
        $vs_template_path = "{$vs_template_path}/local/{$ps_template}.php";
    } elseif (file_exists("{$vs_template_path}/{$ps_template}.php")) {
        $vs_template_path = "{$vs_template_path}/{$ps_template}.php";
    } else {
        return false;
    }
    $vs_cache_key = caMakeCacheKeyFromOptions($pa_options, $ps_type . '/' . $vs_template_path);
    if (ExternalCache::contains($vs_cache_key, 'PrintTemplateDetails')) {
        $va_list = ExternalCache::fetch($vs_cache_key, 'PrintTemplateDetails');
        if (ExternalCache::fetch("{$vs_cache_key}_mtime", 'PrintTemplateDetails') >= filemtime($vs_template_path)) {
            //Debug::msg('[caGetPrintTemplateDetails] cache hit');
            return $va_list;
        }
    }
    //Debug::msg('[caGetPrintTemplateDetails] cache miss');
    $vs_template = file_get_contents($vs_template_path);
    $va_info = array();
    foreach (array("@name", "@type", "@pageSize", "@pageOrientation", "@tables", "@marginLeft", "@marginRight", "@marginTop", "@marginBottom", "@horizontalGutter", "@verticalGutter", "@labelWidth", "@labelHeight", "@elementCode") as $vs_tag) {
        if (preg_match("!{$vs_tag}([^\n\n]+)!", $vs_template, $va_matches)) {
            $va_info[str_replace("@", "", $vs_tag)] = trim($va_matches[1]);
        } else {
            $va_info[str_replace("@", "", $vs_tag)] = null;
        }
    }
    $va_info['tables'] = preg_split("![,;]{1}!", $va_info['tables']);
    $va_info['path'] = $vs_template_path;
    ExternalCache::save($vs_cache_key, $va_info, 'PrintTemplateDetails');
    ExternalCache::save("{$vs_cache_key}_mtime", filemtime($vs_template_path), 'PrintTemplateDetails');
    return $va_info;
}
Example #7
0
 /**
  * Returns a list of ca_object rows related to the currently loaded object lot.
  *
  * @param int $pn_lot_id Optional lot_id to get object list for; if null then the id of the currently loaded lot will be used
  * @param array $pa_options Options include:
  *		return = Set to "components" to return the count of component objects only; "objects" to return the count of objects (but not components) or "all" to return a count of any kind of object. [Default = "all"]
  * @return array List of objects related to the object lot or null if $pn_lot_id is not set and there is no currently loaded lot
  */
 public function getObjects($pn_lot_id = null, $pa_options = null)
 {
     $vn_lot_id = $this->getPrimaryKey();
     if ($pn_lot_id && $pn_lot_id != $vn_lot_id) {
         $vn_lot_id = $pn_lot_id;
     }
     $ps_return = caGetOption('return', $pa_options, 'all');
     $vs_cache_key = caMakeCacheKeyFromOptions($pa_options);
     if (is_array($va_component_types = $this->getAppConfig()->getList('ca_objects_component_types')) && sizeof($va_component_types)) {
         $va_component_types = caMakeTypeIDList('ca_objects', $va_component_types);
     }
     $o_db = $this->getDb();
     $qr_res = $o_db->query("\n\t\t\t\tSELECT *\n\t\t\t\tFROM ca_objects\n\t\t\t\tWHERE\n\t\t\t\t\tlot_id = ? AND deleted = 0\n\t\t\t\tORDER BY\n\t\t\t\t\tidno_sort\n\t\t\t", (int) $vn_lot_id);
     $va_rows = array();
     while ($qr_res->nextRow()) {
         $va_rows[$qr_res->get('object_id')] = 1;
     }
     if (!sizeof($va_rows)) {
         ca_object_lots::$s_object_count_cache[$vn_lot_id][$vs_cache_key] = 0;
         return array();
     }
     $qr_res = $o_db->query("\n\t\t\tSELECT *\n\t\t\tFROM ca_objects\n\t\t\tWHERE\n\t\t\t\thier_object_id IN (?) AND deleted = 0\n\t\t\tORDER BY\n\t\t\t\tidno_sort\n\t\t", array(array_keys($va_rows)));
     $va_objects = array();
     while ($qr_res->nextRow()) {
         $va_row = $qr_res->getRow();
         if ($ps_return == 'objects' && in_array($va_row['type_id'], $va_component_types)) {
             continue;
         }
         if ($ps_return == 'components' && !in_array($va_row['type_id'], $va_component_types)) {
             continue;
         }
         $va_objects[$va_row['object_id']] = $va_row;
     }
     ca_object_lots::$s_object_count_cache[$vn_lot_id][$vs_cache_key] = sizeof($va_objects);
     return $va_objects;
 }
 /**
  * Generate hierarchical values for using in indexing of hierarchical values with INDEX_ANCESTORS enabled
  */
 private function _genHierarchicalPath($pn_subject_row_id, $ps_field, $t_subject, $pa_options = null)
 {
     $vs_key = caMakeCacheKeyFromOptions($pa_options, "{$pn_subject_row_id}/{$ps_field}");
     if (MemoryCache::contains($vs_key, 'SearchIndexerHierPaths')) {
         return MemoryCache::fetch($vs_key, 'SearchIndexerHierPaths');
     }
     $pn_start = caGetOption('INDEX_ANCESTORS_START_AT_LEVEL', $pa_options, 0);
     $pn_max_levels = caGetOption('INDEX_ANCESTORS_MAX_NUMBER_OF_LEVELS', $pa_options, null);
     $ps_delimiter = caGetOption('INDEX_ANCESTORS_AS_PATH_WITH_DELIMITER', $pa_options, '; ');
     // Automagically generate hierarchical paths for preferred labels passed as label table + label field
     if (is_subclass_of($t_subject, "BaseLabel")) {
         if (!($t_subject->getPrimaryKey() == $pn_subject_row_id)) {
             $t_subject->load($pn_subject_row_id);
         }
         $pn_subject_row_id = $t_subject->get($t_subject->getSubjectKey());
         $t_subject = $t_subject->getSubjectTableInstance();
         $ps_field = "preferred_labels.{$ps_field}";
     }
     $va_ids = $t_subject->getHierarchyAncestors($pn_subject_row_id, array('idsOnly' => true, 'includeSelf' => true));
     $vs_subject_tablename = $t_subject->tableName();
     if (is_array($va_ids) && sizeof($va_ids) > 0) {
         $qr_hier_res = $t_subject->makeSearchResult($vs_subject_tablename, $va_ids, array('db' => $this->getDb()));
         $va_hier_values = array();
         while ($qr_hier_res->nextHit()) {
             if ($vs_v = $qr_hier_res->get($vs_subject_tablename . "." . $ps_field)) {
                 $va_hier_values[] = $vs_v;
             }
         }
         $va_hier_values = array_reverse($va_hier_values);
         if ($pn_start > 0) {
             $va_hier_values = array_slice($va_hier_values, $pn_start);
         }
         if ($pn_max_levels > 0) {
             $va_hier_values = array_slice($va_hier_values, 0, $pn_max_levels);
         }
         if (MemoryCache::itemCountForNamespace('SearchIndexerHierPaths') > 100) {
             MemoryCache::flush('SearchIndexerHierPaths');
         }
         $va_return = array('values' => $va_hier_values, 'path' => join($ps_delimiter, $va_hier_values));
         MemoryCache::save($vs_key, $va_return, 'SearchIndexerHierPaths');
         return $va_return;
     }
     MemoryCache::save($vs_key, null, 'SearchIndexerHierPaths');
     return null;
 }
Example #9
0
 /**
  * Fetches configuration for the specified location class/subclass
  *
  * @param mixed $pm_current_loc_class Table name or number (aka. class)
  * @param mixed $pm_current_loc_subclass Type_id or code (aka. subclass)
  * 
  * @return array
  */
 public static function getConfigurationForCurrentLocationType($pm_current_loc_class, $pm_current_loc_subclass = null, $pa_options = null)
 {
     $vs_cache_key = caMakeCacheKeyFromOptions($pa_options, "{$pm_current_loc_class}/{$pm_current_loc_subclass}");
     if (isset(ca_objects::$s_current_location_type_configuration_cache[$vs_cache_key])) {
         return ca_objects::$s_current_location_type_configuration_cache[$vs_cache_key];
     }
     $o_config = Configuration::load();
     $o_dm = Datamodel::load();
     $va_map = $o_config->getAssoc('current_location_criteria');
     if (!($t_instance = $o_dm->getInstance($pm_current_loc_class, true))) {
         return ca_objects::$s_current_location_type_configuration_cache[$vs_cache_key] = null;
     }
     $vs_table_name = $t_instance->tableName();
     if (isset($va_map[$vs_table_name])) {
         if (!$pm_current_loc_subclass && isset($va_map[$vs_table_name]['*'])) {
             return ca_objects::$s_current_location_type_configuration_cache[caMakeCacheKeyFromOptions($pa_options, "{$vs_table_name}/{$pm_type_id}")] = ca_objects::$s_current_location_type_configuration_cache[$vs_cache_key] = $va_map[$vs_table_name]['*'];
         }
         // return default config if no type is specified
         if ($pm_current_loc_subclass) {
             switch ($vs_table_name) {
                 case 'ca_storage_locations':
                     $va_types = ca_relationship_types::relationshipTypeIDsToTypeCodes(array($pm_current_loc_subclass));
                     $vs_type = array_shift($va_types);
                     break;
                 default:
                     $vs_type = $t_instance->getTypeCode($pm_current_loc_subclass);
                     break;
             }
             $va_facet_display_config = caGetOption('facet', $pa_options, null);
             if ($vs_type && isset($va_map[$vs_table_name][$vs_type])) {
                 if (is_array($va_facet_display_config) && isset($va_facet_display_config[$vs_table_name][$vs_type])) {
                     $va_map[$vs_table_name][$vs_type] = array_merge($va_map[$vs_table_name][$vs_type], $va_facet_display_config[$vs_table_name][$vs_type]);
                 }
                 return ca_objects::$s_current_location_type_configuration_cache[caMakeCacheKeyFromOptions($pa_options, "{$vs_table_name}/{$pm_current_loc_subclass}")] = ca_objects::$s_current_location_type_configuration_cache[$vs_cache_key] = $va_map[$vs_table_name][$vs_type];
             } elseif (isset($va_map[$vs_table_name]['*'])) {
                 if (is_array($va_facet_display_config) && isset($va_facet_display_config[$vs_table_name]['*'])) {
                     $va_map[$vs_table_name][$vs_type] = array_merge($va_map[$vs_table_name]['*'], $va_facet_display_config[$vs_table_name]['*']);
                 }
                 return ca_objects::$s_current_location_type_configuration_cache[caMakeCacheKeyFromOptions($pa_options, "{$vs_table_name}/{$pm_current_loc_subclass}")] = ca_objects::$s_current_location_type_configuration_cache[$vs_cache_key] = $va_map[$vs_table_name]['*'];
             }
         }
     }
     return ca_objects::$s_current_location_type_configuration_cache[caMakeCacheKeyFromOptions($pa_options, "{$vs_table_name}/{$pm_current_loc_subclass}")] = ca_objects::$s_current_location_type_configuration_cache[$vs_cache_key] = null;
 }
Example #10
0
 /**
  * Returns items contained in list, including their labels. This method will returned the list items sorted according to the default_sort field setting of
  * the list they belong to. Note that correct order when sorting by label is only guaranteed if 'extractValuesByUserLocale' is set to true [default is false]. 
  * This is due to the list return format: since each item is indexed by item_id first, it can only have a single position in the return structure. If multiple labels are returned
  * for an item then the item will only be in the correct sort order for one of the labels in most cases. To ensure proper sort order by label text, labels must be restricted to a 
  * single locale.
  * 
  * @param $pm_list_name_or_id mixed - list_code or list_id of desired list
  * @param $pa_options array - optional array of options. Supported options include:
  *			returnHierarchyLevels =		if true list is returned with 'LEVEL' field set to hierarchical level of item, and items are returned in order such that if you loop through the returned list and indent each item according to its level you get a nicely formatted hierarchical display. Default is false.
  * 			extractValuesByUserLocale = if true then values are processed to be appropriate for current user locale; default is false:  return values for all locales
  *			directChildrenOnly =	 	if true, only children immediately below the specified item are returned; [default is false]
  * 			includeSelf =	if true, the specified item is included in the returned set of items; [default is false]
  *			type_id = 		optional list item type to limit returned items by; default is to not limit by type (eg. type_id = null)
  *			item_id =		optional item_id to use as root of hierarchy for returned items; if this is not set (the default) then all items in the list are returned
  *			sort =			if set to a __CA_LISTS_SORT_BY_*__ constant, will force the list to be sorted by that criteria overriding the sort order set in the ca_lists.default_sort field
  *			idsOnly = 		if true, only the primary key id values of the list items are returned
  *			enabledOnly =	return only enabled list items [default=false]
  *			labelsOnly = 	if true only labels in the current locale are returns in an array key'ed on item_id
  *
  * @return array List of items indexed first on item_id and then on locale_id of label
  */
 public function getItemsForList($pm_list_name_or_id, $pa_options = null)
 {
     $vn_list_id = $this->_getListID($pm_list_name_or_id);
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     if (!isset($pa_options['returnHierarchyLevels'])) {
         $pa_options['returnHierarchyLevels'] = false;
     }
     if (isset($pa_options['directChildrenOnly']) && $pa_options['directChildrenOnly']) {
         $pa_options['returnHierarchyLevels'] = false;
     }
     $vb_enabled_only = caGetOption('enabledOnly', $pa_options, false);
     $vb_labels_only = false;
     if (isset($pa_options['labelsOnly']) && $pa_options['labelsOnly']) {
         $pa_options['extractValuesByUserLocale'] = true;
         $pa_options['returnHierarchyLevels'] = false;
         $vb_labels_only = true;
     }
     $vs_cache_key = caMakeCacheKeyFromOptions(array_merge($pa_options, array('list_id' => $vn_list_id)));
     if (is_array(ca_lists::$s_list_item_cache[$vs_cache_key])) {
         return ca_lists::$s_list_item_cache[$vs_cache_key];
     }
     $t_list = new ca_lists($vn_list_id);
     $pn_type_id = isset($pa_options['type_id']) ? (int) $pa_options['type_id'] : null;
     $pn_sort = isset($pa_options['sort']) ? (int) $pa_options['sort'] : $t_list->get('default_sort');
     if (!($pn_item_id = isset($pa_options['item_id']) ? (int) $pa_options['item_id'] : null)) {
         $pn_item_id = $t_list->getRootListItemID($vn_list_id);
     }
     $t_list_item = new ca_list_items($pn_item_id);
     if (!$t_list_item->getPrimaryKey() || $t_list_item->get('list_id') != $vn_list_id) {
         return null;
     }
     $vs_hier_sql = '';
     if ($t_list_item->getPrimaryKey()) {
         $vs_hier_sql = " AND ((cli.hier_left >= " . floatval($t_list_item->get('hier_left')) . ") AND (cli.hier_right <= " . floatval($t_list_item->get('hier_right')) . "))";
     }
     if (!isset($pa_options['returnHierarchyLevels']) || !$pa_options['returnHierarchyLevels']) {
         $vs_type_sql = '';
         if ($pn_type_id) {
             $vs_type_sql = ' AND (cli.type_id = ' . intval($pn_type_id) . ')';
         }
         $vs_order_by = '';
         switch ($pn_sort) {
             case __CA_LISTS_SORT_BY_LABEL__:
                 // by label
                 $vs_order_by = 'clil.name_plural';
                 break;
             case __CA_LISTS_SORT_BY_RANK__:
                 // by rank
                 $vs_order_by = 'cli.rank';
                 break;
             case __CA_LISTS_SORT_BY_VALUE__:
                 // by value
                 $vs_order_by = 'cli.item_value';
                 break;
             case __CA_LISTS_SORT_BY_IDENTIFIER__:
                 // by identifier
                 $vs_order_by = 'cli.idno_sort';
                 break;
         }
         if ($vs_order_by) {
             $vs_order_by = "ORDER BY {$vs_order_by}";
         }
         $vs_enabled_sql = '';
         if ($vb_enabled_only) {
             $vs_enabled_sql = ' AND (cli.is_enabled = 1)';
         }
         $vs_direct_children_sql = '';
         if (isset($pa_options['directChildrenOnly']) && $pa_options['directChildrenOnly']) {
             $vs_direct_children_sql = " AND cli.parent_id = " . (int) $pn_item_id;
         }
         $o_db = $this->getDb();
         $vs_sql = "\n\t\t\t\tSELECT clil.*, cli.*\n\t\t\t\tFROM ca_list_items cli\n\t\t\t\tINNER JOIN ca_list_item_labels AS clil ON clil.item_id = cli.item_id\n\t\t\t\tWHERE\n\t\t\t\t\t(cli.deleted = 0) AND (clil.is_preferred = 1) AND (cli.list_id = ?) {$vs_type_sql} {$vs_direct_children_sql} {$vs_hier_sql} {$vs_enabled_sql}\n\t\t\t\t{$vs_order_by}\n\t\t\t";
         //print $vs_sql;
         $qr_res = $o_db->query($vs_sql, (int) $vn_list_id);
         $va_seen_locales = array();
         $va_items = array();
         while ($qr_res->nextRow()) {
             $vn_item_id = $qr_res->get('item_id');
             if (isset($pa_options['idsOnly']) && $pa_options['idsOnly']) {
                 $va_items[] = $vn_item_id;
                 continue;
             }
             if ((!isset($pa_options['includeSelf']) || !$pa_options['includeSelf']) && $vn_item_id == $pn_item_id) {
                 continue;
             }
             if (isset($pa_options['directChildrenOnly']) && $pa_options['directChildrenOnly'] && $qr_res->get('parent_id') != $pn_item_id) {
                 continue;
             }
             $va_items[$vn_item_id][$vn_locale_id = $qr_res->get('locale_id')] = $qr_res->getRow();
             $va_seen_locales[$vn_locale_id] = true;
         }
         if (isset($pa_options['idsOnly']) && $pa_options['idsOnly']) {
             return $va_items;
         }
         if (isset($pa_options['extractValuesByUserLocale']) && $pa_options['extractValuesByUserLocale']) {
             $va_items = caExtractValuesByUserLocale($va_items);
             if ($pn_sort == 0 && sizeof($va_seen_locales) > 1) {
                 // do we need to resort list based upon labels? (will already be in correct order if there's only one locale)
                 $va_labels = array();
                 foreach ($va_items as $vn_item_id => $va_row) {
                     $va_labels[$va_row['name_plural'] . $vn_item_id] = $va_row;
                 }
                 ksort($va_labels);
                 $va_items = array();
                 foreach ($va_labels as $vs_key => $va_row) {
                     $va_items[$va_row['item_id']] = $va_row;
                 }
             }
         }
         if ($vb_labels_only) {
             $va_labels = array();
             foreach ($va_items as $vn_item_id => $va_row) {
                 $va_labels[$vn_item_id] = $va_row['name_plural'];
             }
             return $va_labels;
         }
     } else {
         // hierarchical output
         $va_list_items = $t_list_item->getHierarchyAsList($pn_item_id, array('additionalTableToJoin' => 'ca_list_item_labels', 'additionalTableSelectFields' => array('name_singular', 'name_plural', 'locale_id'), 'additionalTableWheres' => array('ca_list_item_labels.is_preferred = 1')));
         foreach ($va_list_items as $vn_i => $va_item) {
             if ($pn_type_id && $va_item['NODE']['type_id'] != $pn_type_id) {
                 continue;
             }
             if ($vb_enabled_only && !$va_item['NODE']['is_enabled']) {
                 continue;
             }
             $vn_item_id = $va_item['NODE']['item_id'];
             $vn_parent_id = $va_item['NODE']['parent_id'];
             if ((!isset($pa_options['includeSelf']) || !$pa_options['includeSelf']) && $vn_item_id == $pn_item_id) {
                 continue;
             }
             if (isset($pa_options['directChildrenOnly']) && $pa_options['directChildrenOnly'] && $vn_parent_id != $pn_item_id) {
                 continue;
             }
             switch ($pn_sort) {
                 case __CA_LISTS_SORT_BY_LABEL__:
                     // label
                 // label
                 default:
                     $vs_key = $va_item['NODE']['name_singular'];
                     break;
                 case __CA_LISTS_SORT_BY_RANK__:
                     // rank
                     $vs_key = sprintf("%08d", (int) $va_item['NODE']['rank']);
                     break;
                 case __CA_LISTS_SORT_BY_VALUE__:
                     // value
                     $vs_key = $va_item['NODE']['item_value'];
                     break;
                 case __CA_LISTS_SORT_BY_IDENTIFIER__:
                     // identifier
                     $vs_key = $va_item['NODE']['idno_sort'];
                     break;
             }
             if (isset($pa_options['extractValuesByUserLocale']) && $pa_options['extractValuesByUserLocale']) {
                 $va_items[$vn_parent_id][$vn_item_id][$va_item['NODE']['locale_id']][$vs_key][$vn_item_id] = array_merge($va_item['NODE'], array('LEVEL' => $va_item['LEVEL']));
             } else {
                 $va_items[$vn_parent_id][$va_item['NODE']['locale_id']][$vs_key][$vn_item_id] = array_merge($va_item['NODE'], array('LEVEL' => $va_item['LEVEL']));
             }
         }
         $pa_sorted_items = array();
         if (is_array($va_items) && (isset($pa_options['extractValuesByUserLocale']) && $pa_options['extractValuesByUserLocale'])) {
             //$va_items = caExtractValuesByUserLocale($va_items);
             $va_proc_items = array();
             foreach ($va_items as $vn_parent_id => $va_item) {
                 $va_item = caExtractValuesByUserLocale($va_item);
                 foreach ($va_item as $vn_item_id => $va_items_by_key) {
                     foreach ($va_items_by_key as $vs_key => $va_val) {
                         foreach ($va_val as $vn_item_id => $va_item_info) {
                             $va_proc_items[$vn_parent_id][$vs_key][$vn_item_id] = $va_item_info;
                         }
                     }
                 }
             }
             $this->_getItemsForListProcListLevel($pn_item_id, $va_proc_items, $pa_sorted_items, $pa_options);
         } else {
             $this->_getItemsForListProcListLevel($pn_item_id, $va_items, $pa_sorted_items, $pa_options);
         }
         $va_items = $pa_sorted_items;
     }
     ca_lists::$s_list_item_cache[$vs_cache_key] = $va_items;
     return $va_items;
 }
Example #11
0
 /**
  * Implementation of primary get() functionality
  */
 private function _get($ps_field, $pa_options = null)
 {
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     if (isset($pa_options['restrictToType']) && (!isset($pa_options['restrict_to_type']) || !$pa_options['restrict_to_type'])) {
         $pa_options['restrict_to_type'] = $pa_options['restrictToType'];
     }
     if (isset($pa_options['restrictToTypes']) && (!isset($pa_options['restrict_to_types']) || !$pa_options['restrict_to_types'])) {
         $pa_options['restrict_to_types'] = $pa_options['restrictToTypes'];
     }
     if (isset($pa_options['restrictToRelationshipTypes']) && (!isset($pa_options['restrict_to_relationship_types']) || !$pa_options['restrict_to_relationship_types'])) {
         $pa_options['restrict_to_relationship_types'] = $pa_options['restrictToRelationshipTypes'];
     }
     if (isset($pa_options['excludeType']) && (!isset($pa_options['exclude_type']) || !$pa_options['exclude_type'])) {
         $pa_options['exclude_type'] = $pa_options['excludeType'];
     }
     if (isset($pa_options['excludeTypes']) && (!isset($pa_options['exclude_types']) || !$pa_options['exclude_types'])) {
         $pa_options['exclude_types'] = $pa_options['excludeTypes'];
     }
     if (isset($pa_options['excludeRelationshipTypes']) && (!isset($pa_options['exclude_relationship_types']) || !$pa_options['exclude_relationship_types'])) {
         $pa_options['exclude_relationship_types'] = $pa_options['excludeRelationshipTypes'];
     }
     $vb_return_as_array = caGetOption('returnAsArray', $pa_options, false, array('castTo' => 'bool'));
     $vb_return_all_locales = caGetOption('returnAllLocales', $pa_options, false, array('castTo' => 'bool'));
     $vb_return_as_link = caGetOption('returnAsLink', $pa_options, false, array('castTo' => 'bool'));
     $vs_return_as_link_text = caGetOption('returnAsLinkText', $pa_options, '');
     $vs_return_as_link_target = caGetOption('returnAsLinkTarget', $pa_options, '');
     $vs_return_as_link_attributes = caGetOption('returnAsLinkAttributes', $pa_options, array(), array('castTo' => 'array'));
     $va_original_path_components = $va_path_components = $this->getFieldPathComponents($ps_field);
     if ($va_path_components['table_name'] != $this->ops_table_name) {
         $vs_access_chk_key = $va_path_components['table_name'] . ($va_path_components['field_name'] ? '.' . $va_path_components['field_name'] : '');
     } else {
         $vs_access_chk_key = $va_path_components['field_name'];
     }
     if (caGetBundleAccessLevel($this->ops_table_name, $vs_access_chk_key) == __CA_BUNDLE_ACCESS_NONE__) {
         return null;
     }
     $vo_request = caGetOption('request', $pa_options, null);
     unset($pa_options['request']);
     // first see if the search engine can provide the field value directly (fastest)
     if (!(($vs_value = $this->opo_engine_result->get($ps_field, $pa_options)) === false)) {
         if ($vb_return_as_array) {
             if ($vb_return_all_locales) {
                 return array(1 => $vs_value);
             } else {
                 return array($vs_value);
             }
         } else {
             return $vs_value;
         }
     }
     $vs_template = caGetOption('template', $pa_options, null);
     $vs_delimiter = caGetOption('delimiter', $pa_options, ' ');
     $vs_hierarchical_delimiter = caGetOption('hierarchicalDelimiter', $pa_options, ' ');
     if ($vb_return_all_locales && !$vb_return_as_array) {
         $vb_return_as_array = true;
     }
     if (isset($pa_options['sort']) && !is_array($pa_options['sort'])) {
         $pa_options['sort'] = array($pa_options['sort']);
     }
     if (is_array($va_sort_fields = isset($pa_options['sort']) && is_array($pa_options['sort']) ? $pa_options['sort'] : null)) {
         foreach ($va_sort_fields as $vn_i => $vs_sort_fld) {
             if (!trim($vs_sort_fld)) {
                 unset($va_sort_fields[$vn_i]);
             }
         }
     }
     $vn_row_id = $this->opo_engine_result->get($this->ops_table_pk);
     // try to lazy load (slower)...
     //
     // Are we getting timestamp (created on or last modified) info?
     //
     if ($va_path_components['table_name'] == $this->ops_table_name && $va_path_components['field_name'] == 'created') {
         if (!isset($this->opa_timestamp_cache['created_on'][$this->ops_table_name][$vn_row_id])) {
             $this->prefetchChangeLogData($this->ops_table_name, $this->opo_engine_result->currentRow(), $this->getOption('prefetch'));
         }
         if ($vb_return_as_array) {
             return $this->opa_timestamp_cache['created_on'][$this->ops_table_name][$vn_row_id];
         } else {
             $vs_subfield = $va_path_components['subfield_name'] ? $va_path_components['subfield_name'] : 'timestamp';
             $vm_val = $this->opa_timestamp_cache['created_on'][$this->ops_table_name][$vn_row_id][$vs_subfield];
             if ($vs_subfield == 'timestamp') {
                 $o_tep = new TimeExpressionParser();
                 $o_tep->setUnixTimestamps($vm_val, $vm_val);
                 $vm_val = $o_tep->getText($pa_options);
             }
             return $vm_val;
         }
     }
     if ($va_path_components['table_name'] == $this->ops_table_name && $va_path_components['field_name'] == 'lastModified') {
         if (!isset($this->opa_timestamp_cache['last_changed'][$this->ops_table_name][$vn_row_id])) {
             $this->prefetchChangeLogData($this->ops_table_name, $this->opo_engine_result->currentRow(), $this->getOption('prefetch'));
         }
         if ($vb_return_as_array) {
             return $this->opa_timestamp_cache['last_changed'][$this->ops_table_name][$vn_row_id];
         } else {
             $vs_subfield = $va_path_components['subfield_name'] ? $va_path_components['subfield_name'] : 'timestamp';
             $vm_val = $this->opa_timestamp_cache['last_changed'][$this->ops_table_name][$vn_row_id][$vs_subfield];
             if ($vs_subfield == 'timestamp') {
                 $o_tep = new TimeExpressionParser();
                 $o_tep->setUnixTimestamps($vm_val, $vm_val);
                 $vm_val = $o_tep->getText($pa_options);
             }
             return $vm_val;
         }
     }
     if (!($t_instance = $this->opo_datamodel->getInstanceByTableName($va_path_components['table_name'], true))) {
         return null;
     }
     // Bad table
     $t_original_instance = $t_instance;
     // $t_original_instance will always be the as-called subject; optimizations may results in $t_instance being transformed into a different model
     //
     // Simple related table get:
     //			<table>
     //			<table>.related
     //			<table>.hierarchy
     //			<table>.related.hierarchy
     //
     if ($va_path_components['num_components'] == 1 && $va_path_components['table_name'] !== $this->ops_table_name || $va_path_components['num_components'] == 2 && $va_path_components['field_name'] == 'related' || $va_path_components['num_components'] == 2 && $va_path_components['field_name'] == 'hierarchy' || $va_path_components['num_components'] == 3 && $va_path_components['field_name'] == 'related' && $va_path_components['subfield_name'] == 'hierarchy') {
         if (!($t_table = $this->opo_datamodel->getInstanceByTableName($this->ops_table_name, true))) {
             return null;
         }
         $vb_show_hierarachy = (bool) ($va_path_components['field_name'] == 'hierarchy' && $t_instance->isHierarchical());
         if ($va_path_components['num_components'] == 2) {
             $va_path_components['num_components'] = 1;
             $va_path_components['field_name'] = null;
         }
         $vs_opt_md5 = caMakeCacheKeyFromOptions($pa_options);
         if (!isset($this->opa_rel_prefetch_cache[$va_path_components['table_name']][$vn_row_id][$vs_opt_md5])) {
             $this->prefetchRelated($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
         }
         $va_related_items = $this->opa_rel_prefetch_cache[$va_path_components['table_name']][$vn_row_id][$vs_opt_md5];
         if (!is_array($va_related_items)) {
             return null;
         }
         if (is_array($va_sort_fields) && sizeof($va_sort_fields)) {
             $va_related_items = caSortArrayByKeyInValue($va_related_items, $va_sort_fields);
         }
         // Return as array
         if ($vs_template) {
             return caProcessTemplateForIDs($vs_template, $this->opo_subject_instance->tableName(), array($vn_row_id), array_merge($pa_options, array('placeholderPrefix' => $va_path_components['field_name'])));
         }
         if ($vb_return_as_array || $vb_return_all_locales) {
             if ($vb_return_all_locales) {
                 $va_related_tmp = array();
                 foreach ($va_related_items as $vn_i => $va_related_item) {
                     $va_related_tmp[$vn_i][$va_related_item['locale_id']] = $va_related_item;
                 }
                 return $va_related_tmp;
             } else {
                 if (!$vs_template && !$va_path_components['field_name']) {
                     return $va_related_items;
                 }
                 $vs_pk = $t_instance->primaryKey();
                 $va_links = array();
                 foreach ($va_related_items as $vn_relation_id => $va_relation_info) {
                     $va_relation_info['labels'] = caExtractValuesByUserLocale(array(0 => $va_relation_info['labels']));
                     if ($vb_return_as_link) {
                         $va_template_opts = array();
                         $va_template_opts['relationshipValues'][$va_relation_info[$vs_pk]][$va_relation_info['relation_id']]['relationship_typename'] = $va_relation_info['relationship_typename'];
                         $vs_text = $vs_template ? caProcessTemplateForIDs($vs_template, $t_instance->tableName(), array($va_relation_info[$vs_pk]), $va_template_opts) : join("; ", $va_relation_info['labels']);
                         $va_link = caCreateLinksFromText(array($vs_text), $va_original_path_components['table_name'], array($va_relation_info[$vs_pk]), $vs_return_as_link_class, $vs_return_as_link_target);
                         $va_links[$vn_relation_id] = array_pop($va_link);
                     } else {
                         $va_related_items[$vn_relation_id]['labels'] = $va_relation_info['labels'];
                     }
                 }
                 if ($vb_return_as_link) {
                     return $va_links;
                 }
                 return $va_related_items;
             }
         } else {
             // Return scalar
             $va_proc_labels = array();
             $va_row_ids = array();
             $vs_rel_pk = $t_instance->primaryKey();
             $va_relationship_values = array();
             foreach ($va_related_items as $vn_relation_id => $va_relation_info) {
                 $va_row_ids[] = $va_relation_info[$vs_rel_pk];
                 $va_relationship_values[$va_relation_info[$vs_rel_pk]][$vn_relation_id] = array('relationship_typename' => $va_relation_info['relationship_typename'], 'relationship_type_id' => $va_relation_info['relationship_type_id'], 'relationship_type_code' => $va_relation_info['relationship_type_code'], 'relationship_typecode' => $va_relation_info['relationship_type_code'], 'label' => $va_relation_info['label']);
             }
             if (!sizeof($va_row_ids)) {
                 return '';
             }
             if (!$vs_template) {
                 $vs_template = "^label";
             }
             $va_template_opts = $pa_options;
             unset($va_template_opts['request']);
             unset($va_template_opts['template']);
             $va_template_opts['returnAsLink'] = false;
             $va_template_opts['returnAsArray'] = true;
             $va_text = caProcessTemplateForIDs($vs_template, $t_instance->tableNum(), $va_row_ids, array_merge($va_template_opts, array('relationshipValues' => $va_relationship_values, 'showHierarchicalLabels' => $vb_show_hierarachy)));
             if ($vb_return_as_link) {
                 $va_links = caCreateLinksFromText($va_text, $va_original_path_components['table_name'], $va_row_ids, $vs_return_as_link_class, $vs_return_as_link_target);
                 return join($vs_delimiter, $va_links);
             }
             return join($vs_delimiter, $va_text);
         }
     }
     $vb_need_parent = false;
     $vb_need_children = false;
     //
     // Transform "preferred_labels" into tables for pre-fetching
     //
     $vb_is_get_for_labels = $vb_return_all_label_values = $vb_get_preferred_labels_only = $vb_get_nonpreferred_labels_only = false;
     if (in_array($va_path_components['field_name'], array('preferred_labels', 'nonpreferred_labels'))) {
         if ($t_instance->getProperty('LABEL_TABLE_NAME')) {
             $vb_get_preferred_labels_only = $va_path_components['field_name'] == 'preferred_labels' ? true : false;
             $vb_get_nonpreferred_labels_only = $va_path_components['field_name'] == 'nonpreferred_labels' ? true : false;
             if ($va_path_components['num_components'] == 2) {
                 // if it's just <table_name>.preferred_labels then return an array of fields from the label table
                 $vb_return_all_label_values = true;
             }
             $va_path_components['table_name'] = $t_instance->getLabelTableName();
             $t_label_instance = $t_instance->getLabelTableInstance();
             if (!$va_path_components['subfield_name'] || !$t_label_instance->hasField($va_path_components['subfield_name'])) {
                 $va_path_components['field_name'] = $t_instance->getLabelDisplayField();
             } else {
                 $va_path_components['field_name'] = $va_path_components['subfield_name'];
             }
             $va_path_components['subfield_name'] = null;
             $va_path_components = $this->getFieldPathComponents($va_path_components['table_name'] . '.' . $va_path_components['field_name']);
             // Ok, convert the table instance to the label table since that's the table we'll be grabbing data from
             $t_instance = $t_label_instance;
             $vb_is_get_for_labels = true;
         }
     }
     //
     // Handle modifiers (parent, children, related, hierarchy) with and without fields
     //
     if ($va_path_components['num_components'] >= 2) {
         switch ($va_path_components['field_name']) {
             case 'parent':
                 if ($t_instance->isHierarchical() && ($vn_parent_id = $this->get($va_path_components['table_name'] . '.' . $t_instance->getProperty('HIERARCHY_PARENT_ID_FLD')))) {
                     //
                     // TODO: support some kind of prefetching of parents?
                     //
                     unset($va_path_components['components'][1]);
                     if ($t_instance->load($vn_parent_id)) {
                         return $t_instance->get(join('.', array_values($va_path_components['components'])), $pa_options);
                     }
                     return null;
                 }
                 break;
             case 'children':
                 if ($t_instance->isHierarchical()) {
                     //unset($va_path_components['components'][1]);	// remove 'children' from field path
                     $vs_field_spec = join('.', array_values($va_path_components['components']));
                     if ($vn_id = $this->get($va_path_components['table_name'] . '.' . $t_instance->primaryKey(), array('returnAsArray' => false))) {
                         if ($t_instance->load($vn_id)) {
                             return $t_instance->get($vs_field_spec, $pa_options);
                         }
                     }
                     return null;
                 }
                 break;
             case 'related':
                 // Regular related table call
                 if ($va_path_components['table_name'] != $this->ops_table_name) {
                     // just remove "related" from name and be on our way
                     $va_tmp = $va_path_components['components'];
                     array_splice($va_tmp, 1, 1);
                     return $this->get(join('.', $va_tmp), $pa_options);
                 }
                 // Self-relations need special handling
                 $vs_opt_md5 = caMakeCacheKeyFromOptions($pa_options);
                 if (!isset($this->opa_rel_prefetch_cache[$va_path_components['table_name']][$vn_row_id][$vs_opt_md5])) {
                     $this->prefetchRelated($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
                 }
                 $va_related_items = $this->opa_rel_prefetch_cache[$va_path_components['table_name']][$vn_row_id][$vs_opt_md5];
                 if (!($t_table = $this->opo_datamodel->getInstanceByTableName($va_path_components['table_name'], true))) {
                     return null;
                 }
                 $va_ids = array();
                 foreach ($va_related_items as $vn_relation_id => $va_item) {
                     $va_ids[] = $va_item[$t_table->primaryKey()];
                 }
                 $va_vals = array();
                 if ($qr_res = $t_table->makeSearchResult($va_path_components['table_name'], $va_ids)) {
                     $va_tmp = $va_path_components['components'];
                     unset($va_tmp[1]);
                     $vs_rel_field = join('.', $va_tmp);
                     while ($qr_res->nextHit()) {
                         if ($vb_return_as_array) {
                             $va_vals = array_merge($va_vals, $qr_res->get($vs_rel_field, $pa_options));
                         } else {
                             $va_vals[] = $qr_res->get($vs_rel_field, $pa_options);
                         }
                     }
                 }
                 //if (is_array($va_sort_fields) && sizeof($va_sort_fields)) {
                 //	$va_vals = caSortArrayByKeyInValue($va_vals, $va_sort_fields);
                 //}
                 if ($vb_return_as_link) {
                     if (!$vb_return_all_locales) {
                         $va_vals = caCreateLinksFromText($va_vals, $va_original_path_components['table_name'], $va_ids, $vs_return_as_link_class, $vs_return_as_link_target);
                     }
                 }
                 if ($vb_return_as_array) {
                     return $va_vals;
                 } else {
                     return join($vs_delimiter, $va_vals);
                 }
                 break;
             case 'hierarchy':
                 $vn_max_levels_from_bottom = caGetOption('maxLevelsFromBottom', $pa_options, caGetOption('maxLevels', $pa_options, null));
                 $vn_max_levels_from_top = caGetOption('maxLevelsFromTop', $pa_options, null);
                 if ($t_instance->isHierarchical()) {
                     $vs_field_spec = join('.', array_values($va_path_components['components']));
                     $vs_hier_pk_fld = $t_instance->primaryKey();
                     if ($va_ids = $this->get($va_path_components['table_name'] . '.' . $vs_hier_pk_fld, array_merge($pa_options, array('returnAsArray' => true, 'returnAsLink' => false, 'returnAllLocales' => false)))) {
                         $va_vals = array();
                         if ($va_path_components['subfield_name'] == $vs_hier_pk_fld) {
                             foreach ($va_ids as $vn_id) {
                                 // TODO: This is too slow
                                 if ($t_instance->load($vn_id)) {
                                     $va_vals = array_merge($va_vals, $t_instance->get($va_path_components['table_name'] . ".hierarchy." . $vs_hier_pk_fld, array_merge($pa_options, array('returnAsArray' => true))));
                                 }
                             }
                         } else {
                             foreach ($va_ids as $vn_id) {
                                 // TODO: This is too slow
                                 if ($t_instance->load($vn_id)) {
                                     $va_vals = $t_instance->get($vs_field_spec, array_merge($pa_options, array('returnAsArray' => true)));
                                     if (is_array($va_vals)) {
                                         $va_vals = array_reverse($va_vals);
                                     }
                                     // Add/replace hierarchy name
                                     if ($t_instance->getProperty('HIERARCHY_TYPE') == __CA_HIER_TYPE_MULTI_MONO__ && $t_instance->getHierarchyName()) {
                                         $vn_first_key = array_shift(array_keys($va_vals));
                                         if ($vb_return_all_locales) {
                                             $va_vals[$vn_first_key] = array(0 => array($t_instance->getHierarchyName()));
                                         } else {
                                             $va_vals[$vn_first_key] = $t_instance->getHierarchyName();
                                         }
                                     }
                                     if ($vn_max_levels_from_bottom > 0) {
                                         if (($vn_start = sizeof($va_vals) - $vn_max_levels_from_bottom) < 0) {
                                             $vn_start = 0;
                                         }
                                         $va_vals = array_slice($va_vals, $vn_start, $vn_max_levels_from_bottom, true);
                                     } elseif ($vn_max_levels_from_top > 0) {
                                         $va_vals = array_slice($va_vals, 0, $vn_max_levels_from_top, true);
                                     }
                                 }
                             }
                         }
                         if ($vb_return_as_array) {
                             return $va_vals;
                         } else {
                             return join($vs_hierarchical_delimiter, $va_vals);
                         }
                     }
                     return null;
                 }
                 break;
         }
     }
     // If the requested table was not added to the query via SearchEngine::addTable()
     // then auto-add it here. It's better to explicitly add it with addTables() as that call
     // gives you precise control over which fields are autoloaded and also lets you specify limiting criteria
     // for selection of related field data; and it also lets you explicitly define the tables used to join the
     // related table. Autoloading guesses and usually does what you want, but not always.
     if (!isset($this->opa_tables[$va_path_components['table_name']]) || !$this->opa_tables[$va_path_components['table_name']]) {
         $va_join_tables = $this->opo_datamodel->getPath($this->ops_table_name, $va_path_components['table_name']);
         array_shift($va_join_tables);
         // remove subject table
         array_pop($va_join_tables);
         // remove content table (we only need linking tables here)
         $va_join_criteria = array();
         if (is_array($va_primary_ids)) {
             foreach ($va_primary_ids as $vs_t => $va_t_ids) {
                 if (isset($va_join_tables[$vs_t]) && sizeof($va_t_ids) > 0) {
                     $vs_t_pk = $this->opo_datamodel->getTablePrimaryKeyName($vs_t);
                     $va_join_criteria[] = "{$vs_t}.{$vs_t_pk} NOT IN (" . join(",", $va_t_ids) . ")";
                 }
             }
         }
         $this->opa_tables[$va_path_components['table_name']] = array('fieldList' => array($va_path_components['table_name'] . '.*'), 'joinTables' => array_keys($va_join_tables), 'criteria' => $va_join_criteria);
     }
     if ($va_path_components['table_name'] === $this->ops_table_name && !$t_instance->hasField($va_path_components['field_name']) && method_exists($t_instance, 'getAttributes')) {
         //
         // Return attribute values for primary table
         //
         if ($va_path_components['field_name'] && ($t_element = $t_instance->_getElementInstance($va_path_components['field_name']))) {
             $vn_element_id = $t_element->getPrimaryKey();
         } else {
             $vn_element_id = null;
         }
         if (!isset(ca_attributes::$s_get_attributes_cache[$this->opn_table_num . '/' . $vn_row_id][$vn_element_id])) {
             ca_attributes::prefetchAttributes($this->opo_db, $this->opn_table_num, $this->getRowIDsToPrefetch($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch')), $vn_element_id ? array($vn_element_id) : null, array('dontFetchAlreadyCachedValues' => true));
         }
         if (!$vb_return_as_array && !$vb_return_all_locales) {
             // return scalar
             //
             // Handle "hierarchy" modifier on list elements
             //
             if ($va_hier = $this->_getElementHierarchy($t_instance, $va_path_components)) {
                 return join($vs_hierarchical_delimiter, $va_hier);
             }
             if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && $va_path_components['field_name']) {
                 $vs_template = null;
                 if ($va_path_components['subfield_name']) {
                     $va_values = $t_instance->getAttributeDisplayValues($va_path_components['field_name'], $vn_row_id, $pa_options);
                     $va_value_list = array();
                     foreach ($va_values as $vn_id => $va_attr_val_list) {
                         foreach ($va_attr_val_list as $vn_value_id => $va_value_array) {
                             $va_value_list[] = $va_value_array[$va_path_components['subfield_name']];
                         }
                     }
                     return join(" ", $va_value_list);
                 } else {
                     if (isset($pa_options['template'])) {
                         $vs_template = $pa_options['template'];
                     }
                 }
                 unset($pa_options['template']);
                 if (!$vs_template) {
                     $vs_template = "^" . $va_path_components['subfield_name'] ? $va_path_components['subfield_name'] : $va_path_components['field_name'];
                 }
                 return $t_instance->getAttributesForDisplay($va_path_components['field_name'], $vs_template, array_merge(array('row_id' => $vn_row_id), $pa_options));
             }
             if ($t_element && !$va_path_components['subfield_name'] && $t_element->get('datatype') == 0) {
                 return $t_instance->getAttributesForDisplay($va_path_components['field_name'], $vs_template, array_merge($pa_options, array('row_id' => $vn_row_id)));
             } else {
                 if (!$vs_template) {
                     return $t_instance->getRawValue($vn_row_id, $va_path_components['field_name'], $va_path_components['subfield_name'], ',', $pa_options);
                 } else {
                     return caProcessTemplateForIDs($vs_template, $va_path_components['table_name'], array($vn_row_id), array());
                 }
             }
         } else {
             // return array
             //
             // Handle "hierarchy" modifier on list elements
             //
             if ($va_hier = $this->_getElementHierarchy($t_instance, $va_path_components)) {
                 return $va_hier;
             }
             $va_values = $t_instance->getAttributeDisplayValues($va_path_components['field_name'], $vn_row_id, $pa_options);
             if ($vs_template && !$vb_return_all_locales) {
                 $va_values_tmp = array();
                 foreach ($va_values as $vn_i => $va_value_list) {
                     foreach ($va_value_list as $vn_attr_id => $va_attr_data) {
                         $va_values_tmp[] = caProcessTemplateForIDs($vs_template, $va_path_components['table_name'], array($vn_row_id), array_merge($pa_options, array('placeholderPrefix' => $va_path_components['field_name'])));
                     }
                 }
                 $va_values = $va_values_tmp;
             } else {
                 if ($va_path_components['subfield_name']) {
                     if ($vb_return_all_locales) {
                         foreach ($va_values as $vn_row_id => $va_values_by_locale) {
                             foreach ($va_values_by_locale as $vn_locale_id => $va_value_list) {
                                 foreach ($va_value_list as $vn_attr_id => $va_attr_data) {
                                     $va_values[$vn_row_id][$vn_locale_id][$vn_attr_id] = $va_attr_data[$va_path_components['subfield_name']];
                                 }
                             }
                         }
                     } else {
                         $va_processed_value_list = array();
                         foreach ($va_values as $vn_row_id => $va_value_list) {
                             foreach ($va_value_list as $vn_attr_id => $va_attr_data) {
                                 $va_processed_value_list[$vn_attr_id] = $va_attr_data[$va_path_components['subfield_name']];
                             }
                         }
                         $va_values = $va_processed_value_list;
                     }
                 } else {
                     if (!$vb_return_all_locales) {
                         $va_values = array_shift($va_values);
                     }
                 }
             }
             return $va_values;
         }
     } else {
         // Prefetch intrinsic fields in primary and related tables
         if (!isset($this->opa_prefetch_cache[$va_path_components['table_name']][$vn_row_id])) {
             $this->prefetch($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
             // try to prefetch ahead (usually doesn't hurt and very often helps performance)
         }
     }
     $va_return_values = array();
     if ($va_path_components['table_name'] !== $this->ops_table_name && $va_path_components['field_name'] !== 'relationship_typename' && !$t_instance->hasField($va_path_components['field_name']) && method_exists($t_instance, 'getAttributes')) {
         //
         // Return metadata attributes in a related table
         //
         $vs_pk = $t_instance->primaryKey();
         $vb_is_related = $this->ops_table_name !== $va_path_components['table_name'];
         $va_ids = array();
         $vs_opt_md5 = caMakeCacheKeyFromOptions($pa_options);
         if (!isset($this->opa_rel_prefetch_cache[$va_path_components['table_name']][$vn_row_id][$vs_opt_md5])) {
             $this->prefetchRelated($va_path_components['table_name'], $this->opo_engine_result->currentRow(), $this->getOption('prefetch'), $pa_options);
         }
         if (is_array($this->opa_rel_prefetch_cache[$va_path_components['table_name']][$vn_row_id][$vs_opt_md5])) {
             foreach ($this->opa_rel_prefetch_cache[$va_path_components['table_name']][$vn_row_id][$vs_opt_md5] as $vn_i => $va_values) {
                 //$vn_locale_id => $va_values_by_locale) {
                 $va_ids[] = $va_values[$vs_pk];
                 if (!$vb_return_as_array) {
                     $vs_val = $t_instance->getAttributesForDisplay($va_path_components['field_name'], $vs_template, array_merge(array('row_id' => $va_values[$vs_pk]), $pa_options));
                 } else {
                     $vs_val = $t_instance->getAttributeDisplayValues($va_path_components['field_name'], $va_values[$vs_pk], $pa_options);
                 }
                 if ($vs_val) {
                     if ($vb_return_as_array) {
                         if (!$vb_return_all_locales) {
                             foreach ($vs_val as $vn_i => $va_values_list) {
                                 foreach ($va_values_list as $vn_j => $va_values) {
                                     $va_return_values[] = $va_values;
                                 }
                             }
                         } else {
                             foreach ($vs_val as $vn_i => $va_values_list) {
                                 $va_return_values[] = $va_values_list;
                             }
                         }
                     } else {
                         $va_return_values[] = $vs_val;
                     }
                 }
             }
         }
         if ($vb_return_as_array || $vb_return_all_locales) {
             // return array
             if ($vb_return_as_link && $vb_is_related) {
                 $vs_table_name = $t_instance->tableName();
                 $vs_fld_key = $va_path_components['subfield_name'] ? $va_path_components['subfield_name'] : $va_path_components['field_name'];
                 if (!$vb_return_all_locales) {
                     $va_return_values_tmp = array();
                     foreach ($va_return_values as $vn_i => $va_value) {
                         if ($vs_template) {
                             $vs_value = caProcessTemplateForIDs($vs_template, $va_path_components['table_name'], array($va_ids[$vn_i][$vs_pk]), array('returnAsArray' => false));
                         } else {
                             $vs_value = $va_value[$vs_fld_key];
                         }
                         if ($vb_return_as_link) {
                             $va_return_values_tmp[$vn_i] = array_pop(caCreateLinksFromText(array($vs_value), $va_original_path_components['table_name'], array($va_ids[$vn_i]), $vs_return_as_link_class, $vs_return_as_link_target));
                         } else {
                             $va_return_values_tmp[$vn_i] = $vs_value;
                         }
                     }
                     $va_return_values = $va_return_values_tmp;
                 }
             }
             return $va_return_values;
         } else {
             // return scalar
             if ($vb_return_as_link && $vb_is_related) {
                 $va_return_values = caCreateLinksFromText($va_return_values, $va_original_path_components['table_name'], $va_ids, $vs_return_as_link_class, $vs_return_as_link_target);
             }
             if (isset($pa_options['convertLineBreaks']) && $pa_options['convertLineBreaks']) {
                 return caConvertLineBreaks(join($vs_delimiter, $va_return_values));
             } else {
                 return join($vs_delimiter, $va_return_values);
             }
         }
     } else {
         if ($vs_template) {
             return caProcessTemplateForIDs($vs_template, $this->opo_subject_instance->tableName(), array($vn_row_id), array_merge($pa_options, array('placeholderPrefix' => $va_path_components['field_name'])));
         }
         //
         // Return fields (intrinsics, labels) in primary or related table
         //
         $t_list = $this->opo_datamodel->getInstanceByTableName('ca_lists', true);
         $va_value_list = array($vn_row_id => $this->opa_prefetch_cache[$va_path_components['table_name']][$vn_row_id]);
         // Restrict to relationship types (related)
         if (isset($pa_options['restrict_to_relationship_types']) && $pa_options['restrict_to_relationship_types']) {
             if (!is_array($pa_options['restrict_to_relationship_types'])) {
                 $pa_options['restrict_to_relationship_types'] = array($pa_options['restrict_to_relationship_types']);
             }
             if (sizeof($pa_options['restrict_to_relationship_types'])) {
                 $t_rel_type = $this->opo_datamodel->getInstanceByTableName('ca_relationship_types', true);
                 $va_rel_types = array();
                 $va_rel_path = array_keys($this->opo_datamodel->getPath($this->ops_table_name, $va_path_components['table_name']));
                 foreach ($pa_options['restrict_to_relationship_types'] as $vm_type) {
                     if (!$vm_type) {
                         continue;
                     }
                     if ($vn_type_id = $t_rel_type->getRelationshipTypeID($va_rel_path[1], $vm_type)) {
                         $va_rel_types[] = $vn_type_id;
                         if (is_array($va_children = $t_rel_type->getHierarchyChildren($vn_type_id, array('idsOnly' => true)))) {
                             $va_rel_types = array_merge($va_rel_types, $va_children);
                         }
                     }
                 }
                 if (sizeof($va_rel_types)) {
                     $va_tmp = array();
                     foreach ($va_value_list as $vn_id => $va_by_locale) {
                         foreach ($va_by_locale as $vn_locale_id => $va_values) {
                             foreach ($va_values as $vn_i => $va_value) {
                                 if (!$va_value['rel_type_id'] || in_array($va_value['rel_type_id'], $va_rel_types)) {
                                     $va_tmp[$vn_id][$vn_locale_id][$vn_i] = $va_value;
                                 }
                             }
                         }
                     }
                     $va_value_list = $va_tmp;
                 }
             }
         }
         // Exclude relationship types (related)
         if (isset($pa_options['exclude_relationship_types']) && $pa_options['exclude_relationship_types']) {
             if (!is_array($pa_options['exclude_relationship_types'])) {
                 $pa_options['exclude_relationship_types'] = array($pa_options['exclude_relationship_types']);
             }
             if (sizeof($pa_options['exclude_relationship_types'])) {
                 $t_rel_type = $this->opo_datamodel->getInstanceByTableName('ca_relationship_types', true);
                 $va_rel_types = array();
                 $va_rel_path = array_keys($this->opo_datamodel->getPath($this->ops_table_name, $va_path_components['table_name']));
                 foreach ($pa_options['exclude_relationship_types'] as $vm_type) {
                     if ($vn_type_id = $t_rel_type->getRelationshipTypeID($va_rel_path[1], $vm_type)) {
                         $va_rel_types[] = $vn_type_id;
                         if (is_array($va_children = $t_rel_type->getHierarchyChildren($vn_type_id, array('idsOnly' => true)))) {
                             $va_rel_types = array_merge($va_rel_types, $va_children);
                         }
                     }
                 }
                 if (sizeof($va_rel_types)) {
                     $va_tmp = array();
                     foreach ($va_value_list as $vn_id => $va_by_locale) {
                         foreach ($va_by_locale as $vn_locale_id => $va_values) {
                             foreach ($va_values as $vn_i => $va_value) {
                                 if (!in_array($va_value['rel_type_id'], $va_rel_types)) {
                                     $va_tmp[$vn_id][$vn_locale_id][$vn_i] = $va_value;
                                 }
                             }
                         }
                     }
                     $va_value_list = $va_tmp;
                 }
             }
         }
         // Restrict to types (related)
         $va_type_ids = $vs_type_fld = null;
         if (method_exists($t_instance, "getTypeFieldName")) {
             $va_type_ids = caMergeTypeRestrictionLists($t_instance, $pa_options);
             $vs_type_fld = $t_instance->getTypeFieldName();
         } else {
             if (method_exists($t_instance, "getSubjectTableInstance")) {
                 $t_label_subj_instance = $t_instance->getSubjectTableInstance();
                 if (method_exists($t_label_subj_instance, "getTypeFieldName")) {
                     $va_type_ids = caMergeTypeRestrictionLists($t_label_subj_instance, $pa_options);
                     $vs_type_fld = 'item_type_id';
                 }
             }
         }
         if (is_array($va_type_ids) && sizeof($va_type_ids)) {
             $va_tmp = array();
             foreach ($va_value_list as $vn_id => $va_by_locale) {
                 foreach ($va_by_locale as $vn_locale_id => $va_values) {
                     foreach ($va_values as $vn_i => $va_value) {
                         if (!$va_value[$vs_type_fld ? $vs_type_fld : 'item_type_id'] || in_array($va_value[$vs_type_fld ? $vs_type_fld : 'item_type_id'], $va_type_ids)) {
                             $va_tmp[$vn_id][$vn_locale_id][$vn_i] = $va_value;
                         }
                     }
                 }
             }
             $va_value_list = $va_tmp;
         }
         // Restrict to sources (related)
         $va_source_ids = $vs_source_id_fld = null;
         if (method_exists($t_instance, "getSourceFieldName")) {
             $va_source_ids = caMergeSourceRestrictionLists($t_instance, $pa_options);
             $vs_source_id_fld = $t_instance->getSourceFieldName();
         } else {
             if (method_exists($t_instance, "getSubjectTableInstance")) {
                 $t_label_subj_instance = $t_instance->getSubjectTableInstance();
                 if (method_exists($t_label_subj_instance, "getSourceFieldName")) {
                     $va_source_ids = caMergeSourceRestrictionLists($t_label_subj_instance, $pa_options);
                     $vs_source_id_fld = 'item_source_id';
                 }
             }
         }
         if (is_array($va_source_ids) && sizeof($va_source_ids)) {
             $va_tmp = array();
             foreach ($va_value_list as $vn_id => $va_by_locale) {
                 foreach ($va_by_locale as $vn_locale_id => $va_values) {
                     foreach ($va_values as $vn_i => $va_value) {
                         if (!$va_value[$vs_source_id_fld ? $vs_source_id_fld : 'item_source_id'] || in_array($va_value[$vs_source_id_fld ? $vs_source_id_fld : 'item_source_id'], $va_source_ids)) {
                             $va_tmp[$vn_id][$vn_locale_id][$vn_i] = $va_value;
                         }
                     }
                 }
             }
             $va_value_list = $va_tmp;
         }
         // Exclude types (related)
         if (isset($pa_options['exclude_type']) && $pa_options['exclude_type']) {
             if (!isset($pa_options['exclude_types']) || !is_array($pa_options['exclude_types'])) {
                 $pa_options['exclude_types'] = array();
             }
             $pa_options['exclude_types'][] = $pa_options['exclude_type'];
         }
         if (isset($pa_options['exclude_types']) && is_array($pa_options['exclude_types'])) {
             $va_ids = caMakeTypeIDList($va_path_components['table_name'], $pa_options['exclude_types']);
             if (is_array($va_ids) && sizeof($va_ids) > 0) {
                 $va_tmp = array();
                 foreach ($va_value_list as $vn_id => $va_by_locale) {
                     foreach ($va_by_locale as $vn_locale_id => $va_values) {
                         foreach ($va_values as $vn_i => $va_value) {
                             if (!in_array($va_value[$vs_type_fld ? $vs_type_fld : 'item_type_id'], $va_type_ids)) {
                                 $va_tmp[$vn_id][$vn_locale_id][$vn_i] = $va_value;
                             }
                         }
                     }
                 }
                 $va_value_list = $va_tmp;
             }
         }
         // Handle 'relationship_typename' (related)
         $vb_get_relationship_typename = false;
         if ($va_path_components['field_name'] == 'relationship_typename') {
             $va_path_components['field_name'] = 'rel_type_id';
             $vb_get_relationship_typename = true;
         }
         if ($vb_return_as_array) {
             // return array (intrinsics or labels in primary or related table)
             if ($t_instance->hasField($va_path_components['field_name']) && $va_path_components['table_name'] === $t_instance->tableName()) {
                 // Intrinsic
                 $va_field_info = $t_instance->getFieldInfo($va_path_components['field_name']);
                 $vs_pk = $t_original_instance->primaryKey();
                 // Handle specific intrinsic types
                 switch ($va_field_info['FIELD_TYPE']) {
                     case FT_DATERANGE:
                     case FT_HISTORIC_DATERANGE:
                         foreach ($va_value_list as $vn_id => $va_values_by_locale) {
                             foreach ($va_values_by_locale as $vn_locale_id => $va_values) {
                                 foreach ($va_values as $vn_i => $va_value) {
                                     $va_ids[] = $va_value[$vs_pk];
                                     if (caGetOption('GET_DIRECT_DATE', $pa_options, false) || caGetOption('getDirectDate', $pa_options, false)) {
                                         if (caGetOption('sortable', $pa_options, false)) {
                                             $vs_prop = $va_value[$va_field_info['START']] . '/' . $va_value[$va_field_info['END']];
                                         } else {
                                             $vs_prop = $va_value[$va_field_info['START']];
                                         }
                                     } else {
                                         $this->opo_tep->init();
                                         if ($va_field_info['FIELD_TYPE'] == FT_DATERANGE) {
                                             $this->opo_tep->setUnixTimestamps($va_value[$va_field_info['START']], $va_value[$va_field_info['END']]);
                                         } else {
                                             $this->opo_tep->setHistoricTimestamps($va_value[$va_field_info['START']], $va_value[$va_field_info['END']]);
                                         }
                                         $vs_prop = $this->opo_tep->getText($pa_options);
                                     }
                                     if ($vb_return_all_locales) {
                                         $va_return_values[$vn_row_id][$vn_locale_id][] = $vs_prop;
                                     } else {
                                         $va_return_values[] = $vs_prop;
                                     }
                                 }
                             }
                         }
                         break;
                     case FT_MEDIA:
                         if (!($vs_version = $va_path_components['subfield_name'])) {
                             $vs_version = "largeicon";
                         }
                         foreach ($va_value_list as $vn_id => $va_values_by_locale) {
                             foreach ($va_values_by_locale as $vn_locale_id => $va_values) {
                                 foreach ($va_values as $vn_i => $va_value) {
                                     $va_ids[] = $va_value[$vs_pk];
                                     if (isset($pa_options['unserialize']) && $pa_options['unserialize']) {
                                         $vs_prop = caUnserializeForDatabase($va_value[$va_path_components['field_name']]);
                                         if ($vb_return_all_locales) {
                                             $va_return_values[$vn_row_id][$vn_locale_id][] = $vs_prop;
                                         } else {
                                             $va_return_values[] = $vs_prop;
                                         }
                                     } else {
                                         $o_media_settings = new MediaProcessingSettings($va_path_components['table_name'], $va_path_components['field_name']);
                                         $va_versions = $o_media_settings->getMediaTypeVersions('*');
                                         if (!isset($va_versions[$vs_version])) {
                                             $va_tmp = array_keys($va_versions);
                                             $vs_version = array_shift($va_tmp);
                                         }
                                         // See if an info element was passed, eg. ca_object_representations.media.icon.width should return the width of the media rather than a tag or url to the media
                                         $vs_info_element = $va_path_components['num_components'] == 4 ? $va_path_components['components'][3] : null;
                                         if ($vb_return_all_locales) {
                                             if ($vs_info_element) {
                                                 $va_return_values[$vn_row_id][$vn_locale_id][] = $this->getMediaInfo($va_path_components['table_name'] . '.' . $va_path_components['field_name'], $vs_version, $vs_info_element, $pa_options);
                                             } elseif (isset($pa_options['returnURL']) && $pa_options['returnURL']) {
                                                 $va_return_values[$vn_row_id][$vn_locale_id][] = $this->getMediaUrl($va_path_components['table_name'] . '.' . $va_path_components['field_name'], $vs_version, $pa_options);
                                             } else {
                                                 $va_return_values[$vn_row_id][$vn_locale_id][] = $this->getMediaTag($va_path_components['table_name'] . '.' . $va_path_components['field_name'], $vs_version, $pa_options);
                                             }
                                         } else {
                                             if ($vs_info_element) {
                                                 $va_return_values[] = $this->getMediaInfo($va_path_components['table_name'] . '.' . $va_path_components['field_name'], $vs_version, $vs_info_element, $pa_options);
                                             } elseif (isset($pa_options['returnURL']) && $pa_options['returnURL']) {
                                                 $va_return_values[] = $this->getMediaUrl($va_path_components['table_name'] . '.' . $va_path_components['field_name'], $vs_version, $pa_options);
                                             } else {
                                                 $va_return_values[] = $this->getMediaTag($va_path_components['table_name'] . '.' . $va_path_components['field_name'], $vs_version, $pa_options);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         break;
                     default:
                         // is intrinsic field in primary table
                         $vb_supports_preferred = (bool) $t_instance->hasField('is_preferred');
                         foreach ($va_value_list as $vn_id => $va_values_by_locale) {
                             foreach ($va_values_by_locale as $vn_locale_id => $va_values) {
                                 foreach ($va_values as $vn_i => $va_value) {
                                     $va_ids[] = $vn_id = $va_value[$vs_pk];
                                     if ($vb_get_preferred_labels_only && $vb_supports_preferred && !$va_value['is_preferred']) {
                                         continue;
                                     }
                                     if ($vb_get_nonpreferred_labels_only && $vb_supports_preferred && $va_value['is_preferred']) {
                                         continue;
                                     }
                                     $vs_prop = $va_value[$va_path_components['field_name']];
                                     if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && ($vs_list_code = $t_instance->getFieldInfo($va_path_components['field_name'], "LIST_CODE"))) {
                                         $vs_prop = $t_list->getItemFromListForDisplayByItemID($vs_list_code, $vs_prop);
                                     } else {
                                         if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && ($vs_list_code = $t_instance->getFieldInfo($va_path_components['field_name'], "LIST"))) {
                                             $vs_prop = $t_list->getItemFromListForDisplayByItemValue($vs_list_code, $vs_prop);
                                         } else {
                                             if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && $va_path_components['field_name'] === 'locale_id' && (int) $vs_prop > 0) {
                                                 $t_locale = new ca_locales($vs_prop);
                                                 $vs_prop = $t_locale->getName();
                                             } else {
                                                 if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && is_array($va_list = $t_instance->getFieldInfo($va_path_components['field_name'], "BOUNDS_CHOICE_LIST"))) {
                                                     foreach ($va_list as $vs_option => $vs_value) {
                                                         if ($vs_value == $vs_prop) {
                                                             $vs_prop = $vs_option;
                                                             break;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                     if ($vb_return_all_locales) {
                                         $va_return_values[$vn_id][$vn_locale_id][] = $vs_prop;
                                     } else {
                                         $va_return_values[$vn_id][$vn_locale_id] = $vs_prop;
                                     }
                                 }
                             }
                         }
                         if (!$vb_return_all_locales) {
                             $va_return_values = array_values(caExtractValuesByUserLocale($va_return_values));
                         }
                         break;
                 }
             } else {
                 // Attributes
                 $vs_pk = $t_original_instance->primaryKey();
                 $vb_is_related = $this->ops_table_name !== $va_path_components['table_name'];
                 $va_ids = array();
                 $t_instance = $this->opo_datamodel->getInstanceByTableName($va_path_components['table_name'], true);
                 foreach ($va_value_list as $vn_i => $va_values_by_locale) {
                     foreach ($va_values_by_locale as $vn_locale_id => $va_values) {
                         foreach ($va_values as $vn_i => $va_value) {
                             if ($vb_is_related) {
                                 $va_ids[] = $va_value[$vs_pk];
                             }
                             if ($vb_get_preferred_labels_only && !$va_value['is_preferred']) {
                                 continue;
                             }
                             if ($vb_get_nonpreferred_labels_only && $va_value['is_preferred']) {
                                 continue;
                             }
                             // do we need to translate foreign key and choice list codes to display text?
                             $vs_prop = $vb_return_all_label_values && !$vb_return_as_link ? $va_value : $va_value[$va_path_components['field_name']];
                             if ($vb_get_relationship_typename) {
                                 if (!$t_rel_type) {
                                     $t_rel_type = $this->opo_datamodel->getInstanceByTableName('ca_relationship_types', true);
                                 }
                                 if (is_array($va_labels = $t_rel_type->getDisplayLabels(false, array('row_id' => (int) $vs_prop)))) {
                                     $va_label = array_shift($va_labels);
                                     $vs_prop = $va_label[0]['typename'];
                                 } else {
                                     $vs_prop = "?";
                                 }
                             } else {
                                 // Decode list items to text
                                 if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && ($vs_list_code = $t_instance->getFieldInfo($va_path_components['field_name'], "LIST_CODE"))) {
                                     $vs_prop = $t_list->getItemFromListForDisplayByItemID($vs_list_code, $vs_prop);
                                 } else {
                                     if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && ($vs_list_code = $t_instance->getFieldInfo($va_path_components['field_name'], "LIST"))) {
                                         $vs_prop = $t_list->getItemFromListForDisplayByItemValue($vs_list_code, $vs_prop);
                                     } else {
                                         if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && $va_path_components['field_name'] === 'locale_id' && (int) $vs_prop > 0) {
                                             $t_locale = new ca_locales($vs_prop);
                                             $vs_prop = $t_locale->getName();
                                         } else {
                                             if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && is_array($va_list = $t_instance->getFieldInfo($va_path_components['field_name'], "BOUNDS_CHOICE_LIST"))) {
                                                 foreach ($va_list as $vs_option => $vs_value) {
                                                     if ($vs_value == $vs_prop) {
                                                         $vs_prop = $vs_option;
                                                         break;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             if ($vb_return_all_locales) {
                                 $va_return_values[$vn_row_id][$vn_locale_id][] = $vs_prop;
                             } else {
                                 if ($vb_get_nonpreferred_labels_only && is_array($vs_prop)) {
                                     // non-preferred labels are lists of lists because they can repeat
                                     $va_return_values[][] = $vs_prop;
                                 } else {
                                     $va_return_values[] = $vs_prop;
                                 }
                             }
                         }
                     }
                 }
             }
             if ($vb_return_as_link) {
                 if (!$vb_return_all_locales) {
                     $va_return_values = caCreateLinksFromText($va_return_values, $va_original_path_components['table_name'], $va_ids, $vs_return_as_link_class, $vs_return_as_link_target);
                 }
             }
             return $va_return_values;
         } else {
             // Return scalar (intrinsics or labels in primary or related table)
             if ($vb_get_preferred_labels_only || $vb_get_nonpreferred_labels_only) {
                 // We have to distinguish between preferred and non-preferred labels here
                 // so that only appropriate labels are passed for output.
                 $va_filtered_values = array();
                 foreach ($va_value_list as $vn_label_id => $va_labels_by_locale) {
                     foreach ($va_labels_by_locale as $vn_locale_id => $va_labels) {
                         foreach ($va_labels as $vn_i => $va_label) {
                             if ($vb_get_preferred_labels_only && (!isset($va_label['is_preferred']) || $va_label['is_preferred']) || $vb_get_nonpreferred_labels_only && !$va_label['is_preferred']) {
                                 $va_filtered_values[$vn_label_id][$vn_locale_id][] = $va_label;
                             }
                         }
                     }
                 }
                 $va_value_list = $va_filtered_values;
             }
             $va_value_list = caExtractValuesByUserLocale($va_value_list);
             // do we need to translate foreign key and choice list codes to display text?
             $t_instance = $this->opo_datamodel->getInstanceByTableName($va_path_components['table_name'], true);
             $va_field_info = $t_instance->getFieldInfo($va_path_components['field_name']);
             $vs_pk = $t_instance->primaryKey();
             $vb_is_related = $this->ops_table_name !== $va_path_components['table_name'];
             $va_ids = array();
             foreach ($va_value_list as $vn_i => $va_values) {
                 if (!is_array($va_values)) {
                     continue;
                 }
                 // Handle specific intrinsic types
                 $vs_template_value = $vs_template;
                 foreach ($va_values as $vn_j => $va_value) {
                     switch ($va_field_info['FIELD_TYPE']) {
                         case FT_BIT:
                             if ($pa_options['convertCodesToDisplayText']) {
                                 $va_value[$va_path_components['field_name']] = (bool) $vs_prop ? _t('yes') : _t('no');
                             }
                             break;
                         case FT_DATERANGE:
                             if (caGetOption('GET_DIRECT_DATE', $pa_options, false) || caGetOption('getDirectDate', $pa_options, false)) {
                                 if (isset($pa_options['sortable']) && $pa_options['sortable']) {
                                     $va_value[$va_path_components['field_name']] = $va_value[$va_field_info['START']] . '/' . $va_value[$va_field_info['END']];
                                 } else {
                                     $va_value[$va_path_components['field_name']] = $va_value[$va_field_info['START']];
                                 }
                             } else {
                                 $this->opo_tep->init();
                                 $this->opo_tep->setUnixTimestamps($va_value[$va_field_info['START']], $va_value[$va_field_info['END']]);
                                 $va_value[$va_path_components['field_name']] = $this->opo_tep->getText($pa_options);
                             }
                             break;
                         case FT_HISTORIC_DATERANGE:
                             if (caGetOption('GET_DIRECT_DATE', $pa_options, false) || caGetOption('getDirectDate', $pa_options, false)) {
                                 if (caGetOption('sortable', $pa_options, false)) {
                                     $va_value[$va_path_components['field_name']] = $va_value[$va_field_info['START']] . '/' . $va_value[$va_field_info['END']];
                                 } else {
                                     $va_value[$va_path_components['field_name']] = $va_value[$va_field_info['START']];
                                 }
                             } else {
                                 $this->opo_tep->init();
                                 $this->opo_tep->setHistoricTimestamps($va_value[$va_field_info['START']], $va_value[$va_field_info['END']]);
                                 $va_value[$va_path_components['field_name']] = $this->opo_tep->getText($pa_options);
                             }
                             break;
                         case FT_MEDIA:
                             if (!($vs_version = $va_path_components['subfield_name'])) {
                                 $vs_version = "largeicon";
                             }
                             // See if an info element was passed, eg. ca_object_representations.media.icon.width should return the width of the media rather than a tag or url to the media
                             $vs_info_element = $va_path_components['num_components'] == 4 ? $va_path_components['components'][3] : null;
                             if (isset($pa_options['unserialize']) && $pa_options['unserialize']) {
                                 return caUnserializeForDatabase($va_value[$va_path_components['field_name']]);
                             } else {
                                 $o_media_settings = new MediaProcessingSettings($va_path_components['table_name'], $va_path_components['field_name']);
                                 $va_versions = $o_media_settings->getMediaTypeVersions('*');
                                 if (!isset($va_versions[$vs_version])) {
                                     $va_tmp = array_keys($va_versions);
                                     $vs_version = array_shift($va_tmp);
                                 }
                                 if ($vs_info_element) {
                                     // Return media info
                                     $va_value[$va_path_components['field_name']] = $this->getMediaInfo($va_path_components['table_name'] . '.' . $va_path_components['field_name'], $vs_version, $vs_info_element, $pa_options);
                                 } elseif (isset($pa_options['returnURL']) && $pa_options['returnURL']) {
                                     $va_value[$va_path_components['field_name']] = $this->getMediaUrl($va_path_components['table_name'] . '.' . $va_path_components['field_name'], $vs_version, $pa_options);
                                 } else {
                                     $va_value[$va_path_components['field_name']] = $this->getMediaTag($va_path_components['table_name'] . '.' . $va_path_components['field_name'], $vs_version, $pa_options);
                                 }
                             }
                             break;
                         default:
                             // noop
                             break;
                     }
                     $vs_prop = $va_value[$va_path_components['field_name']];
                     // Decode list items to text
                     if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && ($vs_list_code = $t_instance->getFieldInfo($va_path_components['field_name'], "LIST_CODE"))) {
                         $va_value[$va_path_components['field_name']] = $t_list->getItemFromListForDisplayByItemID($vs_list_code, $vs_prop);
                     } else {
                         if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && ($vs_list_code = $t_instance->getFieldInfo($va_path_components['field_name'], "LIST"))) {
                             $va_value[$va_path_components['field_name']] = $t_list->getItemFromListForDisplayByItemValue($vs_list_code, $vs_prop);
                         } else {
                             if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && $va_path_components['field_name'] === 'locale_id' && (int) $vs_prop > 0) {
                                 $t_locale = new ca_locales($vs_prop);
                                 $va_value[$va_path_components['field_name']] = $t_locale->getName();
                             } else {
                                 if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && is_array($va_list = $t_instance->getFieldInfo($va_path_components['field_name'], "BOUNDS_CHOICE_LIST"))) {
                                     foreach ($va_list as $vs_option => $vs_value) {
                                         if ($vs_value == $vs_prop) {
                                             $va_value[$va_path_components['field_name']] = $vs_option;
                                             break;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     $vs_pk = $this->opo_datamodel->getTablePrimaryKeyName($va_original_path_components['table_name']);
                     if ($vs_template) {
                         foreach ($va_value_list as $vn_id => $va_values) {
                             foreach ($va_values as $vn_i => $va_value) {
                                 $vs_prop = caProcessTemplateForIDs($vs_template, $va_original_path_components['table_name'], array($va_value[$vs_pk]), array('returnAsArray' => false));
                                 $va_return_values[] = $vs_prop;
                                 $va_ids[] = $va_value[$vs_pk];
                             }
                         }
                     } else {
                         $vs_prop = $va_value[$va_path_components['field_name']];
                         $va_return_values[] = $vs_prop;
                         if ($vb_is_related) {
                             $va_ids[] = $va_value[$vs_pk];
                         }
                     }
                 }
             }
             if ($vb_return_as_link && $vb_is_related) {
                 $va_return_values = caCreateLinksFromText($va_return_values, $va_original_path_components['table_name'], $va_ids, $vs_return_as_link_class, $vs_return_as_link_target);
             }
             if (isset($pa_options['convertLineBreaks']) && $pa_options['convertLineBreaks']) {
                 return caConvertLineBreaks(join($vs_delimiter, $va_return_values));
             } else {
                 return join($vs_delimiter, $va_return_values);
             }
         }
     }
     return null;
 }
Example #12
0
/**
 *
 *
 * @return array
 */
function caGetPrintTemplateDetails($ps_type, $ps_template, $pa_options = null)
{
    $vs_template_path = caGetPrintTemplateDirectoryPath($ps_type);
    if (file_exists("{$vs_template_path}/local/{$ps_template}.php")) {
        $vs_template_path = "{$vs_template_path}/local/{$ps_template}.php";
    } elseif (file_exists("{$vs_template_path}/{$ps_template}.php")) {
        $vs_template_path = "{$vs_template_path}/{$ps_template}.php";
    } else {
        return false;
    }
    if ($o_cache = caGetCacheObject('caPrintTemplatesList_' . $ps_type)) {
        $vs_cache_key = caMakeCacheKeyFromOptions($pa_options, $ps_type . '/' . $vs_template_path);
        if (($va_info = $o_cache->load($vs_cache_key)) && ($vn_mtime = $o_cache->load("{$vs_cache_key}_mtime")) >= filemtime($vs_template_path)) {
            return $va_info;
        }
    }
    $vs_template = file_get_contents($vs_template_path);
    $va_info = array();
    foreach (array("@name", "@type", "@pageSize", "@pageOrientation", "@tables", "@marginLeft", "@marginRight", "@marginTop", "@marginBottom", "@horizontalGutter", "@verticalGutter", "@labelWidth", "@labelHeight") as $vs_tag) {
        if (preg_match("!{$vs_tag}([^\n\n]+)!", $vs_template, $va_matches)) {
            $va_info[str_replace("@", "", $vs_tag)] = trim($va_matches[1]);
        } else {
            $va_info[str_replace("@", "", $vs_tag)] = null;
        }
    }
    $va_info['tables'] = preg_split("![,;]{1}!", $va_info['tables']);
    $va_info['path'] = $vs_template_path;
    if ($o_cache) {
        $o_cache->save($va_info, $vs_cache_key);
        $o_cache->save(filemtime($vs_template_path), "{$vs_cache_key}_mtime");
    }
    return $va_info;
}
Example #13
0
 /**
  * Return array with list of significant events in object life cycle as configured for 
  * a ca_objects_history editor bundle.
  *
  * @param array $pa_bundle_settings The settings for a ca_objects_history editing BUNDLES
  * @param array $pa_options Array of options. Options include:
  *		noCache = Don't use any cached history data. [Default is false]
  *		currentOnly = Only return history entries dates before or on the current date. [Default is false]
  *		limit = Only return a maximum number of history entries. [Default is null; no limit]
  *
  * @return array A list of life cycle events, indexed by historic timestamp for date of occurrrence. Each list value is an array of history entries.
  *
  * @used-by ca_objects::getObjectHistoryHTMLFormBundle
  */
 public function getObjectHistory($pa_bundle_settings = null, $pa_options = null)
 {
     global $g_ui_locale;
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     if (!is_array($pa_bundle_settings)) {
         $pa_bundle_settings = array();
     }
     $vs_cache_key = caMakeCacheKeyFromOptions(array_merge($pa_bundle_settings, $pa_options, array('object_id' => $this->getPrimaryKey())));
     $pb_no_cache = caGetOption('noCache', $pa_options, false);
     if (!$pb_no_cache && isset(ca_objects::$s_object_use_cache[$vs_cache_key])) {
         return ca_objects::$s_object_use_cache[$vs_cache_key];
     }
     $pb_display_label_only = caGetOption('displayLabelOnly', $pa_options, false);
     $pb_get_current_only = caGetOption('currentOnly', $pa_options, false);
     $pn_limit = caGetOption('limit', $pa_options, null);
     $vs_display_template = caGetOption('display_template', $pa_bundle_settings, _t('No template defined'));
     $vs_history_template = caGetOption('history_template', $pa_bundle_settings, $vs_display_template);
     $vn_current_date = caDateToHistoricTimestamp(_t('now'));
     $o_media_coder = new MediaInfoCoder();
     //
     // Get history
     //
     $va_history = array();
     // Lots
     if (is_array($va_lot_types = caGetOption('ca_object_lots_showTypes', $pa_bundle_settings, null)) && ($vn_lot_id = $this->get('lot_id'))) {
         $t_lot = new ca_object_lots($vn_lot_id);
         if (!$t_lot->get('deleted')) {
             $va_lot_type_info = $t_lot->getTypeList();
             $vn_type_id = $t_lot->get('type_id');
             $vs_color = $va_lot_type_info[$vn_type_id]['color'];
             if (!$vs_color || $vs_color == '000000') {
                 $vs_color = caGetOption("ca_object_lots_{$va_lot_type_info[$vn_type_id]['idno']}_color", $pa_bundle_settings, 'ffffff');
             }
             $va_dates = array();
             $va_date_elements = caGetOption("ca_object_lots_{$va_lot_type_info[$vn_type_id]['idno']}_dateElement", $pa_bundle_settings, null);
             if (!is_array($va_date_elements) && $va_date_elements) {
                 $va_date_elements = array($va_date_elements);
             }
             if (is_array($va_date_elements) && sizeof($va_date_elements)) {
                 foreach ($va_date_elements as $vs_date_element) {
                     $va_dates[] = array('sortable' => $t_lot->get($vs_date_element, array('getDirectDate' => true)), 'display' => $t_lot->get($vs_date_element));
                 }
             }
             if (!sizeof($va_dates)) {
                 $va_dates[] = array('sortable' => $vn_date = caUnixTimestampToHistoricTimestamps($t_lot->getCreationTimestamp(null, array('timestampOnly' => true))), 'display' => caGetLocalizedDate($vn_date));
             }
             foreach ($va_dates as $va_date) {
                 if (!$va_date['sortable']) {
                     continue;
                 }
                 if (!in_array($vn_type_id, $va_lot_types)) {
                     continue;
                 }
                 if ($pb_get_current_only && $va_date['sortable'] > $vn_current_date) {
                     continue;
                 }
                 $vs_default_display_template = '^ca_object_lots.preferred_labels.name (^ca_object_lots.idno_stub)';
                 $vs_display_template = $pb_display_label_only ? "" : caGetOption("ca_object_lots_{$va_lot_type_info[$vn_type_id]['idno']}_displayTemplate", $pa_bundle_settings, $vs_default_display_template);
                 $va_history[$va_date['sortable']][] = array('type' => 'ca_object_lots', 'id' => $vn_lot_id, 'display' => $t_lot->getWithTemplate($vs_display_template), 'color' => $vs_color, 'icon_url' => $vs_icon_url = $o_media_coder->getMediaTag($va_lot_type_info[$vn_type_id]['icon'], 'icon'), 'typename_singular' => $vs_typename = $va_lot_type_info[$vn_type_id]['name_singular'], 'typename_plural' => $va_lot_type_info[$vn_type_id]['name_plural'], 'icon' => '<div class="caUseHistoryIconContainer" style="background-color: #' . $vs_color . '"><div class="caUseHistoryIcon">' . ($vs_icon_url ? $vs_icon_url : '<div class="caUseHistoryIconText">' . $vs_typename . '</div>') . '</div></div>', 'date' => $va_date['display']);
             }
         }
     }
     // Loans
     $va_loans = $this->get('ca_loans.loan_id', array('returnAsArray' => true));
     if (is_array($va_loan_types = caGetOption('ca_loans_showTypes', $pa_bundle_settings, null)) && is_array($va_loans) && sizeof($va_loans)) {
         $qr_loans = caMakeSearchResult('ca_loans', $va_loans);
         $t_loan = new ca_loans();
         $va_loan_type_info = $t_loan->getTypeList();
         $va_date_elements_by_type = array();
         foreach ($va_loan_types as $vn_type_id) {
             if (!is_array($va_date_elements = caGetOption("ca_loans_{$va_loan_type_info[$vn_type_id]['idno']}_dateElement", $pa_bundle_settings, null)) && $va_date_elements) {
                 $va_date_elements = array($va_date_elements);
             }
             if (!$va_date_elements) {
                 continue;
             }
             $va_date_elements_by_type[$vn_type_id] = $va_date_elements;
         }
         while ($qr_loans->nextHit()) {
             $vn_loan_id = $qr_loans->get('loan_id');
             if ((string) $qr_loans->get('ca_loans.deleted') !== '0') {
                 continue;
             }
             // filter out deleted
             $vn_type_id = $qr_loans->get('type_id');
             $va_dates = array();
             if (is_array($va_date_elements_by_type[$vn_type_id]) && sizeof($va_date_elements_by_type[$vn_type_id])) {
                 foreach ($va_date_elements_by_type[$vn_type_id] as $vs_date_element) {
                     $va_dates[] = array('sortable' => $qr_loans->get("ca_loans.{$vs_date_element}", array('getDirectDate' => true)), 'display' => $qr_loans->get("ca_loans.{$vs_date_element}"));
                 }
             }
             if (!sizeof($va_dates)) {
                 $va_dates[] = array('sortable' => $vn_date = caUnixTimestampToHistoricTimestamps($qr_loans->get('lastModified')), 'display' => caGetLocalizedDate($vn_date));
             }
             $vs_default_display_template = '^ca_loans.preferred_labels.name (^ca_loans.idno)';
             $vs_display_template = $pb_display_label_only ? $vs_default_display_template : caGetOption("ca_loans_{$va_loan_type_info[$vn_type_id]['idno']}_displayTemplate", $pa_bundle_settings, $vs_default_display_template);
             foreach ($va_dates as $va_date) {
                 if (!$va_date['sortable']) {
                     continue;
                 }
                 if (!in_array($vn_type_id, $va_loan_types)) {
                     continue;
                 }
                 if ($pb_get_current_only && $va_date['sortable'] > $vn_current_date) {
                     continue;
                 }
                 $vs_color = $va_loan_type_info[$vn_type_id]['color'];
                 if (!$vs_color || $vs_color == '000000') {
                     $vs_color = caGetOption("ca_loans_{$va_loan_type_info[$vn_type_id]['idno']}_color", $pa_bundle_settings, 'ffffff');
                 }
                 $va_history[$va_date['sortable']][] = array('type' => 'ca_loans', 'id' => $vn_loan_id, 'display' => $qr_loans->getWithTemplate($vs_display_template), 'color' => $vs_color, 'icon_url' => $vs_icon_url = $o_media_coder->getMediaTag($va_loan_type_info[$vn_type_id]['icon'], 'icon'), 'typename_singular' => $vs_typename = $va_loan_type_info[$vn_type_id]['name_singular'], 'typename_plural' => $va_loan_type_info[$vn_type_id]['name_plural'], 'icon' => '<div class="caUseHistoryIconContainer" style="background-color: #' . $vs_color . '"><div class="caUseHistoryIcon">' . ($vs_icon_url ? $vs_icon_url : '<div class="caUseHistoryIconText">' . $vs_typename . '</div>') . '</div></div>', 'date' => $va_date['display']);
             }
         }
     }
     // Movements
     $va_movements = $this->get('ca_movements.movement_id', array('returnAsArray' => true));
     if (is_array($va_movement_types = caGetOption('ca_movements_showTypes', $pa_bundle_settings, null)) && is_array($va_movements) && sizeof($va_movements)) {
         $qr_movements = caMakeSearchResult('ca_movements', $va_movements);
         $t_movement = new ca_movements();
         $va_movement_type_info = $t_movement->getTypeList();
         $va_date_elements_by_type = array();
         foreach ($va_movement_types as $vn_type_id) {
             if (!is_array($va_date_elements = caGetOption("ca_movements_{$va_movement_type_info[$vn_type_id]['idno']}_dateElement", $pa_bundle_settings, null)) && $va_date_elements) {
                 $va_date_elements = array($va_date_elements);
             }
             if (!$va_date_elements) {
                 continue;
             }
             $va_date_elements_by_type[$vn_type_id] = $va_date_elements;
         }
         while ($qr_movements->nextHit()) {
             $vn_movement_id = $qr_movements->get('movement_id');
             if ((string) $qr_movements->get('ca_movements.deleted') !== '0') {
                 continue;
             }
             // filter out deleted
             $vn_type_id = $qr_movements->get('type_id');
             $va_dates = array();
             if (is_array($va_date_elements_by_type[$vn_type_id]) && sizeof($va_date_elements_by_type[$vn_type_id])) {
                 foreach ($va_date_elements_by_type[$vn_type_id] as $vs_date_element) {
                     $va_dates[] = array('sortable' => $qr_movements->get("ca_movements.{$vs_date_element}", array('getDirectDate' => true)), 'display' => $qr_movements->get("ca_movements.{$vs_date_element}"));
                 }
             }
             if (!sizeof($va_dates)) {
                 $va_dates[] = array('sortable' => $vn_date = caUnixTimestampToHistoricTimestamps($qr_movements->get('lastModified')), 'display' => caGetLocalizedDate($vn_date));
             }
             $vs_default_display_template = '^ca_movements.preferred_labels.name (^ca_movements.idno)';
             $vs_display_template = $pb_display_label_only ? $vs_default_display_template : caGetOption("ca_movements_{$va_movement_type_info[$vn_type_id]['idno']}_displayTemplate", $pa_bundle_settings, $vs_default_display_template);
             foreach ($va_dates as $va_date) {
                 if (!$va_date['sortable']) {
                     continue;
                 }
                 if (!in_array($vn_type_id, $va_movement_types)) {
                     continue;
                 }
                 if ($pb_get_current_only && $va_date['sortable'] > $vn_current_date) {
                     continue;
                 }
                 $vs_color = $va_movement_type_info[$vn_type_id]['color'];
                 if (!$vs_color || $vs_color == '000000') {
                     $vs_color = caGetOption("ca_movements_{$va_movement_type_info[$vn_type_id]['idno']}_color", $pa_bundle_settings, 'ffffff');
                 }
                 $va_history[$va_date['sortable']][] = array('type' => 'ca_movements', 'id' => $vn_movement_id, 'display' => $qr_movements->getWithTemplate($vs_display_template), 'color' => $vs_color, 'icon_url' => $vs_icon_url = $o_media_coder->getMediaTag($va_movement_type_info[$vn_type_id]['icon'], 'icon'), 'typename_singular' => $vs_typename = $va_movement_type_info[$vn_type_id]['name_singular'], 'typename_plural' => $va_movement_type_info[$vn_type_id]['name_plural'], 'icon' => '<div class="caUseHistoryIconContainer" style="background-color: #' . $vs_color . '"><div class="caUseHistoryIcon">' . ($vs_icon_url ? $vs_icon_url : '<div class="caUseHistoryIconText">' . $vs_typename . '</div>') . '</div></div>', 'date' => $va_date['display']);
             }
         }
     }
     // Occurrences
     $va_occurrences = $this->get('ca_occurrences.occurrence_id', array('returnAsArray' => true));
     if (is_array($va_occurrence_types = caGetOption('ca_occurrences_showTypes', $pa_bundle_settings, null)) && is_array($va_occurrences) && sizeof($va_occurrences)) {
         $qr_occurrences = caMakeSearchResult('ca_occurrences', $va_occurrences);
         $t_occurrence = new ca_occurrences();
         $va_occurrence_type_info = $t_occurrence->getTypeList();
         $va_date_elements_by_type = array();
         foreach ($va_occurrence_types as $vn_type_id) {
             if (!is_array($va_date_elements = caGetOption("ca_occurrences_{$va_occurrence_type_info[$vn_type_id]['idno']}_dateElement", $pa_bundle_settings, null)) && $va_date_elements) {
                 $va_date_elements = array($va_date_elements);
             }
             if (!$va_date_elements) {
                 continue;
             }
             $va_date_elements_by_type[$vn_type_id] = $va_date_elements;
         }
         while ($qr_occurrences->nextHit()) {
             $vn_occurrence_id = $qr_occurrences->get('occurrence_id');
             if ((string) $qr_occurrences->get('ca_occurrences.deleted') !== '0') {
                 continue;
             }
             // filter out deleted
             $vn_type_id = $qr_occurrences->get('type_id');
             $va_dates = array();
             if (is_array($va_date_elements_by_type[$vn_type_id]) && sizeof($va_date_elements_by_type[$vn_type_id])) {
                 foreach ($va_date_elements_by_type[$vn_type_id] as $vs_date_element) {
                     $va_dates[] = array('sortable' => $qr_occurrences->get("ca_occurrences.{$vs_date_element}", array('getDirectDate' => true)), 'display' => $qr_occurrences->get("ca_occurrences.{$vs_date_element}"));
                 }
             }
             if (!sizeof($va_dates)) {
                 $va_dates[] = array('sortable' => $vn_date = caUnixTimestampToHistoricTimestamps($qr_occurrences->get('lastModified')), 'display' => caGetLocalizedDate($vn_date));
             }
             $vs_default_display_template = '^ca_occurrences.preferred_labels.name (^ca_occurrences.idno)';
             $vs_display_template = $pb_display_label_only ? $vs_default_display_template : caGetOption("ca_occurrences_{$va_occurrence_type_info[$vn_type_id]['idno']}_displayTemplate", $pa_bundle_settings, $vs_default_display_template);
             foreach ($va_dates as $va_date) {
                 if (!$va_date['sortable']) {
                     continue;
                 }
                 if (!in_array($vn_type_id, $va_occurrence_types)) {
                     continue;
                 }
                 if ($pb_get_current_only && $va_date['sortable'] > $vn_current_date) {
                     continue;
                 }
                 $vs_color = $va_occurrence_type_info[$vn_type_id]['color'];
                 if (!$vs_color || $vs_color == '000000') {
                     $vs_color = caGetOption("ca_occurrences_{$va_occurrence_type_info[$vn_type_id]['idno']}_color", $pa_bundle_settings, 'ffffff');
                 }
                 $va_history[$va_date['sortable']][] = array('type' => 'ca_occurrences', 'id' => $vn_occurrence_id, 'display' => $qr_occurrences->getWithTemplate($vs_display_template), 'color' => $vs_color, 'icon_url' => $vs_icon_url = $o_media_coder->getMediaTag($va_occurrence_type_info[$vn_type_id]['icon'], 'icon'), 'typename_singular' => $vs_typename = $va_occurrence_type_info[$vn_type_id]['name_singular'], 'typename_plural' => $va_occurrence_type_info[$vn_type_id]['name_plural'], 'icon' => '<div class="caUseHistoryIconContainer" style="background-color: #' . $vs_color . '"><div class="caUseHistoryIcon">' . ($vs_icon_url ? $vs_icon_url : '<div class="caUseHistoryIconText">' . $vs_typename . '</div>') . '</div></div>', 'date' => $va_date['display']);
             }
         }
     }
     // Storage locations
     $va_locations = $this->get('ca_objects_x_storage_locations.relation_id', array('returnAsArray' => true));
     if (is_array($va_location_types = caGetOption('ca_storage_locations_showRelationshipTypes', $pa_bundle_settings, null)) && is_array($va_locations) && sizeof($va_locations)) {
         require_once __CA_MODELS_DIR__ . '/ca_storage_locations.php';
         $t_location = new ca_storage_locations();
         $va_location_type_info = $t_location->getTypeList();
         $vs_name_singular = $t_location->getProperty('NAME_SINGULAR');
         $vs_name_plural = $t_location->getProperty('NAME_PLURAL');
         $qr_locations = caMakeSearchResult('ca_objects_x_storage_locations', $va_locations);
         $vs_default_display_template = '^ca_storage_locations.parent.preferred_labels.name ➜ ^ca_storage_locations.preferred_labels.name (^ca_storage_locations.idno)';
         $vs_display_template = $pb_display_label_only ? $vs_default_display_template : caGetOption('ca_storage_locations_displayTemplate', $pa_bundle_settings, $vs_default_display_template);
         Debug::msg($qr_locations->numHits());
         while ($qr_locations->nextHit()) {
             $vn_location_id = $qr_locations->get('ca_objects_x_storage_locations.location_id');
             if ((string) $qr_locations->get('ca_storage_locations.deleted') !== '0') {
                 continue;
             }
             // filter out deleted
             $va_date = array('sortable' => $qr_locations->get("ca_objects_x_storage_locations.effective_date", array('getDirectDate' => true)), 'display' => $qr_locations->get("ca_objects_x_storage_locations.effective_date"));
             if (!$va_date['sortable']) {
                 continue;
             }
             if (!in_array($vn_rel_type_id = $qr_locations->get('ca_objects_x_storage_locations.type_id'), $va_location_types)) {
                 continue;
             }
             $vn_type_id = $qr_locations->get('ca_storage_locations.type_id');
             if ($pb_get_current_only && $va_date['sortable'] > $vn_current_date) {
                 continue;
             }
             $vs_color = $va_location_type_info[$vn_type_id]['color'];
             if (!$vs_color || $vs_color == '000000') {
                 $vs_color = caGetOption("ca_storage_locations_color", $pa_bundle_settings, 'ffffff');
             }
             $va_history[$va_date['sortable']][] = array('type' => 'ca_storage_locations', 'id' => $vn_location_id, 'display' => $qr_locations->getWithTemplate("<unit relativeTo='ca_storage_locations'>{$vs_display_template}</unit>"), 'color' => $vs_color, 'icon_url' => $vs_icon_url = $o_media_coder->getMediaTag($va_location_type_info[$vn_type_id]['icon'], 'icon'), 'typename_singular' => $vs_name_singular, 'typename_plural' => $vs_name_plural, 'icon' => '<div class="caUseHistoryIconContainer" style="background-color: #' . $vs_color . '"><div class="caUseHistoryIcon">' . ($vs_icon_url ? $vs_icon_url : '<div class="caUseHistoryIconText">' . $vs_name_singular . '</div>') . '</div></div>', 'date' => $va_date['display']);
         }
     }
     // Deaccession
     if ($this->get('is_deaccessioned') && caGetOption('showDeaccessionInformation', $pa_bundle_settings, false)) {
         $vs_color = caGetOption('deaccession_color', $pa_bundle_settings, 'cccccc');
         $vn_date = $this->get('deaccession_date', array('getDirectDate' => true));
         $vs_default_display_template = '^ca_objects.deaccession_notes';
         $vs_display_template = $pb_display_label_only ? $vs_default_display_template : caGetOption('deaccession_displayTemplate', $pa_bundle_settings, $vs_default_display_template);
         if (!($pb_get_current_only && $vn_date > $vn_current_date)) {
             $va_history[$vn_date][] = array('type' => 'ca_objects_deaccession', 'id' => $this->getPrimaryKey(), 'display' => $this->getWithTemplate("<unit>{$vs_display_template}</unit>"), 'color' => $vs_color, 'icon_url' => '', 'typename_singular' => $vs_name_singular = _t('deaccession'), 'typename_plural' => $vs_name_plural = _t('deaccessions'), 'icon' => '<div class="caUseHistoryIconContainer" style="background-color: #' . $vs_color . '"><div class="caUseHistoryIcon"><div class="caUseHistoryIconText">' . $vs_name_singular . '</div>' . '</div></div>', 'date' => $this->get('deaccession_date'));
         }
     }
     ksort($va_history);
     $va_history = array_reverse($va_history);
     if ($pn_limit > 0) {
         $va_history = array_slice($va_history, 0, $pn_limit);
     }
     if (sizeof(ca_objects::$s_object_use_cache[$vs_cache_key]) > 100) {
         ca_objects::$s_object_use_cache[$vs_cache_key] = array_slice(ca_objects::$s_object_use_cache[$vs_cache_key], 0, 50);
     }
     return ca_objects::$s_object_use_cache[$vs_cache_key] = $va_history;
 }