當前位置: 首頁>>代碼示例>>PHP>>正文


PHP QueryBuilder::orderBy方法代碼示例

本文整理匯總了PHP中Doctrine\ORM\QueryBuilder::orderBy方法的典型用法代碼示例。如果您正苦於以下問題:PHP QueryBuilder::orderBy方法的具體用法?PHP QueryBuilder::orderBy怎麽用?PHP QueryBuilder::orderBy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ORM\QueryBuilder的用法示例。


在下文中一共展示了QueryBuilder::orderBy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: process

 /**
  *
  * @return boolean
  */
 public function process()
 {
     $this->form->submit($this->request);
     if ($this->form->isValid()) {
         $formData = $this->form->getData();
         $name = (string) $formData->getName();
         if ($name) {
             $this->qb->andWhere($this->qb->expr()->like('p.name', ':name'))->setParameter('name', '%' . $name . '%');
         }
         $text = (string) $formData->getText();
         if ($text) {
             $this->qb->andWhere($this->qb->expr()->orx($this->qb->expr()->like('p.intro', ':intro'), $this->qb->expr()->like('p.content', ':content')))->setParameter('intro', '%' . $text . '%')->setParameter('content', '%' . $text . '%');
         }
         $isPublished = (string) $formData->getIsPublished();
         if ($isPublished) {
             if ($isPublished == 'yes') {
                 $this->qb->andWhere($this->qb->expr()->eq('p.status', ':status'))->setParameter('status', PostStatus::PUBLISHED);
             }
             if ($isPublished == 'no') {
                 $this->qb->andWhere($this->qb->expr()->neq('p.status', ':status'))->setParameter('status', PostStatus::PUBLISHED);
             }
         }
         $order = (string) $formData->getOrder();
         if ($order) {
             $this->qb->orderBy('p.' . $order, 'DESC');
         }
         return true;
     }
     return false;
 }
開發者ID:radutopala,項目名稱:BlogBundle,代碼行數:34,代碼來源:PostFilterHandler.php

示例2: getQueryRows

 /**
  * Build and returns Query for select rows
  * @param \Doctrine\ORM\QueryBuilder $queryBuilder
  * @param \EMC\TableBundle\Provider\QueryConfigInterface $queryConfig
  * @param array $mapping
  * @return \Doctrine\ORM\Query
  */
 private function getQueryRows(QueryBuilder $queryBuilder, QueryConfigInterface $queryConfig, array &$mapping)
 {
     $queryBuilder->resetDQLPart('select');
     $limit = $queryConfig->getLimit();
     $page = $queryConfig->getPage();
     $select = $queryConfig->getSelect();
     $orderBy = $queryConfig->getOrderBy();
     if ($limit > 0) {
         $queryBuilder->setMaxResults($limit)->setFirstResult(($page - 1) * $limit);
     }
     $mapping = array_map(function ($i) {
         return 'col' . $i;
     }, array_flip($select));
     foreach ($mapping as $column => $name) {
         $queryBuilder->addSelect($column . ' AS ' . $name);
     }
     if (count($orderBy) === 0) {
         $queryBuilder->orderBy($queryBuilder->getRootAlias() . '.id', 'ASC');
     } else {
         foreach ($orderBy as $column => $isAsc) {
             $queryBuilder->orderBy($column, $isAsc ? 'ASC' : 'DESC');
         }
     }
     return $queryBuilder->getQuery();
 }
開發者ID:cwd,項目名稱:TableBundle,代碼行數:32,代碼來源:DataProvider.php

示例3: search

 /**
  * @param ClientConditionInterface $condition
  * @return Client[]
  */
 public function search(ClientConditionInterface $condition)
 {
     $this->qb = $this->em->createQueryBuilder();
     $this->qb->select('c')->from('CoreBundle:Client', 'c');
     $this->initQueryBuilder($condition);
     $this->preparePagination($this->qb, $condition);
     $this->qb->orderBy('c.createdAt', 'DESC');
     return $this->qb->getQuery()->getResult();
 }
開發者ID:Exanrus,項目名稱:crm-bundle,代碼行數:13,代碼來源:ClientManager.php

示例4: getQueryResults

 /**
  * Get the query result
  *
  * @param integer $limit
  *
  * @return ArrayCollection
  */
 public function getQueryResults($limit = null)
 {
     if (isset($limit)) {
         $this->queryBuilder->setMaxResults($limit);
     }
     if (!$this->queryBuilder->getDQLPart('orderBy')) {
         $this->queryBuilder->orderBy('a.createdAt', 'ASC');
     }
     return $this->queryBuilder->getQuery()->getResult();
 }
