Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
91.67% covered (success)
91.67%
33 / 36
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Owner
91.67% covered (success)
91.67%
33 / 36
0.00% covered (danger)
0.00%
0 / 1
5.01
0.00% covered (danger)
0.00%
0 / 1
 readResponse
91.67% covered (success)
91.67%
33 / 36
0.00% covered (danger)
0.00%
0 / 1
5.01
1<?php
2
3/**
4 *
5 * @package Zmsadmin
6 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
7 *
8 */
9
10namespace BO\Zmsadmin;
11
12use BO\Mellon\Validator;
13use BO\Zmsentities\Owner as Entity;
14use BO\Zmsentities\Exception\UserAccountMissingRights;
15use BO\Slim\Render;
16
17class 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}