Skip to content
Snippets Groups Projects
Select Git revision
  • b11152c9e53633e708cb71d76699c47faba63518
  • main default protected
  • 5.5 protected
  • atlantis
  • 5.3 protected
  • 5.0 protected
  • issue-23
  • issue8-seat-logging-and-export
  • ticket-216
  • tickets-215-216-241-242
10 results

PublicLink.php

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    PublicLink.php 1.42 KiB
    <?php
    
    namespace JsonApi\Schemas\Courseware;
    
    use JsonApi\Schemas\SchemaProvider;
    use Neomerx\JsonApi\Contracts\Schema\ContextInterface;
    use Neomerx\JsonApi\Schema\Link;
    
    class PublicLink extends SchemaProvider
    {
        const TYPE = 'courseware-public-links';
    
        const REL_STRUCTURAL_ELEMENT = 'structural-element';
    
        /**
         * {@inheritdoc}
         */
        public function getId($resource): ?string
        {
            return $resource->id;
        }
    
            /**
         * {@inheritdoc}
         */
        public function getAttributes($resource, ContextInterface $context): array
        {
            return [
                'password' => $resource['password'],
                'expire-date' => $resource['expire_date'] ? date('Y-m-d', $resource['expire_date']) : null,
                'mkdate' => date('c', $resource['mkdate']),
                'chdate' => date('c', $resource['chdate']),
            ];
        }
    
            /**
         * {@inheritdoc}
         */
        public function getRelationships($resource, ContextInterface $context): iterable
        {
            $relationships = [];
    
            $relationships[self::REL_STRUCTURAL_ELEMENT] = $resource['structural_element_id']
            ? [
                self::RELATIONSHIP_LINKS => [
                    Link::RELATED => $this->createLinkToResource($resource['structural_element']),
                ],
                self::RELATIONSHIP_DATA => $resource['structural_element'],
            ]
            : [self::RELATIONSHIP_DATA => null];
    
            return $relationships;
        }
    }