|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
namespace HDNET\Calendarize\Form\Element; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use HDNET\Calendarize\Service\IndexerService; |
|
7
|
|
|
use HDNET\Calendarize\Utility\DateTimeUtility; |
|
8
|
|
|
use HDNET\Calendarize\Utility\TranslateUtility; |
|
9
|
|
|
use TYPO3\CMS\Backend\Form\Element\AbstractFormElement; |
|
10
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
11
|
|
|
use TYPO3\CMS\Core\Utility\DebugUtility; |
|
12
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
13
|
|
|
|
|
14
|
|
|
class CalendarizeInfoElement extends AbstractFormElement |
|
|
|
|
|
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
public function render() |
|
18
|
|
|
{ |
|
19
|
|
|
$result = $this->initializeResultArray(); |
|
20
|
|
|
|
|
21
|
|
|
$parameters = $this->data['parameterArray']['fieldConf']['config']['parameters']; |
|
22
|
|
|
|
|
23
|
|
|
$previewLimit = 10; |
|
24
|
|
|
if (isset($parameters['items'])) { |
|
25
|
|
|
$previewLimit = (int)$parameters['items']; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$indexService = GeneralUtility::makeInstance(IndexerService::class); |
|
29
|
|
|
$count = $indexService->getIndexCount($this->data['tableName'], $this->data['vanillaUid']); |
|
30
|
|
|
$next = $indexService->getNextEvents($this->data['tableName'], $this->data['vanillaUid'], $previewLimit); |
|
31
|
|
|
$content = \sprintf(TranslateUtility::get('previewLabel'), $count, $previewLimit) . $this->getEventList($next); |
|
32
|
|
|
|
|
33
|
|
|
$result['html'] = $content; |
|
34
|
|
|
return $result; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Get event list. |
|
40
|
|
|
* |
|
41
|
|
|
* @param $events |
|
42
|
|
|
* |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function getEventList($events) |
|
46
|
|
|
{ |
|
47
|
|
|
$items = []; |
|
48
|
|
|
foreach ($events as $event) { |
|
49
|
|
|
if (!($event['start_date'] instanceof \DateTimeInterface)) { |
|
50
|
|
|
$event['start_date'] = new \DateTime($event['start_date']); |
|
51
|
|
|
} |
|
52
|
|
|
$startDate = \strftime(DateTimeUtility::FORMAT_DATE_BACKEND, (int)$event['start_date']->getTimestamp()); |
|
53
|
|
|
|
|
54
|
|
|
if (!($event['end_date'] instanceof \DateTimeInterface)) { |
|
55
|
|
|
$event['end_date'] = new \DateTime($event['end_date']); |
|
56
|
|
|
} |
|
57
|
|
|
$endDate = \strftime(DateTimeUtility::FORMAT_DATE_BACKEND, (int)$event['end_date']->getTimestamp()); |
|
58
|
|
|
$entry = $startDate . ' - ' . $endDate; |
|
59
|
|
|
if (!$event['all_day']) { |
|
60
|
|
|
$start = BackendUtility::time($event['start_time'] % DateTimeUtility::SECONDS_DAY, false); |
|
61
|
|
|
if ((bool)$event['open_end_time']) { |
|
62
|
|
|
$end = '"' . TranslateUtility::get('openEndTime') . '"'; |
|
63
|
|
|
} else { |
|
64
|
|
|
$end = BackendUtility::time($event['end_time'] % DateTimeUtility::SECONDS_DAY, false); |
|
65
|
|
|
} |
|
66
|
|
|
$entry .= ' (' . $start . ' - ' . $end . ')'; |
|
67
|
|
|
} |
|
68
|
|
|
$items[] = $entry; |
|
69
|
|
|
} |
|
70
|
|
|
if (!$items) { |
|
|
|
|
|
|
71
|
|
|
$items[] = TranslateUtility::get('noEvents'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return '<ul><li>' . \implode('</li><li>', $items) . '</li></ul>'; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|