Skip to content

Commit

Permalink
Fix order of task in gantt diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jan 4, 2018
1 parent 04dd066 commit c4eba66
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 20 deletions.
27 changes: 20 additions & 7 deletions htdocs/projet/class/task.class.php
Expand Up @@ -187,11 +187,12 @@ function create($user, $notrigger=0)
/**
* 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;

Expand All @@ -215,7 +216,13 @@ function fetch($id,$ref='')
$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)."'";
Expand Down Expand Up @@ -253,14 +260,20 @@ function fetch($id,$ref='')
$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;
Expand Down
26 changes: 17 additions & 9 deletions htdocs/projet/ganttchart.inc.php
@@ -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
Expand Down Expand Up @@ -109,6 +109,10 @@ function reloadGraph() {
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;
Expand All @@ -122,8 +126,9 @@ function reloadGraph() {
$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'];
}
Expand All @@ -134,6 +139,8 @@ function reloadGraph() {
findChildGanttLine($tasks, $t["task_id"], $task_dependencies, $level+1);
}
}

echo "\n";
?>

g.Draw(jQuery("#tabs").width()-40);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand All @@ -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;


Expand All @@ -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++)
{
Expand Down
27 changes: 23 additions & 4 deletions htdocs/projet/ganttview.php
Expand Up @@ -246,15 +246,20 @@
$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;
Expand Down Expand Up @@ -321,6 +326,20 @@
$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))
Expand Down

0 comments on commit c4eba66

Please sign in to comment.