[*] Classes: CMS::getCMSPages() now select only data from cms table if id_lang is null

[*] Classes: Db::autoExecute() can now take INSERT IGNORE as third argument
[*] Classes: Tag::addTags() can now take an array of tags as argument (instead of strings separated by comas)

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10033 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-11-10 13:45:41 +00:00
parent c1213e34bc
commit 3e268db6f9
3 changed files with 26 additions and 21 deletions
+14 -11
View File
@@ -127,9 +127,9 @@ class CMSCore extends ObjectModel
public function updatePosition($way, $position) public function updatePosition($way, $position)
{ {
if (!$res = Db::getInstance()->executeS(' if (!$res = Db::getInstance()->executeS('
SELECT cp.`id_cms`, cp.`position`, cp.`id_cms_category` SELECT cp.`id_cms`, cp.`position`, cp.`id_cms_category`
FROM `'._DB_PREFIX_.'cms` cp FROM `'._DB_PREFIX_.'cms` cp
WHERE cp.`id_cms_category` = '.(int)$this->id_cms_category.' WHERE cp.`id_cms_category` = '.(int)$this->id_cms_category.'
ORDER BY cp.`position` ASC' ORDER BY cp.`position` ASC'
)) ))
return false; return false;
@@ -146,7 +146,7 @@ class CMSCore extends ObjectModel
return (Db::getInstance()->execute(' return (Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'cms` UPDATE `'._DB_PREFIX_.'cms`
SET `position`= `position` '.($way ? '- 1' : '+ 1').' SET `position`= `position` '.($way ? '- 1' : '+ 1').'
WHERE `position` WHERE `position`
'.($way '.($way
? '> '.(int)($movedCms['position']).' AND `position` <= '.(int)($position) ? '> '.(int)($movedCms['position']).' AND `position` <= '.(int)($position)
: '< '.(int)($movedCms['position']).' AND `position` >= '.(int)($position)).' : '< '.(int)($movedCms['position']).' AND `position` >= '.(int)($position)).'
@@ -183,14 +183,17 @@ class CMSCore extends ObjectModel
public static function getCMSPages($id_lang = null, $id_cms_category = null, $active = true) public static function getCMSPages($id_lang = null, $id_cms_category = null, $active = true)
{ {
return Db::getInstance()->executeS(' $sql = new DbQuery();
SELECT * $sql->select('*');
FROM `'._DB_PREFIX_.'cms` c $sql->from('cms c');
JOIN `'._DB_PREFIX_.'cms_lang` l ON (c.id_cms = l.id_cms)'. if ($id_lang)
(isset($id_cms_category) ? 'WHERE `id_cms_category` = '.(int)($id_cms_category) : ''). $sql->innerJoin('cms_lang l ON c.id_cms = l.id_cms AND l.id_lang = '.(int)$id_lang);
($active ? ' AND c.`active` = 1 ' : '').'
AND l.id_lang = '.(int)($id_lang).' if ($active)
ORDER BY `position`'); $sql->where('c.active = 1');
$sql->orderBy('position');
return Db::getInstance()->executeS($sql);
} }
public static function getUrlRewriteInformations($id_cms) public static function getUrlRewriteInformations($id_cms)
+7 -6
View File
@@ -87,18 +87,19 @@ class TagCore extends ObjectModel
* *
* @param integer $id_lang Language id * @param integer $id_lang Language id
* @param integer $id_product Product id to link tags with * @param integer $id_product Product id to link tags with
* @param string $string Tags separated by commas * @param string|array $tag_list List of tags, as array or as a string with comas
*
* @return boolean Operation success * @return boolean Operation success
*/ */
public static function addTags($id_lang, $id_product, $string) public static function addTags($id_lang, $id_product, $tag_list)
{ {
if (!Validate::isUnsignedId($id_lang) || !Validate::isTagsList($string)) if (!Validate::isUnsignedId($id_lang))
return false; return false;
$tmp_tab = array_unique(array_map('trim', preg_split('/,/', $string, null, PREG_SPLIT_NO_EMPTY))); if (!is_array($tag_list))
$tag_list = array_unique(array_map('trim', preg_split('/,/', $tag_list, null, PREG_SPLIT_NO_EMPTY)));
$list = array(); $list = array();
foreach ($tmp_tab as $tag) foreach ($tag_list as $tag)
{ {
if (!Validate::isGenericName($tag)) if (!Validate::isGenericName($tag))
return false; return false;
+5 -4
View File
@@ -246,7 +246,7 @@ abstract class DbCore
* *
* @param string $table Table where insert/update data * @param string $table Table where insert/update data
* @param string $data Data to insert/update * @param string $data Data to insert/update
* @param string $type INSERT or UPDATE * @param string $type INSERT or INSERT IGNORE or UPDATE
* @param string $where WHERE clause, only for UPDATE (optional) * @param string $where WHERE clause, only for UPDATE (optional)
* @param string $limit LIMIT clause (optional) * @param string $limit LIMIT clause (optional)
* @param bool $use_null If true, replace empty strings and NULL by a NULL value * @param bool $use_null If true, replace empty strings and NULL by a NULL value
@@ -257,7 +257,8 @@ abstract class DbCore
if (!$data) if (!$data)
return true; return true;
if (strtoupper($type) == 'INSERT') $type = strtoupper($type);
if ($type == 'INSERT' || $type == 'INSERT IGNORE')
{ {
// Check if $data is a list of row // Check if $data is a list of row
$current = current($data); $current = current($data);
@@ -291,12 +292,12 @@ abstract class DbCore
$values_stringified[] = '('.implode(', ', $values).')'; $values_stringified[] = '('.implode(', ', $values).')';
} }
$sql = 'INSERT INTO `'.$table.'` ('.$keys_stringified.') VALUES '.implode(', ', $values_stringified); $sql = $type.' INTO `'.$table.'` ('.$keys_stringified.') VALUES '.implode(', ', $values_stringified);
if ($limit) if ($limit)
$sql .= ' LIMIT '.(int)$limit; $sql .= ' LIMIT '.(int)$limit;
return $this->q($sql, $use_cache); return $this->q($sql, $use_cache);
} }
else if (strtoupper($type) == 'UPDATE') else if ($type == 'UPDATE')
{ {
$sql = 'UPDATE `'.$table.'` SET '; $sql = 'UPDATE `'.$table.'` SET ';
foreach ($data as $key => $value) foreach ($data as $key => $value)