New: Add ref_ext on actions

This commit is contained in:
Laurent Destailleur 2011-11-01 04:58:47 +01:00
parent ecb6c1e67d
commit 28d6fc03f9
3 changed files with 75 additions and 16 deletions

View File

@ -34,6 +34,7 @@ class ActionComm extends CommonObject
{ {
public $element='action'; public $element='action';
public $table_element = 'actioncomm'; 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 protected $ismultientitymanaged = 2; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
var $type_id; var $type_id;
@ -82,7 +83,8 @@ class ActionComm extends CommonObject
/** /**
* Constructor * Constructor
* @param db Database handler *
* @param DoliDB $db Database handler
*/ */
function ActionComm($db) function ActionComm($db)
{ {
@ -123,12 +125,13 @@ class ActionComm extends CommonObject
if (! $this->type_id && $this->type_code) if (! $this->type_id && $this->type_code)
{ {
// Get id from code // Get id from code
$cactioncomm=new CActionComm($this->db); $cactioncomm=new CActionComm($this->db);
$result=$cactioncomm->fetch($this->type_code); $result=$cactioncomm->fetch($this->type_code);
if ($result > 0)
if ($result > 0)
{ {
$this->type_id=$cactioncomm->id; $this->type_id=$cactioncomm->id;
} }
else if ($result == 0) else if ($result == 0)
{ {
@ -149,7 +152,6 @@ class ActionComm extends CommonObject
return -1; return -1;
} }
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm";
@ -879,6 +881,31 @@ class ActionComm extends CommonObject
return $result; 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;
}
} }
?> ?>

View File

@ -45,11 +45,11 @@ class CActionComm
/** /**
* Constructor * Constructor
* *
* @param DoliDB $DB Database handler * @param DoliDB $db Database handler
*/ */
function CActionComm($DB) function CActionComm($db)
{ {
$this->db = $DB; $this->db = $db;
} }
/** /**

View File

@ -589,10 +589,10 @@ abstract class CommonObject
return $result; return $result;
} }
/** /**
* Load value from specific field * Load value from specific field
* *
* @param string $table Table of element or element line * @param string $table Table of element or element line
* @param int $id Element id * @param int $id Element id
* @param string $field Field selected * @param string $field Field selected
@ -601,17 +601,17 @@ abstract class CommonObject
function getValueFrom($table, $id, $field) function getValueFrom($table, $id, $field)
{ {
$result=false; $result=false;
$sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table;
$sql.= " WHERE rowid = ".$id; $sql.= " WHERE rowid = ".$id;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
$row = $this->db->fetch_row($resql); $row = $this->db->fetch_row($resql);
$result = $row[0]; $result = $row[0];
} }
return $result; return $result;
} }
@ -628,7 +628,7 @@ abstract class CommonObject
function setValueFrom($table, $id, $field, $value, $format='text') function setValueFrom($table, $id, $field, $value, $format='text')
{ {
global $conf; global $conf;
$this->db->begin(); $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET ";
@ -1073,6 +1073,38 @@ abstract class CommonObject
} }
} }
/**
* 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 * Update private note of element
* *