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