Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.55% covered (success)
96.55%
28 / 29
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
DayoffByYear
96.55% covered (success)
96.55%
28 / 29
0.00% covered (danger)
0.00%
0 / 1
5
0.00% covered (danger)
0.00%
0 / 1
 readResponse
96.55% covered (success)
96.55%
28 / 29
0.00% covered (danger)
0.00%
0 / 1
5
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Zmsentities\Collection\DayoffList;
11use BO\Zmsentities\Exception\UserAccountMissingRights;
12use BO\Mellon\Validator;
13
14class DayoffByYear extends BaseController
15{
16    /**
17     *
18     * @return \Psr\Http\Message\ResponseInterface
19     */
20    #[\Override]
21    public function readResponse(
22        \Psr\Http\Message\RequestInterface $request,
23        \Psr\Http\Message\ResponseInterface $response,
24        array $args
25    ): \Psr\Http\Message\ResponseInterface {
26        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity();
27        if (!$workstation->getUseraccount()->hasPermissions(['dayoff'])) {
28            throw new UserAccountMissingRights();
29        }
30        $success = $request->getAttribute('validator')->getParameter('success')->isString()->getValue();
31        $year = Validator::value($args['year'])->isNumber()->getValue();
32        $collection = \App::$http->readGetResult('/dayoff/' . $year . '/')->getCollection();
33        $dayOffList = ($collection) ? array_values($collection->sortByCustomKey('date')->getArrayCopy()) : null;
34
35        $updated = false;
36        $input = $request->getParsedBody();
37        if (array_key_exists('save', (array) $input)) {
38            $data = (array_key_exists('dayoff', $input)) ? $input['dayoff'] : [];
39            $collection = (new DayoffList($data))->withTimestampFromDateformat();
40            \App::$http->readPostResult('/dayoff/' . $year . '/', $collection);
41            return \BO\Slim\Render::redirect('dayoffByYear', ['year' => $year], [
42                'success' => 'dayoff_saved'
43            ]);
44        }
45
46        return \BO\Slim\Render::withHtml(
47            $response,
48            'page/dayoffByYear.twig',
49            array(
50                'title' => 'Allgemein gültige Feiertage',
51                'year' => $year,
52                'updated' => $updated,
53                'menuActive' => 'dayoff',
54                'workstation' => $workstation,
55                'success' => $success,
56                'dayoffList' => $dayOffList
57            )
58        );
59    }
60}