Completed
Push — master ( 2d89ff...5cbfab )
by Julius
01:31
created

SettingsController::personalIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 12
loc 12
ccs 9
cts 9
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\AppOrder\Controller;
25
26
use \OCP\AppFramework\Controller;
27
use \OCP\AppFramework\Http\TemplateResponse;
28
use \OCP\IRequest;
29
use \OCP\INavigationManager;
30
use \OCA\AppOrder\Service\ConfigService;
31
use \OCA\AppOrder\Util;
32
33
class SettingsController extends Controller {
34
35
	private $userId;
36
	private $appConfig;
37
	private $navigationManager;
38
	private $util;
39
40 5
	public function __construct($appName, IRequest $request, ConfigService $appConfig, INavigationManager $urlGenerator, Util $util, $userId) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 140 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
41 5
		parent::__construct($appName, $request);
42 5
		$this->userId = $userId;
43 5
		$this->appConfig = $appConfig;
44 5
		$this->navigationManager = $urlGenerator;
45 5
		$this->util = $util;
46 5
	}
47
48
	/**
49
	 * Admin: render admin page
50
	 * FIXME: Move to dedicated class
51
	 *
52
	 * @return TemplateResponse
53
	 */
54 1 View Code Duplication
	public function adminIndex() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
		// Private API call
56 1
		$navigation = $this->navigationManager->getAll();
57 1
		$order = json_decode($this->appConfig->getAppValue('order'));
58 1
		$nav = $this->util->matchOrder($navigation, $order);
59 1
		return new TemplateResponse(
60 1
			$this->appName,
61 1
			'admin',
62 1
			["nav" => $nav, 'type' => 'admin'],
63
			'blank'
64 1
		);
65
	}
66
67 1 View Code Duplication
	public function personalIndex() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
		// Private API call
69 1
		$navigation = $this->navigationManager->getAll();
70 1
		$order = json_decode($this->appConfig->getUserValue('order', $this->userId));
71 1
		$nav = $this->util->matchOrder($navigation, $order);
72 1
		return new TemplateResponse(
73 1
			$this->appName,
74 1
			'admin',
75 1
			["nav" => $nav, 'type' => 'personal'],
76
			'blank'
77 1
		);
78
	}
79
80
	/**
81
	 * Admin: save default order
82
	 *
83
	 * @param $order
84
	 * @return array response
85
	 */
86 1
	public function saveDefaultOrder($order) {
87 1
		if (!is_null($order)) {
88 1
			$this->appConfig->setAppValue('order', $order);
89 1
		}
90 1
		return array('status' => 'success', 'order' => $order);
91
	}
92
93
	/**
94
	 * Return order for current user
95
	 *
96
	 * @NoAdminRequired
97
	 * @return array response
98
	 */
99 1
	public function getOrder() {
100 1
		$order = $this->util->getAppOrder();
101 1
		return array('status' => 'success', 'order' => $order);
102
	}
103
104
	/**
105
	 * Save order for current user
106
	 *
107
	 * @NoAdminRequired
108
	 * @param $order string
109
	 * @return array response
110
	 */
111 1
	public function savePersonal($order) {
112 1
		$this->appConfig->setUserValue('order', $this->userId, $order);
113
		$response = array(
114 1
			'status' => 'success',
115 1
			'data' => array('message' => 'User order saved successfully.'),
116
			'order' => $order
117 1
		);
118 1
		return $response;
119
	}
120
121
}
122