Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Mar 25, 2015
0 parents commit 037d0cd
Show file tree
Hide file tree
Showing 34 changed files with 4,841 additions and 0 deletions.
66 changes: 66 additions & 0 deletions classes/Controller/API/Datasource/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php defined( 'SYSPATH' ) or die( 'No direct access allowed.' );

/**
* @package KodiCMS/Datasource
* @category API
* @author butschster <[email protected]>
* @link http://kodicms.ru
* @copyright (c) 2012-2014 butschster
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
class Controller_Api_Datasource_Data extends Controller_System_API
{
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);
}

public function post_menu()
{
$folder_id = (int) $this->param('folder_id', 0);
$ds_id = (int) $this->param('ds_id', NULL, TRUE);

$ds = DataSource_Section::load($ds_id);

if ($ds->loaded())
{
$ds->move_to_folder($folder_id);
$this->status = TRUE;
}
}

public function get_folder()
{
$folder_id = (int) $this->param('id', 0);
$this->response(DataSource_Folder::get($folder_id));
}

public function put_folder()
{
$name = $this->param('name', NULL, TRUE);

if (DataSource_Folder::add($name))
{
$this->status = TRUE;
}
}

public function delete_folder()
{
$folder_id = (int) $this->param('id', 0);

if (DataSource_Folder::delete($folder_id))
{
$this->status = TRUE;
}
}
}
124 changes: 124 additions & 0 deletions classes/Controller/API/Datasource/Document.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php defined( 'SYSPATH' ) or die( 'No direct access allowed.' );

/**
* @package KodiCMS/Datasource
* @category API
* @author butschster <[email protected]>
* @link http://kodicms.ru
* @copyright (c) 2012-2014 butschster
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
class Controller_Api_Datasource_Document extends Controller_System_API
{
public function get_headline()
{
$ds_id = $this->param('ds_id', NULL, TRUE);
$page = (int) $this->param('page', 1);

$ds = $this->_get_datasource($ds_id);

$this->response($this->_get_headline($ds, $page));
}

public function post_create()
{
$ds_id = $this->param('ds_id', NULL, TRUE);

$ds = $this->_get_datasource($ds_id);

$doc = $ds->get_empty_document();

$doc->read_values($this->params())
->validate();

$doc = $ds->create_document($doc);

$this->message('Document created');
$this->response($doc->values());
}

public function post_update()
{
$ds_id = $this->param('ds_id', NULL, TRUE);
$id = $this->param('id', NULL, TRUE);

$ds = $this->_get_datasource($ds_id);

$doc = $ds->get_document((int) $id);

$doc->read_values($this->params())
->validate();

$doc = $ds->update_document($doc);

$this->message('Document updated');
$this->response($doc->values());
}

public function post_publish()
{
$doc_ids = $this->param('doc', array(), TRUE);
$ds_id = $this->param('ds_id', NULL, TRUE);

if (empty($doc_ids))
{
throw HTTP_API_Exception::factory(API::ERROR_UNKNOWN,
'Error');
}

$ds = $this->_get_datasource($ds_id);

$ds->publish($doc_ids);
$this->response($doc_ids);
}

public function post_unpublish()
{
$doc_ids = $this->param('doc', array(), TRUE);
$ds_id = $this->param('ds_id', NULL, TRUE);

if (empty($doc_ids))
{
throw HTTP_API_Exception::factory(API::ERROR_UNKNOWN,
'Error');
}

$ds = $this->_get_datasource($ds_id);

$ds->unpublish($doc_ids);
$this->response($doc_ids);
}

public function post_remove()
{
$doc_ids = $this->param('doc', array(), TRUE);
$ds_id = $this->param('ds_id', NULL, TRUE);

if (empty($doc_ids))
{
throw HTTP_API_Exception::factory(API::ERROR_UNKNOWN,
'Error');
}

$ds = $this->_get_datasource($ds_id);

$ds->remove_documents( $doc_ids );
$this->response($doc_ids);
}

protected function _get_datasource($ds_id)
{
$ds = Datasource_Section::load($ds_id);
if ($ds === NULL)
{
throw HTTP_API_Exception::factory(API::ERROR_UNKNOWN, 'Datasource section not found');
}

return $ds;
}

protected function _get_headline($ds, $page = 1)
{
return (string) $ds->headline()->set_page($page)->render();
}
}
67 changes: 67 additions & 0 deletions classes/Controller/Datasources/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php defined( 'SYSPATH' ) or die( 'No direct access allowed.' );

/**
* @package KodiCMS/Datasource
* @category Controller
* @author butschster <[email protected]>
* @link http://kodicms.ru
* @copyright (c) 2012-2014 butschster
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
class Controller_Datasources_Data extends Controller_System_Datasource
{
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;
}
}
}
Loading

0 comments on commit 037d0cd

Please sign in to comment.