Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
2.44% covered (danger)
2.44%
1 / 41
20.00% covered (danger)
20.00%
1 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
OlzTerminLocationsListParams
n/a
0 / 0
n/a
0 / 0
0
n/a
0 / 0
OlzTerminLocationsList
2.44% covered (danger)
2.44%
1 / 41
20.00% covered (danger)
20.00%
1 / 5
28.21
0.00% covered (danger)
0.00%
0 / 1
 hasAccess
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 searchSqlWhenHasAccess
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 getPageTitle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPageDescription
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHtmlWhenHasAccess
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Olz\Termine\Components\OlzTerminLocationsList;
4
5use Olz\Common\Components\OlzFooter\OlzFooter;
6use Olz\Common\Components\OlzHeader\OlzHeader;
7use Olz\Common\Components\OlzRootComponent;
8use Olz\Common\Utils\HttpParams;
9use Olz\Entity\Termine\TerminLocation;
10
11/** @extends HttpParams<array{}> */
12class OlzTerminLocationsListParams extends HttpParams {
13}
14
15/** @extends OlzRootComponent<array<string, mixed>> */
16class OlzTerminLocationsList extends OlzRootComponent {
17    public function hasAccess(): bool {
18        return $this->authUtils()->hasPermission('termine');
19    }
20
21    public function searchSqlWhenHasAccess(array $terms): string|array|null {
22        $code_href = $this->envUtils()->getCodeHref();
23        return $this->searchUtils()->getStaticResultQuery([
24            'link' => "{$code_href}termine/orte",
25            'icon' => "{$code_href}assets/icns/link_map_16.svg",
26            'title' => $this->getPageTitle(),
27            'text' => $this->getPageDescription(),
28        ], $terms);
29    }
30
31    public function getPageTitle(): string {
32        return "Termin-Orte";
33    }
34
35    public function getPageDescription(): string {
36        return "Orte, die oft für Termine verwendet werden (z.B. Besammlungsorte für Trainings).";
37    }
38
39    public function getHtmlWhenHasAccess(mixed $args): string {
40        $this->httpUtils()->validateGetParams(OlzTerminLocationsListParams::class);
41        $code_href = $this->envUtils()->getCodeHref();
42
43        $out = OlzHeader::render([
44            'back_link' => "{$code_href}termine",
45            'title' => 'Termin-Orte',
46            'description' => "Orte, an denen Anlässe der OL Zimmerberg stattfinden.",
47            'norobots' => true,
48            'auth_only' => true,
49        ]);
50
51        $creation_tools = <<<ZZZZZZZZZZ
52            <div class='create-termin-location-container'>
53                <button
54                    id='create-termin-location-button'
55                    class='btn btn-auth'
56                    onclick='return olz.initOlzEditTerminLocationModal()'
57                >
58                    <img src='{$code_href}assets/icns/new_16.svg' class='noborder' />
59                    Neuen Ort hinzufügen
60                </button>
61            </div>
62            ZZZZZZZZZZ;
63
64        $termin_location_repo = $this->entityManager()->getRepository(TerminLocation::class);
65        $termin_locations = $termin_location_repo->findBy(['deleted_at' => null]);
66        $locations_data = array_map(function (TerminLocation $termin_location) use ($code_href) {
67            return [
68                'url' => "{$code_href}termine/orte/{$termin_location->getId()}",
69                'name' => $termin_location->getName(),
70                'lat' => $termin_location->getLatitude(),
71                'lng' => $termin_location->getLongitude(),
72            ];
73        }, $termin_locations);
74        $locations_json = json_encode($locations_data);
75
76        $out .= <<<ZZZZZZZZZZ
77            <div class='content-full'>
78                {$creation_tools}
79                <h1>Termin-Orte</h1>
80                <div id='olz-termin-locations-map' class='test-flaky'></div>
81                <script>olz.olzTerminLocationsMapRender({$locations_json});</script>
82            </div>
83            ZZZZZZZZZZ;
84
85        $out .= OlzFooter::render();
86
87        return $out;
88    }
89}