$width = 1600; $start_date = w2PgetParam($_GET, 'start_date', $start_min); $end_date = w2PgetParam($_GET, 'end_date', $end_max); $s1 = $start_date ? new w2p_Utilities_Date($start_date) : new w2p_Utilities_Date(); $e1 = $end_date ? new w2p_Utilities_Date($end_date) : new w2p_Utilities_Date(); //consider critical (concerning end date) tasks as well if ($caller != 'todo') { $start_min = $projects[$project_id]['project_start_date']; $end_max = $projects[$project_id]['project_end_date'] > $criticalTasks[0]['task_end_date'] ? $projects[$project_id]['project_end_date'] : $criticalTasks[0]['task_end_date']; } $count = 0; /* * Prepare Gantt_chart loop */ $gtask_sliced = array(); $gtask_sliced = smart_slice($gantt_arr, $showNoMilestones, $printpdfhr, $e1->dateDiff($s1)); $page = 0; // Numbering of output files $outpfiles = array(); // array of output files to be returned to caller $taskcount = 0; // Create task_index array $ctflag = false; if (count($gtask_sliced) > 1) { for ($i = 0; $i < count($gantt_arr); $i++) { $task_index[$gantt_arr[$i][0]['task_id']] = $i + 1; } $ctflag = true; } foreach ($gtask_sliced as $gts) { $gantt = new w2p_Output_GanttRenderer($AppUI, $width);
function smart_slice($arr, $showNoMilestones, $printpdfhr, $day_diff) { global $gtask_sliced; $length = $showNoMilestones ? 26 : 25; if ($day_diff < 90) { $length = $length - 2; } else { if ($day_diff >= 90 && $day_diff < 1096) { $length = $length; } else { $length++; } } if (count($arr) > $length) { $found = 0; for ($i = $length - 3; $i < $length; $i++) { if ($arr[$i][0]['task_dynamic'] != 0) { $found = $i; } } if (!$found) { for ($i = $length - 1; $i > $length - 3; $i--) { if ($arr[$i][0]['task_milestone'] != 0) { $found = $i; } } if (!$found) { if ($arr[$length][0]['task_milestone'] == 0) { $cut = $length; // No specific task => standard cut } else { $cut = $length - 1; // No orphan milestone } } else { $cut = $found + 1; // include found milestone in lower level array } } else { $cut = $found; //include found dynamic task in higher level array } $gtask_sliced[] = array_slice($arr, 0, $cut); $task_sliced[] = smart_slice(array_slice($arr, $cut), $showNoMilestones, $printpdfhr, $day_diff); } else { $gtask_sliced[] = $arr; } return $gtask_sliced; }
function smart_slice($arr, $showNoMilestones, $printpdfhr, $length) { global $gtask_sliced, $showNoMilestones, $day_diff; // echo '<pre> $day_diff = ' . $day_diff . '</pre>'; // if ($showNoMilestones == '1' && $printpdfhr == '1' && $day_diff > 240) { // $l = 27; // } else if (($showNoMilestones == '1' && $printpdfhr == '1' && $day_diff < 240) || // ($showNoMilestones == '0' && $printpdfhr == '1' && $day_diff > 240)) { // $l = 26; // } else if ($showNoMilestones == '1' && $printpdfhr == '0') { // $l = 24; // } else { // $l = 23; // } // DEFINE ('LENGHT', $l); // echo '<pre> LENGTH = ' . LENGHT . '</pre>'; // die; // if ($showNoMilestones == '1') { // DEFINE ( 'LENGTH', (($printpdfhr == '1') ? 27 : 23)); //24 ); // } elseif ($showNoMilestones == '0') { // DEFINE ( 'LENGTH', (($printpdfhr == '1') ? 26 : 22)); //23 ); // } // if ($day_diff < 240 && LENGTH > 24) { // DEFINE ('LENGHT', 24); // } elseif ($day_diff < 240 && LENGTH < 24) { // DEFINE ('LENGHT', 18); // } // echo '<pre> LENGTH = ' . LENGHT . '</pre>'; // die; DEFINE("LENGTH", $length); if (count($arr) > LENGTH) { $found = 0; for ($i = LENGTH - 3; $i < LENGTH; $i++) { if ($arr[$i][0]['task_dynamic'] != 0) { $found = $i; } } if (!$found) { for ($i = LENGTH - 1; $i > LENGTH - 3; $i--) { if ($arr[$i][0]['task_milestone'] != 0) { $found = $i; } } if (!$found) { if ($arr[LENGTH][0]['task_milestone'] == 0) { $cut = LENGTH; // No specific task => standard cut } else { $cut = LENGTH - 1; // No orphan milestone } } else { $cut = $found + 1; // include found milestone in lower level array } } else { $cut = $found; //include found dynamic task in higher level array } $gtask_sliced[] = array_slice($arr, 0, $cut); // echo '<pre> smart_slice($arr, $cut) $cut =' . $cut . '</pre>'; $task_sliced[] = smart_slice(array_slice($arr, $cut), $showNoMilestones, $printpdfhr, $day_diff); } else { $gtask_sliced[] = $arr; } return $gtask_sliced; }