Ejemplo n.º 1
0
 public function deleteCategory($id)
 {
     try {
         return $this->tableGateway->delete(array('id_category' => $id));
     } catch (InvalidQueryException $e) {
         return 0;
     }
 }
 /**
  * Delete a resource
  *
  * @param  mixed $id
  * @return ApiProblem|mixed
  */
 public function delete($id)
 {
     $result = $this->fetch($id);
     if (!$result) {
         return new ApiProblem(404, 'Registro não encontrado');
     }
     $this->tableGateway->delete(array('id' => $id));
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Save Role
  *
  * @return integer
  */
 public function save()
 {
     $this->events()->trigger(__CLASS__, 'before.save', $this);
     $arraySave = array('name' => $this->getName(), 'description' => $this->getDescription());
     try {
         $roleId = $this->getId();
         if (empty($roleId)) {
             $this->insert($arraySave);
             $this->setId($this->getLastInsertId());
         } else {
             $this->update($arraySave, array('id' => $this->getId()));
         }
         $permissions = $this->getPermissions();
         if (!empty($permissions)) {
             $aclTable = new TableGateway('user_acl', $this->getAdapter());
             $aclTable->delete(array('user_acl_role_id' => $this->getId()));
             foreach ($permissions as $permissionId => $value) {
                 if (!empty($value)) {
                     $aclTable->insert(array('user_acl_role_id' => $this->getId(), 'user_acl_permission_id' => $permissionId));
                 }
             }
         }
         $this->events()->trigger(__CLASS__, 'after.save', $this);
         return $this->getId();
     } catch (\Exception $e) {
         $this->events()->trigger(__CLASS__, 'after.save.failed', $this);
         throw new \Gc\Exception($e->getMessage(), $e->getCode(), $e);
     }
 }
Ejemplo n.º 4
0
 /**
  * Destroy session
  *
  * @param string $id
  * @return boolean
  */
 public function destroy($id)
 {
     return (bool) $this->tableGateway->delete(array(
         $this->options->getIdColumn() => $id,
         $this->options->getNameColumn() => $this->sessionName,
     ));
 }
Ejemplo n.º 5
0
 public function deleteanywhere($mytable, $where)
 {
     $db = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
     $table = new TableGateway($mytable, $db);
     $table->delete($where);
     return 1;
 }
Ejemplo n.º 6
0
 /**
  * @covers Zend\Db\TableGateway\TableGateway::delete
  */
 public function testDelete()
 {
     $mockDelete = $this->mockSql->delete();
     // assert select::from() is called
     $mockDelete->expects($this->once())->method('where')->with($this->equalTo('foo'));
     $this->table->delete('foo');
 }
Ejemplo n.º 7
0
 /**
  * Удаляет объект
  *
  * @param mixed $id
  * @return \App\Storage\Mysql\Simple
  */
 public function delete($id)
 {
     if ($id instanceof EntityInterface) {
         $id = $id->getKeyValue();
     }
     $this->tableGateway->delete(array($this->getItemSetProto()->getFactory()->getEntityProto()->getKeyName() => $id));
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * @covers Zend\Db\TableGateway\TableGateway::delete
  */
 public function testDelete()
 {
     $delete = $this->getMock('Zend\\Db\\Sql\\Delete');
     // assert select::from() is called
     $delete->expects($this->once())->method('where')->with($this->equalTo('foo'));
     $this->table->setSqlDelete($delete);
     $this->table->delete('foo');
 }
Ejemplo n.º 9
0
 /**
  * @param Lock\Handle $handle
  */
 public function clearLock(Lock\Handle $handle)
 {
     if (!isset($this->locks[$handle->getToken()])) {
         return;
     }
     $key = $this->locks[$handle->getToken()];
     $this->gateway->delete(['key' => $key]);
     unset($this->locks[$handle->getToken()]);
 }
Ejemplo n.º 10
0
 /**
  * @param Request $request
  * @param Response $response
  * @param $args
  *
  * @return ResponseInterface
  */
 public function remove(Request $request, Response $response, $args)
 {
     try {
         $result = $this->gateway->delete($this->getIdArray($args));
         return $response->withJson(["result" => $result]);
     } catch (\Exception $e) {
         return $response->withStatus(400);
     }
 }
Ejemplo n.º 11
0
 /**
  * Deletes the account with the given id
  * @param int|string $id
  */
 public function deleteAccount($id)
 {
     $account = $this->getAccount($id);
     $dir = getcwd() . '/public/users/' . $account->getName();
     if (file_exists($dir)) {
         $this->rrmdir($dir);
     }
     $this->tableGateway->delete(['id' => $id]);
 }
Ejemplo n.º 12
0
 /**
  * delete by id of the table or array condition
  *
  * @param int/array $id        	
  */
 public function delete($id)
 {
     try {
         if (is_array($id)) {
             $effectedRows = $this->tableGateway->delete($id);
         } else {
             $effectedRows = $this->tableGateway->delete(array('id' => (int) $id));
         }
     } catch (\Exception $e) {
         return \Model\Custom\Error::trigger($e, $params);
     }
     return $effectedRows;
 }
 /**
  * Delete node
  *
  * @param integer $leftKey
  * @param integer $rightKey
  * @param array $filter
  * @param boolean $useTransaction
  * @return boolean|string
  */
 public function deleteNode($leftKey, $rightKey, array $filter = [], $useTransaction = true)
 {
     try {
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->beginTransaction();
         }
         $predicate = new Predicate();
         $this->tableGateway->delete([$predicate->greaterThanOrEqualTo($this->left, $leftKey), $predicate->lessThanOrEqualTo($this->right, $rightKey)] + $filter);
         $predicate = new Predicate();
         $this->tableGateway->update([$this->left => new Expression('IF(' . $this->left . ' > ?, ' . $this->left . ' - (? - ? + 1), ' . $this->left . ')', [$leftKey, $rightKey, $leftKey]), $this->right => new Expression($this->right . ' - (? - ? + 1)', [$rightKey, $leftKey])], [$predicate->greaterThan($this->right, $rightKey)] + $filter);
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->commit();
         }
     } catch (Exception $e) {
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->rollback();
         }
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     return true;
 }
 /**
  * @param int $id
  */
 public function deleteUser($id)
 {
     $this->tableGateway->delete(array('user_id' => (int) $id));
 }
