diff --git a/inc/task.class.php b/inc/task.class.php index 1784888..4516dd7 100644 --- a/inc/task.class.php +++ b/inc/task.class.php @@ -1,7 +1,7 @@ _task->getId() . "
\n"; @@ -318,14 +308,12 @@ public function closeTask($expired = false, $action_time = 0) $ticket_user = new Ticket_User(); $ticket_users = $ticket_user->find(['tickets_id' => $old_ticket_id]); foreach ($ticket_users as $ticket_user_data) { - if ((in_array('requester', $elementsAssociateToExcessTicket) && $ticket_user_data['type'] == CommonITILActor::REQUESTER) - || (in_array('assign_technician', $elementsAssociateToExcessTicket) && $ticket_user_data['type'] == CommonITILActor::ASSIGN) - || (in_array('watcher_user', $elementsAssociateToExcessTicket) && $ticket_user_data['type'] == CommonITILActor::OBSERVER) - ) { + if ((in_array('requester', $elementsAssociateToExcessTicket) && $ticket_user_data['type'] == CommonITILActor::REQUESTER) || (in_array('assign_technician', $elementsAssociateToExcessTicket) && $ticket_user_data['type'] == CommonITILActor::ASSIGN) || (in_array('watcher_user', $elementsAssociateToExcessTicket) && $ticket_user_data['type'] == CommonITILActor::OBSERVER) + ) { // test if not exist aready in database $ticket_user_exist = $ticket_user->find( - [ + [ 'tickets_id' => $ticket->getId(), 'users_id' => $ticket_user_data['users_id'], 'type' => $ticket_user_data['type'] @@ -388,7 +376,7 @@ public function closeTask($expired = false, $action_time = 0) // add documents $document_item = new Document_Item(); $ticket_document_items = $document_item->find( - [ + [ 'items_id' => $old_ticket_id, 'itemtype' => 'Ticket' ] @@ -459,13 +447,13 @@ public function closeTask($expired = false, $action_time = 0) // add solution $log = new Log(); $logs = $log->find( - [ + [ 'items_id' => $old_ticket_id, 'id_search_option' => 24, 'itemtype' => 'Ticket' ], - ['id' => 'DESC'], - 1 + ['id' => 'DESC'], + 1 ); if (!empty($logs)) { $ticket_new_log_data = array_diff_key(current($logs), ['id' => null,]); @@ -500,7 +488,6 @@ public function closeTask($expired = false, $action_time = 0) ]); } array_push($newTicketIds, $ticket->getId()); - //$nb_successes++; } } } @@ -508,7 +495,6 @@ public function closeTask($expired = false, $action_time = 0) } } - //if (count($newTicketIds) > 0) { // envoi des notifications $recipients = PluginProjectbridgeConfig::getRecipients(); echo __('find', 'projectbridge') . count($recipients) . ' ' . __('person(s) to alert', 'projectbridge') . "
\n"; @@ -524,17 +510,13 @@ public function closeTask($expired = false, $action_time = 0) $bridgeContract = new PluginProjectbridgeContract(); $contractId = $bridgeContract->getFromDBByCrit(['project_id' => $projectId]); if ($contractId) { - $contract = (new Contract())->find(['id'=> $contractId]); + $contract = (new Contract())->find(['id' => $contractId]); } $subject = __('project Task') . ' "' . $project->fields['name'] . '" ' . __('closed'); - $contract = null; - $projectId = $this->_task->fields['projects_id']; - $project = new Project(); $project->getFromDB($projectId); // search contract throw projectbridge_contracts -// $bridgeContract = new PluginProjectbridgeContract(); $bridgeContracts = (new PluginProjectbridgeContract())->find(['project_id' => $projectId]); foreach ($bridgeContracts as $bridgeContract) { $contract = (new Contract())->getById($bridgeContract['contract_id']); @@ -568,11 +550,10 @@ public function closeTask($expired = false, $action_time = 0) PluginProjectbridgeConfig::notify(implode('', $html_parts), $recipient['email'], $recipient['name'], $subject); } } - //} + // exec update percent crontask self::cronUpdateProgressPercent(); - return $newTicketIds; } @@ -583,8 +564,7 @@ public function closeTask($expired = false, $action_time = 0) * @param int $entities_id * @return void */ - public function createExcessTicket($timediff, $entities_id) - { + public function createExcessTicket($timediff, $entities_id) { $ticket_request_type = PluginProjectbridgeState::getProjectStateIdByStatus('renewal'); $ticket_fields = [ @@ -608,7 +588,6 @@ public function createExcessTicket($timediff, $entities_id) 'state' => 2 // fait ]; - $ticket_task->add($ticket_task_data); PluginProjectbridgeTicket::deleteProjectLinks($ticket->getId()); @@ -623,8 +602,7 @@ public function createExcessTicket($timediff, $entities_id) * @param CronTask|null $cron_task for log, if NULL display (default NULL) * @return integer 1 if an action was done, 0 if not */ - public static function cronUpdateProgressPercent($cron_task = null) - { + public static function cronUpdateProgressPercent($cron_task = null) { if (class_exists('PluginProjectbridgeConfig')) { $plugin = new Plugin(); @@ -645,39 +623,27 @@ public static function cronUpdateProgressPercent($cron_task = null) $projectTask = new ProjectTask(); $projectbridgeContract = new PluginProjectbridgeContract(); foreach ($DB->request([ - 'SELECT'=> ['pt.id', 'pbc.contract_id'], + 'SELECT' => ['pt.id', 'pbc.contract_id'], 'DISTINCT' => true, - 'FROM' => $projectTask->getTable(). ' AS pt', + 'FROM' => $projectTask->getTable() . ' AS pt', 'INNER JOIN' => [ - $projectbridgeContract->getTable(). ' AS pbc' => [ - 'FKEY' => [ + $projectbridgeContract->getTable() . ' AS pbc' => [ + 'FKEY' => [ 'pt' => 'projects_id', 'pbc' => 'project_id' ] ] ], 'WHERE' => ['pt.projectstates_id' => PluginProjectbridgeState::getProjectStateIdByStatus('in_progress')] - - ]) as $data) { + ]) as $data) { $taskInfos[] = $data; } - - $pluginProjectbridgeContract = new PluginProjectbridgeContract(); + foreach ($taskInfos as $row) { if ($cron_task) { echo __('re-calculuation for projectTask', 'projectbridge') . ' ' . $row['id'] . "
\n"; } - $contract = new Contract(); - $contract->getFromDB($row['contract_id']); - - $bridge_contract = new PluginProjectbridgeContract($contract); - $nb_hours = $bridge_contract->getNbHours(); - $consumption = $pluginProjectbridgeContract::getTicketsTotalActionTime($row['id']) / 3600; - $ratio = round(($consumption*100)/$nb_hours); - $projectTask->update([ - 'id' => $row['id'], - 'percent_done' => $ratio, - ]); + PluginProjectbridgeTask::updateProjectTaskProgressPercent($row['id'], $row['contract_id']); $nb_successes++; } if ($cron_task) { @@ -687,11 +653,22 @@ public static function cronUpdateProgressPercent($cron_task = null) } return ($nb_successes > 0) ? 1 : 0; - - } - + public static function updateProjectTaskProgressPercent($taskId, $contract_id) { + $projectTask = new ProjectTask(); + $contract = new Contract(); + $contract->getFromDB($contract_id); + + $bridge_contract = new PluginProjectbridgeContract($contract); + $nb_hours = $bridge_contract->getNbHours(); + $consumption = PluginProjectbridgeContract::getTicketsTotalActionTime($taskId) / 3600; + $ratio = round(($consumption * 100) / $nb_hours); + $projectTask->update([ + 'id' => $taskId, + 'percent_done' => $ratio, + ]); + } /** * Customize the duration columns in a list of project tasks @@ -699,8 +676,7 @@ public static function cronUpdateProgressPercent($cron_task = null) * @param Project $project * @return void */ - public static function customizeDurationColumns(Project $project) - { + public static function customizeDurationColumns(Project $project) { $task = new ProjectTask(); $tasks = $task->find(['projects_id' => $project->getId()]); if (!empty($tasks)) { @@ -805,8 +781,7 @@ public static function customizeDurationColumns(Project $project) * @param CronTask|null $task for log, if NULL display (default NULL) * @return integer 1 if an action was done, 0 if not */ - public static function cronAlertContractsToRenew($task = null) - { + public static function cronAlertContractsToRenew($task = null) { if (class_exists('PluginProjectbridgeConfig')) { $plugin = new Plugin(); @@ -836,8 +811,6 @@ public static function cronAlertContractsToRenew($task = null) $html_parts[] = '
    ' . "\n"; - - foreach ($contracts as $contract_id => $contract_data) { $html_parts[] = '
  1. ' . "\n"; @@ -894,7 +867,7 @@ public static function cronAlertContractsToRenew($task = null) $html_parts[] = '
