primo commit
This commit is contained in:
50
modules/mod_banners/src/Dispatcher/Dispatcher.php
Normal file
50
modules/mod_banners/src/Dispatcher/Dispatcher.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_banners
|
||||
*
|
||||
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Module\Banners\Site\Dispatcher;
|
||||
|
||||
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
|
||||
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
|
||||
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
|
||||
use Joomla\Component\Banners\Administrator\Helper\BannersHelper as BannersComponentHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Dispatcher class for mod_banners
|
||||
*
|
||||
* @since 5.1.0
|
||||
*/
|
||||
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
|
||||
{
|
||||
use HelperFactoryAwareTrait;
|
||||
|
||||
/**
|
||||
* Returns the layout data.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 5.1.0
|
||||
*/
|
||||
protected function getLayoutData(): array
|
||||
{
|
||||
BannersComponentHelper::updateReset();
|
||||
|
||||
$data = parent::getLayoutData();
|
||||
|
||||
$data['headerText'] = trim($data['params']->get('header_text', ''));
|
||||
$data['footerText'] = trim($data['params']->get('footer_text', ''));
|
||||
$data['list'] = $this->getHelperFactory()->getHelper('BannersHelper')->getBanners($data['params'], $this->getApplication());
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
89
modules/mod_banners/src/Helper/BannersHelper.php
Normal file
89
modules/mod_banners/src/Helper/BannersHelper.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_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\Module\Banners\Site\Helper;
|
||||
|
||||
use Joomla\CMS\Application\CMSApplication;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Environment\Browser;
|
||||
use Joomla\Component\Banners\Site\Model\BannersModel;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Helper for mod_banners
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class BannersHelper
|
||||
{
|
||||
/**
|
||||
* Retrieve list of banners
|
||||
*
|
||||
* @param Registry $params The module parameters
|
||||
* @param CMSApplication $app The application
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 5.1.0
|
||||
*/
|
||||
public function getBanners(Registry $params, CMSApplication $app)
|
||||
{
|
||||
/** @var BannersModel $model */
|
||||
$model = $app->bootComponent('com_banners')->getMVCFactory()->createModel('Banners', 'Site', ['ignore_request' => true]);
|
||||
|
||||
$keywords = explode(',', $app->getDocument()->getMetaData('keywords'));
|
||||
$config = ComponentHelper::getParams('com_banners');
|
||||
|
||||
$model->setState('filter.client_id', (int) $params->get('cid'));
|
||||
$model->setState('filter.category_id', $params->get('catid', []));
|
||||
$model->setState('list.limit', (int) $params->get('count', 1));
|
||||
$model->setState('list.start', 0);
|
||||
$model->setState('filter.ordering', $params->get('ordering'));
|
||||
$model->setState('filter.tag_search', $params->get('tag_search'));
|
||||
$model->setState('filter.keywords', $keywords);
|
||||
$model->setState('filter.language', $app->getLanguageFilter());
|
||||
|
||||
$banners = $model->getItems();
|
||||
|
||||
if ($banners) {
|
||||
if ($config->get('track_robots_impressions', 1) == 1 || !Browser::getInstance()->isRobot()) {
|
||||
$model->impress();
|
||||
}
|
||||
}
|
||||
|
||||
return $banners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve list of banners
|
||||
*
|
||||
* @param Registry $params The module parameters
|
||||
* @param BannersModel $model The model
|
||||
* @param CMSApplication $app The application
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.5
|
||||
*
|
||||
* @deprecated 5.1.0 will be removed in 7.0
|
||||
* Use the non-static method getBanners
|
||||
* Example: Factory::getApplication()->bootModule('mod_banners', 'site')
|
||||
* ->getHelper('BannersHelper')
|
||||
* ->getBanners($params, Factory::getApplication())
|
||||
*/
|
||||
public static function getList(Registry $params, BannersModel $model, CMSApplication $app)
|
||||
{
|
||||
return (new self())->getBanners($params, $app);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user