mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Fix order of task in gantt diagram
This commit is contained in:
parent
04dd0663ff
commit
c4eba665d0
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
/* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
/* Copyright (C) 2010-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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('<?php print $langs->getDefaultLang(1);?>');
|
||||
|
||||
<?php
|
||||
|
||||
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";
|
||||
|
||||
$level=0;
|
||||
$tnums = count($tasks);
|
||||
$old_project_id = 0;
|
||||
|
|
@ -122,8 +126,9 @@ if (g.getDivId() != null)
|
|||
$projecttmp=new Project($db);
|
||||
$projecttmp->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++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user