Scope schedules that are in progress.

@param \Illuminate\Database\Eloquent\Builder $query

@return \Illuminate\Database\Eloquent\Builder
973715
public function scopeInProgress(Builder $query)
    {
        return $query->where('scheduled_at', '<=', Carbon::now())->where('status', '<>', self::COMPLETE)->where(function ($query) {
            $query->whereNull('completed_at')->orWhere('completed_at', '>', Carbon::now());
        });
    }
1155093
public function getScopes($query, $scopes)
    {
        if ($scopes & self::DEFAULT) {
            return $query;
        }

        if ($scopes & self::WITH_DELETED) {
            return $query->withTrashed();
        }

        if ($scopes & self::DELETED_ONLY) {
            return $query->onlyTrashed();
        }

        return $query;
    }
1237042
public function applyScopeToQuery($scope, $query)
    {
        if (is_string($scope)) {
            $scope = $this->getScope($scope);
        }

        if (!$scope->value) {
            return;
        }

        switch ($scope->type) {
            case 'date':
                if ($scope->value instanceof Carbon) {
                    $value = $scope->value;

                    /*
                     * Condition
                     */
                    if ($scopeConditions = $scope->conditions) {
                        $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                            ':filtered' => $value->format('Y-m-d'),
                            ':after'    => $value->format('Y-m-d H:i:s'),
                            ':before'   => $value->copy()->addDay()->addMinutes(-1)->format('Y-m-d H:i:s')
                        ])));
                    }
                    /*
                     * Scope
                     */
                    elseif ($scopeMethod = $scope->scope) {
                        $query->$scopeMethod($value);
                    }
                }

                break;

            case 'daterange':
                if (is_array($scope->value) && count($scope->value) > 1) {
                    list($after, $before) = array_values($scope->value);

                    if ($after && $after instanceof Carbon && $before && $before instanceof Carbon) {

                        /*
                         * Condition
                         */
                        if ($scopeConditions = $scope->conditions) {
                            $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                                ':afterDate'  => $after->format('Y-m-d'),
                                ':after'      => $after->format('Y-m-d H:i:s'),
                                ':beforeDate' => $before->format('Y-m-d'),
                                ':before'     => $before->format('Y-m-d H:i:s')
                            ])));
                        }
                        /*
                         * Scope
                         */
                        elseif ($scopeMethod = $scope->scope) {
                            $query->$scopeMethod($after, $before);
                        }
                    }
                }

                break;

            case 'number':
                if (is_numeric($scope->value)) {
                    /*
                     * Condition
                     */
                    if ($scopeConditions = $scope->conditions) {
                        $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                            ':filtered' => $scope->value,
                        ])));
                    }
                    /*
                     * Scope
                     */
                    elseif ($scopeMethod = $scope->scope) {
                        $query->$scopeMethod($scope->value);
                    }
                }

                break;

            case 'numberrange':
                if (is_array($scope->value) && count($scope->value) > 1) {
                    list($min, $max) = array_values($scope->value);

                    if ($min && $max) {

                        /*
                         * Condition
                         *
                         */
                        if ($scopeConditions = $scope->conditions) {
                            $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                                ':min'  => $min,
                                ':max'  => $max
                            ])));
                        }
                        /*
                         * Scope
                         */
                        elseif ($scopeMethod = $scope->scope) {
                            $query->$scopeMethod($min, $max);
                        }
                    }
                }

                break;

            case 'text':
                /*
                 * Condition
                 */
                if ($scopeConditions = $scope->conditions) {
                    $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [
                        ':value' => Db::getPdo()->quote($scope->value),
                    ])));
                }

                /*
                 * Scope
                 */
                elseif ($scopeMethod = $scope->scope) {
                    $query->$scopeMethod($scope->value);
                }

                break;

            default:
                $value = is_array($scope->value) ? array_keys($scope->value) : $scope->value;

                /*
                 * Condition
                 */
                if ($scopeConditions = $scope->conditions) {

                    /*
                     * Switch scope: multiple conditions, value either 1 or 2
                     */
                    if (is_array($scopeConditions)) {
                        $conditionNum = is_array($value) ? 0 : $value - 1;
                        list($scopeConditions) = array_slice($scopeConditions, $conditionNum);
                    }

                    if (is_array($value)) {
                        $filtered = implode(',', array_build($value, function ($key, $_value) {
                            return [$key, Db::getPdo()->quote($_value)];
                        }));
                    }
                    else {
                        $filtered = Db::getPdo()->quote($value);
                    }

                    $query->whereRaw(DbDongle::parse(strtr($scopeConditions, [':filtered' => $filtered])));
                }
                /*
                 * Scope
                 */
                elseif ($scopeMethod = $scope->scope) {
                    $query->$scopeMethod($value);
                }

                break;
        }

        return $query;
    }
