id; } /** * {@inheritdoc} */ public function getAttributes($resource, ContextInterface $context): iterable { return [ 'position' => (int) $resource['position'], 'block-type' => (string) $resource->getBlockType(), 'title' => (string) $resource->type->getTitle(), 'visible' => (bool) $resource['visible'], 'commentable' => (bool) $resource['commentable'], 'payload' => $resource->type->getPayload(), 'mkdate' => date('c', $resource['mkdate']), 'chdate' => date('c', $resource['chdate']), ]; } /** * {@inheritdoc} */ public function getRelationships($resource, ContextInterface $context): iterable { $relationships = []; $relationships[self::REL_COMMENTS] = [ self::RELATIONSHIP_LINKS => [ Link::RELATED => $this->getRelationshipRelatedLink($resource, self::REL_COMMENTS), ], self::RELATIONSHIP_DATA => $resource->comments, ]; $relationships[self::REL_CONTAINER] = [ self::RELATIONSHIP_LINKS => [ Link::RELATED => $this->createLinkToResource($resource->container), ], self::RELATIONSHIP_DATA => $resource->container, ]; $relationships[self::REL_OWNER] = $resource->owner ? [ self::RELATIONSHIP_LINKS => [ Link::RELATED => $this->createLinkToResource($resource->owner), ], self::RELATIONSHIP_DATA => $resource->owner, ] : [self::RELATIONSHIP_DATA => null]; $relationships[self::REL_EDITOR] = $resource->editor ? [ self::RELATIONSHIP_LINKS => [ Link::RELATED => $this->createLinkToResource($resource->editor), ], self::RELATIONSHIP_DATA => $resource->editor, ] : [self::RELATIONSHIP_DATA => null]; $relationships[self::REL_EDITBLOCKER] = $resource->edit_blocker ? [ self::RELATIONSHIP_LINKS_SELF => true, self::RELATIONSHIP_LINKS => [ Link::RELATED => $this->createLinkToResource($resource->edit_blocker), ], self::RELATIONSHIP_DATA => $resource->edit_blocker, ] : [self::RELATIONSHIP_LINKS_SELF => true, self::RELATIONSHIP_DATA => null]; $relationships[self::REL_FEEDBACK] = [ self::RELATIONSHIP_LINKS => [ Link::RELATED => $this->getRelationshipRelatedLink($resource, self::REL_FEEDBACK), ], ]; $user = $this->currentUser; if ($user) { $userDataField = UserDataField::getUserDataField($user, $resource); $relationships[self::REL_USERDATAFIELD] = [ self::RELATIONSHIP_LINKS => [ Link::RELATED => $this->getRelationshipRelatedLink($resource, self::REL_USERDATAFIELD), ], self::RELATIONSHIP_DATA => $userDataField, ]; $userProgress = UserProgress::getUserProgress($user, $resource); $relationships[self::REL_USERPROGRESS] = [ self::RELATIONSHIP_LINKS => [ Link::RELATED => $this->getRelationshipRelatedLink($resource, self::REL_USERPROGRESS), ], self::RELATIONSHIP_DATA => $userProgress, ]; } if ($resource->files) { $filesLink = $this->getRelationshipRelatedLink($resource, self::REL_FILES); $relationships[self::REL_FILES] = [ self::RELATIONSHIP_LINKS => [ Link::RELATED => $filesLink, ], ]; } return $relationships; } }