/** * @covers \BjyAuthorize\Provider\Role\ZendDb::getRoles */ public function testGetRolesWithInheritance() { $this->tableGateway->expects($this->any())->method('selectWith')->will($this->returnValue(array(array('id' => 1, 'role_id' => 'guest', 'is_default' => 1, 'parent_id' => null), array('id' => 2, 'role_id' => 'user', 'is_default' => 0, 'parent_id' => 1)))); $this->serviceLocator->expects($this->any())->method('get')->will($this->returnValue($this->tableGateway)); $provider = new ZendDb(array(), $this->serviceLocator); $this->assertEquals($provider->getRoles(), array(new Role('guest'), new Role('user', 'guest'))); }
public function saveCommandeProduit($id, $ajouterCommande, $prixproduit) { $data = array('COMMANDE_ID' => $id, 'PRODUIT_ID' => $ajouterCommande, 'COMMANDEPRODUIT_PRIX' => $prixproduit); $adapter = $this->tableGateway->getAdapter(); $otherTable = new TableGateway('commandeproduit', $adapter); $otherTable->insert($data); }
/** * 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); } }
/** * @param bool $paginated * @param string $filter * @param string $orderBy * @param string $order * @return \Zend\Db\ResultSet\ResultSet|\Zend\Paginator\Paginator * @throws \Exception */ public function fetchAll($paginated = false, $filter = '', $orderBy = 'attendanceDate', $order = 'DESC') { if ($paginated) { return $this->paginate($filter, $orderBy, $order, $this->boardView); } $attendanceBoard = new TableGateway($this->boardView, $this->adapter); return $attendanceBoard->select(); }
/** * @param $id * @return City|null */ public function getCityById($id) { $city = $this->cityTable->select(['ID' => $id]); if ($city->count() < 1) { return null; } return $city->current(); }
public function deleteCategory($id) { try { return $this->tableGateway->delete(array('id_category' => $id)); } catch (InvalidQueryException $e) { return 0; } }
/** * @param bool $paginated * @param string $filter * @param string $orderBy * @param string $order * @return \Zend\Db\ResultSet\ResultSet * @throws \Exception */ public function fetchAll($paginated = false, $filter = '', $orderBy = 'contractBy', $order = 'ASC') { if ($paginated) { $this->paginate($filter, $orderBy, $order); } $contractView = new TableGateway($this->table, $this->adapter); return $contractView->select(array('contract' => $this->staffId)); }
/** * This method init $this->object */ protected function _initObject($data = null) { if (is_null($data)) { $data = $this->_itemsArrayDelault; } $this->_prepareTable($data); $this->dbTable->insert($data); }
/** * @param bool $paginated * @param string $filter * @param string $orderBy * @param string $order * @return \Zend\Db\ResultSet\ResultSet|Paginator * @throws \Exception */ public function fetchAll($paginated = false, $filter = '', $orderBy = 'name', $order = 'ASC') { $view = 'vw_hr_position'; if ($paginated) { return $this->paginate($filter, $orderBy, $order, $view); } $tableGateway = new TableGateway($view, $this->adapter); return $tableGateway->select(); }
/** * @param bool $paginated * @param string $filter * @param string $orderBy * @param string $order * @return \Zend\Db\ResultSet\ResultSet|\Zend\Paginator\Paginator * @throws \Exception */ public function fetchAll($paginated = false, $filter = '', $orderBy = 'proposalDate', $order = 'ASC') { $view = 'vw_cr_proposal'; if ($paginated) { return $this->paginate($filter, $orderBy, $order, $view); } $proposalView = new TableGateway($view, $this->adapter); return $proposalView->select(array('proposalBy' => $this->staffId)); }
/** * @param bool $paginated * @param string $filter * @param string $orderBy * @param string $order * @return \Zend\Db\ResultSet\ResultSet|\Zend\Paginator\Paginator * @throws \Exception */ public function fetchAll($paginated = false, $filter = '', $orderBy = 'contactName', $order = 'ASC') { $view = 'vw_cr_contact'; if ($paginated) { return $this->paginate($filter, $orderBy, $order, $view); } $contactView = new TableGateway($view, $this->adapter); return $contactView->select(); }
public function testSave() { //Insert $data = new ArrayObject(['fullName' => 'Test', 'email' => '*****@*****.**']); $this->assertEquals(1, $this->table->save($data)); $this->assertNotNull($data['id']); //Update $data = new ArrayObject(['id' => 1, 'fullName' => 'TestUser' . rand(10, 99), 'email' => '*****@*****.**']); $this->assertEquals(1, $this->table->save($data)); }
public function getCurrentVersion($mdir_md5) { $select = new Select($this->tableGateway->getTable()); $select->where(array('mdir_md5' => $mdir_md5))->order('version DESC')->limit(1); $result = $this->tableGateway->selectWith($select); if (!$result->count()) { return 0; } return $result->current()->getVersion(); }
public function getCurrentVersion() { $result = $this->tableGateway->select(function (Select $select) { $select->order('version DESC')->limit(1); }); if (!$result->count()) { return 0; } return $result->current()->getVersion(); }
/** * @param Select $select * @param array $options Paginator options * @param ResultSetInterface $resultSet * @return array|Paginator */ public function selectMany(Select $select, array $options = array(), ResultSetInterface $resultSet = null) { if (!$resultSet) { $resultSet = $this->tableGateway->getResultSetPrototype(); } if ($options) { return $this->initPaginator($select, $options, $resultSet); } return $this->tableGateway->selectWith($select, $resultSet); }
/** * @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; } }
/** * * @return Contact[] */ public function findAll() { $rowset = $this->gateway->select(); $results = []; foreach ($rowset as $row) { $contact = new Contact(); $this->hydrator->hydrate((array) $row, $contact); $results[] = $contact; } return $results; }
/** * Constructs instance. * * @param TableGateway $tableGateway * @param Where|\Closure|string|array $where * @param null $order */ public function __construct(TableGateway $tableGateway, $where = null, $order = null) { $select = $tableGateway->getSql()->select(); if ($where) { $select->where($where); } if ($order) { $select->order($order); } $dbAdapter = $tableGateway->getAdapter(); $resultSetPrototype = $tableGateway->getResultSetPrototype(); parent::__construct($select, $dbAdapter, $resultSetPrototype); }
/** * @return \Zend\View\Model\JsonModel */ public function dbMultiAction() { /* @var $request \Zend\Http\Request */ $request = $this->getRequest(); $queries = $request->getQuery('queries', 1); $worlds = array(); for ($i = 0; $i < $queries; $i += 1) { foreach ($this->tableGateway->select(array('id' => mt_rand(1, 10000))) as $found) { $worlds[] = $found; } } return new JsonModel($worlds); }
/** * 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'); } } }
/** * @param bool $paginated * @param string $filter * @param string $orderBy * @param string $order * @return \Zend\Db\ResultSet\ResultSet|Paginator */ public function fetchAll($paginated = false, $filter = '', $orderBy = 'voucherNo', $order = 'ASC') { $view = 'vw_account_receivable'; if ($paginated) { $select = new Select($view); $select->order($orderBy . ' ' . $order); $where = new Where(); $where->literal("concat_ws(' ',description, voucherNo, Type, amount, voucherDate, currencyCode) LIKE ?", '%' . $filter . '%')->and->equalTo('depositBy', $this->staffId); $select->where($where); return $this->paginateWith($select); } $tableGateway = new TableGateway($view, $this->adapter); return $tableGateway->select(array('depositBy' => $this->staffId)); }
/** * {@inheritdoc} */ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { // Captura de Configuração $config = $serviceLocator->get('Config')['balance_manager']['factories'][$requestedName]; // Inicialização $table = new Db\TableGateway\TableGateway($config['params']['table'], $serviceLocator->get('db')); // Chave Primária e Sequência? if (isset($config['params']['primary_key']) && isset($config['params']['sequence'])) { // Configurar Sequência de Chave Primária $table->getFeatureSet()->addFeature(new Db\TableGateway\Feature\SequenceFeature($config['params']['primary_key'], $config['params']['sequence'])); } // Apresentação return $table; }
/** * 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); } } }
public function getDocument($id) { $documentTable = new TableGateway('document', $this->adapter); $rs = $documentTable->select(array('id' => intval($id))); if ($rs->count()) { $row = $rs->current(); $ObjectPropertyHydrator = new ObjectPropertyHydrator(); $document = new Document(); $ObjectPropertyHydrator->hydrate($row->getArrayCopy(), $document); return $document; } else { throw new \Exception('data not exsist!'); } }
protected function _initObject($data = null) { if (is_null($data)) { $data = $this->_itemsArrayDelault; } $this->_prepareTable($data, $this->cacheableDbTableName); $this->_prepareTable($data, $this->dataSourceDbTableName); $cacheableDbTable = new TableGateway($this->cacheableDbTableName, $this->adapter); $dataSourceDbTable = new TableGateway($this->dataSourceDbTableName, $this->adapter); foreach ($data as $record) { $cacheableDbTable->insert($record); $dataSourceDbTable->insert($record); } }
public function getCurrentSourceVersions() { $data = []; $result = $this->tableGateway->select(function (Select $select) { $select->columns(['version' => new Expression('MAX(version)'), 'source'])->order('version DESC')->group('source'); }); if (!$result->count()) { return $data; } foreach ($result as $row) { $data[$row->getSource()] = $row->getVersion(); } return $data; }
public function saveAddress(Address $address) { if ($this->checkAddress($address->address)) { // Save now. $addressTable = new TableGateway('address', $this->adapter); $hydrator = new ObjectPropertyHydrator(); $data = $hydrator->extract($address); $addressTable->insert($data); $id = $addressTable->lastInsertValue; return $id; } else { throw new AddressAlreadyExsistException('Address already exsist!'); } }
/** * Assert that a table has specified number for rows * * @param integer $count * @param string|TableGateway $table * @param string|array|Closure|PredicateInterface $where * @throws \Exception on $table not a table name or TableGateway instance */ protected function assertTableRowCount($count, $table, $where = null) { if (is_string($table)) { $table = new TableGateway\TableGateway($table, $this->getServices()->get('db')); } if (!$table instanceof TableGateway\TableGatewayInterface) { throw new \Exception("{$table} must be a table name or TableGateway object"); } $select = $table->getSql()->select()->columns(array('count' => new Expression('count(*)'))); if (null !== $where) { $select->where($where); } $actual = $table->selectWith($select)->current()->count; parent::assertEquals($count, $actual); }
public function cityAction() { $adapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'); $id = $this->params()->fromRoute('id'); $cityTableGateway = new TableGateway('City', $adapter); $city = $cityTableGateway->select(['ID' => $id])->toArray(); $tableGateway = new TableGateway('Country', $adapter); if (count($city) < 0) { throw new \Exception('No City found with ID ' . $id); } $city = $city[0]; $country = $tableGateway->select(['Code' => $city['CountryCode']])->toArray(); $country = $country[0]; return new ViewModel(['city' => $city, 'country' => $country]); }
public function saveCommande(Commande $Commande) { $data = array('COMMANDE_ID' => $Commande->commande_id, 'CLIENT_ID' => $Commande->client_id, 'COMMANDE_TABLE' => $Commande->commande_table, 'COMMANDE_STATUS' => $Commande->commande_status); if (isset($Commande->commande_id)) { $adapter = $this->tableGateway->getAdapter(); $otherTable = new TableGateway('commande', $adapter); $otherTable->insert($data); } else { if ($this->getCommande($Commande->commande_id)) { $this->tableGateway->update($data, array('COMMANDE_ID' => $Commande->commande_id, 'COMMANDE_STATUS' => $Commande->commande_status)); } else { throw new \Exception('Form id does not exist'); } } }