Exemplo n.º 1
0
 /**
  * Perform a remote insert request using the REST "post" method
  *
  * @return Integer the ID of the inserted model object, or zero on failure
  */
 public function insert()
 {
     if (!is_object($this->object)) {
         return 0;
     }
     if ($this->object->id) {
         return 0;
     }
     if (!$this->is_validated()) {
         return 0;
     }
     $url = $this->secure_url();
     $data = array($this->get_class() => $this->object->data());
     $data[self::DB] = $this->get_database();
     $this->response = REST::post($url, $data, $this->type);
     if (is_null($this->response)) {
         return 0;
     }
     $id = $this->get_id_from_response();
     if (is_numeric($id)) {
         $this->object->id = $id;
     }
     $this->check_response();
     $this->object->changed = array();
     return $id;
 }