1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CMS Pico - Create websites using Pico CMS for Nextcloud. |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2017, Maxence Lange (<[email protected]>) |
6
|
|
|
* @copyright Copyright (c) 2019, Daniel Rudolf (<[email protected]>) |
7
|
|
|
* |
8
|
|
|
* @license GNU AGPL version 3 or any later version |
9
|
|
|
* |
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
13
|
|
|
* License, or (at your option) any later version. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU Affero General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Affero General Public License |
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
declare(strict_types=1); |
25
|
|
|
|
26
|
|
|
namespace OCA\CMSPico\Controller; |
27
|
|
|
|
28
|
|
|
use OCA\CMSPico\AppInfo\Application; |
29
|
|
|
use OCA\CMSPico\Service\WebsitesService; |
30
|
|
|
use OCP\AppFramework\Controller; |
31
|
|
|
use OCP\AppFramework\Http\DataResponse; |
32
|
|
|
use OCP\ILogger; |
33
|
|
|
use OCP\IRequest; |
34
|
|
|
|
35
|
|
|
class SettingsController extends Controller |
36
|
|
|
{ |
37
|
|
|
use ControllerTrait; |
38
|
|
|
|
39
|
|
|
/** @var WebsitesService */ |
40
|
|
|
private $websitesService; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* SettingsController constructor. |
44
|
|
|
* |
45
|
|
|
* @param IRequest $request |
46
|
|
|
* @param ILogger $logger |
47
|
|
|
* @param WebsitesService $websitesService |
48
|
|
|
*/ |
49
|
|
|
public function __construct(IRequest $request, ILogger $logger, WebsitesService $websitesService) |
50
|
|
|
{ |
51
|
|
|
parent::__construct(Application::APP_NAME, $request); |
52
|
|
|
|
53
|
|
|
$this->logger = $logger; |
54
|
|
|
$this->websitesService = $websitesService; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param array $data |
59
|
|
|
* |
60
|
|
|
* @return DataResponse |
61
|
|
|
*/ |
62
|
|
|
public function setLimitGroups(array $data): DataResponse |
63
|
|
|
{ |
64
|
|
|
try { |
65
|
|
|
if (!isset($data['limit_groups'])) { |
66
|
|
|
throw new \UnexpectedValueException(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$limitGroups = $data['limit_groups'] ? explode('|', $data['limit_groups']) : []; |
70
|
|
|
$this->websitesService->setLimitGroups($limitGroups); |
71
|
|
|
|
72
|
|
|
return new DataResponse(); |
73
|
|
|
} catch (\Throwable $e) { |
74
|
|
|
return $this->createErrorResponse($e); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param array $data |
80
|
|
|
* |
81
|
|
|
* @return DataResponse |
82
|
|
|
*/ |
83
|
|
|
public function setLinkMode(array $data): DataResponse |
84
|
|
|
{ |
85
|
|
|
try { |
86
|
|
|
if (!isset($data['link_mode'])) { |
87
|
|
|
throw new \UnexpectedValueException(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$this->websitesService->setLinkMode((int) $data['link_mode']); |
91
|
|
|
|
92
|
|
|
return new DataResponse(); |
93
|
|
|
} catch (\Throwable $e) { |
94
|
|
|
return $this->createErrorResponse($e); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|