Example #1
0
/**
 * Converts result set into display labels for relationship lookup
 *
 * @param SearchResult $qr_rel_items 
 * @param BaseModel $pt_rel
 * @param array $pa_options Array of options, including:
 *		stripTags = default is false
 * 		exclude = list of primary key values to omit from returned list
 *		config = 
 *		limit = maximum number of items to return; if omitted all items are returned
 *		inlineCreateMessage = 
 *		inlineCreateQuery =
 *		inlineCreateMessageDoesNotExist =
 *		template = 
 *		primaryIDs = row_ids for primary rows in related table, keyed by table name; when resolving ambiguous relationships the row_ids will be excluded from consideration. This option is rarely used and exists primarily to take care of a single
 *						edge case: you are processing a template relative to a self-relationship such as ca_entities_x_entities that includes references to the subject table (ca_entities, in the case of ca_entities_x_entities). There are
 *						two possible paths to take in this situations; primaryIDs lets you specify which ones you *don't* want to take by row_id. For interstitial editors, the ids will be set to a single id: that of the subject (Eg. ca_entities) row
 *						from which the interstitial was launched.
 * @return mixed 
 */
function caProcessRelationshipLookupLabel($qr_rel_items, $pt_rel, $pa_options = null)
{
    $va_initial_values = array();
    $vs_hier_fld = $pt_rel->getProperty('HIERARCHY_ID_FLD');
    $vs_idno_fld = $pt_rel->getProperty('ID_NUMBERING_ID_FIELD');
    $vs_idno_sort_fld = $pt_rel->getProperty('ID_NUMBERING_SORT_FIELD');
    $vs_rel_pk = caGetOption('primaryKey', $pa_options, $pt_rel->primaryKey());
    $vs_rel_table = caGetOption('table', $pa_options, $pt_rel->tableName());
    $o_config = !isset($pa_options['config']) || !is_object($pa_options['config']) ? Configuration::load() : $pa_options['config'];
    $pn_limit = caGetOption('limit', $pa_options, null);
    $ps_inline_create_message = caGetOption('inlineCreateMessage', $pa_options, null);
    $ps_inline_create_does_not_exist_message = caGetOption('inlineCreateMessageDoesNotExist', $pa_options, null);
    $ps_inline_create_query = caGetOption('inlineCreateQuery', $pa_options, null);
    $ps_inline_create_query_lc = mb_strtolower($ps_inline_create_query);
    $ps_empty_result_message = caGetOption('emptyResultMessage', $pa_options, null);
    $ps_empty_result_query = caGetOption('emptyResultQuery', $pa_options, null);
    $vs_template = caGetOption('template', $pa_options, null);
    $va_exclude = caGetOption('exclude', $pa_options, array(), array('castTo' => 'array'));
    $va_display_format = $o_config->getList("{$vs_rel_table}_lookup_settings");
    $vs_display_delimiter = $o_config->get("{$vs_rel_table}_lookup_delimiter");
    if (!$vs_template) {
        $vs_template = join($vs_display_delimiter, $va_display_format);
    }
    $va_related_item_info = $va_parent_ids = $va_hierarchy_ids = array();
    $va_items = array();
    $o_dm = Datamodel::load();
    $t_rel = $o_dm->getInstanceByTableName($vs_rel_table, true);
    $vs_type_id_fld = method_exists($t_rel, 'getTypeFieldName') ? $t_rel->getTypeFieldName() : null;
    $vn_c = 0;
    $vb_include_inline_add_does_not_exist_message = $vb_include_empty_result_message = false;
    $vb_include_inline_add_message = true;
    if (is_object($qr_rel_items)) {
        if (!$qr_rel_items->numHits()) {
            if ($ps_inline_create_does_not_exist_message) {
                $vb_include_inline_add_does_not_exist_message = true;
                $vb_include_inline_add_message = false;
            } else {
                if ($ps_empty_result_message) {
                    $vb_include_empty_result_message = true;
                }
            }
        } else {
            $vs_table = $qr_rel_items->tableName();
            $vs_pk = $qr_rel_items->primaryKey();
            $va_primary_ids = method_exists($pt_rel, "isSelfRelationship") && ($vb_is_self_rel = $pt_rel->isSelfRelationship()) ? caGetOption("primaryIDs", $pa_options, null) : null;
            while ($qr_rel_items->nextHit()) {
                $vn_id = $qr_rel_items->get("{$vs_rel_table}.{$vs_rel_pk}");
                if (in_array($vn_id, $va_exclude)) {
                    continue;
                }
                $va_item = array('id' => $vn_id, $vs_rel_pk => $vn_id);
                if ($vs_type_id_fld) {
                    $va_item['type_id'] = $qr_rel_items->get("{$vs_rel_table}.{$vs_type_id_fld}");
                }
                $va_item['_display'] = caProcessTemplateForIDs($vs_template, $vs_table, array($qr_rel_items->get("{$vs_table}.{$vs_pk}")), array('returnAsArray' => false, 'returnAsLink' => false, 'delimiter' => caGetOption('delimiter', $pa_options, $vs_display_delimiter), 'resolveLinksUsing' => $vs_rel_table, 'primaryIDs' => $va_primary_ids));
                $va_item['label'] = mb_strtolower($qr_rel_items->get("{$vs_table}.preferred_labels"));
                $va_items[$vn_id] = $va_item;
                $vn_c++;
                if ($pn_limit && $pn_limit <= $vn_c) {
                    break;
                }
            }
        }
    }
    if (isset($pa_options['relatedItems']) && is_array($pa_options['relatedItems']) && sizeof($pa_options['relatedItems'])) {
        $va_tmp = array();
        foreach ($pa_options['relatedItems'] as $vn_relation_id => $va_relation) {
            $va_items[$va_relation[$vs_rel_pk]]['relation_id'] = $va_relation['relation_id'];
            $va_items[$va_relation[$vs_rel_pk]]['relationship_type_id'] = $va_items[$va_relation[$vs_rel_pk]]['type_id'] = $va_relation['direction'] ? $va_relation['direction'] . '_' . $va_relation['relationship_type_id'] : $va_relation['relationship_type_id'];
            $va_items[$va_relation[$vs_rel_pk]]['rel_type_id'] = $va_relation['relationship_type_id'];
            $va_items[$va_relation[$vs_rel_pk]]['relationship_typename'] = $va_relation['relationship_typename'];
            $va_items[$va_relation[$vs_rel_pk]]['idno'] = $va_relation[$vs_idno_fld];
            $va_items[$va_relation[$vs_rel_pk]]['idno_sort'] = $va_relation[$vs_idno_sort_fld];
            $va_items[$va_relation[$vs_rel_pk]]['label'] = $va_relation['label'];
            $va_items[$va_relation[$vs_rel_pk]]['direction'] = $va_relation['direction'];
            $va_items[$va_relation[$vs_rel_pk]]['effective_date'] = $va_relation['effective_date'];
            if (isset($va_relation['surname'])) {
                // pass forename and surname entity label fields to support proper sorting by name
                $va_items[$va_relation[$vs_rel_pk]]['surname'] = $va_relation['surname'];
                $va_items[$va_relation[$vs_rel_pk]]['forename'] = $va_relation['forename'];
            }
            if (!isset($va_items[$va_relation[$vs_rel_pk]][$vs_rel_pk]) || !$va_items[$va_relation[$vs_rel_pk]][$vs_rel_pk]) {
                $va_items[$va_relation[$vs_rel_pk]][$vs_rel_pk] = $va_items[$va_relation[$vs_rel_pk]]['id'] = $va_relation[$vs_rel_pk];
            }
            if ($vs_template) {
                $va_items[$va_relation[$vs_rel_pk]]['_display'] = caProcessTemplateForIDs($vs_template, $pt_rel->tableName(), array($va_relation['relation_id'] ? $va_relation['relation_id'] : $va_relation[$vs_pk]), array('returnAsArray' => false, 'returnAsLink' => false, 'delimiter' => caGetOption('delimiter', $pa_options, $vs_display_delimiter), 'resolveLinksUsing' => $vs_rel_table, 'primaryIDs' => $va_primary_ids));
            } else {
                $va_items[$va_relation[$vs_rel_pk]]['_display'] = $va_items[$va_relation[$vs_rel_pk]]['label'];
            }
            $va_tmp[$vn_relation_id] = $va_items[$va_relation[$vs_rel_pk]];
        }
        $va_items = $va_tmp;
        unset($va_tmp);
    }
    foreach ($va_items as $va_item) {
        $vn_id = $va_item[$vs_rel_pk];
        if (in_array($vn_id, $va_exclude)) {
            continue;
        }
        $vs_display = $va_item['_display'];
        if (isset($pa_options['stripTags']) && $pa_options['stripTags']) {
            if (preg_match('!(<[A-Za-z0-9]+[ ]+[A-Za-z0-9 ,;\\&\\-_]*>)!', $vs_display, $va_matches)) {
                // convert text in <> to non-tags if the text has only letters, numbers and spaces in it
                array_shift($va_matches);
                foreach ($va_matches as $vs_match) {
                    $vs_display = str_replace($vs_match, htmlspecialchars($vs_match), $vs_display);
                }
            }
            $vs_display = trim(strip_tags($vs_display));
            $vs_label = $va_item['label'];
            if (preg_match('!(<[A-Za-z0-9]+[ ]+[A-Za-z0-9 ,;\\&\\-_]*>)!', $vs_label, $va_matches)) {
                // convert text in <> to non-tags if the text has only letters, numbers and spaces in it
                array_shift($va_matches);
                foreach ($va_matches as $vs_match) {
                    $vs_label = str_replace($vs_match, htmlspecialchars($vs_match), $vs_label);
                }
            }
            $va_item['label'] = trim(strip_tags($vs_label));
        }
        $vs_display_lc = mb_strtolower($vs_display);
        if ($vs_display_lc == $ps_inline_create_query_lc || isset($va_item['label']) && $va_item['label'] == $ps_inline_create_query_lc) {
            $vb_include_inline_add_message = false;
        }
        $po_request = caGetOption('request', $pa_options);
        if ($po_request && ca_editor_uis::loadDefaultUI($pt_rel->tableName(), $po_request, $va_item['rel_type_id'])) {
            $va_item['hasInterstitialUI'] = true;
        } else {
            $va_item['hasInterstitialUI'] = false;
        }
        $va_initial_values[$va_item['relation_id'] ? (int) $va_item['relation_id'] : $va_item[$vs_rel_pk]] = array_merge($va_item, array('label' => $vs_display));
    }
    if ($vb_include_inline_add_message && $ps_inline_create_message) {
        array_push($va_initial_values, array('label' => $ps_inline_create_message, 'id' => 0, $vs_rel_pk => 0, '_query' => $ps_inline_create_query));
    } elseif ($vb_include_inline_add_does_not_exist_message && $ps_inline_create_does_not_exist_message) {
        array_push($va_initial_values, array('label' => $ps_inline_create_does_not_exist_message, 'id' => 0, $vs_rel_pk => 0, '_query' => $ps_inline_create_query));
    } elseif ($vb_include_empty_result_message) {
        array_push($va_initial_values, array('label' => $ps_empty_result_message, 'id' => -1, $vs_rel_pk => -1, '_query' => $ps_empty_result_query));
    }
    return $va_initial_values;
}
 /**
  * Index attribute
  *
  * @param BaseModel $pt_subject
  * @param int $pn_row_id
  * @param mixed $pm_element_code_or_id
  * @param array $pa_data
  * @return bool
  */
 private function _indexAttribute($pt_subject, $pn_row_id, $pm_element_code_or_id, $pa_data)
 {
     $va_attributes = $pt_subject->getAttributesByElement($pm_element_code_or_id, array('row_id' => $pn_row_id));
     $pn_subject_tablenum = $pt_subject->tableNum();
     $vn_datatype = isset($pa_data['datatype']) ? $pa_data['datatype'] : $this->_getElementDataType($pm_element_code_or_id);
     switch ($vn_datatype) {
         case __CA_ATTRIBUTE_VALUE_CONTAINER__:
             // container
             // index components of complex multi-value attributes
             if (sizeof($va_attributes)) {
                 foreach ($va_attributes as $vo_attribute) {
                     /* index each element of the container */
                     $vn_element_id = is_numeric($pm_element_code_or_id) ? $pm_element_code_or_id : $this->_getElementID($pm_element_code_or_id);
                     $va_sub_element_ids = $this->opo_metadata_element->getElementsInSet($vn_element_id, true, array('idsOnly' => true));
                     if (is_array($va_sub_element_ids) && sizeof($va_sub_element_ids)) {
                         $va_sub_element_ids = array_flip($va_sub_element_ids);
                         foreach ($vo_attribute->getValues() as $vo_value) {
                             $vn_list_id = $this->_getElementListID($vo_value->getElementID());
                             $vs_value_to_index = $vo_value->getDisplayValue($vn_list_id);
                             $va_additional_indexing = $vo_value->getDataForSearchIndexing();
                             if (is_array($va_additional_indexing) && sizeof($va_additional_indexing) > 0) {
                                 foreach ($va_additional_indexing as $vs_additional_value) {
                                     $vs_value_to_index .= " ; " . $vs_additional_value;
                                 }
                             }
                             $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $vo_value->getElementID(), $pn_row_id, $vs_value_to_index, $pa_data);
                             unset($va_sub_element_ids[$vo_value->getElementID()]);
                         }
                         // Clear out any elements that aren't defined
                         foreach (array_keys($va_sub_element_ids) as $vn_element_id) {
                             $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $vn_element_id, $pn_row_id, '', $pa_data);
                         }
                     }
                 }
             } else {
                 // we are deleting a container so cleanup existing sub-values
                 if (is_array($va_sub_elements = $this->opo_metadata_element->getElementsInSet($pm_element_code_or_id))) {
                     foreach ($va_sub_elements as $vn_i => $va_element_info) {
                         $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $va_element_info['element_id'], $pn_row_id, '', $pa_data);
                     }
                 }
             }
             break;
         case __CA_ATTRIBUTE_VALUE_LIST__:
         case __CA_ATTRIBUTE_VALUE_OBJECTS__:
         case __CA_ATTRIBUTE_VALUE_ENTITIES__:
         case __CA_ATTRIBUTE_VALUE_PLACES__:
         case __CA_ATTRIBUTE_VALUE_OCCURRENCES__:
         case __CA_ATTRIBUTE_VALUE_COLLECTIONS__:
         case __CA_ATTRIBUTE_VALUE_LOANS__:
         case __CA_ATTRIBUTE_VALUE_MOVEMENTS__:
         case __CA_ATTRIBUTE_VALUE_STORAGELOCATIONS__:
         case __CA_ATTRIBUTE_VALUE_OBJECTLOTS__:
             // We pull the preferred labels of list items for indexing here. We do so for all languages. Note that
             // this only done for list attributes that are standalone and not a sub-element in a container. Perhaps
             // we should also index the text of sub-element lists, but it's not clear that it is a good idea yet. The list_id's of
             // sub-elements *are* indexed however, so advanced search forms passing ids instead of text will work.
             $va_tmp = array();
             $vn_element_id = is_numeric($pm_element_code_or_id) ? $pm_element_code_or_id : $this->_getElementID($pm_element_code_or_id);
             $va_attributes = $pt_subject->getAttributesByElement($vn_element_id, array('row_id' => $pn_row_id));
             if (is_array($va_attributes) && sizeof($va_attributes)) {
                 foreach ($va_attributes as $vo_attribute) {
                     foreach ($vo_attribute->getValues() as $vo_value) {
                         $vs_value_to_index = $vo_value->getDisplayValue(array('idsOnly' => true));
                         $va_additional_indexing = $vo_value->getDataForSearchIndexing();
                         if (is_array($va_additional_indexing) && sizeof($va_additional_indexing) > 0) {
                             foreach ($va_additional_indexing as $vs_additional_value) {
                                 $vs_value_to_index .= " ; " . $vs_additional_value;
                             }
                         }
                         $va_tmp[$vo_attribute->getAttributeID()] = $vs_value_to_index;
                     }
                 }
             } else {
                 // Delete indexing
                 $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $vn_element_id, $pn_row_id, '', $pa_data);
             }
             if (is_array($va_tmp) && sizeof($va_tmp)) {
                 $va_new_values = array();
                 if ($t_item = AuthorityAttributeValue::elementTypeToInstance($vn_datatype)) {
                     $va_labels = $t_item->getPreferredDisplayLabelsForIDs($va_tmp, array('returnAllLocales' => true));
                     foreach ($va_labels as $vn_row_id => $va_labels_per_row) {
                         foreach ($va_labels_per_row as $vn_locale_id => $va_label_list) {
                             foreach ($va_label_list as $vs_label) {
                                 $va_new_values[$vn_row_id][$vs_label] = true;
                             }
                         }
                     }
                     foreach ($va_tmp as $vn_attribute_id => $vn_item_id) {
                         if (!$vn_item_id) {
                             continue;
                         }
                         if (!isset($va_new_values[$vn_item_id]) || !is_array($va_new_values[$vn_item_id])) {
                             continue;
                         }
                         $vs_v = join(' ;  ', array_merge(array($vn_item_id), array_keys($va_new_values[$vn_item_id])));
                         $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $vn_element_id, $pn_row_id, $vs_v, $pa_data);
                         if ($va_hier_values = $this->_genHierarchicalPath($vn_item_id, "preferred_labels." . $t_item->getLabelDisplayField(), $t_item, $pa_data)) {
                             $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $vn_element_id, $pn_row_id, $vs_v . ' ' . join(" ", $va_hier_values['values']), $pa_data);
                             if (caGetOption('INDEX_ANCESTORS_AS_PATH_WITH_DELIMITER', $pa_data, false) !== false) {
                                 $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $vn_element_id, $pn_row_id, $va_hier_values['path'], array_merge($pa_data, array('DONT_TOKENIZE' => 1)));
                             }
                         }
                     }
                 }
             }
             break;
         default:
             $vn_element_id = is_numeric($pm_element_code_or_id) ? $pm_element_code_or_id : $this->_getElementID($pm_element_code_or_id);
             $va_attributes = $pt_subject->getAttributesByElement($pm_element_code_or_id, array('row_id' => $pn_row_id));
             if (!is_array($va_attributes)) {
                 $va_attributes = array();
             }
             if (sizeof($va_attributes) > 0) {
                 foreach ($va_attributes as $vo_attribute) {
                     foreach ($vo_attribute->getValues() as $vo_value) {
                         $vs_value_to_index = $vo_value->getDisplayValue();
                         $va_additional_indexing = $vo_value->getDataForSearchIndexing();
                         if (is_array($va_additional_indexing) && sizeof($va_additional_indexing) > 0) {
                             foreach ($va_additional_indexing as $vs_additional_value) {
                                 $vs_value_to_index .= " ; " . $vs_additional_value;
                             }
                         }
                         $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $vn_element_id, $pn_row_id, $vs_value_to_index, $pa_data);
                     }
                 }
             } else {
                 // Delete indexing
                 $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $vn_element_id, $pn_row_id, '', $pa_data);
             }
             $vs_subject_pk = $pt_subject->primaryKey();
             // reindex children?
             if (caGetOption('INDEX_ANCESTORS', $pa_data, false) !== false || in_array('INDEX_ANCESTORS', $pa_data)) {
                 if ($pt_subject && $pt_subject->isHierarchical()) {
                     if ($va_hier_values = $this->_genHierarchicalPath($pn_row_id, $vs_element_code = $this->_getElementCode($vn_element_id), $pt_subject, $pa_data)) {
                         $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $vn_element_id, $pn_row_id, join(" ", $va_hier_values['values']), $pa_data);
                         if (caGetOption('INDEX_ANCESTORS_AS_PATH_WITH_DELIMITER', $pa_data, false) !== false) {
                             $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $vn_element_id, $pn_row_id, $va_hier_values['path'], array_merge($pa_data, array('DONT_TOKENIZE' => 1)));
                         }
                     }
                     $va_children_ids = $pt_subject->getHierarchyAsList($pn_row_id, array('idsOnly' => true, 'includeSelf' => false));
                     if (!$pb_reindex_mode && is_array($va_children_ids) && sizeof($va_children_ids) > 0) {
                         // trigger reindexing of children
                         $o_indexer = new SearchIndexer($this->opo_db);
                         $pt_subject->load($pn_row_id);
                         $va_content = $pt_subject->get($pt_subject->tableName() . "." . $vs_element_code, array('returnAsArray' => true, 'returnAllLocales' => true));
                         foreach ($va_children_ids as $vn_id) {
                             if ($vn_id == $pn_row_id) {
                                 continue;
                             }
                             $o_indexer->opo_engine->startRowIndexing($pn_subject_tablenum, $vn_id);
                             foreach ($va_content as $vn_i => $va_by_locale) {
                                 foreach ($va_by_locale as $vn_locale_id => $va_content_list) {
                                     foreach ($va_content_list as $va_content_container) {
                                         $o_indexer->opo_engine->indexField($pn_subject_tablenum, 'A' . $vn_element_id, $vn_id, $va_content_container[$vs_element_code], array_merge($pa_data, array('DONT_TOKENIZE' => 1)));
                                     }
                                 }
                             }
                             $o_indexer->opo_engine->commitRowIndexing();
                         }
                     }
                     continue;
                 }
             }
             break;
     }
     return true;
 }
