Пример #1
0
 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');
     });
 }
Пример #2
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);
             }
         });
     }
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function apply(Search $search, $bit)
 {
     $users = $this->users->getIdsForUsername($bit, $search->getActor());
     $search->getQuery()->whereIn('id', $users);
     $search->setDefaultSort(['id' => $users]);
 }