main.itop-tickets.php 3.3 KB

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