Example #3
0
 /**
  * get() value for attribute
  *
  * @param array $pa_value_list
  * @param BaseModel $pt_instance
  * @param array Options
  *
  * @return array|string
  */
 private function _getAttributeValue($pa_value_list, $pt_instance, $pa_options)
 {
     $va_path_components =& $pa_options['pathComponents'];
     $va_return_values = array();
     $vn_id = $this->get($pt_instance->primaryKey(true));
     $vs_table_name = $pt_instance->tableName();
     if (is_array($pa_value_list) && sizeof($pa_value_list)) {
         foreach ($pa_value_list as $o_attribute) {
             $va_values = $o_attribute->getValues();
             if ($pa_options['useLocaleCodes']) {
                 if (!$o_attribute->getLocaleID() || !($vm_locale_id = $this->opo_locales->localeIDToCode($o_attribute->getLocaleID()))) {
                     $vm_locale_id = __CA_DEFAULT_LOCALE__;
                 }
             } else {
                 if (!($vm_locale_id = $o_attribute->getLocaleID())) {
                     $vm_locale_id = $this->opo_locales->localeCodeToID(__CA_DEFAULT_LOCALE__);
                 }
             }
             foreach ($va_values as $o_value) {
                 $vs_element_code = $o_value->getElementCode();
                 if ($va_path_components['subfield_name']) {
                     if ($va_path_components['subfield_name'] && $va_path_components['subfield_name'] !== $vs_element_code && !$o_value instanceof InformationServiceAttributeValue) {
                         continue;
                     }
                 }
                 switch ($o_value->getType()) {
                     case __CA_ATTRIBUTE_VALUE_LIST__:
                         $t_element = $pt_instance->_getElementInstance($o_value->getElementID());
                         $vn_list_id = $t_element->get('list_id');
                         $vs_val_proc = $o_value->getDisplayValue(array_merge($pa_options, array('output' => $pa_options['output'], 'list_id' => $vn_list_id)));
                         break;
                     case __CA_ATTRIBUTE_VALUE_INFORMATIONSERVICE__:
                         //ca_objects.informationservice.ulan_container
                         // support subfield notations like ca_objects.wikipedia.abstract, but only if we're not already at subfield-level, e.g. ca_objects.container.wikipedia
                         if ($va_path_components['subfield_name'] && $vs_element_code != $va_path_components['subfield_name'] && $vs_element_code == $va_path_components['field_name']) {
                             $vs_val_proc = $o_value->getExtraInfo($va_path_components['subfield_name']);
                             break;
                         }
                         // support ca_objects.container.wikipedia.abstract
                         if ($vs_element_code == $va_path_components['subfield_name'] && $va_path_components['num_components'] == 4) {
                             $vs_val_proc = $o_value->getExtraInfo($va_path_components['components'][3]);
                             break;
                         }
                         // support ca_objects.wikipedia or ca_objects.container.wikipedia (Eg. no "extra" value specified)
                         if ($vs_element_code == $va_path_components['field_name'] || $vs_element_code == $va_path_components['subfield_name']) {
                             $vs_val_proc = $o_value->getDisplayValue(array_merge($pa_options, array('output' => $pa_options['output'])));
                             break;
                         }
                         continue;
                     default:
                         $vs_val_proc = $o_value->getDisplayValue(array_merge($pa_options, array('output' => $pa_options['output'])));
                         break;
                 }
                 if ($pa_options['makeLink']) {
                     $vs_val_proc = array_shift(caCreateLinksFromText(array($vs_val_proc), $vs_table_name, array($vn_id)));
                 }
                 if ($pa_options['returnWithStructure']) {
                     $va_return_values[(int) $vn_id][$vm_locale_id][(int) $o_attribute->getAttributeID()][$vs_element_code] = $vs_val_proc;
                 } else {
                     $va_return_values[(int) $vn_id][$vm_locale_id][(int) $o_attribute->getAttributeID()] = $vs_val_proc;
                 }
             }
         }
     } else {
         // is blank
         if ($pa_options['returnWithStructure'] && $pa_options['returnBlankValues']) {
             $va_return_values[(int) $vn_id][null][null][$va_path_components['subfield_name'] ? $va_path_components['subfield_name'] : $va_path_components['field_name']] = '';
         }
     }
     if (!$pa_options['returnAllLocales']) {
         $va_return_values = caExtractValuesByUserLocale($va_return_values);
     }
     if ($pa_options['returnWithStructure']) {
         return is_array($va_return_values) ? $va_return_values : array();
     }
     //
     // Flatten array for return as string or simple array value
     //
     $va_flattened_values = $this->_flattenArray($va_return_values, $pa_options);
     if ($pa_options['returnAsArray']) {
         return $va_flattened_values;
     } else {
         return sizeof($va_flattened_values) > 0 ? join($pa_options['delimiter'], $va_flattened_values) : null;
     }
 }
