public function hideTags(DiscussionSearchWillBePerformed $event) { $query = $event->search->getQuery(); foreach ($event->search->getActiveGambits() as $gambit) { if ($gambit instanceof TagGambit) { return; } } $query->whereNotExists(function ($query) { return $query->select(app('flarum.db')->raw(1))->from('discussions_tags')->whereIn('tag_id', Tag::where('is_hidden', 1)->lists('id'))->where('discussions.id', new Expression('discussion_id')); }); }
/** * @param ConfigureDiscussionSearch $event */ public function hideTagsFromDiscussionList(ConfigureDiscussionSearch $event) { $query = $event->search->getQuery(); foreach ($event->search->getActiveGambits() as $gambit) { if ($gambit instanceof TagGambit) { return; } } $query->whereNotExists(function ($query) { return $query->select(new Expression(1))->from('discussions_tags')->whereIn('tag_id', Tag::where('is_hidden', 1)->lists('id'))->where('discussions.id', new Expression('discussion_id')); }); }
/** * {@inheritdoc} */ public function handle(ServerRequestInterface $request) { $this->assertAdmin($request->getAttribute('actor')); $order = array_get($request->getParsedBody(), 'order'); Tag::query()->update(['position' => null, 'parent_id' => null]); foreach ($order as $i => $parent) { $parentId = array_get($parent, 'id'); Tag::where('id', $parentId)->update(['position' => $i]); if (isset($parent['children']) && is_array($parent['children'])) { foreach ($parent['children'] as $j => $childId) { Tag::where('id', $childId)->update(['position' => $j, 'parent_id' => $parentId]); } } } return new EmptyResponse(204); }
public function handle(Request $request) { if (!$request->actor->isAdmin()) { throw new PermissionDeniedException(); } $order = $request->get('order'); Tag::query()->update(['position' => null, 'parent_id' => null]); foreach ($order as $i => $parent) { $parentId = array_get($parent, 'id'); Tag::where('id', $parentId)->update(['position' => $i]); if (isset($parent['children']) && is_array($parent['children'])) { foreach ($parent['children'] as $j => $childId) { Tag::where('id', $childId)->update(['position' => $j, 'parent_id' => $parentId]); } } } return new EmptyResponse(204); }
/** * Get the ID of a tag with the given slug. * * @param string $slug * @param User|null $user * @return integer */ public function getIdForSlug($slug, User $user = null) { $query = Tag::where('slug', 'like', $slug); return $this->scopeVisibleTo($query, $user)->pluck('id'); }