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


PHP Builder::groupBy方法代碼示例

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


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

示例1: summaryGroupBy

 /**
  * Create the summary columns with aggregate calls in select clause and group aggregates query using $groupByKey.
  *
  * @param  string $groupByKey
  * @return $this
  */
 public function summaryGroupBy($groupByKey)
 {
     // ReportData is in summary, so set $isDetailed to false
     $this->isDetailed = false;
     // Get the modelGridQueries starting from an mgq which it has the groupByKey column.
     $mgqs = array_start_from($this->gridQuery->getModelGridQueries(), function ($mgq) use($groupByKey) {
         return !is_null($mgq->{$groupByKey});
     });
     // Then add the columns of those mgqs in select clause.
     foreach ($mgqs as $mgq) {
         // Do not addSelect() if mgq has a static columnsToAddSelect method, since it will be added later.
         if (!method_exists($mgq, 'columnsToAddSelect')) {
             $this->query->addSelect($mgq->makeSelect());
         }
     }
     /*
      * Start using the defaultGroupByKey() method.
      * Use the defaultGroupByKey if gridQuery has.
      */
     $defaultGroupByKeys = $this->gridQuery->defaultGroupByKey();
     // Convert to array for those single groupByKeys
     if (!is_array($defaultGroupByKeys)) {
         $defaultGroupByKeys = [$defaultGroupByKeys];
     }
     foreach ($defaultGroupByKeys as $defaultGroupByKey => $groupByColumn) {
         // Use the groupByColumn string as the defaultGroupByColumnKey
         $defaultGroupByKey = is_int($defaultGroupByKey) ? $groupByColumn : $defaultGroupByKey;
         $this->query->addSelect(DB::raw("{$groupByColumn} as {$defaultGroupByKey}"));
         // Query group by $defautlGroupByKey
         $this->query->groupBy($defaultGroupByKey);
     }
     // Finally, use the groupByKey to group query for the summary report
     $this->query->groupBy($groupByKey);
     return $this;
 }
開發者ID:sedp-mis,項目名稱:base-report,代碼行數:41,代碼來源:ReportQueryBuilder.php

示例2: checkQueryGroupBy

 protected function checkQueryGroupBy()
 {
     $groups = $this->query->getQuery()->groups;
     $keyGroup = $this->model->getQualifiedKeyName();
     if (empty($groups) || !in_array($keyGroup, $groups)) {
         $this->query->groupBy($keyGroup);
     }
 }
開發者ID:anlutro,項目名稱:l4-core,代碼行數:8,代碼來源:RelationshipQueryJoiner.php

示例3: apply

 public function apply(Query $query, BaseRepository $repository)
 {
     $meta = false;
     if (isset($this->filter['meta'])) {
         $meta = $this->filter['meta'];
         unset($this->filter['meta']);
     }
     if (!empty($this->filter)) {
         $query->where($this->filter);
     }
     if (!empty($meta)) {
         $table = $query->getModel()->getTable();
         $query->join('meta', $table . '.id', '=', 'meta.object_id');
         $metaQuery = $query->getQuery()->newQuery();
         foreach ($meta as $k => $v) {
             $metaQuery->orWhere(['meta.key' => $k, 'meta.value' => $v]);
         }
         $query->addNestedWhereQuery($metaQuery);
         $query->groupBy($table . '.id');
         $results = $query->get();
     }
 }
開發者ID:psesd,項目名稱:chms-common,代碼行數:22,代碼來源:QueryFilter.php

示例4: makeGroupBy

 /**
  * Makes the query not repeat the results.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  */
 protected function makeGroupBy(Builder $query)
 {
     $driver = $this->getDatabaseDriver();
     if ($driver == 'sqlsrv') {
         $columns = $this->getTableColumns();
     } else {
         $id = $this->getTable() . '.' . $this->primaryKey;
         $joins = array_keys($this->getJoins());
         foreach ($this->getColumns() as $column => $relevance) {
             array_map(function ($join) use($column, $query) {
                 if (Str::contains($column, $join)) {
                     $query->groupBy("{$column}");
                 }
             }, $joins);
         }
     }
     $query->groupBy($id);
 }
開發者ID:singgihsap,項目名稱:elearning,代碼行數:23,代碼來源:SearchableTrait.php

示例5: applyQuery

 /**
  * @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query
  * @return void
  */
 public function applyQuery($query)
 {
     $query->selectRaw($this->getSQLSelect($query->from) . ' as __interval__');
     $query->groupBy('__interval__');
 }
開發者ID:legalweb,項目名稱:php-statistics-helper,代碼行數:9,代碼來源:Interval.php

示例6: groupBy

 /**
  * @param $key
  * @param $value
  * @return static
  */
 public function groupBy($key)
 {
     return parent::groupBy($key);
 }
開發者ID:garrinar,項目名稱:laravel,代碼行數:9,代碼來源:Builder.php

示例7: makeGroupBy

 /**
  * Makes the query not repeat the results.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  */
 protected function makeGroupBy(Builder $query)
 {
     if ($groupBy = $this->getGroupBy()) {
         $query->groupBy($groupBy);
     } else {
         $driver = $this->getDatabaseDriver();
         if ($driver == 'sqlsrv') {
             $columns = $this->getTableColumns();
         } else {
             $columns = $this->getTable() . '.' . $this->primaryKey;
         }
         $query->groupBy($columns);
         $joins = array_keys($this->getJoins());
         foreach ($this->getColumns() as $column => $relevance) {
             array_map(function ($join) use($column, $query) {
                 if (Str::contains($column, $join)) {
                     if (Str::startsWith($column, DB::getTablePrefix())) {
                         $column = substr($column, strlen(DB::getTablePrefix()));
                     }
                     $query->groupBy($column);
                 }
             }, $joins);
         }
     }
 }
開發者ID:jacobcyl,項目名稱:searchable,代碼行數:30,代碼來源:SearchableTrait.php

示例8: makeGroupBy

 /**
  * Makes the query not repeat the results.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  */
 protected function makeGroupBy(Builder $query)
 {
     if ($groupBy = $this->getGroupBy()) {
         $query->groupBy($groupBy);
         return $query;
     }
     $columns = $this->getTable() . '.' . $this->primaryKey;
     $query->groupBy($columns);
     $joins = array_keys($this->getJoins());
     foreach (array_keys($this->getColumns()) as $column) {
         array_map(function ($join) use($column, $query) {
             if (str_contains($column, $join)) {
                 $query->groupBy($column);
             }
         }, $joins);
     }
 }
開發者ID:askedio,項目名稱:laravel-cruddy,代碼行數:22,代碼來源:SearchableTrait.php


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