Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 51 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
OlzNewsGalerieTile | |
0.00% |
0 / 51 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
getRelevance | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHtml | |
0.00% |
0 / 50 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | // ============================================================================= |
4 | // Zeigt eine Startseiten-Kachel mit kürzlich veröffentlichten News an. |
5 | // ============================================================================= |
6 | |
7 | namespace Olz\Startseite\Components\OlzNewsGalerieTile; |
8 | |
9 | use Olz\Entity\News\NewsEntry; |
10 | use Olz\Entity\Users\User; |
11 | use Olz\News\Utils\NewsFilterUtils; |
12 | use Olz\Startseite\Components\AbstractOlzTile\AbstractOlzTile; |
13 | |
14 | class OlzNewsGalerieTile extends AbstractOlzTile { |
15 | /** @var array<string, string> */ |
16 | protected static $iconBasenameByFormat = [ |
17 | 'galerie' => 'entry_type_gallery_white_20.svg', |
18 | 'video' => 'entry_type_movie_white_20.svg', |
19 | ]; |
20 | |
21 | public function getRelevance(?User $user): float { |
22 | return 0.55; |
23 | } |
24 | |
25 | public function getHtml(mixed $args): string { |
26 | $entity_manager = $this->dbUtils()->getEntityManager(); |
27 | $code_href = $this->envUtils()->getCodeHref(); |
28 | $news_filter_utils = NewsFilterUtils::fromEnv(); |
29 | |
30 | $galerie_url = $news_filter_utils->getUrl(['format' => 'galerie']); |
31 | $video_url = $news_filter_utils->getUrl(['format' => 'video']); |
32 | $out = <<<ZZZZZZZZZZ |
33 | <h3> |
34 | <a href='{$galerie_url}&von=startseite'> |
35 | <img src='{$code_href}assets/icns/entry_type_gallery_20.svg' alt='Galerie' class='link-icon'> |
36 | Galerie |
37 | </a> |
38 | & |
39 | <a href='{$video_url}&von=startseite'> |
40 | <img src='{$code_href}assets/icns/entry_type_movie_20.svg' alt='Video' class='link-icon'> |
41 | Video |
42 | </a> |
43 | </h3> |
44 | ZZZZZZZZZZ; |
45 | |
46 | $out .= "<ul class='links'>"; |
47 | $news_entry_class = NewsEntry::class; |
48 | $query = $entity_manager->createQuery(<<<ZZZZZZZZZZ |
49 | SELECT n |
50 | FROM {$news_entry_class} n |
51 | WHERE n.on_off = '1' and n.format IN ('galerie', 'video') |
52 | ORDER BY n.published_date DESC, n.published_time DESC |
53 | ZZZZZZZZZZ); |
54 | $query->setMaxResults(3); |
55 | $index = 0; |
56 | foreach ($query->getResult() as $news_entry) { |
57 | $id = $news_entry->getId(); |
58 | $date = $this->dateUtils()->compactDate($news_entry->getPublishedDate()); |
59 | $title = $news_entry->getTitle(); |
60 | $format = $news_entry->getFormat(); |
61 | $image_ids = $news_entry->getImageIds(); |
62 | |
63 | $icon_basename = self::$iconBasenameByFormat[$format]; |
64 | $icon = "{$code_href}assets/icns/{$icon_basename}"; |
65 | $images = ""; |
66 | for ($i = 0; $i < min(count($image_ids), 3); $i++) { |
67 | $olz_image = $this->imageUtils()->olzImage( |
68 | 'news', |
69 | $id, |
70 | $image_ids[$i], |
71 | 80, |
72 | null, |
73 | ' class="noborder"' |
74 | ); |
75 | $images .= "{$olz_image}"; |
76 | } |
77 | |
78 | $out .= <<<ZZZZZZZZZZ |
79 | <li class='flex gallery min-two-lines'> |
80 | <a href='{$code_href}news/{$id}?von=startseite'> |
81 | <div class='overlay'> |
82 | <img src='{$icon}' alt='{$format}' class='link-icon'> |
83 | <span class='date'>{$date}</span> |
84 | <span class='title'>{$title}</span> |
85 | </div> |
86 | <div class='images'> |
87 | {$images} |
88 | </div> |
89 | </a> |
90 | </li> |
91 | ZZZZZZZZZZ; |
92 | |
93 | $index++; |
94 | } |
95 | $out .= "</ul>"; |
96 | |
97 | return $out; |
98 | } |
99 | } |