Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 94
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
OlzTerminLocationDetailParams
n/a
0 / 0
n/a
0 / 0
0
n/a
0 / 0
OlzTerminLocationDetail
0.00% covered (danger)
0.00%
0 / 94
0.00% covered (danger)
0.00%
0 / 6
182
0.00% covered (danger)
0.00%
0 / 1
 hasAccess
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 searchSqlWhenHasAccess
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
 getPageTitle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPageDescription
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHtmlWhenHasAccess
0.00% covered (danger)
0.00%
0 / 72
0.00% covered (danger)
0.00%
0 / 1
72
 getTerminLocationById
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Olz\Termine\Components\OlzTerminLocationDetail;
4
5use Olz\Common\Components\OlzFooter\OlzFooter;
6use Olz\Common\Components\OlzHeader\OlzHeader;
7use Olz\Common\Components\OlzLocationMap\OlzLocationMap;
8use Olz\Common\Components\OlzRootComponent;
9use Olz\Common\Utils\HttpParams;
10use Olz\Entity\Termine\TerminLocation;
11
12/** @extends HttpParams<array{}> */
13class OlzTerminLocationDetailParams extends HttpParams {
14}
15
16/** @extends OlzRootComponent<array<string, mixed>> */
17class 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                deleted_at IS NULL
43                AND {$where}
44            ZZZZZZZZZZ;
45    }
46
47    public function getPageTitle(): string {
48        return "";
49    }
50
51    public function getPageDescription(): string {
52        return "";
53    }
54
55    public function getHtmlWhenHasAccess(mixed $args): string {
56        $this->httpUtils()->validateGetParams(OlzTerminLocationDetailParams::class);
57
58        $code_href = $this->envUtils()->getCodeHref();
59        $user = $this->authUtils()->getCurrentUser();
60        $id = $args['id'] ?? null;
61
62        $termin_location = $this->getTerminLocationById($id);
63
64        if (!$termin_location) {
65            $this->httpUtils()->dieWithHttpError(404);
66            throw new \Exception('should already have failed');
67        }
68
69        $title = $termin_location->getName();
70        $out = OlzHeader::render([
71            'back_link' => "{$code_href}termine/orte",
72            'title' => "{$title} - Orte",
73            'description' => "Orte, an denen Anlässe der OL Zimmerberg stattfinden.",
74            'norobots' => true,
75            'auth_only' => true,
76        ]);
77
78        // Creation Tools
79        $has_termine_permissions = $this->authUtils()->hasPermission('termine');
80        $creation_tools = '';
81        if ($has_termine_permissions) {
82            $creation_tools .= <<<ZZZZZZZZZZ
83                <div>
84                    <button
85                        id='create-termin-location-button'
86                        class='btn btn-auth'
87                        onclick='return olz.initOlzEditTerminLocationModal()'
88                    >
89                        <img src='{$code_href}assets/icns/new_16.svg' class='noborder' />
90                        Neuen Ort hinzufügen
91                    </button>
92                </div>
93                ZZZZZZZZZZ;
94        }
95
96        $out .= <<<ZZZZZZZZZZ
97            <div class='content-right'>
98                <div style='padding:4px 3px 10px 3px;'>
99                    {$creation_tools}
100                    <p>
101                        <a href='{$code_href}termine/orte' class='linkint'>
102                            Alle Termin-Orte
103                        </a>
104                    </p>
105                </div>
106            </div>
107            <div class='content-middle'>
108            ZZZZZZZZZZ;
109
110        $name = $termin_location->getName();
111        $details = $termin_location->getDetails() ?? '';
112        $latitude = $termin_location->getLatitude();
113        $longitude = $termin_location->getLongitude();
114        $image_ids = $termin_location->getImageIds();
115
116        $out .= "<div class='olz-termin-location-detail'>";
117
118        // Editing Tools
119        $is_owner = $user && intval($termin_location->getOwnerUser()?->getId() ?? 0) === intval($user->getId());
120        $has_termine_permissions = $this->authUtils()->hasPermission('termine');
121        $can_edit = $is_owner || $has_termine_permissions;
122        if ($can_edit) {
123            $json_id = json_encode($id);
124            $out .= <<<ZZZZZZZZZZ
125                <div>
126                    <button
127                        id='edit-termin-location-button'
128                        class='btn btn-auth'
129                        onclick='return olz.editTerminLocation({$json_id})'
130                    >
131                        <img src='{$code_href}assets/icns/edit_16.svg' class='noborder' />
132                        Bearbeiten
133                    </button>
134                </div>
135                ZZZZZZZZZZ;
136        }
137
138        $out .= "<h1>{$name}</h1>";
139
140        $out .= OlzLocationMap::render([
141            'name' => $name,
142            'latitude' => $latitude,
143            'longitude' => $longitude,
144            'zoom' => 13,
145        ]);
146
147        $details_html = $this->htmlUtils()->renderMarkdown($details);
148        $details_html = $termin_location->replaceImagePaths($details_html);
149        $details_html = $termin_location->replaceFilePaths($details_html);
150        $out .= "<div>{$details_html}</div>";
151
152        if (count($image_ids) > 0) {
153            $out .= "<h3>Bilder</h3><div class='lightgallery gallery-container'>";
154            foreach ($image_ids as $image_id) {
155                $out .= "<div class='gallery-image'>";
156                $out .= $this->imageUtils()->olzImage(
157                    'termin_locations',
158                    $id,
159                    $image_id,
160                    128,
161                    'gallery[myset]'
162                );
163                $out .= "</div>";
164            }
165            $out .= "</div>";
166        }
167
168        $out .= "</div>"; // olz-termin-location-detail
169        $out .= "</div>"; // content-middle
170
171        $out .= OlzFooter::render();
172
173        return $out;
174    }
175
176    protected function getTerminLocationById(int $id): ?TerminLocation {
177        $termin_location_repo = $this->entityManager()->getRepository(TerminLocation::class);
178        return $termin_location_repo->findOneBy([
179            'id' => $id,
180            'deleted_at' => null,
181        ]);
182    }
183}