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