Esempio n. 1
0
 /**
  * Добавление раздела в меню Backend
  * 
  * @param Datasource_Section $section
  * @param Model_Navigation_Section $parent_section
  * return Model_Navigation_Section;
  */
 public static function add_section_to_menu(Datasource_Section $section, Model_Navigation_Section $parent_section = NULL)
 {
     if ($parent_section === NULL) {
         $parent_section = Model_Navigation::get_root_section();
     }
     if (!$section->has_access_view()) {
         return $parent_section;
     }
     return $parent_section->add_page(new Model_Navigation_Page(array('name' => $section->name, 'url' => Route::get('datasources')->uri(array('controller' => 'data', 'directory' => 'datasources')) . URL::query(array('ds_id' => $section->id())), 'icon' => $section->icon(), 'permissions' => 'ds_id.' . $section->id() . '.section.view')), 999);
 }
Esempio n. 2
0
 /**
  * Метод используется для поиска по документам по ключевому слову.
  * 
  * Ключевое слово передается в качестве $_GET запроса с ключем "keyword"
  * 
  * @param Database_Query $query
  * @return Database_Query
  */
 public function search_by_keyword(Database_Query $query)
 {
     $keyword = Request::initial()->query('keyword');
     if (empty($keyword)) {
         return $query;
     }
     if ($this->_section->is_indexable()) {
         $ids = Search::instance()->find_by_keyword($keyword, FALSE, 'ds_' . $this->_section->id(), NULL);
         $ids = Arr::get($ids, 'ds_' . $this->_section->id());
         if (!empty($ids)) {
             $query->where('d.id', 'in', array_keys($ids));
         } else {
             $query->where('d.id', '=', 0);
         }
     } else {
         $query->where_open()->where('d.id', 'like', '%' . $keyword . '%')->or_where('d.header', 'like', '%' . $keyword . '%')->where_close();
     }
     return $query;
 }
Esempio n. 3
0
 /**
  * 
  * @param Datasource_Document $datasource
  */
 public function __construct(Datasource_Section $datasource)
 {
     $this->_datasource = $datasource;
     $this->_ds_id = (int) $datasource->id();
     $this->load();
 }
Esempio n. 4
0
 /**
  * 
  * @param Datasource_Section $ds
  */
 private function _edit($ds)
 {
     $data = $this->request->post();
     try {
         $ds->values($data);
         $ds->update();
     } catch (Validation_Exception $e) {
         Messages::errors($e->errors('validation'));
         $this->go_back();
     } catch (DataSource_Exception_Section $e) {
         Messages::errors($e->getMessage());
         $this->go_back();
     }
     Messages::success(__('Datasource has been saved!'));
     // save and quit or save and continue editing?
     if ($this->request->post('commit') !== NULL) {
         $this->go(Route::get('datasources')->uri(array('directory' => 'datasources', 'controller' => 'data')) . URL::query(array('ds_id' => $ds->id()), FALSE));
     } else {
         $this->go_back();
     }
 }