// removing group_module_restriction table to set every restrictions in an only table : module_group
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10936 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+20
-13
@@ -236,7 +236,7 @@ class GroupCore extends ObjectModel
|
||||
public static function truncateModulesRestrictions($id_group)
|
||||
{
|
||||
return Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'group_module_restriction`
|
||||
DELETE FROM `'._DB_PREFIX_.'module_group`
|
||||
WHERE `id_group` = '.(int)$id_group);
|
||||
}
|
||||
|
||||
@@ -248,27 +248,32 @@ class GroupCore extends ObjectModel
|
||||
public static function truncateRestrictionsByModule($id_module)
|
||||
{
|
||||
return Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'group_module_restriction`
|
||||
DELETE FROM `'._DB_PREFIX_.'module_group`
|
||||
WHERE `id_module` = '.(int)$id_module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adding restrictions modules to the group with id $id_group
|
||||
* @param integer id_group
|
||||
* @param array modules
|
||||
* @param integer authorized
|
||||
* @param $id_group
|
||||
* @param $modules
|
||||
* @param array $shops
|
||||
* @return bool
|
||||
* @internal param \id_group $integer
|
||||
* @internal param \modules $array
|
||||
* @internal param \authorized $integer
|
||||
*/
|
||||
public static function addModulesRestrictions($id_group, $modules, $authorized)
|
||||
public static function addModulesRestrictions($id_group, $modules, $shops = array(1))
|
||||
{
|
||||
if (!is_array($modules) AND !empty($modules))
|
||||
if (!is_array($modules) && !empty($modules))
|
||||
return false;
|
||||
else
|
||||
{
|
||||
//delete all record for this group
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'group_module_restriction` WHERE `id_group` = '.(int)$id_group.' AND `authorized` = '.(int)$authorized);
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'group_module_restriction` (`id_group`, `id_module`, `authorized`) VALUES ';
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'module_group` WHERE `id_group` = '.(int)$id_group);
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'module_group` (`id_module`, `id_shop`, `id_group`) VALUES ';
|
||||
foreach ($modules as $mod)
|
||||
$sql .= '("'.(int)$id_group.'", "'.(int)$mod.'", "'.(int)$authorized.'"),';
|
||||
foreach ($shops as $s)
|
||||
$sql .= '("'.(int)$mod.'", "'.(int)$s.'", "'.(int)$id_group.'"),';
|
||||
// removing last comma to avoid SQL error
|
||||
$sql = substr($sql, 0, strlen($sql) - 1);
|
||||
Db::getInstance()->execute($sql);
|
||||
@@ -279,13 +284,15 @@ class GroupCore extends ObjectModel
|
||||
* Add restrictions for a new module
|
||||
* We authorize every groups to the new module
|
||||
* @param integer id_module
|
||||
* @param array $shops
|
||||
*/
|
||||
public static function addRestrictionsForModule($id_module)
|
||||
public static function addRestrictionsForModule($id_module, $shops = array(1))
|
||||
{
|
||||
$groups = Group::getGroups(Context::getContext()->language->id);
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'group_module_restriction` (`id_group`, `id_module`, `authorized`) VALUES ';
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'module_group` (`id_module`, `id_shop`, `id_group`) VALUES ';
|
||||
foreach ($groups as $g)
|
||||
$sql .= '("'.(int)$g['id_group'].'", "'.(int)$id_module.'", "1"),';
|
||||
foreach ($shops as $s)
|
||||
$sql .= '("'.(int)$id_module.'", "'.(int)$s.'", "'.(int)$g['id_group'].'"),';
|
||||
// removing last comma to avoid SQL error
|
||||
$sql = substr($sql, 0, strlen($sql) - 1);
|
||||
Db::getInstance()->execute($sql);
|
||||
|
||||
+3
-3
@@ -207,8 +207,8 @@ class HookCore extends ObjectModel
|
||||
ON hm.`id_module` = m.`id_module`';
|
||||
if (isset($context->customer) && $context->customer->isLogged())
|
||||
$sql .= '
|
||||
LEFT JOIN `'._DB_PREFIX_.'group_module_restriction` gmr
|
||||
ON gmr.`id_module` = m.`id_module`';
|
||||
LEFT JOIN `'._DB_PREFIX_.'module_group` mg
|
||||
ON mg.`id_module` = m.`id_module`';
|
||||
$sql .= '
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook` h
|
||||
ON hm.`id_hook` = h.`id_hook`
|
||||
@@ -216,7 +216,7 @@ class HookCore extends ObjectModel
|
||||
AND hm.id_shop IN('.implode(', ', $list).')';
|
||||
if (isset($context->customer) && $context->customer->isLogged())
|
||||
$sql .= '
|
||||
AND (gmr.`authorized` = 1 AND gmr.`id_group` IN('.implode(', ', $groups).'))';
|
||||
AND (mg.`id_group` IN('.implode(', ', $groups).'))';
|
||||
$sql .= '
|
||||
GROUP BY hm.id_hook, hm.id_module
|
||||
ORDER BY hm.`position`';
|
||||
|
||||
+7
-16
@@ -187,7 +187,7 @@ abstract class ModuleCore
|
||||
AND a.`view` = 0
|
||||
)');
|
||||
// Adding Restrictions for client groups
|
||||
Group::addRestrictionsForModule($this->id);
|
||||
Group::addRestrictionsForModule($this->id, Shop::getShops(true, null, true));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -918,21 +918,14 @@ abstract class ModuleCore
|
||||
INNER JOIN `'._DB_PREFIX_.'module_group` mg ON (m.`id_module` = mg.`id_module`)
|
||||
INNER JOIN `'._DB_PREFIX_.'customer_group` cg on (cg.`id_group` = mg.`id_group` AND cg.`id_customer` = '.(int)$context->customer->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`';
|
||||
if (isset($context->customer))
|
||||
$sql .= '
|
||||
LEFT JOIN `'._DB_PREFIX_.'group_module_restriction` gmr ON gmr.`id_module` = m.`id_module`';
|
||||
$sql .= '
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
|
||||
WHERE h.`name` = \''.pSQL($hookPayment).'\'
|
||||
AND mc.id_country = '.(int)($billing->id_country).'
|
||||
AND mc.id_shop = '.(int)$context->shop->getID(true).'
|
||||
AND mg.id_shop = '.(int)$context->shop->getID(true).'
|
||||
AND (SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $list).')) = '.count($list).'
|
||||
AND hm.id_shop IN('.implode(', ', $list).')';
|
||||
if (isset($context->customer))
|
||||
$sql .= '
|
||||
AND (gmr.`authorized` = 1 AND gmr.`id_group` IN('.implode(', ', $groups).'))';
|
||||
$sql .= '
|
||||
AND hm.id_shop IN('.implode(', ', $list).')
|
||||
AND (mg.`id_group` IN('.implode(', ', $groups).'))
|
||||
GROUP BY hm.id_hook, hm.id_module
|
||||
ORDER BY hm.`position`, m.`name` DESC';
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
@@ -1311,11 +1304,9 @@ abstract class ModuleCore
|
||||
public static function getAuthorizedModules($group_id)
|
||||
{
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT m.id_module, m.name FROM `'._DB_PREFIX_.'group_module_restriction` gmr
|
||||
LEFT JOIN `'._DB_PREFIX_.'module` m ON (m.`id_module` = gmr.`id_module`)
|
||||
WHERE gmr.`id_group` = '.(int) $group_id.'
|
||||
AND gmr.`authorized` = 1
|
||||
');
|
||||
SELECT m.id_module, m.name FROM `'._DB_PREFIX_.'module_group` mg
|
||||
LEFT JOIN `'._DB_PREFIX_.'module` m ON (m.`id_module` = mg.`id_module`)
|
||||
WHERE mg.`id_group` = '.(int) $group_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user