2018-01-25 20:56:15 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
|
|
|
|
*
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCP\AppFramework\Http\Template;
|
|
|
|
|
2018-02-09 17:12:49 +03:00
|
|
|
use InvalidArgumentException;
|
2018-01-25 20:56:15 +03:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
|
2018-02-09 11:41:04 +03:00
|
|
|
/**
|
|
|
|
* Class PublicTemplateResponse
|
|
|
|
*
|
|
|
|
* @package OCP\AppFramework\Http\Template
|
|
|
|
* @since 14.0.0
|
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
class PublicTemplateResponse extends TemplateResponse {
|
|
|
|
|
|
|
|
private $headerTitle = '';
|
|
|
|
private $headerDetails = '';
|
|
|
|
private $headerActions = [];
|
2018-04-05 13:22:01 +03:00
|
|
|
private $footerVisible = true;
|
2018-01-25 20:56:15 +03:00
|
|
|
|
2018-02-09 11:41:04 +03:00
|
|
|
/**
|
|
|
|
* PublicTemplateResponse constructor.
|
|
|
|
*
|
|
|
|
* @param string $appName
|
|
|
|
* @param string $templateName
|
|
|
|
* @param array $params
|
|
|
|
* @since 14.0.0
|
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function __construct(string $appName, string $templateName, array $params = array()) {
|
|
|
|
parent::__construct($appName, $templateName, $params, 'public');
|
|
|
|
\OC_Util::addScript('core', 'public/publicpage');
|
|
|
|
}
|
|
|
|
|
2018-02-09 11:41:04 +03:00
|
|
|
/**
|
|
|
|
* @param string $title
|
|
|
|
* @since 14.0.0
|
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function setHeaderTitle(string $title) {
|
|
|
|
$this->headerTitle = $title;
|
|
|
|
}
|
|
|
|
|
2018-02-09 11:41:04 +03:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
* @since 14.0.0
|
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function getHeaderTitle(): string {
|
|
|
|
return $this->headerTitle;
|
|
|
|
}
|
|
|
|
|
2018-02-09 11:41:04 +03:00
|
|
|
/**
|
|
|
|
* @param string $details
|
|
|
|
* @since 14.0.0
|
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function setHeaderDetails(string $details) {
|
|
|
|
$this->headerDetails = $details;
|
|
|
|
}
|
|
|
|
|
2018-02-09 11:41:04 +03:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
* @since 14.0.0
|
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function getHeaderDetails(): string {
|
|
|
|
return $this->headerDetails;
|
|
|
|
}
|
|
|
|
|
2018-02-09 11:41:04 +03:00
|
|
|
/**
|
|
|
|
* @param array $actions
|
|
|
|
* @since 14.0.0
|
2018-02-09 17:12:49 +03:00
|
|
|
* @throws InvalidArgumentException
|
2018-02-09 11:41:04 +03:00
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function setHeaderActions(array $actions) {
|
|
|
|
foreach ($actions as $action) {
|
|
|
|
if ($actions instanceof IMenuAction) {
|
2018-02-09 17:12:49 +03:00
|
|
|
throw new InvalidArgumentException('Actions must be of type IMenuAction');
|
2018-01-25 20:56:15 +03:00
|
|
|
}
|
|
|
|
$this->headerActions[] = $action;
|
|
|
|
}
|
2018-02-09 17:12:49 +03:00
|
|
|
usort($this->headerActions, function(IMenuAction $a, IMenuAction $b) {
|
|
|
|
return $a->getPriority() > $b->getPriority();
|
|
|
|
});
|
2018-01-25 20:56:15 +03:00
|
|
|
}
|
|
|
|
|
2018-02-09 11:41:04 +03:00
|
|
|
/**
|
|
|
|
* @return IMenuAction
|
|
|
|
* @since 14.0.0
|
2018-02-09 17:12:49 +03:00
|
|
|
* @throws \Exception
|
2018-02-09 11:41:04 +03:00
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function getPrimaryAction(): IMenuAction {
|
2018-02-09 17:12:49 +03:00
|
|
|
if ($this->getActionCount() > 0) {
|
|
|
|
return $this->headerActions[0];
|
2018-01-25 20:56:15 +03:00
|
|
|
}
|
2018-02-09 17:12:49 +03:00
|
|
|
throw new \Exception('No header actions have been set');
|
2018-01-25 20:56:15 +03:00
|
|
|
}
|
|
|
|
|
2018-02-09 11:41:04 +03:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
* @since 14.0.0
|
|
|
|
*/
|
2018-01-25 20:56:15 +03:00
|
|
|
public function getActionCount(): int {
|
|
|
|
return count($this->headerActions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return IMenuAction[]
|
2018-02-09 11:41:04 +03:00
|
|
|
* @since 14.0.0
|
2018-01-25 20:56:15 +03:00
|
|
|
*/
|
|
|
|
public function getOtherActions(): array {
|
2018-02-09 17:12:49 +03:00
|
|
|
return array_slice($this->headerActions, 1);
|
2018-01-25 20:56:15 +03:00
|
|
|
}
|
|
|
|
|
2018-04-05 13:22:01 +03:00
|
|
|
/**
|
|
|
|
* @since 14.0.0
|
|
|
|
*/
|
|
|
|
public function setFooterVisible(bool $visible = false) {
|
|
|
|
$this->footerVisible = $visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 14.0.0
|
|
|
|
*/
|
|
|
|
public function getFooterVisible(): bool {
|
|
|
|
return $this->footerVisible;
|
|
|
|
}
|
|
|
|
|
2018-02-09 11:41:04 +03:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
* @since 14.0.0
|
|
|
|
*/
|
2018-02-09 17:12:49 +03:00
|
|
|
public function render(): string {
|
2018-01-25 20:56:15 +03:00
|
|
|
$params = array_merge($this->getParams(), [
|
|
|
|
'template' => $this,
|
|
|
|
]);
|
|
|
|
$this->setParams($params);
|
|
|
|
return parent::render();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|