From f093cfbcefbc56b63eb87ab2db951a23a1de9966 Mon Sep 17 00:00:00 2001 From: APHW2 MFGENG Date: Mon, 13 Nov 2017 10:27:24 -0800 Subject: [PATCH] add Filtering to monitors index --- web/api/app/Controller/EventsController.php | 17 ++++------- web/api/app/Controller/MonitorsController.php | 28 ++++++++++--------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/web/api/app/Controller/EventsController.php b/web/api/app/Controller/EventsController.php index f3e054c42..b5a17d461 100644 --- a/web/api/app/Controller/EventsController.php +++ b/web/api/app/Controller/EventsController.php @@ -34,17 +34,13 @@ public function beforeFilter() { public function index() { $this->Event->recursive = -1; - $allowedMonitors=preg_split ('@,@', $this->Session->Read('allowedMonitors'),NULL, PREG_SPLIT_NO_EMPTY); - - if (!empty($allowedMonitors)) - { - $mon_options = array('Event.MonitorId' => $allowedMonitors); - } - else - { - $mon_options=''; - } + $allowedMonitors=preg_split ('@,@', $this->Session->Read('allowedMonitors'),NULL, PREG_SPLIT_NO_EMPTY); + if (!empty($allowedMonitors)) { + $mon_options = array('Event.MonitorId' => $allowedMonitors); + } else { + $mon_options=''; + } if ($this->request->params['named']) { $this->FilterComponent = $this->Components->load('Filter'); @@ -81,7 +77,6 @@ public function beforeFilter() { //$thumbData = $this->createThumbnail($value['Event']['Id']); $thumbData = ""; $events[$key]['thumbData'] = $thumbData; - } $this->set(compact('events')); diff --git a/web/api/app/Controller/MonitorsController.php b/web/api/app/Controller/MonitorsController.php index a0a4c8c6b..2785d2ffb 100644 --- a/web/api/app/Controller/MonitorsController.php +++ b/web/api/app/Controller/MonitorsController.php @@ -35,22 +35,24 @@ public function beforeFilter() { * @return void */ public function index() { - $this->Monitor->recursive = 0; - $allowedMonitors=preg_split ('@,@', $this->Session->Read('allowedMonitors'),NULL, PREG_SPLIT_NO_EMPTY); + $this->Monitor->recursive = 0; - if (!empty($allowedMonitors)) - { - $options = array('conditions'=>array('Monitor.Id'=> $allowedMonitors)); + if ($this->request->params['named']) { + $this->FilterComponent = $this->Components->load('Filter'); + $conditions = $this->FilterComponent->buildFilter($this->request->params['named']); + } else { + $conditions = array(); } - else - { - $options=''; + + $allowedMonitors=preg_split ('@,@', $this->Session->Read('allowedMonitors'),NULL, PREG_SPLIT_NO_EMPTY); + if (!empty($allowedMonitors)) { + $conditions['Monitor.Id' ] = $allowedMonitors; } - $monitors = $this->Monitor->find('all',$options); - $this->set(array( - 'monitors' => $monitors, - '_serialize' => array('monitors') - )); + $monitors = $this->Monitor->find('all',array('conditions'=>$conditions)); + $this->set(array( + 'monitors' => $monitors, + '_serialize' => array('monitors') + )); } /**