Example #1
0
 /**
  * Applies parameter filtering for a given query
  *
  * @param string          $name
  * @param mixed           $value
  * @param EloquentBuilder $query
  * @param FilterInterface $filter
  * @return EloquentBuilder
  */
 public function apply($name, $value, $query, FilterInterface $filter)
 {
     $column = (!empty($this->table) ? $this->table . '.' : null) . (!empty($this->column) ? $this->column : $name);
     return $query->where(function ($query) use($column) {
         return $query->whereNull($column)->orWhere($column, '');
     });
 }
Example #2
0
 public function execute(Builder $query)
 {
     if ($this->group) {
         return $query->where('group', '=', $this->group);
     } else {
         return $query->whereNull('group');
     }
 }
Example #3
0
 public function build(Builder $query)
 {
     if ($this->parentId) {
         return $query->where('parent_id', '=', $this->parentId);
     } else {
         return $query->whereNull('parent_id');
     }
 }
Example #4
0
 /**
  * @param Builder $query
  *
  * @return Builder
  */
 public function build(Builder $query)
 {
     if ($this->page === null) {
         return $query->whereNull('parent_id');
     }
     list($col, $direction) = $this->page->getChildOrderingPolicy();
     return $query->where('parent_id', '=', $this->page->getId())->orderBy($col, $direction);
 }
Example #5
0
 /**
  * @param User $actor
  * @param Builder $query
  */
 public function find(User $actor, Builder $query)
 {
     if (!$actor->hasPermission('discussion.hide')) {
         $query->where(function ($query) use($actor) {
             $query->whereNull('discussions.hide_time')->where('comments_count', '>', 0)->orWhere('start_user_id', $actor->id);
             $this->events->fire(new ScopeHiddenDiscussionVisibility($query, $actor, 'discussion.hide'));
         });
     }
 }
Example #6
0
 /**
  * Overriding newQuery() to the custom PostBuilder with some intereting methods
  * 
  * @param bool $excludeDeleted
  * @return Corcel\PostBuilder
  */
 public function newQuery($excludeDeleted = true)
 {
     $builder = new Builder($this->newBaseQueryBuilder());
     $builder->setModel($this);
     $builder->leftJoin('wp_term_taxonomy', 'wp_terms.term_id', '=', 'wp_term_taxonomy.term_id')->where('wp_term_taxonomy.taxonomy', '=', 'category')->select('wp_terms.*');
     if ($excludeDeleted and $this->softDelete) {
         $builder->whereNull($this->getQualifiedDeletedAtColumn());
     }
     return $builder;
 }
Example #7
0
 /**
  * Constrain a query to an ability for a specific model.
  *
  * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return void
  */
 public function scopeForModel($query, Model $model)
 {
     $query->where(function ($query) use($model) {
         $query->where('entity_type', $model->getMorphClass());
         $query->where(function ($query) use($model) {
             $query->whereNull('entity_id');
             if ($model->exists) {
                 $query->orWhere('entity_id', $model->getKey());
             }
         });
     });
 }
Example #8
0
 /**
  * @param Builder $builder
  * @param Collection $tags
  * @return Builder
  */
 public function scopeTaggedWith(Builder $builder, Collection $tags)
 {
     /** @var MorphToMany $relation */
     $relation = $this->tags();
     $key = $this->getTable() . '.' . $this->getKeyName();
     if ($tags->count()) {
         $builder->join($relation->getTable(), function ($join) use($relation, $key, $tags) {
             $join->on($relation->getForeignKey(), '=', $key);
             $join->where($relation->getMorphType(), '=', $relation->getMorphClass());
             $join->whereIn($relation->getOtherKey(), $tags->keys()->toArray());
         });
     } else {
         $builder->whereNull($this->getTable());
     }
     return $builder;
 }
Example #9
0
 /**
  * Aplicar.
  *
  * @param Builder $builder
  * @param Model $model
  */
 public function apply(Builder $builder, Model $model)
 {
     // Verificar se deve filtrar o inquilino
     if (isset($model->multTenant) && $model->multTenant == true) {
         // Verificar se esta logado
         if (is_null(\Auth::id())) {
             return;
         }
         // Verificar qual o inquilino informado
         $inquilino_id = \Auth::user()->{Table::tenantField()};
         if (is_null($inquilino_id)) {
             $builder->whereNull(Table::tenantField());
         } else {
             $builder->where(Table::tenantField(), $inquilino_id);
         }
     }
 }
Example #10
0
 /**
  * Finds all non-scheduled incidents.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeNotScheduled(Builder $query)
 {
     return $query->where('status', '>', 0)->orWhere(function ($query) {
         $query->where('status', 0)->where(function ($query) {
             $query->whereNull('scheduled_at')->orWhere('scheduled_at', '<=', Carbon::now()->toDateTimeString());
         });
     });
 }
Example #11
0
 /**
  * Constrain a query to an permission for a specific model.
  *
  * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Model|string  $model
  * @param  bool  $strict
  * @return void
  */
 public function scopeForModel($query, $model, $strict = false)
 {
     $model = is_string($model) ? new $model() : $model;
     $query->where(function ($query) use($model, $strict) {
         $query->where('entity_type', $model->getMorphClass());
         $query->where(function ($query) use($model, $strict) {
             // If the model does not exist, we want to search for blanket permissions
             // that cover all instances of this model. If it does exist, we only
             // want to find blanket permissions if we're not using strict mode.
             if (!$model->exists || !$strict) {
                 $query->whereNull('entity_id');
             }
             if ($model->exists) {
                 $query->orWhere('entity_id', $model->getKey());
             }
         });
     });
 }
