2016-05-06 03:33:28 +08:00
|
|
|
<?php
|
|
|
|
require_once( 'database.php' );
|
|
|
|
require_once( 'Event.php' );
|
|
|
|
|
|
|
|
class Frame {
|
2017-10-11 03:11:59 +08:00
|
|
|
public function __construct( $IdOrRow=null ) {
|
2016-05-06 03:33:28 +08:00
|
|
|
$row = NULL;
|
|
|
|
if ( $IdOrRow ) {
|
2016-12-09 04:58:00 +08:00
|
|
|
if ( is_integer( $IdOrRow ) or ctype_digit($IdOrRow) ) {
|
2016-05-06 03:33:28 +08:00
|
|
|
$row = dbFetchOne( 'SELECT * FROM Frames WHERE Id=?', NULL, array( $IdOrRow ) );
|
|
|
|
if ( ! $row ) {
|
|
|
|
Error("Unable to load Frame record for Id=" . $IdOrRow );
|
|
|
|
}
|
|
|
|
} elseif ( is_array( $IdOrRow ) ) {
|
|
|
|
$row = $IdOrRow;
|
|
|
|
} else {
|
|
|
|
Error("Unknown argument passed to Frame Constructor ($IdOrRow)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-11 03:11:59 +08:00
|
|
|
if ( $row ) {
|
|
|
|
foreach ($row as $k => $v) {
|
|
|
|
$this->{$k} = $v;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Error("No row for Frame " . $IdOrRow );
|
2016-05-06 03:33:28 +08:00
|
|
|
}
|
2017-10-11 03:11:59 +08:00
|
|
|
} # end if isset($IdOrRow)
|
2016-05-06 03:33:28 +08:00
|
|
|
} // end function __construct
|
2017-05-31 01:47:30 +08:00
|
|
|
|
2016-05-06 03:33:28 +08:00
|
|
|
public function Storage() {
|
|
|
|
return $this->Event()->Storage();
|
|
|
|
}
|
2017-05-31 01:47:30 +08:00
|
|
|
|
2016-05-06 03:33:28 +08:00
|
|
|
public function Event() {
|
|
|
|
return new Event( $this->{'EventId'} );
|
|
|
|
}
|
|
|
|
public function __call( $fn, array $args){
|
2017-10-18 01:09:14 +08:00
|
|
|
if ( count( $args ) ) {
|
|
|
|
$this->{$fn} = $args[0];
|
|
|
|
}
|
|
|
|
if ( array_key_exists( $fn, $this ) ) {
|
2016-05-06 03:33:28 +08:00
|
|
|
return $this->{$fn};
|
2017-10-18 01:09:14 +08:00
|
|
|
|
|
|
|
$backTrace = debug_backtrace();
|
|
|
|
$file = $backTrace[1]['file'];
|
|
|
|
$line = $backTrace[1]['line'];
|
|
|
|
Warning( "Unknown function call Frame->$fn from $file:$line" );
|
2016-05-06 03:33:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-13 03:14:51 +08:00
|
|
|
public function getImageSrc( $show='capture' ) {
|
2017-05-31 01:47:30 +08:00
|
|
|
|
|
|
|
return $_SERVER['PHP_SELF'].'?view=image&fid='.$this->{'FrameId'}.'&eid='.$this->{'EventId'}.'&show='.$show;
|
|
|
|
#return $_SERVER['PHP_SELF'].'?view=image&fid='.$this->{'Id'}.'&show='.$show.'&filename='.$this->Event()->MonitorId().'_'.$this->{'EventId'}.'_'.$this->{'FrameId'}.'.jpg';
|
2016-05-06 03:33:28 +08:00
|
|
|
} // end function getImageSrc
|
|
|
|
|
|
|
|
public static function find( $parameters = array(), $limit = NULL ) {
|
|
|
|
$sql = 'SELECT * FROM Frames';
|
|
|
|
$values = array();
|
|
|
|
if ( sizeof($parameters) ) {
|
|
|
|
$sql .= ' WHERE ' . implode( ' AND ', array_map(
|
|
|
|
function($v){ return $v.'=?'; },
|
|
|
|
array_keys( $parameters )
|
|
|
|
) );
|
|
|
|
$values = array_values( $parameters );
|
|
|
|
}
|
|
|
|
if ( $limit ) {
|
2016-12-09 04:58:00 +08:00
|
|
|
if ( is_integer( $limit ) or ctype_digit( $limit ) ) {
|
2016-12-09 02:37:23 +08:00
|
|
|
$sql .= ' LIMIT ' . $limit;
|
|
|
|
} else {
|
|
|
|
$backTrace = debug_backtrace();
|
|
|
|
$file = $backTrace[1]['file'];
|
|
|
|
$line = $backTrace[1]['line'];
|
|
|
|
Error("Invalid value for limit($limit) passed to Frame::find from $file:$line");
|
|
|
|
return;
|
|
|
|
}
|
2016-05-06 03:33:28 +08:00
|
|
|
}
|
|
|
|
$results = dbFetchAll( $sql, NULL, $values );
|
|
|
|
if ( $results ) {
|
|
|
|
return array_map( function($id){ return new Frame($id); }, $results );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function find_one( $parameters = array() ) {
|
|
|
|
$results = Frame::find( $parameters, 1 );
|
|
|
|
if ( ! sizeof( $results ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return $results[0];
|
|
|
|
}
|
|
|
|
} # end class
|
|
|
|
?>
|