From 52f429e3c7023725139e43a9c9b37fcefc329072 Mon Sep 17 00:00:00 2001 From: Iglocska Date: Mon, 4 Jan 2016 11:57:21 +0100 Subject: [PATCH] Quickfilter added for users --- app/Controller/EventsController.php | 2 +- app/Controller/UsersController.php | 34 +++++++++++++++++++++++++---- app/View/Events/index.ctp | 2 +- app/View/Users/admin_index.ctp | 28 +++++++++++++----------- app/webroot/js/ajaxification.js | 3 +-- 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index b4e96b184..784048afb 100755 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -261,7 +261,7 @@ class EventsController extends AppController { $searchTerm = substr($k, 6); switch ($searchTerm) { case 'all' : - $this->paginate['conditions']['AND'][] = array('Event.id' => $this->__quickFilter($passedArgs['searchall'])); + if (!empty($passedArgs['searchall'])) $this->paginate['conditions']['AND'][] = array('Event.id' => $this->__quickFilter($passedArgs['searchall'])); break; case 'attribute' : $event_id_arrays = $this->__filterOnAttributeValue($v); diff --git a/app/Controller/UsersController.php b/app/Controller/UsersController.php index 0322a4991..f7547500d 100755 --- a/app/Controller/UsersController.php +++ b/app/Controller/UsersController.php @@ -17,8 +17,13 @@ class UsersController extends AppController { public $paginate = array( 'limit' => 60, + 'recursive' => -1, 'order' => array( 'Organisation.name' => 'ASC' + ), + 'contain' => array( + 'Organisation' => array('id', 'name'), + 'Role' => array('id', 'name') ) ); @@ -160,10 +165,10 @@ class UsersController extends AppController { $urlparams = ""; $passedArgsArray = array(); $booleanFields = array('autoalert', 'contactalert', 'termsaccepted'); - $textFields = array('role', 'email'); + $textFields = array('role', 'email', 'all'); // org admins can't see users of other orgs if ($this->_isSiteAdmin()) $textFields[] = 'org'; - + $this->set('passedArgs', json_encode($this->passedArgs)); // check each of the passed arguments whether they're a filter (could also be a sort for example) and if yes, add it to the pagination conditions foreach ($this->passedArgs as $k => $v) { if (substr($k, 0, 6) === 'search') { @@ -183,10 +188,20 @@ class UsersController extends AppController { if ($piece[0] == '!') { if ($searchTerm == 'email') $this->paginate['conditions']['AND'][] = array('LOWER(User.' . $searchTerm . ') NOT LIKE' => '%' . strtolower(substr($piece, 1)) . '%'); else if ($searchTerm == 'org') $this->paginate['conditions']['AND'][] = array('User.org_id !=' => substr($piece, 1)); + else $this->paginate['conditions']['AND'][] = array('User.' . $searchTerm => substr($piece, 1)); } else { if ($searchTerm == 'email') $test['OR'][] = array('LOWER(User.' . $searchTerm . ') LIKE' => '%' . strtolower($piece) . '%'); else if ($searchTerm == 'org') $this->paginate['conditions']['OR'][] = array('User.org_id' => $piece); + else if ($searchTerm == 'all') { + $this->paginate['conditions']['AND'][] = array( + 'OR' => array( + 'UPPER(User.email) LIKE' => '%' . strtoupper($piece) . '%', + 'UPPER(Organisation.name) LIKE' => '%' . strtoupper($piece) . '%', + 'UPPER(Role.name) LIKE' => '%' . strtoupper($piece) . '%', + ), + ); + } else $test['OR'][] = array('User.' . $searchTerm => $piece); } } @@ -198,7 +213,6 @@ class UsersController extends AppController { } $this->set('urlparams', $urlparams); $this->set('passedArgsArray', $passedArgsArray); - $this->User->recursive = 0; $conditions = array(); if ($this->_isSiteAdmin()) { $this->set('users', $this->paginate()); @@ -215,6 +229,9 @@ class UsersController extends AppController { public function index($id) { $this->autoRender = false; $this->layout = false; + $overrideAbleParams = array('all'); + $passedArgs = $this->passedArgs; + $overrideAbleParams = array('all'); $org = $this->User->Organisation->read(null, $id); if (!$this->User->Organisation->exists() || !($this->_isSiteAdmin() || $this->Auth->user('org_id') == $id)) { throw MethodNotAllowedException('Organisation not found or no authorisation to view it.'); @@ -223,7 +240,16 @@ class UsersController extends AppController { $conditions = array('org_id' => $id); if ($this->_isSiteAdmin() || ($this->_isAdmin() && $this->Auth->user('org_id') == $id)) { $user_fields = array_merge($user_fields, array('newsread', 'termsaccepted', 'change_pw', 'authkey')); - } + } + $passedArgs = $this->passedArgs; + if (isset($this->request->data)) { + if (isset($this->request->data['searchall'])) $this->request->data['all'] = $this->request->data['searchall']; + if (isset($this->request->data['all']) && !empty($this->request->data['all'])) { + $passedArgs['searchall'] = $this->request->data['all']; + $conditions['OR'][] = array('User.email LIKE' => '%' . $passedArgs['searchall'] . '%'); + } + } + $this->set('passedArgs', json_encode($passedArgs)); $this->paginate = array( 'conditions' => $conditions, 'recursive' => -1, diff --git a/app/View/Events/index.ctp b/app/View/Events/index.ctp index 6942a70d9..de86bbdda 100755 --- a/app/View/Events/index.ctp +++ b/app/View/Events/index.ctp @@ -38,7 +38,7 @@ Html->link('', array('controller' => 'events', 'action' => 'index'), array('class' => 'icon-remove', 'title' => 'Remove filters'));?> - Filter + Filter diff --git a/app/View/Users/admin_index.ctp b/app/View/Users/admin_index.ctp index f96538875..f8cc83cb3 100755 --- a/app/View/Users/admin_index.ctp +++ b/app/View/Users/admin_index.ctp @@ -24,19 +24,21 @@ } ?>
- - - - $v):?> - - - - - - Html->link('', array('controller' => 'users', 'action' => 'index', 'admin' => true), array('class' => 'icon-remove', 'title' => 'Remove filters'));?> - - + + + + $v):?> + + + + + + Html->link('', array('controller' => 'users', 'action' => 'index', 'admin' => true), array('class' => 'icon-remove', 'title' => 'Remove filters'));?> + + + Filter +
diff --git a/app/webroot/js/ajaxification.js b/app/webroot/js/ajaxification.js index 6f69267bc..cfc346ead 100644 --- a/app/webroot/js/ajaxification.js +++ b/app/webroot/js/ajaxification.js @@ -1067,9 +1067,8 @@ function indexEvaluateFiltering() { $('#generatedURLContent').html(indexCreateFilters()); } -function quickFilterEvents(passedArgs) { +function quickFilter(passedArgs, url) { passedArgs["searchall"] = $('#quickFilterField').val(); - var url = "/events/index"; for (var key in passedArgs) { url += "/" + key + ":" + passedArgs[key]; }