Example #12
0
 /**
  * Returns all the guest users.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeGuests(Builder $query)
 {
     return $query->whereNull('user_id');
 }
 private function generateNullConditionFromHasOneOrMany(HasOneOrMany $relation)
 {
     $this->query = $this->query->whereNull($relation->getForeignKey());
 }
Example #14
0
 public function scopeParents(Builder $builder)
 {
     $builder->whereNull('parent_id');
 }
Example #15
0
 /**
  * Add a whereNull to the query
  *
  * @param $field
  * @return mixed
  */
 public function whereNull($field)
 {
     $this->builder = $this->builder->whereNull($field);
     return $this;
 }
Example #16
0
 /**
  * Get a new query builder for the model's table.
  *
  * @param  bool  $excludeDeleted
  * @return \Illuminate\Database\Eloquent\Builder|static
  */
 public function newQuery($excludeDeleted = true)
 {
     $builder = new Builder($this->newBaseQueryBuilder());
     // Once we have the query builders, we will set the model instances so the
     // builder can easily access any information it may need from the model
     // while it is constructing and executing various queries against it.
     $builder->setModel($this)->with($this->with);
     if ($excludeDeleted and $this->softDelete) {
         $builder->whereNull($this->getQualifiedDeletedAtColumn());
     }
     return $builder;
 }
Example #17
0
 /**
  * Overwrite the whereNull method to add the table name in front of the column
  *
  * @param $column
  * @param string $boolean
  * @param bool|false $not
  * @return mixed
  */
 public function whereNull($column, $boolean = 'and', $not = false)
 {
     return parent::whereNull($this->getModelTableColumn($column), $boolean, $not);
 }
Example #18
0
 /**
  * Modifies the query to only include files without clippables.
  *
  * @param Builder $query
  * @return Builder
  */
 public function scopeUnattached(Builder $query)
 {
     return $query->whereNull('clippable_id')->whereNull('clippable_type');
 }
 /**
  * @param Builder $builder
  * @return Builder
  */
 public function scopeExpired(Builder $builder)
 {
     $builder->whereNull('expired_at')->orWhere('expired_at', '<=', Carbon::now());
     return $builder;
 }
Example #20
0
 public function scopeActive(Builder $query)
 {
     $query->whereNull('approved');
 }
Example #21
0
 public function apply(Builder $builder, Model $model)
 {
     $builder->whereNull($model->getQualifiedArchivedAtColumn());
 }
Example #22
0
 /**
  * Scopes to non-hooked repositories.
  *
  * @param \Illuminate\Database\Eloquent\Builder $builder
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeNotHooked(Builder $builder)
 {
     return $builder->whereNull('hook_id');
 }
Example #23
0
 /**
  * Constrain a query to simple abilities.
  *
  * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder  $query
  * @return void
  */
 public function scopeSimpleAbility($query)
 {
     $query->whereNull("{$this->table}.entity_type");
 }
 /**
  * Query filters.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $query
  * @return \Illuminate\Database\Eloquent\Builder
  */
 protected function queryFilters($query, $filters = [])
 {
     $filters = $filters ?: $this->filters;
     foreach ($filters as $key => $filter) {
         foreach ($filter as $operator => $values) {
             $values = is_array($values) ? $values : [$values];
             $operator = is_numeric($operator) ? '=' : $operator;
             if ($operator == '=') {
                 $query->whereIn($key, $values);
             } elseif ($operator == '!=') {
                 $query->whereNotIn($key, $values);
             } elseif ($operator == 'null') {
                 $query->whereNull($key);
             } elseif ($operator == 'not_null') {
                 $query->whereNotNull($key);
             } else {
                 $query->where($key, $operator, head($values));
             }
         }
     }
     return $query;
 }
Example #25
0
 /**
  * Query scope for active groups.
  */
 public function scopeActive(Builder $query)
 {
     return $query->whereNull($this->getInactiveColumn());
 }
Example #26
0
 /**
  * Scope for get node items of root
  *
  * @param Builder $query query builder
  * @return Builder
  */
 public function scopeRoots(Builder $query)
 {
     return $query->whereNull($this->getParentIdName())->orderBy($this->getOrderKeyName(), 'asc');
 }
Example #27
0
 /**
  * Finds all non-scheduled incidents.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeNotScheduled($query)
 {
     return $query->where(function ($query) {
         return $query->whereNull('scheduled_at')->orWhere('scheduled_at', '<=', Carbon::now());
     });
 }
Example #28
0
 /**
  * Scope of categories with no parents.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeRoots($query)
 {
     return $query->whereNull('parent_category_id');
 }
 /**
  * Scope a query to only include activities that have no sign-up and not passed the current date.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query  the query to activities to be scoped
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeUnfilled($query)
 {
     $query->select('activities.*')->leftJoin('tasks', 'activities.activity_id', '=', 'tasks.activity_id')->where(function ($query) {
         $query->whereNull('tasks.approval')->orWhere(function ($orQuery) {
             $orQuery->whereNotIn('tasks.approval', ['pending', 'approved']);
         });
     })->upcoming();
 }
Example #30
0
 /**
  * @param $key
  * @return static
  */
 public function whereNull($key)
 {
     return parent::whereNull($key);
 }