Example #1
0
 /**
  * @return integer
  */
 public function put()
 {
     if (null === $this->identifier) {
         throw new Exception('Identifier not found.');
     }
     $fields = array();
     $update = $this->properties[$this->identifier]->has();
     $return = 0;
     foreach ($this->properties as $name => $instance) {
         if (!is_subclass_of($instance, 'Property')) {
             continue;
         }
         if ($instance instanceof PropertyIdentifier) {
             continue;
         }
         $fields[$name] = $instance->get();
     }
     if ($update) {
         $return = $affected = $this->db->update($this->table, $fields, array($this->identifier => $this->properties[$this->identifier]->get()));
     } else {
         $return = $inserted = $this->db->insert($this->table, $fields);
         if ($inserted) {
             $this->properties[$this->identifier]->set($inserted);
         }
     }
     $this->hash = Model::hash($this->properties);
     return $return;
 }