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


PHP QueryBuilder::addOrderBy方法代码示例

本文整理汇总了PHP中Doctrine\DBAL\Query\QueryBuilder::addOrderBy方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::addOrderBy方法的具体用法?PHP QueryBuilder::addOrderBy怎么用?PHP QueryBuilder::addOrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\DBAL\Query\QueryBuilder的用法示例。


在下文中一共展示了QueryBuilder::addOrderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: incorporateDbalQueryBuilder

 /**
  * @internal
  */
 private function incorporateDbalQueryBuilder(QueryBuilder $qb, FilterInterface $filter)
 {
     $criteria = $this->getFilteringCriteria($filter);
     // extraindo os rootAliases, pois o DBAL\QueryBuilder não tem
     $fromPart = $qb->getQueryPart('from');
     $rootAliases = array();
     foreach ($fromPart as $part) {
         $rootAliases[] = $part['alias'];
     }
     $visitor = new DbalQueryExpressionVisitor($qb->getConnection(), $rootAliases, $this->fieldMap);
     if ($whereExpression = $criteria->getWhereExpression()) {
         $qb->andWhere($visitor->dispatch($whereExpression));
         $qb->setParameters($visitor->getParameters());
     }
     if ($criteria->getOrderings()) {
         foreach ($criteria->getOrderings() as $sort => $order) {
             $qb->addOrderBy($visitor->getFieldName($sort), $order);
         }
     }
     if (($firstResult = $criteria->getFirstResult()) !== null) {
         $qb->setFirstResult($firstResult);
     }
     if (($maxResults = $criteria->getMaxResults()) !== null) {
         $qb->setMaxResults($maxResults);
     }
 }
开发者ID:brodaproject,项目名称:broda,代码行数:29,代码来源:DbalQueryBuilderIncorporator.php

示例2: getDataQuery

 /**
  * Build the data query
  *
  * @return QueryBuilder
  */
 public function getDataQuery()
 {
     $this->buildFilteredQuery();
     if ($this->offset !== null) {
         $this->currentQueryBuilder->setFirstResult($this->offset);
     }
     if ($this->length !== null) {
         $this->currentQueryBuilder->setMaxResults($this->length);
     }
     if ($this->orders !== null) {
         foreach ($this->orders as $order) {
             list($column, $dir) = $order;
             $this->currentQueryBuilder->addOrderBy($column->sourceSort, $dir);
         }
     }
     if (isset($this->conf->group)) {
         $this->currentQueryBuilder->groupBy($this->conf->group);
     }
     return $this->currentQueryBuilder;
 }
开发者ID:solire,项目名称:trieur,代码行数:25,代码来源:Doctrine.php

示例3: setOrderBy

 /**
  * @inheritdoc
  */
 protected function setOrderBy(ColumnPriorityQueue $gridColumns, QueryBuilder $queryBuilder)
 {
     $queryBuilder->addOrderBy('main.start', 'DESC')->addOrderBy('main.end', 'DESC')->addOrderBy('main.id', 'DESC');
 }
开发者ID:acp3,项目名称:module-news,代码行数:7,代码来源:DataGridRepository.php

示例4: setOrderBy

 /**
  * @param \ACP3\Core\Helpers\DataGrid\ColumnPriorityQueue $gridColumns
  * @param \Doctrine\DBAL\Query\QueryBuilder               $queryBuilder
  */
 protected function setOrderBy(ColumnPriorityQueue $gridColumns, QueryBuilder $queryBuilder)
 {
     foreach (clone $gridColumns as $gridColumn) {
         if ($gridColumn['default_sort'] === true) {
             if (!is_array($gridColumn['fields'])) {
                 $gridColumn['fields'] = [$gridColumn['fields']];
             }
             foreach ($gridColumn['fields'] as $field) {
                 $queryBuilder->addOrderBy($field, strtoupper($gridColumn['default_sort_direction']));
             }
         }
     }
 }
开发者ID:acp3,项目名称:core,代码行数:17,代码来源:DataGridRepository.php

