當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。