Completed
Push — master ( 8e98e3...862cae )
by Raimund
02:08 queued 48s
created

PageController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 5
1
<?php
2
/**
3
 * Nextcloud - Tasks
4
 *
5
 * @author Raimund Schlüßler
6
 * @copyright 2018 Raimund Schlüßler <[email protected]>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
namespace OCA\Tasks\Controller;
24
25
use \OCP\AppFramework\Controller;
26
use \OCP\AppFramework\Http\TemplateResponse;
27
use \OCP\AppFramework\Http\NotFoundResponse;
28
use \OCP\IRequest;
29
use \OCP\IUserSession;
30
use \OCP\IConfig;
31
32
/**
33
 * Controller class for main page.
34
 */
35
class PageController extends Controller {
36
37
	/**
38
	 * @param string $appName
39
	 * @param IUserSession $userSession
40
	 * @param IConfig $config
41
	 */
42
	public function __construct($appName, IRequest $request, IUserSession $userSession,
43
								$userId, IConfig $config) {
44
		parent::__construct($appName, $request);
45
		$this->config = $config;
46
		$this->userSession = $userSession;
47
		$this->userId = $userId;
48
	}
49
50
51
	/**
52
	 * @NoAdminRequired
53
	 * @NoCSRFRequired
54
	 */
55
	public function index() {
56
		\OCP\Util::connectHook('\OCP\Config', 'js', $this, 'addJavaScriptVariablesForIndex');
57
		return new TemplateResponse('tasks', 'main');
58
	}
59
60
61
	/**
62
	 * @NoAdminRequired
63
	 * @NoCSRFRequired
64
	 */
65
	public function templates($template) {
66
		$templates = array(	'confirmation');
67
		if (in_array($template, $templates)) {
68
			$response = new TemplateResponse('tasks', $template, [], 'blank');
69
		} else {
70
			$response = new NotFoundResponse();
71
		}
72
		return $response;
73
	}
74
75
	/**
76
	 * Add parameters to javascript for user sites
77
	 *
78
	 * @param array $array
79
	 */
80
	public function addJavaScriptVariablesForIndex(array $array) {
81
		$user = $this->userSession->getUser();
82
		if ($user === null) {
83
			return;
84
		}
85
		$appversion = $this->config->getAppValue($this->appName, 'installed_version');
86
		$array['array']['oca_tasks'] = \json_encode([
87
			'versionstring' => $appversion,
88
		]);
89
	}
90
}
91