diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 2a77de4f552..e694b3c7bfd 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -187,11 +187,12 @@ class Task extends CommonObject /** * Load object in memory from database * - * @param int $id Id object - * @param int $ref ref object - * @return int <0 if KO, 0 if not found, >0 if OK + * @param int $id Id object + * @param int $ref ref object + * @param int $loadparentdata Also load parent data + * @return int <0 if KO, 0 if not found, >0 if OK */ - function fetch($id,$ref='') + function fetch($id, $ref='', $loadparentdata=0) { global $langs; @@ -215,7 +216,13 @@ class Task extends CommonObject $sql.= " t.note_private,"; $sql.= " t.note_public,"; $sql.= " t.rang"; + if (! empty($loadparentdata)) + { + $sql.=", t2.ref as task_parent_ref"; + $sql.=", t2.rang as task_parent_position"; + } $sql.= " FROM ".MAIN_DB_PREFIX."projet_task as t"; + if (! empty($loadparentdata)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t2 ON t.fk_task_parent = t2.rowid"; $sql.= " WHERE "; if (!empty($ref)) { $sql.="t.ref = '".$this->db->escape($ref)."'"; @@ -253,14 +260,20 @@ class Task extends CommonObject $this->note_public = $obj->note_public; $this->rang = $obj->rang; - // Retreive all extrafield for thirdparty + if (! empty($loadparentdata)) + { + $this->task_parent_ref = $obj->task_parent_ref; + $this->task_parent_position = $obj->task_parent_position; + } + + // Retreive all extrafield data $this->fetch_optionals(); } $this->db->free($resql); - if ($num_rows) { - $this->fetchComments(); + if ($num_rows) + { return 1; }else { return 0; diff --git a/htdocs/projet/ganttchart.inc.php b/htdocs/projet/ganttchart.inc.php index 58d212db7bd..fc8ab9d7882 100644 --- a/htdocs/projet/ganttchart.inc.php +++ b/htdocs/projet/ganttchart.inc.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2010-2017 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -109,6 +109,10 @@ if (g.getDivId() != null) g.setLang('getDefaultLang(1);?>'); fetch($t['task_project_id']); $tmpt = array( - 'task_id'=> '-'.$t['task_project_id'], 'task_name'=>$projecttmp->ref.' '.$projecttmp->title, 'task_resources'=>'', 'task_start_date'=>'', 'task_end_date'=>'', - 'task_is_group'=>1, 'task_css'=>'ggroupblack', 'task_milestone'=> 0, 'task_parent'=>0, 'task_notes'=>''); + 'task_id'=> '-'.$t['task_project_id'], 'task_alternate_id'=> '-'.$t['task_project_id'], 'task_name'=>$projecttmp->ref.' '.$projecttmp->title, 'task_resources'=>'', 'task_start_date'=>'', 'task_end_date'=>'', + 'task_is_group'=>1, 'task_position'=>0, 'task_css'=>'ggroupblack', 'task_milestone'=> 0, 'task_parent'=>0, 'task_parent_alternate_id'=>0, 'task_notes'=>'' + ); constructGanttLine($tasks, $tmpt, array(), 0, $t['task_project_id']); $old_project_id = $t['task_project_id']; } @@ -134,6 +139,8 @@ if (g.getDivId() != null) findChildGanttLine($tasks, $t["task_id"], $task_dependencies, $level+1); } } + + echo "\n"; ?> g.Draw(jQuery("#tabs").width()-40); @@ -188,7 +195,8 @@ function constructGanttLine($tarr, $task, $task_dependencies, $level=0, $project } else { - $parent = $task["task_parent"]; + $parent = $task["task_parent_alternate_id"]; + //$parent = $task["task_parent"]; } // Define percent $percent = $task['task_percent_complete']?$task['task_percent_complete']:0; @@ -238,7 +246,7 @@ function constructGanttLine($tarr, $task, $task_dependencies, $level=0, $project //$note=""; - $s = "\n// Add taks id=".$task["task_id"]." level = ".$level."\n"; + $s = "\n// Add task level = ".$level." id=".$task["task_id"]." parent_id=".$task["task_parent"]." aternate_id=".$task["task_alternate_id"]." parent_aternate_id=".$task["task_parent_alternate_id"]."\n"; //$task["task_is_group"]=1; // When task_is_group is 1, content will be autocalculated from sum of all low tasks @@ -251,7 +259,10 @@ function constructGanttLine($tarr, $task, $task_dependencies, $level=0, $project $dependency = ''; //$name = str_repeat("..", $level).$name; - $s.= "g.AddTaskItem(new JSGantt.TaskItem('".$task['task_id']."', '".dol_escape_js(trim($name))."', '".$start_date."', '".$end_date."', '".$css."', '".$link."', ".$task['task_milestone'].", '".dol_escape_js($resources)."', ".($percent >= 0 ? $percent : 0).", ".$line_is_auto_group.", '".$parent."', 1, '".$dependency."', '".(empty($task["task_is_group"]) ? (($percent >= 0 && $percent != '') ? $percent.'%' : '') : '')."', '".dol_escape_js($task['note'])."', g));"; + $taskid = $task["task_alternate_id"]; + //$taskid = $task['task_id']; + + $s.= "g.AddTaskItem(new JSGantt.TaskItem('".$taskid."', '".dol_escape_js(trim($name))."', '".$start_date."', '".$end_date."', '".$css."', '".$link."', ".$task['task_milestone'].", '".dol_escape_js($resources)."', ".($percent >= 0 ? $percent : 0).", ".$line_is_auto_group.", '".$parent."', 1, '".$dependency."', '".(empty($task["task_is_group"]) ? (($percent >= 0 && $percent != '') ? $percent.'%' : '') : '')."', '".dol_escape_js($task['note'])."', g));"; echo $s; @@ -270,9 +281,6 @@ function findChildGanttLine($tarr, $parent, $task_dependencies, $level) { $n=count($tarr); - echo "\n"; - echo "/* g.AddTaskItem(new JSGantt.TaskItem(task_id, 'label', 'start_date', 'end_date', 'css', 'link', milestone, 'Resources', Compl%, Group, Parent, 1, 'Dependency', 'label','note', g)); */\n"; - $old_parent_id = 0; for ($x=0; $x < $n; $x++) { diff --git a/htdocs/projet/ganttview.php b/htdocs/projet/ganttview.php index c3552d714f2..119684bf6e6 100644 --- a/htdocs/projet/ganttview.php +++ b/htdocs/projet/ganttview.php @@ -246,15 +246,20 @@ if (count($tasksarray)>0) $tasks=array(); $task_dependencies=array(); $taskcursor=0; - foreach($tasksarray as $key => $val) + foreach($tasksarray as $key => $val) // Task array are sorted by "project, position, dateo" { - $task->fetch($val->id); + $task->fetch($val->id, ''); + + $idparent = ($val->fk_parent ? $val->fk_parent : '-'.$val->fk_project); // If start with -, id is a project id $tasks[$taskcursor]['task_id']=$val->id; + $tasks[$taskcursor]['task_alternate_id']=($taskcursor+1); // An id that has same order than position (requird by ganttchart) $tasks[$taskcursor]['task_project_id']=$val->fk_project; - $tasks[$taskcursor]['task_parent']=($val->fk_parent ? $val->fk_parent : '-'.$val->fk_project); - $tasks[$taskcursor]['task_is_group'] = 0; + $tasks[$taskcursor]['task_parent']=$idparent; + + $tasks[$taskcursor]['task_is_group'] = 0; $tasks[$taskcursor]['task_css'] = 'gtaskblue'; + $tasks[$taskcursor]['task_position'] = $val->rang; if ($val->fk_parent != 0 && $task->hasChildren()> 0){ $tasks[$taskcursor]['task_is_group']=1; @@ -321,6 +326,20 @@ if (count($tasksarray)>0) $taskcursor++; } + // Search parent to set task_parent_alternate_id (requird by ganttchart) + foreach($tasks as $tmpkey => $tmptask) + { + foreach($tasks as $tmptask2) + { + if ($tmptask2['task_id'] == $tmptask['task_parent']) + { + $tasks[$tmpkey]['task_parent_alternate_id']=$tmptask2['task_alternate_id']; + break; + } + } + if (empty($tasks[$tmpkey]['task_parent_alternate_id'])) $tasks[$tmpkey]['task_parent_alternate_id'] = $tasks[$tmpkey]['task_parent']; + } + print "\n"; if (! empty($conf->use_javascript_ajax))