zoneminder/web/api/app/Controller/ZonePresetsController.php

101 lines
2.6 KiB
PHP
Raw Normal View History

2015-06-11 10:58:58 +08:00
<?php
App::uses('AppController', 'Controller');
/**
* ZonePresets Controller
*
* @property ZonePreset $ZonePreset
* @property PaginatorComponent $Paginator
*/
class ZonePresetsController extends AppController {
2018-07-25 04:41:09 +08:00
/**
* Components
*
* @var array
*/
public $components = array('RequestHandler');
2015-06-11 10:58:58 +08:00
2018-07-25 04:41:09 +08:00
/**
* index method
*
* @return void
*/
public function index() {
$zonePresets = $this->ZonePreset->find('all');
$this->set(array(
'zonePresets' => $zonePresets,
'_serialize' => array('zonePresets')
));
}
2015-06-11 10:58:58 +08:00
2018-07-25 04:41:09 +08:00
/**
* 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));
}
2015-06-11 10:58:58 +08:00
2018-07-25 04:41:09 +08:00
/**
* 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'));
}
}
}
2015-06-11 10:58:58 +08:00
2018-07-25 04:41:09 +08:00
/**
* 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);
}
}
2015-06-11 10:58:58 +08:00
2018-07-25 04:41:09 +08:00
/**
* 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'));
}
}
} // end class ZonePresetsController