main.itop-tickets.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. $oSLTSet = new DBObjectSet(DBObjectSearch::FromOQL(RESPONSE_TICKET_SLT_QUERY),
  44. array(),
  45. array(
  46. 'metric' => $sMetric,
  47. 'service' => $oTicket->Get('service_id'),
  48. 'customer' => $oTicket->Get('org_id'),
  49. 'request_type' => $sRequestType,
  50. 'priority' => $oTicket->Get('priority'),
  51. )
  52. );
  53. $iMinDuration = PHP_INT_MAX;
  54. $sSLTName = '';
  55. while($oSLT = $oSLTSet->Fetch())
  56. {
  57. $iDuration = (int)$oSLT->Get('value');
  58. $sUnit = $oSLT->Get('unit');
  59. switch($sUnit)
  60. {
  61. case 'days':
  62. $iDuration = $iDuration * 24; // 24 hours in 1 days
  63. // Fall though
  64. case 'hours':
  65. $iDuration = $iDuration * 60; // 60 minutes in 1 hour
  66. // Fall though
  67. case 'minutes':
  68. $iDuration = $iDuration * 60;
  69. }
  70. if ($iDuration < $iMinDuration)
  71. {
  72. $iMinDuration = $iDuration;
  73. $sSLTName = $oSLT->GetName();
  74. }
  75. }
  76. if ($iMinDuration == PHP_INT_MAX)
  77. {
  78. $iDeadline = null;
  79. }
  80. else
  81. {
  82. // Store $sSLTName to keep track of which SLT has been used
  83. $iDeadline = $iMinDuration;
  84. }
  85. }
  86. return $iDeadline;
  87. }
  88. }
  89. /**
  90. * Compute the TTO of a ticket - null if the class 'SLT' does not exist
  91. */
  92. class ResponseTicketTTO extends ResponseTicketSLT implements iMetricComputer
  93. {
  94. public static function GetDescription()
  95. {
  96. return "Time to own a ticket";
  97. }
  98. public function ComputeMetric($oObject)
  99. {
  100. $iRes = $this->ComputeSLT($oObject, 'TTO');
  101. return $iRes;
  102. }
  103. }
  104. /**
  105. * Compute the TTR of a ticket - null if the class 'SLT' does not exist
  106. */
  107. class ResponseTicketTTR extends ResponseTicketSLT implements iMetricComputer
  108. {
  109. public static function GetDescription()
  110. {
  111. return "Time to resolve a ticket";
  112. }
  113. public function ComputeMetric($oObject)
  114. {
  115. $iRes = $this->ComputeSLT($oObject, 'TTR');
  116. return $iRes;
  117. }
  118. }
  119. ?>