예제 #1
2
 /**
  * @param Lock\Handle $handle
  * @return bool
  */
 public function verifyLock(Lock\Handle $handle)
 {
     if (!isset($this->locks[$handle->getToken()])) {
         return false;
     }
     $key = $this->locks[$handle->getToken()];
     return (bool) $this->gateway->select(['key' => $key])->count();
 }
예제 #2
1
 /**
  * Retrieves an Account with the warstatus
  * @param int $account_id
  * @return null|Warstatus
  */
 public function getWarstatus(int $id)
 {
     $rowset = $this->tableGateway->select(function (Select $select) use($id) {
         $select->where(['id' => $id]);
     });
     $row = $rowset->current();
     return $row;
 }
예제 #3
0
 /**
  * Returns a comment by id.
  *
  * @param  int                      $id
  * @return \RbComment\Model\Comment
  */
 public function getComment($id)
 {
     $id = (int) $id;
     $rowset = $this->tableGateway->select(array('id' => $id));
     $row = $rowset->current();
     return $row;
 }
 /**
  * @param int    $id
  * @param int $limit
  * @param int $offset
  *
  * @return \Zend\Db\ResultSet\ResultSet
  */
 public function getByUserId($id, $limit = 10, $offset = 0)
 {
     $id = (int) $id;
     $rows = $this->tableGateway->select(function (Select $select) use($id, $limit, $offset) {
         $select->where(array('user_id' => $id))->limit($limit)->offset(0)->order('news_id DESC');
     });
     return $rows;
 }
예제 #5
0
 /**
  * @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 getApplicationCountLast30Days()
 {
     $dateNow = new \DateTime();
     $dateBehind = (new \DateTime())->sub(new \DateInterval('P30D'));
     return $this->tableGateway->select(function (Select $select) use($dateNow, $dateBehind) {
         $select->where->between('date_applied', $dateBehind->format('Y-m-d H:i:s'), $dateNow->format('Y-m-d H:i:s'));
     })->count();
 }
예제 #7
0
 public function getCategoryById($id)
 {
     $rowset = $this->tableGateway->select(array('id_category' => $id));
     $row = $rowset->current();
     if (!$row) {
         throw new \Exception("Could not find row with id {$id}");
     }
     return $row;
 }
예제 #8
0
 /**
  * Returns the data requested by the array. Key of array must be column name of Account table and $value the actual value
  * @param array $array with one [key => value] pair
  *
  * @return array|\ArrayObject|null|Account the account with the given email
  */
 public function getNewsCategoryBy($array)
 {
     $rowset = $this->tableGateway->select($array);
     $row = $rowset->current();
     if (!$row) {
         return null;
     }
     return $row;
 }
예제 #9
0
 /**
  * @param Request $request
  * @param Response $response
  * @param $args
  *
  * @return ResponseInterface
  */
 public function fetch(Request $request, Response $response, $args)
 {
     try {
         $result = $this->gateway->select(['id' => 1])->current();
         return $response->withJson($result->getArrayCopy(), 200);
     } catch (\Exception $e) {
         return $response->withStatus(400);
     }
 }
예제 #10
0
 /**
  *
  * @param string|int $id
  *
  * @return array|\ArrayObject|null the account with the given id
  */
 public function getWarlog()
 {
     $rowset = $this->tableGateway->select([1]);
     $row = $rowset->current();
     if (!$row) {
         return null;
     }
     return $row;
 }
 /**
  * @param $token
  *
  * @return User
  * @throws \Exception
  */
 public function getByToken($token)
 {
     $rows = $this->tableGateway->select(array('token' => $token));
     $row = $rows->current();
     if (!$row) {
         throw new \Exception("Could not find row " . $token);
     }
     return $row;
 }
