1
|
|
|
<?php namespace CalDAVClient\Facade\Requests; |
2
|
|
|
/** |
3
|
|
|
* Copyright 2017 OpenStack Foundation |
4
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
5
|
|
|
* you may not use this file except in compliance with the License. |
6
|
|
|
* You may obtain a copy of the License at |
7
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
8
|
|
|
* Unless required by applicable law or agreed to in writing, software |
9
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
10
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
11
|
|
|
* See the License for the specific language governing permissions and |
12
|
|
|
* limitations under the License. |
13
|
|
|
**/ |
14
|
|
|
|
15
|
|
|
use CalDAVClient\Facade\Utils\ICalTimeZoneBuilder; |
16
|
|
|
use Eluceo\iCal\Component\Event; |
17
|
|
|
use DateTime; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class EventCreateRequest |
21
|
|
|
* @package CalDAVClient\Facade\Requests |
22
|
|
|
*/ |
23
|
|
|
class EventCreateRequest implements IAbstractWebDAVRequest |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var EventRequestVO |
27
|
|
|
*/ |
28
|
|
|
private $vo; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* EventCreateRequest constructor. |
32
|
|
|
* @param EventRequestVO $vo |
33
|
|
|
*/ |
34
|
|
|
public function __construct(EventRequestVO $vo) |
35
|
|
|
{ |
36
|
|
|
$this->vo = $vo; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
public function getContent() |
43
|
|
|
{ |
44
|
|
|
|
45
|
|
|
$time_zone = $this->vo->getTimeZone(); |
46
|
|
|
$calendar = ICalTimeZoneBuilder::build($time_zone, $this->vo->getProdId()); |
47
|
|
|
$local_start_time = new DateTime($this->vo->getStartTime()->format('Y-m-d H:i:s'), $time_zone); |
48
|
|
|
$local_end_time = new DateTime($this->vo->getEndTime()->format('Y-m-d H:i:s'), $time_zone); |
49
|
|
|
$event = new Event($this->vo->getUID()); |
50
|
|
|
|
51
|
|
|
$event |
52
|
|
|
->setCreated(new DateTime()) |
53
|
|
|
->setDtStart($local_start_time) |
54
|
|
|
->setDtEnd($local_end_time) |
55
|
|
|
->setNoTime(false) |
56
|
|
|
->setSummary($this->vo->getTitle()) |
57
|
|
|
->setDescription(strip_tags($this->vo->getDescription())) |
58
|
|
|
->setDescriptionHTML($this->vo->getDescription()); |
59
|
|
|
|
60
|
|
|
if($time_zone->getName() == 'UTC'){ |
61
|
|
|
$event->setUseUtc(true) |
62
|
|
|
->setUseTimezone(false); |
63
|
|
|
} |
64
|
|
|
else{ |
65
|
|
|
$event->setUseUtc(false) |
66
|
|
|
->setUseTimezone(true); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if(!empty($this->vo->getLocationTitle())){ |
70
|
|
|
$geo = sprintf("%s;%s", $this->vo->getLocationLat(), $this->vo->getLocationLng()); |
71
|
|
|
$event->setLocation($this->vo->getLocationTitle(), $this->vo->getLocationTitle(), $geo); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$calendar->addComponent($event); |
75
|
|
|
|
76
|
|
|
return $calendar->render(); |
77
|
|
|
} |
78
|
|
|
} |