* @license GPL2 or any later version * * @since Stud.IP 5.0 */ class ContainersCopy extends NonJsonApiController { public function __invoke(Request $request, Response $response, array $args) { $data = $request->getParsedBody()['data']; $container = \Courseware\Container::find($data['container']['id']); if (!$container) { throw new RecordNotFoundException(); } $element = \Courseware\StructuralElement::find($data['parent_id']); if (!$element) { throw new RecordNotFoundException(); } $user = $this->getUser($request); if (!Authority::canCreateContainer($user, $element) || !Authority::canUpdateContainer($user, $container)) { throw new AuthorizationFailedException(); } $new_container = $this->copyContainer($user, $container, $element); $response = $response->withHeader('Content-Type', 'application/json'); $response->getBody()->write((string) json_encode($new_container)); return $response; } private function copyContainer(\User $user, \Courseware\Container $remote_container, \Courseware\StructuralElement $element) { list($container, $blockMapObjs) = $remote_container->copy($user, $element); return $container; } }