/**
* Module list
*
* @return array
*/
public static function getModuleList()
{
$app = Factory::getApplication();
$itemId = $app->input->getInt('Itemid', 0);
$groups = $app->getIdentity()->getAuthorisedViewLevels();
$clientId = (int) $app->getClientId();
// Build a cache ID for the resulting data object
$cacheId = implode(',', $groups) . '.' . $clientId . '.' . $itemId;
$db = Factory::getDbo();
$query = $db->getQuery(true);
$nowDate = Factory::getDate()->toSql();
$query->select($db->quoteName(['m.id', 'm.title', 'm.module', 'm.position', 'm.content', 'm.showtitle', 'm.params', 'mm.menuid']))->from($db->quoteName('#__modules', 'm'))->join('LEFT', $db->quoteName('#__modules_menu', 'mm'), $db->quoteName('mm.moduleid') . ' = ' . $db->quoteName('m.id'))->join('LEFT', $db->quoteName('#__extensions', 'e'), $db->quoteName('e.element') . ' = ' . $db->quoteName('m.module') . ' AND ' . $db->quoteName('e.client_id') . ' = ' . $db->quoteName('m.client_id'))->where([$db->quoteName('m.published') . ' = 1', $db->quoteName('e.enabled') . ' = 1', $db->quoteName('m.client_id') . ' = :clientId'])->bind(':clientId', $clientId, ParameterType::INTEGER)->whereIn($db->quoteName('m.access'), $groups)->extendWhere('AND', [$db->quoteName('m.publish_up') . ' IS NULL', $db->quoteName('m.publish_up') . ' <= :publishUp'], 'OR')->bind(':publishUp', $nowDate)->extendWhere('AND', [$db->quoteName('m.publish_down') . ' IS NULL', $db->quoteName('m.publish_down') . ' >= :publishDown'], 'OR')->bind(':publishDown', $nowDate)->extendWhere('AND', [$db->quoteName('mm.menuid') . ' = :itemId', $db->quoteName('mm.menuid') . ' <= 0'], 'OR')->bind(':itemId', $itemId, ParameterType::INTEGER);
// Filter by language
if ($app->isClient('site') && $app->getLanguageFilter() || $app->isClient('administrator') && static::isAdminMultilang()) {
$language = $app->getLanguage()->getTag();
$query->whereIn($db->quoteName('m.language'), [$language, '*'], ParameterType::STRING);
$cacheId .= $language . '*';
}
$query->order($db->quoteName(['m.position', 'm.ordering']));
// Set the query
$db->setQuery($query);
try {
/** @var CallbackController $cache */
$cache = Factory::getContainer()->get(CacheControllerFactoryInterface::class)->createCacheController('callback', ['defaultgroup' => 'com_modules']);
$modules = $cache->get(array($db, 'loadObjectList'), array(), md5($cacheId), false);
} catch (\RuntimeException $e) {
$app->getLogger()->warning(Text::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $e->getMessage()), array('category' => 'jerror'));
return array();
}
return $modules;
}