Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
56 / 56
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DesignController
100.00% covered (success)
100.00%
56 / 56
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 index
100.00% covered (success)
100.00%
55 / 55
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Controllers;
6
7use Carbon\CarbonImmutable;
8use DateInterval;
9use DateTimeImmutable;
10use Engelsystem\Config\Config;
11use Engelsystem\Helpers\BarChart;
12use Engelsystem\Http\Response;
13use Engelsystem\Models\User\PersonalData;
14use Engelsystem\Models\User\State;
15use Engelsystem\Models\User\User;
16
17class DesignController extends BaseController
18{
19    public function __construct(protected Response $response, protected Config $config)
20    {
21    }
22
23    /**
24     * Show the design overview page
25     */
26    public function index(): Response
27    {
28        $demoUser = (new User())->forceFill([
29            'id'   => 42,
30            'name' => 'test',
31        ]);
32        $demoUser->__set('state', (new State())->forceFill([
33            'user_id' => 42,
34            'arrived' => true,
35        ]));
36        $demoUser2 = (new User())->forceFill([
37            'id'   => 1337,
38            'name' => 'test2',
39        ]);
40        $demoUser2->__set('state', (new State())->forceFill([
41            'user_id' => 1337,
42            'arrived' => false,
43        ]));
44        $demoUser2->__set('personalData', (new PersonalData())->forceFill([
45            'pronoun' => 'it/its',
46        ]));
47
48        $selectOptions = [];
49
50        for ($i = 1; $i <= 50; $i++) {
51            $selectOptions['option_' . $i] = 'Option ' . $i;
52        }
53
54        $dateSelectOptions = [];
55        $date = CarbonImmutable::now();
56
57        for ($i = 1; $i <= 600; $i++) {
58            $dateKey = $date->format('Y-m-d');
59            $formattedDisplayDate = $date->format(__('general.date'));
60            $dateSelectOptions[$dateKey] = $formattedDisplayDate;
61            $date = $date->addDay();
62        }
63
64        $themes = $this->config->get('themes');
65        $date = new DateTimeImmutable();
66        $data = [
67            'demo_user'         => $demoUser,
68            'demo_user_2'       => $demoUser2,
69            'themes'            => $themes,
70            'bar_chart'         => BarChart::render(...BarChart::generateChartDemoData(23)),
71
72            'timestamp30m'      => $date->add(new DateInterval('PT30M')),
73            'timestamp59m'      => $date->add(new DateInterval('PT59M')),
74            'timestamp1h'       => $date->add(new DateInterval('PT1H')),
75            'timestamp1h30m'    => $date->add(new DateInterval('PT1H30M')),
76            'timestamp1h31m'    => $date->add(new DateInterval('PT1H31M')),
77            'timestamp2h'       => $date->add(new DateInterval('PT2H')),
78            'timestamp2d'       => $date->add(new DateInterval('P2D')),
79            'timestamp3m'       => $date->add(new DateInterval('P3M')),
80            'timestamp22y'      => $date->add(new DateInterval('P22Y')),
81            'timestamp30s'      => $date->add(new DateInterval('PT30S')),
82
83            'timestamp30mago'   => $date->sub(new DateInterval('PT30M')),
84            'timestamp45mago'   => $date->sub(new DateInterval('PT45M')),
85            'selectOptions'     => $selectOptions,
86            'dateSelectOptions' => $dateSelectOptions,
87        ];
88
89        return $this->response->withView(
90            'pages/design',
91            $data
92        );
93    }
94}