Example #4
0
 /**
  * get() value for attribute
  *
  * @param array $pa_value_list
  * @param BaseModel $pt_instance
  * @param array Options
  *
  * @return array|string
  */
 private function _getAttributeValue($pa_value_list, $pt_instance, $pa_options)
 {
     $va_path_components =& $pa_options['pathComponents'];
     $vs_delimiter = isset($pa_options['delimiter']) ? $pa_options['delimiter'] : ';';
     $va_return_values = array();
     $vn_id = $this->get($pt_instance->primaryKey(true));
     $vs_table_name = $pt_instance->tableName();
     if (is_array($pa_value_list) && sizeof($pa_value_list)) {
         $va_val_proc = array();
         foreach ($pa_value_list as $o_attribute) {
             $t_attr_element = $pt_instance->_getElementInstance($o_attribute->getElementID());
             $vn_attr_type = $t_attr_element->get('datatype');
             $va_acc = array();
             $va_values = $o_attribute->getValues();
             if ($pa_options['useLocaleCodes']) {
                 if (!$o_attribute->getLocaleID() || !($vm_locale_id = SearchResult::$opo_locales->localeIDToCode($o_attribute->getLocaleID()))) {
                     $vm_locale_id = __CA_DEFAULT_LOCALE__;
                 }
             } else {
                 if (!($vm_locale_id = $o_attribute->getLocaleID())) {
                     $vm_locale_id = SearchResult::$opo_locales->localeCodeToID(__CA_DEFAULT_LOCALE__);
                 }
             }
             $vb_did_return_value = false;
             foreach ($va_values as $o_value) {
                 $vs_val_proc = null;
                 $vb_dont_return_value = false;
                 $vs_element_code = $o_value->getElementCode();
                 $va_auth_spec = null;
                 if (is_a($o_value, "AuthorityAttributeValue")) {
                     $va_auth_spec = $va_path_components['components'];
                     if ($pt_instance->hasElement($va_path_components['subfield_name'], null, true, array('dontCache' => false))) {
                         array_shift($va_auth_spec);
                         array_shift($va_auth_spec);
                         array_shift($va_auth_spec);
                     } elseif ($pt_instance->hasElement($va_path_components['field_name'], null, true, array('dontCache' => false))) {
                         array_shift($va_auth_spec);
                         array_shift($va_auth_spec);
                         $va_path_components['subfield_name'] = null;
                     }
                 }
                 if ($va_path_components['subfield_name'] && $va_path_components['subfield_name'] !== $vs_element_code && !$o_value instanceof InformationServiceAttributeValue) {
                     $vb_dont_return_value = true;
                     if (!$pa_options['filter']) {
                         continue;
                     }
                 }
                 if (is_a($o_value, "AuthorityAttributeValue") && sizeof($va_auth_spec) > 0) {
                     array_unshift($va_auth_spec, $vs_auth_table_name = $o_value->tableName());
                     if ($qr_res = caMakeSearchResult($vs_auth_table_name, array($o_value->getID()))) {
                         if ($qr_res->nextHit()) {
                             unset($pa_options['returnWithStructure']);
                             $va_options['returnAsArray'] = true;
                             $va_val_proc = $qr_res->get(join(".", $va_auth_spec), $pa_options);
                             if (is_array($va_val_proc)) {
                                 foreach ($va_val_proc as $vn_i => $vs_v) {
                                     $va_return_values[(int) $vn_id][$vm_locale_id][(int) $o_attribute->getAttributeID() . "_{$vn_i}"][$vs_element_code] = $vs_v;
                                 }
                             }
                         }
                     }
                     continue;
                 }
                 if (is_null($vs_val_proc)) {
                     switch ($o_value->getType()) {
                         case __CA_ATTRIBUTE_VALUE_LIST__:
                             $t_element = $pt_instance->_getElementInstance($o_value->getElementID());
                             $vn_list_id = $t_element->get('list_id');
                             $vs_val_proc = $o_value->getDisplayValue(array_merge($pa_options, array('output' => $pa_options['output'], 'list_id' => $vn_list_id)));
                             break;
                         case __CA_ATTRIBUTE_VALUE_INFORMATIONSERVICE__:
                             //ca_objects.informationservice.ulan_container
                             // support subfield notations like ca_objects.wikipedia.abstract, but only if we're not already at subfield-level, e.g. ca_objects.container.wikipedia
                             if ($va_path_components['subfield_name'] && $vs_element_code != $va_path_components['subfield_name'] && $vs_element_code == $va_path_components['field_name']) {
                                 $vs_val_proc = $o_value->getExtraInfo($va_path_components['subfield_name']);
                                 $vb_dont_return_value = false;
                                 break;
                             }
                             // support ca_objects.container.wikipedia.abstract
                             if ($vs_element_code == $va_path_components['subfield_name'] && $va_path_components['num_components'] == 4) {
                                 $vs_val_proc = $o_value->getExtraInfo($va_path_components['components'][3]);
                                 $vb_dont_return_value = false;
                                 break;
                             }
                             // support ca_objects.wikipedia or ca_objects.container.wikipedia (Eg. no "extra" value specified)
                             if ($vs_element_code == $va_path_components['field_name'] || $vs_element_code == $va_path_components['subfield_name']) {
                                 $vs_val_proc = $o_value->getDisplayValue(array_merge($pa_options, array('output' => $pa_options['output'])));
                                 $vb_dont_return_value = false;
                                 break;
                             }
                             continue 2;
                         default:
                             $vs_val_proc = $o_value->getDisplayValue(array_merge($pa_options, array('output' => $pa_options['output'])));
                             break;
                     }
                 }
                 if ($vn_attr_type == __CA_ATTRIBUTE_VALUE_CONTAINER__ && !$va_path_components['subfield_name'] && !$pa_options['returnWithStructure']) {
                     if (strlen($vs_val_proc) > 0) {
                         $va_val_proc[] = $vs_val_proc;
                     }
                     $vs_val_proc = join($vs_delimiter, $va_val_proc);
                 }
                 $va_spec = $va_path_components['components'];
                 array_pop($va_spec);
                 $va_acc[join('.', $va_spec) . '.' . $vs_element_code] = $o_value->getDisplayValue(array_merge($pa_options, array('output' => 'idno')));
                 if (!$vb_dont_return_value) {
                     $vb_did_return_value = true;
                     if ($pa_options['makeLink']) {
                         $vs_val_proc = array_shift(caCreateLinksFromText(array($vs_val_proc), $vs_table_name, array($vn_id)));
                     }
                     if ($pa_options['returnWithStructure']) {
                         $va_return_values[(int) $vn_id][$vm_locale_id][(int) $o_attribute->getAttributeID()][$vs_element_code] = $vs_val_proc;
                     } else {
                         $va_return_values[(int) $vn_id][$vm_locale_id][(int) $o_attribute->getAttributeID()] = $vs_val_proc;
                     }
                 }
             }
             if ($va_path_components['subfield_name'] && $pa_options['returnBlankValues'] && !$vb_did_return_value) {
                 // value is missing so insert blank
                 if ($pa_options['returnWithStructure']) {
                     $va_return_values[(int) $vn_id][$vm_locale_id][(int) $o_attribute->getAttributeID()][$va_path_components['subfield_name']] = '';
                 } else {
                     $va_return_values[(int) $vn_id][$vm_locale_id][(int) $o_attribute->getAttributeID()] = '';
                 }
             }
             if ($pa_options['filter']) {
                 $va_tags = caGetTemplateTags($pa_options['filter']);
                 $va_vars = array();
                 foreach ($va_tags as $vs_tag) {
                     if (isset($va_acc[$vs_tag])) {
                         $va_vars[$vs_tag] = $va_acc[$vs_tag];
                     } else {
                         $va_vars[$vs_tag] = $this->get($vs_tag, array('convertCodesToIdno' => true));
                     }
                 }
                 if (ExpressionParser::evaluate($pa_options['filter'], $va_vars)) {
                     unset($va_return_values[(int) $vn_id][$vm_locale_id][(int) $o_attribute->getAttributeID()]);
                     continue;
                 }
             }
         }
     } else {
         // is blank
         if ($pa_options['returnWithStructure'] && $pa_options['returnBlankValues']) {
             $va_return_values[(int) $vn_id][null][null][$va_path_components['subfield_name'] ? $va_path_components['subfield_name'] : $va_path_components['field_name']] = '';
         }
     }
     if (!$pa_options['returnAllLocales']) {
         $va_return_values = caExtractValuesByUserLocale($va_return_values);
     }
     if ($pa_options['returnWithStructure']) {
         return is_array($va_return_values) ? $va_return_values : array();
     }
     //
     // Flatten array for return as string or simple array value
     //
     $va_flattened_values = $this->_flattenArray($va_return_values, $pa_options);
     if ($pa_options['returnAsArray']) {
         return $va_flattened_values;
     } else {
         return sizeof($va_flattened_values) > 0 ? join($pa_options['delimiter'], $va_flattened_values) : null;
     }
 }