primo commit
This commit is contained in:
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_articles_categories
|
||||
*
|
||||
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Module\ArticlesCategories\Site\Dispatcher;
|
||||
|
||||
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
|
||||
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
|
||||
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
|
||||
use Joomla\CMS\Helper\ModuleHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Dispatcher class for mod_articles_categories
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
|
||||
{
|
||||
use HelperFactoryAwareTrait;
|
||||
|
||||
/**
|
||||
* Returns the layout data.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
protected function getLayoutData(): array
|
||||
{
|
||||
$data = parent::getLayoutData();
|
||||
$params = $data['params'];
|
||||
|
||||
$cacheParams = new \stdClass();
|
||||
$cacheParams->cachemode = 'id';
|
||||
$cacheParams->class = $this->getHelperFactory()->getHelper('ArticlesCategoriesHelper');
|
||||
$cacheParams->method = 'getChildrenCategories';
|
||||
$cacheParams->methodparams = [$params, $data['app']];
|
||||
$cacheParams->modeparams = md5(serialize($this->module->id));
|
||||
|
||||
$data['list'] = ModuleHelper::moduleCache($this->module, $params, $cacheParams);
|
||||
|
||||
$data['startLevel'] = $data['list'] ? reset($data['list'])->getParent()->level : null;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_articles_categories
|
||||
*
|
||||
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Module\ArticlesCategories\Site\Helper;
|
||||
|
||||
use Joomla\CMS\Application\SiteApplication;
|
||||
use Joomla\CMS\Categories\CategoryInterface;
|
||||
use Joomla\CMS\Categories\CategoryNode;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\Database\DatabaseAwareInterface;
|
||||
use Joomla\Database\DatabaseAwareTrait;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Helper for mod_articles_categories
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class ArticlesCategoriesHelper implements DatabaseAwareInterface
|
||||
{
|
||||
use DatabaseAwareTrait;
|
||||
|
||||
/**
|
||||
* Given a parent category, return a list of children categories
|
||||
*
|
||||
* @param Registry $moduleParams The module parameters.
|
||||
* @param SiteApplication $app The current application.
|
||||
*
|
||||
* @return CategoryNode[]
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
public function getChildrenCategories(Registry $moduleParams, SiteApplication $app): array
|
||||
{
|
||||
// Joomla\CMS\Categories\Categories options to set
|
||||
$options = [];
|
||||
|
||||
// Get the number of items in this category or descendants of this category at the expense of performance.
|
||||
$options['countItems'] = $moduleParams->get('numitems', 0);
|
||||
|
||||
/** @var CategoryInterface $categoryFactory */
|
||||
$categoryFactory = $app->bootComponent('com_content')->getCategory($options);
|
||||
|
||||
/** @var CategoryNode $parentCategory */
|
||||
$parentCategory = $categoryFactory->get($moduleParams->get('parent', 'root'));
|
||||
|
||||
if ($parentCategory === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Get all the children categories of this node
|
||||
$childrenCategories = $parentCategory->getChildren();
|
||||
|
||||
$count = $moduleParams->get('count', 0);
|
||||
|
||||
if ($count > 0 && \count($childrenCategories) > $count) {
|
||||
$childrenCategories = \array_slice($childrenCategories, 0, $count);
|
||||
}
|
||||
|
||||
return $childrenCategories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of categories
|
||||
*
|
||||
* @param Registry $params module parameters
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.6
|
||||
*
|
||||
* @deprecated 4.4.0 will be removed in 6.0
|
||||
* Use the non-static method getChildrenCategories
|
||||
* Example: Factory::getApplication()->bootModule('mod_articles_categories', 'site')
|
||||
* ->getHelper('ArticlesCategoriesHelper')
|
||||
* ->getChildrenCategories($params, Factory::getApplication())
|
||||
*/
|
||||
public static function getList($params)
|
||||
{
|
||||
/** @var SiteApplication $app */
|
||||
$app = Factory::getApplication();
|
||||
|
||||
return (new self())->getChildrenCategories($params, $app);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user