Completed
Push — master ( 4a6e31...2a2ab1 )
by Morris
18:03
created

PublicTemplateResponse::setFooterVisible()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2018 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[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 OCP\AppFramework\Http\Template;
25
26
use InvalidArgumentException;
27
use OCP\AppFramework\Http\TemplateResponse;
28
29
/**
30
 * Class PublicTemplateResponse
31
 *
32
 * @package OCP\AppFramework\Http\Template
33
 * @since 14.0.0
34
 */
35
class PublicTemplateResponse extends TemplateResponse {
36
37
	private $headerTitle = '';
38
	private $headerDetails = '';
39
	private $headerActions = [];
40
	private $footerVisible = true;
41
42
	/**
43
	 * PublicTemplateResponse constructor.
44
	 *
45
	 * @param string $appName
46
	 * @param string $templateName
47
	 * @param array $params
48
	 * @since 14.0.0
49
	 */
50
	public function __construct(string $appName, string $templateName, array $params = array()) {
51
		parent::__construct($appName, $templateName, $params, 'public');
52
		\OC_Util::addScript('core', 'public/publicpage');
53
	}
54
55
	/**
56
	 * @param string $title
57
	 * @since 14.0.0
58
	 */
59
	public function setHeaderTitle(string $title) {
60
		$this->headerTitle = $title;
61
	}
62
63
	/**
64
	 * @return string
65
	 * @since 14.0.0
66
	 */
67
	public function getHeaderTitle(): string {
68
		return $this->headerTitle;
69
	}
70
71
	/**
72
	 * @param string $details
73
	 * @since 14.0.0
74
	 */
75
	public function setHeaderDetails(string $details) {
76
		$this->headerDetails = $details;
77
	}
78
79
	/**
80
	 * @return string
81
	 * @since 14.0.0
82
	 */
83
	public function getHeaderDetails(): string {
84
		return $this->headerDetails;
85
	}
86
87
	/**
88
	 * @param array $actions
89
	 * @since 14.0.0
90
	 * @throws InvalidArgumentException
91
	 */
92
	public function setHeaderActions(array $actions) {
93
		foreach ($actions as $action) {
94
			if ($actions instanceof IMenuAction) {
95
				throw new InvalidArgumentException('Actions must be of type IMenuAction');
96
			}
97
			$this->headerActions[] = $action;
98
		}
99
		usort($this->headerActions, function(IMenuAction $a, IMenuAction $b) {
100
			return $a->getPriority() > $b->getPriority();
101
		});
102
	}
103
104
	/**
105
	 * @return IMenuAction
106
	 * @since 14.0.0
107
	 * @throws \Exception
108
	 */
109
	public function getPrimaryAction(): IMenuAction {
110
		if ($this->getActionCount() > 0) {
111
			return $this->headerActions[0];
112
		}
113
		throw new \Exception('No header actions have been set');
114
	}
115
116
	/**
117
	 * @return int
118
	 * @since 14.0.0
119
	 */
120
	public function getActionCount(): int {
121
		return count($this->headerActions);
122
	}
123
124
	/**
125
	 * @return IMenuAction[]
126
	 * @since 14.0.0
127
	 */
128
	public function getOtherActions(): array {
129
		return array_slice($this->headerActions, 1);
130
	}
131
132
	/**
133
	 * @since 14.0.0
134
	 */
135
	public function setFooterVisible(bool $visible = false) {
136
		$this->footerVisible = $visible;
137
	}
138
139
	/**
140
	 * @since 14.0.0
141
	 */
142
	public function getFooterVisible(): bool {
143
		return $this->footerVisible;
144
	}
145
146
	/**
147
	 * @return string
148
	 * @since 14.0.0
149
	 */
150
	public function render(): string {
151
		$params = array_merge($this->getParams(), [
152
			'template' => $this,
153
		]);
154
		$this->setParams($params);
155
		return  parent::render();
156
	}
157
158
}