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

BlockCommentsUpdate.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.
    StructuralElementsImageDelete.php 1.01 KiB
    <?php
    
    namespace JsonApi\Routes\Courseware;
    
    use Courseware\StructuralElement;
    use JsonApi\Errors\AuthorizationFailedException;
    use JsonApi\Errors\RecordNotFoundException;
    use JsonApi\NonJsonApiController;
    use Psr\Http\Message\ResponseInterface as Response;
    use Psr\Http\Message\ServerRequestInterface as Request;
    
    class StructuralElementsImageDelete extends NonJsonApiController
    {
        public function invoke(Request $request, Response $response, array $args): Response
        {
            if (!($structuralElement = StructuralElement::find($args['id']))) {
                throw new RecordNotFoundException();
            }
    
            if (!Authority::canDeleteStructuralElementsImage($this->getUser($request), $structuralElement)) {
                throw new AuthorizationFailedException();
            }
    
            if ($structuralElement->image) {
                $structuralElement->image->getFileType()->delete();
            }
    
            $structuralElement->image_id = null;
            $structuralElement->store();
    
            return $response->withStatus(204);
        }
    }