Fix: Avoid home project page to hung when too many tasks opened.

This commit is contained in:
Laurent Destailleur 2014-03-12 02:43:31 +01:00
parent 7684e9e4f7
commit 4a983811d0

View File

@ -26,6 +26,7 @@
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
$langs->load("projects");
@ -81,7 +82,7 @@ print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("ThirdParties"),"index.php","s.nom","","","",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("ThirdParties"),$_SERVER["PHP_SELF"],"s.nom","","","",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("NbOfProjects"),"","","","",'align="right"',$sortfield,$sortorder);
print "</tr>\n";
@ -132,13 +133,17 @@ else
}
print "</table>";
print '</td></tr></table>';
print '</div></div></div>';
// Tasks for all resources of all opened projects and time spent for each task/resource
print '<div class="fichecenter">';
print '<BR>';
print '<br>';
print_fiche_titre($langs->trans("TimeSpent"),'','').'<br>';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<th>'.$langs->trans('TaskRessourceLinks').'</th>';
@ -146,11 +151,11 @@ print '<th>'.$langs->trans('Projects').'</th>';
print '<th>'.$langs->trans('Task').'</th>';
print '<th>'.$langs->trans('DateStart').'</th>';
print '<th>'.$langs->trans('DateEnd').'</th>';
print '<th>'.$langs->trans('WorkloadOccupation').'</th>';
print '<th>'.$langs->trans('TimeSpent').'</th>';
print '</tr>';
$sql = "SELECT p.title, p.rowid as projectid, t.label, t.rowid as taskid, u.rowid as userid, t.planned_workload, t.dateo, t.datee, tasktime.task_duration";
$sql = "SELECT p.title, p.rowid as projectid, t.label, t.rowid as taskid, u.rowid as userid, t.planned_workload, t.dateo, t.datee, SUM(tasktime.task_duration) as timespent";
$sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."projet_task as t on t.fk_projet = p.rowid";
@ -160,6 +165,7 @@ $sql.= " WHERE p.entity = ".$conf->entity;
if ($mine || ! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")";
if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
$sql.= " AND p.fk_statut=1";
$sql.= " GROUP BY p.title, p.rowid, t.label, t.rowid, u.rowid, t.planned_workload, t.dateo, t.datee";
$sql.= " ORDER BY u.rowid, t.dateo, t.datee";
$userstatic=new User($db);
@ -171,42 +177,61 @@ if ( $resql )
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
if ($num > (empty($conf->global->PROJECT_LIMIT_TASK_PROJECT_AREA)?1000:$conf->global->PROJECT_LIMIT_TASK_PROJECT_AREA))
{
$obj = $db->fetch_object($resql);
$var=!$var;
$username='';
$userstatic->fetch($obj->userid);
if (!empty($userstatic->id)) {
$username = $userstatic->getNomUrl(0,0);
}
print "<tr ".$bc[$var].">";
print '<td>'.$username.'</td>';
print '<td><a href="'.DOL_URL_ROOT.'/projet/fiche.php?id="'.$obj->projectid.'">'.$obj->title.'</a></td>';
print '<td><a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$obj->taskid.'&withproject=1">'.$obj->label.'</a></td>';
print '<td>'.dol_print_date($db->jdate($obj->dateo)).'</td>';
print '<td>'.dol_print_date($db->jdate($obj->datee)).'</td>';
if (empty($obj->planned_workload)) {
$percentcompletion = '0';
} else {
$percentcompletion = intval(($obj->task_duration*100)/$obj->planned_workload);
}
print '<td><a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$obj->taskid.'&withproject=1">'.$percentcompletion.' %</a></td>';
print "</tr>\n";
$i++;
print '<tr '.$bc[0].'>';
print '<td colspan="9">';
print $langs->trans("TooManyDataPleaseUseMoreFilters");
print '</td></tr>';
}
else
{
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$var=!$var;
$db->free($resql);
$username='';
if ($obj->userid && $userstatic->id != $obj->userid) // We have a user and it is not last loaded user
{
$result=$userstatic->fetch($obj->userid);
if (! $result) $userstatic->id=0;
}
if ($userstatic->id) $username = $userstatic->getNomUrl(0,0);
print "<tr ".$bc[$var].">";
print '<td>'.$username.'</td>';
print '<td><a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$obj->projectid.'">'.$obj->title.'</a></td>';
print '<td><a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$obj->taskid.'&withproject=1">'.$obj->label.'</a></td>';
print '<td>'.dol_print_date($db->jdate($obj->dateo)).'</td>';
print '<td>'.dol_print_date($db->jdate($obj->datee)).'</td>';
/* I disable this because information is wrong. This percent has no meaning for a particular resource. What do we want ?
* Percent of completion ?
* If we want to show completion, we must remove "user" into list,
if (empty($obj->planned_workload)) {
$percentcompletion = $langs->trans("Unknown");
} else {
$percentcompletion = intval($obj->task_duration*100/$obj->planned_workload);
}*/
print '<td><a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$obj->taskid.'&withproject=1">';
//print $percentcompletion.' %';
print convertSecondToTime($obj->timespent, 'all');
print '</a></td>';
print "</tr>\n";
$i++;
}
$db->free($resql);
}
}
else
{
dol_print_error($db);
}
print "</table></div>";
print "</table>";
print '</div>';