[*] BO : product images can now be dragged and dropped to change position (CC021)

This commit is contained in:
tDidierjean
2011-09-13 15:22:29 +00:00
parent 95d5d50af4
commit 36ae7699df
6 changed files with 92 additions and 14 deletions
+33
View File
@@ -283,9 +283,12 @@ class ImageCore extends ObjectModel
*
* @param integer $position Position
* @param boolean $direction Direction
* @deprecated since version 1.5.0.1 use Image::updatePosition() instead
*/
public function positionImage($position, $direction)
{
Tools::displayAsDeprecated();
$position = (int)($position);
$direction = (int)($direction);
@@ -310,6 +313,36 @@ class ImageCore extends ObjectModel
AND `position` = '.(int)($high_position));
}
/**
* Change an image position and update relative positions
*
* @param int $way position is moved up if 0, moved down if 1
* @param int $position new position of the moved image
* @return int success
*/
public function updatePosition($way, $position)
{
if (!isset($this->id) || !$position)
return false;
// < and > statements rather than BETWEEN operator
// since BETWEEN is treated differently according to databases
$result = (Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'image`
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
WHERE `position`
'.($way
? '> '.(int)($this->position).' AND `position` <= '.(int)($position)
: '< '.(int)($this->position).' AND `position` >= '.(int)($position)).'
AND `id_product`='.(int)($this->id_product))
&& Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'image`
SET `position` = '.(int)($position).'
WHERE `id_image` = '.(int)($this->id_image)));
return $result;
}
public static function getSize($type)
{
if (!isset(self::$_cacheGetSize[$type]) OR self::$_cacheGetSize[$type] === NULL)