Ejemplo n.º 1
0
 protected function checkQuerySelects()
 {
     $selects = $this->query->getQuery()->columns;
     $tableSelect = $this->model->getTable() . '.*';
     if (empty($selects) || !in_array($tableSelect, $selects)) {
         $this->query->addSelect($tableSelect);
     }
 }
Ejemplo n.º 2
0
 /**
  * Return the query.
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function getQuery()
 {
     // If report is detailed, add all columns of modelGridQueries used by the gridQuery.
     // If report is summary, and method summaryGroupBy() is called, the columns are added
     // starting from the groupByKey which is a column of an modelGridQuery
     if ($this->isDetailed) {
         $this->query->addSelect($this->gridQuery->makeSelect($this->gridQuery->columnsToAddSelect()));
     }
     return $this->query;
 }
Ejemplo n.º 3
0
 /**
  * @param Builder $query
  *
  * @return void
  */
 public function select(Builder $query)
 {
     if (!is_null($select = $this->getRule()->getField()->getSelectField())) {
         if ($select instanceof Builder) {
             $query->selectSub($select->toSql(), $this->getRule()->getField()->getQueryField());
         } else {
             $query->addSelect($select);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Filter a query by the value of a
  * field using this field type.
  *
  * @param Builder         $query
  * @param FilterInterface $filter
  */
 public function filter(Builder $query, FilterInterface $filter)
 {
     $stream = $filter->getStream();
     $assignment = $stream->getAssignment($filter->getField());
     $column = $this->fieldType->getColumnName();
     $translations = $stream->getEntryTranslationsTableName();
     if ($assignment->isTranslatable()) {
         if ($query instanceof EloquentQueryBuilder && !$query->hasJoin($translations)) {
             $query->leftJoin($stream->getEntryTranslationsTableName(), $stream->getEntryTableName() . '.id', '=', $stream->getEntryTranslationsTableName() . '.entry_id');
         }
         $query->addSelect($translations . '.locale');
         $query->addSelect($translations . '.' . $column);
         $query->{$this->where()}(function (Builder $query) use($stream, $filter, $column) {
             $query->where($stream->getEntryTranslationsTableName() . '.locale', config('app.locale'));
             $query->where($stream->getEntryTranslationsTableName() . '.' . $column, 'LIKE', "%" . $filter->getValue() . "%");
         });
     } else {
         $query->{$this->where()}(function (Builder $query) use($stream, $filter, $column) {
             $query->where($stream->getEntryTableName() . '.' . $column, 'LIKE', "%" . $filter->getValue() . "%");
         });
     }
 }
 /**
  * Apply the scope to a given Eloquent query builder.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $builder
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return void
  */
 public function apply(Builder $builder, Model $model)
 {
     if (isset($model['calculated_columns'])) {
         $builder->addSelect('*');
         foreach ($model['calculated_columns'] as $column => $query) {
             if (str_contains($query, ':user_id')) {
                 $query = auth() && auth()->user() ? str_replace(':user_id', auth()->user()->id, $query) : 'false';
             }
             $builder->selectSub($query, $column);
         }
     }
     return $builder;
 }
Ejemplo n.º 6
0
 /**
  * Очень простая фильтрация скоупов.
  *
  * Если необходимо отфильтровать скоупы по id чему либо, обязательно нужно создать scope следующего вида.<br>
  * Пример:
  * * Ссылка для фильтрации - `catalog_id=*`
  * * Метод - `public function scopeCatalogId($int) {}`
  *
  * @return \Illuminate\Support\Collection
  */
 protected function filterScopes()
 {
     if (count($this->_request) > 0) {
         foreach ($this->_request as $scope => $value) {
             if (!empty($value)) {
                 //checked scope method for model
                 if (method_exists($this->_query->getModel(), 'scope' . camel_case($scope))) {
                     $this->_query->{camel_case($scope)}($value);
                 } else {
                     $values = explode(',', $value);
                     if (count($values) > 1) {
                         $this->filterSearch($scope, $values[0], '>');
                         $this->filterSearch($scope, $values[1], '<');
                     } else {
                         $this->filterSearch($scope, $value, 'like', '%', '%');
                     }
                 }
             }
         }
         $this->_query->addSelect($this->_query->getModel()->getTable() . '.*');
     }
     return $this->_request;
 }
Ejemplo n.º 7
0
 public function execute(Builder $query)
 {
     return $query->addSelect(DB::raw("(((match(search_texts.title) against ('{$this->text}')) * 100) + ((match(search_texts.meta) against ('{$this->text}')) * 20) + ((match(search_texts.standfirst) against ('{$this->text}')) * 10) + match(search_texts.text) against ('{$this->text}')) as rel"))->join('search_texts', 'pages.id', '=', 'search_texts.page_id')->where('search_texts.embargoed_until', '<=', time())->orderBy('rel', 'desc');
 }
Ejemplo n.º 8
0
 /**
  * Puts all the select clauses to the main query.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  * @param array $selects
  */
 protected function addSelectsToQuery(Builder $query, array $selects)
 {
     $selects = new Expression(implode(' + ', $selects) . ' as relevance');
     $query->addSelect($selects);
 }
Ejemplo n.º 9
0
 /**
  * @param Builder           $query
  * @param DocumentInterface $document
  */
 public function querySelectColumn(Builder $query, DocumentInterface $document)
 {
     $query->addSelect($this->getDBKey());
 }
Ejemplo n.º 10
0
 /**
  * @param Builder $table
  *
  * @return Builder
  */
 public function apply(Builder $table)
 {
     return $table->addSelect($this->getColumnsToSelect());
 }
Ejemplo n.º 11
0
 public function build(Builder $query)
 {
     return $query->addSelect(DB::raw('count(pages_tags.tag_id) as tag_count'))->join('pages_tags', 'pages.id', '=', 'pages_tags.page_id')->whereIn('tag_id', $this->tagIds)->where('pages.id', '!=', $this->page->getId())->orderBy('tag_count', 'desc')->orderBy(DB::raw('rand()'))->groupBy('pages.id');
 }