|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OCA\AppOrder\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use \OCP\AppFramework\Controller; |
|
6
|
|
|
use \OCP\AppFramework\Http\TemplateResponse; |
|
7
|
|
|
use \OCP\IRequest; |
|
8
|
|
|
use \OCP\INavigationManager; |
|
9
|
|
|
use \OCA\AppOrder\Service\ConfigService; |
|
10
|
|
|
|
|
11
|
|
|
class SettingsController extends Controller { |
|
12
|
|
|
|
|
13
|
|
|
private $userId; |
|
14
|
|
|
private $l10n; |
|
|
|
|
|
|
15
|
|
|
private $appConfig; |
|
16
|
|
|
private $navigationManager; |
|
17
|
|
|
|
|
18
|
7 |
|
public function __construct($appName, IRequest $request, ConfigService $appConfig, INavigationManager $navigationManager, $userId) { |
|
|
|
|
|
|
19
|
7 |
|
parent::__construct($appName, $request); |
|
20
|
7 |
|
$this->userId = $userId; |
|
21
|
7 |
|
$this->appConfig = $appConfig; |
|
22
|
7 |
|
$this->navigationManager = $navigationManager; |
|
23
|
7 |
|
} |
|
24
|
|
|
|
|
25
|
1 |
|
public function adminIndex() { |
|
26
|
1 |
|
$navigation = $this->navigationManager->getAll(); |
|
27
|
1 |
|
$order = json_decode($this->appConfig->getAppValue('order')); |
|
28
|
1 |
|
$nav = $this->matchOrder($navigation, $order); |
|
29
|
1 |
|
return new TemplateResponse( |
|
30
|
1 |
|
$this->appName, |
|
31
|
1 |
|
'admin', |
|
32
|
1 |
|
["nav" => $nav], |
|
33
|
1 |
|
'blank' |
|
34
|
|
|
); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
3 |
|
public function getAppOrder() { |
|
38
|
3 |
|
$order_user = $this->appConfig->getUserValue('order', $this->userId); |
|
39
|
3 |
|
$order_default = $this->appConfig->getAppValue('order'); |
|
40
|
3 |
|
if ($order_user !== null && $order_user !== "") |
|
41
|
2 |
|
$order = $order_user; |
|
42
|
|
|
else |
|
43
|
1 |
|
$order = $order_default; |
|
44
|
3 |
|
return $order; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
2 |
|
public function matchOrder($nav, $order) { |
|
48
|
2 |
|
$nav_tmp = array(); |
|
49
|
2 |
|
$result = array(); |
|
50
|
2 |
|
foreach ($nav as $app) |
|
51
|
2 |
|
$nav_tmp[$app['href']] = $app; |
|
52
|
2 |
|
foreach ($order as $app) |
|
53
|
2 |
|
$result[$app] = $nav_tmp[$app]; |
|
54
|
2 |
|
foreach ($nav as $app) |
|
55
|
2 |
|
if (!array_key_exists($app['href'], $result)) |
|
56
|
2 |
|
$result[$app['href']] = $app; |
|
57
|
2 |
|
return $result; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @NoAdminRequired |
|
62
|
|
|
*/ |
|
63
|
1 |
|
public function getOrder() { |
|
64
|
1 |
|
$order = $this->getAppOrder(); |
|
65
|
1 |
|
return array('status' => 'success', 'order' => $order); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @NoAdminRequired |
|
70
|
|
|
*/ |
|
71
|
1 |
|
public function savePersonal($order) { |
|
72
|
1 |
|
$this->appConfig->setUserValue('order', $this->userId, $order); |
|
73
|
|
|
$response = array( |
|
74
|
1 |
|
'status' => 'success', |
|
75
|
|
|
'data' => array('message'=> 'User order saved successfully.'), |
|
76
|
1 |
|
'order' => $order |
|
77
|
|
|
); |
|
78
|
1 |
|
return $response; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
1 |
|
public function saveDefaultOrder($order) { |
|
82
|
1 |
|
if (!is_null($order)) { |
|
83
|
1 |
|
$this->appConfig->setAppValue('order', $order); |
|
84
|
|
|
} |
|
85
|
1 |
|
return array('status' => 'success', 'order' => $order); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.