From 6353cbc9387774ea20167d31dd166754da8b2343 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Wed, 9 Nov 2016 15:38:14 +0700 Subject: [PATCH] Fixes #10, partially fixes #11 --- application/classes/Controller/Client.php | 27 +++++++++- application/classes/Model/Client.php | 4 -- application/classes/View/Client/View.php | 60 ++++++++++++++++++++++ application/i18n/ru.php | 10 ++++ application/templates/client/view.mustache | 11 ++++ 5 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 application/classes/View/Client/View.php create mode 100644 application/templates/client/view.mustache diff --git a/application/classes/Controller/Client.php b/application/classes/Controller/Client.php index ffc5c1b..f71133b 100644 --- a/application/classes/Controller/Client.php +++ b/application/classes/Controller/Client.php @@ -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; diff --git a/application/classes/Model/Client.php b/application/classes/Model/Client.php index a6ff0c1..c85b8c4 100644 --- a/application/classes/Model/Client.php +++ b/application/classes/Model/Client.php @@ -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' diff --git a/application/classes/View/Client/View.php b/application/classes/View/Client/View.php new file mode 100644 index 0000000..e83b614 --- /dev/null +++ b/application/classes/View/Client/View.php @@ -0,0 +1,60 @@ +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'); + } +} diff --git a/application/i18n/ru.php b/application/i18n/ru.php index 2899818..053bc70 100644 --- a/application/i18n/ru.php +++ b/application/i18n/ru.php @@ -86,4 +86,14 @@ return array( 'Group' => 'Группа', 'New group' => 'Новая группа', 'Type' => 'Тип', + 'Groups' => 'Группы', + 'Courses' => 'Курсы', + 'unknown' => 'неизвестно', + 'Female' => 'Женский', + 'Male' => 'Мужской', + 'Sex' => 'Пол', + 'Referrer' => 'Реферал', + 'City' => 'Город', + 'Groups' => 'Группы', + 'Courses' => 'Курсы', ); diff --git a/application/templates/client/view.mustache b/application/templates/client/view.mustache new file mode 100644 index 0000000..adc3f16 --- /dev/null +++ b/application/templates/client/view.mustache @@ -0,0 +1,11 @@ + + + {{#get_details}} + + + + + {{/get_details}} + +
{{caption}}{{value}}
+

{{message}}