[*] Classes: calcul position in class when an attribute, an image or a scene is added
This commit is contained in:
@@ -124,6 +124,9 @@ class AttributeCore extends ObjectModel
|
|||||||
|
|
||||||
public function add($autodate = true, $null_values = false)
|
public function add($autodate = true, $null_values = false)
|
||||||
{
|
{
|
||||||
|
if ($this->position <= 0)
|
||||||
|
$this->position = Attribute::getHigherPosition($this->id_attribute_group) + 1;
|
||||||
|
|
||||||
$return = parent::add($autodate, $null_values);
|
$return = parent::add($autodate, $null_values);
|
||||||
if ($return)
|
if ($return)
|
||||||
Module::hookExec('afterSaveAttribute', array('id_attribute' => $this->id));
|
Module::hookExec('afterSaveAttribute', array('id_attribute' => $this->id));
|
||||||
@@ -339,7 +342,7 @@ class AttributeCore extends ObjectModel
|
|||||||
FROM `'._DB_PREFIX_.'attribute`
|
FROM `'._DB_PREFIX_.'attribute`
|
||||||
WHERE id_attribute_group = '.(int)$id_attribute_group;
|
WHERE id_attribute_group = '.(int)$id_attribute_group;
|
||||||
$position = DB::getInstance()->getValue($sql);
|
$position = DB::getInstance()->getValue($sql);
|
||||||
return ($position !== false) ? $position : -1;
|
return (is_numeric($position)) ? $position : -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ class AttributeGroupCore extends ObjectModel
|
|||||||
|
|
||||||
public function add($autodate = true, $nullValues = false)
|
public function add($autodate = true, $nullValues = false)
|
||||||
{
|
{
|
||||||
|
if ($this->position <= 0)
|
||||||
|
$this->position = AttributeGroup::getHigherPosition() + 1;
|
||||||
|
|
||||||
$return = parent::add($autodate, true);
|
$return = parent::add($autodate, true);
|
||||||
Module::hookExec('afterSaveAttributeGroup', array('id_attribute_group' => $this->id));
|
Module::hookExec('afterSaveAttributeGroup', array('id_attribute_group' => $this->id));
|
||||||
return $return;
|
return $return;
|
||||||
@@ -288,7 +291,7 @@ class AttributeGroupCore extends ObjectModel
|
|||||||
$sql = 'SELECT MAX(`position`)
|
$sql = 'SELECT MAX(`position`)
|
||||||
FROM `'._DB_PREFIX_.'attribute_group`';
|
FROM `'._DB_PREFIX_.'attribute_group`';
|
||||||
$position = DB::getInstance()->getValue($sql);
|
$position = DB::getInstance()->getValue($sql);
|
||||||
return ($position !== false) ? $position : -1;
|
return (is_numeric($position)) ? $position : -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,14 @@ class ImageCore extends ObjectModel
|
|||||||
return $this->getTranslationsFields(array('legend'));
|
return $this->getTranslationsFields(array('legend'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function add($autodate = true, $null_values = false)
|
||||||
|
{
|
||||||
|
if ($this->position <= 0)
|
||||||
|
$this->position = Image::getHighestPosition($this->id_product) + 1;
|
||||||
|
|
||||||
|
return parent::add($autodate, $null_values);
|
||||||
|
}
|
||||||
|
|
||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
if (!parent::delete() ||
|
if (!parent::delete() ||
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ class SceneCore extends ObjectModel
|
|||||||
$result = true;
|
$result = true;
|
||||||
foreach ($zones AS $zone)
|
foreach ($zones AS $zone)
|
||||||
{
|
{
|
||||||
|
// @todo use multiple insert
|
||||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'scene_products` ( `id_scene` , `id_product` , `x_axis` , `y_axis` , `zone_width` , `zone_height`) VALUES
|
$sql = 'INSERT INTO `'._DB_PREFIX_.'scene_products` ( `id_scene` , `id_product` , `x_axis` , `y_axis` , `zone_width` , `zone_height`) VALUES
|
||||||
('.(int)($this->id).', '.(int)($zone['id_product']).', '.(int)($zone['x1']).', '.(int)($zone['y1']).', '.(int)($zone['width']).', '.(int)($zone['height']).')';
|
('.(int)($this->id).', '.(int)($zone['id_product']).', '.(int)($zone['x1']).', '.(int)($zone['y1']).', '.(int)($zone['width']).', '.(int)($zone['height']).')';
|
||||||
if (!Db::getInstance()->execute($sql))
|
if (!Db::getInstance()->execute($sql))
|
||||||
|
|||||||
Reference in New Issue
Block a user