/** * {@inheritDoc} */ protected function doUpdateModel($model) { if ($id = $this->getModelId($model)) { $this->tableGateway->update($this->tableGateway->getResultSetPrototype()->getHydrator()->extract($model), array("{$this->idField} = ?" => $id)); } else { $this->tableGateway->insert($this->tableGateway->getResultSetPrototype()->getHydrator()->extract($model)); } }
public function update($id, array $data) { $this->table->update($data, array($this->identifierName => $id)); $entity = $this->find($id); if (!$entity) { throw new \Exception("Entity not updated?"); } return $entity; }
/** * @param AbstractEntity $entity * @return $this */ public function persist(AbstractEntity $entity) { $data = $this->hydrator->extract($entity); if ($this->hasIdentity($entity)) { $this->gateway->update($data, ['id' => $entity->getId()]); } else { $this->gateway->insert($data); $entity->setId($this->gateway->getLastInsertValue()); } return $this; }
/** * @param AbstractModel $model */ protected function internalSave(AbstractModel $model) { $pKey = $this->getPrimaryKey(); if (isset($model->id)) { $this->tableGateway->update($model->toArray(), [$pKey => $model->{$pKey}]); } else { $this->tableGateway->insert($model->toArray()); $id = $this->tableGateway->getLastInsertValue(); $model->{$pKey} = $id; } }
public function saveCategory(Category $category) { $data = array('id_category' => $category->id_category, 'name' => $category->name, 'slug' => $category->slug); $id = (int) $category->id_category; if ($id == 0) { $this->tableGateway->insert($data); } elseif ($this->getCategoryById($id)) { $this->tableGateway->update($data, array('id_category = ?' => $id)); } else { throw new \Exception('Form id does not exist'); } }
/** * Saves an account to the db. If the id exists the given dataset will be updated * @param \Account\Model\Account $account * * @throws \Exception */ public function saveWarlog(Warlog $warlog) { $data = ['wins' => $warlog->getWins(), 'losses' => $warlog->getLosses(), 'draws' => $warlog->getDraws()]; if (!$warlog->getId()) { $this->tableGateway->insert($data); } else { if ($this->getWarlog()) { $this->tableGateway->update($data, ['id' => $warlog->getId()]); } else { throw new \Exception('Account id does not exist'); } } }
public function saveForm(Form $form) { $data = array('name' => $form->name); $id = (int) $form->id; if ($id == 0) { $this->tableGateway->insert($data); } else { if ($this->getForm($id)) { $this->tableGateway->update($data, array('id' => $id)); } else { throw new \Exception('Form id does not exist'); } } }
/** * Saves the given NewsCategory object to the db * * @param NewsCategory * @throws \Exception */ public function saveNewsCategory(NewsCategory $nc) { $data = ['name' => $nc->getName()]; $id = (int) $nc->getId(); if ($id == 0) { $this->tableGateway->insert($data); } else { if ($this->getNewsCategoryBy(['id' => $id])) { $this->tableGateway->update($data, ['id' => $id]); } else { throw new \Ȩxception('NewsCategory id does not exist'); } } }
/** * Saves the given object ot the db * @param Warstatus $warstatus * @throws \Exception */ public function saveWarstatus(Warstatus $warstatus) { $data = $warstatus->getArrayCopy(); if ($warstatus->getId() == 0) { throw new \Exception('Id needed to save a warstatus'); } else { if ($this->getWarstatus((int) $warstatus->getId())) { $this->tableGateway->update($data, ['id' => (int) $warstatus->getId()]); } else { $data['id'] = $warstatus->getId(); $this->tableGateway->insert($data); } } }
/** * Saves the given media object to the db * * @param \Media\Model\Media $media * * @throws \Exception */ public function saveMedia(Media $media) { $data = ['account_id' => $media->getAccountId(), 'title' => $media->getTitle(), 'url' => $media->getUrl(), 'date_posted' => $media->getDatePosted()]; $id = (int) $media->getId(); if ($id == 0) { $this->tableGateway->insert($data); } else { if ($this->getMedia($id)) { $this->tableGateway->update($data, ['id' => $id]); } else { throw new \Exception('Media id does not exist'); } } }
public function saveCore(Core $core) { $data = array('name' => $core->name); $id = (int) $core->id; if ($id == 0) { $this->tableGateway->insert($data); } else { if ($this->getCore($id)) { $data['last_updated'] = $core->lastUpdated; $this->tableGateway->update($data, array('id' => $id)); } else { throw new \Exception('Core id does not exist'); } } }
protected function _update($itemData, $createIfAbsent = false) { $adapter = $this->dbTable->getAdapter(); $identifier = $this->getIdentifier(); if (!isset($itemData[$identifier])) { throw new DataStoreException('Item must has primary key'); } $id = $itemData[$identifier]; $this->checkIdentifierType($id); $queryStr = 'SELECT ' . Select::SQL_STAR . ' FROM ' . $adapter->platform->quoteIdentifier($this->dbTable->getTable()) . ' WHERE ' . $adapter->platform->quoteIdentifier($identifier) . ' = ?' . ' FOR UPDATE'; //is row with this index exist? $rowset = $adapter->query($queryStr, array($id)); $isExist = !is_null($rowset->current()); $result = []; switch (true) { case !$isExist && !$createIfAbsent: throw new DataStoreException('Can\'t update item with "id" = ' . $id); case !$isExist && $createIfAbsent: $this->dbTable->insert($itemData); $result = $itemData; break; case $isExist: unset($itemData[$identifier]); $this->dbTable->update($itemData, array($identifier => $id)); $rowset = $adapter->query($queryStr, array($id)); $result = $rowset->current()->getArrayCopy(); break; } return $result; }
public function update($set, $where) { if (!$where) { return []; } return $this->tableGateway->update($set, $where); }
public function updateSales($data = null) { $id = $data['id']; $data['sales_markup'] = preg_replace("|[\\s]+|s", " ", $data['sales_markup']); $data['sales_active'] = $data['sales_active'] == 'on' ? '1' : '0'; parent::update($data, array('id' => $id)); }
public function updateanywhere($mytable, array $data, $where) { $db = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'); $table = new TableGateway($mytable, $db); $results = $table->update($data, $where); return 1; }
/** * @covers Zend\Db\TableGateway\TableGateway::update */ public function testUpdate() { $mockUpdate = $this->mockSql->update(); // assert select::from() is called $mockUpdate->expects($this->once())->method('where')->with($this->equalTo('id = 2')); $this->table->update(array('foo' => 'bar'), 'id = 2'); }
/** * * @throws \Exception * @return number */ public function save($entity, $where = null) { // if $entity do not exists, return false if ($entity == false) { return false; } $table = $this->getTableGateway()->table; $columns = $this->getColumns(); foreach ($columns as $key => $value) { if (property_exists($entity, $value)) { $data[$value] = $entity->{$value}; } } // if id is set then also we need to update // create $where based on id in such a case try { if (!is_array($where)) { if ($data['id'] > 0) { $where = array("id" => $data['id']); $this->tableGateway->update($data, $where); return $data['id']; } else { // insert and return last ID $this->tableGateway->insert($data); return $this->tableGateway->lastInsertValue; } } else { $this->tableGateway->update($data, $where); return $data['id']; } } catch (\Exception $e) { die($e->getMessage()); } }
/** * @covers Zend\Db\TableGateway\TableGateway::update */ public function testUpdate() { $update = $this->getMock('Zend\\Db\\Sql\\Update'); // assert select::from() is called $update->expects($this->once())->method('where')->with($this->equalTo('foo')); $this->table->setSqlUpdate($update); $this->table->update(array('foo' => 'bar'), 'foo'); }
/** * @param Request $request * @param Response $response * @param $args * * @return ResponseInterface */ public function update(Request $request, Response $response, $args) { try { $result = $this->gateway->update($request->getParsedBody(), $this->getIdArray($args)); return $response->withJson(["result" => $result]); } catch (\Exception $e) { return $response->withStatus(400); } }
/** * Test * * @return void */ public function testReadWithLifetimeExpired() { $this->object->open('savepath', 'sessionname'); $id = '242'; $this->assertTrue($this->object->write($id, serialize($this->testArray))); $this->adapter->update(array('lifetime' => 0), array('id' => $id)); $data = $this->object->read($id); $this->assertEquals('', $data); }
/** * Updates data */ public function update() { if (!array_key_exists($this->primary, $this->data)) { throw new Exception('Unable to update object without id', 1301251051); } $data = $this->data; unset($data[$this->primary]); $this->table->update($data, array($this->primary => $this->data[$this->primary])); }
/** * Saves the given rating to the storage system. * * @param Rating $rating The rating to persist. */ public function persist(Rating $rating) { if ($rating->getId()) { $this->gateway->update(array('typeId' => $rating->getTypeId(), 'userId' => $rating->getUserId(), 'rating' => $rating->getRating()), array('id' => $rating->getId())); } else { $this->gateway->insert(array('typeId' => $rating->getTypeId(), 'userId' => $rating->getUserId(), 'rating' => $rating->getRating())); $id = $this->gateway->getLastInsertValue(); $rating->setId($id); } }
/** * Update a resource * * @param mixed $id * @param mixed $data * @return ApiProblem|mixed */ public function update($id, $data) { $result = $this->fetch($id); if (!$result) { return new ApiProblem(404, 'Registro não encontrado'); } $data = json_decode(json_encode($data), true); $result->exchangeArray($data); $data = $result->getArrayCopy(); $this->tableGateway->update($data, array('id' => $id)); return $data; }
/** * Write session data * * @param string $id * @param string $data * @return bool */ public function write($id, $data) { $data = array($this->options->getModifiedColumn() => time(), $this->options->getDataColumn() => (string) $data); $rows = $this->tableGateway->select(array($this->options->getIdColumn() => $id, $this->options->getNameColumn() => $this->sessionName)); if ($row = $rows->current()) { return (bool) $this->tableGateway->update($data, array($this->options->getIdColumn() => $id, $this->options->getNameColumn() => $this->sessionName)); } $data[$this->options->getLifetimeColumn()] = $this->lifetime; $data[$this->options->getIdColumn()] = $id; $data[$this->options->getNameColumn()] = $this->sessionName; return (bool) $this->tableGateway->insert($data); }
public function saveDocument(Document $document) { $documentTable = new TableGateway('document', $this->adapter); $data = array('id' => intval($document->id), 'title' => $document->title, 'content' => $document->content); if (empty($data['id'])) { $documentTable->insert($data); $id = $documentTable->lastInsertValue; } else { $id = $documentTable->update($data, array('id' => $data['id'])); } return $id; }
public function saveTask(Task $task) { $taskTable = new TableGateway('task', $this->adapter); $data = array('id' => intval($task->id), 'title' => $task->title); if (empty($data['id'])) { $data['create_time'] = date('Y-n-j H:i:s', time()); $taskTable->insert($data); $id = $taskTable->lastInsertValue; } else { $id = $taskTable->update($data, array('id' => $data['id'])); } return $id; }
/** * Saves a comment into the database. * * @param \RbComment\Model\Comment $comment * @return int The id of the inserted/updated comment */ public function saveComment(Comment $comment) { $data = array('thread' => $comment->thread, 'uri' => $comment->uri, 'author' => $comment->author, 'contact' => $comment->contact, 'content' => $comment->content, 'visible' => $comment->visible, 'spam' => $comment->spam); $id = (int) $comment->id; if ($id === 0) { $this->tableGateway->insert($data); $id = $this->tableGateway->lastInsertValue; } else { if ($this->getComment($id)) { $this->tableGateway->update($data, array('id' => $id)); } } return $id; }
/** * @param Application $application to be saved * * @throws \Exception */ public function saveApplication(Application $application) { $data = ['name' => $application->getName(), 'tag' => $application->getTag(), 'email' => $application->getEmail(), 'strategies' => $application->getStrategies(), 'th' => $application->getTh(), 'warStars' => $application->getWarStars(), 'age' => $application->getAge(), 'infos' => $application->getInfos(), 'why' => $application->getWhy(), 'niceAndTidy' => $application->getNiceAndTidy(), 'spoilsOfWar' => $application->getSpoilsOfWar(), 'goldGrab' => $application->getGoldGrab(), 'basepic' => $application->getBasepic(), 'profilepic' => $application->getProfilepic(), 'processed' => $application->getProcessed(), 'processed_by' => $application->getProcessedBy(), 'date_applied' => $application->getDateApplied(), 'mails_send' => $application->getMailsSend()]; $id = (int) $application->getId(); if ($id == 0) { $this->tableGateway->insert($data); } else { if ($this->getApplication($id)) { $this->tableGateway->update($data, ['id' => $id]); } else { throw new \Exception('Application id does not exist'); } } }
/** * Saves the given news object to the db * * @param \News\Model\News $news * * @throws \Exception */ public function saveNews(News $news) { $data = ['account_id' => $news->getAccountId(), 'title' => $news->getTitle(), 'content' => $news->getContent(), 'category_id' => $news->getCategoryId(), 'date_posted' => $news->getDatePosted()]; $id = (int) $news->getId(); if ($id == 0) { $this->tableGateway->insert($data); } else { if ($this->getNews($id)) { $this->tableGateway->update($data, ['id' => $id]); } else { throw new \Exception('News id does not exist'); } } }
/** * Saves an account to the db. If the id exists the given dataset will be updated * @param \Account\Model\Account $account * * @throws \Exception */ public function saveAccount(Account $account) { $data = ['name' => $account->getName(), 'password' => $account->getPassword(), 'userhash' => $account->getUserHash(), 'email' => $account->getEmail(), 'role' => $account->getRole(), 'avatar' => $account->getAvatar(), 'date_registered' => $account->getDateRegistered(), 'mini' => $account->getMini()]; if (!$account->getId()) { $data['password'] = hash('sha256', $account->getPassword()) . Constants::SALT; $this->tableGateway->insert($data); } else { if ($this->getAccount($account->getId())) { $this->tableGateway->update($data, ['id' => $account->getId()]); } else { throw new \Exception('Account id does not exist'); } } }