mirror of
https://github.com/Oreolek/kangana.git
synced 2024-06-26 03:40:56 +03:00
Client search
This commit is contained in:
parent
eef5f834ae
commit
fb4306ec7a
|
@ -7,6 +7,10 @@ class Controller_Client extends Controller_Layout {
|
|||
protected $secure_actions = array(
|
||||
'index','create', 'edit', 'delete', 'view'
|
||||
);
|
||||
protected $controls = array(
|
||||
'name' => 'input',
|
||||
'email' => 'input',
|
||||
);
|
||||
public function action_index()
|
||||
{
|
||||
$this->template = new View_Client_Index;
|
||||
|
@ -21,6 +25,43 @@ class Controller_Client extends Controller_Layout {
|
|||
**/
|
||||
public function action_create()
|
||||
{
|
||||
$this->template = new View_Edit;
|
||||
$this->template->model = ORM::factory('Client');
|
||||
$this->template->title = __('New client');
|
||||
$this->_edit($this->template->model);
|
||||
}
|
||||
|
||||
public function action_edit()
|
||||
{
|
||||
$this->template = new View_Edit;
|
||||
$this->template->title = __('Edit client info');
|
||||
$id = $this->request->param('id');
|
||||
$model = ORM::factory('Client', $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('Client', $id);
|
||||
if (!$model->loaded())
|
||||
{
|
||||
$this->redirect('error/404');
|
||||
}
|
||||
$this->template->title = __('Delete client');
|
||||
$this->template->content_title = $model->name;
|
||||
$this->template->content = $model->email;
|
||||
|
||||
$confirmation = $this->request->post('confirmation');
|
||||
if ($confirmation === 'yes') {
|
||||
$post->delete();
|
||||
$this->redirect('/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,13 +69,19 @@ class Controller_Client extends Controller_Layout {
|
|||
**/
|
||||
public function action_search()
|
||||
{
|
||||
$this->template = new View_Client_Search;
|
||||
}
|
||||
|
||||
public function action_subscribe()
|
||||
{
|
||||
$this->template = new View_Client_Index;
|
||||
$this->template->show_create = FALSE;
|
||||
$this->template->title = __('Clients');
|
||||
$query = $this->request->post('query');
|
||||
$this->template->items = ORM::factory('Client')
|
||||
->search($query)
|
||||
->filter_by_page($this->request->param('page'))
|
||||
->find_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscription link action.
|
||||
**/
|
||||
public function action_unsubscribe()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -46,4 +46,15 @@ class Model_Client extends ORM {
|
|||
$this->token = base64_encode(openssl_random_pseudo_bytes(32));
|
||||
}
|
||||
|
||||
/**
|
||||
* Search by name or email
|
||||
**/
|
||||
public function search($query)
|
||||
{
|
||||
$query = '%'.trim($query, '%').'%';
|
||||
return $this
|
||||
->where(DB::expr('LOWER(name)'), 'LIKE', strtolower($query))
|
||||
->or_where(DB::expr('LOWER(email)'), 'LIKE', strtolower($query));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
/**
|
||||
* Search client view controller
|
||||
**/
|
||||
class View_Client_Search extends View_Layout {
|
||||
}
|
|
@ -113,4 +113,13 @@ class View_Layout {
|
|||
'warning' => $session->get_once('flash_warning'),
|
||||
);
|
||||
}
|
||||
|
||||
public function search_form()
|
||||
{
|
||||
return array(
|
||||
'button_text' => __('Submit'),
|
||||
'input_text' => __('Search'),
|
||||
'action' => Route::url('default', array('controller' => 'Client', 'action' => 'search'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,5 +39,10 @@ return array(
|
|||
'Sending letter with subject "%subject" to address %address' => 'Отсылаю письмо с темой %subject на адрес %address',
|
||||
'Clients' => 'Клиенты',
|
||||
'Description' => 'Описание',
|
||||
'Subscribers' => 'Подписчики'
|
||||
'Subscribers' => 'Подписчики',
|
||||
'New client' => 'Новый клиент',
|
||||
'Edit client info' => 'Редактировать информацию о подписчике',
|
||||
'Delete client' => 'Удалить клиента',
|
||||
'Submit' => 'Отправить',
|
||||
'Search' => 'Искать'
|
||||
);
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
{{content}}
|
|
@ -13,28 +13,19 @@
|
|||
{{{get_paging}}}
|
||||
</div>
|
||||
<nav class="navbar navbar-default" role="navigation">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="#">{{site_title}}</a>
|
||||
</div>
|
||||
<div class="collapse navbar-collapse">
|
||||
<form class="navbar-form navbar-left" role="search">
|
||||
{{#search_form}}
|
||||
<form class="navbar-form navbar-left" role="search" action="{{{action}}}" method="POST">
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control" placeholder="Search">
|
||||
<input type="text" name="query" class="form-control" placeholder="{{input_text}}">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
<button type="submit" class="btn btn-default">{{button_text}}</button>
|
||||
</form>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
{{#navigation}}
|
||||
<li><a href="{{url}}">{{title}}</a></li>
|
||||
{{/navigation}}
|
||||
</ul>
|
||||
</div>
|
||||
{{/search_form}}
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
{{#navigation}}
|
||||
<li><a href="{{url}}">{{title}}</a></li>
|
||||
{{/navigation}}
|
||||
</ul>
|
||||
</nav>
|
||||
<a href="#" class="link_top hidden-xs"><i class="fa fa-angle-up"> </i>Наверх</a>
|
||||
<div class = "main_content">
|
||||
|
|
Loading…
Reference in a new issue