Completed
Pull Request — master (#5615)
by Joas
28:27 queued 12:27
created
lib/private/NavigationManager.php 1 patch
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -41,252 +41,252 @@
 block discarded – undo
41 41
  */
42 42
 
43 43
 class NavigationManager implements INavigationManager {
44
-	protected $entries = [];
45
-	protected $closureEntries = [];
46
-	protected $activeEntry;
47
-	/** @var bool */
48
-	protected $init = false;
49
-	/** @var IAppManager|AppManager */
50
-	protected $appManager;
51
-	/** @var IURLGenerator */
52
-	private $urlGenerator;
53
-	/** @var IFactory */
54
-	private $l10nFac;
55
-	/** @var IUserSession */
56
-	private $userSession;
57
-	/** @var IGroupManager|Manager */
58
-	private $groupManager;
59
-	/** @var IConfig */
60
-	private $config;
44
+    protected $entries = [];
45
+    protected $closureEntries = [];
46
+    protected $activeEntry;
47
+    /** @var bool */
48
+    protected $init = false;
49
+    /** @var IAppManager|AppManager */
50
+    protected $appManager;
51
+    /** @var IURLGenerator */
52
+    private $urlGenerator;
53
+    /** @var IFactory */
54
+    private $l10nFac;
55
+    /** @var IUserSession */
56
+    private $userSession;
57
+    /** @var IGroupManager|Manager */
58
+    private $groupManager;
59
+    /** @var IConfig */
60
+    private $config;
61 61
 
62
-	public function __construct(IAppManager $appManager,
63
-						 IURLGenerator $urlGenerator,
64
-						 IFactory $l10nFac,
65
-						 IUserSession $userSession,
66
-						 IGroupManager $groupManager,
67
-						 IConfig $config) {
68
-		$this->appManager = $appManager;
69
-		$this->urlGenerator = $urlGenerator;
70
-		$this->l10nFac = $l10nFac;
71
-		$this->userSession = $userSession;
72
-		$this->groupManager = $groupManager;
73
-		$this->config = $config;
74
-	}
62
+    public function __construct(IAppManager $appManager,
63
+                            IURLGenerator $urlGenerator,
64
+                            IFactory $l10nFac,
65
+                            IUserSession $userSession,
66
+                            IGroupManager $groupManager,
67
+                            IConfig $config) {
68
+        $this->appManager = $appManager;
69
+        $this->urlGenerator = $urlGenerator;
70
+        $this->l10nFac = $l10nFac;
71
+        $this->userSession = $userSession;
72
+        $this->groupManager = $groupManager;
73
+        $this->config = $config;
74
+    }
75 75
 
76
-	/**
77
-	 * Creates a new navigation entry
78
-	 *
79
-	 * @param array|\Closure $entry Array containing: id, name, order, icon and href key
80
-	 *					The use of a closure is preferred, because it will avoid
81
-	 * 					loading the routing of your app, unless required.
82
-	 * @return void
83
-	 */
84
-	public function add($entry) {
85
-		if ($entry instanceof \Closure) {
86
-			$this->closureEntries[] = $entry;
87
-			return;
88
-		}
76
+    /**
77
+     * Creates a new navigation entry
78
+     *
79
+     * @param array|\Closure $entry Array containing: id, name, order, icon and href key
80
+     *					The use of a closure is preferred, because it will avoid
81
+     * 					loading the routing of your app, unless required.
82
+     * @return void
83
+     */
84
+    public function add($entry) {
85
+        if ($entry instanceof \Closure) {
86
+            $this->closureEntries[] = $entry;
87
+            return;
88
+        }
89 89
 
90
-		$entry['active'] = false;
91
-		if(!isset($entry['icon'])) {
92
-			$entry['icon'] = '';
93
-		}
94
-		if(!isset($entry['type'])) {
95
-			$entry['type'] = 'link';
96
-		}
97
-		$this->entries[] = $entry;
98
-	}
90
+        $entry['active'] = false;
91
+        if(!isset($entry['icon'])) {
92
+            $entry['icon'] = '';
93
+        }
94
+        if(!isset($entry['type'])) {
95
+            $entry['type'] = 'link';
96
+        }
97
+        $this->entries[] = $entry;
98
+    }
99 99
 
100
-	/**
101
-	 * returns all the added Menu entries
102
-	 * @param string $type
103
-	 * @return array an array of the added entries
104
-	 */
105
-	public function getAll($type = 'link') {
106
-		$this->init();
107
-		foreach ($this->closureEntries as $c) {
108
-			$this->add($c());
109
-		}
110
-		$this->closureEntries = array();
100
+    /**
101
+     * returns all the added Menu entries
102
+     * @param string $type
103
+     * @return array an array of the added entries
104
+     */
105
+    public function getAll($type = 'link') {
106
+        $this->init();
107
+        foreach ($this->closureEntries as $c) {
108
+            $this->add($c());
109
+        }
110
+        $this->closureEntries = array();
111 111
 
112
-		if ($type === 'all') {
113
-			return $this->entries;
114
-		}
112
+        if ($type === 'all') {
113
+            return $this->entries;
114
+        }
115 115
 
116
-		return array_filter($this->entries, function($entry) use ($type) {
117
-			return $entry['type'] === $type;
118
-		});
119
-	}
116
+        return array_filter($this->entries, function($entry) use ($type) {
117
+            return $entry['type'] === $type;
118
+        });
119
+    }
120 120
 
121
-	/**
122
-	 * removes all the entries
123
-	 */
124
-	public function clear($loadDefaultLinks = true) {
125
-		$this->entries = [];
126
-		$this->closureEntries = [];
127
-		$this->init = !$loadDefaultLinks;
128
-	}
121
+    /**
122
+     * removes all the entries
123
+     */
124
+    public function clear($loadDefaultLinks = true) {
125
+        $this->entries = [];
126
+        $this->closureEntries = [];
127
+        $this->init = !$loadDefaultLinks;
128
+    }
129 129
 
130
-	/**
131
-	 * Sets the current navigation entry of the currently running app
132
-	 * @param string $id of the app entry to activate (from added $entry)
133
-	 */
134
-	public function setActiveEntry($id) {
135
-		$this->activeEntry = $id;
136
-	}
130
+    /**
131
+     * Sets the current navigation entry of the currently running app
132
+     * @param string $id of the app entry to activate (from added $entry)
133
+     */
134
+    public function setActiveEntry($id) {
135
+        $this->activeEntry = $id;
136
+    }
137 137
 
138
-	/**
139
-	 * gets the active Menu entry
140
-	 * @return string id or empty string
141
-	 *
142
-	 * This function returns the id of the active navigation entry (set by
143
-	 * setActiveEntry
144
-	 */
145
-	public function getActiveEntry() {
146
-		return $this->activeEntry;
147
-	}
138
+    /**
139
+     * gets the active Menu entry
140
+     * @return string id or empty string
141
+     *
142
+     * This function returns the id of the active navigation entry (set by
143
+     * setActiveEntry
144
+     */
145
+    public function getActiveEntry() {
146
+        return $this->activeEntry;
147
+    }
148 148
 
149
-	private function init() {
150
-		if ($this->init) {
151
-			return;
152
-		}
153
-		$this->init = true;
149
+    private function init() {
150
+        if ($this->init) {
151
+            return;
152
+        }
153
+        $this->init = true;
154 154
 
155
-		$l = $this->l10nFac->get('lib');
156
-		if ($this->config->getSystemValue('knowledgebaseenabled', true)) {
157
-			$this->add([
158
-				'type' => 'settings',
159
-				'id' => 'help',
160
-				'order' => 5,
161
-				'href' => $this->urlGenerator->linkToRoute('settings_help'),
162
-				'name' => $l->t('Help'),
163
-				'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'),
164
-			]);
165
-		}
155
+        $l = $this->l10nFac->get('lib');
156
+        if ($this->config->getSystemValue('knowledgebaseenabled', true)) {
157
+            $this->add([
158
+                'type' => 'settings',
159
+                'id' => 'help',
160
+                'order' => 5,
161
+                'href' => $this->urlGenerator->linkToRoute('settings_help'),
162
+                'name' => $l->t('Help'),
163
+                'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'),
164
+            ]);
165
+        }
166 166
 
167
-		if ($this->userSession->isLoggedIn()) {
168
-			if ($this->isAdmin()) {
169
-				// App management
170
-				$this->add([
171
-					'type' => 'settings',
172
-					'id' => 'core_apps',
173
-					'order' => 3,
174
-					'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
175
-					'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
176
-					'name' => $l->t('Apps'),
177
-				]);
178
-			}
167
+        if ($this->userSession->isLoggedIn()) {
168
+            if ($this->isAdmin()) {
169
+                // App management
170
+                $this->add([
171
+                    'type' => 'settings',
172
+                    'id' => 'core_apps',
173
+                    'order' => 3,
174
+                    'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
175
+                    'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
176
+                    'name' => $l->t('Apps'),
177
+                ]);
178
+            }
179 179
 
180
-			// Personal and (if applicable) admin settings
181
-			$this->add([
182
-				'type' => 'settings',
183
-				'id' => 'settings',
184
-				'order' => 1,
185
-				'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
186
-				'name' => $l->t('Settings'),
187
-				'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
188
-			]);
180
+            // Personal and (if applicable) admin settings
181
+            $this->add([
182
+                'type' => 'settings',
183
+                'id' => 'settings',
184
+                'order' => 1,
185
+                'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
186
+                'name' => $l->t('Settings'),
187
+                'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
188
+            ]);
189 189
 
190
-			// Logout
191
-			$this->add([
192
-				'type' => 'settings',
193
-				'id' => 'logout',
194
-				'order' => 99999,
195
-				'href' => $this->urlGenerator->linkToRouteAbsolute(
196
-					'core.login.logout',
197
-					['requesttoken' => \OCP\Util::callRegister()]
198
-				),
199
-				'name' => $l->t('Log out'),
200
-				'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
201
-			]);
190
+            // Logout
191
+            $this->add([
192
+                'type' => 'settings',
193
+                'id' => 'logout',
194
+                'order' => 99999,
195
+                'href' => $this->urlGenerator->linkToRouteAbsolute(
196
+                    'core.login.logout',
197
+                    ['requesttoken' => \OCP\Util::callRegister()]
198
+                ),
199
+                'name' => $l->t('Log out'),
200
+                'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
201
+            ]);
202 202
 
203
-			if ($this->isSubadmin()) {
204
-				// User management
205
-				$this->add([
206
-					'type' => 'settings',
207
-					'id' => 'core_users',
208
-					'order' => 4,
209
-					'href' => $this->urlGenerator->linkToRoute('settings_users'),
210
-					'name' => $l->t('Users'),
211
-					'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'),
212
-				]);
213
-			}
214
-		}
203
+            if ($this->isSubadmin()) {
204
+                // User management
205
+                $this->add([
206
+                    'type' => 'settings',
207
+                    'id' => 'core_users',
208
+                    'order' => 4,
209
+                    'href' => $this->urlGenerator->linkToRoute('settings_users'),
210
+                    'name' => $l->t('Users'),
211
+                    'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'),
212
+                ]);
213
+            }
214
+        }
215 215
 
