Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 59 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
OlzNewsAktuellKaderblogTile | |
0.00% |
0 / 59 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
getRelevance | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHtml | |
0.00% |
0 / 58 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | // ============================================================================= |
4 | // Zeigt eine Startseiten-Kachel mit kürzlich veröffentlichten News an. |
5 | // ============================================================================= |
6 | |
7 | namespace Olz\Startseite\Components\OlzNewsAktuellKaderblogTile; |
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 OlzNewsAktuellKaderblogTile extends AbstractOlzTile { |
15 | /** @var array<string, string> */ |
16 | protected static $iconBasenameByFormat = [ |
17 | 'aktuell' => 'entry_type_aktuell_20.svg', |
18 | 'kaderblog' => 'entry_type_kaderblog_20.svg', |
19 | ]; |
20 | |
21 | public function getRelevance(?User $user): float { |
22 | return 0.65; |
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 | $aktuell_url = $news_filter_utils->getUrl(['format' => 'aktuell']); |
31 | $kaderblog_url = $news_filter_utils->getUrl(['format' => 'kaderblog']); |
32 | $out = <<<ZZZZZZZZZZ |
33 | <h3> |
34 | <a href='{$aktuell_url}&von=startseite'> |
35 | <img src='{$code_href}assets/icns/entry_type_aktuell_20.svg' alt='Aktuell' class='link-icon'> |
36 | Aktuell |
37 | </a> |
38 | & |
39 | <a href='{$kaderblog_url}&von=startseite'> |
40 | <img src='{$code_href}assets/icns/entry_type_kaderblog_20.svg' alt='Kaderblog' class='link-icon'> |
41 | Kaderblog |
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 ('aktuell', 'kaderblog') |
52 | ORDER BY n.published_date DESC, n.published_time DESC |
53 | ZZZZZZZZZZ); |
54 | $query->setMaxResults(4); |
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 | $image = ''; |
66 | $is_image_right = ($index % 2) === 0; |
67 | if (count($image_ids) > 0) { |
68 | $class = $is_image_right ? 'right' : 'left'; |
69 | $olz_image = $this->imageUtils()->olzImage( |
70 | 'news', |
71 | $id, |
72 | $image_ids[0] ?? null, |
73 | 80, |
74 | null, |
75 | ' class="noborder"' |
76 | ); |
77 | $image = "<div class='link-image-{$class}'>{$olz_image}</div>"; |
78 | } |
79 | $image_left = ''; |
80 | $image_right = ''; |
81 | if ($is_image_right) { |
82 | $image_right = $image; |
83 | } else { |
84 | $image_left = $image; |
85 | } |
86 | |
87 | $out .= <<<ZZZZZZZZZZ |
88 | <li> |
89 | <a href='{$code_href}news/{$id}?von=startseite' class='flex min-two-lines aktuell-kaderblog-tile'> |
90 | {$image_left} |
91 | <img src='{$icon}' alt='{$format}' class='link-icon'> |
92 | <div style='flex-grow:1;'> |
93 | <span class='title'>{$title}</span> |
94 | <span class='secondary'>({$date})</span> |
95 | </div> |
96 | {$image_right} |
97 | </a> |
98 | </li> |
99 | ZZZZZZZZZZ; |
100 | |
101 | $index++; |
102 | } |
103 | $out .= "</ul>"; |
104 | |
105 | return $out; |
106 | } |
107 | } |