Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.67% covered (success)
96.67%
29 / 30
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
DayoffByYear
96.67% covered (success)
96.67%
29 / 30
0.00% covered (danger)
0.00%
0 / 1
5
0.00% covered (danger)
0.00%
0 / 1
 readResponse
96.67% covered (success)
96.67%
29 / 30
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            $collection->testUniqueDates();
41            \App::$http->readPostResult('/dayoff/' . $year . '/', $collection)->getCollection();
42            return \BO\Slim\Render::redirect('dayoffByYear', ['year' => $year], [
43                'success' => 'dayoff_saved'
44            ]);
45        }
46
47        return \BO\Slim\Render::withHtml(
48            $response,
49            'page/dayoffByYear.twig',
50            array(
51                'title' => 'Allgemein gültige Feiertage',
52                'year' => $year,
53                'updated' => $updated,
54                'menuActive' => 'dayoff',
55                'workstation' => $workstation,
56                'success' => $success,
57                'dayoffList' => $dayOffList
58            )
59        );
60    }
61}