開發者ID:opifer,項目名稱:rulesengine,代碼行數:17,代碼來源:DoctrineEnvironment.php

示例5: getItems

 public function getItems()
 {
     $this->qb->setMaxResults($this->getLimit());
     $this->qb->setFirstResult($this->getOffset());
     list($sortColumn, $sortType) = $this->getSorting();
     if ($sortColumn) {
         $this->qb->orderBy($this->qb->getRootAlias() . "." . $sortColumn, $sortType);
     }
     return $this->qb->getQuery()->getResult();
 }
開發者ID:janmarek,項目名稱:Neuron,代碼行數:10,代碼來源:DoctrineQueryBuilderModel.php

示例6: order

 protected function order()
 {
     $column = $this->getParamAdapter()->getColumn();
     $order = $this->getParamAdapter()->getOrder();
     if (!$column) {
         return;
     }
     $header = $this->getTable()->getHeader($column);
     $tableAlias = $header ? $header->getTableAlias() : 'q';
     if ($column) {
         $this->query->orderBy($tableAlias . '.' . $column, $order);
     }
 }
開發者ID:noc-med,項目名稱:zftable,代碼行數:13,代碼來源:DoctrineQueryBuilder.php

示例7: sort

 public function sort(array $p_cols)
 {
     foreach (array_keys($p_cols) as $id => $property) {
         if (!is_string($property)) {
             // not sortable
             continue;
         }
         if (@in_array($id, $p_params['sortCol'])) {
             $dir = @in_array($id, $p_params['sortDir']) ?: 'asc';
             $this->_queryObject->orderBy("e.{$property}", $dir);
         }
     }
 }
開發者ID:sourcefabric,項目名稱:newscoop,代碼行數:13,代碼來源:Doctrine.php

示例8: orderBy

 /**
  * Parse order conditions and add it to query
  *
  * @param string|null $sort
  * @param string|null $order
  */
 public function orderBy($sort = null, $order = null)
 {
     if (is_string($sort)) {
         if (strpos($sort, '.') > 0) {
             $parts = explode('.', $sort);
             if (count($parts) >= 2 && array_key_exists($parts[0], $this->metadata->associationMappings)) {
                 $this->qBuilder->innerJoin('e.' . $parts[0], $parts[0], Join::WITH);
                 $this->qBuilder->orderBy($parts[0] . '.' . $parts[1], $order);
             }
         } else {
             if (array_key_exists($sort, $this->metadata->fieldMappings)) {
                 $this->qBuilder->orderBy('e.' . $sort, $order);
             }
         }
     }
 }
開發者ID:sunnyct,項目名稱:silexcmf-doctrine,代碼行數:22,代碼來源:ORMQueryBuilder.php

示例9: sorting

 /**
  * @param QueryBuilder $qb
  * @param string $alias
  * @param string|null $sortField
  * @param string|null $sortOrder
  * @return QueryBuilder
  */
 protected function sorting(QueryBuilder $qb, string $alias, string $sortField = null, string $sortOrder = null)
 {
     if (!empty($sortField) && (strtolower($sortOrder) == 'asc' || strtolower($sortOrder) == 'desc')) {
         $qb->orderBy($alias . '.' . $sortField, $sortOrder);
     }
     return $qb;
 }
開發者ID:coresite,項目名稱:corebundle,代碼行數:14,代碼來源:FilterRepository.php

示例10: apply

 public static function apply(QueryBuilder $qb, array $orderBy)
 {
     foreach ($orderBy as $field => $sortOrder) {
         $qb->orderBy('a.' . Camelizer::camelize($field), $sortOrder);
     }
     return $qb;
 }
開發者ID:spdionis,項目名稱:un-webservice,代碼行數:7,代碼來源:SortHelper.php

示例11: modify

 /**
  * @param QueryBuilder $qb
  * @param string       $dqlAlias
  */
 public function modify(QueryBuilder $qb, $dqlAlias)
 {
     if ($this->dqlAlias !== null) {
         $dqlAlias = $this->dqlAlias;
     }
     $qb->orderBy(sprintf('%s.%s', $dqlAlias, $this->field), $this->order);
 }
開發者ID:kgilden,項目名稱:Doctrine-Specification,代碼行數:11,代碼來源:OrderBy.php

示例12: setOrder

 /**
  * set order
  * 
  * @param string $order_field
  * @param string $order_type
  * 
  * @return Datatable 
  */
 public function setOrder($order_field, $order_type)
 {
     $this->order_field = $order_field;
     $this->order_type = $order_type;
     $this->queryBuilder->orderBy($order_field, $order_type);
     return $this;
 }
