protected function conditions(Search $search, array $matches, $negate) { $actor = $search->getActor(); // might be better as `id IN (subquery)`? $method = $negate ? 'whereNotExists' : 'whereExists'; $search->getQuery()->{$method}(function ($query) use($actor, $matches) { $query->select(app('flarum.db')->raw(1))->from('users_discussions')->where('discussions.id', new Expression('discussion_id'))->where('user_id', $actor->id)->where('subscription', $matches[1] === 'follow' ? 'follow' : 'ignore'); }); }
/** * {@inheritdoc} */ protected function conditions(Search $search, array $matches, $negate) { if (!$search instanceof DiscussionSearch) { throw new LogicException('This gambit can only be applied on a DiscussionSearch'); } $username = trim($matches[1], '"'); $id = $this->users->getIdForUsername($username); $search->getQuery()->where('start_user_id', $negate ? '!=' : '=', $id); }
/** * {@inheritdoc} */ public function apply(Search $search, $bit) { if (!$search instanceof DiscussionSearch) { throw new LogicException('This gambit can only be applied on a DiscussionSearch'); } $relevantPostIds = $this->fulltext->match($bit); $discussionIds = array_keys($relevantPostIds); $search->setRelevantPostIds($relevantPostIds); $search->getQuery()->whereIn('id', $discussionIds); $search->setDefaultSort(['id' => $discussionIds]); }
/** * {@inheritdoc} */ protected function conditions(Search $search, array $matches, $negate) { if (!$search instanceof DiscussionSearch) { throw new LogicException('This gambit can only be applied on a DiscussionSearch'); } $search->getQuery()->where(function ($query) use($negate) { if ($negate) { $query->whereNull('hide_time')->where('comments_count', '>', 0); } else { $query->whereNotNull('hide_time')->orWhere('comments_count', 0); } }); }
/** * {@inheritdoc} */ protected function conditions(Search $search, array $matches, $negate) { if (!$search instanceof DiscussionSearch) { throw new LogicException('This gambit can only be applied on a DiscussionSearch'); } $actor = $search->getActor(); if ($actor->exists) { $readIds = $this->discussions->getReadIds($actor); $search->getQuery()->where(function ($query) use($readIds, $negate, $actor) { if (!$negate) { $query->whereNotIn('id', $readIds)->where('last_time', '>', $actor->read_time ?: 0); } else { $query->whereIn('id', $readIds)->orWhere('last_time', '<=', $actor->read_time ?: 0); } }); } }
protected function conditions(Search $search, array $matches, $negate) { $slugs = explode(',', trim($matches[1], '"')); // TODO: implement $negate $search->getQuery()->where(function ($query) use($slugs) { foreach ($slugs as $slug) { if ($slug === 'untagged') { $query->orWhereNotExists(function ($query) { $query->select(app('flarum.db')->raw(1))->from('discussions_tags')->whereRaw('discussion_id = discussions.id'); }); } else { $id = $this->tags->getIdForSlug($slug); $query->orWhereExists(function ($query) use($id) { $query->select(app('flarum.db')->raw(1))->from('discussions_tags')->whereRaw('discussion_id = discussions.id AND tag_id = ?', [$id]); }); } } }); }
/** * @param Search $search * @param string $query */ protected function applyFulltext(Search $search, $query) { if (!$this->fulltextGambit) { return; } $gambit = $this->container->make($this->fulltextGambit); $search->addActiveGambit($gambit); $gambit->apply($search, $query); }
protected function conditions(Search $search, array $matches, $negate) { $search->getQuery()->where('is_locked', !$negate); }
/** * {@inheritdoc} */ public function apply(Search $search, $bit) { $users = $this->users->getIdsForUsername($bit, $search->getActor()); $search->getQuery()->whereIn('id', $users); $search->setDefaultSort(['id' => $users]); }