- md5
- 0bc97f195616a5c3ed27a2cd88556273
- sha1
- 1a8f47c2e67cbd7ae01f66cce96e979f662e9f5f
- sha256
- 227f1ec119ec1960d63a46e42f814c89a651c2b15e48e134baabe6f67d89339d
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
<?php
/**
* @package Joomla.Administrator
* @subpackage mod_multilangstatus
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Module\Multilangstatus\Administrator\Helper;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Multilanguage;
/**
* Helper class for the multilangstatus module
*
* @since 4.0.0
*/
class MultilangstatusAdminHelper
{
/**
* Method to check if the module exists and is enabled as extension
*
* @return boolean
*
* @since 4.0.0
*/
public static function isEnabled()
{
$app = Factory::getApplication();
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('enabled'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('module'))
->where($db->quoteName('element') . ' = ' . $db->quote('mod_multilangstatus'));
$db->setQuery($query);
try
{
$result = (int) $db->loadResult();
}
catch (\RuntimeException $e)
{
$app->enqueueMessage($e->getMessage(), 'error');
}
return $result;
}
/**
* Method to check the state of the module
*
* @return void
*
* @since 4.0.0
*/
public static function getState()
{
$app = Factory::getApplication();
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('published'))
->from($db->quoteName('#__modules'))
->where($db->quoteName('module') . ' = ' . $db->quote('mod_multilangstatus'));
$db->setQuery($query);
try
{
$result = (int) $db->loadResult();
}
catch (\RuntimeException $e)
{
$app->enqueueMessage($e->getMessage(), 'error');
}
return $result;
}
/**
* Method to publish/unpublish the module depending on the languagefilter state
*
* @return void
*
* @since 4.0.0
*/
public static function publish()
{
$app = Factory::getApplication();
$db = Factory::getDbo();
// If the module is trashed do not change its status
if (self::getState() != -2)
{
// Publish the module when the languagefilter is enabled
if (Multilanguage::isEnabled())
{
$query = $db->getQuery(true)
->update($db->quoteName('#__modules'))
->set($db->quoteName('published') . ' = ' . (int) 1)
->where($db->quoteName('module') . ' = ' . $db->quote('mod_multilangstatus'));
try
{
$db->setQuery($query)->execute();
}
catch (\RuntimeException $e)
{
$app->enqueueMessage($e->getMessage(), 'error');
return;
}
}
else
{
// Unpublish the module when the languagefilter is disabled
$query = $db->getQuery(true)
->update($db->quoteName('#__modules'))
->set($db->quoteName('published') . ' = ' . (int) 0)
->where($db->quoteName('module') . ' = ' . $db->quote('mod_multilangstatus'));
try
{
$db->setQuery($query)->execute();
}
catch (Exception $e)
{
$app->enqueueMessage($e->getMessage(), 'error');
return;
}
}
}
}
}
The same content is in 3 releases, Joomla 4.0.0-alpha7 to 4.0.0-alpha9. See them all, or every version of this file.