NEW triggers create, modify, delete
Also modified deleteByFkAttribute() to use the function delete()
This commit is contained in:
parent
a53f7ff9c9
commit
bb16564b98
@ -16,17 +16,18 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
||||||
/**
|
/**
|
||||||
* Class ProductAttributeValue
|
* Class ProductAttributeValue
|
||||||
* Used to represent a product attribute value
|
* Used to represent a product attribute value
|
||||||
*/
|
*/
|
||||||
class ProductAttributeValue
|
class ProductAttributeValue extends CommonObject
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Database handler
|
* Database handler
|
||||||
* @var DoliDB
|
* @var DoliDB
|
||||||
*/
|
*/
|
||||||
private $db;
|
public $db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attribute value id
|
* Attribute value id
|
||||||
@ -144,15 +145,25 @@ class ProductAttributeValue
|
|||||||
/**
|
/**
|
||||||
* Creates a value for a product attribute
|
* Creates a value for a product attribute
|
||||||
*
|
*
|
||||||
* @param User $user Object user
|
* @param User $user Object user
|
||||||
* @return int <0 KO >0 OK
|
* @param int $notrigger Do not execute trigger
|
||||||
|
* @return int <0 KO >0 OK
|
||||||
*/
|
*/
|
||||||
public function create(User $user)
|
public function create(User $user, $notrigger = 0)
|
||||||
{
|
{
|
||||||
if (!$this->fk_product_attribute) {
|
if (!$this->fk_product_attribute) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($notrigger)) {
|
||||||
|
// Call trigger
|
||||||
|
$result = $this->call_trigger('PRODUCT_ATTRIBUTE_VALUE_CREATE', $user);
|
||||||
|
if ($result < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
// Ref must be uppercase
|
// Ref must be uppercase
|
||||||
$this->ref = strtoupper($this->ref);
|
$this->ref = strtoupper($this->ref);
|
||||||
|
|
||||||
@ -173,11 +184,21 @@ class ProductAttributeValue
|
|||||||
/**
|
/**
|
||||||
* Updates a product attribute value
|
* Updates a product attribute value
|
||||||
*
|
*
|
||||||
* @param User $user Object user
|
* @param User $user Object user
|
||||||
* @return int <0 if KO, >0 if OK
|
* @param int $notrigger Do not execute trigger
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
public function update(User $user)
|
public function update(User $user, $notrigger = 0)
|
||||||
{
|
{
|
||||||
|
if (empty($notrigger)) {
|
||||||
|
// Call trigger
|
||||||
|
$result = $this->call_trigger('PRODUCT_ATTRIBUTE_VALUE_MODIFY', $user);
|
||||||
|
if ($result < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
//Ref must be uppercase
|
//Ref must be uppercase
|
||||||
$this->ref = trim(strtoupper($this->ref));
|
$this->ref = trim(strtoupper($this->ref));
|
||||||
$this->value = trim($this->value);
|
$this->value = trim($this->value);
|
||||||
@ -196,33 +217,63 @@ class ProductAttributeValue
|
|||||||
/**
|
/**
|
||||||
* Deletes a product attribute value
|
* Deletes a product attribute value
|
||||||
*
|
*
|
||||||
|
* @param User $user Object user
|
||||||
|
* @param int $notrigger Do not execute trigger
|
||||||
* @return int <0 KO, >0 OK
|
* @return int <0 KO, >0 OK
|
||||||
*/
|
*/
|
||||||
public function delete()
|
public function delete(User $user, $notrigger = 0)
|
||||||
{
|
{
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE rowid = ".(int) $this->id;
|
if (empty($notrigger)) {
|
||||||
|
// Call trigger
|
||||||
|
$result = $this->call_trigger('PRODUCT_ATTRIBUTE_VALUE_DELETE', $user);
|
||||||
|
if ($result < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->db->query($sql)) {
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE rowid = ".(int) $this->id;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
if ($this->db->query($sql)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes all product attribute values by a product attribute id
|
* Deletes all product attribute values by a product attribute id
|
||||||
*
|
*
|
||||||
* @param int $fk_attribute Product attribute id
|
* @param int $fk_attribute Product attribute id
|
||||||
|
* @param int $notrigger Do not execute trigger
|
||||||
* @return int <0 KO, >0 OK
|
* @return int <0 KO, >0 OK
|
||||||
*/
|
*/
|
||||||
public function deleteByFkAttribute($fk_attribute)
|
public function deleteByFkAttribute($fk_attribute, User $user)
|
||||||
{
|
{
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE fk_product_attribute = ".(int) $fk_attribute;
|
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE fk_product_attribute = ".(int) $fk_attribute;
|
||||||
|
|
||||||
if ($this->db->query($sql)) {
|
$query = $this->db->query($sql);
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
if (!$query) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->db->num_rows($query)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ($obj = $this->db->fetch_object($query)) {
|
||||||
|
$tmp = new ProductAttributeValue($this->db);
|
||||||
|
if ($tmp->fetch($obj->rowid) > 0) {
|
||||||
|
$result = $tmp->delete($user);
|
||||||
|
if ($result < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user