Пример #1
0
 public function action_index()
 {
     Assets::package('jquery-ui');
     $cur_ds_id = (int) Arr::get($this->request->query(), 'ds_id', Cookie::get('ds_id'));
     $tree = Datasource_Data_Manager::get_tree();
     $cur_ds_id = Datasource_Data_Manager::exists($cur_ds_id) ? $cur_ds_id : Datasource_Data_Manager::$first_section;
     $ds = $this->section($cur_ds_id);
     $this->template->content = View::factory('datasource/content', array('content' => View::factory('datasource/data/index'), 'menu' => View::factory('datasource/data/menu', array('tree' => $tree, 'folders' => Datasource_Folder::get_all()))));
     $this->template->footer = NULL;
     $this->template->breadcrumbs = NULL;
     if ($ds instanceof Datasource_Section) {
         $this->set_title($ds->name);
         $limit = (int) Arr::get($this->request->query(), 'limit', Cookie::get('limit'));
         Cookie::set('ds_id', $cur_ds_id);
         $keyword = $this->request->query('keyword');
         if (!empty($limit)) {
             Cookie::set('limit', $limit);
             $this->section()->headline()->limit($limit);
         }
         $this->template->content->content->headline = $this->section()->headline()->render();
         $this->template->content->content->toolbar = View::factory('datasource/' . $ds->type() . '/toolbar', array('keyword' => $keyword));
         $this->template->set_global(array('datasource' => $ds));
         $this->template_js_params['DS_ID'] = $this->_section->id();
         $this->template_js_params['DS_TYPE'] = $this->_section->type();
     } else {
         $this->template->content->content = NULL;
     }
 }
Пример #2
0
 public function section()
 {
     if ($this->_section === NULL) {
         $this->_section = Datasource_Data_Manager::load($this->from_ds);
     }
     return $this->_section;
 }
Пример #3
0
 /**
  * 
  * @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);
 }
Пример #4
0
 public function get_menu()
 {
     $ds_id = (int) $this->param('ds_id', NULL);
     $tree = Datasource_Data_Manager::get_tree();
     $menu = View::factory('datasource/data/menu', array('tree' => $tree, 'folders' => Datasource_Folder::get_all(), 'datasource' => DataSource_Section::load($ds_id)));
     $this->response((string) $menu);
 }
Пример #5
0
 /**
  * 
  * @return array
  */
 public function sources()
 {
     $sources_list = Datasource_Data_Manager::get_all();
     $sources = array();
     foreach ($sources_list as $id => $source) {
         $sources[$id] = $source->name;
     }
     return $sources;
 }
Пример #6
0
 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);
 }
Пример #7
0
 public function create()
 {
     parent::create();
     if (!$this->id) {
         return FALSE;
     }
     $ds = Datasource_Data_Manager::load($this->from_ds);
     $this->update();
     return $this->id;
 }
Пример #8
0
 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);
     }
 }
Пример #9
0
 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;
 }
Пример #10
0
 /**
  * Загрузить дерево всех разделов
  * Если есть разделы, модули для которых отключены, они будут игнорироваться
  * 
  * @return array array([Type][ID] => Datasource_Section)
  */
 public static function get_tree($type = NULL)
 {
     $result = array();
     $sections = self::get_all($type);
     foreach ($sections as $section) {
         if (!Datasource_Section::exists($section->type())) {
             continue;
         }
         if (self::$first_section === NULL) {
             self::$first_section = $section->id();
         }
         $result[$section->type()][$section->id()] = $section;
     }
     return $result;
 }
Пример #11
0
 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;
 }
Пример #12
0
 public function action_create()
 {
     $type = $this->request->param('id');
     $type = strtolower($type);
     $types = Datasource_Data_Manager::types();
     if (Arr::get($types, $type) === NULL) {
         throw new Kohana_Exception('Datasource type :type not found', array(':type' => $type));
     }
     if ($this->request->method() === Request::POST) {
         return $this->_create($type);
     }
     $this->set_title(__('Add section :type', array(':type' => Arr::get($types, $type))));
     try {
         $this->template->content = View::factory('datasource/' . $type . '/section/create', array('type' => $type, 'data' => Flash::get('post_data'), 'users' => ORM::factory('user')->find_all()->as_array('id', 'username')));
     } catch (Exception $exc) {
         $this->template->content = View::factory('datasource/section/create', array('type' => $type, 'data' => Flash::get('post_data'), 'users' => ORM::factory('user')->find_all()->as_array('id', 'username')));
     }
 }
