Completed
Push — master ( 88f2dc...58f7d6 )
by René
26s queued 12s
created

CalendarEvent::getRecurrencies()   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
26
use \OCP\Calendar\ICalendar;
27
28
class CalendarEvent implements \JsonSerializable {
29
30
	/** @var Array */
31
	protected $calDav;
32
33
	/** @var Array */
34
	protected $event;
35
36
	/** @var ICalendar */
37
	protected $calendar;
38
39
	public function __construct(
40
		array $calDav,
41
		ICalendar $calendar
42
	) {
43
		$this->calDav = $calDav;
44
		$this->calendar = $calendar;
45
		$this->event = $this->calDav['objects'][0];
46
	}
47
48
	public function getAllDay() {
49
		return ($this->getEnd() - $this->getStart() === 86400) ? $this->event['DTSTART'][0]->format('Y-m-d') : '';
50
	}
51
52
	public function getCalendarName(): ?string {
53
		return $this->calendar->getDisplayName();
54
	}
55
56
	public function getCalendarKey(): string {
57
		return $this->calendar->getKey();
58
	}
59
60
	public function getDisplayColor(): ?string {
61
		return $this->calendar->getDisplayColor();
62
	}
63
64
	public function getId() {
65
		return $this->calDav['id'];
66
	}
67
68
	public function getUID() {
69
		return $this->event['UID'][0];
70
	}
71
72
	public function getSummary() {
73
		return $this->event['SUMMARY'][0];
74
	}
75
76
	public function getDescription() {
77
		return $this->event['DESCRIPTION'][0] ?? '';
78
	}
79
80
	public function getLocation() {
81
		return $this->event['LOCATION'][0] ?? '';
82
	}
83
84
	public function getStart() {
85
		return isset($this->event['DTSTART'][0]) ? $this->event['DTSTART'][0]->getTimestamp() : 0;
86
	}
87
88
	public function getEnd() {
89
		return isset($this->event['DTEND'][0])? $this->event['DTEND'][0]->getTimestamp() : 0;
90
	}
91
92
	public function getHasRRule() {
93
		return isset($this->event['RRULE']);
94
	}
95
96
	public function getRecurrencies() {
97
		return 'not implementend yet';
98
	}
99
100
	public function getRRule() {
101
		$rRule = [];
102
		if ($this->getHasRRule()) {
103
			preg_match_all("/([^;= ]+)=([^;= ]+)/", $this->event['RRULE'][0], $r);
104
			$rRule = array_combine($r[1], $r[2]);
105
		}
106
		return $rRule;
107
	}
108
109
	public function getStatus() {
110
		return $this->event['STATUS'][0] ?? '';
111
	}
112
113
	public function getCalDav(): array {
114
		return $this->calDav;
115
	}
116
117
	public function jsonSerialize(): array {
118
		return	[
119
			'id' => $this->getId(),
120
			'UID' => $this->getUID(),
121
			'calendarKey' => $this->getCalendarKey(),
122
			'calendarName' => $this->getCalendarName(),
123
			'displayColor' => $this->getDisplayColor(),
124
			'allDay' => $this->getAllDay(),
125
			'description' => $this->getDescription(),
126
			'end' => $this->getEnd(),
127
			'location' => $this->getLocation(),
128
			'start' => $this->getStart(),
129
			'status' => $this->getStatus(),
130
			'summary' => $this->getSummary(),
131
			'calDav' => $this->getCalDav(),
132
			'hasRRule' => $this->getHasRRule(),
133
			'rRule' => $this->getRRule(),
134
			'recurrencies' => $this->getRecurrencies(),
135
		];
136
	}
137
}
138