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