942347
public function getPager($query)
    {
        $pager = new Pagerfanta(new DoctrineORMAdapter($query, true, false));
        return $pager->setNormalizeOutOfRangePages(true);
    }
207058
public function scopeOrder(Builder $query)
    {
        if ($order = config('typicms.'.$this->getTable().'.order')) {
            foreach ($order as $column => $direction) {
                $query->orderBy($column, $direction);
            }
        }

        return $query;
    }
1016004
public function scopeLastActive($query, $minutes = null)
    {
        $date = $this->freshTimestamp()->subMinutes(
            $minutes ?: config('laravel_auth.track-activity.minutes', 5)
        )->toDateTimeString();

        return $query->where('last_activity', '>=', $date);
    }
969392
public function scopeResellers(Builder $query)
    {
        $query->with('roles')->whereNotNull('tbl_users.id')->whereHas('roles', function ($query) {
            $query->whereIn('tbl_roles.name', ['reseller']);
        });


        return $query;
    }
609955
public function scopeStillActive($query)
    {
        $query->where(function ($query) {
            return $query->where('start_at', '<=', Carbon::now())->orWhereNull('start_at');
        })
        ->where(function ($query) {
            return $query->where('end_at', '>=', Carbon::now())->orWhereNull('end_at');
        })
        ->where(function ($query) {
            return $query->where('parent_id', 0)->orWhereNull('parent_id');
        });

        return $query;
    }
597019
public function setEagerLoaded($query)
	{
		if( ! empty($this->getEagerLoad()))
		{
			$query = $query->with($this->getEagerLoad());
		}

		return $query;
	}
146143
public function scopeUseless($query)
    {
        return $query
            ->where(function ($q) {
                $this->scopeExpired($q);
            })
            ->orWhere(function ($q) {
                $this->scopeFull($q);
            });
    }
741053
public function scopeFromDecadesAgo(Builder $query, $ago, $endDateTime = null)
    {
        return $this->scopeFromDateTimeRange(DateTime::getDecadesAgo($ago, $endDateTime));
    }
1162707
public function scopeMatchUsingRequest($query)
    {
        return $query->where(function ($query) {
            $from = $this->pathAndQuery();
            $escaped_from = DB::connection()->getPdo()->quote($from);
            $from_col = DB::getDriverName() == 'sqlsrv' ? '[from]' : '`from`';
            $query->where('from', $from)->orWhereRaw("{$escaped_from} LIKE {$from_col}");
            if (Config::get('decoy::core.allow_regex_in_redirects')) {
                $query->orWhereRaw("{$escaped_from} REGEXP {$from_col}");
            }
        });
    }
313252
public function query($query)
    {
        if (is_subclass_of($query, 'Database\Query\QueryAbstract')) {
            return $this->query($this->buildQuery($query));
        }

        $debug = (new Debug\ExecutedQuery($query))->setBacktrace(debug_backtrace());
        $startTime = microtime(true);
        try {
            $result = $this->pdo->query($query);
        } catch (\Throwable $throwable) {
            $debug->setException($throwable);
            throw $throwable;
        } finally {
            $debug->setExecutionTime(microtime(true) - $startTime);
            Debug::addQuery($debug);
        }

        return $this->getPDODatabaseRecord($result);
    }
521993
public function scopeRecentlyCreated(Builder $query, $limit = null)
    {
        $query->orderBy('created_at', 'desc');

        if ($limit)
        {
            $query->limit($limit);
        }

        return $query;
    }
795052
public function applyToQuery(Builder $query)
    {
        $this->query = $query;

        foreach ($this->request->all() as $filter => $value) {
            $method = Str::camel($filter);

            if ($this->filterCanBeApplied($method, $value)) {
                call_user_func([$this, $method], $value);
            }
        }

        return $query;
    }
557735
public function scopeOlderThan($query, $time)
    {
        if ( ! $time instanceof Carbon)
        {
            $time = Carbon::createFromTimestamp($time);
        }

        return $query->where('created_at', '<=', $time->toDateTimeString())->latest();
    }
149949
public function scopePublished(Builder $query)
    {
        return $query->where(function ($query)
        {
            $query->where('status', '>=', Node::PUBLISHED)
                ->orWhere(function ($query)
                {
                    $query->where('status', '>=', Node::PENDING)
                        ->where('published_at', '<=', Carbon::now());
                });
        });
    }