Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 71 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| OlzTerminTemplatesListItem | |
0.00% |
0 / 71 |
|
0.00% |
0 / 2 |
156 | |
0.00% |
0 / 1 |
| getHtml | |
0.00% |
0 / 68 |
|
0.00% |
0 / 1 |
110 | |||
| getTimeText | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Termine\Components\OlzTerminTemplatesListItem; |
| 4 | |
| 5 | use Olz\Common\Components\OlzComponent; |
| 6 | use Olz\Termine\Components\OlzDateCalendar\OlzDateCalendar; |
| 7 | use Olz\Users\Components\OlzUserInfoModal\OlzUserInfoModal; |
| 8 | |
| 9 | /** @extends OlzComponent<array<string, mixed>> */ |
| 10 | class OlzTerminTemplatesListItem extends OlzComponent { |
| 11 | public function getHtml(mixed $args): string { |
| 12 | $db = $this->dbUtils()->getDb(); |
| 13 | $code_href = $this->envUtils()->getCodeHref(); |
| 14 | $code_path = $this->envUtils()->getCodePath(); |
| 15 | |
| 16 | $out = ''; |
| 17 | |
| 18 | $termin_template = $args['termin_template']; |
| 19 | $id = $termin_template->getId(); |
| 20 | $start_time = $termin_template->getStartTime(); |
| 21 | $duration_seconds = $termin_template->getDurationSeconds(); |
| 22 | $title = $termin_template->getTitle(); |
| 23 | $text = $termin_template->getText(); |
| 24 | $organizer = $termin_template->getOrganizerUser(); |
| 25 | $termin_location = $termin_template->getLocation(); |
| 26 | |
| 27 | $link = "{$code_href}termine/vorlagen/{$id}"; |
| 28 | |
| 29 | $duration_seconds_or_zero = $duration_seconds ?? 0; |
| 30 | $duration_string = "+{$duration_seconds_or_zero} seconds"; |
| 31 | $duration_interval = \DateInterval::createFromDateString($duration_string); |
| 32 | $this->generalUtils()->checkNotFalse($duration_interval, "Invalid duration: {$duration_string}"); |
| 33 | $start_time_or_midnight = new \DateTime($start_time?->format('Y-m-d H:i:s') ?? '00:00:00'); |
| 34 | $end_time = $duration_seconds |
| 35 | ? $start_time_or_midnight->add($duration_interval) : null; |
| 36 | $end_time_text = $this->getTimeText($end_time); |
| 37 | $day_diff = ($start_time && $end_time) |
| 38 | ? intval($end_time->format('d')) - intval($start_time->format('d')) : null; |
| 39 | $start_icon = OlzDateCalendar::render([ |
| 40 | 'weekday' => '', |
| 41 | 'day' => 'X', |
| 42 | 'month' => '', |
| 43 | 'size' => 'S', |
| 44 | ]); |
| 45 | $end_icon = ($day_diff > 0) |
| 46 | ? ' – '.OlzDateCalendar::render([ |
| 47 | 'weekday' => '', |
| 48 | 'day' => "X+{$day_diff}", |
| 49 | 'month' => '', |
| 50 | 'size' => 'S', |
| 51 | ]) |
| 52 | : null; |
| 53 | $start_time_text = $this->getTimeText($start_time); |
| 54 | |
| 55 | $time_text = $start_time_text ? ( |
| 56 | $end_time_text |
| 57 | ? "{$start_time_text} – {$end_time_text}" |
| 58 | : "{$start_time_text}" |
| 59 | ) : ( |
| 60 | $end_time_text |
| 61 | ? "? +{$end_time_text}" |
| 62 | : '' |
| 63 | ); |
| 64 | $text = $this->htmlUtils()->renderMarkdown($text ?? ''); |
| 65 | $text = $termin_template->replaceImagePaths($text); |
| 66 | $text = $termin_template->replaceFilePaths($text); |
| 67 | if ($termin_location) { |
| 68 | $sane_termin_location_id = intval($termin_location->getId()); |
| 69 | $result_location = $db->query("SELECT name FROM termin_locations WHERE id='{$sane_termin_location_id}'"); |
| 70 | // @phpstan-ignore-next-line |
| 71 | $row_location = $result_location->fetch_assoc(); |
| 72 | $location_name = $row_location['name'] ?? null; |
| 73 | $text = "<a href='{$code_href}termine/orte/{$sane_termin_location_id}' class='linkmap'>{$location_name}</a> {$text}"; |
| 74 | } |
| 75 | if ($organizer) { |
| 76 | $pretty_organizer = OlzUserInfoModal::render(['user' => $organizer]); |
| 77 | $text = "{$pretty_organizer} {$text}"; |
| 78 | } |
| 79 | |
| 80 | $out .= <<<ZZZZZZZZZZ |
| 81 | <div class='olz-termin-templates-list-item'> |
| 82 | <a class='link' href='{$link}'></a> |
| 83 | <div class='content'> |
| 84 | <div class='date'> |
| 85 | <div class='date-calendars'>{$start_icon}{$end_icon}</div> |
| 86 | <div class='time-text'>{$time_text}</div> |
| 87 | </div> |
| 88 | <div class='title-text-container'> |
| 89 | <div class='title'>{$title}</div> |
| 90 | <div class='text'>{$text}</div> |
| 91 | </div> |
| 92 | </div> |
| 93 | </div> |
| 94 | ZZZZZZZZZZ; |
| 95 | return $out; |
| 96 | } |
| 97 | |
| 98 | protected function getTimeText(?\DateTime $datetime_time): ?string { |
| 99 | if (!$datetime_time) { |
| 100 | return null; |
| 101 | } |
| 102 | return $datetime_time->format('H:i'); |
| 103 | } |
| 104 | } |