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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

105 lines
2.3 KiB
PHP
Raw Normal View History

2014-11-16 02:05:53 +08:00
<?php
App::uses('AppController', 'Controller');
/**
* Logs Controller
*
* @property Log $Log
* @property PaginatorComponent $Paginator
*/
class LogsController extends AppController {
/**
* Components
*
* @var array
*/
2015-06-11 10:58:58 +08:00
public $components = array('Paginator', 'RequestHandler');
public $paginate = array(
'limit' => 100,
'order' => array( 'Log.TimeKey' => 'asc' ),
'paramType' => 'querystring'
);
2014-11-16 02:05:53 +08:00
/**
* index method
*
* @return void
*/
public function index() {
2015-06-11 10:58:58 +08:00
$this->Log->recursive = -1;
$this->Paginator->settings = $this->paginate;
$logs = $this->Paginator->paginate('Log');
$this->set(compact('logs'));
2014-11-16 02:05:53 +08:00
}
/**
* view method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function view($id = null) {
if (!$this->Log->exists($id)) {
throw new NotFoundException(__('Invalid log'));
}
$options = array('conditions' => array('Log.' . $this->Log->primaryKey => $id));
$this->set('log', $this->Log->find('first', $options));
}
/**
* add method
*
* @return void
*/
public function add() {
if ($this->request->is('post')) {
$this->Log->create();
if ($this->Log->save($this->request->data)) {
return $this->flash(__('The log has been saved.'), array('action' => 'index'));
}
}
}
/**
* edit method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function edit($id = null) {
if (!$this->Log->exists($id)) {
throw new NotFoundException(__('Invalid log'));
}
if ($this->request->is(array('post', 'put'))) {
if ($this->Log->save($this->request->data)) {
return $this->flash(__('The log has been saved.'), array('action' => 'index'));
}
} else {
$options = array('conditions' => array('Log.' . $this->Log->primaryKey => $id));
$this->request->data = $this->Log->find('first', $options);
}
}
/**
* delete method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function delete($id = null) {
$this->Log->id = $id;
if (!$this->Log->exists()) {
throw new NotFoundException(__('Invalid log'));
}
$this->request->allowMethod('post', 'delete');
if ($this->Log->delete()) {
return $this->flash(__('The log has been deleted.'), array('action' => 'index'));
} else {
return $this->flash(__('The log could not be deleted. Please, try again.'), array('action' => 'index'));
}
}}