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