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

webpack.dev.js

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.
    UnitsCopy.php 1.50 KiB
    <?php
    
    namespace JsonApi\Routes\Courseware;
    
    use JsonApi\NonJsonApiController;
    use Courseware\Unit;
    use JsonApi\Errors\AuthorizationFailedException;
    use JsonApi\Errors\BadRequestException;
    use JsonApi\Errors\RecordNotFoundException;
    use JsonApi\Errors\UnprocessableEntityException;
    use Psr\Http\Message\ResponseInterface as Response;
    use Psr\Http\Message\ServerRequestInterface as Request;
    
    /**
    * Copy an courseware unit into a course or users contents
    *
    * @author  Ron Lucke <lucke@elan-ev.de>
    * @license GPL2 or any later version
    *
    * @since   Stud.IP 5.3
    */
    
    class UnitsCopy extends NonJsonApiController
    {
        public function __invoke(Request $request, Response $response, array $args)
        {
            $data = $request->getParsedBody()['data'];
    
            $sourceUnit = Unit::find($args['id']);
            $user = $this->getUser($request);
            $rangeId = $data['rangeId'];
            $rangeType = $data['rangeType'];
            $modified = $data['modified'];
    
            try {
                $range = \RangeFactory::createRange($rangeType, $rangeId);
            } catch (\Exception $e) {
                throw new RecordNotFoundException('Range could not be found');
            }
    
            if (!Authority::canCreateUnit($user, $range)) {
                throw new AuthorizationFailedException();
            }
    
            $newUnit = $sourceUnit->copy($user, $rangeId, $rangeType, $modified);
    
            $response = $response->withHeader('Content-Type', 'application/json');
            $response->getBody()->write((string) json_encode($newUnit));
    
            return $response;
        }
    }