Skip to content

Commit

Permalink
Mise en place calcul durée total et durée privée à partir du champ ac…
Browse files Browse the repository at this point in the history
…tiontime de la table ticketstasks plutôt que celui de la table tickets. Prise en compte de la permission voir les tâches privées dans ce calcul ainsi que du paramètre onlypublicTasks du plugin

refs #42 @2h
  • Loading branch information
Philippe GODOT committed Sep 16, 2020
1 parent 4405e21 commit dfe783e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
58 changes: 45 additions & 13 deletions ajax/get_tickets_actiontime.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,57 @@

Session::checkLoginUser();

if ($_SERVER['REQUEST_METHOD'] == 'POST'
&& !empty($_POST['ticket_ids'])
&& is_array($_POST['ticket_ids'])
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['ticket_ids']) && is_array($_POST['ticket_ids'])
) {
$ticket = new Ticket();

$tickets = $ticket->find([ 'id' => $_POST['ticket_ids'] ]);
$onlypublicTasks = PluginProjectbridgeConfig::getConfValueByName('CountOnlyPublicTasks');

$tickets_actiontime = [];

foreach ($tickets as $ticket_data) {
$actiontime = (int) $ticket_data['actiontime'];
foreach ($_POST['ticket_ids'] as $ticketID) {
$whereConditionsArray = [];
$totalActiontime = 0;
$whereConditionsArray = ['tickets_id' => $ticketID];
//if ($onlypublicTasks) {
if ( !Session::haveRight("task", CommonITILTask::SEEPRIVATE) || $onlypublicTasks) {
$whereConditionsArray['is_private'] = 0;
}

$iterator = $DB->request([
'SELECT' => new QueryExpression('SUM(' . TicketTask::getTable() . '.actiontime) AS duration'),
'FROM' => TicketTask::getTable(),
'WHERE' => $whereConditionsArray
]);
if ($row = $iterator->next()) {
$totalActiontime = (int) $row['duration'];
}
if (!empty($totalActiontime)) {
$totalActiontime = round($totalActiontime / 3600 * 100, 1) / 100;
}

$tickets_actiontime[$ticketID]['totalDuration'] = $totalActiontime;

// récupération durée privée
$privateActiontime = 0;
if (Session::haveRight("task", CommonITILTask::SEEPRIVATE) && !$onlypublicTasks) {
$whereConditionsArray['is_private'] = 1;
$iterator = $DB->request([
'SELECT' => new QueryExpression('SUM(' . TicketTask::getTable() . '.actiontime) AS duration'),
'FROM' => TicketTask::getTable(),
'WHERE' => $whereConditionsArray
]);
if ($row = $iterator->next()) {
$privateActiontime = (int) $row['duration'];
}
if (!empty($privateActiontime)) {
$privateActiontime = round($privateActiontime / 3600 * 100, 1) / 100;
}
}

$tickets_actiontime[$ticketID]['privateDuration'] = $privateActiontime;
}


if (!empty($actiontime)) {
$actiontime = round($actiontime / 3600 * 100) / 100;
}

$tickets_actiontime[$ticket_data['id']] = $actiontime;
}

echo json_encode($tickets_actiontime);
}
14 changes: 10 additions & 4 deletions inc/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ private static function _getProjectList() {
*/
public static function postShowTask(ProjectTask $project_task) {
global $CFG_GLPI;
$onlypublicTasks = PluginProjectbridgeConfig::getConfValueByName('CountOnlyPublicTasks');

$get_tickets_actiontime_url = PLUGIN_PROJECTBRIDGE_WEB_DIR . '/ajax/get_tickets_actiontime.php';
$js_block = '
debugger;
//debugger;
var
current_table_cell,
table_parent,
Expand Down Expand Up @@ -243,12 +244,17 @@ public static function postShowTask(ProjectTask $project_task) {
current_table_cell = $("td.left:nth-child(2)", current_row);
current_ticket_id = getTicketIdFromCell(current_table_cell);
current_action_time = 0;
private_action_time = 0;
if (tickets_actiontime[current_ticket_id] !== undefined) {
current_action_time = tickets_actiontime[current_ticket_id];
current_action_time = tickets_actiontime[current_ticket_id]["totalDuration"];
private_action_time = tickets_actiontime[current_ticket_id]["privateDuration"];
}
if(private_action_time > 0) {
current_row.append("<td>" + current_action_time + " heure(s) dont " + private_action_time + " heures privées</td>");
}else {
current_row.append("<td>" + current_action_time + " heure(s) </td>");
}
current_row.append("<td>" + current_action_time + " heure(s)</td>");
} else if (idx == 0) {
current_table_cell = $("th", current_row);
current_table_cell.attr("colspan", parseInt(current_table_cell.attr("colspan")) + 1);
Expand Down

0 comments on commit dfe783e

Please sign in to comment.