/** * @param EditTag $command * @return \Flarum\Tags\Tag * @throws \Flarum\Core\Exception\PermissionDeniedException */ public function handle(EditTag $command) { $actor = $command->actor; $data = $command->data; $tag = $this->tags->findOrFail($command->tagId, $actor); $this->assertCan($actor, 'edit', $tag); $attributes = array_get($data, 'attributes', []); if (isset($attributes['name'])) { $tag->name = $attributes['name']; } if (isset($attributes['slug'])) { $tag->slug = $attributes['slug']; } if (isset($attributes['description'])) { $tag->description = $attributes['description']; } if (isset($attributes['color'])) { $tag->color = $attributes['color']; } if (isset($attributes['isHidden'])) { $tag->is_hidden = (bool) $attributes['isHidden']; } if (isset($attributes['isRestricted'])) { $tag->is_restricted = (bool) $attributes['isRestricted']; } event(new TagWillBeSaved($tag, $actor, $data)); $this->validator->assertValid($tag->getDirty()); $tag->save(); return $tag; }
/** * @param DeleteTag $command * @return \Flarum\Tags\Tag * @throws \Flarum\Core\Exception\PermissionDeniedException */ public function handle(DeleteTag $command) { $actor = $command->actor; $tag = $this->tags->findOrFail($command->tagId, $actor); $this->assertCan($actor, 'delete', $tag); $tag->delete(); return $tag; }
/** * @param DeleteTag $command * @return \Flarum\Tags\Tag * @throws \Flarum\Core\Exception\PermissionDeniedException */ public function handle(DeleteTag $command) { $actor = $command->actor; $tag = $this->tags->findOrFail($command->tagId, $actor); $this->assertCan($actor, 'delete', $tag); $this->tags->query()->where('parent_id', $tag->id)->update(['parent_id' => null]); $tag->delete(); return $tag; }
/** * {@inheritdoc} */ protected function conditions(AbstractSearch $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(new Expression(1))->from('discussions_tags')->where('discussions.id', new Expression('discussion_id')); }); } else { $id = $this->tags->getIdForSlug($slug); $query->orWhereExists(function ($query) use($id) { $query->select(new Expression(1))->from('discussions_tags')->where('discussions.id', new Expression('discussion_id'))->where('tag_id', $id); }); } } }); }
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]); }); } } }); }
/** * {@inheritdoc} */ protected function data(ServerRequestInterface $request, Document $document) { return $this->tags->all($request->getAttribute('actor')); }