Skip to content

Commit

Permalink
New: Add ref_ext on actions
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Nov 1, 2011
1 parent ecb6c1e commit 28d6fc0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 16 deletions.
41 changes: 34 additions & 7 deletions htdocs/comm/action/class/actioncomm.class.php
Expand Up @@ -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;
Expand Down Expand Up @@ -82,7 +83,8 @@ class ActionComm extends CommonObject

/**
* Constructor
* @param db Database handler
*
* @param DoliDB $db Database handler
*/
function ActionComm($db)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -149,7 +152,6 @@ function add($user,$notrigger=0)
return -1;
}


$this->db->begin();

$sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm";
Expand Down Expand Up @@ -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;
}

}

?>
6 changes: 3 additions & 3 deletions htdocs/comm/action/class/cactioncomm.class.php
Expand Up @@ -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;
}

/**
Expand Down
44 changes: 38 additions & 6 deletions htdocs/core/class/commonobject.class.php
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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 ";
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 28d6fc0

Please sign in to comment.