Completed
Pull Request — master (#9919)
by Robin
244:16 queued 223:02
created
lib/public/IGroup.php 1 patch
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -33,109 +33,109 @@
 block discarded – undo
33 33
  * @since 8.0.0
34 34
  */
35 35
 interface IGroup {
36
-	/**
37
-	 * @return string
38
-	 * @since 8.0.0
39
-	 */
40
-	public function getGID();
36
+    /**
37
+     * @return string
38
+     * @since 8.0.0
39
+     */
40
+    public function getGID();
41 41
 
42
-	/**
43
-	 * Returns the group display name
44
-	 *
45
-	 * @return string
46
-	 * @since 12.0.0
47
-	 */
48
-	public function getDisplayName();
42
+    /**
43
+     * Returns the group display name
44
+     *
45
+     * @return string
46
+     * @since 12.0.0
47
+     */
48
+    public function getDisplayName();
49 49
 
50
-	/**
51
-	 * get all users in the group
52
-	 *
53
-	 * @return \OCP\IUser[]
54
-	 * @since 8.0.0
55
-	 */
56
-	public function getUsers();
50
+    /**
51
+     * get all users in the group
52
+     *
53
+     * @return \OCP\IUser[]
54
+     * @since 8.0.0
55
+     */
56
+    public function getUsers();
57 57
 
58
-	/**
59
-	 * check if a user is in the group
60
-	 *
61
-	 * @param \OCP\IUser $user
62
-	 * @return bool
63
-	 * @since 8.0.0
64
-	 */
65
-	public function inGroup(IUser $user);
58
+    /**
59
+     * check if a user is in the group
60
+     *
61
+     * @param \OCP\IUser $user
62
+     * @return bool
63
+     * @since 8.0.0
64
+     */
65
+    public function inGroup(IUser $user);
66 66
 
67
-	/**
68
-	 * add a user to the group
69
-	 *
70
-	 * @param \OCP\IUser $user
71
-	 * @since 8.0.0
72
-	 */
73
-	public function addUser(IUser $user);
67
+    /**
68
+     * add a user to the group
69
+     *
70
+     * @param \OCP\IUser $user
71
+     * @since 8.0.0
72
+     */
73
+    public function addUser(IUser $user);
74 74
 
75
-	/**
76
-	 * remove a user from the group
77
-	 *
78
-	 * @param \OCP\IUser $user
79
-	 * @since 8.0.0
80
-	 */
81
-	public function removeUser($user);
75
+    /**
76
+     * remove a user from the group
77
+     *
78
+     * @param \OCP\IUser $user
79
+     * @since 8.0.0
80
+     */
81
+    public function removeUser($user);
82 82
 
83
-	/**
84
-	 * search for users in the group by userid
85
-	 *
86
-	 * @param string $search
87
-	 * @param int $limit
88
-	 * @param int $offset
89
-	 * @return \OCP\IUser[]
90
-	 * @since 8.0.0
91
-	 */
92
-	public function searchUsers($search, $limit = null, $offset = null);
83
+    /**
84
+     * search for users in the group by userid
85
+     *
86
+     * @param string $search
87
+     * @param int $limit
88
+     * @param int $offset
89
+     * @return \OCP\IUser[]
90
+     * @since 8.0.0
91
+     */
92
+    public function searchUsers($search, $limit = null, $offset = null);
93 93
 
94
-	/**
95
-	 * returns the number of users matching the search string
96
-	 *
97
-	 * @param string $search
98
-	 * @return int|bool
99
-	 * @since 8.0.0
100
-	 */
101
-	public function count($search = '');
94
+    /**
95
+     * returns the number of users matching the search string
96
+     *
97
+     * @param string $search
98
+     * @return int|bool
99
+     * @since 8.0.0
100
+     */
101
+    public function count($search = '');
102 102
 
103
-	/**
104
-	 * returns the number of disabled users
105
-	 *
106
-	 * @return int|bool
107
-	 * @since 14.0.0
108
-	 */
109
-	public function countDisabled();
103
+    /**
104
+     * returns the number of disabled users
105
+     *
106
+     * @return int|bool
107
+     * @since 14.0.0
108
+     */
109
+    public function countDisabled();
110 110
 
111
-	/**
112
-	 * search for users in the group by displayname
113
-	 *
114
-	 * @param string $search
115
-	 * @param int $limit
116
-	 * @param int $offset
117
-	 * @return \OCP\IUser[]
118
-	 * @since 8.0.0
119
-	 */
120
-	public function searchDisplayName($search, $limit = null, $offset = null);
111
+    /**
112
+     * search for users in the group by displayname
113
+     *
114
+     * @param string $search
115
+     * @param int $limit
116
+     * @param int $offset
117
+     * @return \OCP\IUser[]
118
+     * @since 8.0.0
119
+     */
120
+    public function searchDisplayName($search, $limit = null, $offset = null);
121 121
 
122
-	/**
123
-	 * delete the group
124
-	 *
125
-	 * @return bool
126
-	 * @since 8.0.0
127
-	 */
128
-	public function delete();
122
+    /**
123
+     * delete the group
124
+     *
125
+     * @return bool
126
+     * @since 8.0.0
127
+     */
128
+    public function delete();
129 129
 
130
-	/**
131
-	 * @return bool
132
-	 * @since 14.0.0
133
-	 */
134
-	public function canRemoveUser();
130
+    /**
131
+     * @return bool
132
+     * @since 14.0.0
133
+     */
134
+    public function canRemoveUser();
135 135
 
136
-	/**
137
-	 * @return bool
138
-	 * @since 14.0.0
139
-	 */
140
-	public function canAddUser();
136
+    /**
137
+     * @return bool
138
+     * @since 14.0.0
139
+     */
140
+    public function canAddUser();
141 141
 }
Please login to merge, or discard this patch.
lib/private/Group/Group.php 1 patch
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -36,318 +36,318 @@
 block discarded – undo
36 36
 use OCP\Group\Backend\ICountDisabledInGroup;
37 37
 
38 38
 class Group implements IGroup {
39
-	/** @var null|string  */
40
-	protected $displayName;
39
+    /** @var null|string  */
40
+    protected $displayName;
41 41
 
42
-	/**
43
-	 * @var string $id
44
-	 */
45
-	private $gid;
42
+    /**
43
+     * @var string $id
44
+     */
45
+    private $gid;
46 46
 
47
-	/**
48
-	 * @var \OC\User\User[] $users
49
-	 */
50
-	private $users = array();
47
+    /**
48
+     * @var \OC\User\User[] $users
49
+     */
50
+    private $users = array();
51 51
 
52
-	/**
53
-	 * @var bool $usersLoaded
54
-	 */
55
-	private $usersLoaded;
52
+    /**
53
+     * @var bool $usersLoaded
54
+     */
55
+    private $usersLoaded;
56 56
 
57
-	/**
58
-	 * @var \OC\Group\Backend[]|\OC\Group\Database[] $backend
59
-	 */
60
-	private $backends;
57
+    /**
58
+     * @var \OC\Group\Backend[]|\OC\Group\Database[] $backend
59
+     */
60
+    private $backends;
61 61
 
62
-	/**
63
-	 * @var \OC\Hooks\PublicEmitter $emitter
64
-	 */
65
-	private $emitter;
62
+    /**
63
+     * @var \OC\Hooks\PublicEmitter $emitter
64
+     */
65
+    private $emitter;
66 66
 
67
-	/**
68
-	 * @var \OC\User\Manager $userManager
69
-	 */
70
-	private $userManager;
67
+    /**
68
+     * @var \OC\User\Manager $userManager
69
+     */
70
+    private $userManager;
71 71
 
72
-	/**
73
-	 * @param string $gid
74
-	 * @param \OC\Group\Backend[] $backends
75
-	 * @param \OC\User\Manager $userManager
76
-	 * @param \OC\Hooks\PublicEmitter $emitter
77
-	 * @param string $displayName
78
-	 */
79
-	public function __construct($gid, $backends, $userManager, $emitter = null, $displayName = null) {
80
-		$this->gid = $gid;
81
-		$this->backends = $backends;
82
-		$this->userManager = $userManager;
83
-		$this->emitter = $emitter;
84
-		$this->displayName = $displayName;
85
-	}
72
+    /**
73
+     * @param string $gid
74
+     * @param \OC\Group\Backend[] $backends
75
+     * @param \OC\User\Manager $userManager
76
+     * @param \OC\Hooks\PublicEmitter $emitter
77
+     * @param string $displayName
78
+     */
79
+    public function __construct($gid, $backends, $userManager, $emitter = null, $displayName = null) {
80
+        $this->gid = $gid;
81
+        $this->backends = $backends;
82
+        $this->userManager = $userManager;
83
+        $this->emitter = $emitter;
84
+        $this->displayName = $displayName;
85
+    }
86 86
 
87
-	public function getGID() {
88
-		return $this->gid;
89
-	}
87
+    public function getGID() {
88
+        return $this->gid;
89
+    }
90 90
 
91
-	public function getDisplayName() {
92
-		if (is_null($this->displayName)) {
93
-			return $this->gid;
94
-		}
95
-		return $this->displayName;
96
-	}
91
+    public function getDisplayName() {
92
+        if (is_null($this->displayName)) {
93
+            return $this->gid;
94
+        }
95
+        return $this->displayName;
96
+    }
97 97
 
98
-	/**
99
-	 * get all users in the group
100
-	 *
101
-	 * @return \OC\User\User[]
102
-	 */
103
-	public function getUsers() {
104
-		if ($this->usersLoaded) {
105
-			return $this->users;
106
-		}
98
+    /**
99
+     * get all users in the group
100
+     *
101
+     * @return \OC\User\User[]
102
+     */
103
+    public function getUsers() {
104
+        if ($this->usersLoaded) {
105
+            return $this->users;
106
+        }
107 107
 
108
-		$userIds = array();
109
-		foreach ($this->backends as $backend) {
110
-			$diff = array_diff(
111
-				$backend->usersInGroup($this->gid),
112
-				$userIds
113
-			);
114
-			if ($diff) {
115
-				$userIds = array_merge($userIds, $diff);
116
-			}
117
-		}
108
+        $userIds = array();
109
+        foreach ($this->backends as $backend) {
110
+            $diff = array_diff(
111
+                $backend->usersInGroup($this->gid),
112
+                $userIds
113
+            );
114
+            if ($diff) {
115
+                $userIds = array_merge($userIds, $diff);
116
+            }
117
+        }
118 118
 
119
-		$this->users = $this->getVerifiedUsers($userIds);
120
-		$this->usersLoaded = true;
121
-		return $this->users;
122
-	}
119
+        $this->users = $this->getVerifiedUsers($userIds);
120
+        $this->usersLoaded = true;
121
+        return $this->users;
122
+    }
123 123
 
124
-	/**
125
-	 * check if a user is in the group
126
-	 *
127
-	 * @param IUser $user
128
-	 * @return bool
129
-	 */
130
-	public function inGroup(IUser $user) {
131
-		if (isset($this->users[$user->getUID()])) {
132
-			return true;
133
-		}
134
-		foreach ($this->backends as $backend) {
135
-			if ($backend->inGroup($user->getUID(), $this->gid)) {
136
-				$this->users[$user->getUID()] = $user;
137
-				return true;
138
-			}
139
-		}
140
-		return false;
141
-	}
124
+    /**
125
+     * check if a user is in the group
126
+     *
127
+     * @param IUser $user
128
+     * @return bool
129
+     */
130
+    public function inGroup(IUser $user) {
131
+        if (isset($this->users[$user->getUID()])) {
132
+            return true;
133
+        }
134
+        foreach ($this->backends as $backend) {
135
+            if ($backend->inGroup($user->getUID(), $this->gid)) {
136
+                $this->users[$user->getUID()] = $user;
137
+                return true;
138
+            }
139
+        }
140
+        return false;
141
+    }
142 142
 
143
-	/**
144
-	 * add a user to the group
145
-	 *
146
-	 * @param IUser $user
147
-	 */
148
-	public function addUser(IUser $user) {
149
-		if ($this->inGroup($user)) {
150
-			return;
151
-		}
143
+    /**
144
+     * add a user to the group
145
+     *
146
+     * @param IUser $user
147
+     */
148
+    public function addUser(IUser $user) {
149
+        if ($this->inGroup($user)) {
150
+            return;
151
+        }
152 152
 
153
-		if ($this->emitter) {
154
-			$this->emitter->emit('\OC\Group', 'preAddUser', array($this, $user));
155
-		}
156
-		foreach ($this->backends as $backend) {
157
-			if ($backend->implementsActions(\OC\Group\Backend::ADD_TO_GROUP)) {
158
-				$backend->addToGroup($user->getUID(), $this->gid);
159
-				if ($this->users) {
160
-					$this->users[$user->getUID()] = $user;
161
-				}
162
-				if ($this->emitter) {
163
-					$this->emitter->emit('\OC\Group', 'postAddUser', array($this, $user));
164
-				}
165
-				return;
166
-			}
167
-		}
168
-	}
153
+        if ($this->emitter) {
154
+            $this->emitter->emit('\OC\Group', 'preAddUser', array($this, $user));
155
+        }
156
+        foreach ($this->backends as $backend) {
157
+            if ($backend->implementsActions(\OC\Group\Backend::ADD_TO_GROUP)) {
158
+                $backend->addToGroup($user->getUID(), $this->gid);
159
+                if ($this->users) {
160
+                    $this->users[$user->getUID()] = $user;
161
+                }
162
+                if ($this->emitter) {
163
+                    $this->emitter->emit('\OC\Group', 'postAddUser', array($this, $user));
164
+                }
165
+                return;
166
+            }
167
+        }
168
+    }
169 169
 
170
-	/**
171
-	 * remove a user from the group
172
-	 *
173
-	 * @param \OC\User\User $user
174
-	 */
175
-	public function removeUser($user) {
176
-		$result = false;
177
-		if ($this->emitter) {
178
-			$this->emitter->emit('\OC\Group', 'preRemoveUser', array($this, $user));
179
-		}
180
-		foreach ($this->backends as $backend) {
181
-			if ($backend->implementsActions(\OC\Group\Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) {
182
-				$backend->removeFromGroup($user->getUID(), $this->gid);
183
-				$result = true;
184
-			}
185
-		}
186
-		if ($result) {
187
-			if ($this->emitter) {
188
-				$this->emitter->emit('\OC\Group', 'postRemoveUser', array($this, $user));
189
-			}
190
-			if ($this->users) {
191
-				foreach ($this->users as $index => $groupUser) {
192
-					if ($groupUser->getUID() === $user->getUID()) {
193
-						unset($this->users[$index]);
194
-						return;
195
-					}
196
-				}
197
-			}
198
-		}
199
-	}
170
+    /**
171
+     * remove a user from the group
172
+     *
173
+     * @param \OC\User\User $user
174
+     */
175
+    public function removeUser($user) {
176
+        $result = false;
177
+        if ($this->emitter) {
178
+            $this->emitter->emit('\OC\Group', 'preRemoveUser', array($this, $user));
179
+        }
180
+        foreach ($this->backends as $backend) {
181
+            if ($backend->implementsActions(\OC\Group\Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) {
182
+                $backend->removeFromGroup($user->getUID(), $this->gid);
183
+                $result = true;
184
+            }
185
+        }
186
+        if ($result) {
187
+            if ($this->emitter) {
188
+                $this->emitter->emit('\OC\Group', 'postRemoveUser', array($this, $user));
189
+            }
190
+            if ($this->users) {
191
+                foreach ($this->users as $index => $groupUser) {
192
+                    if ($groupUser->getUID() === $user->getUID()) {
193
+                        unset($this->users[$index]);
194
+                        return;
195
+                    }
196
+                }
197
+            }
198
+        }
199
+    }
200 200
 
201
-	/**
202
-	 * search for users in the group by userid
203
-	 *
204
-	 * @param string $search
205
-	 * @param int $limit
206
-	 * @param int $offset
207
-	 * @return \OC\User\User[]
208
-	 */
209
-	public function searchUsers($search, $limit = null, $offset = null) {
210
-		$users = array();
211
-		foreach ($this->backends as $backend) {
212
-			$userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset);
213
-			$users += $this->getVerifiedUsers($userIds);
214
-			if (!is_null($limit) and $limit <= 0) {
215
-				return $users;
216
-			}
217
-		}
218
-		return $users;
219
-	}
201
+    /**
202
+     * search for users in the group by userid
203
+     *
204
+     * @param string $search
205
+     * @param int $limit
206
+     * @param int $offset
207
+     * @return \OC\User\User[]
208
+     */
209
+    public function searchUsers($search, $limit = null, $offset = null) {
210
+        $users = array();
211
+        foreach ($this->backends as $backend) {
212
+            $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset);
213
+            $users += $this->getVerifiedUsers($userIds);
214
+            if (!is_null($limit) and $limit <= 0) {
215
+                return $users;
216
+            }
217
+        }
218
+        return $users;
219
+    }
220 220
 
221
-	/**
222
-	 * returns the number of users matching the search string
223
-	 *
224
-	 * @param string $search
225
-	 * @return int|bool
226
-	 */
227
-	public function count($search = '') {
228
-		$users = false;
229
-		foreach ($this->backends as $backend) {
230
-			if($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) {
231
-				if($users === false) {
232
-					//we could directly add to a bool variable, but this would
233
-					//be ugly
234
-					$users = 0;
235
-				}
236
-				$users += $backend->countUsersInGroup($this->gid, $search);
237
-			}
238
-		}
239
-		return $users;
240
-	}
221
+    /**
222
+     * returns the number of users matching the search string
223
+     *
224
+     * @param string $search
225
+     * @return int|bool
226
+     */
227
+    public function count($search = '') {
228
+        $users = false;
229
+        foreach ($this->backends as $backend) {
230
+            if($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) {
231
+                if($users === false) {
232
+                    //we could directly add to a bool variable, but this would
233
+                    //be ugly
234
+                    $users = 0;
235
+                }
236
+                $users += $backend->countUsersInGroup($this->gid, $search);
237
+            }
238
+        }
239
+        return $users;
240
+    }
241 241
 
242
-	/**
243
-	 * returns the number of disabled users
244
-	 *
245
-	 * @return int|bool
246
-	 */
247
-	public function countDisabled() {
248
-		$users = false;
249
-		foreach ($this->backends as $backend) {
250
-			if($backend instanceOf ICountDisabledInGroup) {
251
-				if($users === false) {
252
-					//we could directly add to a bool variable, but this would
253
-					//be ugly
254
-					$users = 0;
255
-				}
256
-				$users += $backend->countDisabledInGroup($this->gid);
257
-			}
258
-		}
259
-		return $users;
260
-	}
242
+    /**
243
+     * returns the number of disabled users
244
+     *
245
+     * @return int|bool
246
+     */
247
+    public function countDisabled() {
248
+        $users = false;
249
+        foreach ($this->backends as $backend) {
250
+            if($backend instanceOf ICountDisabledInGroup) {
251
+                if($users === false) {
252
+                    //we could directly add to a bool variable, but this would
253
+                    //be ugly
254
+                    $users = 0;
255
+                }
256
+                $users += $backend->countDisabledInGroup($this->gid);
257
+            }
258
+        }
259
+        return $users;
260
+    }
261 261
 
262
-	/**
263
-	 * search for users in the group by displayname
264
-	 *
265
-	 * @param string $search
266
-	 * @param int $limit
267
-	 * @param int $offset
268
-	 * @return \OC\User\User[]
269
-	 */
270
-	public function searchDisplayName($search, $limit = null, $offset = null) {
271
-		$users = array();
272
-		foreach ($this->backends as $backend) {
273
-			$userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset);
274
-			$users = $this->getVerifiedUsers($userIds);
275
-			if (!is_null($limit) and $limit <= 0) {
276
-				return array_values($users);
277
-			}
278
-		}
279
-		return array_values($users);
280
-	}
262
+    /**
263
+     * search for users in the group by displayname
264
+     *
265
+     * @param string $search
266
+     * @param int $limit
267
+     * @param int $offset
268
+     * @return \OC\User\User[]
269
+     */
270
+    public function searchDisplayName($search, $limit = null, $offset = null) {
271
+        $users = array();
272
+        foreach ($this->backends as $backend) {
273
+            $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset);
274
+            $users = $this->getVerifiedUsers($userIds);
275
+            if (!is_null($limit) and $limit <= 0) {
276
+                return array_values($users);
277
+            }
278
+        }
279
+        return array_values($users);
280
+    }
281 281
 
