public function info($pa_parameters) { parent::info($pa_parameters); if ($t_item = $this->view->getVar('t_item')) { if (!($vn_tour_id = $t_item->get('tour_id'))) { $t_parent = new ca_list_items($this->request->getParameter('parent_id', pInteger)); $vn_tour_id = $t_parent->get('tour_id'); } } $t_tour = new ca_tours($vn_tour_id); $this->view->setVar('t_tour', $t_tour); return $this->render('widget_tour_stop_info_html.php', true); }
/** * Returns string representing the name of the item the browse will return * * If $ps_mode is 'singular' [default] then the singular version of the name is returned, otherwise the plural is returned */ public function browseName($ps_mode = 'singular') { $vb_type_restriction_has_changed = false; $vn_type_id = $this->opo_result_context->getTypeRestriction($vb_type_restriction_has_changed); $t_list = new ca_lists(); $t_list->load(array('list_code' => 'occurrence_types')); $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()); if (!($vs_name = $ps_mode == 'singular' ? $va_hier[$vn_type_id]['name_singular'] : $va_hier[$vn_type_id]['name_plural'])) { $vs_name = '???'; } return $vs_name; }
public function info($pa_parameters) { parent::info($pa_parameters); $t_list = $this->view->getVar('t_item'); if ($t_list->getPrimaryKey()) { $va_labels = $t_list->getDisplayLabels(); $this->view->setVar('labels', $t_list->getPrimaryKey() ? $va_labels : array()); $this->view->setVar('idno', $t_list->get('idno')); } $t_list_item = new ca_list_items(); $t_list_item->load(array('list_id' => $t_list->getPrimaryKey(), 'parent_id' => null)); $this->view->setVar('t_list_item', $t_list_item); if ($vn_item_id = $t_list_item->getPrimaryKey()) { $va_children = caExtractValuesByUserLocaleFromHierarchyChildList($t_list_item->getHierarchyChildren(null, array('additionalTableToJoin' => 'ca_list_item_labels', 'additionalTableJoinType' => 'LEFT', 'additionalTableSelectFields' => array('name_plural', 'locale_id'), 'additionalTableWheres' => array('(ca_list_item_labels.is_preferred = 1 OR ca_list_item_labels.is_preferred IS NULL)'))), 'item_id', 'name_plural', 'item_value'); $this->view->setVar('children', $va_children); } return $this->render('widget_list_info_html.php', true); }
/** * Returns or Creates a list item or list item id matching the parameters and options provided * @param string/int $pm_list_code_or_id * @param string $ps_item_idno * @param string/int $pn_type_id * @param int $pn_locale_id * @param null/array $pa_values * @param array $pa_options An optional array of options. See DataMigrationUtils::_getID() for a list. * @return bool|ca_list_items|mixed|null * * @see DataMigrationUtils::_getID() */ static function getListItemID($pm_list_code_or_id, $ps_item_idno, $pn_type_id, $pn_locale_id, $pa_values = null, $pa_options = null) { if (!is_array($pa_options)) { $pa_options = array(); } $pb_output_errors = caGetOption('outputErrors', $pa_options, false); $pa_match_on = caGetOption('matchOn', $pa_options, array('label', 'idno'), array('castTo' => "array")); $vn_parent_id = caGetOption('parent_id', $pa_values, false); $vs_singular_label = isset($pa_values['preferred_labels']['name_singular']) && $pa_values['preferred_labels']['name_singular'] ? $pa_values['preferred_labels']['name_singular'] : ''; if (!$vs_singular_label) { $vs_singular_label = isset($pa_values['name_singular']) && $pa_values['name_singular'] ? $pa_values['name_singular'] : str_replace("_", " ", $ps_item_idno); } $vs_plural_label = isset($pa_values['preferred_labels']['name_plural']) && $pa_values['preferred_labels']['name_plural'] ? $pa_values['preferred_labels']['name_plural'] : ''; if (!$vs_plural_label) { $vs_plural_label = isset($pa_values['name_plural']) && $pa_values['name_plural'] ? $pa_values['name_plural'] : str_replace("_", " ", $ps_item_idno); } if (!$vs_singular_label) { $vs_singular_label = $vs_plural_label; } if (!$vs_plural_label) { $vs_plural_label = $vs_singular_label; } if (!$ps_item_idno) { $ps_item_idno = $vs_plural_label; } if (!isset($pa_options['cache'])) { $pa_options['cache'] = true; } // Create cache key $vs_cache_key = md5($pm_list_code_or_id . '/' . $ps_item_idno . '/' . $vn_parent_id . '/' . $vs_singular_label . '/' . $vs_plural_label . '/' . json_encode($pa_match_on)); $o_event = isset($pa_options['importEvent']) && $pa_options['importEvent'] instanceof ca_data_import_events ? $pa_options['importEvent'] : null; $ps_event_source = isset($pa_options['importEventSource']) && $pa_options['importEventSource'] ? $pa_options['importEventSource'] : "?"; /** @var KLogger $o_log */ $o_log = isset($pa_options['log']) && $pa_options['log'] instanceof KLogger ? $pa_options['log'] : null; if ($pa_options['cache'] && isset(DataMigrationUtils::$s_cached_list_item_ids[$vs_cache_key])) { if (isset($pa_options['returnInstance']) && $pa_options['returnInstance']) { $t_item = new ca_list_items(DataMigrationUtils::$s_cached_list_item_ids[$vs_cache_key]); if (isset($pa_options['transaction']) && $pa_options['transaction'] instanceof Transaction) { $t_item->setTransaction($pa_options['transaction']); } return $t_item; } if ($o_event) { $o_event->beginItem($ps_event_source, 'ca_list_items', 'U'); $o_event->endItem(DataMigrationUtils::$s_cached_list_item_ids[$vs_cache_key], __CA_DATA_IMPORT_ITEM_SUCCESS__, ''); } if ($o_log) { $o_log->logDebug(_t("Found existing list item %1 (member of list %2) in DataMigrationUtils::getListItemID() using idno", $ps_item_idno, $pm_list_code_or_id)); } return DataMigrationUtils::$s_cached_list_item_ids[$vs_cache_key]; } if (!($vn_list_id = ca_lists::getListID($pm_list_code_or_id))) { if ($pb_output_errors) { print "[Error] " . _t("Could not find list with list code %1", $pm_list_code_or_id) . "\n"; } if ($o_log) { $o_log->logError(_t("Could not find list with list code %1", $pm_list_code_or_id)); } return DataMigrationUtils::$s_cached_list_item_ids[$vs_cache_key] = null; } if (!$vn_parent_id && $vn_parent_id !== false) { $vn_parent_id = caGetListRootID($pm_list_code_or_id); } $t_list = new ca_lists(); $t_item = new ca_list_items(); if (isset($pa_options['transaction']) && $pa_options['transaction'] instanceof Transaction) { $t_list->setTransaction($pa_options['transaction']); $t_item->setTransaction($pa_options['transaction']); if ($o_event) { $o_event->setTransaction($pa_options['transaction']); } } $vn_item_id = null; foreach ($pa_match_on as $vs_match_on) { switch (strtolower($vs_match_on)) { case 'label': case 'labels': if (trim($vs_singular_label) || trim($vs_plural_label)) { $va_criteria = array('preferred_labels' => array('name_singular' => $vs_singular_label), 'list_id' => $vn_list_id); if ($vn_parent_id !== false) { $va_criteria['parent_id'] = $vn_parent_id; } if ($vn_item_id = ca_list_items::find($va_criteria, array('returnAs' => 'firstId', 'purifyWithFallback' => true, 'transaction' => $pa_options['transaction']))) { if ($o_log) { $o_log->logDebug(_t("Found existing list item %1 (member of list %2) in DataMigrationUtils::getListItemID() using singular label %3", $ps_item_idno, $pm_list_code_or_id, $vs_singular_label)); } break 2; } else { $va_criteria['preferred_labels'] = array('name_plural' => $vs_plural_label); if ($vn_item_id = ca_list_items::find($va_criteria, array('returnAs' => 'firstId', 'purifyWithFallback' => true, 'transaction' => $pa_options['transaction']))) { if ($o_log) { $o_log->logDebug(_t("Found existing list item %1 (member of list %2) in DataMigrationUtils::getListItemID() using plural label %3", $ps_item_idno, $pm_list_code_or_id, $vs_plural_label)); } break 2; } } break; } case 'idno': if ($ps_item_idno == '%') { break; } // don't try to match on an unreplaced idno placeholder $va_criteria = array('idno' => $ps_item_idno ? $ps_item_idno : $vs_plural_label, 'list_id' => $vn_list_id); if ($vn_parent_id !== false) { $va_criteria['parent_id'] = $vn_parent_id; } if ($vn_item_id = ca_list_items::find($va_criteria, array('returnAs' => 'firstId', 'purifyWithFallback' => true, 'transaction' => $pa_options['transaction']))) { if ($o_log) { $o_log->logDebug(_t("Found existing list item %1 (member of list %2) in DataMigrationUtils::getListItemID() using idno with %3", $ps_item_idno, $pm_list_code_or_id, $ps_item_idno)); } break 2; } break; } } if ($vn_item_id) { DataMigrationUtils::$s_cached_list_item_ids[$vs_cache_key] = $vn_item_id; if ($o_event) { $o_event->beginItem($ps_event_source, 'ca_list_items', 'U'); $o_event->endItem($vn_item_id, __CA_DATA_IMPORT_ITEM_SUCCESS__, ''); } if (($vb_force_update = caGetOption('forceUpdate', $pa_options, false)) || ($vb_return_instance = caGetOption('returnInstance', $pa_options, false))) { $vb_has_attr = false; if ($vb_force_update) { foreach ($pa_values as $vs_element => $va_values) { if ($t_item->hasElement($vs_element)) { $vb_has_attr = true; break; } } } if ($vb_return_instance || $vb_force_update && $vb_has_attr) { $t_item = new ca_list_items($vn_item_id); if (isset($pa_options['transaction']) && $pa_options['transaction'] instanceof Transaction) { $t_item->setTransaction($pa_options['transaction']); } } $vb_attr_errors = false; if ($vb_force_update && $vb_has_attr) { $vb_attr_errors = !DataMigrationUtils::_setAttributes($t_item, $pn_locale_id, $pa_values, $pa_options); } if ($o_event) { if ($vb_attr_errors) { $o_event->endItem($vn_item_id, __CA_DATA_IMPORT_ITEM_PARTIAL_SUCCESS__, _t("Errors setting field values: %1", join('; ', $t_item->getErrors()))); } else { $o_event->endItem($vn_item_id, __CA_DATA_IMPORT_ITEM_SUCCESS__, ''); } } if ($vb_return_instance) { return $t_item; } } return $vn_item_id; } if (isset($pa_options['dontCreate']) && $pa_options['dontCreate']) { return false; } // // Need to create list item // if (!$t_list->load($vn_list_id)) { if ($o_log) { $o_log->logError(_t("Could not find list with list id %1", $vn_list_id)); } return null; } if ($o_event) { $o_event->beginItem($ps_event_source, 'ca_list_items', 'I'); } if ($t_item = $t_list->addItem($ps_item_idno, $pa_values['is_enabled'], $pa_values['is_default'], $vn_parent_id, $pn_type_id, $ps_item_idno, '', (int) $pa_values['status'], (int) $pa_values['access'], $pa_values['rank'])) { $vb_label_errors = false; $t_item->addLabel(array('name_singular' => $vs_singular_label, 'name_plural' => $vs_plural_label), $pn_locale_id, null, true); if ($t_item->numErrors()) { if ($pb_output_errors) { print "[Error] " . _t("Could not set preferred label for list item %1: %2", "{$vs_singular_label}/{$vs_plural_label}/{$ps_item_idno}", join('; ', $t_item->getErrors())) . "\n"; } if ($o_log) { $o_log->logError(_t("Could not set preferred label for list item %1: %2", "{$vs_singular_label}/{$vs_plural_label}/{$ps_item_idno}", join('; ', $t_item->getErrors()))); } $vb_label_errors = true; } unset($pa_values['access']); unset($pa_values['status']); unset($pa_values['idno']); unset($pa_values['source_id']); $vb_attr_errors = !DataMigrationUtils::_setAttributes($t_item, $pn_locale_id, $pa_values, $pa_options); DataMigrationUtils::_setNonPreferredLabels($t_item, $pn_locale_id, $pa_options); DataMigrationUtils::_setIdno($t_item, $ps_item_idno, $pa_options); $vn_item_id = DataMigrationUtils::$s_cached_list_item_ids[$vs_cache_key] = $t_item->getPrimaryKey(); if ($o_event) { if ($vb_attr_errors || $vb_label_errors) { $o_event->endItem($vn_item_id, __CA_DATA_IMPORT_ITEM_PARTIAL_SUCCESS__, _t("Errors setting field values: %1", join('; ', $t_item->getErrors()))); } else { $o_event->endItem($vn_item_id, __CA_DATA_IMPORT_ITEM_SUCCESS__, ''); } } if ($o_log) { $o_log->logInfo(_t("Created new list item %1 in list %2", "{$vs_singular_label}/{$vs_plural_label}/{$ps_item_idno}", $pm_list_code_or_id)); } if (isset($pa_options['returnInstance']) && $pa_options['returnInstance']) { return $t_item; } return $vn_item_id; } else { if ($o_log) { $o_log->logError(_t("Could not find add item to list: %1", join("; ", $t_list->getErrors()))); } } return null; }
/** * Indexes single row in a table; this is the public call when one needs to index content. * indexRow() will analyze the dependencies of the row being indexed and automatically * apply the indexing of the row to all dependent rows in other tables. (Note that while I call this * a "public" call in fact you shouldn't need to call this directly. BaseModel.php does this for you * during insert() and update().) * * For example, if you are indexing a row in table 'entities', then indexRow() * will automatically apply the indexing not just to the entities record, but also * to all objects, place_names, occurrences, lots, etc. that reference the entity. * The dependencies are configured in the search_indices.conf configuration file. * * "subject" tablenum/row_id refer to the row **to which the indexing is being applied**. This may be the row being indexed * or it may be a dependent row. The "content" tablenum/fieldnum/row_id parameters define the specific row and field being indexed. * This is always the actual row being indexed. $pm_content is the content to be indexed and $pa_options is an optional associative * array of indexing options passed through from the search_indices.conf (no options are defined yet - but will be soon) */ public function indexRow($pn_subject_tablenum, $pn_subject_row_id, $pa_field_data, $pb_reindex_mode = false, $pa_exclusion_list = null, $pa_changed_fields = null, $pa_old_values = null, $pa_options = null) { if (!$pb_reindex_mode && is_array($pa_changed_fields) && !sizeof($pa_changed_fields)) { return; } // don't bother indexing if there are no changed fields $vs_subject_tablename = $this->opo_datamodel->getTableName($pn_subject_tablenum); $t_subject = $this->getTableInstance($vs_subject_tablename, true); // Prevent endless recursive reindexing if (is_array($pa_exclusion_list[$pn_subject_tablenum]) && isset($pa_exclusion_list[$pn_subject_tablenum][$pn_subject_row_id])) { return; } $vb_reindex_children = false; $vs_subject_pk = $t_subject->primaryKey(); if (!is_array($pa_changed_fields)) { $pa_changed_fields = array(); } foreach ($pa_changed_fields as $vs_k => $vb_bool) { if (!isset($pa_field_data[$vs_k])) { $pa_field_data[$vs_k] = null; } } $vb_can_do_incremental_indexing = $this->opo_engine->can('incremental_reindexing') ? true : false; // can the engine do incremental indexing? Or do we need to reindex the entire row every time? foreach ($this->opo_search_config->get('search_indexing_replacements') as $vs_to_replace => $vs_replacement) { foreach ($pa_field_data as $vs_k => &$vs_value) { if ($vs_replacement == "nothing") { $vs_replacement = ""; } $vs_value = str_replace($vs_to_replace, $vs_replacement, $vs_value); } } if (!$pa_exclusion_list) { $pa_exclusion_list = array(); } $pa_exclusion_list[$pn_subject_tablenum][$pn_subject_row_id] = true; // // index fields in subject table itself // $va_fields_to_index = $this->getFieldsToIndex($pn_subject_tablenum); if (is_array($va_fields_to_index)) { foreach ($va_fields_to_index as $vs_k => $va_data) { if (preg_match('!^ca_attribute_(.*)$!', $vs_k, $va_matches)) { if (!is_numeric($va_matches[1])) { if ($vn_x = $this->_getElementID($va_matches[1])) { $va_matches[1] = $vn_x; } else { unset($va_fields_to_index[$vs_k]); continue; } } unset($va_fields_to_index[$vs_k]); if ($va_data['DONT_INDEX']) { // remove attribute from indexing list unset($va_fields_to_index['_ca_attribute_' . $va_matches[1]]); } else { $va_fields_to_index['_ca_attribute_' . $va_matches[1]] = $va_data; } } } } // // If location in hierarchy has changed we need to reindex this record and all of its children // if ($t_subject->isHierarchical() && isset($pa_changed_fields['parent_id']) && $pa_changed_fields['parent_id'] && method_exists($t_subject, "makeSearchResult")) { $pb_reindex_mode = true; $vb_reindex_children = true; } $vb_started_indexing = false; if (is_array($va_fields_to_index)) { $this->opo_engine->startRowIndexing($pn_subject_tablenum, $pn_subject_row_id); $vb_started_indexing = true; foreach ($va_fields_to_index as $vs_field => $va_data) { if (substr($vs_field, 0, 14) === '_ca_attribute_') { // // Is attribute // $vs_v = $pa_field_data[$vs_field]; if (!preg_match('!^_ca_attribute_(.*)$!', $vs_field, $va_matches)) { continue; } if ($vb_can_do_incremental_indexing && !$pb_reindex_mode && (!isset($pa_changed_fields[$vs_field]) || !$pa_changed_fields[$vs_field])) { continue; // skip unchanged attribute value } if ($va_data['DONT_INDEX'] && is_array($va_data['DONT_INDEX'])) { $vb_cont = false; foreach ($va_data["DONT_INDEX"] as $vs_exclude_type) { if ($this->_getElementID($vs_exclude_type) == intval($va_matches[1])) { $vb_cont = true; break; } } if ($vb_cont) { continue; } // skip excluded attribute type } $va_data['datatype'] = (int) $this->_getElementDataType($va_matches[1]); switch ($va_data['datatype']) { case 0: // container // index components of complex multi-value attributes $va_attributes = $t_subject->getAttributesByElement($va_matches[1], array('row_id' => $pn_subject_row_id)); if (sizeof($va_attributes)) { foreach ($va_attributes as $vo_attribute) { /* index each element of the container */ foreach ($vo_attribute->getValues() as $vo_value) { $vn_list_id = $this->_getElementListID($vo_value->getElementID()); $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $vo_value->getElementID(), $vo_attribute->getAttributeID(), $vo_value->getDisplayValue($vn_list_id), $va_data); } } } else { // we are deleting a container so cleanup existing sub-values $va_sub_elements = $this->opo_metadata_element->getElementsInSet($va_matches[1]); foreach ($va_sub_elements as $vn_i => $va_element_info) { $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $va_element_info['element_id'], $va_element_info['element_id'], '', $va_data); } } break; case 3: // list // 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(); if (is_array($va_attributes = $t_subject->getAttributesByElement($va_matches[1], array('row_id' => $pn_subject_row_id)))) { foreach ($va_attributes as $vo_attribute) { foreach ($vo_attribute->getValues() as $vo_value) { $va_tmp[$vo_attribute->getAttributeID()] = $vo_value->getDisplayValue(); } } } $va_new_values = array(); $t_item = new ca_list_items(); $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' . $va_matches[1], $vn_attribute_id, $vs_v, $va_data); } break; default: $va_attributes = $t_subject->getAttributesByElement($va_matches[1], array('row_id' => $pn_subject_row_id)); if (!is_array($va_attributes)) { break; } foreach ($va_attributes as $vo_attribute) { foreach ($vo_attribute->getValues() as $vo_value) { //if the field is a daterange type get content from start and end fields $va_field_list = $t_subject->getFieldsArray(); if (in_array($va_field_list[$vs_field]['FIELD_TYPE'], array(FT_DATERANGE, FT_HISTORIC_DATERANGE))) { $start_field = $va_field_list[$vs_field]['START']; $end_field = $va_field_list[$vs_field]['END']; $pn_content = $pa_field_data[$start_field] . " - " . $pa_field_data[$end_field]; } else { $pn_content = $vo_value->getDisplayValue(); } $this->opo_engine->indexField($pn_subject_tablenum, 'A' . $va_matches[1], $vo_attribute->getAttributeID(), $pn_content, $va_data); } } break; } } else { // // Plain old field // if ($vb_can_do_incremental_indexing && !$pb_reindex_mode && !isset($pa_changed_fields[$vs_field]) && $vs_field != $vs_subject_pk) { // skip unchanged continue; } if (!($vn_fld_num = $t_subject->fieldNum($vs_field))) { continue; } // // Hierarchical indexing in primary table // if (isset($va_data['INDEX_ANCESTORS']) && $va_data['INDEX_ANCESTORS'] || in_array('INDEX_ANCESTORS', $va_data)) { if ($t_subject && $t_subject->isHierarchical()) { $vn_fld_num = $t_subject->fieldNum($vs_field); if ($va_hier_values = $this->_genHierarchicalPath($pn_subject_row_id, $vs_field, $t_subject, $va_data)) { $this->opo_engine->indexField($pn_subject_tablenum, 'I' . $vn_fld_num, $pn_subject_row_id, join(" ", $va_hier_values['values']), $va_data); if (caGetOption('INDEX_ANCESTORS_AS_PATH_WITH_DELIMITER', $va_data, false) !== false) { $this->opo_engine->indexField($pn_subject_tablenum, 'I' . $vn_fld_num, $pn_subject_row_id, $va_hier_values['path'], array_merge($va_data, array('DONT_TOKENIZE' => 1))); } } $va_children_ids = $t_subject->getHierarchyAsList($pn_subject_row_id, array('idsOnly' => true)); 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); $qr_children_res = $t_subject->makeSearchResult($vs_subject_tablename, $va_children_ids); while ($qr_children_res->nextHit()) { $o_indexer->indexRow($pn_subject_tablenum, $vn_id = $qr_children_res->get($vs_subject_pk), array($vs_subject_pk => $vn_id, 'parent_id' => $qr_children_res->get('parent_id'), $vs_field => $qr_children_res->get($vs_field)), false, $pa_exclusion_list, array($vs_field => true), null); } } continue; } } // specialized identifier (idno) processing; used IDNumbering plugin to generate searchable permutations of identifier if ((isset($va_data['INDEX_AS_IDNO']) && $va_data['INDEX_AS_IDNO'] || in_array('INDEX_AS_IDNO', $va_data)) && method_exists($t_subject, "getIDNoPlugInInstance") && ($o_idno = $t_subject->getIDNoPlugInInstance())) { $va_values = $o_idno->getIndexValues($pa_field_data[$vs_field]); $vn_fld_num = $t_subject->fieldNum($vs_field); $this->opo_engine->indexField($pn_subject_tablenum, 'I' . $vn_fld_num, $pn_subject_row_id, join(" ", $va_values), $va_data); continue; } $va_field_list = $t_subject->getFieldsArray(); if (in_array($va_field_list[$vs_field]['FIELD_TYPE'], array(FT_DATERANGE, FT_HISTORIC_DATERANGE))) { // if the field is a daterange type get content from start and end fields $start_field = $va_field_list[$vs_field]['START']; $end_field = $va_field_list[$vs_field]['END']; $pn_content = $pa_field_data[$start_field] . " - " . $pa_field_data[$end_field]; } else { $va_content = array(); if (isset($va_field_list[$vs_field]['LIST_CODE']) && $va_field_list[$vs_field]['LIST_CODE']) { // Is reference to list item so index preferred label values $t_item = new ca_list_items((int) $pa_field_data[$vs_field]); $va_labels = $t_item->getPreferredDisplayLabelsForIDs(array((int) $pa_field_data[$vs_field]), array('returnAllLocales' => true)); foreach ($va_labels as $vn_label_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_content[$vs_label] = true; } } } $va_content[$t_item->get('idno')] = true; } else { // is this field related to something? if (is_array($va_rels = $this->opo_datamodel->getManyToOneRelations($vs_subject_tablename)) && $va_rels[$vs_field]) { if (isset($va_rels[$vs_field])) { if ($pa_changed_fields[$vs_field]) { $pb_reindex_mode = true; // trigger full reindex of record so it reflects text of related item (if so indexed) } } $this->opo_engine->indexField($pn_subject_tablenum, 'I' . $vn_fld_num, $pn_subject_row_id, $pn_content, $va_data); } } $va_content[$pa_field_data[$vs_field]] = true; $this->opo_engine->indexField($pn_subject_tablenum, 'I' . $vn_fld_num, $pn_subject_row_id, join(" ", array_keys($va_content)), $va_data); continue; } $this->opo_engine->indexField($pn_subject_tablenum, 'I' . $vn_fld_num, $pn_subject_row_id, $pn_content, $va_data); } } } // ------------------------------------- // // index related fields // // Here's where we generate indexing on the subject from content in related rows (data stored externally to the subject row) // If the underlying engine doesn't support incremental indexing (if it can't change existing indexing for a row in-place, in other words) // then we need to do this every time we update the indexing for a row; if the engine *does* support incremental indexing then // we can just update the existing indexing with content from the changed fields. // // We also do this indexing if we're in "reindexing" mode. When reindexing is indicated it means that we need to act as if // we're indexing this row for the first time, and all indexing should be performed. if (!$vb_can_do_incremental_indexing || $pb_reindex_mode) { if (is_array($va_related_tables = $this->getRelatedIndexingTables($pn_subject_tablenum))) { if (!$vb_started_indexing) { $this->opo_engine->startRowIndexing($pn_subject_tablenum, $pn_subject_row_id); $vb_started_indexing = true; } foreach ($va_related_tables as $vs_related_table) { $vn_related_tablenum = $this->opo_datamodel->getTableNum($vs_related_table); $vs_related_pk = $this->opo_datamodel->getTablePrimaryKeyName($vn_related_tablenum); $t_rel = $this->opo_datamodel->getInstanceByTableNum($vn_related_tablenum, true); $va_fields_to_index = $this->getFieldsToIndex($pn_subject_tablenum, $vs_related_table); $va_table_info = $this->getTableIndexingInfo($pn_subject_tablenum, $vs_related_table); $va_field_list = array_keys($va_fields_to_index); $va_table_list_list = array(); //$va_table_info['tables']; $va_table_key_list = array(); //$va_table_info['keys']; if (isset($va_table_info['key']) && $va_table_info['key']) { $va_table_list_list = array('key' => array($vs_related_table)); $va_table_key_list = array(); } else { if ($pb_reindex_mode || !$vb_can_do_incremental_indexing) { $va_table_list_list = isset($va_table_info['tables']) ? $va_table_info['tables'] : null; $va_table_key_list = isset($va_table_info['keys']) ? $va_table_info['keys'] : null; } } if (!is_array($va_table_list_list) || !sizeof($va_table_list_list)) { continue; } //$va_table_list_list = array($vs_related_table => array()); } foreach ($va_table_list_list as $vs_list_name => $va_linking_tables) { array_push($va_linking_tables, $vs_related_table); $vs_left_table = $vs_subject_tablename; $va_joins = array(); foreach ($va_linking_tables as $vs_right_table) { if (is_array($va_table_key_list) && (isset($va_table_key_list[$vs_list_name][$vs_right_table][$vs_left_table]) || isset($va_table_key_list[$vs_list_name][$vs_left_table][$vs_right_table]))) { // are the keys for this join specified in the indexing config? if (isset($va_table_key_list[$vs_list_name][$vs_left_table][$vs_right_table])) { $va_key_spec = $va_table_key_list[$vs_list_name][$vs_left_table][$vs_right_table]; $vs_join = 'INNER JOIN ' . $vs_right_table . ' ON (' . $vs_right_table . '.' . $va_key_spec['right_key'] . ' = ' . $vs_left_table . '.' . $va_key_spec['left_key']; if ($va_key_spec['left_table_num'] || $va_key_spec['right_table_num']) { if ($va_key_spec['right_table_num']) { $vs_join .= ' AND ' . $vs_right_table . '.' . $va_key_spec['right_table_num'] . ' = ' . $this->opo_datamodel->getTableNum($vs_left_table); } else { $vs_join .= ' AND ' . $vs_left_table . '.' . $va_key_spec['left_table_num'] . ' = ' . $this->opo_datamodel->getTableNum($vs_right_table); } } $vs_join .= ")"; } else { $va_key_spec = $va_table_key_list[$vs_list_name][$vs_right_table][$vs_left_table]; $vs_join = 'INNER JOIN ' . $vs_right_table . ' ON (' . $vs_right_table . '.' . $va_key_spec['left_key'] . ' = ' . $vs_left_table . '.' . $va_key_spec['right_key']; if ($va_key_spec['left_table_num'] || $va_key_spec['right_table_num']) { if ($va_key_spec['right_table_num']) { $vs_join .= ' AND ' . $vs_left_table . '.' . $va_key_spec['right_table_num'] . ' = ' . $this->opo_datamodel->getTableNum($vs_right_table); } else { $vs_join .= ' AND ' . $vs_right_table . '.' . $va_key_spec['left_table_num'] . ' = ' . $this->opo_datamodel->getTableNum($vs_left_table); } } $vs_join .= ")"; } $va_joins[] = $vs_join; } else { if ($va_rel = $this->opo_datamodel->getOneToManyRelations($vs_left_table, $vs_right_table)) { $va_joins[] = 'INNER JOIN ' . $va_rel['many_table'] . ' ON ' . $va_rel['one_table'] . '.' . $va_rel['one_table_field'] . ' = ' . $va_rel['many_table'] . '.' . $va_rel['many_table_field']; } else { if ($va_rel = $this->opo_datamodel->getOneToManyRelations($vs_right_table, $vs_left_table)) { $va_joins[] = 'INNER JOIN ' . $va_rel['one_table'] . ' ON ' . $va_rel['one_table'] . '.' . $va_rel['one_table_field'] . ' = ' . $va_rel['many_table'] . '.' . $va_rel['many_table_field']; } } } $vs_left_table = $vs_right_table; } $va_proc_field_list = array(); $vn_field_list_count = sizeof($va_field_list); for ($vn_i = 0; $vn_i < $vn_field_list_count; $vn_i++) { if ($va_field_list[$vn_i] == '_count') { continue; } if (substr($va_field_list[$vn_i], 0, 14) === '_ca_attribute_') { continue; } if (!trim($va_field_list[$vn_i])) { continue; } $va_proc_field_list[$vn_i] = $vs_related_table . '.' . $va_field_list[$vn_i]; } $va_proc_field_list[] = $vs_related_table . '.' . $vs_related_pk; if (isset($va_rel['many_table']) && $va_rel['many_table']) { $va_proc_field_list[] = $va_rel['many_table'] . '.' . $va_rel['many_table_field']; } $vs_sql = "\n\t\t\t\t\t\tSELECT " . join(",", $va_proc_field_list) . "\n\t\t\t\t\t\tFROM " . $vs_subject_tablename . "\n\t\t\t\t\t\t" . join("\n", $va_joins) . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t(" . $vs_subject_tablename . '.' . $vs_subject_pk . ' = ?) '; $qr_res = $this->opo_db->query($vs_sql, $pn_subject_row_id); if ($this->opo_db->numErrors()) { // Shouldn't ever happen throw new Exception(_t("SQL error while getting content for index of related fields: %1; SQL was %2", $this->opo_db->getErrors(), $vs_sql)); } while ($qr_res->nextRow()) { $va_field_data = $qr_res->getRow(); $vn_row_id = $qr_res->get($vs_related_pk); foreach ($va_fields_to_index as $vs_rel_field => $va_rel_field_info) { // // BEGIN: Index attributes in related tables // $vb_is_attr = false; if (substr($vs_rel_field, 0, 14) === '_ca_attribute_') { if (!preg_match('!^_ca_attribute_(.*)$!', $vs_rel_field, $va_matches)) { continue; } if ($va_rel_field_info['DONT_INDEX'] && is_array($va_rel_field_info['DONT_INDEX'])) { $vb_cont = false; foreach ($va_rel_field_info["DONT_INDEX"] as $vs_exclude_type) { if ($this->_getElementID($vs_exclude_type) == intval($va_matches[1])) { $vb_cont = true; break; } } if ($vb_cont) { continue; } // skip excluded attribute type } $vb_is_attr = true; $va_rel_field_info['datatype'] = (int) $this->_getElementDataType($va_matches[1]); switch ($va_rel_field_info['datatype']) { case 0: // container // index components of complex multi-value attributes $va_attributes = $t_rel->getAttributesByElement($va_matches[1], array('row_id' => $vn_row_id)); if (sizeof($va_attributes)) { foreach ($va_attributes as $vo_attribute) { foreach ($vo_attribute->getValues() as $vo_value) { $vn_list_id = $this->_getElementListID($vo_value->getElementID()); $this->opo_engine->indexField($vn_related_tablenum, 'A' . $vo_value->getElementID(), $vo_attribute->getAttributeID(), $vo_value->getDisplayValue($vn_list_id), $va_rel_field_info); // 4 = ca_attributes } } } else { // we are deleting a container so cleanup existing sub-values $va_sub_elements = $this->opo_metadata_element->getElementsInSet($va_matches[1]); foreach ($va_sub_elements as $vn_i => $va_element_info) { $this->opo_engine->indexField($vn_related_tablenum, 'A' . $va_element_info['element_id'], $va_element_info['element_id'], '', $va_rel_field_info); } } break; case 3: // list // 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(); if (is_array($va_attributes = $t_rel->getAttributesByElement($va_matches[1], array('row_id' => $vn_row_id)))) { foreach ($va_attributes as $vo_attribute) { foreach ($vo_attribute->getValues() as $vo_value) { $va_tmp[$vo_attribute->getAttributeID()] = $vo_value->getDisplayValue(); } } } $va_new_values = array(); $t_item = new ca_list_items(); $va_labels = $t_item->getPreferredDisplayLabelsForIDs($va_tmp, array('returnAllLocales' => true)); foreach ($va_labels as $vn_label_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_label_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($vn_related_tablenum, 'A' . $va_matches[1], $vn_attribute_id, $vs_v, $va_rel_field_info); } break; default: $va_attributes = $t_rel->getAttributesByElement($va_matches[1], array('row_id' => $vn_row_id)); if (!is_array($va_attributes)) { break; } foreach ($va_attributes as $vo_attribute) { foreach ($vo_attribute->getValues() as $vo_value) { $pn_content = $vo_value->getDisplayValue(); $this->opo_engine->indexField($vn_related_tablenum, 'A' . $va_matches[1], $vo_attribute->getAttributeID(), $pn_content, $va_rel_field_info); } } break; } } $vs_fld_data = trim($va_field_data[$vs_rel_field]); // // Hierarchical indexing in related tables // if (isset($va_rel_field_info['INDEX_ANCESTORS']) && $va_rel_field_info['INDEX_ANCESTORS'] || in_array('INDEX_ANCESTORS', $va_rel_field_info)) { // is this current field a label? $t_hier_rel = $t_rel; $vn_fld_num = $t_rel->fieldNum($vs_rel_field); $vn_id = $vn_row_id; $vb_is_label = false; if (is_subclass_of($t_hier_rel, "BaseLabel")) { $t_hier_rel->load($vn_row_id); $t_hier_rel = $t_hier_rel->getSubjectTableInstance(); $vn_id = $t_hier_rel->getPrimaryKey(); $vb_is_label = true; } if ($t_hier_rel && $t_hier_rel->isHierarchical()) { // get hierarchy if ($va_hier_values = $this->_genHierarchicalPath($vn_id, $vb_is_label ? "preferred_labels." . $vs_rel_field : $vs_rel_field, $t_hier_rel, $va_rel_field_info)) { $this->opo_engine->indexField($vn_related_tablenum, 'I' . $vn_fld_num, $vn_id, $vs_fld_data . ' ' . join(" ", $va_hier_values['values']), $va_rel_field_info); if (caGetOption('INDEX_ANCESTORS_AS_PATH_WITH_DELIMITER', $va_rel_field_info, false) !== false) { $this->opo_engine->indexField($vn_related_tablenum, 'I' . $vn_fld_num, $vn_id, $va_hier_values['path'], array_merge($va_rel_field_info, array('DONT_TOKENIZE' => 1))); } } $va_children_ids = $t_hier_rel->getHierarchyAsList($vn_row_id, array('idsOnly' => true)); 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); $qr_children_res = $t_hier_rel->makeSearchResult($t_hier_rel->tableName(), $va_children_ids); $vs_pk = $t_hier_rel->primaryKey(); $vn_table_num = $t_hier_rel->tableNum(); while ($qr_children_res->nextHit()) { $vn_id = $qr_children_res->get($vs_pk); if ($vn_id == $vn_row_id) { continue; } $o_indexer->indexRow($vn_table_num, $vn_id, array($vs_pk => $vn_id, 'parent_id' => $qr_children_res->get('parent_id'), $vs_rel_field => $qr_children_res->get($vs_rel_field)), false, $pa_exclusion_list, array($vs_rel_field => true), null); } } continue; } } switch ($vs_rel_field) { case '_count': // noop break; default: if ($vb_is_attr) { $this->opo_engine->indexField($vn_related_tablenum, 'A' . $va_matches[1], $qr_res->get($vs_related_pk), $vs_fld_data, $va_rel_field_info); } else { $this->opo_engine->indexField($vn_related_tablenum, 'I' . $this->opo_datamodel->getFieldNum($vs_related_table, $vs_rel_field), $qr_res->get($vs_related_pk), $vs_fld_data, $va_rel_field_info); } break; } // // END: Index attributes in related tables // } } //if (isset($va_fields_to_index['_count'])) { //$this->opo_engine->indexField($pn_subject_tablenum, '_count', $pn_subject_row_id, $qr_res->numRows(), array()); //} } } } } // save indexing on subject if ($vb_started_indexing) { $this->opo_engine->commitRowIndexing(); } if (!$pb_reindex_mode && sizeof($pa_changed_fields) > 0) { // // When not reindexing then we consider the effect of the change on this row upon related rows that use it // in their indexing. This means figuring out which related tables have indexing that depend upon the subject row. // // We deal with this by pulling up a dependency map generated from the search_indexing.conf file and then reindexing // those rows // $va_deps = $this->getDependencies($vs_subject_tablename); $va_changed_field_nums = array(); foreach (array_keys($pa_changed_fields) as $vs_f) { if ($t_subject->hasField($vs_f)) { $va_changed_field_nums[$vs_f] = 'I' . $t_subject->fieldNum($vs_f); } else { if (preg_match('!^_ca_attribute_([\\d]+)$!', $vs_f, $va_matches)) { $va_changed_field_nums[$vs_f] = 'A' . $this->_getElementListCode($va_matches[1]); } } } // // reindex rows in dependent tables that use the subject_row_id // $va_rows_to_reindex = $this->_getDependentRowsForSubject($pn_subject_tablenum, $pn_subject_row_id, $va_deps, $va_changed_field_nums); if ($vb_can_do_incremental_indexing) { $va_rows_to_reindex_by_row_id = array(); foreach ($va_rows_to_reindex as $vs_key => $va_row_to_reindex) { foreach ($va_row_to_reindex['field_nums'] as $vs_fld_name => $vn_fld_num) { $vs_new_key = $va_row_to_reindex['table_num'] . '/' . $va_row_to_reindex['field_table_num'] . '/' . $vn_fld_num . '/' . $va_row_to_reindex['field_row_id']; if (!isset($va_rows_to_reindex_by_row_id[$vs_new_key])) { $va_rows_to_reindex_by_row_id[$vs_new_key] = array('table_num' => $va_row_to_reindex['table_num'], 'row_ids' => array(), 'field_table_num' => $va_row_to_reindex['field_table_num'], 'field_num' => $vn_fld_num, 'field_name' => $vs_fld_name, 'field_row_id' => $va_row_to_reindex['field_row_id'], 'field_values' => $va_row_to_reindex['field_values'], 'indexing_info' => $va_row_to_reindex['indexing_info'][$vs_fld_name]); } $va_rows_to_reindex_by_row_id[$vs_new_key]['row_ids'][] = $va_row_to_reindex['row_id']; } } $o_indexer = new SearchIndexer($this->opo_db); foreach ($va_rows_to_reindex_by_row_id as $va_row_to_reindex) { if ($va_row_to_reindex['field_table_num'] === 4) { // is attribute $va_row_to_reindex['indexing_info']['datatype'] = $this->_getElementDataType($va_row_to_reindex['field_num']); } if (isset($va_row_to_reindex['indexing_info']['INDEX_ANCESTORS']) && $va_row_to_reindex['indexing_info']['INDEX_ANCESTORS'] || in_array('INDEX_ANCESTORS', $va_row_to_reindex['indexing_info'])) { if (!is_array($va_row_to_reindex['row_ids'])) { continue; } $va_content = $this->_genHierarchicalPath($va_row_to_reindex['field_row_id'], $va_row_to_reindex['field_name'], $this->opo_datamodel->getInstanceByTableNum($va_row_to_reindex['field_table_num'], true), array()); $vs_content = is_array($va_content['values']) ? join(" ", $va_content['values']) : ""; $this->opo_engine->updateIndexingInPlace($va_row_to_reindex['table_num'], $va_row_to_reindex['row_ids'], $va_row_to_reindex['field_table_num'], $va_row_to_reindex['field_num'], $va_row_to_reindex['field_row_id'], $vs_content, array_merge($va_row_to_reindex['indexing_info'], array('literalContent' => $va_content['path']))); // // THE FOLLOWING CODE IS TOO SLOW - updateIndexingInPlace() call following the commented-out block of code // replaces this and is much faster... but we need to validate that it works reliably // // foreach($va_row_to_reindex['row_ids'] as $vn_row_to_reindex_id) { // if ($t_dep = $this->getTableInstance($va_row_to_reindex['table_num'], true)) { // $va_dep_ids = $t_dep->getHierarchyAsList($vn_row_to_reindex_id, array('idsOnly' => true, 'includeSelf' => true)); // // $va_dep_values = BaseModel::getFieldValueArraysForIDs($va_dep_ids, $t_dep->tableName()); // // foreach($va_dep_values as $vn_dep_id => $va_dep_value) { // $o_indexer->indexRow($va_row_to_reindex['table_num'], $vn_dep_id, $va_dep_value, true, $pa_exclusion_list, null, null); // } // } // } } else { $this->opo_engine->updateIndexingInPlace($va_row_to_reindex['table_num'], $va_row_to_reindex['row_ids'], $va_row_to_reindex['field_table_num'], $va_row_to_reindex['field_num'], $va_row_to_reindex['field_row_id'], $va_row_to_reindex['field_values'][$va_row_to_reindex['field_name']], $va_row_to_reindex['indexing_info']); } } } else { // // If the underlying engine doesn't support incremental indexing then // we fall back to reindexing each dependenting row completely and independently. // This can be *really* slow for subjects with many dependent rows (for example, a ca_list_item value used as a type for many ca_objects rows) // and we need to think about how to optimize this for such engines; ultimately since no matter how you slice it in such // engines you're going to have a lot of reindexing going on, we may just have to construct a facility to handle large // indexing tasks in a separate process when the number of dependent rows exceeds a certain threshold // $o_indexer = new SearchIndexer($this->opo_db); foreach ($va_rows_to_reindex as $va_row_to_reindex) { if (!$t_dep || $t_dep->tableNum() != $va_row_to_reindex['table_num']) { $t_dep = $this->opo_datamodel->getInstanceByTableNum($va_row_to_reindex['table_num']); } $vb_support_attributes = is_subclass_of($t_dep, 'BaseModelWithAttributes') ? true : false; if (is_array($pa_exclusion_list[$va_row_to_reindex['table_num']]) && isset($pa_exclusion_list[$va_row_to_reindex['table_num']][$va_row_to_reindex['row_id']])) { continue; } // trigger reindexing if ($vb_support_attributes) { if ($t_dep->load($va_row_to_reindex['row_id'])) { // $o_indexer->indexRow($va_row_to_reindex['table_num'], $va_row_to_reindex['row_id'], $t_dep->getFieldValuesArray(), true, $pa_exclusion_list); } } else { $o_indexer->indexRow($va_row_to_reindex['table_num'], $va_row_to_reindex['row_id'], $va_row_to_reindex['field_values'], true, $pa_exclusion_list); } } $o_indexer = null; } } if ($vb_reindex_children && method_exists($t_subject, "makeSearchResult")) { // // Force reindexing of children of this record, typically because the record has shifted location in the hierarchy and is hierarchically indexed // $va_children_ids = $t_subject->getHierarchyAsList($pn_subject_row_id, array('idsOnly' => true)); if (is_array($va_children_ids) && sizeof($va_children_ids) > 0) { // trigger reindexing of children $o_indexer = new SearchIndexer($this->opo_db); $qr_children_res = $t_subject->makeSearchResult($vs_subject_tablename, $va_children_ids); while ($qr_children_res->nextHit()) { $o_indexer->indexRow($pn_subject_tablenum, $vn_id = $qr_children_res->get($vs_subject_pk), array($vs_subject_pk => $vn_id, 'parent_id' => $qr_children_res->get('parent_id')), true, $pa_exclusion_list, array(), null); } } } }
$vn_col_span_xs = 6; } if ($vn_start < $qr_res->numHits()) { $vn_c = 0; $qr_res->seek($vn_start); if ($vs_table != 'ca_objects') { $va_ids = array(); while ($qr_res->nextHit() && $vn_c < $vn_hits_per_block) { $va_ids[] = $qr_res->get($vs_pk); $vn_c++; } $va_images = caGetDisplayImagesForAuthorityItems($vs_table, $va_ids, array('version' => 'small', 'relationshipTypes' => caGetOption('selectMediaUsingRelationshipTypes', $va_options, null), 'checkAccess' => $va_access_values)); $vn_c = 0; $qr_res->seek($vn_start); } $t_list_item = new ca_list_items(); $vs_add_to_lightbox_msg = addslashes(_t('Add to lightbox')); while ($qr_res->nextHit() && $vn_c < $vn_hits_per_block) { $vn_id = $qr_res->get("{$vs_table}.{$vs_pk}"); $vs_idno_detail_link = caDetailLink($this->request, $qr_res->get("{$vs_table}.idno"), '', $vs_table, $vn_id); $vs_label_detail_link = caDetailLink($this->request, $qr_res->get("{$vs_table}.preferred_labels.name"), '', $vs_table, $vn_id); $vs_thumbnail = ""; $vs_type_placeholder = ""; $vs_typecode = ""; if ($vs_table == 'ca_objects') { if (!($vs_thumbnail = $qr_res->getMediaTag('ca_object_representations.media', 'medium', array("checkAccess" => $va_access_values)))) { $t_list_item->load($qr_res->get("type_id")); $vs_typecode = $t_list_item->get("idno"); if ($vs_type_placeholder = getPlaceholder($vs_typecode, "placeholder_media_icon")) { $vs_thumbnail = "<div class='bResultItemImgPlaceholder'>" . $vs_type_placeholder . "</div>"; } else {
/** * Converts the given list of list idnos or item_ids into a list of numeric item_ids * * @param mixed $pm_list List code or list_id * @param array $pa_list_items List of item idnos and/or item_ids * @param array $pa_options Options include: * transaction = transaction to execute queries within. [Default=null] * * @return array List of numeric item_ids */ function caMakeListItemIDList($pm_list, $pa_list_items, $pa_options = null) { if (!($vn_list_id = caGetListID($pm_list))) { return array(); } $t_item = new ca_list_items(); if ($o_trans = caGetOption('transaction', $pa_options, null)) { $t_item->setTransaction($o_trans); } $va_ids = array(); foreach ($pa_list_items as $vm_item) { if (is_numeric($vm_item) && (int) $vm_item > 0) { $va_ids[(int) $vm_item] = true; } else { if ($vn_id = caGetListItemID($vn_list_id, $vm_item)) { $va_ids[(int) $vn_id] = true; } } } return array_keys($va_ids); }
/** * 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; }
/** * Converts the given list of source names or source_ids into an expanded list of numeric source_ids suitable for enforcing source restrictions. Processing * includes expansion of sources to include subsources and conversion of any source codes to source_ids. * * @param mixed $pm_table_name_or_num Table name or number to which sources apply * @param array $pa_sources List of source codes and/or source_ids that are the basis of the list * @param array $pa_options Array of options: * dont_include_subsources_in_source_restriction = if set, returned list is not expanded to include subsources * dontIncludeSubsourcesInSourceRestriction = synonym for dont_include_subsources_in_source_restriction * * @return array List of numeric source_ids */ function caMakeSourceIDList($pm_table_name_or_num, $pa_sources, $pa_options = null) { $o_dm = Datamodel::load(); if (isset($pa_options['dontIncludeSubsourcesInSourceRestriction']) && (!isset($pa_options['dont_include_subsources_in_source_restriction']) || !$pa_options['dont_include_subsources_in_source_restriction'])) { $pa_options['dont_include_subsources_in_source_restriction'] = $pa_options['dontIncludeSubsourcesInSourceRestriction']; } if (isset($pa_options['dont_include_subsources_in_source_restriction']) && $pa_options['dont_include_subsources_in_source_restriction']) { $pa_options['noChildren'] = true; } if (is_numeric($pm_table_name_or_num)) { $vs_table_name = $o_dm->getTableName($pm_table_name_or_num); } else { $vs_table_name = $pm_table_name_or_num; } $t_instance = $o_dm->getInstanceByTableName($vs_table_name, true); if (!$t_instance) { return null; } // bad table if (!($vs_source_list_code = $t_instance->getSourceListCode())) { return null; } // table doesn't use sources $va_source_ids = array(); $t_list = new ca_lists(); $t_item = new ca_list_items(); $vs_list_code = $t_instance->getSourceListCode(); foreach ($pa_sources as $vm_source) { if (!$vm_source) { continue; } $vn_source_id = null; if (is_numeric($vm_source)) { $vn_source_id = (int) $vm_source; } else { $vn_source_id = (int) $t_list->getItemIDFromList($vs_source_list_code, $vm_source); } if ($vn_source_id && !(isset($pa_options['noChildren']) || $pa_options['noChildren'])) { if ($qr_children = $t_item->getHierarchy($vn_source_id, array())) { while ($qr_children->nextRow()) { $va_source_ids[$qr_children->get('item_id')] = true; } } } else { if ($vn_source_id) { $va_source_ids[$vn_source_id] = true; } } } return array_keys($va_source_ids); }
/** * * * @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; }
/** * Save edits from "spreadsheet" (editable results) mode * */ public function saveInlineEdit($pa_options = null) { global $g_ui_locale_id; $pa_changes = $this->request->getParameter("changes", pArray); $vs_resp = array(); $o_dm = Datamodel::load(); if (!is_array($pa_changes) || !sizeof($pa_changes)) { $va_resp['messages'][0] = _t("Nothing to save"); } else { foreach ($pa_changes as $vn_i => $pa_change) { $ps_table = $pa_change['table']; $pa_bundle = explode("-", $ps_bundle = $pa_change['bundle']); $pn_id = (int) $pa_change['id']; $ps_val = $pa_change['value']; if (!($t_instance = $o_dm->getInstanceByTableName($ps_table, true))) { $va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Invalid table: %1', $ps_table)); } else { if (!$t_instance->load($pn_id)) { $va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Invalid id: %1', $pn_id)); } else { if (!$t_instance->isSaveable($this->request)) { $va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('You are not allowed to edit this.')); } elseif ($pa_bundle[0] == 'preferred_labels') { if ($this->request->user->getBundleAccessLevel($ps_table, $pa_bundle[0]) != __CA_BUNDLE_ACCESS_EDIT__) { $va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('You are not allowed to edit this.')); } else { $vn_label_id = $t_instance->getPreferredLabelID($g_ui_locale_id); $va_label_values = array(); if (sizeof($pa_bundle) == 1) { // is generic "preferred_labels" $va_label_values[$t_instance->getLabelDisplayField()] = $ps_val; } else { $vs_preferred_label_element = $pa_bundle[1]; $va_label_values[$vs_preferred_label_element] = $ps_val; } if ($vn_label_id) { $t_instance->editLabel($vn_label_id, $va_label_values, $g_ui_locale_id, null, true); // TODO: what about type? } else { $t_instance->addLabel($va_label_values, $g_ui_locale_id, null, true); } if ($t_instance->numErrors()) { $va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Could not set preferred label %1 to %2: %3', $ps_bundle, $ps_val, join("; ", $t_instance->getErrors()))); } else { $va_resp['messages'][$pn_id] = array('message' => _t('Set preferred label %1 to %2', $ps_bundle, $ps_val), 'value' => $ps_val); } } } elseif ($t_instance->hasField($ps_bundle)) { if ($this->request->user->getBundleAccessLevel($ps_table, $ps_bundle) != __CA_BUNDLE_ACCESS_EDIT__) { $va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('You are not allowed to edit this.')); } else { // is it a list? $t_list = new ca_lists(); $t_instance->setMode(ACCESS_WRITE); if (($vs_list_code = $t_instance->getFieldInfo($ps_bundle, 'LIST')) && ($va_item = $t_list->getItemFromListByLabel($vs_list_code, $ps_val))) { $t_instance->set($ps_bundle, $va_item['item_value']); } elseif (($vs_list_code = $t_instance->getFieldInfo($ps_bundle, 'LIST_CODE')) && ($vn_item_id = $t_list->getItemIDFromListByLabel($vs_list_code, $ps_val))) { $t_instance->set($ps_bundle, $vn_item_id); } else { $t_instance->set($ps_bundle, $ps_val); } $t_instance->update(); if ($t_instance->numErrors()) { $va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Could not set %1 to %2: %3', $ps_bundle, $ps_val, join("; ", $t_instance->getErrors()))); } else { $va_resp['messages'][$pn_id] = array('message' => _t('Set %1 to %2', $ps_bundle, $ps_val), 'value' => $ps_val); } } } elseif ($t_instance->hasElement($ps_bundle)) { $vn_datatype = ca_metadata_elements::getElementDatatype($ps_bundle); // Check if it repeats? if ($vn_count = $t_instance->getAttributeCountByElement($ps_bundle) > 1) { $va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Cannot edit <em>%1</em> here because it has multiple values. Try editing it directly.', mb_strtolower($t_instance->getDisplayLabel("{$ps_table}.{$ps_bundle}")))); } elseif (!in_array($vn_datatype, array(1, 2, 3, 5, 6, 8, 9, 10, 11, 12))) { // Check if it's a supported type? $va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Cannot edit <em>%1</em> here. Try editing it directly.', mb_strtolower($t_instance->getDisplayLabel("{$ps_table}.{$ps_bundle}")))); } elseif ($this->request->user->getBundleAccessLevel($ps_table, $ps_bundle) != __CA_BUNDLE_ACCESS_EDIT__) { $va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('You are not allowed to edit this.')); } else { // Do edit $t_instance->setMode(ACCESS_WRITE); $vs_val_proc = null; if ($vn_datatype == 3) { if ($vn_id = ca_list_items::find(array('preferred_labels' => array('name_plural' => $ps_val)), array('returnAs' => 'firstId'))) { $t_instance->replaceAttribute(array('locale_id' => $g_ui_locale_id, $ps_bundle => $vn_id), $ps_bundle); // convert list codes to display text $t_list_item = new ca_list_items((int) $vn_id); if ($t_list_item->getPrimaryKey()) { $vs_val_proc = $t_list_item->get('ca_list_items.preferred_labels.name_plural'); } } } else { $t_instance->replaceAttribute(array('locale_id' => $g_ui_locale_id, $ps_bundle => $ps_val), $ps_bundle); } $t_instance->update(); if (!$vs_val_proc) { $vs_val_proc = $t_instance->get($ps_table . '.' . $ps_bundle); } if ($t_instance->numErrors()) { $va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Could not set %1 to %2: %3', $ps_bundle, $ps_val, join("; ", $t_instance->getErrors()))); } else { $va_resp['messages'][$pn_id] = array('message' => _t('Set %1 to %2', $ps_bundle, $ps_val), 'value' => $vs_val_proc); } } } else { $va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Invalid bundle: %1', $ps_bundle)); } } } } } $this->view->setVar('results', $va_resp); $this->render('Results/ajax_save_inline_edit_json.php'); }
/** * Helper to extract the list a new item is about to be inserted in from the request. * This is usually not passed as simple list_id parameter by the UI but through the parent_id. */ private function _getListIDFromRequest($po_request) { if ($vn_list_id = $po_request->getParameter('list_id', pInteger)) { return $vn_list_id; } if ($vn_parent_id = $po_request->getParameter('parent_id', pInteger)) { $t_item = new ca_list_items($vn_parent_id); if ($t_item->getPrimaryKey()) { return $t_item->get('list_id'); } } return false; }
# --- set for featured member - set name assigned in app.conf - featured_member_set_name - this is an ENTITY set $t_featured_member = new ca_sets(); $t_featured_member->load(array('set_code' => $this->request->config->get('featured_member_set_name'))); # Enforce access control on set if (sizeof($va_access_values) == 0 || sizeof($va_access_values) && in_array($t_featured_member->get("access"), $va_access_values)) { $vn_featured_member_set_id = $t_featured_member->get("set_id"); $va_featured_member_ids = array_keys(is_array($va_tmp = $t_featured_member->getItemRowIDs(array('checkAccess' => $va_access_values, 'shuffle' => 1))) ? $va_tmp : array()); // These are the entity ids in the set } $t_entity = new ca_entities($va_featured_member_ids[0]); $vn_featured_member_id = $va_featured_member_ids[0]; $vs_featured_member_image = $t_entity->get("mem_inst_image", array("version" => "frontpage", "return" => "tag")); $vs_featured_member_name = $t_entity->getLabelForDisplay(); # --- canned browses $va_browse_codes = $this->request->config->get('hp_category_browse_codes'); $t_list_item = new ca_list_items(); $va_browses = array(); if (is_array($va_browse_codes) && sizeof($va_browse_codes)) { foreach ($va_browse_codes as $vs_item_code) { $t_list_item->load(array('idno' => $vs_item_code)); $va_browses[$t_list_item->get("item_id")] = array("idno" => $vs_item_code, "name" => $t_list_item->getLabelForDisplay()); } } if ($this->getVar("featured_set_id")) { $t_featured_set = new ca_sets($this->getVar("featured_set_id")); ?> <div id="contentcontainer"> <div id="objectcontainerHP"> <div class="homeIntro">Navigate through some of the collections of Nova Scotia's community museums to learn about the province's past, and share your own stories and information about what is important to you.</div><!-- end home intro --> <div id="objectslidesContainerHP"> <?php
public function processDisplays() { require_once __CA_MODELS_DIR__ . "/ca_bundle_displays.php"; require_once __CA_MODELS_DIR__ . "/ca_bundle_display_placements.php"; require_once __CA_MODELS_DIR__ . "/ca_bundle_display_type_restrictions.php"; $o_config = Configuration::load(); $vo_dm = Datamodel::load(); if ($this->ops_base_name) { // "merge" profile and its base $va_displays = array(); if ($this->opo_base->displays) { foreach ($this->opo_base->displays->children() as $vo_display) { $va_displays[self::getAttribute($vo_display, "code")] = $vo_display; } } if ($this->opo_profile->displays) { foreach ($this->opo_profile->displays->children() as $vo_display) { $va_displays[self::getAttribute($vo_display, "code")] = $vo_display; } } } else { if ($this->opo_profile->displays) { foreach ($this->opo_profile->displays->children() as $vo_display) { $va_displays[self::getAttribute($vo_display, "code")] = $vo_display; } } } if (!is_array($va_displays) || sizeof($va_displays) == 0) { return true; } foreach ($va_displays as $vo_display) { $vs_display_code = self::getAttribute($vo_display, "code"); $vb_system = self::getAttribute($vo_display, "system"); $vs_table = self::getAttribute($vo_display, "type"); if ($o_config->get($vs_table . '_disable')) { continue; } $t_display = $this->opb_updating ? ca_bundle_displays::find(array('code' => $vs_display_code, 'type' => $vs_table), array('returnAs' => 'firstModelInstance')) : false; $t_display = $t_display ? $t_display : new ca_bundle_displays(); $t_display->setMode(ACCESS_WRITE); $t_display->set("display_code", $vs_display_code); $t_display->set("is_system", $vb_system); $t_display->set("table_num", $vo_dm->getTableNum($vs_table)); $t_display->set("user_id", 1); // let administrative user own these $this->_processSettings($t_display, $vo_display->settings); if ($t_display->getPrimaryKey()) { $t_display->update(); } else { $t_display->insert(); } if ($t_display->numErrors()) { $this->addError("There was an error while inserting display {$vs_display_code}: " . join(" ", $t_display->getErrors())); } else { self::addLabelsFromXMLElement($t_display, $vo_display->labels, $this->opa_locales); if ($t_display->numErrors()) { $this->addError("There was an error while inserting display label for {$vs_display_code}: " . join(" ", $t_display->getErrors())); } if (!$this->processDisplayPlacements($t_display, $vo_display->bundlePlacements, null)) { return false; } } if ($vo_display->typeRestrictions) { foreach ($vo_display->typeRestrictions->children() as $vo_restriction) { $t_list = new ca_lists(); $t_list_item = new ca_list_items(); $vs_restriction_code = trim((string) self::getAttribute($vo_restriction, "code")); $vs_type = trim((string) self::getAttribute($vo_restriction, "type")); $t_instance = $vo_dm->getInstanceByTableNum($vn_table_num = $vo_dm->getTableNum($vs_table)); $vs_type_list_name = $t_instance->getFieldListCode($t_instance->getTypeFieldName()); if ($vs_type) { $t_list->load(array('list_code' => $vs_type_list_name)); $t_list_item->load(array('list_id' => $t_list->getPrimaryKey(), 'idno' => $vs_type)); } $vn_type_id = $vs_type ? $t_list_item->getPrimaryKey() : null; $t_restriction = $this->opb_updating ? ca_bundle_display_type_restrictions::find(array('table_num' => $vn_table_num, 'type_id' => $vn_type_id), array('returnAs' => 'firstModelInstance')) : false; $t_restriction = $t_restriction ? $t_restriction : new ca_bundle_display_type_restrictions(); $t_restriction->setMode(ACCESS_WRITE); $t_restriction->set('table_num', $vn_table_num); $t_restriction->set('include_subtypes', (bool) $vo_restriction->includeSubtypes ? 1 : 0); $t_restriction->set('type_id', $vn_type_id); $t_restriction->set('display_id', $t_display->getPrimaryKey()); $this->_processSettings($t_restriction, $vo_restriction->settings); if ($t_restriction->getPrimaryKey()) { $t_restriction->update(); } else { $t_restriction->insert(); } if ($t_restriction->numErrors()) { $this->addError("There was an error while inserting type restriction {$vs_restriction_code} in display {$vs_display_code}: " . join("; ", $t_restriction->getErrors())); } } } if ($vo_display->userAccess) { $t_user = new ca_users(); $va_display_users = array(); foreach ($vo_display->userAccess->children() as $vo_permission) { $vs_user = trim((string) self::getAttribute($vo_permission, "user")); $vn_access = $this->_convertUserGroupAccessStringToInt(self::getAttribute($vo_permission, 'access')); if ($vn_access && $t_user->load(array('user_name' => $vs_user))) { $va_display_users[$t_user->getUserID()] = $vn_access; } else { $this->addError("User name or access value invalid for display {$vs_display_code} (permission item with user name '{$vs_user}')"); } } if (sizeof($va_display_users) > 0) { $t_display->addUsers($va_display_users); } } if ($vo_display->groupAccess) { $t_group = new ca_user_groups(); $va_display_groups = array(); foreach ($vo_display->groupAccess->children() as $vo_permission) { $vs_group = trim((string) self::getAttribute($vo_permission, "group")); $vn_access = $this->_convertUserGroupAccessStringToInt(self::getAttribute($vo_permission, 'access')); if ($vn_access && $t_group->load(array('code' => $vs_group))) { $va_display_groups[$t_group->getPrimaryKey()] = $vn_access; } else { $this->addError("Group code or access value invalid for display {$vs_display_code} (permission item with group code '{$vs_group}')"); } } if (sizeof($va_display_groups) > 0) { $t_display->addUserGroups($va_display_groups); } } } return true; }
/** * Given a item_id (request parameter 'id') returns a list of ancestors for use in the hierarchy browser * Returned data is JSON format */ public function getFacetHierarchyAncestorList() { $pn_id = $this->request->getParameter('id', pInteger); $ps_facet_name = $this->request->getParameter('facet', pString); if (!is_array($va_facet_info = $this->opo_browse->getInfoForFacet($ps_facet_name))) { return null; } $va_ancestors = array(); switch ($va_facet_info['type']) { case 'attribute': // is it a list attribute? $t_element = new ca_metadata_elements(); if ($t_element->load(array('element_code' => $va_facet_info['element_code']))) { if ($t_element->get('datatype') == 3) { // 3=list if (!$pn_id) { $t_list = new ca_lists(); $pn_id = $t_list->getRootListItemID($t_element->get('list_id')); } $t_item = new ca_list_items($pn_id); if ($t_item->getPrimaryKey()) { $va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'idsOnly' => true))); array_shift($va_ancestors); } } } break; case 'label': // label facet $va_facet_info['table'] = $this->ops_tablename; // fall through to default case // fall through to default case default: $t_item = $this->opo_datamodel->getInstanceByTableName($va_facet_info['table']); $t_item->load($pn_id); if (method_exists($t_item, "getHierarchyList")) { $va_access_values = caGetUserAccessValues($this->request); $va_facet = $this->opo_browse->getFacet($ps_facet_name, array('sort' => 'name', 'checkAccess' => $va_access_values)); $va_hierarchy_list = $t_item->getHierarchyList(true); $vn_hierarchies_in_use = 0; foreach ($va_hierarchy_list as $vn_i => $va_item) { if (isset($va_facet[$va_item[$t_item->primaryKey()]])) { $vn_hierarchies_in_use++; if ($vn_hierarchies_in_use > 1) { break; } } } } if ($t_item->getPrimaryKey()) { $va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'idsOnly' => true))); if (!is_array($va_ancestors)) { $va_ancestors = array(); } } if ($vn_hierarchies_in_use <= 1) { array_shift($va_ancestors); } break; } $this->view->setVar('ancestors', $va_ancestors); return $this->render('Browse/facet_hierarchy_ancestors_json.php'); }
<?php print "<div class='unit'><b>" . _t('Era') . ": </b>" . caReturnDefaultIfBlank($vs_era) . "</div>"; print "<div class='unit'><b>" . _t('Period') . ": </b>" . caReturnDefaultIfBlank(str_replace(", -", "", $vs_period)) . "</div>"; print "<div class='unit'><b>" . _t('Epoch') . ": </b>" . caReturnDefaultIfBlank($vs_epoch) . "</div>"; print "<div class='unit'><b>" . _t('Age') . ": </b>" . caReturnDefaultIfBlank($vs_ageNALMA) . "</div>"; print "<div class='unit'><b>" . _t('Zone') . ": </b>" . caReturnDefaultIfBlank($vs_unit) . "</div>"; print "<div class='unit'><b>" . _t('Group') . ": </b>" . caReturnDefaultIfBlank($vs_group) . "</div>"; print "<div class='unit'><b>" . _t('Formation') . ": </b>" . caReturnDefaultIfBlank($vs_formation) . "</div>"; print "<div class='unit'><b>" . _t('Member') . ": </b>" . caReturnDefaultIfBlank($vs_member) . "</div>"; } elseif (in_array($t_object->get('ca_objects.type_id'), $va_track_type_ids)) { # --- Tracks, Tracings if ($vs_other = $t_object->get("ca_objects.other_catalog_number")) { print "<div class='unit'><b>" . _t('Other Catalog Number') . ":</b> {$vs_other}</div><!-- end unit -->"; } if ($vn_taxonomy = $t_object->get('ca_objects.taxonomic_rank', array('idsOnly' => true))) { $t_list_item = new ca_list_items(); $va_hierarchy = caExtractValuesByUserLocale($t_list_item->getHierarchyAncestors($vn_taxonomy, array("includeSelf" => true, "additionalTableToJoin" => "ca_list_item_labels", "additionalTableSelectFields" => array("name_singular")))); $va_hierarchy = array_reverse($va_hierarchy); foreach ($va_hierarchy as $va_hier_taxonomy) { if ($va_hier_taxonomy["parent_id"]) { print "<div class='unit'><b>" . $t_lists->getItemFromListForDisplayByItemID("list_item_types", $va_hier_taxonomy["type_id"]) . ": </b>" . $va_hier_taxonomy["name_singular"] . "</div>"; } } } if ($va_ichnogenus = $t_object->get('ca_objects.ichnogenus', array('convertCodesToDisplayText' => true))) { print "<div class='unit'><b>" . _t('Ichnogenus') . ":</b> " . $va_ichnogenus . "</div>"; } if ($vs_ichnospecies = $t_object->get("ca_objects.ichnospecies")) { print "<div class='unit'><b>" . _t('Ichnospecies') . ":</b> {$vs_ichnospecies}</div><!-- end unit -->"; } if ($vs_clade = $t_object->get("ca_objects.clade", array('convertCodesToDisplayText' => true, 'delimiter' => ', '))) {
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; }
/** * When source restrictions are specified, the search will only consider items of the given sources. * If you specify a source that has hierarchical children then the children will automatically be included * in the restriction. You may pass numeric source_id and alphanumeric source codes interchangeably. * * @param array $pa_source_codes_or_ids List of source_id or code values to filter search by. When set, the search will only consider items of the specified sources. Using a hierarchical parent source will automatically include its children in the restriction. * @param array $pa_options Options include * includeSubsources = include any child sources in the restriction. Default is true. * @return boolean True on success, false on failure */ public function setSourceRestrictions($pa_source_codes_or_ids, $pa_options = null) { $t_instance = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true); 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(); $this->opa_search_source_ids = array(); foreach ($pa_source_codes_or_ids as $vs_code_or_id) { if (!strlen($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 if (caGetOption('includeSubsources', $pa_options, true)) { // See if there are any child sources $t_item = new ca_list_items($vn_source_id); $va_ids = $t_item->getHierarchyChildren(null, array('idsOnly' => true)); $va_ids[] = $vn_source_id; $this->opa_search_source_ids = array_merge($this->opa_search_source_ids, $va_ids); } } } return true; }
?> _id{n}" value="{id}"/> </td> <td> <a href="#" class="caDeleteItemButton"><?php print caNavIcon($this->request, __CA_NAV_BUTTON_DEL_BUNDLE__, null, null, array('graphicsPath' => $this->getVar('graphicsPath'))); ?> </a> </td> </tr> </table> <?php } else { $vn_use_as_root_id = 'null'; if (sizeof($va_settings['restrict_to_lists']) == 1) { $t_item = new ca_list_items(); if ($t_item->load(array('list_id' => $va_settings['restrict_to_lists'][0], 'parent_id' => null))) { $vn_use_as_root_id = $t_item->getPrimaryKey(); } } ?> <div style="float: right;"><a href="#" class="caDeleteItemButton"><?php print caNavIcon($this->request, __CA_NAV_BUTTON_DEL_BUNDLE__, null, null, array('graphicsPath' => $this->getVar('graphicsPath'))); ?> </a></div> <div style='width: 690px; height: <?php print $va_settings['hierarchicalBrowserHeight']; ?> ;'> <div id='<?php
* * This source code is free and modifiable under the terms of * GNU General Public License. (http://www.gnu.org/copyleft/gpl.html). See * the "license.txt" file for details, or visit the CollectiveAccess web site at * http://www.CollectiveAccess.org * * ---------------------------------------------------------------------- */ require_once __CA_MODELS_DIR__ . '/ca_list_items.php'; $t_object_event = $this->getVar('t_subject'); $vn_event_id = $this->getVar('subject_id'); $t_ui = $this->getVar('t_ui'); $vb_can_edit = $t_object_event->isSaveable($this->request); $vb_can_delete = $t_object_event->isDeletable($this->request); //get a screen name from the type_id $type_list_item = new ca_list_items($this->request->getParameter('type_id', 1)); $screens = $t_ui->getScreens($this->request); foreach ($screens as $screen) { if ($screen['idno'] == $type_list_item->get('idno')) { $screen_from_type = 'Screen' . $screen['screen_id']; } } $screen_name = $screen_from_type ? $screen_from_type : $this->request->getActionExtra(); if ($vb_can_edit) { print $vs_control_box = caFormControlBox(caFormSubmitButton($this->request, __CA_NAV_BUTTON_SAVE__, _t("Save"), 'ObjectEventEditorForm') . ' ' . caNavButton($this->request, __CA_NAV_BUTTON_CANCEL__, _t("Cancel"), 'editor/object_events', 'ObjectEventEditor', 'Edit/' . $this->request->getActionExtra(), array('event_id' => $vn_event_id)), '', intval($vn_event_id) > 0 && $vb_can_delete ? caNavButton($this->request, __CA_NAV_BUTTON_DELETE__, _t("Delete"), 'editor/object_events', 'ObjectEventEditor', 'Delete/' . $this->request->getActionExtra(), array('event_id' => $vn_event_id)) : ''); } ?> <div class="sectionBox"> <?php print caFormTag($this->request, 'Save/' . $this->request->getActionExtra() . '/event_id/' . $vn_event_id, 'ObjectEventEditorForm', null, 'POST', 'multipart/form-data'); $va_form_elements = $t_object_event->getBundleFormHTMLForScreen($screen_name, array('request' => $this->request, 'formName' => 'ObjectEventEditorForm'));
/** * Returns name of hierarchy for currently loaded place or, if specified, place with place_id = to optional $pn_id parameter */ public function getHierarchyName($pn_id = null) { $t_list = new ca_list_items(); if ($pn_id) { $t_place = new ca_places($pn_id); $vn_hierarchy_id = $t_place->get('hierarchy_id'); } else { $vn_hierarchy_id = $this->get('hierarchy_id'); } $t_list->load($vn_hierarchy_id); return $t_list->getLabelForDisplay(false); }
/** * */ private function _getChangeLogFromRawData($pa_data, $pn_table_num, $pa_options = null) { //print "<pre>".print_r($pa_data, true)."</pre>\n"; $va_log_output = array(); $vs_blank_placeholder = '<' . _t('BLANK') . '>'; if (!$pa_options) { $pa_options = array(); } if (sizeof($pa_data)) { // // Init // $o_datamodel = Datamodel::load(); $va_change_types = array('I' => _t('Added'), 'U' => _t('Edited'), 'D' => _t('Deleted')); $vs_label_table_name = $vs_label_display_name = ''; $t_item = $o_datamodel->getInstanceByTableNum($pn_table_num, true); $vs_label_table_name = $vn_label_table_num = $vs_label_display_name = null; if (method_exists($t_item, 'getLabelTableName')) { $t_item_label = $t_item->getLabelTableInstance(); $vs_label_table_name = $t_item->getLabelTableName(); $vn_label_table_num = $t_item_label->tableNum(); $vs_label_display_name = $t_item_label->getProperty('NAME_SINGULAR'); } // // Group data by unit // $va_grouped_data = array(); foreach ($pa_data as $va_log_entry) { $va_grouped_data[$va_log_entry['unit_id']]['ca_table_num_' . $va_log_entry['logged_table_num']][] = $va_log_entry; } // // Process units // $va_attributes = array(); foreach ($va_grouped_data as $vn_unit_id => $va_log_entries_by_table) { foreach ($va_log_entries_by_table as $vs_table_key => $va_log_entries) { foreach ($va_log_entries as $va_log_entry) { $va_changes = array(); if (!is_array($va_log_entry['snapshot'])) { $va_log_entry['snapshot'] = array(); } // // Get date/time stamp for display // $vs_datetime = date("n/d/Y@g:i:sa T", $va_log_entry['log_datetime']); // // Get user name // $vs_user = $va_log_entry['fname'] . ' ' . $va_log_entry['lname']; $vs_email = $va_log_entry['email']; // The "logged" table/row is the row to which the change was actually applied // The "subject" table/row is the row to which the change is considered to have been made for workflow purposes. // // For example: if an entity is related to an object, strictly speaking the logging occurs on the ca_objects_x_entities // row (ca_objects_x_entities is the "logged" table), but the subject is ca_objects since it's only in the context of the // object (and probably the ca_entities row as well) that you can about the change. // $t_obj = $o_datamodel->getInstanceByTableNum($va_log_entry['logged_table_num'], true); // get instance for logged table if (!$t_obj) { continue; } $vs_subject_display_name = '???'; $vn_subject_row_id = null; $vn_subject_table_num = null; if (isset($pa_options['return_item_names']) && $pa_options['return_item_names']) { if (!($vn_subject_table_num = $va_log_entry['subject_table_num'])) { $vn_subject_table_num = $va_log_entry['logged_table_num']; $vn_subject_row_id = $va_log_entry['logged_row_id']; } else { $vn_subject_row_id = $va_log_entry['subject_row_id']; } if ($t_subject = $o_datamodel->getInstanceByTableNum($vn_subject_table_num, true)) { if ($t_subject->load($vn_subject_row_id)) { if (method_exists($t_subject, 'getLabelForDisplay')) { $vs_subject_display_name = $t_subject->getLabelForDisplay(false); } else { if ($vs_idno_field = $t_subject->getProperty('ID_NUMBERING_ID_FIELD')) { $vs_subject_display_name = $t_subject->getProperty('NAME_SINGULAR') . ' [' . $t_subject->get($vs_idno_field) . ']'; } else { $vs_subject_display_name = $t_subject->getProperty('NAME_SINGULAR') . ' [' . $vn_subject_row_id . ']'; } } } } } // // Get item changes // // --------------------------------------------------------------- // is this an intrinsic field? if ($pn_table_num == $va_log_entry['logged_table_num']) { foreach ($va_log_entry['snapshot'] as $vs_field => $vs_value) { $va_field_info = $t_obj->getFieldInfo($vs_field); if (isset($va_field_info['IDENTITY']) && $va_field_info['IDENTITY']) { continue; } if (isset($va_field_info['DISPLAY_TYPE']) && $va_field_info['DISPLAY_TYPE'] == DT_OMIT) { continue; } if (isset($va_field_info['DISPLAY_FIELD']) && is_array($va_field_info['DISPLAY_FIELD']) && ($va_disp_fields = $va_field_info['DISPLAY_FIELD'])) { // // Lookup value in related table // if (!$vs_value) { continue; } if (sizeof($va_disp_fields)) { $va_rel = $o_datamodel->getManyToOneRelations($t_obj->tableName(), $vs_field); $va_rel_values = array(); if ($t_rel_obj = $o_datamodel->getTableInstance($va_rel['one_table'], true)) { $t_rel_obj->load($vs_value); foreach ($va_disp_fields as $vs_display_field) { $va_tmp = explode('.', $vs_display_field); if (($vs_tmp = $t_rel_obj->get($va_tmp[1])) !== '') { $va_rel_values[] = $vs_tmp; } } } $vs_proc_val = join(', ', $va_rel_values); } } else { // Is field a foreign key? $va_keys = $o_datamodel->getManyToOneRelations($t_obj->tableName(), $vs_field); if (sizeof($va_keys)) { // yep, it's a foreign key $va_rel_values = array(); if ($t_rel_obj = $o_datamodel->getTableInstance($va_keys['one_table'], true)) { if ($t_rel_obj->load($vs_value)) { if (method_exists($t_rel_obj, 'getLabelForDisplay')) { $vs_proc_val = $t_rel_obj->getLabelForDisplay(false); } else { $va_disp_fields = $t_rel_obj->getProperty('LIST_FIELDS'); foreach ($va_disp_fields as $vs_display_field) { if (($vs_tmp = $t_rel_obj->get($vs_display_field)) !== '') { $va_rel_values[] = $vs_tmp; } } $vs_proc_val = join(' ', $va_rel_values); } if (!$vs_proc_val) { $vs_proc_val = '???'; } } else { $vs_proc_val = _t("Not set"); } } else { $vs_proc_val = _t('Non-existent'); } } else { // Adjust display of value for different field types switch ($va_field_info['FIELD_TYPE']) { case FT_BIT: $vs_proc_val = $vs_value ? 'Yes' : 'No'; break; default: $vs_proc_val = $vs_value; break; } // Adjust display of value for lists if ($va_field_info['LIST']) { $t_list = new ca_lists(); if ($t_list->load(array('list_code' => $va_field_info['LIST']))) { $vn_list_id = $t_list->getPrimaryKey(); $t_list_item = new ca_list_items(); if ($t_list_item->load(array('list_id' => $vn_list_id, 'item_value' => $vs_value))) { $vs_proc_val = $t_list_item->getLabelForDisplay(); } } } else { if ($va_field_info['BOUNDS_CHOICE_LIST']) { // TODO } } } } $va_changes[] = array('label' => $va_field_info['LABEL'], 'description' => strlen((string) $vs_proc_val) ? $vs_proc_val : $vs_blank_placeholder, 'value' => $vs_value); } } // --------------------------------------------------------------- // is this a label row? if ($va_log_entry['logged_table_num'] == $vn_label_table_num) { foreach ($va_log_entry['snapshot'] as $vs_field => $vs_value) { $va_changes[] = array('label' => $t_item_label->getFieldInfo($vs_field, 'LABEL'), 'description' => $vs_value); } } // --------------------------------------------------------------- // is this an attribute? if ($va_log_entry['logged_table_num'] == 3) { // attribute_values if ($t_element = ca_attributes::getElementInstance($va_log_entry['snapshot']['element_id'])) { if ($o_attr_val = Attribute::getValueInstance($t_element->get('datatype'))) { $o_attr_val->loadValueFromRow($va_log_entry['snapshot']); $vs_attr_val = $o_attr_val->getDisplayValue(); } else { $vs_attr_val = '?'; } // Convert list-based attributes to text if ($vn_list_id = $t_element->get('list_id')) { $t_list = new ca_lists(); $vs_attr_val = $t_list->getItemFromListForDisplayByItemID($vn_list_id, $vs_attr_val, true); } if (!$vs_attr_val) { $vs_attr_val = $vs_blank_placeholder; } $vs_label = $t_element->getLabelForDisplay(); $va_attributes[$va_log_entry['snapshot']['attribute_id']]['values'][] = array('label' => $vs_label, 'value' => $vs_attr_val); $va_changes[] = array('label' => $vs_label, 'description' => $vs_attr_val); } } // --------------------------------------------------------------- // is this a related (many-many) row? $va_keys = $o_datamodel->getOneToManyRelations($t_item->tableName(), $t_obj->tableName()); if (sizeof($va_keys) > 0) { if (method_exists($t_obj, 'getLeftTableNum')) { if ($t_obj->getLeftTableNum() == $t_item->tableNum()) { // other side of rel is on right $t_related_table = $o_datamodel->getInstanceByTableNum($t_obj->getRightTableNum(), true); $t_related_table->load($va_log_entry['snapshot'][$t_obj->getRightTableFieldName()]); } else { // other side of rel is on left $t_related_table = $o_datamodel->getInstanceByTableNum($t_obj->getLeftTableNum(), true); $t_related_table->load($va_log_entry['snapshot'][$t_obj->getLeftTableFieldName()]); } $t_rel = $o_datamodel->getInstanceByTableNum($t_obj->tableNum(), true); $va_changes[] = array('label' => caUcFirstUTF8Safe($t_related_table->getProperty('NAME_SINGULAR')), 'idno' => ($vs_idno_field = $t_related_table->getProperty('ID_NUMBERING_ID_FIELD')) ? $t_related_table->get($vs_idno_field) : null, 'description' => $t_related_table->getLabelForDisplay(), 'table_name' => $t_related_table->tableName(), 'table_num' => $t_related_table->tableNum(), 'row_id' => $t_related_table->getPrimaryKey(), 'rel_type_id' => $va_log_entry['snapshot']['type_id'], 'rel_typename' => $t_rel->getRelationshipTypename('ltor', $va_log_entry['snapshot']['type_id'])); } } // --------------------------------------------------------------- // record log line if (sizeof($va_changes)) { $va_log_output[$vn_unit_id][] = array('datetime' => $vs_datetime, 'user_fullname' => $vs_user, 'user_email' => $vs_email, 'user' => $vs_user . ' (' . $vs_email . ')', 'changetype_display' => $va_change_types[$va_log_entry['changetype']], 'changetype' => $va_log_entry['changetype'], 'changes' => $va_changes, 'subject' => $vs_subject_display_name, 'subject_id' => $vn_subject_row_id, 'subject_table_num' => $vn_subject_table_num, 'logged_table_num' => $va_log_entry['logged_table_num'], 'logged_table' => $t_obj->tableName(), 'logged_row_id' => $va_log_entry['logged_row_id']); } } } } } return $va_log_output; }
/** * Given a item_id (request parameter 'id') returns a list of direct children for use in the hierarchy browser * Returned data is JSON format */ public function getFacetHierarchyLevel() { $va_access_values = caGetUserAccessValues($this->request); $ps_facet_name = $this->request->getParameter('facet', pString); $this->opo_browse->setTypeRestrictions(array($this->opn_type_restriction_id)); if (!is_array($va_facet_info = $this->opo_browse->getInfoForFacet($ps_facet_name))) { return null; } $va_facet = $this->opo_browse->getFacet($ps_facet_name, array('sort' => 'name', 'checkAccess' => $va_access_values)); $pa_ids = explode(";", $ps_ids = $this->request->getParameter('id', pString)); if (!sizeof($pa_ids)) { $pa_ids = array(null); } $va_level_data = array(); if (($vn_max_items_per_page = $this->request->getParameter('max', pInteger)) < 1 || $vn_max_items_per_page > 1000) { $vn_max_items_per_page = null; } $t_model = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true); $o_config = Configuration::load(); if (!is_array($va_sorts = $o_config->getList($this->ops_tablename . '_hierarchy_browser_sort_values')) || !sizeof($va_sorts)) { $va_sorts = array(); } foreach ($va_sorts as $vn_i => $vs_sort_fld) { $va_tmp = explode(".", $vs_sort_fld); if ($va_tmp[1] == 'preferred_labels') { $va_tmp[0] = $vs_label_table_name; if (!($va_tmp[1] = $va_tmp[2])) { $va_tmp[1] = $vs_label_display_field_name; } unset($va_tmp[2]); $va_sorts[$vn_i] = join(".", $va_tmp); } } if (!in_array($vs_sort_dir = strtolower($o_config->get($this->ops_tablename . '_hierarchy_browser_sort_direction')), array('asc', 'desc'))) { $vs_sort_dir = 'asc'; } $va_expanded_facet = array(); $t_item = new ca_list_items(); foreach ($va_facet as $vn_id => $va_facet_item) { $va_expanded_facet[$vn_id] = true; $va_ancestors = $t_item->getHierarchyAncestors($vn_id, array('idsOnly' => true)); if (is_array($va_ancestors)) { foreach ($va_ancestors as $vn_ancestor_id) { $va_expanded_facet[$vn_ancestor_id] = true; } } } foreach ($pa_ids as $pn_id) { $va_json_data = array('_primaryKey' => 'item_id'); $va_tmp = explode(":", $pn_id); $vn_id = $va_tmp[0]; $vn_start = (int) $va_tmp[1]; if ($vn_start < 0) { $vn_start = 0; } switch ($va_facet_info['type']) { case 'attribute': // is it a list attribute? $t_element = new ca_metadata_elements(); if ($t_element->load(array('element_code' => $va_facet_info['element_code']))) { if ($t_element->get('datatype') == 3) { // 3=list $t_list = new ca_lists(); if (!$vn_id) { $vn_id = $t_list->getRootListItemID($t_element->get('list_id')); } $t_item = new ca_list_items($vn_id); $va_children = $t_item->getHierarchyChildren(null, array('idsOnly' => true)); $va_child_counts = $t_item->getHierarchyChildCountsForIDs($va_children); $qr_res = caMakeSearchResult('ca_list_items', $va_children); $vs_pk = $t_model->primaryKey(); if ($qr_res) { while ($qr_res->nextHit()) { $vn_parent_id = $qr_res->get('ca_list_items.parent_id'); $vn_item_id = $qr_res->get('ca_list_items.item_id'); if (!isset($va_expanded_facet[$vn_item_id])) { continue; } $va_item = array(); $va_item['item_id'] = $vn_item_id; $va_item['name'] = $qr_res->get('ca_list_items.preferred_labels'); $va_item['children'] = isset($va_child_counts[$vn_item_id]) && $va_child_counts[$vn_item_id] ? $va_child_counts[$vn_item_id] : 0; $va_json_data[$vn_item_id] = $va_item; } } } } break; case 'label': // label facet $va_facet_info['table'] = $this->ops_tablename; // fall through to default case // fall through to default case default: if (!$vn_id) { $va_hier_ids = $this->opo_browse->getHierarchyIDsForFacet($ps_facet_name, array('checkAccess' => $va_access_values)); $t_item = $this->opo_datamodel->getInstanceByTableName($va_facet_info['table']); $t_item->load($vn_id); $vn_id = $vn_root = $t_item->getHierarchyRootID(); $va_hierarchy_list = $t_item->getHierarchyList(true); $vn_last_id = null; $vn_c = 0; foreach ($va_hierarchy_list as $vn_i => $va_item) { if (!in_array($vn_i, $va_hier_ids)) { continue; } // only show hierarchies that have items in browse result if ($vn_start <= $vn_c) { $va_item['item_id'] = $va_item[$t_item->primaryKey()]; if (!isset($va_facet[$va_item['item_id']]) && $vn_root == $va_item['item_id']) { continue; } unset($va_item['parent_id']); unset($va_item['label']); $va_json_data[$va_item['item_id']] = $va_item; $vn_last_id = $va_item['item_id']; } $vn_c++; if (!is_null($vn_max_items_per_page) && $vn_c >= $vn_max_items_per_page + $vn_start) { break; } } if (sizeof($va_json_data) == 2) { // if only one hierarchy root (root + _primaryKey in array) then don't bother showing it $vn_id = $vn_last_id; unset($va_json_data[$vn_last_id]); } } if ($vn_id) { $vn_c = 0; foreach ($va_facet as $vn_i => $va_item) { if ($va_item['parent_id'] == $vn_id) { if ($vn_start <= $vn_c) { $va_item['item_id'] = $va_item['id']; $va_item['name'] = $va_item['label']; $va_item['children'] = $va_item['child_count']; unset($va_item['label']); unset($va_item['child_count']); unset($va_item['id']); $va_json_data[$va_item['item_id']] = $va_item; } $vn_c++; if (!is_null($vn_max_items_per_page) && $vn_c >= $vn_max_items_per_page + $vn_start) { break; } } } } break; } $vs_rank_fld = $t_item->getProperty('RANK'); $va_sorted_items = array(); foreach ($va_json_data as $vn_id => $va_node) { if (!is_array($va_node)) { continue; } $vs_key = preg_replace('![^A-Za-z0-9]!', '_', $va_node['name']); if (isset($va_node['sort']) && $va_node['sort']) { $va_sorted_items[$va_node['sort']][$vs_key] = $va_node; } else { if ($vs_rank_fld && ($vs_rank = (int) sprintf("%08d", $va_node[$vs_rank_fld]))) { $va_sorted_items[$vs_rank][$vs_key] = $va_node; } else { $va_sorted_items[$vs_key][$vs_key] = $va_node; } } } ksort($va_sorted_items); if ($vs_sort_dir == 'desc') { $va_sorted_items = array_reverse($va_sorted_items); } $va_json_data = array(); $va_sorted_items = array_slice($va_sorted_items, $vn_start, $vn_max_items_per_page); foreach ($va_sorted_items as $vs_k => $va_v) { ksort($va_v); if ($vs_sort_dir == 'desc') { $va_v = array_reverse($va_v); } $va_json_data = array_merge($va_json_data, $va_v); } $va_json_data['_itemCount'] = sizeof($va_json_data); $va_json_data['_sortOrder'] = array_keys($va_json_data); $va_json_data['_primaryKey'] = $t_model->primaryKey(); // pass the name of the primary key so the hierbrowser knows where to look for item_id's $va_level_data[$pn_id] = $va_json_data; } if (!trim($this->request->getParameter('init', pString))) { $this->opo_result_context->setParameter($ps_facet_name . '_browse_last_id', $pn_id); $this->opo_result_context->saveContext(); } $this->view->setVar('facet_list', $va_level_data); return $this->render('Browse/facet_hierarchy_level_json.php'); }
/** * Generates standard-format inspector panels for editors * * @param View $po_view Inspector view object * @param array $pa_options Optional array of options. Supported options are: * backText = a string to use as the "back" button text; default is "Results" * * @return string HTML implementing the inspector */ function caEditorInspector($po_view, $pa_options = null) { require_once __CA_MODELS_DIR__ . '/ca_sets.php'; require_once __CA_MODELS_DIR__ . '/ca_data_exporters.php'; $t_item = $po_view->getVar('t_item'); $vs_table_name = $t_item->tableName(); if (($vs_priv_table_name = $vs_table_name) == 'ca_list_items') { $vs_priv_table_name = 'ca_lists'; } $vn_item_id = $t_item->getPrimaryKey(); $o_result_context = $po_view->getVar('result_context'); $t_ui = $po_view->getVar('t_ui'); $t_type = method_exists($t_item, "getTypeInstance") ? $t_item->getTypeInstance() : null; $vs_type_name = method_exists($t_item, "getTypeName") ? $t_item->getTypeName() : ''; if (!$vs_type_name) { $vs_type_name = $t_item->getProperty('NAME_SINGULAR'); } $va_reps = $po_view->getVar('representations'); $o_dm = Datamodel::load(); if ($t_item->isHierarchical()) { $va_ancestors = $po_view->getVar('ancestors'); $vn_parent_id = $t_item->get($t_item->getProperty('HIERARCHY_PARENT_ID_FLD')); } else { $va_ancestors = array(); $vn_parent_id = null; } // action extra to preserve currently open screen across next/previous links $vs_screen_extra = $po_view->getVar('screen') ? '/' . $po_view->getVar('screen') : ''; if ($vs_type_name == "list item") { $vs_style = "style='height:auto;'"; } if ($vn_item_id | $po_view->request->getAction() === 'Delete') { $vs_buf = '<h3 class="nextPrevious" ' . $vs_style . '>' . caEditorFindResultNavigation($po_view->request, $t_item, $o_result_context, $pa_options) . "</h3>\n"; } $vs_color = null; if ($t_type) { $vs_color = trim($t_type->get('color')); } if (!$vs_color && $t_ui) { $vs_color = trim($t_ui->get('color')); } if (!$vs_color) { $vs_color = "FFFFFF"; } $vs_buf .= "<h4><div id='caColorbox' style='border: 6px solid #{$vs_color};'>\n"; $vs_icon = null; if ($t_type) { $vs_icon = $t_type->getMediaTag('icon', 'icon'); } if (!$vs_icon && $t_ui) { $vs_icon = $t_ui->getMediaTag('icon', 'icon'); } if ($vs_icon) { $vs_buf .= "<div id='inspectoricon' style='border-right: 6px solid #{$vs_color}; border-bottom: 6px solid #{$vs_color}; -moz-border-radius-bottomright: 8px; -webkit-border-bottom-right-radius: 8px;'>\n{$vs_icon}</div>\n"; } if ($po_view->request->getAction() === 'Delete' && $po_view->request->getParameter('confirm', pInteger)) { $vs_buf .= "<strong>" . _t("Deleted %1", $vs_type_name) . "</strong>\n"; $vs_buf .= "<br style='clear: both;'/></div></h4>\n"; } else { if ($vn_item_id) { if (!$po_view->request->config->get("{$vs_priv_table_name}_inspector_disable_headline")) { if ($po_view->request->user->canDoAction("can_edit_" . $vs_priv_table_name) && sizeof($t_item->getTypeList()) > 1) { $vs_buf .= "<strong>" . _t("Editing %1", $vs_type_name) . ": </strong>\n"; } else { $vs_buf .= "<strong>" . _t("Viewing %1", $vs_type_name) . ": </strong>\n"; } } if ($t_item->hasField('is_deaccessioned') && $t_item->get('is_deaccessioned') && $t_item->get('deaccession_date', array('getDirectDate' => true)) <= caDateToHistoricTimestamp(_t('now'))) { // If currently deaccessioned then display deaccession message $vs_buf .= "<br/><div class='inspectorDeaccessioned'>" . _t('Deaccessioned %1', $t_item->get('deaccession_date')) . "</div>\n"; if ($vs_deaccession_notes = $t_item->get('deaccession_notes')) { TooltipManager::add(".inspectorDeaccessioned", $vs_deaccession_notes); } } else { if ($po_view->request->user->canDoAction('can_see_current_location_in_inspector_ca_objects')) { if ($t_ui && method_exists($t_item, "getObjectHistory") && (is_array($va_placements = $t_ui->getPlacementsForBundle('ca_objects_history')) && sizeof($va_placements) > 0)) { // // Output current "location" of object in life cycle. Configuration is taken from a ca_objects_history bundle configured for the current editor // $va_placement = array_shift($va_placements); $va_bundle_settings = $va_placement['settings']; if (is_array($va_history = $t_item->getObjectHistory($va_bundle_settings, array('limit' => 1, 'currentOnly' => true))) && sizeof($va_history) > 0) { $va_current_location = array_shift(array_shift($va_history)); if (!($vs_inspector_current_location_label = $po_view->request->config->get("ca_objects_inspector_current_location_label"))) { $vs_inspector_current_location_label = _t('Current'); } if ($va_current_location['display']) { $vs_buf .= "<div class='inspectorCurrentLocation'><strong>" . $vs_inspector_current_location_label . ':</strong><br/>' . $va_current_location['display'] . "</div>"; } } } elseif (method_exists($t_item, "getLastLocationForDisplay")) { // If no ca_objects_history bundle is configured then display the last storage location if ($vs_current_location = $t_item->getLastLocationForDisplay("<ifdef code='ca_storage_locations.parent.preferred_labels'>^ca_storage_locations.parent.preferred_labels âžœ </ifdef>^ca_storage_locations.preferred_labels.name")) { $vs_buf .= "<br/><div class='inspectorCurrentLocation'>" . _t('Location: %1', $vs_current_location) . "</div>\n"; $vs_full_location_hierarchy = $t_item->getLastLocationForDisplay("^ca_storage_locations.hierarchy.preferred_labels.name%delimiter=_âžœ_"); if ($vs_full_location_hierarchy !== $vs_current_location) { TooltipManager::add(".inspectorCurrentLocation", $vs_full_location_hierarchy); } } } } } // // Display flags; expressions for these are defined in app.conf in the <table_name>_inspector_display_flags directive // if (is_array($va_display_flags = $po_view->request->config->getAssoc("{$vs_table_name}_inspector_display_flags"))) { $va_display_flag_buf = array(); foreach ($va_display_flags as $vs_exp => $vs_display_flag) { $va_exp_vars = array(); foreach (ExpressionParser::getVariableList($vs_exp) as $vs_var_name) { $va_exp_vars[$vs_var_name] = $t_item->get($vs_var_name, array('returnIdno' => true)); } if (ExpressionParser::evaluate($vs_exp, $va_exp_vars)) { $va_display_flag_buf[] = $t_item->getWithTemplate("{$vs_display_flag}"); } } if (sizeof($va_display_flag_buf) > 0) { $vs_buf .= join("; ", $va_display_flag_buf); } } $vs_label = ''; $vb_dont_use_labels_for_ca_objects = (bool) $t_item->getAppConfig()->get('ca_objects_dont_use_labels'); if (!($vs_table_name === 'ca_objects' && $vb_dont_use_labels_for_ca_objects)) { if ($vs_get_spec = $po_view->request->config->get("{$vs_table_name}_inspector_display_title")) { $vs_label = caProcessTemplateForIDs($vs_get_spec, $vs_table_name, array($t_item->getPrimaryKey())); } else { $va_object_collection_collection_ancestors = $po_view->getVar('object_collection_collection_ancestors'); if ($t_item->tableName() == 'ca_objects' && $t_item->getAppConfig()->get('ca_objects_x_collections_hierarchy_enabled') && is_array($va_object_collection_collection_ancestors) && sizeof($va_object_collection_collection_ancestors)) { $va_collection_links = array(); foreach ($va_object_collection_collection_ancestors as $va_collection_ancestor) { $va_collection_links[] = caEditorLink($po_view->request, $va_collection_ancestor['label'], '', 'ca_collections', $va_collection_ancestor['collection_id']); } $vs_label .= join(" / ", $va_collection_links) . ' > '; } if (method_exists($t_item, 'getLabelForDisplay')) { $vn_parent_index = sizeof($va_ancestors) - 1; if ($vn_parent_id && ($vs_table_name != 'ca_places' || $vn_parent_index > 0)) { $va_parent = $va_ancestors[$vn_parent_index]; $vs_disp_fld = $t_item->getLabelDisplayField(); if ($va_parent['NODE'][$vs_disp_fld] && ($vs_editor_link = caEditorLink($po_view->request, $va_parent['NODE'][$vs_disp_fld], '', $vs_table_name, $va_parent['NODE'][$t_item->primaryKey()]))) { $vs_label .= $vs_editor_link . ' > ' . $t_item->getLabelForDisplay(); } else { $vs_label .= ($va_parent['NODE'][$vs_disp_fld] ? $va_parent['NODE'][$vs_disp_fld] . ' > ' : '') . $t_item->getLabelForDisplay(); } } else { $vs_label .= $t_item->getLabelForDisplay(); if ($vs_table_name === 'ca_editor_uis' && in_array($po_view->request->getAction(), array('EditScreen', 'DeleteScreen', 'SaveScreen'))) { $t_screen = new ca_editor_ui_screens($po_view->request->getParameter('screen_id', pInteger)); if (!($vs_screen_name = $t_screen->getLabelForDisplay())) { $vs_screen_name = _t('new screen'); } $vs_label .= " > " . $vs_screen_name; } } } else { $vs_label .= $t_item->get('name'); } } } $vb_show_idno = (bool) ($vs_idno = $t_item->get($t_item->getProperty('ID_NUMBERING_ID_FIELD'))); if (!$vs_label) { switch ($vs_table_name) { case 'ca_commerce_orders': if ($t_item->get('order_type') == 'L') { if ($vs_org = $t_item->get('billing_organization')) { $vs_label = _t('%5 #%4 on %1 to %2 (%3)', caGetLocalizedDate($t_item->get('created_on', array('getDirectDate' => true)), array('dateFormat' => 'delimited', 'timeOmit' => true)), $t_item->get('billing_fname') . ' ' . $t_item->get('billing_lname'), $vs_org, $t_item->getOrderNumber(), caUcFirstUTF8Safe($t_item->getProperty('NAME_SINGULAR'))); } else { $vs_label = _t('%4 #%3 on %1 to %2', caGetLocalizedDate($t_item->get('created_on', array('getDirectDate' => true)), array('dateFormat' => 'delimited', 'timeOmit' => true)), $t_item->get('billing_fname') . ' ' . $t_item->get('billing_lname'), $t_item->getOrderNumber(), caUcFirstUTF8Safe($t_item->getProperty('NAME_SINGULAR'))); } } else { if ($vs_org = $t_item->get('billing_organization')) { $vs_label = _t('%5 #%4 on %1 from %2 (%3)', caGetLocalizedDate($t_item->get('created_on', array('getDirectDate' => true)), array('dateFormat' => 'delimited', 'timeOmit' => true)), $t_item->get('billing_fname') . ' ' . $t_item->get('billing_lname'), $vs_org, $t_item->getOrderNumber(), caUcFirstUTF8Safe($t_item->getProperty('NAME_SINGULAR'))); } else { $vs_label = _t('%4 #%3 on %1 from %2', caGetLocalizedDate($t_item->get('created_on', array('getDirectDate' => true)), array('dateFormat' => 'delimited', 'timeOmit' => true)), $t_item->get('billing_fname') . ' ' . $t_item->get('billing_lname'), $t_item->getOrderNumber(), caUcFirstUTF8Safe($t_item->getProperty('NAME_SINGULAR'))); } } break; default: if ($vs_table_name === 'ca_objects' && $vb_dont_use_labels_for_ca_objects) { $vs_label = $vs_idno; $vb_show_idno = false; } else { $vs_label = '[' . _t('BLANK') . ']'; } break; } } $vs_buf .= "<div class='recordTitle {$vs_table_name}' style='width:190px; overflow:hidden;'>{$vs_label}" . ($vb_show_idno ? "<a title='{$vs_idno}'>" . ($vs_idno ? " ({$vs_idno})" : '') : "") . "</a></div>"; if ($vs_table_name === 'ca_object_lots' && $t_item->getPrimaryKey()) { $vs_buf .= "<div id='inspectorLotMediaDownload'><strong>" . (($vn_num_objects = $t_item->numObjects()) == 1 ? _t('Lot contains %1 object', $vn_num_objects) : _t('Lot contains %1 objects', $vn_num_objects)) . "</strong>\n"; } if ($po_view->request->config->get("include_custom_inspector")) { if (file_exists($po_view->request->getViewsDirectoryPath() . "/bundles/inspector_info.php")) { $vo_inspector_view = new View($po_view->request, $po_view->request->getViewsDirectoryPath() . "/bundles/"); $vo_inspector_view->setVar('t_item', $t_item); $vs_buf .= $vo_inspector_view->render('inspector_info.php'); } } } else { $vs_parent_name = ''; if ($vn_parent_id = $po_view->request->getParameter('parent_id', pInteger)) { $t_parent = clone $t_item; $t_parent->load($vn_parent_id); $vs_parent_name = $t_parent->getLabelForDisplay(); } $vs_buf .= "<div class='creatingNew'>" . _t("Creating new %1", $vs_type_name) . " " . ($vs_parent_name ? _t("%1 > New %2", $vs_parent_name, $vs_type_name) : '') . "</div>\n"; $vs_buf .= "<br/>\n"; } // ------------------------------------------------------------------------------------- if ($t_item->getPrimaryKey()) { if (sizeof($va_reps) > 0) { $va_imgs = array(); $vs_buf .= "<div id='inspectorMedia'>"; $vn_r = $vn_primary_index = 0; foreach ($va_reps as $va_rep) { if (!($va_rep['info']['preview170']['WIDTH'] && $va_rep['info']['preview170']['HEIGHT'])) { continue; } if ($vb_is_primary = isset($va_rep['is_primary']) && (bool) $va_rep['is_primary']) { $vn_primary_index = $vn_r; } $va_imgs[] = "{url:'" . $va_rep['urls']['preview170'] . "', width: " . $va_rep['info']['preview170']['WIDTH'] . ", height: " . $va_rep['info']['preview170']['HEIGHT'] . ", link: '#', onclick: 'caMediaPanel.showPanel(\\'" . caNavUrl($po_view->request, '*', '*', 'GetMediaOverlay', array($t_item->primaryKey() => $vn_item_id, 'representation_id' => $va_rep['representation_id'])) . "\\')'}"; $vn_r++; } if (sizeof($va_reps) > 1) { $vs_buf .= "\n\t\t\t\t\t<div class='leftScroll'>\n\t\t\t\t\t\t<a href='#' onclick='inspectorInfoRepScroller.scrollToPreviousImage(); return false;'>" . caNavIcon($po_view->request, __CA_NAV_BUTTON_SCROLL_LT__) . "</a>\n\t\t\t\t\t</div>\n\t\t"; } if (sizeof($va_imgs) > 0) { $vs_buf .= "\n\t\t\t\t<div id='inspectorInfoRepScrollingViewer' style='position: relative;'>\n\t\t\t\t\t<div id='inspectorInfoRepScrollingViewerContainer'>\n\t\t\t\t\t\t<div id='inspectorInfoRepScrollingViewerImageContainer'></div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t"; if (sizeof($va_reps) > 1) { $vs_buf .= "\n\t\t\t\t\t<div class='rightScroll'>\n\t\t\t\t\t\t<a href='#' onclick='inspectorInfoRepScroller.scrollToNextImage(); return false;'>" . caNavIcon($po_view->request, __CA_NAV_BUTTON_SCROLL_RT__) . "</a>\n\t\t\t\t\t</div>\n\t\t"; } TooltipManager::add(".leftScroll", _t('Previous')); TooltipManager::add(".rightScroll", _t('Next')); $vs_buf .= "<script type='text/javascript'>"; $vs_buf .= "\n\t\t\t\t\tvar inspectorInfoRepScroller = caUI.initImageScroller([" . join(",", $va_imgs) . "], 'inspectorInfoRepScrollingViewerImageContainer', {\n\t\t\t\t\t\t\tcontainerWidth: 170, containerHeight: 170,\n\t\t\t\t\t\t\timageCounterID: 'inspectorInfoRepScrollingViewerCounter',\n\t\t\t\t\t\t\tscrollingImageClass: 'inspectorInfoRepScrollerImage',\n\t\t\t\t\t\t\tscrollingImagePrefixID: 'inspectorInfoRep',\n\t\t\t\t\t\t\tinitialIndex: {$vn_primary_index}\n\t\t\t\t\t\t\t\n\t\t\t\t\t});\n\t\t\t\t</script>"; } $vs_buf .= "</div>\n"; if ($vs_get_spec = $po_view->request->config->get("{$vs_table_name}_inspector_display_below_media")) { $vs_buf .= caProcessTemplateForIDs($vs_get_spec, $vs_table_name, array($t_item->getPrimaryKey())); } } $vs_buf .= "<div id='toolIcons'>"; if ($vn_item_id) { # --- watch this link $vs_watch = ""; if (in_array($vs_table_name, array('ca_objects', 'ca_object_lots', 'ca_entities', 'ca_places', 'ca_occurrences', 'ca_collections', 'ca_storage_locations'))) { require_once __CA_MODELS_DIR__ . '/ca_watch_list.php'; $t_watch_list = new ca_watch_list(); $vs_watch = "<div class='watchThis'><a href='#' title='" . _t('Add/remove item to/from watch list.') . "' onclick='caToggleItemWatch(); return false;' id='caWatchItemButton'>" . caNavIcon($po_view->request, $t_watch_list->isItemWatched($vn_item_id, $t_item->tableNum(), $po_view->request->user->get("user_id")) ? __CA_NAV_BUTTON_UNWATCH__ : __CA_NAV_BUTTON_WATCH__) . "</a></div>"; $vs_buf .= "\n<script type='text/javascript'>\n\t\tfunction caToggleItemWatch() {\n\t\t\tvar url = '" . caNavUrl($po_view->request, $po_view->request->getModulePath(), $po_view->request->getController(), 'toggleWatch', array($t_item->primaryKey() => $vn_item_id)) . "';\n\t\t\t\n\t\t\tjQuery.getJSON(url, {}, function(data, status) {\n\t\t\t\tif (data['status'] == 'ok') {\n\t\t\t\t\tjQuery('#caWatchItemButton').html((data['state'] == 'watched') ? '" . addslashes(caNavIcon($po_view->request, __CA_NAV_BUTTON_UNWATCH__)) . "' : '" . addslashes(caNavIcon($po_view->request, __CA_NAV_BUTTON_WATCH__)) . "');\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log('Error toggling watch status for item: ' + data['errors']);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\t</script>\n"; } $vs_buf .= "{$vs_watch}\n"; TooltipManager::add("#caWatchItemButton", _t('Watch/Unwatch this record')); if ($po_view->request->user->canDoAction("can_change_type_{$vs_table_name}")) { $vs_buf .= "<div id='inspectorChangeType'><div id='inspectorChangeTypeButton'><a href='#' onclick='caTypeChangePanel.showPanel(); return false;'>" . caNavIcon($po_view->request, __CA_NAV_BUTTON_CHANGE__ . " Change Type", array('title' => _t('Change type'))) . "</a></div></div>\n"; $vo_change_type_view = new View($po_view->request, $po_view->request->getViewsDirectoryPath() . "/bundles/"); $vo_change_type_view->setVar('t_item', $t_item); FooterManager::add($vo_change_type_view->render("change_type_html.php")); TooltipManager::add("#inspectorChangeType", _t('Change Record Type')); } if ($t_item->getPrimaryKey() && $po_view->request->config->get($vs_table_name . '_show_add_child_control_in_inspector')) { $vb_show_add_child_control = true; if (is_array($va_restrict_add_child_control_to_types = $po_view->request->config->getList($vs_table_name . '_restrict_child_control_in_inspector_to_types')) && sizeof($va_restrict_add_child_control_to_types)) { $t_type_instance = $t_item->getTypeInstance(); if (!in_array($t_type_instance->get('idno'), $va_restrict_add_child_control_to_types) && !in_array($t_type_instance->getPrimaryKey(), $va_restrict_add_child_control_to_types)) { $vb_show_add_child_control = false; } } if ($vb_show_add_child_control) { if ((bool) $po_view->request->config->get($vs_table_name . '_enforce_strict_type_hierarchy')) { // strict menu $vs_type_list = $t_item->getTypeListAsHTMLFormElement('type_id', array('style' => 'width: 90px; font-size: 9px;'), array('childrenOfCurrentTypeOnly' => true, 'directChildrenOnly' => $po_view->request->config->get($vs_table_name . '_enforce_strict_type_hierarchy') == '~' ? false : true, 'returnHierarchyLevels' => true, 'access' => __CA_BUNDLE_ACCESS_EDIT__)); } else { // all types $vs_type_list = $t_item->getTypeListAsHTMLFormElement('type_id', array('style' => 'width: 90px; font-size: 9px;'), array('access' => __CA_BUNDLE_ACCESS_EDIT__)); } if ($vs_type_list) { $vs_buf .= "<div id='inspectorCreateChild'><div id='inspectorCreateChildButton'><a href='#' onclick='caCreateChildPanel.showPanel(); return false;'>" . caNavIcon($po_view->request, __CA_NAV_BUTTON_CHILD__, array('title' => _t('Create Child Record'))) . "</a></div></div>\n"; $vo_create_child_view = new View($po_view->request, $po_view->request->getViewsDirectoryPath() . "/bundles/"); $vo_create_child_view->setVar('t_item', $t_item); $vo_create_child_view->setVar('type_list', $vs_type_list); FooterManager::add($vo_create_child_view->render("create_child_html.php")); TooltipManager::add("#inspectorCreateChildButton", _t('Create a child record under this one')); } } } } if ($po_view->request->user->canDoAction('can_duplicate_' . $vs_table_name) && $t_item->getPrimaryKey()) { $vs_buf .= '<div id="caDuplicateItemButton">'; $vs_buf .= caFormTag($po_view->request, 'Edit', 'DuplicateItemForm', $po_view->request->getModulePath() . '/' . $po_view->request->getController(), 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true, 'noTimestamp' => true)); $vs_buf .= caFormSubmitLink($po_view->request, caNavIcon($po_view->request, __CA_NAV_BUTTON_DUPLICATE__), '', 'DuplicateItemForm'); $vs_buf .= caHTMLHiddenInput($t_item->primaryKey(), array('value' => $t_item->getPrimaryKey())); $vs_buf .= caHTMLHiddenInput('mode', array('value' => 'dupe')); $vs_buf .= "</form>"; $vs_buf .= "</div>"; TooltipManager::add("#caDuplicateItemButton", _t('Duplicate this %1', mb_strtolower($vs_type_name, 'UTF-8'))); } // // Download media in lot ($vn_num_objects is only set for object lots) if ($vn_num_objects > 0) { $vs_buf .= "<div id='inspectorLotMediaDownloadButton'>" . caNavLink($po_view->request, caNavIcon($po_view->request, __CA_NAV_BUTTON_DOWNLOAD__), "button", $po_view->request->getModulePath(), $po_view->request->getController(), 'getLotMedia', array('lot_id' => $t_item->getPrimaryKey(), 'download' => 1), array()) . "</div>\n"; TooltipManager::add('#inspectorLotMediaDownloadButton', _t("Download all media associated with objects in this lot")); } // // Download media in set if ($vs_table_name == 'ca_sets' && sizeof($t_item->getItemRowIDs()) > 0) { $vs_buf .= "<div id='inspectorSetMediaDownloadButton'>" . caNavLink($po_view->request, caNavIcon($po_view->request, __CA_NAV_BUTTON_DOWNLOAD__), "button", $po_view->request->getModulePath(), $po_view->request->getController(), 'getSetMedia', array('set_id' => $t_item->getPrimaryKey(), 'download' => 1), array()) . "</div>\n"; TooltipManager::add('#inspectorSetMediaDownloadButton', _t("Download all media associated with records in this set")); } $vs_more_info = ''; // list of sets in which item is a member $t_set = new ca_sets(); if (is_array($va_sets = caExtractValuesByUserLocale($t_set->getSetsForItem($t_item->tableNum(), $t_item->getPrimaryKey(), array('user_id' => $po_view->request->getUserID(), 'access' => __CA_SET_READ_ACCESS__)))) && sizeof($va_sets)) { $va_links = array(); foreach ($va_sets as $vn_set_id => $va_set) { $va_links[] = "<a href='" . caEditorUrl($po_view->request, 'ca_sets', $vn_set_id) . "'>" . $va_set['name'] . "</a>"; } $vs_more_info .= "<div><strong>" . (sizeof($va_links) == 1 ? _t("In set") : _t("In sets")) . "</strong> " . join(", ", $va_links) . "</div>\n"; } // export options if ($vn_item_id && ($vs_select = $po_view->getVar('available_mappings_as_html_select'))) { $vs_more_info .= "<div class='inspectorExportControls'>" . caFormTag($po_view->request, 'exportItem', 'caExportForm', null, 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true)); $vs_more_info .= $vs_select; $vs_more_info .= caHTMLHiddenInput($t_item->primaryKey(), array('value' => $t_item->getPrimaryKey())); $vs_more_info .= caHTMLHiddenInput('download', array('value' => 1)); $vs_more_info .= caFormSubmitLink($po_view->request, 'Export ›', 'button', 'caExportForm'); $vs_more_info .= "</form></div>"; } $va_creation = $t_item->getCreationTimestamp(); $va_last_change = $t_item->getLastChangeTimestamp(); if ($va_creation['timestamp'] || $va_last_change['timestamp']) { $vs_more_info .= "<div class='inspectorChangeDateList'>"; if ($va_creation['timestamp']) { if (!trim($vs_name = $va_creation['fname'] . ' ' . $va_creation['lname'])) { $vs_name = null; } $vs_interval = ($vn_t = time() - $va_creation['timestamp']) == 0 ? _t('Just now') : _t('%1 ago', caFormatInterval($vn_t, 2)); $vs_more_info .= "<div class='inspectorChangeDateListLine' id='caInspectorCreationDate'>" . ($vs_name ? _t('<strong>Created</strong><br/>%1 by %2', $vs_interval, $vs_name) : _t('<strong>Created</strong><br/>%1', $vs_interval)) . "</div>"; TooltipManager::add("#caInspectorCreationDate", "<h2>" . _t('Created on') . "</h2>" . _t('Created on %1', caGetLocalizedDate($va_creation['timestamp'], array('dateFormat' => 'delimited')))); } if ($va_last_change['timestamp'] && $va_creation['timestamp'] != $va_last_change['timestamp']) { if (!trim($vs_name = $va_last_change['fname'] . ' ' . $va_last_change['lname'])) { $vs_name = null; } $vs_interval = ($vn_t = time() - $va_last_change['timestamp']) == 0 ? _t('Just now') : _t('%1 ago', caFormatInterval($vn_t, 2)); $vs_more_info .= "<div class='inspectorChangeDateListLine' id='caInspectorChangeDate'>" . ($vs_name ? _t('<strong>Last changed</strong><br/>%1 by %2', $vs_interval, $vs_name) : _t('<strong>Last changed</strong><br/>%1', $vs_interval)) . "</div>"; TooltipManager::add("#caInspectorChangeDate", "<h2>" . _t('Last changed on') . "</h2>" . _t('Last changed on %1', caGetLocalizedDate($va_last_change['timestamp'], array('dateFormat' => 'delimited')))); } if (method_exists($t_item, 'getMetadataDictionaryRuleViolations') && is_array($va_violations = $t_item->getMetadataDictionaryRuleViolations()) && ($vn_num_violations = sizeof($va_violations)) > 0) { $va_violation_messages = array(); foreach ($va_violations as $vn_violation_id => $va_violation) { $vs_label = $t_item->getDisplayLabel($va_violation['bundle_name']); $va_violation_messages[] = "<li><em><u>{$vs_label}</u></em> " . $va_violation['violationMessage'] . "</li>"; } $vs_more_info .= "<div id='caInspectorViolationsList'>" . ($vs_num_violations_display = "<img src='" . $po_view->request->getThemeUrlPath() . "/graphics/icons/warning_small.gif' border='0'/> " . ($vn_num_violations > 1 ? _t('%1 problems require attention', $vn_num_violations) : _t('%1 problem requires attention', $vn_num_violations))) . "</div>\n"; TooltipManager::add("#caInspectorViolationsList", "<h2>{$vs_num_violations_display}</h2><ol>" . join("\n", $va_violation_messages)) . "</ol>\n"; } $vs_more_info .= "</div>\n"; } if ($vs_get_spec = $po_view->request->config->get("{$vs_table_name}_inspector_display_more_info")) { $vs_more_info .= caProcessTemplateForIDs($vs_get_spec, $vs_table_name, array($t_item->getPrimaryKey())); } if ($vs_more_info) { $vs_buf .= "<div class='button info'><a href='#' id='inspectorMoreInfo'>" . caNavIcon($po_view->request, __CA_NAV_BUTTON_INFO2__) . "</a></div>\n\t\t\t<div id='inspectorInfo' >"; $vs_buf .= $vs_more_info . "</div>\n"; TooltipManager::add("#inspectorMoreInfo", _t('See more information about this record')); } $vs_buf .= "</div><!--End tooIcons-->"; } // ------------------------------------------------------------------------------------- // // Item-specific information // // // Output info for related items // if (!$t_item->getPrimaryKey()) { // only applies to new records $vs_rel_table = $po_view->request->getParameter('rel_table', pString); $vn_rel_type_id = $po_view->request->getParameter('rel_type_id', pString); $vn_rel_id = $po_view->request->getParameter('rel_id', pInteger); if ($vs_rel_table && $po_view->request->datamodel->tableExists($vs_rel_table) && $vn_rel_type_id && $vn_rel_id) { $t_rel = $po_view->request->datamodel->getTableInstance($vs_rel_table); if ($t_rel && $t_rel->load($vn_rel_id)) { $vs_buf .= '<strong>' . _t("Will be related to %1", $t_rel->getTypeName()) . '</strong>: ' . $t_rel->getLabelForDisplay(); } } } // // Output lot info for ca_objects // $vb_is_currently_part_of_lot = true; if (!($vn_lot_id = $t_item->get('lot_id'))) { $vn_lot_id = $po_view->request->getParameter('lot_id', pInteger); $vb_is_currently_part_of_lot = false; } if ($vs_table_name === 'ca_objects' && $vn_lot_id) { require_once __CA_MODELS_DIR__ . '/ca_object_lots.php'; $va_lot_lots = caGetTypeListForUser('ca_object_lots', array('access' => __CA_BUNDLE_ACCESS_READONLY__)); $t_lot = new ca_object_lots($vn_lot_id); if ($t_lot->get('deleted') == 0 && in_array($t_lot->get('type_id'), $va_lot_lots)) { if (!($vs_lot_displayname = $t_lot->get('idno_stub'))) { if (!($vs_lot_displayname = $t_lot->getLabelForDisplay())) { $vs_lot_displayname = "Lot {$vn_lot_id}"; } } if ($vs_lot_displayname) { if (!($vs_part_of_lot_msg = $po_view->request->config->get("ca_objects_inspector_part_of_lot_msg"))) { $vs_part_of_lot_msg = _t('Part of lot'); } if (!($vs_will_be_part_of_lot_msg = $po_view->request->config->get("ca_objects_inspector_will_be_part_of_lot_msg"))) { $vs_will_be_part_of_lot_msg = _t('Will be part of lot'); } $vs_buf .= "<strong>" . ($vb_is_currently_part_of_lot ? $vs_part_of_lot_msg : $vs_will_be_part_of_lot_msg) . "</strong>: " . caNavLink($po_view->request, $vs_lot_displayname, '', 'editor/object_lots', 'ObjectLotEditor', 'Edit', array('lot_id' => $vn_lot_id)); } } } $va_object_container_types = $po_view->request->config->getList('ca_objects_container_types'); $va_object_component_types = $po_view->request->config->getList('ca_objects_component_types'); $vb_can_add_component = $vs_table_name === 'ca_objects' && $t_item->getPrimaryKey() && $po_view->request->user->canDoAction('can_create_ca_objects') && $t_item->canTakeComponents(); if (method_exists($t_item, 'getComponentCount')) { if ($vn_component_count = $t_item->getComponentCount()) { if ($t_ui && ($vs_component_list_screen = $t_ui->getScreenWithBundle("ca_objects_components_list", $po_view->request)) && $vs_component_list_screen !== $po_view->request->getActionExtra()) { $vs_component_count_link = caNavLink($po_view->request, $vn_component_count == 1 ? _t('%1 component', $vn_component_count) : _t('%1 components', $vn_component_count), '', '*', '*', $po_view->request->getAction() . '/' . $vs_component_list_screen, array($t_item->primaryKey() => $t_item->getPrimaryKey())); } else { $vs_component_count_link = $vn_component_count == 1 ? _t('%1 component', $vn_component_count) : _t('%1 components', $vn_component_count); } $vs_buf .= "<br/><strong>" . _t('Has') . ":</strong> {$vs_component_count_link}"; } } if ($vb_can_add_component) { $vs_buf .= ' <a href="#" onclick=\'caObjectComponentPanel.showPanel("' . caNavUrl($po_view->request, '*', 'ObjectComponent', 'Form', array('parent_id' => $t_item->getPrimaryKey())) . '"); return false;\')>' . caNavIcon($po_view->request, __CA_NAV_BUTTON_ADD__) . '</a>'; $vo_change_type_view = new View($po_view->request, $po_view->request->getViewsDirectoryPath() . "/bundles/"); $vo_change_type_view->setVar('t_item', $t_item); FooterManager::add($vo_change_type_view->render("create_component_html.php")); } // // Output lot info for ca_object_lots // if ($vs_table_name === 'ca_object_lots' && $t_item->getPrimaryKey()) { $va_component_types = $po_view->request->config->getList('ca_objects_component_types'); if (is_array($va_component_types) && sizeof($va_component_types)) { $vs_buf .= "<strong>" . (($vn_num_objects = $t_item->numObjects(null, array('return' => 'objects'))) == 1 ? _t('Lot contains %1 object', $vn_num_objects) : _t('Lot contains %1 objects', $vn_num_objects)) . "</strong>\n"; $vs_buf .= "<strong>" . (($vn_num_components = $t_item->numObjects(null, array('return' => 'components'))) == 1 ? _t('Lot contains %1 component', $vn_num_components) : _t('Lot contains %1 components', $vn_num_components)) . "</strong>\n"; } else { $vs_buf .= "<strong>" . (($vn_num_objects = $t_item->numObjects()) == 1 ? _t('Lot contains %1 object', $vn_num_objects) : _t('Lot contains %1 objects', $vn_num_objects)) . "</strong>\n"; } if ((bool) $po_view->request->config->get('allow_automated_renumbering_of_objects_in_a_lot') && ($va_nonconforming_objects = $t_item->getObjectsWithNonConformingIdnos())) { $vs_buf .= '<br/><br/><em>' . (($vn_c = sizeof($va_nonconforming_objects)) == 1 ? _t('There is %1 object with non-conforming numbering', $vn_c) : _t('There are %1 objects with non-conforming numbering', $vn_c)) . "</em>\n"; $vs_buf .= "<a href='#' onclick='jQuery(\"#inspectorNonConformingNumberList\").toggle(250); return false;'>" . caNavIcon($po_view->request, __CA_NAV_BUTTON_ADD__); $vs_buf .= "<div id='inspectorNonConformingNumberList' class='inspectorNonConformingNumberList'><div class='inspectorNonConformingNumberListScroll'><ol>\n"; foreach ($va_nonconforming_objects as $vn_object_id => $va_object_info) { $vs_buf .= '<li>' . caEditorLink($po_view->request, $va_object_info['idno'], '', 'ca_objects', $vn_object_id) . "</li>\n"; } $vs_buf .= "</ol></div>"; $vs_buf .= caNavLink($po_view->request, _t('Re-number objects') . ' ›', 'button', $po_view->request->getModulePath(), $po_view->request->getController(), 'renumberObjects', array('lot_id' => $t_item->getPrimaryKey())); $vs_buf .= "</div>\n"; } require_once __CA_MODELS_DIR__ . '/ca_objects.php'; $t_object = new ca_objects(); $vs_buf .= "<div class='inspectorLotObjectTypeControls'><form action='#' id='caAddObjectToLotForm'>"; if ((bool) $po_view->request->config->get('ca_objects_enforce_strict_type_hierarchy')) { // strict menu $vs_buf .= _t('Add new %1 to lot', $t_object->getTypeListAsHTMLFormElement('type_id', array('id' => 'caAddObjectToLotForm_type_id'), array('childrenOfCurrentTypeOnly' => true, 'directChildrenOnly' => $po_view->request->config->get('ca_objects_enforce_strict_type_hierarchy') == '~' ? false : true, 'returnHierarchyLevels' => true, 'access' => __CA_BUNDLE_ACCESS_EDIT__))); } else { // all types $vs_buf .= _t('Add new %1 to lot', $t_object->getTypeListAsHTMLFormElement('type_id', array('id' => 'caAddObjectToLotForm_type_id'), array('access' => __CA_BUNDLE_ACCESS_EDIT__))); } $vs_buf .= " <a href='#' onclick='caAddObjectToLotForm()'>" . caNavIcon($po_view->request, __CA_NAV_BUTTON_ADD__) . '</a>'; $vs_buf .= "</form></div>\n"; $vs_buf .= "<script type='text/javascript'>\n\tfunction caAddObjectToLotForm() { \n\t\twindow.location='" . caEditorUrl($po_view->request, 'ca_objects', 0, false, array('lot_id' => $t_item->getPrimaryKey(), 'rel' => 1, 'type_id' => '')) . "' + jQuery('#caAddObjectToLotForm_type_id').val();\n\t}\n\tjQuery(document).ready(function() {\n\t\tjQuery('#objectLotsNonConformingNumberList').hide();\n\t});\n</script>\n"; } if ($vs_table_name === 'ca_objects') { // // Output loan info for ca_objects // if ($po_view->request->user->canDoAction('can_manage_clients') && ($va_loan_details = $t_item->isOnLoan())) { $vs_buf .= "<div>" . caNavLink($po_view->request, _t('On loan to %1', $va_loan_details['billing_fname'] . ' ' . $va_loan_details['billing_lname']), 'inspectorOnLoan', 'client/library', 'OrderEditor', 'Edit', array('order_id' => $va_loan_details['order_id'])) . "</div>"; } // // Output checkout info for ca_objects // if ((bool) $po_view->request->config->get('enable_client_services') && ((bool) $po_view->request->config->get('enable_client_services_sales') || (bool) $po_view->request->config->get('enable_client_services_library')) && $t_item->canBeCheckedOut() && ($va_checkout_status = $t_item->getCheckoutStatus(array('returnAsArray' => true)))) { $vs_buf .= "<div class='inspectorCheckedOut'>" . $va_checkout_status['status_display']; if ($va_checkout_status['user_name']) { $vs_buf .= _t("; checked out by %1", $va_checkout_status['user_name']); } $vs_buf .= "</div>"; } } // // Output related objects for ca_object_representations // if ($vs_table_name === 'ca_object_representations') { foreach (array('ca_objects', 'ca_object_lots', 'ca_entities', 'ca_places', 'ca_occurrences', 'ca_collections', 'ca_storage_locations', 'ca_loans', 'ca_movements') as $vs_rel_table) { if (sizeof($va_objects = $t_item->getRelatedItems($vs_rel_table))) { $vs_buf .= "<div><strong>" . _t("Related %1", $o_dm->getTableProperty($vs_rel_table, 'NAME_PLURAL')) . "</strong>: <br/>\n"; $vs_screen = ''; if ($t_ui = ca_editor_uis::loadDefaultUI($vs_rel_table, $po_view->request, null)) { $vs_screen = $t_ui->getScreenWithBundle('ca_object_representations', $po_view->request); } foreach ($va_objects as $vn_rel_id => $va_rel_info) { if ($vs_label = array_shift($va_rel_info['labels'])) { $vs_buf .= caEditorLink($po_view->request, '← ' . $vs_label . ' (' . $va_rel_info['idno'] . ')', '', $vs_rel_table, $va_rel_info[$o_dm->getTablePrimaryKeyName($vs_rel_table)], array(), array(), array('action' => 'Edit' . ($vs_screen ? "/{$vs_screen}" : ""))) . "<br/>\n"; } } $vs_buf .= "</div>\n"; } } } // // Output related object reprsentation for ca_representation_annotation // if ($vs_table_name === 'ca_representation_annotations') { if ($vn_representation_id = $t_item->get('representation_id')) { $vs_buf .= "<div><strong>" . _t("Applied to representation") . "</strong>: <br/>\n"; $t_rep = new ca_object_representations($vn_representation_id); $vs_buf .= caNavLink($po_view->request, '← ' . $t_rep->getLabelForDisplay(), '', 'editor/object_representations', 'ObjectRepresentationEditor', 'Edit/' . $po_view->getVar('representation_editor_screen'), array('representation_id' => $vn_representation_id)) . '<br/>'; $vs_buf .= "</div>\n"; } } // // Output extra useful info for sets // if ($vs_table_name === 'ca_sets') { $vn_set_item_count = $t_item->getItemCount(array('user_id' => $po_view->request->getUserID())); if ($vn_set_item_count > 0 && $po_view->request->user->canDoAction('can_batch_edit_' . $o_dm->getTableName($t_item->get('table_num')))) { $vs_buf .= caNavButton($po_view->request, __CA_NAV_BUTTON_BATCH_EDIT__, _t('Batch edit'), 'editorBatchSetEditorLink', 'batch', 'Editor', 'Edit', array('set_id' => $t_item->getPrimaryKey()), array(), array('icon_position' => __CA_NAV_BUTTON_ICON_POS_LEFT__, 'no_background' => true, 'dont_show_content' => true)); } $vs_buf .= "<div><strong>" . _t("Number of items") . "</strong>: {$vn_set_item_count}<br/>\n"; if ($t_item->getPrimaryKey()) { $vn_set_table_num = $t_item->get('table_num'); $vs_set_table_name = $o_dm->getTableName($vn_set_table_num); $vs_buf .= "<strong>" . _t("Type of content") . "</strong>: " . caGetTableDisplayName($vn_set_table_num) . "<br/>\n"; $vs_buf .= "</div>\n"; } else { if ($vn_set_table_num = $po_view->request->getParameter('table_num', pInteger)) { $vs_buf .= "<div><strong>" . _t("Type of content") . "</strong>: " . caGetTableDisplayName($vn_set_table_num) . "<br/>\n"; $vs_buf .= "</div>\n"; } } $t_user = new ca_users(($vn_user_id = $t_item->get('user_id')) ? $vn_user_id : $po_view->request->getUserID()); if ($t_user->getPrimaryKey()) { $vs_buf .= "<div><strong>" . _t('Owner') . "</strong>: " . $t_user->get('fname') . ' ' . $t_user->get('lname') . "</div>\n"; } if ($po_view->request->user->canDoAction('can_export_' . $vs_set_table_name) && $t_item->getPrimaryKey() && sizeof(ca_data_exporters::getExporters($vn_set_table_num)) > 0) { $vs_buf .= '<div style="border-top: 1px solid #aaaaaa; margin-top: 5px; font-size: 10px; text-align: right;" id="caExportItemButton">'; $vs_buf .= _t('Export this set of records') . " "; $vs_buf .= "<a class='button' onclick='jQuery(\"#exporterFormList\").show();' style='text-align:right;' href='#'>" . caNavIcon($po_view->request, __CA_NAV_BUTTON_ADD__) . "</a>"; $vs_buf .= caFormTag($po_view->request, 'ExportData', 'caExportForm', 'manage/MetadataExport', 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true)); $vs_buf .= "<div id='exporterFormList'>"; $vs_buf .= ca_data_exporters::getExporterListAsHTMLFormElement('exporter_id', $vn_set_table_num, array('id' => 'caExporterList'), array('width' => '135px')); $vs_buf .= caHTMLHiddenInput('set_id', array('value' => $t_item->getPrimaryKey())); $vs_buf .= caFormSubmitLink($po_view->request, _t('Export') . " ›", "button", "caExportForm"); $vs_buf .= "</div>\n"; $vs_buf .= "</form>"; $vs_buf .= "</div>"; $vs_buf .= "<script type='text/javascript'>"; $vs_buf .= "jQuery(document).ready(function() {"; $vs_buf .= "jQuery(\"#exporterFormList\").hide();"; $vs_buf .= "});"; $vs_buf .= "</script>"; } } // // Output extra useful info for set items // if ($vs_table_name === 'ca_set_items') { AssetLoadManager::register("panel"); $t_set = new ca_sets(); if ($t_set->load($vn_set_id = $t_item->get('set_id'))) { $vs_buf .= "<div><strong>" . _t("Part of set") . "</strong>: " . caEditorLink($po_view->request, $t_set->getLabelForDisplay(), '', 'ca_sets', $vn_set_id) . "<br/>\n"; $t_content_instance = $t_item->getAppDatamodel()->getInstanceByTableNum($vn_item_table_num = $t_item->get('table_num')); if ($t_content_instance->load($vn_row_id = $t_item->get('row_id'))) { $vs_label = $t_content_instance->getLabelForDisplay(); if ($vs_id_fld = $t_content_instance->getProperty('ID_NUMBERING_ID_FIELD')) { $vs_label .= " (" . $t_content_instance->get($vs_id_fld) . ")"; } $vs_buf .= "<strong>" . _t("Is %1", caGetTableDisplayName($vn_item_table_num, false) . "</strong>: " . caEditorLink($po_view->request, $vs_label, '', $vn_item_table_num, $vn_row_id)) . "<br/>\n"; } $vs_buf .= "</div>\n"; } } // // Output extra useful info for lists // if ($vs_table_name === 'ca_lists' && $t_item->getPrimaryKey()) { $vs_buf .= "<strong>" . _t("Number of items") . "</strong>: " . $t_item->numItemsInList() . "<br/>\n"; $t_list_item = new ca_list_items(); $t_list_item->load(array('list_id' => $t_item->getPrimaryKey(), 'parent_id' => null)); $vs_type_list = $t_list_item->getTypeListAsHTMLFormElement('type_id', array('style' => 'width: 90px; font-size: 9px;'), array('access' => __CA_BUNDLE_ACCESS_EDIT__)); if ($vs_type_list) { $vs_buf .= '<div style="border-top: 1px solid #aaaaaa; margin-top: 5px; font-size: 10px;">'; $vs_buf .= caFormTag($po_view->request, 'Edit', 'NewChildForm', 'administrate/setup/list_item_editor/ListItemEditor', 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true)); $vs_buf .= _t('Add a %1 to this list', $vs_type_list) . caHTMLHiddenInput($t_list_item->primaryKey(), array('value' => '0')) . caHTMLHiddenInput('parent_id', array('value' => $t_list_item->getPrimaryKey())); $vs_buf .= caFormSubmitLink($po_view->request, caNavIcon($po_view->request, __CA_NAV_BUTTON_ADD__), '', 'NewChildForm'); $vs_buf .= "</form></div>\n"; } } // // Output containing list for list items // if ($vs_table_name === 'ca_list_items') { if ($t_list = $po_view->getVar('t_list')) { $vn_list_id = $t_list->getPrimaryKey(); $vs_buf .= "<strong>" . _t("Part of") . "</strong>: " . caEditorLink($po_view->request, $t_list->getLabelForDisplay(), '', 'ca_lists', $vn_list_id) . "<br/>\n"; if ($t_item->get('is_default')) { $vs_buf .= "<strong>" . _t("Is default for list") . "</strong><br/>\n"; } } } // // Output containing relationship type name for relationship types // if ($vs_table_name === 'ca_relationship_types') { if (!($t_rel_instance = $t_item->getAppDatamodel()->getInstanceByTableNum($t_item->get('table_num'), true))) { if ($vn_parent_id = $po_view->request->getParameter('parent_id', pInteger)) { $t_rel_type = new ca_relationship_types($vn_parent_id); $t_rel_instance = $t_item->getAppDatamodel()->getInstanceByTableNum($t_rel_type->get('table_num'), true); } } if ($t_rel_instance) { $vs_buf .= "<div><strong>" . _t("Is a") . "</strong>: " . $t_rel_instance->getProperty('NAME_SINGULAR') . "<br/></div>\n"; } } // // Output extra useful info for metadata elements // if ($vs_table_name === 'ca_metadata_elements' && $t_item->getPrimaryKey()) { $vs_buf .= "<div><strong>" . _t("Element code") . "</strong>: " . $t_item->get('element_code') . "<br/></div>\n"; if (sizeof($va_uis = $t_item->getUIs()) > 0) { $vs_buf .= "<div><strong>" . _t("Referenced by user interfaces") . "</strong>:<br/>\n"; foreach ($va_uis as $vn_ui_id => $va_ui_info) { $vs_buf .= caNavLink($po_view->request, $va_ui_info['name'], '', 'administrate/setup/interface_screen_editor', 'InterfaceScreenEditor', 'Edit', array('ui_id' => $vn_ui_id, 'screen_id' => $va_ui_info['screen_id'])); $vs_buf .= " (" . $o_dm->getTableProperty($va_ui_info['editor_type'], 'NAME_PLURAL') . ")<br/>\n"; } $vs_buf .= "</div>\n"; } } // // Output related objects for ca_editor_uis and ca_editor_ui_screens // if ($vs_table_name === 'ca_editor_uis') { $vs_buf .= "<div><strong>" . _t("Number of screens") . "</strong>: " . (int) $t_item->getScreenCount() . "\n"; if ($t_item->getPrimaryKey()) { $vs_buf .= "<div><strong>" . _t("Edits") . "</strong>: " . caGetTableDisplayName($t_item->get('editor_type')) . "<br/>\n"; } else { $vs_buf .= "<div><strong>" . _t("Edits") . "</strong>: " . caGetTableDisplayName($po_view->request->getParameter('editor_type', pInteger)) . "<br/>\n"; } $vs_buf .= "</div>\n"; } // // Output related objects for ca_editor_uis and ca_editor_ui_screens // if ($vs_table_name === 'ca_editor_ui_screens') { $t_ui = new ca_editor_uis($vn_ui_id = $t_item->get('ui_id')); $vs_buf .= "<div><strong>" . _t("Part of") . "</strong>: " . caNavLink($po_view->request, $t_ui->getLabelForDisplay(), '', 'administrate/setup/interface_editor', 'InterfaceEditor', 'Edit', array('ui_id' => $vn_ui_id)) . "\n"; $vs_buf .= "</div>\n"; } // // Output extra useful info for bundle displays // if ($vs_table_name === 'ca_bundle_displays') { $vs_buf .= "<div><strong>" . _t("Number of placements") . "</strong>: " . $t_item->getPlacementCount(array('user_id' => $po_view->request->getUserID())) . "<br/>\n"; if ($t_item->getPrimaryKey()) { $vn_content_table_num = $t_item->get('table_num'); $vs_buf .= "<strong>" . _t("Type of content") . "</strong>: " . caGetTableDisplayName($vn_content_table_num) . "\n"; $vs_buf .= "</div>\n"; } else { if ($vn_content_table_num = $po_view->request->getParameter('table_num', pInteger)) { $vs_buf .= "<div><strong>" . _t("Type of content") . "</strong>: " . caGetTableDisplayName($vn_content_table_num) . "\n"; $vs_buf .= "</div>\n"; } } $t_user = new ca_users(($vn_user_id = $t_item->get('user_id')) ? $vn_user_id : $po_view->request->getUserID()); if ($t_user->getPrimaryKey()) { $vs_buf .= "<div><strong>" . _t('Owner') . "</strong>: " . $t_user->get('fname') . ' ' . $t_user->get('lname') . "</div>\n"; } } // // Output extra useful info for search forms // if ($vs_table_name === 'ca_search_forms') { $vs_buf .= "<div><strong>" . _t("Number of placements") . "</strong>: " . $t_item->getPlacementCount(array('user_id' => $po_view->request->getUserID())) . "<br/>\n"; if ($t_item->getPrimaryKey()) { $vn_content_table_num = $t_item->get('table_num'); $vs_buf .= "<strong>" . _t("Searches for") . "</strong>: " . caGetTableDisplayName($vn_content_table_num) . "\n"; $vs_buf .= "</div>\n"; } else { if ($vn_content_table_num = $po_view->request->getParameter('table_num', pInteger)) { $vs_buf .= "<strong>" . _t("Searches for") . "</strong>: " . caGetTableDisplayName($vn_content_table_num) . "\n"; $vs_buf .= "</div>\n"; } } $t_user = new ca_users(($vn_user_id = $t_item->get('user_id')) ? $vn_user_id : $po_view->request->getUserID()); if ($t_user->getPrimaryKey()) { $vs_buf .= "<div><strong>" . _t('Owner') . "</strong>: " . $t_user->get('fname') . ' ' . $t_user->get('lname') . "</div>\n"; } } // // Output extra useful info for tours // if ($vs_table_name === 'ca_tours' && $t_item->getPrimaryKey()) { $vs_buf .= "<br/><strong>" . _t("Number of stops") . "</strong>: " . $t_item->getStopCount() . "<br/>\n"; } // // Output containing tour for tour stops // if ($vs_table_name === 'ca_tour_stops') { $t_tour = new ca_tours($vn_tour_id = $t_item->get('tour_id')); $vs_buf .= "<strong>" . _t("Part of") . "</strong>: " . caEditorLink($po_view->request, $t_tour->getLabelForDisplay(), '', 'ca_tours', $vn_tour_id) . "<br/>\n"; } // // Output extra useful info for bundle mappings // if ($vs_table_name === 'ca_bundle_mappings') { if ($t_item->getPrimaryKey()) { $vn_content_table_num = $t_item->get('table_num'); $vs_buf .= "<br/><strong>" . _t("Type of content") . "</strong>: " . caGetTableDisplayName($vn_content_table_num) . "<br/>\n"; $vs_buf .= "<strong>" . _t("Type") . "</strong>: " . $t_item->getChoiceListValue('direction', $t_item->get('direction')) . "<br/>\n"; $vs_buf .= "<strong>" . _t("Target format") . "</strong>: " . $t_item->get('target') . "<br/>\n"; $va_stats = $t_item->getMappingStatistics(); $vs_buf .= "<div><strong>" . _t("Number of groups") . "</strong>: " . $va_stats['groupCount'] . "<br/>\n"; $vs_buf .= "<strong>" . _t("Number of rules") . "</strong>: " . $va_stats['ruleCount'] . "<br/>\n"; $vs_buf .= "</div>\n"; } else { if ($vn_content_table_num = $po_view->request->getParameter('table_num', pInteger)) { $vs_buf .= "<div><strong>" . _t("Type of content") . "</strong>: " . caGetTableDisplayName($vn_content_table_num) . "<br/>\n"; $vs_buf .= "<strong>" . _t("Type") . "</strong>: " . $t_item->getChoiceListValue('direction', $po_view->request->getParameter('direction', pString)) . "<br/>\n"; $vs_buf .= "<strong>" . _t("Target format") . "</strong>: " . $po_view->request->getParameter('target', pString) . "<br/>\n"; $vs_buf .= "<div><strong>" . _t("Number of groups") . "</strong>: 0<br/>\n"; $vs_buf .= "<strong>" . _t("Number of rules") . "</strong>: 0</div>\n"; $vs_buf .= "</div>\n"; } } } // // Output extra useful info for client services/commerce orders // if ($vs_table_name === 'ca_commerce_orders') { $o_client_services_config = Configuration::load($po_view->request->config->get('client_services_config')); $va_order_totals = $t_item->getOrderTotals(); if ($va_order_totals['fee'] + $va_order_totals['tax'] + $va_order_totals['shipping'] + $va_order_totals['handling'] + $va_order_totals['additional_order_fees'] + $va_order_totals['additional_item_fees'] != 0) { $vs_currency_symbol = $o_client_services_config->get('currency_symbol'); $vs_buf .= "<table style='margin-left: 10px;'>"; $vs_buf .= "<tr><td><strong>" . _t("Items") . '</strong></td><td>' . $vs_currency_symbol . sprintf("%4.2f", $va_order_totals['fee']) . " (" . (int) $va_order_totals['items'] . ")</td></tr>\n"; $vs_buf .= "<tr><td><strong>" . _t("S+H") . '</strong></td><td>' . $vs_currency_symbol . sprintf("%4.2f", $va_order_totals['shipping'] + $va_order_totals['handling']) . "</td></tr>\n"; $vs_buf .= "<tr><td><strong>" . _t("Tax") . '</strong></td><td>' . $vs_currency_symbol . sprintf("%4.2f", $va_order_totals['tax']) . "</td></tr>\n"; $vs_buf .= "<tr><td><strong>" . _t("Addtl fees") . '</strong></td><td>' . $vs_currency_symbol . sprintf("%4.2f", $va_order_totals['additional_order_fees'] + $va_order_totals['additional_item_fees']) . "</td></tr>\n"; $vs_buf .= "<tr><td><strong>" . _t("Total") . '</strong></td><td>' . $vs_currency_symbol . sprintf("%4.2f", $va_order_totals['fee'] + $va_order_totals['tax'] + $va_order_totals['shipping'] + $va_order_totals['handling'] + $va_order_totals['additional_order_fees'] + $va_order_totals['additional_item_fees']) . "</td></tr>\n"; $vs_buf .= "</table>"; $vs_buf .= "<strong>" . $t_item->getFieldInfo('payment_status', 'LABEL') . "</strong>: " . $t_item->getChoiceListValue('payment_status', $t_item->get('payment_status')) . "<br/>\n"; } $vs_buf .= "<br/><strong>" . $t_item->getFieldInfo('order_status', 'LABEL') . "</strong>: " . $t_item->getChoiceListValue('order_status', $t_item->get('order_status')) . "<br/>\n"; if ($vs_shipping_date = $t_item->get('shipping_date', array('dateFormat' => 'delimited', 'timeOmit' => true))) { $vs_buf .= "<strong>" . $t_item->getFieldInfo('shipping_date', 'LABEL') . "</strong>: " . $vs_shipping_date; if ($vs_shipped_on_date = $t_item->get('shipped_on_date', array('dateFormat' => 'delimited'))) { $vs_buf .= " (" . _t('shipped %1', $vs_shipped_on_date) . ")"; } else { $vs_buf .= " (" . _t('not shipped') . ")"; } $vs_buf .= "<br/>\n"; } if (($vn_shipping_method = $t_item->get('shipping_method')) && $t_item->getChoiceListValue('shipping_method', $vn_shipping_method) != 'None') { $vs_buf .= "<strong>" . $t_item->getFieldInfo('shipping_method', 'LABEL') . "</strong>: " . $t_item->getChoiceListValue('shipping_method', $vn_shipping_method) . "<br/>\n"; } } // // Output configurable additional info from config, if set // if ($vs_additional_info = $po_view->request->config->get("{$vs_table_name}_inspector_additional_info")) { if (is_array($vs_additional_info)) { $vs_buf .= "<br/>"; foreach ($vs_additional_info as $vs_info) { $vs_buf .= caProcessTemplateForIDs($vs_info, $vs_table_name, array($t_item->getPrimaryKey()), array('requireLinkTags' => true)) . "<br/>\n"; } } else { $vs_buf .= "<br/>" . caProcessTemplateForIDs($vs_additional_info, $vs_table_name, array($t_item->getPrimaryKey()), array('requireLinkTags' => true)) . "<br/>\n"; } } // ------------------------------------------------------------------------------------- // Export if ($t_item->getPrimaryKey() && $po_view->request->config->get($vs_table_name . '_show_add_child_control_in_inspector')) { $vb_show_add_child_control = true; if (is_array($va_restrict_add_child_control_to_types = $po_view->request->config->getList($vs_table_name . '_restrict_child_control_in_inspector_to_types')) && sizeof($va_restrict_add_child_control_to_types)) { $t_type_instance = $t_item->getTypeInstance(); if (!in_array($t_type_instance->get('idno'), $va_restrict_add_child_control_to_types) && !in_array($t_type_instance->getPrimaryKey(), $va_restrict_add_child_control_to_types)) { $vb_show_add_child_control = false; } } } if ($po_view->request->user->canDoAction('can_export_' . $vs_table_name) && $t_item->getPrimaryKey() && sizeof(ca_data_exporters::getExporters($t_item->tableNum())) > 0) { $vs_buf .= '<div style="border-top: 1px solid #aaaaaa; margin-top: 5px; font-size: 10px; text-align: right;" id="caExportItemButton">'; $vs_buf .= _t('Export this %1', mb_strtolower($vs_type_name, 'UTF-8')) . " "; $vs_buf .= "<a class='button' onclick='jQuery(\"#exporterFormList\").show();' style='text-align:right;' href='#'>" . caNavIcon($po_view->request, __CA_NAV_BUTTON_ADD__) . "</a>"; $vs_buf .= caFormTag($po_view->request, 'ExportSingleData', 'caExportForm', 'manage/MetadataExport', 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true)); $vs_buf .= "<div id='exporterFormList'>"; $vs_buf .= ca_data_exporters::getExporterListAsHTMLFormElement('exporter_id', $t_item->tableNum(), array('id' => 'caExporterList'), array('width' => '120px')); $vs_buf .= caHTMLHiddenInput('item_id', array('value' => $t_item->getPrimaryKey())); $vs_buf .= caFormSubmitLink($po_view->request, _t('Export') . " ›", "button", "caExportForm"); $vs_buf .= "</div>\n"; $vs_buf .= "</form>"; $vs_buf .= "</div>"; $vs_buf .= "<script type='text/javascript'>"; $vs_buf .= "jQuery(document).ready(function() {"; $vs_buf .= "jQuery(\"#exporterFormList\").hide();"; $vs_buf .= "});"; $vs_buf .= "</script>"; } $vs_buf .= "</div></h4>\n"; $vs_buf .= "<script type='text/javascript'>\n\t\t\tvar inspectorCookieJar = jQuery.cookieJar('caCookieJar');"; if ($t_item->getPrimaryKey()) { if ($vs_more_info) { $vs_buf .= "\t\t\t\n\t\t\tif (inspectorCookieJar.get('inspectorMoreInfoIsOpen') == undefined) {\t\t// default is to have info open\n\t\t\t\tinspectorCookieJar.set('inspectorMoreInfoIsOpen', 1);\n\t\t\t}\n\t\t\tif (inspectorCookieJar.get('inspectorMoreInfoIsOpen') == 1) {\n\t\t\t\tjQuery('#inspectorInfo').toggle(0);\n\t\t\t\tjQuery('#inspectorMoreInfo').html('" . addslashes(caNavIcon($po_view->request, __CA_NAV_BUTTON_COLLAPSE__)) . "');\n\t\t\t}\n\t\t\n\t\t\tjQuery('#inspectorMoreInfo').click(function() {\n\t\t\t\tjQuery('#inspectorInfo').slideToggle(350, function() { \n\t\t\t\t\tinspectorCookieJar.set('inspectorMoreInfoIsOpen', (this.style.display == 'block') ? 1 : 0); \n\t\t\t\t\tjQuery('#inspectorMoreInfo').html((this.style.display == 'block') ? '" . addslashes(caNavIcon($po_view->request, __CA_NAV_BUTTON_COLLAPSE__)) . "' : '" . addslashes(caNavIcon($po_view->request, __CA_NAV_BUTTON_INFO2__)) . "');\n\t\t\t\t\tcaResizeSideNav();\n\t\t\t\t}); \n\t\t\t\treturn false;\n\t\t\t});\n\t\t"; } if (sizeof($va_reps)) { $vs_buf .= "\n\t\tif (inspectorCookieJar.get('inspectorShowMediaIsOpen') == undefined) {\t\t// default is to have media open\n\t\t\tinspectorCookieJar.set('inspectorShowMediaIsOpen', 1);\n\t\t}\n\t\t\n\t\tif (inspectorCookieJar.get('inspectorShowMediaIsOpen') == 1) {\n\t\t\tjQuery('#inspectorMedia').toggle();\n\t\t}\n\t\n\t\tjQuery('#caColorbox').on('click', function(e) {\n\t\t\tif (e.altKey) {\n\t\t\t\tjQuery('#inspectorMedia').slideToggle(200, function() { \n\t\t\t\t\tinspectorCookieJar.set('inspectorShowMediaIsOpen', (this.style.display == 'block') ? 1 : 0); \n\t\t\t\t\t\tcaResizeSideNav();\n\t\t\t\t}); \n\t\t\t\treturn false;\n\t\t\t}\n\t\t});\n\t\t\t\t\t"; } } $vs_buf .= "</script>\n"; } $o_app_plugin_manager = new ApplicationPluginManager(); $va_hookAppend = $o_app_plugin_manager->hookAppendToEditorInspector(array("t_item" => $t_item)); if (is_string($va_hookAppend["caEditorInspectorAppend"])) { $vs_buf .= $va_hookAppend["caEditorInspectorAppend"]; } return $vs_buf; }
/** * Get a record summary that is easier to parse when importing to another system */ private function getItemInfoForImport() { if (!($t_instance = $this->_getTableInstance($this->ops_table, $this->opn_id))) { return false; } $o_dm = Datamodel::load(); $t_list = new ca_lists(); $t_locales = new ca_locales(); // // Options // if (!($vs_delimiter = $this->opo_request->getParameter('delimiter', pString))) { $vs_delimiter = "; "; } if (!($vs_flatten = $this->opo_request->getParameter('flatten', pString))) { $vs_flatten = null; } $va_flatten = preg_split("![ ]*[;]+[ ]*!", $vs_flatten); $va_flatten = array_flip($va_flatten); $va_locales = $t_locales->getLocaleList(array("available_for_cataloguing_only" => true)); $va_return = array(); // allow user-defined template to be passed; allows flexible formatting of returned "display" value if (!($vs_template = $this->opo_request->getParameter('template', pString))) { $vs_template = ''; } if ($vs_template) { $va_return['display'] = caProcessTemplateForIDs($vs_template, $this->ops_table, array($this->opn_id)); } // "intrinsic" fields foreach ($t_instance->getFieldsArray() as $vs_field_name => $va_field_info) { $vs_list = null; if (!is_null($vs_val = $t_instance->get($vs_field_name))) { if (preg_match("/^hier\\_/", $vs_field_name)) { continue; } if (preg_match("/\\_sort\$/", $vs_field_name)) { continue; } if ($vs_field_name == $t_instance->primaryKey()) { continue; } if (isset($va_field_info["LIST_CODE"])) { // typical example: type_id $va_item = $t_list->getItemFromListByItemID($va_field_info["LIST_CODE"], $vs_val); if ($t_item = new ca_list_items($va_item["item_id"])) { $vs_val = $t_item->get('idno'); } } $va_return['intrinsic'][$vs_field_name] = $vs_val; } } // preferred labels $va_labels = $t_instance->get($this->ops_table . ".preferred_labels", array("returnAllLocales" => true)); $va_labels = end($va_labels); $vs_display_field_name = $t_instance->getLabelDisplayField(); if (is_array($va_labels)) { foreach ($va_labels as $vn_locale_id => $va_labels_by_locale) { foreach ($va_labels_by_locale as $va_tmp) { $va_label = array(); $va_label['locale'] = $va_locales[$vn_locale_id]["code"]; // add only UI fields to return foreach (array_merge($t_instance->getLabelUIFields(), array('type_id')) as $vs_label_fld) { $va_label[$vs_label_fld] = $va_tmp[$vs_label_fld]; } $va_label[$vs_label_fld] = $va_tmp[$vs_label_fld]; $va_label['label'] = $va_tmp[$vs_display_field_name]; $va_return["preferred_labels"][$va_label['locale']] = $va_label; } } if (isset($va_flatten['locales'])) { $va_return["preferred_labels"] = array_pop(caExtractValuesByUserLocale(array($va_return["preferred_labels"]))); } } // nonpreferred labels $va_labels = $t_instance->get($this->ops_table . ".nonpreferred_labels", array("returnAllLocales" => true)); $va_labels = end($va_labels); if (is_array($va_labels)) { foreach ($va_labels as $vn_locale_id => $va_labels_by_locale) { foreach ($va_labels_by_locale as $va_tmp) { $va_label = array(); $va_label['locale'] = $va_locales[$vn_locale_id]["code"]; // add only UI fields to return foreach (array_merge($t_instance->getLabelUIFields(), array('type_id')) as $vs_label_fld) { $va_label[$vs_label_fld] = $va_tmp[$vs_label_fld]; } $va_return["nonpreferred_labels"][$va_label['locale']] = $va_label; } } if (isset($va_flatten['locales'])) { $va_return["nonpreferred_labels"] = array_pop(caExtractValuesByUserLocale(array($va_return["nonpreferred_labels"]))); } } // attributes $va_codes = $t_instance->getApplicableElementCodes(); foreach ($va_codes as $vs_code) { if ($va_vals = $t_instance->get($this->ops_table . "." . $vs_code, array("convertCodesToDisplayText" => false, "returnAllLocales" => true))) { $va_vals_as_text = end($t_instance->get($this->ops_table . "." . $vs_code, array("convertCodesToDisplayText" => true, "returnAllLocales" => true))); $va_vals_by_locale = end($va_vals); foreach ($va_vals_by_locale as $vn_locale_id => $va_locale_vals) { foreach ($va_locale_vals as $vs_val_id => $va_actual_data) { if (!is_array($va_actual_data)) { continue; } $vs_locale_code = isset($va_locales[$vn_locale_id]["code"]) ? $va_locales[$vn_locale_id]["code"] : "none"; foreach ($va_actual_data as $vs_f => $vs_v) { if (isset($va_vals_as_text[$vn_locale_id][$vs_val_id][$vs_f]) && $vs_v != $va_vals_as_text[$vn_locale_id][$vs_val_id][$vs_f]) { $va_actual_data[$vs_f . '_display'] = $va_vals_as_text[$vn_locale_id][$vs_val_id][$vs_f]; if ($vs_item_idno = caGetListItemIdno($va_actual_data[$vs_f])) { $va_actual_data[$vs_f] = $vs_item_idno; } } } $va_return['attributes'][$vs_code][$vs_locale_code][] = array_merge(array('locale' => $vs_locale_code), $va_actual_data); } } } } if (isset($va_flatten['locales'])) { $va_return['attributes'] = caExtractValuesByUserLocale($va_return['attributes']); } // relationships // yes, not all combinations between these tables have // relationships but it also doesn't hurt to query foreach ($this->opa_valid_tables as $vs_rel_table) { $t_rel = $o_dm->getInstanceByTableName($vs_rel_table, true); // // set-related hacks if ($this->ops_table == "ca_sets" && $vs_rel_table == "ca_tours") { // throw SQL error in getRelatedItems continue; } $va_related_items = $t_instance->get($vs_rel_table, array("returnAsArray" => true, 'returnLocaleCodes' => true, 'groupFields' => true)); if ($this->ops_table == "ca_objects" && $vs_rel_table == "ca_object_representations") { $va_versions = $t_instance->getMediaVersions('media'); if (isset($va_flatten['all'])) { $va_reps = $t_instance->getRepresentations(array('original')); $va_urls = array(); foreach ($va_reps as $vn_i => $va_rep) { $va_urls[] = $va_rep['urls']['original']; } $va_return['representations'] = join($vs_delimiter, $va_urls); } else { $va_return['representations'] = $t_instance->getRepresentations($va_versions); } foreach ($va_return['representations'] as $vn_i => $va_rep) { unset($va_return['representations'][$vn_i]['media']); unset($va_return['representations'][$vn_i]['media_metadata']); } } if (is_array($va_related_items) && sizeof($va_related_items) > 0) { foreach ($va_related_items as $va_rel_item) { $va_item_add = array(); foreach ($va_rel_item as $vs_fld => $vs_val) { if (!is_array($vs_val) && strlen(trim($vs_val)) > 0) { // rewrite and ignore certain field names switch ($vs_fld) { case 'item_type_id': $va_item_add[$vs_fld] = $vs_val; $va_item_add['type_id'] = $vs_val; break; default: $va_item_add[$vs_fld] = $vs_val; break; } } else { if (in_array($vs_fld, array('preferred_labels', 'intrinsic'))) { $va_item_add[$vs_fld] = $vs_val; } } } if ($vs_rel_table == "ca_object_representations") { $t_rep = new ca_object_representations($va_rel_item['representation_id']); $va_item_add['media'] = $t_rep->getMediaUrl('media', 'original'); } $va_return["related"][$vs_rel_table][] = $va_item_add; } } } return $va_return; }
/** * @param mixed $ps_value * @param array $pa_element_info * @param array $pa_options Options are: * alwaysTreatValueAsIdno = Always try to convert $ps_value to a list idno value, even if it is numeric * * @return array */ public function parseValue($ps_value, $pa_element_info, $pa_options = null) { $vb_treat_value_as_idno = caGetOption('alwaysTreatValueAsIdno', $pa_options, false); $vb_require_value = is_null($pa_element_info['settings']['requireValue']) ? true : (bool) $pa_element_info['settings']['requireValue']; if ($vb_treat_value_as_idno || preg_match('![^\\d]+!', $ps_value)) { // try to convert idno to item_id if ($vn_id = ca_lists::getItemID($pa_element_info['list_id'], $ps_value)) { $ps_value = $vn_id; } } if (!$vb_require_value && !(int) $ps_value) { return array('value_longtext1' => null, 'item_id' => null); } if (strlen($ps_value) && !is_numeric($ps_value)) { $this->postError(1970, _t('Item_id %2 is not valid for element %1', $pa_element_info["element_code"], $ps_value), 'ListAttributeValue->parseValue()'); return false; } $t_item = new ca_list_items((int) $ps_value); if (!$t_item->getPrimaryKey()) { if ($ps_value) { $this->postError(1970, _t('%1 is not a valid list item_id for %2 [%3]', $ps_value, $pa_element_info['displayLabel'], $pa_element_info['element_code']), 'ListAttributeValue->parseValue()'); } else { //$this->postError(1970, _t('Value %1 [%2] cannot be blank', $pa_element_info['displayLabel'], $pa_element_info['element_code']), 'ListAttributeValue->parseValue()'); return null; } return false; } if ((int) $t_item->get('list_id') != (int) $pa_element_info['list_id']) { $this->postError(1970, _t('Item is not in the correct list for element %1. List id is %2 but should be %3', $pa_element_info["element_code"], $t_item->get('list_id'), $pa_element_info['list_id']), 'ListAttributeValue->parseValue()'); return false; } return array('value_longtext1' => $ps_value, 'item_id' => (int) $ps_value); }
?> " class="caEditItemButton" id="<?php print $vs_id_prefix; ?> _edit_related_{n}"><?php print caNavIcon($this->request, __CA_NAV_BUTTON_GO__); ?> </a> </td> </tr> </table> <?php } else { $vn_use_as_root_id = 'null'; if (sizeof($va_settings['restrict_to_lists']) == 1) { $t_item = new ca_list_items(); if ($t_item->load(array('list_id' => $va_settings['restrict_to_lists'][0], 'parent_id' => null))) { $vn_use_as_root_id = $t_item->getPrimaryKey(); } } if (!$vb_read_only && !$vb_dont_show_del) { ?> <div style="float: right;"><a href="#" class="caDeleteItemButton"><?php print caNavIcon($this->request, __CA_NAV_BUTTON_DEL_BUNDLE__); ?> </a></div> <?php } ?> <div style='width: 690px; height: <?php print $va_settings['hierarchicalBrowserHeight'];
public function getDisplaysAsXML() { $t_display = new ca_bundle_displays(); /** @var Datamodel $o_dm */ $o_dm = Datamodel::load(); $this->opt_locale = new ca_locales(); $va_displays = $t_display->getBundleDisplays(); $vs_buf = "<displays>\n"; foreach ($va_displays as $vn_i => $va_display_by_locale) { $va_locales = array_keys($va_display_by_locale); $va_info = $va_display_by_locale[$va_locales[0]]; if (!$t_display->load($va_info['display_id'])) { continue; } $vs_buf .= "\t<display code='" . ($va_info['display_code'] && preg_match('!^[A-Za-z0-9_]+$!', $va_info['display_code']) ? $va_info['display_code'] : 'display_' . $va_info['display_id']) . "' type='" . $o_dm->getTableName($va_info['table_num']) . "' system='" . $t_display->get('is_system') . "'>\n"; $vs_buf .= "\t\t<labels>\n"; foreach ($va_display_by_locale as $vn_locale_id => $va_display_info) { if (strlen($this->opt_locale->localeIDToCode($vn_locale_id)) > 0) { $vs_buf .= "\t\t\t<label locale='" . $this->opt_locale->localeIDToCode($vn_locale_id) . "'><name>" . caEscapeForXML($va_display_info['name']) . "</name></label>\n"; } } $vs_buf .= "\t\t</labels>\n"; $va_settings = $t_display->getSettings(); if (sizeof($va_settings) > 0) { $vs_buf .= "\t\t<settings>\n"; foreach ($va_settings as $vs_setting => $vm_val) { if (is_array($vm_val)) { foreach ($vm_val as $vn_i => $vn_val) { $vs_buf .= "\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vn_val . "]]></setting>\n"; } } else { $vs_buf .= "\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vm_val . "]]></setting>\n"; } } $vs_buf .= "\t\t</settings>\n"; } // User and group access $va_users = $t_display->getUsers(); if (sizeof($va_users) > 0) { $vs_buf .= "\t\t<userAccess>\n"; foreach ($va_users as $va_user_info) { $vs_buf .= "\t\t\t<permission user='******' access='" . $this->_convertUserGroupAccessToString(intval($va_user_info['access'])) . "'/>\n"; } $vs_buf .= "\t\t</userAccess>\n"; } $va_groups = $t_display->getUserGroups(); if (sizeof($va_groups) > 0) { $vs_buf .= "\t\t<groupAccess>\n"; foreach ($va_groups as $va_group_info) { $vs_buf .= "\t\t\t<permission group='" . $va_group_info["code"] . "' access='" . $this->_convertUserGroupAccessToString(intval($va_group_info['access'])) . "'/>\n"; } $vs_buf .= "\t\t</groupAccess>\n"; } $va_placements = $t_display->getPlacements(); $vs_buf .= "<bundlePlacements>\n"; foreach ($va_placements as $vn_placement_id => $va_placement_info) { $vs_buf .= "\t\t<placement code='" . preg_replace("![^A-Za-z0-9_]+!", "_", $va_placement_info['bundle_name']) . "'><bundle>" . $va_placement_info['bundle_name'] . "</bundle>\n"; $va_settings = caUnserializeForDatabase($va_placement_info['settings']); if (is_array($va_settings)) { $vs_buf .= "<settings>\n"; foreach ($va_settings as $vs_setting => $vm_value) { switch ($vs_setting) { case 'label': if (is_array($vm_value)) { foreach ($vm_value as $vn_locale_id => $vm_locale_specific_value) { if (preg_match("/^[a-z]{2,3}\\_[A-Z]{2,3}\$/", $vn_locale_id)) { // locale code $vs_locale_code = $vn_locale_id; } else { if (!($vs_locale_code = $this->opt_locale->localeIDToCode($vn_locale_id))) { $vs_locale_code = 'en_US'; } } $vs_buf .= "<setting name='label' locale='" . $vs_locale_code . "'>" . caEscapeForXML($vm_locale_specific_value) . "</setting>\n"; } } break; case 'restrict_to_relationship_types': if (is_array($vm_value)) { foreach ($vm_value as $vn_val) { $t_rel_type = new ca_relationship_types($vn_val); if ($t_rel_type->getPrimaryKey()) { $vs_value = $t_rel_type->get('type_code'); $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vs_value . "]]></setting>\n"; } } } break; case 'restrict_to_types': if (is_array($vm_value)) { foreach ($vm_value as $vn_val) { $t_item = new ca_list_items($vn_val); if ($t_item->getPrimaryKey()) { $vs_value = $t_item->get('idno'); $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vs_value . "]]></setting>\n"; } } } break; default: if (is_array($vm_value)) { foreach ($vm_value as $vn_i => $vn_val) { $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vn_val . "]]></setting>\n"; } } else { $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vm_value . "]]></setting>\n"; } break; } } $vs_buf .= "</settings>\n"; } $vs_buf .= "\t\t</placement>\n"; } $vs_buf .= "</bundlePlacements>\n"; $vs_buf .= "\t</display>\n"; } $vs_buf .= "</displays>\n"; return $vs_buf; }
?> _id{n}" value="{id}"/> </td> <td> <a href="#" class="caDeleteItemButton"><?php print caNavIcon($this->request, __CA_NAV_BUTTON_DEL_BUNDLE__); ?> </a> </td> </tr> </table> <?php } else { $vn_use_as_root_id = 'null'; if (sizeof($va_settings['restrict_to_lists']) == 1) { $t_item = new ca_list_items(); if ($t_item->load(array('list_id' => $va_settings['restrict_to_lists'][0], 'parent_id' => null))) { $vn_use_as_root_id = $t_item->getPrimaryKey(); } } ?> <div style="float: right;"><a href="#" class="caDeleteItemButton"><?php print caNavIcon($this->request, __CA_NAV_BUTTON_DEL_BUNDLE__); ?> </a></div> <div style='width: 700px; height: <?php print $va_settings['hierarchicalBrowserHeight']; ?> ;'>
/** * */ public function getTypeMenu() { $t_list = new ca_lists(); $t_list->load(array('list_code' => $this->getTypeListCode())); $t_list_item = new ca_list_items(); $t_list_item->load(array('list_id' => $t_list->getPrimaryKey(), 'parent_id' => null)); $va_hierarchy = caExtractValuesByUserLocale($t_list_item->getHierarchyWithLabels()); $va_types = array(); if (is_array($va_hierarchy)) { $va_types_by_parent_id = array(); $vn_root_id = null; foreach ($va_hierarchy as $vn_item_id => $va_item) { if (!$vn_root_id) { $vn_root_id = $va_item['parent_id']; continue; } $va_types_by_parent_id[$va_item['parent_id']][] = $va_item; } foreach ($va_hierarchy as $vn_item_id => $va_item) { if ($va_item['parent_id'] != $vn_root_id) { continue; } // does this item have sub-items? if (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); } else { $va_subtypes = array(); } $va_types[] = array('displayName' => $va_item['name_singular'], 'parameters' => array('type_id' => $va_item['item_id']), 'navigation' => $va_subtypes); } } return $va_types; }