Ejemplo n.º 1
0
 public function save(EntityInterface $entity, $id = null)
 {
     $params = [];
     $params['body'] = $entity->toArray();
     $params['index'] = static::getIndex();
     $params['type'] = static::getType();
     $params['id'] = $entity->getId();
     $ret = $this->client->index($params);
     if ($ret['created']) {
         return true;
     } else {
         throw new \Exception('Could not create booking');
     }
 }
Ejemplo n.º 2
0
 /**
  * Update the entity.
  *
  * @param EntityInterface $entity
  * @param $id
  */
 public function update(EntityInterface $entity, $id)
 {
     $update = function () use($entity) {
         $sql = 'UPDATE ' . $this->table() . ' SET ';
         $sep = null;
         foreach ($entity->toArray() as $key => $value) {
             $sql .= $sep . $key . ' = ' . '?';
             $sep = ', ';
         }
         $sql .= ' WHERE id = ?';
         return rtrim(trim($sql), ',');
     };
     $values = $entity->toArray() + array('id' => $id);
     $this->execute($update(), array_values($values));
 }