main.itop-tickets.php 3.7 KB

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