Completed
Pull Request — master (#40)
by
unknown
01:55
created

SettingsController::getOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
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 7
	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 7
		parent::__construct($appName, $request);
42 7
		$this->userId = $userId;
43 7
		$this->appConfig = $appConfig;
44 7
		$this->navigationManager = $urlGenerator;
45 7
		$this->util = $util;
46 7
	}
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
		$hidden = json_decode($this->appConfig->getAppValue('hidden'));
60 1
		return new TemplateResponse(
61 1
			$this->appName,
62 1
			'admin',
63 1
			["nav" => $nav, 'type' => 'admin', 'hidden' => $hidden],
64
			'blank'
65 1
		);
66
	}
67
68 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...
69
		// Private API call
70 1
		$navigation = $this->navigationManager->getAll();
71 1
		$order = json_decode($this->appConfig->getUserValue('order', $this->userId));
72 1
		$nav = $this->util->matchOrder($navigation, $order);
73 1
		$hidden = json_decode($this->appConfig->getUserValue('hidden',$this->userId));
74 1
		return new TemplateResponse(
75 1
			$this->appName,
76 1
			'admin',
77 1
			["nav" => $nav, 'type' => 'personal', 'hidden' => $hidden],
78
			'blank'
79 1
		);
80
	}
81
82
	/**
83
	 * Admin: save default order
84
	 *
85
	 * @param $order
86
	 * @return array response
87
	 */
88 2
	public function saveDefaultOrder($order) {
89 2
		if (!is_null($order)) {
90 2
			$this->appConfig->setAppValue('order', $order);
91 2
		}
92 2
		return array('status' => 'success', 'order' => $order);
93
	}
94
95
	/**
96
	 * Return order for current user
97
	 *
98
	 * @NoAdminRequired
99
	 * @return array response
100
	 */
101 1
	public function getOrder() {
102 1
		$order = $this->util->getAppOrder();
103 1
		$hidden = $this->util->getAppHidden();
104 1
		return array('status' => 'success', 'order' => $order, 'hidden' => $hidden);
105
	}
106
107
	/**
108
	 * Save order for current user
109
	 *
110
	 * @NoAdminRequired
111
	 * @param $order string
112
	 * @return array response
113
	 */
114 2 View Code Duplication
	public function savePersonal($order) {
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...
115 2
		$this->appConfig->setUserValue('order', $this->userId, $order);
116
		$response = array(
117 2
			'status' => 'success',
118 2
			'data' => array('message' => 'User order saved successfully.'),
119
			'order' => $order
120 2
		);
121 2
		return $response;
122
	}
123
124
	/**
125
	 * Save hidden for current user
126
	 *
127
	 * @NoAdminRequired
128
	 * @param $hidden string
129
	 * @return array response
130
	 */
131 View Code Duplication
	public function savePersonalHidden($hidden) {
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...
132
		$this->appConfig->setUserValue('hidden', $this->userId, $hidden);
133
		$response = array(
134
			'status' => 'success',
135
			'data' => array('message' => 'User hidden saved successfully.'),
136
			'hidden' => $hidden
137
		);
138
		return $response;
139
	}
140
141
	/**
142
	 * Admin: save default hidden
143
	 *
144
	 * @param $hidden
145
	 * @return array response
146
	 */
147
	public function saveDefaultHidden($hidden) {
148
		if (!is_null($hidden)) {
149
			$this->appConfig->setAppValue('hidden', $hidden);
150
		}
151
		return array('status' => 'success', 'hidden' => $hidden);
152
	}
153
154
}
155