Skip to content
Snippets Groups Projects
Select Git revision
  • 5f78b312c8ad82f91148d6bfe79c614651736161
  • main default protected
  • studip-rector
  • ci-opt
  • course-members-export-as-word
  • data-vue-app
  • pipeline-improvements
  • webpack-optimizations
  • rector
  • icon-renewal
  • http-client-and-factories
  • jsonapi-atomic-operations
  • vueify-messages
  • tic-2341
  • 135-translatable-study-areas
  • extensible-sorm-action-parameters
  • sorm-configuration-trait
  • jsonapi-mvv-routes
  • docblocks-for-magic-methods
19 results

StructuralElementCommentsOfStructuralElementsIndex.php

Blame
  • Forked from Stud.IP / Stud.IP
    1157 commits behind the upstream repository.
    David Siegfried's avatar
    David Siegfried authored
    Closes #44
    
    Merge request studip/studip!811
    8fabce22
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    StructuralElementCommentsOfStructuralElementsIndex.php 1.18 KiB
    <?php
    
    namespace JsonApi\Routes\Courseware;
    
    use Courseware\StructuralElement;
    use Courseware\StructuralElementComment;
    use JsonApi\Errors\AuthorizationFailedException;
    use JsonApi\Errors\RecordNotFoundException;
    use JsonApi\JsonApiController;
    use Psr\Http\Message\ResponseInterface as Response;
    use Psr\Http\Message\ServerRequestInterface as Request;
    
    /**
     * Displays the user progress of a structural element.
     */
    class StructuralElementCommentsOfStructuralElementsIndex extends JsonApiController
    {
        protected $allowedIncludePaths = ['structural-element', 'user'];
    
        /**
         * @SuppressWarnings(PHPMD.UnusedFormalParameter)
         */
        public function __invoke(Request $request, Response $response, $args)
        {
            if (!($structural_element = StructuralElement::find($args['id']))) {
                throw new RecordNotFoundException();
            }
            if (!Authority::canIndexStructuralElementComments($this->getUser($request), $structural_element)) {
                throw new AuthorizationFailedException();
            }
            $resources = StructuralElementComment::findBySql('structural_element_id = ?', [$structural_element->id]);
    
            return $this->getContentResponse($resources);
        }
    }