2014-04-23 11:14:15 +08:00
|
|
|
<?php
|
2019-02-27 00:28:56 +08:00
|
|
|
require_once __DIR__ .'/../../../includes/Event.php';
|
|
|
|
|
2014-04-23 11:14:15 +08:00
|
|
|
App::uses('AppModel', 'Model');
|
|
|
|
/**
|
|
|
|
* Event Model
|
|
|
|
*
|
|
|
|
* @property Monitor $Monitor
|
|
|
|
* @property Frame $Frame
|
|
|
|
*/
|
|
|
|
class Event extends AppModel {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use table
|
|
|
|
*
|
|
|
|
* @var mixed False or table name
|
|
|
|
*/
|
|
|
|
public $useTable = 'Events';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Primary key field
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $primaryKey = 'Id';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display field
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $displayField = 'Name';
|
|
|
|
|
|
|
|
|
|
|
|
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
|
|
|
|
|
|
|
/**
|
|
|
|
* belongsTo associations
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $belongsTo = array(
|
|
|
|
'Monitor' => array(
|
|
|
|
'className' => 'Monitor',
|
|
|
|
'foreignKey' => 'MonitorId',
|
|
|
|
'conditions' => '',
|
|
|
|
'fields' => '',
|
|
|
|
'order' => ''
|
2018-05-08 05:06:48 +08:00
|
|
|
),
|
|
|
|
'Storage' => array(
|
|
|
|
'className' => 'Storage',
|
|
|
|
'joinTable' => 'Storage',
|
|
|
|
'foreignKey' => 'StorageId',
|
|
|
|
'conditions' => '',
|
|
|
|
'fields' => '',
|
|
|
|
'order' => ''
|
|
|
|
)
|
2014-04-23 11:14:15 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hasMany associations
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $hasMany = array(
|
|
|
|
'Frame' => array(
|
|
|
|
'className' => 'Frame',
|
|
|
|
'foreignKey' => 'EventId',
|
2014-04-25 10:24:46 +08:00
|
|
|
'dependent' => true,
|
2014-04-23 11:14:15 +08:00
|
|
|
'conditions' => '',
|
|
|
|
'fields' => '',
|
|
|
|
'order' => '',
|
|
|
|
'limit' => '',
|
|
|
|
'offset' => '',
|
2015-10-01 03:53:23 +08:00
|
|
|
'exclusive' => 'true',
|
2014-04-23 11:14:15 +08:00
|
|
|
'finderQuery' => '',
|
|
|
|
'counterQuery' => ''
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2017-12-05 04:52:16 +08:00
|
|
|
/**
|
|
|
|
* * * hasMany associations
|
|
|
|
* * *
|
|
|
|
* * * @var array
|
|
|
|
* * */
|
|
|
|
public $hasAndBelongsToMany = array(
|
|
|
|
'Group' => array(
|
|
|
|
'className' => 'Group',
|
|
|
|
'joinTable' => 'Groups_Monitors',
|
|
|
|
'foreignKey' => 'MonitorId',
|
2017-12-20 07:09:41 +08:00
|
|
|
'associationForeignKey' => 'MonitorId',
|
2017-12-05 04:52:16 +08:00
|
|
|
'unique' => true,
|
|
|
|
'dependent' => false,
|
2017-12-20 07:09:41 +08:00
|
|
|
'conditions' => '',
|
2017-12-05 04:52:16 +08:00
|
|
|
'fields' => '',
|
|
|
|
'order' => '',
|
|
|
|
'limit' => '',
|
|
|
|
'offset' => '',
|
|
|
|
'exclusive' => '',
|
|
|
|
'finderQuery' => '',
|
|
|
|
'counterQuery' => ''
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2019-11-30 02:48:20 +08:00
|
|
|
public $actsAs = array(
|
|
|
|
'CakePHP-Enum-Behavior.Enum' => array(
|
|
|
|
'Orientation' => array('ROTATE_0','ROTATE_90','ROTATE_180','ROTATE_270','FLIP_HORI','FLIP_VERT'),
|
|
|
|
'Scheme' => array('Deep','Medium','Shallow')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-02-27 00:28:56 +08:00
|
|
|
public function Relative_Path() {
|
2019-04-01 22:11:56 +08:00
|
|
|
$Event = new ZM\Event($this->id);
|
2019-02-27 00:28:56 +08:00
|
|
|
return $Event->Relative_Path();
|
2018-05-08 05:06:48 +08:00
|
|
|
} // end function Relative_Path()
|
|
|
|
|
2019-04-01 22:11:56 +08:00
|
|
|
public function Path() {
|
|
|
|
$Event = new ZM\Event($this->id);
|
2019-02-27 00:28:56 +08:00
|
|
|
return $Event->Path();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Link_Path() {
|
2019-04-01 22:11:56 +08:00
|
|
|
$Event = new ZM\Event($this->id);
|
2019-02-27 00:28:56 +08:00
|
|
|
return $Event->Link_Path();
|
|
|
|
}
|
2018-05-08 05:06:48 +08:00
|
|
|
|
2018-05-09 00:22:20 +08:00
|
|
|
public function fileExists($event) {
|
2018-05-08 05:06:48 +08:00
|
|
|
//$data = $this->findById($id);
|
|
|
|
//return $data['Event']['dataset_filename'];
|
2018-05-09 00:22:20 +08:00
|
|
|
$storage = $this->Storage->findById($event['StorageId']);
|
2018-05-08 05:06:48 +08:00
|
|
|
|
|
|
|
if ( $event['DefaultVideo'] ) {
|
2019-04-01 22:11:56 +08:00
|
|
|
if ( file_exists($this->Path().'/'.$event['DefaultVideo']) ) {
|
2018-05-08 05:06:48 +08:00
|
|
|
return 1;
|
|
|
|
} else {
|
2019-04-01 22:11:56 +08:00
|
|
|
ZM\Logger::Debug('File does not exist at ' . $this->Path().'/'.$event['DefaultVideo'] );
|
2018-05-08 05:06:48 +08:00
|
|
|
}
|
|
|
|
} else {
|
2019-04-01 22:11:56 +08:00
|
|
|
ZM\Logger::Debug('No DefaultVideo in Event' . $this->Event);
|
2018-05-08 05:06:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2018-05-09 00:22:20 +08:00
|
|
|
} // end function fileExists($event)
|
|
|
|
|
|
|
|
public function fileSize($event) {
|
2019-04-01 22:11:56 +08:00
|
|
|
return filesize($this->Path().'/'.$event['DefaultVideo']);
|
2018-05-08 05:06:48 +08:00
|
|
|
}
|
2019-03-20 05:26:20 +08:00
|
|
|
|
2019-02-27 00:28:56 +08:00
|
|
|
public function beforeDelete($cascade=true) {
|
2019-03-20 05:26:20 +08:00
|
|
|
$Event = new ZM\Event($this->id);
|
|
|
|
$Event->delete();
|
|
|
|
// Event->delete() will do it all, so cake doesn't have to do anything.
|
|
|
|
return false;
|
2019-02-27 00:28:56 +08:00
|
|
|
} // end function afterDelete
|
2014-04-23 11:14:15 +08:00
|
|
|
}
|