Ejemplo n.º 15
0
 public function delete($version, $mdir_md5)
 {
     $this->tableGateway->delete(array('version' => $version, 'mdir_md5' => $mdir_md5));
 }
Ejemplo n.º 16
0
 /**
  * {@inheritdoc}
  *
  * {@inheritdoc}
  */
 public function deleteAll()
 {
     $where = '1=1';
     $deletedItemsCount = $this->dbTable->delete($where);
     return $deletedItemsCount;
 }
Ejemplo n.º 17
0
 public function dropColumn($columnName, $tableName = null)
 {
     if ($tableName == null) {
         $tableName = $this->table;
     }
     if (!TableSchema::hasTableColumn($tableName, $columnName, true)) {
         return false;
     }
     if (!$this->acl->hasTablePrivilege($tableName, 'alter')) {
         $aclErrorPrefix = $this->acl->getErrorMessagePrefix();
         throw new UnauthorizedTableAddException($aclErrorPrefix . 'Table alter access forbidden on table ' . $tableName);
     }
     // Drop table column if is a non-alias column
     if (!array_key_exists($columnName, array_flip(TableSchema::getAllAliasTableColumns($tableName, true)))) {
         $sql = new Sql($this->adapter);
         $alterTable = new Ddl\AlterTable($tableName);
         $dropColumn = $alterTable->dropColumn($columnName);
         $query = $sql->getSqlStringForSqlObject($dropColumn);
         $this->adapter->query($query)->execute();
     }
     // Remove column from directus_columns
     $columnsTableGateway = new TableGateway('directus_columns', $this->adapter);
     $columnsTableGateway->delete(['table_name' => $tableName, 'column_name' => $columnName]);
     // Remove column from directus_ui
     $uisTableGateway = new TableGateway('directus_ui', $this->adapter);
     $uisTableGateway->delete(['table_name' => $tableName, 'column_name' => $columnName]);
     return true;
 }
Ejemplo n.º 18
0
 /**
  * Deletes the news with the corresponding id.
  *
  * @param int|string $id
  */
 public function deleteNews($id)
 {
     $this->tableGateway->delete(['id' => (int) $id]);
 }
Ejemplo n.º 19
0
 /**
  * Delete
  * 
  * @param  string $where
  * @return type 
  */
 public function delete($where)
 {
     $this->adapter = $this->masterAdapter;
     return parent::delete($where);
 }
Ejemplo n.º 20
0
 public function deleteForm($id)
 {
     $id = (int) $id;
     $this->tableGateway->delete(array('id' => $id));
 }
Ejemplo n.º 21
0
<?php

namespace My;

