Finds all verified subscriptions for a component.

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

@return \Illuminate\Database\Eloquent\Builder
547649
public function scopeIsVerifiedForComponent(Builder $query, $component_id)
    {
        return $query->select('subscriptions.*')
            ->join('subscribers', 'subscriptions.subscriber_id', '=', 'subscribers.id')
            ->where(function ($query) {
                $query->where('subscriptions.component_id', '=', $component_id)
                    ->orWhere('subscribers.global');
            })
            ->whereNotNull('subscribers.verified_at');
    }
1103655
public static function getComponentById(array $componentToData, $id){
    	foreach ($componentToData as $ctd){
    		if ($ctd['id'] == $id){
    			return $ctd['component'];
    		}
    	}
    	
    	return null;
    }
1033662
protected function performJoins(Builder $query = null)
    {
        $query = $query ?: $this->query;

        foreach ($this->throughParents as $i => $model) {
            $table = $model->getTable();

            $predecessor = $i > 0 ? $this->throughParents[$i - 1] : $this->related;

            $first = $table.'.'.$this->getForeignKeyName($predecessor);

            $second = $predecessor->getQualifiedKeyName();

            $query->join($table, $first, '=', $second);

            if ($this->hasSoftDeletes($model)) {
                $this->query->whereNull($model->getQualifiedDeletedAtColumn());
            }
        }
    }
813495
public function is_related($query) {
        if (parent::is_related($query)) {
            return true;
        }

        $protocols = core_component::get_plugin_list('webservice');
        foreach ($protocols as $protocol=>$location) {
            if (strpos($protocol, $query) !== false) {
                return true;
            }
            $protocolstr = get_string('pluginname', 'webservice_'.$protocol);
            if (strpos(core_text::strtolower($protocolstr), $query) !== false) {
                return true;
            }
        }
        return false;
    }
274839
public function executeOn(Builder $query)
    {
        $this->stack->each(function (CriteriaInterface $criteria) use ($query) {
            $criteria->execute($query);
        });

        return $query;
    }
825572
protected function setKeysForSaveQuery(Builder $query)
    {
        if (isset($this->attributes[$this->getKeyName()])) {
            return parent::setKeysForSaveQuery($query);
        }

        $query->where($this->foreignKey, $this->getOriginal(
            $this->foreignKey, $this->getAttribute($this->foreignKey)
        ));

        return $query->where($this->relatedKey, $this->getOriginal(
            $this->relatedKey, $this->getAttribute($this->relatedKey)
        ));
    }
1107763
public function setQuantityAllocation($subscriptionId, $componentId)
    {
        $service       = $this->getService();
        $rawData       = $this->getRawData(array('component' => $this->_params));
        $response      = $service->request('subscriptions/' . (int)$subscriptionId . '/components/' . (int)$componentId, 'PUT', $rawData);
        $responseArray = $this->getResponseArray($response);

        if (!$this->isError()) {
            $this->_data = $responseArray['component'];
        } else {
            $this->_data = array();
        }

        return $this;
    }
665154
public function alterQueryBuilderWithParentRoot($query, $parent_id, $include_parent = true)
    {
        if (is_null($parent_id)) {
            return $query;
        }
        $parent = $this->find($parent_id);

        $query->andWhere(
            $query->getRootAliases()[0] . '.lft >=' . $this->addNamedParameter('lft', $parent->getLft(), $query)
            . ' AND ' .
            $query->getRootAliases()[0] . '.lft <=' . $this->addNamedParameter('rgt', $parent->getRgt(), $query)
        );
        if (!$include_parent) {
            $query->andWhere(
                $query->getRootAliases()[0] . '.id !=' . $this->addNamedParameter('id', $parent_id, $query)
            );
        }
        return $query;
    }
1356465
public function scopeCurrentVersion(Builder $query)
    {
        $subquery = $this->getCurrentVersionQuery();

        return $query
            ->select('version.*')
            ->addSelect('version.id as version:id')
            ->addSelect('version.created_at as version:created_at')
            ->addSelect('version.created_by as version:created_by')
            ->addSelect('pages.*')
            ->join(DB::raw('('.$subquery->toSql().') as v2'), 'pages.id', '=', 'v2.page_id')
            ->mergeBindings($subquery)
            ->join('page_versions as version', function (JoinClause $join) {
                $join
                    ->on('pages.id', '=', 'version.page_id')
                    ->on('v2.id', '=', 'version.id');
            });
    }
1284835
public function compileSelect(Builder $query)
    {
        if ($query->unions && $query->aggregate) {
            return $this->compileUnionAggregate($query);
        }

        // If the query does not have any columns set, we'll set the columns to the
        // * character to just get all of the columns from the database. Then we
        // can build the query and concatenate all the pieces together as one.
        $original = $query->columns;

        if (is_null($query->columns)) {
            $query->columns = ['*'];
        }

        // To compile the query, we'll spin through each component of the query and
        // see if that component exists. If it does we'll just call the compiler
        // function for the component which is responsible for making the SQL.
        $sql = trim($this->concatenate(
            $this->compileComponents($query))
        );

        $query->columns = $original;

        return $sql;
    }
