|
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
|
4 |
|
public function __construct($appName, IRequest $request, ConfigService $appConfig, INavigationManager $urlGenerator, Util $util, $userId) { |
|
|
|
|
|
|
41
|
4 |
|
parent::__construct($appName, $request); |
|
42
|
4 |
|
$this->userId = $userId; |
|
43
|
4 |
|
$this->appConfig = $appConfig; |
|
44
|
4 |
|
$this->navigationManager = $urlGenerator; |
|
45
|
4 |
|
$this->util = $util; |
|
46
|
4 |
|
} |
|
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() { |
|
|
|
|
|
|
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
|
1 |
|
'blank' |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
View Code Duplication |
public function personalIndex() { |
|
|
|
|
|
|
68
|
|
|
// Private API call |
|
69
|
|
|
$navigation = $this->navigationManager->getAll(); |
|
70
|
|
|
$order = json_decode($this->appConfig->getUserValue('order', $this->userId)); |
|
71
|
|
|
$nav = $this->util->matchOrder($navigation, $order); |
|
72
|
|
|
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
|
|
|
} |
|
90
|
|
|
return array('status' => 'success', 'order' => $order); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Return order for current user |
|
95
|
|
|
* |
|
96
|
|
|
* @NoAdminRequired |
|
97
|
|
|
* @return array response |
|
98
|
1 |
|
*/ |
|
99
|
1 |
|
public function getOrder() { |
|
100
|
|
|
$order = $this->util->getAppOrder(); |
|
101
|
1 |
|
return array('status' => 'success', 'order' => $order); |
|
102
|
|
|
} |
|
103
|
1 |
|
|
|
104
|
|
|
/** |
|
105
|
1 |
|
* Save order for current user |
|
106
|
|
|
* |
|
107
|
|
|
* @NoAdminRequired |
|
108
|
|
|
* @param $order string |
|
109
|
|
|
* @return array response |
|
110
|
|
|
*/ |
|
111
|
|
|
public function savePersonal($order) { |
|
112
|
|
|
$this->appConfig->setUserValue('order', $this->userId, $order); |
|
113
|
|
|
$response = array( |
|
114
|
|
|
'status' => 'success', |
|
115
|
|
|
'data' => array('message' => 'User order saved successfully.'), |
|
116
|
|
|
'order' => $order |
|
117
|
|
|
); |
|
118
|
|
|
return $response; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|
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.