main.itop-tickets.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Base class for computing TTO or TTR on a ticket
  20. */
  21. class ResponseTicketSLT
  22. {
  23. /**
  24. * Determines the shortest SLT, for this ticket, for the given metric. Returns null is no SLT was found
  25. * @param string $sMetric Type of metric 'TTO', 'TTR', etc as defined in the SLT class
  26. * @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
  27. */
  28. protected static function ComputeSLT($oTicket, $sMetric = 'TTO')
  29. {
  30. $iDeadline = null;
  31. if (MetaModel::IsValidClass('SLT'))
  32. {
  33. $sType=get_class($oTicket);
  34. if ($sType == 'Incident')
  35. {
  36. $sRequestType = 'incident';
  37. }
  38. else
  39. {
  40. $sRequestType = $oTicket->Get('request_type');
  41. }
  42. //echo "<p>Managing:".$sMetric."-".$this->Get('request_type')."-".$this->Get('importance')."</p>\n";
  43. $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";
  44. $oSLTSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL),
  45. array(),
  46. array(
  47. 'metric' => $sMetric,
  48. 'service' => $oTicket->Get('service_id'),
  49. 'customer' => $oTicket->Get('org_id'),
  50. 'request_type' => $sRequestType,
  51. 'priority' => $oTicket->Get('priority'),
  52. )
  53. );
  54. $iMinDuration = PHP_INT_MAX;
  55. $sSLTName = '';
  56. while($oSLT = $oSLTSet->Fetch())
  57. {
  58. $iDuration = (int)$oSLT->Get('value');
  59. $sUnit = $oSLT->Get('unit');
  60. switch($sUnit)
  61. {
  62. case 'days':
  63. $iDuration = $iDuration * 24; // 24 hours in 1 days
  64. // Fall though
  65. case 'hours':
  66. $iDuration = $iDuration * 60; // 60 minutes in 1 hour
  67. // Fall though
  68. case 'minutes':
  69. $iDuration = $iDuration * 60;
  70. }
  71. if ($iDuration < $iMinDuration)
  72. {
  73. $iMinDuration = $iDuration;
  74. $sSLTName = $oSLT->GetName();
  75. }
  76. }
  77. if ($iMinDuration == PHP_INT_MAX)
  78. {
  79. $iDeadline = null;
  80. }
  81. else
  82. {
  83. // Store $sSLTName to keep track of which SLT has been used
  84. $iDeadline = $iMinDuration;
  85. }
  86. }
  87. return $iDeadline;
  88. }
  89. }
  90. /**
  91. * Compute the TTO of a ticket - null if the class 'SLT' does not exist
  92. */
  93. class ResponseTicketTTO extends ResponseTicketSLT implements iMetricComputer
  94. {
  95. public static function GetDescription()
  96. {
  97. return "Time to own a ticket";
  98. }
  99. public function ComputeMetric($oObject)
  100. {
  101. $iRes = $this->ComputeSLT($oObject, 'TTO');
  102. return $iRes;
  103. }
  104. }
  105. /**
  106. * Compute the TTR of a ticket - null if the class 'SLT' does not exist
  107. */
  108. class ResponseTicketTTR extends ResponseTicketSLT implements iMetricComputer
  109. {
  110. public static function GetDescription()
  111. {
  112. return "Time to resolve a ticket";
  113. }
  114. public function ComputeMetric($oObject)
  115. {
  116. $iRes = $this->ComputeSLT($oObject, 'TTR');
  117. return $iRes;
  118. }
  119. }
  120. ?>