public function Get($pa_additional_query_params = null, $pa_options = null) { $ps_query = $this->request->getParameter('term', pString); $ps_bundle = $this->request->getParameter('bundle', pString); $va_tmp = explode('.', $ps_bundle); $o_dm = Datamodel::load(); if (!($t_table = $o_dm->getInstanceByTableName($va_tmp[0], true))) { // bad table name print _t("Invalid table name"); return null; } $t_element = new ca_metadata_elements(); if (!$t_element->load(array('element_code' => $va_tmp[1]))) { print _t("Invalid element code"); return null; } if ((int) $t_element->getSetting('suggestExistingValues') !== 1) { print _t("Value suggestion is not supported for this metadata element"); return null; } if ($this->request->user->getBundleAccessLevel($va_tmp[0], $va_tmp[1]) == __CA_BUNDLE_ACCESS_NONE__) { print _t("You do not have access to this bundle"); return null; } $va_type_restrictions = $t_element->getTypeRestrictions($t_table->tableNum()); if (!$va_type_restrictions || !is_array($va_type_restrictions) || !sizeof($va_type_restrictions)) { print _t("Element code is not bound to the specified table"); return null; } $o_db = new Db(); switch ($t_element->getSetting('suggestExistingValueSort')) { case 'recent': // date/time entered $vs_sort_field = 'value_id DESC'; $vn_max_returned_values = 10; break; default: // alphabetically $vs_sort_field = 'value_longtext1 ASC'; $vn_max_returned_values = 50; break; } $qr_res = $o_db->query("\n\t\t\t\tSELECT DISTINCT value_longtext1\n\t\t\t\tFROM ca_attribute_values\n\t\t\t\tWHERE\n\t\t\t\t\telement_id = ?\n\t\t\t\t\tAND\n\t\t\t\t\t(value_longtext1 LIKE ?)\n\t\t\t\tORDER BY\n\t\t\t\t\t{$vs_sort_field}\n\t\t\t\tLIMIT {$vn_max_returned_values}\n\t\t\t", (int) $t_element->getPrimaryKey(), (string) $ps_query . '%'); $this->view->setVar('attribute_value_list', $qr_res->getAllFieldValues('value_longtext1')); return $this->render('ajax_attribute_value_list_html.php'); }
public function Get() { $ps_query = $this->request->getParameter('q', pString); $ps_type = $this->request->getParameter('type', pString); $va_vocs = array(); $vs_voc_query = ''; if ($vn_element_id = $this->request->getParameter('element_id', pInteger)) { $t_element = new ca_metadata_elements($vn_element_id); if ($vs_voc = $t_element->getSetting('vocabulary')) { $vs_voc_query .= '&q=' . urlencode($vs_voc); } } $va_items = array(); if (unicode_strlen($ps_query) >= 3) { try { // // Get up to 50 suggestions as ATOM feed // $vs_data = @file_get_contents($x = "http://id.loc.gov/search/?q=" . urlencode($ps_query) . $vs_voc_query . '&format=atom&count=50'); if ($vs_data) { $o_xml = @simplexml_load_string($vs_data); if ($o_xml) { $o_entries = $o_xml->{'entry'}; if ($o_entries && sizeof($o_entries)) { foreach ($o_entries as $o_entry) { $o_links = $o_entry->{'link'}; $va_attr = $o_links[0]->attributes(); $vs_url = (string) $va_attr->{'href'}; $va_items[$vs_url] = array('displayname' => (string) $o_entry->{'title'}, 'idno' => (string) $o_entry->{'id'}); } } } } } catch (Exception $e) { $va_items['error'] = array('displayname' => _t('ERROR') . ':' . $e->getMessage(), 'idno' => ''); } } $this->view->setVar('lcsh_list', $va_items); return $this->render('ajax_lcsh_list_html.php'); }
public function Get($pa_additional_query_params = null, $pa_options = null) { if (!($ps_query = $this->request->getParameter('q', pString))) { $ps_query = $this->request->getParameter('term', pString); } $ps_type = $this->request->getParameter('type', pString); $va_vocs = array(); $vs_voc_query = ''; if ($vn_element_id = $this->request->getParameter('element_id', pInteger)) { $t_element = new ca_metadata_elements($vn_element_id); if ($vs_voc = $t_element->getSetting('vocabulary')) { $vs_voc_query .= '&q=' . rawurlencode($vs_voc); } } $vo_conf = Configuration::load(); $va_items = array(); if (unicode_strlen($ps_query) >= 3) { try { $vs_data = caQueryExternalWebservice('http://id.loc.gov/search/?q=' . urlencode('"' . $ps_query . '"') . $vs_voc_query . '&format=atom&count=150'); if ($vs_data) { $o_xml = @simplexml_load_string($vs_data); if ($o_xml) { $o_entries = $o_xml->{'entry'}; if ($o_entries && sizeof($o_entries)) { foreach ($o_entries as $o_entry) { $o_links = $o_entry->{'link'}; $va_attr = $o_links[0]->attributes(); $vs_url = (string) $va_attr->{'href'}; $va_items[] = array('label' => (string) $o_entry->{'title'}, 'idno' => (string) $o_entry->{'id'}, 'url' => $vs_url); } } } } } catch (Exception $e) { $va_items['error'] = array('displayname' => _t('ERROR') . ':' . $e->getMessage(), 'idno' => ''); } } $this->view->setVar('lcsh_list', $va_items); return $this->render('ajax_lcsh_list_html.php'); }
/** * Fetch details on an item from a remote data source and output results of the 'display' key in the response. * */ public function GetDetail() { $pn_element_id = $this->request->getParameter('element_id', pInteger); $t_element = new ca_metadata_elements($pn_element_id); $va_data = array(); if (!$t_element->getPrimaryKey()) { // error $va_items['error'] = array('label' => _t('ERROR: Invalid element_id'), 'idno' => ''); } else { $vs_service = $t_element->getSetting('service'); $va_settings = $t_element->getSettings(); $pn_attribute_id = $this->request->getParameter('id', pInteger); $t_attr_val = new ca_attribute_values(); if ($t_attr_val->load(array('attribute_id' => $pn_attribute_id, 'element_id' => $pn_element_id))) { $t_attr = new ca_attributes(); if ($t_attr->load($pn_attribute_id)) { if (!caCanRead($this->request->getUserID(), $t_attr->get('table_num'), $t_attr->get('row_id'), $t_element->get('element_code'))) { $va_items['error'] = array('label' => _t('ERROR: You do not have access to this item'), 'idno' => ''); } else { $vs_url = $t_attr_val->get('value_longtext2'); if (!($o_plugin = InformationServiceManager::getInformationServiceInstance($vs_service))) { $va_items['error'] = array('label' => _t('ERROR: Invalid service'), 'idno' => ''); } else { $vs_cache_key = md5(print_r($va_settings, true) . $vs_url); if (CompositeCache::contains($vs_cache_key, 'InformationServiceExtendedInfo')) { $va_data = CompositeCache::fetch($vs_cache_key, 'InformationServiceExtendedInfo'); } else { $va_data = $o_plugin->getExtendedInformation($va_settings, $vs_url); CompositeCache::save($vs_cache_key, $va_data, 'InformationServiceExtendedInfo'); } } } } } } $this->view->setVar('detail', $va_data); return $this->render('ajax_information_service_detail_html.php'); }