76 lines
1.6 KiB
PHP
76 lines
1.6 KiB
PHP
<?php
|
|
namespace FooNamespace\Component\Foos\Administrator\Table;
|
|
|
|
\defined('_JEXEC') or die;
|
|
|
|
use Joomla\CMS\Application\ApplicationHelper;
|
|
use Joomla\CMS\Table\Table;
|
|
use Joomla\Database\DatabaseDriver;
|
|
use Joomla\CMS\Language\Text;
|
|
use Joomla\Registry\Registry;
|
|
|
|
class FooTable extends Table
|
|
{
|
|
public function __construct(DatabaseDriver $db)
|
|
{
|
|
$this->typeAlias = 'com_foos.foo';
|
|
|
|
parent::__construct('#__foos_details', 'id', $db);
|
|
}
|
|
|
|
public function generateAlias()
|
|
{
|
|
if (empty($this->alias)) {
|
|
$this->alias = $this->name;
|
|
}
|
|
|
|
$this->alias = ApplicationHelper::stringURLSafe($this->alias, $this->language);
|
|
|
|
if (trim(str_replace('-', '', $this->alias)) == '') {
|
|
$this->alias = Factory::getDate()->format('Y-m-d-H-i-s');
|
|
}
|
|
|
|
return $this->alias;
|
|
}
|
|
|
|
public function check()
|
|
{
|
|
try {
|
|
parent::check();
|
|
} catch (\Exception $e) {
|
|
$this->setError($e->getMessage());
|
|
|
|
return false;
|
|
}
|
|
|
|
// Check the publish down date is not earlier than publish up.
|
|
if ($this->publish_down > $this->_db->getNullDate() && $this->publish_down < $this->publish_up) {
|
|
$this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
|
|
|
|
return false;
|
|
}
|
|
|
|
// Set publish_up, publish_down to null if not set
|
|
if (!$this->publish_up) {
|
|
$this->publish_up = null;
|
|
}
|
|
|
|
if (!$this->publish_down) {
|
|
$this->publish_down = null;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function store($updateNulls = true)
|
|
{
|
|
// Transform the params field
|
|
if (is_array($this->params)) {
|
|
$registry = new Registry($this->params);
|
|
$this->params = (string) $registry;
|
|
}
|
|
|
|
return parent::store($updateNulls);
|
|
}
|
|
}
|