add Inserting when saving

This commit is contained in:
Isaac Connor 2017-10-30 16:29:13 -04:00
parent 01acd154f9
commit 97757ba6cd
1 changed files with 11 additions and 4 deletions

View File

@ -111,10 +111,17 @@ class MontageLayout {
$this->{$k} = $v;
}
}
$sql = 'UPDATE MontageLayouts SET '.implode(', ', array_map( function($field) {return $field.'=?';}, array_keys( $this->defaults ) ) ) . ' WHERE Id=?';
$values = array_map( function($field){return $this->{$field};}, $this->fields );
$values[] = $this->{'Id'};
$fields = array_keys( $this->defaults );
$values = null;
if ( $this->{'Id'} ) {
$sql = 'UPDATE MontageLayouts SET '.implode(', ', array_map( function($field) {return $field.'=?';}, $fields ) ) . ' WHERE Id=?';
$values = array_map( function($field){return $this->{$field};}, $fields );
$values[] = $this->{'Id'};
} else {
$sql = 'INSERT INTO MontageLayouts ('.implode( ',', $fields ).') VALUES ('.implode(',',array_map( function(){return '?';}, $fields ) ).')';
$values = array_map( function($field){return $this->{$field};}, $fields );
}
dbQuery( $sql, $values );
} // end function save