Passed
Push — master ( d93a36...dff845 )
by Daniel
11:45 queued 11s
created
apps/dav/lib/CalDAV/CalendarHome.php 1 patch
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -42,154 +42,154 @@
 block discarded – undo
42 42
 
43 43
 class CalendarHome extends \Sabre\CalDAV\CalendarHome {
44 44
 
45
-	/** @var \OCP\IL10N */
46
-	private $l10n;
47
-
48
-	/** @var \OCP\IConfig */
49
-	private $config;
50
-
51
-	/** @var PluginManager */
52
-	private $pluginManager;
53
-
54
-	/** @var bool */
55
-	private $returnCachedSubscriptions = false;
56
-
57
-	public function __construct(BackendInterface $caldavBackend, $principalInfo) {
58
-		parent::__construct($caldavBackend, $principalInfo);
59
-		$this->l10n = \OC::$server->getL10N('dav');
60
-		$this->config = \OC::$server->getConfig();
61
-		$this->pluginManager = new PluginManager(
62
-			\OC::$server,
63
-			\OC::$server->getAppManager()
64
-		);
65
-	}
66
-
67
-	/**
68
-	 * @return BackendInterface
69
-	 */
70
-	public function getCalDAVBackend() {
71
-		return $this->caldavBackend;
72
-	}
73
-
74
-	/**
75
-	 * @inheritdoc
76
-	 */
77
-	public function createExtendedCollection($name, MkCol $mkCol) {
78
-		$reservedNames = [BirthdayService::BIRTHDAY_CALENDAR_URI];
79
-
80
-		if (\in_array($name, $reservedNames, true) || ExternalCalendar::doesViolateReservedName($name)) {
81
-			throw new MethodNotAllowed('The resource you tried to create has a reserved name');
82
-		}
83
-
84
-		parent::createExtendedCollection($name, $mkCol);
85
-	}
86
-
87
-	/**
88
-	 * @inheritdoc
89
-	 */
90
-	public function getChildren() {
91
-		$calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
92
-		$objects = [];
93
-		foreach ($calendars as $calendar) {
94
-			$objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
95
-		}
96
-
97
-		if ($this->caldavBackend instanceof SchedulingSupport) {
98
-			$objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
99
-			$objects[] = new Outbox($this->config, $this->principalInfo['uri']);
100
-		}
101
-
102
-		// We're adding a notifications node, if it's supported by the backend.
103
-		if ($this->caldavBackend instanceof NotificationSupport) {
104
-			$objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
105
-		}
106
-
107
-		// If the backend supports subscriptions, we'll add those as well,
108
-		if ($this->caldavBackend instanceof SubscriptionSupport) {
109
-			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
110
-				if ($this->returnCachedSubscriptions) {
111
-					$objects[] = new CachedSubscription($this->caldavBackend, $subscription);
112
-				} else {
113
-					$objects[] = new Subscription($this->caldavBackend, $subscription);
114
-				}
115
-			}
116
-		}
117
-
118
-		foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) {
119
-			/** @var ICalendarProvider $calendarPlugin */
120
-			$calendars = $calendarPlugin->fetchAllForCalendarHome($this->principalInfo['uri']);
121
-			foreach ($calendars as $calendar) {
122
-				$objects[] = $calendar;
123
-			}
124
-		}
125
-
126
-		return $objects;
127
-	}
128
-
129
-	/**
130
-	 * @inheritdoc
131
-	 */
132
-	public function getChild($name) {
133
-		// Special nodes
134
-		if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
135
-			return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
136
-		}
137
-		if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
138
-			return new Outbox($this->config, $this->principalInfo['uri']);
139
-		}
140
-		if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
141
-			return new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
142
-		}
143
-
144
-		// Calendars
145
-		foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
146
-			if ($calendar['uri'] === $name) {
147
-				return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
148
-			}
149
-		}
150
-
151
-		if ($this->caldavBackend instanceof SubscriptionSupport) {
152
-			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
153
-				if ($subscription['uri'] === $name) {
154
-					if ($this->returnCachedSubscriptions) {
155
-						return new CachedSubscription($this->caldavBackend, $subscription);
156
-					}
157
-
158
-					return new Subscription($this->caldavBackend, $subscription);
159
-				}
160
-			}
161
-		}
162
-
163
-		if (ExternalCalendar::isAppGeneratedCalendar($name)) {
164
-			[$appId, $calendarUri] = ExternalCalendar::splitAppGeneratedCalendarUri($name);
165
-
166
-			foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) {
167
-				/** @var ICalendarProvider $calendarPlugin */
168
-				if ($calendarPlugin->getAppId() !== $appId) {
169
-					continue;
170
-				}
171
-
172
-				if ($calendarPlugin->hasCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri)) {
173
-					return $calendarPlugin->getCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri);
174
-				}
175
-			}
176
-		}
177
-
178
-		throw new NotFound('Node with name \'' . $name . '\' could not be found');
179
-	}
180
-
181
-	/**
182
-	 * @param array $filters
183
-	 * @param integer|null $limit
184
-	 * @param integer|null $offset
185
-	 */
186
-	public function calendarSearch(array $filters, $limit = null, $offset = null) {
187
-		$principalUri = $this->principalInfo['uri'];
188
-		return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset);
189
-	}
190
-
191
-
192
-	public function enableCachedSubscriptionsForThisRequest() {
193
-		$this->returnCachedSubscriptions = true;
194
-	}
45
+    /** @var \OCP\IL10N */
46
+    private $l10n;
47
+
48
+    /** @var \OCP\IConfig */
49
+    private $config;
50
+
51
+    /** @var PluginManager */
52
+    private $pluginManager;
53
+
54
+    /** @var bool */
55
+    private $returnCachedSubscriptions = false;
56
+
57
+    public function __construct(BackendInterface $caldavBackend, $principalInfo) {
58
+        parent::__construct($caldavBackend, $principalInfo);
59
+        $this->l10n = \OC::$server->getL10N('dav');
60
+        $this->config = \OC::$server->getConfig();
61
+        $this->pluginManager = new PluginManager(
62
+            \OC::$server,
63
+            \OC::$server->getAppManager()
64
+        );
65
+    }
66
+
67
+    /**
68
+     * @return BackendInterface
69
+     */
70
+    public function getCalDAVBackend() {
71
+        return $this->caldavBackend;
72
+    }
73
+
74
+    /**
75
+     * @inheritdoc
76
+     */
77
+    public function createExtendedCollection($name, MkCol $mkCol) {
78
+        $reservedNames = [BirthdayService::BIRTHDAY_CALENDAR_URI];
79
+
80
+        if (\in_array($name, $reservedNames, true) || ExternalCalendar::doesViolateReservedName($name)) {
81
+            throw new MethodNotAllowed('The resource you tried to create has a reserved name');
82
+        }
83
+
84
+        parent::createExtendedCollection($name, $mkCol);
85
+    }
86
+
87
+    /**
88
+     * @inheritdoc
89
+     */
90
+    public function getChildren() {
91
+        $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
92
+        $objects = [];
93
+        foreach ($calendars as $calendar) {
94
+            $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
95
+        }
96
+
97
+        if ($this->caldavBackend instanceof SchedulingSupport) {
98
+            $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
99
+            $objects[] = new Outbox($this->config, $this->principalInfo['uri']);
100
+        }
101
+
102
+        // We're adding a notifications node, if it's supported by the backend.
103
+        if ($this->caldavBackend instanceof NotificationSupport) {
104
+            $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
105
+        }
106
+
107
+        // If the backend supports subscriptions, we'll add those as well,
108
+        if ($this->caldavBackend instanceof SubscriptionSupport) {
109
+            foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
110
+                if ($this->returnCachedSubscriptions) {
111
+                    $objects[] = new CachedSubscription($this->caldavBackend, $subscription);
112
+                } else {
113
+                    $objects[] = new Subscription($this->caldavBackend, $subscription);
114
+                }
115
+            }
116
+        }
117
+
118
+        foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) {
119
+            /** @var ICalendarProvider $calendarPlugin */
120
+            $calendars = $calendarPlugin->fetchAllForCalendarHome($this->principalInfo['uri']);
121
+            foreach ($calendars as $calendar) {
122
+                $objects[] = $calendar;
123
+            }
124
+        }
125
+
126
+        return $objects;
127
+    }
128
+
129
+    /**
130
+     * @inheritdoc
131
+     */
132
+    public function getChild($name) {
133
+        // Special nodes
134
+        if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
135
+            return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
136
+        }
137
+        if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
138
+            return new Outbox($this->config, $this->principalInfo['uri']);
139
+        }
140
+        if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
141
+            return new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
142
+        }
143
+
144
+        // Calendars
145
+        foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
146
+            if ($calendar['uri'] === $name) {
147
+                return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
148
+            }
149
+        }
150
+
151
+        if ($this->caldavBackend instanceof SubscriptionSupport) {
152
+            foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
153
+                if ($subscription['uri'] === $name) {
154
+                    if ($this->returnCachedSubscriptions) {
155
+                        return new CachedSubscription($this->caldavBackend, $subscription);
156
+                    }
157
+
158
+                    return new Subscription($this->caldavBackend, $subscription);
159
+                }
160
+            }
161
+        }
162
+
163
+        if (ExternalCalendar::isAppGeneratedCalendar($name)) {
164
+            [$appId, $calendarUri] = ExternalCalendar::splitAppGeneratedCalendarUri($name);
165
+
166
+            foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) {
167
+                /** @var ICalendarProvider $calendarPlugin */
168
+                if ($calendarPlugin->getAppId() !== $appId) {
169
+                    continue;
170
+                }
171
+
172
+                if ($calendarPlugin->hasCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri)) {
173
+                    return $calendarPlugin->getCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri);
174
+                }
175
+            }
176
+        }
177
+
178
+        throw new NotFound('Node with name \'' . $name . '\' could not be found');
179
+    }
180
+
181
+    /**
182
+     * @param array $filters
183
+     * @param integer|null $limit
184
+     * @param integer|null $offset
185
+     */
186
+    public function calendarSearch(array $filters, $limit = null, $offset = null) {
187
+        $principalUri = $this->principalInfo['uri'];
188
+        return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset);
189
+    }
190
+
191
+
192
+    public function enableCachedSubscriptionsForThisRequest() {
193
+        $this->returnCachedSubscriptions = true;
194
+    }
195 195
 }
Please login to merge, or discard this patch.