当前位置: 首页>>代码示例>>PHP>>正文


PHP ca_metadata_elements::get方法代码示例

本文整理汇总了PHP中ca_metadata_elements::get方法的典型用法代码示例。如果您正苦于以下问题:PHP ca_metadata_elements::get方法的具体用法?PHP ca_metadata_elements::get怎么用?PHP ca_metadata_elements::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ca_metadata_elements的用法示例。


在下文中一共展示了ca_metadata_elements::get方法的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;
}
开发者ID:guaykuru,项目名称:pawtucket,代码行数:41,代码来源:advancedSearchHelpers.php

示例2: updateSolrConfiguration

 public static function updateSolrConfiguration($pb_invoked_from_command_line = false)
 {
     /* get search and search indexing configuration */
     $po_app_config = Configuration::load();
     $po_search_config = Configuration::load($po_app_config->get("search_config"));
     $po_search_indexing_config = Configuration::load($po_search_config->get("search_indexing_config"));
     $ps_solr_home_dir = $po_search_config->get('search_solr_home_dir');
     $po_datamodel = Datamodel::load();
     $po_search_base = new SearchBase();
     global $o_db;
     if (!is_object($o_db)) {
         /* catch command line usage */
         $o_db = new Db();
     }
     $t_element = new ca_metadata_elements();
     /* parse search indexing configuration to see which tables are indexed */
     $va_tables = $po_search_indexing_config->getAssocKeys();
     /* create solr.xml first to support multicore */
     $vs_solr_xml = "";
     $vs_solr_xml .= '<?xml version="1.0" encoding="UTF-8" ?>' . SolrConfiguration::nl();
     $vs_solr_xml .= '<solr persistent="true">' . SolrConfiguration::nl();
     $vs_solr_xml .= SolrConfiguration::tabs(1) . '<cores adminPath="/admin/cores">' . SolrConfiguration::nl();
     foreach ($va_tables as $vs_table) {
         /* I don't like tablenums, so we use the table name to name the cores */
         $vs_solr_xml .= SolrConfiguration::tabs(2) . '<core name="' . $vs_table . '" instanceDir="' . $vs_table . '" />' . SolrConfiguration::nl();
     }
     $vs_solr_xml .= SolrConfiguration::tabs(1) . '</cores>' . SolrConfiguration::nl();
     $vs_solr_xml .= '</solr>' . SolrConfiguration::nl();
     /* try to write configuration file */
     $vr_solr_xml_file = fopen($ps_solr_home_dir . "/solr.xml", 'w+');
     // overwrite old one
     if (!is_resource($vr_solr_xml_file)) {
         die("Couldn't write to solr.xml file in Solr home directory. Please check the permissions.\n");
     }
     fprintf($vr_solr_xml_file, "%s", $vs_solr_xml);
     fclose($vr_solr_xml_file);
     /* configure the cores */
     foreach ($va_tables as $vs_table) {
         $t_instance = $po_datamodel->getTableInstance($vs_table);
         /* create core directory */
         if (!file_exists($ps_solr_home_dir . "/" . $vs_table)) {
             if (!mkdir($ps_solr_home_dir . "/" . $vs_table, 0777)) {
                 /* TODO: think about permissions */
                 die("Couldn't create directory in Solr home. Please check the permissions.\n");
             }
         }
         /* create conf directory */
         if (!file_exists($ps_solr_home_dir . "/" . $vs_table . "/conf")) {
             if (!mkdir($ps_solr_home_dir . "/" . $vs_table . "/conf", 0777)) {
                 die("Couldn't create directory in core directory. Please check the permissions.\n");
             }
         }
         /* create solrconfig.xml for this core */
         $vr_solrconfig_xml_file = fopen($ps_solr_home_dir . "/" . $vs_table . "/conf/solrconfig.xml", 'w+');
         if (!is_resource($vr_solrconfig_xml_file)) {
             die("Couldn't write to solrconfig.xml file for core {$vs_table}. Please check the permissions.\n");
         }
         /* read template and copy it */
         $va_solrconfig_xml_template = file(__CA_LIB_DIR__ . "/core/Search/Solr/solrplugin_templates/solrconfig.xml");
         if (!is_array($va_solrconfig_xml_template)) {
             die("Couldn't read solrconfig.xml template.");
         }
         foreach ($va_solrconfig_xml_template as $vs_line) {
             fprintf($vr_solrconfig_xml_file, "%s", $vs_line);
         }
         fclose($vr_solrconfig_xml_file);
         /* create schema.xml for this core */
         $vr_schema_xml_file = fopen($ps_solr_home_dir . "/" . $vs_table . "/conf/schema.xml", 'w+');
         if (!is_resource($vr_schema_xml_file)) {
             die("Couldn't write to schema.xml file for core {$vs_table}. Please check the permissions.\n");
         }
         /* read template, modify it, add table-specific fields and write to schema.xml configuration for this core */
         $va_schema_xml_template = file(__CA_LIB_DIR__ . "/core/Search/Solr/solrplugin_templates/schema.xml");
         if (!is_array($va_schema_xml_template)) {
             die("Couldn't read solrconfig.xml template.");
         }
         foreach ($va_schema_xml_template as $vs_line) {
             /* 1st replacement: core name */
             if (strpos($vs_line, "CORE_NAME") !== false) {
                 fprintf($vr_schema_xml_file, "%s", str_replace("CORE_NAME", $vs_table, $vs_line));
                 continue;
             }
             /* 2nd replacement: fields - the big part */
             if (strpos($vs_line, "<!--FIELDS-->") !== false) {
                 $vs_field_schema = "";
                 $vs_subject_table_copyfields = "";
                 /* the schema is very very hardcoded, so we have to create a design that still fits
                  * when new metadata elements are created or sth like that. for now, we're just considering
                  * the "straightforward" fields
                  */
                 $va_schema_fields = array();
                 /* list of all fields created - is used for copyField directives after field block */
                 /* subject table */
                 /* we add the PK - this is used for incremental indexing */
                 $vs_field_schema .= SolrConfiguration::tabs(2) . '<field name="' . $vs_table . '.' . $t_instance->primaryKey() . '" type="int" indexed="true" stored="true" />' . SolrConfiguration::nl();
                 $vs_field_schema .= SolrConfiguration::tabs(2) . '<field name="' . $t_instance->primaryKey() . '" type="int" indexed="true" stored="true" />' . SolrConfiguration::nl();
                 $vs_subject_table_copyfields .= SolrConfiguration::tabs(1) . '<copyField source="' . $vs_table . '.' . $t_instance->primaryKey() . '" dest="' . $t_instance->primaryKey() . '" />' . SolrConfiguration::nl();
                 /* get fields-to-index from search indexing configuration */
                 if (!is_array($va_table_fields = $po_search_base->getFieldsToIndex($vs_table))) {
                     $va_table_fields = array();
//.........这里部分代码省略.........
开发者ID:guaykuru,项目名称:pawtucket,代码行数:101,代码来源:SolrConfiguration.php

示例3: _getMetadataElement

 private function _getMetadataElement($ps_element_code)
 {
     if (isset(WLPlugSearchEngineSolr::$s_element_code_cache[$ps_element_code])) {
         return WLPlugSearchEngineSolr::$s_element_code_cache[$ps_element_code];
     }
     $t_element = new ca_metadata_elements($ps_element_code);
     if (!($vn_element_id = $t_element->getPrimaryKey())) {
         return WLPlugSearchEngineSolr::$s_element_code_cache[$ps_element_code] = null;
     }
     return WLPlugSearchEngineSolr::$s_element_code_cache[$ps_element_code] = array('element_id' => $vn_element_id, 'element_code' => $t_element->get('element_code'), 'datatype' => $t_element->get('datatype'));
 }
开发者ID:kai-iak,项目名称:pawtucket2,代码行数:11,代码来源:Solr.php

示例4: sortHits

 /**
  * @param $pa_hits Array of row_ids to sort. *MUST HAVE row_ids AS KEYS, NOT VALUES*
  */
 public function sortHits($pa_hits, $ps_field, $ps_direction = 'asc', $pa_options = null)
 {
     if (!in_array(strtolower($ps_direction), array('asc', 'desc'))) {
         $ps_direction = 'asc';
     }
     if (!is_array($pa_hits) || !sizeof($pa_hits)) {
         return $pa_hits;
     }
     $vs_search_tmp_table = $this->loadListIntoTemporaryResultTable($pa_hits, $pa_options['search']);
     $t_table = $this->opo_datamodel->getInstanceByTableNum($this->opn_tablenum, true);
     $vs_table_pk = $t_table->primaryKey();
     $vs_table_name = $this->ops_tablename;
     $va_fields = explode(';', $ps_field);
     $va_sorted_hits = array();
     $vn_num_locales = ca_locales::numberOfCataloguingLocales();
     foreach ($va_fields as $vs_field) {
         $va_joins = $va_orderbys = array();
         $vs_locale_where = $vs_is_preferred_sql = '';
         $va_tmp = explode('.', $vs_field);
         // Rewrite for <table>.preferred_labels.* syntax
         if ($va_tmp[1] == 'preferred_labels') {
             if ($t_labeled_item_table = $this->opo_datamodel->getInstanceByTableName($va_tmp[0], true)) {
                 if ($t_label_table = $t_labeled_item_table->getLabelTableInstance()) {
                     $va_tmp2 = array($t_label_table->tableName());
                     if (isset($va_tmp[2]) && $t_label_table->hasField($va_tmp[2])) {
                         $va_tmp2[] = $va_tmp[2];
                     } else {
                         $va_tmp2[] = $t_labeled_item_table->getLabelDisplayField();
                     }
                     $va_tmp = $va_tmp2;
                     $vs_field = join(".", $va_tmp);
                 }
             }
         }
         if ($va_tmp[0] == $vs_table_name) {
             //
             // sort field is in search table
             //
             if (!$t_table->hasField($va_tmp[1])) {
                 //
                 // is it an attribute?
                 //
                 $t_element = new ca_metadata_elements();
                 $vs_sort_element_code = array_pop($va_tmp);
                 if ($t_element->load(array('element_code' => $vs_sort_element_code))) {
                     $vn_element_id = $t_element->getPrimaryKey();
                     if (!($vs_sortable_value_fld = Attribute::getSortFieldForDatatype($t_element->get('datatype')))) {
                         return $pa_hits;
                     }
                     if ((int) $t_element->get('datatype') == 3) {
                         $vs_sortable_value_fld = 'lil.name_plural';
                         $vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
                         $vs_locale_where = $vn_num_locales > 1 ? ', lil.locale_id' : '';
                         $vs_sql = "\n\t\t\t\t\t\t\t\tSELECT attr.row_id, lil.locale_id, lower({$vs_sortable_value_fld}) {$vs_sort_field}\n\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\tINNER JOIN ca_list_item_labels AS lil ON lil.item_id = attr_vals.item_id\n\t\t\t\t\t\t\t\tINNER JOIN {$vs_browse_tmp_table} ON {$vs_browse_tmp_table}.row_id = attr.row_id\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND (attr.table_num = ?) AND (lil.{$vs_sort_field} IS NOT NULL)\n\t\t\t\t\t\t\t\tORDER BY lil.{$vs_sort_field}\n\t\t\t\t\t\t\t";
                     } else {
                         $vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
                         $vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
                         $vs_locale_where = $vn_num_locales > 1 ? 'attr.locale_id' : '';
                         $vs_sql = "\n\t\t\t\t\t\t\t\tSELECT attr.row_id, attr.locale_id, lower({$vs_sortable_value_fld}) {$vs_sort_field}\n\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\tINNER JOIN {$vs_search_tmp_table} ON {$vs_search_tmp_table}.row_id = attr.row_id\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND (attr.table_num = ?) AND (attr_vals.{$vs_sort_field} IS NOT NULL)\n\t\t\t\t\t\t\t\tORDER BY attr_vals.{$vs_sort_field}\n\t\t\t\t\t\t\t";
                         //print $vs_sql." ; $vn_element_id/; ".$this->opn_tablenum."<br>";
                     }
                     $qr_sort = $this->opo_db->query($vs_sql, (int) $vn_element_id, (int) $this->opn_tablenum);
                     while ($qr_sort->nextRow()) {
                         $va_row = $qr_sort->getRow();
                         if (!$va_row['row_id']) {
                             continue;
                         }
                         if ($vn_num_locales > 1) {
                             $va_sorted_hits[$va_row['row_id']][$va_row['locale_id']] .= trim(str_replace(array("'", '"'), array('', ''), $va_row[$vs_sort_field]));
                         } else {
                             $va_sorted_hits[$va_row['row_id']] .= trim(str_replace(array("'", '"'), array('', ''), $va_row[$vs_sort_field]));
                         }
                         unset($pa_hits[$va_row['row_id']]);
                     }
                     // Add on hits that aren't sorted because they don't have an attribute associated
                     foreach ($pa_hits as $vn_id => $va_row) {
                         if (!is_array($va_row)) {
                             $va_row = array();
                         }
                         if ($vn_num_locales > 1) {
                             $va_sorted_hits[$vn_id][1] = $va_row;
                         } else {
                             $va_sorted_hits[$vn_id] = $va_row;
                         }
                     }
                 }
                 continue;
             } else {
                 $va_field_info = $t_table->getFieldInfo($va_tmp[1]);
                 if ($va_field_info['START'] && $va_field_info['END']) {
                     $va_orderbys[] = $va_field_info['START'] . ' ' . $ps_direction;
                     $va_orderbys[] = $va_field_info['END'] . ' ' . $ps_direction;
                 } else {
                     $va_orderbys[] = $vs_field . ' ' . $ps_direction;
                 }
                 if ($t_table->hasField('locale_id')) {
                     $vs_locale_where = ", " . $vs_table_name . ".locale_id";
//.........这里部分代码省略.........
开发者ID:guaykuru,项目名称:pawtucket,代码行数:101,代码来源:SearchEngine.php

示例5: processExporterItem

 /**
  * Processes single exporter item for a given record
  *
  * @param int $pn_item_id Primary of exporter item
  * @param int $pn_table_num Table num of item to export
  * @param int $pn_record_id Primary key value of item to export
  * @param array $pa_options
  *		ignoreContext = don't switch context even though context may be set for current item
  *		relationship_type_id, relationship_type_code, relationship_typename =
  *			if this export is a sub-export (context-switch), we have no way of knowing the relationship
  *			to the 'parent' element in the export, so there has to be a means to pass it down to make it accessible
  * 		attribute_id = signals that this is an export relative to a specific attribute instance
  * 			this triggers special behavior that allows getting container values in a kind of sub-export
  *			it's really only useful for Containers but in theory can be any attribute
  *		logger = KLogger instance to use for logging. This option is mandatory!
  * @return array Item info
  */
 public function processExporterItem($pn_item_id, $pn_table_num, $pn_record_id, $pa_options = array())
 {
     $o_log = caGetOption('logger', $pa_options);
     // always set by exportRecord()
     $vb_ignore_context = caGetOption('ignoreContext', $pa_options);
     $vn_attribute_id = caGetOption('attribute_id', $pa_options);
     $o_log->logInfo(_t("Export mapping processor called with parameters [exporter_item_id:%1 table_num:%2 record_id:%3]", $pn_item_id, $pn_table_num, $pn_record_id));
     $t_exporter_item = ca_data_exporters::loadExporterItemByID($pn_item_id);
     $t_instance = ca_data_exporters::loadInstanceByID($pn_record_id, $pn_table_num);
     // switch context to a different set of records if necessary and repeat current exporter item for all those selected records
     // (e.g. hierarchy children or related items in another table, restricted by types or relationship types)
     if (!$vb_ignore_context && ($vs_context = $t_exporter_item->getSetting('context'))) {
         $va_restrict_to_types = $t_exporter_item->getSetting('restrictToTypes');
         $va_restrict_to_rel_types = $t_exporter_item->getSetting('restrictToRelationshipTypes');
         $va_restrict_to_bundle_vals = $t_exporter_item->getSetting('restrictToBundleValues');
         $va_check_access = $t_exporter_item->getSetting('checkAccess');
         $va_sort = $t_exporter_item->getSetting('sort');
         $vn_new_table_num = $this->getAppDatamodel()->getTableNum($vs_context);
         $vb_context_is_related_table = false;
         $va_related = null;
         if ($vn_new_table_num) {
             // switch to new table
             $vs_key = $this->getAppDatamodel()->getTablePrimaryKeyName($vs_context);
         } else {
             // this table, i.e. hierarchy context switch
             $vs_key = $t_instance->primaryKey();
         }
         $o_log->logInfo(_t("Initiating context switch to '%1' for mapping ID %2 and record ID %3. The processor now tries to find matching records for the switch and calls itself for each of those items.", $vs_context, $pn_item_id, $pn_record_id));
         switch ($vs_context) {
             case 'children':
                 $va_related = $t_instance->getHierarchyChildren();
                 break;
             case 'parent':
                 $va_related = array();
                 if ($vs_parent_id_fld = $t_instance->getProperty("HIERARCHY_PARENT_ID_FLD")) {
                     $va_related[] = array($vs_key => $t_instance->get($vs_parent_id_fld));
                 }
                 break;
             case 'ancestors':
                 $va_parents = $t_instance->getHierarchyAncestors(null, array('idsOnly' => true));
                 $va_related = array();
                 foreach (array_unique($va_parents) as $vn_pk) {
                     $va_related[] = array($vs_key => intval($vn_pk));
                 }
                 break;
             case 'ca_sets':
                 $t_set = new ca_sets();
                 $va_set_options = array();
                 if (isset($va_restrict_to_types[0])) {
                     // the utility used below doesn't support passing multiple types so we just pass the first.
                     // this should be enough for 99.99% of the actual use cases anyway
                     $va_set_options['setType'] = $va_restrict_to_types[0];
                 }
                 $va_set_options['checkAccess'] = $va_check_access;
                 $va_set_options['setIDsOnly'] = true;
                 $va_set_ids = $t_set->getSetsForItem($pn_table_num, $t_instance->getPrimaryKey(), $va_set_options);
                 $va_related = array();
                 foreach (array_unique($va_set_ids) as $vn_pk) {
                     $va_related[] = array($vs_key => intval($vn_pk));
                 }
                 break;
             case 'ca_list_items.firstLevel':
                 if ($t_instance->tableName() == 'ca_lists') {
                     $o_dm = Datamodel::load();
                     $va_related = array();
                     $va_items_legacy_format = $t_instance->getListItemsAsHierarchy(null, array('maxLevels' => 1, 'dontIncludeRoot' => true));
                     $vn_new_table_num = $o_dm->getTableNum('ca_list_items');
                     $vs_key = 'item_id';
                     foreach ($va_items_legacy_format as $va_item_legacy_format) {
                         $va_related[$va_item_legacy_format['NODE']['item_id']] = $va_item_legacy_format['NODE'];
                     }
                     break;
                 } else {
                     return array();
                 }
                 break;
             default:
                 if ($vn_new_table_num) {
                     $va_options = array('restrictToTypes' => $va_restrict_to_types, 'restrictToRelationshipTypes' => $va_restrict_to_rel_types, 'restrictToBundleValues' => $va_restrict_to_bundle_vals, 'checkAccess' => $va_check_access, 'sort' => $va_sort);
                     $o_log->logDebug(_t("Calling getRelatedItems with options: %1.", print_r($va_options, true)));
                     $va_related = $t_instance->getRelatedItems($vs_context, $va_options);
                     $vb_context_is_related_table = true;
                 } else {
//.........这里部分代码省略.........
开发者ID:samrahman,项目名称:providence,代码行数:101,代码来源:ca_data_exporters.php

示例6: 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);
     }
 }
开发者ID:samrahman,项目名称:providence,代码行数:51,代码来源:FieldType.php

示例7: 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));
//.........这里部分代码省略.........
开发者ID:idiscussforum,项目名称:providence,代码行数:101,代码来源:BaseRefineableSearchController.php

示例8: _doQueriesForSqlSearch

 private function _doQueriesForSqlSearch($po_rewritten_query, $pn_subject_tablenum, $ps_dest_table, $pn_level = 0)
 {
     // query is always of type Zend_Search_Lucene_Search_Query_Boolean
     $vn_i = 0;
     $va_old_signs = $po_rewritten_query->getSigns();
     foreach ($po_rewritten_query->getSubqueries() as $o_lucene_query_element) {
         $vb_is_blank_search = false;
         if (is_null($va_old_signs)) {
             // if array is null then according to Zend Lucene all subqueries should be "are required"... so we AND them
             $vs_op = "AND";
         } else {
             if (is_null($va_old_signs[$vn_i])) {
                 // is the sign for a particular query is null then OR is (it is "neither required nor prohibited")
                 $vs_op = 'OR';
             } else {
                 $vs_op = $va_old_signs[$vn_i] === false ? 'NOT' : 'AND';
                 // true sign indicated "required" (AND) operation, false indicated "prohibited" (NOT) operation
             }
         }
         if ($vn_i == 0) {
             $vs_op = 'OR';
         }
         $va_direct_query_temp_tables = array();
         // List of temporary tables created by direct search queries; tables listed here are dropped at the end of processing for the query element
         switch (get_class($o_lucene_query_element)) {
             case 'Zend_Search_Lucene_Search_Query_Boolean':
                 $this->_createTempTable('ca_sql_search_temp_' . $pn_level);
                 $this->_doQueriesForSqlSearch($o_lucene_query_element, $pn_subject_tablenum, 'ca_sql_search_temp_' . $pn_level, $pn_level + 1);
                 // merge with current destination
                 switch ($vs_op) {
                     case 'AND':
                         // and
                         $this->_createTempTable($ps_dest_table . '_acc');
                         if ($vn_i == 0) {
                             $vs_sql = "\n\t\t\t\t\t\t\t\t\tINSERT IGNORE INTO {$ps_dest_table}\n\t\t\t\t\t\t\t\t\tSELECT DISTINCT row_id, boost\n\t\t\t\t\t\t\t\t\tFROM ca_sql_search_temp_{$pn_level}\n\t\t\t\t\t\t\t\t";
                             //print "$vs_sql<hr>";
                             $qr_res = $this->opo_db->query($vs_sql);
                         } else {
                             $vs_sql = "\n\t\t\t\t\t\t\t\t\tINSERT IGNORE INTO {$ps_dest_table}_acc\n\t\t\t\t\t\t\t\t\tSELECT mfs.row_id, SUM(mfs.boost)\n\t\t\t\t\t\t\t\t\tFROM {$ps_dest_table} mfs\n\t\t\t\t\t\t\t\t\tINNER JOIN ca_sql_search_temp_{$pn_level} AS ftmp1 ON ftmp1.row_id = mfs.row_id\n\t\t\t\t\t\t\t\t\tGROUP BY mfs.row_id\n\t\t\t\t\t\t\t\t";
                             //print "$vs_sql<hr>";
                             $qr_res = $this->opo_db->query($vs_sql);
                             $qr_res = $this->opo_db->query("TRUNCATE TABLE {$ps_dest_table}");
                             $qr_res = $this->opo_db->query("INSERT INTO {$ps_dest_table} SELECT row_id, boost FROM {$ps_dest_table}_acc");
                         }
                         $this->_dropTempTable($ps_dest_table . '_acc');
                         break;
                     case 'NOT':
                         $vs_sql = "\n\t\t\t\t\t\t\t\tDELETE FROM {$ps_dest_table} WHERE row_id IN\n\t\t\t\t\t\t\t\t(SELECT row_id FROM ca_sql_search_temp_{$pn_level})\n\t\t\t\t\t\t\t";
                         //print "$vs_sql<hr>";
                         $qr_res = $this->opo_db->query($vs_sql);
                         break;
                     default:
                     case 'OR':
                         // or
                         $vs_sql = "\n\t\t\t\t\t\t\t\tINSERT IGNORE INTO {$ps_dest_table}\n\t\t\t\t\t\t\t\tSELECT row_id, SUM(boost)\n\t\t\t\t\t\t\t\tFROM ca_sql_search_temp_{$pn_level}\n\t\t\t\t\t\t\t\tGROUP BY row_id\n\t\t\t\t\t\t\t";
                         //print "$vs_sql<hr>";
                         $qr_res = $this->opo_db->query($vs_sql);
                         break;
                 }
                 $this->_dropTempTable('ca_sql_search_temp_' . $pn_level);
                 break;
             case 'Zend_Search_Lucene_Search_Query_Term':
             case 'Zend_Search_Lucene_Search_Query_MultiTerm':
             case 'Zend_Search_Lucene_Search_Query_Phrase':
             case 'Zend_Search_Lucene_Search_Query_Range':
                 $va_ft_terms = array();
                 $va_ft_like_terms = array();
                 $va_ft_stem_terms = array();
                 $vs_direct_sql_query = null;
                 $pa_direct_sql_query_params = null;
                 // set to array with values to use with direct SQL query placeholders or null to pass single standard table_num value as param (most queries just need this single value)
                 $va_tmp = array();
                 $vs_access_point = '';
                 $va_raw_terms = array();
                 switch (get_class($o_lucene_query_element)) {
                     case 'Zend_Search_Lucene_Search_Query_Range':
                         $va_lower_term = $o_lucene_query_element->getLowerTerm();
                         $va_upper_term = $o_lucene_query_element->getUpperTerm();
                         $va_element = $this->_getElementIDForAccessPoint($va_lower_term->field);
                         switch ($va_element['datatype']) {
                             case 4:
                                 // geocode
                                 $t_geocode = new GeocodeAttributeValue();
                                 $va_parsed_value = $t_geocode->parseValue($va_lower_term->text, $va_element['element_info']);
                                 $vs_lower_lat = $va_parsed_value['value_decimal1'];
                                 $vs_lower_long = $va_parsed_value['value_decimal2'];
                                 $va_parsed_value = $t_geocode->parseValue($va_upper_term->text, $va_element['element_info']);
                                 $vs_upper_lat = $va_parsed_value['value_decimal1'];
                                 $vs_upper_long = $va_parsed_value['value_decimal2'];
                                 $vs_direct_sql_query = "\n\t\t\t\t\t\t\t\t\t\tSELECT ca.row_id, 1\n\t\t\t\t\t\t\t\t\t\tFROM ca_attribute_values cav\n\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^JOIN\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(cav.element_id = " . intval($va_element['element_id']) . ") AND (ca.table_num = ?)\n\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t(cav.value_decimal1 BETWEEN " . floatval($vs_lower_lat) . " AND " . floatval($vs_upper_lat) . ")\n\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t(cav.value_decimal2 BETWEEN " . floatval($vs_lower_long) . " AND " . floatval($vs_upper_long) . ")\t\n\t\t\t\t\t\t\t\t\t";
                                 break;
                             case 6:
                                 // currency
                                 $t_cur = new CurrencyAttributeValue();
                                 $va_parsed_value = $t_cur->parseValue($va_lower_term->text, $va_element['element_info']);
                                 $vs_currency = preg_replace('![^A-Z0-9]+!', '', $va_parsed_value['value_longtext1']);
                                 $vn_lower_val = $va_parsed_value['value_decimal1'];
                                 $va_parsed_value = $t_cur->parseValue($va_upper_term->text, $va_element['element_info']);
                                 $vn_upper_val = $va_parsed_value['value_decimal1'];
                                 $vs_direct_sql_query = "\n\t\t\t\t\t\t\t\t\t\tSELECT ca.row_id, 1\n\t\t\t\t\t\t\t\t\t\tFROM ca_attribute_values cav\n\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^JOIN\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(cav.element_id = " . intval($va_element['element_id']) . ") AND (ca.table_num = ?)\n\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t(cav.value_decimal1 BETWEEN " . floatval($vn_lower_val) . " AND " . floatval($vn_upper_val) . ")\n\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t(cav.value_longtext1 = '" . $this->opo_db->escape($vs_currency) . "')\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t";
//.........这里部分代码省略.........
开发者ID:guaykuru,项目名称:pawtucket,代码行数:101,代码来源:SqlSearch.php

示例9: 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);
     $va_access_values = caGetUserAccessValues($this->request);
     $ps_facet_name = $this->request->getParameter('facet', pString);
     $this->view->setVar("facet_name", $ps_facet_name);
     $this->view->setVar("key", $this->request->getParameter('key', pString));
     $ps_browse_type = $this->request->getParameter('browseType', pString);
     if (!($va_browse_info = caGetInfoForBrowseType($ps_browse_type))) {
         // invalid browse type – throw error
         die("Invalid browse type");
     }
     $this->view->setVar("browse_type", $ps_browse_type);
     $vs_class = $va_browse_info['table'];
     $o_browse = caGetBrowseInstance($vs_class);
     if (!is_array($va_facet_info = $o_browse->getInfoForFacet($ps_facet_name))) {
         return null;
     }
     if ($ps_cache_key = $this->request->getParameter('key', pString)) {
         $o_browse->reload($ps_cache_key);
     }
     $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()) {
                         $vs_primary_key = $t_item->primaryKey();
                         $this->view->setVar("primary_key", $vs_primary_key);
                         $vs_display_fld = $t_item->getLabelDisplayField();
                         $this->view->setVar("display_field", $vs_display_fld);
                         $vs_label_table_name = $t_item->getLabelTableName();
                         $va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'additionalTableToJoin' => $vs_label_table_name, 'additionalTableJoinType' => 'LEFT', 'additionalTableSelectFields' => array($vs_display_fld, 'locale_id'), 'additionalTableWheres' => array('(' . $vs_label_table_name . '.is_preferred = 1 OR ' . $vs_label_table_name . '.is_preferred IS NULL)'))));
                         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->request->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 = $o_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()) {
                 $vs_primary_key = $t_item->primaryKey();
                 $this->view->setVar("primary_key", $vs_primary_key);
                 $vs_display_fld = $t_item->getLabelDisplayField();
                 $this->view->setVar("display_field", $vs_display_fld);
                 $vs_label_table_name = $t_item->getLabelTableName();
                 $va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'additionalTableToJoin' => $vs_label_table_name, 'additionalTableJoinType' => 'LEFT', 'additionalTableSelectFields' => array($vs_display_fld, 'locale_id'), 'additionalTableWheres' => array('(' . $vs_label_table_name . '.is_preferred = 1 OR ' . $vs_label_table_name . '.is_preferred IS NULL)'))));
             }
             if ($vn_hierarchies_in_use <= 1) {
                 array_shift($va_ancestors);
             }
             break;
     }
     $this->view->setVar('ancestors', $va_ancestors);
     switch ($this->request->getParameter('returnAs', pString)) {
         case "json":
             return $this->render('Browse/facet_hierarchy_ancestors_json.php');
             break;
             # ------------------------------------------------
         # ------------------------------------------------
         case "html":
         default:
             return $this->render('Browse/facet_hierarchy_ancestors_html.php');
             break;
             # ------------------------------------------------
     }
 }
开发者ID:ffarago,项目名称:pawtucket2,代码行数:99,代码来源:FindController.php

示例10: sortHits

 /**
  *
  */
 public function sortHits(&$pa_hits, $ps_table, $ps_field, $ps_key, $ps_direction = 'asc', $pa_options = null)
 {
     //$t= new Timer();
     $vs_browse_tmp_table = $this->loadListIntoTemporaryResultTable($pa_hits, $ps_key);
     if (!in_array(strtolower($ps_direction), array('asc', 'desc'))) {
         $ps_direction = 'asc';
     }
     if (!is_array($pa_hits) || !sizeof($pa_hits)) {
         return $pa_hits;
     }
     $t_table = $this->opo_datamodel->getInstanceByTableName($ps_table, true);
     $vs_table_pk = $t_table->primaryKey();
     $vn_table_num = $t_table->tableNum();
     $va_sort_tmp = explode('/', $ps_field);
     $ps_field = $va_sort_tmp[0];
     $vs_rel_type = sizeof($va_sort_tmp) > 1 ? $va_sort_tmp[1] : null;
     $va_fields = explode(';', $ps_field);
     $va_sorted_hits = array();
     $va_joins = array();
     $vs_locale_where = $vs_is_preferred_sql = '';
     $vs_primary_sort_field = array_shift($va_fields);
     $va_primary_sort_field = explode('.', $vs_primary_sort_field);
     $va_additional_sort_fields = array();
     foreach ($va_fields as $vs_additional_sort_field) {
         $va_tmp = explode('.', $vs_additional_sort_field);
         if ($va_tmp[0] == $va_primary_sort_field[0]) {
             $va_additional_sort_fields[] = $va_tmp;
         }
     }
     if ($va_primary_sort_field[0] == $ps_table) {
         //
         // sort field is in search table
         //
         if (!$t_table->hasField($va_primary_sort_field[1])) {
             //
             // is it an attribute?
             //
             $t_element = new ca_metadata_elements();
             $vs_sort_element_code = array_pop($va_primary_sort_field);
             if ($t_element->load(array('element_code' => $vs_sort_element_code))) {
                 $vn_element_id = $t_element->getPrimaryKey();
                 if (!($vs_sortable_value_fld = Attribute::getSortFieldForDatatype($t_element->get('datatype')))) {
                     return $pa_hits;
                 }
                 if ((int) $t_element->get('datatype') == __CA_ATTRIBUTE_VALUE_LIST__) {
                     $vs_sortable_value_fld = 'lil.name_plural';
                     $vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
                     $vs_sql = "\n\t\t\t\t\t\t\t\tSELECT attr.row_id, lil.locale_id, lower({$vs_sortable_value_fld}) {$vs_sort_field}\n\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\tINNER JOIN ca_list_item_labels AS lil ON lil.item_id = attr_vals.item_id\n\t\t\t\t\t\t\t\tINNER JOIN {$vs_browse_tmp_table} ON {$vs_browse_tmp_table}.row_id = attr.row_id\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND (attr.table_num = ?) AND (lil.{$vs_sort_field} IS NOT NULL)\n\t\t\t\t\t\t\t\tORDER BY lil.{$vs_sort_field} {$ps_direction}\n\t\t\t\t\t\t\t";
                 } elseif ((int) $t_element->get('datatype') == __CA_ATTRIBUTE_VALUE_DATERANGE__) {
                     $vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
                     $vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
                     $vs_sql = "\n\t\t\t\t\t\t\t\tSELECT attr.row_id, attr.locale_id, {$vs_sortable_value_fld}\n\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\tINNER JOIN {$vs_browse_tmp_table} ON {$vs_browse_tmp_table}.row_id = attr.row_id\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND (attr.table_num = ?) AND (attr_vals.{$vs_sort_field} IS NOT NULL)\n\t\t\t\t\t\t\t\tORDER BY attr_vals.{$vs_sort_field} {$ps_direction}, attr.row_id\n\t\t\t\t\t\t\t";
                 } else {
                     $vs_sortable_value_fld = 'attr_vals.' . $vs_sortable_value_fld;
                     $vs_sort_field = array_pop(explode('.', $vs_sortable_value_fld));
                     $vs_sql = "\n\t\t\t\t\t\t\t\tSELECT attr.row_id, attr.locale_id, lower({$vs_sortable_value_fld}) {$vs_sort_field}\n\t\t\t\t\t\t\t\tFROM ca_attributes attr\n\t\t\t\t\t\t\t\tINNER JOIN ca_attribute_values AS attr_vals ON attr_vals.attribute_id = attr.attribute_id\n\t\t\t\t\t\t\t\tINNER JOIN {$vs_browse_tmp_table} ON {$vs_browse_tmp_table}.row_id = attr.row_id\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t(attr_vals.element_id = ?) AND (attr.table_num = ?) AND (attr_vals.{$vs_sort_field} IS NOT NULL)\n\t\t\t\t\t\t\t\tORDER BY attr_vals.{$vs_sort_field} {$ps_direction}, attr.row_id\n\t\t\t\t\t\t\t";
                 }
                 $qr_sort = $this->opo_db->query($vs_sql, (int) $vn_element_id, (int) $vn_table_num);
                 $va_sorted_hits = $qr_sort->getAllFieldValues('row_id');
                 // Add on hits that aren't sorted because they don't have an attribute associated
                 $va_missing_items = array_diff($pa_hits, $va_sorted_hits);
                 $va_sorted_hits = array_merge($va_sorted_hits, $va_missing_items);
             }
             return $va_sorted_hits;
         } else {
             $va_field_info = $t_table->getFieldInfo($va_primary_sort_field[1]);
             if ($va_field_info['START'] && $va_field_info['END']) {
                 $vs_sortable_value_fld = $vs_primary_sort_field;
                 $va_additional_sort_fields[] = $va_field_info['END'];
             } else {
                 $vs_sortable_value_fld = $vs_primary_sort_field;
             }
         }
     } else {
         // sort field is in related table
         $va_path = $this->opo_datamodel->getPath($ps_table, $va_primary_sort_field[0]);
         if (sizeof($va_path) > 2) {
             // many-many
             $vs_last_table = null;
             // generate related joins
             foreach ($va_path as $vs_table => $va_info) {
                 $t_table = $this->opo_datamodel->getInstanceByTableName($vs_table, true);
                 $vs_rel_type_sql = null;
                 if ($t_table->isRelationship() && $vs_rel_type) {
                     if (is_array($va_rel_types = caMakeRelationshipTypeIDList($vs_table, array($vs_rel_type))) && sizeof($va_rel_types)) {
                         $vs_rel_type_sql = " AND {$vs_table}.type_id IN (" . join(",", $va_rel_types) . ")";
                     }
                 }
                 if ($vs_last_table) {
                     $va_rels = $this->opo_datamodel->getOneToManyRelations($vs_last_table, $vs_table);
                     if (!sizeof($va_rels)) {
                         $va_rels = $this->opo_datamodel->getOneToManyRelations($vs_table, $vs_last_table);
                     }
                     if ($vs_table == $va_rels['one_table']) {
                         $va_joins[$vs_table] = "INNER JOIN " . $va_rels['one_table'] . " ON " . $va_rels['one_table'] . "." . $va_rels['one_table_field'] . " = " . $va_rels['many_table'] . "." . $va_rels['many_table_field'] . $vs_rel_type_sql;
                     } else {
                         $va_joins[$vs_table] = "INNER JOIN " . $va_rels['many_table'] . " ON " . $va_rels['many_table'] . "." . $va_rels['many_table_field'] . " = " . $va_rels['one_table'] . "." . $va_rels['one_table_field'] . $vs_rel_type_sql;
//.........这里部分代码省略.........
开发者ID:ffarago,项目名称:pawtucket2,代码行数:101,代码来源:BaseFindEngine.php

示例11: GetDetail

 /**
  * 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');
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:42,代码来源:InformationServiceController.php

示例12: DownloadAttributeMedia

 /**
  * Initiates user download of media stored in a media attribute, returning file in response to request.
  * Adds download output to response directly. No view is used.
  *
  * @param array $pa_options Array of options passed through to _initView 
  */
 public function DownloadAttributeMedia($pa_options = null)
 {
     if (!($pn_value_id = $this->request->getParameter('value_id', pInteger))) {
         return;
     }
     $t_attr_val = new ca_attribute_values($pn_value_id);
     if (!$t_attr_val->getPrimaryKey()) {
         return;
     }
     $t_attr = new ca_attributes($t_attr_val->get('attribute_id'));
     $vn_table_num = $this->opo_datamodel->getTableNum($this->ops_table_name);
     if ($t_attr->get('table_num') != $vn_table_num) {
         $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/2580?r=' . urlencode($this->request->getFullUrlPath()));
         return;
     }
     $t_element = new ca_metadata_elements($t_attr->get('element_id'));
     $this->request->setParameter($this->opo_datamodel->getTablePrimaryKeyName($vn_table_num), $t_attr->get('row_id'));
     list($vn_subject_id, $t_subject) = $this->_initView($pa_options);
     $ps_version = $this->request->getParameter('version', pString);
     if (!$this->_checkAccess($t_subject)) {
         return false;
     }
     //
     // Does user have access to bundle?
     //
     if ($this->request->user->getBundleAccessLevel($this->ops_table_name, $t_element->get('element_code')) < __CA_BUNDLE_ACCESS_READONLY__) {
         $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/2580?r=' . urlencode($this->request->getFullUrlPath()));
         return;
     }
     $t_attr_val->useBlobAsMediaField(true);
     if (!in_array($ps_version, $t_attr_val->getMediaVersions('value_blob'))) {
         $ps_version = 'original';
     }
     $o_view = new View($this->request, $this->request->getViewsDirectoryPath() . '/bundles/');
     // get value
     $t_element = new ca_metadata_elements($t_attr_val->get('element_id'));
     // check that value is a media attribute
     if ($t_element->get('datatype') != 16) {
         // 16=media
         return;
     }
     $vs_path = $t_attr_val->getMediaPath('value_blob', $ps_version);
     $vs_path_ext = pathinfo($vs_path, PATHINFO_EXTENSION);
     if ($vs_name = trim($t_attr_val->get('value_longtext2'))) {
         $vs_file_name = pathinfo($vs_name, PATHINFO_FILENAME);
         $vs_name = "{$vs_file_name}.{$vs_path_ext}";
     } else {
         $vs_name = _t("downloaded_file.%1", $vs_path_ext);
     }
     $o_view->setVar('file_path', $vs_path);
     $o_view->setVar('file_name', $vs_name);
     // send download
     $this->response->addContent($o_view->render('ca_attributes_download_media.php'));
 }
开发者ID:kai-iak,项目名称:pawtucket2,代码行数:60,代码来源:BaseEditorController.php

示例13: getInstance

 /**
  * 
  */
 public static function getInstance($pm_element_code_or_id)
 {
     if (isset(ca_metadata_elements::$s_element_instance_cache[$pm_element_code_or_id])) {
         return ca_metadata_elements::$s_element_instance_cache[$pm_element_code_or_id];
     }
     $t_element = new ca_metadata_elements(is_numeric($pm_element_code_or_id) ? $pm_element_code_or_id : null);
     if (!($vn_element_id = $t_element->getPrimaryKey())) {
         if ($t_element->load(array('element_code' => $pm_element_code_or_id))) {
             return ca_metadata_elements::$s_element_instance_cache[$t_element->getPrimaryKey()] = ca_metadata_elements::$s_element_instance_cache[$t_element->get('element_code')] = $t_element;
         }
     } else {
         return ca_metadata_elements::$s_element_instance_cache[$vn_element_id] = ca_metadata_elements::$s_element_instance_cache[$t_element->get('element_code')] = $t_element;
     }
     return null;
 }
开发者ID:guaykuru,项目名称:pawtucket,代码行数:18,代码来源:ca_metadata_elements.php

示例14: getUIUsageCounts

 /**
  * Returns array of with information about usage of metadata element(s) in user interfaces
  *
  * @param $pm_element_code_or_id mixed Optional element_id or code. If set then counts are only returned for the specified element. If omitted then counts are returned for all elements.
  * @return array Array of counts. Keys are element_codes, values are arrays keyed on table DISPLAY name (eg. "set items", not "ca_set_items"). Values are the number of times the element is references in a user interface for the table.
  */
 public static function getUIUsageCounts($pm_element_code_or_id = null)
 {
     // Get UI usage counts
     $vo_db = new Db();
     $vn_element_id = null;
     if ($pm_element_code_or_id) {
         $t_element = new ca_metadata_elements($pm_element_code_or_id);
         if (!($vn_element_id = $t_element->getPrimaryKey())) {
             if ($t_element->load(array('element_code' => $pm_element_code_or_id))) {
                 $vn_element_id = $t_element->getPrimaryKey();
             }
         }
     }
     $vs_sql_where = '';
     if ($vn_element_id) {
         $vs_sql_where = " WHERE p.bundle_name = 'ca_attribute_" . $t_element->get('element_code') . "'";
     }
     $qr_use_counts = $vo_db->query("\n\t\t\tSELECT count(*) c, p.bundle_name, u.editor_type \n\t\t\tFROM ca_editor_ui_bundle_placements p \n\t\t\tINNER JOIN ca_editor_ui_screens AS s ON s.screen_id = p.screen_id \n\t\t\tINNER JOIN ca_editor_uis AS u ON u.ui_id = s.ui_id \n\t\t\t{$vs_sql_where}\n\t\t\tGROUP BY \n\t\t\t\tp.bundle_name, u.editor_type\n\t\t");
     $va_counts_by_attribute = array();
     $o_dm = Datamodel::load();
     while ($qr_use_counts->nextRow()) {
         if (preg_match('!^ca_attribute_([A-Za-z0-9_\\-]+)$!', $qr_use_counts->get('bundle_name'), $va_matches)) {
             if (!($t_table = $o_dm->getInstanceByTableNum($qr_use_counts->get('editor_type'), true))) {
                 continue;
             }
             $va_counts_by_attribute[$va_matches[1]][$t_table->getProperty('NAME_PLURAL')] = $qr_use_counts->get('c');
         }
     }
     return $va_counts_by_attribute;
 }
开发者ID:kai-iak,项目名称:pawtucket2,代码行数:36,代码来源:ca_metadata_elements.php

示例15: 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');
 }
开发者ID:kai-iak,项目名称:pawtucket2,代码行数:67,代码来源:BaseBrowseController.php


注:本文中的ca_metadata_elements::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。