Passed
Push — master ( 3d306b...237a49 )
by Morris
12:39 queued 02:23
created
apps/dav/lib/CalDAV/Schedule/Plugin.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -34,105 +34,105 @@
 block discarded – undo
34 34
 
35 35
 class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
36 36
 
37
-	/**
38
-	 * Initializes the plugin
39
-	 *
40
-	 * @param Server $server
41
-	 * @return void
42
-	 */
43
-	function initialize(Server $server) {
44
-		parent::initialize($server);
45
-		$server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
46
-	}
47
-
48
-	/**
49
-	 * This method handler is invoked during fetching of properties.
50
-	 *
51
-	 * We use this event to add calendar-auto-schedule-specific properties.
52
-	 *
53
-	 * @param PropFind $propFind
54
-	 * @param INode $node
55
-	 * @return void
56
-	 */
57
-	function propFind(PropFind $propFind, INode $node) {
58
-		// overwrite Sabre/Dav's implementation
59
-		$propFind->handle('{' . self::NS_CALDAV . '}calendar-user-type', function() use ($node) {
60
-			$calendarUserType = '{' . self::NS_CALDAV . '}calendar-user-type';
61
-			$props = $node->getProperties([$calendarUserType]);
62
-
63
-			if (isset($props[$calendarUserType])) {
64
-				return $props[$calendarUserType];
65
-			}
66
-
67
-			return 'INDIVIDUAL';
68
-		});
69
-
70
-		parent::propFind($propFind, $node);
71
-	}
72
-
73
-	/**
74
-	 * Returns a list of addresses that are associated with a principal.
75
-	 *
76
-	 * @param string $principal
77
-	 * @return array
78
-	 */
79
-	protected function getAddressesForPrincipal($principal) {
80
-		$result = parent::getAddressesForPrincipal($principal);
81
-
82
-		if ($result === null) {
83
-			$result = [];
84
-		}
85
-
86
-		return $result;
87
-	}
88
-
89
-	/**
90
-	 * Always use the personal calendar as target for scheduled events
91
-	 *
92
-	 * @param PropFind $propFind
93
-	 * @param INode $node
94
-	 * @return void
95
-	 */
96
-	function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
97
-		if ($node instanceof IPrincipal) {
98
-			$propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($node) {
99
-				/** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
100
-				$caldavPlugin = $this->server->getPlugin('caldav');
101
-				$principalUrl = $node->getPrincipalUrl();
102
-
103
-				$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
104
-				if (!$calendarHomePath) {
105
-					return null;
106
-				}
107
-
108
-				if (strpos($principalUrl, 'principals/users') === 0) {
109
-					$uri = CalDavBackend::PERSONAL_CALENDAR_URI;
110
-					$displayname = CalDavBackend::PERSONAL_CALENDAR_NAME;
111
-				} elseif (strpos($principalUrl, 'principals/calendar-resources') === 0 ||
112
-						  strpos($principalUrl, 'principals/calendar-rooms') === 0) {
113
-					$uri = CalDavBackend::RESOURCE_BOOKING_CALENDAR_URI;
114
-					$displayname = CalDavBackend::RESOURCE_BOOKING_CALENDAR_NAME;
115
-				} else {
116
-					// How did we end up here?
117
-					// TODO - throw exception or just ignore?
118
-					return null;
119
-				}
120
-
121
-				/** @var CalendarHome $calendarHome */
122
-				$calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
123
-				if (!$calendarHome->childExists($uri)) {
124
-					$calendarHome->getCalDAVBackend()->createCalendar($principalUrl, $uri, [
125
-						'{DAV:}displayname' => $displayname,
126
-					]);
127
-				}
128
-
129
-				$result = $this->server->getPropertiesForPath($calendarHomePath . '/' . $uri, [], 1);
130
-				if (empty($result)) {
131
-					return null;
132
-				}
133
-
134
-				return new LocalHref($result[0]['href']);
135
-			});
136
-		}
137
-	}
37
+    /**
38
+     * Initializes the plugin
39
+     *
40
+     * @param Server $server
41
+     * @return void
42
+     */
43
+    function initialize(Server $server) {
44
+        parent::initialize($server);
45
+        $server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
46
+    }
47
+
48
+    /**
49
+     * This method handler is invoked during fetching of properties.
50
+     *
51
+     * We use this event to add calendar-auto-schedule-specific properties.
52
+     *
53
+     * @param PropFind $propFind
54
+     * @param INode $node
55
+     * @return void
56
+     */
57
+    function propFind(PropFind $propFind, INode $node) {
58
+        // overwrite Sabre/Dav's implementation
59
+        $propFind->handle('{' . self::NS_CALDAV . '}calendar-user-type', function() use ($node) {
60
+            $calendarUserType = '{' . self::NS_CALDAV . '}calendar-user-type';
61
+            $props = $node->getProperties([$calendarUserType]);
62
+
63
+            if (isset($props[$calendarUserType])) {
64
+                return $props[$calendarUserType];
65
+            }
66
+
67
+            return 'INDIVIDUAL';
68
+        });
69
+
70
+        parent::propFind($propFind, $node);
71
+    }
72
+
73
+    /**
74
+     * Returns a list of addresses that are associated with a principal.
75
+     *
76
+     * @param string $principal
77
+     * @return array
78
+     */
79
+    protected function getAddressesForPrincipal($principal) {
80
+        $result = parent::getAddressesForPrincipal($principal);
81
+
82
+        if ($result === null) {
83
+            $result = [];
84
+        }
85
+
86
+        return $result;
87
+    }
88
+
89
+    /**
90
+     * Always use the personal calendar as target for scheduled events
91
+     *
92
+     * @param PropFind $propFind
93
+     * @param INode $node
94
+     * @return void
95
+     */
96
+    function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
97
+        if ($node instanceof IPrincipal) {
98
+            $propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($node) {
99
+                /** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
100
+                $caldavPlugin = $this->server->getPlugin('caldav');
101
+                $principalUrl = $node->getPrincipalUrl();
102
+
103
+                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
104
+                if (!$calendarHomePath) {
105
+                    return null;
106
+                }
107
+
108
+                if (strpos($principalUrl, 'principals/users') === 0) {
109
+                    $uri = CalDavBackend::PERSONAL_CALENDAR_URI;
110
+                    $displayname = CalDavBackend::PERSONAL_CALENDAR_NAME;
111
+                } elseif (strpos($principalUrl, 'principals/calendar-resources') === 0 ||
112
+                          strpos($principalUrl, 'principals/calendar-rooms') === 0) {
113
+                    $uri = CalDavBackend::RESOURCE_BOOKING_CALENDAR_URI;
114
+                    $displayname = CalDavBackend::RESOURCE_BOOKING_CALENDAR_NAME;
115
+                } else {
116
+                    // How did we end up here?
117
+                    // TODO - throw exception or just ignore?
118
+                    return null;
119
+                }
120
+
121
+                /** @var CalendarHome $calendarHome */
122
+                $calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
123
+                if (!$calendarHome->childExists($uri)) {
124
+                    $calendarHome->getCalDAVBackend()->createCalendar($principalUrl, $uri, [
125
+                        '{DAV:}displayname' => $displayname,
126
+                    ]);
127
+                }
128
+
129
+                $result = $this->server->getPropertiesForPath($calendarHomePath . '/' . $uri, [], 1);
130
+                if (empty($result)) {
131
+                    return null;
132
+                }
133
+
134
+                return new LocalHref($result[0]['href']);
135
+            });
136
+        }
137
+    }
138 138
 }
Please login to merge, or discard this patch.