Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 74
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
OlzTermineDeadlinesTile
0.00% covered (danger)
0.00%
0 / 74
0.00% covered (danger)
0.00%
0 / 3
156
0.00% covered (danger)
0.00%
0 / 1
 getRelevance
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHtml
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 1
30
 getDeadlineHtml
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2
3// =============================================================================
4// Zeigt eine Startseiten-Kachel mit den nächsten Meldeschlüssen an.
5// =============================================================================
6
7namespace Olz\Startseite\Components\OlzTermineDeadlinesTile;
8
9use Olz\Entity\Users\User;
10use Olz\Startseite\Components\AbstractOlzTile\AbstractOlzTile;
11
12class OlzTermineDeadlinesTile extends AbstractOlzTile {
13    private string $in_three_days;
14    private string $in_one_week;
15    private string $in_two_weeks;
16
17    public function getRelevance(?User $user): float {
18        return 0.75;
19    }
20
21    public function getHtml(mixed $args): string {
22        $db = $this->dbUtils()->getDb();
23        $date_utils = $this->dateUtils();
24        $today = $date_utils->getIsoToday();
25        $now = $date_utils->getIsoNow();
26        $plus_three_days = \DateInterval::createFromDateString("+3 days");
27        $plus_one_week = \DateInterval::createFromDateString("+7 days");
28        $plus_two_weeks = \DateInterval::createFromDateString("+14 days");
29        $this->in_three_days = (new \DateTime($today))->add($plus_three_days)->format('Y-m-d');
30        $this->in_one_week = (new \DateTime($today))->add($plus_one_week)->format('Y-m-d');
31        $this->in_two_weeks = (new \DateTime($today))->add($plus_two_weeks)->format('Y-m-d');
32
33        $out = "<h3>Meldeschlüsse</h3>";
34
35        $res = $db->query(<<<ZZZZZZZZZZ
36            SELECT
37                DATE(t.deadline) as deadline,
38                t.start_date as date,
39                t.title as title,
40                t.id as id,
41                t.image_ids as image_ids
42            FROM termine t
43            WHERE
44                t.deadline IS NOT NULL
45                AND t.deadline >= '{$now}'
46                AND t.deadline <= '{$this->in_two_weeks}'
47            ORDER BY deadline ASC
48            ZZZZZZZZZZ);
49        // @phpstan-ignore-next-line
50        if ($res->num_rows > 0) {
51            $out .= "<ul class='links'>";
52            // @phpstan-ignore-next-line
53            while ($row = $res->fetch_assoc()) {
54                $out .= $this->getDeadlineHtml($row);
55            }
56            $out .= "</ul>";
57        } else {
58            $out .= "<br /><center><i>Keine Meldeschlüsse in den nächsten drei Wochen</i></center>";
59        }
60
61        // Outlook
62        $res = $db->query(<<<ZZZZZZZZZZ
63            SELECT
64                DATE(t.deadline) as deadline,
65                t.start_date as date,
66                t.title as title,
67                t.id as id,
68                t.image_ids as image_ids
69            FROM termine t
70            WHERE
71                t.deadline IS NOT NULL
72                AND t.deadline > '{$this->in_two_weeks}'
73                AND t.should_promote != '0'
74                AND t.image_ids IS NOT NULL
75                AND t.image_ids != '[]'
76            ORDER BY deadline ASC
77            LIMIT 7
78            ZZZZZZZZZZ);
79        // @phpstan-ignore-next-line
80        if ($res->num_rows > 0) {
81            $out .= "<hr/>";
82            $out .= "<ul class='links'>";
83            // @phpstan-ignore-next-line
84            while ($row = $res->fetch_assoc()) {
85                $out .= $this->getDeadlineHtml($row);
86            }
87            $out .= "</ul>";
88        }
89        return $out;
90    }
91
92    /**
93     * @param array<string, mixed> $row
94     */
95    protected function getDeadlineHtml(array $row): string {
96        $code_href = $this->envUtils()->getCodeHref();
97
98        $id = $row['id'];
99        $deadline = $this->dateUtils()->compactDate($row['deadline']);
100        $date = $this->dateUtils()->compactDate($row['date']);
101        $title = $row['title'];
102        $urgency = 'full';
103        if ($row['deadline'] <= $this->in_three_days) {
104            $urgency = 'empty';
105        } elseif ($row['deadline'] <= $this->in_one_week) {
106            $urgency = 'mid';
107        }
108        $image_ids = json_decode($row['image_ids'], true);
109        $image_id = count($image_ids ?? []) > 0 ? $image_ids[0] : null;
110        $icon_color = $image_id ? '_white' : '';
111        $icon_basename = "termine_type_meldeschluss_{$urgency}{$icon_color}_20.svg";
112        $icon = "{$code_href}assets/icns/{$icon_basename}";
113        $icon_img = "<img src='{$icon}' alt='' class='link-icon'>";
114        if ($image_id) {
115            $image = $this->imageUtils()->olzImage(
116                'termine',
117                $id,
118                $image_id,
119                128,
120                null,
121                ' class="noborder"'
122            );
123            return <<<ZZZZZZZZZZ
124                    <li class='flex deadline-image min-two-lines'>
125                        <a href='{$code_href}termine/{$id}?von=startseite'>
126                            <div class='overlay'>
127                                {$icon_img}
128                                <span class='date'>{$deadline}</span>
129                                <span class='title'>Für {$title} vom {$date}</span>
130                            </div>
131                            <div class='blurry-image'>{$image}</div>
132                            <div class='sharp-image'>{$image}</div>
133                        </a>
134                    </li>
135                ZZZZZZZZZZ;
136        }
137        return <<<ZZZZZZZZZZ
138                <li class='flex'>
139                    {$icon_img}
140                    <a href='{$code_href}termine/{$id}?von=startseite'>
141                        <b>{$deadline}</b>: Für {$title} vom {$date}
142                    </a>
143                </li>
144            ZZZZZZZZZZ;
145    }
146}