1053084
public function build(&$query)
    {
        if (isset($query['alias']) && isset($query['id'])) {
            if (!isset($query['get'])) {
                $query['id'] = $query['id'].'-'.$query['alias'];
            }

            unset($query['alias']);
        }

        $has_id = isset($query['id']);
        $segments = parent::build($query);

        if ($has_id) {
            if (isset($query['get'])) {
                $segments[] = $query['get'];

                if ($query['get'] == 'graph') {
                    if (!isset($query['type'])) {
                        $query['type'] = 'followers';
                    }

                    $segments[] = $query['type'];

                    unset($query['type']);
                }

                unset($query['get']);
            }
        } elseif (isset($query['oid'])) {
            if ($query['oid'] == 'viewer') {
                $query['oid'] = get_viewer()->uniqueAlias;
            }

            $segments[] = '@'.$query['oid'];

            unset($query['oid']);
        }

        return $segments;
    }
213603
public function getManyPublishedFrom(Builder $query, QueryBuilder $builder): LengthAwarePaginator
    {
        $query = $query->where('published_at', '<=', Carbon::now())
            ->join('routes as r', function ($join) {
                $join->on('contents.id', '=', 'r.routable_id')
                    ->where('r.routable_type', '=', Content::class)
                    ->where('r.is_active', true);
            })
            ->distinct();

        if ($builder->hasFilter('type') || $builder->hasSort('type')) {
            $query->join('content_types as ct', 'contents.type_id', '=', 'ct.id');
            optional($builder->getFilter('type'))->apply($query, 'ct', 'name');
            optional($builder->getSort('type'))->apply($query, 'ct', 'name');
        }

        $count = clone $query->getQuery();

        $results = $query->limit($builder->getPageSize())
            ->offset($builder->getPageSize() * ($builder->getPage() - 1))
            ->get(['contents.*']);

        $results->load(
            array_merge(
                self::$loadRelations,
                [
                    'routes' => function ($query) {
                        $query->where('is_active', true);
                    }
                ]
            )
        );

        $results->transform(function ($content) {
            $languages            = $content->routes->pluck('language_code');
            $filteredTranslations = $content->translations->filter(function ($translation) use ($languages) {
                return $languages->contains($translation->language_code);
            });
            $content->setRelation('translations', $filteredTranslations);
            return $content;
        });

        return new LengthAwarePaginator(
            $results,
            $count->select('contents.id')->get()->count(),
            $builder->getPageSize(),
            $builder->getPage()
        );
    }
1307949
public function scopeFiltersApply(Builder $query, array $filters = []): Builder
    {
        foreach ($filters as $filter) {
            if (! is_object($filter)) {
                $filter = app()->make($filter);
            }

            $query = $filter->filter($query);
        }

        return $query;
    }
400431
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
    {
        if ($query->getQuery()->from == $parentQuery->getQuery()->from) {
            return $this->getRelationExistenceQueryForSelfRelation($query, $parentQuery, $columns);
        }

        return parent::getRelationExistenceQuery($query, $parentQuery, $columns);
    }
90077
protected function performJoin(Builder $query = null)
    {
        $query = $query ?: $this->query;

        $farKey = $this->getQualifiedFarKeyName();

        $query->join($this->throughParent->getTable(), $this->getQualifiedParentKeyName(), '=', $farKey);

        if ($this->throughParentSoftDeletes()) {
            $query->whereNull($this->throughParent->getQualifiedDeletedAtColumn());
        }
    }
683964
public function scopeForUser(Builder $query, $userId)
    {
        $participantsTable = Models::table('participants');
        $threadsTable = Models::table('threads');

        return $query->join($participantsTable, $this->getQualifiedKeyName(), '=', $participantsTable . '.thread_id')
            ->where($participantsTable . '.user_id', $userId)
            ->where($participantsTable . '.deleted_at', null)
            ->select($threadsTable . '.*');
    }
952361
public function build(&$query)
    {
        $segments = array();

        if (isset($query['view'])) {
            $id = null;

            //if there's an id pluralize the view
            if (isset($query['id']) && !is_array($query['id'])) {
                //remove the singularize view
                $query['view'] = AnInflector::pluralize($query['view']);
                $id = $query['id'];
                unset($query['id']);
            }

            //prevent duplicate name
            if ($query['view'] != $this->getIdentifier()->package) {
                $segments[] = $query['view'];
            }

            unset($query['view']);

            if ($id) {
                $segments[] = $id;
            }
        }

        return $segments;
    }