mirror of
https://github.com/flarum/core.git
synced 2025-10-09 05:56:25 +02:00
- Use contextual namespaces within Flarum\Core - Clean up and docblock everything - Refactor Activity/Notification blueprint stuff - Refactor Formatter stuff - Refactor Search stuff - Upgrade to JSON-API 1.0 - Removed “addedPosts” and “removedPosts” relationships from discussion API. This was used for adding/removing event posts after renaming a discussion etc. Instead we should make an additional request to get all new posts Todo: - Fix Extenders and extensions - Get rid of repository interfaces - Fix other bugs I’ve inevitably introduced
35 lines
1.3 KiB
PHP
35 lines
1.3 KiB
PHP
<?php namespace Flarum\Api\Serializers;
|
|
|
|
use Flarum\Core\Discussions\Discussion;
|
|
|
|
class DiscussionSerializer extends DiscussionBasicSerializer
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getDefaultAttributes($discussion)
|
|
{
|
|
$attributes = parent::getDefaultAttributes($discussion) + [
|
|
'commentsCount' => (int) $discussion->comments_count,
|
|
'participantsCount' => (int) $discussion->participants_count,
|
|
'startTime' => $discussion->start_time->toRFC3339String(),
|
|
'lastTime' => $discussion->last_time ? $discussion->last_time->toRFC3339String() : null,
|
|
'lastPostNumber' => $discussion->last_post_number,
|
|
'canReply' => $discussion->can($this->actor, 'reply'),
|
|
'canRename' => $discussion->can($this->actor, 'rename'),
|
|
'canDelete' => $discussion->can($this->actor, 'delete')
|
|
];
|
|
|
|
Discussion::setStateUser($this->actor);
|
|
|
|
if ($state = $discussion->state) {
|
|
$attributes += [
|
|
'readTime' => $state->read_time ? $state->read_time->toRFC3339String() : null,
|
|
'readNumber' => (int) $state->read_number
|
|
];
|
|
}
|
|
|
|
return $attributes;
|
|
}
|
|
}
|