In commonoobject add method for adding resource to an element
This commit is contained in:
parent
e63f8b87c1
commit
bb58bed930
@ -3317,6 +3317,7 @@ abstract class CommonObject
|
||||
}
|
||||
// TODO : add other elements
|
||||
|
||||
|
||||
$element_properties = array(
|
||||
'module' => $module,
|
||||
'classpath' => $classpath,
|
||||
@ -3355,6 +3356,47 @@ abstract class CommonObject
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add resources to the current object
|
||||
*
|
||||
* @param int $resource_id Resource id
|
||||
* @param string $resource_element Resource element
|
||||
* @return int <=0 if KO, >0 if OK
|
||||
*/
|
||||
function add_element_resource($resource_id,$resource_element,$busy=0,$mandatory=0)
|
||||
{
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources (";
|
||||
$sql.= "resource_id";
|
||||
$sql.= ", resource_type";
|
||||
$sql.= ", element_id";
|
||||
$sql.= ", element_type";
|
||||
$sql.= ", busy";
|
||||
$sql.= ", mandatory";
|
||||
$sql.= ") VALUES (";
|
||||
$sql.= $resource_id;
|
||||
$sql.= ", '".$resource_element."'";
|
||||
$sql.= ", '".$this->id."'";
|
||||
$sql.= ", '".$this->element."'";
|
||||
$sql.= ", '".$busy."'";
|
||||
$sql.= ", '".$mandatory."'";
|
||||
$sql.= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::add_element_resource sql=".$sql, LOG_DEBUG);
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
$this->db->rollback();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Overwrite magic function to solve problem of cloning object that are kept as references
|
||||
|
||||
@ -373,51 +373,6 @@ class Resource extends CommonObject
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add resources to the actioncom object
|
||||
*
|
||||
* @param int $element_id Element id
|
||||
* @param string $element_type Element type
|
||||
* @param int $resource_id Resource id
|
||||
* @param string $resource_type Resource type
|
||||
* @param array $resource Resources linked with element
|
||||
* @return int <=0 if KO, >0 if OK
|
||||
*/
|
||||
function add_element_resource($element_id,$element_type,$resource_id,$resource_element,$busy=0,$mandatory=0)
|
||||
{
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources (";
|
||||
$sql.= "resource_id";
|
||||
$sql.= ", resource_type";
|
||||
$sql.= ", element_id";
|
||||
$sql.= ", element_type";
|
||||
$sql.= ", busy";
|
||||
$sql.= ", mandatory";
|
||||
$sql.= ") VALUES (";
|
||||
$sql.= $resource_id;
|
||||
$sql.= ", '".$resource_element."'";
|
||||
$sql.= ", '".$element_id."'";
|
||||
$sql.= ", '".$element_type."'";
|
||||
$sql.= ", '".$busy."'";
|
||||
$sql.= ", '".$mandatory."'";
|
||||
$sql.= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::add_element_resource sql=".$sql, LOG_DEBUG);
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
$this->db->rollback();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return an array with resources linked to the element
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user