use Zend\Db\TableGateway\TableGateway;
function doSomething()
{
}
$table = new TableGateway('album', $adapter);
// select
$rowset = $table->select(array('id' => 2));
$row = $rowset->current();
// update
$result = $table->update(array('name' => 'Adele'), array('id' => 2));
// delete
$table->delete(array('id' => 2));
Ejemplo n.º 22
0
 /**
  * Deletes all comments maked as spam from the database.
  *
  * @return int - number of rows affected.
  */
 public function deleteSpam()
 {
     return $this->tableGateway->delete(array('spam' => 1));
 }
Ejemplo n.º 23
0
 /**
  * Delete
  * 
  * @param  string $where
  * @return type 
  */
 public function delete($where)
 {
     $this->initialize();
     return parent::delete($where);
 }
Ejemplo n.º 24
0
 /**
  * Delete property
  *
  * @return boolean
  */
 public function delete()
 {
     $this->events()->trigger(__CLASS__, 'before.delete', $this);
     $id = $this->getId();
     if (!empty($id)) {
         try {
             parent::delete(array('id' => (int) $id));
             $table = new TableGateway('property_value', $this->getAdapter());
             $table->delete(array('property_id' => (int) $id));
         } catch (\Exception $e) {
             throw new \Gc\Exception($e->getMessage());
         }
         $this->events()->trigger(__CLASS__, 'after.delete', $this);
         return true;
     }
     $this->events()->trigger(__CLASS__, 'after.delete.failed', $this);
     return false;
 }
Ejemplo n.º 25
0
 public function dropColumn($columnName, $tableName = null)
 {
     if ($tableName == null) {
         $tableName = $this->table;
     }
     if (!TableSchema::hasTableColumn($tableName, $columnName, true)) {
         return false;
     }
     // Drop table column if is a non-alias column
     if (!array_key_exists($columnName, array_flip(TableSchema::getAllAliasTableColumns($tableName, true)))) {
         $sql = new Sql($this->adapter);
         $alterTable = new Ddl\AlterTable($tableName);
         $dropColumn = $alterTable->dropColumn($columnName);
         $query = $sql->getSqlStringForSqlObject($dropColumn);
         $this->adapter->query($query)->execute();
     }
     // Remove column from directus_columns
     $columnsTableGateway = new TableGateway('directus_columns', $this->adapter);
     $columnsTableGateway->delete(['table_name' => $tableName, 'column_name' => $columnName]);
     // Remove column from directus_ui
     $uisTableGateway = new TableGateway('directus_ui', $this->adapter);
     $uisTableGateway->delete(['table_name' => $tableName, 'column_name' => $columnName]);
     return true;
 }
Ejemplo n.º 26
0
 /**
  * Delete document
  *
  * @return boolean
  */
 public function delete()
 {
     $this->events()->trigger(__CLASS__, 'before.delete', $this);
     $documentId = $this->getId();
     if (!empty($documentId)) {
         try {
             $propertiesTable = new TableGateway('property_value', $this->getAdapter());
             $propertiesTable->delete(array('document_id' => $this->getId()));
             parent::delete(array('id' => $documentId));
         } catch (\Exception $e) {
             throw new \Gc\Exception($e->getMessage(), $e->getCode(), $e);
         }
         $this->events()->trigger(__CLASS__, 'after.delete', $this);
         unset($this);
         return true;
     }
     $this->events()->trigger(__CLASS__, 'after.delete.failed', $this);
     return false;
 }
 public function delete($version)
 {
     $this->tableGateway->delete(['version' => $version]);
 }
Ejemplo n.º 28
0
 /**
  * Deletes data
  */
 public function delete()
 {
     if (array_key_exists($this->primary, $this->data)) {
         $this->table->delete(array($this->primary => $this->data[$this->primary]));
     }
 }
Ejemplo n.º 29
0
 /**
  * Garbage Collection
  *
  * @param int $maxlifetime
  * @return true
  */
 public function gc($maxlifetime)
 {
     $platform = $this->tableGateway->getAdapter()->getPlatform();
     return (bool) $this->tableGateway->delete(sprintf('%s + %s < %d', $platform->quoteIdentifier($this->options->getModifiedColumn()), $platform->quoteIdentifier($this->options->getLifetimeColumn()), time()));
 }
Ejemplo n.º 30
0
 /**
  * {@inheritDoc}
  */
 protected function doDeleteModel($model)
 {
     $this->tableGateway->delete(array("{$this->idField} = ?" => $this->getModelId($model)));
 }