Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 92
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
OlzTerminLocationDetailParams
n/a
0 / 0
n/a
0 / 0
0
n/a
0 / 0
OlzTerminLocationDetail
0.00% covered (danger)
0.00%
0 / 92
0.00% covered (danger)
0.00%
0 / 5
240
0.00% covered (danger)
0.00%
0 / 1
 hasAccess
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSearchTitle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSearchResultsWhenHasAccess
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
20
 getHtmlWhenHasAccess
0.00% covered (danger)
0.00%
0 / 71
0.00% covered (danger)
0.00%
0 / 1
72
 getTerminLocationById
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Olz\Termine\Components\OlzTerminLocationDetail;
4
5use Olz\Components\Common\OlzLocationMap\OlzLocationMap;
6use Olz\Components\Common\OlzRootComponent;
7use Olz\Components\Page\OlzFooter\OlzFooter;
8use Olz\Components\Page\OlzHeader\OlzHeader;
9use Olz\Entity\Termine\TerminLocation;
10use Olz\Utils\HttpParams;
11
12/** @extends HttpParams<array{}> */
13class OlzTerminLocationDetailParams extends HttpParams {
14}
15
16/** @extends OlzRootComponent<array<string, mixed>> */
17class OlzTerminLocationDetail extends OlzRootComponent {
18    public function hasAccess(): bool {
19        return $this->authUtils()->hasPermission('termine');
20    }
21
22    public function getSearchTitle(): string {
23        return 'Termin-Orte';
24    }
25
26    public function getSearchResultsWhenHasAccess(array $terms): array {
27        $results = [];
28        $code_href = $this->envUtils()->getCodeHref();
29        $termin_location_repo = $this->entityManager()->getRepository(TerminLocation::class);
30        $termin_locations = $termin_location_repo->search($terms);
31        foreach ($termin_locations as $termin_location) {
32            $id = $termin_location->getId();
33            $results[] = $this->searchUtils()->getScoredSearchResult([
34                'link' => "{$code_href}termine/orte/{$id}",
35                'icon' => "{$code_href}assets/icns/link_map_16.svg",
36                'date' => null,
37                'title' => $termin_location->getName() ?: '?',
38                'text' => strip_tags("{$termin_location->getDetails()}") ?: null,
39            ], $terms);
40        }
41        return $results;
42    }
43
44    public function getHtmlWhenHasAccess(mixed $args): string {
45        $this->httpUtils()->validateGetParams(OlzTerminLocationDetailParams::class);
46
47        $code_href = $this->envUtils()->getCodeHref();
48        $user = $this->authUtils()->getCurrentUser();
49        $id = $args['id'] ?? null;
50
51        $termin_location = $this->getTerminLocationById($id);
52
53        if (!$termin_location) {
54            $this->httpUtils()->dieWithHttpError(404);
55            throw new \Exception('should already have failed');
56        }
57
58        $title = $termin_location->getName();
59        $out = OlzHeader::render([
60            'back_link' => "{$code_href}termine/orte",
61            'title' => "{$title} - Orte",
62            'description' => "Orte, an denen Anlässe der OL Zimmerberg stattfinden.",
63            'norobots' => true,
64        ]);
65
66        // Creation Tools
67        $has_termine_permissions = $this->authUtils()->hasPermission('termine');
68        $creation_tools = '';
69        if ($has_termine_permissions) {
70            $creation_tools .= <<<ZZZZZZZZZZ
71                <div>
72                    <button
73                        id='create-termin-location-button'
74                        class='btn btn-secondary'
75                        onclick='return olz.initOlzEditTerminLocationModal()'
76                    >
77                        <img src='{$code_href}assets/icns/new_white_16.svg' class='noborder' />
78                        Neuen Ort hinzufügen
79                    </button>
80                </div>
81                ZZZZZZZZZZ;
82        }
83
84        $out .= <<<ZZZZZZZZZZ
85            <div class='content-right'>
86                <div style='padding:4px 3px 10px 3px;'>
87                    {$creation_tools}
88                    <p>
89                        <a href='{$code_href}termine/orte' class='linkint'>
90                            Alle Termin-Orte
91                        </a>
92                    </p>
93                </div>
94            </div>
95            <div class='content-middle'>
96            ZZZZZZZZZZ;
97
98        $name = $termin_location->getName();
99        $details = $termin_location->getDetails() ?? '';
100        $latitude = $termin_location->getLatitude();
101        $longitude = $termin_location->getLongitude();
102        $image_ids = $termin_location->getImageIds();
103
104        $out .= "<div class='olz-termin-location-detail'>";
105
106        // Editing Tools
107        $is_owner = $user && intval($termin_location->getOwnerUser()?->getId() ?? 0) === intval($user->getId());
108        $has_termine_permissions = $this->authUtils()->hasPermission('termine');
109        $can_edit = $is_owner || $has_termine_permissions;
110        if ($can_edit) {
111            $json_id = json_encode($id);
112            $out .= <<<ZZZZZZZZZZ
113                <div>
114                    <button
115                        id='edit-termin-location-button'
116                        class='btn btn-primary'
117                        onclick='return olz.editTerminLocation({$json_id})'
118                    >
119                        <img src='{$code_href}assets/icns/edit_white_16.svg' class='noborder' />
120                        Bearbeiten
121                    </button>
122                </div>
123                ZZZZZZZZZZ;
124        }
125
126        $out .= "<h1>{$name}</h1>";
127
128        $out .= OlzLocationMap::render([
129            'name' => $name,
130            'latitude' => $latitude,
131            'longitude' => $longitude,
132            'zoom' => 13,
133        ]);
134
135        $details_html = $this->htmlUtils()->renderMarkdown($details);
136        $details_html = $termin_location->replaceImagePaths($details_html);
137        $details_html = $termin_location->replaceFilePaths($details_html);
138        $out .= "<div>{$details_html}</div>";
139
140        if (count($image_ids) > 0) {
141            $out .= "<h3>Bilder</h3><div class='lightgallery gallery-container'>";
142            foreach ($image_ids as $image_id) {
143                $out .= "<div class='gallery-image'>";
144                $out .= $this->imageUtils()->olzImage(
145                    'termin_locations',
146                    $id,
147                    $image_id,
148                    110,
149                    'gallery[myset]'
150                );
151                $out .= "</div>";
152            }
153            $out .= "</div>";
154        }
155
156        $out .= "</div>"; // olz-termin-location-detail
157        $out .= "</div>"; // content-middle
158
159        $out .= OlzFooter::render();
160
161        return $out;
162    }
163
164    protected function getTerminLocationById(int $id): ?TerminLocation {
165        $termin_location_repo = $this->entityManager()->getRepository(TerminLocation::class);
166        return $termin_location_repo->findOneBy([
167            'id' => $id,
168            'on_off' => 1,
169        ]);
170    }
171}