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