// Normalize
This commit is contained in:
+17
-17
@@ -63,15 +63,15 @@ class CMSCore extends ObjectModel
|
||||
'objectsNodeName' => 'content_management_system',
|
||||
);
|
||||
|
||||
public function add($autodate = true, $nullValues = false)
|
||||
public function add($autodate = true, $null_values = false)
|
||||
{
|
||||
$this->position = CMS::getLastPosition((int)$this->id_cms_category);
|
||||
return parent::add($autodate, true);
|
||||
}
|
||||
|
||||
public function update($nullValues = false)
|
||||
public function update($null_values = false)
|
||||
{
|
||||
if (parent::update($nullValues))
|
||||
if (parent::update($null_values))
|
||||
return $this->cleanPositions($this->id_cms_category);
|
||||
return false;
|
||||
}
|
||||
@@ -90,7 +90,7 @@ class CMSCore extends ObjectModel
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT c.id_cms, cl.link_rewrite, cl.meta_title
|
||||
FROM '._DB_PREFIX_.'cms c
|
||||
LEFT JOIN '._DB_PREFIX_.'cms_lang cl ON (c.id_cms = cl.id_cms AND cl.id_lang = '.(int)($id_lang).')
|
||||
LEFT JOIN '._DB_PREFIX_.'cms_lang cl ON (c.id_cms = cl.id_cms AND cl.id_lang = '.(int)$id_lang.')
|
||||
'.Context::getContext()->shop->addSqlAssociation('cms', 'c').'
|
||||
WHERE 1
|
||||
'.(($selection !== null) ? ' AND c.id_cms IN ('.implode(',', array_map('intval', $selection)).')' : '').
|
||||
@@ -102,7 +102,7 @@ class CMSCore extends ObjectModel
|
||||
if ($result)
|
||||
foreach ($result as $row)
|
||||
{
|
||||
$row['link'] = $link->getCMSLink((int)($row['id_cms']), $row['link_rewrite']);
|
||||
$row['link'] = $link->getCMSLink((int)$row['id_cms'], $row['link_rewrite']);
|
||||
$links[] = $row;
|
||||
}
|
||||
return $links;
|
||||
@@ -119,7 +119,7 @@ class CMSCore extends ObjectModel
|
||||
JOIN '._DB_PREFIX_.'cms_lang l ON (c.id_cms = l.id_cms)
|
||||
'.Context::getContext()->shop->addSqlAssociation('cms', 'c').'
|
||||
'.(($id_block) ? 'JOIN '._DB_PREFIX_.'block_cms b ON (c.id_cms = b.id_cms)' : '').'
|
||||
WHERE l.id_lang = '.(int)($id_lang).(($id_block) ? ' AND b.id_block = '.(int)($id_block) : '').($active ? ' AND c.`active` = 1 ' : '').'
|
||||
WHERE l.id_lang = '.(int)$id_lang.(($id_block) ? ' AND b.id_block = '.(int)$id_block : '').($active ? ' AND c.`active` = 1 ' : '').'
|
||||
GROUP BY c.id_cms
|
||||
ORDER BY c.`position`');
|
||||
}
|
||||
@@ -135,10 +135,10 @@ class CMSCore extends ObjectModel
|
||||
return false;
|
||||
|
||||
foreach ($res as $cms)
|
||||
if ((int)($cms['id_cms']) == (int)($this->id))
|
||||
$movedCms = $cms;
|
||||
if ((int)$cms['id_cms'] == (int)$this->id)
|
||||
$moved_cms = $cms;
|
||||
|
||||
if (!isset($movedCms) || !isset($position))
|
||||
if (!isset($moved_cms) || !isset($position))
|
||||
return false;
|
||||
|
||||
// < and > statements rather than BETWEEN operator
|
||||
@@ -148,14 +148,14 @@ class CMSCore extends ObjectModel
|
||||
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
|
||||
WHERE `position`
|
||||
'.($way
|
||||
? '> '.(int)($movedCms['position']).' AND `position` <= '.(int)($position)
|
||||
: '< '.(int)($movedCms['position']).' AND `position` >= '.(int)($position)).'
|
||||
AND `id_cms_category`='.(int)($movedCms['id_cms_category']))
|
||||
? '> '.(int)$moved_cms['position'].' AND `position` <= '.(int)$position
|
||||
: '< '.(int)$moved_cms['position'].' AND `position` >= '.(int)$position).'
|
||||
AND `id_cms_category`='.(int)$moved_cms['id_cms_category'])
|
||||
&& Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'cms`
|
||||
SET `position` = '.(int)($position).'
|
||||
WHERE `id_cms` = '.(int)($movedCms['id_cms']).'
|
||||
AND `id_cms_category`='.(int)($movedCms['id_cms_category'])));
|
||||
SET `position` = '.(int)$position.'
|
||||
WHERE `id_cms` = '.(int)$moved_cms['id_cms'].'
|
||||
AND `id_cms_category`='.(int)$moved_cms['id_cms_category']));
|
||||
}
|
||||
|
||||
public static function cleanPositions($id_category)
|
||||
@@ -163,7 +163,7 @@ class CMSCore extends ObjectModel
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT `id_cms`
|
||||
FROM `'._DB_PREFIX_.'cms`
|
||||
WHERE `id_cms_category` = '.(int)($id_category).'
|
||||
WHERE `id_cms_category` = '.(int)$id_category.'
|
||||
ORDER BY `position`');
|
||||
for ($i = 0, $total = count($result); $i < $total; ++$i)
|
||||
{
|
||||
@@ -178,7 +178,7 @@ class CMSCore extends ObjectModel
|
||||
|
||||
public static function getLastPosition($id_category)
|
||||
{
|
||||
return (Db::getInstance()->getValue('SELECT MAX(position)+1 FROM `'._DB_PREFIX_.'cms` WHERE `id_cms_category` = '.(int)($id_category)));
|
||||
return (Db::getInstance()->getValue('SELECT MAX(position)+1 FROM `'._DB_PREFIX_.'cms` WHERE `id_cms_category` = '.(int)$id_category));
|
||||
}
|
||||
|
||||
public static function getCMSPages($id_lang = null, $id_cms_category = null, $active = true)
|
||||
|
||||
Reference in New Issue
Block a user