コード例 #1
0
ファイル: ZendDbTest.php プロジェクト: pbrilius/BjyAuthorize
 /**
  * @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')));
 }
コード例 #2
0
 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);
 }
コード例 #3
0
ファイル: Model.php プロジェクト: gotcms/gotcms
 /**
  * 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);
     }
 }
コード例 #4
0
 /**
  * @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();
 }
コード例 #5
0
ファイル: DataService.php プロジェクト: GeeH/bad-puppy
 /**
  * @param $id
  * @return City|null
  */
 public function getCityById($id)
 {
     $city = $this->cityTable->select(['ID' => $id]);
     if ($city->count() < 1) {
         return null;
     }
     return $city->current();
 }
コード例 #6
0
 public function deleteCategory($id)
 {
     try {
         return $this->tableGateway->delete(array('id_category' => $id));
     } catch (InvalidQueryException $e) {
         return 0;
     }
 }
コード例 #7
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));
 }
コード例 #8
0
 /**
  * This method init $this->object
  */
 protected function _initObject($data = null)
 {
     if (is_null($data)) {
         $data = $this->_itemsArrayDelault;
     }
     $this->_prepareTable($data);
     $this->dbTable->insert($data);
 }
コード例 #9
0
 /**
  * @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();
 }
コード例 #10
0
 /**
  * @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));
 }
コード例 #11
0
 /**
  * @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();
 }
コード例 #12
0
 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));
 }
コード例 #13
0
 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();
 }
コード例 #14
0
 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();
 }
コード例 #15
0
 /**
  * @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);
 }
コード例 #16
0
 /**
  * @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;
     }
 }
コード例 #17
0
 /**
  * 
  * @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;
 }
コード例 #18
0
ファイル: DbTableGateway.php プロジェクト: idwsdta/INIT-frame
 /**
  * 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);
 }
コード例 #19
0
 /**
  * @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);
 }
コード例 #20
0
 /**
  * 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');
         }
     }
 }
コード例 #21
0
 /**
  * @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));
 }
コード例 #22
0
 /**
  * {@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;
 }
コード例 #23
0
 /**
  * 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);
         }
     }
 }
コード例 #24
0
ファイル: DocumentService.php プロジェクト: solody/xmail
 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!');
     }
 }
コード例 #25
0
ファイル: CacheableTest.php プロジェクト: avz-cmf/zaboy-rest
 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);
     }
 }
コード例 #26
0
 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;
 }
コード例 #27
0
ファイル: AddressService.php プロジェクト: solody/xmail
 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!');
     }
 }
コード例 #28
0
ファイル: TestCaseDb.php プロジェクト: sporkcode/spork
 /**
  * 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);
 }
コード例 #29
0
 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]);
 }
コード例 #30
0
 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');
         }
     }
 }