Completed
Pull Request — master (#9029)
by Julius
15:02
created
lib/private/Settings/Manager.php 1 patch
Indentation   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -49,359 +49,359 @@
 block discarded – undo
49 49
 use OCP\Util;
50 50
 
51 51
 class Manager implements IManager {
52
-	/** @var ILogger */
53
-	private $log;
54
-	/** @var IDBConnection */
55
-	private $dbc;
56
-	/** @var IL10N */
57
-	private $l;
58
-	/** @var IConfig */
59
-	private $config;
60
-	/** @var EncryptionManager */
61
-	private $encryptionManager;
62
-	/** @var IUserManager */
63
-	private $userManager;
64
-	/** @var ILockingProvider */
65
-	private $lockingProvider;
66
-	/** @var IRequest */
67
-	private $request;
68
-	/** @var IURLGenerator */
69
-	private $url;
70
-	/** @var AccountManager */
71
-	private $accountManager;
72
-	/** @var IGroupManager */
73
-	private $groupManager;
74
-	/** @var IFactory */
75
-	private $l10nFactory;
76
-	/** @var IAppManager */
77
-	private $appManager;
78
-
79
-	/**
80
-	 * @param ILogger $log
81
-	 * @param IDBConnection $dbc
82
-	 * @param IL10N $l
83
-	 * @param IConfig $config
84
-	 * @param EncryptionManager $encryptionManager
85
-	 * @param IUserManager $userManager
86
-	 * @param ILockingProvider $lockingProvider
87
-	 * @param IRequest $request
88
-	 * @param IURLGenerator $url
89
-	 * @param AccountManager $accountManager
90
-	 * @param IGroupManager $groupManager
91
-	 * @param IFactory $l10nFactory
92
-	 * @param IAppManager $appManager
93
-	 */
94
-	public function __construct(
95
-		ILogger $log,
96
-		IDBConnection $dbc,
97
-		IL10N $l,
98
-		IConfig $config,
99
-		EncryptionManager $encryptionManager,
100
-		IUserManager $userManager,
101
-		ILockingProvider $lockingProvider,
102
-		IRequest $request,
103
-		IURLGenerator $url,
104
-		AccountManager $accountManager,
105
-		IGroupManager $groupManager,
106
-		IFactory $l10nFactory,
107
-		IAppManager $appManager
108
-	) {
109
-		$this->log = $log;
110
-		$this->dbc = $dbc;
111
-		$this->l = $l;
112
-		$this->config = $config;
113
-		$this->encryptionManager = $encryptionManager;
114
-		$this->userManager = $userManager;
115
-		$this->lockingProvider = $lockingProvider;
116
-		$this->request = $request;
117
-		$this->url = $url;
118
-		$this->accountManager = $accountManager;
119
-		$this->groupManager = $groupManager;
120
-		$this->l10nFactory = $l10nFactory;
121
-		$this->appManager = $appManager;
122
-	}
123
-
124
-	/** @var array */
125
-	protected $sectionClasses = [];
126
-
127
-	/** @var array */
128
-	protected $sections = [];
129
-
130
-	/**
131
-	 * @param string $type 'admin' or 'personal'
132
-	 * @param string $section Class must implement OCP\Settings\ISection
133
-	 * @return void
134
-	 */
135
-	public function registerSection(string $type, string $section) {
136
-		$this->sectionClasses[$section] = $type;
137
-	}
138
-
139
-	/**
140
-	 * @param string $type 'admin' or 'personal'
141
-	 * @return ISection[]
142
-	 */
143
-	protected function getSections(string $type): array {
144
-		if (!isset($this->sections[$type])) {
145
-			$this->sections[$type] = [];
146
-		}
147
-
148
-		foreach ($this->sectionClasses as $class => $sectionType) {
149
-			try {
150
-				/** @var ISection $section */
151
-				$section = \OC::$server->query($class);
152
-			} catch (QueryException $e) {
153
-				$this->log->logException($e, ['level' => Util::INFO]);
154
-				continue;
155
-			}
156
-
157
-			if (!$section instanceof ISection) {
158
-				$this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => Util::INFO]);
159
-				continue;
160
-			}
161
-
162
-			$this->sections[$sectionType][$section->getID()] = $section;
163
-
164
-			unset($this->sectionClasses[$class]);
165
-		}
166
-
167
-		return $this->sections[$type];
168
-	}
169
-
170
-	/** @var array */
171
-	protected $settingClasses = [];
172
-
173
-	/** @var array */
174
-	protected $settings = [];
175
-
176
-	/**
177
-	 * @param string $type 'admin' or 'personal'
178
-	 * @param string $setting Class must implement OCP\Settings\ISetting
179
-	 * @return void
180
-	 */
181
-	public function registerSetting(string $type, string $setting) {
182
-		$this->settingClasses[$setting] = $type;
183
-	}
184
-
185
-	/**
186
-	 * @param string $type 'admin' or 'personal'
187
-	 * @param string $section
188
-	 * @return ISettings[]
189
-	 */
190
-	protected function getSettings(string $type, string $section): array {
191
-		if (!isset($this->settings[$type])) {
192
-			$this->settings[$type] = [];
193
-		}
194
-		if (!isset($this->settings[$type][$section])) {
195
-			$this->settings[$type][$section] = [];
196
-		}
197
-
198
-		foreach ($this->settingClasses as $class => $settingsType) {
199
-			try {
200
-				/** @var ISettings $setting */
201
-				$setting = \OC::$server->query($class);
202
-			} catch (QueryException $e) {
203
-				$this->log->logException($e, ['level' => Util::INFO]);
204
-				continue;
205
-			}
206
-
207
-			if (!$setting instanceof ISettings) {
208
-				$this->log->logException(new \InvalidArgumentException('Invalid settings setting registered'), ['level' => Util::INFO]);
209
-				continue;
210
-			}
211
-
212
-			if (!isset($this->settings[$settingsType][$setting->getSection()])) {
213
-				$this->settings[$settingsType][$setting->getSection()] = [];
214
-			}
215
-			$this->settings[$settingsType][$setting->getSection()][] = $setting;
216
-
217
-			unset($this->settingClasses[$class]);
218
-		}
219
-
220
-		return $this->settings[$type][$section];
221
-	}
222
-
223
-	/**
224
-	 * @inheritdoc
225
-	 */
226
-	public function getAdminSections(): array {
227
-		// built-in sections
228
-		$sections = [
229
-			0 => [new Section('overview', $this->l->t('Overview'), 0, $this->url->imagePath('settings', 'admin.svg'))],
230
-			1 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
231
-			5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))],
232
-			10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
233
-			45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
234
-			98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
235
-			99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))],
236
-		];
237
-
238
-		$appSections = $this->getSections('admin');
239
-
240
-		foreach ($appSections as $section) {
241
-			/** @var ISection $section */
242
-			if (!isset($sections[$section->getPriority()])) {
243
-				$sections[$section->getPriority()] = [];
244
-			}
245
-
246
-			$sections[$section->getPriority()][] = $section;
247
-		}
248
-
249
-		ksort($sections);
250
-
251
-		return $sections;
252
-	}
253
-
254
-	/**
255
-	 * @param string $section
256
-	 * @return ISection[]
257
-	 */
258
-	private function getBuiltInAdminSettings($section): array {
259
-		$forms = [];
260
-
261
-		if ($section === 'overview') {
262
-			/** @var ISettings $form */
263
-			$form = new Admin\Overview($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l);
264
-			$forms[$form->getPriority()] = [$form];
265
-			$form = new Admin\ServerDevNotice();
266
-			$forms[$form->getPriority()] = [$form];
267
-		}
268
-		if ($section === 'server') {
269
-			/** @var ISettings $form */
270
-			$form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l);
271
-			$forms[$form->getPriority()] = [$form];
272
-			$form = new Admin\Mail($this->config);
273
-			$forms[$form->getPriority()] = [$form];
274
-		}
275
-		if ($section === 'encryption') {
276
-			/** @var ISettings $form */
277
-			$form = new Admin\Encryption($this->encryptionManager, $this->userManager);
278
-			$forms[$form->getPriority()] = [$form];
279
-		}
280
-		if ($section === 'sharing') {
281
-			/** @var ISettings $form */
282
-			$form = new Admin\Sharing($this->config, $this->l);
283
-			$forms[$form->getPriority()] = [$form];
284
-		}
285
-		if ($section === 'tips-tricks') {
286
-			/** @var ISettings $form */
287
-			$form = new Admin\TipsTricks($this->config);
288
-			$forms[$form->getPriority()] = [$form];
289
-		}
290
-
291
-		return $forms;
292
-	}
293
-
294
-	/**
295
-	 * @param string $section
296
-	 * @return ISection[]
297
-	 */
298
-	private function getBuiltInPersonalSettings($section): array {
299
-		$forms = [];
300
-
301
-		if ($section === 'personal-info') {
302
-			/** @var ISettings $form */
303
-			$form = new Personal\PersonalInfo(
304
-				$this->config,
305
-				$this->userManager,
306
-				$this->groupManager,
307
-				$this->accountManager,
308
-				$this->appManager,
309
-				$this->l10nFactory,
310
-				$this->l
311
-			);
312
-			$forms[$form->getPriority()] = [$form];
313
-		}
314
-		if($section === 'security') {
315
-			/** @var ISettings $form */
316
-			$form = new Personal\Security();
317
-			$forms[$form->getPriority()] = [$form];
318
-		}
319
-		if ($section === 'additional') {
320
-			/** @var ISettings $form */
321
-			$form = new Personal\Additional();
322
-			$forms[$form->getPriority()] = [$form];
323
-		}
324
-
325
-		return $forms;
326
-	}
327
-
328
-	/**
329
-	 * @inheritdoc
330
-	 */
331
-	public function getAdminSettings($section): array {
332
-		$settings = $this->getBuiltInAdminSettings($section);
333
-		$appSettings = $this->getSettings('admin', $section);
334
-
335
-		foreach ($appSettings as $setting) {
336
-			if (!isset($settings[$setting->getPriority()])) {
337
-				$settings[$setting->getPriority()] = [];
338
-			}
339
-			$settings[$setting->getPriority()][] = $setting;
340
-		}
341
-
342
-		ksort($settings);
343
-		return $settings;
344
-	}
345
-
346
-	/**
347
-	 * @inheritdoc
348
-	 */
349
-	public function getPersonalSections(): array {
350
-		$sections = [
351
-			0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))],
352
-			5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))],
353
-			15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))],
354
-		];
355
-
356
-		$legacyForms = \OC_App::getForms('personal');
357
-		if(!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) {
358
-			$sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
359
-		}
360
-
361
-		$appSections = $this->getSections('personal');
362
-
363
-		foreach ($appSections as $section) {
364
-			/** @var ISection $section */
365
-			if (!isset($sections[$section->getPriority()])) {
366
-				$sections[$section->getPriority()] = [];
367
-			}
368
-
369
-			$sections[$section->getPriority()][] = $section;
370
-		}
371
-
372
-		ksort($sections);
373
-
374
-		return $sections;
375
-	}
376
-
377
-	/**
378
-	 * @param string[] $forms
379
-	 * @return bool
380
-	 */
381
-	private function hasLegacyPersonalSettingsToRender(array $forms): bool {
382
-		foreach ($forms as $form) {
383
-			if(trim($form) !== '') {
384
-				return true;
385
-			}
386
-		}
387
-		return false;
388
-	}
389
-
390
-	/**
391
-	 * @inheritdoc
392
-	 */
393
-	public function getPersonalSettings($section): array {
394
-		$settings = $this->getBuiltInPersonalSettings($section);
395
-		$appSettings = $this->getSettings('personal', $section);
396
-
397
-		foreach ($appSettings as $setting) {
398
-			if (!isset($settings[$setting->getPriority()])) {
399
-				$settings[$setting->getPriority()] = [];
400
-			}
401
-			$settings[$setting->getPriority()][] = $setting;
402
-		}
403
-
404
-		ksort($settings);
405
-		return $settings;
406
-	}
52
+    /** @var ILogger */
53
+    private $log;
54
+    /** @var IDBConnection */
55
+    private $dbc;
56
+    /** @var IL10N */
57
+    private $l;
58
+    /** @var IConfig */
59
+    private $config;
60
+    /** @var EncryptionManager */
61
+    private $encryptionManager;
62
+    /** @var IUserManager */
63
+    private $userManager;
64
+    /** @var ILockingProvider */
65
+    private $lockingProvider;
66
+    /** @var IRequest */
67
+    private $request;
68
+    /** @var IURLGenerator */
69
+    private $url;
70
+    /** @var AccountManager */
71
+    private $accountManager;
72
+    /** @var IGroupManager */
73
+    private $groupManager;
74
+    /** @var IFactory */
75
+    private $l10nFactory;
76
+    /** @var IAppManager */
77
+    private $appManager;
78
+
79
+    /**
80
+     * @param ILogger $log
81
+     * @param IDBConnection $dbc
82
+     * @param IL10N $l
83
+     * @param IConfig $config
84
+     * @param EncryptionManager $encryptionManager
85
+     * @param IUserManager $userManager
86
+     * @param ILockingProvider $lockingProvider
87
+     * @param IRequest $request
88
+     * @param IURLGenerator $url
89
+     * @param AccountManager $accountManager
90
+     * @param IGroupManager $groupManager
91
+     * @param IFactory $l10nFactory
92
+     * @param IAppManager $appManager
93
+     */
94
+    public function __construct(
95
+        ILogger $log,
96
+        IDBConnection $dbc,
97
+        IL10N $l,
98
+        IConfig $config,
99
+        EncryptionManager $encryptionManager,
100
+        IUserManager $userManager,
101
+        ILockingProvider $lockingProvider,
102
+        IRequest $request,
103
+        IURLGenerator $url,
104
+        AccountManager $accountManager,
105
+        IGroupManager $groupManager,
106
+        IFactory $l10nFactory,
107
+        IAppManager $appManager
108
+    ) {
109
+        $this->log = $log;
110
+        $this->dbc = $dbc;
111
+        $this->l = $l;
112
+        $this->config = $config;
113
+        $this->encryptionManager = $encryptionManager;
114
+        $this->userManager = $userManager;
115
+        $this->lockingProvider = $lockingProvider;
116
+        $this->request = $request;
117
+        $this->url = $url;
118
+        $this->accountManager = $accountManager;
119
+        $this->groupManager = $groupManager;
120
+        $this->l10nFactory = $l10nFactory;
121
+        $this->appManager = $appManager;
122
+    }
123
+
124
+    /** @var array */
125
+    protected $sectionClasses = [];
126
+
127
+    /** @var array */
128
+    protected $sections = [];
129
+
130
+    /**
131
+     * @param string $type 'admin' or 'personal'
132
+     * @param string $section Class must implement OCP\Settings\ISection
133
+     * @return void
134
+     */
135
+    public function registerSection(string $type, string $section) {
136
+        $this->sectionClasses[$section] = $type;
137
+    }
138
+
139
+    /**
140
+     * @param string $type 'admin' or 'personal'
141
+     * @return ISection[]
142
+     */
143
+    protected function getSections(string $type): array {
144
+        if (!isset($this->sections[$type])) {
145
+            $this->sections[$type] = [];
146
+        }
147
+
148
+        foreach ($this->sectionClasses as $class => $sectionType) {
149
+            try {
150
+                /** @var ISection $section */
151
+                $section = \OC::$server->query($class);
152
+            } catch (QueryException $e) {
153
+                $this->log->logException($e, ['level' => Util::INFO]);
154
+                continue;
155
+            }
156
+
157
+            if (!$section instanceof ISection) {
158
+                $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => Util::INFO]);
159
+                continue;
160
+            }
161
+
162
+            $this->sections[$sectionType][$section->getID()] = $section;
163
+
164
+            unset($this->sectionClasses[$class]);
165
+        }
166
+
167
+        return $this->sections[$type];
168
+    }
169
+
170
+    /** @var array */
171
+    protected $settingClasses = [];
172
+
173
+    /** @var array */
174
+    protected $settings = [];
175
+
176
+    /**
177
+     * @param string $type 'admin' or 'personal'
178
+     * @param string $setting Class must implement OCP\Settings\ISetting
179
+     * @return void
180
+     */
181
+    public function registerSetting(string $type, string $setting) {
182
+        $this->settingClasses[$setting] = $type;
183
+    }
184
+
185
+    /**
186
+     * @param string $type 'admin' or 'personal'
187
+     * @param string $section
188
+     * @return ISettings[]
189
+     */
190
+    protected function getSettings(string $type, string $section): array {
191
+        if (!isset($this->settings[$type])) {
192
+            $this->settings[$type] = [];
193
+        }
194
+        if (!isset($this->settings[$type][$section])) {
195
+            $this->settings[$type][$section] = [];
196
+        }
197
+
198
+        foreach ($this->settingClasses as $class => $settingsType) {
199
+            try {
200
+                /** @var ISettings $setting */
201
+                $setting = \OC::$server->query($class);
202
+            } catch (QueryException $e) {
203
+                $this->log->logException($e, ['level' => Util::INFO]);
204
+                continue;
205
+            }
206
+
207
+            if (!$setting instanceof ISettings) {
208
+                $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered'), ['level' => Util::INFO]);
209
+                continue;
210
+            }
211
+
212
+            if (!isset($this->settings[$settingsType][$setting->getSection()])) {
213
+                $this->settings[$settingsType][$setting->getSection()] = [];
214
+            }
215
+            $this->settings[$settingsType][$setting->getSection()][] = $setting;
216
+
217
+            unset($this->settingClasses[$class]);
218
+        }
219
+
220
+        return $this->settings[$type][$section];
221
+    }
222
+
223
+    /**
224
+     * @inheritdoc
225
+     */
226
+    public function getAdminSections(): array {
227
+        // built-in sections
228
+        $sections = [
229
+            0 => [new Section('overview', $this->l->t('Overview'), 0, $this->url->imagePath('settings', 'admin.svg'))],
230
+            1 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
231
+            5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))],
232
+            10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
233
+            45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
234
+            98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
235
+            99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))],
236
+        ];
237
+
238
+        $appSections = $this->getSections('admin');
239
+
240
+        foreach ($appSections as $section) {
241
+            /** @var ISection $section */
242
+            if (!isset($sections[$section->getPriority()])) {
243
+                $sections[$section->getPriority()] = [];
244
+            }
245
+
246
+            $sections[$section->getPriority()][] = $section;
247
+        }
248
+
249
+        ksort($sections);
250
+
251
+        return $sections;
252
+    }
253
+
254
+    /**
255
+     * @param string $section
256
+     * @return ISection[]
257
+     */
258
+    private function getBuiltInAdminSettings($section): array {
259
+        $forms = [];
260
+
261
+        if ($section === 'overview') {
262
+            /** @var ISettings $form */
263
+            $form = new Admin\Overview($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l);
264
+            $forms[$form->getPriority()] = [$form];
265
+            $form = new Admin\ServerDevNotice();
266
+            $forms[$form->getPriority()] = [$form];
267
+        }
268
+        if ($section === 'server') {
269
+            /** @var ISettings $form */
270
+            $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l);
271
+            $forms[$form->getPriority()] = [$form];
272
+            $form = new Admin\Mail($this->config);
273
+            $forms[$form->getPriority()] = [$form];
274
+        }
275
+        if ($section === 'encryption') {
276
+            /** @var ISettings $form */
277
+            $form = new Admin\Encryption($this->encryptionManager, $this->userManager);
278
+            $forms[$form->getPriority()] = [$form];
279
+        }
280
+        if ($section === 'sharing') {
281
+            /** @var ISettings $form */
282
+            $form = new Admin\Sharing($this->config, $this->l);
283
+            $forms[$form->getPriority()] = [$form];
284
+        }
285
+        if ($section === 'tips-tricks') {
286
+            /** @var ISettings $form */
287
+            $form = new Admin\TipsTricks($this->config);
288
+            $forms[$form->getPriority()] = [$form];
289
+        }
290
+
291
+        return $forms;
292
+    }
293
+
294
+    /**
295
+     * @param string $section
296
+     * @return ISection[]
297
+     */
298
+    private function getBuiltInPersonalSettings($section): array {
299
+        $forms = [];
300
+
301
+        if ($section === 'personal-info') {
302
+            /** @var ISettings $form */
303
+            $form = new Personal\PersonalInfo(
304
+                $this->config,
305
+                $this->userManager,
306
+                $this->groupManager,
307
+                $this->accountManager,
308
+                $this->appManager,
309
+                $this->l10nFactory,
310
+                $this->l
311
+            );
312
+            $forms[$form->getPriority()] = [$form];
313
+        }
314
+        if($section === 'security') {
315
+            /** @var ISettings $form */
316
+            $form = new Personal\Security();
317
+            $forms[$form->getPriority()] = [$form];
318
+        }
319
+        if ($section === 'additional') {
320
+            /** @var ISettings $form */
321
+            $form = new Personal\Additional();
322
+            $forms[$form->getPriority()] = [$form];
323
+        }
324
+
325
+        return $forms;
326
+    }
327
+
328
+    /**
329
+     * @inheritdoc
330
+     */
331
+    public function getAdminSettings($section): array {
332
+        $settings = $this->getBuiltInAdminSettings($section);
333
+        $appSettings = $this->getSettings('admin', $section);
334
+
335
+        foreach ($appSettings as $setting) {
336
+            if (!isset($settings[$setting->getPriority()])) {
337
+                $settings[$setting->getPriority()] = [];
338
+            }
339
+            $settings[$setting->getPriority()][] = $setting;
340
+        }
341
+
342
+        ksort($settings);
343
+        return $settings;
344
+    }
345
+
346
+    /**
347
+     * @inheritdoc
348
+     */
349
+    public function getPersonalSections(): array {
350
+        $sections = [
351
+            0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))],
352
+            5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))],
353
+            15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))],
354
+        ];
355
+
356
+        $legacyForms = \OC_App::getForms('personal');
357
+        if(!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) {
358
+            $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
359
+        }
360
+
361
+        $appSections = $this->getSections('personal');
362
+
363
+        foreach ($appSections as $section) {
364
+            /** @var ISection $section */
365
+            if (!isset($sections[$section->getPriority()])) {
366
+                $sections[$section->getPriority()] = [];
367
+            }
368
+
369
+            $sections[$section->getPriority()][] = $section;
370
+        }
371
+
372
+        ksort($sections);
373
+
374
+        return $sections;
375
+    }
376
+
377
+    /**
378
+     * @param string[] $forms
379
+     * @return bool
380
+     */
381
+    private function hasLegacyPersonalSettingsToRender(array $forms): bool {
382
+        foreach ($forms as $form) {
383
+            if(trim($form) !== '') {
384
+                return true;
385
+            }
386
+        }
387
+        return false;
388
+    }
389
+
390
+    /**
391
+     * @inheritdoc
392
+     */
393
+    public function getPersonalSettings($section): array {
394
+        $settings = $this->getBuiltInPersonalSettings($section);
395
+        $appSettings = $this->getSettings('personal', $section);
396
+
397
+        foreach ($appSettings as $setting) {
398
+            if (!isset($settings[$setting->getPriority()])) {
399
+                $settings[$setting->getPriority()] = [];
400
+            }
401
+            $settings[$setting->getPriority()][] = $setting;
402
+        }
403
+
404
+        ksort($settings);
405
+        return $settings;
406
+    }
407 407
 }
