From 28d6fc03f9e9b1d10772813dea2df7e855002821 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 1 Nov 2011 04:58:47 +0100 Subject: [PATCH] New: Add ref_ext on actions --- htdocs/comm/action/class/actioncomm.class.php | 41 ++++++++++++++--- .../comm/action/class/cactioncomm.class.php | 6 +-- htdocs/core/class/commonobject.class.php | 44 ++++++++++++++++--- 3 files changed, 75 insertions(+), 16 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 806d60929f226..9d5a480769a8a 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -34,6 +34,7 @@ class ActionComm extends CommonObject { public $element='action'; public $table_element = 'actioncomm'; + public $table_rowid = 'id'; protected $ismultientitymanaged = 2; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe var $type_id; @@ -82,7 +83,8 @@ class ActionComm extends CommonObject /** * Constructor - * @param db Database handler + * + * @param DoliDB $db Database handler */ function ActionComm($db) { @@ -123,12 +125,13 @@ function add($user,$notrigger=0) if (! $this->type_id && $this->type_code) { - // Get id from code - $cactioncomm=new CActionComm($this->db); - $result=$cactioncomm->fetch($this->type_code); - if ($result > 0) + // Get id from code + $cactioncomm=new CActionComm($this->db); + $result=$cactioncomm->fetch($this->type_code); + + if ($result > 0) { - $this->type_id=$cactioncomm->id; + $this->type_id=$cactioncomm->id; } else if ($result == 0) { @@ -149,7 +152,6 @@ function add($user,$notrigger=0) return -1; } - $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm"; @@ -879,6 +881,31 @@ function build_exportfile($format,$type,$cachedelay,$filename,$filters) return $result; } + /** + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + function initAsSpecimen() + { + global $user,$langs,$conf; + + $now=dol_now(); + + // Initialise parametres + $this->id=0; + $this->specimen=1; + + $this->type_code='AC_OTH'; + $this->label='Event Specimen'; + $this->note = 'Note'; + $this->location='Location'; + $this->datep=$now; + $this->datef=$now; + } + } ?> diff --git a/htdocs/comm/action/class/cactioncomm.class.php b/htdocs/comm/action/class/cactioncomm.class.php index 786317a30c9cb..4c140b4abd83a 100644 --- a/htdocs/comm/action/class/cactioncomm.class.php +++ b/htdocs/comm/action/class/cactioncomm.class.php @@ -45,11 +45,11 @@ class CActionComm /** * Constructor * - * @param DoliDB $DB Database handler + * @param DoliDB $db Database handler */ - function CActionComm($DB) + function CActionComm($db) { - $this->db = $DB; + $this->db = $db; } /** diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d4583a02d7eac..22f5a1ae70548 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -589,10 +589,10 @@ function fetchObjectFrom($table,$field,$key) return $result; } - + /** * Load value from specific field - * + * * @param string $table Table of element or element line * @param int $id Element id * @param string $field Field selected @@ -601,17 +601,17 @@ function fetchObjectFrom($table,$field,$key) function getValueFrom($table, $id, $field) { $result=false; - + $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; $sql.= " WHERE rowid = ".$id; - + $resql = $this->db->query($sql); if ($resql) { $row = $this->db->fetch_row($resql); $result = $row[0]; } - + return $result; } @@ -628,7 +628,7 @@ function getValueFrom($table, $id, $field) function setValueFrom($table, $id, $field, $value, $format='text') { global $conf; - + $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; @@ -1073,6 +1073,38 @@ function line_max($fk_parent_line=0) } } + /** + * Update private note of element + * + * @param string $ref_ext Update field ref_ext + * @return int <0 if KO, >0 if OK + */ + function update_ref_ext($ref_ext) + { + if (! $this->table_element) + { + dol_syslog(get_class($this)."::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); + return -1; + } + + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql.= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; + $sql.= " WHERE ".(isset($this->table_rowid)?$this->table_rowid:'rowid')." = ". $this->id; + + dol_syslog(get_class($this)."::update_ref_ext sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) + { + $this->ref_ext = $ref_ext; + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog(get_class($this)."::update_ref_ext error=".$this->error, LOG_ERR); + return -1; + } + } + /** * Update private note of element *