本文整理汇总了PHP中ca_metadata_elements类的典型用法代码示例。如果您正苦于以下问题:PHP ca_metadata_elements类的具体用法?PHP ca_metadata_elements怎么用?PHP ca_metadata_elements使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ca_metadata_elements类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: caGetAdvancedSearchFormElementNames
/**
* Returns array of name for bundles in the specified form. The array is keyed on bundle name (in <table>.<name> format) with values set to arrays of bundle-specific form options (no such options are currently supported however)
*
* @param string $ps_code The code for the form
* @param string $ps_target The type of search the form targets. This should be a table name (ca_objects, ca_entities, etc.). If omitted defaults to ca_objects.
* @return array An array of bundle names with associated bundle-level form option arrays
*/
function caGetAdvancedSearchFormElementNames($ps_code, $ps_target = 'ca_objects', $pa_options = null)
{
$o_config = Configuration::load(Configuration::load()->get('advanced_search_config'));
$va_forms = $o_config->getAssoc($ps_target);
$va_form_elements = array();
if (isset($va_forms[$ps_code]) && is_array($va_forms[$ps_code])) {
$t_element = new ca_metadata_elements();
foreach ($va_forms[$ps_code]['bundles'] as $vs_bundle => $va_info) {
$va_tmp = explode('.', $vs_bundle);
if ($t_element->load(array('element_code' => $va_tmp[1]))) {
if ($t_element->get('datatype') > 0) {
$va_form_elements[$vs_bundle] = $va_info;
continue;
}
if (isset($pa_options['includeSubElements']) && $pa_options['includeSubElements']) {
if (sizeof($va_sub_elements = $t_element->getElementsInSet()) > 1) {
foreach ($va_sub_elements as $vn_element_id => $va_element_info) {
if ($va_tmp[1] == $va_element_info['element_code']) {
continue;
}
if ($va_element_info['datatype'] == 0) {
continue;
}
$va_form_elements[$va_tmp[0] . '.' . $va_element_info['element_code']] = array();
}
}
}
}
$va_form_elements[$vs_bundle] = $va_info;
}
return $va_form_elements;
}
return null;
}
示例2: testGetElementIDsForTable
public function testGetElementIDsForTable()
{
$o_mapping = new ElasticSearch\Mapping();
$va_element_ids = $o_mapping->getElementIDsForTable('ca_objects');
foreach (array_keys(ca_metadata_elements::getElementsAsList(true, 'ca_objects')) as $vn_element_id) {
$this->assertTrue(in_array($vn_element_id, $va_element_ids), "Expected element id {$vn_element_id} to be part of " . print_r($va_element_ids, true));
}
}
示例3: getInstance
/**
* @param string $ps_table
* @param string $ps_content_fieldname
* @return \ElasticSearch\FieldTypes\FieldType
*/
public static function getInstance($ps_table, $ps_content_fieldname)
{
if ($ps_table == 'created' || $ps_table == 'modified') {
return new Timestamp($ps_table);
}
// if this is an indexing field name, rewrite it
if (preg_match("/^(I|A)[0-9]+\$/", $ps_content_fieldname)) {
if ($ps_content_fieldname[0] === 'A') {
// Metadata attribute
$vn_field_num_proc = (int) substr($ps_content_fieldname, 1);
$t_element = new \ca_metadata_elements($vn_field_num_proc);
if (!$t_element->getPrimaryKey()) {
return null;
}
$ps_content_fieldname = $t_element->get('element_code');
} else {
// Plain intrinsic
$vn_field_num_proc = (int) substr($ps_content_fieldname, 1);
$ps_content_fieldname = \Datamodel::load()->getFieldName($ps_table, $vn_field_num_proc);
}
}
if ($vn_datatype = \ca_metadata_elements::getDataTypeForElementCode($ps_content_fieldname)) {
switch ($vn_datatype) {
case 2:
return new DateRange($ps_table, $ps_content_fieldname);
case 4:
return new Geocode($ps_table, $ps_content_fieldname);
case 6:
return new Currency($ps_table, $ps_content_fieldname);
case 8:
return new Length($ps_table, $ps_content_fieldname);
case 9:
return new Weight($ps_table, $ps_content_fieldname);
case 10:
return new Timecode($ps_table, $ps_content_fieldname);
case 11:
return new Integer($ps_table, $ps_content_fieldname);
case 12:
return new Float($ps_table, $ps_content_fieldname);
default:
return new GenericElement($ps_table, $ps_content_fieldname);
}
} else {
return new Intrinsic($ps_table, $ps_content_fieldname);
}
}
示例4: __call
public function __call($ps_function, $pa_args)
{
$ps_function = strtolower($ps_function);
if (!($va_form_info = $this->_checkForm($ps_function))) {
return;
}
$this->view->setVar('t_subject', $t_subject = $this->pt_subject);
$va_tags = $this->view->getTagList($va_form_info['view']);
foreach ($va_tags as $vs_tag) {
if (in_array($vs_tag, array('form', '/form', 'submit', 'reset'))) {
continue;
}
$va_parse = caParseTagOptions($vs_tag);
$vs_tag_proc = $va_parse['tag'];
$va_opts = $va_parse['options'];
if (($vs_default_value = caGetOption('default', $va_opts, null)) || ($vs_default_value = caGetOption($vs_tag_proc, $va_default_form_values, null))) {
$va_default_form_values[$vs_tag_proc] = $vs_default_value;
unset($va_opts['default']);
}
$vs_tag_val = null;
switch (strtolower($vs_tag_proc)) {
case 'submit':
$this->view->setVar($vs_tag, "<a href='#' class='caContributeFormSubmit'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Submit')) . "</a>");
break;
case 'reset':
$this->view->setVar($vs_tag, "<a href='#' class='caContributeFormReset'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Reset')) . "</a>");
$vs_script = "<script type='text/javascript'>\n\tjQuery('.caContributeFormSubmit').bind('click', function() {\n\t\tjQuery('#caContribute').submit();\n\t\treturn false;\n\t});\n\tjQuery('.caContributeFormReset').bind('click', function() {\n\t\tjQuery('#caContribute').find('input[type!=\"hidden\"],textarea').val('');\n\t\tjQuery('#caContribute').find('select.caContributeBoolean').val('AND');\n\t\tjQuery('#caContribute').find('select').prop('selectedIndex', 0);\n\t\treturn false;\n\t});\n\tjQuery(document).ready(function() {\n\t\tvar f, defaultValues = " . json_encode($va_default_form_values) . ", defaultBooleans = " . json_encode($va_default_form_booleans) . ";\n\t\tfor (f in defaultValues) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('input[name=\"' + f_proc+ '\"], textarea[name=\"' + f_proc+ '\"], select[name=\"' + f_proc+ '\"]').each(function(k, v) {\n\t\t\t\tif (defaultValues[f][k]) { jQuery(v).val(defaultValues[f][k]); } \n\t\t\t});\n\t\t}\n\t\tfor (f in defaultBooleans) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('select[name=\"' + f_proc+ '\"].caContributeBoolean').each(function(k, v) {\n\t\t\t\tif (defaultBooleans[f][k]) { jQuery(v).val(defaultBooleans[f][k]); }\n\t\t\t});\n\t\t}\n\t});\n</script>\n";
break;
default:
if (preg_match("!^(.*):label\$!", $vs_tag_proc, $va_matches)) {
$this->view->setVar($vs_tag, $vs_tag_val = $t_subject->getDisplayLabel($va_matches[1]));
} else {
$va_opts['asArrayElement'] = true;
if ($vs_tag_val = $t_subject->htmlFormElementForSimpleForm($this->request, $vs_tag_proc, $va_opts)) {
$this->view->setVar($vs_tag, $vs_tag_val);
}
$va_tmp = explode('.', $vs_tag_proc);
if (($t_element = ca_metadata_elements::getInstance($va_tmp[1])) && $t_element->get('datatype') == 0) {
if (is_array($va_elements = $t_element->getElementsInSet())) {
foreach ($va_elements as $va_element) {
if ($va_element['datatype'] > 0) {
$va_form_elements[] = $va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code'];
}
}
}
break;
}
}
if ($vs_tag_val) {
$va_form_elements[] = $vs_tag_proc;
}
break;
}
}
$this->view->setVar("form", caFormTag($this->request, "Send", 'caContribute', null, 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true)));
$this->view->setVar("/form", $vs_script . caHTMLHiddenInput("_contributeFormName", array("value" => $ps_function)) . caHTMLHiddenInput("_formElements", array("value" => join(';', $va_form_elements))) . caHTMLHiddenInput("_contribute", array("value" => 1)) . "</form>");
$this->render($va_form_info['view']);
}
示例5: __construct
public function __construct(&$po_request, &$po_response, $pa_view_paths = null)
{
parent::__construct($po_request, $po_response, $pa_view_paths);
$va_sortable_elements = ca_metadata_elements::getSortableElements($this->ops_tablename, $this->opn_type_restriction_id);
$this->opa_sorts = array();
foreach ($va_sortable_elements as $vn_element_id => $va_sortable_element) {
$this->opa_sorts[$this->ops_tablename . '.' . $va_sortable_element['element_code']] = $va_sortable_element['display_label'];
}
}
示例6: Get
public function Get($pa_additional_query_params = null, $pa_options = null)
{
$ps_query = $this->request->getParameter('q', 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;
}
$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('lookup/ajax_attribute_value_list_html.php');
}
示例7: Get
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');
}
示例8: Get
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');
}
示例9: getFacetContent
/**
* Return list of items from the specified table that are related to the current browse set. This is the method that actually
* pulls the facet content, regardless of whether the facet is cached yet or not. If you want to use the facet cache, call
* BrowseEngine::getFacet()
*
* @see BrowseEngine::getFacet()
* Options:
* checkAccess = array of access values to filter facets that have an 'access' field by
* checkAvailabilityOnly = if true then content is not actually fetch - only the availablility of content is verified
* user_id = If set item level access control is performed relative to specified user_id, otherwise defaults to logged in user
*/
public function getFacetContent($ps_facet_name, $pa_options = null)
{
global $AUTH_CURRENT_USER_ID;
$vs_browse_table_name = $this->ops_browse_table_name;
$vs_browse_table_num = $this->opn_browse_table_num;
$vn_user_id = isset($pa_options['user_id']) && (int) $pa_options['user_id'] ? (int) $pa_options['user_id'] : (int) $AUTH_CURRENT_USER_ID;
$vb_show_if_no_acl = (bool) ($this->opo_config->get('default_item_access_level') > __CA_ACL_NO_ACCESS__);
$t_user = new ca_users($vn_user_id);
if (is_array($va_groups = $t_user->getUserGroups()) && sizeof($va_groups)) {
$va_group_ids = array_keys($va_groups);
} else {
$va_group_ids = array();
}
if (!is_array($this->opa_browse_settings)) {
return null;
}
if (!isset($this->opa_browse_settings['facets'][$ps_facet_name])) {
return null;
}
if (!is_array($pa_options)) {
$pa_options = array();
}
$vb_check_availability_only = isset($pa_options['checkAvailabilityOnly']) ? (bool) $pa_options['checkAvailabilityOnly'] : false;
$va_all_criteria = $this->getCriteria();
$va_criteria = $this->getCriteria($ps_facet_name);
$va_facet_info = $this->opa_browse_settings['facets'][$ps_facet_name];
$t_subject = $this->getSubjectInstance();
if ($va_facet_info['relative_to']) {
$vs_browse_table_name = $va_facet_info['relative_to'];
$vs_browse_table_num = $this->opo_datamodel->getTableNum($vs_browse_table_name);
}
$vs_browse_type_limit_sql = '';
if (($va_browse_type_ids = $this->getTypeRestrictionList()) && sizeof($va_browse_type_ids)) {
// type restrictions
$vs_browse_type_limit_sql = '(' . $t_subject->tableName() . '.' . $t_subject->getTypeFieldName() . ' IN (' . join(', ', $va_browse_type_ids) . ')' . ($t_subject->getFieldInfo('type_id', 'IS_NULL') ? " OR (" . $this->ops_browse_table_name . '.' . $t_subject->getTypeFieldName() . " IS NULL)" : '') . ')';
if (is_array($va_facet_info['type_restrictions'])) {
// facet type restrictions bind a facet to specific types; we check them here
$va_restrict_to_types = $this->_convertTypeCodesToIDs($va_facet_info['type_restrictions']);
$vb_is_ok_to_browse = false;
foreach ($va_browse_type_ids as $vn_type_id) {
if (in_array($vn_type_id, $va_restrict_to_types)) {
$vb_is_ok_to_browse = true;
break;
}
}
if (!$vb_is_ok_to_browse) {
return array();
}
}
}
// Values to exclude from list attributes and authorities; can be idnos or ids
$va_exclude_values = caGetOption('exclude_values', $va_facet_info, array(), array('castTo' => 'array'));
$va_results = $this->opo_ca_browse_cache->getResults();
$vb_single_value_is_present = false;
$vs_single_value = isset($va_facet_info['single_value']) ? $va_facet_info['single_value'] : null;
$va_wheres = array();
switch ($va_facet_info['type']) {
# -----------------------------------------------------
case 'has':
$vn_state = null;
if (isset($va_all_criteria[$ps_facet_name])) {
break;
}
// only one instance of this facet allowed per browse
if (!($t_item = $this->opo_datamodel->getInstanceByTableName($vs_browse_table_name, true))) {
break;
}
$vs_yes_text = isset($va_facet_info['label_yes']) && $va_facet_info['label_yes'] ? $va_facet_info['label_yes'] : _t('Yes');
$vs_no_text = isset($va_facet_info['label_no']) && $va_facet_info['label_no'] ? $va_facet_info['label_no'] : _t('No');
$va_facet_values = array('yes' => array('id' => 1, 'label' => $vs_yes_text), 'no' => array('id' => 0, 'label' => $vs_no_text));
// Actually check that both yes and no values will result in something
if ($va_facet_info['element_code']) {
$t_element = new ca_metadata_elements();
if (!$t_element->load(array('element_code' => $va_facet_info['element_code']))) {
break;
}
$vs_element_code = $va_facet_info['element_code'];
$va_facet = array();
$va_counts = array();
foreach ($va_facet_values as $vs_state_name => $va_state_info) {
$va_wheres = array();
$va_joins = array();
if (!(bool) $va_state_info['id']) {
// no option
$va_wheres[] = $this->ops_browse_table_name . '.' . $t_item->primaryKey() . " NOT IN (select row_id from ca_attributes where table_num = " . $t_item->tableNum() . " AND element_id = " . $t_element->getPrimaryKey() . ")";
} else {
// yes option
$va_joins[] = "LEFT JOIN ca_attributes AS caa ON " . $this->ops_browse_table_name . '.' . $t_item->primaryKey() . " = caa.row_id AND " . $t_item->tableNum() . " = caa.table_num";
$va_wheres[] = "caa.element_id = " . $t_element->getPrimaryKey();
//.........这里部分代码省略.........
示例10: getFacetHierarchyAncestorList
/**
* Given a item_id (request parameter 'id') returns a list of ancestors for use in the hierarchy browser
* Returned data is JSON format
*/
public function getFacetHierarchyAncestorList()
{
$pn_id = $this->request->getParameter('id', pInteger);
$ps_facet_name = $this->request->getParameter('facet', pString);
if (!is_array($va_facet_info = $this->opo_browse->getInfoForFacet($ps_facet_name))) {
return null;
}
$va_ancestors = array();
switch ($va_facet_info['type']) {
case 'attribute':
// is it a list attribute?
$t_element = new ca_metadata_elements();
if ($t_element->load(array('element_code' => $va_facet_info['element_code']))) {
if ($t_element->get('datatype') == 3) {
// 3=list
if (!$pn_id) {
$t_list = new ca_lists();
$pn_id = $t_list->getRootListItemID($t_element->get('list_id'));
}
$t_item = new ca_list_items($pn_id);
if ($t_item->getPrimaryKey()) {
$va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'idsOnly' => true)));
array_shift($va_ancestors);
}
}
}
break;
case 'label':
// label facet
$va_facet_info['table'] = $this->ops_tablename;
// fall through to default case
// fall through to default case
default:
$t_item = $this->opo_datamodel->getInstanceByTableName($va_facet_info['table']);
$t_item->load($pn_id);
if (method_exists($t_item, "getHierarchyList")) {
$va_access_values = caGetUserAccessValues($this->request);
$va_facet = $this->opo_browse->getFacet($ps_facet_name, array('sort' => 'name', 'checkAccess' => $va_access_values));
$va_hierarchy_list = $t_item->getHierarchyList(true);
$vn_hierarchies_in_use = 0;
foreach ($va_hierarchy_list as $vn_i => $va_item) {
if (isset($va_facet[$va_item[$t_item->primaryKey()]])) {
$vn_hierarchies_in_use++;
if ($vn_hierarchies_in_use > 1) {
break;
}
}
}
}
if ($t_item->getPrimaryKey()) {
$va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'idsOnly' => true)));
if (!is_array($va_ancestors)) {
$va_ancestors = array();
}
}
if ($vn_hierarchies_in_use <= 1) {
array_shift($va_ancestors);
}
break;
}
$this->view->setVar('ancestors', $va_ancestors);
return $this->render('Browse/facet_hierarchy_ancestors_json.php');
}
示例11: processMetadataElement
private function processMetadataElement($po_element, $pn_parent_id)
{
require_once __CA_MODELS_DIR__ . "/ca_metadata_elements.php";
require_once __CA_MODELS_DIR__ . "/ca_lists.php";
if (($vn_datatype = ca_metadata_elements::getAttributeTypeCode(self::getAttribute($po_element, "datatype"))) === false) {
return false;
// should not happen due to XSD restrictions, but just in case
}
$vs_element_code = self::getAttribute($po_element, "code");
$t_lists = new ca_lists();
if ($this->opb_updating) {
$t_md_element = ca_metadata_elements::getInstance($vs_element_code) ? ca_metadata_elements::getInstance($vs_element_code) : new ca_metadata_elements();
} else {
$t_md_element = new ca_metadata_elements();
}
$t_md_element->setMode(ACCESS_WRITE);
$t_md_element->set('element_code', $vs_element_code);
$t_md_element->set('parent_id', $pn_parent_id);
$t_md_element->set('documentation_url', (string) $po_element->documentationUrl);
$t_md_element->set('datatype', $vn_datatype);
$vs_list = self::getAttribute($po_element, "list");
if (isset($vs_list) && $vs_list && $t_lists->load(array('list_code' => $vs_list))) {
$vn_list_id = $t_lists->getPrimaryKey();
} else {
$vn_list_id = null;
}
$t_md_element->set('list_id', $vn_list_id);
$this->_processSettings($t_md_element, $po_element->settings);
if ($t_md_element->getPrimaryKey()) {
$t_md_element->update();
} else {
$t_md_element->insert();
}
if ($t_md_element->numErrors()) {
$this->addError("There was an error while inserting metadata element {$vs_element_code}: " . join(" ", $t_md_element->getErrors()));
return false;
}
$vn_element_id = $t_md_element->getPrimaryKey();
// add element labels
self::addLabelsFromXMLElement($t_md_element, $po_element->labels, $this->opa_locales);
if ($po_element->elements) {
foreach ($po_element->elements->children() as $vo_child) {
$this->processMetadataElement($vo_child, $vn_element_id);
}
}
return $vn_element_id;
}
示例12: caNavUrl
print caNavUrl($this->request, 'administrate/setup', 'Elements', 'Edit', array('parent_id' => $vn_element_id, 'element_id' => $va_sub_element['element_id']));
?>
" class="caDeleteLabelButton"><?php
print caNavIcon($this->request, __CA_NAV_BUTTON_EDIT__);
?>
</a>
<a href="<?php
print caNavUrl($this->request, 'administrate/setup', 'Elements', 'Delete', array('parent_id' => $vn_element_id, 'element_id' => $va_sub_element['element_id']));
?>
" class="caDeleteLabelButton"><?php
print caNavIcon($this->request, __CA_NAV_BUTTON_DEL_BUNDLE__);
?>
</a>
<span class="labelDisplay">
<?php
print $va_sub_element['name'] . ' (' . $va_sub_element['element_code'] . ') [' . ca_metadata_elements::getAttributeNameForTypeCode($va_sub_element['datatype']) . ']';
?>
</span>
</div>
<?php
}
?>
</div>
<div class="button labelInfo caAddLabelButton">
<a href="<?php
print caNavUrl($this->request, 'administrate/setup', 'Elements', 'Edit', array('parent_id' => $vn_element_id, 'element_id' => 0));
?>
">
<?php
print caNavIcon($this->request, __CA_NAV_BUTTON_ADD__);
?>
示例13: htmlFormElement
/**
* Return HTML form element for editing.
*
* @param array $pa_element_info An array of information about the metadata element being edited
* @param array $pa_options array Options include:
* usewysiwygeditor = overrides element level setting for visual text editor [Default=false]
* forSearch = settings and options regarding visual text editor are ignored [Default=false]
* class = the CSS class to apply to all visible form elements [Default=null]
* width = the width of the form element [Default=field width defined in metadata element definition]
* height = the height of the form element [Default=field height defined in metadata element definition]
* t_subject = an instance of the model to which the attribute belongs; required if suggestExistingValues lookups are enabled [Default is null]
* request = the RequestHTTP object for the current request; required if suggestExistingValues lookups are enabled [Default is null]
* suggestExistingValues = suggest values based on existing input for this element as user types [Default is false]
*
* @return string
*/
public function htmlFormElement($pa_element_info, $pa_options = null)
{
$va_settings = $this->getSettingValuesFromElementArray($pa_element_info, array('fieldWidth', 'fieldHeight', 'minChars', 'maxChars', 'suggestExistingValues', 'usewysiwygeditor', 'isDependentValue', 'dependentValueTemplate'));
if (isset($pa_options['usewysiwygeditor'])) {
$va_settings['usewysiwygeditor'] = $pa_options['usewysiwygeditor'];
}
if (isset($pa_options['forSearch']) && $pa_options['forSearch']) {
unset($va_settings['usewysiwygeditor']);
}
$vs_width = trim(isset($pa_options['width']) && $pa_options['width'] > 0 ? $pa_options['width'] : $va_settings['fieldWidth']);
$vs_height = trim(isset($pa_options['height']) && $pa_options['height'] > 0 ? $pa_options['height'] : $va_settings['fieldHeight']);
$vs_class = trim(isset($pa_options['class']) && $pa_options['class'] ? $pa_options['class'] : '');
$vs_element = '';
if (!preg_match("!^[\\d\\.]+px\$!i", $vs_width)) {
$vs_width = (int) $vs_width * 6 . "px";
}
if (!preg_match("!^[\\d\\.]+px\$!i", $vs_height)) {
$vs_height = (int) $vs_height * 16 . "px";
}
if ($va_settings['usewysiwygeditor']) {
$o_config = Configuration::load();
if (!is_array($va_toolbar_config = $o_config->getAssoc('wysiwyg_editor_toolbar'))) {
$va_toolbar_config = array();
}
AssetLoadManager::register("ckeditor");
$vs_element = "<script type='text/javascript'>jQuery(document).ready(function() {\n\t\t\t\t\t\tvar ckEditor = CKEDITOR.replace( '{fieldNamePrefix}" . $pa_element_info['element_id'] . "_{n}',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttoolbar : " . json_encode(array_values($va_toolbar_config)) . ", /* this does the magic */\n\t\t\t\t\t\t\twidth: '{$vs_width}',\n\t\t\t\t\t\t\theight: '{$vs_height}',\n\t\t\t\t\t\t\ttoolbarLocation: 'top',\n\t\t\t\t\t\t\tenterMode: CKEDITOR.ENTER_BR\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\n\t\t\t\t\t\tckEditor.on('instanceReady', function(){ \n\t\t\t\t\t\t\t ckEditor.document.on( 'keydown', function(e) {if (caUI && caUI.utils) { caUI.utils.showUnsavedChangesWarning(true); } });\n\t\t\t\t\t\t});\n \t});\t\t\t\t\t\t\t\t\t\n</script>";
}
$va_opts = array('size' => $vs_width, 'height' => $vs_height, 'value' => '{{' . $pa_element_info['element_id'] . '}}', 'maxlength' => $va_settings['maxChars'], 'class' => $vs_class, 'id' => '{fieldNamePrefix}' . $pa_element_info['element_id'] . '_{n}', 'class' => "{$vs_class}" . ($va_settings['usewysiwygeditor'] ? " ckeditor" : ''));
if (caGetOption('readonly', $pa_options, false)) {
$va_opts['disabled'] = 1;
}
$vs_element .= caHTMLTextInput('{fieldNamePrefix}' . $pa_element_info['element_id'] . '_{n}', $va_opts);
if ($va_settings['isDependentValue']) {
AssetLoadManager::register('displayTemplateParser');
$t_element = new ca_metadata_elements($pa_element_info['element_id']);
$va_elements = $t_element->getElementsInSet($t_element->getHierarchyRootID());
$va_element_dom_ids = array();
foreach ($va_elements as $vn_i => $va_element) {
if ($va_element['datatype'] == __CA_ATTRIBUTE_VALUE_CONTAINER__) {
continue;
}
$va_element_dom_ids[$va_element['element_code']] = "#{fieldNamePrefix}" . $va_element['element_id'] . "_{n}";
}
$vs_element .= "<script type='text/javascript'>jQuery(document).ready(function() {\n \t\t\t\t\tjQuery('#{fieldNamePrefix}" . $pa_element_info['element_id'] . "_{n}').html(caDisplayTemplateParser.processDependentTemplate('" . addslashes($va_settings['dependentValueTemplate']) . "', " . json_encode($va_element_dom_ids, JSON_FORCE_OBJECT) . "));\n \t\t\t\t";
$vs_element .= "jQuery('" . join(", ", $va_element_dom_ids) . "').bind('keyup', function(e) { \n \t\t\t\t\tjQuery('#{fieldNamePrefix}" . $pa_element_info['element_id'] . "_{n}').html(caDisplayTemplateParser.processDependentTemplate('" . addslashes($va_settings['dependentValueTemplate']) . "', " . json_encode($va_element_dom_ids, JSON_FORCE_OBJECT) . "));\n \t\t\t\t});";
$vs_element .= "});</script>";
}
$vs_bundle_name = $vs_lookup_url = null;
if (isset($pa_options['t_subject']) && is_object($pa_options['t_subject'])) {
$vs_bundle_name = $pa_options['t_subject']->tableName() . '.' . $pa_element_info['element_code'];
if ($pa_options['request']) {
if (isset($pa_options['lookupUrl']) && $pa_options['lookupUrl']) {
$vs_lookup_url = $pa_options['lookupUrl'];
} else {
$vs_lookup_url = caNavUrl($pa_options['request'], 'lookup', 'AttributeValue', 'Get', array('max' => 500, 'bundle' => $vs_bundle_name));
}
}
}
if ($va_settings['suggestExistingValues'] && $vs_lookup_url && $vs_bundle_name) {
$vs_element .= "<script type='text/javascript'>\n \t\t\t\t\tjQuery('#{fieldNamePrefix}" . $pa_element_info['element_id'] . "_{n}').autocomplete( \n\t\t\t\t\t\t{ \n\t\t\t\t\t\t\tsource: '{$vs_lookup_url}',\n\t\t\t\t\t\t\tminLength: 3, delay: 800\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n \t\t\t\t</script>\n";
}
return $vs_element;
}
示例14: _doQueriesForSqlSearch
//.........这里部分代码省略.........
$va_range = $o_tep->getUnixTimestamps();
$vn_user_id = null;
if ($vs_field = trim($vs_field)) {
if (!is_int($vs_field)) {
$t_user = new ca_users();
if ($t_user->load(array("user_name" => $vs_field))) {
$vn_user_id = (int) $t_user->getPrimaryKey();
}
} else {
$vn_user_id = (int) $vs_field;
}
}
$vs_user_sql = $vn_user_id ? " AND (ccl.user_id = " . (int) $vn_user_id . ")" : "";
switch ($vs_table) {
case 'created':
$vs_direct_sql_query = "\n\t\t\t\t\t\t\t\t\t\t\tSELECT ccl.logged_row_id, 1\n\t\t\t\t\t\t\t\t\t\t\tFROM ca_change_log ccl\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t(ccl.log_datetime BETWEEN " . (int) $va_range['start'] . " AND " . (int) $va_range['end'] . ")\n\t\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t(ccl.logged_table_num = ?)\n\t\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t(ccl.changetype = 'I')\n\t\t\t\t\t\t\t\t\t\t\t\t{$vs_user_sql}\n\t\t\t\t\t\t\t\t\t\t";
break;
case 'modified':
$vs_direct_sql_query = "\n\t\t\t\t\t\t\t\t\t\t\tSELECT ccl.logged_row_id, 1\n\t\t\t\t\t\t\t\t\t\t\tFROM ca_change_log ccl\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t(ccl.log_datetime BETWEEN " . (int) $va_range['start'] . " AND " . (int) $va_range['end'] . ")\n\t\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t(ccl.logged_table_num = ?)\n\t\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t(ccl.changetype = 'U')\n\t\t\t\t\t\t\t\t\t\t\t\t{$vs_user_sql}\n\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\tSELECT ccls.subject_row_id, 1\n\t\t\t\t\t\t\t\t\t\t\tFROM ca_change_log ccl\n\t\t\t\t\t\t\t\t\t\t\tINNER JOIN ca_change_log_subjects AS ccls ON ccls.log_id = ccl.log_id\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t(ccl.log_datetime BETWEEN " . (int) $va_range['start'] . " AND " . (int) $va_range['end'] . ")\n\t\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t(ccls.subject_table_num = {$pn_subject_tablenum})\n\t\t\t\t\t\t\t\t\t\t\t\t{$vs_user_sql}\n\t\t\t\t\t\t\t\t\t\t";
break;
}
} else {
if ($vs_table && $vs_field) {
$t_table = $this->opo_datamodel->getInstanceByTableName($vs_table, true);
if ($t_table) {
$vs_table_num = $t_table->tableNum();
if (is_numeric($vs_field)) {
$vs_fld_num = 'I' . $vs_field;
$vn_fld_num = (int) $vs_field;
} else {
$vn_fld_num = $this->getFieldNum($vs_table, $vs_field);
$vs_fld_num = 'I' . $vn_fld_num;
if (!strlen($vn_fld_num)) {
$t_element = new ca_metadata_elements();
if ($t_element->load(array('element_code' => $vs_sub_field ? $vs_sub_field : $vs_field))) {
$vn_fld_num = $t_element->getPrimaryKey();
$vs_fld_num = 'A' . $vn_fld_num;
if (!$vb_is_blank_search) {
//
// For certain types of attributes we can directly query the
// attributes in the database rather than using the full text index
// This allows us to do "intelligent" querying... for example on date ranges
// parsed from natural language input and for length dimensions using unit conversion
//
switch ($t_element->get('datatype')) {
case 2:
// dates
$vb_all_numbers = true;
foreach ($va_raw_terms as $vs_term) {
if (!is_numeric($vs_term)) {
$vb_all_numbers = false;
break;
}
}
$vs_raw_term = join(' ', $va_raw_terms);
$vb_exact = $vs_raw_term[0] == "#" ? true : false;
// dates prepended by "#" are considered "exact" or "contained - the matched dates must be wholly contained by the search term
if ($vb_exact) {
$vs_raw_term = substr($vs_raw_term, 1);
if ($this->opo_tep->parse($vs_raw_term)) {
$va_dates = $this->opo_tep->getHistoricTimestamps();
$vs_direct_sql_query = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT ca.row_id, 1\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM ca_attribute_values cav\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN ca_attributes AS ca ON ca.attribute_id = cav.attribute_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t^JOIN\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(cav.element_id = {$vn_fld_num}) AND (ca.table_num = ?)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(cav.value_decimal1 BETWEEN " . floatval($va_dates['start']) . " AND " . floatval($va_dates['end']) . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(cav.value_decimal2 BETWEEN " . floatval($va_dates['start']) . " AND " . floatval($va_dates['end']) . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
}
} else {
if ($this->opo_tep->parse($vs_raw_term)) {
$va_dates = $this->opo_tep->getHistoricTimestamps();
示例15: getFacetHierarchyLevel
/**
* 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));
//.........这里部分代码省略.........