diff --git a/web/api/app/Config/routes.php b/web/api/app/Config/routes.php index 148f2a581..d41c2fd9e 100755 --- a/web/api/app/Config/routes.php +++ b/web/api/app/Config/routes.php @@ -31,6 +31,7 @@ Router::mapResources('host'); Router::mapResources('logs'); Router::mapResources('states'); + Router::mapResources('zonepresets'); Router::parseExtensions(); /** diff --git a/web/api/app/Controller/ZonePresetsController.php b/web/api/app/Controller/ZonePresetsController.php new file mode 100644 index 000000000..b89a6c75d --- /dev/null +++ b/web/api/app/Controller/ZonePresetsController.php @@ -0,0 +1,99 @@ +ZonePreset->find('all'); + $this->set(array( + 'zonePresets' => $zonePresets, + '_serialize' => array('zonePresets') + )); + } + +/** + * view method + * + * @throws NotFoundException + * @param string $id + * @return void + */ + public function view($id = null) { + if (!$this->ZonePreset->exists($id)) { + throw new NotFoundException(__('Invalid zone preset')); + } + $options = array('conditions' => array('ZonePreset.' . $this->ZonePreset->primaryKey => $id)); + $this->set('zonePreset', $this->ZonePreset->find('first', $options)); + } + +/** + * add method + * + * @return void + */ + public function add() { + if ($this->request->is('post')) { + $this->ZonePreset->create(); + if ($this->ZonePreset->save($this->request->data)) { + return $this->flash(__('The zone preset has been saved.'), array('action' => 'index')); + } + } + } + +/** + * edit method + * + * @throws NotFoundException + * @param string $id + * @return void + */ + public function edit($id = null) { + if (!$this->ZonePreset->exists($id)) { + throw new NotFoundException(__('Invalid zone preset')); + } + if ($this->request->is(array('post', 'put'))) { + if ($this->ZonePreset->save($this->request->data)) { + return $this->flash(__('The zone preset has been saved.'), array('action' => 'index')); + } + } else { + $options = array('conditions' => array('ZonePreset.' . $this->ZonePreset->primaryKey => $id)); + $this->request->data = $this->ZonePreset->find('first', $options); + } + } + +/** + * delete method + * + * @throws NotFoundException + * @param string $id + * @return void + */ + public function delete($id = null) { + $this->ZonePreset->id = $id; + if (!$this->ZonePreset->exists()) { + throw new NotFoundException(__('Invalid zone preset')); + } + $this->request->allowMethod('post', 'delete'); + if ($this->ZonePreset->delete()) { + return $this->flash(__('The zone preset has been deleted.'), array('action' => 'index')); + } else { + return $this->flash(__('The zone preset could not be deleted. Please, try again.'), array('action' => 'index')); + } + }} diff --git a/web/api/app/Model/ZonePreset.php b/web/api/app/Model/ZonePreset.php new file mode 100644 index 000000000..611f1094c --- /dev/null +++ b/web/api/app/Model/ZonePreset.php @@ -0,0 +1,30 @@ +