|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Check if the given Index is on the given day. |
|
5
|
|
|
*/ |
|
6
|
|
|
declare(strict_types=1); |
|
7
|
|
|
|
|
8
|
|
|
namespace HDNET\Calendarize\ViewHelpers\DateTime; |
|
9
|
|
|
|
|
10
|
|
|
use HDNET\Calendarize\Domain\Model\Index; |
|
11
|
|
|
use HDNET\Calendarize\Utility\DateTimeUtility; |
|
12
|
|
|
use HDNET\Calendarize\Utility\IndexUtility; |
|
13
|
|
|
use HDNET\Calendarize\ViewHelpers\AbstractViewHelper; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Check if the given Index is on the given day. |
|
17
|
|
|
*/ |
|
18
|
|
|
class IndexOnDayViewHelper extends AbstractViewHelper |
|
19
|
|
|
{ |
|
20
|
|
|
public function initializeArguments() |
|
21
|
|
|
{ |
|
22
|
|
|
parent::initializeArguments(); |
|
23
|
|
|
$this->registerArgument('day', \DateTimeInterface::class, 'Day to check against the Indices', true); |
|
24
|
|
|
$this->registerArgument('index', Index::class, 'Index to check against day', false, null); |
|
25
|
|
|
$this->registerArgument('indices', \Iterator::class, 'Indices to check against day', false, []); |
|
26
|
|
|
$this->registerArgument('modification', 'string', 'Apply Modifier to the Date', false, ''); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Check if the index or one of the given indices is on the given day. |
|
31
|
|
|
* |
|
32
|
|
|
* @return bool |
|
33
|
|
|
*/ |
|
34
|
|
|
public function render() |
|
35
|
|
|
{ |
|
36
|
|
|
/** @var \DateTimeInterface $day */ |
|
37
|
|
|
$day = $this->arguments['day']; |
|
38
|
|
|
/** @var ?Index $index */ |
|
|
|
|
|
|
39
|
|
|
$index = $this->arguments['index']; |
|
40
|
|
|
/** @var array<Index> $indices */ |
|
41
|
|
|
$indices = $this->arguments['indices']; |
|
42
|
|
|
/** @var string $modification */ |
|
43
|
|
|
$modification = $this->arguments['modification']; |
|
44
|
|
|
|
|
45
|
|
|
$day = DateTimeUtility::normalizeDateTimeSingle($day->format('d.m.Y')); |
|
46
|
|
|
$baseDay = clone $day; |
|
47
|
|
|
if ($modification !== '') { |
|
48
|
|
|
$baseDay->modify($modification); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$baseDay->setTime(0, 0, 0); |
|
52
|
|
|
$startTime = clone $baseDay; |
|
53
|
|
|
$baseDay->setTime(23, 59, 59); |
|
54
|
|
|
$endTime = clone $baseDay; |
|
55
|
|
|
|
|
56
|
|
|
if ($index instanceof Index) { |
|
57
|
|
|
$indices[] = $index; |
|
58
|
|
|
} |
|
59
|
|
|
foreach ($indices as $index) { |
|
60
|
|
|
/** @var $index Index */ |
|
61
|
|
|
if (IndexUtility::isIndexInRange($index, $startTime, $endTime)) { |
|
62
|
|
|
return true; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return false; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.