Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
41 / 41
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
OrganisationAddDepartment
100.00% covered (success)
100.00%
41 / 41
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
31 / 31
100.00% covered (success)
100.00%
1 / 1
2
 withCleanupLinks
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 withCleanupDayoffs
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Zmsentities\Department as Entity;
11use BO\Mellon\Validator;
12
13class OrganisationAddDepartment extends BaseController
14{
15    /**
16     * @return \Psr\Http\Message\ResponseInterface
17     */
18    #[\Override]
19    public function readResponse(
20        \Psr\Http\Message\RequestInterface $request,
21        \Psr\Http\Message\ResponseInterface $response,
22        array $args
23    ): \Psr\Http\Message\ResponseInterface {
24        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity();
25        $input = $request->getParsedBody();
26        $organisationId = Validator::value($args['id'])->isNumber()->getValue();
27        $organisation = \App::$http->readGetResult('/organisation/' . $organisationId . '/')->getEntity();
28        if ($request->getMethod() === 'POST') {
29            $input = $this->withCleanupLinks($input);
30            $input = $this->withCleanupDayoffs($input);
31            $entity = (new Entity($input))->withCleanedUpFormData();
32            $entity->dayoff = $entity->getDayoffList()->withTimestampFromDateformat();
33            $department = \App::$http->readPostResult('/organisation/' . $organisationId . '/department/', $entity)
34                ->getEntity();
35            return \BO\Slim\Render::redirect(
36                'department',
37                array(
38                    'id' => $department->id
39                ),
40                array(
41                    'success' => 'department_created'
42                )
43            );
44        }
45
46        return \BO\Slim\Render::withHtml(
47            $response,
48            'page/department.twig',
49            array(
50                'title' => 'Behörde einrichten',
51                'action' => 'add',
52                'menuActive' => 'owner',
53                'workstation' => $workstation,
54                'organisation' => $organisation
55            )
56        );
57    }
58
59    protected function withCleanupLinks(array $input)
60    {
61        $links = $input['links'];
62
63        $input['links'] = array_filter($links, function ($link) {
64            return !($link['name'] === '' && $link['url'] == '');
65        });
66
67        return $input;
68    }
69
70    protected function withCleanupDayoffs(array $input)
71    {
72        $dayoffs = $input['dayoff'];
73        $input['dayoff'] = array_filter($dayoffs, function ($dayoff) {
74            return !($dayoff['name'] === '');
75        });
76
77        return $input;
78    }
79}