예제 #12
0
 public function getForm($id)
 {
     $id = (int) $id;
     $rowset = $this->tableGateway->select(array('id' => $id));
     $row = $rowset->current();
     if (!$row) {
         throw new \Exception("Could not find row {$id}");
     }
     return $row;
 }
 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();
 }
 /**
  * 
  * @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;
 }
예제 #15
0
 /**
  * {@inheritdoc}
  *
  * {@inheritdoc}
  */
 public function read($id)
 {
     $this->checkIdentifierType($id);
     $identifier = $this->getIdentifier();
     $rowset = $this->dbTable->select(array($identifier => $id));
     $row = $rowset->current();
     if (isset($row)) {
         return $row->getArrayCopy();
     } else {
         return null;
     }
 }
 /**
  * @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);
 }
 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;
 }
예제 #18
0
 public function index02Action()
 {
     $resultSetPrototype = new ResultSet();
     // dành cho tham số thu 4 của tableGateway
     $resultSetPrototype->setArrayObjectPrototype(new \Database\Model\Entity\User());
     // dành cho tham số thu 4 của tableGateway
     $table = "user";
     $adapter = $this->getServiceLocator()->get("db_books");
     $tableGateway = new TableGateway($table, $adapter, null, $resultSetPrototype);
     // $where = new Where();
     // $where->notEqualTo("id","1");
     //SELECT * FROM user WHERE (name NOT NULL) AND (id #1)
     //ORDER BY email
     $resultSet = $tableGateway->select(function (Select $select) {
         //closure
         $select->where->isNotNull("id")->notEqualTo("id", "1");
         $select->order("email DESC");
     });
     foreach ($resultSet as $row) {
         echo "<pre style='font-weight:bold'>";
         print_r($row);
         echo "</pre>";
     }
     return false;
 }
예제 #19
0
 /**
  * @covers Zend\Db\TableGateway\TableGateway::select
  */
 public function testSelectWithWhereString()
 {
     $select = $this->getMock('Zend\\Db\\Sql\\Select');
     // assert select::from() is called
     $select->expects($this->once())->method('where')->with($this->equalTo('foo'));
     $this->table->setSqlSelect($select);
     $this->table->select('foo');
 }
 /**
  * @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));
 }
 /**
  * @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();
 }
예제 #22
0
 /**
  * @covers Zend\Db\TableGateway\TableGateway::select
  * @covers Zend\Db\TableGateway\TableGateway::selectWith
  */
 public function testSelectWithWhereString()
 {
     $mockSelect = $this->mockSql->select();
     $mockSelect->expects($this->any())->method('getRawState')->will($this->returnValue(array('table' => $this->table->getTable())));
     // assert select::from() is called
     $mockSelect->expects($this->once())->method('where')->with($this->equalTo('foo'));
     $this->table->select('foo');
 }
 /**
  * @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();
 }
 /**
  * @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));
 }
예제 #25
0
 public function enrich(Entity\Certificate $certificate)
 {
     /** thing I like in ZF2 is improved work with db layer with usage of new PHP features */
     $where = function (Select $select) use($certificate) {
         $select->where(array('certificate_id' => $certificate->id));
     };
     $certificate->setPriceHistory($this->history->select($where));
     $certificate->setDocuments($this->documents->select($where));
 }
예제 #26
0
 /**
  * Отдает объект по ключу
  *
  * @param string|integer $id
  * @return mixed
  * @throws \Exception
  */
 public function getByKey($id)
 {
     $rowset = $this->tableGateway->select(array($this->getItemSetProto()->getFactory()->getEntityProto()->getKeyName() => $id));
     $row = $rowset->current();
     if (!$row) {
         throw new \Exception("Could not find row {$id}");
     }
     return $row;
 }
예제 #27
0
 /**
  * @param string $field
  * @param mixed $value
  * @return array $readData
  */
 protected function read(string $field, $value) : array
 {
     $row = [];
     // @todo
     $this->isPersistent = is_array($row) && count($row) > 0;
     $resultSet = $this->tableGateway->select(array($field => $value));
     $this->rowGateway = $resultSet->current();
     return $this->rowGateway->getArrayCopy();
 }
 /**
  * @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();
 }
예제 #29
0
 /**
  * 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);
 }
예제 #30
-2
파일: EavTest.php 프로젝트: Eway/zf2-eav
 public function testLoadAttributes()
 {
     $rows = $this->_entityTable->select();
     $attributes = array();
     $attributes[] = $this->_eav->getAttribute('secname');
     $attributes[] = $this->_eav->getAttribute('age');
     $cache = $this->_eav->loadAttributes($rows, $attributes);
     $this->assertTrue($cache instanceof ValuesCache);
     $this->assertCount(2, $cache->toArray());
     $rows = $rows->toArray();
     // changing value in db for row[0]
     $this->_eav->setAttributeValue($rows[0], 'age', 100);
     $newValue = $this->_eav->getAttributeValue($rows[0], 'age');
     $this->assertEquals(100, $newValue);
     // value from cache should contains old value
     $cachedValue = $this->_eav->getAttributeValue($rows[0], 'age', $cache);
     $this->assertEquals(10, $cachedValue);
     // row[3] does not have age attribute in db
     $this->_eav->setAttributeValue($rows[3], 'age', 100);
     // so it should be loaded from db
     $this->assertEquals(100, $this->_eav->getAttributeValue($rows[3], 'age', $cache));
     // row[2] does not have age attribute in db
     // and we do not want to load value if it's not in cache
     $this->assertEquals('', $this->_eav->getAttributeValue($rows[2], 'age', $cache, false));
 }