Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
OlzWeeklyPictureTile | |
0.00% |
0 / 39 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
getRelevance | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHtml | |
0.00% |
0 / 38 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | // ============================================================================= |
4 | // Zeigt eine Startseiten-Kachel mit dem Bild der Woche an. |
5 | // ============================================================================= |
6 | |
7 | namespace Olz\Startseite\Components\OlzWeeklyPictureTile; |
8 | |
9 | use Olz\Entity\Startseite\WeeklyPicture; |
10 | use Olz\Entity\Users\User; |
11 | use Olz\Startseite\Components\AbstractOlzTile\AbstractOlzTile; |
12 | |
13 | class OlzWeeklyPictureTile extends AbstractOlzTile { |
14 | public function getRelevance(?User $user): float { |
15 | return 0.9; |
16 | } |
17 | |
18 | public function getHtml(mixed $args): string { |
19 | $out = ""; |
20 | |
21 | $has_access = $this->authUtils()->hasPermission('weekly_picture'); |
22 | $code_href = $this->envUtils()->getCodeHref(); |
23 | |
24 | $add_new_html = ''; |
25 | if ($has_access) { |
26 | $add_new_html .= <<<ZZZZZZZZZZ |
27 | <a |
28 | href='#' |
29 | id='create-weekly-picture-button' |
30 | class='header-link' |
31 | onclick='return olz.initOlzEditWeeklyPictureModal()' |
32 | > |
33 | <img |
34 | src='{$code_href}assets/icns/new_white_16.svg' |
35 | alt='+' |
36 | class='header-link-icon' |
37 | title='Neues Bild der Woche' |
38 | /> |
39 | </a> |
40 | ZZZZZZZZZZ; |
41 | } |
42 | |
43 | $entity_manager = $this->dbUtils()->getEntityManager(); |
44 | |
45 | $weekly_picture_repo = $entity_manager->getRepository(WeeklyPicture::class); |
46 | $latest_weekly_pictures = $weekly_picture_repo->getLatestThree(); |
47 | $index = 0; |
48 | $carousel_inner = ''; |
49 | foreach ($latest_weekly_pictures as $weekly_picture) { |
50 | $text = $weekly_picture->getText(); |
51 | $id = $weekly_picture->getId(); |
52 | $image_id = $weekly_picture->getImageId(); |
53 | |
54 | $edit_html = ''; |
55 | if ($has_access) { |
56 | $enc_id = json_encode($id); |
57 | $edit_html .= <<<ZZZZZZZZZZ |
58 | <a |
59 | href='#' |
60 | id='edit-weekly-picture-{$id}-button' |
61 | class='header-link' |
62 | onclick='return olz.editWeeklyPicture({$enc_id})' |
63 | > |
64 | <img |
65 | src='{$code_href}assets/icns/edit_white_16.svg' |
66 | alt='E' |
67 | class='header-link-icon' |
68 | title='Bild der Woche bearbeiten' |
69 | /> |
70 | </a> |
71 | ZZZZZZZZZZ; |
72 | } |
73 | |
74 | $active_class = $index === 0 ? ' active' : ''; |
75 | $carousel_inner .= "<div class='carousel-item{$active_class}'>"; |
76 | $carousel_inner .= $this->imageUtils()->olzImage('weekly_picture', $id, $image_id, 512, 'image'); |
77 | $carousel_inner .= "<div class='weekly-picture-tile-text'>{$text} {$edit_html}</div>"; |
78 | $carousel_inner .= "</div>"; |
79 | $index++; |
80 | } |
81 | |
82 | $out .= <<<ZZZZZZZZZZ |
83 | <h3 class='weekly-picture-h3'>Bild der Woche {$add_new_html}</h3> |
84 | <div |
85 | id='weekly-picture-carousel' |
86 | class='carousel slide' |
87 | data-bs-ride='carousel' |
88 | data-bs-interval='3600000' |
89 | data-bs-wrap='false' |
90 | > |
91 | <div class='carousel-inner'>{$carousel_inner}</div> |
92 | <button |
93 | class="carousel-control-prev" |
94 | data-bs-target="#weekly-picture-carousel" |
95 | data-bs-slide="prev" |
96 | > |
97 | <span class="carousel-control-prev-icon" aria-hidden="true"></span> |
98 | </button> |
99 | <button |
100 | class="carousel-control-next" |
101 | data-bs-target="#weekly-picture-carousel" |
102 | data-bs-slide="next" |
103 | > |
104 | <span class="carousel-control-next-icon" aria-hidden="true"></span> |
105 | </button> |
106 | </div> |
107 | ZZZZZZZZZZ; |
108 | |
109 | return $out; |
110 | } |
111 | } |