Merge pull request #15108 from frederic34/patch-4
Update cproductnature.class.php
This commit is contained in:
commit
0a1e49447d
@ -42,9 +42,20 @@ class CProductNature // extends CommonObject
|
|||||||
* @var string[] Error codes (or messages)
|
* @var string[] Error codes (or messages)
|
||||||
*/
|
*/
|
||||||
public $errors = array();
|
public $errors = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array record
|
||||||
|
*/
|
||||||
public $records = array();
|
public $records = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string element
|
||||||
|
*/
|
||||||
public $element='cproductnbature';
|
public $element='cproductnbature';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string table element
|
||||||
|
*/
|
||||||
public $table_element='c_product_nature';
|
public $table_element='c_product_nature';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,13 +63,22 @@ class CProductNature // extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public $id;
|
public $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int code
|
||||||
|
*/
|
||||||
public $code;
|
public $code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string label
|
||||||
|
*/
|
||||||
public $label;
|
public $label;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int active
|
||||||
|
*/
|
||||||
public $active;
|
public $active;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -80,17 +100,6 @@ class CProductNature // extends CommonObject
|
|||||||
public function create($user, $notrigger = 0)
|
public function create($user, $notrigger = 0)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
$error = 0;
|
|
||||||
|
|
||||||
// Clean parameters
|
|
||||||
|
|
||||||
if (isset($this->id)) $this->id = (int) $this->id;
|
|
||||||
if (isset($this->code)) $this->code = trim($this->code);
|
|
||||||
if (isset($this->label)) $this->libelle = trim($this->label);
|
|
||||||
if (isset($this->active)) $this->active = trim($this->active);
|
|
||||||
|
|
||||||
// Check parameters
|
|
||||||
// Put here code to add control on parameters values
|
|
||||||
|
|
||||||
// Insert request
|
// Insert request
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
|
||||||
@ -101,32 +110,22 @@ class CProductNature // extends CommonObject
|
|||||||
$sql .= ") VALUES (";
|
$sql .= ") VALUES (";
|
||||||
$sql .= " ".(!isset($this->id) ? 'NULL' : ((int) $this->id)) .",";
|
$sql .= " ".(!isset($this->id) ? 'NULL' : ((int) $this->id)) .",";
|
||||||
$sql .= " ".(!isset($this->code) ? 'NULL' : ((int) $this->code)).",";
|
$sql .= " ".(!isset($this->code) ? 'NULL' : ((int) $this->code)).",";
|
||||||
$sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").",";
|
$sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape(trim($this->label))."'").",";
|
||||||
$sql .= " ".(!isset($this->active) ? 'NULL' : ((int) $this->db->escape($this->active))).",";
|
$sql .= " ".(!isset($this->active) ? 'NULL' : ((int) $this->active)).",";
|
||||||
$sql .= ")";
|
$sql .= ")";
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
|
|
||||||
|
|
||||||
if (!$error)
|
|
||||||
{
|
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commit or rollback
|
// Commit or rollback
|
||||||
if ($error)
|
if (!$resql) {
|
||||||
{
|
dol_syslog(get_class($this)."::create ".$this->db->lasterror(), LOG_ERR);
|
||||||
foreach ($this->errors as $errmsg)
|
$this->error = "Error ".$this->db->lasterror();
|
||||||
{
|
|
||||||
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
|
|
||||||
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
|
|
||||||
}
|
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1 * $error;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
@ -265,39 +264,24 @@ class CProductNature // extends CommonObject
|
|||||||
public function update($user = null, $notrigger = 0)
|
public function update($user = null, $notrigger = 0)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
$error = 0;
|
|
||||||
|
|
||||||
// Clean parameters
|
|
||||||
if (isset($this->code)) $this->code = trim($this->code);
|
|
||||||
if (isset($this->label)) $this->label = trim($this->label);
|
|
||||||
if (isset($this->active)) $this->active = trim($this->active);
|
|
||||||
|
|
||||||
// Check parameters
|
|
||||||
// Put here code to add control on parameters values
|
|
||||||
|
|
||||||
// Update request
|
// Update request
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
|
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
|
||||||
$sql .= " code=".(isset($this->code) ? ((int) $this->code) : "null").",";
|
$sql .= " code=".(isset($this->code) ? ((int) $this->code) : "null").",";
|
||||||
$sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
|
$sql .= " label=".(isset($this->label) ? "'".$this->db->escape(trim($this->label))."'" : "null").",";
|
||||||
$sql .= " active=".(isset($this->active) ? ((int) $this->active) : "null");
|
$sql .= " active=".(isset($this->active) ? ((int) $this->active) : "null");
|
||||||
$sql .= " WHERE rowid=".$this->id;
|
$sql .= " WHERE rowid=".(int) $this->id;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
|
|
||||||
|
|
||||||
// Commit or rollback
|
// Commit or rollback
|
||||||
if ($error)
|
if (!$resql) {
|
||||||
{
|
dol_syslog(get_class($this)."::update Error ".$this->db->lasterror(), LOG_ERR);
|
||||||
foreach ($this->errors as $errmsg)
|
$this->error = "Error ".$this->db->lasterror();
|
||||||
{
|
|
||||||
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
|
|
||||||
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
|
|
||||||
}
|
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1 * $error;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
@ -318,24 +302,18 @@ class CProductNature // extends CommonObject
|
|||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
|
||||||
$sql .= " WHERE rowid=".$this->id;
|
$sql .= " WHERE rowid=".(int) $this->id;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
|
|
||||||
|
|
||||||
// Commit or rollback
|
// Commit or rollback
|
||||||
if ($error)
|
if (!$resql) {
|
||||||
{
|
dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
|
||||||
foreach ($this->errors as $errmsg)
|
$this->error = "Error ".$this->db->lasterror();
|
||||||
{
|
|
||||||
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
|
|
||||||
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
|
|
||||||
}
|
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1 * $error;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
@ -345,7 +323,7 @@ class CProductNature // extends CommonObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get unit from code
|
* Get unit from code
|
||||||
* @param string $code code of unit
|
* @param int $code code of unit
|
||||||
* @param string $mode 0= id , short_label=Use short label as value, code=use code
|
* @param string $mode 0= id , short_label=Use short label as value, code=use code
|
||||||
* @return int <0 if KO, Id of code if OK
|
* @return int <0 if KO, Id of code if OK
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user