diff --git a/api/app/Controller/MonitorsController.php b/api/app/Controller/MonitorsController.php new file mode 100644 index 000000000..6a0114e0c --- /dev/null +++ b/api/app/Controller/MonitorsController.php @@ -0,0 +1,101 @@ +Monitor->recursive = 0; + $monitors = $this->Monitor->find('all'); + $this->set(array( + 'monitors' => $monitors, + '_serialize' => array('monitors') + )); + } + +/** + * view method + * + * @throws NotFoundException + * @param string $id + * @return void + */ + public function view($id = null) { + if (!$this->Monitor->exists($id)) { + throw new NotFoundException(__('Invalid monitor')); + } + $options = array('conditions' => array('Monitor.' . $this->Monitor->primaryKey => $id)); + $this->set('monitor', $this->Monitor->find('first', $options)); + } + +/** + * add method + * + * @return void + */ + public function add() { + if ($this->request->is('post')) { + $this->Monitor->create(); + if ($this->Monitor->save($this->request->data)) { + return $this->flash(__('The monitor has been saved.'), array('action' => 'index')); + } + } + } + +/** + * edit method + * + * @throws NotFoundException + * @param string $id + * @return void + */ + public function edit($id = null) { + if (!$this->Monitor->exists($id)) { + throw new NotFoundException(__('Invalid monitor')); + } + if ($this->request->is(array('post', 'put'))) { + if ($this->Monitor->save($this->request->data)) { + return $this->flash(__('The monitor has been saved.'), array('action' => 'index')); + } + } else { + $options = array('conditions' => array('Monitor.' . $this->Monitor->primaryKey => $id)); + $this->request->data = $this->Monitor->find('first', $options); + } + } + +/** + * delete method + * + * @throws NotFoundException + * @param string $id + * @return void + */ + public function delete($id = null) { + $this->Monitor->id = $id; + if (!$this->Monitor->exists()) { + throw new NotFoundException(__('Invalid monitor')); + } + $this->request->allowMethod('post', 'delete'); + if ($this->Monitor->delete()) { + return $this->flash(__('The monitor has been deleted.'), array('action' => 'index')); + } else { + return $this->flash(__('The monitor could not be deleted. Please, try again.'), array('action' => 'index')); + } + }}