| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\Package\CalDav\Entities; |
| 4 |
|
| 5 |
class Event implements \JsonSerializable |
| 6 |
{ |
| 7 |
/** |
| 8 |
* The \Entities\Calendar object |
| 9 |
* @var null |
| 10 |
*/ |
| 11 |
protected $calendar = null; |
| 12 |
|
| 13 |
/** |
| 14 |
* The \ICal\Event object |
| 15 |
* @var null |
| 16 |
*/ |
| 17 |
protected $icalEvent = []; |
| 18 |
|
| 19 |
/** |
| 20 |
* Information about the calebdar |
| 21 |
* |
| 22 |
* @var array |
| 23 |
*/ |
| 24 |
protected $meta = []; |
| 25 |
|
| 26 |
public function __construct($event, array $meta) |
| 27 |
{ |
| 28 |
$this->meta = $meta; |
| 29 |
$this->icalEvent = $event; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Getter to get underlying Event Object |
| 34 |
* @return \ICal\Event |
| 35 |
*/ |
| 36 |
public function getIcalEvent() |
| 37 |
{ |
| 38 |
return $this->icalEvent; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Dynamic property getter |
| 43 |
* |
| 44 |
* @param string $key |
| 45 |
* @return mixed |
| 46 |
*/ |
| 47 |
public function __get($key) |
| 48 |
{ |
| 49 |
if (isset($this->meta[$key])) { |
| 50 |
return $this->meta[$key]; |
| 51 |
} |
| 52 |
|
| 53 |
return $this->icalEvent->{$key}; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Get the uid of underlying event |
| 58 |
* @return [type] [description] |
| 59 |
*/ |
| 60 |
public function getUid() |
| 61 |
{ |
| 62 |
return $this->icalEvent->getUid(); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Dynamic property setter |
| 67 |
* |
| 68 |
* @param string $key |
| 69 |
* @param mixed $value |
| 70 |
* @return mixed |
| 71 |
*/ |
| 72 |
public function __set($key, $value) |
| 73 |
{ |
| 74 |
$this->icalEvent->{$key} = $value; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Create/Update an event |
| 79 |
* |
| 80 |
* @return \Ical\Event |
| 81 |
*/ |
| 82 |
public function save() |
| 83 |
{ |
| 84 |
if ($this->calendar->addEvent($this->icalEvent)) { |
| 85 |
return $this->calendar->getEvent($this->icalEvent->getUid()); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
public function delete() |
| 90 |
{ |
| 91 |
return $this->calendar->deleteEvent( |
| 92 |
$this->icalEvent->getUid() |
| 93 |
); |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Set the calendar object |
| 98 |
* |
| 99 |
* @param \Entities\Calendar |
| 100 |
*/ |
| 101 |
public function setCalendar($calendar) |
| 102 |
{ |
| 103 |
$this->calendar = $calendar; |
| 104 |
} |
| 105 |
|
| 106 |
#[\ReturnTypeWillChange] |
| 107 |
public function jsonSerialize() |
| 108 |
{ |
| 109 |
return $this->icalEvent; |
| 110 |
} |
| 111 |
} |
| 112 |
|