1
0
Fork 0
mirror of https://github.com/Oreolek/kangana.git synced 2024-06-30 21:55:06 +03:00
kangana/application/classes/Controller/Client.php

128 lines
3.3 KiB
PHP
Raw Normal View History

<?php defined('SYSPATH') or die('No direct script access.');
/**
* Client controller.
**/
class Controller_Client extends Controller_Layout {
2014-02-02 05:25:58 +02:00
protected $secure_actions = array(
'index',
'create',
'edit',
'delete',
'view',
'search',
2014-02-02 05:25:58 +02:00
);
2014-02-02 05:43:51 +02:00
protected $controls = array(
'name' => 'input',
'email' => 'input',
);
2014-02-02 05:25:58 +02:00
public function action_index()
{
$this->template = new View_Client_Index;
2016-10-11 08:37:54 +03:00
$this->template->title = I18n::translate('Clients');
2016-11-09 10:38:14 +02:00
if ($this->request->method() === Request::POST)
{
$group_id = $this->request->post('group_id');
} else {
$group_id = $this->request->query('group_id');
}
if ($group_id)
{
2016-10-11 08:12:01 +03:00
$group = ORM::factory('Group', $group_id);
2016-10-11 08:37:54 +03:00
if ( ! $group->loaded()) {
2016-10-11 08:12:01 +03:00
$this->redirect('error/404');
}
2016-10-11 08:37:54 +03:00
$this->template->title .= ' - '.$group->name;
2016-10-11 08:12:01 +03:00
$this->template->items = $group
->clients
->filter_by_page($this->request->param('page'))
->find_all();
2016-11-10 08:32:09 +02:00
$this->template->item_count = $group
->clients
->count_all();
2016-10-11 08:12:01 +03:00
} else {
$this->template->items = ORM::factory('Client')
->filter_by_page($this->request->param('page'))
->find_all();
2016-11-10 08:32:09 +02:00
$this->template->item_count = ORM::factory('Client')
->count_all();
2016-10-11 08:12:01 +03:00
}
}
2014-01-16 14:01:14 +02:00
/**
* Manually add a client.
**/
2014-02-02 05:25:58 +02:00
public function action_create()
2014-01-16 14:01:14 +02:00
{
2014-02-02 05:43:51 +02:00
$this->template = new View_Edit;
$this->template->model = ORM::factory('Client');
2016-10-11 08:37:54 +03:00
$this->template->title = I18n::translate('New client');
2014-02-02 05:43:51 +02:00
$this->_edit($this->template->model);
}
2016-11-09 10:38:14 +02:00
/**
* Manually add a client.
**/
public function action_view()
{
$this->template = new View_Client_View();
$model = ORM::factory('Client', $this->request->param('id'))
->with('courses')
->with('groups');
if ( ! $model->loaded())
{
$this->redirect('error/404');
}
$this->template->title = I18n::translate('Client details for').' '.$model->email;
$this->template->model = $model;
}
2014-02-02 05:43:51 +02:00
public function action_edit()
{
$this->template = new View_Edit;
2016-10-11 08:37:54 +03:00
$this->template->title = I18n::translate('Edit client info');
2014-02-02 05:43:51 +02:00
$id = $this->request->param('id');
$model = ORM::factory('Client', $id);
2016-10-11 08:37:54 +03:00
if ( ! $model->loaded())
2014-02-02 05:43:51 +02:00
{
$this->redirect('error/404');
}
$this->_edit($model);
}
public function action_delete()
{
$this->template = new View_Delete;
$id = $this->request->param('id');
$model = ORM::factory('Client', $id);
2016-10-11 08:37:54 +03:00
if ( ! $model->loaded())
2014-02-02 05:43:51 +02:00
{
$this->redirect('error/404');
}
2016-10-11 08:37:54 +03:00
$this->template->title = I18n::translate('Delete client');
2014-02-02 05:43:51 +02:00
$this->template->content_title = $model->name;
$this->template->content = $model->email;
$confirmation = $this->request->post('confirmation');
if ($confirmation === 'yes') {
2016-10-11 08:12:01 +03:00
$model->delete();
2014-02-02 05:43:51 +02:00
$this->redirect('/');
}
2014-01-16 14:01:14 +02:00
}
/**
* Search a client.
**/
public function action_search()
{
2014-02-02 05:43:51 +02:00
$this->template = new View_Client_Index;
$this->template->show_create = FALSE;
2016-10-11 08:37:54 +03:00
$this->template->title = I18n::translate('Clients');
2014-02-02 05:43:51 +02:00
$query = $this->request->post('query');
$this->template->items = ORM::factory('Client')
->search($query)
->filter_by_page($this->request->param('page'))
->find_all();
2014-01-17 09:37:23 +02:00
}
}