/** * * * @param string $ps_refinery_name * @param string $ps_table * @param array $pa_parents * @param array $pa_source_data * @param array $pa_item * @param int $pn_c * @param KLogger $o_log * * @return int */ function caProcessRefineryParents($ps_refinery_name, $ps_table, $pa_parents, $pa_source_data, $pa_item, $pn_c, $pa_options = null) { global $g_ui_locale_id; if (!is_array($pa_options)) { $pa_options = array(); } $o_log = caGetOption('log', $pa_options, null); $o_reader = caGetOption('reader', $pa_options, null); $o_trans = caGetOption('transaction', $pa_options, null); $vn_list_id = caGetOption('list_id', $pa_options, null); $vb_hierarchy_mode = caGetOption('hierarchyMode', $pa_options, false); if (!is_array($pa_parents)) { $pa_parents = array($pa_parents); } $vn_id = null; $pa_parents = array_reverse($pa_parents); foreach ($pa_parents as $vn_i => $va_parent) { if (!is_array($va_parent)) { $o_log->logWarn(_t('[%2] Parents options invalid. Did you forget to pass a list? Parents list passed was: %1', print_r($pa_parents, true), $ps_refinery_name)); break; } $vs_name = BaseRefinery::parsePlaceholder($va_parent['name'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); $vs_idno = BaseRefinery::parsePlaceholder($va_parent['idno'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); $vs_type = BaseRefinery::parsePlaceholder($va_parent['type'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); if (!$vs_name && !$vs_idno) { continue; } if (!$vs_name) { continue; } //$vs_name = $vs_idno; } $va_attributes = isset($va_parent['attributes']) && is_array($va_parent['attributes']) ? $va_parent['attributes'] : array(); foreach ($va_attributes as $vs_element_code => $va_attrs) { if (is_array($va_attrs)) { foreach ($va_attrs as $vs_k => $vs_v) { // BaseRefinery::parsePlaceholder may return an array if the input format supports repeated values (as XML does) // DataMigrationUtils::getCollectionID(), which ca_data_importers::importDataFromSource() uses to create related collections // only supports non-repeating attribute values, so we join any values here and call it a day. $va_attributes[$vs_element_code][$vs_k] = BaseRefinery::parsePlaceholder($vs_v, $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); } } else { $va_attributes[$vs_element_code] = array($vs_element_code => BaseRefinery::parsePlaceholder($va_attrs, $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' '))); } } $va_attributes['idno'] = $vs_idno; $va_attributes['parent_id'] = $vn_id; if (isset($va_parent['rules']) && is_array($va_parent['rules'])) { foreach ($va_parent['rules'] as $va_rule) { $vm_ret = ExpressionParser::evaluate($va_rule['trigger'], $pa_source_data); if (!ExpressionParser::hadError() && (bool) $vm_ret) { foreach ($va_rule['actions'] as $va_action) { if (!is_array($va_action) && strtolower($va_action) == 'skip') { $va_action = array('action' => 'skip'); } switch ($vs_action_code = strtolower($va_action['action'])) { case 'set': switch ($va_action['target']) { case 'name': $vs_name = BaseRefinery::parsePlaceholder($va_action['value'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); break; case 'type': $vs_type = BaseRefinery::parsePlaceholder($va_action['value'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); break; default: $va_attributes[$va_action['target']] = BaseRefinery::parsePlaceholder($va_action['value'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); break; } break; case 'skip': default: if ($o_log) { if ($vs_action_code != 'skip') { $o_log->logInfo(_t('[%3] Parent was skipped using rule "%1" with default action because an invalid action ("%2") was specified', $va_rule['trigger'], $vs_action_code, $ps_refinery_name)); } else { $o_log->logDebug(_t('[%3] Parent was skipped using rule "%1" with action "%2"', $va_rule['trigger'], $vs_action_code, $ps_refinery_name)); } } continue 4; break; } } } elseif (ExpressionParser::hadError() && $o_log) { $o_log->logError(_t('[%3] Error processing rule "%1" as an error occurred. Error number was "%2"', $va_rule['trigger'], ExpressionParser::$s_last_error, $ps_refinery_name)); } } } $va_match_on = caGetOption("{$ps_refinery_name}_dontMatchOnLabel", $pa_item['settings'], false) ? array('idno') : array('idno', 'label'); $pa_options = array_merge(array('matchOn' => $va_match_on), $pa_options); switch ($ps_table) { case 'ca_objects': $vn_id = DataMigrationUtils::getObjectID($vs_name, $vn_id, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_entities': $vn_id = DataMigrationUtils::getEntityID($va_entity_label = DataMigrationUtils::splitEntityName($vs_name, $pa_options), $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels'] = $va_entity_label; $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_places': if (!$vn_id) { // get place hierarchy root require_once __CA_MODELS_DIR__ . "/ca_places.php"; $t_place = new ca_places(); if ($o_trans) { $t_place->setTransaction($o_trans); } $vn_id = $pa_options['defaultParentID']; if (!$vn_id) { $vn_id = $t_place->getHierarchyRootID($pa_options['hierarchyID']); } $va_attributes['parent_id'] = $vn_id; } $vn_id = DataMigrationUtils::getPlaceID($vs_name, $vn_id, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_occurrences': $vn_id = DataMigrationUtils::getOccurrenceID($vs_name, $vn_id, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_collections': $vn_id = DataMigrationUtils::getCollectionID($vs_name, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_loans': $vn_id = DataMigrationUtils::getLoanID($vs_name, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_movements': $vn_id = DataMigrationUtils::getMovementID($vs_name, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_list_items': if (!$vn_list_id) { if ($o_log) { $o_log->logDebug(_t('[importHelpers:caProcessRefineryParents] List was not specified')); } return null; } if (!$vn_id) { // get place hierarchy root require_once __CA_MODELS_DIR__ . "/ca_lists.php"; $t_list = new ca_lists(); if ($o_trans) { $t_list->setTransaction($o_trans); } $vn_id = $t_list->getRootItemIDForList($vn_list_id); $va_attributes['parent_id'] = $vn_id; } $vn_id = DataMigrationUtils::getListItemID($vn_list_id, $vs_name, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name_singular'] = $va_attributes['preferred_labels']['name_plural'] = $vs_name; break; case 'ca_storage_locations': if (!$vn_id) { // get storage location hierarchy root require_once __CA_MODELS_DIR__ . "/ca_storage_locations.php"; $t_loc = new ca_storage_locations(); if ($o_trans) { $t_loc->setTransaction($o_trans); } $vn_id = $t_loc->getHierarchyRootID(); $va_attributes['parent_id'] = $vn_id; } $vn_id = DataMigrationUtils::getStorageLocationID($vs_name, $vn_id, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; default: if ($o_log) { $o_log->logDebug(_t('[importHelpers:caProcessRefineryParents] Invalid table %1', $ps_table)); } return null; break; } $va_attributes['locale_id'] = $g_ui_locale_id; if ($o_log) { $o_log->logDebug(_t('[%6] Got parent %1 (%2) with id %3 and type %4 for %5', $vs_name, $vs_idno, $vn_id, $vs_type, $vs_name, $ps_refinery_name)); } } if ($vb_hierarchy_mode) { return $va_attributes; } return $vn_id; }
public function _genTypeNav($pa_params) { $t_subject = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true); $t_list = new ca_lists(); $t_list->load(array('list_code' => $t_subject->getTypeListCode())); $t_list_item = new ca_list_items(); $t_list_item->load(array('list_id' => $t_list->getPrimaryKey(), 'parent_id' => null)); $va_hier = caExtractValuesByUserLocale($t_list_item->getHierarchyWithLabels()); $va_restrict_to_types = null; if ($t_subject->getAppConfig()->get('perform_type_access_checking')) { $va_restrict_to_types = caGetTypeRestrictionsForUser($this->ops_tablename, array('access' => __CA_BUNDLE_ACCESS_READONLY__)); } $va_types = array(); if (is_array($va_hier)) { $va_types_by_parent_id = array(); $vn_root_id = $t_list->getRootItemIDForList($t_subject->getTypeListCode()); // organize items by parent id, exclude root foreach ($va_hier as $vn_item_id => $va_item) { if ($vn_item_id == $vn_root_id) { continue; } // skip root if (is_array($va_restrict_to_types) && !in_array($vn_item_id, $va_restrict_to_types)) { continue; } $va_types_by_parent_id[$va_item['parent_id']][] = $va_item; } foreach ($va_hier as $vn_item_id => $va_item) { if (is_array($va_restrict_to_types) && !in_array($vn_item_id, $va_restrict_to_types)) { continue; } if ($va_item['parent_id'] != $vn_root_id) { continue; } // does this item have sub-items? if (isset($va_item['item_id']) && isset($va_types_by_parent_id[$va_item['item_id']]) && is_array($va_types_by_parent_id[$va_item['item_id']])) { $va_subtypes = $this->_getSubTypes($va_types_by_parent_id[$va_item['item_id']], $va_types_by_parent_id, $va_restrict_to_types); } else { $va_subtypes = array(); } $va_types[] = array('displayName' => $va_item['name_plural'], 'parameters' => array('type_id' => $va_item['item_id']), 'is_enabled' => $va_item['is_enabled'], 'navigation' => $va_subtypes); } } return $va_types; }
/** * Returns navigation fragment for types and subtypes of a given primary item type (Eg. ca_objects). Used to generate dynamic type menus * from database by AppNavigation class. * * @param array $pa_params Array of parameters used to generate menu * @return array List of types with subtypes ready for inclusion in a menu spec */ public function _genTypeNav($pa_params) { $t_subject = $this->opo_datamodel->getInstanceByTableName($this->ops_table_name, true); $t_list = new ca_lists(); $t_list->load(array('list_code' => $t_subject->getTypeListCode())); $t_list_item = new ca_list_items(); $t_list_item->load(array('list_id' => $t_list->getPrimaryKey(), 'parent_id' => null)); $va_hier = caExtractValuesByUserLocale($t_list_item->getHierarchyWithLabels()); $vn_sort_type = $t_list->get('default_sort'); $va_restrict_to_types = null; if ($t_subject->getAppConfig()->get('perform_type_access_checking')) { $va_restrict_to_types = caGetTypeRestrictionsForUser($this->ops_table_name, array('access' => __CA_BUNDLE_ACCESS_EDIT__)); } $va_types = array(); if (is_array($va_hier)) { $va_types_by_parent_id = array(); $vn_root_id = $t_list->getRootItemIDForList($t_subject->getTypeListCode()); foreach ($va_hier as $vn_item_id => $va_item) { if ($vn_item_id == $vn_root_id) { continue; } // skip root $va_types_by_parent_id[$va_item['parent_id']][] = $va_item; } foreach ($va_hier as $vn_item_id => $va_item) { if (is_array($va_restrict_to_types) && !in_array($vn_item_id, $va_restrict_to_types)) { continue; } if ($va_item['parent_id'] != $vn_root_id) { continue; } // does this item have sub-items? $va_subtypes = array(); if (!(bool) $this->getRequest()->config->get($this->ops_table_name . '_navigation_new_menu_shows_top_level_types_only') && !(bool) $this->getRequest()->config->get($this->ops_table_name . '_enforce_strict_type_hierarchy')) { if (isset($va_item['item_id']) && isset($va_types_by_parent_id[$va_item['item_id']]) && is_array($va_types_by_parent_id[$va_item['item_id']])) { $va_subtypes = $this->_getSubTypes($va_types_by_parent_id[$va_item['item_id']], $va_types_by_parent_id, $vn_sort_type, $va_restrict_to_types); } } switch ($vn_sort_type) { case 0: // label // label default: $vs_key = $va_item['name_singular']; break; case 1: // rank $vs_key = sprintf("%08d", (int) $va_item['rank']); break; case 2: // value $vs_key = $va_item['item_value']; break; case 3: // identifier $vs_key = $va_item['idno_sort']; break; } $va_types[$vs_key][] = array('displayName' => $va_item['name_singular'], 'parameters' => array('type_id' => $va_item['item_id']), 'is_enabled' => $va_item['is_enabled'], 'navigation' => $va_subtypes); } ksort($va_types); } $va_types_proc = array(); foreach ($va_types as $vs_sort_key => $va_items) { foreach ($va_items as $vn_i => $va_item) { $va_types_proc[] = $va_item; } } return $va_types_proc; }
public function getListsAsDOM() { $qr_lists = $this->opo_db->query("SELECT * FROM ca_lists ORDER BY list_id"); $vo_lists = $this->opo_dom->createElement("lists"); $t_list = new ca_lists(); while ($qr_lists->nextRow()) { $vo_list = $this->opo_dom->createElement("list"); $vo_list->setAttribute("code", $this->makeIDNOFromInstance($qr_lists, 'list_code')); $vo_list->setAttribute("hierarchical", $qr_lists->get("is_hierarchical")); $vo_list->setAttribute("system", $qr_lists->get("is_system_list")); $vo_list->setAttribute("vocabulary", $qr_lists->get("use_as_vocabulary")); if ($qr_lists->get("default_sort")) { $vo_list->setAttribute("defaultSort", $qr_lists->get("default_sort")); } $vo_labels = $this->opo_dom->createElement("labels"); $qr_list_labels = $this->opo_db->query("SELECT * FROM ca_list_labels WHERE list_id=?", $qr_lists->get("list_id")); // label-less lists are ignored if ($qr_list_labels->numRows() == 0) { continue; } else { while ($qr_list_labels->nextRow()) { $vo_label = $this->opo_dom->createElement("label"); $vo_label->setAttribute("locale", $this->opt_locale->localeIDToCode($qr_list_labels->get("locale_id"))); $vo_label->appendChild($this->opo_dom->createElement("name", caEscapeForXML($qr_list_labels->get("name")))); $vo_labels->appendChild($vo_label); } } $vo_list->appendChild($vo_labels); $vo_items = $this->getListItemsAsDOM($t_list->getRootItemIDForList($qr_lists->get("list_code"))); if ($vo_items) { $vo_list->appendChild($vo_items); } $vo_lists->appendChild($vo_list); } return $vo_lists; }
$vs_title = $this->getVar('label'); $va_access_values = $this->getVar('access_values'); JavascriptLoadManager::register('tabUI'); JavascriptLoadManager::register('formUI'); $qr_hits = $this->getVar('browse_results'); $va_items = array(); $va_item_classifications = array(); if ($qr_hits->numHits()) { while ($qr_hits->nextHit()) { $va_items[$qr_hits->get("ca_objects.showcase_classification")][] = array("object_id" => $qr_hits->get("ca_objects.object_id"), "label" => join($qr_hits->getDisplayLabels(), "; "), "image" => $qr_hits->getMediaTag('ca_object_representations.media', 'widepreview', array('checkAccess' => $va_access_values)), "classification" => $qr_hits->get("ca_objects.showcase_classification", array('convertCodesToDisplayText' => true))); } $va_item_classifications = array_keys($va_items); } # -- get the top level showcase classifications to display as tabs containing items with that showcase classification $o_lists = new ca_lists(); $vn_root_node = $o_lists->getRootItemIDForList("archival_showcase_classification"); $va_classification_for_tabs = caExtractValuesByUserLocale($o_lists->getChildItemsForList("archival_showcase_classification", $vn_root_node, array('directChildrenOnly' => true))); ?> <div id="collectionDetail"><div style="float:left;"> <div class="maincolimage" style="margin-top:16px;"> <?php print $t_collection->get("showcase_banner", array("version" => "original", "showMediaInfo" => false)); ?> </div><!-- end mailcolImage --> <div class="maincol"> <h1><?php print $vs_title; ?> </h1>