model.itop-tickets.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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. abstract class Ticket extends cmdbAbstractObject
  25. {
  26. public static function Init()
  27. {
  28. $aParams = array
  29. (
  30. "category" => "bizmodel,searchable",
  31. "key_type" => "autoincrement",
  32. "name_attcode" => "ref",
  33. "state_attcode" => "",
  34. "reconc_keys" => array("ref"),
  35. "db_table" => "ticket",
  36. "db_key_field" => "id",
  37. "db_finalclass_field" => "",
  38. "display_template" => "",
  39. );
  40. MetaModel::Init_Params($aParams);
  41. MetaModel::Init_InheritAttributes();
  42. MetaModel::Init_AddAttribute(new AttributeString("ref", array("allowed_values"=>null, "sql"=>"ref", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  43. MetaModel::Init_AddAttribute(new AttributeString("title", array("allowed_values"=>null, "sql"=>"title", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  44. MetaModel::Init_AddAttribute(new AttributeText("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  45. MetaModel::Init_AddAttribute(new AttributeCaseLog("ticket_log", array("allowed_values"=>null, "sql"=>"ticket_log", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  46. MetaModel::Init_AddAttribute(new AttributeDateTime("start_date", array("allowed_values"=>null, "sql"=>"start_date", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  47. MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("document_list", array("linked_class"=>"lnkTicketToDoc", "ext_key_to_me"=>"ticket_id", "ext_key_to_remote"=>"document_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array())));
  48. MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("ci_list", array("linked_class"=>"lnkTicketToCI", "ext_key_to_me"=>"ticket_id", "ext_key_to_remote"=>"ci_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array())));
  49. MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("contact_list", array("linked_class"=>"lnkTicketToContact", "ext_key_to_me"=>"ticket_id", "ext_key_to_remote"=>"contact_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array())));
  50. MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("incident_list", array("linked_class"=>"lnkTicketToIncident", "ext_key_to_me"=>"ticket_id", "ext_key_to_remote"=>"incident_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array())));
  51. MetaModel::Init_SetZListItems('details', array('ref', 'title', 'description', 'start_date', 'document_list', 'ci_list', 'contact_list','incident_list'));
  52. MetaModel::Init_SetZListItems('advanced_search', array('finalclass', 'ref', 'title', 'start_date'));
  53. MetaModel::Init_SetZListItems('standard_search', array('finalclass', 'ref', 'title', 'start_date'));
  54. MetaModel::Init_SetZListItems('list', array('finalclass', 'ref', 'title', 'ticket_log', 'start_date'));
  55. }
  56. }
  57. class lnkTicketToDoc extends cmdbAbstractObject
  58. {
  59. public static function Init()
  60. {
  61. $aParams = array
  62. (
  63. "category" => "bizmodel,searchable,incidentmgmt,requestmgmt,changemgmt,problemmgmt,lnkticket",
  64. "key_type" => "autoincrement",
  65. "name_attcode" => "ticket_id",
  66. "state_attcode" => "",
  67. "reconc_keys" => array("ticket_id","document_id"),
  68. "db_table" => "lnktickettodoc",
  69. "db_key_field" => "id",
  70. "db_finalclass_field" => "",
  71. "display_template" => "",
  72. );
  73. MetaModel::Init_Params($aParams);
  74. MetaModel::Init_InheritAttributes();
  75. 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())));
  76. 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())));
  77. MetaModel::Init_AddAttribute(new AttributeExternalKey("document_id", array("targetclass"=>"Document", "jointype"=>null, "allowed_values"=>null, "sql"=>"document_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  78. MetaModel::Init_AddAttribute(new AttributeExternalField("document_name", array("allowed_values"=>null, "extkey_attcode"=>"document_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
  79. MetaModel::Init_SetZListItems('details', array('ticket_id', 'document_id'));
  80. MetaModel::Init_SetZListItems('advanced_search', array('ticket_id', 'document_id'));
  81. MetaModel::Init_SetZListItems('standard_search', array('ticket_id', 'document_id'));
  82. MetaModel::Init_SetZListItems('list', array('ticket_id', 'document_id'));
  83. }
  84. }
  85. class lnkTicketToContact extends cmdbAbstractObject
  86. {
  87. public static function Init()
  88. {
  89. $aParams = array
  90. (
  91. "category" => "bizmodel,searchable,incidentmgmt,requestmgmt,changemgmt,problemmgmt,lnkticket",
  92. "key_type" => "autoincrement",
  93. "name_attcode" => "ticket_id",
  94. "state_attcode" => "",
  95. "reconc_keys" => array("ticket_id","contact_id"),
  96. "db_table" => "lnktickettocontact",
  97. "db_key_field" => "id",
  98. "db_finalclass_field" => "",
  99. "display_template" => "",
  100. );
  101. MetaModel::Init_Params($aParams);
  102. MetaModel::Init_InheritAttributes();
  103. 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())));
  104. 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())));
  105. MetaModel::Init_AddAttribute(new AttributeExternalKey("contact_id", array("targetclass"=>"Contact", "jointype"=>null, "allowed_values"=>null, "sql"=>"contact_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  106. MetaModel::Init_AddAttribute(new AttributeExternalField("contact_name", array("allowed_values"=>null, "extkey_attcode"=>"contact_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
  107. MetaModel::Init_AddAttribute(new AttributeExternalField("contact_email", array("allowed_values"=>null, "extkey_attcode"=>"contact_id", "target_attcode"=>"email", "is_null_allowed"=>true, "depends_on"=>array())));
  108. MetaModel::Init_AddAttribute(new AttributeString("role", array("allowed_values"=>null, "sql"=>"role", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  109. MetaModel::Init_SetZListItems('details', array('ticket_id', 'contact_id', 'contact_email', 'role'));
  110. MetaModel::Init_SetZListItems('advanced_search', array('ticket_id', 'contact_id', 'contact_email', 'role'));
  111. MetaModel::Init_SetZListItems('standard_search', array('ticket_id', 'contact_id', 'contact_email', 'role'));
  112. MetaModel::Init_SetZListItems('list', array('ticket_id', 'contact_id', 'contact_email', 'role'));
  113. }
  114. }
  115. class lnkTicketToCI extends cmdbAbstractObject
  116. {
  117. public static function Init()
  118. {
  119. $aParams = array
  120. (
  121. "category" => "bizmodel,searchable,incidentmgmt,requestmgmt,changemgmt,problemmgmt,lnkticket",
  122. "key_type" => "autoincrement",
  123. "name_attcode" => "ticket_id",
  124. "state_attcode" => "",
  125. "reconc_keys" => array("ticket_id","ci_id"),
  126. "db_table" => "lnktickettoci",
  127. "db_key_field" => "id",
  128. "db_finalclass_field" => "",
  129. "display_template" => "",
  130. );
  131. MetaModel::Init_Params($aParams);
  132. MetaModel::Init_InheritAttributes();
  133. 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())));
  134. 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())));
  135. MetaModel::Init_AddAttribute(new AttributeExternalKey("ci_id", array("targetclass"=>"FunctionalCI", "jointype"=>null, "allowed_values"=>null, "sql"=>"ci_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  136. MetaModel::Init_AddAttribute(new AttributeExternalField("ci_name", array("allowed_values"=>null, "extkey_attcode"=>"ci_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
  137. MetaModel::Init_AddAttribute(new AttributeExternalField("ci_status", array("allowed_values"=>null, "extkey_attcode"=>"ci_id", "target_attcode"=>"status", "is_null_allowed"=>true, "depends_on"=>array())));
  138. MetaModel::Init_AddAttribute(new AttributeString("impact", array("allowed_values"=>null, "sql"=>"impact", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  139. MetaModel::Init_SetZListItems('details', array('ticket_id', 'ci_id', 'impact','ci_status'));
  140. MetaModel::Init_SetZListItems('advanced_search', array('ticket_id', 'ci_id', 'ci_status'));
  141. MetaModel::Init_SetZListItems('standard_search', array('ticket_id', 'ci_id', 'ci_status'));
  142. MetaModel::Init_SetZListItems('list', array('ticket_id', 'ci_id', 'impact','ci_status'));
  143. }
  144. }
  145. abstract class ResponseTicket extends Ticket
  146. {
  147. public static function Init()
  148. {
  149. $aParams = array
  150. (
  151. "category" => "bizmodel",
  152. "key_type" => "autoincrement",
  153. "name_attcode" => "ref",
  154. "state_attcode" => "status",
  155. "reconc_keys" => array("ref"),
  156. "db_table" => "ticket_response",
  157. "db_key_field" => "id",
  158. "db_finalclass_field" => "",
  159. "display_template" => "",
  160. );
  161. MetaModel::Init_Params($aParams);
  162. MetaModel::Init_InheritAttributes();
  163. MetaModel::Init_AddAttribute(new AttributeEnum("status", array("allowed_values"=>new ValueSetEnum('new,assigned,frozen,escalated_tto,escalated_ttr,resolved,closed'), "sql"=>"status", "default_value"=>"new", "is_null_allowed"=>false, "depends_on"=>array())));
  164. MetaModel::Init_AddAttribute(new AttributeExternalKey("caller_id", array("targetclass"=>"Person", "jointype"=>null, "allowed_values"=>new ValueSetObjects('SELECT Person WHERE org_id = :this->org_id'), "sql"=>"caller_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array("org_id"))));
  165. MetaModel::Init_AddAttribute(new AttributeExternalField("caller_email", array("allowed_values"=>null, "extkey_attcode"=>"caller_id", "target_attcode"=>"email", "is_null_allowed"=>true, "depends_on"=>array())));
  166. MetaModel::Init_AddAttribute(new AttributeExternalKey("org_id", array("targetclass"=>"Organization", "jointype"=>null, "allowed_values"=>null, "sql"=>"org_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  167. MetaModel::Init_AddAttribute(new AttributeExternalField("org_name", array("allowed_values"=>null, "extkey_attcode"=>"org_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
  168. MetaModel::Init_AddAttribute(new AttributeExternalKey("service_id", array("targetclass"=>"Service", "jointype"=>null, "allowed_values"=>new ValueSetObjects('SELECT Service AS s JOIN SLA AS sla ON sla.service_id=s.id JOIN lnkContractToSLA AS ln ON ln.sla_id=sla.id JOIN CustomerContract AS cc ON ln.contract_id=cc.id WHERE cc.org_id =:this->org_id'), "sql"=>"service_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array("org_id"))));
  169. MetaModel::Init_AddAttribute(new AttributeExternalField("service_name", array("allowed_values"=>null, "extkey_attcode"=>"service_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
  170. MetaModel::Init_AddAttribute(new AttributeExternalKey("servicesubcategory_id", array("targetclass"=>"ServiceSubcategory", "jointype"=>null, "allowed_values"=>new ValueSetObjects('SELECT ServiceSubcategory WHERE service_id = :this->service_id'), "sql"=>"servicesubcategory_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array("service_id"))));
  171. MetaModel::Init_AddAttribute(new AttributeExternalField("servicesubcategory_name", array("allowed_values"=>null, "extkey_attcode"=>"servicesubcategory_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
  172. MetaModel::Init_AddAttribute(new AttributeString("product", array("allowed_values"=>null, "sql"=>"product", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  173. MetaModel::Init_AddAttribute(new AttributeEnum("impact", array("allowed_values"=>new ValueSetEnum('1,2,3'), "sql"=>"impact", "default_value"=>"1", "is_null_allowed"=>false, "depends_on"=>array())));
  174. MetaModel::Init_AddAttribute(new AttributeEnum("urgency", array("allowed_values"=>new ValueSetEnum('1,2,3'), "sql"=>"urgency", "default_value"=>"1", "is_null_allowed"=>false, "depends_on"=>array())));
  175. MetaModel::Init_AddAttribute(new AttributeEnum("priority", array("allowed_values"=>new ValueSetEnum('1,2,3'), "sql"=>"priority", "default_value"=>"1", "is_null_allowed"=>false, "depends_on"=>array())));
  176. MetaModel::Init_AddAttribute(new AttributeExternalKey("workgroup_id", array("targetclass"=>"Team", "jointype"=>null, "allowed_values"=>new ValueSetObjects('SELECT Team AS t JOIN CustomerContract AS cc ON cc.support_team_id=t.id JOIN lnkContractToSLA AS ln ON ln.contract_id=cc.id JOIN SLA AS sla ON ln.sla_id=sla.id WHERE sla.service_id = :this->service_id AND cc.org_id = :this->org_id'), "sql"=>"workgroup_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array("org_id","service_id"))));
  177. MetaModel::Init_AddAttribute(new AttributeExternalField("workgroup_name", array("allowed_values"=>null, "extkey_attcode"=>"workgroup_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
  178. MetaModel::Init_AddAttribute(new AttributeExternalKey("agent_id", array("targetclass"=>"Person", "jointype"=>null, "allowed_values"=>new ValueSetObjects('SELECT Person AS p JOIN lnkTeamToContact AS l ON l.contact_id=p.id JOIN Team AS t ON l.team_id=t.id WHERE t.id = :this->workgroup_id'), "sql"=>"agent_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array("workgroup_id"))));
  179. MetaModel::Init_AddAttribute(new AttributeExternalField("agent_name", array("allowed_values"=>null, "extkey_attcode"=>"agent_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
  180. MetaModel::Init_AddAttribute(new AttributeExternalField("agent_email", array("allowed_values"=>null, "extkey_attcode"=>"agent_id", "target_attcode"=>"email", "is_null_allowed"=>true, "depends_on"=>array())));
  181. MetaModel::Init_AddAttribute(new AttributeExternalKey("related_problem_id", array("targetclass"=>"Problem", "jointype"=>null, "allowed_values"=>null, "sql"=>"related_problem_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  182. MetaModel::Init_AddAttribute(new AttributeExternalField("related_problem_ref", array("allowed_values"=>null, "extkey_attcode"=>"related_problem_id", "target_attcode"=>"ref", "is_null_allowed"=>true, "depends_on"=>array())));
  183. MetaModel::Init_AddAttribute(new AttributeExternalKey("related_change_id", array("targetclass"=>"Change", "jointype"=>null, "allowed_values"=>null, "sql"=>"related_change_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  184. MetaModel::Init_AddAttribute(new AttributeExternalField("related_change_ref", array("allowed_values"=>null, "extkey_attcode"=>"related_change_id", "target_attcode"=>"ref", "is_null_allowed"=>true, "depends_on"=>array())));
  185. MetaModel::Init_AddAttribute(new AttributeDateTime("close_date", array("allowed_values"=>null, "sql"=>"close_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  186. MetaModel::Init_AddAttribute(new AttributeDateTime("last_update", array("allowed_values"=>null, "sql"=>"last_update", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  187. MetaModel::Init_AddAttribute(new AttributeDateTime("assignment_date", array("allowed_values"=>null, "sql"=>"assignment_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  188. MetaModel::Init_AddAttribute(new AttributeDateTime("resolution_date", array("allowed_values"=>null, "sql"=>"resolution_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  189. MetaModel::Init_AddAttribute(new AttributeDeadline("tto_escalation_deadline", array("allowed_values"=>null, "sql"=>"tto_escalation_deadline", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  190. MetaModel::Init_AddAttribute(new AttributeDeadline("ttr_escalation_deadline", array("allowed_values"=>null, "sql"=>"ttr_escalation_deadline", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  191. MetaModel::Init_AddAttribute(new AttributeDeadline("closure_deadline", array("allowed_values"=>null, "sql"=>"closure_deadline", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  192. MetaModel::Init_AddAttribute(new AttributeEnum("resolution_code", array("allowed_values"=>new ValueSetEnum('fixed,duplicate,couldnotreproduce,irrelevant'), "sql"=>"resolution_code", "default_value"=>"fixed", "is_null_allowed"=>true, "depends_on"=>array())));
  193. MetaModel::Init_AddAttribute(new AttributeText("solution", array("allowed_values"=>null, "sql"=>"solution", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  194. MetaModel::Init_AddAttribute(new AttributeEnum("user_satisfaction", array("allowed_values"=>new ValueSetEnum('1,2,3,4'), "sql"=>"user_satisfaction", "default_value"=>"1", "is_null_allowed"=>true, "depends_on"=>array())));
  195. MetaModel::Init_AddAttribute(new AttributeText("user_commment", array("allowed_values"=>null, "sql"=>"user_commment", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  196. MetaModel::Init_SetZListItems('details', array('ref', 'title', 'org_id', 'start_date', 'tto_escalation_deadline', 'ttr_escalation_deadline', 'closure_deadline', 'document_list', 'ci_list', 'contact_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', 'resolution_code', 'solution', 'user_satisfaction', 'user_commment'));
  197. MetaModel::Init_SetZListItems('advanced_search', array('finalclass', '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', 'last_update', 'assignment_date', 'tto_escalation_deadline', 'ttr_escalation_deadline', 'closure_deadline', 'resolution_code', 'solution', 'user_satisfaction', 'user_commment'));
  198. MetaModel::Init_SetZListItems('standard_search', array('finalclass', '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'));
  199. MetaModel::Init_SetZListItems('list', array('finalclass', 'title', 'org_id', 'start_date', 'status', 'caller_id', 'service_id', 'priority', 'workgroup_id', 'agent_id', 'last_update'));
  200. // Lifecycle
  201. MetaModel::Init_DefineState(
  202. "new",
  203. array(
  204. "attribute_inherit" => null,
  205. "attribute_list" => array(
  206. 'ref' => OPT_ATT_READONLY,
  207. 'caller_id' => OPT_ATT_MANDATORY,
  208. 'related_change_id' => OPT_ATT_HIDDEN,
  209. 'description' => OPT_ATT_MUSTCHANGE,
  210. 'contact_list' => OPT_ATT_READONLY,
  211. 'start_date' => OPT_ATT_READONLY,
  212. 'last_update' => OPT_ATT_READONLY,
  213. 'assignment_date' => OPT_ATT_HIDDEN,
  214. 'resolution_date' => OPT_ATT_HIDDEN,
  215. 'tto_escalation_deadline' => OPT_ATT_READONLY,
  216. 'ttr_escalation_deadline' => OPT_ATT_HIDDEN,
  217. 'closure_deadline' => OPT_ATT_HIDDEN,
  218. 'close_date' => OPT_ATT_HIDDEN,
  219. 'org_id' => OPT_ATT_MUSTCHANGE,
  220. 'service_id' => OPT_ATT_MUSTCHANGE,
  221. 'servicesubcategory_id' => OPT_ATT_MUSTCHANGE,
  222. 'product' => OPT_ATT_MUSTPROMPT,
  223. 'impact' => OPT_ATT_MUSTCHANGE,
  224. 'urgency' => OPT_ATT_MUSTCHANGE,
  225. 'priority' => OPT_ATT_READONLY,
  226. 'workgroup_id' => OPT_ATT_MUSTCHANGE,
  227. 'agent_id' => OPT_ATT_HIDDEN,
  228. 'agent_email' => OPT_ATT_HIDDEN,
  229. 'resolution_code' => OPT_ATT_HIDDEN,
  230. 'solution' => OPT_ATT_HIDDEN,
  231. 'user_satisfaction' => OPT_ATT_HIDDEN,
  232. 'related_problem_id' => OPT_ATT_HIDDEN,
  233. 'related_change_id' => OPT_ATT_HIDDEN,
  234. 'user_commment' => OPT_ATT_HIDDEN,
  235. ),
  236. )
  237. );
  238. MetaModel::Init_DefineState(
  239. "escalated_tto",
  240. array(
  241. "attribute_inherit" => 'new',
  242. "attribute_list" => array(
  243. ),
  244. )
  245. );
  246. MetaModel::Init_DefineState(
  247. "assigned",
  248. array(
  249. "attribute_inherit" => 'new',
  250. "attribute_list" => array(
  251. 'title' => OPT_ATT_READONLY,
  252. 'caller_id' => OPT_ATT_READONLY,
  253. 'org_id' => OPT_ATT_READONLY,
  254. 'ticket_log' => OPT_ATT_NORMAL,
  255. 'description' => OPT_ATT_READONLY,
  256. 'agent_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  257. 'agent_email' => OPT_ATT_READONLY,
  258. 'workgroup_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  259. 'tto_escalation_deadline' => OPT_ATT_HIDDEN,
  260. 'ttr_escalation_deadline' => OPT_ATT_READONLY,
  261. 'related_problem_id' => OPT_ATT_NORMAL,
  262. 'related_change_id' => OPT_ATT_NORMAL,
  263. ),
  264. )
  265. );
  266. MetaModel::Init_DefineState(
  267. "escalated_ttr",
  268. array(
  269. "attribute_inherit" => 'assigned',
  270. "attribute_list" => array(
  271. // MUST_PROMPT is not inherited...but does that make sense
  272. 'agent_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  273. 'workgroup_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  274. ),
  275. )
  276. );
  277. MetaModel::Init_DefineState(
  278. "frozen",
  279. array(
  280. "attribute_inherit" => 'assigned',
  281. "attribute_list" => array(
  282. ),
  283. )
  284. );
  285. MetaModel::Init_DefineState(
  286. "resolved",
  287. array(
  288. "attribute_inherit" => 'assigned',
  289. "attribute_list" => array(
  290. 'service_id' => OPT_ATT_READONLY,
  291. 'servicesubcategory_id' => OPT_ATT_READONLY,
  292. 'product' => OPT_ATT_READONLY,
  293. 'impact' => OPT_ATT_READONLY,
  294. 'workgroup_id' => OPT_ATT_READONLY,
  295. 'agent_id' => OPT_ATT_READONLY,
  296. 'urgency' => OPT_ATT_READONLY,
  297. 'resolution_code' => OPT_ATT_MUSTPROMPT,
  298. 'solution' => OPT_ATT_MUSTPROMPT,
  299. 'closure_deadline' => OPT_ATT_READONLY,
  300. 'ttr_escalation_deadline' => OPT_ATT_HIDDEN,
  301. ),
  302. )
  303. );
  304. MetaModel::Init_DefineState(
  305. "closed",
  306. array(
  307. "attribute_inherit" => 'resolved',
  308. "attribute_list" => array(
  309. 'ticket_log' => OPT_ATT_READONLY,
  310. 'user_satisfaction' => OPT_ATT_MUSTPROMPT,
  311. 'user_commment' => OPT_ATT_MUSTPROMPT,
  312. 'resolution_code' => OPT_ATT_READONLY,
  313. 'solution' => OPT_ATT_READONLY,
  314. 'close_date' => OPT_ATT_READONLY,
  315. 'closure_deadline' => OPT_ATT_HIDDEN,
  316. ),
  317. )
  318. );
  319. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_assign", array()));
  320. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_reassign", array()));
  321. MetaModel::Init_DefineStimulus(new StimulusInternal("ev_timeout", array()));
  322. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_resolve", array()));
  323. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_close", array()));
  324. MetaModel::Init_DefineTransition("new", "ev_assign", array("target_state"=>"assigned", "actions"=>array('SetAssignedDate'), "user_restriction"=>null));
  325. MetaModel::Init_DefineTransition("new", "ev_timeout", array("target_state"=>"escalated_tto", "actions"=>array(), "user_restriction"=>null));
  326. MetaModel::Init_DefineTransition("escalated_tto", "ev_assign", array("target_state"=>"assigned", "actions"=>array('SetAssignedDate'), "user_restriction"=>null));
  327. MetaModel::Init_DefineTransition("assigned", "ev_reassign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  328. MetaModel::Init_DefineTransition("assigned", "ev_timeout", array("target_state"=>"escalated_ttr", "actions"=>array(), "user_restriction"=>null));
  329. MetaModel::Init_DefineTransition("assigned", "ev_resolve", array("target_state"=>"resolved", "actions"=>array('SetResolveDate','SetClosureDeadline'), "user_restriction"=>null));
  330. MetaModel::Init_DefineTransition("escalated_ttr", "ev_reassign", array("target_state"=>"escalated_ttr", "actions"=>array(), "user_restriction"=>null));
  331. MetaModel::Init_DefineTransition("escalated_ttr", "ev_resolve", array("target_state"=>"resolved", "actions"=>array('SetResolveDate','SetClosureDeadline'), "user_restriction"=>null));
  332. MetaModel::Init_DefineTransition("resolved", "ev_reassign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  333. MetaModel::Init_DefineTransition("resolved", "ev_close", array("target_state"=>"closed", "actions"=>array('SetClosureDate'), "user_restriction"=>null));
  334. }
  335. // Lifecycle actions
  336. //
  337. public function SetClosureDeadline($sStimulusCode)
  338. {
  339. $iMaxWaitHours = 24;
  340. $this->Set('closure_deadline', time() + $iMaxWaitHours * 3600);
  341. return true;
  342. }
  343. public function SetAssignedDate($sStimulusCode)
  344. {
  345. $this->Set('assignment_date', time());
  346. return true;
  347. }
  348. public function SetResolveDate($sStimulusCode)
  349. {
  350. $this->Set('resolution_date', time());
  351. return true;
  352. }
  353. public function SetClosureDate($sStimulusCode)
  354. {
  355. $this->Set('close_date', time());
  356. return true;
  357. }
  358. /**
  359. * Determines the shortest SLT, for this ticket, for the given metric. Returns null is no SLT was found
  360. * @param string $sMetric Type of metric 'TTO', 'TTR', etc as defined in the SLT class
  361. * @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
  362. */
  363. public function ComputeSLT($sMetric = 'TTO')
  364. {
  365. $aResult = null;
  366. if (MetaModel::IsValidClass('SLT'))
  367. {
  368. $sOQL = "SELECT SLT JOIN lnkSLTToSLA AS L1 ON L1.slt_id=SLT.id JOIN SLA ON L1.sla_id = SLA.id JOIN lnkContractToSLA AS L2 ON L2.sla_id = SLA.id JOIN CustomerContract ON L2.contract_id = CustomerContract.id
  369. WHERE SLT.ticket_priority = :priority AND SLA.service_id = :service_id AND SLT.metric = :metric AND CustomerContract.org_id = :org_id";
  370. $oSLTSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL),
  371. array(),
  372. array(
  373. 'priority' => $this->Get('priority'),
  374. 'service_id' => $this->Get('service_id'),
  375. 'metric' => $sMetric,
  376. 'org_id' => $this->Get('org_id'),
  377. )
  378. );
  379. $iMinDuration = PHP_INT_MAX;
  380. $sSLTName = '';
  381. while($oSLT = $oSLTSet->Fetch())
  382. {
  383. $iDuration = (int)$oSLT->Get('value');
  384. $sUnit = $oSLT->Get('value_unit');
  385. //echo "<p>Found SLT: ".$oSLT->GetName()." - $iDuration ($sUnit)</p>\n";
  386. switch($sUnit)
  387. {
  388. case 'days':
  389. $iDuration = $iDuration * 24; // 24 hours in 1 days
  390. // Fall though
  391. case 'hours':
  392. $iDuration = $iDuration * 60; // 60 minutes in 1 hour
  393. // Fall though
  394. case 'minutes':
  395. $iDuration = $iDuration * 60;
  396. }
  397. if ($iDuration < $iMinDuration)
  398. {
  399. $iMinDuration = $iDuration;
  400. $sSLTName = $oSLT->GetName();
  401. }
  402. }
  403. if ($iMinDuration == PHP_INT_MAX)
  404. {
  405. $aResult = null;
  406. }
  407. else
  408. {
  409. $aResult = array('SLT' => $sSLTName, 'value' => $iMinDuration);
  410. }
  411. }
  412. return $aResult;
  413. }
  414. /**
  415. * Compute the priority of the ticket based on its impact and urgency
  416. * @return integer The priority of the ticket 1(high) .. 3(low)
  417. */
  418. public function ComputePriority()
  419. {
  420. // priority[impact][urgency]
  421. $aPriorities = array(
  422. // single person
  423. 1 => array(
  424. 1 => 1,
  425. 2 => 1,
  426. 3 => 2,
  427. ),
  428. // a group
  429. 2 => array(
  430. 1 => 1,
  431. 2 => 2,
  432. 3 => 3,
  433. ),
  434. // a departement!
  435. 3 => array(
  436. 1 => 2,
  437. 2 => 3,
  438. 3 => 3,
  439. ),
  440. );
  441. $iPriority = $aPriorities[(int)$this->Get('impact')][(int)$this->Get('urgency')];
  442. return $iPriority;
  443. }
  444. public function ComputeValues()
  445. {
  446. // Compute the priority of the ticket
  447. $this->Set('priority', $this->ComputePriority());
  448. // Compute the SLA deadlines, if any is applicable to this ticket
  449. $aSLT = $this->ComputeSLT('TTO');
  450. if ($aSLT != null)
  451. {
  452. $oStartDate = new DateTime($this->Get('start_date'));
  453. $oDeadline = SLAComputation::GetDeadline($this, $aSLT['value'], $oStartDate);
  454. $this->Set('tto_escalation_deadline', $oDeadline->format('U'));
  455. }
  456. else
  457. {
  458. $this->Set('tto_escalation_deadline', null);
  459. }
  460. $aSLT = $this->ComputeSLT('TTR');
  461. if ($aSLT != null)
  462. {
  463. $oStartDate = new DateTime($this->Get('start_date'));
  464. $oDeadline = SLAComputation::GetDeadline($this, $aSLT['value'], $oStartDate);
  465. $this->Set('ttr_escalation_deadline', $oDeadline->format('U'));
  466. }
  467. else
  468. {
  469. $this->Set('ttr_escalation_deadline', null);
  470. }
  471. }
  472. /**
  473. * Determines if the ticket must be hilighted in the list, if we're about to miss a SLA for instance
  474. */
  475. public function GetHilightClass()
  476. {
  477. $sHilightClass = '';
  478. switch($this->GetState())
  479. {
  480. case 'new':
  481. $oEscalationDeadline = $this->Get('tto_escalation_deadline');
  482. if ($oEscalationDeadline != null)
  483. {
  484. // A SLA is running
  485. $iStartDate = AttributeDateTime::GetAsUnixSeconds($this->Get('start_date'));
  486. $iEscalationDeadline = AttributeDateTime::GetAsUnixSeconds($oEscalationDeadline);
  487. $ratio = ($iEscalationDeadline - time())/($iEscalationDeadline - $iStartDate);
  488. if ($ratio <= 0)
  489. {
  490. $sHilightClass = HILIGHT_CLASS_CRITICAL;
  491. }
  492. else if ($ratio <= 0.25)
  493. {
  494. $sHilightClass = HILIGHT_CLASS_WARNING;
  495. }
  496. }
  497. break;
  498. case 'assigned':
  499. $oEscalationDeadline = $this->Get('ttr_escalation_deadline');
  500. if ($oEscalationDeadline != null)
  501. {
  502. // A SLA is running
  503. $iStartDate = AttributeDateTime::GetAsUnixSeconds($this->Get('start_date'));
  504. $iEscalationDeadline = AttributeDateTime::GetAsUnixSeconds($oEscalationDeadline);
  505. $ratio = ($iEscalationDeadline - time())/($iEscalationDeadline - $iStartDate);
  506. if ($ratio <= 0)
  507. {
  508. $sHilightClass = HILIGHT_CLASS_CRITICAL;
  509. }
  510. else if ($ratio <= 0.25)
  511. {
  512. $sHilightClass = HILIGHT_CLASS_WARNING;
  513. }
  514. }
  515. break;
  516. case 'escalated_tto':
  517. case 'escalated_ttr':
  518. $sHilightClass = HILIGHT_CLASS_CRITICAL;
  519. break;
  520. }
  521. return $sHilightClass;
  522. }
  523. protected function OnInsert()
  524. {
  525. $this->Set('last_update', time());
  526. }
  527. protected function OnUpdate()
  528. {
  529. $this->Set('last_update', time());
  530. }
  531. /*
  532. EXAMPLE: OnInsert....
  533. protected function OnInsert()
  534. {
  535. // Romain: ajouter cette ligne
  536. $oToNotify = $this->Get('contacts_a_notifier');
  537. // Romain: ca c'etait pour verifier que ca fonctionne bien
  538. // $oFirstContact = MetaModel::GetObject('bizPerson', 6);
  539. // $oNewLink = new lnkContactTicket();
  540. // $oNewLink->Set('contact_id', 6);
  541. // $oNewLink->Set('role', 'created before');
  542. // $oToNotify->AddObject($oNewLink);
  543. $oImpactedInfras = DBObjectSet::FromLinkSet($this, 'impacted_infra_manual', 'ci_id');
  544. $aComputed = $oImpactedInfras->GetRelatedObjects('impacts', 10);
  545. if (array_key_exists('logRealObject', $aComputed))
  546. {
  547. foreach($aComputed['logRealObject'] as $iKey => $oObject)
  548. {
  549. if (MetaModel::IsParentClass('bizContact', get_class($oObject)))
  550. {
  551. $oNewLink = new lnkContactTicket();
  552. $oNewLink->Set('contact_id', $iKey);
  553. //$oNewLink->Set('ticket_id', $this->GetKey()); // unkown at that time!
  554. $oNewLink->Set('role', 'contact automatically computed');
  555. // Romain: transformer cette ligne
  556. $oToNotify->AddObject($oNewLink);
  557. }
  558. }
  559. // Romain: supprimer cette ligne
  560. // $this->Set('contacts_a_notifier', $oToNotify);
  561. }
  562. }
  563. */
  564. }
  565. class ProcessSLAResponseTicket implements iBackgroundProcess
  566. {
  567. public function GetPeriodicity()
  568. {
  569. return 2; // seconds
  570. }
  571. public function Process($iTimeLimit)
  572. {
  573. $oMyChange = new CMDBChange();
  574. $oMyChange->Set("date", time());
  575. $oMyChange->Set("userinfo", "Automatic updates");
  576. $iChangeId = $oMyChange->DBInsertNoReload();
  577. $aReport = array();
  578. $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT ResponseTicket WHERE status = \'new\' AND tto_escalation_deadline <= NOW()'));
  579. while ((time() < $iTimeLimit) && $oToEscalate = $oSet->Fetch())
  580. {
  581. $oToEscalate->ApplyStimulus('ev_timeout');
  582. //$oToEscalate->Set('tto_escalation_deadline', null);
  583. $oToEscalate->DBUpdateTracked($oMyChange, true);
  584. $aReport['reached TTO ESCALATION deadline'][] = $oToEscalate->Get('ref');
  585. }
  586. $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT ResponseTicket WHERE status = \'assigned\' AND ttr_escalation_deadline <= NOW()'));
  587. while ((time() < $iTimeLimit) && $oToEscalate = $oSet->Fetch())
  588. {
  589. $oToEscalate->ApplyStimulus('ev_timeout');
  590. //$oToEscalate->Set('ttr_escalation_deadline', null);
  591. $oToEscalate->DBUpdateTracked($oMyChange, true);
  592. $aReport['reached TTR ESCALATION deadline'][] = $oToEscalate->Get('ref');
  593. }
  594. $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT ResponseTicket WHERE status = \'resolved\' AND closure_deadline <= NOW()'));
  595. while ((time() < $iTimeLimit) && $oToEscalate = $oSet->Fetch())
  596. {
  597. $oToEscalate->ApplyStimulus('ev_close');
  598. //$oToEscalate->Set('closure_deadline', null);
  599. $oToEscalate->DBUpdateTracked($oMyChange, true);
  600. $aReport['reached closure deadline'][] = $oToEscalate->Get('ref');
  601. }
  602. $aStringReport = array();
  603. foreach ($aReport as $sOperation => $aTicketRefs)
  604. {
  605. if (count($aTicketRefs) > 0)
  606. {
  607. $aStringReport[] = $sOperation.': '.count($aTicketRefs).' {'.implode(', ', $aTicketRefs).'}';
  608. }
  609. }
  610. if (count($aStringReport) == 0)
  611. {
  612. return "No ticket to process";
  613. }
  614. else
  615. {
  616. return "Some tickets reached the limit - ".implode('; ', $aStringReport);
  617. }
  618. }
  619. }
  620. ?>