main.itop-request-mgmt-itil.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Base class for computing TTO or TTR on a ticket
  18. */
  19. class ResponseTicketSLT
  20. {
  21. /**
  22. * Determines the shortest SLT, for this ticket, for the given metric. Returns null is no SLT was found
  23. * @param string $sMetric Type of metric 'TTO', 'TTR', etc as defined in the SLT class
  24. * @return hash Array with 'SLT' => name of the SLT selected, 'value' => duration in seconds of the SLT metric, null if no SLT applies to this ticket
  25. */
  26. protected static function ComputeSLT($oTicket, $sMetric = 'TTO')
  27. {
  28. $iDeadline = null;
  29. if (MetaModel::IsValidClass('SLT'))
  30. {
  31. $sType=get_class($oTicket);
  32. //echo "<p>Managing:".$sMetric."-".$this->Get('request_type')."-".$this->Get('importance')."</p>\n";
  33. $sOQL = "SELECT SLT AS slt JOIN lnkSLAToSLT AS l1 ON l1.slt_id=slt.id JOIN SLA AS sla ON l1.sla_id=sla.id JOIN lnkCustomerContractToService AS l2 ON l2.sla_id=sla.id JOIN CustomerContract AS sc ON l2.customercontract_id=sc.id WHERE slt.metric = :metric AND l2.service_id = :service AND sc.org_id = :customer AND slt.request_type = :request_type AND slt.priority = :priority";
  34. $oSLTSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL),
  35. array(),
  36. array(
  37. 'metric' => $sMetric,
  38. 'service' => $oTicket->Get('service_id'),
  39. 'customer' => $oTicket->Get('org_id'),
  40. 'request_type' => $oTicket->Get('request_type'),
  41. 'priority' => $oTicket->Get('priority'),
  42. )
  43. );
  44. $iMinDuration = PHP_INT_MAX;
  45. $sSLTName = '';
  46. while($oSLT = $oSLTSet->Fetch())
  47. {
  48. $iDuration = (int)$oSLT->Get('value');
  49. $sUnit = $oSLT->Get('unit');
  50. switch($sUnit)
  51. {
  52. case 'days':
  53. $iDuration = $iDuration * 24; // 24 hours in 1 days
  54. // Fall though
  55. case 'hours':
  56. $iDuration = $iDuration * 60; // 60 minutes in 1 hour
  57. // Fall though
  58. case 'minutes':
  59. $iDuration = $iDuration * 60;
  60. }
  61. if ($iDuration < $iMinDuration)
  62. {
  63. $iMinDuration = $iDuration;
  64. $sSLTName = $oSLT->GetName();
  65. }
  66. }
  67. if ($iMinDuration == PHP_INT_MAX)
  68. {
  69. $iDeadline = null;
  70. }
  71. else
  72. {
  73. // Store $sSLTName to keep track of which SLT has been used
  74. $iDeadline = $iMinDuration - $oTicket->Get('cumulated_pending_period') - $oTicket->Get('cumulated_resolved_period') ;
  75. }
  76. }
  77. return $iDeadline;
  78. }
  79. }
  80. /**
  81. * Compute the TTO of a ticket - null if the class 'SLT' does not exist
  82. */
  83. class ResponseTicketTTO extends ResponseTicketSLT implements iMetricComputer
  84. {
  85. public static function GetDescription()
  86. {
  87. return "Time to own a ticket";
  88. }
  89. public function ComputeMetric($oObject)
  90. {
  91. $iRes = $this->ComputeSLT($oObject, 'TTO');
  92. return $iRes;
  93. }
  94. }
  95. /**
  96. * Compute the TTR of a ticket - null if the class 'SLT' does not exist
  97. */
  98. class ResponseTicketTTR extends ResponseTicketSLT implements iMetricComputer
  99. {
  100. public static function GetDescription()
  101. {
  102. return "Time to resolve a ticket";
  103. }
  104. public function ComputeMetric($oObject)
  105. {
  106. $iRes = $this->ComputeSLT($oObject, 'TTR');
  107. return $iRes;
  108. }
  109. }
  110. ?>