216
-		if ($this->appManager === 'null') {
217
-			return;
218
-		}
216
+        if ($this->appManager === 'null') {
217
+            return;
218
+        }
219 219
 
220
-		if ($this->userSession->isLoggedIn()) {
221
-			$apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser());
222
-		} else {
223
-			$apps = $this->appManager->getInstalledApps();
224
-		}
220
+        if ($this->userSession->isLoggedIn()) {
221
+            $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser());
222
+        } else {
223
+            $apps = $this->appManager->getInstalledApps();
224
+        }
225 225
 
226
-		foreach ($apps as $app) {
227
-			if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
228
-				continue;
229
-			}
226
+        foreach ($apps as $app) {
227
+            if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
228
+                continue;
229
+            }
230 230
 
231
-			// load plugins and collections from info.xml
232
-			$info = $this->appManager->getAppInfo($app);
233
-			if (empty($info['navigations'])) {
234
-				continue;
235
-			}
236
-			foreach ($info['navigations'] as $nav) {
237
-				if (!isset($nav['name'])) {
238
-					continue;
239
-				}
240
-				if (!isset($nav['route'])) {
241
-					continue;
242
-				}
243
-				$role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
244
-				if ($role === 'admin' && !$this->isAdmin()) {
245
-					continue;
246
-				}
247
-				$l = $this->l10nFac->get($app);
248
-				$id = isset($nav['id']) ? $nav['id'] : $app;
249
-				$order = isset($nav['order']) ? $nav['order'] : 100;
250
-				$type = isset($nav['type']) ? $nav['type'] : 'link';
251
-				$route = $this->urlGenerator->linkToRoute($nav['route']);
252
-				$icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
253
-				foreach ([$icon, "$app.svg"] as $i) {
254
-					try {
255
-						$icon = $this->urlGenerator->imagePath($app, $i);
256
-						break;
257
-					} catch (\RuntimeException $ex) {
258
-						// no icon? - ignore it then
259
-					}
260
-				}
261
-				if ($icon === null) {
262
-					$icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
263
-				}
231
+            // load plugins and collections from info.xml
232
+            $info = $this->appManager->getAppInfo($app);
233
+            if (empty($info['navigations'])) {
234
+                continue;
235
+            }
236
+            foreach ($info['navigations'] as $nav) {
237
+                if (!isset($nav['name'])) {
238
+                    continue;
239
+                }
240
+                if (!isset($nav['route'])) {
241
+                    continue;
242
+                }
243
+                $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
244
+                if ($role === 'admin' && !$this->isAdmin()) {
245
+                    continue;
246
+                }
247
+                $l = $this->l10nFac->get($app);
248
+                $id = isset($nav['id']) ? $nav['id'] : $app;
249
+                $order = isset($nav['order']) ? $nav['order'] : 100;
250
+                $type = isset($nav['type']) ? $nav['type'] : 'link';
251
+                $route = $this->urlGenerator->linkToRoute($nav['route']);
252
+                $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
253
+                foreach ([$icon, "$app.svg"] as $i) {
254
+                    try {
255
+                        $icon = $this->urlGenerator->imagePath($app, $i);
256
+                        break;
257
+                    } catch (\RuntimeException $ex) {
258
+                        // no icon? - ignore it then
259
+                    }
260
+                }
261
+                if ($icon === null) {
262
+                    $icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
263
+                }
264 264
 
265
-				$this->add([
266
-					'id' => $id,
267
-					'order' => $order,
268
-					'href' => $route,
269
-					'icon' => $icon,
270
-					'type' => $type,
271
-					'name' => $l->t($nav['name']),
272
-				]);
273
-			}
274
-		}
275
-	}
265
+                $this->add([
266
+                    'id' => $id,
267
+                    'order' => $order,
268
+                    'href' => $route,
269
+                    'icon' => $icon,
270
+                    'type' => $type,
271
+                    'name' => $l->t($nav['name']),
272
+                ]);
273
+            }
274
+        }
275
+    }
276 276
 
277
-	private function isAdmin() {
278
-		$user = $this->userSession->getUser();
279
-		if ($user !== null) {
280
-			return $this->groupManager->isAdmin($user->getUID());
281
-		}
282
-		return false;
283
-	}
277
+    private function isAdmin() {
278
+        $user = $this->userSession->getUser();
279
+        if ($user !== null) {
280
+            return $this->groupManager->isAdmin($user->getUID());
281
+        }
282
+        return false;
283
+    }
284 284
 
285
-	private function isSubadmin() {
286
-		$user = $this->userSession->getUser();
287
-		if ($user !== null) {
288
-			return $this->groupManager->getSubAdmin()->isSubAdmin($user);
289
-		}
290
-		return false;
291
-	}
285
+    private function isSubadmin() {
286
+        $user = $this->userSession->getUser();
287
+        if ($user !== null) {
288
+            return $this->groupManager->getSubAdmin()->isSubAdmin($user);
289
+        }
290
+        return false;
291
+    }
292 292
 }
Please login to merge, or discard this patch.