/** * Returns all the comments pending approval for a thread. * * @param string $thread * @return ResultSet */ public function fetchAllPendingForThread($thread) { $select = new Select($this->tableGateway->getTable()); $select->columns(array('id', 'author', 'content', 'contact', 'published_on_raw' => 'published_on', 'published_on' => new Expression("DATE_FORMAT(published_on, '%M %d, %Y %H:%i')")))->where(array('thread' => $thread, 'visible' => 0))->order('published_on_raw ASC'); $resultSet = $this->tableGateway->selectWith($select); return $resultSet; }
protected function setUp() { parent::setUp(); $tableGateway = $this->config['testDbTableMultiInsert']['tableGateway']; $this->dbTable = $this->container->get($tableGateway); $this->dbTableName = $this->dbTable->getTable(); $this->adapter = $this->container->get('db'); $this->object = $this->container->get('testDbTableMultiInsert'); }
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(); }
/** * Gets the set of ratings for the given type id. * * @param string $typeId The type identifier to get the set of ratings for. * @return RatingSet */ public function getRatingSet($typeId) { $adapter = $this->gateway->getAdapter(); $sql = new Sql($adapter); $select = $sql->select(); $select->from($this->gateway->getTable()); $select->columns(array('amount' => new Expression('COUNT(rating)'), 'avarage' => new Expression('AVG(rating)'), 'highest' => new Expression('MAX(rating)'), 'lowest' => new Expression('MIN(rating)')), false); $rowset = $this->gateway->selectWith($select); $row = $rowset->current(); return new RatingSet($typeId, $row['amount'], $row['avarage'], $row['highest'], $row['lowest']); }
public function test__construct() { // constructor with only required args $table = new TableGateway( 'foo', $this->mockAdapter ); $this->assertEquals('foo', $table->getTable()); $this->assertSame($this->mockAdapter, $table->getAdapter()); $this->assertInstanceOf('Zend\Db\TableGateway\Feature\FeatureSet', $table->getFeatureSet()); $this->assertInstanceOf('Zend\Db\ResultSet\ResultSet', $table->getResultSetPrototype()); $this->assertInstanceOf('Zend\Db\Sql\Sql', $table->getSql()); // injecting all args $table = new TableGateway( 'foo', $this->mockAdapter, $featureSet = new Feature\FeatureSet, $resultSet = new ResultSet, $sql = new Sql($this->mockAdapter, 'foo') ); $this->assertEquals('foo', $table->getTable()); $this->assertSame($this->mockAdapter, $table->getAdapter()); $this->assertSame($featureSet, $table->getFeatureSet()); $this->assertSame($resultSet, $table->getResultSetPrototype()); $this->assertSame($sql, $table->getSql()); }
/** * {@inheritdoc} * * {@inheritdoc} */ public function count() { $adapter = $this->dbTable->getAdapter(); /* @var $rowset Zend\Db\ResultSet\ResultSet */ $rowset = $adapter->query('SELECT COUNT(*) AS count FROM ' . $adapter->platform->quoteIdentifier($this->dbTable->getTable()), $adapter::QUERY_MODE_EXECUTE); return $rowset->current()['count']; }
/** * @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'); }
/** * Returns EntitySet defined by $start and $stop range of key * * @param integer $start * @param integer $stop * @return TableEntitySetInterface */ public function getRangeByKey($start, $stop) { $sql = new Sql($this->getAdapter()); $select = $sql->select(); $select->from($this->tableGateway->getTable()); $select->where(new Predicate\Between($this->getItemSetProto()->getFactory()->getEntityProto()->getKeyName(), $start, $stop)); return $this->tableGateway->selectWith($select); }
public function getSqlQuery(Query $query) { $conditionBuilder = new SqlConditionBuilder($this->dbTable->getAdapter(), $this->dbTable->getTable()); $selectSQL = $this->dbTable->getSql()->select(); $selectSQL->where($conditionBuilder($query->getQuery())); $selectSQL = $this->setSelectOrder($selectSQL, $query); $selectSQL = $this->setSelectLimitOffset($selectSQL, $query); $selectSQL = $this->setSelectColumns($selectSQL, $query); $selectSQL = $this->setSelectJoin($selectSQL, $query); $selectSQL = $this->makeExternalSql($selectSQL); //build sql string $sql = $this->dbTable->getSql()->buildSqlString($selectSQL); //replace double ` char to single. $sql = str_replace(["`(", ")`", "``"], ['(', ')', "`"], $sql); return $sql; }
public function test__construct() { // constructor with only required args $table = new TableGateway('foo', $this->mockAdapter); $this->assertEquals('foo', $table->getTable()); $this->assertSame($this->mockAdapter, $table->getAdapter()); $this->assertInstanceOf('Zend\\Db\\TableGateway\\Feature\\FeatureSet', $table->getFeatureSet()); $this->assertInstanceOf('Zend\\Db\\ResultSet\\ResultSet', $table->getResultSetPrototype()); $this->assertInstanceOf('Zend\\Db\\Sql\\Sql', $table->getSql()); // injecting all args $table = new TableGateway('foo', $this->mockAdapter, $featureSet = new Feature\FeatureSet(), $resultSet = new ResultSet(), $sql = new Sql($this->mockAdapter, 'foo')); $this->assertEquals('foo', $table->getTable()); $this->assertSame($this->mockAdapter, $table->getAdapter()); $this->assertSame($featureSet, $table->getFeatureSet()); $this->assertSame($resultSet, $table->getResultSetPrototype()); $this->assertSame($sql, $table->getSql()); // constructor expects exception $this->setExpectedException('Zend\\Db\\TableGateway\\Exception\\InvalidArgumentException', 'Table name must be a string or an instance of Zend\\Db\\Sql\\TableIdentifier'); new TableGateway(null, $this->mockAdapter); }
protected function getTable() { return $this->tableGateway->getTable(); }
public function getAll() { $select = new \Zend\Db\Sql\Select(); $select->from($this->tableGateway->getTable()); return $select; }