public function serialize(Forum $forum, array $options = [])
    {
        $currentUser = $this->tokenStorage->getToken()->getUser();

        if (!is_string($currentUser)) {
            $forumUser = $this->manager->getValidationUser($currentUser, $forum);
        } else {
            $forumUser = new User();
        }

        $now = new \DateTime();
        $readonly = false;

        if ($forum->getLockDate()) {
            $readonly = $forum->getLockDate() > $now;
        }

        $banned = $this->checkPermission('EDIT', $forum->getResourceNode()) ?
          false :
          $forumUser->isBanned() || $readonly;

        return [
            'id' => $forum->getUuid(),
            'moderation' => $forum->getValidationMode(),
            'maxComment' => $forum->getMaxComment(),
            'display' => [
              'description' => $forum->getDescription(),
              'showOverview' => $forum->getShowOverview(),
              'subjectDataList' => $forum->getDataListOptions(),
              'lastMessagesCount' => $forum->getDisplayMessages(),
            ],
            'restrictions' => [
              'lockDate' => $forum->getLockDate() ? $forum->getLockDate()->format('Y-m-d\TH:i:s') : null, // TODO : use DateNormalizer
              'banned' => $banned, // TODO : data about current user should not be here
              'moderator' => $this->checkPermission('EDIT', $forum->getResourceNode()), // TODO : data about current user should not be here
            ],
            'meta' => [
              'users' => $this->finder->fetch(User::class, ['forum' => $forum->getUuid()], null, 0, 0, true),
              'subjects' => $this->finder->fetch(Subject::class, ['forum' => $forum->getUuid()], null, 0, 0, true),
              //probably an issue with the validate_none somewhere
              'messages' => $this->finder->fetch(Message::class, ['forum' => $forum->getUuid()], null, 0, 0, true),
              'myMessages' => !is_string($currentUser) ?
                  $this->finder->fetch(Message::class, ['forum' => $forum->getUuid(), 'creator' => $currentUser->getUsername()], null, 0, 0, true) :
                  0, // TODO : data about current user should not be here
              'tags' => $this->getTags($forum),
              'notified' => $forumUser->isNotified(),
            ],
        ];
    }
public function serialize(Forum $forum, array $options = [])
    {
        $currentUser = $this->tokenStorage->getToken()->getUser();

        if (!is_string($currentUser)) {
            $forumUser = $this->manager->getValidationUser($currentUser, $forum);
        } else {
            $forumUser = new User();
        }

        $now = new \DateTime();
        $readonly = false;

        if ($forum->getLockDate()) {
            $readonly = $forum->getLockDate() > $now;
        }

        $banned = $this->checkPermission('EDIT', $forum->getResourceNode()) ?
          false :
          $forumUser->isBanned() || $readonly;

        return [
            'id' => $forum->getUuid(),
            'moderation' => $forum->getValidationMode(),
            'maxComment' => $forum->getMaxComment(),
            'display' => [
              'description' => $forum->getDescription(),
              'showOverview' => $forum->getShowOverview(),
              'subjectDataList' => $forum->getDataListOptions(),
              'lastMessagesCount' => $forum->getDisplayMessages(),
            ],
            'restrictions' => [
              'lockDate' => $forum->getLockDate() ? $forum->getLockDate()->format('Y-m-d\TH:i:s') : null, // TODO : use DateNormalizer
              'banned' => $banned, // TODO : data about current user should not be here
              'moderator' => $this->checkPermission('EDIT', $forum->getResourceNode()), // TODO : data about current user should not be here
            ],
            'meta' => [
              'users' => $this->finder->fetch(User::class, ['forum' => $forum->getUuid()], null, 0, 0, true),
              'subjects' => $this->finder->fetch(Subject::class, ['forum' => $forum->getUuid()], null, 0, 0, true),
              //probably an issue with the validate_none somewhere
              'messages' => $this->finder->fetch(Message::class, ['forum' => $forum->getUuid()], null, 0, 0, true),
              'myMessages' => !is_string($currentUser) ?
                  $this->finder->fetch(Message::class, ['forum' => $forum->getUuid(), 'creator' => $currentUser->getUsername()], null, 0, 0, true) :
                  0, // TODO : data about current user should not be here
              'tags' => $this->getTags($forum),
              'notified' => $forumUser->isNotified(),
            ],
        ];
    }
public function serialize ( Forum $ forum , array $ options = [ ] ) { $ currentUser = $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ; if ( ! is_string ( $ currentUser ) ) { $ forumUser = $ this -> manager -> getValidationUser ( $ currentUser , $ forum ) ; } else { $ forumUser = new User ( ) ; } $ now = new \ DateTime ( ) ; $ readonly = false ; if ( $ forum -> getLockDate ( ) ) { $ readonly = $ forum -> getLockDate ( ) > $ now ; } $ banned = $ this -> checkPermission ( 'EDIT' , $ forum -> getResourceNode ( ) ) ? false : $ forumUser -> isBanned ( ) || $ readonly ; return [ 'id' => $ forum -> getUuid ( ) , 'moderation' => $ forum -> getValidationMode ( ) , 'maxComment' => $ forum -> getMaxComment ( ) , 'display' => [ 'description' => $ forum -> getDescription ( ) , 'showOverview' => $ forum -> getShowOverview ( ) , 'subjectDataList' => $ forum -> getDataListOptions ( ) , 'lastMessagesCount' => $ forum -> getDisplayMessages ( ) , ] , 'restrictions' => [ 'lockDate' => $ forum -> getLockDate ( ) ? $ forum -> getLockDate ( ) -> format ( 'Y-m-d\TH:i:s' ) : null , // TODO : use DateNormalizer 'banned' => $ banned , // TODO : data about current user should not be here 'moderator' => $ this -> checkPermission ( 'EDIT' , $ forum -> getResourceNode ( ) ) , // TODO : data about current user should not be here ] , 'meta' => [ 'users' => $ this -> finder -> fetch ( User :: class , [ 'forum' => $ forum -> getUuid ( ) ] , null , 0 , 0 , true ) , 'subjects' => $ this -> finder -> fetch ( Subject :: class , [ 'forum' => $ forum -> getUuid ( ) ] , null , 0 , 0 , true ) , //probably an issue with the validate_none somewhere 'messages' => $ this -> finder -> fetch ( Message :: class , [ 'forum' => $ forum -> getUuid ( ) ] , null , 0 , 0 , true ) , 'myMessages' => ! is_string ( $ currentUser ) ? $ this -> finder -> fetch ( Message :: class , [ 'forum' => $ forum -> getUuid ( ) , 'creator' => $ currentUser -> getUsername ( ) ] , null , 0 , 0 , true ) : 0 , // TODO : data about current user should not be here 'tags' => $ this -> getTags ( $ forum ) , 'notified' => $ forumUser -> isNotified ( ) , ] , ] ; }
Serializes a Forum entity.

@param Forum $forum
@param array $options

@return array
Serializes a Forum entity .