From 9d68dd50ba13113d3d8d54a0c931607ecd9a167d Mon Sep 17 00:00:00 2001 From: Murtaza Sultani Date: Thu, 18 Sep 2025 11:15:04 +0200 Subject: Resolve "Forum: Variablennamen und Typdeklarationen aktualisieren" Closes #5890 Merge request studip/studip!4491 --- .../JsonApi/Routes/Forum/ForumAuthority.php | 14 ---- lib/classes/JsonApi/Schemas/Forum/Category.php | 48 ++++++++----- lib/classes/JsonApi/Schemas/Forum/Discussion.php | 69 +++++++++++------- lib/classes/JsonApi/Schemas/Forum/Member.php | 23 ++++-- lib/classes/JsonApi/Schemas/Forum/Posting.php | 57 +++++++++------ .../JsonApi/Schemas/Forum/PostingReaction.php | 31 ++++---- lib/classes/JsonApi/Schemas/Forum/Subscription.php | 84 ++++++++++++---------- lib/classes/JsonApi/Schemas/Forum/Tag.php | 17 +++-- lib/classes/JsonApi/Schemas/Forum/Topic.php | 51 ++++++------- lib/models/Forum/Posting.php | 2 +- resources/vue/apps/forum/categories/Index.vue | 4 +- resources/vue/apps/forum/categories/Show.vue | 2 +- resources/vue/apps/forum/discussions/Index.vue | 2 +- resources/vue/apps/forum/recent/Index.vue | 2 +- resources/vue/apps/forum/subscriptions/Index.vue | 2 +- resources/vue/apps/forum/topics/Index.vue | 2 +- resources/vue/apps/forum/topics/Show.vue | 2 +- resources/vue/components/forum/ForumApp.vue | 2 +- .../vue/components/forum/SubscriptionDropdown.vue | 2 +- resources/vue/components/forum/helpers/types.ts | 28 ++++++++ resources/vue/components/forum/posts/Post.vue | 6 +- .../vue/components/forum/posts/PostContent.vue | 2 +- .../vue/components/forum/posts/PostCreateForm.vue | 2 +- .../vue/components/forum/posts/PostEditForm.vue | 2 +- .../vue/components/forum/posts/PostReactions.vue | 4 +- .../vue/components/forum/topics/TopicsIndex.vue | 2 +- 26 files changed, 273 insertions(+), 189 deletions(-) delete mode 100644 lib/classes/JsonApi/Routes/Forum/ForumAuthority.php create mode 100644 resources/vue/components/forum/helpers/types.ts diff --git a/lib/classes/JsonApi/Routes/Forum/ForumAuthority.php b/lib/classes/JsonApi/Routes/Forum/ForumAuthority.php deleted file mode 100644 index 0a0017f..0000000 --- a/lib/classes/JsonApi/Routes/Forum/ForumAuthority.php +++ /dev/null @@ -1,14 +0,0 @@ -isAccessibleToUser($user?->id); - } -} diff --git a/lib/classes/JsonApi/Schemas/Forum/Category.php b/lib/classes/JsonApi/Schemas/Forum/Category.php index de5aa3e..5e3012b 100644 --- a/lib/classes/JsonApi/Schemas/Forum/Category.php +++ b/lib/classes/JsonApi/Schemas/Forum/Category.php @@ -10,31 +10,43 @@ class Category extends SchemaProvider const TYPE = 'forum-categories'; const REL_TOPICS = 'topics'; - public function getId($category): ?string + /** + * @param \Forum\Category $resource + */ + public function getId($resource): ?string { - return $category->id; + return $resource->id; } - public function getAttributes($category, ContextInterface $context): iterable + /** + * @param \Forum\Category $resource + */ + public function getAttributes($resource, ContextInterface $context): iterable { return [ - 'name' => $category->name, - 'description' => $category->description, - 'color' => $category->color, - 'position' => (int) $category->position, - 'mkdate' => date('c', $category->mkdate), - 'chdate' => date('c', $category->chdate) + 'name' => $resource->name, + 'description' => $resource->description, + 'color' => $resource->color, + 'position' => (int) $resource->position, + 'mkdate' => date('c', $resource->mkdate), + 'chdate' => date('c', $resource->chdate) ]; } - public function hasResourceMeta($category): bool + /** + * @param \Forum\Category $resource + */ + public function hasResourceMeta($resource): bool { return true; } - public function getResourceMeta($category) + /** + * @param \Forum\Category $resource + */ + public function getResourceMeta($resource) { - $metaData = $category->getMetaData(); + $metaData = $resource->getMetaData(); return [ 'topics-count' => (int) $metaData['topics_count'], @@ -46,18 +58,18 @@ class Category extends SchemaProvider ]; } - public function getRelationships($category, ContextInterface $context): iterable + /** + * @param \Forum\Category $resource + */ + public function getRelationships($resource, ContextInterface $context): iterable { $relationships = []; - $relationships = $this->addTopicsRelationship($relationships, $category, $this->shouldInclude($context, self::REL_TOPICS)); + $relationships = $this->addTopicsRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_TOPICS)); return $relationships; } - /** - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - private function addTopicsRelationship($relationships, $category, $withTopics = false) + private function addTopicsRelationship(array $relationships, \Forum\Category $category, $withTopics = false) { if ($withTopics) { $relationships[self::REL_TOPICS] = [ diff --git a/lib/classes/JsonApi/Schemas/Forum/Discussion.php b/lib/classes/JsonApi/Schemas/Forum/Discussion.php index abac14e..9252aaa 100644 --- a/lib/classes/JsonApi/Schemas/Forum/Discussion.php +++ b/lib/classes/JsonApi/Schemas/Forum/Discussion.php @@ -17,31 +17,43 @@ class Discussion extends SchemaProvider const REL_MEMBERS = 'members'; const REL_TAGS = 'tags'; - public function getId($discussion): ?string + /** + * @param \Forum\Discussion $resource + */ + public function getId($resource): ?string { - return $discussion->discussion_id; + return $resource->discussion_id; } - public function getAttributes($discussion, ContextInterface $context): iterable + /** + * @param \Forum\Discussion $resource + */ + public function getAttributes($resource, ContextInterface $context): iterable { return [ - 'title' => $discussion->title, - 'closed-at' => $discussion->closed_at ? date('c', $discussion->closed_at) : null, - 'sticky' => (bool) $discussion->sticky, - 'view-count' => (int) $discussion->view_count, - 'mkdate' => date('c', $discussion->mkdate), - 'chdate' => date('c', $discussion->chdate) + 'title' => $resource->title, + 'closed-at' => $resource->closed_at ? date('c', $resource->closed_at) : null, + 'sticky' => (bool) $resource->sticky, + 'view-count' => (int) $resource->view_count, + 'mkdate' => date('c', $resource->mkdate), + 'chdate' => date('c', $resource->chdate) ]; } - public function hasResourceMeta($discussion): bool + /** + * @param \Forum\Discussion $resource + */ + public function hasResourceMeta($resource): bool { return true; } - public function getResourceMeta($discussion) + /** + * @param \Forum\Discussion $resource + */ + public function getResourceMeta($resource) { - $metaData = $discussion->getMetaData(); + $metaData = $resource->getMetaData(); return [ 'postings-count' => (int) $metaData['postings_count'], @@ -51,22 +63,25 @@ class Discussion extends SchemaProvider ]; } - public function getRelationships($discussion, ContextInterface $context): iterable + /** + * @param \Forum\Discussion $resource + */ + public function getRelationships($resource, ContextInterface $context): iterable { $relationships = []; - $relationships = $this->addPostingsRelationship($relationships, $discussion, $this->shouldInclude($context, self::REL_POSTINGS)); - $relationships = $this->addTopicRelationship($relationships, $discussion, $this->shouldInclude($context, self::REL_TOPIC)); - $relationships = $this->addCategoryRelationship($relationships, $discussion, $this->shouldInclude($context, self::REL_CATEGORY)); - $relationships = $this->addUserRelationship($relationships, $discussion, $this->shouldInclude($context, self::REL_USER)); - $relationships = $this->addDiscussionTypeRelationship($relationships, $discussion, $this->shouldInclude($context, self::REL_DISCUSSION_TYPE)); - $relationships = $this->addMembersRelationship($relationships, $discussion, $this->shouldInclude($context, self::REL_MEMBERS)); - $relationships = $this->addTagsRelationship($relationships, $discussion, $this->shouldInclude($context, self::REL_TAGS)); + $relationships = $this->addPostingsRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_POSTINGS)); + $relationships = $this->addTopicRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_TOPIC)); + $relationships = $this->addCategoryRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_CATEGORY)); + $relationships = $this->addUserRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_USER)); + $relationships = $this->addDiscussionTypeRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_DISCUSSION_TYPE)); + $relationships = $this->addMembersRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_MEMBERS)); + $relationships = $this->addTagsRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_TAGS)); return $relationships; } - private function addPostingsRelationship(array $relationships, $discussion, bool $withPostings = false) + private function addPostingsRelationship(array $relationships, \Forum\Discussion $discussion, bool $withPostings = false) { if ($withPostings) { $relationships[self::REL_POSTINGS] = [ @@ -80,7 +95,7 @@ class Discussion extends SchemaProvider return $relationships; } - private function addTopicRelationship(array $relationships, $discussion, bool $withTopic = false) + private function addTopicRelationship(array $relationships, \Forum\Discussion $discussion, bool $withTopic = false) { if ($withTopic) { $relationships[self::REL_TOPIC] = [ @@ -94,7 +109,7 @@ class Discussion extends SchemaProvider return $relationships; } - private function addCategoryRelationship(array $relationships, $discussion, bool $withCategory = false) + private function addCategoryRelationship(array $relationships, \Forum\Discussion $discussion, bool $withCategory = false) { $category = $discussion->category; if ($withCategory && $category) { @@ -109,7 +124,7 @@ class Discussion extends SchemaProvider return $relationships; } - private function addUserRelationship(array $relationships, $discussion, bool $withUser = false) + private function addUserRelationship(array $relationships, \Forum\Discussion $discussion, bool $withUser = false) { $user = $discussion->user; if ($withUser && $user) { @@ -124,7 +139,7 @@ class Discussion extends SchemaProvider return $relationships; } - private function addDiscussionTypeRelationship(array $relationships, $discussion, bool $withDiscussionType = false) + private function addDiscussionTypeRelationship(array $relationships, \Forum\Discussion $discussion, bool $withDiscussionType = false) { $discussionType = $discussion->discussion_type; @@ -140,7 +155,7 @@ class Discussion extends SchemaProvider return $relationships; } - private function addMembersRelationship(array $relationships, $discussion, bool $withMembers = false) + private function addMembersRelationship(array $relationships, \Forum\Discussion $discussion, bool $withMembers = false) { if ($withMembers) { $relationships[self::REL_MEMBERS] = [ @@ -154,7 +169,7 @@ class Discussion extends SchemaProvider return $relationships; } - private function addTagsRelationship(array $relationships, $discussion, bool $withTags = false) + private function addTagsRelationship(array $relationships, \Forum\Discussion $discussion, bool $withTags = false) { if ($withTags) { $relationships[self::REL_TAGS] = [ diff --git a/lib/classes/JsonApi/Schemas/Forum/Member.php b/lib/classes/JsonApi/Schemas/Forum/Member.php index 6798c4e..5e72e26 100644 --- a/lib/classes/JsonApi/Schemas/Forum/Member.php +++ b/lib/classes/JsonApi/Schemas/Forum/Member.php @@ -8,21 +8,30 @@ class Member extends SchemaProvider { const TYPE = 'forum-members'; - public function getId($member): ?string + /** + * @param \Forum\DTO\Member $resource + */ + public function getId($resource): ?string { - return $member->id; + return $resource->id; } - public function getAttributes($member, ContextInterface $context): iterable + /** + * @param \Forum\DTO\Member $resource + */ + public function getAttributes($resource, ContextInterface $context): iterable { return [ - 'username' => $member->username, - 'name' => $member->name, - 'role' => $member->role, - 'avatar_url' => $member->avatar_url + 'username' => $resource->username, + 'name' => $resource->name, + 'role' => $resource->role, + 'avatar_url' => $resource->avatar_url ]; } + /** + * @param \Forum\DTO\Member $resource + */ public function getRelationships($resource, ContextInterface $context): iterable { return []; diff --git a/lib/classes/JsonApi/Schemas/Forum/Posting.php b/lib/classes/JsonApi/Schemas/Forum/Posting.php index 8ec8d07..aa8423a 100644 --- a/lib/classes/JsonApi/Schemas/Forum/Posting.php +++ b/lib/classes/JsonApi/Schemas/Forum/Posting.php @@ -17,28 +17,42 @@ class Posting extends SchemaProvider const REL_REACTIONS_USER = 'reactions.user'; const REL_OPENGRAPH_URLS = 'opengraph-urls'; - public function getId($posting): ?string + /** + * @param \Forum\Posting $resource + */ + public function getId($resource): ?string { - return $posting->posting_id; + return $resource->posting_id; } - public function getAttributes($posting, ContextInterface $context): iterable + /** + * @inheritDoc + * @param \Forum\Posting $resource + */ + public function getAttributes($resource, ContextInterface $context): iterable { return [ - 'content' => \Studip\Markup::markupToHtml($posting->content), - 'content-html' => formatReady($posting->content), - 'anonymous' => (bool) $posting->anonymous, - 'mkdate' => date('c', $posting->mkdate), - 'chdate' => date('c', $posting->chdate) + 'content' => \Studip\Markup::markupToHtml($resource->content), + 'content-html' => formatReady($resource->content), + 'anonymous' => (bool) $resource->anonymous, + 'mkdate' => date('c', $resource->mkdate), + 'chdate' => date('c', $resource->chdate) ]; } - public function hasResourceMeta($posting): bool + /** + * @param \Forum\Posting $resource + */ + public function hasResourceMeta($resource): bool { return true; } - public function getResourceMeta($posting) + /** + * @inheritDoc + * @param \Forum\Posting $resource + */ + public function getResourceMeta($resource) { return [ self::REL_OPENGRAPH_URLS => array_map(fn($og) => [ @@ -47,22 +61,25 @@ class Posting extends SchemaProvider 'title' => $og['title'], 'description' => $og['description'], 'image' => $og['image'], - ], $posting->getOpenGraphURLs()) + ], $resource->getOpenGraphURLs()) ]; } - public function getRelationships($posting, ContextInterface $context): iterable + /** + * @param \Forum\Posting $resource + */ + public function getRelationships($resource, ContextInterface $context): iterable { $relationships = []; - $relationships = $this->addAuthorRelationship($relationships, $posting, $this->shouldInclude($context, self::REL_AUTHOR)); - $relationships = $this->addDiscussionRelationship($relationships, $posting, $this->shouldInclude($context, self::REL_DISCUSSION)); - $relationships = $this->addPostingRelationship($relationships, $posting, $this->shouldInclude($context, self::REL_POSTING)); - $relationships = $this->addReactionsRelationship($relationships, $posting, $this->shouldInclude($context, self::REL_REACTIONS)); + $relationships = $this->addAuthorRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_AUTHOR)); + $relationships = $this->addDiscussionRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_DISCUSSION)); + $relationships = $this->addPostingRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_POSTING)); + $relationships = $this->addReactionsRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_REACTIONS)); return $relationships; } - private function addAuthorRelationship($relationships, $posting, $withAuthor = false) + private function addAuthorRelationship(array $relationships, \Forum\Posting $posting, $withAuthor = false) { $author = $posting->author; @@ -78,7 +95,7 @@ class Posting extends SchemaProvider return $relationships; } - private function addDiscussionRelationship($relationships, $posting, $withDiscussion = false) + private function addDiscussionRelationship(array $relationships, \Forum\Posting $posting, $withDiscussion = false) { if ($withDiscussion) { $relationships[self::REL_DISCUSSION] = [ @@ -92,7 +109,7 @@ class Posting extends SchemaProvider return $relationships; } - private function addPostingRelationship($relationships, $posting, $withPosting = false) + private function addPostingRelationship(array $relationships, \Forum\Posting $posting, $withPosting = false) { $posting = $posting->posting; @@ -108,7 +125,7 @@ class Posting extends SchemaProvider return $relationships; } - private function addReactionsRelationship($relationships, $posting, $withReactions = false) + private function addReactionsRelationship(array $relationships, \Forum\Posting $posting, $withReactions = false) { if ($withReactions) { $relationships[self::REL_REACTIONS] = [ diff --git a/lib/classes/JsonApi/Schemas/Forum/PostingReaction.php b/lib/classes/JsonApi/Schemas/Forum/PostingReaction.php index 4104e01..ed39a3d 100644 --- a/lib/classes/JsonApi/Schemas/Forum/PostingReaction.php +++ b/lib/classes/JsonApi/Schemas/Forum/PostingReaction.php @@ -12,36 +12,41 @@ class PostingReaction extends SchemaProvider const REL_POSTING = 'posting'; const REL_USER = 'user'; - public function getId($postingReaction): ?string + /** + * @param \Forum\PostingReaction $resource + */ + public function getId($resource): ?string { - return $postingReaction->id; + return $resource->id; } - public function getAttributes($postingReaction, ContextInterface $context): iterable + /** + * @param \Forum\PostingReaction $resource + */ + public function getAttributes($resource, ContextInterface $context): iterable { return [ - 'emoji' => $postingReaction->emoji, - 'mkdate' => date('c', $postingReaction->mkdate), - 'chdate' => date('c', $postingReaction->chdate) + 'emoji' => $resource->emoji, + 'mkdate' => date('c', $resource->mkdate), + 'chdate' => date('c', $resource->chdate) ]; } /** - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @param \Forum\PostingReaction $resource */ - public function getRelationships($postingReaction, ContextInterface $context): iterable + public function getRelationships($resource, ContextInterface $context): iterable { $relationships = []; - $relationships = $this->addPostingRelationship($relationships, $postingReaction, $this->shouldInclude($context, self::REL_POSTING)); - $relationships = $this->addUserRelationship($relationships, $postingReaction, $this->shouldInclude($context, self::REL_USER)); + $relationships = $this->addPostingRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_POSTING)); + $relationships = $this->addUserRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_USER)); return $relationships; } - - private function addPostingRelationship(array $relationships, $postingReaction, bool $withPosting = false) + private function addPostingRelationship(array $relationships, \Forum\PostingReaction $postingReaction, bool $withPosting = false) { if ($withPosting) { $relationships[self::REL_POSTING] = [ @@ -55,7 +60,7 @@ class PostingReaction extends SchemaProvider return $relationships; } - private function addUserRelationship(array $relationships, $postingReaction, bool $withUser = false) + private function addUserRelationship(array $relationships, \Forum\PostingReaction $postingReaction, bool $withUser = false) { $user = $postingReaction->user; if ($withUser && $user) { diff --git a/lib/classes/JsonApi/Schemas/Forum/Subscription.php b/lib/classes/JsonApi/Schemas/Forum/Subscription.php index 4e5484e..a41e8bd 100644 --- a/lib/classes/JsonApi/Schemas/Forum/Subscription.php +++ b/lib/classes/JsonApi/Schemas/Forum/Subscription.php @@ -13,71 +13,79 @@ class Subscription extends SchemaProvider const REL_RANGE = 'range'; const REL_SUBJECT = 'subject'; - public function getId($subscription): ?string + /** + * @param \Forum\Subscription $resource + */ + public function getId($resource): ?string { - return $subscription->id; + return $resource->id; } - public function getAttributes($subscription, ContextInterface $context): iterable + public function getAttributes($resource, ContextInterface $context): iterable { return [ - 'notification-type' => $subscription->notification_type, - 'mkdate' => date('c', $subscription->mkdate), - 'chdate' => date('c', $subscription->chdate) + 'notification-type' => $resource->notification_type, + 'mkdate' => date('c', $resource->mkdate), + 'chdate' => date('c', $resource->chdate) ]; } - /** - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @param \Forum\Subscription $resource */ - public function getRelationships($subscription, ContextInterface $context): iterable + public function getRelationships($resource, ContextInterface $context): iterable { - $isPrimary = $context->getPosition()->getLevel() === 0; - $includeList = $context->getIncludePaths(); - $relationships = []; - if ($isPrimary) { - $relationships = $this->addUserRelationship($relationships, $subscription, $includeList); - $relationships = $this->addSubjectRelationship($relationships, $subscription, $includeList); - $relationships = $this->addRangeRelationship($relationships, $subscription, $includeList); - } + + $relationships = $this->addUserRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_USER)); + $relationships = $this->addSubjectRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_SUBJECT)); + $relationships = $this->addRangeRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_RANGE)); return $relationships; } - private function addUserRelationship(array $relationships, $subscription, array $includeList) + private function addUserRelationship(array $relationships, \Forum\Subscription $subscription, bool $withUser = false) { - $relationships[self::REL_USER] = [ - self::RELATIONSHIP_LINKS => [ - Link::RELATED => $this->createLinkToResource($subscription->user) - ], - self::RELATIONSHIP_DATA => $subscription->user - ]; + $user = $subscription->user; + + if ($withUser && $user) { + $relationships[self::REL_USER] = [ + self::RELATIONSHIP_LINKS => [ + Link::RELATED => $this->createLinkToResource($user) + ], + self::RELATIONSHIP_DATA => $user + ]; + } return $relationships; } - private function addSubjectRelationship(array $relationships, $subscription, array $includeList) + private function addSubjectRelationship(array $relationships, $subscription, bool $withSubject = false) { - $relationships[self::REL_SUBJECT] = [ - self::RELATIONSHIP_LINKS => [ - Link::RELATED => $this->createLinkToResource($subscription->subject_object) - ], - self::RELATIONSHIP_DATA => $subscription->subject_object - ]; + $subject = $subscription->subject_object; + + if ($withSubject && $subject) { + $relationships[self::REL_SUBJECT] = [ + self::RELATIONSHIP_LINKS => [ + Link::RELATED => $this->createLinkToResource($subject) + ], + self::RELATIONSHIP_DATA => $subject + ]; + } return $relationships; } - private function addRangeRelationship(array $relationships, $subscription, $includeList) + private function addRangeRelationship(array $relationships, $subscription, bool $withRange = false) { - $relationships[self::REL_RANGE] = [ - self::RELATIONSHIP_LINKS => [ - Link::RELATED => $this->createLinkToResource($subscription->range), - ], - self::RELATIONSHIP_DATA => $subscription->range, - ]; + if ($withRange) { + $relationships[self::REL_RANGE] = [ + self::RELATIONSHIP_LINKS => [ + Link::RELATED => $this->createLinkToResource($subscription->range), + ], + self::RELATIONSHIP_DATA => $subscription->range, + ]; + } return $relationships; } diff --git a/lib/classes/JsonApi/Schemas/Forum/Tag.php b/lib/classes/JsonApi/Schemas/Forum/Tag.php index 1c2e72e..cf7ab68 100644 --- a/lib/classes/JsonApi/Schemas/Forum/Tag.php +++ b/lib/classes/JsonApi/Schemas/Forum/Tag.php @@ -8,18 +8,27 @@ class Tag extends SchemaProvider { const TYPE = 'forum-tags'; - public function getId($tag): ?string + /** + * @param \Forum\DTO\Tag $resource + */ + public function getId($resource): ?string { - return $tag->id; + return $resource->id; } - public function getAttributes($tag, ContextInterface $context): iterable + /** + * @param \Forum\DTO\Tag $resource + */ + public function getAttributes($resource, ContextInterface $context): iterable { return [ - 'name' => $tag->name + 'name' => $resource->name ]; } + /** + * @param \Forum\DTO\Tag $resource + */ public function getRelationships($resource, ContextInterface $context): iterable { return []; diff --git a/lib/classes/JsonApi/Schemas/Forum/Topic.php b/lib/classes/JsonApi/Schemas/Forum/Topic.php index 624c6e7..06022c6 100644 --- a/lib/classes/JsonApi/Schemas/Forum/Topic.php +++ b/lib/classes/JsonApi/Schemas/Forum/Topic.php @@ -3,7 +3,6 @@ namespace JsonApi\Schemas\Forum; use JsonApi\Schemas\SchemaProvider; -use JsonApi\Schemas\Studip; use Neomerx\JsonApi\Contracts\Schema\ContextInterface; use Neomerx\JsonApi\Schema\Link; @@ -13,45 +12,43 @@ class Topic extends SchemaProvider const REL_CATEGORY = 'category'; const REL_DISCUSSION = 'discussion'; - public function getId($topic): ?string + /** + * @param \Forum\Topic $resource + */ + public function getId($resource): ?string { - return $topic->topic_id; + return $resource->topic_id; } /** * @inheritdoc - * - * @param \Forum\Topic $topic + * @param \Forum\Topic $resource */ - public function getAttributes($topic, ContextInterface $context): iterable + public function getAttributes($resource, ContextInterface $context): iterable { return [ - 'name' => $topic->name, - 'description' => $topic->description, - 'position' => (int) $topic->position, - 'mkdate' => date('c', $topic->mkdate), - 'chdate' => date('c', $topic->chdate) + 'name' => $resource->name, + 'description' => $resource->description, + 'position' => (int) $resource->position, + 'mkdate' => date('c', $resource->mkdate), + 'chdate' => date('c', $resource->chdate) ]; } /** - * @inheritdoc - * - * @param \Forum\Topic $topic + * @param \Forum\Topic $resource */ - public function hasResourceMeta($topic): bool + public function hasResourceMeta($resource): bool { return true; } /** - * @inheritdoc - * - * @param \Forum\Topic $topic + * @param \Forum\Topic $resource */ - public function getResourceMeta($topic) + public function getResourceMeta($resource) { - $metaData = $topic->getMetaData(); + $metaData = $resource->getMetaData(); return [ 'discussions-count' => (int) $metaData['discussions_count'], @@ -63,20 +60,18 @@ class Topic extends SchemaProvider } /** - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - * - * @param \Forum\Topic $topic + * @param \Forum\Topic $resource */ - public function getRelationships($topic, ContextInterface $context): iterable + public function getRelationships($resource, ContextInterface $context): iterable { $relationships = []; - $relationships = $this->addCategoryRelationship($relationships, $topic, $this->shouldInclude($context, self::REL_CATEGORY)); - $relationships = $this->addDiscussionsRelationship($relationships, $topic, $this->shouldInclude($context, self::REL_DISCUSSION)); + $relationships = $this->addCategoryRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_CATEGORY)); + $relationships = $this->addDiscussionsRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_DISCUSSION)); return $relationships; } - private function addCategoryRelationship($relationships, $topic, $withCategory = false) + private function addCategoryRelationship(array $relationships, \Forum\Topic $topic, bool $withCategory = false) { if ($withCategory) { $relationships[self::REL_CATEGORY] = [ @@ -90,7 +85,7 @@ class Topic extends SchemaProvider return $relationships; } - private function addDiscussionsRelationship($relationships, $topic, $withDiscussions = false) + private function addDiscussionsRelationship(array $relationships, \Forum\Topic $topic, bool $withDiscussions = false) { if ($withDiscussions) { $relationships[self::REL_DISCUSSION] = [ diff --git a/lib/models/Forum/Posting.php b/lib/models/Forum/Posting.php index 58b22be..0bca814 100644 --- a/lib/models/Forum/Posting.php +++ b/lib/models/Forum/Posting.php @@ -35,7 +35,7 @@ class Posting extends SimpleORMap ]; $config['belongs_to']['posting'] = [ - 'class_name' => Posting::class, + 'class_name' => self::class, 'foreign_key' => 'parent_id', 'assoc_foreign_key' => 'posting_id' ]; diff --git a/resources/vue/apps/forum/categories/Index.vue b/resources/vue/apps/forum/categories/Index.vue index 647a6a5..4329bc3 100644 --- a/resources/vue/apps/forum/categories/Index.vue +++ b/resources/vue/apps/forum/categories/Index.vue @@ -49,7 +49,7 @@ const fetchCategories = async (_, offset = 0) => { categories.value = await deserializeJSONAPIResponse(response); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } } @@ -76,7 +76,7 @@ const updateCategoriesOrder = async () => { { data: { data } } ); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } } diff --git a/resources/vue/apps/forum/categories/Show.vue b/resources/vue/apps/forum/categories/Show.vue index 4c340cd..a9e7ab8 100644 --- a/resources/vue/apps/forum/categories/Show.vue +++ b/resources/vue/apps/forum/categories/Show.vue @@ -51,7 +51,7 @@ const fetchTopics = async (_, offset = 0) => { topics.value = await deserializeJSONAPIResponse(response); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } finally { isLoading.value = false; } diff --git a/resources/vue/apps/forum/discussions/Index.vue b/resources/vue/apps/forum/discussions/Index.vue index 4845f16..26c29ae 100644 --- a/resources/vue/apps/forum/discussions/Index.vue +++ b/resources/vue/apps/forum/discussions/Index.vue @@ -39,7 +39,7 @@ const fetchDiscussions = async (_, offset = 0) => { discussions.value = await deserializeJSONAPIResponse(response); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } finally { isLoading.value = false; } diff --git a/resources/vue/apps/forum/recent/Index.vue b/resources/vue/apps/forum/recent/Index.vue index 4346a05..aa0f327 100644 --- a/resources/vue/apps/forum/recent/Index.vue +++ b/resources/vue/apps/forum/recent/Index.vue @@ -40,7 +40,7 @@ const fetchDiscussions = async (_, offset = 0) => { discussions.value = await deserializeJSONAPIResponse(response) } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } finally { isLoading.value = false; } diff --git a/resources/vue/apps/forum/subscriptions/Index.vue b/resources/vue/apps/forum/subscriptions/Index.vue index 2ca3706..175fa9d 100644 --- a/resources/vue/apps/forum/subscriptions/Index.vue +++ b/resources/vue/apps/forum/subscriptions/Index.vue @@ -63,7 +63,7 @@ const fetchSubscribedDiscussions = async (_, offset = 0) => { subscriptions.value = data.map(subscriptionTransformer); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } finally { isLoading.value = false; } diff --git a/resources/vue/apps/forum/topics/Index.vue b/resources/vue/apps/forum/topics/Index.vue index 75c5267..4e4ef35 100644 --- a/resources/vue/apps/forum/topics/Index.vue +++ b/resources/vue/apps/forum/topics/Index.vue @@ -42,7 +42,7 @@ const fetchTopics = async (_, offset = 0) => { const data = await deserializeJSONAPIResponse(response); topics.value = data.map(topicTransformer); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } finally { isLoading.value = false; } diff --git a/resources/vue/apps/forum/topics/Show.vue b/resources/vue/apps/forum/topics/Show.vue index 58319fa..0adda3d 100644 --- a/resources/vue/apps/forum/topics/Show.vue +++ b/resources/vue/apps/forum/topics/Show.vue @@ -54,7 +54,7 @@ const fetchDiscussions = async (_, offset = 0) => { discussions.value = await deserializeJSONAPIResponse(response); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } finally { isLoading.value = false; } diff --git a/resources/vue/components/forum/ForumApp.vue b/resources/vue/components/forum/ForumApp.vue index 372a077..dc0adc0 100644 --- a/resources/vue/components/forum/ForumApp.vue +++ b/resources/vue/components/forum/ForumApp.vue @@ -14,7 +14,7 @@ const fetchConfigs = async () => { tileLayout: response.meta['tile-layout'], }); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } } diff --git a/resources/vue/components/forum/SubscriptionDropdown.vue b/resources/vue/components/forum/SubscriptionDropdown.vue index 2d214ff..98a4543 100644 --- a/resources/vue/components/forum/SubscriptionDropdown.vue +++ b/resources/vue/components/forum/SubscriptionDropdown.vue @@ -118,7 +118,7 @@ const subscribe = async (notification_type = 'all') => { STUDIP.Report.success($gettext('Erfolgreich abonniert!'), subscriptionButtonLabel); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } finally { isLoading.value = false; } diff --git a/resources/vue/components/forum/helpers/types.ts b/resources/vue/components/forum/helpers/types.ts new file mode 100644 index 0000000..8ffc59d --- /dev/null +++ b/resources/vue/components/forum/helpers/types.ts @@ -0,0 +1,28 @@ +export interface Post { + id: string; + content: string; + anonymous: boolean; + mkdate: string; + chdate: string; + author: Member | null; + reactions: Reaction[]; + meta: { + opengraph_urls: [] + }; +} + +export interface Member { + id: string; + username: string; + name: string; + role: string; + avatar_url: string; +} + +export interface Reaction { + id: string; + emoji: string; + mkdate: string; + chdate: string; + user: object; +} diff --git a/resources/vue/components/forum/posts/Post.vue b/resources/vue/components/forum/posts/Post.vue index 7155eea..ed27d6e 100644 --- a/resources/vue/components/forum/posts/Post.vue +++ b/resources/vue/components/forum/posts/Post.vue @@ -61,7 +61,7 @@ const deletePost = async (post) => { forumDiscussionPost.removePost(post.id); STUDIP.Report.success($gettext('Der Beitrag wurde gelöscht.')); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } }, STUDIP.Dialog.close()); @@ -140,10 +140,10 @@ const removePostHighlight = id => { > {{ post.author.name }} - + {{ $gettext('Bearbeitet: ') }} - + diff --git a/resources/vue/components/forum/posts/PostContent.vue b/resources/vue/components/forum/posts/PostContent.vue index 84d388e..50af192 100644 --- a/resources/vue/components/forum/posts/PostContent.vue +++ b/resources/vue/components/forum/posts/PostContent.vue @@ -26,7 +26,7 @@ const onTextSelected = event => { } const newSelectionHandler = () => { - if(! document.getSelection().toString()) { + if(!document.getSelection().toString() && actionsRef.value) { actionsRef.value.style.display = 'none'; } } diff --git a/resources/vue/components/forum/posts/PostCreateForm.vue b/resources/vue/components/forum/posts/PostCreateForm.vue index 00daeba..9608f8d 100644 --- a/resources/vue/components/forum/posts/PostCreateForm.vue +++ b/resources/vue/components/forum/posts/PostCreateForm.vue @@ -109,7 +109,7 @@ const storePost = async () => { STUDIP.Report.success($gettext("Der Beitrag wurde gespeichert.")); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } finally { isLoading.value = false; } diff --git a/resources/vue/components/forum/posts/PostEditForm.vue b/resources/vue/components/forum/posts/PostEditForm.vue index f7ebbe0..10821a1 100644 --- a/resources/vue/components/forum/posts/PostEditForm.vue +++ b/resources/vue/components/forum/posts/PostEditForm.vue @@ -60,7 +60,7 @@ const updatePost = async () => { STUDIP.Report.success($gettext("Die Änderungen wurde gespeichert.")); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } finally { isLoading.value = false; } diff --git a/resources/vue/components/forum/posts/PostReactions.vue b/resources/vue/components/forum/posts/PostReactions.vue index eff8d6b..767e48e 100644 --- a/resources/vue/components/forum/posts/PostReactions.vue +++ b/resources/vue/components/forum/posts/PostReactions.vue @@ -70,7 +70,7 @@ const storeReaction = async (emoji) => { forumDiscussionPost.addPostReaction(reaction, props.posting_id); showReactions.value = false; } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } } @@ -79,7 +79,7 @@ const deleteReaction = async (reactionId) => { await STUDIP.jsonapi.withPromises().DELETE(`forum-posting-reactions/${reactionId}`); forumDiscussionPost.removePostReaction(reactionId, props.posting_id); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } } diff --git a/resources/vue/components/forum/topics/TopicsIndex.vue b/resources/vue/components/forum/topics/TopicsIndex.vue index 9bdf233..e937932 100644 --- a/resources/vue/components/forum/topics/TopicsIndex.vue +++ b/resources/vue/components/forum/topics/TopicsIndex.vue @@ -64,7 +64,7 @@ const updateTopicsOrder = async () => { { data: { data } } ); } catch (error) { - STUDIP.Report.error(error.statusText); + STUDIP.Report.error(error); } } -- cgit v1.0