Passed
Pull Request — master (#1187)
by René
04:18
created

CalendarEvent::getUID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author René Gieling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Polls\Model;
25
use \OCP\Calendar\ICalendar;
26
27
class CalendarEvent implements \JsonSerializable {
28
29
	/** @var Array */
30
	protected $calDav;
31
32
	/** @var Array */
33
	protected $event;
34
35
	/** @var ICalendar */
36
	protected $calendar;
37
38
	/**
39
	 * CalendarEvent constructor.
40
	 * @param Array $calDav
41
	 * @param ICalendar $calendar
42
	 */
43
	public function __construct(
44
		$calDav,
45
		$calendar
46
	) {
47
		$this->calDav = $calDav;
48
		$this->calendar = $calendar;
49
		$this->event = $this->calDav['objects'][0];
50
	}
51
52
53
	/**
54
	 * getAllDay
55
	 * @return string
56
	 */
57
	public function getAllDay() {
58
		if ($this->getEnd() - $this->getStart() === 86400) {
59
			return $this->event['DTSTART'][0]->format('Y-m-d');
60
		} else {
61
			return '';
62
		}
63
	}
64
65
	/**
66
	 * getCalendarName
67
	 * @return string
68
	 */
69
	public function getCalendarName() {
70
		return $this->calendar->getDisplayName();
71
	}
72
73
	/**
74
	 * getCalendarKey
75
	 * @return string
76
	 */
77
	public function getCalendarKey() {
78
		return $this->calendar->getKey();
79
	}
80
81
	/**
82
	 * getDisplayColor
83
	 * @return string
84
	 */
85
	public function getDisplayColor() {
86
		return $this->calendar->getDisplayColor();
87
	}
88
89
	/**
90
	 * getId
91
	 * @return int
92
	 */
93
	public function getId() {
94
		return $this->calDav['id'];
95
	}
96
97
	/**
98
	 * getUID
99
	 * @return string
100
	 */
101
	public function getUID() {
102
		return $this->event['UID'][0];
103
	}
104
105
	/**
106
	 * getSummary
107
	 * @return string
108
	 */
109
	public function getSummary() {
110
		return $this->event['SUMMARY'][0];
111
	}
112
113
	/**
114
	 * getDescription
115
	 * @return string
116
	 */
117
	public function getDescription() {
118
		if (isset($this->event['DESCRIPTION'][0])) {
119
			return $this->event['DESCRIPTION'][0];
120
		} else {
121
			return '';
122
		}
123
	}
124
125
	/**
126
	 * getLocation
127
	 * @return string
128
	 */
129
	public function getLocation() {
130
		if (isset($this->event['LOCATION'][0])) {
131
			return $this->event['LOCATION'][0];
132
		} else {
133
			return '';
134
		}
135
	}
136
137
	/**
138
	 * getStart
139
	 * @return int
140
	 */
141
	public function getStart() {
142
		if (isset($this->event['DTSTART'][0])) {
143
			return $this->event['DTSTART'][0]->getTimestamp();
144
		} else {
145
			return 0;
146
		}
147
	}
148
149
	/**
150
	 * getEnd
151
	 * @return int
152
	 */
153
	public function getEnd() {
154
		if (isset($this->event['DTEND'][0])) {
155
			return $this->event['DTEND'][0]->getTimestamp();
156
		} else {
157
			return 0;
158
		}
159
	}
160
161
	/**
162
	 * getStatus
163
	 * @return string
164
	 */
165
	public function getStatus() {
166
		if (isset($this->event['STATUS'][0])) {
167
			return $this->event['STATUS'][0];
168
		} else {
169
			return '';
170
		}
171
	}
172
173
	/**
174
	 * getCalDav
175
	 * @return
176
	 */
177
	public function getCalDav() {
178
		return $this->calDav;
179
	}
180
181
	/**
182
	 * @return array
183
	 */
184
	public function jsonSerialize(): array {
185
		return	[
186
			'id'			=> $this->getId(),
187
			'UID'			=> $this->getUID(),
188
			'calendarKey'	=> $this->getCalendarKey(),
189
			'calendarName'	=> $this->getCalendarName(),
190
			'displayColor'	=> $this->getDisplayColor(),
191
			'allDay'		=> $this->getAllDay(),
192
			'description'	=> $this->getDescription(),
193
			'end'			=> $this->getEnd(),
194
			'location'		=> $this->getLocation(),
195
			'start'			=> $this->getStart(),
196
			'status'		=> $this->getStatus(),
197
			'summary'		=> $this->getSummary(),
198
			'calDav'		=> $this->getCalDav(),
199
		];
200
	}
201
}
202