示例5: make

 /**
  * @param array $request
  * @return array
  */
 public function make(array $request)
 {
     $output = ['data' => [], 'draw' => $request['draw'], 'recordsFiltered' => 0, 'recordsTotal' => 0];
     /**
      * Order By
      */
     if (isset($request['order'])) {
         for ($i = 0; $i < count($request['order']); ++$i) {
             $j = intval($request['order'][$i]['column']);
             if ($request['columns'][$j]['orderable'] != 'true') {
                 continue;
             }
             $column = $request['columns'][$j]['data'];
             $sort = $request['order'][$i]['dir'];
             $this->query->addOrderBy($column, $sort);
         }
     }
     /**
      * Count All
      */
     $temp = clone $this->query;
     $temp->resetQueryPart('select');
     $temp->resetQueryPart('orderBy');
     $temp->select("COUNT(*)");
     $output['recordsTotal'] = $temp->execute()->fetchColumn(0);
     /**
      * Filter
      */
     for ($i = 0; $i < count($request['columns']); ++$i) {
         if ($request['columns'][$i]['searchable'] != 'true') {
             continue;
         }
         $value = $request['columns'][$i]['search']['value'];
         if (strlen($value) > 0) {
             $column = $request['columns'][$i]['data'];
             $value = $this->query->getConnection()->quote("{$value}%");
             $this->query->andHaving($this->query->expr()->like($column, $value));
         }
     }
     /**
      * Search
      */
     if (isset($request['search'])) {
         $value = $request['search']['value'];
         if (strlen($value) > 0) {
             for ($i = 0; $i < count($request['columns']); ++$i) {
                 if ($request['columns'][$i]['searchable'] != 'true') {
                     continue;
                 }
                 $column = $request['columns'][$i]['data'];
                 $this->query->orHaving($this->query->expr()->like($column, ':search'));
             }
             $this->query->setParameter('search', "%{$value}%");
         }
     }
     /**
      * Count Filtered
      */
     $temp = clone $this->query;
     $temp->resetQueryPart('orderBy');
     $output['recordsFiltered'] = $temp->execute()->rowCount();
     /**
      * Limit
      */
     if (isset($request['start'])) {
         $this->query->setFirstResult($request['start']);
     }
     if (isset($request['length'])) {
         $this->query->setMaxResults($request['length']);
     }
     /**
      * Fetch Results
      */
     $output['data'] = $this->query->execute()->fetchAll(\PDO::FETCH_ASSOC);
     /**
      * Add Filter
      */
     return $output;
 }
开发者ID:vaibhavpandeyvpz,项目名称:acraviz,代码行数:83,代码来源:Datatables.php

示例6: addOrderByQuotesIdentifierAndDelegatesToConcreteQueryBuilder

 /**
  * @test
  */
 public function addOrderByQuotesIdentifierAndDelegatesToConcreteQueryBuilder()
 {
     $this->connection->quoteIdentifier('aField')->shouldBeCalled()->willReturnArgument(0);
     $this->concreteQueryBuilder->addOrderBy('aField', 'DESC')->shouldBeCalled()->willReturn($this->subject);
     $this->subject->addOrderBy('aField', 'DESC');
 }
开发者ID:dachcom-digital,项目名称:TYPO3.CMS,代码行数:9,代码来源:QueryBuilderTest.php

示例7: addOrderBy

 /**
  * {@inheritdoc}
  */
 public function addOrderBy($field, $direction)
 {
     return $this->queryBuilder->addOrderBy($field, $direction);
 }
开发者ID:ReissClothing,项目名称:Sylius,代码行数:7,代码来源:ExpressionBuilder.php

示例8: addOrderBy

 /**
  * Adds an ordering to the query results.
  *
  * @param string $sort The ordering expression.
  * @param string $order The ordering direction.
  *
  * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance.
  */
 public function addOrderBy($sort, $order = null)
 {
     $this->queryBuilder->addOrderBy($this->helper->quoteColumnName($sort), $order);
     return $this;
 }
开发者ID:rchicoli,项目名称:owncloud-core,代码行数:13,代码来源:QueryBuilder.php

示例9: buildOrderBy

 /**
  * Builds the ORDER BY part
  * @param QueryBuilder $qb
  * @param array $order_by
  * @return self
  */
 protected function buildOrderBy(QueryBuilder $qb, array $order_by = [])
 {
     foreach ($order_by as $order) {
         $column = null;
         $direction = 'ASC';
         if (is_string($order)) {
             $column = $order;
         } elseif (is_array($order) && count($order) === 2) {
             list($column, $direction) = $order;
         }
         if ($column === null || $this->getColumn($column) === null) {
             throw Schema\SchemaException::columnDoesNotExist($column, $this->table_name);
         }
         if (!in_array($direction, ['ASC', 'DESC'])) {
             throw QueryBuilderException::orderByDirectionDoesNotExist($direction);
         }
         $qb->addOrderBy($this->conn->quoteIdentifier($column), $direction);
     }
     return $this;
 }
开发者ID:schwaen,项目名称:doctrine-dbal-extensions,代码行数:26,代码来源:Model.php

示例10: addOrderBy

 /**
  * Adds an ordering to the query results.
  *
  * @param string $sort The ordering expression.
  * @param string $order The ordering direction.
  * @return QueryBuilder This QueryBuilder instance.
  */
 public function addOrderBy($sort, $order = null)
 {
     $connection = $this->getConnection();
     return parent::addOrderBy($connection->quoteIdentifier($sort), $order);
 }
开发者ID:GruppoMeta,项目名称:Movio,代码行数:12,代码来源:QueryBuilder.php

