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                AND t.on_off = '1'
48            ORDER BY deadline ASC
49            ZZZZZZZZZZ);
50        // @phpstan-ignore-next-line
51        if ($res->num_rows > 0) {
52            $out .= "<ul class='links'>";
53            // @phpstan-ignore-next-line
54            while ($row = $res->fetch_assoc()) {
55                $out .= $this->getDeadlineHtml($row);
56            }
57            $out .= "</ul>";
58        } else {
59            $out .= "<br /><center><i>Keine Meldeschlüsse in den nächsten drei Wochen</i></center>";
60        }
61
62        // Outlook
63        $res = $db->query(<<<ZZZZZZZZZZ
64            SELECT
65                DATE(t.deadline) as deadline,
66                t.start_date as date,
67                t.title as title,
68                t.id as id,
69                t.image_ids as image_ids
70            FROM termine t
71            WHERE
72                t.deadline IS NOT NULL
73                AND t.deadline > '{$this->in_two_weeks}'
74                AND t.should_promote != '0'
75                AND t.image_ids IS NOT NULL
76                AND t.image_ids != '[]'
77                AND t.on_off = '1'
78            ORDER BY deadline ASC
79            LIMIT 7
80            ZZZZZZZZZZ);
81        // @phpstan-ignore-next-line
82        if ($res->num_rows > 0) {
83            $out .= "<hr/>";
84            $out .= "<ul class='links'>";
85            // @phpstan-ignore-next-line
86            while ($row = $res->fetch_assoc()) {
87                $out .= $this->getDeadlineHtml($row);
88            }
89            $out .= "</ul>";
90        }
91        return $out;
92    }
93
94    /**
95     * @param array<string, mixed> $row
96     */
97    protected function getDeadlineHtml(array $row): string {
98        $code_href = $this->envUtils()->getCodeHref();
99
100        $id = $row['id'];
101        $deadline = $this->dateUtils()->compactDate($row['deadline']);
102        $date = $this->dateUtils()->compactDate($row['date']);
103        $title = $row['title'];
104        $urgency = 'full';
105        if ($row['deadline'] <= $this->in_three_days) {
106            $urgency = 'empty';
107        } elseif ($row['deadline'] <= $this->in_one_week) {
108            $urgency = 'mid';
109        }
110        $image_ids = json_decode($row['image_ids'], true);
111        $image_id = count($image_ids ?? []) > 0 ? $image_ids[0] : null;
112        $icon_color = $image_id ? '_white' : '';
113        $icon_basename = "termine_type_meldeschluss_{$urgency}{$icon_color}_20.svg";
114        $icon = "{$code_href}assets/icns/{$icon_basename}";
115        $icon_img = "<img src='{$icon}' alt='' class='link-icon'>";
116        if ($image_id) {
117            $image = $this->imageUtils()->olzImage(
118                'termine',
119                $id,
120                $image_id,
121                128,
122                null,
123                ' class="noborder"'
124            );
125            return <<<ZZZZZZZZZZ
126                    <li class='flex deadline-image min-two-lines'>
127                        <a href='{$code_href}termine/{$id}?von=startseite'>
128                            <div class='overlay'>
129                                {$icon_img}
130                                <span class='date'>{$deadline}</span>
131                                <span class='title'>Für {$title} vom {$date}</span>
132                            </div>
133                            <div class='blurry-image'>{$image}</div>
134                            <div class='sharp-image'>{$image}</div>
135                        </a>
136                    </li>
137                ZZZZZZZZZZ;
138        }
139        return <<<ZZZZZZZZZZ
140                <li class='flex'>
141                    {$icon_img}
142                    <a href='{$code_href}termine/{$id}?von=startseite'>
143                        <b>{$deadline}</b>: Für {$title} vom {$date}
144                    </a>
145                </li>
146            ZZZZZZZZZZ;
147    }
148}