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 as Collection;
11use BO\Mellon\Validator;
12
13class DayoffByYear extends BaseController
14{
15    /**
16     *
17     * @return \Psr\Http\Message\ResponseInterface
18     */
19    #[\Override]
20    public function readResponse(
21        \Psr\Http\Message\RequestInterface $request,
22        \Psr\Http\Message\ResponseInterface $response,
23        array $args
24    ): \Psr\Http\Message\ResponseInterface {
25        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity();
26        if (!$workstation->getUseraccount()->hasPermissions(['dayoff'])) {
27            throw new \BO\Zmsentities\Exception\UserAccountMissingRights();
28        }
29        $success = $request->getAttribute('validator')->getParameter('success')->isString()->getValue();
30        $year = Validator::value($args['year'])->isNumber()->getValue();
31        $collection = \App::$http->readGetResult('/dayoff/' . $year . '/')->getCollection();
32        $dayOffList = ($collection) ? array_values($collection->sortByCustomKey('date')->getArrayCopy()) : null;
33
34        $updated = false;
35        $input = $request->getParsedBody();
36        if (array_key_exists('save', (array) $input)) {
37            $data = (array_key_exists('dayoff', $input)) ? $input['dayoff'] : [];
38            $collection = (new Collection($data))->withTimestampFromDateformat();
39            \App::$http->readPostResult('/dayoff/' . $year . '/', $collection);
40            return \BO\Slim\Render::redirect('dayoffByYear', ['year' => $year], [
41                'success' => 'dayoff_saved'
42            ]);
43        }
44
45        return \BO\Slim\Render::withHtml(
46            $response,
47            'page/dayoffByYear.twig',
48            array(
49                'title' => 'Allgemein gültige Feiertage',
50                'year' => $year,
51                'updated' => $updated,
52                'menuActive' => 'dayoff',
53                'workstation' => $workstation,
54                'success' => $success,
55                'dayoffList' => $dayOffList
56            )
57        );
58    }
59}