model.itop-tickets.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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,incidentmgmt,requestmgmt,changemgmt,problemmgmt",
  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 AttributeText("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', 'ticket_log', 'start_date', 'document_list', 'ci_list', 'contact_list','incident_list'));
  52. MetaModel::Init_SetZListItems('advanced_search', array('finalclass', 'ref', 'title', 'ticket_log', 'start_date'));
  53. MetaModel::Init_SetZListItems('standard_search', array('finalclass', 'ref', 'title', 'ticket_log', '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",
  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",
  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",
  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,incidentmgmt,requestmgmt",
  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', 'ticket_log', '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. 'ticket_log' => OPT_ATT_HIDDEN,
  208. 'caller_id' => OPT_ATT_MANDATORY,
  209. 'related_change_id' => OPT_ATT_HIDDEN,
  210. 'description' => OPT_ATT_MUSTCHANGE,
  211. 'contact_list' => OPT_ATT_READONLY,
  212. 'start_date' => OPT_ATT_READONLY,
  213. 'last_update' => OPT_ATT_READONLY,
  214. 'assignment_date' => OPT_ATT_HIDDEN,
  215. 'resolution_date' => OPT_ATT_HIDDEN,
  216. 'tto_escalation_deadline' => OPT_ATT_READONLY,
  217. 'ttr_escalation_deadline' => OPT_ATT_HIDDEN,
  218. 'closure_deadline' => OPT_ATT_HIDDEN,
  219. 'close_date' => OPT_ATT_HIDDEN,
  220. 'org_id' => OPT_ATT_MUSTCHANGE,
  221. 'service_id' => OPT_ATT_MUSTCHANGE,
  222. 'servicesubcategory_id' => OPT_ATT_MUSTCHANGE,
  223. 'product' => OPT_ATT_MUSTPROMPT,
  224. 'impact' => OPT_ATT_MUSTCHANGE,
  225. 'urgency' => OPT_ATT_MUSTCHANGE,
  226. 'priority' => OPT_ATT_READONLY,
  227. 'workgroup_id' => OPT_ATT_MUSTCHANGE,
  228. 'agent_id' => OPT_ATT_HIDDEN,
  229. 'agent_email' => OPT_ATT_HIDDEN,
  230. 'resolution_code' => OPT_ATT_HIDDEN,
  231. 'solution' => OPT_ATT_HIDDEN,
  232. 'user_satisfaction' => OPT_ATT_HIDDEN,
  233. 'related_problem_id' => OPT_ATT_HIDDEN,
  234. 'related_change_id' => OPT_ATT_HIDDEN,
  235. 'user_commment' => OPT_ATT_HIDDEN,
  236. ),
  237. )
  238. );
  239. MetaModel::Init_DefineState(
  240. "escalated_tto",
  241. array(
  242. "attribute_inherit" => 'new',
  243. "attribute_list" => array(
  244. ),
  245. )
  246. );
  247. MetaModel::Init_DefineState(
  248. "assigned",
  249. array(
  250. "attribute_inherit" => 'new',
  251. "attribute_list" => array(
  252. 'title' => OPT_ATT_READONLY,
  253. 'caller_id' => OPT_ATT_READONLY,
  254. 'org_id' => OPT_ATT_READONLY,
  255. 'ticket_log' => OPT_ATT_NORMAL,
  256. 'description' => OPT_ATT_READONLY,
  257. 'agent_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  258. 'agent_email' => OPT_ATT_READONLY,
  259. 'workgroup_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  260. 'tto_escalation_deadline' => OPT_ATT_HIDDEN,
  261. 'ttr_escalation_deadline' => OPT_ATT_READONLY,
  262. 'related_problem_id' => OPT_ATT_NORMAL,
  263. 'related_change_id' => OPT_ATT_NORMAL,
  264. ),
  265. )
  266. );
  267. MetaModel::Init_DefineState(
  268. "escalated_ttr",
  269. array(
  270. "attribute_inherit" => 'assigned',
  271. "attribute_list" => array(
  272. // MUST_PROMPT is not inherited...but does that make sense
  273. 'agent_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  274. 'workgroup_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  275. ),
  276. )
  277. );
  278. MetaModel::Init_DefineState(
  279. "frozen",
  280. array(
  281. "attribute_inherit" => 'assigned',
  282. "attribute_list" => array(
  283. ),
  284. )
  285. );
  286. MetaModel::Init_DefineState(
  287. "resolved",
  288. array(
  289. "attribute_inherit" => 'assigned',
  290. "attribute_list" => array(
  291. 'service_id' => OPT_ATT_READONLY,
  292. 'servicesubcategory_id' => OPT_ATT_READONLY,
  293. 'product' => OPT_ATT_READONLY,
  294. 'impact' => OPT_ATT_READONLY,
  295. 'workgroup_id' => OPT_ATT_READONLY,
  296. 'agent_id' => OPT_ATT_READONLY,
  297. 'urgency' => OPT_ATT_READONLY,
  298. 'resolution_code' => OPT_ATT_MUSTPROMPT,
  299. 'solution' => OPT_ATT_MUSTPROMPT,
  300. 'closure_deadline' => OPT_ATT_READONLY,
  301. 'ttr_escalation_deadline' => OPT_ATT_HIDDEN,
  302. ),
  303. )
  304. );
  305. MetaModel::Init_DefineState(
  306. "closed",
  307. array(
  308. "attribute_inherit" => 'resolved',
  309. "attribute_list" => array(
  310. 'ticket_log' => OPT_ATT_READONLY,
  311. 'user_satisfaction' => OPT_ATT_MUSTPROMPT,
  312. 'user_commment' => OPT_ATT_MUSTPROMPT,
  313. 'resolution_code' => OPT_ATT_READONLY,
  314. 'solution' => OPT_ATT_READONLY,
  315. 'close_date' => OPT_ATT_READONLY,
  316. 'closure_deadline' => OPT_ATT_HIDDEN,
  317. ),
  318. )
  319. );
  320. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_assign", array()));
  321. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_reassign", array()));
  322. MetaModel::Init_DefineStimulus(new StimulusInternal("ev_timeout", array()));
  323. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_resolve", array()));
  324. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_close", array()));
  325. MetaModel::Init_DefineTransition("new", "ev_assign", array("target_state"=>"assigned", "actions"=>array('SetAssignedDate'), "user_restriction"=>null));
  326. MetaModel::Init_DefineTransition("new", "ev_timeout", array("target_state"=>"escalated_tto", "actions"=>array(), "user_restriction"=>null));
  327. MetaModel::Init_DefineTransition("escalated_tto", "ev_assign", array("target_state"=>"assigned", "actions"=>array('SetAssignedDate'), "user_restriction"=>null));
  328. MetaModel::Init_DefineTransition("assigned", "ev_reassign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  329. MetaModel::Init_DefineTransition("assigned", "ev_timeout", array("target_state"=>"escalated_ttr", "actions"=>array(), "user_restriction"=>null));
  330. MetaModel::Init_DefineTransition("assigned", "ev_resolve", array("target_state"=>"resolved", "actions"=>array('SetResolveDate','SetClosureDeadline'), "user_restriction"=>null));
  331. MetaModel::Init_DefineTransition("escalated_ttr", "ev_reassign", array("target_state"=>"escalated_ttr", "actions"=>array(), "user_restriction"=>null));
  332. MetaModel::Init_DefineTransition("escalated_ttr", "ev_resolve", array("target_state"=>"resolved", "actions"=>array('SetResolveDate','SetClosureDeadline'), "user_restriction"=>null));
  333. MetaModel::Init_DefineTransition("resolved", "ev_reassign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  334. MetaModel::Init_DefineTransition("resolved", "ev_close", array("target_state"=>"closed", "actions"=>array('SetClosureDate'), "user_restriction"=>null));
  335. }
  336. // Lifecycle actions
  337. //
  338. public function SetClosureDeadline($sStimulusCode)
  339. {
  340. $iMaxWaitHours = 24;
  341. $this->Set('closure_deadline', time() + $iMaxWaitHours * 3600);
  342. return true;
  343. }
  344. public function SetAssignedDate($sStimulusCode)
  345. {
  346. $this->Set('assignment_date', time());
  347. return true;
  348. }
  349. public function SetResolveDate($sStimulusCode)
  350. {
  351. $this->Set('resolution_date', time());
  352. return true;
  353. }
  354. public function SetClosureDate($sStimulusCode)
  355. {
  356. $this->Set('close_date', time());
  357. return true;
  358. }
  359. /**
  360. * Determines the shortest SLT, for this ticket, for the given metric. Returns null is no SLT was found
  361. * @param string $sMetric Type of metric 'TTO', 'TTR', etc as defined in the SLT class
  362. * @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
  363. */
  364. public function ComputeSLT($sMetric = 'TTO')
  365. {
  366. $aResult = null;
  367. if (MetaModel::IsValidClass('SLT'))
  368. {
  369. $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
  370. WHERE SLT.ticket_priority = :priority AND SLA.service_id = :service_id AND SLT.metric = :metric AND CustomerContract.org_id = :org_id";
  371. $oSLTSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL),
  372. array(),
  373. array(
  374. 'priority' => $this->Get('priority'),
  375. 'service_id' => $this->Get('service_id'),
  376. 'metric' => $sMetric,
  377. 'org_id' => $this->Get('org_id'),
  378. )
  379. );
  380. $iMinDuration = PHP_INT_MAX;
  381. $sSLTName = '';
  382. while($oSLT = $oSLTSet->Fetch())
  383. {
  384. $iDuration = (int)$oSLT->Get('value');
  385. $sUnit = $oSLT->Get('value_unit');
  386. //echo "<p>Found SLT: ".$oSLT->GetName()." - $iDuration ($sUnit)</p>\n";
  387. switch($sUnit)
  388. {
  389. case 'days':
  390. $iDuration = $iDuration * 24; // 24 hours in 1 days
  391. // Fall though
  392. case 'hours':
  393. $iDuration = $iDuration * 60; // 60 minutes in 1 hour
  394. // Fall though
  395. case 'minutes':
  396. $iDuration = $iDuration * 60;
  397. }
  398. if ($iDuration < $iMinDuration)
  399. {
  400. $iMinDuration = $iDuration;
  401. $sSLTName = $oSLT->GetName();
  402. }
  403. }
  404. if ($iMinDuration == PHP_INT_MAX)
  405. {
  406. $aResult = null;
  407. }
  408. else
  409. {
  410. $aResult = array('SLT' => $sSLTName, 'value' => $iMinDuration);
  411. }
  412. }
  413. return $aResult;
  414. }
  415. /**
  416. * Compute the priority of the ticket based on its impact and urgency
  417. * @return integer The priority of the ticket 1(high) .. 3(low)
  418. */
  419. public function ComputePriority()
  420. {
  421. // priority[impact][urgency]
  422. $aPriorities = array(
  423. // single person
  424. 1 => array(
  425. 1 => 1,
  426. 2 => 1,
  427. 3 => 2,
  428. ),
  429. // a group
  430. 2 => array(
  431. 1 => 1,
  432. 2 => 2,
  433. 3 => 3,
  434. ),
  435. // a departement!
  436. 3 => array(
  437. 1 => 2,
  438. 2 => 3,
  439. 3 => 3,
  440. ),
  441. );
  442. $iPriority = $aPriorities[(int)$this->Get('impact')][(int)$this->Get('urgency')];
  443. return $iPriority;
  444. }
  445. public function ComputeValues()
  446. {
  447. // Compute the priority of the ticket
  448. $this->Set('priority', $this->ComputePriority());
  449. // Compute the SLA deadlines, if any is applicable to this ticket
  450. $aSLT = $this->ComputeSLT('TTO');
  451. if ($aSLT != null)
  452. {
  453. //echo "<p>TTO: SLT found: {$aSLT['SLT']}, value: {$aSLT['value']}</p>\n";
  454. $iStartDate = AttributeDateTime::GetAsUnixSeconds($this->Get('start_date'));
  455. $this->Set('tto_escalation_deadline', $iStartDate + $aSLT['value']);
  456. }
  457. else
  458. {
  459. $this->Set('tto_escalation_deadline', null);
  460. }
  461. $aSLT = $this->ComputeSLT('TTR');
  462. if ($aSLT != null)
  463. {
  464. //echo "<p>TTR: SLT found: {$aSLT['SLT']}, value: {$aSLT['value']}</p>\n";
  465. $iStartDate = AttributeDateTime::GetAsUnixSeconds($this->Get('start_date'));
  466. $this->Set('ttr_escalation_deadline', $iStartDate + $aSLT['value']);
  467. }
  468. else
  469. {
  470. $this->Set('ttr_escalation_deadline', null);
  471. }
  472. }
  473. /**
  474. * Determines if the ticket must be hilighted in the list, if we're about to miss a SLA for instance
  475. */
  476. public function GetHilightClass()
  477. {
  478. $sHilightClass = '';
  479. switch($this->GetState())
  480. {
  481. case 'new':
  482. $oEscalationDeadline = $this->Get('tto_escalation_deadline');
  483. if ($oEscalationDeadline != null)
  484. {
  485. // A SLA is running
  486. $iStartDate = AttributeDateTime::GetAsUnixSeconds($this->Get('start_date'));
  487. $iEscalationDeadline = AttributeDateTime::GetAsUnixSeconds($oEscalationDeadline);
  488. $ratio = ($iEscalationDeadline - time())/($iEscalationDeadline - $iStartDate);
  489. if ($ratio <= 0)
  490. {
  491. $sHilightClass = HILIGHT_CLASS_CRITICAL;
  492. }
  493. else if ($ratio <= 0.25)
  494. {
  495. $sHilightClass = HILIGHT_CLASS_WARNING;
  496. }
  497. }
  498. break;
  499. case 'assigned':
  500. $oEscalationDeadline = $this->Get('ttr_escalation_deadline');
  501. if ($oEscalationDeadline != null)
  502. {
  503. // A SLA is running
  504. $iStartDate = AttributeDateTime::GetAsUnixSeconds($this->Get('start_date'));
  505. $iEscalationDeadline = AttributeDateTime::GetAsUnixSeconds($oEscalationDeadline);
  506. $ratio = ($iEscalationDeadline - time())/($iEscalationDeadline - $iStartDate);
  507. if ($ratio <= 0)
  508. {
  509. $sHilightClass = HILIGHT_CLASS_CRITICAL;
  510. }
  511. else if ($ratio <= 0.25)
  512. {
  513. $sHilightClass = HILIGHT_CLASS_WARNING;
  514. }
  515. }
  516. break;
  517. case 'escalated_tto':
  518. case 'escalated_ttr':
  519. $sHilightClass = HILIGHT_CLASS_CRITICAL;
  520. break;
  521. }
  522. return $sHilightClass;
  523. }
  524. protected function OnInsert()
  525. {
  526. $this->Set('last_update', time());
  527. }
  528. protected function OnUpdate()
  529. {
  530. $this->Set('last_update', time());
  531. }
  532. /*
  533. EXAMPLE: OnInsert....
  534. protected function OnInsert()
  535. {
  536. // Romain: ajouter cette ligne
  537. $oToNotify = $this->Get('contacts_a_notifier');
  538. // Romain: ca c'etait pour verifier que ca fonctionne bien
  539. // $oFirstContact = MetaModel::GetObject('bizPerson', 6);
  540. // $oNewLink = new lnkContactTicket();
  541. // $oNewLink->Set('contact_id', 6);
  542. // $oNewLink->Set('role', 'created before');
  543. // $oToNotify->AddObject($oNewLink);
  544. $oImpactedInfras = DBObjectSet::FromLinkSet($this, 'impacted_infra_manual', 'ci_id');
  545. $aComputed = $oImpactedInfras->GetRelatedObjects('impacts', 10);
  546. if (array_key_exists('logRealObject', $aComputed))
  547. {
  548. foreach($aComputed['logRealObject'] as $iKey => $oObject)
  549. {
  550. if (MetaModel::IsParentClass('bizContact', get_class($oObject)))
  551. {
  552. $oNewLink = new lnkContactTicket();
  553. $oNewLink->Set('contact_id', $iKey);
  554. //$oNewLink->Set('ticket_id', $this->GetKey()); // unkown at that time!
  555. $oNewLink->Set('role', 'contact automatically computed');
  556. // Romain: transformer cette ligne
  557. $oToNotify->AddObject($oNewLink);
  558. }
  559. }
  560. // Romain: supprimer cette ligne
  561. // $this->Set('contacts_a_notifier', $oToNotify);
  562. }
  563. }
  564. */
  565. }
  566. ?>