282
-	/**
283
-	 * delete the group
284
-	 *
285
-	 * @return bool
286
-	 */
287
-	public function delete() {
288
-		// Prevent users from deleting group admin
289
-		if ($this->getGID() === 'admin') {
290
-			return false;
291
-		}
282
+    /**
283
+     * delete the group
284
+     *
285
+     * @return bool
286
+     */
287
+    public function delete() {
288
+        // Prevent users from deleting group admin
289
+        if ($this->getGID() === 'admin') {
290
+            return false;
291
+        }
292 292
 
293
-		$result = false;
294
-		if ($this->emitter) {
295
-			$this->emitter->emit('\OC\Group', 'preDelete', array($this));
296
-		}
297
-		foreach ($this->backends as $backend) {
298
-			if ($backend->implementsActions(\OC\Group\Backend::DELETE_GROUP)) {
299
-				$result = true;
300
-				$backend->deleteGroup($this->gid);
301
-			}
302
-		}
303
-		if ($result and $this->emitter) {
304
-			$this->emitter->emit('\OC\Group', 'postDelete', array($this));
305
-		}
306
-		return $result;
307
-	}
293
+        $result = false;
294
+        if ($this->emitter) {
295
+            $this->emitter->emit('\OC\Group', 'preDelete', array($this));
296
+        }
297
+        foreach ($this->backends as $backend) {
298
+            if ($backend->implementsActions(\OC\Group\Backend::DELETE_GROUP)) {
299
+                $result = true;
300
+                $backend->deleteGroup($this->gid);
301
+            }
302
+        }
303
+        if ($result and $this->emitter) {
304
+            $this->emitter->emit('\OC\Group', 'postDelete', array($this));
305
+        }
306
+        return $result;
307
+    }
308 308
 
