Your IP : 216.73.216.240
<?php
/**
* @copyright
* @package Easybook Reloaded - EBR for Joomla! 3.x
* @author Viktor Vogel <admin@kubik-rubik.de>
* @version 3.4.1.1-FREE - 2021-08-29
* @link https://kubik-rubik.de/ebr-easybook-reloaded
*
* @license GNU/GPL
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
defined('_JEXEC') || die('Restricted access');
use EasybookReloaded\Helper;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\{Factory, Session\Session, Language\Text, Router\Route};
/**
* Class EasybookReloadedControllerEntry
*
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
class EasybookReloadedControllerEntry extends BaseController
{
/**
* @var object $input
* @since 3.4.0-FREE
*/
protected $input;
/**
* EasybookReloadedControllerEntry constructor.
*
* @throws Exception
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
public function __construct()
{
parent::__construct();
$this->registerTask('add', 'edit');
$this->registerTask('apply', 'save');
$this->input = Factory::getApplication()->input;
if ($this->input->getCmd('task', '') === '') {
$view = $this->getView('easybookreloaded', 'html');
if ($modelGb = $this->getModel('gb')) {
$view->setModel($modelGb, false);
}
Helper::addSubmenu($this->input->getCmd('view', 'easybookreloaded'));
}
}
/**
* Loads the edit page
*
* @throws Exception
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
public function edit(): void
{
$this->input->set('view', 'entry');
$this->input->set('layout', 'form');
$this->input->set('hidemainmenu', 1);
$view = $this->getView('entry', 'html');
$view->setLayout('form');
if ($modelGb = $this->getModel('gb')) {
$view->setModel($modelGb, false);
}
$this->display();
}
/**
* Executes the saving process
*
* @throws Exception
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
public function save(): void
{
Session::checkToken() || jexit('Invalid Token');
$message = Text::_('COM_EASYBOOKRELOADED_ERROR_SAVING_ENTRY');
$type = 'error';
/* @var EasybookReloadedModelEntry $model */
$model = $this->getModel('entry');
if ($model->store()) {
$message = Text::_('COM_EASYBOOKRELOADED_ENTRY_SAVED');
$type = 'message';
}
if ($this->task === 'apply') {
$this->setRedirect('index.php?' . $this->input->getString('url_current'), $message, $type);
return;
}
$this->setRedirect('index.php?option=com_easybookreloaded', $message, $type);
}
/**
* Executes the removing process
*
* @throws Exception
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
public function remove(): void
{
Session::checkToken() || jexit('Invalid Token');
$message = Text::_('COM_EASYBOOKRELOADED_ERROR_ENTRY_COULD_NOT_BE_DELETED');
$type = 'error';
/* @var EasybookReloadedModelEntry $model */
$model = $this->getModel('entry');
if ($model->delete()) {
$message = Text::_('COM_EASYBOOKRELOADED_ENTRY_DELETED');
$type = 'message';
}
$this->setRedirect(Route::_('index.php?option=com_easybookreloaded', false), $message, $type);
}
/**
* Executes the cancellation process
*
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
public function cancel(): void
{
$message = Text::_('COM_EASYBOOKRELOADED_OPERATION_CANCELLED');
$this->setRedirect('index.php?option=com_easybookreloaded', $message, 'notice');
}
/**
* Executes the publishing process
*
* @throws Exception
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
public function publish(): void
{
Session::checkToken() || jexit('Invalid Token');
$message = Text::_('COM_EASYBOOKRELOADED_ENTRY_PUBLISHED');
$type = 'message';
/* @var EasybookReloadedModelEntry $model */
$model = $this->getModel('entry');
if (!$model->publish(1)) {
$message = Text::_('COM_EASYBOOKRELOADED_ERROR_COULD_NOT_CHANGE_PUBLISH_STATUS') . " - " . $model->getError();
$type = 'error';
}
$this->setRedirect(Route::_('index.php?option=com_easybookreloaded', false), $message, $type);
}
/**
* Executes the unpublishing process
*
* @throws Exception
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
public function unpublish(): void
{
Session::checkToken() || jexit('Invalid Token');
$message = Text::_('COM_EASYBOOKRELOADED_ENTRY_UNPUBLISHED');
$type = 'message';
/* @var EasybookReloadedModelEntry $model */
$model = $this->getModel('entry');
if (!$model->publish(0)) {
$message = Text::_('COM_EASYBOOKRELOADED_ERROR_COULD_NOT_CHANGE_PUBLISH_STATUS') . " - " . $model->getError();
$type = 'error';
}
$this->setRedirect(Route::_('index.php?option=com_easybookreloaded', false), $message, $type);
}
}