1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author René Gieling <[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\Polls\Controller; |
25
|
|
|
|
26
|
|
|
use OCP\IRequest; |
27
|
|
|
use OCP\IURLGenerator; |
28
|
|
|
use OCP\AppFramework\Controller; |
29
|
|
|
use OCP\AppFramework\Http\DataResponse; |
30
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
31
|
|
|
|
32
|
|
|
use OCA\Polls\Db\Poll; |
33
|
|
|
use OCA\Polls\Service\PollService; |
34
|
|
|
|
35
|
|
|
class AdminController extends Controller { |
36
|
|
|
|
37
|
|
|
/** @var IURLGenerator */ |
38
|
|
|
private $urlGenerator; |
39
|
|
|
|
40
|
|
|
/** @var PollService */ |
41
|
|
|
private $pollService; |
42
|
|
|
|
43
|
|
|
/** @var Poll */ |
44
|
|
|
private $poll; |
45
|
|
|
|
46
|
|
|
use ResponseHandle; |
47
|
|
|
|
48
|
|
|
public function __construct( |
49
|
|
|
string $appName, |
50
|
|
|
IRequest $request, |
51
|
|
|
IURLGenerator $urlGenerator, |
52
|
|
|
PollService $pollService, |
53
|
|
|
Poll $poll |
54
|
|
|
) { |
55
|
|
|
parent::__construct($appName, $request); |
56
|
|
|
$this->urlGenerator = $urlGenerator; |
57
|
|
|
$this->pollService = $pollService; |
58
|
|
|
$this->poll = $poll; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @NoCSRFRequired |
63
|
|
|
*/ |
64
|
|
|
public function index(): TemplateResponse { |
65
|
|
|
return new TemplateResponse('polls', 'polls.tmpl', |
66
|
|
|
['urlGenerator' => $this->urlGenerator]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get list of polls for administrative purposes |
71
|
|
|
*/ |
72
|
|
|
public function list(): DataResponse { |
73
|
|
|
return $this->response(function () { |
74
|
|
|
return $this->pollService->listForAdmin(); |
75
|
|
|
}); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Get list of polls for administrative purposes |
80
|
|
|
*/ |
81
|
|
|
public function takeover(int $pollId): DataResponse { |
82
|
|
|
return $this->response(function () use ($pollId) { |
83
|
|
|
return $this->pollService->takeover($pollId); |
84
|
|
|
}); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Switch deleted status (move to deleted polls) |
89
|
|
|
*/ |
90
|
|
|
public function switchDeleted(int $pollId): DataResponse { |
91
|
|
|
return $this->response(function () use ($pollId) { |
92
|
|
|
return $this->pollService->switchDeleted($pollId); |
93
|
|
|
}); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Delete poll |
98
|
|
|
*/ |
99
|
|
|
public function delete(int $pollId): DataResponse { |
100
|
|
|
return $this->responseDeleteTolerant(function () use ($pollId) { |
101
|
|
|
return $this->pollService->delete($pollId); |
102
|
|
|
}); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|