예제 #1
0
 public function save()
 {
     if (count($this->updates) < 1 && !$this->tags->updates()) {
         throw new DBException('no changes');
     }
     if (is_null($this->id)) {
         if (count($this->updates) > 1) {
             $fields = implode(',', array_keys($this->updates));
             $values = implode("','", $this->updates);
         } else {
             $fields = key($this->updates);
             $values = $this->updates[0];
         }
         $sql = sprintf("INSERT INTO entries (%s,date,views) VALUES \n\t\t\t\t\t('%s',UNIX_TIMESTAMP(),0)", $fields, $values);
         if (!$this->db->query($sql)) {
             throw new DBException('error in insert query ' . $sql);
         }
         $this->id = $this->db->insert_id;
         $update = false;
     } else {
         if (count($this->updates) > 0) {
             foreach ($this->updates as $key => $val) {
                 $updates[] = $key . "='" . $val . "'";
                 update_hook($this->id, $key, $this->data[$key], $val);
             }
             $sql = sprintf('UPDATE entries SET %s WHERE id=%d', implode(',', $updates), $this->id);
             if (!$this->db->query($sql)) {
                 throw new DBException('error in update query');
             }
         }
         $update = true;
     }
     if (!is_null($this->tags)) {
         $this->tags->save($update);
     }
 }
예제 #2
0
 public function save($update = true)
 {
     foreach ($this->add as $tag) {
         $this->associate($tag);
     }
     foreach ($this->del as $tag) {
         $this->disassociate($tag);
     }
     if ($update) {
         update_hook($this->id, 'tags', $this->new_string, $this->old_string);
     }
 }