示例11: addSort

 /**
  * Helper function which iterates all sort arrays and at them as order by condition.
  * @param DBALQueryBuilder $builder
  * @param $sort
  * @return $this
  */
 private function addSort(DBALQueryBuilder $builder, $sort)
 {
     if (empty($sort)) {
         return $this;
     }
     foreach ($sort as $condition) {
         $builder->addOrderBy($condition['property'], $condition['direction']);
     }
     return $this;
 }
开发者ID:ClaudioThomas,项目名称:shopware-4,代码行数:16,代码来源:Repository.php

示例12: sortUnsortedByDefault

 /**
  * Sort products for current category by passed sort type
  *
  * @param QueryBuilder $builder
  * @param integer $orderBy
  */
 private function sortUnsortedByDefault($builder, $orderBy)
 {
     switch ($orderBy) {
         case 1:
             $builder->addOrderBy('product.datum', 'DESC')->addOrderBy('product.changetime', 'DESC');
             break;
         case 2:
             $builder->leftJoin('product', 's_articles_top_seller_ro', 'topSeller', 'topSeller.article_id = product.id')->addOrderBy('topSeller.sales', 'DESC')->addOrderBy('topSeller.article_id', 'DESC');
             break;
         case 3:
             $builder->addSelect('MIN(ROUND(defaultPrice.price * priceVariant.minpurchase * 1, 2)) as cheapest_price')->leftJoin('product', 's_articles_prices', 'defaultPrice', 'defaultPrice.articleID = product.id')->innerJoin('defaultPrice', 's_articles_details', 'priceVariant', 'priceVariant.id = defaultPrice.articledetailsID')->addOrderBy('cheapest_price', 'ASC')->addOrderBy('product.id', 'DESC');
             break;
         case 4:
             $builder->addSelect('MIN(ROUND(defaultPrice.price * priceVariant.minpurchase * 1, 2)) as cheapest_price')->leftJoin('product', 's_articles_prices', 'defaultPrice', 'defaultPrice.articleID = product.id')->innerJoin('defaultPrice', 's_articles_details', 'priceVariant', 'priceVariant.id = defaultPrice.articledetailsID')->addOrderBy('cheapest_price', 'DESC')->addOrderBy('product.id', 'DESC');
             break;
         case 5:
             $builder->addOrderBy('product.name', 'ASC');
             break;
         case 6:
             $builder->addOrderBy('product.name', 'DESC');
             break;
         case 7:
             $builder->addSelect('(SUM(vote.points) / COUNT(vote.id)) as votes')->leftJoin('product', 's_articles_vote', 'vote', 'product.id = vote.articleID')->addOrderBy('votes', 'DESC')->addOrderBy('product.id', 'DESC')->groupBy('product.id');
             break;
         case 9:
             $builder->innerJoin('product', 's_articles_details', 'variant', 'variant.id = product.main_detail_id')->addOrderBy('variant.instock', 'ASC')->addOrderBy('product.id', 'DESC');
             break;
         case 10:
             $builder->innerJoin('product', 's_articles_details', 'variant', 'variant.id = product.main_detail_id')->addOrderBy('variant.instock', 'DESC')->addOrderBy('product.id', 'DESC');
             break;
     }
 }
开发者ID:zirkeldesign,项目名称:SwagCustomSort,代码行数:38,代码来源:CustomSortRepository.php

示例13: addOrderBy

 /**
  * Adds an ordering to the query results.
  *
  * @param string $sort  The ordering expression.
  * @param string $order The ordering direction.
  *
  * @return self
  */
 public function addOrderBy($sort, $order = null)
 {
     $this->qb->addOrderBy($sort, $order);
     return $this;
 }
开发者ID:Maksold,项目名称:platform,代码行数:13,代码来源:SqlQueryBuilder.php

示例14: 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 "pricelth":
             $query->orderBy('pPrice', 'ASC');
             break;
         case "pricehtl":
             $query->orderBy('pPrice', '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:vividweb,项目名称:vivid_store,代码行数:66,代码来源:ProductList.php

示例15: applySorting

 /**
  * @inheritdoc
  */
 public function applySorting(QueryBuilder $builder, $modelClass, array $sortParams)
 {
     $table = $this->getTableName($modelClass);
     foreach ($sortParams as $sortParam) {
         /** @var SortParameterInterface $sortParam */
         $column = null;
         if ($sortParam->isRelationship() === false) {
             $column = $sortParam->getName();
         } elseif ($sortParam->getRelationshipType() === RelationshipTypes::BELONGS_TO) {
             $column = $this->getModelSchemes()->getForeignKey($modelClass, $sortParam->getName());
         }
         if ($column !== null) {
             $builder->addOrderBy($this->buildTableColumnName($table, $column), $sortParam->isAscending() === true ? 'ASC' : 'DESC');
         }
     }
 }
开发者ID:limoncello-php,项目名称:json-api,代码行数:19,代码来源:Repository.php


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