当前位置: 首页>>代码示例>>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;未经允许,请勿转载。