Skip to content

Commit

Permalink
Resource acquisition: multiple ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
veggiematts committed Jun 21, 2017
1 parent ee31a58 commit 801c751
Show file tree
Hide file tree
Showing 66 changed files with 1,793 additions and 1,129 deletions.
13 changes: 10 additions & 3 deletions resources/admin/classes/common/DatabaseObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function delete() {
return $this->db->processQuery($query);
}

public function save() {
public function save($new = 0) {
$pairs = array();
foreach (array_keys($this->attributeNames) as $attributeName) {
$value = $this->attributes[$attributeName];
Expand All @@ -229,19 +229,26 @@ public function save() {
array_push($pairs, $pair);
}
$set = implode(', ', $pairs);
if (isset($this->primaryKey)) {
if (($new == 0) && isset($this->primaryKey)) {
// Update object
$query = "UPDATE `$this->tableName` SET $set WHERE `$this->primaryKeyName` = '$this->primaryKey'";
//error_log($query);
//echo $query;
$this->db->processQuery($query);
} else {
// Insert object
$query = "INSERT INTO `$this->tableName` SET $set";
//echo $query;
//error_log($query);
$this->primaryKey = $this->db->processQuery($query);
if ($new) return $this->primaryKey;
}
}

public function saveAsNew() {
return $this->save(1);
}


public function all() {
$query = "SELECT * FROM `$this->tableName` ORDER BY 2, 1";
Expand Down Expand Up @@ -309,4 +316,4 @@ public function load() {

}

?>
?>
Loading

0 comments on commit 801c751

Please sign in to comment.