public function section() { if ($this->_section === NULL) { $this->_section = Datasource_Data_Manager::load($this->from_ds); } return $this->_section; }
/** * * @return array [$archive] */ public function fetch_data() { $datasource = Datasource_Data_Manager::load($this->ds_id); if ($datasource === NULL) { return array(); } $is_system = TRUE; if ($this->date_field == 'created_on') { $field = 'd.' . $this->date_field; } else { $field = 'ds.' . $this->date_field; $is_system = FALSE; } switch ($this->archive_type) { case 'day': $type = '%Y/%m/%d'; break; case 'year': $type = '%Y'; break; default: $type = '%Y/%m'; } $query = DB::select(array(DB::expr('DATE_FORMAT(' . Database::instance()->quote_column($field) . ', "' . $type . '")'), 'date'))->select(array(DB::expr('COUNT(*)'), 'total'))->distinct(TRUE)->from(array('dshybrid', 'd'))->where('d.published', '=', 1)->where('d.ds_id', '=', $this->ds_id)->group_by('date')->order_by($field, $this->order_by == 'asc' ? 'asc' : 'desc'); if ($is_system === FALSE) { $query->join(array('dshybrid_' . $this->ds_id, 'ds'))->on('ds.id', '=', 'd.id'); } $result = $query->execute()->as_array(); return array('archive' => $result); }
public function create() { parent::create(); if (!$this->id) { return FALSE; } $ds = Datasource_Data_Manager::load($this->from_ds); $this->update(); return $this->id; }
public function set(array $data) { if (!empty($data['from_ds'])) { $section = Datasource_Data_Manager::load($data['from_ds']); if ($section !== NULL) { $data['ds_type'] = $section->type(); } } return parent::set($data); }
public function post_repair() { $field = $this->_get_field(); if (!DataSource_Hybrid_Field_Factory::is_column_exists($field)) { $ds = Datasource_Data_Manager::load($field->ds_id); if (!$ds->loaded()) { throw HTTP_API_Exception::factory(API::ERROR_UNKNOWN, 'Datasource section :id not found', array(':id' => $field->ds_id)); } DataSource_Hybrid_Field_Factory::create_field($ds->record(), $field); $this->message('Field ":field" repaired', array(':field' => $field->header)); $this->response(TRUE); } }
public function sections() { $options = Datasource_Data_Manager::get_all_as_options('hybrid'); foreach ($options as $id => $name) { $ds = Datasource_Data_Manager::load($id); if ($ds === NULL) { continue; } if (!in_array('profile_id', $ds->agent()->get_field_names())) { unset($options[$id]); } } return $options; }
public function get_doc_fields() { $fields = array(); if (!$this->ds_id) { return $fields; } $datasource = Datasource_Data_Manager::load($this->ds_id); if ($datasource !== NULL) { foreach ($datasource->record()->fields() as $field) { if ($field instanceof DataSource_Hybrid_Field_Source_Tags) { $fields[$field->id] = $field->header; } } } return $fields; }
/** * * @param integer $id * @return DataSource_Section * @throws HTTP_Exception_404 */ public function section($id = NULL) { if ($this->_section instanceof DataSource_Section) { return $this->_section; } if ($id === NULL) { Messages::errors(__('Datasource section not loaded')); $this->go_home(); } $this->_section = Datasource_Data_Manager::load((int) $id); if ($this->request->action() == 'index' and !$this->_section->has_access_view()) { $this->_deny_access(); } if (empty($this->_section)) { Messages::errors(__('Datasource section :id not found', array(':id' => $id))); $this->go_home(); } return $this->_section; }
public function get_find() { $query = $this->param('key', NULL); $ids = $this->param('ids', array()); $doc_id = $this->param('id', NULL); $is_array = $this->param('is_array', FALSE); $ds_id = (int) $this->param('doc_ds', NULL, TRUE); $this->request->query('keyword', $query); $ds = Datasource_Data_Manager::load($ds_id); $documents = $ds->headline()->get($ids); $response = array(); if ($is_array === FALSE) { $response[] = array('id' => 0, 'text' => __('--- Not set ---')); } foreach ($documents['documents'] as $id => $data) { if ($doc_id != $id) { $response[] = array('id' => $id, 'text' => $data['header']); } } $this->response($response); }
/** * * @return array [$fields, $datasource, $document] */ public function fetch_data() { $datasource = Datasource_Data_Manager::load($this->ds_id); if ($datasource === NULL) { return array(); } $id = $this->get_doc_id(); if (empty($id)) { $document = $datasource->get_empty_document(); } else { $document = $datasource->get_document($id); if (!$document) { if ($this->throw_404) { $this->_ctx->throw_404(); } $document = $datasource->get_empty_document(); } } View::set_global(array('form' => array('label_class' => 'control-label col-md-2 col-sm-3', 'input_container_class' => 'col-md-10 col-lg-10 col-sm-9', 'input_container_offset_class' => 'col-md-offset-2 col-sm-offset-3 col-md-10 col-sm-9'))); return array('fields' => $datasource->record()->fields(), 'datasource' => $datasource, 'document' => $document); }
/** * @deprecated since 10.0.0 * * @param integer $ds_id * @return Datasource_Section */ public static function load_ds($ds_id) { return Datasource_Data_Manager::load($ds_id); }
if (empty($folder['sections'])) { continue; } $folder_section = Model_Navigation::get_section($folder['name'], $ds_section); foreach ($folder['sections'] as $id => $section) { $section->add_to_menu($folder_section); } } foreach ($sections_list as $type => $sections) { foreach ($sections as $id => $section) { $section->add_to_menu($ds_section); } } $_create_section = Model_Navigation::get_section(__('Create section'), $ds_section, 999); foreach ($types as $id => $type) { $_create_section->add_page(new Model_Navigation_Page(array('name' => $type, 'url' => Route::get('datasources')->uri(array('controller' => 'section', 'directory' => 'datasources', 'action' => 'create', 'id' => $id)), 'permissions' => $id . '.section.create'))); } unset($sections_list, $folders, $root_section); } catch (Exception $ex) { } }); Observer::observe('update_search_index', function () { $ds_ids = Datasource_Data_Manager::get_all(); foreach ($ds_ids as $ds_id => $data) { $ds = Datasource_Data_Manager::load($ds_id); if (!$ds->loaded()) { continue; } $ds->update_index(); } });
/** * Опубликовать или снять с публикации документы раздела по ID * * @param array $ids * @param boolean $value * @return \DataSource_Hybrid_Factory */ public function set_published(array $ids, $value) { if (empty($ids)) { return $this; } $res = DB::select('dsh.id', 'dsh.ds_id')->from(array('dshybrid', 'dsh'))->join(array('datasources', 'dss'), 'left')->on('dsh.ds_id', '=', 'dss.id')->where('dsh.id', 'in', $ids)->execute(); $docs = array(); foreach ($res as $row) { $docs[$row['ds_id']][] = $row['id']; } if (!empty($docs)) { $ds_ids = array_keys($docs); foreach ($ds_ids as $ds_id) { $ds = Datasource_Data_Manager::load($ds_id); $ids = $docs[$ds_id]; if ($value === TRUE) { $ds->add_to_index($ids); } else { $ds->remove_from_index($ids); } DB::update('dshybrid')->set(array('published' => (int) $value, 'updated_on' => date('Y-m-d H:i:s')))->where('ds_id', '=', $ds_id)->where('id', 'in', $ids)->execute(); unset($ds, $ids, $docs); Datasource_Data_Manager::clear_cache($ds_id, self::$widget_types); } } return $this; }
<?php defined('SYSPATH') or die('No direct access allowed.'); $datasources = Datasource_Data_Manager::get_all('hybrid'); foreach ($datasources as $id => $ds) { $datasource = Datasource_Data_Manager::load($id); if ($datasource->loaded()) { $datasource->remove(); } }
/** * * @param array $data * @return null|integer */ protected function _handle_document($data, Validation $external_validation = NULL) { $ds = Datasource_Data_Manager::load($this->ds_id); $create = TRUE; if (empty($data['id']) or $this->disable_update === TRUE) { $document = $ds->get_empty_document(); } else { $id = (int) $data['id']; $document = $ds->get_document($id); $create = FALSE; if (!$document->loaded()) { $this->_errors = __('Document ID :id not found', array(':id' => $id)); return NULL; } } try { if ($this->auto_publish === TRUE and !isset($data['published'])) { $data['published'] = TRUE; } $document->read_values($data, $this->doc_fields)->read_files($data)->validate($external_validation, $this->doc_fields); if ($create === TRUE) { $ds->create_document($document); } else { $ds->update_document($document); } $this->handle_email_type($data); $this->status = TRUE; return $document->id; } catch (Validation_Exception $e) { $this->_errors = $e->errors('validation'); return NULL; } catch (DataSource_Exception_Document $e) { $this->_errors = $e->getMessage(); return NULL; } }