Please login to merge, or discard this patch.
apps/federatedfilesharing/templates/settings-admin.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -4,13 +4,13 @@  discard block
 block discarded – undo
4 4
 script('federatedfilesharing', 'settings-admin');
5 5
 ?>
6 6
 
7
-<?php if($_['internalOnly'] === false): ?>
7
+<?php if ($_['internalOnly'] === false): ?>
8 8
 
9 9
 <div id="fileSharingSettings" class="section">
10 10
 	<h2>
11
-		<?php p($l->t('Federated Cloud Sharing'));?>
11
+		<?php p($l->t('Federated Cloud Sharing')); ?>
12 12
 		<a target="_blank" rel="noreferrer noopener" class="icon-info svg"
13
-		   title="<?php p($l->t('Open documentation'));?>"
13
+		   title="<?php p($l->t('Open documentation')); ?>"
14 14
 		   href="<?php p(link_to_docs('admin-sharing-federated')); ?>"></a>
15 15
 	</h2>
16 16
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 		<input type="checkbox" name="outgoing_server2server_share_enabled" id="outgoingServer2serverShareEnabled" class="checkbox"
21 21
 			   value="1" <?php if ($_['outgoingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> />
22 22
 		<label for="outgoingServer2serverShareEnabled">
23
-			<?php p($l->t('Allow users on this server to send shares to other servers'));?>
23
+			<?php p($l->t('Allow users on this server to send shares to other servers')); ?>
24 24
 		</label>
25 25
 	</p>
26 26
 
@@ -28,21 +28,21 @@  discard block
 block discarded – undo
28 28
 		<input type="checkbox" name="incoming_server2server_share_enabled" id="incomingServer2serverShareEnabled" class="checkbox"
29 29
 			   value="1" <?php if ($_['incomingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> />
30 30
 		<label for="incomingServer2serverShareEnabled">
31
-			<?php p($l->t('Allow users on this server to receive shares from other servers'));?>
31
+			<?php p($l->t('Allow users on this server to receive shares from other servers')); ?>
32 32
 		</label><br/>
33 33
 	</p>
34 34
 	<p>
35 35
 		<input type="checkbox" name="lookupServerEnabled" id="lookupServerEnabled" class="checkbox"
36 36
 			   value="1" <?php if ($_['lookupServerEnabled']) print_unescaped('checked="checked"'); ?> />
37 37
 		<label for="lookupServerEnabled">
38
-			<?php p($l->t('Search global and public address book for users'));?>
38
+			<?php p($l->t('Search global and public address book for users')); ?>
39 39
 		</label><br/>
40 40
 	</p>
41 41
 	<p>
42 42
 		<input type="checkbox" name="lookupServerUploadEnabled" id="lookupServerUploadEnabled" class="checkbox"
43 43
 			   value="1" <?php if ($_['lookupServerUploadEnabled']) print_unescaped('checked="checked"'); ?> />
44 44
 		<label for="lookupServerUploadEnabled">
45
-			<?php p($l->t('Allow users to publish their data to a global and public address book'));?>
45
+			<?php p($l->t('Allow users to publish their data to a global and public address book')); ?>
46 46
 		</label><br/>
47 47
 	</p>
48 48
 
Please login to merge, or discard this patch.
settings/Controller/CommonSettingsTrait.php 2 patches
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -31,102 +31,102 @@
 block discarded – undo
31 31
 use OCP\Settings\ISettings;
32 32
 
33 33
 trait CommonSettingsTrait  {
34
-	/** @var ISettingsManager */
35
-	private $settingsManager;
36
-
37
-	/** @var INavigationManager */
38
-	private $navigationManager;
39
-
40
-	/**
41
-	 * @param string $currentSection
42
-	 * @return array
43
-	 */
44
-	private function getNavigationParameters($currentType, $currentSection) {
45
-		$templateParameters = [
46
-			'personal' => $this->formatPersonalSections($currentType, $currentSection),
47
-			'admin' => []
48
-		];
49
-
50
-		if(\OC_User::isAdminUser(\OC_User::getUser())) {
51
-			$templateParameters['admin'] = $this->formatAdminSections($currentType, $currentSection);
52
-		}
53
-
54
-		return [
55
-			'forms' => $templateParameters
56
-		];
57
-	}
58
-
59
-	protected function formatSections($sections, $currentSection, $type, $currentType) {
60
-		$templateParameters = [];
61
-		/** @var \OCP\Settings\ISection[] $prioritizedSections */
62
-		foreach($sections as $prioritizedSections) {
63
-			foreach ($prioritizedSections as $section) {
64
-				if($type === 'admin') {
65
-					$settings = $this->settingsManager->getAdminSettings($section->getID());
66
-				} else if($type === 'personal') {
67
-					$settings = $this->settingsManager->getPersonalSettings($section->getID());
68
-				}
69
-				if (empty($settings) && !($section->getID() === 'additional' && count(\OC_App::getForms('admin')) > 0)) {
70
-					continue;
71
-				}
72
-
73
-				$icon = '';
74
-				if ($section instanceof IIconSection) {
75
-					$icon = $section->getIcon();
76
-				}
77
-
78
-				$active = $section->getID() === $currentSection
79
-					&& $type === $currentType;
80
-
81
-				$templateParameters[] = [
82
-					'anchor'       => $section->getID(),
83
-					'section-name' => $section->getName(),
84
-					'active'       => $active,
85
-					'icon'         => $icon,
86
-				];
87
-			}
88
-		}
89
-		return $templateParameters;
90
-	}
91
-
92
-	protected function formatPersonalSections($currentType, $currentSections) {
93
-		$sections = $this->settingsManager->getPersonalSections();
94
-		$templateParameters = $this->formatSections($sections, $currentSections, 'personal', $currentType);
95
-
96
-		return $templateParameters;
97
-	}
98
-
99
-	protected function formatAdminSections($currentType, $currentSections) {
100
-		$sections = $this->settingsManager->getAdminSections();
101
-		$templateParameters = $this->formatSections($sections, $currentSections, 'admin', $currentType);
102
-
103
-		return $templateParameters;
104
-	}
105
-
106
-	/**
107
-	 * @param ISettings[] $settings
108
-	 * @return array
109
-	 */
110
-	private function formatSettings($settings) {
111
-		$html = '';
112
-		foreach ($settings as $prioritizedSettings) {
113
-			foreach ($prioritizedSettings as $setting) {
114
-				/** @var \OCP\Settings\ISettings $setting */
115
-				$form = $setting->getForm();
116
-				$html .= $form->renderAs('')->render();
117
-			}
118
-		}
119
-		return ['content' => $html];
120
-	}
121
-
122
-	private function getIndexResponse($type, $section) {
123
-		$this->navigationManager->setActiveEntry('settings');
124
-		$templateParams = [];
125
-		$templateParams = array_merge($templateParams, $this->getNavigationParameters($type, $section));
126
-		$templateParams = array_merge($templateParams, $this->getSettings($section));
127
-
128
-		return new TemplateResponse('settings', 'settings/frame', $templateParams);
129
-	}
130
-
131
-	abstract protected function getSettings($section);
34
+    /** @var ISettingsManager */
35
+    private $settingsManager;
36
+
37
+    /** @var INavigationManager */
38
+    private $navigationManager;
39
+
40
+    /**
41
+     * @param string $currentSection
42
+     * @return array
43
+     */
44
+    private function getNavigationParameters($currentType, $currentSection) {
45
+        $templateParameters = [
46
+            'personal' => $this->formatPersonalSections($currentType, $currentSection),
47
+            'admin' => []
48
+        ];
49
+
50
+        if(\OC_User::isAdminUser(\OC_User::getUser())) {
51
+            $templateParameters['admin'] = $this->formatAdminSections($currentType, $currentSection);
52
+        }
53
+
54
+        return [
55
+            'forms' => $templateParameters
56
+        ];
57
+    }
58
+
59
+    protected function formatSections($sections, $currentSection, $type, $currentType) {
60
+        $templateParameters = [];
61
+        /** @var \OCP\Settings\ISection[] $prioritizedSections */
62
+        foreach($sections as $prioritizedSections) {
63
+            foreach ($prioritizedSections as $section) {
64
+                if($type === 'admin') {
65
+                    $settings = $this->settingsManager->getAdminSettings($section->getID());
66
+                } else if($type === 'personal') {
67
+                    $settings = $this->settingsManager->getPersonalSettings($section->getID());
68
+                }
69
+                if (empty($settings) && !($section->getID() === 'additional' && count(\OC_App::getForms('admin')) > 0)) {
70
+                    continue;
71
+                }
72
+
73
+                $icon = '';
74
+                if ($section instanceof IIconSection) {
75
+                    $icon = $section->getIcon();
76
+                }
77
+
78
+                $active = $section->getID() === $currentSection
79
+                    && $type === $currentType;
80
+
81
+                $templateParameters[] = [
82
+                    'anchor'       => $section->getID(),
83
+                    'section-name' => $section->getName(),
84
+                    'active'       => $active,
85
+                    'icon'         => $icon,
86
+                ];
87
+            }
88
+        }
89
+        return $templateParameters;
90
+    }
91
+
92
+    protected function formatPersonalSections($currentType, $currentSections) {
93
+        $sections = $this->settingsManager->getPersonalSections();
94
+        $templateParameters = $this->formatSections($sections, $currentSections, 'personal', $currentType);
95
+
96
+        return $templateParameters;
97
+    }
98
+
99
+    protected function formatAdminSections($currentType, $currentSections) {
100
+        $sections = $this->settingsManager->getAdminSections();
101
+        $templateParameters = $this->formatSections($sections, $currentSections, 'admin', $currentType);
102
+
103
+        return $templateParameters;
104
+    }
105
+
106
+    /**
107
+     * @param ISettings[] $settings
108
+     * @return array
109
+     */
110
+    private function formatSettings($settings) {
111
+        $html = '';
112
+        foreach ($settings as $prioritizedSettings) {
113
+            foreach ($prioritizedSettings as $setting) {
114
+                /** @var \OCP\Settings\ISettings $setting */
115
+                $form = $setting->getForm();
116
+                $html .= $form->renderAs('')->render();
117
+            }
118
+        }
119
+        return ['content' => $html];
120
+    }
121
+
122
+    private function getIndexResponse($type, $section) {
123
+        $this->navigationManager->setActiveEntry('settings');
124
+        $templateParams = [];
125
+        $templateParams = array_merge($templateParams, $this->getNavigationParameters($type, $section));
126
+        $templateParams = array_merge($templateParams, $this->getSettings($section));
127
+
128
+        return new TemplateResponse('settings', 'settings/frame', $templateParams);
129
+    }
130
+
131
+    abstract protected function getSettings($section);
132 132
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 use OCP\Settings\IIconSection;
31 31
 use OCP\Settings\ISettings;
32 32
 
33
-trait CommonSettingsTrait  {
33
+trait CommonSettingsTrait {
34 34
 	/** @var ISettingsManager */
35 35
 	private $settingsManager;
36 36
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 			'admin' => []
48 48
 		];
49 49
 
50
-		if(\OC_User::isAdminUser(\OC_User::getUser())) {
50
+		if (\OC_User::isAdminUser(\OC_User::getUser())) {
51 51
 			$templateParameters['admin'] = $this->formatAdminSections($currentType, $currentSection);
52 52
 		}
53 53
 
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
 	protected function formatSections($sections, $currentSection, $type, $currentType) {
60 60
 		$templateParameters = [];
61 61
 		/** @var \OCP\Settings\ISection[] $prioritizedSections */
62
-		foreach($sections as $prioritizedSections) {
62
+		foreach ($sections as $prioritizedSections) {
63 63
 			foreach ($prioritizedSections as $section) {
64
-				if($type === 'admin') {
64
+				if ($type === 'admin') {
65 65
 					$settings = $this->settingsManager->getAdminSettings($section->getID());
66
-				} else if($type === 'personal') {
66
+				} else if ($type === 'personal') {
67 67
 					$settings = $this->settingsManager->getPersonalSettings($section->getID());
68 68
 				}
69 69
 				if (empty($settings) && !($section->getID() === 'additional' && count(\OC_App::getForms('admin')) > 0)) {
Please login to merge, or discard this patch.