Ejemplo n.º 1
0
 public function delete()
 {
     unlink(realpath($this->path));
     $dbcnx = ORM::get_dbcnx();
     $q = 'update ' . $this->table . ' set deleted = 1 where id = :' . $this->id_column;
     $stmt = $dbcnx->prepare($q);
     $stmt->execute(array(':' . $this->id_column => $this->data['id']));
 }
Ejemplo n.º 2
0
 public function save($do_validate = true)
 {
     if ($do_validate && !$this->validate()) {
         return false;
     }
     $dbcnx = ORM::get_dbcnx();
     $columns = array_diff(array_keys($this->attr), array($this->id_column));
     foreach ($columns as $col) {
         $values[':' . $col] = $this->data[$col];
     }
     if ($this->data[$this->id_column] === null) {
         $q = 'insert into ' . $this->table . ' (' . join(', ', $columns) . ') VALUES (' . join(', ', array_keys($values)) . ')';
     } else {
         $values[':' . $this->id_column] = $this->data[$this->id_column];
         $q = 'update ' . $this->table . ' set ';
         foreach ($columns as $col) {
             $q .= $col . ' = :' . $col . ',';
         }
         $q = substr($q, 0, -1) . ' where ' . $this->id_column . ' = :' . $this->id_column;
     }
     $stmt = $dbcnx->prepare($q);
     $stmt->execute($values);
     return true;
 }