diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index ec180704563..2a6a1af6ac3 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -534,6 +534,40 @@ class Task extends CommonObject return -1; } } + + /** + * Return nb of time spent + * + * @return int <0 if KO, 0 if no children, >0 if OK + */ + function hasTimeSpent() + { + $error=0; + $ret=0; + + $sql = "SELECT COUNT(*) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time"; + $sql.= " WHERE fk_task=".$this->id; + + dol_syslog(get_class($this)."::hasTimeSpent", 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; + $this->db->free($resql); + } + + if (! $error) + { + return $ret; + } + else + { + return -1; + } + } /** diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index 3c6f9bb7e6e..63c6b6208c3 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -551,7 +551,7 @@ if ($id > 0 || ! empty($ref)) } // Delete - if ($user->rights->projet->supprimer && ! $object->hasChildren()) + if ($user->rights->projet->supprimer && ! $object->hasChildren() && ! $object->hasTimeSpent()) { print ''.$langs->trans('Delete').''; }