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

AdminCourseFilter.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.
    CourseMember.php 2.21 KiB
    <?php
    
    namespace JsonApi\Schemas;
    
    use JsonApi\Routes\Courses\Authority as CourseAuthority;
    use JsonApi\Routes\CourseMemberships\Authority as MembershipAuthority;
    use Neomerx\JsonApi\Contracts\Schema\ContextInterface;
    use Neomerx\JsonApi\Schema\Link;
    
    class CourseMember extends SchemaProvider
    {
        const TYPE = 'course-memberships';
        const REL_COURSE = 'course';
        const REL_USER = 'user';
    
        public function getId($membership): ?string
        {
            return $membership->id;
        }
    
        public function getAttributes($membership, ContextInterface $context): iterable
        {
            $attributes = [
                'permission' => $membership->status,
                'position' => (int) $membership->position,
                'group' => (int) $membership->gruppe,
                'mkdate' => date('c', $membership->mkdate),
                'label' => $membership->label,
            ];
    
            if ($this->currentUser) {
                if (MembershipAuthority::canIndexMembershipsOfUser($this->currentUser, $membership->user)) {
                    # TODO: $attributes['notification'] = (int) $membership->notification;
                    $attributes['visible'] = $membership->visible;
                }
                if (CourseAuthority::canEditCourse($this->currentUser, $membership->course)) {
                    $attributes['comment'] = $membership->comment;
                    $attributes['visible'] = $membership->visible;
                }
            }
    
            return $attributes;
        }
    
        public function getRelationships($membership, ContextInterface $context): iterable
        {
            $isPrimary = $context->getPosition()->getLevel() === 0;
    
            $relationships = [];
    
            if ($isPrimary) {
                $relationships[self::REL_COURSE] = [
                    self::RELATIONSHIP_LINKS => [
                        Link::RELATED => $this->createLinkToResource($membership->course)
                    ],
                    self::RELATIONSHIP_DATA => $membership->course,
                ];
    
                $relationships[self::REL_USER] = [
                    self::RELATIONSHIP_LINKS => [
                        Link::RELATED => $this->createLinkToResource($membership->user)
                    ],
                    self::RELATIONSHIP_DATA => $membership->user,
                ];
            }
    
            return $relationships;
        }
    }