Пример #13
0
 /**
  * 
  * @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;
 }
Пример #14
0
 /**
  * 
  * @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);
 }
Пример #15
0
 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);
 }
Пример #16
0
            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();
    }
});
Пример #17
0
	<div class="sections-list">
	<?php 
if (!empty($tree)) {
    ?>
		<?php 
    foreach ($tree as $type => $data) {
        ?>
		<?php 
        if (empty($data)) {
            continue;
        }
        ?>

		<div class="mail-nav-header" data-type="section" data-icon="<?php 
        echo Datasource_Data_Manager::get_icon($type);
        ?>
">
			<?php 
        echo __(ucfirst($type));
        ?>
		</div>
		<ul class="sections">
		<?php 
        foreach ($data as $id => $section) {
            ?>
			<?php 
            echo recurse_menu($id, $section, $datasource->id());
            ?>
		<?php 
        }
Пример #18
0
	<div class="panel-footer">
		<?php 
    if (ACL::check($section->has_access('document.create', TRUE))) {
        ?>
		<?php 
        echo UI::button(__('Create Document'), array('href' => Route::get('datasources')->uri(array('controller' => 'document', 'directory' => $section->type(), 'action' => 'create')) . URL::query(array('ds_id' => $section->id())), 'icon' => UI::icon('plus')));
        ?>
		<?php 
    }
    ?>
		
		<?php 
    if (ACL::check($section->has_access_view())) {
        ?>
		<?php 
        echo UI::button(__('Goto section'), array('href' => Route::get('datasources')->uri(array('controller' => 'data', 'directory' => 'datasources')) . URL::query(array('ds_id' => $section->id())), 'icon' => UI::icon(Datasource_Data_Manager::get_icon($section->type())), 'class' => 'btn-xs btn-inverse'));
        ?>
		<?php 
    }
    ?>
	</div>
	<?php 
} else {
    ?>
	<div class="note note-warning">
		<?php 
    echo UI::icon('lightbulb-o fa-lg');
    ?>
 <?php 
    echo __('You need select hybrid section');
    ?>
Пример #19
0
 public function fetch_backend_content()
 {
     if ($this->ds_id > 0 and !Datasource_Data_Manager::exists($this->ds_id)) {
         $this->ds_id = 0;
         Widget_Manager::update($this);
     }
     return parent::fetch_backend_content();
 }
Пример #20
0
 /**
  * Опубликовать или снять с публикации документы раздела по 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;
 }
Пример #21
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
$perms = array();
foreach (Datasource_Data_Manager::get_all() as $id => $section) {
    $actions = $section->acl_actions();
    $actions['title'] = __('Datasource :name', array(':name' => $section->name));
    $perms['ds_id.' . $id] = $actions;
}
foreach (Datasource_Data_Manager::types() as $type => $title) {
    $perms[$type . '.section'] = array('title' => 'Datasource', array('action' => 'create', 'description' => 'Create ' . $type . ' section'));
}
return $perms;
Пример #22
0
 protected function _get_sections()
 {
     $map = Datasource_Data_Manager::get_tree();
     $hds = Datasource_Data_Manager::get_all('hybrid');
     $sections = array();
     foreach (Datasource_Data_Manager::types() as $key => $value) {
         if ($key != 'hybrid' and !empty($map[$key])) {
             foreach ($map[$key] as $id => $section) {
                 $sections[$key][$id] = $section->name;
             }
         } else {
             foreach ($hds as $id => $section) {
                 $sections[$key][$id] = $section->name;
             }
         }
     }
     return $sections;
 }
Пример #23
0
<div class="form-group">
	<label class="control-label col-md-3" for="array_type"><?php 
echo __('Datasource');
?>
</label>
	<div class="col-md-9">
		<?php 
echo Form::select('from_ds', Datasource_Data_Manager::get_all_as_options('hybrid'), $field->from_ds);
?>
	</div>
</div>

<hr />

<div class="form-group">
	<div class="col-md-offset-3 col-md-9">
		<div class="checkbox">
			<label>
				<?php 
echo Form::checkbox('one_to_many', 1, $field->one_to_many == 1, array('id' => 'one_to_many'));
?>
				<?php 
echo __('Remove the related documents when deleting a document');
?>
			</label>
		</div>
	</div>
</div>
Пример #24
0
<?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();
    }
}
Пример #25
0
 /**
  * Очистка кеша виджетов раздела
  * 
  * @return \Datasource_Section
  */
 public function clear_cache()
 {
     Datasource_Data_Manager::clear_cache($this->id(), $this->_widget_types);
     return $this;
 }
Пример #26
0
 /**
  * @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);
 }
Пример #27
0
<div class="panel-body">
	<div class="form-group">
		<label class="control-label col-md-3" for="ds_id"><?php 
echo __('Hybrid section');
?>
</label>
		<div class="col-md-3">
			<?php 
echo Form::select('ds_id', Datasource_Data_Manager::get_all_as_options('hybrid'), $widget->ds_id, array('id' => 'ds_id'));
?>
		</div>
	</div>
</div>