Merge pull request #877 from pliablepixels/799-api-improvements

799 api improvements
This commit is contained in:
Isaac Connor 2015-06-11 09:06:31 -04:00
commit bc5ae78e79
4 changed files with 118 additions and 1 deletions

View File

@ -32,6 +32,10 @@
Router::mapResources('logs');
Router::mapResources('states');
Router::mapResources('zonepresets');
/* Add new API to retrieve camera controls - for PTZ */
/* refer to https://github.com/ZoneMinder/ZoneMinder/issues/799#issuecomment-105233112 */
Router::mapResources('controls');
Router::parseExtensions();
/**

View File

@ -0,0 +1,59 @@
<?php
App::uses('AppController', 'Controller');
/**
* Controls Controller
*
* @property Control $Control
* @property PaginatorComponent $Paginator
*/
/*
We need a control API to get the PTZ parameters associated with a monitor
The monitor API returns a control ID which we then need to use to construct
an appropriate PTZ command to control PTZ operations
https://github.com/ZoneMinder/ZoneMinder/issues/799#issuecomment-105233112
*/
class ControlsController extends AppController {
/**
* Components
*
* @var array
*/
public $components = array('Paginator', 'RequestHandler');
/**
* index method
*
* @return void
*/
public function index() {
$this->Control->recursive = 0;
$controls = $this->Control->find('all');
$this->set(array(
'controls' => $controls,
'_serialize' => array('controls')
));
}
/**
* view method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function view($id = null) {
if (!$this->Control->exists($id)) {
throw new NotFoundException(__('Invalid control'));
}
$options = array('conditions' => array('Control.' . $this->Control->primaryKey => $id));
$control = $this->Control->find('first', $options);
$this->set(array(
'control' => $control,
'_serialize' => array('control')
));
}
}

View File

@ -0,0 +1,54 @@
<?php
App::uses('AppModel', 'Model');
/**
* Control Model
* For PTZ table access via APIs
* https://github.com/ZoneMinder/ZoneMinder/issues/799#issuecomment-105233112
*
* @property Event $Event
* @property Zone $Zone
*/
class Control extends AppModel {
/**
* Use table
*
* @var mixed False or table name
*/
public $useTable = 'Controls';
/**
* Primary key field
*
* @var string
*/
public $primaryKey = 'Id';
/**
* Display field
*
* @var string
*/
public $displayField = 'Name';
public $recursive = -1;
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'Id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
);
}

@ -1 +1 @@
Subproject commit 813857bb220ac8858c1dd89f11b086a7d06e70d5
Subproject commit 0e7910cfcc19f97ca05fec97afcdb4701d4e76c9