Commit a3f95ff8d81b4331f89d22e58d344c23b7d45bb8
1 parent
771c4ebc
users search backend
Showing
2 changed files
with
32 additions
and
4 deletions
Show diff stats
src/app/backend/controllers/CustomersController.php
@@ -12,10 +12,18 @@ class CustomersController extends \Phalcon\Mvc\Controller | @@ -12,10 +12,18 @@ class CustomersController extends \Phalcon\Mvc\Controller | ||
12 | { | 12 | { |
13 | return $this->response->redirect([ 'for' => 'admin_login' ]); | 13 | return $this->response->redirect([ 'for' => 'admin_login' ]); |
14 | } | 14 | } |
15 | - $params = $this->dispatcher->getParams(); | ||
16 | - $page = !empty( $params['page'] ) ? $params['page'] : 1; | ||
17 | - $data = $this->models->getCustomers()->getAllData($page); | ||
18 | - $total = $this->models->getCustomers()->countData(); | 15 | + |
16 | + $params = $this->dispatcher->getParams(); | ||
17 | + $page = !empty( $params['page'] ) ? $params['page'] : 1; | ||
18 | + | ||
19 | + $search = $this->request->getPost('search', 'string', NULL); | ||
20 | + if (!empty($search)) { | ||
21 | + $data = $this->models->getCustomers()->getDataByName($page); | ||
22 | + } | ||
23 | + else { | ||
24 | + $data = $this->models->getCustomers()->getAllData($page); | ||
25 | + $total = $this->models->getCustomers()->countData(); | ||
26 | + } | ||
19 | 27 | ||
20 | if( $total['0']['total'] > \config::get( 'limits/items') ) | 28 | if( $total['0']['total'] > \config::get( 'limits/items') ) |
21 | { | 29 | { |
@@ -29,6 +37,7 @@ class CustomersController extends \Phalcon\Mvc\Controller | @@ -29,6 +37,7 @@ class CustomersController extends \Phalcon\Mvc\Controller | ||
29 | ], true | 37 | ], true |
30 | ); | 38 | ); |
31 | } | 39 | } |
40 | + | ||
32 | $this->view->setVars([ | 41 | $this->view->setVars([ |
33 | 'info' => $data, | 42 | 'info' => $data, |
34 | 'paginate' => !empty($paginate['output']) ? $paginate['output'] : '' , | 43 | 'paginate' => !empty($paginate['output']) ? $paginate['output'] : '' , |
@@ -177,4 +186,5 @@ class CustomersController extends \Phalcon\Mvc\Controller | @@ -177,4 +186,5 @@ class CustomersController extends \Phalcon\Mvc\Controller | ||
177 | ]); | 186 | ]); |
178 | 187 | ||
179 | } | 188 | } |
189 | + | ||
180 | } | 190 | } |
181 | \ No newline at end of file | 191 | \ No newline at end of file |
src/lib/models/customers.php
@@ -1289,6 +1289,24 @@ class customers extends \db | @@ -1289,6 +1289,24 @@ class customers extends \db | ||
1289 | ); | 1289 | ); |
1290 | } | 1290 | } |
1291 | 1291 | ||
1292 | + public function getDataByName($like) { | ||
1293 | + | ||
1294 | + return $this->get( | ||
1295 | + ' | ||
1296 | + SELECT * FROM | ||
1297 | + public.customers | ||
1298 | + WHERE | ||
1299 | + name LIKE %:like% | ||
1300 | + ' | ||
1301 | + , | ||
1302 | + [ | ||
1303 | + 'like' => $like | ||
1304 | + ], | ||
1305 | + -1 | ||
1306 | + ); | ||
1307 | + | ||
1308 | + } | ||
1309 | + | ||
1292 | } | 1310 | } |
1293 | 1311 | ||
1294 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 1312 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
1295 | \ No newline at end of file | 1313 | \ No newline at end of file |