From 9c44f56f37d9b0defb8a396affd12f0bbcb1e276 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 7 May 2018 14:06:48 -0700 Subject: [PATCH] Add Storage to belongsTo. Implement Relative_Path and fileExists functions --- web/api/app/Model/Event.php | 41 ++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/web/api/app/Model/Event.php b/web/api/app/Model/Event.php index dd5cc0531..3eb78b9fe 100644 --- a/web/api/app/Model/Event.php +++ b/web/api/app/Model/Event.php @@ -44,7 +44,15 @@ class Event extends AppModel { 'conditions' => '', 'fields' => '', 'order' => '' - ) + ), + 'Storage' => array( + 'className' => 'Storage', + 'joinTable' => 'Storage', + 'foreignKey' => 'StorageId', + 'conditions' => '', + 'fields' => '', + 'order' => '' + ) ); /** @@ -92,4 +100,35 @@ class Event extends AppModel { ), ); + public function Relative_Path($event) { + $event_path = ''; + + if ( $event['Scheme'] == 'Deep' ) { + $event_path = $event['MonitorId'] .'/'.strftime('%y/%m/%d/%H/%M/%S', strtotime($event['StartTime'])); + } else if ( $event['Scheme'] == 'Medium' ) { + $event_path = $event['MonitorId'] .'/'.strftime('%Y-%m-%d', strtotime($event['StartTime'])) . '/'.$event['Id']; + } else { + $event_path = $event['MonitorId'] .'/'.$event['Id']; + } + + return $event_path; + } // end function Relative_Path() + + + public function fileExists( $event ) { + //$data = $this->findById($id); + //return $data['Event']['dataset_filename']; + $storage = $this->Storage->findById( $event['StorageId'] ); + + if ( $event['DefaultVideo'] ) { + if ( file_exists( $storage['Storage']['Path'].'/'.$this->Relative_Path($event).'/'.$event['DefaultVideo'] ) ) { + return 1; + } else { + Logger::Debug("FIle does not exist at " . $storage['Storage']['Path'].'/'.$this->Relative_Path($event).'/'.$event['DefaultVideo'] ); + } + } else { +Logger::Debug("No DefaultVideo in Event" . $this->Event); + return 0; + } + } }