Skip to content
Snippets Groups Projects
Select Git revision
  • a3da1483a9e689846179159355badfec8073dbec
  • 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

FileArchiveManagerException.class.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.
    Instance.php 3.20 KiB
    <?php
    
    namespace JsonApi\Schemas\Courseware;
    
    use JsonApi\Schemas\SchemaProvider;
    use Neomerx\JsonApi\Contracts\Schema\ContextInterface;
    use Neomerx\JsonApi\Schema\Link;
    
    class Instance extends SchemaProvider
    {
        const TYPE = 'courseware-instances';
    
        const REL_BOOKMARKS = 'bookmarks';
        const REL_ROOT = 'root';
    
        /**
         * {@inheritdoc}
         */
        public function getId($resource): ?string
        {
            $root = $resource->getRoot();
            $unit = \Courseware\Unit::findOneBySQL('structural_element_id = ?', [$root->id]);
    
            return join('_', [$root->range_type, $root->range_id, $unit->id]);
        }
    
        /**
         * {@inheritdoc}
         *
         * @param \Courseware\Instance $resource
         */
        public function getAttributes($resource, ContextInterface $context): iterable
        {
            $user = $this->currentUser;
    
            return [
                'block-types' => array_map([$this, 'mapBlockType'], $resource->getBlockTypes()),
                'container-types' => array_map([$this, 'mapContainerType'], $resource->getContainerTypes()),
                'favorite-block-types' => $resource->getFavoriteBlockTypes($user),
                'sequential-progression' => $resource->getSequentialProgression(),
                'editing-permission-level' => $resource->getEditingPermissionLevel(),
                'certificate-settings' => $resource->getCertificateSettings(),
                'reminder-settings' => $resource->getReminderSettings(),
                'reset-progress-settings' => $resource->getResetProgressSettings(),
                'root-id' => $resource->getRoot()->id
            ];
        }
    
        /**
         * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
         */
        private function mapBlockType(string $typeClass): array
        {
            return [
                'type' => $typeClass::getType(),
                'title' => $typeClass::getTitle(),
                'description' => $typeClass::getDescription(),
                'categories' => $typeClass::getCategories(),
                'content_types' => $typeClass::getContentTypes(),
                'file_types' => $typeClass::getFileTypes(),
                'tags' => $typeClass::getTags(),
            ];
        }
    
        /**
         * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
         */
        private function mapContainerType(string $typeClass): array
        {
            return [
                'type' => $typeClass::getType(),
                'title' => $typeClass::getTitle(),
                'description' => $typeClass::getDescription(),
            ];
        }
    
        /**
         * {@inheritdoc}
         */
        public function getRelationships($resource, ContextInterface $context): iterable
        {
            $relationships = [];
    
            $user = $this->currentUser;
            $relationships[self::REL_BOOKMARKS] = [
                self::RELATIONSHIP_LINKS_SELF => true,
                self::RELATIONSHIP_LINKS => [
                    Link::RELATED => $this->getRelationshipRelatedLink($resource, self::REL_BOOKMARKS),
                ],
                self::RELATIONSHIP_DATA => $resource->getUsersBookmarks($user),
            ];
    
            $relationships[self::REL_ROOT] = [
                self::RELATIONSHIP_LINKS => [
                    Link::RELATED => $this->createLinkToResource($resource->getRoot()),
                ],
                self::RELATIONSHIP_DATA => $resource->getRoot(),
            ];
    
            return $relationships;
        }
    }