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