本文整理汇总了PHP中Zend\Db\TableGateway\TableGateway::selectWith方法的典型用法代码示例。如果您正苦于以下问题:PHP TableGateway::selectWith方法的具体用法?PHP TableGateway::selectWith怎么用?PHP TableGateway::selectWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Db\TableGateway\TableGateway
的用法示例。
在下文中一共展示了TableGateway::selectWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCurrentVersion
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();
}
示例2: selectMany
/**
* @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);
}
示例3: testClearExpiredLocks
public function testClearExpiredLocks()
{
$this->throttle->clearExpiredLocks();
$select = $this->gateway->getSql()->select();
$select->where->like('key', '%::past');
$this->assertEmpty($this->gateway->selectWith($select)->count());
}
示例4: getRangeByKey
/**
* 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);
}
示例5: findMany
/**
* @param CriteriaInterface|array $criteria
* @return EntityInterface[]
*/
public function findMany($criteria)
{
if (is_array($criteria)) {
$criteria = $this->createCriteria($criteria);
}
if (empty($this->with)) {
return $this->entityRepository->findMany($criteria);
}
/** @var Select $select */
$select = $criteria->getQuery();
$rows = $this->tableGateway->selectWith($select)->toArray();
if (empty($rows)) {
return [];
}
$relatedEntityIds = [];
foreach ($rows as $row) {
foreach ($this->with as $relatedEntityName => $cascadeWith) {
$relatedField = $this->getRelatedField($relatedEntityName);
if (!array_key_exists($relatedField, $row)) {
throw new \RuntimeException(get_class($this) . ": relation field {$relatedEntityName} not fetched");
}
if (!isset($relatedEntityIds[$relatedEntityName])) {
$relatedEntityIds[$relatedEntityName] = new ArrayObject();
}
if (!in_array($row[$relatedField], (array) $relatedEntityIds[$relatedEntityName])) {
$relatedEntityIds[$relatedEntityName]->append($row[$relatedField]);
}
}
}
$relatedEntities = [];
foreach ($this->with as $relatedEntityName => $cascadeWith) {
if (empty((array) $relatedEntityIds[$relatedEntityName])) {
continue;
}
$criteria = $this->relatedRepository[$relatedEntityName]->createCriteria(['id.in' => (array) $relatedEntityIds[$relatedEntityName]]);
$relatedEntities[$relatedEntityName] = $this->relatedRepository[$relatedEntityName]->findMany($criteria);
}
$entitiesArgs = [];
foreach ($rows as &$row) {
$entityArgs = ['data' => $this->mapper->fromTableRow($row)];
foreach ($this->relationsConfig as $entityName => $joinRule) {
$relatedField = $this->getRelatedField($entityName);
if (isset($relatedEntities[$entityName])) {
if (isset($relatedEntities[$entityName][$row[$relatedField]])) {
$entityArgs['aggregateItems'][] = $relatedEntities[$entityName][$row[$relatedField]];
} else {
$entityArgs['aggregateItems'][] = null;
}
} else {
$entityArgs['aggregateItems'][] = null;
}
}
$entitiesArgs[] = $entityArgs;
}
$entities = $this->entityFactory->createCollection($entitiesArgs);
$this->with = null;
return $entities;
}
示例6: getIdentityRoles
/**
* {@inheritDoc}
*/
public function getIdentityRoles()
{
$authService = $this->userService->getAuthService();
if (!$authService->hasIdentity()) {
return array($this->getDefaultRole());
}
// get roles associated with the logged in user
$sql = new Select();
$sql->from($this->tableName);
// @todo these fields should eventually be configurable
$sql->join('user_role', 'user_role.id = ' . $this->tableName . '.role_id');
$sql->where(array('user_id' => $authService->getIdentity()->getId()));
$results = $this->tableGateway->selectWith($sql);
$roles = array();
foreach ($results as $role) {
$roles[] = $role['role_id'];
}
return $roles;
}
示例7: getRatingSet
/**
* 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']);
}
示例8: assertTableRowCount
/**
* 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);
}
示例9: findAll
/**
* レコードを全件取得
*
* @param array $keys
* @param Sql\Select $select
* @return array|ModelInterface[]
*/
public function findAll(array $keys, Sql\Select $select = null)
{
$select = $this->buildSelect($keys, $select);
if ($this->resultArray) {
$statement = $this->tableData->getSql()->prepareStatementForSqlObject($select);
$result = $statement->execute();
} else {
$result = $this->tableData->selectWith($select);
}
$res = array();
foreach ($result as $row) {
$res[] = $row;
}
$this->resultArray = false;
return $res;
}
示例10: getKeys
/**
* {@inheritdoc}
*
* {@inheritdoc}
*/
protected function getKeys()
{
$identifier = $this->getIdentifier();
$select = $this->dbTable->getSql()->select();
$select->columns(array($identifier));
$rowset = $this->dbTable->selectWith($select);
$keysArrays = $rowset->toArray();
if (PHP_VERSION_ID >= 50500) {
$keys = array_column($keysArrays, $identifier);
} else {
$keys = array();
foreach ($keysArrays as $value) {
$keys[] = $value[$identifier];
}
}
return $keys;
}
示例11: getList
/**
* Получить справочник.
*/
public function getList()
{
$result = new JsonModel();
$ref = (string) $this->params()->fromQuery("ref");
$refmap = array("ownership_type" => array("fieldmap" => array("id" => "id", "text" => "name")));
// Запрос
$tableRef = new TableGateway($ref, $this->getAdapter());
$select = $tableRef->getSql()->select();
$data = $tableRef->selectWith($select)->toArray();
// Переименовывание полей таблицы
$_data = array();
foreach ($data as $row) {
$_data[] = array("id" => (int) $row[$refmap[$ref]["fieldmap"]["id"]], "text" => $row[$refmap[$ref]["fieldmap"]["text"]]);
}
$data = $_data;
$result->success = true;
$result->data = $data;
return $result;
}
示例12: loadFromId
/**
* Loads data from its id
* @param int $id
*/
public function loadFromId($id)
{
if (!is_object($this->table) || !$this->table instanceof \Zend\Db\TableGateway\TableGateway) {
throw new \Exception('No database table associated with this content', 1409011101);
}
$this->data = array();
$select = $this->table->getSql()->select()->where(array($this->primary => $id));
$data = $this->table->selectWith($select)->current();
$mysqli = $this->table->getAdapter()->getDriver()->getConnection()->getResource();
if (is_object($data)) {
$this->data = $data->getArrayCopy();
} else {
if ($mysqli->errno > 0) {
$this->data = array();
if (is_numeric($mysqli->errno) && $mysqli->errno != 0) {
throw new \Exception('Error on query ' . $select->getSqlString($this->table->getAdapter()->getPlatform()) . ' ' . $mysqli->errno . ' ' . $mysqli->error, 1401301242);
}
}
}
}
示例13: index03Action
public function index03Action()
{
$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);
$sql = new Sql($adapter);
$select = $sql->select();
$select->from("user")->where("id <> 2");
$selectWith = $tableGateway->selectWith($select);
foreach ($selectWith as $row) {
echo "<pre style='font-weight:bold'>";
print_r($row);
echo "</pre>";
}
return false;
}
示例14: getRoles
public function getRoles()
{
$tableGateway = new TableGateway($this->tableName, $this->sm->get('Zend\\Db\\Adapter\\Adapter'));
$sql = new Select();
$sql->from($this->tableName);
$rowset = $tableGateway->selectWith($sql);
$roles = array();
// Pass One: Build each object
foreach ($rowset as $row) {
$roleId = $row[$this->roleIdFieldName];
$roles[$roleId] = new Role($roleId, $row[$this->parentRoleFieldName]);
}
// Pass Two: Re-inject parent objects to preserve hierarchy
foreach ($roles as $roleId => $roleObj) {
$parentRoleObj = $roleObj->getParent();
if ($parentRoleObj) {
$roleObj->setParent($roles[$parentRoleObj->getRoleId()]);
}
}
return array_values($roles);
}
示例15: execute
public function execute(Request $request, Response $response, callable $next = null)
{
$collectionname = $request->getAttribute('collectionname');
$collection = new TableGateway($collectionname, $this->boot()->db);
$range = $request->getHeader('Range');
$lexer = new \Xiag\Rql\Parser\Lexer();
$tokens = $lexer->tokenize($request->getUri()->getQuery());
$parser = \Xiag\Rql\Parser\Parser::createDefault();
//file_put_contents('xxxx', print_r($parser->parse($tokens), true));
$rql = $parser->parse($tokens);
$select = $collection->getSql()->select();
$sort = $rql->getSort();
if ($sort) {
foreach ($sort->getFields() as $field => $descending) {
//file_put_contents('xxxx', print_r($field, true));
$select->order("{$field} " . ($descending > 0 ? 'ASC' : 'DESC'));
}
}
$result = $collection->selectWith($select);
return $response->withHeader('Content-Type', 'application/json')->withBody($this->toJsonStream($result->toArray()));
}