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