Commit 380ad0f1 authored by Johan Cwiklinski's avatar Johan Cwiklinski Committed by Johan Cwiklinski

Add trait for getAlreadyPlannedInformation

parent 89a8965c
......@@ -36,6 +36,7 @@ if (!defined('GLPI_ROOT')) {
/// TODO extends it from CommonDBChild
abstract class CommonITILTask extends CommonDBTM {
use PlanningEvent;
// From CommonDBTM
public $auto_message_on_action = false;
......@@ -49,7 +50,7 @@ abstract class CommonITILTask extends CommonDBTM {
function getItilObjectItemType() {
public function getItilObjectItemType() {
return str_replace('Task', '', $this->getType());
}
......@@ -1113,34 +1114,6 @@ abstract class CommonITILTask extends CommonDBTM {
}
/**
* Display a Planning Item
*
* @param string $itemtype itemtype
* @param array $val the item to display
*
* @return string Output
**/
public static function getAlreadyPlannedInformation($itemtype, array $val) {
if ($item = getItemForItemtype($itemtype)) {
$objectitemtype = $item->getItilObjectItemType();
//TRANS: %1$s is a type, %2$$ is a date, %3$s is a date
$out = sprintf(__('%1$s: from %2$s to %3$s:'), $item->getTypeName(1),
Html::convDateTime($val["begin"]), Html::convDateTime($val["end"]));
$out .= "<br/><a href='".$objectitemtype::getFormURLWithID($val[getForeignKeyFieldForItemType($objectitemtype)]);
if ($item instanceof CommonITILTask) {
$out .= "&amp;forcetab=".$itemtype."$1";
}
$out .= "'>";
$out .= Html::resume_text($val["name"], 80).'</a>';
return $out;
}
}
/**
* Display a Planning Item
*
......
......@@ -203,13 +203,15 @@ class Planning extends CommonGLPI {
$message = '';
foreach ($CFG_GLPI['planning_types'] as $itemtype) {
$data = call_user_func([$itemtype, 'populatePlanning'],
['who' => $users_id,
'who_group' => 0,
'whogroup' => 0,
'begin' => $begin,
'end' => $end,
'check_planned' => true]);
$item = new $itemtype;
$data = $item->populatePlanning([
'who' => $users_id,
'who_group' => 0,
'whogroup' => 0,
'begin' => $begin,
'end' => $end,
'check_planned' => true
]);
if (isPluginItemType($itemtype)) {
if (isset($data['items'])) {
$data = $data['items'];
......@@ -225,8 +227,8 @@ class Planning extends CommonGLPI {
|| (is_array($except[$itemtype]) && !in_array($val['id'], $except[$itemtype]))) {
$planned = true;
$message .= '- '.call_user_func([$itemtype, 'getAlreadyPlannedInformation'],
$itemtype, $val).'<br>';
$message .= '- ' . $item->getAlreadyPlannedInformation($val);
$message .= '<br/>';
}
}
}
......@@ -1644,9 +1646,13 @@ JAVASCRIPT;
}
if (!$abort) {
$update = ['id' => $params['items_id'],
'plan' => ['begin' => $params['start'],
'end' => $params['end']]];
$update = [
'id' => $params['items_id'],
'plan' => [
'begin' => $params['start'],
'end' => $params['end']
]
];
if (isset($item->fields['users_id_tech'])) {
$update['users_id_tech'] = $item->fields['users_id_tech'];
......
<?php
/**
* ---------------------------------------------------------------------
* GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2015-2018 Teclib' and contributors.
*
* http://glpi-project.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* GLPI is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GLPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GLPI. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
trait PlanningEvent {
/**
* Display a Planning Item
*
* @param array $val the item to display
*
* @return string
**/
public function getAlreadyPlannedInformation(array $val) {
$itemtype = $this->getType();
if ($item = getItemForItemtype($itemtype)) {
$objectitemtype = (method_exists($item, 'getItilObjectItemType') ? $item->getItilObjectItemType() : $itemtype);
//TRANS: %1$s is a type, %2$$ is a date, %3$s is a date
$out = sprintf(__('%1$s: from %2$s to %3$s:'), $item->getTypeName(1),
Html::convDateTime($val["begin"]), Html::convDateTime($val["end"]));
$out .= "<br/><a href='".$objectitemtype::getFormURLWithID($val[getForeignKeyFieldForItemType($objectitemtype)]);
if ($item instanceof CommonITILTask) {
$out .= "&amp;forcetab=".$itemtype."$1";
}
$out .= "'>";
$out .= Html::resume_text($val["name"], 80).'</a>';
return $out;
}
}
}
......@@ -41,6 +41,7 @@ if (!defined('GLPI_ROOT')) {
* @since 0.85
**/
class ProjectTask extends CommonDBChild {
use PlanningEvent;
// From CommonDBTM
public $dohistory = true;
......@@ -1676,19 +1677,4 @@ class ProjectTask extends CommonDBChild {
$html.= "<div class='event-description rich_text_container'>".html_entity_decode($val["content"])."</div>";
return $html;
}
/**
* Display a Planning Item
*
* @param $val Array of the item to display
*
* @return Already planned information
**/
static function getAlreadyPlannedInformation($itemtype, array $val) {
return CommonITILTask::getAlreadyPlannedInformation($itemtype, $val);
}
function getItilObjectItemType() {
return $this->getType();
}
}
......@@ -39,6 +39,7 @@ if (!defined('GLPI_ROOT')) {
* Reminder Class
**/
class Reminder extends CommonDBVisible {
use PlanningEvent;
// From CommonDBTM
public $dohistory = true;
......@@ -1027,18 +1028,6 @@ class Reminder extends CommonDBVisible {
}
/**
* Display a Planning Item
*
* @param $val Array of the item to display
*
* @return Already planned information
**/
static function getAlreadyPlannedInformation(array $val) {
return CommonITILTask::getAlreadyPlannedInformation(static::getType(), $val);
}
/**
* Display a Planning Item
*
......@@ -1240,8 +1229,4 @@ class Reminder extends CommonDBVisible {
}
return $values;
}
function getItilObjectItemType() {
return $this->getType();
}
}
......@@ -105,7 +105,7 @@ class ProjectTask extends DbTestCase {
$this->array($_SESSION['MESSAGE_AFTER_REDIRECT'])->isIdenticalTo([
WARNING => [
"The user $usr_str is busy at the selected timeframe.<br/>- Project task: from 2019-08-13 00:00 to 2019-08-14 00:00:<br/><a href='".
$ptask->getFormURLWithID($task_id)."'>first test, whole period</a><br>"
$ptask->getFormURLWithID($task_id)."'>first test, whole period</a><br/>"
]
]);
$_SESSION['MESSAGE_AFTER_REDIRECT'] = []; //reset
......@@ -184,7 +184,7 @@ class ProjectTask extends DbTestCase {
$this->array($_SESSION['MESSAGE_AFTER_REDIRECT'])->isIdenticalTo([
WARNING => [
"The user $usr_str is busy at the selected timeframe.<br/>- Project task: from 2019-08-11 to 2019-08-12 :<br/><a href='".
$ptask->getFormURLWithID($task_id)."'>first test, whole period</a><br>"
$ptask->getFormURLWithID($task_id)."'>first test, whole period</a><br/>"
]
]);
$_SESSION['MESSAGE_AFTER_REDIRECT'] = []; //reset
......
......@@ -306,7 +306,7 @@ class TicketTask extends DbTestCase {
$this->array($_SESSION['MESSAGE_AFTER_REDIRECT'])->isIdenticalTo([
WARNING => [
"The user $usr_str is busy at the selected timeframe.<br/>- Ticket task: from 2019-08-13 to 2019-08-14 :<br/><a href='".
$ticket->getFormURLWithID($tid)."&amp;forcetab=TicketTask$1'>ticket title</a><br>"
$ticket->getFormURLWithID($tid)."&amp;forcetab=TicketTask$1'>ticket title</a><br/>"
]
]);
$_SESSION['MESSAGE_AFTER_REDIRECT'] = []; //reset
......@@ -345,8 +345,8 @@ class TicketTask extends DbTestCase {
$this->array($_SESSION['MESSAGE_AFTER_REDIRECT'])->isIdenticalTo([
WARNING => [
"The user $usr_str is busy at the selected timeframe.<br/>- Ticket task: from 2019-08-10 00:00 to 2019-08-20 00:00:<br/><a href='".
$ticket->getFormURLWithID($tid)."&amp;forcetab=TicketTask$1'>ticket title</a><br>- Ticket task: from 2019-08-13 00:00 to 2019-08-14 00:00:<br/><a href='".$ticket
->getFormURLWithID($tid)."&amp;forcetab=TicketTask$1'>ticket title</a><br>"
$ticket->getFormURLWithID($tid)."&amp;forcetab=TicketTask$1'>ticket title</a><br/>- Ticket task: from 2019-08-13 00:00 to 2019-08-14 00:00:<br/><a href='".$ticket
->getFormURLWithID($tid)."&amp;forcetab=TicketTask$1'>ticket title</a><br/>"
]
]);
$_SESSION['MESSAGE_AFTER_REDIRECT'] = []; //reset
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment