Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
38 / 38 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
SourceEdit | |
100.00% |
38 / 38 |
|
100.00% |
2 / 2 |
11 | |
100.00% |
1 / 1 |
readResponse | |
100.00% |
27 / 27 |
|
100.00% |
1 / 1 |
8 | |||
testUpdateEntity | |
100.00% |
11 / 11 |
|
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\Source as Entity; |
13 | use BO\Mellon\Validator; |
14 | |
15 | class SourceEdit extends BaseController |
16 | { |
17 | /** |
18 | * @SuppressWarnings(Param) |
19 | * @return String |
20 | */ |
21 | public function readResponse( |
22 | \Psr\Http\Message\RequestInterface $request, |
23 | \Psr\Http\Message\ResponseInterface $response, |
24 | array $args |
25 | ) { |
26 | $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity(); |
27 | $success = $request->getAttribute('validator')->getParameter('success')->isString()->getValue(); |
28 | if (!$workstation->hasSuperUseraccount()) { |
29 | throw new Exception\NotAllowed(); |
30 | } |
31 | |
32 | if ('add' != $args['name']) { |
33 | $source = \App::$http |
34 | ->readGetResult('/source/' . $args['name'] . '/', ['resolveReferences' => 2]) |
35 | ->getEntity(); |
36 | } |
37 | |
38 | $input = $request->getParsedBody(); |
39 | if (is_array($input) && array_key_exists('save', $input)) { |
40 | $result = $this->testUpdateEntity($input); |
41 | if ($result instanceof Entity) { |
42 | return \BO\Slim\Render::redirect('sourceEdit', ['name' => $result->getSource()], [ |
43 | 'success' => 'source_saved' |
44 | ]); |
45 | } |
46 | } |
47 | |
48 | return \BO\Slim\Render::withHtml( |
49 | $response, |
50 | 'page/sourceedit.twig', |
51 | array( |
52 | 'title' => 'Mandanten bearbeiten', |
53 | 'menuActive' => 'source', |
54 | 'workstation' => $workstation, |
55 | 'source' => (isset($source)) ? $source : null, |
56 | 'success' => $success, |
57 | 'exception' => (isset($result)) ? $result : null |
58 | ) |
59 | ); |
60 | } |
61 | |
62 | protected function testUpdateEntity($input) |
63 | { |
64 | $entity = (new Entity($input))->withCleanedUpFormData(); |
65 | try { |
66 | $entity = \App::$http->readPostResult('/source/', $entity)->getEntity(); |
67 | } catch (\BO\Zmsclient\Exception $exception) { |
68 | if ('BO\Zmsentities\Exception\SchemaValidation' == $exception->template) { |
69 | $exceptionData = [ |
70 | 'template' => 'exception/bo/zmsentities/exception/schemavalidation.twig' |
71 | ]; |
72 | $exceptionData['data'] = $exception->data; |
73 | return $exceptionData; |
74 | } else { |
75 | throw $exception; |
76 | } |
77 | } |
78 | return $entity; |
79 | } |
80 | } |