309
-	/**
310
-	 * returns all the Users from an array that really exists
311
-	 * @param string[] $userIds an array containing user IDs
312
-	 * @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value
313
-	 */
314
-	private function getVerifiedUsers($userIds) {
315
-		if (!is_array($userIds)) {
316
-			return array();
317
-		}
318
-		$users = array();
319
-		foreach ($userIds as $userId) {
320
-			$user = $this->userManager->get($userId);
321
-			if (!is_null($user)) {
322
-				$users[$userId] = $user;
323
-			}
324
-		}
325
-		return $users;
326
-	}
309
+    /**
310
+     * returns all the Users from an array that really exists
311
+     * @param string[] $userIds an array containing user IDs
312
+     * @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value
313
+     */
314
+    private function getVerifiedUsers($userIds) {
315
+        if (!is_array($userIds)) {
316
+            return array();
317
+        }
318
+        $users = array();
319
+        foreach ($userIds as $userId) {
320
+            $user = $this->userManager->get($userId);
321
+            if (!is_null($user)) {
322
+                $users[$userId] = $user;
323
+            }
324
+        }
325
+        return $users;
326
+    }
327 327
 
328
-	/**
329
-	 * @return bool
330
-	 * @since 14.0.0
331
-	 */
332
-	public function canRemoveUser() {
333
-		foreach ($this->backends as $backend) {
334
-			if ($backend->implementsActions(GroupInterface::REMOVE_FROM_GOUP)) {
335
-				return true;
336
-			}
337
-		}
338
-		return false;
339
-	}
328
+    /**
329
+     * @return bool
330
+     * @since 14.0.0
331
+     */
332
+    public function canRemoveUser() {
333
+        foreach ($this->backends as $backend) {
334
+            if ($backend->implementsActions(GroupInterface::REMOVE_FROM_GOUP)) {
335
+                return true;
336
+            }
337
+        }
338
+        return false;
339
+    }
340 340
 
