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


PHP ca_metadata_elements::load方法代码示例

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


在下文中一共展示了ca_metadata_elements::load方法的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: Get

 public function Get($pa_additional_query_params = null, $pa_options = null)
 {
     $ps_query = $this->request->getParameter('term', pString);
     $ps_bundle = $this->request->getParameter('bundle', pString);
     $va_tmp = explode('.', $ps_bundle);
     $o_dm = Datamodel::load();
     if (!($t_table = $o_dm->getInstanceByTableName($va_tmp[0], true))) {
         // bad table name
         print _t("Invalid table name");
         return null;
     }
     $t_element = new ca_metadata_elements();
     if (!$t_element->load(array('element_code' => $va_tmp[1]))) {
         print _t("Invalid element code");
         return null;
     }
     if ((int) $t_element->getSetting('suggestExistingValues') !== 1) {
         print _t("Value suggestion is not supported for this metadata element");
         return null;
     }
     if ($this->request->user->getBundleAccessLevel($va_tmp[0], $va_tmp[1]) == __CA_BUNDLE_ACCESS_NONE__) {
         print _t("You do not have access to this bundle");
         return null;
     }
     $va_type_restrictions = $t_element->getTypeRestrictions($t_table->tableNum());
     if (!$va_type_restrictions || !is_array($va_type_restrictions) || !sizeof($va_type_restrictions)) {
         print _t("Element code is not bound to the specified table");
         return null;
     }
     $o_db = new Db();
     switch ($t_element->getSetting('suggestExistingValueSort')) {
         case 'recent':
             // date/time entered
             $vs_sort_field = 'value_id DESC';
             $vn_max_returned_values = 10;
             break;
         default:
             // alphabetically
             $vs_sort_field = 'value_longtext1 ASC';
             $vn_max_returned_values = 50;
             break;
     }
     $qr_res = $o_db->query("\n\t\t\t\tSELECT DISTINCT value_longtext1\n\t\t\t\tFROM ca_attribute_values\n\t\t\t\tWHERE\n\t\t\t\t\telement_id = ?\n\t\t\t\t\tAND\n\t\t\t\t\t(value_longtext1 LIKE ?)\n\t\t\t\tORDER BY\n\t\t\t\t\t{$vs_sort_field}\n\t\t\t\tLIMIT {$vn_max_returned_values}\n\t\t\t", (int) $t_element->getPrimaryKey(), (string) $ps_query . '%');
     $this->view->setVar('attribute_value_list', $qr_res->getAllFieldValues('value_longtext1'));
     return $this->render('ajax_attribute_value_list_html.php');
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:46,代码来源:AttributeValueController.php

示例3: getElementAsDOM

 private function getElementAsDOM($pn_parent_id)
 {
     $t_element = new ca_metadata_elements();
     $t_list = new ca_lists();
     $qr_elements = $this->opo_db->query("SELECT * FROM ca_metadata_elements WHERE parent_id = ? ORDER BY element_id", $pn_parent_id);
     if (!$qr_elements->numRows()) {
         return null;
     }
     $vo_elements = $this->opo_dom->createElement("elements");
     while ($qr_elements->nextRow()) {
         $vo_element = $this->opo_dom->createElement("metadataElement");
         $vo_element->setAttribute("code", $this->makeIDNO($qr_elements->get("element_code")));
         $vo_element->setAttribute("datatype", ca_metadata_elements::getAttributeNameForTypeCode($qr_elements->get("datatype")));
         if ($qr_elements->get("list_id")) {
             $t_list->load($qr_elements->get("list_id"));
             $vo_element->setAttribute("list", $t_list->get("list_code"));
         }
         $vo_labels = $this->opo_dom->createElement("labels");
         $qr_element_labels = $this->opo_db->query("SELECT * FROM ca_metadata_element_labels WHERE element_id=?", $qr_elements->get("element_id"));
         while ($qr_element_labels->nextRow()) {
             $vo_label = $this->opo_dom->createElement("label");
             $vo_label->setAttribute("locale", $this->opt_locale->localeIDToCode($qr_element_labels->get("locale_id")));
             $vo_label->appendChild($this->opo_dom->createElement("name", caEscapeForXML($qr_element_labels->get("name"))));
             if (strlen(trim($qr_element_labels->get("description"))) > 0) {
                 $vo_label->appendChild($this->opo_dom->createElement("description", caEscapeForXML($qr_element_labels->get("description"))));
             }
             $vo_labels->appendChild($vo_label);
         }
         $vo_element->appendChild($vo_labels);
         $t_element->load($qr_elements->get("element_id"));
         $vo_settings = $this->opo_dom->createElement("settings");
         if (is_array($va_settings = $t_element->getSettings())) {
             foreach ($va_settings as $vs_setting => $va_values) {
                 if (is_null($va_values)) {
                     continue;
                 }
                 if (!is_array($va_values)) {
                     $va_values = array($va_values);
                 }
                 foreach ($va_values as $vs_value) {
                     $vo_setting = $this->opo_dom->createElement("setting", $vs_value);
                     $vo_setting->setAttribute("name", $vs_setting);
                     $vo_settings->appendChild($vo_setting);
                 }
             }
         }
         $vo_element->appendChild($vo_settings);
         $vo_sub_elements = $this->getElementAsDOM($qr_elements->get("element_id"));
         if ($vo_sub_elements) {
             $vo_element->appendChild($vo_sub_elements);
         }
         $vo_elements->appendChild($vo_element);
     }
     return $vo_elements;
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:55,代码来源:ConfigurationExporter.php

示例4: stabilizeElementRanks

 private function stabilizeElementRanks($pn_parent_id, $pa_ranks)
 {
     $vo_db = new Db();
     $t_element = new ca_metadata_elements();
     do {
         $va_ranks = array_keys($pa_ranks);
         $vn_rank = $va_ranks[0];
         $qr_res = $vo_db->query("\n\t\t\t\tSELECT * FROM\n\t\t\t\t\tca_metadata_elements\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t(parent_id=?)\n\t\t\t\t\t\tAND\n\t\t\t\t\t\t(rank>?)\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\trank\n\t\t\t", $pn_parent_id, $vn_rank);
         while ($qr_res->nextRow()) {
             $t_element->load($qr_res->get('element_id'));
             $t_element->set('rank', intval($t_element->get('rank')) + $pa_ranks[0]);
             $t_element->setMode(ACCESS_WRITE);
             $t_element->update();
         }
         $qr_res = $vo_db->query("\n\t\t\t\tSELECT * FROM\n\t\t\t\t\tca_metadata_elements\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t(parent_id=?)\n\t\t\t\t\t\tAND\n\t\t\t\t\t\t(rank=?)\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\trank\n\t\t\t", $pn_parent_id, $vn_rank);
         $i = 0;
         while ($qr_res->nextRow()) {
             $i++;
             $t_element->load($qr_res->get('element_id'));
             $t_element->set('rank', intval($t_element->get('rank')) + $i);
             $t_element->setMode(ACCESS_WRITE);
             $t_element->update();
         }
         $pa_ranks = $this->elementRankStabilizationNeeded($pn_parent_id);
     } while (is_array($pa_ranks));
 }
开发者ID:samrahman,项目名称:providence,代码行数:26,代码来源:ElementsController.php

示例5: search

 protected function search($pa_bundles = null)
 {
     $va_return = parent::search($pa_bundles);
     if ($this->getTableName() == 'ca_entities' && is_array($va_return['results']) && sizeof($va_return['results']) > 0) {
         $o_db = new Db();
         $t_element = new ca_metadata_elements();
         $t_element->load(array('element_code' => 'is_index_display'));
         $vn_element_id = $t_element->getPrimaryKey();
         if (!$vn_element_id) {
             return $va_return;
         }
         $vn_yes_id = caGetListItemID('yn', 'yes');
         foreach ($va_return['results'] as &$va_result) {
             $vn_entity_id = $va_result['entity_id'];
             $qr_objects = $o_db->query("\n\t\t\t\t\tSELECT DISTINCT ca_objects.object_id FROM ca_entities, ca_objects_x_entities, ca_objects, ca_attributes, ca_attribute_values\n\t\t\t\t\tWHERE ca_entities.entity_id = ca_objects_x_entities.entity_id\n\t\t\t\t\tAND ca_attributes.row_id = ca_objects.object_id\n\t\t\t\t\tAND ca_attribute_values.attribute_id = ca_attributes.attribute_id\n\t\t\t\t\tAND ca_objects_x_entities.object_id = ca_objects.object_id\n\t\t\t\t\tAND ca_attribute_values.element_id = ?\n\t\t\t\t\tAND ca_entities.entity_id = ?\n\t\t\t\t\tAND ca_attribute_values.item_id = ?\n\t\t\t\t\tAND ca_objects.deleted = 0\n\t\t\t\t", $vn_element_id, $vn_entity_id, $vn_yes_id);
             while ($qr_objects->nextRow()) {
                 $va_object_info = array();
                 $vn_object_id = $qr_objects->get('ca_objects.object_id');
                 if (MemoryCache::contains($vn_object_id, 'AboutDrawingServices')) {
                     $va_object_info = MemoryCache::fetch($vn_object_id, 'AboutDrawingServices');
                 } else {
                     $va_object_info['object_id'] = $vn_object_id;
                     $qr_labels = $o_db->query("\n\t\t\t\t\t\t\tSELECT ca_object_labels.* FROM ca_object_labels, ca_objects\n\t\t\t\t\t\t\tWHERE ca_object_labels.object_id = ca_objects.object_id\n\t\t\t\t\t\t\tAND ca_objects.object_id = ?\n\t\t\t\t\t\t", $vn_object_id);
                     $vs_label = '';
                     while ($qr_labels->nextRow()) {
                         $va_object_info['labels'][] = $qr_labels->getRow();
                         $vs_label = $qr_labels->get('name');
                         // keep the last label around
                     }
                     $va_object_info['label'] = $vs_label;
                     $qr_reps = $o_db->query("\n\t\t\t\t\t\t\tSELECT ca_object_representations.* FROM ca_object_representations, ca_objects_x_object_representations, ca_objects\n\t\t\t\t\t\t\tWHERE ca_object_representations.representation_id = ca_objects_x_object_representations.representation_id\n\t\t\t\t\t\t\tAND ca_objects_x_object_representations.object_id = ca_objects.object_id\n\t\t\t\t\t\t\tAND ca_objects.object_id = ?\n\t\t\t\t\t\t\tAND ca_objects.deleted = 0 AND ca_object_representations.deleted = 0\n\t\t\t\t\t\t", $vn_object_id);
                     while ($qr_reps->nextRow()) {
                         $va_object_info['representations'][] = array('representation_id' => $qr_reps->get('representation_id'), 'icon' => $qr_reps->getMediaUrl('media', 'icon'), 'preview170' => $qr_reps->getMediaUrl('media', 'preview170'), 'medium' => $qr_reps->getMediaUrl('media', 'medium'), 'original' => $qr_reps->getMediaUrl('media', 'original'));
                     }
                     MemoryCache::save($vn_object_id, $va_object_info, 'AboutDrawingServices');
                 }
                 $va_result['ca_objects'][] = $va_object_info;
             }
             /* the old&simple, but very slow code
             				$t_entity = new ca_entities($va_result['entity_id']);
             				$va_objects = $t_entity->getRelatedItems('ca_objects');
             
             				foreach($va_objects as $va_object) {
             					$t_object = new ca_objects($va_object['object_id']);
             					$va_reps = $t_object->getRepresentations(array('icon', 'preview170', 'medium', 'original'));
             					$va_representation_info = array();
             					foreach($va_reps as $va_rep) {
             						$va_representation_info[] = array(
             							'representation_id' => $va_rep['representation_id'],
             							'urls' => $va_rep['urls'],
             						);
             					}
             
             					$va_object_info = array();
             					$va_object_info['object_id'] = $va_object['object_id'];
             					$va_object_info['labels'] = $va_object['labels'];
             					$va_object_info['label'] = $va_object['label'];
             					$va_object_info['representations'] = $va_representation_info;
             
             					$va_result['ca_objects'][] = $va_object_info;
             				}*/
         }
     }
     return $va_return;
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:65,代码来源:AboutDrawingSearchService.php

示例6: 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

示例7: _doQueriesForSqlSearch


//.........这里部分代码省略.........
                                         }
                                         $va_ft_stem_terms[] = "'" . $this->opo_db->escape($vs_stem) . "'";
                                     } else {
                                         $va_ft_terms[] = '"' . $this->opo_db->escape($vs_term) . '"';
                                     }
                                 } else {
                                     $va_ft_terms[] = '"' . $this->opo_db->escape($vs_term) . '"';
                                 }
                                 $vb_output_term = true;
                             }
                         }
                         if ($vb_output_term) {
                             $va_raw_terms[] = $vs_term;
                         } else {
                             $vn_i--;
                         }
                         break;
                 }
                 $vs_fld_num = $vs_table_num = $t_table = null;
                 $vb_ft_bit_optimization = false;
                 if ($vs_access_point) {
                     list($vs_table, $vs_field, $vs_sub_field) = explode('.', $vs_access_point);
                     if (in_array($vs_table, array('created', 'modified'))) {
                         $o_tep = new TimeExpressionParser();
                         $vs_date = join(' ', $va_raw_terms);
                         if (!$o_tep->parse($vs_date)) {
                             break;
                         }
                         $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) {
开发者ID:guaykuru,项目名称:pawtucket,代码行数:67,代码来源:SqlSearch.php

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

示例9: 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

示例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: _getElementInstance

 public function _getElementInstance($pm_element_code_or_id)
 {
     if (!$pm_element_code_or_id) {
         $this->postError(1950, _t("Element code or id must not be blank"), "BaseModelWithAttributes->_getElementInstance()");
         return false;
     }
     if (isset(BaseModelWithAttributes::$s_element_instance_cache[$pm_element_code_or_id]) && BaseModelWithAttributes::$s_element_instance_cache[$pm_element_code_or_id]) {
         return BaseModelWithAttributes::$s_element_instance_cache[$pm_element_code_or_id];
     }
     require_once __CA_APP_DIR__ . '/models/ca_metadata_elements.php';
     $t_element = new ca_metadata_elements();
     if (!is_numeric($pm_element_code_or_id)) {
         if ($t_element->load(array('element_code' => $pm_element_code_or_id))) {
             return BaseModelWithAttributes::$s_element_instance_cache[$pm_element_code_or_id] = $t_element;
         }
     }
     if ($t_element->load($pm_element_code_or_id)) {
         return BaseModelWithAttributes::$s_element_instance_cache[$pm_element_code_or_id] = $t_element;
     } else {
         //$this->postError(1950, _t("Element code or id '%1' is invalid", $pm_element_code_or_id), "BaseModelWithAttributes->_getElementInstance()");
         return false;
     }
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:23,代码来源:BaseModelWithAttributes.php

示例12: search

 public function search($pn_subject_tablenum, $ps_search_expression, $pa_filters = array(), $po_rewritten_query = null)
 {
     $t = new Timer();
     $va_solr_search_filters = array();
     $vn_i = 0;
     $va_old_signs = $po_rewritten_query->getSigns();
     $va_terms = $va_signs = array();
     foreach ($po_rewritten_query->getSubqueries() as $o_lucene_query_element) {
         if (!$va_old_signs || !is_array($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';
         }
         switch ($vs_class = get_class($o_lucene_query_element)) {
             case 'Zend_Search_Lucene_Search_Query_Term':
             case 'Zend_Search_Lucene_Search_Query_MultiTerm':
             case 'Zend_Search_Lucene_Search_Query_Phrase':
                 if ($vs_class != 'Zend_Search_Lucene_Search_Query_Term') {
                     $va_raw_terms = array();
                     foreach ($o_lucene_query_element->getQueryTerms() as $o_term) {
                         if (!$vs_access_point && ($vs_field = $o_term->field)) {
                             $vs_access_point = $vs_field;
                         }
                         $va_raw_terms[] = $vs_text = (string) $o_term->text;
                     }
                     $vs_term = join(" ", $va_raw_terms);
                 } else {
                     $vs_access_point = $o_lucene_query_element->getTerm()->field;
                     $vs_term = $o_lucene_query_element->getTerm()->text;
                 }
                 if ($vs_access_point) {
                     list($vs_table, $vs_field, $vs_sub_field) = explode('.', $vs_access_point);
                     if (in_array($vs_table, array('created', 'modified'))) {
                         if (!$this->opo_tep->parse($vs_term)) {
                             break;
                         }
                         $va_range = $this->opo_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':
                                 if ($vn_user_id) {
                                     $o_lucene_query_element = new Zend_Search_Lucene_Search_Query_Boolean(array(new Zend_Search_Lucene_Index_Term('[' . $this->opo_tep->getText(array('start_as_iso8601' => true)) . " TO " . $this->opo_tep->getText(array('end_as_iso8601' => true)) . ']', 'created'), new Zend_Search_Lucene_Index_Term($vn_user_id, 'created_user_id')), array(true, true));
                                 } else {
                                     $o_lucene_query_element = new Zend_Search_Lucene_Search_Query_Term(new Zend_Search_Lucene_Index_Term('[' . $this->opo_tep->getText(array('start_as_iso8601' => true)) . " TO " . $this->opo_tep->getText(array('end_as_iso8601' => true)) . ']', 'created'));
                                 }
                                 break;
                             case 'modified':
                                 if ($vn_user_id) {
                                     $o_lucene_query_element = new Zend_Search_Lucene_Search_Query_Boolean(array(new Zend_Search_Lucene_Index_Term('[' . $this->opo_tep->getText(array('start_as_iso8601' => true)) . " TO " . $this->opo_tep->getText(array('end_as_iso8601' => true)) . ']', 'modified'), new Zend_Search_Lucene_Index_Term($vn_user_id, 'modified_user_id')), array(true, true));
                                 } else {
                                     $o_lucene_query_element = new Zend_Search_Lucene_Search_Query_Term(new Zend_Search_Lucene_Index_Term('[' . $this->opo_tep->getText(array('start_as_iso8601' => true)) . " TO " . $this->opo_tep->getText(array('end_as_iso8601' => true)) . ']', 'modified'));
                                 }
                                 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 = $vs_field;
                                 } else {
                                     $vs_fld_num = $this->opo_datamodel->getFieldNum($vs_table, $vs_field);
                                     if (!$vs_fld_num) {
                                         $t_element = new ca_metadata_elements();
                                         if ($t_element->load(array('element_code' => $vs_sub_field ? $vs_sub_field : $vs_field))) {
                                             $vs_fld_num = $t_element->getPrimaryKey();
                                             //
                                             // 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_exact = $vs_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) {
//.........这里部分代码省略.........
开发者ID:guaykuru,项目名称:pawtucket,代码行数:101,代码来源:ElasticSearch.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: getInstance

 /**
  * 
  */
 public static function getInstance($pm_element_code_or_id)
 {
     if (!$pm_element_code_or_id) {
         return null;
     }
     if (MemoryCache::contains($pm_element_code_or_id, 'ElementInstances')) {
         return MemoryCache::fetch($pm_element_code_or_id, 'ElementInstances');
     }
     $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))) {
             MemoryCache::save($t_element->getPrimaryKey(), $t_element, 'ElementInstances');
             MemoryCache::save($t_element->get('element_code'), $t_element, 'ElementInstances');
             return $t_element;
         }
     } else {
         MemoryCache::save($vn_element_id, $t_element, 'ElementInstances');
         MemoryCache::save($t_element->get('element_code'), $t_element, 'ElementInstances');
         return $t_element;
     }
     return null;
 }
开发者ID:kai-iak,项目名称:pawtucket2,代码行数:25,代码来源:ca_metadata_elements.php

示例15: 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


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