getTicketsTotalActionTime() static public method

Get total duration of tickets linked to a project task
static public getTicketsTotalActionTime ( $projecttasks_id ) : integer
$projecttasks_id integer $projecttasks_id ID of the project task
return integer total actiontime
Ejemplo n.º 1
0
 /**
  * Print the Project task form
  *
  * @param $ID        integer  Id of the project task
  * @param $options   array    of possible options:
  *     - target form target
  *     - projects_id ID of the software for add process
  *
  * @return true if displayed  false if item not found or not right to display
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     if ($ID > 0) {
         $this->check($ID, READ);
         $projects_id = $this->fields['projects_id'];
         $projecttasks_id = $this->fields['projecttasks_id'];
     } else {
         $projects_id = $options['projects_id'];
         $projecttasks_id = $options['projecttasks_id'];
         $this->check(-1, CREATE, $options);
     }
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'><td>" . _n('Project', 'Projects', Session::getPluralNumber()) . "</td>";
     echo "<td>";
     if ($this->isNewID($ID)) {
         echo "<input type='hidden' name='projects_id' value='{$projects_id}'>";
     }
     echo "<a href='project.form.php?id=" . $projects_id . "'>" . Dropdown::getDropdownName("glpi_projects", $projects_id) . "</a>";
     echo "</td>";
     echo "<td>" . __('As child of') . "</td>";
     echo "<td>";
     $this->dropdown(array('entity' => $this->fields['entities_id'], 'value' => $projecttasks_id, 'condition' => "`glpi_projecttasks`.`projects_id`='" . $this->fields['projects_id'] . "'", 'used' => array($this->fields['id'])));
     echo "</td></tr>";
     $showuserlink = 0;
     if (Session::haveRight('user', READ)) {
         $showuserlink = 1;
     }
     if ($ID) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Creation date') . "</td>";
         echo "<td>";
         echo sprintf(__('%1$s by %2$s'), Html::convDateTime($this->fields["date"]), getUserName($this->fields["users_id"], $showuserlink));
         echo "</td>";
         echo "<td>" . __('Last update') . "</td>";
         echo "<td>";
         echo Html::convDateTime($this->fields["date_mod"]);
         echo "</td></tr>";
     }
     echo "<tr class='tab_bg_1'><td>" . __('Name') . "</td>";
     echo "<td colspan='3'>";
     Html::autocompletionTextField($this, "name", array('size' => 80));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . _x('item', 'State') . "</td>";
     echo "<td>";
     ProjectState::dropdown(array('value' => $this->fields["projectstates_id"]));
     echo "</td>";
     echo "<td>" . __('Type') . "</td>";
     echo "<td>";
     ProjectTaskType::dropdown(array('value' => $this->fields["projecttasktypes_id"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Percent done') . "</td>";
     echo "<td>";
     Dropdown::showNumber("percent_done", array('value' => $this->fields['percent_done'], 'min' => 0, 'max' => 100, 'step' => 5, 'unit' => '%'));
     echo "</td>";
     echo "<td>";
     _e('Milestone');
     echo "</td>";
     echo "<td>";
     Dropdown::showYesNo("is_milestone", $this->fields["is_milestone"]);
     echo "</td>";
     echo "</tr>";
     echo "<tr><td colspan='4' class='subheader'>" . __('Planning') . "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Planned start date') . "</td>";
     echo "<td>";
     Html::showDateTimeField("plan_start_date", array('value' => $this->fields['plan_start_date']));
     echo "</td>";
     echo "<td>" . __('Real start date') . "</td>";
     echo "<td>";
     Html::showDateTimeField("real_start_date", array('value' => $this->fields['real_start_date']));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Planned end date') . "</td>";
     echo "<td>";
     Html::showDateTimeField("plan_end_date", array('value' => $this->fields['plan_end_date']));
     echo "</td>";
     echo "<td>" . __('Real end date') . "</td>";
     echo "<td>";
     Html::showDateTimeField("real_end_date", array('value' => $this->fields['real_end_date']));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Planned duration') . "</td>";
     echo "<td>";
     Dropdown::showTimeStamp("planned_duration", array('min' => 0, 'max' => 100 * HOUR_TIMESTAMP, 'step' => HOUR_TIMESTAMP, 'value' => $this->fields["planned_duration"], 'addfirstminutes' => true, 'inhours' => true));
     echo "</td>";
     echo "<td>" . __('Effective duration') . "</td>";
     echo "<td>";
     Dropdown::showTimeStamp("effective_duration", array('min' => 0, 'max' => 100 * HOUR_TIMESTAMP, 'step' => HOUR_TIMESTAMP, 'value' => $this->fields["effective_duration"], 'addfirstminutes' => true, 'inhours' => true));
     if ($ID) {
         $ticket_duration = ProjectTask_Ticket::getTicketsTotalActionTime($this->getID());
         echo "<br>";
         printf(__('%1$s: %2$s'), __('Tickets duration'), Html::timestampToString($ticket_duration, false));
         echo '<br>';
         printf(__('%1$s: %2$s'), __('Total duration'), Html::timestampToString($ticket_duration + $this->fields["effective_duration"], false));
     }
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Description') . "</td>";
     echo "<td colspan='3'>";
     echo "<textarea id='content' name='content' cols='90' rows='6'>" . $this->fields["content"] . "</textarea>";
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Comments') . "</td>";
     echo "<td colspan='3'>";
     echo "<textarea id='comment' name='comment' cols='90' rows='6'>" . $this->fields["comment"] . "</textarea>";
     echo "</td></tr>\n";
     $this->showFormButtons($options);
     return true;
 }
 /**
  * @see NotificationTarget::getDatasForTemplate()
  **/
 function getDatasForTemplate($event, $options = array())
 {
     global $CFG_GLPI, $DB;
     //----------- Reservation infos -------------- //
     $events = $this->getAllEvents();
     $item = $this->obj;
     $this->datas['##projecttask.action##'] = $events[$event];
     $this->datas['##projecttask.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "ProjectTask_" . $item->getField("id"));
     $this->datas["##projecttask.name##"] = $item->getField('name');
     $this->datas["##projecttask.project##"] = Dropdown::getDropdownName('glpi_projects', $item->getField('projects_id'));
     $this->datas["##projecttask.projecturl##"] = $this->formatURL($options['additionnaloption']['usertype'], "Project_" . $item->getField("projects_id"));
     $this->datas["##projecttask.description##"] = $item->getField('content');
     $this->datas["##projecttask.comments##"] = $item->getField('comment');
     $this->datas["##projecttask.creationdate##"] = Html::convDateTime($item->getField('date'));
     $this->datas["##projecttask.lastupdatedate##"] = Html::convDateTime($item->getField('date_mod'));
     $this->datas["##projecttask.percent##"] = Dropdown::getValueWithUnit($item->getField('percent_done'), "%");
     $this->datas["##projecttask.planstartdate##"] = Html::convDateTime($item->getField('plan_start_date'));
     $this->datas["##projecttask.planenddate##"] = Html::convDateTime($item->getField('plan_end_date'));
     $this->datas["##projecttask.realstartdate##"] = Html::convDateTime($item->getField('real_start_date'));
     $this->datas["##projecttask.realenddate##"] = Html::convDateTime($item->getField('real_end_date'));
     $this->datas["##projecttask.plannedduration##"] = Html::timestampToString($item->getField('planned_duration'), false);
     $this->datas["##projecttask.effectiveduration##"] = Html::timestampToString($item->getField('effective_duration'), false);
     $ticket_duration = ProjectTask_Ticket::getTicketsTotalActionTime($item->getID());
     $this->datas["##projecttask.ticketsduration##"] = Html::timestampToString($ticket_duration, false);
     $this->datas["##projecttask.totalduration##"] = Html::timestampToString($ticket_duration + $item->getField('effective_duration'), false);
     $entity = new Entity();
     $this->datas["##projecttask.entity##"] = '';
     $this->datas["##projecttask.shortentity##"] = '';
     if ($entity->getFromDB($this->getEntity())) {
         $this->datas["##projecttask.entity##"] = $entity->getField('completename');
         $this->datas["##projecttask.shortentity##"] = $entity->getField('name');
     }
     $this->datas["##projecttask.father##"] = '';
     if ($item->getField('projecttasks_id')) {
         $this->datas["##projecttask.father##"] = Dropdown::getDropdownName('glpi_projecttasks', $item->getField('projecttasks_id'));
     }
     $this->datas["##projecttask.state##"] = '';
     if ($item->getField('projectstates_id')) {
         $this->datas["##projecttask.state##"] = Dropdown::getDropdownName('glpi_projectstates', $item->getField('projectstates_id'));
     }
     $this->datas["##projecttask.type##"] = '';
     if ($item->getField('projecttasktypes_id')) {
         $this->datas["##projecttask.type##"] = Dropdown::getDropdownName('glpi_projecttasktypes', $item->getField('projecttasktypes_id'));
     }
     $this->datas["##projecttask.createbyuser##"] = '';
     if ($item->getField('users_id')) {
         $user_tmp = new User();
         $user_tmp->getFromDB($item->getField('users_id'));
         $this->datas["##projecttask.createbyuser##"] = $user_tmp->getName();
     }
     // Team infos
     $restrict = "`projecttasks_id` = '" . $item->getField('id') . "'";
     $items = getAllDatasFromTable('glpi_projecttaskteams', $restrict);
     $this->datas['teammembers'] = array();
     if (count($items)) {
         foreach ($items as $data) {
             if ($item2 = getItemForItemtype($data['itemtype'])) {
                 if ($item2->getFromDB($data['items_id'])) {
                     $tmp = array();
                     $tmp['##teammember.itemtype##'] = $item2->getTypeName();
                     $tmp['##teammember.name##'] = $item2->getName();
                     $this->datas['teammembers'][] = $tmp;
                 }
             }
         }
     }
     $this->datas['##projecttask.numberofteammembers##'] = count($this->datas['teammembers']);
     // Task infos
     $restrict = "`projecttasks_id`='" . $item->getField('id') . "'";
     $restrict .= " ORDER BY `date` DESC, `id` ASC";
     $tasks = getAllDatasFromTable('glpi_projecttasks', $restrict);
     $this->datas['tasks'] = array();
     foreach ($tasks as $task) {
         $tmp = array();
         $tmp['##task.creationdate##'] = Html::convDateTime($task['date']);
         $tmp['##task.lastupdatedate##'] = Html::convDateTime($task['date_mod']);
         $tmp['##task.name##'] = $task['name'];
         $tmp['##task.description##'] = $task['content'];
         $tmp['##task.comments##'] = $task['comment'];
         $tmp['##task.state##'] = Dropdown::getDropdownName('glpi_projectstates', $task['projectstates_id']);
         $tmp['##task.type##'] = Dropdown::getDropdownName('glpi_projecttasktypes', $task['projecttasktypes_id']);
         $tmp['##task.percent##'] = Dropdown::getValueWithUnit($task['percent_done'], "%");
         $this->datas["##task.planstartdate##"] = '';
         $this->datas["##task.planenddate##"] = '';
         $this->datas["##task.realstartdate##"] = '';
         $this->datas["##task.realenddate##"] = '';
         if (!is_null($task['plan_start_date'])) {
             $tmp['##task.planstartdate##'] = Html::convDateTime($task['plan_start_date']);
         }
         if (!is_null($task['plan_end_date'])) {
             $tmp['##task.planenddate##'] = Html::convDateTime($task['plan_end_date']);
         }
         if (!is_null($task['real_start_date'])) {
             $tmp['##task.realstartdate##'] = Html::convDateTime($task['real_start_date']);
         }
         if (!is_null($task['real_end_date'])) {
             $tmp['##task.realenddate##'] = Html::convDateTime($task['real_end_date']);
         }
         $this->datas['tasks'][] = $tmp;
     }
     $this->datas["##projecttask.numberoftasks##"] = count($this->datas['tasks']);
     // History infos
     $this->datas['log'] = array();
     // Use list_limit_max or load the full history ?
     foreach (Log::getHistoryData($item, 0, $CFG_GLPI['list_limit_max']) as $data) {
         $tmp = array();
         $tmp["##projecttask.log.date##"] = $data['date_mod'];
         $tmp["##projecttask.log.user##"] = $data['user_name'];
         $tmp["##projecttask.log.field##"] = $data['field'];
         $tmp["##projecttask.log.content##"] = $data['change'];
         $this->datas['log'][] = $tmp;
     }
     $this->datas["##projecttask.numberoflogs##"] = count($this->datas['log']);
     // Tickets infos
     $restrict = "`projecttasks_id`='" . $item->getField('id') . "'";
     $tickets = getAllDatasFromTable('glpi_projecttasks_tickets', $restrict);
     $this->datas['tickets'] = array();
     if (count($tickets)) {
         $ticket = new Ticket();
         foreach ($tickets as $data) {
             if ($ticket->getFromDB($data['tickets_id'])) {
                 $tmp = array();
                 $tmp['##ticket.id##'] = $data['tickets_id'];
                 $tmp['##ticket.date##'] = $ticket->getField('date');
                 $tmp['##ticket.title##'] = $ticket->getField('name');
                 $tmp['##ticket.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "Ticket_" . $data['tickets_id']);
                 $tmp['##ticket.content##'] = $ticket->getField('content');
                 $this->datas['tickets'][] = $tmp;
             }
         }
     }
     $this->datas['##projecttask.numberoftickets##'] = count($this->datas['tickets']);
     // Document
     $query = "SELECT `glpi_documents`.*\n                FROM `glpi_documents`\n                LEFT JOIN `glpi_documents_items`\n                  ON (`glpi_documents`.`id` = `glpi_documents_items`.`documents_id`)\n                WHERE `glpi_documents_items`.`itemtype` =  'ProjectTask'\n                      AND `glpi_documents_items`.`items_id` = '" . $item->getField('id') . "'";
     $this->datas["documents"] = array();
     if ($result = $DB->query($query)) {
         while ($data = $DB->fetch_assoc($result)) {
             $tmp = array();
             $tmp['##document.id##'] = $data['id'];
             $tmp['##document.name##'] = $data['name'];
             $tmp['##document.weblink##'] = $data['link'];
             $tmp['##document.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "document_" . $data['id']);
             $downloadurl = "/front/document.send.php?docid=" . $data['id'];
             $tmp['##document.downloadurl##'] = $this->formatURL($options['additionnaloption']['usertype'], $downloadurl);
             $tmp['##document.heading##'] = Dropdown::getDropdownName('glpi_documentcategories', $data['documentcategories_id']);
             $tmp['##document.filename##'] = $data['filename'];
             $this->datas['documents'][] = $tmp;
         }
     }
     $this->datas["##projecttask.urldocument##"] = $this->formatURL($options['additionnaloption']['usertype'], "ProjectTask_" . $item->getField("id") . '_Document_Item$1');
     $this->datas["##projecttask.numberofdocuments##"] = count($this->datas['documents']);
     // Items infos
     $restrict = "`projects_id` = '" . $item->getField('id') . "'";
     $items = getAllDatasFromTable('glpi_items_projects', $restrict);
     $this->getTags();
     foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
         if (!isset($this->datas[$tag])) {
             $this->datas[$tag] = $values['label'];
         }
     }
 }