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


PHP SelectInterface::orderBy方法代碼示例

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


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

示例1: addSort

 /**
  * Adds the sort to the build query.
  *
  * @return \Drupal\Core\Entity\Query\Sql\Query
  *   Returns the called object.
  */
 protected function addSort()
 {
     if ($this->count) {
         $this->sort = array();
     }
     // Gather the SQL field aliases first to make sure every field table
     // necessary is added. This might change whether the query is simple or
     // not. See below for more on simple queries.
     $sort = array();
     if ($this->sort) {
         foreach ($this->sort as $key => $data) {
             $sort[$key] = $this->getSqlField($data['field'], $data['langcode']);
         }
     }
     $simple_query = $this->isSimpleQuery();
     // If the query is set up for paging either via pager or by range or a
     // count is requested, then the correct amount of rows returned is
     // important. If the entity has a data table or multiple value fields are
     // involved then each revision might appear in several rows and this needs
     // a significantly more complex query.
     if (!$simple_query) {
         // First, GROUP BY revision id (if it has been added) and entity id.
         // Now each group contains a single revision of an entity.
         foreach ($this->sqlFields as $field) {
             $group_by = "{$field['0']}.{$field['1']}";
             $this->sqlGroupBy[$group_by] = $group_by;
         }
     }
     // Now we know whether this is a simple query or not, actually do the
     // sorting.
     foreach ($sort as $key => $sql_alias) {
         $direction = $this->sort[$key]['direction'];
         if ($simple_query || isset($this->sqlGroupBy[$sql_alias])) {
             // Simple queries, and the grouped columns of complicated queries
             // can be ordered normally, without the aggregation function.
             $this->sqlQuery->orderBy($sql_alias, $direction);
             if (!isset($this->sqlFields[$sql_alias])) {
                 $this->sqlFields[$sql_alias] = explode('.', $sql_alias);
             }
         } else {
             // Order based on the smallest element of each group if the
             // direction is ascending, or on the largest element of each group
             // if the direction is descending.
             $function = $direction == 'ASC' ? 'min' : 'max';
             $expression = "{$function}({$sql_alias})";
             $expression_alias = $this->sqlQuery->addExpression($expression);
             $this->sqlQuery->orderBy($expression_alias, $direction);
         }
     }
     return $this;
 }
開發者ID:davidsoloman,項目名稱:drupalconsole.com,代碼行數:57,代碼來源:Query.php

示例2: orderBy

 public function orderBy($field, $direction = 'ASC')
 {
     $this->query->orderBy($field, $direction);
     return $this;
 }
開發者ID:nstielau,項目名稱:drops-8,代碼行數:5,代碼來源:SelectExtender.php


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