primo commit
This commit is contained in:
		@ -0,0 +1,111 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @package     Joomla.Administrator
 | 
			
		||||
 * @subpackage  com_banners
 | 
			
		||||
 *
 | 
			
		||||
 * @copyright   (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
 | 
			
		||||
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Joomla\Component\Banners\Administrator\Controller;
 | 
			
		||||
 | 
			
		||||
use Joomla\CMS\MVC\Controller\FormController;
 | 
			
		||||
use Joomla\CMS\Router\Route;
 | 
			
		||||
use Joomla\CMS\Versioning\VersionableControllerTrait;
 | 
			
		||||
use Joomla\Utilities\ArrayHelper;
 | 
			
		||||
 | 
			
		||||
// phpcs:disable PSR1.Files.SideEffects
 | 
			
		||||
\defined('_JEXEC') or die;
 | 
			
		||||
// phpcs:enable PSR1.Files.SideEffects
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Banner controller class.
 | 
			
		||||
 *
 | 
			
		||||
 * @since  1.6
 | 
			
		||||
 */
 | 
			
		||||
class BannerController extends FormController
 | 
			
		||||
{
 | 
			
		||||
    use VersionableControllerTrait;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The prefix to use with controller messages.
 | 
			
		||||
     *
 | 
			
		||||
     * @var    string
 | 
			
		||||
     * @since  1.6
 | 
			
		||||
     */
 | 
			
		||||
    protected $text_prefix = 'COM_BANNERS_BANNER';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method override to check if you can add a new record.
 | 
			
		||||
     *
 | 
			
		||||
     * @param   array  $data  An array of input data.
 | 
			
		||||
     *
 | 
			
		||||
     * @return  boolean
 | 
			
		||||
     *
 | 
			
		||||
     * @since   1.6
 | 
			
		||||
     */
 | 
			
		||||
    protected function allowAdd($data = [])
 | 
			
		||||
    {
 | 
			
		||||
        $filter     = $this->input->getInt('filter_category_id');
 | 
			
		||||
        $categoryId = ArrayHelper::getValue($data, 'catid', $filter, 'int');
 | 
			
		||||
 | 
			
		||||
        if ($categoryId) {
 | 
			
		||||
            // If the category has been passed in the URL check it.
 | 
			
		||||
            return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // In the absence of better information, revert to the component permissions.
 | 
			
		||||
        return parent::allowAdd($data);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method override to check if you can edit an existing record.
 | 
			
		||||
     *
 | 
			
		||||
     * @param   array   $data  An array of input data.
 | 
			
		||||
     * @param   string  $key   The name of the key for the primary key.
 | 
			
		||||
     *
 | 
			
		||||
     * @return  boolean
 | 
			
		||||
     *
 | 
			
		||||
     * @since   1.6
 | 
			
		||||
     */
 | 
			
		||||
    protected function allowEdit($data = [], $key = 'id')
 | 
			
		||||
    {
 | 
			
		||||
        $recordId   = (int) isset($data[$key]) ? $data[$key] : 0;
 | 
			
		||||
        $categoryId = 0;
 | 
			
		||||
 | 
			
		||||
        if ($recordId) {
 | 
			
		||||
            $categoryId = (int) $this->getModel()->getItem($recordId)->catid;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($categoryId) {
 | 
			
		||||
            // The category has been set. Check the category permissions.
 | 
			
		||||
            return $this->app->getIdentity()->authorise('core.edit', $this->option . '.category.' . $categoryId);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Since there is no asset tracking, revert to the component permissions.
 | 
			
		||||
        return parent::allowEdit($data, $key);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method to run batch operations.
 | 
			
		||||
     *
 | 
			
		||||
     * @param   string  $model  The model
 | 
			
		||||
     *
 | 
			
		||||
     * @return  boolean  True on success.
 | 
			
		||||
     *
 | 
			
		||||
     * @since   2.5
 | 
			
		||||
     */
 | 
			
		||||
    public function batch($model = null)
 | 
			
		||||
    {
 | 
			
		||||
        $this->checkToken();
 | 
			
		||||
 | 
			
		||||
        // Set the model
 | 
			
		||||
        $model = $this->getModel('Banner', '', []);
 | 
			
		||||
 | 
			
		||||
        // Preset the redirect
 | 
			
		||||
        $this->setRedirect(Route::_('index.php?option=com_banners&view=banners' . $this->getRedirectToListAppend(), false));
 | 
			
		||||
 | 
			
		||||
        return parent::batch($model);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,140 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @package     Joomla.Administrator
 | 
			
		||||
 * @subpackage  com_banners
 | 
			
		||||
 *
 | 
			
		||||
 * @copyright   (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
 | 
			
		||||
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Joomla\Component\Banners\Administrator\Controller;
 | 
			
		||||
 | 
			
		||||
use Joomla\CMS\Application\CMSApplication;
 | 
			
		||||
use Joomla\CMS\Language\Text;
 | 
			
		||||
use Joomla\CMS\MVC\Controller\AdminController;
 | 
			
		||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
 | 
			
		||||
use Joomla\CMS\Response\JsonResponse;
 | 
			
		||||
use Joomla\Input\Input;
 | 
			
		||||
use Joomla\Utilities\ArrayHelper;
 | 
			
		||||
 | 
			
		||||
// phpcs:disable PSR1.Files.SideEffects
 | 
			
		||||
\defined('_JEXEC') or die;
 | 
			
		||||
// phpcs:enable PSR1.Files.SideEffects
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Banners list controller class.
 | 
			
		||||
 *
 | 
			
		||||
 * @since  1.6
 | 
			
		||||
 */
 | 
			
		||||
class BannersController extends AdminController
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * The prefix to use with controller messages.
 | 
			
		||||
     *
 | 
			
		||||
     * @var    string
 | 
			
		||||
     * @since  1.6
 | 
			
		||||
     */
 | 
			
		||||
    protected $text_prefix = 'COM_BANNERS_BANNERS';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructor.
 | 
			
		||||
     *
 | 
			
		||||
     * @param   array                 $config   An optional associative array of configuration settings.
 | 
			
		||||
     * @param   ?MVCFactoryInterface  $factory  The factory.
 | 
			
		||||
     * @param   ?CMSApplication       $app      The Application for the dispatcher
 | 
			
		||||
     * @param   ?Input                $input    Input
 | 
			
		||||
     *
 | 
			
		||||
     * @since   3.0
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct($config = [], ?MVCFactoryInterface $factory = null, $app = null, $input = null)
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct($config, $factory, $app, $input);
 | 
			
		||||
 | 
			
		||||
        $this->registerTask('sticky_unpublish', 'sticky_publish');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method to get a model object, loading it if required.
 | 
			
		||||
     *
 | 
			
		||||
     * @param   string  $name    The model name. Optional.
 | 
			
		||||
     * @param   string  $prefix  The class prefix. Optional.
 | 
			
		||||
     * @param   array   $config  Configuration array for model. Optional.
 | 
			
		||||
     *
 | 
			
		||||
     * @return  \Joomla\CMS\MVC\Model\BaseDatabaseModel  The model.
 | 
			
		||||
     *
 | 
			
		||||
     * @since   1.6
 | 
			
		||||
     */
 | 
			
		||||
    public function getModel($name = 'Banner', $prefix = 'Administrator', $config = ['ignore_request' => true])
 | 
			
		||||
    {
 | 
			
		||||
        return parent::getModel($name, $prefix, $config);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Stick items
 | 
			
		||||
     *
 | 
			
		||||
     * @return  void
 | 
			
		||||
     *
 | 
			
		||||
     * @since   1.6
 | 
			
		||||
     */
 | 
			
		||||
    public function sticky_publish()
 | 
			
		||||
    {
 | 
			
		||||
        // Check for request forgeries.
 | 
			
		||||
        $this->checkToken();
 | 
			
		||||
 | 
			
		||||
        $ids    = (array) $this->input->get('cid', [], 'int');
 | 
			
		||||
        $values = ['sticky_publish' => 1, 'sticky_unpublish' => 0];
 | 
			
		||||
        $task   = $this->getTask();
 | 
			
		||||
        $value  = ArrayHelper::getValue($values, $task, 0, 'int');
 | 
			
		||||
 | 
			
		||||
        // Remove zero values resulting from input filter
 | 
			
		||||
        $ids = array_filter($ids);
 | 
			
		||||
 | 
			
		||||
        if (empty($ids)) {
 | 
			
		||||
            $this->app->enqueueMessage(Text::_('COM_BANNERS_NO_BANNERS_SELECTED'), 'warning');
 | 
			
		||||
        } else {
 | 
			
		||||
            // Get the model.
 | 
			
		||||
            /** @var \Joomla\Component\Banners\Administrator\Model\BannerModel $model */
 | 
			
		||||
            $model = $this->getModel();
 | 
			
		||||
 | 
			
		||||
            // Change the state of the records.
 | 
			
		||||
            if (!$model->stick($ids, $value)) {
 | 
			
		||||
                $this->app->enqueueMessage($model->getError(), 'warning');
 | 
			
		||||
            } else {
 | 
			
		||||
                if ($value == 1) {
 | 
			
		||||
                    $ntext = 'COM_BANNERS_N_BANNERS_STUCK';
 | 
			
		||||
                } else {
 | 
			
		||||
                    $ntext = 'COM_BANNERS_N_BANNERS_UNSTUCK';
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                $this->setMessage(Text::plural($ntext, \count($ids)));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->setRedirect('index.php?option=com_banners&view=banners');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method to get the number of published banners for quickicons
 | 
			
		||||
     *
 | 
			
		||||
     * @return  void
 | 
			
		||||
     *
 | 
			
		||||
     * @since   4.3.0
 | 
			
		||||
     */
 | 
			
		||||
    public function getQuickiconContent()
 | 
			
		||||
    {
 | 
			
		||||
        $model = $this->getModel('banners');
 | 
			
		||||
 | 
			
		||||
        $model->setState('filter.published', 1);
 | 
			
		||||
 | 
			
		||||
        $amount = (int) $model->getTotal();
 | 
			
		||||
 | 
			
		||||
        $result = [];
 | 
			
		||||
 | 
			
		||||
        $result['amount'] = $amount;
 | 
			
		||||
        $result['sronly'] = Text::plural('COM_BANNERS_N_QUICKICON_SRONLY', $amount);
 | 
			
		||||
        $result['name']   = Text::plural('COM_BANNERS_N_QUICKICON', $amount);
 | 
			
		||||
 | 
			
		||||
        echo new JsonResponse($result);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,36 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @package     Joomla.Administrator
 | 
			
		||||
 * @subpackage  com_banners
 | 
			
		||||
 *
 | 
			
		||||
 * @copyright   (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
 | 
			
		||||
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Joomla\Component\Banners\Administrator\Controller;
 | 
			
		||||
 | 
			
		||||
use Joomla\CMS\MVC\Controller\FormController;
 | 
			
		||||
use Joomla\CMS\Versioning\VersionableControllerTrait;
 | 
			
		||||
 | 
			
		||||
// phpcs:disable PSR1.Files.SideEffects
 | 
			
		||||
\defined('_JEXEC') or die;
 | 
			
		||||
// phpcs:enable PSR1.Files.SideEffects
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Client controller class.
 | 
			
		||||
 *
 | 
			
		||||
 * @since  1.6
 | 
			
		||||
 */
 | 
			
		||||
class ClientController extends FormController
 | 
			
		||||
{
 | 
			
		||||
    use VersionableControllerTrait;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The prefix to use with controller messages.
 | 
			
		||||
     *
 | 
			
		||||
     * @var    string
 | 
			
		||||
     * @since  1.6
 | 
			
		||||
     */
 | 
			
		||||
    protected $text_prefix = 'COM_BANNERS_CLIENT';
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,49 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @package     Joomla.Administrator
 | 
			
		||||
 * @subpackage  com_banners
 | 
			
		||||
 *
 | 
			
		||||
 * @copyright   (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
 | 
			
		||||
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Joomla\Component\Banners\Administrator\Controller;
 | 
			
		||||
 | 
			
		||||
use Joomla\CMS\MVC\Controller\AdminController;
 | 
			
		||||
 | 
			
		||||
// phpcs:disable PSR1.Files.SideEffects
 | 
			
		||||
\defined('_JEXEC') or die;
 | 
			
		||||
// phpcs:enable PSR1.Files.SideEffects
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Clients list controller class.
 | 
			
		||||
 *
 | 
			
		||||
 * @since  1.6
 | 
			
		||||
 */
 | 
			
		||||
class ClientsController extends AdminController
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * The prefix to use with controller messages.
 | 
			
		||||
     *
 | 
			
		||||
     * @var    string
 | 
			
		||||
     * @since  1.6
 | 
			
		||||
     */
 | 
			
		||||
    protected $text_prefix = 'COM_BANNERS_CLIENTS';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method to get a model object, loading it if required.
 | 
			
		||||
     *
 | 
			
		||||
     * @param   string  $name    The model name. Optional.
 | 
			
		||||
     * @param   string  $prefix  The class prefix. Optional.
 | 
			
		||||
     * @param   array   $config  Configuration array for model. Optional.
 | 
			
		||||
     *
 | 
			
		||||
     * @return  \Joomla\CMS\MVC\Model\BaseDatabaseModel  The model.
 | 
			
		||||
     *
 | 
			
		||||
     * @since   1.6
 | 
			
		||||
     */
 | 
			
		||||
    public function getModel($name = 'Client', $prefix = 'Administrator', $config = ['ignore_request' => true])
 | 
			
		||||
    {
 | 
			
		||||
        return parent::getModel($name, $prefix, $config);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,81 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @package     Joomla.Administrator
 | 
			
		||||
 * @subpackage  com_banners
 | 
			
		||||
 *
 | 
			
		||||
 * @copyright   (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
 | 
			
		||||
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Joomla\Component\Banners\Administrator\Controller;
 | 
			
		||||
 | 
			
		||||
use Joomla\CMS\Language\Text;
 | 
			
		||||
use Joomla\CMS\MVC\Controller\BaseController;
 | 
			
		||||
use Joomla\CMS\Router\Route;
 | 
			
		||||
use Joomla\Component\Banners\Administrator\Helper\BannersHelper;
 | 
			
		||||
 | 
			
		||||
// phpcs:disable PSR1.Files.SideEffects
 | 
			
		||||
\defined('_JEXEC') or die;
 | 
			
		||||
// phpcs:enable PSR1.Files.SideEffects
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Banners display controller.
 | 
			
		||||
 *
 | 
			
		||||
 * @since  1.6
 | 
			
		||||
 */
 | 
			
		||||
class DisplayController extends BaseController
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * The default view.
 | 
			
		||||
     *
 | 
			
		||||
     * @var    string
 | 
			
		||||
     * @since  1.6
 | 
			
		||||
     */
 | 
			
		||||
    protected $default_view = 'banners';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method to display a view.
 | 
			
		||||
     *
 | 
			
		||||
     * @param   boolean  $cachable   If true, the view output will be cached
 | 
			
		||||
     * @param   array    $urlparams  An array of safe URL parameters and their variable types
 | 
			
		||||
     *                   @see        \Joomla\CMS\Filter\InputFilter::clean() for valid values.
 | 
			
		||||
     *
 | 
			
		||||
     * @return  BaseController|boolean  This object to support chaining.
 | 
			
		||||
     *
 | 
			
		||||
     * @since   1.5
 | 
			
		||||
     */
 | 
			
		||||
    public function display($cachable = false, $urlparams = [])
 | 
			
		||||
    {
 | 
			
		||||
        BannersHelper::updateReset();
 | 
			
		||||
 | 
			
		||||
        $view   = $this->input->get('view', 'banners');
 | 
			
		||||
        $layout = $this->input->get('layout', 'default');
 | 
			
		||||
        $id     = $this->input->getInt('id');
 | 
			
		||||
 | 
			
		||||
        // Check for edit form.
 | 
			
		||||
        if ($view === 'banner' && $layout === 'edit' && !$this->checkEditId('com_banners.edit.banner', $id)) {
 | 
			
		||||
            // Somehow the person just went to the form - we don't allow that.
 | 
			
		||||
            if (!\count($this->app->getMessageQueue())) {
 | 
			
		||||
                $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error');
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $this->setRedirect(Route::_('index.php?option=com_banners&view=banners', false));
 | 
			
		||||
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($view === 'client' && $layout === 'edit' && !$this->checkEditId('com_banners.edit.client', $id)) {
 | 
			
		||||
            // Somehow the person just went to the form - we don't allow that.
 | 
			
		||||
            if (!\count($this->app->getMessageQueue())) {
 | 
			
		||||
                $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error');
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $this->setRedirect(Route::_('index.php?option=com_banners&view=clients', false));
 | 
			
		||||
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return parent::display();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,174 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @package     Joomla.Administrator
 | 
			
		||||
 * @subpackage  com_banners
 | 
			
		||||
 *
 | 
			
		||||
 * @copyright   (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
 | 
			
		||||
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Joomla\Component\Banners\Administrator\Controller;
 | 
			
		||||
 | 
			
		||||
use Joomla\CMS\Application\ApplicationHelper;
 | 
			
		||||
use Joomla\CMS\Language\Text;
 | 
			
		||||
use Joomla\CMS\MVC\Controller\BaseController;
 | 
			
		||||
 | 
			
		||||
// phpcs:disable PSR1.Files.SideEffects
 | 
			
		||||
\defined('_JEXEC') or die;
 | 
			
		||||
// phpcs:enable PSR1.Files.SideEffects
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Tracks list controller class.
 | 
			
		||||
 *
 | 
			
		||||
 * @since  1.6
 | 
			
		||||
 */
 | 
			
		||||
class TracksController extends BaseController
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * The prefix to use with controller messages.
 | 
			
		||||
     *
 | 
			
		||||
     * @var    string
 | 
			
		||||
     * @since  1.6
 | 
			
		||||
     */
 | 
			
		||||
    protected $context = 'com_banners.tracks';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method to get a model object, loading it if required.
 | 
			
		||||
     *
 | 
			
		||||
     * @param   string  $name    The model name. Optional.
 | 
			
		||||
     * @param   string  $prefix  The class prefix. Optional.
 | 
			
		||||
     * @param   array   $config  Configuration array for model. Optional.
 | 
			
		||||
     *
 | 
			
		||||
     * @return  \Joomla\CMS\MVC\Model\BaseDatabaseModel  The model.
 | 
			
		||||
     *
 | 
			
		||||
     * @since   1.6
 | 
			
		||||
     */
 | 
			
		||||
    public function getModel($name = 'Tracks', $prefix = 'Administrator', $config = ['ignore_request' => true])
 | 
			
		||||
    {
 | 
			
		||||
        return parent::getModel($name, $prefix, $config);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method to remove a record.
 | 
			
		||||
     *
 | 
			
		||||
     * @return  void
 | 
			
		||||
     *
 | 
			
		||||
     * @since   1.6
 | 
			
		||||
     */
 | 
			
		||||
    public function delete()
 | 
			
		||||
    {
 | 
			
		||||
        // Check for request forgeries.
 | 
			
		||||
        $this->checkToken();
 | 
			
		||||
 | 
			
		||||
        // Get the model.
 | 
			
		||||
        /** @var \Joomla\Component\Banners\Administrator\Model\TracksModel $model */
 | 
			
		||||
        $model = $this->getModel();
 | 
			
		||||
 | 
			
		||||
        // Load the filter state.
 | 
			
		||||
        $model->setState('filter.type', $this->app->getUserState($this->context . '.filter.type'));
 | 
			
		||||
        $model->setState('filter.begin', $this->app->getUserState($this->context . '.filter.begin'));
 | 
			
		||||
        $model->setState('filter.end', $this->app->getUserState($this->context . '.filter.end'));
 | 
			
		||||
        $model->setState('filter.category_id', $this->app->getUserState($this->context . '.filter.category_id'));
 | 
			
		||||
        $model->setState('filter.client_id', $this->app->getUserState($this->context . '.filter.client_id'));
 | 
			
		||||
        $model->setState('list.limit', 0);
 | 
			
		||||
        $model->setState('list.start', 0);
 | 
			
		||||
 | 
			
		||||
        $count = $model->getTotal();
 | 
			
		||||
 | 
			
		||||
        // Remove the items.
 | 
			
		||||
        if (!$model->delete()) {
 | 
			
		||||
            $this->app->enqueueMessage($model->getError(), 'warning');
 | 
			
		||||
        } elseif ($count > 0) {
 | 
			
		||||
            $this->setMessage(Text::plural('COM_BANNERS_TRACKS_N_ITEMS_DELETED', $count));
 | 
			
		||||
        } else {
 | 
			
		||||
            $this->setMessage(Text::_('COM_BANNERS_TRACKS_NO_ITEMS_DELETED'));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->setRedirect('index.php?option=com_banners&view=tracks');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Display method for the raw track data.
 | 
			
		||||
     *
 | 
			
		||||
     * @param   boolean  $cachable   If true, the view output will be cached
 | 
			
		||||
     * @param   array    $urlparams  An array of safe URL parameters and their variable types.
 | 
			
		||||
     *                   @see        \Joomla\CMS\Filter\InputFilter::clean() for valid values.
 | 
			
		||||
     *
 | 
			
		||||
     * @return  static  This object to support chaining.
 | 
			
		||||
     *
 | 
			
		||||
     * @since   1.5
 | 
			
		||||
     * @todo    This should be done as a view, not here!
 | 
			
		||||
     */
 | 
			
		||||
    public function display($cachable = false, $urlparams = [])
 | 
			
		||||
    {
 | 
			
		||||
        // Get the document object.
 | 
			
		||||
        $vName = 'tracks';
 | 
			
		||||
 | 
			
		||||
        // Get and render the view.
 | 
			
		||||
        if ($view = $this->getView($vName, 'raw')) {
 | 
			
		||||
            // Check for request forgeries.
 | 
			
		||||
            $this->checkToken('GET');
 | 
			
		||||
 | 
			
		||||
            // Get the model for the view.
 | 
			
		||||
            /** @var \Joomla\Component\Banners\Administrator\Model\TracksModel $model */
 | 
			
		||||
            $model = $this->getModel($vName);
 | 
			
		||||
 | 
			
		||||
            // Load the filter state.
 | 
			
		||||
            $app = $this->app;
 | 
			
		||||
 | 
			
		||||
            $model->setState('filter.type', $app->getUserState($this->context . '.filter.type'));
 | 
			
		||||
            $model->setState('filter.begin', $app->getUserState($this->context . '.filter.begin'));
 | 
			
		||||
            $model->setState('filter.end', $app->getUserState($this->context . '.filter.end'));
 | 
			
		||||
            $model->setState('filter.category_id', $app->getUserState($this->context . '.filter.category_id'));
 | 
			
		||||
            $model->setState('filter.client_id', $app->getUserState($this->context . '.filter.client_id'));
 | 
			
		||||
            $model->setState('list.limit', 0);
 | 
			
		||||
            $model->setState('list.start', 0);
 | 
			
		||||
 | 
			
		||||
            $form = $this->input->get('jform', [], 'array');
 | 
			
		||||
 | 
			
		||||
            $model->setState('basename', $form['basename']);
 | 
			
		||||
            $model->setState('compressed', $form['compressed']);
 | 
			
		||||
 | 
			
		||||
            // Create one year cookies.
 | 
			
		||||
            $cookieLifeTime = time() + 365 * 86400;
 | 
			
		||||
            $cookieDomain   = $app->get('cookie_domain', '');
 | 
			
		||||
            $cookiePath     = $app->get('cookie_path', '/');
 | 
			
		||||
            $isHttpsForced  = $app->isHttpsForced();
 | 
			
		||||
 | 
			
		||||
            $this->input->cookie->set(
 | 
			
		||||
                ApplicationHelper::getHash($this->context . '.basename'),
 | 
			
		||||
                $form['basename'],
 | 
			
		||||
                [
 | 
			
		||||
                    'expires'  => $cookieLifeTime,
 | 
			
		||||
                    'path'     => $cookiePath,
 | 
			
		||||
                    'domain'   => $cookieDomain,
 | 
			
		||||
                    'secure'   => $isHttpsForced,
 | 
			
		||||
                    'httponly' => true,
 | 
			
		||||
                ]
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            $this->input->cookie->set(
 | 
			
		||||
                ApplicationHelper::getHash($this->context . '.compressed'),
 | 
			
		||||
                $form['compressed'],
 | 
			
		||||
                [
 | 
			
		||||
                    'expires'  => $cookieLifeTime,
 | 
			
		||||
                    'path'     => $cookiePath,
 | 
			
		||||
                    'domain'   => $cookieDomain,
 | 
			
		||||
                    'secure'   => $isHttpsForced,
 | 
			
		||||
                    'httponly' => true,
 | 
			
		||||
                ]
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            // Push the model into the view (as default).
 | 
			
		||||
            $view->setModel($model, true);
 | 
			
		||||
 | 
			
		||||
            // Push document object into the view.
 | 
			
		||||
            $view->document = $this->app->getDocument();
 | 
			
		||||
 | 
			
		||||
            $view->display();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user