CalendarEvent::getSummary()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
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(): string {
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(): string {
65
		return $this->calDav['id'];
66
	}
67
68
	public function getUID(): string {
69
		return $this->event['UID'][0];
70
	}
71
72
	public function getSummary(): string {
73
		return $this->event['SUMMARY'][0];
74
	}
75
76
	public function getDescription(): string {
77
		return $this->event['DESCRIPTION'][0] ?? '';
78
	}
79
80
	public function getLocation(): string {
81
		return $this->event['LOCATION'][0] ?? '';
82
	}
83
84
	public function getStart(): int {
85
		return isset($this->event['DTSTART'][0]) ? $this->event['DTSTART'][0]->getTimestamp() : 0;
86
	}
87
88
	public function getEnd(): int {
89
		return isset($this->event['DTEND'][0])? $this->event['DTEND'][0]->getTimestamp() : 0;
90
	}
91
92
	public function getHasRRule(): bool {
93
		return isset($this->event['RRULE']);
94
	}
95
96
	public function getRecurrencies(): string {
97
		return 'not implementend yet';
98
	}
99
100
	/**
101
	 * @return false|string[]
102
	 *
103
	 * @psalm-return array<string, string>|false
104
	 */
105
	public function getRRule() {
106
		$rRule = [];
107
		if ($this->getHasRRule()) {
108
			preg_match_all("/([^;= ]+)=([^;= ]+)/", $this->event['RRULE'][0], $r);
109
			$rRule = array_combine($r[1], $r[2]);
110
		}
111
		return $rRule;
112
	}
113
114
	public function getStatus(): string {
115
		return $this->event['STATUS'][0] ?? '';
116
	}
117
118
	public function getCalDav(): array {
119
		return $this->calDav;
120
	}
121
122
	public function jsonSerialize(): array {
123
		return	[
124
			'id' => $this->getId(),
125
			'UID' => $this->getUID(),
126
			'calendarKey' => $this->getCalendarKey(),
127
			'calendarName' => $this->getCalendarName(),
128
			'displayColor' => $this->getDisplayColor(),
129
			'allDay' => $this->getAllDay(),
130
			'description' => $this->getDescription(),
131
			'end' => $this->getEnd(),
132
			'location' => $this->getLocation(),
133
			'start' => $this->getStart(),
134
			'status' => $this->getStatus(),
135
			'summary' => $this->getSummary(),
136
			'calDav' => $this->getCalDav(),
137
			'hasRRule' => $this->getHasRRule(),
138
			'rRule' => $this->getRRule(),
139
			'recurrencies' => $this->getRecurrencies(),
140
		];
141
	}
142
}
143