' . "\n"; $html_parts[] = '


' . "\n"; - $html_parts[] = '

'.__('This Email is send automatically by the plugin projectBridge', 'projectbridge') .' ('.PLUGIN_PROJECTBRIDGE_VERSION.')

.'; + $html_parts[] = '

' . __('This Email is send automatically by the plugin projectBridge', 'projectbridge') . ' (' . PLUGIN_PROJECTBRIDGE_VERSION . ')

.'; foreach ($recipients as $recipient) { $success = PluginProjectbridgeConfig::notify(implode('', $html_parts), $recipient['email'], $recipient['name'], $subject); @@ -911,8 +884,7 @@ public static function cronAlertContractsToRenew($task = null) return ($nb_successes > 0) ? 1 : 0; } - public static function cronAlertContractsOverQuota($task = null) - { + public static function cronAlertContractsOverQuota($task = null) { if (class_exists('PluginProjectbridgeConfig')) { $plugin = new Plugin(); @@ -932,11 +904,11 @@ public static function cronAlertContractsOverQuota($task = null) if (count($recipients)) { // récupération des contrat en cours $contracts = PluginProjectbridgeContract::getContractsOverQuota(); - $subject = __('Contract(s) over limit quota alert', 'projectbridge').' ('.count($contracts).')'; + $subject = __('Contract(s) over limit quota alert', 'projectbridge') . ' (' . count($contracts) . ')'; $html_parts = []; $html_parts[] = '

