mirror of
https://github.com/Oreolek/kangana.git
synced 2024-05-05 02:28:17 +03:00
parent
7321898413
commit
6353cbc938
|
@ -20,8 +20,14 @@ class Controller_Client extends Controller_Layout {
|
|||
{
|
||||
$this->template = new View_Client_Index;
|
||||
$this->template->title = I18n::translate('Clients');
|
||||
$group_id = $this->request->post('group_id');
|
||||
if ($group_id) {
|
||||
if ($this->request->method() === Request::POST)
|
||||
{
|
||||
$group_id = $this->request->post('group_id');
|
||||
} else {
|
||||
$group_id = $this->request->query('group_id');
|
||||
}
|
||||
if ($group_id)
|
||||
{
|
||||
$group = ORM::factory('Group', $group_id);
|
||||
if ( ! $group->loaded()) {
|
||||
$this->redirect('error/404');
|
||||
|
@ -49,6 +55,23 @@ class Controller_Client extends Controller_Layout {
|
|||
$this->_edit($this->template->model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
public function action_edit()
|
||||
{
|
||||
$this->template = new View_Edit;
|
||||
|
|
|
@ -11,10 +11,6 @@ class Model_Client extends ORM {
|
|||
'model' => 'Course',
|
||||
'through' => 'clients_courses'
|
||||
),
|
||||
'subscription' => array(
|
||||
'model' => 'Subscription',
|
||||
'through' => 'clients_subscriptions'
|
||||
),
|
||||
'group' => array(
|
||||
'model' => 'Group',
|
||||
'through' => 'clients_groups'
|
||||
|
|
60
application/classes/View/Client/View.php
Normal file
60
application/classes/View/Client/View.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
/**
|
||||
* Client details view controller
|
||||
**/
|
||||
class View_Client_View extends View_Layout {
|
||||
protected $details;
|
||||
|
||||
/**
|
||||
* Prepare and return a details table
|
||||
* @return array
|
||||
*/
|
||||
public function get_details()
|
||||
{
|
||||
$retval = [];
|
||||
$retval[] = $this->detail('Name', 'name');
|
||||
$retval[] = $this->detail('Email', 'email');
|
||||
$retval[] = $this->detail('Sex', 'sex', $this->sex($this->model->sex));
|
||||
$retval[] = $this->detail('Referrer', 'referrer');
|
||||
$retval[] = $this->detail('City', 'city');
|
||||
$retval[] = [
|
||||
'caption' => I18n::translate('Groups'),
|
||||
'value' => implode(',', $this->model->group->find_all()->as_array(NULL, 'name'))
|
||||
];
|
||||
$retval[] = [
|
||||
'caption' => I18n::translate('Courses'),
|
||||
'value' => implode(',', $this->model->course->find_all()->as_array(NULL, 'title'))
|
||||
];
|
||||
return $retval;
|
||||
}
|
||||
|
||||
protected function detail($caption, $attribute, $value = NULL)
|
||||
{
|
||||
if (is_null($value))
|
||||
{
|
||||
$value = $this->model->$attribute;
|
||||
if (empty($value))
|
||||
{
|
||||
$value = I18n::translate('unknown');
|
||||
}
|
||||
}
|
||||
return [
|
||||
'caption' => I18n::translate($caption),
|
||||
'value' => $value
|
||||
];
|
||||
}
|
||||
|
||||
protected function sex($value)
|
||||
{
|
||||
if ($value === 'm')
|
||||
{
|
||||
return I18n::translate('Male');
|
||||
}
|
||||
if ($value === 'f')
|
||||
{
|
||||
return I18n::translate('Female');
|
||||
}
|
||||
return I18n::translate('unknown');
|
||||
}
|
||||
}
|
|
@ -86,4 +86,14 @@ return array(
|
|||
'Group' => 'Группа',
|
||||
'New group' => 'Новая группа',
|
||||
'Type' => 'Тип',
|
||||
'Groups' => 'Группы',
|
||||
'Courses' => 'Курсы',
|
||||
'unknown' => 'неизвестно',
|
||||
'Female' => 'Женский',
|
||||
'Male' => 'Мужской',
|
||||
'Sex' => 'Пол',
|
||||
'Referrer' => 'Реферал',
|
||||
'City' => 'Город',
|
||||
'Groups' => 'Группы',
|
||||
'Courses' => 'Курсы',
|
||||
);
|
||||
|
|
11
application/templates/client/view.mustache
Normal file
11
application/templates/client/view.mustache
Normal file
|
@ -0,0 +1,11 @@
|
|||
<table class="table">
|
||||
<tbody>
|
||||
{{#get_details}}
|
||||
<tr>
|
||||
<th>{{caption}}</th>
|
||||
<td>{{value}}</td>
|
||||
</tr>
|
||||
{{/get_details}}
|
||||
</tbody>
|
||||
</table>
|
||||
<p>{{message}}</p>
|
Loading…
Reference in a new issue