Lines
91.66%
33 / 36
Functions and Methods
0.00%
0 / 1
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Owner | 91.66% | 33 / 36 | 0.00% | 0 / 1 | 5.01 | 0.00% | 0 / 1 | |||
| readResponse | 91.66% | 33 / 36 | 0.00% | 0 / 1 | 5.01 | |||||
| 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\Zmsentities\Owner as Entity; | |
| 14 | use BO\Zmsentities\Exception\UserAccountMissingRights; | |
| 15 | use BO\Slim\Render; | |
| 16 | ||
| 17 | class Owner extends BaseController | |
| 18 | { | |
| 19 | /** | |
| 20 | * | |
| 21 | * @return \Psr\Http\Message\ResponseInterface | |
| 22 | */ | |
| 23 | #[\Override] | |
| 24 | public function readResponse( | |
| 25 | \Psr\Http\Message\RequestInterface $request, | |
| 26 | \Psr\Http\Message\ResponseInterface $response, | |
| 27 | array $args | |
| 28 | ): \Psr\Http\Message\ResponseInterface { | |
| 29 | $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity(); | |
| 30 | if (!$workstation instanceof \BO\Zmsentities\Workstation) { | |
| 31 | throw new \BO\Zmsclient\Exception\BadRequest('Could not load workstation'); | |
| 32 | } | |
| 33 | if (!$workstation->getUseraccount()->hasPermissions(['jurisdiction'])) { | |
| 34 | throw new UserAccountMissingRights(); | |
| 35 | } | |
| 36 | $success = $request->getAttribute('validator')->getParameter('success')->isString()->getValue(); | |
| 37 | $entityId = Validator::value($args['id'])->isNumber()->getValue(); | |
| 38 | $entity = \App::$http->readGetResult('/owner/' . $entityId . '/')->getEntity(); | |
| 39 | if (!$entity instanceof Entity) { | |
| 40 | throw new \BO\Zmsclient\Exception\BadRequest('Could not load owner'); | |
| 41 | } | |
| 42 | $input = $request->getParsedBody(); | |
| 43 | if (array_key_exists('save', (array) $input)) { | |
| 44 | $entity = (new Entity($input))->withCleanedUpFormData(); | |
| 45 | $entity->id = $entityId; | |
| 46 | \App::$http->readPostResult('/owner/' . $entity->id . '/', $entity) | |
| 47 | ->getEntity(); | |
| 48 | return Render::redirect( | |
| 49 | 'owner', | |
| 50 | [ | |
| 51 | 'id' => $entityId | |
| 52 | ], | |
| 53 | [ | |
| 54 | 'success' => 'owner_saved' | |
| 55 | ] | |
| 56 | ); | |
| 57 | } | |
| 58 | ||
| 59 | return Render::withHtml( | |
| 60 | $response, | |
| 61 | 'page/owner.twig', | |
| 62 | array( | |
| 63 | 'title' => 'Kunde', | |
| 64 | 'workstation' => $workstation->getArrayCopy(), | |
| 65 | 'menuActive' => 'owner', | |
| 66 | 'owner' => $entity->getArrayCopy(), | |
| 67 | 'success' => $success | |
| 68 | ) | |
| 69 | ); | |
| 70 | } | |
| 71 | } |