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