341
-	/**
342
-	 * @return bool
343
-	 * @since 14.0.0
344
-	 */
345
-	public function canAddUser() {
346
-		foreach ($this->backends as $backend) {
347
-			if ($backend->implementsActions(GroupInterface::ADD_TO_GROUP)) {
348
-				return true;
349
-			}
350
-		}
351
-		return false;
352
-	}
341
+    /**
342
+     * @return bool
343
+     * @since 14.0.0
344
+     */
345
+    public function canAddUser() {
346
+        foreach ($this->backends as $backend) {
347
+            if ($backend->implementsActions(GroupInterface::ADD_TO_GROUP)) {
348
+                return true;
349
+            }
350
+        }
351
+        return false;
352
+    }
353 353
 }
Please login to merge, or discard this patch.
lib/private/Group/MetaData.php 1 patch
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -32,176 +32,176 @@
 block discarded – undo
32 32
 use OCP\IGroupManager;
33 33
 
34 34
 class MetaData {
35
-	const SORT_NONE = 0;
36
-	const SORT_USERCOUNT = 1; // May have performance issues on LDAP backends
37
-	const SORT_GROUPNAME = 2;
38
-
39
-	/** @var string */
40
-	protected $user;
41
-	/** @var bool */
42
-	protected $isAdmin;
43
-	/** @var array */
44
-	protected $metaData = array();
45
-	/** @var IGroupManager */
46
-	protected $groupManager;
47
-	/** @var bool */
48
-	protected $sorting = false;
49
-	/** @var IUserSession */
50
-	protected $userSession;
51
-
52
-	/**
53
-	 * @param string $user the uid of the current user
54
-	 * @param bool $isAdmin whether the current users is an admin
55
-	 * @param IGroupManager $groupManager
56
-	 * @param IUserManager $userManager
57
-	 * @param IUserSession $userSession
58
-	 */
59
-	public function __construct(
60
-			$user,
61
-			$isAdmin,
62
-			IGroupManager $groupManager,
63
-			IUserSession $userSession
64
-			) {
65
-		$this->user = $user;
66
-		$this->isAdmin = (bool)$isAdmin;
67
-		$this->groupManager = $groupManager;
68
-		$this->userSession = $userSession;
69
-	}
70
-
71
-	/**
72
-	 * returns an array with meta data about all available groups
73
-	 * the array is structured as follows:
74
-	 * [0] array containing meta data about admin groups
75
-	 * [1] array containing meta data about unprivileged groups
76
-	 * @param string $groupSearch only effective when instance was created with
77
-	 * isAdmin being true
78
-	 * @param string $userSearch the pattern users are search for
79
-	 * @return array
80
-	 */
81
-	public function get($groupSearch = '', $userSearch = '') {
82
-		$key = $groupSearch . '::' . $userSearch;
83
-		if(isset($this->metaData[$key])) {
84
-			return $this->metaData[$key];
85
-		}
86
-
87
-		$adminGroups = array();
88
-		$groups = array();
89
-		$sortGroupsIndex = 0;
90
-		$sortGroupsKeys = array();
91
-		$sortAdminGroupsIndex = 0;
92
-		$sortAdminGroupsKeys = array();
93
-
94
-		foreach($this->getGroups($groupSearch) as $group) {
95
-			$groupMetaData = $this->generateGroupMetaData($group, $userSearch);
96
-			if (strtolower($group->getGID()) !== 'admin') {
97
-				$this->addEntry(
98
-					$groups,
99
-					$sortGroupsKeys,
100
-					$sortGroupsIndex,
101
-					$groupMetaData);
102
-			} else {
103
-				//admin group is hard coded to 'admin' for now. In future,
104
-				//backends may define admin groups too. Then the if statement
105
-				//has to be adjusted accordingly.
106
-				$this->addEntry(
107
-					$adminGroups,
108
-					$sortAdminGroupsKeys,
109
-					$sortAdminGroupsIndex,
110
-					$groupMetaData);
111
-			}
112
-		}
113
-
114
-		//whether sorting is necessary is will be checked in sort()
115
-		$this->sort($groups, $sortGroupsKeys);
116
-		$this->sort($adminGroups, $sortAdminGroupsKeys);
117
-
118
-		$this->metaData[$key] = array($adminGroups, $groups);
119
-		return $this->metaData[$key];
120
-	}
121
-
122
-	/**
123
-	 * sets the sort mode, see SORT_* constants for supported modes
124
-	 *
125
-	 * @param int $sortMode
126
-	 */
127
-	public function setSorting($sortMode) {
128
-		switch ($sortMode) {
129
-			case self::SORT_USERCOUNT:
130
-			case self::SORT_GROUPNAME:
131
-				$this->sorting = $sortMode;
132
-				break;
133
-
134
-			default:
135
-				$this->sorting = self::SORT_NONE;
136
-		}
137
-	}
138
-
139
-	/**
140
-	 * adds an group entry to the resulting array
141
-	 * @param array $entries the resulting array, by reference
142
-	 * @param array $sortKeys the sort key array, by reference
143
-	 * @param int $sortIndex the sort key index, by reference
144
-	 * @param array $data the group's meta data as returned by generateGroupMetaData()
145
-	 */
146
-	private function addEntry(&$entries, &$sortKeys, &$sortIndex, $data) {
147
-		$entries[] = $data;
148
-		if ($this->sorting === self::SORT_USERCOUNT) {
149
-			$sortKeys[$sortIndex] = $data['usercount'];
150
-			$sortIndex++;
151
-		} else if ($this->sorting === self::SORT_GROUPNAME) {
152
-			$sortKeys[$sortIndex] = $data['name'];
153
-			$sortIndex++;
154
-		}
155
-	}
156
-
157
-	/**
158
-	 * creates an array containing the group meta data
159
-	 * @param \OCP\IGroup $group
160
-	 * @param string $userSearch
161
-	 * @return array with the keys 'id', 'name', 'usercount' and 'disabled'
162
-	 */
163
-	private function generateGroupMetaData(\OCP\IGroup $group, $userSearch) {
164
-		return array(
165
-				'id' => $group->getGID(),
166
-				'name' => $group->getDisplayName(),
167
-				'usercount' => $this->sorting === self::SORT_USERCOUNT ? $group->count($userSearch) : 0,
168
-				'disabled' => $group->countDisabled(),
169
-				'canAdd' => $group->canAddUser(),
170
-				'canRemove' => $group->canRemoveUser(),
171
-			);
172
-	}
173
-
174
-	/**
175
-	 * sorts the result array, if applicable
176
-	 * @param array $entries the result array, by reference
177
-	 * @param array $sortKeys the array containing the sort keys
178
-	 * @param return null
179
-	 */
180
-	private function sort(&$entries, $sortKeys) {
181
-		if ($this->sorting === self::SORT_USERCOUNT) {
182
-			array_multisort($sortKeys, SORT_DESC, $entries);
183
-		} else if ($this->sorting === self::SORT_GROUPNAME) {
184
-			array_multisort($sortKeys, SORT_ASC, $entries);
185
-		}
186
-	}
187
-
188
-	/**
189
-	 * returns the available groups
190
-	 * @param string $search a search string
191
-	 * @return \OCP\IGroup[]
192
-	 */
193
-	public function getGroups($search = '') {
194
-		if($this->isAdmin) {
195
-			return $this->groupManager->search($search);
196
-		} else {
197
-			$userObject = $this->userSession->getUser();
198
-			if($userObject !== null) {
199
-				$groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($userObject);
200
-			} else {
201
-				$groups = [];
202
-			}
203
-
204
-			return $groups;
205
-		}
206
-	}
35
+    const SORT_NONE = 0;
36
+    const SORT_USERCOUNT = 1; // May have performance issues on LDAP backends
37
+    const SORT_GROUPNAME = 2;
38
+
39
+    /** @var string */
40
+    protected $user;
41
+    /** @var bool */
42
+    protected $isAdmin;
43
+    /** @var array */
44
+    protected $metaData = array();
45
+    /** @var IGroupManager */
46
+    protected $groupManager;
47
+    /** @var bool */
48
+    protected $sorting = false;
49
+    /** @var IUserSession */
50
+    protected $userSession;
51
+
52
+    /**
53
+     * @param string $user the uid of the current user
54
+     * @param bool $isAdmin whether the current users is an admin
55
+     * @param IGroupManager $groupManager
56
+     * @param IUserManager $userManager
57
+     * @param IUserSession $userSession
58
+     */
59
+    public function __construct(
60
+            $user,
61
+            $isAdmin,
62
+            IGroupManager $groupManager,
63
+            IUserSession $userSession
64
+            ) {
65
+        $this->user = $user;
66
+        $this->isAdmin = (bool)$isAdmin;
67
+        $this->groupManager = $groupManager;
68
+        $this->userSession = $userSession;
69
+    }
70
+
71
+    /**
72
+     * returns an array with meta data about all available groups
73
+     * the array is structured as follows:
74
+     * [0] array containing meta data about admin groups
75
+     * [1] array containing meta data about unprivileged groups
76
+     * @param string $groupSearch only effective when instance was created with
77
+     * isAdmin being true
78
+     * @param string $userSearch the pattern users are search for
79
+     * @return array
80
+     */
81
+    public function get($groupSearch = '', $userSearch = '') {
82
+        $key = $groupSearch . '::' . $userSearch;
83
+        if(isset($this->metaData[$key])) {
84
+            return $this->metaData[$key];
85
+        }
86
+
87
+        $adminGroups = array();
88
+        $groups = array();
89
+        $sortGroupsIndex = 0;
90
+        $sortGroupsKeys = array();
91
+        $sortAdminGroupsIndex = 0;
92
+        $sortAdminGroupsKeys = array();
93
+
94
+        foreach($this->getGroups($groupSearch) as $group) {
95
+            $groupMetaData = $this->generateGroupMetaData($group, $userSearch);
96
+            if (strtolower($group->getGID()) !== 'admin') {
97
+                $this->addEntry(
98
+                    $groups,
99
+                    $sortGroupsKeys,
100
+                    $sortGroupsIndex,
101
+                    $groupMetaData);
102
+            } else {
103
+                //admin group is hard coded to 'admin' for now. In future,
104
+                //backends may define admin groups too. Then the if statement
105
+                //has to be adjusted accordingly.
106
+                $this->addEntry(
107
+                    $adminGroups,
108
+                    $sortAdminGroupsKeys,
109
+                    $sortAdminGroupsIndex,
110
+                    $groupMetaData);
111
+            }
112
+        }
113
+
114
+        //whether sorting is necessary is will be checked in sort()
115
+        $this->sort($groups, $sortGroupsKeys);
116
+        $this->sort($adminGroups, $sortAdminGroupsKeys);
117
+
118
+        $this->metaData[$key] = array($adminGroups, $groups);
119
+        return $this->metaData[$key];
120
+    }
121
+
122
+    /**
123
+     * sets the sort mode, see SORT_* constants for supported modes
124
+     *
125
+     * @param int $sortMode
126
+     */
127
+    public function setSorting($sortMode) {
128
+        switch ($sortMode) {
129
+            case self::SORT_USERCOUNT:
130
+            case self::SORT_GROUPNAME:
131
+                $this->sorting = $sortMode;
132
+                break;
133
+
134
+            default:
135
+                $this->sorting = self::SORT_NONE;
136
+        }
137
+    }
138
+
139
+    /**
140
+     * adds an group entry to the resulting array
141
+     * @param array $entries the resulting array, by reference
142
+     * @param array $sortKeys the sort key array, by reference
143
+     * @param int $sortIndex the sort key index, by reference
144
+     * @param array $data the group's meta data as returned by generateGroupMetaData()
145
+     */
146
+    private function addEntry(&$entries, &$sortKeys, &$sortIndex, $data) {
147
+        $entries[] = $data;
148
+        if ($this->sorting === self::SORT_USERCOUNT) {
149
+            $sortKeys[$sortIndex] = $data['usercount'];
150
+            $sortIndex++;
151
+        } else if ($this->sorting === self::SORT_GROUPNAME) {
152
+            $sortKeys[$sortIndex] = $data['name'];
153
+            $sortIndex++;
154
+        }
155
+    }
156
+
157
+    /**
158
+     * creates an array containing the group meta data
159
+     * @param \OCP\IGroup $group
160
+     * @param string $userSearch
161
+     * @return array with the keys 'id', 'name', 'usercount' and 'disabled'
162
+     */
163
+    private function generateGroupMetaData(\OCP\IGroup $group, $userSearch) {
164
+        return array(
165
+                'id' => $group->getGID(),
166
+                'name' => $group->getDisplayName(),
167
+                'usercount' => $this->sorting === self::SORT_USERCOUNT ? $group->count($userSearch) : 0,
168
+                'disabled' => $group->countDisabled(),
169
+                'canAdd' => $group->canAddUser(),
170
+                'canRemove' => $group->canRemoveUser(),
171
+            );
172
+    }
173
+
174
+    /**
175
+     * sorts the result array, if applicable
176
+     * @param array $entries the result array, by reference
177
+     * @param array $sortKeys the array containing the sort keys
178
+     * @param return null
179
+     */
180
+    private function sort(&$entries, $sortKeys) {
181
+        if ($this->sorting === self::SORT_USERCOUNT) {
182
+            array_multisort($sortKeys, SORT_DESC, $entries);
183
+        } else if ($this->sorting === self::SORT_GROUPNAME) {
184
+            array_multisort($sortKeys, SORT_ASC, $entries);
185
+        }
186
+    }
187
+
188
+    /**
189
+     * returns the available groups
190
+     * @param string $search a search string
191
+     * @return \OCP\IGroup[]
192
+     */
193
+    public function getGroups($search = '') {
194
+        if($this->isAdmin) {
195
+            return $this->groupManager->search($search);
196
+        } else {
197
+            $userObject = $this->userSession->getUser();
198
+            if($userObject !== null) {
199
+                $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($userObject);
200
+            } else {
201
+                $groups = [];
202
+            }
203
+
204
+            return $groups;
205
+        }
206
+    }
207 207
 }
Please login to merge, or discard this patch.