1
0
Fork 0
mirror of https://github.com/Oreolek/kangana.git synced 2024-05-18 08:58:19 +03:00

Group CRUD

This commit is contained in:
Alexander Yakovlev 2016-10-11 12:12:01 +07:00
parent f918e54768
commit ab5d2efacd
15 changed files with 360 additions and 73 deletions

View file

@ -6,7 +6,6 @@
class Controller_Client extends Controller_Layout { class Controller_Client extends Controller_Layout {
protected $secure_actions = array( protected $secure_actions = array(
'index', 'index',
'group',
'create', 'create',
'edit', 'edit',
'delete', 'delete',
@ -21,18 +20,22 @@ class Controller_Client extends Controller_Layout {
{ {
$this->template = new View_Client_Index; $this->template = new View_Client_Index;
$this->template->title = __('Clients'); $this->template->title = __('Clients');
$this->template->items = ORM::factory('Client') $group_id = $this->request->post('group_id');
->filter_by_page($this->request->param('page')) if ($group_id) {
->find_all(); $group = ORM::factory('Group', $group_id);
} if (!$group->loaded()) {
$this->redirect('error/404');
public function action_group() }
{ $this->template->title .= ' - ' . $group->name;
$this->template = new View_Client_Index; $this->template->items = $group
$this->template->title = __('Clients'); ->clients
$this->template->items = ORM::factory('Client') ->filter_by_page($this->request->param('page'))
->filter_by_page($this->request->param('page')) ->find_all();
->find_by_group($this->request->param('group_id')); } else {
$this->template->items = ORM::factory('Client')
->filter_by_page($this->request->param('page'))
->find_all();
}
} }
/** /**
@ -74,7 +77,7 @@ class Controller_Client extends Controller_Layout {
$confirmation = $this->request->post('confirmation'); $confirmation = $this->request->post('confirmation');
if ($confirmation === 'yes') { if ($confirmation === 'yes') {
$post->delete(); $model->delete();
$this->redirect('/'); $this->redirect('/');
} }
} }
@ -93,11 +96,4 @@ class Controller_Client extends Controller_Layout {
->filter_by_page($this->request->param('page')) ->filter_by_page($this->request->param('page'))
->find_all(); ->find_all();
} }
/**
* Unsubscription link action.
**/
public function action_unsubscribe()
{
}
} }

View file

@ -0,0 +1,99 @@
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Client controller.
**/
class Controller_Group extends Controller_Layout {
protected $secure_actions = array(
'index',
'create',
'edit',
'delete',
'view',
'search',
);
protected $controls = array(
'name' => 'input',
);
public function action_index()
{
$this->template = new View_Index;
$this->template->title = __('Groups');
$this->template->header = [
__('Group name'),
__('Edit'),
__('Delete'),
];
$this->template->items = ORM::factory('Group')
->filter_by_page($this->request->param('page'))
->find_all();
}
/**
* Manually add a group.
**/
public function action_create()
{
$this->template = new View_Edit;
$this->template->model = ORM::factory('Group');
$this->template->title = __('New group');
$this->_edit($this->template->model);
}
public function action_edit()
{
$this->template = new View_Edit;
$this->template->title = __('Edit group info');
$id = $this->request->param('id');
$model = ORM::factory('Group', $id);
if (!$model->loaded())
{
$this->redirect('error/404');
}
$this->_edit($model);
}
public function action_delete()
{
$this->template = new View_Delete;
$id = $this->request->param('id');
$model = ORM::factory('Group', $id);
if (!$model->loaded())
{
$this->redirect('error/404');
}
$this->template->title = __('Delete group');
$this->template->content_title = $model->name;
// $this->template->content = $model->email;
// TODO - display a list of subscribers in group
$confirmation = $this->request->post('confirmation');
if ($confirmation === 'yes') {
$model->delete();
$this->redirect('/');
}
}
/**
* Group view.
**/
public function action_view()
{
$this->redirect('client/index?group_id='.$this->request->param('id'));
}
/**
* Search groups.
**/
public function action_search()
{
$this->template = new View_Client_Index;
$this->template->show_create = FALSE;
$this->template->title = __('Groups');
$query = $this->request->post('query');
$this->template->items = ORM::factory('Group')
->search($query)
->filter_by_page($this->request->param('page'))
->find_all();
}
}

View file

@ -1,10 +1,10 @@
<?php defined('SYSPATH') or die('No direct script access.'); <?php defined('SYSPATH') or die('No direct script access.');
/** /**
* Redefined Form helper for Bootstrap-compliant and ORM generation. * Redefined Form helper for Bootstrap-compliant and ORM generation.
* @package Oreolek * @package Oreolek
* @category Helpers * @category Helpers
**/ **/
class Form extends Kohana_Form { class Form extends Kohana_Form {
public static function orm_input($model, $name, $type = 'input') public static function orm_input($model, $name, $type = 'input')
{ {
@ -179,12 +179,12 @@ class Form extends Kohana_Form {
$template->name = $name; $template->name = $name;
$template->label = __(Arr::get($attributes, 'label')); $template->label = __(Arr::get($attributes, 'label'));
$template->options = array(); $template->options = array();
foreach ($options as $name => $value) foreach ($options as $value => $text)
{ {
$template->options[] = array( $template->options[] = array(
'name' => $name,
'value' => $value, 'value' => $value,
'is_selected' => ($name == $selected) 'text' => $text,
'is_selected' => ($value == $selected)
); );
} }
return self::render_control($template); return self::render_control($template);
@ -214,7 +214,7 @@ class Form extends Kohana_Form {
{ {
return self::btn('submit', __($text), 'primary', 'submit'); return self::btn('submit', __($text), 'primary', 'submit');
} }
protected static function render_control($template) protected static function render_control($template)
{ {
$renderer = Kostache_Layout::factory('form/control'); $renderer = Kostache_Layout::factory('form/control');

View file

@ -65,4 +65,15 @@ class Model_Client extends ORM {
->or_where(DB::expr('LOWER(email)'), 'LIKE', strtolower($query)); ->or_where(DB::expr('LOWER(email)'), 'LIKE', strtolower($query));
} }
/**
* A function to search by group ID
* @param int $group_id
*/
public function find_by_group($group_id) {
return $this
->with('groups')
->find()
->where('groups.id', '=', (int) $group_id);
}
} }

View file

@ -19,10 +19,10 @@ class Model_Group extends ORM {
public function rules() public function rules()
{ {
return array( return array(
'title' => array( 'name' => array(
array('not_empty'), array('not_empty'),
array('min_length', array(':value', 4)), array('min_length', array(':value', 4)),
array('max_length', array(':value', 255)), array('max_length', array(':value', 255)),
), ),
); );
} }
@ -32,7 +32,7 @@ class Model_Group extends ORM {
* Used in forms. * Used in forms.
**/ **/
protected $_labels = array( protected $_labels = array(
'title' => 'Title', 'name' => 'Name',
); );
public static function count($id) public static function count($id)

View file

@ -9,6 +9,27 @@ class View_Client_Index extends View_Index {
protected $is_admin = TRUE; // admin only view protected $is_admin = TRUE; // admin only view
public $show_date = FALSE; public $show_date = FALSE;
public $subscription_id; public $subscription_id;
public $group;
public function get_header()
{
return array(
__('Name'),
__('Email'),
__('Edit'),
__('Delete')
);
}
/**
* Group search field
*/
public function groups() {
return Form::open()
. Form::select('group_id', ORM::factory('Group')->find_all()->as_array('id', 'name'))
. Form::submit('s', __('Submit'))
. Form::close();
}
/** /**
* An internal function to prepare item data. * An internal function to prepare item data.
**/ **/

View file

@ -22,6 +22,10 @@ class View_Index extends View_Layout {
* Index description * Index description
**/ **/
public $content = ''; public $content = '';
/**
* Table header
*/
public $header = NULL;
protected $is_admin; protected $is_admin;
@ -51,6 +55,14 @@ class View_Index extends View_Layout {
return $output; return $output;
} }
/**
* Table header
*/
public function get_header()
{
return $this->header;
}
public function get_items() public function get_items()
{ {
$result = array(); $result = array();
@ -87,10 +99,6 @@ class View_Index extends View_Layout {
$output = array( $output = array(
'view_link' => HTML::anchor(Route::url('default', array('controller' => Request::current()->controller(), 'action' => 'view','id' => $item->id)), $item->name, array('class' => 'link_view')), 'view_link' => HTML::anchor(Route::url('default', array('controller' => Request::current()->controller(), 'action' => 'view','id' => $item->id)), $item->name, array('class' => 'link_view')),
); );
if ($this->show_date)
{
$output['date'] = $item->posted_at;
}
if ($this->is_admin and $this->show_edit) if ($this->is_admin and $this->show_edit)
{ {
$output['edit_link'] = HTML::anchor(Route::url('default', array('controller' => Request::current()->controller(), 'action' => 'edit','id' => $item->id)), __('Edit'), array('class' => 'link_edit')); $output['edit_link'] = HTML::anchor(Route::url('default', array('controller' => Request::current()->controller(), 'action' => 'edit','id' => $item->id)), __('Edit'), array('class' => 'link_edit'));

View file

@ -11,12 +11,12 @@ class View_Layout {
public $base_scripts = array( public $base_scripts = array(
); );
public $errors; public $errors;
/** /**
* Inherited paging function * Inherited paging function
**/ **/
public function get_paging() {} public function get_paging() {}
public function has_errors() public function has_errors()
{ {
return !empty($this->errors); return !empty($this->errors);
@ -80,6 +80,7 @@ class View_Layout {
__('Courses') => 'course/index', __('Courses') => 'course/index',
__('Subscriptions') => 'subscription/index', __('Subscriptions') => 'subscription/index',
__('Clients') => 'client/index', __('Clients') => 'client/index',
__('Groups') => 'group/index',
)); ));
} }
@ -121,7 +122,7 @@ class View_Layout {
return array( return array(
'button_text' => __('Submit'), 'button_text' => __('Submit'),
'input_text' => __('Search'), 'input_text' => __('Search'),
'action' => Route::url('default', array('controller' => 'Client', 'action' => 'search')) 'action' => Route::url('default', array('controller' => 'Client', 'action' => 'search'))
); );
} }
} }

View file

@ -73,5 +73,8 @@ return array(
'Your e-mail' => 'Ваш адрес электронной почты', 'Your e-mail' => 'Ваш адрес электронной почты',
'Tired of receiving these emails? Click this link to unsubscribe.' => 'Устали получать эти письма? Нажмите на эту ссылку для отписки.', 'Tired of receiving these emails? Click this link to unsubscribe.' => 'Устали получать эти письма? Нажмите на эту ссылку для отписки.',
'Client not found. Possible subscription token problem.' => 'Клиент не найден. Возможна проблема с токеном подписки.', 'Client not found. Possible subscription token problem.' => 'Клиент не найден. Возможна проблема с токеном подписки.',
'You have been successfully unsubscribed from course %s' => 'Вы были успешно отписаны от курса %s' 'You have been successfully unsubscribed from course %s' => 'Вы были успешно отписаны от курса %s',
'Groups' => 'Группы',
'Group name' => 'Название группы',
'Delete group' => 'Удалить группу',
); );

View file

@ -56,3 +56,15 @@ footer {
} }
} }
} }
.groupform {
margin-top: -3em;
float: right;
width: 50%;
.form-group {
width: 50%;
display: inline-block;
}
input {
margin-right: 1em;
}
}

View file

@ -1,10 +1,21 @@
{{#show_create}} <div class="groupform">
{{{link_new}}} {{{groups}}}
{{/show_create}}
<div class="hyphenate">
{{{content}}}
</div> </div>
{{#show_create}}
<p>{{{link_new}}}</p>
{{/show_create}}
{{#content}}
<div class="hyphenate">
{{{.}}}
</div>
{{/content}}
<table class="table"> <table class="table">
<thead>
{{#get_header}}
<th>{{.}}</th>
{{/get_header}}
</thead>
<tbody>
{{#get_items}} {{#get_items}}
<tr> <tr>
<td>{{{view_link}}}</td> <td>{{{view_link}}}</td>
@ -15,4 +26,5 @@
{{/edit_link}} {{/edit_link}}
</tr> </tr>
{{/get_items}} {{/get_items}}
</tbody>
</table> </table>

View file

@ -1,5 +1,5 @@
<select class="form-control" name="{{name}}" id="{{id}}"> <select class="form-control" name="{{name}}" id="{{id}}">
{{#options}} {{#options}}
<option name="{{name}}" {{#is_selected}}selected="selected"{{/is_selected}}>{{value}}</option> <option value="{{value}}" {{#is_selected}}selected="selected"{{/is_selected}}>{{text}}</option>
{{/options}} {{/options}}
</select> </select>

View file

@ -4,17 +4,23 @@
<div class="hyphenate"> <div class="hyphenate">
{{{content}}} {{{content}}}
</div> </div>
<div class="table_index"> <table class="table">
<thead>
{{#get_header}}
<th>
{{.}}
</th>
{{/get_header}}
</thead>
<tbody>
{{#get_items}} {{#get_items}}
<div class="table_row"> <tr>
{{#date}} <td class="hyphenate">{{{view_link}}}</td>
<div class="date">{{date}}</div>
{{/date}}
<div class="hyphenate">{{{view_link}}}</div>
{{#edit_link}} {{#edit_link}}
<div>{{{edit_link}}}</div> <td>{{{edit_link}}}</td>
<div>{{{delete_link}}}</div> <td>{{{delete_link}}}</td>
{{/edit_link}} {{/edit_link}}
</div> </tr>
{{/get_items}} {{/get_items}}
</div> <tbody>
</table>

View file

@ -42,7 +42,8 @@
"require-dev": { "require-dev": {
"phing/phing": "dev-master", "phing/phing": "dev-master",
"kohana/unittest": "3.4.*", "kohana/unittest": "3.4.*",
"kohana/userguide": "3.4.*" "kohana/userguide": "3.4.*",
"kohana/coding-standards": "*"
}, },
"minimum-stability": "dev", "minimum-stability": "dev",
"extra": { "extra": {

147
composer.lock generated
View file

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "370816fa629c0856ac1c68ef503cd333", "hash": "cdd5d55f92469dea3bcd533ffcd17fde",
"content-hash": "37236e1d636299186f13be656b62c8fa", "content-hash": "05d74ec93f60bdb8b4c933cbc4b857f6",
"packages": [ "packages": [
{ {
"name": "composer/installers", "name": "composer/installers",
@ -637,12 +637,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/log.git", "url": "https://github.com/php-fig/log.git",
"reference": "607ce1d4005af32dd866c4a402459494c168d555" "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/607ce1d4005af32dd866c4a402459494c168d555", "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"reference": "607ce1d4005af32dd866c4a402459494c168d555", "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -676,7 +676,7 @@
"psr", "psr",
"psr-3" "psr-3"
], ],
"time": "2016-09-25 13:41:54" "time": "2016-10-10 12:19:37"
}, },
{ {
"name": "swiftmailer/swiftmailer", "name": "swiftmailer/swiftmailer",
@ -989,6 +989,48 @@
], ],
"time": "2016-03-31 10:24:22" "time": "2016-03-31 10:24:22"
}, },
{
"name": "kohana/coding-standards",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/kohana/coding-standards.git",
"reference": "5cbecdfce7f238c59d3eeb12fd5d4457e1b05c30"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/kohana/coding-standards/zipball/5cbecdfce7f238c59d3eeb12fd5d4457e1b05c30",
"reference": "5cbecdfce7f238c59d3eeb12fd5d4457e1b05c30",
"shasum": ""
},
"require": {
"squizlabs/php_codesniffer": "1.*"
},
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Kohana Team",
"email": "team@kohanaframework.org",
"homepage": "http://www.kohanaframework.org",
"role": "Maintainer"
}
],
"description": "PHP_CodeSniffer rules for the Kohana Framework coding style",
"homepage": "https://github.com/kohana/coding-standards",
"keywords": [
"Code style",
"code standard",
"coding stanards",
"kohana",
"phpcs",
"standards"
],
"time": "2014-05-27 16:40:02"
},
{ {
"name": "kohana/unittest", "name": "kohana/unittest",
"version": "dev-3.4/develop", "version": "dev-3.4/develop",
@ -1156,12 +1198,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phingofficial/phing.git", "url": "https://github.com/phingofficial/phing.git",
"reference": "ea5617995882f0e0f90e5ba94dc4d1948c84388a" "reference": "74af0362988dfd6c53eaf7f6ade823d8e7d40348"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phingofficial/phing/zipball/ea5617995882f0e0f90e5ba94dc4d1948c84388a", "url": "https://api.github.com/repos/phingofficial/phing/zipball/74af0362988dfd6c53eaf7f6ade823d8e7d40348",
"reference": "ea5617995882f0e0f90e5ba94dc4d1948c84388a", "reference": "74af0362988dfd6c53eaf7f6ade823d8e7d40348",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1208,7 +1250,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "2.15.x-dev" "dev-master": "2.16.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -1241,7 +1283,7 @@
"task", "task",
"tool" "tool"
], ],
"time": "2016-10-04 15:20:11" "time": "2016-10-10 11:51:22"
}, },
{ {
"name": "phpdocumentor/reflection-common", "name": "phpdocumentor/reflection-common",
@ -2195,6 +2237,81 @@
"homepage": "https://github.com/sebastianbergmann/version", "homepage": "https://github.com/sebastianbergmann/version",
"time": "2015-06-21 13:59:46" "time": "2015-06-21 13:59:46"
}, },
{
"name": "squizlabs/php_codesniffer",
"version": "1.5.x-dev",
"source": {
"type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "6f3e42d311b882b25b4d409d23a289f4d3b803d5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6f3e42d311b882b25b4d409d23a289f4d3b803d5",
"reference": "6f3e42d311b882b25b4d409d23a289f4d3b803d5",
"shasum": ""
},
"require": {
"ext-tokenizer": "*",
"php": ">=5.1.2"
},
"suggest": {
"phpunit/php-timer": "dev-master"
},
"bin": [
"scripts/phpcs"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-phpcs-fixer": "2.0.x-dev"
}
},
"autoload": {
"classmap": [
"CodeSniffer.php",
"CodeSniffer/CLI.php",
"CodeSniffer/Exception.php",
"CodeSniffer/File.php",
"CodeSniffer/Report.php",
"CodeSniffer/Reporting.php",
"CodeSniffer/Sniff.php",
"CodeSniffer/Tokens.php",
"CodeSniffer/Reports/",
"CodeSniffer/CommentParser/",
"CodeSniffer/Tokenizers/",
"CodeSniffer/DocGenerators/",
"CodeSniffer/Standards/AbstractPatternSniff.php",
"CodeSniffer/Standards/AbstractScopeSniff.php",
"CodeSniffer/Standards/AbstractVariableSniff.php",
"CodeSniffer/Standards/IncorrectPatternException.php",
"CodeSniffer/Standards/Generic/Sniffs/",
"CodeSniffer/Standards/MySource/Sniffs/",
"CodeSniffer/Standards/PEAR/Sniffs/",
"CodeSniffer/Standards/PSR1/Sniffs/",
"CodeSniffer/Standards/PSR2/Sniffs/",
"CodeSniffer/Standards/Squiz/Sniffs/",
"CodeSniffer/Standards/Zend/Sniffs/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Greg Sherwood",
"role": "lead"
}
],
"description": "PHP_CodeSniffer tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
"homepage": "http://www.squizlabs.com/php-codesniffer",
"keywords": [
"phpcs",
"standards"
],
"time": "2014-12-04 22:32:15"
},
{ {
"name": "symfony/yaml", "name": "symfony/yaml",
"version": "dev-master", "version": "dev-master",
@ -2256,12 +2373,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/webmozart/assert.git", "url": "https://github.com/webmozart/assert.git",
"reference": "8444f2ac9f86342665cdae47b6d3ea6e07794456" "reference": "1a6cc8d09dd675802ca93de290ac483c10ef95e0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/webmozart/assert/zipball/8444f2ac9f86342665cdae47b6d3ea6e07794456", "url": "https://api.github.com/repos/webmozart/assert/zipball/1a6cc8d09dd675802ca93de290ac483c10ef95e0",
"reference": "8444f2ac9f86342665cdae47b6d3ea6e07794456", "reference": "1a6cc8d09dd675802ca93de290ac483c10ef95e0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2298,7 +2415,7 @@
"check", "check",
"validate" "validate"
], ],
"time": "2016-08-18 09:30:53" "time": "2016-10-10 07:45:47"
} }
], ],
"aliases": [], "aliases": [],