1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the eluceo/iCal package. |
5
|
|
|
* |
6
|
|
|
* (c) Markus Poerschke <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Eluceo\iCal\Property\Event; |
13
|
|
|
|
14
|
|
|
use Eluceo\iCal\ParameterBag; |
15
|
|
|
use Eluceo\iCal\Property; |
16
|
|
|
use Eluceo\iCal\Util\DateUtil; |
17
|
|
|
use Eluceo\iCal\Property\ValueInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Implementation of Recurrence Id. |
21
|
|
|
* |
22
|
|
|
* @see http://www.ietf.org/rfc/rfc2445.txt 4.8.4.4 Recurrence ID |
23
|
|
|
*/ |
24
|
|
|
class RecurrenceId extends Property |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* The effective range of recurrence instances from the instance |
28
|
|
|
* specified by the recurrence identifier specified by the property. |
29
|
|
|
*/ |
30
|
|
|
const RANGE_THISANDPRIOR = 'THISANDPRIOR'; |
31
|
|
|
const RANGE_THISANDFUTURE = 'THISANDFUTURE'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The dateTime to identify a particular instance of a recurring event which is getting modified. |
35
|
|
|
* |
36
|
|
|
* @var \DateTime |
37
|
|
|
*/ |
38
|
|
|
protected $dateTime; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Specify the effective range of recurrence instances from the instance. |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $range; |
46
|
|
|
|
47
|
|
|
public function __construct(\DateTime $dateTime = null) |
48
|
|
|
{ |
49
|
|
|
$this->dateTime = $dateTime; |
50
|
|
|
parent::__construct('RECURRENCE-ID', null); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function applyTimeSettings($noTime = false, $useTimezone = false, $useUtc = false) |
54
|
|
|
{ |
55
|
|
|
$params = DateUtil::getDefaultParams($this->dateTime, $noTime, $useTimezone); |
56
|
|
|
|
57
|
|
|
foreach ($params as $name => $value) { |
58
|
|
|
$this->parameterBag->setParam($name, $value); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ($this->range) { |
62
|
|
|
$this->parameterBag->setParam('RANGE', $this->range); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$this->setValue(DateUtil::getDateString($this->dateTime, $noTime, $useTimezone, $useUtc)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $range |
70
|
|
|
* |
71
|
|
|
* @return \Eluceo\iCal\Property\Event\RecurrenceId |
72
|
|
|
*/ |
73
|
|
|
public function setRange($range) |
74
|
|
|
{ |
75
|
|
|
$this->range = $range; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param \DateTime $dateTime |
80
|
|
|
*/ |
81
|
|
|
public function setDateTime(\DateTime $dateTime) |
82
|
|
|
{ |
83
|
|
|
$this->dateTime = $dateTime; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return array |
88
|
|
|
* @throws \Exception |
89
|
|
|
*/ |
90
|
|
|
public function toLines() |
91
|
|
|
{ |
92
|
|
|
if (!$this->value instanceof ValueInterface) { |
93
|
|
|
throw new \Exception('The value must implement the ValueInterface. Call RecurrenceId::applyTimeSettings() before adding RecurrenceId.'); |
94
|
|
|
} else { |
95
|
|
|
return parent::toLines(); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|