Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| OlzTermineUpcomingTile | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| getRelevance | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getHtml | |
0.00% |
0 / 31 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | // ============================================================================= |
| 4 | // Zeigt eine Startseiten-Kachel mit den nächsten Terminen an. |
| 5 | // ============================================================================= |
| 6 | |
| 7 | namespace Olz\Startseite\Components\OlzTermineUpcomingTile; |
| 8 | |
| 9 | use Olz\Entity\Termine\TerminLabel; |
| 10 | use Olz\Entity\Users\User; |
| 11 | use Olz\Startseite\Components\AbstractOlzTile\AbstractOlzTile; |
| 12 | |
| 13 | class OlzTermineUpcomingTile extends AbstractOlzTile { |
| 14 | public function getRelevance(?User $user): float { |
| 15 | return 0.7; |
| 16 | } |
| 17 | |
| 18 | public function getHtml(mixed $args): string { |
| 19 | $db = $this->dbUtils()->getDb(); |
| 20 | $code_href = $this->envUtils()->getCodeHref(); |
| 21 | $code_path = $this->envUtils()->getCodePath(); |
| 22 | $today = $this->dateUtils()->getIsoToday(); |
| 23 | $termin_label_repo = $this->entityManager()->getRepository(TerminLabel::class); |
| 24 | |
| 25 | $out = "<h3>Bevorstehende Termine</h3>"; |
| 26 | |
| 27 | $out .= "<ul class='links'>"; |
| 28 | $res = $db->query(<<<ZZZZZZZZZZ |
| 29 | SELECT |
| 30 | t.id, |
| 31 | t.start_date as date, |
| 32 | t.title as title, |
| 33 | ( |
| 34 | SELECT l.id |
| 35 | FROM |
| 36 | termin_label_map tl |
| 37 | JOIN termin_labels l ON (l.id = tl.label_id) |
| 38 | WHERE tl.termin_id = t.id |
| 39 | ORDER BY l.position ASC |
| 40 | LIMIT 1 |
| 41 | ) as label_id |
| 42 | FROM termine t |
| 43 | WHERE t.on_off = '1' AND t.start_date >= '{$today}' |
| 44 | ORDER BY t.start_date ASC |
| 45 | LIMIT 7 |
| 46 | ZZZZZZZZZZ); |
| 47 | // @phpstan-ignore-next-line |
| 48 | while ($row = $res->fetch_assoc()) { |
| 49 | $id = $row['id']; |
| 50 | // @phpstan-ignore-next-line |
| 51 | $date = $this->dateUtils()->compactDate($row['date']); |
| 52 | $title = $row['title']; |
| 53 | $label_id = $row['label_id']; |
| 54 | $label = $termin_label_repo->findOneBy(['id' => $label_id]); |
| 55 | $label_ident = $label?->getIdent(); |
| 56 | $fallback_path = "{$code_path}assets/icns/termine_type_{$label_ident}_20.svg"; |
| 57 | $fallback_href = is_file($fallback_path) |
| 58 | ? "{$code_href}assets/icns/termine_type_{$label_ident}_20.svg" : null; |
| 59 | $icon_href = $label?->getIcon() ? $label->getFileHref($label->getIcon()) : $fallback_href; |
| 60 | $icon_img = $icon_href ? "<img src='{$icon_href}' alt='' class='link-icon'>" : ''; |
| 61 | $out .= <<<ZZZZZZZZZZ |
| 62 | <li class='flex'> |
| 63 | {$icon_img} |
| 64 | <a href='{$code_href}termine/{$id}?von=startseite'> |
| 65 | <b>{$date}</b>: {$title} |
| 66 | </a> |
| 67 | </li> |
| 68 | ZZZZZZZZZZ; |
| 69 | } |
| 70 | $out .= "</ul>"; |
| 71 | |
| 72 | return $out; |
| 73 | } |
| 74 | } |