| 16 | | class Scope extends BaseController |
| 17 | | { |
| 18 | | |
| 19 | | |
| 20 | | |
| 21 | | |
| 22 | | #[\Override] |
| 23 | | public function readResponse( |
| 24 | | \Psr\Http\Message\RequestInterface $request, |
| 25 | | \Psr\Http\Message\ResponseInterface $response, |
| 26 | | array $args |
| 27 | | ): \Psr\Http\Message\ResponseInterface { |
| 28 | | $success = $request->getAttribute('validator')->getParameter('success')->isString()->getValue(); |
| 29 | | |
| 30 | | $workstation = \App::$http->readGetResult('/workstation/', [ |
| 31 | | 'resolveReferences' => 1, |
| 32 | | 'gql' => Helper\GraphDefaults::getWorkstation() |
| 33 | | ])->getEntity(); |
| 34 | | if (!$workstation->getUseraccount()->hasAnyPermission(['scope','restrictedscope'])) { |
| 35 | | throw new \BO\Zmsentities\Exception\UserAccountMissingRights(); |
| 36 | | } |
| 37 | | $entityId = Validator::value($args['id'])->isNumber()->getValue(); |
| 38 | | $entity = \App::$http |
| 39 | | ->readGetResult('/scope/' . $entityId . '/', [ |
| 40 | | 'resolveReferences' => 1, |
| 41 | | 'accessRights' => 'restrictedscope', |
| 42 | | 'gql' => Helper\GraphDefaults::getScope() |
| 43 | | ]) |
| 44 | | ->getEntity(); |
| 45 | | |
| 46 | | $sourceList = $this->readSourceList(); |
| 47 | | $providerList = Helper\ProviderHandler::readProviderList($entity->getSource()); |
| 48 | | $currentSource = $this->readCurrentSource($entity->getSource()); |
| 49 | | |
| 50 | | $organisation = \App::$http->readGetResult('/scope/' . $entityId . '/organisation/')->getEntity(); |
| 51 | | $department = \App::$http->readGetResult('/scope/' . $entityId . '/department/')->getEntity(); |
| 52 | | $callDisplayImage = \App::$http->readGetResult('/scope/' . $entityId . '/imagedata/calldisplay/')->getEntity(); |
| 53 | | $input = $request->getParsedBody(); |
| 54 | | if ($request->getMethod() === 'POST') { |
| 55 | | $result = $this->writeUpdatedEntity($input, $entityId, $entity, $workstation); |
| 56 | | if ($result instanceof Entity) { |
| 57 | | if ($workstation->getUseraccount()->hasPermissions(['scope'])) { |
| 58 | | $this->writeUploadedImage($request, $entityId, $input); |
| 59 | | } |
| 60 | | return Render::redirect('scope', ['id' => $entityId], [ |
| 61 | | 'success' => 'scope_saved' |
| 62 | | ]); |
| 63 | | } |
| 64 | | } |
| 65 | | |
| 66 | | return Render::withHtml( |
| 67 | | $response, |
| 68 | | 'page/scope.twig', |
| 69 | | array( |
| 70 | | 'title' => 'Standort', |
| 71 | | 'menuActive' => 'owner', |
| 72 | | 'workstation' => $workstation, |
| 73 | | 'scope' => $entity, |
| 74 | | 'provider' => $entity->provider, |
| 75 | | 'organisation' => $organisation, |
| 76 | | 'department' => $department, |
| 77 | | 'providerList' => $providerList, |
| 78 | | 'sourceList' => $sourceList, |
| 79 | | 'source' => $currentSource, |
| 80 | | 'callDisplayImage' => $callDisplayImage, |
| 81 | | 'success' => $success, |
| 82 | | 'exception' => (isset($result)) ? $result : null |
| 83 | | ) |
| 84 | | ); |
| 85 | | } |
| 86 | | |
| 87 | | protected function readSourceList() |
| 88 | | { |
| 89 | | $sourceList = \App::$http->readGetResult('/source/')->getCollection(); |
| 90 | | return $sourceList; |
| 91 | | } |
| 92 | | |
| 93 | | protected function readCurrentSource($source) |
| 94 | | { |
| 95 | | $source = \App::$http->readGetResult('/source/' . $source . '/')->getEntity(); |
| 96 | | return $source; |
| 97 | | } |
| 98 | | |
| 99 | | protected function writeUpdatedEntity(array $input, $entityId = null, ?Entity $existingScope = null, $workstation = null) |
| 100 | | { |
| 101 | | $entity = (new Entity($input))->withCleanedUpFormData(); |
| 102 | | if ($workstation && !$workstation->getUseraccount()->hasPermissions(['scope'])) { |
| 103 | | if (!$existingScope) { |
| 104 | | throw new \BO\Zmsentities\Exception\UserAccountMissingRights(); |
| 105 | | } |
| 106 | | $entity = $entity->withProviderSourceFrom($existingScope); |
| 107 | | } |
| 108 | | return $this->handleEntityWrite(function () use ($entity, $entityId, $existingScope) { |
| 109 | | if ($existingScope) { |
| 110 | | $entity->id = $entityId; |
| 111 | | return \App::$http->readPostResult('/scope/' . $entity->id . '/', $entity)->getEntity(); |
| 112 | | } |
| 113 | | return \App::$http |
| 114 | | ->readPostResult('/department/' . $entityId . '/scope/', $entity) |
| 115 | | ->getEntity(); |
| 116 | | }); |
| 117 | | } |
| 118 | | |
| 119 | | protected function writeUploadedImage(\Psr\Http\Message\RequestInterface $request, $entityId, array $input): void |
| 120 | | { |
| 121 | | if (isset($input['removeImage']) && $input['removeImage']) { |
| 122 | | \App::$http->readDeleteResult('/scope/' . $entityId . '/imagedata/calldisplay/'); |
| 123 | | } else { |
| 124 | | (new Helper\FileUploader($request, 'uploadCallDisplayImage'))->writeUploadToScope($entityId); |
| 125 | | } |
| 126 | | } |
| 127 | | } |