Completed
Push — master ( 44b423...f32fbb )
by Morris
13:09
created

CalendarImpl::getKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright 2017, Georg Ehrke <[email protected]>
4
 *
5
 * @author Georg Ehrke <[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\DAV\CalDAV;
25
26
use OCP\Constants;
27
use OCP\Calendar\ICalendar;
28
29
class CalendarImpl implements ICalendar {
30
31
	/** @var CalDavBackend */
32
	private $backend;
33
34
	/** @var Calendar */
35
	private $calendar;
36
37
	/** @var array */
38
	private $calendarInfo;
39
40
	/**
41
	 * CalendarImpl constructor.
42
	 *
43
	 * @param Calendar $calendar
44
	 * @param array $calendarInfo
45
	 * @param CalDavBackend $backend
46
	 */
47
	public function __construct(Calendar $calendar, array $calendarInfo,
48
								CalDavBackend $backend) {
49
		$this->calendar = $calendar;
50
		$this->calendarInfo = $calendarInfo;
51
		$this->backend = $backend;
52
	}
53
	
54
	/**
55
	 * @return string defining the technical unique key
56
	 * @since 13.0.0
57
	 */
58
	public function getKey() {
59
		return $this->calendarInfo['id'];
60
	}
61
62
	/**
63
	 * In comparison to getKey() this function returns a human readable (maybe translated) name
64
	 * @return null|string
65
	 * @since 13.0.0
66
	 */
67
	public function getDisplayName() {
68
		return $this->calendarInfo['{DAV:}displayname'];
69
	}
70
71
	/**
72
	 * Calendar color
73
	 * @return null|string
74
	 * @since 13.0.0
75
	 */
76
	public function getDisplayColor() {
77
		return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color'];
78
	}
79
80
	/**
81
	 * @param string $pattern which should match within the $searchProperties
82
	 * @param array $searchProperties defines the properties within the query pattern should match
83
	 * @param array $options - optional parameters:
84
	 * 	['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]]
85
	 * @param integer|null $limit - limit number of search results
86
	 * @param integer|null $offset - offset for paging of search results
87
	 * @return array an array of events/journals/todos which are arrays of key-value-pairs
88
	 * @since 13.0.0
89
	 */
90
	public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null) {
91
		return $this->backend->search($this->calendarInfo, $pattern,
92
			$searchProperties, $options, $limit, $offset);
93
	}
94
95
	/**
96
	 * @return integer build up using \OCP\Constants
97
	 * @since 13.0.0
98
	 */
99 View Code Duplication
	public function getPermissions() {
100
		$permissions = $this->calendar->getACL();
101
		$result = 0;
102
		foreach ($permissions as $permission) {
103
			switch($permission['privilege']) {
104
				case '{DAV:}read':
105
					$result |= Constants::PERMISSION_READ;
106
					break;
107
				case '{DAV:}write':
108
					$result |= Constants::PERMISSION_CREATE;
109
					$result |= Constants::PERMISSION_UPDATE;
110
					break;
111
				case '{DAV:}all':
112
					$result |= Constants::PERMISSION_ALL;
113
					break;
114
			}
115
		}
116
117
		return $result;
118
	}
119
}
120