diff --git a/dev/skeletons/skeleton_class.class.php b/dev/skeletons/skeleton_class.class.php
index 8bf001e0e9a..a9fdb4ffa5f 100644
--- a/dev/skeletons/skeleton_class.class.php
+++ b/dev/skeletons/skeleton_class.class.php
@@ -50,9 +50,9 @@ class Skeleton_Class // extends CommonObject
/**
- * Constructor
+ * Constructor
*
- * @param DoliDb $DB Database handler
+ * @param DoliDb $DB Database handler
*/
function Skeleton_Class($DB)
{
@@ -62,11 +62,11 @@ class Skeleton_Class // extends CommonObject
/**
- * Create object into database
+ * Create object into database
*
- * @param User $user User that create
- * @param int $notrigger 0=launch triggers after, 1=disable triggers
- * @return int <0 if KO, Id of created object if OK
+ * @param User $user User that create
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, Id of created object if OK
*/
function create($user, $notrigger=0)
{
@@ -136,10 +136,10 @@ class Skeleton_Class // extends CommonObject
/**
- * Load object in memory from database
+ * Load object in memory from database
*
- * @param int $id Id object
- * @return int <0 if KO, >0 if OK
+ * @param int $id Id object
+ * @return int <0 if KO, >0 if OK
*/
function fetch($id)
{
@@ -179,11 +179,11 @@ class Skeleton_Class // extends CommonObject
/**
- * Update object into database
+ * Update object into database
*
- * @param User $user User that modify
- * @param int $notrigger 0=launch triggers after, 1=disable triggers
- * @return int <0 if KO, >0 if OK
+ * @param User $user User that modify
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, >0 if OK
*/
function update($user=0, $notrigger=0)
{
@@ -247,11 +247,11 @@ class Skeleton_Class // extends CommonObject
/**
- * Delete object in database
+ * Delete object in database
*
- * @param User $user User that delete
- * @param int $notrigger 0=launch triggers after, 1=disable triggers
- * @return int <0 if KO, >0 if OK
+ * @param User $user User that delete
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, >0 if OK
*/
function delete($user, $notrigger=0)
{
@@ -304,10 +304,10 @@ class Skeleton_Class // extends CommonObject
/**
- * Load an object from its id and create a new one in database
+ * Load an object from its id and create a new one in database
*
- * @param int $fromid Id of object to clone
- * @return int New id of clone
+ * @param int $fromid Id of object to clone
+ * @return int New id of clone
*/
function createFromClone($fromid)
{
@@ -359,10 +359,10 @@ class Skeleton_Class // extends CommonObject
/**
- * Initialisz object with example values
- * Id must be 0 if object instance is a specimen
+ * Initialise object with example values
+ * Id must be 0 if object instance is a specimen
*
- * @return none
+ * @return void
*/
function initAsSpecimen()
{
diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php
index c82e7382807..1f63031869e 100644
--- a/htdocs/projet/class/project.class.php
+++ b/htdocs/projet/class/project.class.php
@@ -163,8 +163,8 @@ class Project extends CommonObject
/**
* Update a project
*
- * @param $user User object of making update
- * @param $notrigger 1=Disable all triggers
+ * @param User $user User object of making update
+ * @param int $notrigger 1=Disable all triggers
* @return int
*/
function update($user, $notrigger=0)
@@ -284,8 +284,9 @@ class Project extends CommonObject
/**
* Return list of projects
- * @param socid To filter on a particular third party
- * @return array Liste of projects
+ *
+ * @param int $socid To filter on a particular third party
+ * @return array List of projects
*/
function liste_array($socid='')
{
@@ -324,9 +325,10 @@ class Project extends CommonObject
}
/**
- * \brief Return list of elements for type linked to project
- * \param type 'propal','order','invoice','order_supplier','invoice_supplier'
- * \return array List of orders linked to project, <0 if error
+ * Return list of elements for type linked to project
+ *
+ * @param string $type 'propal','order','invoice','order_supplier','invoice_supplier'
+ * @return array List of orders linked to project, <0 if error
*/
function get_element_list($type)
{
@@ -376,9 +378,10 @@ class Project extends CommonObject
/**
* Delete a project from database
- * @param user User
- * @param notrigger Disable triggers
- * @return int <0 if KO, 0 if not possible, >0 if OK
+ *
+ * @param User $user User
+ * @param int $notrigger Disable triggers
+ * @return int <0 if KO, 0 if not possible, >0 if OK
*/
function delete($user, $notrigger=0)
{
@@ -469,8 +472,9 @@ class Project extends CommonObject
/**
* Validate a project
- * @param user User that validate
- * @return int <0 if KO, >0 if OK
+ *
+ * @param User $user User that validate
+ * @return int <0 if KO, >0 if OK
*/
function setValid($user)
{
@@ -521,8 +525,9 @@ class Project extends CommonObject
/**
* Close a project
- * @param user User that validate
- * @return int <0 if KO, >0 if OK
+ *
+ * @param User $user User that validate
+ * @return int <0 if KO, >0 if OK
*/
function setClose($user)
{
@@ -573,9 +578,10 @@ class Project extends CommonObject
}
/**
- * \brief Return status label of object
- * \param mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
- * \return string Label
+ * Return status label of object
+ *
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
+ * @return string Label
*/
function getLibStatut($mode=0)
{
@@ -583,10 +589,11 @@ class Project extends CommonObject
}
/**
- * \brief Renvoi status label for a status
- * \param statut id statut
- * \param mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
- * \return string Label
+ * Renvoi status label for a status
+ *
+ * @param int $statut id statut
+ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
+ * @return string Label
*/
function LibStatut($statut,$mode=0)
{
@@ -627,10 +634,11 @@ class Project extends CommonObject
}
/**
- * \brief Renvoie nom clicable (avec eventuellement le picto)
- * \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
- * \param option Variante ('', 'nolink')
- * \return string Chaine avec URL
+ * Renvoie nom clicable (avec eventuellement le picto)
+ *
+ * @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
+ * @param string $option Variante ('', 'nolink')
+ * @return string Chaine avec URL
*/
function getNomUrl($withpicto=0,$option='')
{
@@ -658,7 +666,9 @@ class Project extends CommonObject
}
/**
- * \brief Initialise object with default value to be used as example
+ * Initialise object with default value to be used as example
+ *
+ * @return void
*/
function initAsSpecimen()
{
@@ -734,9 +744,11 @@ class Project extends CommonObject
}
/**
- * \brief Check if user has read permission on project
- * @param user Object user to evaluate
- * @param noprint 0=Print forbidden message if no permission, 1=Return -1 if no permission
+ * Check if user has read permission on project
+ *
+ * @param User $user Object user to evaluate
+ * @param int $noprint 0=Print forbidden message if no permission, 1=Return -1 if no permission
+ * @return void
*/
function restrictedProjectArea($user,$noprint=0)
{
@@ -795,11 +807,11 @@ class Project extends CommonObject
/**
* Return array of projects a user has permission on, is affected to, or all projects
*
- * @param user User object
- * @param mode 0=All project I have permission on, 1=Projects affected to me only, 2=Will return list of all projects with no test on contacts
- * @param list 0=Return array,1=Return string list
- * @param socid 0=No filter on third party, id of third party
- * @return array or string
+ * @param User $user User object
+ * @param int $mode 0=All project I have permission on, 1=Projects affected to me only, 2=Will return list of all projects with no test on contacts
+ * @param int $list 0=Return array,1=Return string list
+ * @param int $socid 0=No filter on third party, id of third party
+ * @return array Array of projects
*/
function getProjectsAuthorizedForUser($user,$mode=0,$list=0,$socid=0)
{
diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php
index 58c2f7d3020..82b9631c852 100644
--- a/htdocs/projet/class/task.class.php
+++ b/htdocs/projet/class/task.class.php
@@ -32,42 +32,42 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
*/
class Task extends CommonObject
{
- var $db; //!< To store db handler
- var $error; //!< To return error code (or message)
- var $errors=array(); //!< To return several error codes (or messages)
- var $element='project_task'; //!< Id that identify managed objects
- var $table_element='projet_task'; //!< Name of table without prefix where object is stored
+ var $db; //!< To store db handler
+ var $error; //!< To return error code (or message)
+ var $errors=array(); //!< To return several error codes (or messages)
+ var $element='project_task'; //!< Id that identify managed objects
+ var $table_element='projet_task'; //!< Name of table without prefix where object is stored
var $id;
- var $fk_project;
- var $fk_task_parent;
- var $label;
- var $description;
- var $duration_effective;
- var $date_c;
- var $date_start;
- var $date_end;
- var $progress;
- var $priority;
- var $fk_user_creat;
- var $fk_user_valid;
- var $statut;
- var $note_private;
- var $note_public;
+ var $fk_project;
+ var $fk_task_parent;
+ var $label;
+ var $description;
+ var $duration_effective;
+ var $date_c;
+ var $date_start;
+ var $date_end;
+ var $progress;
+ var $priority;
+ var $fk_user_creat;
+ var $fk_user_valid;
+ var $statut;
+ var $note_private;
+ var $note_public;
- var $timespent_id;
- var $timespent_duration;
- var $timespent_old_duration;
- var $timespent_date;
- var $timespent_fk_user;
- var $timespent_note;
+ var $timespent_id;
+ var $timespent_duration;
+ var $timespent_old_duration;
+ var $timespent_date;
+ var $timespent_fk_user;
+ var $timespent_note;
/**
- * Constructor
- *
- * @param DoliDB $DB Database handler
+ * Constructor
+ *
+ * @param DoliDB $DB Database handler
*/
function Task($DB)
{
@@ -77,116 +77,118 @@ class Task extends CommonObject
/**
- * \brief Create in database
- * \param user User that create
- * \param notrigger 0=launch triggers after, 1=disable triggers
- * \return int <0 if KO, Id of created object if OK
+ * Create into database
+ *
+ * @param User $user User that create
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, Id of created object if OK
*/
function create($user, $notrigger=0)
{
- global $conf, $langs;
+ global $conf, $langs;
- $error=0;
+ $error=0;
- // Clean parameters
- $this->label = trim($this->label);
- $this->description = trim($this->description);
+ // Clean parameters
+ $this->label = trim($this->label);
+ $this->description = trim($this->description);
- // Check parameters
- // Put here code to add control on parameters values
+ // Check parameters
+ // Put here code to add control on parameters values
// Insert request
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task (";
- $sql.= "fk_projet";
- $sql.= ", fk_task_parent";
- $sql.= ", label";
- $sql.= ", description";
- $sql.= ", datec";
- $sql.= ", fk_user_creat";
- $sql.= ", dateo";
- $sql.= ", datee";
- $sql.= ", progress";
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task (";
+ $sql.= "fk_projet";
+ $sql.= ", fk_task_parent";
+ $sql.= ", label";
+ $sql.= ", description";
+ $sql.= ", datec";
+ $sql.= ", fk_user_creat";
+ $sql.= ", dateo";
+ $sql.= ", datee";
+ $sql.= ", progress";
$sql.= ") VALUES (";
- $sql.= $this->fk_project;
- $sql.= ", ".$this->fk_task_parent;
- $sql.= ", '".$this->db->escape($this->label)."'";
- $sql.= ", '".$this->db->escape($this->description)."'";
- $sql.= ", '".$this->db->idate($this->date_c)."'";
- $sql.= ", ".$user->id;
- $sql.= ", ".($this->date_start!=''?"'".$this->db->idate($this->date_start)."'":'null');
- $sql.= ", ".($this->date_end!=''?"'".$this->db->idate($this->date_end)."'":'null');
- $sql.= ", ".($this->progress!=''?$this->progress:0);
- $sql.= ")";
+ $sql.= $this->fk_project;
+ $sql.= ", ".$this->fk_task_parent;
+ $sql.= ", '".$this->db->escape($this->label)."'";
+ $sql.= ", '".$this->db->escape($this->description)."'";
+ $sql.= ", '".$this->db->idate($this->date_c)."'";
+ $sql.= ", ".$user->id;
+ $sql.= ", ".($this->date_start!=''?"'".$this->db->idate($this->date_start)."'":'null');
+ $sql.= ", ".($this->date_end!=''?"'".$this->db->idate($this->date_end)."'":'null');
+ $sql.= ", ".($this->progress!=''?$this->progress:0);
+ $sql.= ")";
- $this->db->begin();
+ $this->db->begin();
- dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
+ dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
- if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
+ if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
- if (! $error)
+ if (! $error)
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
- if (! $notrigger)
- {
- // Call triggers
- include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
- $interface=new Interfaces($this->db);
- $result=$interface->run_triggers('TASK_CREATE',$this,$user,$langs,$conf);
- if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // End call triggers
- }
+ if (! $notrigger)
+ {
+ // Call triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($this->db);
+ $result=$interface->run_triggers('TASK_CREATE',$this,$user,$langs,$conf);
+ if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ // End call triggers
+ }
}
// Commit or rollback
if ($error)
- {
- foreach($this->errors as $errmsg)
- {
- dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
- $this->error.=($this->error?', '.$errmsg:$errmsg);
- }
- $this->db->rollback();
- return -1*$error;
- }
- else
- {
- $this->db->commit();
+ {
+ foreach($this->errors as $errmsg)
+ {
+ dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
+ $this->error.=($this->error?', '.$errmsg:$errmsg);
+ }
+ $this->db->rollback();
+ return -1*$error;
+ }
+ else
+ {
+ $this->db->commit();
return $this->id;
- }
+ }
}
/**
- * \brief Load object in memory from database
- * \param id id object
- * \return int <0 if KO, >0 if OK
+ * Load object in memory from database
+ *
+ * @param int $id Id object
+ * @return int <0 if KO, >0 if OK
*/
function fetch($id)
{
- global $langs;
+ global $langs;
$sql = "SELECT";
- $sql.= " t.rowid,";
- $sql.= " t.fk_projet,";
- $sql.= " t.fk_task_parent,";
- $sql.= " t.label,";
- $sql.= " t.description,";
- $sql.= " t.duration_effective,";
- $sql.= " t.dateo,";
- $sql.= " t.datee,";
- $sql.= " t.fk_user_creat,";
- $sql.= " t.fk_user_valid,";
- $sql.= " t.fk_statut,";
- $sql.= " t.progress,";
- $sql.= " t.priority,";
- $sql.= " t.note_private,";
- $sql.= " t.note_public";
+ $sql.= " t.rowid,";
+ $sql.= " t.fk_projet,";
+ $sql.= " t.fk_task_parent,";
+ $sql.= " t.label,";
+ $sql.= " t.description,";
+ $sql.= " t.duration_effective,";
+ $sql.= " t.dateo,";
+ $sql.= " t.datee,";
+ $sql.= " t.fk_user_creat,";
+ $sql.= " t.fk_user_valid,";
+ $sql.= " t.fk_statut,";
+ $sql.= " t.progress,";
+ $sql.= " t.priority,";
+ $sql.= " t.note_private,";
+ $sql.= " t.note_public";
$sql.= " FROM ".MAIN_DB_PREFIX."projet_task as t";
$sql.= " WHERE t.rowid = ".$id;
- dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
+ dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -196,21 +198,21 @@ class Task extends CommonObject
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
- $this->fk_project = $obj->fk_projet;
- $this->fk_task_parent = $obj->fk_task_parent;
- $this->label = $obj->label;
- $this->description = $obj->description;
- $this->duration_effective = $obj->duration_effective;
- $this->date_c = $this->db->jdate($obj->datec);
- $this->date_start = $this->db->jdate($obj->dateo);
- $this->date_end = $this->db->jdate($obj->datee);
- $this->fk_user_creat = $obj->fk_user_creat;
- $this->fk_user_valid = $obj->fk_user_valid;
- $this->fk_statut = $obj->fk_statut;
- $this->progress = $obj->progress;
- $this->priority = $obj->priority;
- $this->note_private = $obj->note_private;
- $this->note_public = $obj->note_public;
+ $this->fk_project = $obj->fk_projet;
+ $this->fk_task_parent = $obj->fk_task_parent;
+ $this->label = $obj->label;
+ $this->description = $obj->description;
+ $this->duration_effective = $obj->duration_effective;
+ $this->date_c = $this->db->jdate($obj->datec);
+ $this->date_start = $this->db->jdate($obj->dateo);
+ $this->date_end = $this->db->jdate($obj->datee);
+ $this->fk_user_creat = $obj->fk_user_creat;
+ $this->fk_user_valid = $obj->fk_user_valid;
+ $this->fk_statut = $obj->fk_statut;
+ $this->progress = $obj->progress;
+ $this->priority = $obj->priority;
+ $this->note_private = $obj->note_private;
+ $this->note_public = $obj->note_public;
}
$this->db->free($resql);
@@ -219,7 +221,7 @@ class Task extends CommonObject
}
else
{
- $this->error="Error ".$this->db->lasterror();
+ $this->error="Error ".$this->db->lasterror();
dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
return -1;
}
@@ -227,511 +229,524 @@ class Task extends CommonObject
/**
- * \brief Update database
- * \param user User that modify
- * \param notrigger 0=launch triggers after, 1=disable triggers
- * \return int <0 if KO, >0 if OK
+ * Update database
+ *
+ * @param User $user User that modify
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, >0 if OK
*/
function update($user=0, $notrigger=0)
{
- global $conf, $langs;
- $error=0;
+ global $conf, $langs;
+ $error=0;
- // Clean parameters
- if (isset($this->fk_project)) $this->fk_project=trim($this->fk_project);
- if (isset($this->fk_task_parent)) $this->fk_task_parent=trim($this->fk_task_parent);
- if (isset($this->label)) $this->label=trim($this->label);
- if (isset($this->description)) $this->description=trim($this->description);
- if (isset($this->duration_effective)) $this->duration_effective=trim($this->duration_effective);
+ // Clean parameters
+ if (isset($this->fk_project)) $this->fk_project=trim($this->fk_project);
+ if (isset($this->fk_task_parent)) $this->fk_task_parent=trim($this->fk_task_parent);
+ if (isset($this->label)) $this->label=trim($this->label);
+ if (isset($this->description)) $this->description=trim($this->description);
+ if (isset($this->duration_effective)) $this->duration_effective=trim($this->duration_effective);
- // Check parameters
- // Put here code to add control on parameters values
+ // Check parameters
+ // Put here code to add control on parameters values
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET";
- $sql.= " fk_projet=".(isset($this->fk_project)?$this->fk_project:"null").",";
- $sql.= " fk_task_parent=".(isset($this->fk_task_parent)?$this->fk_task_parent:"null").",";
- $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
- $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").",";
- $sql.= " duration_effective=".(isset($this->duration_effective)?$this->duration_effective:"null").",";
- $sql.= " dateo=".($this->date_start!=''?$this->db->idate($this->date_start):'null').",";
- $sql.= " datee=".($this->date_end!=''?$this->db->idate($this->date_end):'null').",";
- $sql.= " progress=".$this->progress;
+ $sql.= " fk_projet=".(isset($this->fk_project)?$this->fk_project:"null").",";
+ $sql.= " fk_task_parent=".(isset($this->fk_task_parent)?$this->fk_task_parent:"null").",";
+ $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
+ $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").",";
+ $sql.= " duration_effective=".(isset($this->duration_effective)?$this->duration_effective:"null").",";
+ $sql.= " dateo=".($this->date_start!=''?$this->db->idate($this->date_start):'null').",";
+ $sql.= " datee=".($this->date_end!=''?$this->db->idate($this->date_end):'null').",";
+ $sql.= " progress=".$this->progress;
$sql.= " WHERE rowid=".$this->id;
- $this->db->begin();
+ $this->db->begin();
- dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
+ dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
- if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
+ if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
- if (! $error)
- {
- if (! $notrigger)
- {
- // Call triggers
- include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
- $interface=new Interfaces($this->db);
- $result=$interface->run_triggers('TASK_MODIFY',$this,$user,$langs,$conf);
- if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // End call triggers
- }
- }
+ if (! $error)
+ {
+ if (! $notrigger)
+ {
+ // Call triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($this->db);
+ $result=$interface->run_triggers('TASK_MODIFY',$this,$user,$langs,$conf);
+ if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ // End call triggers
+ }
+ }
// Commit or rollback
- if ($error)
- {
- foreach($this->errors as $errmsg)
- {
- dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
- $this->error.=($this->error?', '.$errmsg:$errmsg);
- }
- $this->db->rollback();
- return -1*$error;
- }
- else
- {
- $this->db->commit();
- return 1;
- }
+ if ($error)
+ {
+ foreach($this->errors as $errmsg)
+ {
+ dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
+ $this->error.=($this->error?', '.$errmsg:$errmsg);
+ }
+ $this->db->rollback();
+ return -1*$error;
+ }
+ else
+ {
+ $this->db->commit();
+ return 1;
+ }
}
- /**
- * \brief Delete object in database
- * \param user User that delete
- * \param notrigger 0=launch triggers after, 1=disable triggers
- * \return int <0 if KO, >0 if OK
- */
- function delete($user, $notrigger=0)
- {
- global $conf, $langs;
+ /**
+ * Delete object in database
+ *
+ * @param User $user User that delete
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ function delete($user, $notrigger=0)
+ {
+ global $conf, $langs;
- $error=0;
+ $error=0;
- $this->db->begin();
+ $this->db->begin();
- if ($this->hasChildren() > 0)
- {
- dol_syslog(get_class($this)."::delete Can't delete record as it has some child", LOG_WARNING);
- $this->error='ErrorRecordHasChildren';
- $this->db->rollback();
- return 0;
- }
+ if ($this->hasChildren() > 0)
+ {
+ dol_syslog(get_class($this)."::delete Can't delete record as it has some child", LOG_WARNING);
+ $this->error='ErrorRecordHasChildren';
+ $this->db->rollback();
+ return 0;
+ }
- if (! $error)
- {
- // Delete linked contacts
- $res = $this->delete_linked_contact();
- if ($res < 0)
- {
- $this->error='ErrorFailToDeleteLinkedContact';
- //$error++;
- $this->db->rollback();
- return 0;
- }
- }
+ if (! $error)
+ {
+ // Delete linked contacts
+ $res = $this->delete_linked_contact();
+ if ($res < 0)
+ {
+ $this->error='ErrorFailToDeleteLinkedContact';
+ //$error++;
+ $this->db->rollback();
+ return 0;
+ }
+ }
- // Delete rang of line
- //$this->delRangOfLine($this->id, $this->element);
+ // Delete rang of line
+ //$this->delRangOfLine($this->id, $this->element);
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task";
- $sql.= " WHERE rowid=".$this->id;
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task";
+ $sql.= " WHERE rowid=".$this->id;
- dol_syslog(get_class($this)."::delete sql=".$sql);
- $resql = $this->db->query($sql);
- if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
+ dol_syslog(get_class($this)."::delete sql=".$sql);
+ $resql = $this->db->query($sql);
+ if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
- if (! $error)
- {
- if (! $notrigger)
- {
- // Call triggers
- include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
- $interface=new Interfaces($this->db);
- $result=$interface->run_triggers('TASK_DELETE',$this,$user,$langs,$conf);
- if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // End call triggers
- }
- }
+ if (! $error)
+ {
+ if (! $notrigger)
+ {
+ // Call triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($this->db);
+ $result=$interface->run_triggers('TASK_DELETE',$this,$user,$langs,$conf);
+ if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ // End call triggers
+ }
+ }
// Commit or rollback
- if ($error)
- {
- foreach($this->errors as $errmsg)
- {
- dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
- $this->error.=($this->error?', '.$errmsg:$errmsg);
- }
- $this->db->rollback();
- return -1*$error;
- }
- else
- {
- $this->db->commit();
- return 1;
- }
- }
-
- /**
- * \brief Return nb of children
- * \return <0 if KO, 0 if no children, >0 if OK
- */
- function hasChildren()
- {
- $ret=0;
-
- $sql = "SELECT COUNT(*) as nb";
- $sql.= " FROM ".MAIN_DB_PREFIX."projet_task";
- $sql.= " WHERE fk_task_parent=".$this->id;
-
- dol_syslog(get_class($this)."::hasChildren sql=".$sql, LOG_DEBUG);
- $resql = $this->db->query($sql);
- if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
- else
- {
- $obj=$this->db->fetch_object($resql);
- if ($obj) $ret=$obj->nb;
- }
-
- if (! $error)
- {
- return $ret;
- }
- else
- {
- return -1;
- }
- }
-
-
- /**
- * \brief Renvoie nom clicable (avec eventuellement le picto)
- * \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
- * \param option Sur quoi pointe le lien
- * \return string Chaine avec URL
- */
- function getNomUrl($withpicto=0,$option='')
- {
- global $langs;
-
- $result='';
-
- $lien = '';
- $lienfin='';
-
- $picto='projecttask';
-
- $label=$langs->trans("ShowTask").': '.$this->ref.($this->label?' - '.$this->label:'');
-
- if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
- if ($withpicto && $withpicto != 2) $result.=' ';
- if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin;
- return $result;
- }
-
- /**
- * \brief Initialise object with example values
- * \remarks id must be 0 if object instance is a specimen.
- */
- function initAsSpecimen()
- {
- $this->id=0;
-
- $this->fk_projet='';
- $this->fk_task_parent='';
- $this->title='';
- $this->duration_effective='';
- $this->fk_user_creat='';
- $this->statut='';
- $this->note='';
- }
-
- /**
- * Return list of tasks for all projects or for one particular project
- * Sort order is on project, TODO then of position of task, and last on title of first level task
- * @param usert Object user to limit tasks affected to a particular user
- * @param userp Object user to limit projects of a particular user and public projects
- * @param projectid Project id
- * @param socid Third party id
- * @param mode 0=Return list of tasks and their projects, 1=Return projects and tasks if exists
- * @return array Array of tasks
- */
- function getTasksArray($usert=0, $userp=0, $projectid=0, $socid=0, $mode=0)
- {
- global $conf;
-
- $tasks = array();
-
- //print $usert.'-'.$userp.'-'.$projectid.'-'.$socid.'-'.$mode.'
';
-
- // List of tasks (does not care about permissions. Filtering will be done later)
- $sql = "SELECT p.rowid as projectid, p.ref, p.title as plabel, p.public,";
- $sql.= " t.rowid as taskid, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress,";
- $sql.= " t.dateo as date_start, t.datee as date_end";
- if ($mode == 0)
- {
- $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
- $sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
- $sql.= " WHERE t.fk_projet = p.rowid";
- $sql.= " AND p.entity = ".$conf->entity;
- if ($socid) $sql.= " AND p.fk_soc = ".$socid;
- if ($projectid) $sql.= " AND p.rowid in (".$projectid.")";
- }
- if ($mode == 1)
- {
- $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t on t.fk_projet = p.rowid";
- $sql.= " WHERE p.entity = ".$conf->entity;
- if ($socid) $sql.= " AND p.fk_soc = ".$socid;
- if ($projectid) $sql.= " AND p.rowid in (".$projectid.")";
- }
- $sql.= " ORDER BY p.ref, t.label";
-
- //print $sql;
- dol_syslog("Task::getTasksArray sql=".$sql, LOG_DEBUG);
- $resql = $this->db->query($sql);
- if ($resql)
- {
- $num = $this->db->num_rows($resql);
- $i = 0;
- // Loop on each record found, so each couple (project id, task id)
- while ($i < $num)
- {
- $error=0;
-
- $obj = $this->db->fetch_object($resql);
-
- if ((! $obj->public) && (is_object($userp))) // If not public project and we ask a filter on project owned by a user
- {
- if (! $this->getUserRolesForProjectsOrTasks($userp, 0, $obj->projectid, 0))
- {
- $error++;
- }
- }
- if (is_object($usert)) // If we ask a filter on a user affected to a task
- {
- if (! $this->getUserRolesForProjectsOrTasks(0, $usert, $obj->projectid, $obj->taskid))
- {
- $error++;
- }
- }
-
- if (! $error)
- {
- $tasks[$i]->id = $obj->taskid;
- $tasks[$i]->ref = $obj->taskid;
- $tasks[$i]->fk_project = $obj->projectid;
- $tasks[$i]->projectref = $obj->ref;
- $tasks[$i]->projectlabel = $obj->plabel;
- $tasks[$i]->label = $obj->label;
- $tasks[$i]->description = $obj->description;
- $tasks[$i]->fk_parent = $obj->fk_task_parent;
- $tasks[$i]->duration = $obj->duration_effective;
- $tasks[$i]->progress = $obj->progress;
- $tasks[$i]->public = $obj->public;
- $tasks[$i]->date_start = $this->db->jdate($obj->date_start);
- $tasks[$i]->date_end = $this->db->jdate($obj->date_end);
- }
-
- $i++;
- }
- $this->db->free($resql);
- }
- else
- {
- dol_print_error($this->db);
- }
-
- return $tasks;
- }
-
- /**
- * Return list of roles for a user for each projects or each tasks (or a particular project or task)
- * @param userp Return roles on project for this internal user (task id can't be defined)
- * @param usert Return roles on task for this internal user
- * @param projectid Project id list separated with , to filter on project
- * @param taskid Task id to filter on a task
- * @return array Array (projectid => 'list of roles for project' or taskid => 'list of roles for task')
- */
- function getUserRolesForProjectsOrTasks($userp,$usert,$projectid='',$taskid=0)
- {
- $arrayroles = array();
-
- dol_syslog("Task::getUserRolesForProjectsOrTasks userp=".is_object($userp)." usert=".is_object($usert)." projectid=".$projectid." taskid=".$taskid);
-
- // We want role of user for a projet or role of user for a task. Both are not possible.
- if (empty($userp) && empty($usert))
- {
- $this->error="CallWithWrongParameters";
- return -1;
- }
- if (! empty($userp) && ! empty($usert))
- {
- $this->error="CallWithWrongParameters";
- return -1;
- }
-
- /* Liste des taches et role sur les projets ou taches */
- $sql = "SELECT pt.rowid as pid, ec.element_id, ctc.code, ctc.source";
- if ($userp) $sql.= " FROM ".MAIN_DB_PREFIX."projet as pt";
- if ($usert) $sql.= " FROM ".MAIN_DB_PREFIX."projet_task as pt";
- $sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
- $sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
- $sql.= " WHERE pt.rowid = ec.element_id";
- if ($userp) $sql.= " AND ctc.element = 'project'";
- if ($usert) $sql.= " AND ctc.element = 'project_task'";
- $sql.= " AND ctc.rowid = ec.fk_c_type_contact";
- if ($userp) $sql.= " AND ec.fk_socpeople = ".$userp->id;
- if ($usert) $sql.= " AND ec.fk_socpeople = ".$usert->id;
- $sql.= " AND ec.statut = 4";
- $sql.= " AND ctc.source = 'internal'";
- if ($projectid)
- {
- if ($userp) $sql.= " AND pt.rowid in (".$projectid.")";
- if ($usert) $sql.= " AND pt.fk_projet in (".$projectid.")";
- }
- if ($taskid)
- {
- if ($userp) $sql.= " ERROR SHOULD NOT HAPPENS";
- if ($usert) $sql.= " AND pt.rowid = ".$taskid;
- }
- //print $sql;
-
- dol_syslog("Task::getUserRolesForProjectsOrTasks sql=".$sql);
- $resql = $this->db->query($sql);
- if ($resql)
- {
- $num = $this->db->num_rows($resql);
- $i = 0;
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- if (empty($arrayroles[$obj->pid])) $arrayroles[$obj->pid] = $obj->code;
- else $arrayroles[$obj->pid].=','.$obj->code;
- $i++;
- }
- $this->db->free($resql);
- }
- else
- {
- dol_print_error($this->db);
- }
-
- return $arrayroles;
- }
-
-
- /**
- * \brief Return list of id of contacts of task
- * \return array Array of id of contacts
- */
- function getListContactId($source='internal')
- {
- $contactAlreadySelected = array();
- $tab = $this->liste_contact(-1,$source);
- //var_dump($tab);
- $num=count($tab);
- $i = 0;
- while ($i < $num)
- {
- if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid'];
- else $contactAlreadySelected[$i] = $tab[$i]['id'];
- $i++;
- }
- return $contactAlreadySelected;
- }
-
-
- /**
- * \brief Add time spent
- * \param user user id
- * \param notrigger 0=launch triggers after, 1=disable triggers
- */
- function addTimeSpent($user, $notrigger=0)
- {
- global $conf,$langs;
-
- $ret = 0;
-
- // Clean parameters
- if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note);
-
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (";
- $sql.= "fk_task";
- $sql.= ", task_date";
- $sql.= ", task_duration";
- $sql.= ", fk_user";
- $sql.= ", note";
- $sql.= ") VALUES (";
- $sql.= $this->id;
- $sql.= ", '".$this->db->idate($this->timespent_date)."'";
- $sql.= ", ".$this->timespent_duration;
- $sql.= ", ".$this->timespent_fk_user;
- $sql.= ", ".(isset($this->timespent_note)?"'".$this->db->escape($this->timespent_note)."'":"null");
- $sql.= ")";
-
- dol_syslog(get_class($this)."::addTimeSpent sql=".$sql, LOG_DEBUG);
- if ($this->db->query($sql) )
- {
- $task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_time");
- $ret = $task_id;
-
- if (! $notrigger)
- {
- // Call triggers
- include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
- $interface=new Interfaces($this->db);
- $result=$interface->run_triggers('TASK_TIMESPENT_CREATE',$this,$user,$langs,$conf);
- if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // End call triggers
- }
- }
- else
- {
- $this->error=$this->db->lasterror();
- dol_syslog(get_class($this)."::addTimeSpent error -1 ".$this->error,LOG_ERR);
- $ret = -1;
- }
-
- if ($ret >= 0)
- {
- $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
- $sql.= " SET duration_effective = duration_effective + '".price2num($this->timespent_duration)."'";
- $sql.= " WHERE rowid = ".$this->id;
-
- dol_syslog(get_class($this)."::addTimeSpent sql=".$sql, LOG_DEBUG);
- if (! $this->db->query($sql) )
- {
- $this->error=$this->db->lasterror();
- dol_syslog(get_class($this)."::addTimeSpent error -2 ".$this->error, LOG_ERR);
- $ret = -2;
- }
- }
-
- return $ret;
- }
+ if ($error)
+ {
+ foreach($this->errors as $errmsg)
+ {
+ dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
+ $this->error.=($this->error?', '.$errmsg:$errmsg);
+ }
+ $this->db->rollback();
+ return -1*$error;
+ }
+ else
+ {
+ $this->db->commit();
+ return 1;
+ }
+ }
/**
- * \brief Load object in memory from database
- * \param id id object
- * \return int <0 if KO, >0 if OK
+ * Return nb of children
+ *
+ * @return int <0 if KO, 0 if no children, >0 if OK
+ */
+ function hasChildren()
+ {
+ $ret=0;
+
+ $sql = "SELECT COUNT(*) as nb";
+ $sql.= " FROM ".MAIN_DB_PREFIX."projet_task";
+ $sql.= " WHERE fk_task_parent=".$this->id;
+
+ dol_syslog(get_class($this)."::hasChildren sql=".$sql, LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
+ else
+ {
+ $obj=$this->db->fetch_object($resql);
+ if ($obj) $ret=$obj->nb;
+ }
+
+ if (! $error)
+ {
+ return $ret;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
+
+ /**
+ * Renvoie nom clicable (avec eventuellement le picto)
+ *
+ * @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
+ * @param int $option Sur quoi pointe le lien
+ * @return string Chaine avec URL
+ */
+ function getNomUrl($withpicto=0,$option='')
+ {
+ global $langs;
+
+ $result='';
+
+ $lien = '';
+ $lienfin='';
+
+ $picto='projecttask';
+
+ $label=$langs->trans("ShowTask").': '.$this->ref.($this->label?' - '.$this->label:'');
+
+ if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
+ if ($withpicto && $withpicto != 2) $result.=' ';
+ if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin;
+ return $result;
+ }
+
+ /**
+ * Initialise object with example values
+ * id must be 0 if object instance is a specimen.
+ *
+ * @return void
+ */
+ function initAsSpecimen()
+ {
+ $this->id=0;
+
+ $this->fk_projet='';
+ $this->fk_task_parent='';
+ $this->title='';
+ $this->duration_effective='';
+ $this->fk_user_creat='';
+ $this->statut='';
+ $this->note='';
+ }
+
+ /**
+ * Return list of tasks for all projects or for one particular project
+ * Sort order is on project, TODO then of position of task, and last on title of first level task
+ *
+ * @param User $usert Object user to limit tasks affected to a particular user
+ * @param User $userp Object user to limit projects of a particular user and public projects
+ * @param int $projectid Project id
+ * @param int $socid Third party id
+ * @param int $mode 0=Return list of tasks and their projects, 1=Return projects and tasks if exists
+ * @return array Array of tasks
+ */
+ function getTasksArray($usert=0, $userp=0, $projectid=0, $socid=0, $mode=0)
+ {
+ global $conf;
+
+ $tasks = array();
+
+ //print $usert.'-'.$userp.'-'.$projectid.'-'.$socid.'-'.$mode.'
';
+
+ // List of tasks (does not care about permissions. Filtering will be done later)
+ $sql = "SELECT p.rowid as projectid, p.ref, p.title as plabel, p.public,";
+ $sql.= " t.rowid as taskid, t.label, t.description, t.fk_task_parent, t.duration_effective, t.progress,";
+ $sql.= " t.dateo as date_start, t.datee as date_end";
+ if ($mode == 0)
+ {
+ $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
+ $sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
+ $sql.= " WHERE t.fk_projet = p.rowid";
+ $sql.= " AND p.entity = ".$conf->entity;
+ if ($socid) $sql.= " AND p.fk_soc = ".$socid;
+ if ($projectid) $sql.= " AND p.rowid in (".$projectid.")";
+ }
+ if ($mode == 1)
+ {
+ $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t on t.fk_projet = p.rowid";
+ $sql.= " WHERE p.entity = ".$conf->entity;
+ if ($socid) $sql.= " AND p.fk_soc = ".$socid;
+ if ($projectid) $sql.= " AND p.rowid in (".$projectid.")";
+ }
+ $sql.= " ORDER BY p.ref, t.label";
+
+ //print $sql;
+ dol_syslog("Task::getTasksArray sql=".$sql, LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ // Loop on each record found, so each couple (project id, task id)
+ while ($i < $num)
+ {
+ $error=0;
+
+ $obj = $this->db->fetch_object($resql);
+
+ if ((! $obj->public) && (is_object($userp))) // If not public project and we ask a filter on project owned by a user
+ {
+ if (! $this->getUserRolesForProjectsOrTasks($userp, 0, $obj->projectid, 0))
+ {
+ $error++;
+ }
+ }
+ if (is_object($usert)) // If we ask a filter on a user affected to a task
+ {
+ if (! $this->getUserRolesForProjectsOrTasks(0, $usert, $obj->projectid, $obj->taskid))
+ {
+ $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ $tasks[$i]->id = $obj->taskid;
+ $tasks[$i]->ref = $obj->taskid;
+ $tasks[$i]->fk_project = $obj->projectid;
+ $tasks[$i]->projectref = $obj->ref;
+ $tasks[$i]->projectlabel = $obj->plabel;
+ $tasks[$i]->label = $obj->label;
+ $tasks[$i]->description = $obj->description;
+ $tasks[$i]->fk_parent = $obj->fk_task_parent;
+ $tasks[$i]->duration = $obj->duration_effective;
+ $tasks[$i]->progress = $obj->progress;
+ $tasks[$i]->public = $obj->public;
+ $tasks[$i]->date_start = $this->db->jdate($obj->date_start);
+ $tasks[$i]->date_end = $this->db->jdate($obj->date_end);
+ }
+
+ $i++;
+ }
+ $this->db->free($resql);
+ }
+ else
+ {
+ dol_print_error($this->db);
+ }
+
+ return $tasks;
+ }
+
+ /**
+ * Return list of roles for a user for each projects or each tasks (or a particular project or task).
+ *
+ * @param User $userp Return roles on project for this internal user (task id can't be defined)
+ * @param User $usert Return roles on task for this internal user
+ * @param int $projectid Project id list separated with , to filter on project
+ * @param int $taskid Task id to filter on a task
+ * @return array Array (projectid => 'list of roles for project' or taskid => 'list of roles for task')
+ */
+ function getUserRolesForProjectsOrTasks($userp,$usert,$projectid='',$taskid=0)
+ {
+ $arrayroles = array();
+
+ dol_syslog("Task::getUserRolesForProjectsOrTasks userp=".is_object($userp)." usert=".is_object($usert)." projectid=".$projectid." taskid=".$taskid);
+
+ // We want role of user for a projet or role of user for a task. Both are not possible.
+ if (empty($userp) && empty($usert))
+ {
+ $this->error="CallWithWrongParameters";
+ return -1;
+ }
+ if (! empty($userp) && ! empty($usert))
+ {
+ $this->error="CallWithWrongParameters";
+ return -1;
+ }
+
+ /* Liste des taches et role sur les projets ou taches */
+ $sql = "SELECT pt.rowid as pid, ec.element_id, ctc.code, ctc.source";
+ if ($userp) $sql.= " FROM ".MAIN_DB_PREFIX."projet as pt";
+ if ($usert) $sql.= " FROM ".MAIN_DB_PREFIX."projet_task as pt";
+ $sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
+ $sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
+ $sql.= " WHERE pt.rowid = ec.element_id";
+ if ($userp) $sql.= " AND ctc.element = 'project'";
+ if ($usert) $sql.= " AND ctc.element = 'project_task'";
+ $sql.= " AND ctc.rowid = ec.fk_c_type_contact";
+ if ($userp) $sql.= " AND ec.fk_socpeople = ".$userp->id;
+ if ($usert) $sql.= " AND ec.fk_socpeople = ".$usert->id;
+ $sql.= " AND ec.statut = 4";
+ $sql.= " AND ctc.source = 'internal'";
+ if ($projectid)
+ {
+ if ($userp) $sql.= " AND pt.rowid in (".$projectid.")";
+ if ($usert) $sql.= " AND pt.fk_projet in (".$projectid.")";
+ }
+ if ($taskid)
+ {
+ if ($userp) $sql.= " ERROR SHOULD NOT HAPPENS";
+ if ($usert) $sql.= " AND pt.rowid = ".$taskid;
+ }
+ //print $sql;
+
+ dol_syslog("Task::getUserRolesForProjectsOrTasks sql=".$sql);
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+ if (empty($arrayroles[$obj->pid])) $arrayroles[$obj->pid] = $obj->code;
+ else $arrayroles[$obj->pid].=','.$obj->code;
+ $i++;
+ }
+ $this->db->free($resql);
+ }
+ else
+ {
+ dol_print_error($this->db);
+ }
+
+ return $arrayroles;
+ }
+
+
+ /**
+ * Return list of id of contacts of task
+ *
+ * @param string $source Source
+ * @return array Array of id of contacts
+ */
+ function getListContactId($source='internal')
+ {
+ $contactAlreadySelected = array();
+ $tab = $this->liste_contact(-1,$source);
+ //var_dump($tab);
+ $num=count($tab);
+ $i = 0;
+ while ($i < $num)
+ {
+ if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid'];
+ else $contactAlreadySelected[$i] = $tab[$i]['id'];
+ $i++;
+ }
+ return $contactAlreadySelected;
+ }
+
+
+ /**
+ * Add time spent
+ *
+ * @param User $user user id
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return void
+ */
+ function addTimeSpent($user, $notrigger=0)
+ {
+ global $conf,$langs;
+
+ $ret = 0;
+
+ // Clean parameters
+ if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note);
+
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (";
+ $sql.= "fk_task";
+ $sql.= ", task_date";
+ $sql.= ", task_duration";
+ $sql.= ", fk_user";
+ $sql.= ", note";
+ $sql.= ") VALUES (";
+ $sql.= $this->id;
+ $sql.= ", '".$this->db->idate($this->timespent_date)."'";
+ $sql.= ", ".$this->timespent_duration;
+ $sql.= ", ".$this->timespent_fk_user;
+ $sql.= ", ".(isset($this->timespent_note)?"'".$this->db->escape($this->timespent_note)."'":"null");
+ $sql.= ")";
+
+ dol_syslog(get_class($this)."::addTimeSpent sql=".$sql, LOG_DEBUG);
+ if ($this->db->query($sql) )
+ {
+ $task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_time");
+ $ret = $task_id;
+
+ if (! $notrigger)
+ {
+ // Call triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($this->db);
+ $result=$interface->run_triggers('TASK_TIMESPENT_CREATE',$this,$user,$langs,$conf);
+ if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ // End call triggers
+ }
+ }
+ else
+ {
+ $this->error=$this->db->lasterror();
+ dol_syslog(get_class($this)."::addTimeSpent error -1 ".$this->error,LOG_ERR);
+ $ret = -1;
+ }
+
+ if ($ret >= 0)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
+ $sql.= " SET duration_effective = duration_effective + '".price2num($this->timespent_duration)."'";
+ $sql.= " WHERE rowid = ".$this->id;
+
+ dol_syslog(get_class($this)."::addTimeSpent sql=".$sql, LOG_DEBUG);
+ if (! $this->db->query($sql) )
+ {
+ $this->error=$this->db->lasterror();
+ dol_syslog(get_class($this)."::addTimeSpent error -2 ".$this->error, LOG_ERR);
+ $ret = -2;
+ }
+ }
+
+ return $ret;
+ }
+
+ /**
+ * Load object in memory from database
+ *
+ * @param int $id Id object
+ * @return int <0 if KO, >0 if OK
*/
function fetchTimeSpent($id)
{
- global $langs;
+ global $langs;
$sql = "SELECT";
- $sql.= " t.rowid,";
- $sql.= " t.fk_task,";
- $sql.= " t.task_date,";
- $sql.= " t.task_duration,";
- $sql.= " t.fk_user,";
- $sql.= " t.note";
+ $sql.= " t.rowid,";
+ $sql.= " t.fk_task,";
+ $sql.= " t.task_date,";
+ $sql.= " t.task_duration,";
+ $sql.= " t.fk_user,";
+ $sql.= " t.note";
$sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
$sql.= " WHERE t.rowid = ".$id;
- dol_syslog(get_class($this)."::fetchTimeSpent sql=".$sql, LOG_DEBUG);
+ dol_syslog(get_class($this)."::fetchTimeSpent sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -740,11 +755,11 @@ class Task extends CommonObject
$obj = $this->db->fetch_object($resql);
$this->timespent_id = $obj->rowid;
- $this->id = $obj->fk_task;
- $this->timespent_date = $obj->task_date;
- $this->timespent_duration = $obj->task_duration;
- $this->timespent_user = $obj->fk_user;
- $this->timespent_note = $obj->note;
+ $this->id = $obj->fk_task;
+ $this->timespent_date = $obj->task_date;
+ $this->timespent_duration = $obj->task_duration;
+ $this->timespent_user = $obj->fk_user;
+ $this->timespent_note = $obj->note;
}
$this->db->free($resql);
@@ -753,142 +768,145 @@ class Task extends CommonObject
}
else
{
- $this->error="Error ".$this->db->lasterror();
+ $this->error="Error ".$this->db->lasterror();
dol_syslog(get_class($this)."::fetchTimeSpent ".$this->error, LOG_ERR);
return -1;
}
}
- /**
- * \brief Update time spent
- * \param user User id
- * \param notrigger 0=launch triggers after, 1=disable triggers
- */
- function updateTimeSpent($user, $notrigger=0)
- {
- $ret = 0;
+ /**
+ * Update time spent
+ *
+ * @param User $user User id
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ function updateTimeSpent($user, $notrigger=0)
+ {
+ $ret = 0;
- // Clean parameters
- if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note);
+ // Clean parameters
+ if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note);
- $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time SET";
- $sql.= " task_date = '".$this->db->idate($this->timespent_date)."',";
- $sql.= " task_duration = ".$this->timespent_duration.",";
- $sql.= " fk_user = ".$this->timespent_fk_user.",";
- $sql.= " note = ".(isset($this->timespent_note)?"'".$this->db->escape($this->timespent_note)."'":"null");
- $sql.= " WHERE rowid = ".$this->timespent_id;
+ $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time SET";
+ $sql.= " task_date = '".$this->db->idate($this->timespent_date)."',";
+ $sql.= " task_duration = ".$this->timespent_duration.",";
+ $sql.= " fk_user = ".$this->timespent_fk_user.",";
+ $sql.= " note = ".(isset($this->timespent_note)?"'".$this->db->escape($this->timespent_note)."'":"null");
+ $sql.= " WHERE rowid = ".$this->timespent_id;
- dol_syslog(get_class($this)."::updateTimeSpent sql=".$sql, LOG_DEBUG);
- if ($this->db->query($sql) )
- {
- if (! $notrigger)
- {
- // Call triggers
- include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
- $interface=new Interfaces($this->db);
- $result=$interface->run_triggers('TASK_TIMESPENT_MODIFY',$this,$user,$langs,$conf);
- if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // End call triggers
- }
- $ret = 1;
- }
- else
- {
- $this->error=$this->db->lasterror();
- dol_syslog(get_class($this)."::updateTimeSpent error -1 ".$this->error,LOG_ERR);
- $ret = -1;
- }
+ dol_syslog(get_class($this)."::updateTimeSpent sql=".$sql, LOG_DEBUG);
+ if ($this->db->query($sql) )
+ {
+ if (! $notrigger)
+ {
+ // Call triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($this->db);
+ $result=$interface->run_triggers('TASK_TIMESPENT_MODIFY',$this,$user,$langs,$conf);
+ if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ // End call triggers
+ }
+ $ret = 1;
+ }
+ else
+ {
+ $this->error=$this->db->lasterror();
+ dol_syslog(get_class($this)."::updateTimeSpent error -1 ".$this->error,LOG_ERR);
+ $ret = -1;
+ }
- if ($ret == 1 && ($this->timespent_old_duration != $this->timespent_duration))
- {
- $newDuration = $this->timespent_duration - $this->timespent_old_duration;
+ if ($ret == 1 && ($this->timespent_old_duration != $this->timespent_duration))
+ {
+ $newDuration = $this->timespent_duration - $this->timespent_old_duration;
- $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
- $sql.= " SET duration_effective = duration_effective + '".$newDuration."'";
- $sql.= " WHERE rowid = ".$this->id;
+ $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
+ $sql.= " SET duration_effective = duration_effective + '".$newDuration."'";
+ $sql.= " WHERE rowid = ".$this->id;
- dol_syslog(get_class($this)."::updateTimeSpent sql=".$sql, LOG_DEBUG);
- if (! $this->db->query($sql) )
- {
- $this->error=$this->db->lasterror();
- dol_syslog(get_class($this)."::addTimeSpent error -2 ".$this->error, LOG_ERR);
- $ret = -2;
- }
- }
+ dol_syslog(get_class($this)."::updateTimeSpent sql=".$sql, LOG_DEBUG);
+ if (! $this->db->query($sql) )
+ {
+ $this->error=$this->db->lasterror();
+ dol_syslog(get_class($this)."::addTimeSpent error -2 ".$this->error, LOG_ERR);
+ $ret = -2;
+ }
+ }
- return $ret;
- }
+ return $ret;
+ }
- /**
- * \brief Delete time spent
- * \param user User that delete
- * \param notrigger 0=launch triggers after, 1=disable triggers
- * \return int <0 if KO, >0 if OK
- */
- function delTimeSpent($user, $notrigger=0)
- {
- global $conf, $langs;
+ /**
+ * Delete time spent
+ *
+ * @param User $user User that delete
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ function delTimeSpent($user, $notrigger=0)
+ {
+ global $conf, $langs;
- $error=0;
+ $error=0;
- $this->db->begin();
+ $this->db->begin();
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task_time";
- $sql.= " WHERE rowid = ".$this->timespent_id;
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task_time";
+ $sql.= " WHERE rowid = ".$this->timespent_id;
- dol_syslog(get_class($this)."::delTimeSpent sql=".$sql);
- $resql = $this->db->query($sql);
- if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
+ dol_syslog(get_class($this)."::delTimeSpent sql=".$sql);
+ $resql = $this->db->query($sql);
+ if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
- if (! $error)
- {
- if (! $notrigger)
- {
- // Call triggers
- include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
- $interface=new Interfaces($this->db);
- $result=$interface->run_triggers('TASK_TIMESPENT_DELETE',$this,$user,$langs,$conf);
- if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // End call triggers
- }
- }
+ if (! $error)
+ {
+ if (! $notrigger)
+ {
+ // Call triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($this->db);
+ $result=$interface->run_triggers('TASK_TIMESPENT_DELETE',$this,$user,$langs,$conf);
+ if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ // End call triggers
+ }
+ }
- if (! $error)
- {
- $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
- $sql.= " SET duration_effective = duration_effective - '".$this->timespent_duration."'";
- $sql.= " WHERE rowid = ".$this->id;
+ if (! $error)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
+ $sql.= " SET duration_effective = duration_effective - '".$this->timespent_duration."'";
+ $sql.= " WHERE rowid = ".$this->id;
- dol_syslog(get_class($this)."::delTimeSpent sql=".$sql, LOG_DEBUG);
- if ($this->db->query($sql) )
- {
- $result = 0;
- }
- else
- {
- $this->error=$this->db->lasterror();
- dol_syslog(get_class($this)."::addTimeSpent error -3 ".$this->error, LOG_ERR);
- $result = -2;
- }
- }
+ dol_syslog(get_class($this)."::delTimeSpent sql=".$sql, LOG_DEBUG);
+ if ($this->db->query($sql) )
+ {
+ $result = 0;
+ }
+ else
+ {
+ $this->error=$this->db->lasterror();
+ dol_syslog(get_class($this)."::addTimeSpent error -3 ".$this->error, LOG_ERR);
+ $result = -2;
+ }
+ }
// Commit or rollback
- if ($error)
- {
- foreach($this->errors as $errmsg)
- {
- dol_syslog(get_class($this)."::delTimeSpent ".$errmsg, LOG_ERR);
- $this->error.=($this->error?', '.$errmsg:$errmsg);
- }
- $this->db->rollback();
- return -1*$error;
- }
- else
- {
- $this->db->commit();
- return 1;
- }
- }
+ if ($error)
+ {
+ foreach($this->errors as $errmsg)
+ {
+ dol_syslog(get_class($this)."::delTimeSpent ".$errmsg, LOG_ERR);
+ $this->error.=($this->error?', '.$errmsg:$errmsg);
+ }
+ $this->db->rollback();
+ return -1*$error;
+ }
+ else
+ {
+ $this->db->commit();
+ return 1;
+ }
+ }
}
?>
\ No newline at end of file