当前位置: 首页>>代码示例>>PHP>>正文


PHP Query\QueryBuilder类代码示例

本文整理汇总了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);
 }
开发者ID:octava,项目名称:replication,代码行数:40,代码来源:Walker.php

示例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()]));
 }
开发者ID:Volyz,项目名称:barometre,代码行数:10,代码来源:CompanyTypeFilter.php

示例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(*)');
     };
 }
开发者ID:kbond,项目名称:porpaginas,代码行数:11,代码来源:DBALQueryBuilderResult.php

示例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);
             }
         }
     }
 }
开发者ID:eddmash,项目名称:powerorm,代码行数:38,代码来源:Lookup.php

示例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);
 }
开发者ID:matheusviegas,项目名称:crudkit,代码行数:10,代码来源:LoggingHelper.php

示例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;
 }
开发者ID:view-components,项目名称:doctrine-data-processing,代码行数:14,代码来源:SortProcessor.php

示例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) . ')';
 }
开发者ID:vlucas,项目名称:spot2,代码行数:14,代码来源:In.php

示例8: match

 public function match(QueryBuilder $qb)
 {
     if ($this->has('username')) {
         $qb->andWhere('u.username = :username');
         $qb->setParameter('username', $this->get('username'));
     }
 }
开发者ID:comphppuebla,项目名称:restful-extensions,代码行数:7,代码来源:FilterByUsernameSpecification.php

示例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;
 }
开发者ID:pvernaglia,项目名称:vivid_store,代码行数:60,代码来源:ProductList.php

示例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;
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:8,代码来源:GroupList.php

示例11: testSetQueryBuilder02

 public function testSetQueryBuilder02()
 {
     $contain = $this->testConstruct02();
     $queryBuilder = new QueryBuilder($this->getConnection());
     $queryBuilder->select('*')->from('table', 't');
     $contain->setQueryBuilder($queryBuilder);
     return $contain;
 }
开发者ID:solire,项目名称:trieur,代码行数:8,代码来源:Contain.php

示例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);
     }
 }
开发者ID:PHPRepository,项目名称:sql-repository,代码行数:13,代码来源:SqlSorter.php

示例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;
 }
开发者ID:itkg,项目名称:core,代码行数:14,代码来源:Loader.php

示例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);
     }
 }
开发者ID:comphppuebla,项目名称:restful-extensions,代码行数:11,代码来源:PaginationSpecification.php

示例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());
 }
开发者ID:alexdpy,项目名称:acl,代码行数:9,代码来源:DoctrineDbalAclFilterTest.php


注:本文中的Doctrine\DBAL\Query\QueryBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。