diff options
| author | Murtaza Sultani <sultani@data-quest.de> | 2025-09-18 11:15:04 +0200 |
|---|---|---|
| committer | David Siegfried <david.siegfried@uni-vechta.de> | 2025-09-18 09:15:04 +0000 |
| commit | 9d68dd50ba13113d3d8d54a0c931607ecd9a167d (patch) | |
| tree | 8b4fb45430a255297e31035bea9238ba69ace3af /lib | |
| parent | 08ea2ee27c3d287d8a99375cb71d6906371b3499 (diff) | |
Resolve "Forum: Variablennamen und Typdeklarationen aktualisieren"
Closes #5890
Merge request studip/studip!4491
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/classes/JsonApi/Routes/Forum/ForumAuthority.php | 14 | ||||
| -rw-r--r-- | lib/classes/JsonApi/Schemas/Forum/Category.php | 48 | ||||
| -rw-r--r-- | lib/classes/JsonApi/Schemas/Forum/Discussion.php | 69 | ||||
| -rw-r--r-- | lib/classes/JsonApi/Schemas/Forum/Member.php | 23 | ||||
| -rw-r--r-- | lib/classes/JsonApi/Schemas/Forum/Posting.php | 57 | ||||
| -rw-r--r-- | lib/classes/JsonApi/Schemas/Forum/PostingReaction.php | 31 | ||||
| -rw-r--r-- | lib/classes/JsonApi/Schemas/Forum/Subscription.php | 84 | ||||
| -rw-r--r-- | lib/classes/JsonApi/Schemas/Forum/Tag.php | 17 | ||||
| -rw-r--r-- | lib/classes/JsonApi/Schemas/Forum/Topic.php | 51 | ||||
| -rw-r--r-- | lib/models/Forum/Posting.php | 2 |
10 files changed, 226 insertions, 170 deletions
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 @@ -<?php - -namespace JsonApi\Routes\Forum; - -use Range; -use User; - -class ForumAuthority -{ - public static function canShowForum(Range $range, ?User $user = null): bool - { - return $range->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' ]; |
