/** * */ public function refine(&$pa_destination_data, $pa_group, $pa_item, $pa_source_data, $pa_options = null) { $o_log = isset($pa_options['log']) && is_object($pa_options['log']) ? $pa_options['log'] : null; // Set place hierarchy if ($vs_hierarchy = $pa_item['settings']['placeSplitter_placeHierarchy']) { $vn_hierarchy_id = caGetListItemID('place_hierarchies', $vs_hierarchy); } else { // Default to first place hierarchy $t_list = new ca_lists(); $va_hierarchy_ids = $t_list->getItemsForList('place_hierarchies', array('idsOnly' => true)); $vn_hierarchy_id = array_shift($va_hierarchy_ids); } if (!$vn_hierarchy_id) { if ($o_log) { $o_log->logError(_t('[placeSplitterRefinery] No place hierarchies are defined')); } return array(); } $pa_options['hierarchyID'] = $vn_hierarchy_id; $t_place = new ca_places(); if ($t_place->load(array('parent_id' => null, 'hierarchy_id' => $vn_hierarchy_id))) { $pa_options['defaultParentID'] = $t_place->getPrimaryKey(); } return caGenericImportSplitter('placeSplitter', 'place', 'ca_places', $this, $pa_destination_data, $pa_group, $pa_item, $pa_source_data, $pa_options); }
public function __construct($ps_widget_path, $pa_settings) { $this->title = _t('Records by status'); $this->description = _t('Displays objects or authority items by cataloguing status'); parent::__construct($ps_widget_path, $pa_settings); $this->opo_config = Configuration::load($ps_widget_path . '/conf/recordsByStatus.conf'); $this->opo_datamodel = Datamodel::load(); # -- get status values $t_lists = new ca_lists(); $va_statuses = caExtractValuesByUserLocale($t_lists->getItemsForList("workflow_statuses")); $va_status_info = array(); $va_status_values = array(); foreach ($va_statuses as $i => $va_info) { $va_status_info[$va_info["item_value"]] = $va_info["name_singular"]; $va_status_values[] = $va_info["item_value"]; } $this->opa_status_display_names = $va_status_info; $this->opa_status_values = $va_status_values; $this->opa_table_display_names = array('ca_objects' => _t('Objects'), 'ca_entities' => _t('Entities'), 'ca_places' => _t('Places'), 'ca_occurrences' => _t('Occurrences'), 'ca_sets' => _t('Sets'), 'ca_collections' => _t('Collections'), 'ca_object_representations' => _t('Object representations'), 'ca_object_lots' => _t('Object lots')); foreach ($this->opa_table_display_names as $vs_table => $vs_display) { if (!$this->getRequest() || !$this->getRequest()->user->canDoAction("can_use_records_by_status_widget_{$vs_table}")) { foreach (BaseWidget::$s_widget_settings['recordsByStatusWidget']["display_type"]["options"] as $vs_setting_display => $vs_setting_table) { if ($vs_setting_table == $vs_table) { unset(BaseWidget::$s_widget_settings['recordsByStatusWidget']["display_type"]["options"][$vs_setting_display]); } } } } }
public function __construct(&$po_request, &$po_response, $pa_view_paths = null) { $this->ops_theme = __CA_THEME__; // get current theme if (!is_dir(__CA_APP_DIR__ . '/plugins/MetabolicChronology/themes/' . $this->ops_theme . '/views')) { // if theme is not defined for this plugin, try to use "default" theme $this->ops_theme = 'default'; } parent::__construct($po_request, $po_response, array(__CA_APP_DIR__ . '/plugins/MetabolicChronology/themes/' . $this->ops_theme . '/views')); $this->opo_plugin_config = Configuration::load($this->request->getAppConfig()->get('application_plugins') . '/MetabolicChronology/conf/Chronology.conf'); if (!(bool) $this->opo_plugin_config->get('enabled')) { die(_t('Metabolic Chronology plugin is not enabled')); } $this->_initView($pa_options); $this->opo_result_context = new ResultContext($po_request, 'ca_objects', 'MetabolicChronology'); MetaTagManager::addLink('stylesheet', $po_request->getBaseUrlPath() . "/app/plugins/MetabolicChronology/themes/" . $this->ops_theme . "/css/chronology.css", 'text/css'); JavascriptLoadManager::register('jcarousel'); JavascriptLoadManager::register('maps'); $t_list = new ca_lists(); $this->opn_silo_type_id = $t_list->getItemIDFromList('collection_types', 'silo'); $this->opn_action_type_id = $t_list->getItemIDFromList('occurrence_types', 'action'); $this->opn_context_type_id = $t_list->getItemIDFromList('occurrence_types', 'context'); $this->opn_yes_list_id = $t_list->getItemIDFromList('yes_no', 'yes'); $t_relationship_types = new ca_relationship_types(); $this->opn_rel_type_action_display_image = $t_relationship_types->getRelationshipTypeID("ca_objects_x_occurrences", "display"); $this->opn_rel_type_action_secondary_images = $t_relationship_types->getRelationshipTypeID("ca_objects_x_occurrences", "secondary"); $va_access_values = caGetUserAccessValues($this->request); $this->opa_access_values = $va_access_values; $this->view->setVar('access_values', $va_access_values); }
/** * */ public function __construct(&$po_request, &$po_response, $pa_view_paths = null) { $this->ops_theme = __CA_THEME__; // get current theme if (!is_dir(__CA_APP_DIR__ . '/plugins/Contribute/themes/' . $this->ops_theme . '/views')) { // if theme is not defined for this plugin, try to use "default" theme $this->ops_theme = 'default'; } parent::__construct($po_request, $po_response, array(__CA_APP_DIR__ . '/plugins/Contribute/themes/' . $this->ops_theme . '/views')); #$this->opo_plugin_config = Configuration::load($po_request->getAppConfig()->get('application_plugins').'/Contribute/conf/contribute.conf'); if (file_exists($po_request->getAppConfig()->get('application_plugins') . '/Contribute/themes/' . $this->ops_theme . '/conf/contribute.conf')) { // check if there is a config file in the theme first $this->opo_plugin_config = Configuration::load($po_request->getAppConfig()->get('application_plugins') . '/Contribute/themes/' . $this->ops_theme . '/conf/contribute.conf'); } else { $this->opo_plugin_config = Configuration::load($po_request->getAppConfig()->get('application_plugins') . '/Contribute/conf/contribute.conf'); } if (!(bool) $this->opo_plugin_config->get('enabled')) { die(_t('Contribute plugin is not enabled')); } $vs_default_ui = $this->opo_plugin_config->get('default_ui'); $vs_requested_ui = $this->request->getParameter('ui', pString); $va_ui_list = $this->opo_plugin_config->getAssoc('uis'); $o_dm = Datamodel::load(); if (isset($va_ui_list[$vs_requested_ui]) && is_array($va_ui_list[$vs_requested_ui])) { $this->opa_ui_info = $va_ui_list[$vs_requested_ui]; $this->ops_ui_code = $vs_requested_ui; } else { if (isset($va_ui_list[$vs_default_ui]) && is_array($va_ui_list[$vs_default_ui])) { $this->opa_ui_info = $va_ui_list[$vs_default_ui]; } else { $vs_default_ui = array_shift(array_keys($va_ui_list)); $this->opa_ui_info = $va_ui_list[$vs_default_ui]; } $this->ops_ui_code = $vs_default_ui; } $this->ops_table_name = $this->opa_ui_info['table']; if (!($this->opo_instance = $o_dm->getInstanceByTableName($this->ops_table_name, true))) { die(_t('Invalid table "%1" specified in Contribute plugin for form "%2"', $this->ops_table_name, $vs_default_ui)); } $t_list = new ca_lists(); if (isset($this->opa_ui_info['type']) && $this->opa_ui_info['type']) { $this->opa_ui_info['type_id'] = $t_list->getItemIDFromList($this->opo_instance->getTypeListCode(), $this->opa_ui_info['type']); } if (isset($this->opa_ui_info['representation_type']) && $this->opa_ui_info['representation_type']) { $this->opa_ui_info['representation_type_id'] = $t_list->getItemIDFromList('object_representation_types', $this->opa_ui_info['representation_type']); } ContributePlugin::setUIInfo($this->ops_ui_code, $this->opa_ui_info); JavascriptLoadManager::register('panel'); MetaTagManager::addLink('stylesheet', $po_request->getBaseUrlPath() . "/app/plugins/Contribute/themes/" . $this->ops_theme . "/css/contribute.css", 'text/css'); $this->request->setParameter('dont_set_pawtucket2_last_page', '1'); // Setting this parameter ensures that the "last page" we (may) redirect to after submission isn't the Contribute form itself if ($this->opa_ui_info['require_login'] && !$po_request->isLoggedIn()) { $this->notification->addNotification(_t("You must be logged in to use user contribution features."), __NOTIFICATION_TYPE_ERROR__); $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'form')); return; } }
public function displaySet() { $pn_set_id = $this->request->getParameter('set_id', pInteger); $t_set = new ca_sets($pn_set_id); $t_list = new ca_lists(); $va_access_values = caGetUserAccessValues($this->request); $this->view->setVar('t_set', $t_set); $this->view->setVar('set_presentation_types', caExtractValuesByUserLocale($t_list->getItemsForList('set_presentation_types'))); $this->view->setVar('access_values', $va_access_values); $this->render('features_contents_html.php'); }
/** * 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 testInsertLoadAndDeleteCycleWithCaObjectsModel() { $t_list = new ca_lists(); $va_object_types = $t_list->getItemsForList('object_types'); $this->assertGreaterThan(0, sizeof($va_object_types), "No object types available"); $va_object_types = caExtractValuesByUserLocale($va_object_types); $this->assertGreaterThan(0, sizeof($va_object_types), "No locale-filtered object types available"); $vn_locale_id = 1; $t_object = new ca_objects(); $t_object->setMode(ACCESS_WRITE); $vn_item_id = 0; foreach ($va_object_types as $va_object_type) { if (intval($va_object_type['is_enabled']) === 1) { $vn_item_id = $va_object_type['item_id']; } } $this->assertGreaterThan(0, $vn_item_id, 'No enabled object type found'); $t_object->set('type_id', $vn_item_id); $t_object->set('locale_id', $vn_locale_id); $t_object->set('idno', time()); $t_object->addAttribute(array('description' => 'Test description', 'locale_id' => $vn_locale_id), 'description'); $vb_res = $t_object->insert(); $this->assertTrue($vb_res !== false, 'Insert returned non-true value'); // insert() returns false OR the primary key, therefore simply asserting $vb_res being true doesn't cut it $this->assertEquals($t_object->numErrors(), 0, "Errors on insert: " . join('; ', $t_object->getErrors())); $this->opa_test_record_ids['ca_objects'][] = $t_object->getPrimaryKey(); $vb_res = $t_object->addLabel(array('name' => 'Unit test object'), $vn_locale_id, null, true); $this->assertGreaterThan(0, $vb_res, 'AddLabel returned zero value but should return non-zero label_id: ' . join('; ', $t_object->getErrors())); $t_object2 = new ca_objects(); $vb_res = $t_object2->load($t_object->getPrimaryKey()); $this->assertTrue($vb_res, 'Load of newly created record failed [record does not seem to exist or return row id was invalid?]'); $this->assertEquals($t_object2->getLabelForDisplay(), 'Unit test object', 'Retrieved row label does not match'); $this->assertEquals($t_object2->getAttributesForDisplay('description'), 'Test description', 'Retrieved value for attribute "description" does not match expected value'); // try to search for it $o_search = new ObjectSearch(); $qr_hits = $o_search->search("Unit test object"); $this->assertGreaterThan(0, $qr_hits->numHits(), 'Search for ca_object by label found no results'); $vb_found_object = false; while ($qr_hits->nextHit()) { if ($qr_hits->get('object_id') == $t_object->getPrimaryKey()) { $vb_found_object = true; break; } } $this->assertTrue($vb_found_object, 'ca_object was not in returned search results for ca_object by label'); // try delete $t_object->delete(true, array('hard' => true)); $this->assertEquals($t_object->numErrors(), 0, "Errors on delete: " . join('; ', $t_object->getErrors())); }
/** * */ public function __call($ps_function, $pa_args) { $ps_function = strtolower($ps_function); # --- which type of set is configured for display in gallery section $t_list = new ca_lists(); $vn_gallery_set_type_id = $t_list->getItemIDFromList('set_types', $this->config->get('gallery_set_type')); $t_set = new ca_sets(); if ($ps_function == "index") { if ($vn_gallery_set_type_id) { $va_sets = caExtractValuesByUserLocale($t_set->getSets(array('table' => 'ca_objects', 'checkAccess' => $this->opa_access_values, 'setType' => $vn_gallery_set_type_id))); $va_set_first_items = $t_set->getFirstItemsFromSets(array_keys($va_sets), array("version" => "icon", "checkAccess" => $this->opa_access_values)); $o_front_config = caGetFrontConfig(); $vs_front_page_set = $o_front_config->get('front_page_set_code'); $vb_omit_front_page_set = (bool) $this->config->get('omit_front_page_set_from_gallery'); foreach ($va_sets as $vn_set_id => $va_set) { if ($vb_omit_front_page_set && $va_set['set_code'] == $vs_front_page_set) { unset($va_sets[$vn_set_id]); } } $this->view->setVar('sets', $va_sets); $this->view->setVar('first_items_from_sets', $va_set_first_items); } MetaTagManager::setWindowTitle($this->request->config->get("app_display_name") . ": " . ($this->config->get('gallery_section_name') ? $this->config->get('gallery_section_name') : _t("Gallery"))); $this->render("Gallery/index_html.php"); } else { $ps_set_id = $ps_function; $this->view->setVar("set_id", $ps_set_id); $t_set->load($ps_set_id); $this->view->setVar("set", $t_set); $this->view->setVar("label", $t_set->getLabelForDisplay()); $this->view->setVar("description", $t_set->get($this->config->get('gallery_set_description_element_code'))); $this->view->setVar("set_items", caExtractValuesByUserLocale($t_set->getItems(array("thumbnailVersions" => array("icon", "iconlarge"), "checkAccess" => $this->opa_access_values)))); $pn_set_item_id = $this->request->getParameter('set_item_id', pInteger); if (!in_array($pn_set_item_id, array_keys($t_set->getItemIDs()))) { $pn_set_item_id = ""; } $this->view->setVar("set_item_id", $pn_set_item_id); MetaTagManager::setWindowTitle($this->request->config->get("app_display_name") . ": " . ($this->config->get('gallery_section_name') ? $this->config->get('gallery_section_name') : _t("Gallery")) . ": " . $t_set->getLabelForDisplay()); $this->render("Gallery/detail_html.php"); } }
public function setUp() { $t_list = new ca_lists(); // add a minimal object for testing $va_object_types = $t_list->getItemsForList('object_types', array('idsOnly' => true, 'enabledOnly' => true)); $t_object = new ca_objects(); $t_object->setMode(ACCESS_WRITE); $t_object->set('type_id', array_shift($va_object_types)); $t_object->insert(); $this->opn_object_id = $t_object->getPrimaryKey(); $this->assertGreaterThan(0, $this->opn_object_id, 'Object should have a primary key after insert'); // add minimal set $va_set_types = $t_list->getItemsForList('set_types', array('idsOnly' => true, 'enabledOnly' => true)); $t_set = new ca_sets(); $t_set->setMode(ACCESS_WRITE); $t_set->set('type_id', array_shift($va_set_types)); $t_set->set('table_num', $t_object->tableNum()); $t_set->insert(); $this->opn_set_id = $t_set->getPrimaryKey(); $this->assertGreaterThan(0, $this->opn_set_id, 'Set should have a primary key after insert'); }
public function __construct(&$po_request, &$po_response, $pa_view_paths = null) { $this->ops_theme = __CA_THEME__; // get current theme if (!is_dir(__CA_APP_DIR__ . '/plugins/NovaMuse/themes/' . $this->ops_theme . '/views')) { // if theme is not defined for this plugin, try to use "default" theme $this->ops_theme = 'default'; } parent::__construct($po_request, $po_response, array(__CA_APP_DIR__ . '/plugins/NovaMuse/themes/' . $this->ops_theme . '/views')); $this->opo_plugin_config = Configuration::load($this->request->getAppConfig()->get('application_plugins') . '/NovaMuse/conf/NovaMuse.conf'); if (!(bool) $this->opo_plugin_config->get('enabled')) { die(_t('NovaMuse plugin is not enabled')); } MetaTagManager::addLink('stylesheet', $po_request->getBaseUrlPath() . "/app/plugins/NovaMuse/themes/" . $this->ops_theme . "/css/memberMap.css", 'text/css'); JavascriptLoadManager::register('maps'); $this->opo_result_context = new ResultContext($po_request, 'ca_entities', 'member_map'); $t_list = new ca_lists(); $this->opn_member_institution_id = $t_list->getItemIDFromList('entity_types', 'member_institution'); $va_access_values = caGetUserAccessValues($this->request); $this->opa_access_values = $va_access_values; $this->view->setVar('access_values', $va_access_values); }
public function __construct(&$po_request, &$po_response, $pa_view_paths = null) { $this->ops_theme = __CA_THEME__; // get current theme if (!is_dir(__CA_APP_DIR__ . '/plugins/eastend/themes/' . $this->ops_theme . '/views')) { // if theme is not defined for this plugin, try to use "default" theme $this->ops_theme = 'default'; } parent::__construct($po_request, $po_response, array(__CA_APP_DIR__ . '/plugins/eastend/themes/' . $this->ops_theme . '/views')); MetaTagManager::addLink('stylesheet', $po_request->getBaseUrlPath() . "/app/plugins/eastend/themes/" . $this->ops_theme . "/css/eastend.css", 'text/css'); $this->opo_plugin_config = Configuration::load($this->request->getAppConfig()->get('application_plugins') . '/eastend/conf/eastend.conf'); if (!(bool) $this->opo_plugin_config->get('enabled')) { die(_t('eastend plugin is not enabled')); } // redirect user if not logged in if ($this->request->config->get('pawtucket_requires_login') && !$this->request->isLoggedIn()) { $this->response->setRedirect(caNavUrl($this->request, "", "LoginReg", "form")); } JavascriptLoadManager::register('cycle'); $t_list = new ca_lists(); $this->view->setVar("user_contributed_source_id", $t_list->getItemIDFromList('object_sources', 'user_contributed')); $this->view->setVar("user_contributed_other_source_id", $t_list->getItemIDFromList('object_sources', 'user_contributed_other')); }
public function setUp() { // don't forget to call parent so that request is set up correctly parent::setUp(); // search subject table $this->setPrimaryTable('ca_objects'); /** * @see http://docs.collectiveaccess.org/wiki/Web_Service_API#Creating_new_records * @see https://gist.githubusercontent.com/skeidel/3871797/raw/item_request.json */ $this->assertGreaterThan(0, $this->addTestRecord('ca_objects', array('intrinsic_fields' => array('type_id' => 'image', 'access' => 1, 'status' => 4)))); $vn_image_type_id = ca_lists::getItemID('object_types', 'image'); // search queries $this->setSearchQueries(array('ca_objects.type_id:"image"' => 1, 'ca_objects.type_id:image' => 1, 'ca_objects.type_id:"' . $vn_image_type_id . '"' => 1, 'ca_objects.type_id:' . $vn_image_type_id => 1, 'ca_objects.type_id:"' . ($vn_image_type_id - 1) . '"' => 0, 'ca_objects.status:4' => 1, 'ca_objects.status:"4"' => 1, 'ca_objects.status:44' => 0, 'ca_objects.status:"44"' => 0, 'ca_objects.access:1' => 1, 'ca_objects.access:"1"' => 1, 'ca_objects.access:0' => 0, 'ca_objects.access:"0"' => 0, 'ca_objects.is_deaccessioned:"0"' => 1, 'ca_objects.is_deaccessioned:0' => 1)); }
/** * * * @param string $ps_refinery_name * @param string $ps_table * @param array $pa_parents * @param array $pa_source_data * @param array $pa_item * @param int $pn_c * @param KLogger $o_log * * @return int */ function caProcessRefineryParents($ps_refinery_name, $ps_table, $pa_parents, $pa_source_data, $pa_item, $pn_c, $pa_options = null) { global $g_ui_locale_id; if (!is_array($pa_options)) { $pa_options = array(); } $o_log = caGetOption('log', $pa_options, null); $o_reader = caGetOption('reader', $pa_options, null); $o_trans = caGetOption('transaction', $pa_options, null); $vn_list_id = caGetOption('list_id', $pa_options, null); $vb_hierarchy_mode = caGetOption('hierarchyMode', $pa_options, false); if (!is_array($pa_parents)) { $pa_parents = array($pa_parents); } $vn_id = null; $pa_parents = array_reverse($pa_parents); foreach ($pa_parents as $vn_i => $va_parent) { if (!is_array($va_parent)) { $o_log->logWarn(_t('[%2] Parents options invalid. Did you forget to pass a list? Parents list passed was: %1', print_r($pa_parents, true), $ps_refinery_name)); break; } $vs_name = BaseRefinery::parsePlaceholder($va_parent['name'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); $vs_idno = BaseRefinery::parsePlaceholder($va_parent['idno'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); $vs_type = BaseRefinery::parsePlaceholder($va_parent['type'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); if (!$vs_name && !$vs_idno) { continue; } if (!$vs_name) { continue; } //$vs_name = $vs_idno; } $va_attributes = isset($va_parent['attributes']) && is_array($va_parent['attributes']) ? $va_parent['attributes'] : array(); foreach ($va_attributes as $vs_element_code => $va_attrs) { if (is_array($va_attrs)) { foreach ($va_attrs as $vs_k => $vs_v) { // BaseRefinery::parsePlaceholder may return an array if the input format supports repeated values (as XML does) // DataMigrationUtils::getCollectionID(), which ca_data_importers::importDataFromSource() uses to create related collections // only supports non-repeating attribute values, so we join any values here and call it a day. $va_attributes[$vs_element_code][$vs_k] = BaseRefinery::parsePlaceholder($vs_v, $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); } } else { $va_attributes[$vs_element_code] = array($vs_element_code => BaseRefinery::parsePlaceholder($va_attrs, $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' '))); } } $va_attributes['idno'] = $vs_idno; $va_attributes['parent_id'] = $vn_id; if (isset($va_parent['rules']) && is_array($va_parent['rules'])) { foreach ($va_parent['rules'] as $va_rule) { $vm_ret = ExpressionParser::evaluate($va_rule['trigger'], $pa_source_data); if (!ExpressionParser::hadError() && (bool) $vm_ret) { foreach ($va_rule['actions'] as $va_action) { if (!is_array($va_action) && strtolower($va_action) == 'skip') { $va_action = array('action' => 'skip'); } switch ($vs_action_code = strtolower($va_action['action'])) { case 'set': switch ($va_action['target']) { case 'name': $vs_name = BaseRefinery::parsePlaceholder($va_action['value'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); break; case 'type': $vs_type = BaseRefinery::parsePlaceholder($va_action['value'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); break; default: $va_attributes[$va_action['target']] = BaseRefinery::parsePlaceholder($va_action['value'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')); break; } break; case 'skip': default: if ($o_log) { if ($vs_action_code != 'skip') { $o_log->logInfo(_t('[%3] Parent was skipped using rule "%1" with default action because an invalid action ("%2") was specified', $va_rule['trigger'], $vs_action_code, $ps_refinery_name)); } else { $o_log->logDebug(_t('[%3] Parent was skipped using rule "%1" with action "%2"', $va_rule['trigger'], $vs_action_code, $ps_refinery_name)); } } continue 4; break; } } } elseif (ExpressionParser::hadError() && $o_log) { $o_log->logError(_t('[%3] Error processing rule "%1" as an error occurred. Error number was "%2"', $va_rule['trigger'], ExpressionParser::$s_last_error, $ps_refinery_name)); } } } $va_match_on = caGetOption("{$ps_refinery_name}_dontMatchOnLabel", $pa_item['settings'], false) ? array('idno') : array('idno', 'label'); $pa_options = array_merge(array('matchOn' => $va_match_on), $pa_options); switch ($ps_table) { case 'ca_objects': $vn_id = DataMigrationUtils::getObjectID($vs_name, $vn_id, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_entities': $vn_id = DataMigrationUtils::getEntityID($va_entity_label = DataMigrationUtils::splitEntityName($vs_name, $pa_options), $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels'] = $va_entity_label; $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_places': if (!$vn_id) { // get place hierarchy root require_once __CA_MODELS_DIR__ . "/ca_places.php"; $t_place = new ca_places(); if ($o_trans) { $t_place->setTransaction($o_trans); } $vn_id = $pa_options['defaultParentID']; if (!$vn_id) { $vn_id = $t_place->getHierarchyRootID($pa_options['hierarchyID']); } $va_attributes['parent_id'] = $vn_id; } $vn_id = DataMigrationUtils::getPlaceID($vs_name, $vn_id, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_occurrences': $vn_id = DataMigrationUtils::getOccurrenceID($vs_name, $vn_id, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_collections': $vn_id = DataMigrationUtils::getCollectionID($vs_name, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_loans': $vn_id = DataMigrationUtils::getLoanID($vs_name, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_movements': $vn_id = DataMigrationUtils::getMovementID($vs_name, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; case 'ca_list_items': if (!$vn_list_id) { if ($o_log) { $o_log->logDebug(_t('[importHelpers:caProcessRefineryParents] List was not specified')); } return null; } if (!$vn_id) { // get place hierarchy root require_once __CA_MODELS_DIR__ . "/ca_lists.php"; $t_list = new ca_lists(); if ($o_trans) { $t_list->setTransaction($o_trans); } $vn_id = $t_list->getRootItemIDForList($vn_list_id); $va_attributes['parent_id'] = $vn_id; } $vn_id = DataMigrationUtils::getListItemID($vn_list_id, $vs_name, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name_singular'] = $va_attributes['preferred_labels']['name_plural'] = $vs_name; break; case 'ca_storage_locations': if (!$vn_id) { // get storage location hierarchy root require_once __CA_MODELS_DIR__ . "/ca_storage_locations.php"; $t_loc = new ca_storage_locations(); if ($o_trans) { $t_loc->setTransaction($o_trans); } $vn_id = $t_loc->getHierarchyRootID(); $va_attributes['parent_id'] = $vn_id; } $vn_id = DataMigrationUtils::getStorageLocationID($vs_name, $vn_id, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options); $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name; break; default: if ($o_log) { $o_log->logDebug(_t('[importHelpers:caProcessRefineryParents] Invalid table %1', $ps_table)); } return null; break; } $va_attributes['locale_id'] = $g_ui_locale_id; if ($o_log) { $o_log->logDebug(_t('[%6] Got parent %1 (%2) with id %3 and type %4 for %5', $vs_name, $vs_idno, $vn_id, $vs_type, $vs_name, $ps_refinery_name)); } } if ($vb_hierarchy_mode) { return $va_attributes; } return $vn_id; }
/** * Returns list of items in the specified table related to the currently loaded row or rows specified in options. This is a simplified version of * BundlableLabelableBaseModelWithAttributes::getRelatedItems() for models derived directly from BaseModel. * * @param $pm_rel_table_name_or_num - the table name or table number of the item type you want to get a list of (eg. if you are calling this on an ca_item_comments instance passing 'ca_users' here will get you a list of users related to the comment) * @param $pa_options - array of options. Supported options are: * * [Options controlling rows for which data is returned] * row_ids = Array of primary key values to use when fetching related items. If omitted or set to a null value the 'row_id' option will be used. [Default is null] * row_id = Primary key value to use when fetching related items. If omitted or set to a false value (null, false, 0) then the primary key value of the currently loaded row is used. [Default is currently loaded row] * start = Zero-based index to begin return set at. [Default is 0] * limit = Maximum number of related items to return. [Default is 1000] * showDeleted = Return related items that have been deleted. [Default is false] * primaryIDs = array of primary keys in related table to exclude from returned list of items. Array is keyed on table name for compatibility with the parameter as used in the caProcessTemplateForIDs() helper [Default is null - nothing is excluded]. * where = Restrict returned items to specified field values. The fields must be intrinsic and in the related table. This option can be useful when you want to efficiently fetch specific rows from a related table. Note that multiple fields/values are logically AND'ed together – all must match for a row to be returned - and that only equivalence is supported. [Default is null] * criteria = Restrict returned items using SQL criteria appended directly onto the query. Criteria is used as-is and must be compatible with the generated SQL query. [Default is null] * * [Options controlling scope of data in return value] * restrictToLists = Restrict returned items to those that are in one or more specified lists. This option is only relevant when fetching related ca_list_items. An array of list list_codes or list_ids may be specified. [Default is null] * fields = array of fields (in table.fieldname format) to include in returned data. [Default is null] * idsOnly = Return one-dimensional array of related primary key values only. [Default is false] * * [Options controlling format of data in return value] * sort = Array list of bundles to sort returned values on. The sortable bundle specifiers are fields with or without tablename. Only those fields returned for the related tables (intrinsics) are sortable. [Default is null] * sortDirection = Direction of sort. Use "asc" (ascending) or "desc" (descending). [Default is asc] * * [Front-end access control] * checkAccess = Array of access values to filter returned values on. Available for any related table with an "access" field (ca_objects, ca_entities, etc.). If omitted no filtering is performed. [Default is null] * user_id = Perform item level access control relative to specified user_id rather than currently logged in user. [Default is user_id for currently logged in user] * * @return array List of related items */ public function getRelatedItems($pm_rel_table_name_or_num, $pa_options = null) { global $AUTH_CURRENT_USER_ID; $vn_user_id = isset($pa_options['user_id']) && $pa_options['user_id'] ? $pa_options['user_id'] : (int) $AUTH_CURRENT_USER_ID; $vb_show_if_no_acl = (bool) ($this->getAppConfig()->get('default_item_access_level') > __CA_ACL_NO_ACCESS__); $va_primary_ids = isset($pa_options['primaryIDs']) && is_array($pa_options['primaryIDs']) ? $pa_options['primaryIDs'] : null; $va_get_where = isset($pa_options['where']) && is_array($pa_options['where']) && sizeof($pa_options['where']) ? $pa_options['where'] : null; $va_row_ids = isset($pa_options['row_ids']) && is_array($pa_options['row_ids']) ? $pa_options['row_ids'] : null; $vn_row_id = isset($pa_options['row_id']) && $pa_options['row_id'] ? $pa_options['row_id'] : $this->getPrimaryKey(); $o_db = $this->getDb(); $o_tep = new TimeExpressionParser(); $vb_uses_effective_dates = false; if (isset($pa_options['sort']) && !is_array($pa_options['sort'])) { $pa_options['sort'] = array($pa_options['sort']); } $va_sort_fields = isset($pa_options['sort']) && is_array($pa_options['sort']) ? $pa_options['sort'] : null; $vs_sort_direction = isset($pa_options['sortDirection']) && $pa_options['sortDirection'] ? $pa_options['sortDirection'] : null; if (!$va_row_ids && $vn_row_id > 0) { $va_row_ids = array($vn_row_id); } if (!$va_row_ids || !is_array($va_row_ids) || !sizeof($va_row_ids)) { return array(); } $vn_limit = isset($pa_options['limit']) && (int) $pa_options['limit'] > 0 ? (int) $pa_options['limit'] : 1000; $vn_start = isset($pa_options['start']) && (int) $pa_options['start'] > 0 ? (int) $pa_options['start'] : 0; if (is_numeric($pm_rel_table_name_or_num)) { if (!($vs_related_table_name = $this->getAppDatamodel()->getTableName($pm_rel_table_name_or_num))) { return null; } } else { if (sizeof($va_tmp = explode(".", $pm_rel_table_name_or_num)) > 1) { $pm_rel_table_name_or_num = array_shift($va_tmp); } if (!($o_instance = $this->getAppDatamodel()->getInstanceByTableName($pm_rel_table_name_or_num, true))) { return null; } $vs_related_table_name = $pm_rel_table_name_or_num; } if (!is_array($pa_options)) { $pa_options = array(); } switch (sizeof($va_path = array_keys($this->getAppDatamodel()->getPath($this->tableName(), $vs_related_table_name)))) { case 3: $t_item_rel = $this->getAppDatamodel()->getTableInstance($va_path[1]); $t_rel_item = $this->getAppDatamodel()->getTableInstance($va_path[2]); $vs_key = $t_item_rel->primaryKey(); //'relation_id'; break; case 2: $t_item_rel = null; $t_rel_item = $this->getAppDatamodel()->getTableInstance($va_path[1]); $vs_key = $t_rel_item->primaryKey(); break; default: // bad related table return null; break; } $va_wheres = array(); $va_selects = array(); $va_joins_post_add = array(); $vs_related_table = $t_rel_item->tableName(); if ($t_item_rel) { //define table names $vs_linking_table = $t_item_rel->tableName(); $va_selects[] = "{$vs_related_table}." . $t_rel_item->primaryKey(); if ($t_rel_item->hasField('is_enabled')) { $va_selects[] = "{$vs_related_table}.is_enabled"; } } if (is_array($va_get_where)) { foreach ($va_get_where as $vs_fld => $vm_val) { if ($t_rel_item->hasField($vs_fld)) { $va_wheres[] = "({$vs_related_table_name}.{$vs_fld} = " . (!is_numeric($vm_val) ? "'" . $this->getDb()->escape($vm_val) . "'" : $vm_val) . ")"; } } } if ($vs_idno_fld = $t_rel_item->getProperty('ID_NUMBERING_ID_FIELD')) { $va_selects[] = "{$vs_related_table}.{$vs_idno_fld}"; } if ($vs_idno_sort_fld = $t_rel_item->getProperty('ID_NUMBERING_SORT_FIELD')) { $va_selects[] = "{$vs_related_table}.{$vs_idno_sort_fld}"; } $va_selects[] = $va_path[1] . '.' . $vs_key; if (isset($pa_options['fields']) && is_array($pa_options['fields'])) { $va_selects = array_merge($va_selects, $pa_options['fields']); } if (isset($pa_options['checkAccess']) && is_array($pa_options['checkAccess']) && sizeof($pa_options['checkAccess']) && $t_rel_item->hasField('access')) { $va_wheres[] = "({$vs_related_table}.access IN (" . join(',', $pa_options['checkAccess']) . "))"; } if ((!isset($pa_options['showDeleted']) || !$pa_options['showDeleted']) && $t_rel_item->hasField('deleted')) { $va_wheres[] = "({$vs_related_table}.deleted = 0)"; } if (($va_criteria = isset($pa_options['criteria']) ? $pa_options['criteria'] : null) && is_array($va_criteria) && sizeof($va_criteria)) { $va_wheres[] = "(" . join(" AND ", $va_criteria) . ")"; } $va_wheres[] = "(" . $this->tableName() . '.' . $this->primaryKey() . " IN (" . join(",", $va_row_ids) . "))"; $va_selects[] = $t_rel_item->tableName() . ".*"; $vs_cur_table = array_shift($va_path); $va_joins = array(); // Enforce restrict_to_lists for related list items if ($vs_related_table_name == 'ca_list_items' && is_array($pa_options['restrictToLists'])) { $va_list_ids = array(); foreach ($pa_options['restrictToLists'] as $vm_list) { if ($vn_list_id = ca_lists::getListID($vm_list)) { $va_list_ids[] = $vn_list_id; } } if (sizeof($va_list_ids)) { $va_wheres[] = "(ca_list_items.list_id IN (" . join(",", $va_list_ids) . "))"; } } foreach ($va_path as $vs_join_table) { $va_rel_info = $this->getAppDatamodel()->getRelationships($vs_cur_table, $vs_join_table); $va_joins[] = 'INNER JOIN ' . $vs_join_table . ' ON ' . $vs_cur_table . '.' . $va_rel_info[$vs_cur_table][$vs_join_table][0][0] . ' = ' . $vs_join_table . '.' . $va_rel_info[$vs_cur_table][$vs_join_table][0][1] . "\n"; $vs_cur_table = $vs_join_table; } // If we're getting ca_set_items, we have to rename the intrinsic row_id field because the pk is named row_id below. Hence, this hack. if ($vs_related_table_name == 'ca_set_items') { $va_selects[] = 'ca_set_items.row_id AS record_id'; } $va_selects[] = $this->tableName() . '.' . $this->primaryKey() . ' AS row_id'; $vs_order_by = ''; if ($t_item_rel && $t_item_rel->hasField('rank')) { $vs_order_by = ' ORDER BY ' . $t_item_rel->tableName() . '.rank'; } else { if ($t_rel_item && ($vs_sort = $t_rel_item->getProperty('ID_NUMBERING_SORT_FIELD'))) { $vs_order_by = " ORDER BY {$vs_related_table}.{$vs_sort}"; } } $vs_sql = "\n\t\t\tSELECT DISTINCT " . join(', ', $va_selects) . "\n\t\t\tFROM " . $this->tableName() . "\n\t\t\t" . join("\n", array_merge($va_joins, $va_joins_post_add)) . "\n\t\t\tWHERE\n\t\t\t\t" . join(' AND ', $va_wheres) . "\n\t\t\t{$vs_order_by}\n\t\t"; $qr_res = $o_db->query($vs_sql); $va_rels = array(); $vn_c = 0; if ($vn_start > 0) { $qr_res->seek($vn_start); } while ($qr_res->nextRow()) { if ($vn_c >= $vn_limit) { break; } if (is_array($va_primary_ids) && is_array($va_primary_ids[$vs_related_table])) { if (in_array($qr_res->get($vs_key), $va_primary_ids[$vs_related_table])) { continue; } } if (isset($pa_options['idsOnly']) && $pa_options['idsOnly']) { $va_rels[] = $qr_res->get($t_rel_item->primaryKey()); continue; } $va_row = $qr_res->getRow(); $vs_v = sizeof($va_path) <= 2 ? $va_row['row_id'] . '/' . $va_row[$vs_key] : $va_row[$vs_key]; $vs_display_label = $va_row[$vs_label_display_field]; if (!isset($va_rels[$vs_v]) || !$va_rels[$vs_v]) { $va_rels[$vs_v] = $va_row; } $va_rels[$vs_v]['_key'] = $vs_key; $va_rels[$vs_v]['direction'] = $vs_direction; $vn_c++; } // // Sort on fields if specified // if (is_array($va_sort_fields) && sizeof($va_rels)) { $va_ids = array(); $vs_rel_pk = $t_rel_item->primaryKey(); foreach ($va_rels as $vn_i => $va_rel) { $va_ids[] = $va_rel[$vs_rel_pk]; } $vs_rel_pk = $t_rel_item->primaryKey(); foreach ($va_sort_fields as $vn_x => $vs_sort_field) { if ($vs_sort_field == 'relation_id') { // sort by relationship primary key if ($t_item_rel) { $va_sort_fields[$vn_x] = $vs_sort_field = $t_item_rel->tableName() . '.' . $t_item_rel->primaryKey(); } continue; } $va_tmp = explode('.', $vs_sort_field); if ($va_tmp[0] == $vs_related_table_name) { if (!($qr_rel = caMakeSearchResult($va_tmp[0], $va_ids))) { continue; } $vs_table = array_shift($va_tmp); $vs_key = join(".", $va_tmp); while ($qr_rel->nextHit()) { $vn_pk_val = $qr_rel->get($vs_table . "." . $vs_rel_pk); foreach ($va_rels as $vn_rel_id => $va_rel) { if ($va_rel[$vs_rel_pk] == $vn_pk_val) { $va_rels[$vn_rel_id][$vs_key] = $qr_rel->get($vs_sort_field, array("delimiter" => ";", 'sortable' => 1)); break; } } } } } // Perform sort $va_rels = caSortArrayByKeyInValue($va_rels, $va_sort_fields, $vs_sort_direction); } return $va_rels; }
/** * 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; }
/** * 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); }
/** * Return array of access statuses with access levels for current user. Levels are: * 0 = no access * 1 = read * null = use whatever the default is * * The array is indexed on access status value (eg. 0, 1, 2...) not name; the values are level values. * * If the $pn_access_level parameter is set to 0 or 1, then a simple list of access status values for which the user * has that access level is returned * * @return array */ public function getAccessStatuses($pn_access_level = null) { if (!$this->getPrimaryKey()) { return null; } // get user roles $va_roles = $this->getUserRoles(); foreach ($this->getGroupRoles() as $vn_role_id => $va_role_info) { $va_roles[$vn_role_id] = $va_role_info; } $va_access_by_item_id = array(); if (is_array($va_roles)) { foreach ($va_roles as $vn_role_id => $va_role_info) { if (is_array($va_access_status_settings = $va_role_info['vars']['access_status_settings'])) { foreach ($va_access_status_settings as $vn_item_id => $vn_access) { if (!isset($va_access_by_item_id[$vn_item_id])) { $va_access_by_item_id[$vn_item_id] = $vn_access; continue; } if (is_null($vn_access)) { continue; } if ($vn_access >= (int) $va_access_by_item_id[$vn_item_id]) { $va_access_by_item_id[$vn_item_id] = $vn_access; } } } } } if (!sizeof($va_access_by_item_id)) { return array(); } $va_item_values = ca_lists::itemIDsToItemValues(array_keys($va_access_by_item_id), array('transaction' => $this->getTransaction())); if (!is_array($va_item_values) || !sizeof($va_item_values)) { return array(); } $va_ret = array(); if (is_array($va_item_values)) { foreach ($va_item_values as $vn_item_id => $vn_val) { $va_ret[$vn_val] = $va_access_by_item_id[$vn_item_id]; } } if (!is_null($pn_access_level) && in_array($pn_access_level, array(0, 1))) { $va_filtered_ret = array(); foreach ($va_ret as $vn_val => $vn_access) { if ($vn_access == $pn_access_level) { $va_filtered_ret[] = $vn_val; } } return $va_filtered_ret; } return $va_ret; }
/** * */ 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; }
public function Save() { AssetLoadManager::register('tableList'); $o_dm = Datamodel::load(); $t_list = new ca_lists(); $t_role = $this->getRoleObject(); $t_role->setMode(ACCESS_WRITE); foreach ($t_role->getFormFields() as $vs_f => $va_field_info) { $t_role->set($vs_f, $_REQUEST[$vs_f]); if ($t_role->numErrors()) { $this->request->addActionErrors($t_role->errors(), 'field_' . $vs_f); } } // get vars $va_vars = $t_role->get('vars'); if (!is_array($va_vars)) { $va_vars = array(); } // save bundle access settings $t_screen = new ca_editor_ui_screens(); $va_bundle_access_settings = array(); foreach (ca_users::$s_bundlable_tables as $vs_table) { $va_available_bundles = $t_screen->getAvailableBundles($vs_table); foreach ($va_available_bundles as $vs_bundle_name => $va_bundle_info) { $vs_bundle_name_proc = $vs_table . '_' . str_replace(".", "_", $vs_bundle_name); $vn_access = $this->request->getParameter($vs_bundle_name_proc, pInteger); $va_bundle_access_settings[$vs_table . '.' . $vs_bundle_name] = $vn_access; } } $va_vars['bundle_access_settings'] = $va_bundle_access_settings; if ($t_role->getAppConfig()->get('perform_type_access_checking')) { // save type access settings $va_type_access_settings = array(); foreach (ca_users::$s_bundlable_tables as $vs_table) { if (!caTableIsActive($vs_table) && $vs_table != 'ca_object_representations') { continue; } $t_instance = $o_dm->getInstanceByTableName($vs_table, true); if (!($vs_list_code = $t_instance->getTypeListCode())) { continue; } $va_type_ids = $t_list->getItemsForList($vs_list_code, array('idsOnly' => true)); if (is_array($va_type_ids)) { foreach ($va_type_ids as $vn_i => $vn_item_id) { $vn_access = $this->request->getParameter($vs_table . '_type_' . $vn_item_id, pInteger); $va_type_access_settings[$vs_table . '.' . $vn_item_id] = $vn_access; } } } $va_vars['type_access_settings'] = $va_type_access_settings; } if ($t_role->getAppConfig()->get('perform_source_access_checking')) { // save source access settings $va_source_access_settings = array(); foreach (ca_users::$s_bundlable_tables as $vs_table) { if (!caTableIsActive($vs_table) && $vs_table != 'ca_object_representations') { continue; } $t_instance = $o_dm->getInstanceByTableName($vs_table, true); if (!($vs_list_code = $t_instance->getSourceListCode())) { continue; } $va_source_ids = $t_list->getItemsForList($vs_list_code, array('idsOnly' => true)); if (is_array($va_source_ids)) { foreach ($va_source_ids as $vn_i => $vn_item_id) { $vn_access = $this->request->getParameter($vs_table . '_source_' . $vn_item_id, pInteger); $va_source_access_settings[$vs_table . '.' . $vn_item_id] = $vn_access; } } $va_source_access_settings[$vs_table . '_default_id'] = $this->request->getParameter($vs_table . '_default_source', pInteger); } $va_vars['source_access_settings'] = $va_source_access_settings; } $va_access_status_settings = array(); if (is_array($va_access_status_ids = $va_source_ids = $t_list->getItemsForList('access_statuses', array('idsOnly' => true)))) { foreach ($va_access_status_ids as $vn_i => $vn_item_id) { $vs_access = $this->request->getParameter('access_status_' . $vn_item_id, pString); switch ($vs_access) { case 0: case 1: $va_access_status_settings[$vn_item_id] = $vs_access; break; default: $va_access_status_settings[$vn_item_id] = null; break; } } } $va_vars['access_status_settings'] = $va_access_status_settings; $t_role->set('vars', $va_vars); // save actions $va_role_action_list = $t_role->getRoleActionList(); $va_new_role_action_settings = array(); foreach ($va_role_action_list as $vs_group => $va_group_info) { if (caTableIsActive($vs_group) === false && $vs_group != 'ca_object_representations') { continue; } // will return null if group name is not a table name; true if it's an enabled table and false if it's a disabled table foreach ($va_group_info['actions'] as $vs_action => $va_action_info) { if ($this->request->getParameter($vs_action, pInteger) > 0) { $va_new_role_action_settings[] = $vs_action; } } } $t_role->setRoleActions($va_new_role_action_settings); AppNavigation::clearMenuBarCache($this->request); // clear menu bar cache since role changes may affect content if ($this->request->numActionErrors() == 0) { if (!$t_role->getPrimaryKey()) { $t_role->insert(); $vs_message = _t("Added role"); } else { $t_role->update(); $vs_message = _t("Saved changes to role"); } if ($t_role->numErrors()) { foreach ($t_role->errors() as $o_e) { $this->request->addActionError($o_e, 'general'); $this->notification->addNotification($o_e->getErrorDescription(), __NOTIFICATION_TYPE_ERROR__); } } else { $this->notification->addNotification($vs_message, __NOTIFICATION_TYPE_INFO__); } } else { $this->notification->addNotification(_t("Your entry has errors. See below for details."), __NOTIFICATION_TYPE_ERROR__); } if ($this->request->numActionErrors()) { $this->render('role_edit_html.php'); } else { $this->view->setVar('role_list', $t_role->getRoleList()); $this->render('role_list_html.php'); } }
/** * Returns the place_id in ca_places table for root of specified hierarchy. Place hierarchies are enumerated in the "place_hierarchies" list, * so hierarchy specifications are really just plain old list items (ca_list_items records). You can specify a hierarchy using an hierarchy id * (really just a ca_list_items item_id value for the item representing the hierarchy), or by passing the idno of the hierarchy (eg. ca_list_items.idno). * * @param mixed $pm_hierarchy_code_or_id The numeric id or alphanumeric code for the hierarchy. Since hierarchies are represented with list items these are the item_id or idno values of the hierarchy's list item. * @return int Place ID of the place hierarchy root */ public function getRootIDForHierarchy($pm_hierarchy_code_or_id) { $o_db = $this->getDb(); if (!is_numeric($pm_hierarchy_code_or_id)) { $t_list = new ca_lists(); $pn_hierarchy_id = (int) $t_list->getItemIDFromList('place_hierarchies', $pm_hierarchy_code_or_id); } else { $pn_hierarchy_id = (int) $pm_hierarchy_code_or_id; } $qr_res = $o_db->query("\n\t\t\tSELECT place_id\n\t\t\tFROM ca_places \n\t\t\tWHERE \n\t\t\t\t(parent_id IS NULL) AND (hierarchy_id = ?)\n\t\t", (int) $pn_hierarchy_id); if ($qr_res->nextRow()) { return $qr_res->get('place_id'); } return null; }
/** * 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'); }
public function lookup() { $vs_search = $this->request->getParameter('q', pString); $t_list = new ca_lists(); $va_data = array(); $va_access_values = caGetUserAccessValues($this->request); # # Do "quicksearches" on so-configured tables # if ($this->request->config->get('quicksearch_return_ca_objects')) { $va_results = caExtractValuesByUserLocale(SearchEngine::quickSearch($vs_search, 'ca_objects', 57, array('limit' => 3, 'checkAccess' => $va_access_values))); // break found objects out by type foreach ($va_results as $vn_id => $va_match_info) { $vs_type = unicode_ucfirst($t_list->getItemFromListForDisplayByItemID('object_types', $va_match_info['type_id'], true)); $va_data['ca_objects'][$vs_type][$vn_id] = $va_match_info; } } if ($this->request->config->get('quicksearch_return_ca_entities')) { $va_data['ca_entities'][_t('Entities')] = caExtractValuesByUserLocale(SearchEngine::quickSearch($vs_search, 'ca_entities', 20, array('limit' => 10, 'checkAccess' => $va_access_values))); } if ($this->request->config->get('quicksearch_return_ca_places')) { $va_data['ca_places'][_t('Places')] = caExtractValuesByUserLocale(SearchEngine::quickSearch($vs_search, 'ca_places', 72, array('limit' => 10, 'checkAccess' => $va_access_values))); } if ($this->request->config->get('quicksearch_return_ca_occurrences')) { $va_results = caExtractValuesByUserLocale(SearchEngine::quickSearch($vs_search, 'ca_occurrences', 67, array('limit' => 10, 'checkAccess' => $va_access_values))); // break found occurrences out by type foreach ($va_results as $vn_id => $va_match_info) { $vs_type = unicode_ucfirst($t_list->getItemFromListForDisplayByItemID('occurrence_types', $va_match_info['type_id'], true)); $va_data['ca_occurrences'][$vs_type][$vn_id] = $va_match_info; } } if ($this->request->config->get('quicksearch_return_ca_collections')) { $va_data['ca_collections'][_t('Collections')] = caExtractValuesByUserLocale(SearchEngine::quickSearch($vs_search, 'ca_collections', 13, array('limit' => 10, 'checkAccess' => $va_access_values))); } $this->view->setVar('matches', $va_data); $this->render('Search/ajax_search_lookup_json.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 * * ---------------------------------------------------------------------- */ $t_object = $this->getVar('t_item'); $vn_object_id = $t_object->get('object_id'); $vs_title = $this->getVar('label'); $t_rep = $this->getVar('t_primary_rep'); $vs_display_version = $this->getVar('primary_rep_display_version'); $va_display_options = $this->getVar('primary_rep_display_options'); $va_access_values = $this->getVar('access_values'); # -- get the various object types $o_lists = new ca_lists(); $vn_fond_id = $o_lists->getItemIDFromList('object_types', 'fonds'); $vn_sub_fond_id = $o_lists->getItemIDFromList('object_types', 'sub_fonds'); $vn_series_id = $o_lists->getItemIDFromList('object_types', 'series'); ?> <div id="detailBody"> <div id="leftCol" > <!--img src="<?php print $this->request->getThemeUrlPath(); ?> /graphics/city/city-archives.jpg" alt="" title="" /--> <div class="maincol"> <h1>City Archives</h1>
public function displaySet() { # --- set info $pn_set_id = $this->request->getParameter('set_id', pInteger); $t_set = new ca_sets($pn_set_id); $va_access_values = caGetUserAccessValues($this->request); # Enforce access control if (sizeof($va_access_values) && !in_array($t_set->get("access"), $va_access_values)) { $this->notification->addNotification(_t("This set is not available for view"), "message"); $this->response->setRedirect(caNavUrl($this->request, "", "", "", "")); return; } $this->view->setVar('t_set', $t_set); $va_items = caExtractValuesByUserLocale($t_set->getItems(array('thumbnailVersions' => array('widepreview', 'medium', 'setimage'), "checkAccess" => $va_access_values))); $this->view->setVar('items', $va_items); $va_row_ids = array(); foreach ($va_items as $vn_item_id => $va_item_info) { $va_row_ids[] = $va_item_info['row_id']; } # --- all featured sets - for display in right hand column // get sets for public display $t_list = new ca_lists(); $vn_public_set_type_id = $t_list->getItemIDFromList('set_types', $t_list->getAppConfig()->get('simpleGallery_set_type')); $t_set = new ca_sets($pn_set_id); $va_sets = caExtractValuesByUserLocale($t_set->getSets(array('table' => 'ca_objects', 'checkAccess' => $va_access_values, 'setType' => $vn_public_set_type_id))); $va_set_first_items = array(); $va_set_first_items = $t_set->getFirstItemsFromSets(array_keys($va_sets), array("version" => "icon", "checkAccess" => $va_access_values)); $this->view->setVar('sets', $va_sets); $this->view->setVar('first_items_from_sets', $va_set_first_items); $this->view->setVar('set_title', $t_set->getLabelForDisplay()); $this->view->setVar('set_description', $t_set->get($this->opo_plugin_config->get('set_description_element_code'), array('convertLinkBreaks' => true))); // Needed to figure out what result context to use on details $this->opo_result_context->setParameter('set_id', $pn_set_id); $this->opo_result_context->setResultList($va_row_ids); $this->opo_result_context->setAsLastFind(); $this->opo_result_context->saveContext(); $this->render($this->ops_theme . '/set_info_html.php'); }
public function Get($pa_additional_query_params = null, $pa_options = null) { if (!$this->ops_search_class) { return null; } $ps_query = $this->request->getParameter('q', pString); $pb_exact = $this->request->getParameter('exact', pInteger); $ps_exclude = $this->request->getParameter('exclude', pString); $va_excludes = explode(";", $ps_exclude); $ps_type = $this->request->getParameter('type', pString); $ps_types = $this->request->getParameter('types', pString); $pb_no_subtypes = (bool) $this->request->getParameter('noSubtypes', pInteger); if (!($pn_limit = $this->request->getParameter('limit', pInteger))) { $pn_limit = 100; } $va_items = array(); if (($vn_str_len = mb_strlen($ps_query)) > 0) { if ($vn_str_len < 3) { $pb_exact = true; } // force short strings to be an exact match (using a very short string as a stem would perform badly and return too many matches in most cases) $o_search = new $this->ops_search_class(); $pa_types = array(); if ($ps_types) { $pa_types = explode(';', $ps_types); } else { if ($ps_type) { $pa_types = array($ps_type); } } // Get type_ids $vs_type_query = ''; $va_ids = array(); if (sizeof($pa_types)) { $va_types = $this->opo_item_instance->getTypeList(); $va_types_proc = array(); foreach ($va_types as $vn_type_id => $va_type) { $va_types_proc[$vn_type_id] = $va_types_proc[$va_type['idno']] = $vn_type_id; } foreach ($pa_types as $ps_type) { if (isset($va_types_proc[$ps_type])) { $va_ids[$va_types_proc[$ps_type]] = true; } } $va_ids = array_keys($va_ids); if (sizeof($va_ids) > 0) { $t_list = new ca_lists(); if (!$pb_no_subtypes) { foreach ($va_ids as $vn_id) { $va_children = $t_list->getItemsForList($this->opo_item_instance->getTypeListCode(), array('item_id' => $vn_id, 'idsOnly' => true)); $va_ids = array_merge($va_ids, $va_children); } $va_ids = array_flip(array_flip($va_ids)); } $o_search->addResultFilter($this->opo_item_instance->tableName() . '.' . $this->opo_item_instance->getTypeFieldName(), 'IN', join(",", $va_ids)); } } else { $va_ids = null; } // add any additional search elements $vs_additional_query_params = ''; if (is_array($pa_additional_query_params) && sizeof($pa_additional_query_params)) { $vs_additional_query_params = ' AND (' . join(' AND ', $pa_additional_query_params) . ')'; } // get sort field $vs_sort = ''; if ($vs_idno_fld = $this->opo_item_instance->getProperty('ID_NUMBERING_SORT_FIELD')) { $vs_sort = $this->opo_item_instance->tableName() . ".{$vs_idno_fld}"; } else { if (method_exists($this->opo_item_instance, "getLabelSortField")) { $vs_sort = $this->opo_item_instance->getLabelTableName() . '.' . $this->opo_item_instance->getLabelSortField(); } } $vs_hier_parent_id_fld = $this->opo_item_instance->getProperty('HIERARCHY_PARENT_ID_FLD'); $vs_hier_fld = $this->opo_item_instance->getProperty('HIERARCHY_ID_FLD'); if ($vs_hier_fld && ($vn_restrict_to_hier_id = $this->request->getParameter('currentHierarchyOnly', pInteger))) { $o_search->addResultFilter($this->opo_item_instance->tableName() . '.' . $vs_hier_fld, '=', (int) $vn_restrict_to_hier_id); } // add filters if (isset($pa_options['filters']) && is_array($pa_options['filters']) && sizeof($pa_options['filters'])) { foreach ($pa_options['filters'] as $va_filter) { $o_search->addResultFilter($va_filter[0], $va_filter[1], $va_filter[2]); } } // do search $qr_res = $o_search->search('(' . $ps_query . (intval($pb_exact) ? '' : '*') . ')' . $vs_type_query . $vs_additional_query_params, array('search_source' => 'Lookup', 'no_cache' => false, 'sort' => $vs_sort)); $qr_res->setOption('prefetch', $pn_limit); $qr_res->setOption('dontPrefetchAttributes', true); $va_items = caProcessRelationshipLookupLabel($qr_res, $this->opo_item_instance, array('exclude' => $va_excludes, 'config' => $this->opo_plugin_config)); } if (!is_array($va_items)) { $va_items = array(); } $this->view->setVar(str_replace(' ', '_', $this->ops_name_singular) . '_list', $va_items); return $this->render('lookup/' . str_replace(' ', '_', 'ajax_' . $this->ops_name_singular . '_list_html.php')); }
/** * 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; }
</div> <?php break; case 'bubbles': default: if ((bool) $va_settings['restrictToTermsRelatedToCollection']) { ?> <div id="<?php print $vs_id_prefix; ?> Item_{n}" class="labelInfo"> <table class="attributeListItem" cellpadding="5" cellspacing="0"> <tr> <td class="attributeListItem"> <?php if ($vs_checklist = ca_lists::getListAsHTMLFormElement(null, $vs_id_prefix . "_id{n}", null, array('render' => 'checklist', 'limitToItemsRelatedToCollections' => $t_instance->get('ca_collections.collection_id', array('returnAsArray' => true)), 'limitToItemsRelatedToCollectionWithRelationshipTypes' => $va_settings['restrictToTermsOnCollectionWithRelationshipType'], 'limitToListIDs' => $va_settings['restrict_to_lists'], 'maxColumns' => 3))) { print $vs_checklist; } else { ?> <h2><?php print _t('No collection terms selected'); ?> </h2> <?php } if (isset($va_settings['restrictToTermsOnCollectionUseRelationshipType']) && is_array($va_settings['restrictToTermsOnCollectionUseRelationshipType'])) { ?> <input type="hidden" name="<?php print $vs_id_prefix; ?> _type_id{n}" id="<?php
/** * 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; }
/** * 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'); }
/** * */ 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; }