/** * 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; }
/** * */ public static function getLocaleList($pa_options = null) { $vs_sort_field = isset($pa_options['sort_field']) ? $pa_options['sort_field'] : ''; $vs_sort_direction = isset($pa_options['sort_direction']) ? $pa_options['sort_direction'] : 'asc'; $vb_index_by_code = isset($pa_options['index_by_code']) && $pa_options['index_by_code'] ? true : false; $vb_return_display_values = isset($pa_options['return_display_values']) && $pa_options['return_display_values'] ? true : false; $vb_available_for_cataloguing_only = isset($pa_options['available_for_cataloguing_only']) && $pa_options['available_for_cataloguing_only'] ? true : false; $va_valid_sorts = array('name', 'language', 'country', 'dialect'); if (!in_array($vs_sort_field, $va_valid_sorts)) { $vs_sort_field = 'name'; } $vs_cache_key = $vs_sort_field . '/' . $vs_sort_direction . '/' . ($vb_index_by_code ? 1 : 0) . '/' . ($vb_return_display_values ? 1 : 0) . '/' . ($vb_available_for_cataloguing_only ? 1 : 0); if (CompositeCache::contains($vs_cache_key, 'LocaleList')) { $va_locales = CompositeCache::fetch($vs_cache_key, 'LocaleList'); // Check if memory cache has been populated with necessary data yet. // This might not be the case if $va_locales comes from disk and the SQL code below was not executed. // Unfortunately the other helpers like loadLocaleByCode() rely on this side-effect of getLocaleList(). if (MemoryCache::itemCountForNamespace('LocaleCodeToId') == 0) { foreach ($va_locales as $va_locale) { if ($vb_available_for_cataloguing_only && $va_locale['dont_use_for_cataloguing']) { continue; } MemoryCache::save($va_locale['language'] . '_' . $va_locale['country'], $va_locale['locale_id'], 'LocaleCodeToId'); MemoryCache::save($va_locale['locale_id'], $va_locale['language'] . '_' . $va_locale['country'], 'LocaleIdToCode'); MemoryCache::save($va_locale['locale_id'], $va_locale['name'], 'LocaleIdToName'); } } return $va_locales; } $o_db = new Db(); $vs_sort = 'ORDER BY ' . $vs_sort_field; $qr_locales = $o_db->query("\n\t\t\tSELECT *\n\t\t\tFROM ca_locales\n\t\t\t{$vs_sort}\n\t\t"); $va_locales = array(); while ($qr_locales->nextRow()) { if ($vb_available_for_cataloguing_only && $qr_locales->get('dont_use_for_cataloguing')) { continue; } $vs_name = $qr_locales->get('name'); if ($vb_return_display_values) { $vm_val = $vs_name; } else { $vm_val = $qr_locales->getRow(); } $vs_code = $qr_locales->get('language') . '_' . $qr_locales->get('country'); $vn_id = $qr_locales->get('locale_id'); if (!$vb_return_display_values) { $vm_val['code'] = $vs_code; } if ($vb_index_by_code) { $va_locales[$vs_code] = $vm_val; } else { $va_locales[$vn_id] = $vm_val; } MemoryCache::save($vs_code, $vn_id, 'LocaleCodeToId'); MemoryCache::save($vn_id, $vs_code, 'LocaleIdToCode'); MemoryCache::save($vn_id, $vs_name, 'LocaleIdToName'); } CompositeCache::save($vs_cache_key, $va_locales, 'LocaleList'); return $va_locales; }