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; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,82 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_banners | ||||
|  * | ||||
|  * @copyright   (C) 2018 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\Extension; | ||||
|  | ||||
| use Joomla\CMS\Categories\CategoryServiceInterface; | ||||
| use Joomla\CMS\Categories\CategoryServiceTrait; | ||||
| use Joomla\CMS\Component\Router\RouterServiceInterface; | ||||
| use Joomla\CMS\Component\Router\RouterServiceTrait; | ||||
| use Joomla\CMS\Extension\BootableExtensionInterface; | ||||
| use Joomla\CMS\Extension\MVCComponent; | ||||
| use Joomla\CMS\HTML\HTMLRegistryAwareTrait; | ||||
| use Joomla\CMS\Tag\TagServiceInterface; | ||||
| use Joomla\CMS\Tag\TagServiceTrait; | ||||
| use Joomla\Component\Banners\Administrator\Service\Html\Banner; | ||||
| use Joomla\Database\DatabaseInterface; | ||||
| use Psr\Container\ContainerInterface; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Component class for com_banners | ||||
|  * | ||||
|  * @since  4.0.0 | ||||
|  */ | ||||
| class BannersComponent extends MVCComponent implements | ||||
|     BootableExtensionInterface, | ||||
|     CategoryServiceInterface, | ||||
|     RouterServiceInterface, | ||||
|     TagServiceInterface | ||||
| { | ||||
|     use HTMLRegistryAwareTrait; | ||||
|     use RouterServiceTrait; | ||||
|     use CategoryServiceTrait, TagServiceTrait { | ||||
|         CategoryServiceTrait::getTableNameForSection insteadof TagServiceTrait; | ||||
|         CategoryServiceTrait::getStateColumnForSection insteadof TagServiceTrait; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Booting the extension. This is the function to set up the environment of the extension like | ||||
|      * registering new class loaders, etc. | ||||
|      * | ||||
|      * If required, some initial set up can be done from services of the container, eg. | ||||
|      * registering HTML services. | ||||
|      * | ||||
|      * @param   ContainerInterface  $container  The container | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   4.0.0 | ||||
|      */ | ||||
|     public function boot(ContainerInterface $container) | ||||
|     { | ||||
|         $banner = new Banner(); | ||||
|         $banner->setDatabase($container->get(DatabaseInterface::class)); | ||||
|  | ||||
|         $this->getRegistry()->register('banner', $banner); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the table for the count items functions for the given section. | ||||
|      * | ||||
|      * @param   ?string  $section  The section | ||||
|      * | ||||
|      * @return  string|null | ||||
|      * | ||||
|      * @since   4.0.0 | ||||
|      */ | ||||
|     protected function getTableNameForSection(?string $section = null) | ||||
|     { | ||||
|         return 'banners'; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,46 @@ | ||||
| <?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\Field; | ||||
|  | ||||
| use Joomla\CMS\Form\Field\ListField; | ||||
| use Joomla\Component\Banners\Administrator\Helper\BannersHelper; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Bannerclient field. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class BannerclientField extends ListField | ||||
| { | ||||
|     /** | ||||
|      * The form field type. | ||||
|      * | ||||
|      * @var    string | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $type = 'BannerClient'; | ||||
|  | ||||
|     /** | ||||
|      * Method to get the field options. | ||||
|      * | ||||
|      * @return  array  The field option objects. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function getOptions() | ||||
|     { | ||||
|         return array_merge(parent::getOptions(), BannersHelper::getClientOptions()); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,51 @@ | ||||
| <?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\Field; | ||||
|  | ||||
| use Joomla\CMS\Form\FormField; | ||||
| use Joomla\CMS\Language\Text; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Clicks field. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class ClicksField extends FormField | ||||
| { | ||||
|     /** | ||||
|      * The form field type. | ||||
|      * | ||||
|      * @var    string | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $type = 'Clicks'; | ||||
|  | ||||
|     /** | ||||
|      * Method to get the field input markup. | ||||
|      * | ||||
|      * @return  string  The field input markup. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function getInput() | ||||
|     { | ||||
|         $onclick = ' onclick="document.getElementById(\'' . $this->id . '\').value=\'0\';"'; | ||||
|  | ||||
|         return '<div class="input-group"><input class="form-control" type="text" name="' . $this->name . '" id="' . $this->id . '" value="' | ||||
|             . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '" readonly="readonly">' | ||||
|             . '<button type="button" class="btn btn-secondary" ' . $onclick . '>' | ||||
|             . '<span class="icon-sync" aria-hidden="true"></span> ' . Text::_('JRESET') . '</button></div>'; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,51 @@ | ||||
| <?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\Field; | ||||
|  | ||||
| use Joomla\CMS\Form\FormField; | ||||
| use Joomla\CMS\Language\Text; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Impressions field. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class ImpmadeField extends FormField | ||||
| { | ||||
|     /** | ||||
|      * The form field type. | ||||
|      * | ||||
|      * @var    string | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $type = 'ImpMade'; | ||||
|  | ||||
|     /** | ||||
|      * Method to get the field input markup. | ||||
|      * | ||||
|      * @return  string  The field input markup. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function getInput() | ||||
|     { | ||||
|         $onclick = ' onclick="document.getElementById(\'' . $this->id . '\').value=\'0\';"'; | ||||
|  | ||||
|         return '<div class="input-group"><input class="form-control" type="text" name="' . $this->name . '" id="' . $this->id . '" value="' | ||||
|             . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '" readonly="readonly">' | ||||
|             . '<button type="button" class="btn btn-secondary" ' . $onclick . '>' | ||||
|             . '<span class="icon-sync" aria-hidden="true"></span> ' . Text::_('JRESET') . '</button></div>'; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,57 @@ | ||||
| <?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\Field; | ||||
|  | ||||
| use Joomla\CMS\Form\FormField; | ||||
| use Joomla\CMS\Language\Text; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Total Impressions field. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class ImptotalField extends FormField | ||||
| { | ||||
|     /** | ||||
|      * The form field type. | ||||
|      * | ||||
|      * @var    string | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $type = 'ImpTotal'; | ||||
|  | ||||
|     /** | ||||
|      * Method to get the field input markup. | ||||
|      * | ||||
|      * @return  string  The field input markup. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function getInput() | ||||
|     { | ||||
|         $class    = ' class="form-control validate-numeric text_area"'; | ||||
|         $onchange = ' onchange="document.getElementById(\'' . $this->id . '_unlimited\').checked=document.getElementById(\'' . $this->id | ||||
|             . '\').value==\'\';"'; | ||||
|         $onclick  = ' onclick="if (document.getElementById(\'' . $this->id . '_unlimited\').checked) document.getElementById(\'' . $this->id | ||||
|             . '\').value=\'\';"'; | ||||
|         $value    = empty($this->value) ? '' : $this->value; | ||||
|         $checked  = empty($this->value) ? ' checked="checked"' : ''; | ||||
|  | ||||
|         return '<input type="text" name="' . $this->name . '" id="' . $this->id . '" size="9" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') | ||||
|             . '" ' . $class . $onchange . '>' | ||||
|             . '<fieldset class="form-check impunlimited"><input class="form-check-input" id="' . $this->id . '_unlimited" type="checkbox"' . $checked . $onclick . '>' | ||||
|             . '<label for="' . $this->id . '_unlimited" id="jform-imp" class="form-check-label">' . Text::_('COM_BANNERS_UNLIMITED') . '</label></fieldset>'; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,175 @@ | ||||
| <?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\Helper; | ||||
|  | ||||
| use Joomla\CMS\Component\ComponentHelper; | ||||
| use Joomla\CMS\Factory; | ||||
| use Joomla\CMS\Helper\ContentHelper; | ||||
| use Joomla\CMS\HTML\HTMLHelper; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\Table\Table; | ||||
| use Joomla\Database\ParameterType; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Banners component helper. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class BannersHelper extends ContentHelper | ||||
| { | ||||
|     /** | ||||
|      * Update / reset the banners | ||||
|      * | ||||
|      * @return  boolean | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public static function updateReset() | ||||
|     { | ||||
|         $db      = Factory::getDbo(); | ||||
|         $nowDate = Factory::getDate()->toSql(); | ||||
|         $app     = Factory::getApplication(); | ||||
|         $user    = $app->getIdentity(); | ||||
|  | ||||
|         $query = $db->getQuery(true) | ||||
|             ->select('*') | ||||
|             ->from($db->quoteName('#__banners')) | ||||
|             ->where( | ||||
|                 [ | ||||
|                     $db->quoteName('reset') . ' <= :date', | ||||
|                     $db->quoteName('reset') . ' IS NOT NULL', | ||||
|                 ] | ||||
|             ) | ||||
|             ->bind(':date', $nowDate) | ||||
|             ->extendWhere( | ||||
|                 'AND', | ||||
|                 [ | ||||
|                     $db->quoteName('checked_out') . ' IS NULL', | ||||
|                     $db->quoteName('checked_out') . ' = :userId', | ||||
|                 ], | ||||
|                 'OR' | ||||
|             ) | ||||
|             ->bind(':userId', $user->id, ParameterType::INTEGER); | ||||
|  | ||||
|         $db->setQuery($query); | ||||
|  | ||||
|         try { | ||||
|             $rows = $db->loadObjectList(); | ||||
|         } catch (\RuntimeException $e) { | ||||
|             $app->enqueueMessage($e->getMessage(), 'error'); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         foreach ($rows as $row) { | ||||
|             $purchaseType = $row->purchase_type; | ||||
|  | ||||
|             if ($purchaseType < 0 && $row->cid) { | ||||
|                 /** @var \Joomla\Component\Banners\Administrator\Table\ClientTable $client */ | ||||
|                 $client = Table::getInstance('ClientTable', '\\Joomla\\Component\\Banners\\Administrator\\Table\\'); | ||||
|                 $client->load($row->cid); | ||||
|                 $purchaseType = $client->purchase_type; | ||||
|             } | ||||
|  | ||||
|             if ($purchaseType < 0) { | ||||
|                 $params       = ComponentHelper::getParams('com_banners'); | ||||
|                 $purchaseType = $params->get('purchase_type'); | ||||
|             } | ||||
|  | ||||
|             switch ($purchaseType) { | ||||
|                 case 1: | ||||
|                     $reset = null; | ||||
|                     break; | ||||
|                 case 2: | ||||
|                     $date  = Factory::getDate('+1 year ' . date('Y-m-d')); | ||||
|                     $reset = $date->toSql(); | ||||
|                     break; | ||||
|                 case 3: | ||||
|                     $date  = Factory::getDate('+1 month ' . date('Y-m-d')); | ||||
|                     $reset = $date->toSql(); | ||||
|                     break; | ||||
|                 case 4: | ||||
|                     $date  = Factory::getDate('+7 day ' . date('Y-m-d')); | ||||
|                     $reset = $date->toSql(); | ||||
|                     break; | ||||
|                 case 5: | ||||
|                     $date  = Factory::getDate('+1 day ' . date('Y-m-d')); | ||||
|                     $reset = $date->toSql(); | ||||
|                     break; | ||||
|             } | ||||
|  | ||||
|             // Update the row ordering field. | ||||
|             $query = $db->getQuery(true) | ||||
|                 ->update($db->quoteName('#__banners')) | ||||
|                 ->set( | ||||
|                     [ | ||||
|                         $db->quoteName('reset') . ' = :reset', | ||||
|                         $db->quoteName('impmade') . ' = 0', | ||||
|                         $db->quoteName('clicks') . ' = 0', | ||||
|                     ] | ||||
|                 ) | ||||
|                 ->where($db->quoteName('id') . ' = :id') | ||||
|                 ->bind(':reset', $reset, $reset === null ? ParameterType::NULL : ParameterType::STRING) | ||||
|                 ->bind(':id', $row->id, ParameterType::INTEGER); | ||||
|  | ||||
|             $db->setQuery($query); | ||||
|  | ||||
|             try { | ||||
|                 $db->execute(); | ||||
|             } catch (\RuntimeException $e) { | ||||
|                 $app->enqueueMessage($e->getMessage(), 'error'); | ||||
|  | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get client list in text/value format for a select field | ||||
|      * | ||||
|      * @return  array | ||||
|      */ | ||||
|     public static function getClientOptions() | ||||
|     { | ||||
|         $options = []; | ||||
|  | ||||
|         $db    = Factory::getDbo(); | ||||
|         $query = $db->getQuery(true) | ||||
|             ->select( | ||||
|                 [ | ||||
|                     $db->quoteName('id', 'value'), | ||||
|                     $db->quoteName('name', 'text'), | ||||
|                 ] | ||||
|             ) | ||||
|             ->from($db->quoteName('#__banner_clients', 'a')) | ||||
|             ->where($db->quoteName('a.state') . ' = 1') | ||||
|             ->order($db->quoteName('a.name')); | ||||
|  | ||||
|         // Get the options. | ||||
|         $db->setQuery($query); | ||||
|  | ||||
|         try { | ||||
|             $options = $db->loadObjectList(); | ||||
|         } catch (\RuntimeException $e) { | ||||
|             Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); | ||||
|         } | ||||
|  | ||||
|         array_unshift($options, HTMLHelper::_('select.option', '0', Text::_('COM_BANNERS_NO_CLIENT'))); | ||||
|  | ||||
|         return $options; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										481
									
								
								administrator/components/com_banners/src/Model/BannerModel.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										481
									
								
								administrator/components/com_banners/src/Model/BannerModel.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,481 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_banners | ||||
|  * | ||||
|  * @copyright   (C) 2008 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\Model; | ||||
|  | ||||
| use Joomla\CMS\Factory; | ||||
| use Joomla\CMS\Form\Form; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\MVC\Model\AdminModel; | ||||
| use Joomla\CMS\Table\Table; | ||||
| use Joomla\CMS\Table\TableInterface; | ||||
| use Joomla\CMS\Versioning\VersionableModelTrait; | ||||
| use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper; | ||||
| use Joomla\Database\ParameterType; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Banner model. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class BannerModel extends AdminModel | ||||
| { | ||||
|     use VersionableModelTrait; | ||||
|  | ||||
|     /** | ||||
|      * The prefix to use with controller messages. | ||||
|      * | ||||
|      * @var    string | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $text_prefix = 'COM_BANNERS_BANNER'; | ||||
|  | ||||
|     /** | ||||
|      * The type alias for this content type. | ||||
|      * | ||||
|      * @var    string | ||||
|      * @since  3.2 | ||||
|      */ | ||||
|     public $typeAlias = 'com_banners.banner'; | ||||
|  | ||||
|     /** | ||||
|      * Batch copy/move command. If set to false, the batch copy/move command is not supported | ||||
|      * | ||||
|      * @var  string | ||||
|      */ | ||||
|     protected $batch_copymove = 'category_id'; | ||||
|  | ||||
|     /** | ||||
|      * Allowed batch commands | ||||
|      * | ||||
|      * @var  array | ||||
|      */ | ||||
|     protected $batch_commands = [ | ||||
|         'client_id'   => 'batchClient', | ||||
|         'language_id' => 'batchLanguage', | ||||
|     ]; | ||||
|  | ||||
|     /** | ||||
|      * Data cleanup after batch copying data | ||||
|      * | ||||
|      * @param   TableInterface  $table  The table object containing the newly created item | ||||
|      * @param   integer         $newId  The id of the new item | ||||
|      * @param   integer         $oldId  The original item id | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since  4.3.2 | ||||
|      */ | ||||
|     protected function cleanupPostBatchCopy(TableInterface $table, $newId, $oldId) | ||||
|     { | ||||
|         // Initialise clicks and impmade | ||||
|         $db    = $this->getDatabase(); | ||||
|  | ||||
|         $query = $db->getQuery(true) | ||||
|                 ->update($db->quoteName('#__banners')) | ||||
|                 ->set($db->quoteName('clicks') . ' = 0') | ||||
|                 ->set($db->quoteName('impmade') . ' = 0') | ||||
|                 ->where($db->quoteName('id') . ' = :newId') | ||||
|                 ->bind(':newId', $newId, ParameterType::INTEGER); | ||||
|  | ||||
|         $db->setQuery($query); | ||||
|         $db->execute(); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * Batch client changes for a group of banners. | ||||
|      * | ||||
|      * @param   string  $value     The new value matching a client. | ||||
|      * @param   array   $pks       An array of row IDs. | ||||
|      * @param   array   $contexts  An array of item contexts. | ||||
|      * | ||||
|      * @return  boolean  True if successful, false otherwise and internal error is set. | ||||
|      * | ||||
|      * @since   2.5 | ||||
|      */ | ||||
|     protected function batchClient($value, $pks, $contexts) | ||||
|     { | ||||
|         // Set the variables | ||||
|         $user = $this->getCurrentUser(); | ||||
|  | ||||
|         /** @var \Joomla\Component\Banners\Administrator\Table\BannerTable $table */ | ||||
|         $table = $this->getTable(); | ||||
|  | ||||
|         foreach ($pks as $pk) { | ||||
|             if (!$user->authorise('core.edit', $contexts[$pk])) { | ||||
|                 $this->setError(Text::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT')); | ||||
|  | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             $table->reset(); | ||||
|             $table->load($pk); | ||||
|             $table->cid = (int) $value; | ||||
|  | ||||
|             if (!$table->store()) { | ||||
|                 $this->setError($table->getError()); | ||||
|  | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // Clean the cache | ||||
|         $this->cleanCache(); | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to test whether a record can be deleted. | ||||
|      * | ||||
|      * @param   object  $record  A record object. | ||||
|      * | ||||
|      * @return  boolean  True if allowed to delete the record. Defaults to the permission set in the component. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function canDelete($record) | ||||
|     { | ||||
|         if (empty($record->id) || $record->state != -2) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         if (!empty($record->catid)) { | ||||
|             return $this->getCurrentUser()->authorise('core.delete', 'com_banners.category.' . (int) $record->catid); | ||||
|         } | ||||
|  | ||||
|         return parent::canDelete($record); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * A method to preprocess generating a new title in order to allow tables with alternative names | ||||
|      * for alias and title to use the batch move and copy methods | ||||
|      * | ||||
|      * @param   integer  $categoryId  The target category id | ||||
|      * @param   Table    $table       The \Joomla\CMS\Table\Table within which move or copy is taking place | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   3.8.12 | ||||
|      */ | ||||
|     public function generateTitle($categoryId, $table) | ||||
|     { | ||||
|         // Alter the title & alias | ||||
|         $data         = $this->generateNewTitle($categoryId, $table->alias, $table->name); | ||||
|         $table->name  = $data['0']; | ||||
|         $table->alias = $data['1']; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to test whether a record can have its state changed. | ||||
|      * | ||||
|      * @param   object  $record  A record object. | ||||
|      * | ||||
|      * @return  boolean  True if allowed to change the state of the record. Defaults to the permission set in the component. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function canEditState($record) | ||||
|     { | ||||
|         // Check against the category. | ||||
|         if (!empty($record->catid)) { | ||||
|             return $this->getCurrentUser()->authorise('core.edit.state', 'com_banners.category.' . (int) $record->catid); | ||||
|         } | ||||
|  | ||||
|         // Default to component settings if category not known. | ||||
|         return parent::canEditState($record); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to get the record form. | ||||
|      * | ||||
|      * @param   array    $data      Data for the form. [optional] | ||||
|      * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not. [optional] | ||||
|      * | ||||
|      * @return  Form|boolean  A Form object on success, false on failure | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function getForm($data = [], $loadData = true) | ||||
|     { | ||||
|         // Get the form. | ||||
|         $form = $this->loadForm('com_banners.banner', 'banner', ['control' => 'jform', 'load_data' => $loadData]); | ||||
|  | ||||
|         if (empty($form)) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Modify the form based on access controls. | ||||
|         if (!$this->canEditState((object) $data)) { | ||||
|             // Disable fields for display. | ||||
|             $form->setFieldAttribute('ordering', 'disabled', 'true'); | ||||
|             $form->setFieldAttribute('publish_up', 'disabled', 'true'); | ||||
|             $form->setFieldAttribute('publish_down', 'disabled', 'true'); | ||||
|             $form->setFieldAttribute('state', 'disabled', 'true'); | ||||
|             $form->setFieldAttribute('sticky', 'disabled', 'true'); | ||||
|  | ||||
|             // Disable fields while saving. | ||||
|             // The controller has already verified this is a record you can edit. | ||||
|             $form->setFieldAttribute('ordering', 'filter', 'unset'); | ||||
|             $form->setFieldAttribute('publish_up', 'filter', 'unset'); | ||||
|             $form->setFieldAttribute('publish_down', 'filter', 'unset'); | ||||
|             $form->setFieldAttribute('state', 'filter', 'unset'); | ||||
|             $form->setFieldAttribute('sticky', 'filter', 'unset'); | ||||
|         } | ||||
|  | ||||
|         // Don't allow to change the created_by user if not allowed to access com_users. | ||||
|         if (!$this->getCurrentUser()->authorise('core.manage', 'com_users')) { | ||||
|             $form->setFieldAttribute('created_by', 'filter', 'unset'); | ||||
|         } | ||||
|  | ||||
|         return $form; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to get the data that should be injected in the form. | ||||
|      * | ||||
|      * @return  mixed  The data for the form. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function loadFormData() | ||||
|     { | ||||
|         // Check the session for previously entered form data. | ||||
|         $app  = Factory::getApplication(); | ||||
|         $data = $app->getUserState('com_banners.edit.banner.data', []); | ||||
|  | ||||
|         if (empty($data)) { | ||||
|             $data = $this->getItem(); | ||||
|  | ||||
|             // Prime some default values. | ||||
|             if ($this->getState('banner.id') == 0) { | ||||
|                 $filters     = (array) $app->getUserState('com_banners.banners.filter'); | ||||
|                 $filterCatId = $filters['category_id'] ?? null; | ||||
|  | ||||
|                 $data->set('catid', $app->getInput()->getInt('catid', $filterCatId)); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         $this->preprocessData('com_banners.banner', $data); | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to stick records. | ||||
|      * | ||||
|      * @param   array    $pks    The ids of the items to publish. | ||||
|      * @param   integer  $value  The value of the published state | ||||
|      * | ||||
|      * @return  boolean  True on success. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function stick(&$pks, $value = 1) | ||||
|     { | ||||
|         /** @var \Joomla\Component\Banners\Administrator\Table\BannerTable $table */ | ||||
|         $table = $this->getTable(); | ||||
|         $pks   = (array) $pks; | ||||
|  | ||||
|         // Access checks. | ||||
|         foreach ($pks as $i => $pk) { | ||||
|             if ($table->load($pk)) { | ||||
|                 if (!$this->canEditState($table)) { | ||||
|                     // Prune items that you can't change. | ||||
|                     unset($pks[$i]); | ||||
|                     Factory::getApplication()->enqueueMessage(Text::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), 'error'); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // Attempt to change the state of the records. | ||||
|         if (!$table->stick($pks, $value, $this->getCurrentUser()->id)) { | ||||
|             $this->setError($table->getError()); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * A protected method to get a set of ordering conditions. | ||||
|      * | ||||
|      * @param   Table  $table  A record object. | ||||
|      * | ||||
|      * @return  array  An array of conditions to add to ordering queries. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function getReorderConditions($table) | ||||
|     { | ||||
|         $db = $this->getDatabase(); | ||||
|  | ||||
|         return [ | ||||
|             $db->quoteName('catid') . ' = ' . (int) $table->catid, | ||||
|             $db->quoteName('state') . ' >= 0', | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Prepare and sanitise the table prior to saving. | ||||
|      * | ||||
|      * @param   Table  $table  A Table object. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function prepareTable($table) | ||||
|     { | ||||
|         $date = Factory::getDate(); | ||||
|         $user = $this->getCurrentUser(); | ||||
|  | ||||
|         if (empty($table->id)) { | ||||
|             // Set the values | ||||
|             $table->created    = $date->toSql(); | ||||
|             $table->created_by = $user->id; | ||||
|  | ||||
|             // Set ordering to the last item if not set | ||||
|             if (empty($table->ordering)) { | ||||
|                 $db    = $this->getDatabase(); | ||||
|                 $query = $db->getQuery(true) | ||||
|                     ->select('MAX(' . $db->quoteName('ordering') . ')') | ||||
|                     ->from($db->quoteName('#__banners')); | ||||
|  | ||||
|                 $db->setQuery($query); | ||||
|                 $max = $db->loadResult(); | ||||
|  | ||||
|                 $table->ordering = $max + 1; | ||||
|             } | ||||
|         } else { | ||||
|             // Set the values | ||||
|             $table->modified    = $date->toSql(); | ||||
|             $table->modified_by = $user->id; | ||||
|         } | ||||
|  | ||||
|         // Increment the content version number. | ||||
|         $table->version++; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Allows preprocessing of the Form object. | ||||
|      * | ||||
|      * @param   Form    $form   The form object | ||||
|      * @param   array   $data   The data to be merged into the form object | ||||
|      * @param   string  $group  The plugin group to be executed | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since    3.6.1 | ||||
|      */ | ||||
|     protected function preprocessForm(Form $form, $data, $group = 'content') | ||||
|     { | ||||
|         if ($this->canCreateCategory()) { | ||||
|             $form->setFieldAttribute('catid', 'allowAdd', 'true'); | ||||
|  | ||||
|             // Add a prefix for categories created on the fly. | ||||
|             $form->setFieldAttribute('catid', 'customPrefix', '#new#'); | ||||
|         } | ||||
|  | ||||
|         parent::preprocessForm($form, $data, $group); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to save the form data. | ||||
|      * | ||||
|      * @param   array  $data  The form data. | ||||
|      * | ||||
|      * @return  boolean  True on success. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function save($data) | ||||
|     { | ||||
|         $input = Factory::getApplication()->getInput(); | ||||
|  | ||||
|         // Create new category, if needed. | ||||
|         $createCategory = true; | ||||
|  | ||||
|         // If category ID is provided, check if it's valid. | ||||
|         if (is_numeric($data['catid']) && $data['catid']) { | ||||
|             $createCategory = !CategoriesHelper::validateCategoryId($data['catid'], 'com_banners'); | ||||
|         } | ||||
|  | ||||
|         // Save New Category | ||||
|         if ($createCategory && $this->canCreateCategory()) { | ||||
|             $category = [ | ||||
|                 // Remove #new# prefix, if exists. | ||||
|                 'title'     => strpos($data['catid'], '#new#') === 0 ? substr($data['catid'], 5) : $data['catid'], | ||||
|                 'parent_id' => 1, | ||||
|                 'extension' => 'com_banners', | ||||
|                 'language'  => $data['language'], | ||||
|                 'published' => 1, | ||||
|             ]; | ||||
|  | ||||
|             /** @var \Joomla\Component\Categories\Administrator\Model\CategoryModel $categoryModel */ | ||||
|             $categoryModel = Factory::getApplication()->bootComponent('com_categories') | ||||
|                 ->getMVCFactory()->createModel('Category', 'Administrator', ['ignore_request' => true]); | ||||
|  | ||||
|             // Create new category. | ||||
|             if (!$categoryModel->save($category)) { | ||||
|                 $this->setError($categoryModel->getError()); | ||||
|  | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             // Get the new category ID. | ||||
|             $data['catid'] = $categoryModel->getState('category.id'); | ||||
|         } | ||||
|  | ||||
|         // Alter the name for save as copy | ||||
|         if ($input->get('task') == 'save2copy') { | ||||
|             /** @var \Joomla\Component\Banners\Administrator\Table\BannerTable $origTable */ | ||||
|             $origTable = clone $this->getTable(); | ||||
|             $origTable->load($input->getInt('id')); | ||||
|  | ||||
|             if ($data['name'] == $origTable->name) { | ||||
|                 list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']); | ||||
|                 $data['name']       = $name; | ||||
|                 $data['alias']      = $alias; | ||||
|             } else { | ||||
|                 if ($data['alias'] == $origTable->alias) { | ||||
|                     $data['alias'] = ''; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             $data['state'] = 0; | ||||
|         } | ||||
|  | ||||
|         if ($input->get('task') == 'save2copy' || $input->get('task') == 'copy') { | ||||
|             $data['clicks']  = 0; | ||||
|             $data['impmade'] = 0; | ||||
|         } | ||||
|  | ||||
|         return parent::save($data); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Is the user allowed to create an on the fly category? | ||||
|      * | ||||
|      * @return  boolean | ||||
|      * | ||||
|      * @since   3.6.1 | ||||
|      */ | ||||
|     private function canCreateCategory() | ||||
|     { | ||||
|         return $this->getCurrentUser()->authorise('core.create', 'com_banners'); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										286
									
								
								administrator/components/com_banners/src/Model/BannersModel.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										286
									
								
								administrator/components/com_banners/src/Model/BannersModel.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,286 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_banners | ||||
|  * | ||||
|  * @copyright   (C) 2008 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\Model; | ||||
|  | ||||
| use Joomla\CMS\Component\ComponentHelper; | ||||
| use Joomla\CMS\MVC\Model\ListModel; | ||||
| use Joomla\CMS\Table\Table; | ||||
| use Joomla\Database\ParameterType; | ||||
| use Joomla\Database\QueryInterface; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Methods supporting a list of banner records. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class BannersModel extends ListModel | ||||
| { | ||||
|     /** | ||||
|      * Constructor. | ||||
|      * | ||||
|      * @param   array  $config  An optional associative array of configuration settings. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function __construct($config = []) | ||||
|     { | ||||
|         if (empty($config['filter_fields'])) { | ||||
|             $config['filter_fields'] = [ | ||||
|                 'id', 'a.id', | ||||
|                 'cid', 'a.cid', 'client_name', | ||||
|                 'name', 'a.name', | ||||
|                 'alias', 'a.alias', | ||||
|                 'state', 'a.state', | ||||
|                 'ordering', 'a.ordering', | ||||
|                 'language', 'a.language', | ||||
|                 'catid', 'a.catid', 'category_title', | ||||
|                 'checked_out', 'a.checked_out', | ||||
|                 'checked_out_time', 'a.checked_out_time', | ||||
|                 'created', 'a.created', | ||||
|                 'impmade', 'a.impmade', | ||||
|                 'imptotal', 'a.imptotal', | ||||
|                 'clicks', 'a.clicks', | ||||
|                 'publish_up', 'a.publish_up', | ||||
|                 'publish_down', 'a.publish_down', | ||||
|                 'sticky', 'a.sticky', | ||||
|                 'client_id', | ||||
|                 'category_id', | ||||
|                 'published', | ||||
|                 'level', 'c.level', | ||||
|             ]; | ||||
|         } | ||||
|  | ||||
|         parent::__construct($config); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to get the maximum ordering value for each category. | ||||
|      * | ||||
|      * @return  array | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function &getCategoryOrders() | ||||
|     { | ||||
|         if (!isset($this->cache['categoryorders'])) { | ||||
|             $db    = $this->getDatabase(); | ||||
|             $query = $db->getQuery(true) | ||||
|                 ->select( | ||||
|                     [ | ||||
|                         'MAX(' . $db->quoteName('ordering') . ') AS ' . $db->quoteName('max'), | ||||
|                         $db->quoteName('catid'), | ||||
|                     ] | ||||
|                 ) | ||||
|                 ->from($db->quoteName('#__banners')) | ||||
|                 ->group($db->quoteName('catid')); | ||||
|             $db->setQuery($query); | ||||
|             $this->cache['categoryorders'] = $db->loadAssocList('catid', 0); | ||||
|         } | ||||
|  | ||||
|         return $this->cache['categoryorders']; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Build an SQL query to load the list data. | ||||
|      * | ||||
|      * @return  QueryInterface | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function getListQuery() | ||||
|     { | ||||
|         $db    = $this->getDatabase(); | ||||
|         $query = $db->getQuery(true); | ||||
|  | ||||
|         // Select the required fields from the table. | ||||
|         $query->select( | ||||
|             $this->getState( | ||||
|                 'list.select', | ||||
|                 [ | ||||
|                     $db->quoteName('a.id'), | ||||
|                     $db->quoteName('a.name'), | ||||
|                     $db->quoteName('a.alias'), | ||||
|                     $db->quoteName('a.checked_out'), | ||||
|                     $db->quoteName('a.checked_out_time'), | ||||
|                     $db->quoteName('a.catid'), | ||||
|                     $db->quoteName('a.clicks'), | ||||
|                     $db->quoteName('a.metakey'), | ||||
|                     $db->quoteName('a.sticky'), | ||||
|                     $db->quoteName('a.impmade'), | ||||
|                     $db->quoteName('a.imptotal'), | ||||
|                     $db->quoteName('a.state'), | ||||
|                     $db->quoteName('a.ordering'), | ||||
|                     $db->quoteName('a.purchase_type'), | ||||
|                     $db->quoteName('a.language'), | ||||
|                     $db->quoteName('a.publish_up'), | ||||
|                     $db->quoteName('a.publish_down'), | ||||
|                 ] | ||||
|             ) | ||||
|         ) | ||||
|             ->select( | ||||
|                 [ | ||||
|                     $db->quoteName('l.title', 'language_title'), | ||||
|                     $db->quoteName('l.image', 'language_image'), | ||||
|                     $db->quoteName('uc.name', 'editor'), | ||||
|                     $db->quoteName('c.title', 'category_title'), | ||||
|                     $db->quoteName('cl.name', 'client_name'), | ||||
|                     $db->quoteName('cl.purchase_type', 'client_purchase_type'), | ||||
|                 ] | ||||
|             ) | ||||
|             ->from($db->quoteName('#__banners', 'a')) | ||||
|             ->join('LEFT', $db->quoteName('#__languages', 'l'), $db->quoteName('l.lang_code') . ' = ' . $db->quoteName('a.language')) | ||||
|             ->join('LEFT', $db->quoteName('#__users', 'uc'), $db->quoteName('uc.id') . ' = ' . $db->quoteName('a.checked_out')) | ||||
|             ->join('LEFT', $db->quoteName('#__categories', 'c'), $db->quoteName('c.id') . ' = ' . $db->quoteName('a.catid')) | ||||
|             ->join('LEFT', $db->quoteName('#__banner_clients', 'cl'), $db->quoteName('cl.id') . ' = ' . $db->quoteName('a.cid')); | ||||
|  | ||||
|         // Filter by published state | ||||
|         $published = (string) $this->getState('filter.published'); | ||||
|  | ||||
|         if (is_numeric($published)) { | ||||
|             $published = (int) $published; | ||||
|             $query->where($db->quoteName('a.state') . ' = :published') | ||||
|                 ->bind(':published', $published, ParameterType::INTEGER); | ||||
|         } elseif ($published === '') { | ||||
|             $query->where($db->quoteName('a.state') . ' IN (0, 1)'); | ||||
|         } | ||||
|  | ||||
|         // Filter by category. | ||||
|         $categoryId = $this->getState('filter.category_id'); | ||||
|  | ||||
|         if (is_numeric($categoryId)) { | ||||
|             $categoryId = (int) $categoryId; | ||||
|             $query->where($db->quoteName('a.catid') . ' = :categoryId') | ||||
|                 ->bind(':categoryId', $categoryId, ParameterType::INTEGER); | ||||
|         } | ||||
|  | ||||
|         // Filter by client. | ||||
|         $clientId = $this->getState('filter.client_id'); | ||||
|  | ||||
|         if (is_numeric($clientId)) { | ||||
|             $clientId = (int) $clientId; | ||||
|             $query->where($db->quoteName('a.cid') . ' = :clientId') | ||||
|                 ->bind(':clientId', $clientId, ParameterType::INTEGER); | ||||
|         } | ||||
|  | ||||
|         // Filter by search in title | ||||
|         if ($search = $this->getState('filter.search')) { | ||||
|             if (stripos($search, 'id:') === 0) { | ||||
|                 $search = (int) substr($search, 3); | ||||
|                 $query->where($db->quoteName('a.id') . ' = :search') | ||||
|                     ->bind(':search', $search, ParameterType::INTEGER); | ||||
|             } else { | ||||
|                 $search = '%' . str_replace(' ', '%', trim($search)) . '%'; | ||||
|                 $query->where('(' . $db->quoteName('a.name') . ' LIKE :search1 OR ' . $db->quoteName('a.alias') . ' LIKE :search2)') | ||||
|                     ->bind([':search1', ':search2'], $search); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // Filter on the language. | ||||
|         if ($language = $this->getState('filter.language')) { | ||||
|             $query->where($db->quoteName('a.language') . ' = :language') | ||||
|                 ->bind(':language', $language); | ||||
|         } | ||||
|  | ||||
|         // Filter on the level. | ||||
|         if ($level = (int) $this->getState('filter.level')) { | ||||
|             $query->where($db->quoteName('c.level') . ' <= :level') | ||||
|                 ->bind(':level', $level, ParameterType::INTEGER); | ||||
|         } | ||||
|  | ||||
|         // Add the list ordering clause. | ||||
|         $orderCol  = $this->state->get('list.ordering', 'a.name'); | ||||
|         $orderDirn = $this->state->get('list.direction', 'ASC'); | ||||
|  | ||||
|         if ($orderCol === 'a.ordering' || $orderCol === 'category_title') { | ||||
|             $ordering = [ | ||||
|                 $db->quoteName('c.title') . ' ' . $db->escape($orderDirn), | ||||
|                 $db->quoteName('a.ordering') . ' ' . $db->escape($orderDirn), | ||||
|             ]; | ||||
|         } else { | ||||
|             if ($orderCol === 'client_name') { | ||||
|                 $orderCol = 'cl.name'; | ||||
|             } | ||||
|  | ||||
|             $ordering = $db->escape($orderCol) . ' ' . $db->escape($orderDirn); | ||||
|         } | ||||
|  | ||||
|         $query->order($ordering); | ||||
|  | ||||
|         return $query; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to get a store id based on model configuration state. | ||||
|      * | ||||
|      * This is necessary because the model is used by the component and | ||||
|      * different modules that might need different sets of data or different | ||||
|      * ordering requirements. | ||||
|      * | ||||
|      * @param   string  $id  A prefix for the store id. | ||||
|      * | ||||
|      * @return  string  A store id. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function getStoreId($id = '') | ||||
|     { | ||||
|         // Compile the store id. | ||||
|         $id .= ':' . $this->getState('filter.search'); | ||||
|         $id .= ':' . $this->getState('filter.published'); | ||||
|         $id .= ':' . $this->getState('filter.category_id'); | ||||
|         $id .= ':' . $this->getState('filter.client_id'); | ||||
|         $id .= ':' . $this->getState('filter.language'); | ||||
|         $id .= ':' . $this->getState('filter.level'); | ||||
|  | ||||
|         return parent::getStoreId($id); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns a reference to the a Table object, always creating it. | ||||
|      * | ||||
|      * @param   string  $type    The table type to instantiate | ||||
|      * @param   string  $prefix  A prefix for the table class name. Optional. | ||||
|      * @param   array   $config  Configuration array for model. Optional. | ||||
|      * | ||||
|      * @return  Table  A Table object | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function getTable($type = 'Banner', $prefix = 'Administrator', $config = []) | ||||
|     { | ||||
|         return parent::getTable($type, $prefix, $config); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to auto-populate the model state. | ||||
|      * | ||||
|      * Note. Calling getState in this method will result in recursion. | ||||
|      * | ||||
|      * @param   string  $ordering   An optional ordering field. | ||||
|      * @param   string  $direction  An optional direction (asc|desc). | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function populateState($ordering = 'a.name', $direction = 'asc') | ||||
|     { | ||||
|         // Load the parameters. | ||||
|         $this->setState('params', ComponentHelper::getParams('com_banners')); | ||||
|  | ||||
|         // List state information. | ||||
|         parent::populateState($ordering, $direction); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										138
									
								
								administrator/components/com_banners/src/Model/ClientModel.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										138
									
								
								administrator/components/com_banners/src/Model/ClientModel.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,138 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_banners | ||||
|  * | ||||
|  * @copyright   (C) 2008 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\Model; | ||||
|  | ||||
| use Joomla\CMS\Factory; | ||||
| use Joomla\CMS\MVC\Model\AdminModel; | ||||
| use Joomla\CMS\Table\Table; | ||||
| use Joomla\CMS\Versioning\VersionableModelTrait; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Client model. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class ClientModel extends AdminModel | ||||
| { | ||||
|     use VersionableModelTrait; | ||||
|  | ||||
|     /** | ||||
|      * The type alias for this content type. | ||||
|      * | ||||
|      * @var    string | ||||
|      * @since  3.2 | ||||
|      */ | ||||
|     public $typeAlias = 'com_banners.client'; | ||||
|  | ||||
|     /** | ||||
|      * Method to test whether a record can be deleted. | ||||
|      * | ||||
|      * @param   object  $record  A record object. | ||||
|      * | ||||
|      * @return  boolean  True if allowed to delete the record. Defaults to the permission set in the component. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function canDelete($record) | ||||
|     { | ||||
|         if (empty($record->id) || $record->state != -2) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         if (!empty($record->catid)) { | ||||
|             return $this->getCurrentUser()->authorise('core.delete', 'com_banners.category.' . (int) $record->catid); | ||||
|         } | ||||
|  | ||||
|         return parent::canDelete($record); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to test whether a record can have its state changed. | ||||
|      * | ||||
|      * @param   object  $record  A record object. | ||||
|      * | ||||
|      * @return  boolean  True if allowed to change the state of the record. | ||||
|      *                   Defaults to the permission set in the component. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function canEditState($record) | ||||
|     { | ||||
|         $user = $this->getCurrentUser(); | ||||
|  | ||||
|         if (!empty($record->catid)) { | ||||
|             return $user->authorise('core.edit.state', 'com_banners.category.' . (int) $record->catid); | ||||
|         } | ||||
|  | ||||
|         return $user->authorise('core.edit.state', 'com_banners'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to get the record form. | ||||
|      * | ||||
|      * @param   array    $data      Data for the form. | ||||
|      * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not. | ||||
|      * | ||||
|      * @return  \Joomla\CMS\Form\Form|boolean  A Form object on success, false on failure | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function getForm($data = [], $loadData = true) | ||||
|     { | ||||
|         // Get the form. | ||||
|         $form = $this->loadForm('com_banners.client', 'client', ['control' => 'jform', 'load_data' => $loadData]); | ||||
|  | ||||
|         if (empty($form)) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         return $form; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to get the data that should be injected in the form. | ||||
|      * | ||||
|      * @return  mixed  The data for the form. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function loadFormData() | ||||
|     { | ||||
|         // Check the session for previously entered form data. | ||||
|         $data = Factory::getApplication()->getUserState('com_banners.edit.client.data', []); | ||||
|  | ||||
|         if (empty($data)) { | ||||
|             $data = $this->getItem(); | ||||
|         } | ||||
|  | ||||
|         $this->preprocessData('com_banners.client', $data); | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Prepare and sanitise the table prior to saving. | ||||
|      * | ||||
|      * @param   Table  $table  A Table object. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function prepareTable($table) | ||||
|     { | ||||
|         $table->name = htmlspecialchars_decode($table->name, ENT_QUOTES); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										296
									
								
								administrator/components/com_banners/src/Model/ClientsModel.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										296
									
								
								administrator/components/com_banners/src/Model/ClientsModel.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,296 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_banners | ||||
|  * | ||||
|  * @copyright   (C) 2008 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\Model; | ||||
|  | ||||
| use Joomla\CMS\Component\ComponentHelper; | ||||
| use Joomla\CMS\MVC\Model\ListModel; | ||||
| use Joomla\Database\ParameterType; | ||||
| use Joomla\Database\QueryInterface; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Methods supporting a list of banner records. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class ClientsModel extends ListModel | ||||
| { | ||||
|     /** | ||||
|      * Constructor. | ||||
|      * | ||||
|      * @param   array  $config  An optional associative array of configuration settings. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function __construct($config = []) | ||||
|     { | ||||
|         if (empty($config['filter_fields'])) { | ||||
|             $config['filter_fields'] = [ | ||||
|                 'id', 'a.id', | ||||
|                 'name', 'a.name', | ||||
|                 'contact', 'a.contact', | ||||
|                 'state', 'a.state', | ||||
|                 'checked_out', 'a.checked_out', | ||||
|                 'checked_out_time', 'a.checked_out_time', | ||||
|                 'purchase_type', 'a.purchase_type', | ||||
|             ]; | ||||
|         } | ||||
|  | ||||
|         parent::__construct($config); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to auto-populate the model state. | ||||
|      * | ||||
|      * Note. Calling getState in this method will result in recursion. | ||||
|      * | ||||
|      * @param   string  $ordering   An optional ordering field. | ||||
|      * @param   string  $direction  An optional direction (asc|desc). | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function populateState($ordering = 'a.name', $direction = 'asc') | ||||
|     { | ||||
|         // Load the parameters. | ||||
|         $this->setState('params', ComponentHelper::getParams('com_banners')); | ||||
|  | ||||
|         // List state information. | ||||
|         parent::populateState($ordering, $direction); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to get a store id based on model configuration state. | ||||
|      * | ||||
|      * This is necessary because the model is used by the component and | ||||
|      * different modules that might need different sets of data or different | ||||
|      * ordering requirements. | ||||
|      * | ||||
|      * @param   string  $id  A prefix for the store id. | ||||
|      * | ||||
|      * @return  string  A store id. | ||||
|      */ | ||||
|     protected function getStoreId($id = '') | ||||
|     { | ||||
|         // Compile the store id. | ||||
|         $id .= ':' . $this->getState('filter.search'); | ||||
|         $id .= ':' . $this->getState('filter.state'); | ||||
|         $id .= ':' . $this->getState('filter.purchase_type'); | ||||
|  | ||||
|         return parent::getStoreId($id); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Build an SQL query to load the list data. | ||||
|      * | ||||
|      * @return  QueryInterface | ||||
|      */ | ||||
|     protected function getListQuery() | ||||
|     { | ||||
|         // Create a new query object. | ||||
|         $db    = $this->getDatabase(); | ||||
|         $query = $db->getQuery(true); | ||||
|  | ||||
|         $defaultPurchase = (int) ComponentHelper::getParams('com_banners')->get('purchase_type', 3); | ||||
|  | ||||
|         // Select the required fields from the table. | ||||
|         $query->select( | ||||
|             $this->getState( | ||||
|                 'list.select', | ||||
|                 [ | ||||
|                     $db->quoteName('a.id'), | ||||
|                     $db->quoteName('a.name'), | ||||
|                     $db->quoteName('a.contact'), | ||||
|                     $db->quoteName('a.checked_out'), | ||||
|                     $db->quoteName('a.checked_out_time'), | ||||
|                     $db->quoteName('a.state'), | ||||
|                     $db->quoteName('a.metakey'), | ||||
|                     $db->quoteName('a.purchase_type'), | ||||
|                 ] | ||||
|             ) | ||||
|         ) | ||||
|             ->select( | ||||
|                 [ | ||||
|                     'COUNT(' . $db->quoteName('b.id') . ') AS ' . $db->quoteName('nbanners'), | ||||
|                     $db->quoteName('uc.name', 'editor'), | ||||
|                 ] | ||||
|             ); | ||||
|  | ||||
|         $query->from($db->quoteName('#__banner_clients', 'a')); | ||||
|  | ||||
|         // Join over the banners for counting | ||||
|         $query->join('LEFT', $db->quoteName('#__banners', 'b'), $db->quoteName('a.id') . ' = ' . $db->quoteName('b.cid')); | ||||
|  | ||||
|         // Join over the users for the checked out user. | ||||
|         $query->join('LEFT', $db->quoteName('#__users', 'uc'), $db->quoteName('uc.id') . ' = ' . $db->quoteName('a.checked_out')); | ||||
|  | ||||
|         // Filter by published state | ||||
|         $published = (string) $this->getState('filter.state'); | ||||
|  | ||||
|         if (is_numeric($published)) { | ||||
|             $published = (int) $published; | ||||
|             $query->where($db->quoteName('a.state') . ' = :published') | ||||
|                 ->bind(':published', $published, ParameterType::INTEGER); | ||||
|         } elseif ($published === '') { | ||||
|             $query->where($db->quoteName('a.state') . ' IN (0, 1)'); | ||||
|         } | ||||
|  | ||||
|         $query->group( | ||||
|             [ | ||||
|                 $db->quoteName('a.id'), | ||||
|                 $db->quoteName('a.name'), | ||||
|                 $db->quoteName('a.contact'), | ||||
|                 $db->quoteName('a.checked_out'), | ||||
|                 $db->quoteName('a.checked_out_time'), | ||||
|                 $db->quoteName('a.state'), | ||||
|                 $db->quoteName('a.metakey'), | ||||
|                 $db->quoteName('a.purchase_type'), | ||||
|                 $db->quoteName('uc.name'), | ||||
|             ] | ||||
|         ); | ||||
|  | ||||
|         // Filter by search in title | ||||
|         if ($search = trim($this->getState('filter.search', ''))) { | ||||
|             if (stripos($search, 'id:') === 0) { | ||||
|                 $search = (int) substr($search, 3); | ||||
|                 $query->where($db->quoteName('a.id') . ' = :search') | ||||
|                     ->bind(':search', $search, ParameterType::INTEGER); | ||||
|             } else { | ||||
|                 $search = '%' . str_replace(' ', '%', $search) . '%'; | ||||
|                 $query->where($db->quoteName('a.name') . ' LIKE :search') | ||||
|                     ->bind(':search', $search); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // Filter by purchase type | ||||
|         if ($purchaseType = (int) $this->getState('filter.purchase_type')) { | ||||
|             if ($defaultPurchase === $purchaseType) { | ||||
|                 $query->where('(' . $db->quoteName('a.purchase_type') . ' = :type OR ' . $db->quoteName('a.purchase_type') . ' = -1)'); | ||||
|             } else { | ||||
|                 $query->where($db->quoteName('a.purchase_type') . ' = :type'); | ||||
|             } | ||||
|  | ||||
|             $query->bind(':type', $purchaseType, ParameterType::INTEGER); | ||||
|         } | ||||
|  | ||||
|         // Add the list ordering clause. | ||||
|         $query->order( | ||||
|             $db->quoteName($db->escape($this->getState('list.ordering', 'a.name'))) . ' ' . $db->escape($this->getState('list.direction', 'ASC')) | ||||
|         ); | ||||
|  | ||||
|         return $query; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Overrides the getItems method to attach additional metrics to the list. | ||||
|      * | ||||
|      * @return  mixed  An array of data items on success, false on failure. | ||||
|      * | ||||
|      * @since   3.6 | ||||
|      */ | ||||
|     public function getItems() | ||||
|     { | ||||
|         // Get a storage key. | ||||
|         $store = $this->getStoreId('getItems'); | ||||
|  | ||||
|         // Try to load the data from internal storage. | ||||
|         if (!empty($this->cache[$store])) { | ||||
|             return $this->cache[$store]; | ||||
|         } | ||||
|  | ||||
|         // Load the list items. | ||||
|         $items = parent::getItems(); | ||||
|  | ||||
|         // If empty or an error, just return. | ||||
|         if (empty($items)) { | ||||
|             return []; | ||||
|         } | ||||
|  | ||||
|         // Getting the following metric by joins is WAY TOO SLOW. | ||||
|         // Faster to do three queries for very large banner trees. | ||||
|  | ||||
|         // Get the clients in the list. | ||||
|         $db        = $this->getDatabase(); | ||||
|         $clientIds = array_column($items, 'id'); | ||||
|  | ||||
|         $query = $db->getQuery(true) | ||||
|             ->select( | ||||
|                 [ | ||||
|                     $db->quoteName('cid'), | ||||
|                     'COUNT(' . $db->quoteName('cid') . ') AS ' . $db->quoteName('count_published'), | ||||
|                 ] | ||||
|             ) | ||||
|             ->from($db->quoteName('#__banners')) | ||||
|             ->where($db->quoteName('state') . ' = :state') | ||||
|             ->whereIn($db->quoteName('cid'), $clientIds) | ||||
|             ->group($db->quoteName('cid')) | ||||
|             ->bind(':state', $state, ParameterType::INTEGER); | ||||
|  | ||||
|         $db->setQuery($query); | ||||
|  | ||||
|         // Get the published banners count. | ||||
|         try { | ||||
|             $state          = 1; | ||||
|             $countPublished = $db->loadAssocList('cid', 'count_published'); | ||||
|         } catch (\RuntimeException $e) { | ||||
|             $this->setError($e->getMessage()); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Get the unpublished banners count. | ||||
|         try { | ||||
|             $state            = 0; | ||||
|             $countUnpublished = $db->loadAssocList('cid', 'count_published'); | ||||
|         } catch (\RuntimeException $e) { | ||||
|             $this->setError($e->getMessage()); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Get the trashed banners count. | ||||
|         try { | ||||
|             $state        = -2; | ||||
|             $countTrashed = $db->loadAssocList('cid', 'count_published'); | ||||
|         } catch (\RuntimeException $e) { | ||||
|             $this->setError($e->getMessage()); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Get the archived banners count. | ||||
|         try { | ||||
|             $state         = 2; | ||||
|             $countArchived = $db->loadAssocList('cid', 'count_published'); | ||||
|         } catch (\RuntimeException $e) { | ||||
|             $this->setError($e->getMessage()); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Inject the values back into the array. | ||||
|         foreach ($items as $item) { | ||||
|             $item->count_published   = $countPublished[$item->id] ?? 0; | ||||
|             $item->count_unpublished = $countUnpublished[$item->id] ?? 0; | ||||
|             $item->count_trashed     = $countTrashed[$item->id] ?? 0; | ||||
|             $item->count_archived    = $countArchived[$item->id] ?? 0; | ||||
|         } | ||||
|  | ||||
|         // Add the items to the internal cache. | ||||
|         $this->cache[$store] = $items; | ||||
|  | ||||
|         return $this->cache[$store]; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,92 @@ | ||||
| <?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\Model; | ||||
|  | ||||
| use Joomla\CMS\Application\ApplicationHelper; | ||||
| use Joomla\CMS\Factory; | ||||
| use Joomla\CMS\MVC\Model\FormModel; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Download model. | ||||
|  * | ||||
|  * @since  1.5 | ||||
|  */ | ||||
| class DownloadModel extends FormModel | ||||
| { | ||||
|     /** | ||||
|      * The model context | ||||
|      * | ||||
|      * @var  string | ||||
|      */ | ||||
|     protected $_context = 'com_banners.tracks'; | ||||
|  | ||||
|     /** | ||||
|      * Auto-populate the model state. | ||||
|      * | ||||
|      * Note. Calling getState in this method will result in recursion. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function populateState() | ||||
|     { | ||||
|         $input = Factory::getApplication()->getInput(); | ||||
|  | ||||
|         $this->setState('basename', $input->cookie->getString(ApplicationHelper::getHash($this->_context . '.basename'), '__SITE__')); | ||||
|         $this->setState('compressed', $input->cookie->getInt(ApplicationHelper::getHash($this->_context . '.compressed'), 1)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to get the record form. | ||||
|      * | ||||
|      * @param   array    $data      Data for the form. | ||||
|      * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not. | ||||
|      * | ||||
|      * @return  \Joomla\CMS\Form\Form|boolean  A Form object on success, false on failure | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function getForm($data = [], $loadData = true) | ||||
|     { | ||||
|         // Get the form. | ||||
|         $form = $this->loadForm('com_banners.download', 'download', ['control' => 'jform', 'load_data' => $loadData]); | ||||
|  | ||||
|         if (empty($form)) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         return $form; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to get the data that should be injected in the form. | ||||
|      * | ||||
|      * @return  mixed  The data for the form. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function loadFormData() | ||||
|     { | ||||
|         $data = (object) [ | ||||
|             'basename'   => $this->getState('basename'), | ||||
|             'compressed' => $this->getState('compressed'), | ||||
|         ]; | ||||
|  | ||||
|         $this->preprocessData('com_banners.download', $data); | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										497
									
								
								administrator/components/com_banners/src/Model/TracksModel.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										497
									
								
								administrator/components/com_banners/src/Model/TracksModel.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,497 @@ | ||||
| <?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\Model; | ||||
|  | ||||
| use Joomla\Archive\Archive; | ||||
| use Joomla\CMS\Component\ComponentHelper; | ||||
| use Joomla\CMS\Factory; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\MVC\Model\ListModel; | ||||
| use Joomla\Database\ParameterType; | ||||
| use Joomla\Database\QueryInterface; | ||||
| use Joomla\Filesystem\File; | ||||
| use Joomla\Filesystem\Folder; | ||||
| use Joomla\String\StringHelper; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Methods supporting a list of tracks. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class TracksModel extends ListModel | ||||
| { | ||||
|     /** | ||||
|      * The base name | ||||
|      * | ||||
|      * @var    string | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $basename; | ||||
|  | ||||
|     /** | ||||
|      * Constructor. | ||||
|      * | ||||
|      * @param   array  $config  An optional associative array of configuration settings. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function __construct($config = []) | ||||
|     { | ||||
|         if (empty($config['filter_fields'])) { | ||||
|             $config['filter_fields'] = [ | ||||
|                 'b.name', 'banner_name', | ||||
|                 'cl.name', 'client_name', 'client_id', | ||||
|                 'c.title', 'category_title', 'category_id', | ||||
|                 'track_type', 'a.track_type', 'type', | ||||
|                 'count', 'a.count', | ||||
|                 'track_date', 'a.track_date', 'end', 'begin', | ||||
|                 'level', 'c.level', | ||||
|             ]; | ||||
|         } | ||||
|  | ||||
|         parent::__construct($config); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to auto-populate the model state. | ||||
|      * | ||||
|      * Note. Calling getState in this method will result in recursion. | ||||
|      * | ||||
|      * @param   string  $ordering   An optional ordering field. | ||||
|      * @param   string  $direction  An optional direction (asc|desc). | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function populateState($ordering = 'b.name', $direction = 'asc') | ||||
|     { | ||||
|         // Load the parameters. | ||||
|         $this->setState('params', ComponentHelper::getParams('com_banners')); | ||||
|  | ||||
|         // List state information. | ||||
|         parent::populateState($ordering, $direction); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Build an SQL query to load the list data. | ||||
|      * | ||||
|      * @return  QueryInterface | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function getListQuery() | ||||
|     { | ||||
|         // Create a new query object. | ||||
|         $db    = $this->getDatabase(); | ||||
|         $query = $db->getQuery(true); | ||||
|  | ||||
|         // Select the required fields from the table. | ||||
|         $query->select( | ||||
|             [ | ||||
|                 $db->quoteName('a.track_date'), | ||||
|                 $db->quoteName('a.track_type'), | ||||
|                 $db->quoteName('a.count'), | ||||
|                 $db->quoteName('b.name', 'banner_name'), | ||||
|                 $db->quoteName('cl.name', 'client_name'), | ||||
|                 $db->quoteName('c.title', 'category_title'), | ||||
|             ] | ||||
|         ); | ||||
|  | ||||
|         // From tracks table. | ||||
|         $query->from($db->quoteName('#__banner_tracks', 'a')); | ||||
|  | ||||
|         // Join with the banners. | ||||
|         $query->join('LEFT', $db->quoteName('#__banners', 'b'), $db->quoteName('b.id') . ' = ' . $db->quoteName('a.banner_id')); | ||||
|  | ||||
|         // Join with the client. | ||||
|         $query->join('LEFT', $db->quoteName('#__banner_clients', 'cl'), $db->quoteName('cl.id') . ' = ' . $db->quoteName('b.cid')); | ||||
|  | ||||
|         // Join with the category. | ||||
|         $query->join('LEFT', $db->quoteName('#__categories', 'c'), $db->quoteName('c.id') . ' = ' . $db->quoteName('b.catid')); | ||||
|  | ||||
|         // Filter by type. | ||||
|  | ||||
|         if ($type = (int) $this->getState('filter.type')) { | ||||
|             $query->where($db->quoteName('a.track_type') . ' = :type') | ||||
|                 ->bind(':type', $type, ParameterType::INTEGER); | ||||
|         } | ||||
|  | ||||
|         // Filter by client. | ||||
|         $clientId = $this->getState('filter.client_id'); | ||||
|  | ||||
|         if (is_numeric($clientId)) { | ||||
|             $clientId = (int) $clientId; | ||||
|             $query->where($db->quoteName('b.cid') . ' = :clientId') | ||||
|                 ->bind(':clientId', $clientId, ParameterType::INTEGER); | ||||
|         } | ||||
|  | ||||
|         // Filter by category. | ||||
|         $categoryId = $this->getState('filter.category_id'); | ||||
|  | ||||
|         if (is_numeric($categoryId)) { | ||||
|             $categoryId = (int) $categoryId; | ||||
|             $query->where($db->quoteName('b.catid') . ' = :categoryId') | ||||
|                 ->bind(':categoryId', $categoryId, ParameterType::INTEGER); | ||||
|         } | ||||
|  | ||||
|         // Filter by begin date. | ||||
|         if ($begin = $this->getState('filter.begin')) { | ||||
|             $query->where($db->quoteName('a.track_date') . ' >= :begin') | ||||
|                 ->bind(':begin', $begin); | ||||
|         } | ||||
|  | ||||
|         // Filter by end date. | ||||
|         if ($end = $this->getState('filter.end')) { | ||||
|             $query->where($db->quoteName('a.track_date') . ' <= :end') | ||||
|                 ->bind(':end', $end); | ||||
|         } | ||||
|  | ||||
|         // Filter on the level. | ||||
|         if ($level = (int) $this->getState('filter.level')) { | ||||
|             $query->where($db->quoteName('c.level') . ' <= :level') | ||||
|                 ->bind(':level', $level, ParameterType::INTEGER); | ||||
|         } | ||||
|  | ||||
|         // Filter by search in banner name or client name. | ||||
|         if ($search = $this->getState('filter.search')) { | ||||
|             $search = '%' . StringHelper::strtolower($search) . '%'; | ||||
|             $query->where('(LOWER(' . $db->quoteName('b.name') . ') LIKE :search1 OR LOWER(' . $db->quoteName('cl.name') . ') LIKE :search2)') | ||||
|                 ->bind([':search1', ':search2'], $search); | ||||
|         } | ||||
|  | ||||
|         // Add the list ordering clause. | ||||
|         $query->order( | ||||
|             $db->quoteName($db->escape($this->getState('list.ordering', 'b.name'))) . ' ' . $db->escape($this->getState('list.direction', 'ASC')) | ||||
|         ); | ||||
|  | ||||
|         return $query; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to delete rows. | ||||
|      * | ||||
|      * @return  boolean  Returns true on success, false on failure. | ||||
|      */ | ||||
|     public function delete() | ||||
|     { | ||||
|         $user       = $this->getCurrentUser(); | ||||
|         $categoryId = (int) $this->getState('category_id'); | ||||
|  | ||||
|         // Access checks. | ||||
|         if ($categoryId) { | ||||
|             $allow = $user->authorise('core.delete', 'com_banners.category.' . $categoryId); | ||||
|         } else { | ||||
|             $allow = $user->authorise('core.delete', 'com_banners'); | ||||
|         } | ||||
|  | ||||
|         if ($allow) { | ||||
|             // Delete tracks from this banner | ||||
|             $db    = $this->getDatabase(); | ||||
|             $query = $db->getQuery(true) | ||||
|                 ->delete($db->quoteName('#__banner_tracks')); | ||||
|  | ||||
|             // Filter by type | ||||
|             if ($type = (int) $this->getState('filter.type')) { | ||||
|                 $query->where($db->quoteName('track_type') . ' = :type') | ||||
|                     ->bind(':type', $type, ParameterType::INTEGER); | ||||
|             } | ||||
|  | ||||
|             // Filter by begin date | ||||
|             if ($begin = $this->getState('filter.begin')) { | ||||
|                 $query->where($db->quoteName('track_date') . ' >= :begin') | ||||
|                     ->bind(':begin', $begin); | ||||
|             } | ||||
|  | ||||
|             // Filter by end date | ||||
|             if ($end = $this->getState('filter.end')) { | ||||
|                 $query->where($db->quoteName('track_date') . ' <= :end') | ||||
|                     ->bind(':end', $end); | ||||
|             } | ||||
|  | ||||
|             $subQuery = $db->getQuery(true); | ||||
|             $subQuery->select($db->quoteName('id')) | ||||
|                 ->from($db->quoteName('#__banners')); | ||||
|  | ||||
|             // Filter by client | ||||
|             if ($clientId = (int) $this->getState('filter.client_id')) { | ||||
|                 $subQuery->where($db->quoteName('cid') . ' = :clientId'); | ||||
|                 $query->bind(':clientId', $clientId, ParameterType::INTEGER); | ||||
|             } | ||||
|  | ||||
|             // Filter by category | ||||
|             if ($categoryId) { | ||||
|                 $subQuery->where($db->quoteName('catid') . ' = :categoryId'); | ||||
|                 $query->bind(':categoryId', $categoryId, ParameterType::INTEGER); | ||||
|             } | ||||
|  | ||||
|             $query->where($db->quoteName('banner_id') . ' IN (' . $subQuery . ')'); | ||||
|  | ||||
|             $db->setQuery($query); | ||||
|             $this->setError((string) $query); | ||||
|  | ||||
|             try { | ||||
|                 $db->execute(); | ||||
|             } catch (\RuntimeException $e) { | ||||
|                 $this->setError($e->getMessage()); | ||||
|  | ||||
|                 return false; | ||||
|             } | ||||
|         } else { | ||||
|             Factory::getApplication()->enqueueMessage(Text::_('JERROR_CORE_DELETE_NOT_PERMITTED'), 'error'); | ||||
|         } | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get file name | ||||
|      * | ||||
|      * @return  string  The file name | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function getBaseName() | ||||
|     { | ||||
|         if (!isset($this->basename)) { | ||||
|             $basename   = str_replace('__SITE__', Factory::getApplication()->get('sitename'), $this->getState('basename')); | ||||
|             $categoryId = $this->getState('filter.category_id'); | ||||
|  | ||||
|             if (is_numeric($categoryId)) { | ||||
|                 if ($categoryId > 0) { | ||||
|                     $basename = str_replace('__CATID__', $categoryId, $basename); | ||||
|                 } else { | ||||
|                     $basename = str_replace('__CATID__', '', $basename); | ||||
|                 } | ||||
|  | ||||
|                 $categoryName = $this->getCategoryName(); | ||||
|                 $basename     = str_replace('__CATNAME__', $categoryName, $basename); | ||||
|             } else { | ||||
|                 $basename = str_replace(['__CATID__', '__CATNAME__'], '', $basename); | ||||
|             } | ||||
|  | ||||
|             $clientId = $this->getState('filter.client_id'); | ||||
|  | ||||
|             if (is_numeric($clientId)) { | ||||
|                 if ($clientId > 0) { | ||||
|                     $basename = str_replace('__CLIENTID__', $clientId, $basename); | ||||
|                 } else { | ||||
|                     $basename = str_replace('__CLIENTID__', '', $basename); | ||||
|                 } | ||||
|  | ||||
|                 $clientName = $this->getClientName(); | ||||
|                 $basename   = str_replace('__CLIENTNAME__', $clientName, $basename); | ||||
|             } else { | ||||
|                 $basename = str_replace(['__CLIENTID__', '__CLIENTNAME__'], '', $basename); | ||||
|             } | ||||
|  | ||||
|             $type = $this->getState('filter.type'); | ||||
|  | ||||
|             if ($type > 0) { | ||||
|                 $basename = str_replace('__TYPE__', $type, $basename); | ||||
|                 $typeName = Text::_('COM_BANNERS_TYPE' . $type); | ||||
|                 $basename = str_replace('__TYPENAME__', $typeName, $basename); | ||||
|             } else { | ||||
|                 $basename = str_replace(['__TYPE__', '__TYPENAME__'], '', $basename); | ||||
|             } | ||||
|  | ||||
|             $begin = $this->getState('filter.begin'); | ||||
|  | ||||
|             if (!empty($begin)) { | ||||
|                 $basename = str_replace('__BEGIN__', $begin, $basename); | ||||
|             } else { | ||||
|                 $basename = str_replace('__BEGIN__', '', $basename); | ||||
|             } | ||||
|  | ||||
|             $end = $this->getState('filter.end'); | ||||
|  | ||||
|             if (!empty($end)) { | ||||
|                 $basename = str_replace('__END__', $end, $basename); | ||||
|             } else { | ||||
|                 $basename = str_replace('__END__', '', $basename); | ||||
|             } | ||||
|  | ||||
|             $this->basename = $basename; | ||||
|         } | ||||
|  | ||||
|         return $this->basename; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the category name. | ||||
|      * | ||||
|      * @return  string  The category name | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function getCategoryName() | ||||
|     { | ||||
|         $categoryId = (int) $this->getState('filter.category_id'); | ||||
|  | ||||
|         if ($categoryId) { | ||||
|             $db    = $this->getDatabase(); | ||||
|             $query = $db->getQuery(true) | ||||
|                 ->select($db->quoteName('title')) | ||||
|                 ->from($db->quoteName('#__categories')) | ||||
|                 ->where($db->quoteName('id') . ' = :categoryId') | ||||
|                 ->bind(':categoryId', $categoryId, ParameterType::INTEGER); | ||||
|             $db->setQuery($query); | ||||
|  | ||||
|             try { | ||||
|                 $name = $db->loadResult(); | ||||
|             } catch (\RuntimeException $e) { | ||||
|                 $this->setError($e->getMessage()); | ||||
|  | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             return $name; | ||||
|         } | ||||
|  | ||||
|         return Text::_('COM_BANNERS_NOCATEGORYNAME'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the client name | ||||
|      * | ||||
|      * @return  string  The client name. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function getClientName() | ||||
|     { | ||||
|         $clientId = (int) $this->getState('filter.client_id'); | ||||
|  | ||||
|         if ($clientId) { | ||||
|             $db    = $this->getDatabase(); | ||||
|             $query = $db->getQuery(true) | ||||
|                 ->select($db->quoteName('name')) | ||||
|                 ->from($db->quoteName('#__banner_clients')) | ||||
|                 ->where($db->quoteName('id') . ' = :clientId') | ||||
|                 ->bind(':clientId', $clientId, ParameterType::INTEGER); | ||||
|             $db->setQuery($query); | ||||
|  | ||||
|             try { | ||||
|                 $name = $db->loadResult(); | ||||
|             } catch (\RuntimeException $e) { | ||||
|                 $this->setError($e->getMessage()); | ||||
|  | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             return $name; | ||||
|         } | ||||
|  | ||||
|         return Text::_('COM_BANNERS_NOCLIENTNAME'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the file type. | ||||
|      * | ||||
|      * @return  string  The file type | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function getFileType() | ||||
|     { | ||||
|         return $this->getState('compressed') ? 'zip' : 'csv'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the mime type. | ||||
|      * | ||||
|      * @return  string  The mime type. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function getMimeType() | ||||
|     { | ||||
|         return $this->getState('compressed') ? 'application/zip' : 'text/csv'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the content | ||||
|      * | ||||
|      * @return  string  The content. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function getContent() | ||||
|     { | ||||
|         if (!isset($this->content)) { | ||||
|             $this->content = '"' . str_replace('"', '""', Text::_('COM_BANNERS_HEADING_NAME')) . '","' | ||||
|                 . str_replace('"', '""', Text::_('COM_BANNERS_HEADING_CLIENT')) . '","' | ||||
|                 . str_replace('"', '""', Text::_('JCATEGORY')) . '","' | ||||
|                 . str_replace('"', '""', Text::_('COM_BANNERS_HEADING_TYPE')) . '","' | ||||
|                 . str_replace('"', '""', Text::_('COM_BANNERS_HEADING_COUNT')) . '","' | ||||
|                 . str_replace('"', '""', Text::_('JDATE')) . '"' . "\n"; | ||||
|  | ||||
|             foreach ($this->getItems() as $item) { | ||||
|                 $this->content .= '"' . str_replace('"', '""', $item->banner_name) . '","' | ||||
|                     . str_replace('"', '""', $item->client_name) . '","' | ||||
|                     . str_replace('"', '""', $item->category_title) . '","' | ||||
|                     . str_replace('"', '""', ($item->track_type == 1 ? Text::_('COM_BANNERS_IMPRESSION') : Text::_('COM_BANNERS_CLICK'))) . '","' | ||||
|                     . str_replace('"', '""', $item->count) . '","' | ||||
|                     . str_replace('"', '""', $item->track_date) . '"' . "\n"; | ||||
|             } | ||||
|  | ||||
|             if ($this->getState('compressed')) { | ||||
|                 $app = Factory::getApplication(); | ||||
|  | ||||
|                 $files = [ | ||||
|                     'track' => [ | ||||
|                         'name' => $this->getBaseName() . '.csv', | ||||
|                         'data' => $this->content, | ||||
|                         'time' => time(), | ||||
|                     ], | ||||
|                 ]; | ||||
|                 $ziproot = $app->get('tmp_path') . '/' . uniqid('banners_tracks_') . '.zip'; | ||||
|  | ||||
|                 // Run the packager | ||||
|                 $delete = Folder::files($app->get('tmp_path') . '/', uniqid('banners_tracks_'), false, true); | ||||
|  | ||||
|                 if (!empty($delete)) { | ||||
|                     if (!File::delete($delete)) { | ||||
|                         // File::delete throws an error | ||||
|                         $this->setError(Text::_('COM_BANNERS_ERR_ZIP_DELETE_FAILURE')); | ||||
|  | ||||
|                         return false; | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 $archive = new Archive(); | ||||
|  | ||||
|                 if (!$packager = $archive->getAdapter('zip')) { | ||||
|                     $this->setError(Text::_('COM_BANNERS_ERR_ZIP_ADAPTER_FAILURE')); | ||||
|  | ||||
|                     return false; | ||||
|                 } | ||||
|  | ||||
|                 if (!$packager->create($ziproot, $files)) { | ||||
|                     $this->setError(Text::_('COM_BANNERS_ERR_ZIP_CREATE_FAILURE')); | ||||
|  | ||||
|                     return false; | ||||
|                 } | ||||
|  | ||||
|                 $this->content = file_get_contents($ziproot); | ||||
|  | ||||
|                 // Remove tmp zip file, it's no longer needed. | ||||
|                 File::delete($ziproot); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return $this->content; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										126
									
								
								administrator/components/com_banners/src/Service/Html/Banner.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										126
									
								
								administrator/components/com_banners/src/Service/Html/Banner.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,126 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_banners | ||||
|  * | ||||
|  * @copyright   (C) 2011 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\Service\Html; | ||||
|  | ||||
| use Joomla\CMS\Factory; | ||||
| use Joomla\CMS\HTML\HTMLHelper; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\Database\DatabaseAwareTrait; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Banner HTML class. | ||||
|  * | ||||
|  * @since  2.5 | ||||
|  */ | ||||
| class Banner | ||||
| { | ||||
|     use DatabaseAwareTrait; | ||||
|  | ||||
|     /** | ||||
|      * Display a batch widget for the client selector. | ||||
|      * | ||||
|      * @return  string  The necessary HTML for the widget. | ||||
|      * | ||||
|      * @since   2.5 | ||||
|      */ | ||||
|     public function clients() | ||||
|     { | ||||
|         // Create the batch selector to change the client on a selection list. | ||||
|         return implode( | ||||
|             "\n", | ||||
|             [ | ||||
|                 '<label id="batch-client-lbl" for="batch-client-id">', | ||||
|                 Text::_('COM_BANNERS_BATCH_CLIENT_LABEL'), | ||||
|                 '</label>', | ||||
|                 '<select class="form-select" name="batch[client_id]" id="batch-client-id">', | ||||
|                 '<option value="">' . Text::_('COM_BANNERS_BATCH_CLIENT_NOCHANGE') . '</option>', | ||||
|                 '<option value="0">' . Text::_('COM_BANNERS_NO_CLIENT') . '</option>', | ||||
|                 HTMLHelper::_('select.options', static::clientlist(), 'value', 'text'), | ||||
|                 '</select>', | ||||
|             ] | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to get the field options. | ||||
|      * | ||||
|      * @return  array  The field option objects. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function clientlist() | ||||
|     { | ||||
|         $db    = $this->getDatabase(); | ||||
|         $query = $db->getQuery(true) | ||||
|             ->select( | ||||
|                 [ | ||||
|                     $db->quoteName('id', 'value'), | ||||
|                     $db->quoteName('name', 'text'), | ||||
|                 ] | ||||
|             ) | ||||
|             ->from($db->quoteName('#__banner_clients')) | ||||
|             ->order($db->quoteName('name')); | ||||
|  | ||||
|         // Get the options. | ||||
|         $db->setQuery($query); | ||||
|  | ||||
|         try { | ||||
|             $options = $db->loadObjectList(); | ||||
|         } catch (\RuntimeException $e) { | ||||
|             Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); | ||||
|         } | ||||
|  | ||||
|         return $options; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns a pinned state on a grid | ||||
|      * | ||||
|      * @param   integer  $value     The state value. | ||||
|      * @param   integer  $i         The row index | ||||
|      * @param   boolean  $enabled   An optional setting for access control on the action. | ||||
|      * @param   string   $checkbox  An optional prefix for checkboxes. | ||||
|      * | ||||
|      * @return  string   The Html code | ||||
|      * | ||||
|      * @see     HTMLHelperJGrid::state | ||||
|      * @since   2.5.5 | ||||
|      */ | ||||
|     public function pinned($value, $i, $enabled = true, $checkbox = 'cb') | ||||
|     { | ||||
|         $states = [ | ||||
|             1 => [ | ||||
|                 'sticky_unpublish', | ||||
|                 'COM_BANNERS_BANNERS_PINNED', | ||||
|                 'COM_BANNERS_BANNERS_HTML_UNPIN_BANNER', | ||||
|                 'COM_BANNERS_BANNERS_PINNED', | ||||
|                 true, | ||||
|                 'publish', | ||||
|                 'publish', | ||||
|             ], | ||||
|             0 => [ | ||||
|                 'sticky_publish', | ||||
|                 'COM_BANNERS_BANNERS_UNPINNED', | ||||
|                 'COM_BANNERS_BANNERS_HTML_PIN_BANNER', | ||||
|                 'COM_BANNERS_BANNERS_UNPINNED', | ||||
|                 true, | ||||
|                 'unpublish', | ||||
|                 'unpublish', | ||||
|             ], | ||||
|         ]; | ||||
|  | ||||
|         return HTMLHelper::_('jgrid.state', $states, $value, $i, 'banners.', $enabled, true, $checkbox); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										360
									
								
								administrator/components/com_banners/src/Table/BannerTable.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										360
									
								
								administrator/components/com_banners/src/Table/BannerTable.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,360 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_banners | ||||
|  * | ||||
|  * @copyright   (C) 2005 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\Table; | ||||
|  | ||||
| use Joomla\CMS\Application\ApplicationHelper; | ||||
| use Joomla\CMS\Component\ComponentHelper; | ||||
| use Joomla\CMS\Factory; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\Table\Table; | ||||
| use Joomla\CMS\Versioning\VersionableTableInterface; | ||||
| use Joomla\Database\DatabaseDriver; | ||||
| use Joomla\Database\ParameterType; | ||||
| use Joomla\Event\DispatcherInterface; | ||||
| use Joomla\Registry\Registry; | ||||
| use Joomla\Utilities\ArrayHelper; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Banner table | ||||
|  * | ||||
|  * @since  1.5 | ||||
|  */ | ||||
| class BannerTable extends Table implements VersionableTableInterface | ||||
| { | ||||
|     /** | ||||
|      * Indicates that columns fully support the NULL value in the database | ||||
|      * | ||||
|      * @var    boolean | ||||
|      * @since  4.0.0 | ||||
|      */ | ||||
|     protected $_supportNullValue = true; | ||||
|  | ||||
|     /** | ||||
|      * Constructor | ||||
|      * | ||||
|      * @param   DatabaseDriver        $db          Database connector object | ||||
|      * @param   ?DispatcherInterface  $dispatcher  Event dispatcher for this table | ||||
|      * | ||||
|      * @since   1.5 | ||||
|      */ | ||||
|     public function __construct(DatabaseDriver $db, ?DispatcherInterface $dispatcher = null) | ||||
|     { | ||||
|         $this->typeAlias = 'com_banners.banner'; | ||||
|  | ||||
|         parent::__construct('#__banners', 'id', $db, $dispatcher); | ||||
|  | ||||
|         $this->created = Factory::getDate()->toSql(); | ||||
|         $this->setColumnAlias('published', 'state'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Increase click count | ||||
|      * | ||||
|      * @return  void | ||||
|      */ | ||||
|     public function clicks() | ||||
|     { | ||||
|         $id    = (int) $this->id; | ||||
|         $query = $this->_db->getQuery(true) | ||||
|             ->update($this->_db->quoteName('#__banners')) | ||||
|             ->set($this->_db->quoteName('clicks') . ' = ' . $this->_db->quoteName('clicks') . ' + 1') | ||||
|             ->where($this->_db->quoteName('id') . ' = :id') | ||||
|             ->bind(':id', $id, ParameterType::INTEGER); | ||||
|  | ||||
|         $this->_db->setQuery($query); | ||||
|         $this->_db->execute(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Overloaded check function | ||||
|      * | ||||
|      * @return  boolean | ||||
|      * | ||||
|      * @see     Table::check | ||||
|      * @since   1.5 | ||||
|      */ | ||||
|     public function check() | ||||
|     { | ||||
|         try { | ||||
|             parent::check(); | ||||
|         } catch (\Exception $e) { | ||||
|             $this->setError($e->getMessage()); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Set name | ||||
|         $this->name = htmlspecialchars_decode($this->name, ENT_QUOTES); | ||||
|  | ||||
|         // Set alias | ||||
|         if (trim($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'); | ||||
|         } | ||||
|  | ||||
|         // Check for a valid category. | ||||
|         if (!$this->catid = (int) $this->catid) { | ||||
|             $this->setError(Text::_('JLIB_DATABASE_ERROR_CATEGORY_REQUIRED')); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Set created date if not set. | ||||
|         if (!(int) $this->created) { | ||||
|             $this->created = Factory::getDate()->toSql(); | ||||
|         } | ||||
|  | ||||
|         // 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; | ||||
|         } | ||||
|  | ||||
|         // Check the publish down date is not earlier than publish up. | ||||
|         if (!\is_null($this->publish_down) && !\is_null($this->publish_up) && $this->publish_down < $this->publish_up) { | ||||
|             $this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH')); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Set ordering | ||||
|         if ($this->state < 0) { | ||||
|             // Set ordering to 0 if state is archived or trashed | ||||
|             $this->ordering = 0; | ||||
|         } elseif (empty($this->ordering)) { | ||||
|             // Set ordering to last if ordering was 0 | ||||
|             $this->ordering = $this->getNextOrder($this->_db->quoteName('catid') . ' = ' . ((int) $this->catid) . ' AND ' . $this->_db->quoteName('state') . ' >= 0'); | ||||
|         } | ||||
|  | ||||
|         // Set modified to created if not set | ||||
|         if (!$this->modified) { | ||||
|             $this->modified = $this->created; | ||||
|         } | ||||
|  | ||||
|         // Set modified_by to created_by if not set | ||||
|         if (empty($this->modified_by)) { | ||||
|             $this->modified_by = $this->created_by; | ||||
|         } | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Overloaded bind function | ||||
|      * | ||||
|      * @param   mixed  $array   An associative array or object to bind to the \Joomla\CMS\Table\Table instance. | ||||
|      * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding. | ||||
|      * | ||||
|      * @return  boolean  True on success | ||||
|      * | ||||
|      * @since   1.5 | ||||
|      */ | ||||
|     public function bind($array, $ignore = []) | ||||
|     { | ||||
|         if (isset($array['params']) && \is_array($array['params'])) { | ||||
|             $registry = new Registry($array['params']); | ||||
|  | ||||
|             if ((int) $registry->get('width', 0) < 0) { | ||||
|                 $this->setError(Text::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', Text::_('COM_BANNERS_FIELD_WIDTH_LABEL'))); | ||||
|  | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             if ((int) $registry->get('height', 0) < 0) { | ||||
|                 $this->setError(Text::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', Text::_('COM_BANNERS_FIELD_HEIGHT_LABEL'))); | ||||
|  | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             // Converts the width and height to an absolute numeric value: | ||||
|             $width  = abs((int) $registry->get('width', 0)); | ||||
|             $height = abs((int) $registry->get('height', 0)); | ||||
|  | ||||
|             // Sets the width and height to an empty string if = 0 | ||||
|             $registry->set('width', $width ?: ''); | ||||
|             $registry->set('height', $height ?: ''); | ||||
|  | ||||
|             $array['params'] = (string) $registry; | ||||
|         } | ||||
|  | ||||
|         if (isset($array['imptotal'])) { | ||||
|             $array['imptotal'] = abs((int) $array['imptotal']); | ||||
|         } | ||||
|  | ||||
|         return parent::bind($array, $ignore); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to store a row | ||||
|      * | ||||
|      * @param   boolean  $updateNulls  True to update fields even if they are null. | ||||
|      * | ||||
|      * @return  boolean  True on success, false on failure. | ||||
|      */ | ||||
|     public function store($updateNulls = true) | ||||
|     { | ||||
|         $db = $this->getDbo(); | ||||
|  | ||||
|         if (empty($this->id)) { | ||||
|             $purchaseType = $this->purchase_type; | ||||
|  | ||||
|             if ($purchaseType < 0 && $this->cid) { | ||||
|                 $client = new ClientTable($db); | ||||
|                 $client->load($this->cid); | ||||
|                 $purchaseType = $client->purchase_type; | ||||
|             } | ||||
|  | ||||
|             if ($purchaseType < 0) { | ||||
|                 $purchaseType = ComponentHelper::getParams('com_banners')->get('purchase_type'); | ||||
|             } | ||||
|  | ||||
|             switch ($purchaseType) { | ||||
|                 case 1: | ||||
|                     $this->reset = null; | ||||
|                     break; | ||||
|                 case 2: | ||||
|                     $date        = Factory::getDate('+1 year ' . date('Y-m-d')); | ||||
|                     $this->reset = $date->toSql(); | ||||
|                     break; | ||||
|                 case 3: | ||||
|                     $date        = Factory::getDate('+1 month ' . date('Y-m-d')); | ||||
|                     $this->reset = $date->toSql(); | ||||
|                     break; | ||||
|                 case 4: | ||||
|                     $date        = Factory::getDate('+7 day ' . date('Y-m-d')); | ||||
|                     $this->reset = $date->toSql(); | ||||
|                     break; | ||||
|                 case 5: | ||||
|                     $date        = Factory::getDate('+1 day ' . date('Y-m-d')); | ||||
|                     $this->reset = $date->toSql(); | ||||
|                     break; | ||||
|             } | ||||
|  | ||||
|             // Store the row | ||||
|             parent::store($updateNulls); | ||||
|         } else { | ||||
|             // Get the old row | ||||
|             $oldrow = new self($db, $this->getDispatcher()); | ||||
|  | ||||
|             if (!$oldrow->load($this->id) && $oldrow->getError()) { | ||||
|                 $this->setError($oldrow->getError()); | ||||
|             } | ||||
|  | ||||
|             // Verify that the alias is unique | ||||
|             $table = new self($db, $this->getDispatcher()); | ||||
|  | ||||
|             if ($table->load(['alias' => $this->alias, 'catid' => $this->catid]) && ($table->id != $this->id || $this->id == 0)) { | ||||
|                 $this->setError(Text::_('COM_BANNERS_ERROR_UNIQUE_ALIAS')); | ||||
|  | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             // Store the new row | ||||
|             parent::store($updateNulls); | ||||
|  | ||||
|             // Need to reorder ? | ||||
|             if ($oldrow->state >= 0 && ($this->state < 0 || $oldrow->catid != $this->catid)) { | ||||
|                 // Reorder the oldrow | ||||
|                 $this->reorder($this->_db->quoteName('catid') . ' = ' . ((int) $oldrow->catid) . ' AND ' . $this->_db->quoteName('state') . ' >= 0'); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return \count($this->getErrors()) == 0; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to set the sticky state for a row or list of rows in the database | ||||
|      * table.  The method respects checked out rows by other users and will attempt | ||||
|      * to checkin rows that it can after adjustments are made. | ||||
|      * | ||||
|      * @param   mixed    $pks     An optional array of primary key values to update.  If not set the instance property value is used. | ||||
|      * @param   integer  $state   The sticky state. eg. [0 = unsticked, 1 = sticked] | ||||
|      * @param   integer  $userId  The user id of the user performing the operation. | ||||
|      * | ||||
|      * @return  boolean  True on success. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function stick($pks = null, $state = 1, $userId = 0) | ||||
|     { | ||||
|         $k = $this->_tbl_key; | ||||
|  | ||||
|         // Sanitize input. | ||||
|         $pks    = ArrayHelper::toInteger($pks); | ||||
|         $userId = (int) $userId; | ||||
|         $state  = (int) $state; | ||||
|  | ||||
|         // If there are no primary keys set check to see if the instance key is set. | ||||
|         if (empty($pks)) { | ||||
|             if ($this->$k) { | ||||
|                 $pks = [$this->$k]; | ||||
|             } else { | ||||
|                 // Nothing to set publishing state on, return false. | ||||
|                 $this->setError(Text::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED')); | ||||
|  | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // Get an instance of the table | ||||
|         $table = new self($this->getDbo(), $this->getDispatcher()); | ||||
|  | ||||
|         // For all keys | ||||
|         foreach ($pks as $pk) { | ||||
|             // Load the banner | ||||
|             if (!$table->load($pk)) { | ||||
|                 $this->setError($table->getError()); | ||||
|             } | ||||
|  | ||||
|             // Verify checkout | ||||
|             if (\is_null($table->checked_out) || $table->checked_out == $userId) { | ||||
|                 // Change the state | ||||
|                 $table->sticky           = $state; | ||||
|                 $table->checked_out      = null; | ||||
|                 $table->checked_out_time = null; | ||||
|  | ||||
|                 // Check the row | ||||
|                 $table->check(); | ||||
|  | ||||
|                 // Store the row | ||||
|                 if (!$table->store()) { | ||||
|                     $this->setError($table->getError()); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return \count($this->getErrors()) == 0; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the type alias for the history table | ||||
|      * | ||||
|      * @return  string  The alias as described above | ||||
|      * | ||||
|      * @since   4.0.0 | ||||
|      */ | ||||
|     public function getTypeAlias() | ||||
|     { | ||||
|         return $this->typeAlias; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										101
									
								
								administrator/components/com_banners/src/Table/ClientTable.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								administrator/components/com_banners/src/Table/ClientTable.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,101 @@ | ||||
| <?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\Table; | ||||
|  | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\Table\Table; | ||||
| use Joomla\CMS\Versioning\VersionableTableInterface; | ||||
| use Joomla\Database\DatabaseDriver; | ||||
| use Joomla\Event\DispatcherInterface; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Client table | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class ClientTable extends Table implements VersionableTableInterface | ||||
| { | ||||
|     /** | ||||
|      * Indicates that columns fully support the NULL value in the database | ||||
|      * | ||||
|      * @var    boolean | ||||
|      * @since  4.0.0 | ||||
|      */ | ||||
|     protected $_supportNullValue = true; | ||||
|  | ||||
|     /** | ||||
|      * Constructor | ||||
|      * | ||||
|      * @param   DatabaseDriver        $db          Database connector object | ||||
|      * @param   ?DispatcherInterface  $dispatcher  Event dispatcher for this table | ||||
|      * | ||||
|      * @since   1.5 | ||||
|      */ | ||||
|     public function __construct(DatabaseDriver $db, ?DispatcherInterface $dispatcher = null) | ||||
|     { | ||||
|         $this->typeAlias = 'com_banners.client'; | ||||
|  | ||||
|         $this->setColumnAlias('published', 'state'); | ||||
|  | ||||
|         parent::__construct('#__banner_clients', 'id', $db, $dispatcher); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the type alias for the history table | ||||
|      * | ||||
|      * @return  string  The alias as described above | ||||
|      * | ||||
|      * @since   4.0.0 | ||||
|      */ | ||||
|     public function getTypeAlias() | ||||
|     { | ||||
|         return $this->typeAlias; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Overloaded check function | ||||
|      * | ||||
|      * @return  boolean  True if the object is ok | ||||
|      * | ||||
|      * @see     Table::check() | ||||
|      * @since   4.0.0 | ||||
|      */ | ||||
|     public function check() | ||||
|     { | ||||
|         try { | ||||
|             parent::check(); | ||||
|         } catch (\Exception $e) { | ||||
|             $this->setError($e->getMessage()); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Check for valid name | ||||
|         if (trim($this->name) === '') { | ||||
|             $this->setError(Text::_('COM_BANNERS_WARNING_PROVIDE_VALID_NAME')); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Check for valid contact | ||||
|         if (trim($this->contact) === '') { | ||||
|             $this->setError(Text::_('COM_BANNERS_PROVIDE_VALID_CONTACT')); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,149 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_banners | ||||
|  * | ||||
|  * @copyright   (C) 2008 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\View\Banner; | ||||
|  | ||||
| use Joomla\CMS\Component\ComponentHelper; | ||||
| use Joomla\CMS\Factory; | ||||
| use Joomla\CMS\Form\Form; | ||||
| use Joomla\CMS\Helper\ContentHelper; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\MVC\View\GenericDataException; | ||||
| use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; | ||||
| use Joomla\CMS\Toolbar\Toolbar; | ||||
| use Joomla\CMS\Toolbar\ToolbarHelper; | ||||
| use Joomla\Component\Banners\Administrator\Model\BannerModel; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * View to edit a banner. | ||||
|  * | ||||
|  * @since  1.5 | ||||
|  */ | ||||
| class HtmlView extends BaseHtmlView | ||||
| { | ||||
|     /** | ||||
|      * The Form object | ||||
|      * | ||||
|      * @var    Form | ||||
|      * @since  1.5 | ||||
|      */ | ||||
|     protected $form; | ||||
|  | ||||
|     /** | ||||
|      * The active item | ||||
|      * | ||||
|      * @var    object | ||||
|      * @since  1.5 | ||||
|      */ | ||||
|     protected $item; | ||||
|  | ||||
|     /** | ||||
|      * The model state | ||||
|      * | ||||
|      * @var    object | ||||
|      * @since  1.5 | ||||
|      */ | ||||
|     protected $state; | ||||
|  | ||||
|     /** | ||||
|      * Display the view | ||||
|      * | ||||
|      * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.5 | ||||
|      * | ||||
|      * @throws  \Exception | ||||
|      */ | ||||
|     public function display($tpl = null): void | ||||
|     { | ||||
|         /** @var BannerModel $model */ | ||||
|         $model       = $this->getModel(); | ||||
|         $this->form  = $model->getForm(); | ||||
|         $this->item  = $model->getItem(); | ||||
|         $this->state = $model->getState(); | ||||
|  | ||||
|         // Check for errors. | ||||
|         if (\count($errors = $this->get('Errors'))) { | ||||
|             throw new GenericDataException(implode("\n", $errors), 500); | ||||
|         } | ||||
|  | ||||
|         $this->addToolbar(); | ||||
|  | ||||
|         parent::display($tpl); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Add the page title and toolbar. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      * @throws  \Exception | ||||
|      */ | ||||
|     protected function addToolbar(): void | ||||
|     { | ||||
|         Factory::getApplication()->getInput()->set('hidemainmenu', true); | ||||
|  | ||||
|         $user       = $this->getCurrentUser(); | ||||
|         $userId     = $user->id; | ||||
|         $isNew      = ($this->item->id == 0); | ||||
|         $checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $userId); | ||||
|         $toolbar    = $this->getDocument()->getToolbar(); | ||||
|  | ||||
|         // Since we don't track these assets at the item level, use the category id. | ||||
|         $canDo = ContentHelper::getActions('com_banners', 'category', $this->item->catid); | ||||
|  | ||||
|         ToolbarHelper::title($isNew ? Text::_('COM_BANNERS_MANAGER_BANNER_NEW') : Text::_('COM_BANNERS_MANAGER_BANNER_EDIT'), 'bookmark banners'); | ||||
|  | ||||
|         // If not checked out, can save the item. | ||||
|         if (!$checkedOut && ($canDo->get('core.edit') || \count($user->getAuthorisedCategories('com_banners', 'core.create')) > 0)) { | ||||
|             $toolbar->apply('banner.apply'); | ||||
|         } | ||||
|  | ||||
|         $saveGroup = $toolbar->dropdownButton('save-group'); | ||||
|  | ||||
|         $saveGroup->configure( | ||||
|             function (Toolbar $childBar) use ($checkedOut, $canDo, $user, $isNew) { | ||||
|                 // If not checked out, can save the item. | ||||
|                 if (!$checkedOut && ($canDo->get('core.edit') || \count($user->getAuthorisedCategories('com_banners', 'core.create')) > 0)) { | ||||
|                     $childBar->save('banner.save'); | ||||
|  | ||||
|                     if ($canDo->get('core.create')) { | ||||
|                         $childBar->save2new('banner.save2new'); | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 // If an existing item, can save to a copy. | ||||
|                 if (!$isNew && $canDo->get('core.create')) { | ||||
|                     $childBar->save2copy('banner.save2copy'); | ||||
|                 } | ||||
|             } | ||||
|         ); | ||||
|  | ||||
|         if (empty($this->item->id)) { | ||||
|             $toolbar->cancel('banner.cancel', 'JTOOLBAR_CANCEL'); | ||||
|         } else { | ||||
|             $toolbar->cancel('banner.cancel'); | ||||
|  | ||||
|             if (ComponentHelper::isEnabled('com_contenthistory') && $this->state->params->get('save_history', 0) && $canDo->get('core.edit')) { | ||||
|                 $toolbar->versions('com_banners.banner', $this->item->id); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         $toolbar->divider(); | ||||
|         $toolbar->help('Banners:_Edit'); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,212 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_banners | ||||
|  * | ||||
|  * @copyright   (C) 2008 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\View\Banners; | ||||
|  | ||||
| use Joomla\CMS\Form\Form; | ||||
| use Joomla\CMS\Helper\ContentHelper; | ||||
| use Joomla\CMS\Language\Multilanguage; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\MVC\View\GenericDataException; | ||||
| use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; | ||||
| use Joomla\CMS\Pagination\Pagination; | ||||
| use Joomla\CMS\Toolbar\Button\DropdownButton; | ||||
| use Joomla\CMS\Toolbar\ToolbarHelper; | ||||
| use Joomla\Component\Banners\Administrator\Model\BannersModel; | ||||
| use Joomla\Registry\Registry; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * View class for a list of banners. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class HtmlView extends BaseHtmlView | ||||
| { | ||||
|     /** | ||||
|      * The search tools form | ||||
|      * | ||||
|      * @var    Form | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     public $filterForm; | ||||
|  | ||||
|     /** | ||||
|      * The active search filters | ||||
|      * | ||||
|      * @var    array | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     public $activeFilters = []; | ||||
|  | ||||
|     /** | ||||
|      * Category data | ||||
|      * | ||||
|      * @var    array | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $categories = []; | ||||
|  | ||||
|     /** | ||||
|      * An array of items | ||||
|      * | ||||
|      * @var    array | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $items = []; | ||||
|  | ||||
|     /** | ||||
|      * The pagination object | ||||
|      * | ||||
|      * @var    Pagination | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $pagination; | ||||
|  | ||||
|     /** | ||||
|      * The model state | ||||
|      * | ||||
|      * @var    Registry | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $state; | ||||
|  | ||||
|     /** | ||||
|      * Is this view an Empty State | ||||
|      * | ||||
|      * @var  boolean | ||||
|      * @since 4.0.0 | ||||
|      */ | ||||
|     private $isEmptyState = false; | ||||
|  | ||||
|     /** | ||||
|      * Method to display the view. | ||||
|      * | ||||
|      * @param   string  $tpl  A template file to load. [optional] | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      * @throws  \Exception | ||||
|      */ | ||||
|     public function display($tpl = null): void | ||||
|     { | ||||
|         /** @var BannersModel $model */ | ||||
|         $model               = $this->getModel(); | ||||
|         $this->categories    = $model->getCategoryOrders(); | ||||
|         $this->items         = $model->getItems(); | ||||
|         $this->pagination    = $model->getPagination(); | ||||
|         $this->state         = $model->getState(); | ||||
|         $this->filterForm    = $model->getFilterForm(); | ||||
|         $this->activeFilters = $model->getActiveFilters(); | ||||
|  | ||||
|         if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) { | ||||
|             $this->setLayout('emptystate'); | ||||
|         } | ||||
|  | ||||
|         // Check for errors. | ||||
|         if (\count($errors = $this->get('Errors'))) { | ||||
|             throw new GenericDataException(implode("\n", $errors), 500); | ||||
|         } | ||||
|  | ||||
|         $this->addToolbar(); | ||||
|  | ||||
|         // We do not need to filter by language when multilingual is disabled | ||||
|         if (!Multilanguage::isEnabled()) { | ||||
|             unset($this->activeFilters['language']); | ||||
|             $this->filterForm->removeField('language', 'filter'); | ||||
|         } | ||||
|  | ||||
|         parent::display($tpl); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Add the page title and toolbar. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function addToolbar(): void | ||||
|     { | ||||
|         $canDo   = ContentHelper::getActions('com_banners', 'category', $this->state->get('filter.category_id')); | ||||
|         $user    = $this->getCurrentUser(); | ||||
|         $toolbar = $this->getDocument()->getToolbar(); | ||||
|  | ||||
|         ToolbarHelper::title(Text::_('COM_BANNERS_MANAGER_BANNERS'), 'bookmark banners'); | ||||
|  | ||||
|         if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_banners', 'core.create')) > 0) { | ||||
|             $toolbar->addNew('banner.add'); | ||||
|         } | ||||
|  | ||||
|         if (!$this->isEmptyState && ($canDo->get('core.edit.state') || ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')))) { | ||||
|             /** @var  DropdownButton $dropdown */ | ||||
|             $dropdown = $toolbar->dropdownButton('status-group', 'JTOOLBAR_CHANGE_STATUS') | ||||
|                 ->toggleSplit(false) | ||||
|                 ->icon('icon-ellipsis-h') | ||||
|                 ->buttonClass('btn btn-action') | ||||
|                 ->listCheck(true); | ||||
|  | ||||
|             $childBar = $dropdown->getChildToolbar(); | ||||
|  | ||||
|             if ($canDo->get('core.edit.state')) { | ||||
|                 if ($this->state->get('filter.published') != 2) { | ||||
|                     $childBar->publish('banners.publish')->listCheck(true); | ||||
|  | ||||
|                     $childBar->unpublish('banners.unpublish')->listCheck(true); | ||||
|                 } | ||||
|  | ||||
|                 if ($this->state->get('filter.published') != -1) { | ||||
|                     if ($this->state->get('filter.published') != 2) { | ||||
|                         $childBar->archive('banners.archive')->listCheck(true); | ||||
|                     } elseif ($this->state->get('filter.published') == 2) { | ||||
|                         $childBar->publish('publish')->task('banners.publish')->listCheck(true); | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 $childBar->checkin('banners.checkin'); | ||||
|  | ||||
|                 if ($this->state->get('filter.published') != -2) { | ||||
|                     $childBar->trash('banners.trash')->listCheck(true); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) { | ||||
|                 $toolbar->delete('banners.delete', 'JTOOLBAR_DELETE_FROM_TRASH') | ||||
|                     ->message('JGLOBAL_CONFIRM_DELETE') | ||||
|                     ->listCheck(true); | ||||
|             } | ||||
|  | ||||
|             // Add a batch button | ||||
|             if ( | ||||
|                 $user->authorise('core.create', 'com_banners') | ||||
|                 && $user->authorise('core.edit', 'com_banners') | ||||
|                 && $user->authorise('core.edit.state', 'com_banners') | ||||
|             ) { | ||||
|                 $childBar->popupButton('batch', 'JTOOLBAR_BATCH') | ||||
|                     ->popupType('inline') | ||||
|                     ->textHeader(Text::_('COM_BANNERS_BATCH_OPTIONS')) | ||||
|                     ->url('#joomla-dialog-batch') | ||||
|                     ->modalWidth('800px') | ||||
|                     ->modalHeight('fit-content') | ||||
|                     ->listCheck(true); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if ($user->authorise('core.admin', 'com_banners') || $user->authorise('core.options', 'com_banners')) { | ||||
|             $toolbar->preferences('com_banners'); | ||||
|         } | ||||
|  | ||||
|         $toolbar->help('Banners'); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,158 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_banners | ||||
|  * | ||||
|  * @copyright   (C) 2008 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\View\Client; | ||||
|  | ||||
| use Joomla\CMS\Component\ComponentHelper; | ||||
| use Joomla\CMS\Factory; | ||||
| use Joomla\CMS\Form\Form; | ||||
| use Joomla\CMS\Helper\ContentHelper; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\MVC\View\GenericDataException; | ||||
| use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; | ||||
| use Joomla\CMS\Toolbar\Toolbar; | ||||
| use Joomla\CMS\Toolbar\ToolbarHelper; | ||||
| use Joomla\Component\Banners\Administrator\Model\ClientModel; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * View to edit a client. | ||||
|  * | ||||
|  * @since  1.5 | ||||
|  */ | ||||
| class HtmlView extends BaseHtmlView | ||||
| { | ||||
|     /** | ||||
|      * The Form object | ||||
|      * | ||||
|      * @var    Form | ||||
|      * @since  1.5 | ||||
|      */ | ||||
|     protected $form; | ||||
|  | ||||
|     /** | ||||
|      * The active item | ||||
|      * | ||||
|      * @var    \stdClass | ||||
|      * @since  1.5 | ||||
|      */ | ||||
|     protected $item; | ||||
|  | ||||
|     /** | ||||
|      * The model state | ||||
|      * | ||||
|      * @var    \Joomla\Registry\Registry | ||||
|      * @since  1.5 | ||||
|      */ | ||||
|     protected $state; | ||||
|  | ||||
|     /** | ||||
|      * Object containing permissions for the item | ||||
|      * | ||||
|      * @var    \Joomla\Registry\Registry | ||||
|      * @since  1.5 | ||||
|      */ | ||||
|     protected $canDo; | ||||
|  | ||||
|     /** | ||||
|      * Display the view | ||||
|      * | ||||
|      * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.5 | ||||
|      * | ||||
|      * @throws  \Exception | ||||
|      */ | ||||
|     public function display($tpl = null): void | ||||
|     { | ||||
|         /** @var ClientModel $model */ | ||||
|         $model       = $this->getModel(); | ||||
|         $this->form  = $model->getForm(); | ||||
|         $this->item  = $model->getItem(); | ||||
|         $this->state = $model->getState(); | ||||
|         $this->canDo = ContentHelper::getActions('com_banners'); | ||||
|  | ||||
|         // Check for errors. | ||||
|         if (\count($errors = $this->get('Errors'))) { | ||||
|             throw new GenericDataException(implode("\n", $errors), 500); | ||||
|         } | ||||
|  | ||||
|         $this->addToolbar(); | ||||
|  | ||||
|         parent::display($tpl); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Add the page title and toolbar. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      * | ||||
|      * @throws  \Exception | ||||
|      */ | ||||
|     protected function addToolbar(): void | ||||
|     { | ||||
|         Factory::getApplication()->getInput()->set('hidemainmenu', true); | ||||
|  | ||||
|         $user       = $this->getCurrentUser(); | ||||
|         $isNew      = ($this->item->id == 0); | ||||
|         $checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $user->id); | ||||
|         $canDo      = $this->canDo; | ||||
|         $toolbar    = $this->getDocument()->getToolbar(); | ||||
|  | ||||
|         ToolbarHelper::title( | ||||
|             $isNew ? Text::_('COM_BANNERS_MANAGER_CLIENT_NEW') : Text::_('COM_BANNERS_MANAGER_CLIENT_EDIT'), | ||||
|             'bookmark banners-clients' | ||||
|         ); | ||||
|  | ||||
|         // If not checked out, can save the item. | ||||
|         if (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.create'))) { | ||||
|             $toolbar->apply('client.apply'); | ||||
|         } | ||||
|  | ||||
|         $saveGroup = $toolbar->dropdownButton('save-group'); | ||||
|         $saveGroup->configure( | ||||
|             function (Toolbar $childBar) use ($checkedOut, $canDo, $isNew) { | ||||
|                 // If not checked out, can save the item. | ||||
|                 if (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.create'))) { | ||||
|                     $childBar->save('client.save'); | ||||
|                 } | ||||
|  | ||||
|                 if (!$checkedOut && $canDo->get('core.create')) { | ||||
|                     $childBar->save2new('client.save2new'); | ||||
|                 } | ||||
|  | ||||
|                 // If an existing item, can save to a copy. | ||||
|                 if (!$isNew && $canDo->get('core.create')) { | ||||
|                     $childBar->save2copy('client.save2copy'); | ||||
|                 } | ||||
|             } | ||||
|         ); | ||||
|  | ||||
|         if (empty($this->item->id)) { | ||||
|             $toolbar->cancel('client.cancel', 'JTOOLBAR_CANCEL'); | ||||
|         } else { | ||||
|             $toolbar->cancel('client.cancel'); | ||||
|  | ||||
|             if (ComponentHelper::isEnabled('com_contenthistory') && $this->state->params->get('save_history', 0) && $canDo->get('core.edit')) { | ||||
|                 $toolbar->versions('com_banners.client', $this->item->id); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         $toolbar->divider(); | ||||
|         $toolbar->help('Banners:_New_or_Edit_Client'); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,168 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_banners | ||||
|  * | ||||
|  * @copyright   (C) 2008 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\View\Clients; | ||||
|  | ||||
| use Joomla\CMS\Form\Form; | ||||
| use Joomla\CMS\Helper\ContentHelper; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\MVC\View\GenericDataException; | ||||
| use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; | ||||
| use Joomla\CMS\Pagination\Pagination; | ||||
| use Joomla\CMS\Toolbar\ToolbarHelper; | ||||
| use Joomla\Component\Banners\Administrator\Model\ClientsModel; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * View class for a list of clients. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class HtmlView extends BaseHtmlView | ||||
| { | ||||
|     /** | ||||
|      * The search tools form | ||||
|      * | ||||
|      * @var    Form | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     public $filterForm; | ||||
|  | ||||
|     /** | ||||
|      * The active search filters | ||||
|      * | ||||
|      * @var    array | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     public $activeFilters = []; | ||||
|  | ||||
|     /** | ||||
|      * An array of items | ||||
|      * | ||||
|      * @var    array | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $items = []; | ||||
|  | ||||
|     /** | ||||
|      * The pagination object | ||||
|      * | ||||
|      * @var    Pagination | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $pagination; | ||||
|  | ||||
|     /** | ||||
|      * The model state | ||||
|      * | ||||
|      * @var    \Joomla\Registry\Registry | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $state; | ||||
|  | ||||
|     /** | ||||
|      * Is this view an Empty State | ||||
|      * | ||||
|      * @var  boolean | ||||
|      * @since 4.0.0 | ||||
|      */ | ||||
|     private $isEmptyState = false; | ||||
|  | ||||
|     /** | ||||
|      * Display the view | ||||
|      * | ||||
|      * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      * | ||||
|      * @throws  \Exception | ||||
|      */ | ||||
|     public function display($tpl = null): void | ||||
|     { | ||||
|         /** @var ClientsModel $model */ | ||||
|         $model               = $this->getModel(); | ||||
|         $this->items         = $model->getItems(); | ||||
|         $this->pagination    = $model->getPagination(); | ||||
|         $this->state         = $model->getState(); | ||||
|         $this->filterForm    = $model->getFilterForm(); | ||||
|         $this->activeFilters = $model->getActiveFilters(); | ||||
|  | ||||
|         if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) { | ||||
|             $this->setLayout('emptystate'); | ||||
|         } | ||||
|  | ||||
|         // Check for errors. | ||||
|         if (\count($errors = $this->get('Errors'))) { | ||||
|             throw new GenericDataException(implode("\n", $errors), 500); | ||||
|         } | ||||
|  | ||||
|         $this->addToolbar(); | ||||
|  | ||||
|         parent::display($tpl); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Add the page title and toolbar. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function addToolbar(): void | ||||
|     { | ||||
|         $canDo   = ContentHelper::getActions('com_banners'); | ||||
|         $toolbar = $this->getDocument()->getToolbar(); | ||||
|  | ||||
|         ToolbarHelper::title(Text::_('COM_BANNERS_MANAGER_CLIENTS'), 'bookmark banners-clients'); | ||||
|  | ||||
|         if ($canDo->get('core.create')) { | ||||
|             $toolbar->addNew('client.add'); | ||||
|         } | ||||
|  | ||||
|         if (!$this->isEmptyState && ($canDo->get('core.edit.state') || $canDo->get('core.admin'))) { | ||||
|             $dropdown = $toolbar->dropdownButton('status-group', 'JTOOLBAR_CHANGE_STATUS') | ||||
|                 ->toggleSplit(false) | ||||
|                 ->icon('icon-ellipsis-h') | ||||
|                 ->buttonClass('btn btn-action') | ||||
|                 ->listCheck(true); | ||||
|  | ||||
|             $childBar = $dropdown->getChildToolbar(); | ||||
|  | ||||
|             $childBar->publish('clients.publish')->listCheck(true); | ||||
|             $childBar->unpublish('clients.unpublish')->listCheck(true); | ||||
|             $childBar->archive('clients.archive')->listCheck(true); | ||||
|  | ||||
|             if ($canDo->get('core.admin')) { | ||||
|                 $childBar->checkin('clients.checkin')->listCheck(true); | ||||
|             } | ||||
|  | ||||
|             if (!$this->state->get('filter.state') == -2) { | ||||
|                 $childBar->trash('clients.trash')->listCheck(true); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if (!$this->isEmptyState && $this->state->get('filter.state') == -2 && $canDo->get('core.delete')) { | ||||
|             $toolbar->delete('clients.delete', 'JTOOLBAR_DELETE_FROM_TRASH') | ||||
|                 ->message('JGLOBAL_CONFIRM_DELETE') | ||||
|                 ->listCheck(true); | ||||
|         } | ||||
|  | ||||
|         if ($canDo->get('core.admin') || $canDo->get('core.options')) { | ||||
|             $toolbar->preferences('com_banners'); | ||||
|         } | ||||
|  | ||||
|         $toolbar->help('Banners:_Clients'); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,61 @@ | ||||
| <?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\View\Download; | ||||
|  | ||||
| use Joomla\CMS\Form\Form; | ||||
| use Joomla\CMS\MVC\View\GenericDataException; | ||||
| use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; | ||||
| use Joomla\Component\Banners\Administrator\Model\DownloadModel; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * View class for download a list of tracks. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class HtmlView extends BaseHtmlView | ||||
| { | ||||
|     /** | ||||
|      * The Form object | ||||
|      * | ||||
|      * @var    Form | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $form; | ||||
|  | ||||
|     /** | ||||
|      * Display the view | ||||
|      * | ||||
|      * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      * | ||||
|      * @throws  \Exception | ||||
|      */ | ||||
|     public function display($tpl = null): void | ||||
|     { | ||||
|         /** @var DownloadModel $model */ | ||||
|         $model      = $this->getModel(); | ||||
|         $this->form = $model->getForm(); | ||||
|  | ||||
|         // Check for errors. | ||||
|         if (\count($errors = $this->get('Errors'))) { | ||||
|             throw new GenericDataException(implode("\n", $errors), 500); | ||||
|         } | ||||
|  | ||||
|         parent::display($tpl); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,156 @@ | ||||
| <?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\View\Tracks; | ||||
|  | ||||
| use Joomla\CMS\Form\Form; | ||||
| use Joomla\CMS\Helper\ContentHelper; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\MVC\View\GenericDataException; | ||||
| use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; | ||||
| use Joomla\CMS\Pagination\Pagination; | ||||
| use Joomla\CMS\Router\Route; | ||||
| use Joomla\CMS\Toolbar\ToolbarHelper; | ||||
| use Joomla\Component\Banners\Administrator\Model\TracksModel; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * View class for a list of tracks. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class HtmlView extends BaseHtmlView | ||||
| { | ||||
|     /** | ||||
|      * The search tools form | ||||
|      * | ||||
|      * @var    Form | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     public $filterForm; | ||||
|  | ||||
|     /** | ||||
|      * The active search filters | ||||
|      * | ||||
|      * @var    array | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     public $activeFilters = []; | ||||
|  | ||||
|     /** | ||||
|      * An array of items | ||||
|      * | ||||
|      * @var    array | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $items = []; | ||||
|  | ||||
|     /** | ||||
|      * The pagination object | ||||
|      * | ||||
|      * @var    Pagination | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $pagination; | ||||
|  | ||||
|     /** | ||||
|      * The model state | ||||
|      * | ||||
|      * @var    \Joomla\Registry\Registry | ||||
|      * @since  1.6 | ||||
|      */ | ||||
|     protected $state; | ||||
|  | ||||
|     /** | ||||
|      * Is this view an Empty State | ||||
|      * | ||||
|      * @var  boolean | ||||
|      * @since 4.0.0 | ||||
|      */ | ||||
|     private $isEmptyState = false; | ||||
|  | ||||
|     /** | ||||
|      * Display the view | ||||
|      * | ||||
|      * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      * @throws  \Exception | ||||
|      */ | ||||
|     public function display($tpl = null): void | ||||
|     { | ||||
|         /** @var TracksModel $model */ | ||||
|         $model               = $this->getModel(); | ||||
|         $this->items         = $model->getItems(); | ||||
|         $this->pagination    = $model->getPagination(); | ||||
|         $this->state         = $model->getState(); | ||||
|         $this->filterForm    = $model->getFilterForm(); | ||||
|         $this->activeFilters = $model->getActiveFilters(); | ||||
|  | ||||
|         if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) { | ||||
|             $this->setLayout('emptystate'); | ||||
|         } | ||||
|  | ||||
|         // Check for errors. | ||||
|         if (\count($errors = $this->get('Errors'))) { | ||||
|             throw new GenericDataException(implode("\n", $errors), 500); | ||||
|         } | ||||
|  | ||||
|         $this->addToolbar(); | ||||
|  | ||||
|         parent::display($tpl); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Add the page title and toolbar. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     protected function addToolbar(): void | ||||
|     { | ||||
|         $canDo   = ContentHelper::getActions('com_banners', 'category', $this->state->get('filter.category_id')); | ||||
|         $toolbar = $this->getDocument()->getToolbar(); | ||||
|  | ||||
|         ToolbarHelper::title(Text::_('COM_BANNERS_MANAGER_TRACKS'), 'bookmark banners-tracks'); | ||||
|  | ||||
|         if (!$this->isEmptyState) { | ||||
|             $toolbar->popupButton() | ||||
|                 ->url(Route::_('index.php?option=com_banners&view=download&tmpl=component')) | ||||
|                 ->text('JTOOLBAR_EXPORT') | ||||
|                 ->selector('downloadModal') | ||||
|                 ->icon('icon-download') | ||||
|                 ->footer('<button class="btn btn-secondary" data-bs-dismiss="modal" type="button"' | ||||
|                     . ' onclick="window.parent.Joomla.Modal.getCurrent().close();">' | ||||
|                     . Text::_('COM_BANNERS_CANCEL') . '</button>' | ||||
|                     . '<button class="btn btn-success" type="button"' | ||||
|                     . ' onclick="Joomla.iframeButtonClick({iframeSelector: \'#downloadModal\', buttonSelector: \'#exportBtn\'})">' | ||||
|                     . Text::_('COM_BANNERS_TRACKS_EXPORT') . '</button>'); | ||||
|         } | ||||
|  | ||||
|         if (!$this->isEmptyState && $canDo->get('core.delete')) { | ||||
|             $toolbar->delete('tracks.delete', 'COM_BANNERS_TRACKS_DELETE') | ||||
|                 ->message('COM_BANNERS_DELETE_MSG') | ||||
|                 ->listCheck(false); | ||||
|         } | ||||
|  | ||||
|         if ($canDo->get('core.admin') || $canDo->get('core.options')) { | ||||
|             $toolbar->preferences('com_banners'); | ||||
|         } | ||||
|  | ||||
|         $toolbar->help('Banners:_Tracks'); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,66 @@ | ||||
| <?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\View\Tracks; | ||||
|  | ||||
| use Joomla\CMS\Application\CMSApplication; | ||||
| use Joomla\CMS\Factory; | ||||
| use Joomla\CMS\MVC\View\GenericDataException; | ||||
| use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; | ||||
| use Joomla\Component\Banners\Administrator\Model\TracksModel; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * View class for a list of tracks. | ||||
|  * | ||||
|  * @since  1.6 | ||||
|  */ | ||||
| class RawView extends BaseHtmlView | ||||
| { | ||||
|     /** | ||||
|      * Display the view | ||||
|      * | ||||
|      * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      * | ||||
|      * @throws  \Exception | ||||
|      */ | ||||
|     public function display($tpl = null): void | ||||
|     { | ||||
|         /** @var TracksModel $model */ | ||||
|         $model    = $this->getModel(); | ||||
|         $basename = $model->getBaseName(); | ||||
|         $fileType = $model->getFileType(); | ||||
|         $mimeType = $model->getMimeType(); | ||||
|         $content  = $model->getContent(); | ||||
|  | ||||
|         // Check for errors. | ||||
|         if (\count($errors = $this->get('Errors'))) { | ||||
|             throw new GenericDataException(implode("\n", $errors), 500); | ||||
|         } | ||||
|  | ||||
|         $this->getDocument()->setMimeEncoding($mimeType); | ||||
|  | ||||
|         /** @var CMSApplication $app */ | ||||
|         $app = Factory::getApplication(); | ||||
|         $app->setHeader( | ||||
|             'Content-disposition', | ||||
|             'attachment; filename="' . $basename . '.' . $fileType . '"; creation-date="' . Factory::getDate()->toRFC822() . '"', | ||||
|             true | ||||
|         ); | ||||
|         echo $content; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user