/** * */ private static function _getValues(SearchResult $pr_res, array $pa_tags, array $pa_options = null) { unset($pa_options['returnAsArray']); unset($pa_options['returnWithStructure']); $vn_start = caGetOption('unitStart', $pa_options, 0, ['castTo' => 'int']); $vn_length = caGetOption('unitLength', $pa_options, 0, ['castTo' => 'int']); $o_dm = Datamodel::load(); $pb_include_blanks = caGetOption('includeBlankValuesInArray', $pa_options, false); $ps_prefix = caGetOption(['placeholderPrefix', 'relativeTo', 'prefix'], $pa_options, null); $pn_index = caGetOption('index', $pa_options, null); $vs_cache_key = md5($pr_res->tableName() . "/" . $pr_res->getPrimaryKey() . "/" . print_r($pa_tags, true) . "/" . print_r($pa_options, true)); $va_get_specs = []; foreach (array_keys($pa_tags) as $vs_tag) { // Apply placeholder prefix to any tag except the "specials" if (!in_array(strtolower($vs_tag), ['relationship_typename', 'relationship_type_id', 'relationship_typecode', 'relationship_type_code', 'date', 'primary', 'count', 'index', 'omitcount'])) { $va_tag = explode(".", $vs_tag); $vs_get_spec = $vs_tag; if ($ps_prefix && !$o_dm->tableExists($va_tag[0]) && !preg_match("!^" . preg_quote($ps_prefix, "!") . "\\.!", $vs_tag) && sizeof($va_tag) > 0) { $vs_get_spec = "{$ps_prefix}." . array_shift($va_tag); if (sizeof($va_tag) > 0) { $vs_get_spec .= "." . join(".", $va_tag); } } } else { $vs_get_spec = $vs_tag; } // Get trailing options (eg. ca_entities.preferred_labels.displayname%delimiter=;_) if (is_array($va_parsed_tag_opts = DisplayTemplateParser::_parseTagOpts($vs_get_spec))) { $vs_get_spec = $va_parsed_tag_opts['tag']; } $va_get_specs[$vs_tag] = ['spec' => $vs_get_spec, 'parsed' => $va_parsed_tag_opts]; } $vn_count = 1; $va_tag_vals = null; if ($vs_relative_to_container = caGetOption('relativeToContainer', $pa_options, null)) { if (DisplayTemplateParser::$value_cache[$vs_cache_key]) { $va_tag_vals = DisplayTemplateParser::$value_cache[$vs_cache_key]; $vn_count = DisplayTemplateParser::$value_count_cache[$vs_cache_key]; } else { $va_tag_vals = []; foreach (array_keys($pa_tags) as $vs_tag) { $vs_get_spec = $va_get_specs[$vs_tag]['spec']; $va_parsed_tag_opts = $va_get_specs[$vs_tag]['parsed']; $va_vals = $pr_res->get($vs_get_spec, array_merge($pa_options, $va_parsed_tag_opts['options'], ['returnAsArray' => true, 'returnBlankValues' => true])); if (is_array($va_vals)) { if (($vn_start > 0 || $vn_length > 0) && $vn_start < sizeof($va_vals) && (!$vn_length || $vn_start + $vn_length <= sizeof($va_vals))) { $va_vals = array_slice($va_vals, $vn_start, $vn_length > 0 ? $vn_length : null); } foreach ($va_vals as $vn_index => $vs_val) { $va_tag_vals[$vn_index][$vs_tag] = $vs_val; } } } if (isset($pa_options['sort']) && is_array($pa_options['sort']) && sizeof($pa_options['sort'])) { $va_sortables = array(); foreach ($pa_options['sort'] as $vs_sort_spec) { $va_sortables[] = $pr_res->get($vs_sort_spec, ['sortable' => true, 'returnAsArray' => true, 'returnBlankValues' => true]); } if (($vn_start > 0 || $vn_length > 0) && $vn_start < sizeof($va_sortables) && (!$vn_length || $vn_start + $vn_length <= sizeof($va_sortables))) { $va_sortables = array_slice($va_sortables, $vn_start, $vn_length > 0 ? $vn_length : null); } if (is_array($va_sortables)) { foreach ($va_sortables as $i => $va_sort_values) { if (!is_array($va_sort_values)) { continue; } foreach ($va_sort_values as $vn_index => $vs_sort_value) { $va_tag_vals[$vn_index]['__sort__'] .= $vs_sort_value; } } } } DisplayTemplateParser::$value_cache[$vs_cache_key] = $va_tag_vals; DisplayTemplateParser::$value_count_cache[$vs_cache_key] = $vn_count = sizeof($va_tag_vals); } if (strlen($pn_index)) { $va_tag_vals = $va_tag_vals[$pn_index]; $vs_relative_to_container = null; } } $va_vals = []; for ($vn_c = 0; $vn_c < $vn_count; $vn_c++) { foreach (array_keys($pa_tags) as $vs_tag) { $vs_get_spec = $va_get_specs[$vs_tag]['spec']; $va_parsed_tag_opts = $va_get_specs[$vs_tag]['parsed']; switch (strtolower($vs_get_spec)) { case 'relationship_typename': $va_val_list = $pr_res->get('ca_relationship_types.preferred_labels.' . (caGetOption('orientation', $pa_options, 'LTOR') == 'LTOR' ? 'typename' : 'typename_reverse'), $va_opts = array_merge($pa_options, $va_parsed_tag_opts['options'], ['returnAsArray' => true, 'returnWithStructure' => false])); break; case 'relationship_type_id': $va_val_list = $pr_res->get('ca_relationship_types.type_id', $va_opts = array_merge($pa_options, $va_parsed_tag_opts['options'], ['returnAsArray' => true, 'returnWithStructure' => false])); break; case 'relationship_typecode': case 'relationship_type_code': $va_val_list = $pr_res->get('ca_relationship_types.type_code', $va_opts = array_merge($pa_options, $va_parsed_tag_opts['options'], ['returnAsArray' => true, 'returnWithStructure' => false])); break; case 'date': // allows embedding of current date $va_val_list = [date(caGetOption('format', $va_parsed_tag_opts['options'], 'd M Y'))]; break; case 'primary': $va_val_list = [$pr_res->tableName()]; break; case 'count': $va_val_list = [$pr_res->numHits()]; break; case 'omitcount': $va_val_list = [(int) $pr_res->numHits() - ($vn_length - $vn_start)]; break; case 'index': $va_val_list = [$pr_res->currentIndex() + 1]; break; default: if (isset($pa_options['forceValues'][$vs_get_spec][$pr_res->getPrimaryKey()])) { $va_val_list = [$pa_options['forceValues'][$vs_get_spec][$pr_res->getPrimaryKey()]]; } elseif ($vs_relative_to_container) { $va_val_list = [$va_tag_vals[$vn_c][$vs_tag]]; } elseif (strlen($pn_index)) { $va_val_list = [$va_tag_vals[$vs_tag]]; } else { $va_val_list = $pr_res->get($vs_get_spec, $va_opts = array_merge($pa_options, $va_parsed_tag_opts['options'], ['returnAsArray' => true, 'returnWithStructure' => false])); if (!is_array($va_val_list)) { $va_val_list = array(); } if (($vn_start > 0 || $vn_length > 0) && $vn_start < sizeof($va_val_list) && (!$vn_length || $vn_start + $vn_length <= sizeof($va_val_list))) { $va_val_list = array_slice($va_val_list, $vn_start, $vn_length > 0 ? $vn_length : null); } } break; } $ps_delimiter = caGetOption('delimiter', $va_opts, ';'); if ($vs_relative_to_container) { $va_vals[$vn_c][$vs_tag] = join($ps_delimiter, $va_val_list); if (isset($va_tag_vals[$vn_c]['__sort__'])) { $va_vals[$vn_c]['__sort__'] = $va_tag_vals[$vn_c]['__sort__']; } } else { if (!$pb_include_blanks) { $va_val_list = array_filter($va_val_list, 'strlen'); } $va_vals[$vs_tag] = join($ps_delimiter, $va_val_list); if (isset($va_tag_vals[$vn_c]['__sort__'])) { $va_vals['__sort__'] = $va_tag_vals[$vn_c]['__sort__']; } } } } return $va_vals; }