model.itop-incident-mgmt.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. * Persistent classes for a CMDB
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. class Incident extends ResponseTicket
  25. {
  26. public static function Init()
  27. {
  28. $aParams = array
  29. (
  30. "category" => "bizmodel,searchable,incidentmgmt",
  31. "key_type" => "autoincrement",
  32. "name_attcode" => "ref",
  33. "state_attcode" => "status",
  34. "reconc_keys" => array("ref"),
  35. "db_table" => "ticket_incident",
  36. "db_key_field" => "id",
  37. "db_finalclass_field" => "",
  38. "display_template" => "",
  39. "icon" => "../modules/itop-incident-mgmt-1.0.0/images/incident.png",
  40. );
  41. MetaModel::Init_Params($aParams);
  42. MetaModel::Init_InheritAttributes();
  43. MetaModel::Init_InheritLifecycle();
  44. MetaModel::Init_SetZListItems('details', array('document_list', 'ci_list', 'contact_list','incident_list',
  45. 'col:col1' => array(
  46. 'fieldset:Ticket:baseinfo' => array('ref','title','org_id','status','priority','service_id','servicesubcategory_id','product' ),
  47. 'fieldset:Ticket:moreinfo' => array('impact','urgency','description','resolution_code', 'solution', 'user_satisfaction', 'user_commment',),
  48. ),
  49. 'col:col2' => array(
  50. 'fieldset:Ticket:date' => array('start_date','last_update','assignment_date','tto_escalation_deadline', 'ttr_escalation_deadline', 'close_date','closure_deadline',),
  51. 'fieldset:Ticket:contact' => array('caller_id','workgroup_id','agent_id',),
  52. 'fieldset:Ticket:relation' => array('related_problem_id', 'related_change_id',),
  53. )
  54. ));
  55. // MetaModel::Init_SetZListItems('details', array('ref', 'title', 'org_id', 'description', 'start_date', 'tto_escalation_deadline', 'ttr_escalation_deadline', 'document_list', 'ci_list', 'contact_list','incident_list', 'status', 'caller_id', 'service_id', 'servicesubcategory_id', 'product', 'impact', 'urgency', 'priority', 'workgroup_id', 'agent_id', 'agent_email', 'related_problem_id', 'related_change_id', 'close_date', 'last_update', 'assignment_date', 'closure_deadline', 'resolution_code', 'solution', 'user_satisfaction', 'user_commment','ticket_log',));
  56. MetaModel::Init_SetZListItems('advanced_search', array('ref', 'title', 'org_id', 'start_date', 'status', 'caller_id', 'service_id', 'servicesubcategory_id', 'product', 'impact', 'urgency', 'priority', 'workgroup_id', 'agent_id', 'agent_email', 'related_problem_id', 'related_change_id', 'close_date', 'resolution_code', 'solution', 'user_satisfaction', 'user_commment'));
  57. MetaModel::Init_SetZListItems('standard_search', array('ref', 'title', 'org_id', 'start_date', 'status', 'caller_id', 'service_id', 'servicesubcategory_id', 'product', 'impact', 'urgency', 'priority', 'workgroup_id', 'agent_id', 'agent_email', 'close_date', 'resolution_code', 'solution', 'user_satisfaction', 'user_commment'));
  58. MetaModel::Init_SetZListItems('list', array('title', 'org_id', 'start_date', 'status', 'service_id', 'priority', 'workgroup_id', 'agent_id'));
  59. }
  60. public function ComputeValues()
  61. {
  62. $sCurrRef = $this->Get('ref');
  63. if (strlen($sCurrRef) == 0)
  64. {
  65. $iKey = $this->GetKey();
  66. if ($iKey < 0)
  67. {
  68. // Object not yet in the Database
  69. $iKey = MetaModel::GetNextKey(get_class($this));
  70. }
  71. $sName = sprintf('I-%06d', $iKey);
  72. $this->Set('ref', $sName);
  73. }
  74. return parent::ComputeValues();
  75. }
  76. protected function OnInsert()
  77. {
  78. $oToNotify = $this->Get('contact_list');
  79. $oToImpact = $this->Get('ci_list');
  80. $oImpactedInfras = DBObjectSet::FromLinkSet($this, 'ci_list', 'ci_id');
  81. $aComputed = $oImpactedInfras->GetRelatedObjects('impacts', 10);
  82. if (isset($aComputed['FunctionalCI']) && is_array($aComputed['FunctionalCI']))
  83. {
  84. foreach($aComputed['FunctionalCI'] as $iKey => $oObject)
  85. {
  86. $oNewLink = new lnkTicketToCI();
  87. $oNewLink->Set('ci_id', $iKey);
  88. $oNewLink->Set('impact', 'potentially impacted (automatically computed)');
  89. $oToImpact->AddObject($oNewLink);
  90. }
  91. }
  92. if (isset($aComputed['Contact']) && is_array($aComputed['Contact']))
  93. {
  94. foreach($aComputed['Contact'] as $iKey => $oObject)
  95. {
  96. $oNewLink = new lnkTicketToContact();
  97. $oNewLink->Set('contact_id', $iKey);
  98. $oNewLink->Set('role', 'contact automatically computed');
  99. $oToNotify->AddObject($oNewLink);
  100. }
  101. }
  102. parent::OnInsert();
  103. }
  104. /**
  105. * Get the icon representing this object
  106. * @param boolean $bImgTag If true the result is a full IMG tag (or an emtpy string if no icon is defined)
  107. * @return string Either the full IMG tag ($bImgTag == true) or just the path to the icon file
  108. */
  109. public function GetIcon($bImgTag = true)
  110. {
  111. $sStatus = $this->Get('status');
  112. switch($this->GetState())
  113. {
  114. case 'escalated_tto':
  115. case 'escalated_ttr':
  116. $sIcon = self::MakeIconFromName('incident-escalated.png');
  117. break;
  118. case 'resolved':
  119. case 'closed':
  120. $sIcon = self::MakeIconFromName('incident-closed.png');
  121. break;
  122. case 'new':
  123. $sIcon = self::MakeIconFromName('incident.png');
  124. $oEscalationDeadline = $this->Get('tto_escalation_deadline');
  125. if ($oEscalationDeadline != null)
  126. {
  127. // A SLA is running
  128. $iStartDate = AttributeDateTime::GetAsUnixSeconds($this->Get('start_date'));
  129. $iEscalationDeadline = AttributeDateTime::GetAsUnixSeconds($oEscalationDeadline);
  130. $ratio = ($iEscalationDeadline - time())/($iEscalationDeadline - $iStartDate);
  131. if ($ratio <= 0)
  132. {
  133. $sIcon = self::MakeIconFromName('incident-escalated.png');
  134. }
  135. else if ($ratio <= 0.25)
  136. {
  137. $sIcon = self::MakeIconFromName('incident-deadline.png');
  138. }
  139. }
  140. break;
  141. case 'assigned':
  142. $sIcon = self::MakeIconFromName('incident.png');
  143. $oEscalationDeadline = $this->Get('ttr_escalation_deadline');
  144. if ($oEscalationDeadline != null)
  145. {
  146. // A SLA is running
  147. $iStartDate = AttributeDateTime::GetAsUnixSeconds($this->Get('start_date'));
  148. $iEscalationDeadline = AttributeDateTime::GetAsUnixSeconds($oEscalationDeadline);
  149. $ratio = ($iEscalationDeadline - time())/($iEscalationDeadline - $iStartDate);
  150. if ($ratio <= 0)
  151. {
  152. $sIcon = self::MakeIconFromName('incident-escalated.png');
  153. }
  154. else if ($ratio <= 0.25)
  155. {
  156. $sIcon = self::MakeIconFromName('incident-deadline.png');
  157. }
  158. }
  159. break;
  160. default:
  161. $sIcon = MetaModel::GetClassIcon(get_class($this), $bImgTag);
  162. }
  163. return $sIcon;
  164. }
  165. protected static function MakeIconFromName($sIconName, $bImgTag = true)
  166. {
  167. $sIcon = '';
  168. if ($sIconName != '')
  169. {
  170. $sPath = '../modules/itop-incident-mgmt-1.0.0/images/'.$sIconName;
  171. if ($bImgTag)
  172. {
  173. $sIcon = "<img src=\"$sPath\" style=\"vertical-align:middle;\"/>";
  174. }
  175. else
  176. {
  177. $sIcon = $sPath;
  178. }
  179. }
  180. return $sIcon;
  181. }
  182. }
  183. class lnkTicketToIncident extends cmdbAbstractObject
  184. {
  185. public static function Init()
  186. {
  187. $aParams = array
  188. (
  189. "category" => "bizmodel,searchable,incidentmgmt,requestmgmt,lnkincident",
  190. "key_type" => "autoincrement",
  191. "name_attcode" => "ticket_id",
  192. "state_attcode" => "",
  193. "reconc_keys" => array("ticket_id","incident_id"),
  194. "db_table" => "lnktickettoincident",
  195. "db_key_field" => "id",
  196. "db_finalclass_field" => "",
  197. "display_template" => "",
  198. );
  199. MetaModel::Init_Params($aParams);
  200. MetaModel::Init_InheritAttributes();
  201. MetaModel::Init_AddAttribute(new AttributeExternalKey("ticket_id", array("targetclass"=>"Ticket", "jointype"=>null, "allowed_values"=>null, "sql"=>"ticket_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  202. MetaModel::Init_AddAttribute(new AttributeExternalField("ticket_ref", array("allowed_values"=>null, "extkey_attcode"=>"ticket_id", "target_attcode"=>"ref", "is_null_allowed"=>true, "depends_on"=>array())));
  203. MetaModel::Init_AddAttribute(new AttributeExternalKey("incident_id", array("targetclass"=>"Incident", "jointype"=>null, "allowed_values"=>null, "sql"=>"incident_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  204. MetaModel::Init_AddAttribute(new AttributeExternalField("incident_ref", array("allowed_values"=>null, "extkey_attcode"=>"incident_id", "target_attcode"=>"ref", "is_null_allowed"=>true, "depends_on"=>array())));
  205. MetaModel::Init_AddAttribute(new AttributeString("reason", array("allowed_values"=>null, "sql"=>"reason", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  206. MetaModel::Init_SetZListItems('details', array('ticket_id', 'incident_id','reason'));
  207. MetaModel::Init_SetZListItems('advanced_search', array('ticket_id', 'incident_id'));
  208. MetaModel::Init_SetZListItems('standard_search', array('ticket_id', 'incident_id'));
  209. MetaModel::Init_SetZListItems('list', array('ticket_id', 'incident_id','reason'));
  210. }
  211. }
  212. $oMyMenuGroup = new MenuGroup('IncidentManagement', 40 /* fRank */);
  213. new TemplateMenuNode('Incident:Overview', '../modules/itop-incident-mgmt-1.0.0/overview.html', $oMyMenuGroup->GetIndex() /* oParent */, 0 /* fRank */);
  214. new NewObjectMenuNode('NewIncident', 'Incident', $oMyMenuGroup->GetIndex(), 1 /* fRank */);
  215. new SearchMenuNode('SearchIncidents', 'Incident', $oMyMenuGroup->GetIndex(), 2 /* fRank */);
  216. $oShortcutNode = new TemplateMenuNode('Incident:Shortcuts', '', $oMyMenuGroup->GetIndex(), 3 /* fRank */);
  217. $oNode = new OQLMenuNode('Incident:MyIncidents', 'SELECT Incident WHERE agent_id = :current_contact_id AND status NOT IN ("closed", "resolved")', $oShortcutNode->GetIndex(), 1 /* fRank */);
  218. $oNode->SetParameters(array('auto_reload' => 'fast'));
  219. $oNode = new OQLMenuNode('Incident:EscalatedIncidents', 'SELECT Incident WHERE status IN ("escalated_tto", "escalated_ttr")', $oShortcutNode->GetIndex(), 2 /* fRank */);
  220. $oNode->SetParameters(array('auto_reload' => 'fast'));
  221. $oNode = new OQLMenuNode('Incident:OpenIncidents', 'SELECT Incident WHERE status IN ("new", "assigned", "escalated_tto", "escalated_ttr", "resolved")', $oShortcutNode->GetIndex(), 3 /* fRank */);
  222. $oNode->SetParameters(array('auto_reload' => 'standard'));
  223. ?>