Lines
94.20%
65 / 69
Functions and Methods
60.00%
3 / 5
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Scope | 94.20% | 65 / 69 | 60.00% | 3 / 5 | 16.05 | 0.00% | 0 / 1 | |||
| readResponse | 97.95% | 48 / 49 | 0.00% | 0 / 1 | 6 | |||||
| readSourceList | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | |||||
| readCurrentSource | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | |||||
| writeUpdatedEntity | 76.92% | 10 / 13 | 0.00% | 0 / 1 | 5.31 | |||||
| writeUploadedImage | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 3 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * | |
| 5 | * @package Zmsadmin | |
| 6 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 7 | * | |
| 8 | */ | |
| 9 | ||
| 10 | namespace BO\Zmsadmin; | |
| 11 | ||
| 12 | use BO\Mellon\Validator; | |
| 13 | use BO\Slim\Render; | |
| 14 | use BO\Zmsentities\Scope as Entity; | |
| 15 | ||
| 16 | class Scope extends BaseController | |
| 17 | { | |
| 18 | /** | |
| 19 | * | |
| 20 | * @return \Psr\Http\Message\ResponseInterface | |
| 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 | } |