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