Passed
Pull Request — master (#1281)
by René
03:47
created

AdminController::list()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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