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