[*] Classes: calcul position in class when an attribute, an image or a scene is added
This commit is contained in:
1 parent
3c85847608
commit
d2f1d99edb
4 files changed
+17
-2
No files matched your search
@@ -124,6 +124,9 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
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);
|
||||
if ($return)
|
||||
Module::hookExec('afterSaveAttribute', array('id_attribute' => $this->id));
|
||||
@@ -339,7 +342,7 @@ class AttributeCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'attribute`
|
||||
WHERE id_attribute_group = '.(int)$id_attribute_group;
|
||||
$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)
|
||||
{
|
||||
if ($this->position <= 0)
|
||||
$this->position = AttributeGroup::getHigherPosition() + 1;
|
||||
|
||||
$return = parent::add($autodate, true);
|
||||
Module::hookExec('afterSaveAttributeGroup', array('id_attribute_group' => $this->id));
|
||||
return $return;
|
||||
@@ -288,7 +291,7 @@ class AttributeGroupCore extends ObjectModel
|
||||
$sql = 'SELECT MAX(`position`)
|
||||
FROM `'._DB_PREFIX_.'attribute_group`';
|
||||
$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'));
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
if (!parent::delete() ||
|
||||
|
||||
@@ -173,6 +173,7 @@ class SceneCore extends ObjectModel
|
||||
$result = true;
|
||||
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
|
||||
('.(int)($this->id).', '.(int)($zone['id_product']).', '.(int)($zone['x1']).', '.(int)($zone['y1']).', '.(int)($zone['width']).', '.(int)($zone['height']).')';
|
||||
if (!Db::getInstance()->execute($sql))
|
||||
|
||||
Reference in new issue
Block a user