Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
1.08% covered (danger)
1.08%
1 / 93
16.67% covered (danger)
16.67%
1 / 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
1.08% covered (danger)
1.08%
1 / 93
16.67% covered (danger)
16.67%
1 / 6
176.61
0.00% covered (danger)
0.00%
0 / 1
 hasAccess
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 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 / 71
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\Components\Common\OlzLocationMap\OlzLocationMap;
6use Olz\Components\Common\OlzRootComponent;
7use Olz\Components\Page\OlzFooter\OlzFooter;
8use Olz\Components\Page\OlzHeader\OlzHeader;
9use Olz\Entity\Termine\TerminLocation;
10use Olz\Utils\HttpParams;
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                on_off = '1'
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        ]);
76
77        // Creation Tools
78        $has_termine_permissions = $this->authUtils()->hasPermission('termine');
79        $creation_tools = '';
80        if ($has_termine_permissions) {
81            $creation_tools .= <<<ZZZZZZZZZZ
82                <div>
83                    <button
84                        id='create-termin-location-button'
85                        class='btn btn-secondary'
86                        onclick='return olz.initOlzEditTerminLocationModal()'
87                    >
88                        <img src='{$code_href}assets/icns/new_white_16.svg' class='noborder' />
89                        Neuen Ort hinzufügen
90                    </button>
91                </div>
92                ZZZZZZZZZZ;
93        }
94
95        $out .= <<<ZZZZZZZZZZ
96            <div class='content-right'>
97                <div style='padding:4px 3px 10px 3px;'>
98                    {$creation_tools}
99                    <p>
100                        <a href='{$code_href}termine/orte' class='linkint'>
101                            Alle Termin-Orte
102                        </a>
103                    </p>
104                </div>
105            </div>
106            <div class='content-middle'>
107            ZZZZZZZZZZ;
108
109        $name = $termin_location->getName();
110        $details = $termin_location->getDetails() ?? '';
111        $latitude = $termin_location->getLatitude();
112        $longitude = $termin_location->getLongitude();
113        $image_ids = $termin_location->getImageIds();
114
115        $out .= "<div class='olz-termin-location-detail'>";
116
117        // Editing Tools
118        $is_owner = $user && intval($termin_location->getOwnerUser()?->getId() ?? 0) === intval($user->getId());
119        $has_termine_permissions = $this->authUtils()->hasPermission('termine');
120        $can_edit = $is_owner || $has_termine_permissions;
121        if ($can_edit) {
122            $json_id = json_encode($id);
123            $out .= <<<ZZZZZZZZZZ
124                <div>
125                    <button
126                        id='edit-termin-location-button'
127                        class='btn btn-primary'
128                        onclick='return olz.editTerminLocation({$json_id})'
129                    >
130                        <img src='{$code_href}assets/icns/edit_white_16.svg' class='noborder' />
131                        Bearbeiten
132                    </button>
133                </div>
134                ZZZZZZZZZZ;
135        }
136
137        $out .= "<h1>{$name}</h1>";
138
139        $out .= OlzLocationMap::render([
140            'name' => $name,
141            'latitude' => $latitude,
142            'longitude' => $longitude,
143            'zoom' => 13,
144        ]);
145
146        $details_html = $this->htmlUtils()->renderMarkdown($details);
147        $details_html = $termin_location->replaceImagePaths($details_html);
148        $details_html = $termin_location->replaceFilePaths($details_html);
149        $out .= "<div>{$details_html}</div>";
150
151        if (count($image_ids) > 0) {
152            $out .= "<h3>Bilder</h3><div class='lightgallery gallery-container'>";
153            foreach ($image_ids as $image_id) {
154                $out .= "<div class='gallery-image'>";
155                $out .= $this->imageUtils()->olzImage(
156                    'termin_locations',
157                    $id,
158                    $image_id,
159                    128,
160                    'gallery[myset]'
161                );
162                $out .= "</div>";
163            }
164            $out .= "</div>";
165        }
166
167        $out .= "</div>"; // olz-termin-location-detail
168        $out .= "</div>"; // content-middle
169
170        $out .= OlzFooter::render();
171
172        return $out;
173    }
174
175    protected function getTerminLocationById(int $id): ?TerminLocation {
176        $termin_location_repo = $this->entityManager()->getRepository(TerminLocation::class);
177        return $termin_location_repo->findOneBy([
178            'id' => $id,
179            'on_off' => 1,
180        ]);
181    }
182}