' . "\n"; - $html_parts[] = __('Contract(s) over limit quota alert', 'projectbridge') .' ('.count($contracts).') :'; + $html_parts[] = __('Contract(s) over limit quota alert', 'projectbridge') . ' (' . count($contracts) . ') :'; $html_parts[] = '

' . "\n"; $html_parts[] = '
    ' . "\n"; @@ -951,7 +923,7 @@ public static function cronAlertContractsOverQuota($task = null) $html_parts[] = '
    ' . "\n"; $html_parts[] = '' . __('Quota', 'projectbridge') . ' : '; - $html_parts[] = $contract_data['ratio'] .'% ('.round($contract_data['consumption'],1).'/'.$contract_data['nb_hours'].')' ; + $html_parts[] = $contract_data['ratio'] . '% (' . round($contract_data['consumption'], 1) . '/' . $contract_data['nb_hours'] . ')'; $html_parts[] = '
    ' . "\n"; $entity = new Entity(); @@ -964,7 +936,7 @@ public static function cronAlertContractsOverQuota($task = null) $html_parts[] = '
' . "\n"; $html_parts[] = '


' . "\n"; - $html_parts[] = '

'.__('This Email si send automacitly by the plugin projectBridge', 'projectbridge') .' ('.PLUGIN_PROJECTBRIDGE_VERSION.')

.'; + $html_parts[] = '

' . __('This Email si send automacitly by the plugin projectBridge', 'projectbridge') . ' (' . PLUGIN_PROJECTBRIDGE_VERSION . ')

.'; if (count($contracts)) { foreach ($recipients as $recipient) { @@ -982,4 +954,5 @@ public static function cronAlertContractsOverQuota($task = null) return ($nb_successes > 0) ? 1 : 0; } + }