/** * @covers Zend\Db\TableGateway\AbstractTableGateway::update * @covers Zend\Db\TableGateway\AbstractTableGateway::updateWith * @covers Zend\Db\TableGateway\AbstractTableGateway::executeUpdate */ public function testUpdate() { $mockUpdate = $this->mockSql->update(); // assert select::from() is called $mockUpdate->expects($this->once()) ->method('where') ->with($this->equalTo('id = 2')); $affectedRows = $this->table->update(array('foo' => 'bar'), 'id = 2'); $this->assertEquals(5, $affectedRows); }
public function update(array $data, $id) { $this->TableGateway->update($data, ['id' => $id]); return $id; }
/** * Update exists row * * @param mixed $object * @return int * @throws \Exception\BadMethodCallException */ public function update($object, $where = null) { $issetKey = is_array($object) ? isset($object[$this->keyName]) : isset($object->{$this->keyName}); if (!$where && !$issetKey) { throw new \Exception(sprintf('%s expects the provided object has key defined', __METHOD__)); } if (is_array($object)) { $id = $object[$this->keyName]; unset($object[$this->keyName]); $where = $where ? $where : array($this->keyName => $id); return parent::update($object, $where); } if (!is_callable(array($object, 'getArrayCopy'))) { throw new \BadMethodCallException(sprintf('%s expects the provided object to implement getArrayCopy()', __METHOD__)); } $preUpdateMethodName = $this->eventActions[self::PRE_UPDATE]; $postUpdateMethodName = $this->eventActions[self::POST_UPDATE]; if (method_exists($object, $preUpdateMethodName)) { $object->{$preUpdateMethodName}($this->getEventManager()); } $set = $object->getArrayCopy(); $id = $set[$this->keyName]; unset($set[$this->keyName]); $where = $where ? $where : array($this->keyName => $id); $res = parent::update($set, $where); if (method_exists($object, $postUpdateMethodName)) { $object->{$postUpdateMethodName}($this->getEventManager()); } return $res; }
/** * @covers Zend\Db\TableGateway\AbstractTableGateway::update * @covers Zend\Db\TableGateway\AbstractTableGateway::updateWith * @covers Zend\Db\TableGateway\AbstractTableGateway::executeUpdate */ public function testUpdateWithNoCriteria() { $mockUpdate = $this->mockSql->update(); $affectedRows = $this->table->update(array('foo' => 'bar')); $this->assertEquals(5, $affectedRows); }
/** * Met à jour un objet en base. * * @param mixed $mObject * @return int * @throws \Exception\BadMethodCallException */ public function update($mObject, $where = null) { $issetKey = is_array($mObject) ? isset($mObject[$this->nomCle]) : isset($mObject->{$this->nomCle}); if (!$where && !$issetKey) { throw new \Exception(sprintf('%s attend que l\'objet fournit est une clé de définit', __METHOD__)); } if (is_array($mObject)) { if (isset($mObject[$this->nomCle])) { $id = $mObject[$this->nomCle]; unset($mObject[$this->nomCle]); } $where = $where ? $where : array($this->nomCle => $id); return parent::update($mObject, $where); } if (!is_callable(array($mObject, 'getArrayCopy'))) { throw new \BadMethodCallException(sprintf('%s attend que l\'objet fournit implémente la méthode getArrayCopy()', __METHOD__)); } $preUpdateMethodName = $this->eventActions[self::PRE_UPDATE]; $postUpdateMethodName = $this->eventActions[self::POST_UPDATE]; if (method_exists($mObject, $preUpdateMethodName)) { $mObject->{$preUpdateMethodName}($this->getEventManager()); } $set = $mObject->getArrayCopy(); $id = $set[$this->nomCle]; unset($set[$this->nomCle]); $where = $where ? $where : array($this->nomCle => $id); $res = parent::update($set, $where); if (method_exists($mObject, $postUpdateMethodName)) { $mObject->{$postUpdateMethodName}($this->getEventManager()); } return $res; }
public function updateItem($data, $id) { $this->tableGatewayItems->update($data, ['id' => $id]); }
public function update($id, $data) { $hydrator = new ObjectProperty(); $data = $hydrator->extract($data); return $this->tableGateway->update($data, array('id' => $id)); }
public function updateStatus($id, $status) { $this->tableGateway->update(['status' => (int) $status], ['id' => (int) $id]); return $this->findById($id); }
public function update($id, $client) { $this->tableGateway->update((array) $client, ['id' => (int) $id]); return $this->findById($id); }
/** *update * *Wrapper for 'update' * -------------------- * Handle the insertion of model objects in addition to the traditional stuff you could pass into TableGateway's insert. * * * * *@param array|object $set *@param string $where * *@return int * * * */ public function update($set, $where = null) { if (is_object($set)) { // clear out 'id' if we need to $data = $set->toArray(); if (array_key_exists('id', $data)) { unset($data['id']); } return parent::update($set->toArray(), $where); } else { return parent::update($set, $where); } }