Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 100 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
OlzTerminTemplateDetailParams | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | n/a |
0 / 0 |
|||
OlzTerminTemplateDetail | |
0.00% |
0 / 100 |
|
0.00% |
0 / 4 |
342 | |
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 / 93 |
|
0.00% |
0 / 1 |
240 | |||
getTerminTemplateById | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Olz\Termine\Components\OlzTerminTemplateDetail; |
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\TerminLabel; |
10 | use Olz\Entity\Termine\TerminTemplate; |
11 | use Olz\Utils\HttpParams; |
12 | |
13 | /** @extends HttpParams<array{filter?: ?string}> */ |
14 | class OlzTerminTemplateDetailParams extends HttpParams { |
15 | } |
16 | |
17 | /** @extends OlzRootComponent<array<string, mixed>> */ |
18 | class OlzTerminTemplateDetail extends OlzRootComponent { |
19 | public function getSearchTitle(): string { |
20 | return 'TODO'; |
21 | } |
22 | |
23 | public function getSearchResults(array $terms): array { |
24 | return []; |
25 | } |
26 | |
27 | public function getHtml(mixed $args): string { |
28 | $this->httpUtils()->validateGetParams(OlzTerminTemplateDetailParams::class); |
29 | |
30 | $code_href = $this->envUtils()->getCodeHref(); |
31 | $code_path = $this->envUtils()->getCodePath(); |
32 | $user = $this->authUtils()->getCurrentUser(); |
33 | $id = $args['id'] ?? null; |
34 | |
35 | $termin_template = $this->getTerminTemplateById($id); |
36 | |
37 | if (!$termin_template) { |
38 | $this->httpUtils()->dieWithHttpError(404); |
39 | throw new \Exception('should already have failed'); |
40 | } |
41 | |
42 | $title = $termin_template->getTitle() ?? ''; |
43 | $back_link = "{$code_href}termine/vorlagen"; |
44 | $out = OlzHeader::render([ |
45 | 'back_link' => $back_link, |
46 | 'title' => "{$title} - Vorlagen", |
47 | 'description' => "Vorlagen, um OL Zimmerberg-Termine zu erstellen.", |
48 | 'norobots' => true, |
49 | ]); |
50 | |
51 | // Creation Tools |
52 | $has_termine_permissions = $this->authUtils()->hasPermission('termine'); |
53 | $creation_tools = ''; |
54 | if ($has_termine_permissions) { |
55 | $esc_template_id = json_encode($id); |
56 | $creation_tools .= <<<ZZZZZZZZZZ |
57 | <div> |
58 | <button |
59 | id='create-termin-template-button' |
60 | class='btn btn-secondary' |
61 | onclick='return olz.initOlzEditTerminModal(undefined, {$esc_template_id})' |
62 | > |
63 | <img src='{$code_href}assets/icns/new_white_16.svg' class='noborder' /> |
64 | Neuer Termin aus dieser Vorlage |
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 | </div> |
75 | </div> |
76 | <div class='content-middle'> |
77 | ZZZZZZZZZZ; |
78 | |
79 | $start_time = $termin_template->getStartTime() ?? ''; |
80 | $duration_seconds = $termin_template->getDurationSeconds() ?? ''; |
81 | $title = $termin_template->getTitle() ?? ''; |
82 | $text = $termin_template->getText() ?? ''; |
83 | $labels = [...$termin_template->getLabels()]; |
84 | $termin_location = $termin_template->getLocation(); |
85 | $image_ids = $termin_template->getImageIds(); |
86 | |
87 | $out .= "<div class='olz-termin-template-detail'>"; |
88 | |
89 | // Editing Tools |
90 | $is_owner = $user && intval($termin_template->getOwnerUser()?->getId() ?? 0) === intval($user->getId()); |
91 | $has_termine_permissions = $this->authUtils()->hasPermission('termine'); |
92 | $can_edit = $is_owner || $has_termine_permissions; |
93 | if ($can_edit) { |
94 | $json_id = json_encode($id); |
95 | $out .= <<<ZZZZZZZZZZ |
96 | <div> |
97 | <button |
98 | id='edit-termin-template-button' |
99 | class='btn btn-primary' |
100 | onclick='return olz.editTerminTemplate({$json_id})' |
101 | > |
102 | <img src='{$code_href}assets/icns/edit_white_16.svg' class='noborder' /> |
103 | Bearbeiten |
104 | </button> |
105 | </div> |
106 | ZZZZZZZZZZ; |
107 | } |
108 | |
109 | $pretty_date = '(irgendwann)'; |
110 | $duration_interval = \DateInterval::createFromDateString("+{$duration_seconds} seconds"); |
111 | if ($start_time && $duration_interval) { |
112 | $end_time = (clone $start_time)->add($duration_interval); |
113 | $pretty_date = $duration_seconds |
114 | ? $start_time->format('H:i')." – ".$end_time->format('H:i') |
115 | : $start_time->format('H:i'); |
116 | } |
117 | $label_imgs = implode('', array_map(function (TerminLabel $label) use ($code_path, $code_href) { |
118 | $ident = $label->getIdent(); |
119 | // TODO: Remove fallback mechanism? |
120 | $fallback_path = "{$code_path}assets/icns/termine_type_{$ident}_20.svg"; |
121 | $fallback_href = is_file($fallback_path) |
122 | ? "{$code_href}assets/icns/termine_type_{$ident}_20.svg" : null; |
123 | $icon_href = $label->getIcon() ? $label->getFileHref($label->getIcon()) : $fallback_href; |
124 | return $icon_href ? "<img src='{$icon_href}' alt='' class='type-icon'>" : ''; |
125 | }, $labels)); |
126 | |
127 | $out .= "<h5>{$pretty_date}</h5>"; |
128 | $out .= "<h1>{$title} {$label_imgs}</h1>"; |
129 | |
130 | if ($termin_location) { |
131 | $out .= OlzLocationMap::render([ |
132 | 'name' => $termin_location->getName(), |
133 | 'latitude' => $termin_location->getLatitude(), |
134 | 'longitude' => $termin_location->getLongitude(), |
135 | 'zoom' => 13, |
136 | ]); |
137 | } |
138 | |
139 | $text_html = $this->htmlUtils()->renderMarkdown($text); |
140 | $text_html = $termin_template->replaceImagePaths($text_html); |
141 | $text_html = $termin_template->replaceFilePaths($text_html); |
142 | $out .= "<div>{$text_html}</div>"; |
143 | |
144 | if (count($image_ids) > 0) { |
145 | $out .= "<h3>Bilder</h3><div class='lightgallery gallery-container'>"; |
146 | foreach ($image_ids as $image_id) { |
147 | $out .= "<div class='gallery-image'>"; |
148 | $out .= $this->imageUtils()->olzImage( |
149 | 'termin_templates', |
150 | $id, |
151 | $image_id, |
152 | 110, |
153 | 'gallery[myset]' |
154 | ); |
155 | $out .= "</div>"; |
156 | } |
157 | $out .= "</div>"; |
158 | } |
159 | |
160 | $out .= "</div>"; // olz-termin-location-detail |
161 | $out .= "</div>"; // content-middle |
162 | |
163 | $out .= OlzFooter::render(); |
164 | |
165 | return $out; |
166 | } |
167 | |
168 | protected function getTerminTemplateById(int $id): ?TerminTemplate { |
169 | $termin_template_repo = $this->entityManager()->getRepository(TerminTemplate::class); |
170 | return $termin_template_repo->findOneBy([ |
171 | 'id' => $id, |
172 | 'on_off' => 1, |
173 | ]); |
174 | } |
175 | } |