[*] 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+23
-20
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* 2007-2011 PrestaShop
|
* 2007-2011 PrestaShop
|
||||||
*
|
*
|
||||||
* NOTICE OF LICENSE
|
* NOTICE OF LICENSE
|
||||||
*
|
*
|
||||||
@@ -32,19 +32,19 @@ class AttributeGroupCore extends ObjectModel
|
|||||||
public $is_color_group;
|
public $is_color_group;
|
||||||
public $position;
|
public $position;
|
||||||
public $group_type;
|
public $group_type;
|
||||||
|
|
||||||
/** @var string Public Name */
|
/** @var string Public Name */
|
||||||
public $public_name;
|
public $public_name;
|
||||||
|
|
||||||
protected $fieldsRequired = array();
|
protected $fieldsRequired = array();
|
||||||
protected $fieldsValidate = array('is_color_group' => 'isBool');
|
protected $fieldsValidate = array('is_color_group' => 'isBool');
|
||||||
protected $fieldsRequiredLang = array('name', 'public_name');
|
protected $fieldsRequiredLang = array('name', 'public_name');
|
||||||
protected $fieldsSizeLang = array('name' => 64, 'public_name' => 64);
|
protected $fieldsSizeLang = array('name' => 64, 'public_name' => 64);
|
||||||
protected $fieldsValidateLang = array('name' => 'isGenericName', 'public_name' => 'isGenericName', 'position' => 'isInt');
|
protected $fieldsValidateLang = array('name' => 'isGenericName', 'public_name' => 'isGenericName', 'position' => 'isInt');
|
||||||
|
|
||||||
protected $table = 'attribute_group';
|
protected $table = 'attribute_group';
|
||||||
protected $identifier = 'id_attribute_group';
|
protected $identifier = 'id_attribute_group';
|
||||||
|
|
||||||
protected $webserviceParameters = array(
|
protected $webserviceParameters = array(
|
||||||
'objectsNodeName' => 'product_options',
|
'objectsNodeName' => 'product_options',
|
||||||
'objectNodeName' => 'product_option',
|
'objectNodeName' => 'product_option',
|
||||||
@@ -68,21 +68,24 @@ class AttributeGroupCore extends ObjectModel
|
|||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update($nullValues = false)
|
public function update($nullValues = false)
|
||||||
{
|
{
|
||||||
$return = parent::update($nullValues);
|
$return = parent::update($nullValues);
|
||||||
Module::hookExec('afterSaveAttributeGroup', array('id_attribute_group' => $this->id));
|
Module::hookExec('afterSaveAttributeGroup', array('id_attribute_group' => $this->id));
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check then return multilingual fields for database interaction
|
* Check then return multilingual fields for database interaction
|
||||||
*
|
*
|
||||||
@@ -129,7 +132,7 @@ class AttributeGroupCore extends ObjectModel
|
|||||||
Module::hookExec('afterDeleteAttributeGroup', array('id_attribute_group' => $this->id));
|
Module::hookExec('afterDeleteAttributeGroup', array('id_attribute_group' => $this->id));
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all attributes for a given language / group
|
* Get all attributes for a given language / group
|
||||||
*
|
*
|
||||||
@@ -148,7 +151,7 @@ class AttributeGroupCore extends ObjectModel
|
|||||||
WHERE a.`id_attribute_group` = '.(int)($id_attribute_group).'
|
WHERE a.`id_attribute_group` = '.(int)($id_attribute_group).'
|
||||||
ORDER BY `position` ASC');
|
ORDER BY `position` ASC');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all attributes groups for a given language
|
* Get all attributes groups for a given language
|
||||||
*
|
*
|
||||||
@@ -165,7 +168,7 @@ class AttributeGroupCore extends ObjectModel
|
|||||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND `id_lang` = '.(int)($id_lang).')
|
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND `id_lang` = '.(int)($id_lang).')
|
||||||
ORDER BY `name` ASC');
|
ORDER BY `name` ASC');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete several objects from database
|
* Delete several objects from database
|
||||||
*
|
*
|
||||||
@@ -174,7 +177,7 @@ class AttributeGroupCore extends ObjectModel
|
|||||||
public function deleteSelection($selection)
|
public function deleteSelection($selection)
|
||||||
{
|
{
|
||||||
/* Also delete Attributes */
|
/* Also delete Attributes */
|
||||||
foreach ($selection AS $value)
|
foreach ($selection AS $value)
|
||||||
{
|
{
|
||||||
$obj = new AttributeGroup($value);
|
$obj = new AttributeGroup($value);
|
||||||
if (!$obj->delete())
|
if (!$obj->delete())
|
||||||
@@ -182,7 +185,7 @@ class AttributeGroupCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setWsProductOptionValues($values)
|
public function setWsProductOptionValues($values)
|
||||||
{
|
{
|
||||||
$ids = array();
|
$ids = array();
|
||||||
@@ -206,13 +209,13 @@ class AttributeGroupCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
return $ok;
|
return $ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWsProductOptionValues()
|
public function getWsProductOptionValues()
|
||||||
{
|
{
|
||||||
$result = Db::getInstance()->executeS('SELECT id_attribute AS id from `'._DB_PREFIX_.'attribute` WHERE id_attribute_group = '.(int)$this->id);
|
$result = Db::getInstance()->executeS('SELECT id_attribute AS id from `'._DB_PREFIX_.'attribute` WHERE id_attribute_group = '.(int)$this->id);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move a group attribute
|
* Move a group attribute
|
||||||
* @param boolean $way Up (1) or Down (0)
|
* @param boolean $way Up (1) or Down (0)
|
||||||
@@ -250,7 +253,7 @@ class AttributeGroupCore extends ObjectModel
|
|||||||
SET `position` = '.(int)$position.'
|
SET `position` = '.(int)$position.'
|
||||||
WHERE `id_attribute_group`='.(int)$movedGroupAttribute['id_attribute_group']));
|
WHERE `id_attribute_group`='.(int)$movedGroupAttribute['id_attribute_group']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reorder group attribute position
|
* Reorder group attribute position
|
||||||
* Call it after deleting a group attribute.
|
* Call it after deleting a group attribute.
|
||||||
@@ -278,9 +281,9 @@ class AttributeGroupCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getHigherPosition
|
* getHigherPosition
|
||||||
*
|
*
|
||||||
* Get the higher group attribute position
|
* Get the higher group attribute position
|
||||||
*
|
*
|
||||||
* @return integer $position
|
* @return integer $position
|
||||||
*/
|
*/
|
||||||
public static function getHigherPosition()
|
public static function getHigherPosition()
|
||||||
@@ -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