Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 55 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
OlzNewsForumTile | |
0.00% |
0 / 55 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
getRelevance | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHtml | |
0.00% |
0 / 54 |
|
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\OlzNewsForumTile; |
8 | |
9 | use Olz\Entity\News\NewsEntry; |
10 | use Olz\Entity\Users\User; |
11 | use Olz\Startseite\Components\AbstractOlzTile\AbstractOlzTile; |
12 | |
13 | class OlzNewsForumTile extends AbstractOlzTile { |
14 | public function getRelevance(?User $user): float { |
15 | return 0.6; |
16 | } |
17 | |
18 | public function getHtml(mixed $args): string { |
19 | $entity_manager = $this->dbUtils()->getEntityManager(); |
20 | $code_href = $this->envUtils()->getCodeHref(); |
21 | $news_utils = $this->newsUtils(); |
22 | |
23 | $forum_url = $news_utils->getUrl(['format' => 'forum']); |
24 | |
25 | $out = <<<ZZZZZZZZZZ |
26 | <h3> |
27 | <a href='{$forum_url}&von=startseite'> |
28 | <img src='{$code_href}assets/icns/entry_type_forum_20.svg' alt='Forum' class='link-icon'> |
29 | Forum |
30 | </a> |
31 | </h3> |
32 | ZZZZZZZZZZ; |
33 | |
34 | $out .= "<ul class='links'>"; |
35 | $news_entry_class = NewsEntry::class; |
36 | $query = $entity_manager->createQuery(<<<ZZZZZZZZZZ |
37 | SELECT n |
38 | FROM {$news_entry_class} n |
39 | WHERE n.on_off = '1' and n.format IN ('forum') |
40 | ORDER BY n.published_date DESC, n.published_time DESC |
41 | ZZZZZZZZZZ); |
42 | $query->setMaxResults(5); |
43 | $index = 0; |
44 | foreach ($query->getResult() as $news_entry) { |
45 | $id = $news_entry->getId(); |
46 | $date = $this->dateUtils()->compactDate($news_entry->getPublishedDate()); |
47 | $title = $news_entry->getTitle(); |
48 | $format = $news_entry->getFormat(); |
49 | $image_ids = $news_entry->getImageIds(); |
50 | $icon = $this->newsUtils()->getNewsFormatIcon($format); |
51 | |
52 | $image = ''; |
53 | $is_image_right = ($index % 2) === 1; |
54 | if (count($image_ids) > 0) { |
55 | $olz_image = $this->imageUtils()->olzImage( |
56 | 'news', |
57 | $id, |
58 | $image_ids[0] ?? null, |
59 | 80, |
60 | null, |
61 | ' class="noborder"' |
62 | ); |
63 | $image = "{$olz_image}"; |
64 | } |
65 | $image_left = ''; |
66 | $image_right = ''; |
67 | if ($is_image_right) { |
68 | $image_right = "<div class='link-image-right'>{$image}</div>"; |
69 | } else { |
70 | $image_left = "<div class='link-image-left'>{$image}</div>"; |
71 | } |
72 | |
73 | $class = $is_image_right ? 'right' : 'left'; |
74 | $out .= <<<ZZZZZZZZZZ |
75 | <li class='{$class}'> |
76 | <a href='{$code_href}news/{$id}?von=startseite'> |
77 | <div class='flex bubble'> |
78 | {$image_left} |
79 | <img src='{$icon}' alt='{$format}' class='link-icon'> |
80 | <span class='title'>{$title}</span> |
81 | <span class='date'>{$date}</span> |
82 | {$image_right} |
83 | </div> |
84 | </a> |
85 | </li> |
86 | ZZZZZZZZZZ; |
87 | |
88 | $index++; |
89 | } |
90 | $out .= "</ul>"; |
91 | |
92 | return $out; |
93 | } |
94 | } |