本文整理汇总了PHP中Doctrine\DBAL\Query\QueryBuilder类的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder类的具体用法?PHP QueryBuilder怎么用?PHP QueryBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QueryBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @param QueryBuilder $queryBuilder
* @param $callback
* @param int|null $limit
* @param int $maxAttempts
* @throws DBALWalkerException
* @throws DBALException
*/
public function run(QueryBuilder $queryBuilder, $callback, $limit = null, $maxAttempts = 10)
{
if (!is_callable($callback)) {
throw new DBALWalkerException('$callback is not callable');
}
if (!is_null($limit)) {
$queryBuilder->setMaxResults($limit);
} else {
$limit = $queryBuilder->getMaxResults();
}
if (is_null($limit)) {
$limit = PHP_INT_MAX;
}
$offset = 0;
do {
$rows = [];
$errors = $maxAttempts;
while (true) {
try {
$rows = $queryBuilder->setFirstResult($offset)->execute()->fetchAll();
break;
} catch (DBALException $e) {
if ($errors-- == 0) {
throw $e;
}
$queryBuilder->getConnection()->connect();
}
}
call_user_func($callback, $rows, $offset, $limit);
$offset += $limit;
} while (count($rows) >= $limit);
}
示例2: buildQuery
/**
* {@inheritdoc}
*/
public function buildQuery(QueryBuilder $queryBuilder, array $values = array())
{
if (!array_key_exists($this->getName(), $values) || 0 === count($values[$this->getName()])) {
return;
}
$queryBuilder->andWhere($queryBuilder->expr()->in('response.companyType', $values[$this->getName()]));
}
示例3: __construct
/**
* @param QueryBuilder $qb
* @param callable|null $countQueryBuilderModifier
*/
public function __construct(QueryBuilder $qb, callable $countQueryBuilderModifier = null)
{
$this->qb = $qb;
$this->countQueryBuilderModifier = $countQueryBuilderModifier ?: function (QueryBuilder $qb) {
return $qb->select('COUNT(*)');
};
}
示例4: filters
/**
* @param $tableName
* @param $conditions
*
* @return array
*
* @throws LookupError
*
* @since 1.1.0
*
* @author Eddilbert Macharia (http://eddmash.com) <edd.cowan@gmail.com>
*/
public static function filters(QueryBuilder $queryBuilder, $conditions)
{
// default lookup is equal
$lookup = 'eq';
// we add the or conditions afterwards to avoid them being mistaken for "and" conditions when they come first
$or_combine = [];
$and_combine = [];
// create where clause from the conditions given
foreach ($conditions as $condition) {
foreach ($condition as $key => $value) {
$column = self::getLookupColumn($key);
$lookup = self::getLookUP($key);
$value = self::prepareValue($value, $lookup);
echo self::$lookuOptions[$lookup] . '<br>';
echo $queryBuilder->createNamedParameter($value) . '<br>';
echo $value . '<br>';
$lookupCondition = sprintf(self::$lookuOptions[$lookup], $queryBuilder->createNamedParameter($value));
$queryString = sprintf('%s %s', $column, $lookupCondition);
if (self::combine($key) === self::$or) {
$queryBuilder->orWhere($queryString);
} else {
$queryBuilder->andWhere($queryString);
}
}
}
}
示例5: logBuilder
/**
* @param QueryBuilder $builder
*/
public static function logBuilder($builder)
{
$sql = $builder->getSQL();
$params = $builder->getParameters();
self::log("Running Query: " . $sql . " with params:");
self::logObject($params);
}
示例6: process
/**
* Applies operation to data source and returns modified data source.
*
* @param QueryBuilder $src
* @param OperationInterface|SortOperation $operation
* @return QueryBuilder
*/
public function process($src, OperationInterface $operation)
{
$field = $operation->getField();
$order = $operation->getOrder();
$src->orderBy($field, $order);
return $src;
}
示例7: __invoke
/**
* @param QueryBuilder $builder
* @param $column
* @param $value
* @throws Exception
* @return string
*/
public function __invoke(QueryBuilder $builder, $column, $value)
{
if (!is_array($value)) {
throw new Exception("Use of IN operator expects value to be array. Got " . gettype($value) . ".");
}
return $column . ' IN (' . $builder->createPositionalParameter($value, Connection::PARAM_STR_ARRAY) . ')';
}
示例8: match
public function match(QueryBuilder $qb)
{
if ($this->has('username')) {
$qb->andWhere('u.username = :username');
$qb->setParameter('username', $this->get('username'));
}
}
示例9: finalizeQuery
public function finalizeQuery(\Doctrine\DBAL\Query\QueryBuilder $query)
{
$paramcount = 0;
if (!empty($this->gIDs)) {
$validgids = array();
foreach ($this->gIDs as $gID) {
if ($gID > 0) {
$validgids[] = $gID;
}
}
if (!empty($validgids)) {
$query->innerJoin('p', 'VividStoreProductGroups', 'g', 'p.pID = g.pID and g.gID in (' . implode(',', $validgids) . ')');
if (!$this->groupMatchAny) {
$query->having('count(g.gID) = ' . count($validgids));
}
}
}
switch ($this->sortBy) {
case "alpha":
$query->orderBy('pName', 'ASC');
break;
case "date":
$query->orderBy('pDateAdded', 'DESC');
break;
case "popular":
$pr = new StoreProductReport();
$pr->sortByPopularity();
$products = $pr->getProducts();
$pIDs = array();
foreach ($products as $product) {
$pIDs[] = $product['pID'];
}
foreach ($pIDs as $pID) {
$query->addOrderBy("pID = ?", 'DESC')->setParameter($paramcount++, $pID);
}
break;
}
switch ($this->featured) {
case "featured":
$query->andWhere("pFeatured = 1");
break;
case "nonfeatured":
$query->andWhere("pFeatured = 0");
break;
}
if (!$this->showOutOfStock) {
$query->andWhere("pQty > 0 OR pQtyUnlim = 1");
}
if ($this->activeOnly) {
$query->andWhere("pActive = 1");
}
if (is_array($this->cIDs) && !empty($this->cIDs)) {
$query->innerJoin('p', 'VividStoreProductLocations', 'l', 'p.pID = l.pID and l.cID in (' . implode(',', $this->cIDs) . ')');
}
$query->groupBy('p.pID');
if ($this->search) {
$query->andWhere('pName like ?')->setParameter($paramcount++, '%' . $this->search . '%');
}
return $query;
}
示例10: finalizeQuery
public function finalizeQuery(\Doctrine\DBAL\Query\QueryBuilder $query)
{
if (!$this->includeAllGroups) {
$query->andWhere('g.gID > :minGroupID');
$query->setParameter('minGroupID', REGISTERED_GROUP_ID);
}
return $query;
}
示例11: testSetQueryBuilder02
public function testSetQueryBuilder02()
{
$contain = $this->testConstruct02();
$queryBuilder = new QueryBuilder($this->getConnection());
$queryBuilder->select('*')->from('table', 't');
$contain->setQueryBuilder($queryBuilder);
return $contain;
}
示例12: sort
/**
* @param QueryBuilder $queryBuilder
* @param SortInterface $sort
* @param Mapping $mapping
*/
public static function sort(QueryBuilder $queryBuilder, SortInterface $sort, Mapping $mapping)
{
$columns = $mapping->map();
foreach ($sort->orders() as $propertyName => $order) {
self::guardColumnExists($columns, $propertyName);
$queryBuilder->orderBy($columns[$propertyName], $order->isAscending() ? Order::ASCENDING : Order::DESCENDING);
}
}
示例13: addQueryFromBuilder
/**
* Add a query from a query builder
*
* @param QueryBuilder $qb
* @return $this
*/
public function addQueryFromBuilder(QueryBuilder $qb)
{
/**
* @TODO : How to manage query params ?
*/
$this->queries[] = new Query($qb->getSQL());
return $this;
}
示例14: match
/**
* @see \ComPHPPuebla\Doctrine\Query\Specification::match()
*/
public function match(QueryBuilder $qb)
{
if ($this->has('page')) {
$this->page = $this->get('page');
$this->initPageSize();
$qb->setFirstResult($this->calculateOffset())->setMaxResults($this->pageSize);
}
}
示例15: testItShouldWorksWithParametersInTheOrX
public function testItShouldWorksWithParametersInTheOrX()
{
$qb = new QueryBuilder($this->connection);
$qb->select('p.id')->from('posts', 'p')->setParameter('status', 'odd');
$aclFilter = new DoctrineDbalAclFilter($qb);
$aclFilter->setAclSchema($this->aclSchema);
$aclFilter->apply('p', 'id', 'post-', ['user-1'], 1, ['status = :status']);
$this->assertEquals(['status' => 'odd', 'acl_prefix' => 'post-', 'acl_identifiers' => ['user-1'], 'acl_mask' => 1], $qb->getParameters());
}