開發者ID:tiraeth,項目名稱:AliDatatableBundle,代碼行數:15,代碼來源:DoctrineBuilder.php

示例13: filter

 /**
  * {@inheritdoc}
  */
 public function filter(Request $request, QueryBuilder $queryBuilder)
 {
     $order = $request->query->get('order') ?: self::DEFAULT_ORDER;
     if ($request->query->has('sort')) {
         $alias = $queryBuilder->getRootAliases()[0];
         $queryBuilder->orderBy($alias . '.' . $request->query->get('sort'), $order);
     }
 }
開發者ID:csbill,項目名稱:csbill,代碼行數:11,代碼來源:SortFilter.php

示例14: sort

 /**
  * Apply the sortings to the query builder
  *
  * @param QueryBuilder $queryBuilder
  * @param Sort         $sortCollectionDefinition
  *
  * @return \Doctrine\ORM\QueryBuilder
  */
 public function sort(QueryBuilder $queryBuilder, Sort $sortCollectionDefinition, $uniqueNameToQueryFieldMap)
 {
     /** @var $sortDefinition SortCondition */
     foreach ($sortCollectionDefinition as $sortDefinition) {
         $identifier = $uniqueNameToQueryFieldMap[$sortDefinition->getFieldName()];
         $queryBuilder->orderBy($identifier, $sortDefinition->getDirection());
     }
     return $queryBuilder;
 }
開發者ID:adlpz,項目名稱:DataSourceryBundle,代碼行數:17,代碼來源:Sorter.php

示例15: execute

 /**
  * @param $columns \Sorien\DataGridBundle\Grid\Column\Column[]
  * @param $page int Page Number
  * @param $limit int Rows Per Page
  * @return \Sorien\DataGridBundle\Grid\Rows
  */
 public function execute($columns, $page = 0, $limit = 0)
 {
     $this->query = $this->manager->createQueryBuilder($this->class);
     $this->query->from($this->class, self::TABLE_ALIAS);
     $where = $this->query->expr()->andx();
     $sorted = false;
     foreach ($columns as $column) {
         $this->query->addSelect($this->getFieldName($column));
         if ($column->isSorted() && !$column->isDefaultSort()) {
             $this->query->orderBy($this->getFieldName($column, false), $column->getOrder());
             $sorted = true;
         } elseif (!$sorted && $column->isSorted() && $column->isDefaultSort()) {
             $this->query->orderBy($this->getFieldName($column, false), $column->getOrder());
         }
         if ($column->isFiltered()) {
             if ($column->getFiltersConnection() == column::DATA_CONJUNCTION) {
                 foreach ($column->getFilters() as $filter) {
                     $operator = $this->normalizeOperator($filter->getOperator());
                     $where->add($this->query->expr()->{$operator}($this->getFieldName($column, false), $this->normalizeValue($filter->getOperator(), $filter->getValue())));
                 }
             } elseif ($column->getFiltersConnection() == column::DATA_DISJUNCTION) {
                 $sub = $this->query->expr()->orx();
                 foreach ($column->getFilters() as $filter) {
                     $operator = $this->normalizeOperator($filter->getOperator());
                     $sub->add($this->query->expr()->{$operator}($this->getFieldName($column, false), $this->normalizeValue($filter->getOperator(), $filter->getValue())));
                 }
                 $where->add($sub);
             }
             $this->query->where($where);
         }
     }
     foreach ($this->joins as $alias => $field) {
         $this->query->leftJoin($field, $alias);
     }
     if ($page > 0) {
         $this->query->setFirstResult($page * $limit);
     }
     if ($limit > 0) {
         $this->query->setMaxResults($limit);
     }
     //call overridden prepareQuery or associated closure
     $query = $this->prepareQuery(clone $this->query);
     $items = $query->getQuery()->getResult();
     // hydrate result
     $result = new Rows();
     foreach ($items as $item) {
         $row = new Row();
         foreach ($item as $key => $value) {
             $row->setField($key, $value);
         }
         //call overridden prepareRow or associated closure
         if (($modifiedRow = $this->prepareRow($row)) != null) {
             $result->addRow($modifiedRow);
         }
     }
     return $result;
 }
開發者ID:sxn,項目名稱:DataGridBundle,代碼行數:63,代碼來源:Entity.php


注:本文中的Doctrine\ORM\QueryBuilder::orderBy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。