| Current Path : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/Controller/Back/ |
| Current File : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/Controller/Back/TfControllerForm.php |
<?php
/*
* @package Tech Fry Library
* @license https://www.gnu.org/licenses/gpl-3.0.en.html
*/
namespace TechFry\Library\Controller\Back;
defined('_JEXEC') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\Input\Input;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
class TfControllerForm extends FormController
{
// Controller for Backend Form Layouts
public $cparams;
public $today;
public $date_sql;
public $date_unix;
public $date_lc3;
public $juser;
public $user_levels;
public $url;
public $post;
public $get;
public function __construct($config = [], ?MVCFactoryInterface $factory = null, ?CMSApplication $app = null, ?Input $input = null)
{
parent::__construct($config, $factory, $app, $input);
// Available: $this->app, $this->input, $this->option, $this->view_list, $this->view_item
$this->today = Factory::getDate();
$this->date_sql = $this->today->toSql();
$this->date_unix = $this->today->toUnix();
$this->date_lc3 = $this->today->format(Text::_('DATE_FORMAT_LC3'));
$this->juser = $this->app->getIdentity();
$this->user_levels = $this->juser->getAuthorisedViewLevels();
$this->cparams = ComponentHelper::getParams($this->option);
$this->url = Uri::getInstance()->toString();
$this->post = $this->input->post->getArray();
$this->get = $this->input->get->getArray();
}
public function batch($model = null)
{
$model = $this->getModel(ucwords($this->getName()), 'Administrator', array());
$this->setRedirect(Route::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false));
return parent::batch($model);
}
public function cancel($key = null)
{
$result = parent::cancel($key);
// When editing in modal then redirect to modalreturn layout
if ($result && $this->input->get('layout') == 'modal')
{
$id = $this->input->get('id');
$return = 'index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($id)
. '&layout=modalreturn&from-task=cancel';
$this->setRedirect(Route::_($return, false));
}
return $result;
}
protected function postSaveHook(BaseDatabaseModel $model, $validData = [])
{
if ($this->input->get('layout') == 'modal' && $this->task === 'save')
{
// When editing in modal then redirect to modalreturn layout
$id = $model->getState($this->context . '.id', '');
$return = 'index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($id)
. '&layout=modalreturn&from-task=save';
$this->setRedirect(Route::_($return, false));
}
}
public function redirect_to_item($message = '', $type = 'success', $query = [])
{
// success, info, warning, danger/error
if (\is_array($message))
{
$message = print_r($message, true);
}
$this->setMessage($message, $type);
$url = 'index.php?option=' . $this->option . '&view=' . $this->view_item . '&layout=edit';
if (isset($this->get['id']) && $this->get['id'])
{
$url .= '&id=' . $this->get['id'];
}
if (!empty($query))
{
$url .= '&' . http_build_query($query);
}
$this->setRedirect(Route::_($url, false));
}
public function redirect_to_list($message = '', $type = 'success', $query = array())
{
if (\is_array($message))
{
$message = print_r($message, true);
}
$this->setMessage($message, $type);
$url = 'index.php?option=' . $this->option . '&view=' . $this->view_list;
if (!empty($query))
{
$url .= '&' . http_build_query($query);
}
$this->setRedirect(Route::_($url, false));
}
/*
public function custom_function()
{
$data = $this->input->get('jform', array(), 'ARRAY');
$model = $this->getModel();
// Do something with data
$this->setMessage('Display Some Message', 'message');
$this->setRedirect(Route::_('index.php?option=' . $this->option . '&view=<VIEW_NAME>&layout=edit&id=' . $data['id'], false));
}
*/
/*
$view_item, $view_list
cancel(), add(), edit(), save()
*/
}