/** * * @return Database_Query_Builder */ protected function _get_query() { $agent = DataSource_Hybrid_Agent::instance($this->ds_id); if ($this->sort_by_rand === TRUE) { $this->doc_order = NULL; } $query = $agent->get_query_props($this->doc_fields, $this->doc_order, $this->doc_filter); $query = $this->_search_by_keyword($query); if ($this->sort_by_rand === TRUE) { $query->order_by(DB::expr('RAND()')); } if (is_array($this->ids) and count($this->ids) > 0) { $query->where('d.id', 'in', $this->ids); } if ($this->only_published === TRUE) { $query->where('d.published', '=', 1); } $query->limit($this->list_size); $query->offset($this->list_offset); return $query; }
/** * * @param integer $id * @return array */ public function get_document($id = NULL, $recurse = 3) { $result = array(); if ($id === NULL) { $id = $this->get_doc_id(); } if (empty($id)) { return $result; } if (isset(Model_Widget_Hybrid_Document::$_cached_documents[$id])) { return Model_Widget_Hybrid_Document::$_cached_documents[$id]; } $agent = DataSource_Hybrid_Agent::instance($this->ds_id); $result = $agent->get_document($id, $this->doc_fields, $this->doc_id_field); if (empty($result)) { return $result; } $hybrid_fields = $agent->get_fields(); foreach ($result as $key => $value) { if (!isset($hybrid_fields[$key])) { continue; } $field =& $hybrid_fields[$key]; $field_class_method = 'fetch_widget_field'; $result['_' . $field->key] = $result[$key]; if (method_exists($field, $field_class_method)) { $result[$field->key] = $field->{$field_class_method}($this, $field, $result, $key, $recurse - 1); } else { $result[$field->key] = $result[$key]; } unset($result[$key]); } Model_Widget_Hybrid_Document::$_cached_documents[$id] = $result; return $result; }
/** * Загрузка документов раздела в формате для индексации * * В этом методе происходит загрукзка индексируемых полей документа * + поля описания документа * * @param array $id * @return array array([ID] => array('id', 'header', 'content', 'intro', ....), ...) */ public function get_indexable_documents(array $id = NULL) { $result = array(); if (!empty($this->search_intro_field)) { $this->search_index_fields[] = $this->search_intro_field; } $this->search_index_fields = array_unique($this->search_index_fields); $fields = $this->search_index_fields; if (!empty($this->search_index_doc_id_fields)) { foreach ($this->search_index_doc_id_fields as $field) { $fields[] = $field; } } $agent = DataSource_Hybrid_Agent::instance($this->id(), $this->id()); $query = $agent->get_query_props(array_unique($fields)); if (is_array($id) and !empty($id)) { $query->where('d.id', 'in', $id); } else { if (!empty($id)) { $query->where('d.id', '=', (int) $id); } } $rows = $query->execute()->as_array(); foreach ($rows as $row) { $doc_id = $row['id']; $result[$doc_id] = array('id' => $row['id'], 'intro' => Arr::get($row, $this->search_intro_field), 'header' => $row['header']); $content = ''; $params = array(); foreach ($this->search_index_fields as $field) { $content .= ' ' . (string) Arr::get($row, $field); } foreach ($this->search_index_doc_id_fields as $field) { $field_name = DataSource_Hybrid_Field_Factory::get_field_key($field); if (empty($field_name)) { continue; } $params[$field_name] = Arr::get($row, $field); } $result[$doc_id]['content'] = $content; $result[$doc_id]['params'] = $params; } return $result; }
/** * * @return Database_Query_Builder */ protected function _get_query() { $agent = DataSource_Hybrid_Agent::instance($this->ds_id); $query = $agent->get_query_props($this->doc_fields, $this->doc_order, $this->doc_filter); if ($this->only_published === TRUE) { $query->where('d.published', '=', 1); } $query->limit($this->list_size); $query->offset($this->list_offset); return $query; }
public function count_total(array $ids = NULL) { $agent = DataSource_Hybrid_Agent::instance($this->_section->id()); $query = $this->_section->agent()->get_query_props(FALSE, $this->_sorting); $query = $this->search_by_keyword($query); if (!empty($ids)) { $query->where('d.id', 'in', $ids); } return $query->execute()->get('total_docs'); }
public function get_profile($user_id) { $ds_id = (int) Plugins::setting('hybrid', 'user_profile_ds_id'); $profile = NULL; if (!empty($ds_id) and ($agent = DataSource_Hybrid_Agent::instance($ds_id)) !== NULL) { $fields = $agent->get_fields(); $fid = NULL; foreach ($fields as $field) { if ($field->key == 'profile_id') { $fid = $field->id; break; } } $profile = $agent->get_document((int) $user_id, $this->doc_fields, $fid); $recurse = 3; if (!empty($profile)) { $hybrid_fields = $agent->get_fields(); foreach ($profile as $key => $value) { if (!isset($hybrid_fields[$key])) { continue; } $field =& $hybrid_fields[$key]; $profile['_' . $field->key] = $profile[$key]; $profile[$field->key] = $field->fetch_widget_field($this, $field, $profile, $key, $recurse); unset($profile[$key]); } } } return $profile; }