Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
2.50% covered (danger)
2.50%
1 / 40
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.50% covered (danger)
2.50%
1 / 40
20.00% covered (danger)
20.00%
1 / 5
28.17
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 / 30
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Olz\Termine\Components\OlzTerminLocationsList;
4
5use Olz\Components\Common\OlzRootComponent;
6use Olz\Components\Page\OlzFooter\OlzFooter;
7use Olz\Components\Page\OlzHeader\OlzHeader;
8use Olz\Entity\Termine\TerminLocation;
9use Olz\Utils\HttpParams;
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        ]);
49
50        $creation_tools = <<<ZZZZZZZZZZ
51            <div class='create-termin-location-container'>
52                <button
53                    id='create-termin-location-button'
54                    class='btn btn-secondary'
55                    onclick='return olz.initOlzEditTerminLocationModal()'
56                >
57                    <img src='{$code_href}assets/icns/new_white_16.svg' class='noborder' />
58                    Neuen Ort hinzufügen
59                </button>
60            </div>
61            ZZZZZZZZZZ;
62
63        $termin_location_repo = $this->entityManager()->getRepository(TerminLocation::class);
64        $termin_locations = $termin_location_repo->findBy(['on_off' => 1]);
65        $locations_data = array_map(function (TerminLocation $termin_location) use ($code_href) {
66            return [
67                'url' => "{$code_href}termine/orte/{$termin_location->getId()}",
68                'name' => $termin_location->getName(),
69                'lat' => $termin_location->getLatitude(),
70                'lng' => $termin_location->getLongitude(),
71            ];
72        }, $termin_locations);
73        $locations_json = json_encode($locations_data);
74
75        $out .= <<<ZZZZZZZZZZ
76            <div class='content-full'>
77                {$creation_tools}
78                <h1>Termin-Orte</h1>
79                <div id='olz-termin-locations-map' class='test-flaky'></div>
80                <script>olz.olzTerminLocationsMapRender({$locations_json});</script>
81            </div>
82            ZZZZZZZZZZ;
83
84        $out .= OlzFooter::render();
85
86        return $out;
87    }
88}