Skip to content
Snippets Groups Projects
Select Git revision
  • b1f13ce8299d581ccb889e2d98e13574bffcc5ba
  • main default protected
  • step-3263
  • feature/plugins-cli
  • feature/vite
  • step-2484-peerreview
  • biest/issue-5051
  • tests/simplify-jsonapi-tests
  • fix/typo-in-1a70031
  • feature/broadcasting
  • database-seeders-and-factories
  • feature/peer-review-2
  • feature-feedback-jsonapi
  • feature/peerreview
  • feature/balloon-plus
  • feature/stock-images-unsplash
  • tic-2588
  • 5.0
  • 5.2
  • biest/unlock-blocks
  • biest-1514
21 results

StudipSemSearchHelper.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;
        }
    }