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 Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\{Factory, Language\Text};
/**
* Class EasybookReloadedModelEntryGB
*
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
class EasybookReloadedModelEntryGB extends BaseDatabaseModel
{
/**
* @var object $data
* @since 3.4.0-FREE
*/
protected $data;
/**
* @var int $id
* @since 3.4.0-FREE
*/
protected $id;
/**
* @var object $input
* @since 3.4.0-FREE
*/
protected $input;
/**
* EasybookReloadedModelEntryGB constructor.
*
* @throws Exception
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
public function __construct()
{
parent::__construct();
$this->input = Factory::getApplication()->input;
$id = $this->input->get('cid', [0], 'ARRAY');
$this->setId((int)$id[0]);
}
/**
* Sets the ID and the data variables
*
* @param int $id
*
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
public function setId(int $id): void
{
$this->id = $id;
$this->data = null;
}
/**
* Gets the data from the database
*
* @return JTable|mixed|null
* @throws Exception
* @since 3.4.0-FREE
*/
public function getData()
{
if (empty($this->data)) {
$query = "SELECT * FROM " . $this->_db->quoteName('#__easybook_gb') . " WHERE " . $this->_db->quoteName('id') . " = " . $this->_db->quote($this->id);
$this->_db->setQuery($query);
$this->data = $this->_db->loadObject();
}
if (!$this->data) {
$this->data = $this->getTable('entrygb', 'EasybookReloadedTable');
$this->data->id = 0;
}
return $this->data;
}
/**
* Stores the data from the database
*
* @return bool
* @throws Exception
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
public function store(): bool
{
$row = $this->getTable('entrygb', 'EasybookReloadedTable');
// Load all request variables
$data = $this->input->request->getArray();
array_walk(
$data,
static function (&$data) {
$data = htmlspecialchars(strip_tags(trim($data)));
}
);
// Get unfiltered request variable of specific input fields (with formatting)
$data['introtext'] = htmlspecialchars($this->input->get('introtext', '', 'RAW'));
if (!$row->save($data)) {
throw new Exception(Text::_('JERROR_AN_ERROR_HAS_OCCURRED'), 404);
}
return true;
}
/**
* Deletes the data from the database
*
* @return bool
* @throws Exception
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
public function delete(): bool
{
$cIds = $this->input->get('cid', 0, 'ARRAY');
$row = $this->getTable('entrygb', 'EasybookReloadedTable');
foreach ($cIds as $cId) {
if (!$row->delete($cId)) {
throw new Exception(Text::_('JERROR_AN_ERROR_HAS_OCCURRED'), 404);
}
}
return true;
}
}