Check for setting of IdOrRow. When loading from db, using FETCH_CLASS, the constructor is called without arguments

This commit is contained in:
Isaac Connor 2015-12-15 11:12:21 -05:00
parent 010d7b3d64
commit c07c63cde6
1 changed files with 40 additions and 0 deletions

40
web/includes/Storage.php Normal file
View File

@ -0,0 +1,40 @@
<?php
require_once( 'database.php' );
class Storage {
public function __construct( $IdOrRow ) {
$row = NULL;
if ( isset($IdOrRow) ) {
if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) {
$row = dbFetchOne( 'SELECT * FROM Storage WHERE Id=?', NULL, array( $IdOrRow ) );
if ( ! $row ) {
Error("Unable to load Storage record for Id=" . $IdOrRow );
}
} elseif ( is_array( $IdOrRow ) ) {
$row = $IdOrRow;
}
}
if ( $row ) {
foreach ($row as $k => $v) {
$this->{$k} = $v;
}
} else {
$this->{'Name'} = '';
$this->{'Path'} = '';
}
}
public function Path() {
if ( isset( $this->{'Path'} ) and ( $this->{'Path'} != '' ) ) {
return $this->{'Path'};
}
return $this->{'Name'};
}
public function __call( $fn, array $args= NULL){
if(isset($this->{$fn})){
return $this->{$fn};
#array_unshift($args, $this);
#call_user_func_array( $this->{$fn}, $args);
}
}
}
?>