model.itop-tickets.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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",
  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_SetZListItems('details', array('ref', 'title', 'description', 'ticket_log', 'start_date', 'document_list', 'ci_list', 'contact_list'));
  51. MetaModel::Init_SetZListItems('advanced_search', array('finalclass', 'ref', 'title', 'ticket_log', 'start_date'));
  52. MetaModel::Init_SetZListItems('standard_search', array('finalclass', 'ref', 'title', 'ticket_log', 'start_date'));
  53. MetaModel::Init_SetZListItems('list', array('finalclass', 'ref', 'title', 'ticket_log', 'start_date'));
  54. }
  55. }
  56. class lnkTicketToDoc extends cmdbAbstractObject
  57. {
  58. public static function Init()
  59. {
  60. $aParams = array
  61. (
  62. "category" => "bizmodel,searchable,incidentmgmt,requestmgmt,changemgmt",
  63. "key_type" => "autoincrement",
  64. "name_attcode" => "ticket_id",
  65. "state_attcode" => "",
  66. "reconc_keys" => array(),
  67. "db_table" => "lnktickettodoc",
  68. "db_key_field" => "id",
  69. "db_finalclass_field" => "",
  70. "display_template" => "",
  71. );
  72. MetaModel::Init_Params($aParams);
  73. MetaModel::Init_InheritAttributes();
  74. 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())));
  75. 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())));
  76. 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())));
  77. 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())));
  78. MetaModel::Init_SetZListItems('details', array('ticket_id', 'document_id'));
  79. MetaModel::Init_SetZListItems('advanced_search', array('ticket_id', 'document_id'));
  80. MetaModel::Init_SetZListItems('standard_search', array('ticket_id', 'document_id'));
  81. MetaModel::Init_SetZListItems('list', array('ticket_id', 'document_id'));
  82. }
  83. }
  84. class lnkTicketToContact extends cmdbAbstractObject
  85. {
  86. public static function Init()
  87. {
  88. $aParams = array
  89. (
  90. "category" => "bizmodel,searchable,incidentmgmt,requestmgmt,changemgmt",
  91. "key_type" => "autoincrement",
  92. "name_attcode" => "ticket_id",
  93. "state_attcode" => "",
  94. "reconc_keys" => array(),
  95. "db_table" => "lnktickettocontact",
  96. "db_key_field" => "id",
  97. "db_finalclass_field" => "",
  98. "display_template" => "",
  99. );
  100. MetaModel::Init_Params($aParams);
  101. MetaModel::Init_InheritAttributes();
  102. 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())));
  103. 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())));
  104. 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())));
  105. 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())));
  106. 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())));
  107. MetaModel::Init_AddAttribute(new AttributeString("role", array("allowed_values"=>null, "sql"=>"role", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  108. MetaModel::Init_SetZListItems('details', array('ticket_id', 'contact_id', 'contact_email', 'role'));
  109. MetaModel::Init_SetZListItems('advanced_search', array('ticket_id', 'contact_id', 'contact_email', 'role'));
  110. MetaModel::Init_SetZListItems('standard_search', array('ticket_id', 'contact_id', 'contact_email', 'role'));
  111. MetaModel::Init_SetZListItems('list', array('ticket_id', 'contact_id', 'contact_email', 'role'));
  112. }
  113. }
  114. class lnkTicketToCI extends cmdbAbstractObject
  115. {
  116. public static function Init()
  117. {
  118. $aParams = array
  119. (
  120. "category" => "bizmodel,searchable,incidentmgmt,requestmgmt,changemgmt",
  121. "key_type" => "autoincrement",
  122. "name_attcode" => "ticket_id",
  123. "state_attcode" => "",
  124. "reconc_keys" => array(),
  125. "db_table" => "lnktickettoci",
  126. "db_key_field" => "id",
  127. "db_finalclass_field" => "",
  128. "display_template" => "",
  129. );
  130. MetaModel::Init_Params($aParams);
  131. MetaModel::Init_InheritAttributes();
  132. 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())));
  133. 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())));
  134. 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())));
  135. 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())));
  136. 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())));
  137. MetaModel::Init_SetZListItems('details', array('ticket_id', 'ci_id', 'ci_status'));
  138. MetaModel::Init_SetZListItems('advanced_search', array('ticket_id', 'ci_id', 'ci_status'));
  139. MetaModel::Init_SetZListItems('standard_search', array('ticket_id', 'ci_id', 'ci_status'));
  140. MetaModel::Init_SetZListItems('list', array('ticket_id', 'ci_id', 'ci_status'));
  141. }
  142. }
  143. abstract class ResponseTicket extends Ticket
  144. {
  145. public static function Init()
  146. {
  147. $aParams = array
  148. (
  149. "category" => "bizmodel",
  150. "key_type" => "autoincrement",
  151. "name_attcode" => "ref",
  152. "state_attcode" => "status",
  153. "reconc_keys" => array("ref"),
  154. "db_table" => "ticket_response",
  155. "db_key_field" => "id",
  156. "db_finalclass_field" => "",
  157. "display_template" => "",
  158. );
  159. MetaModel::Init_Params($aParams);
  160. MetaModel::Init_InheritAttributes();
  161. 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())));
  162. 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"))));
  163. 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())));
  164. 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())));
  165. 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())));
  166. 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"))));
  167. 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())));
  168. 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"))));
  169. 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())));
  170. MetaModel::Init_AddAttribute(new AttributeString("product", array("allowed_values"=>null, "sql"=>"product", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  171. 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())));
  172. 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())));
  173. 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())));
  174. 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"))));
  175. 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())));
  176. 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"))));
  177. 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())));
  178. 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())));
  179. 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())));
  180. 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())));
  181. 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())));
  182. 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())));
  183. MetaModel::Init_AddAttribute(new AttributeDateTime("close_date", array("allowed_values"=>null, "sql"=>"close_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  184. MetaModel::Init_AddAttribute(new AttributeDateTime("last_update", array("allowed_values"=>null, "sql"=>"last_update", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  185. MetaModel::Init_AddAttribute(new AttributeDateTime("assignment_date", array("allowed_values"=>null, "sql"=>"assignment_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  186. 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())));
  187. 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())));
  188. MetaModel::Init_AddAttribute(new AttributeDeadline("closure_deadline", array("allowed_values"=>null, "sql"=>"closure_deadline", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  189. 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())));
  190. MetaModel::Init_AddAttribute(new AttributeText("solution", array("allowed_values"=>null, "sql"=>"solution", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  191. 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())));
  192. MetaModel::Init_AddAttribute(new AttributeText("user_commment", array("allowed_values"=>null, "sql"=>"user_commment", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  193. 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'));
  194. 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'));
  195. 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', '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'));
  196. MetaModel::Init_SetZListItems('list', 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'));
  197. // Lifecycle
  198. MetaModel::Init_DefineState(
  199. "new",
  200. array(
  201. "attribute_inherit" => null,
  202. "attribute_list" => array(
  203. 'ref' => OPT_ATT_READONLY,
  204. 'ticket_log' => OPT_ATT_HIDDEN,
  205. 'caller_id' => OPT_ATT_MANDATORY,
  206. 'related_change_id' => OPT_ATT_HIDDEN,
  207. 'description' => OPT_ATT_MUSTCHANGE,
  208. 'contact_list' => OPT_ATT_READONLY,
  209. 'start_date' => OPT_ATT_READONLY,
  210. 'last_update' => OPT_ATT_READONLY,
  211. 'assignment_date' => OPT_ATT_HIDDEN,
  212. 'tto_escalation_deadline' => OPT_ATT_READONLY,
  213. 'ttr_escalation_deadline' => OPT_ATT_HIDDEN,
  214. 'closure_deadline' => OPT_ATT_HIDDEN,
  215. 'close_date' => OPT_ATT_HIDDEN,
  216. 'org_id' => OPT_ATT_MUSTCHANGE,
  217. 'service_id' => OPT_ATT_MUSTCHANGE,
  218. 'servicesubcategory_id' => OPT_ATT_MUSTCHANGE,
  219. 'product' => OPT_ATT_MUSTPROMPT,
  220. 'impact' => OPT_ATT_MUSTCHANGE,
  221. 'urgency' => OPT_ATT_MUSTCHANGE,
  222. 'priority' => OPT_ATT_READONLY,
  223. 'workgroup_id' => OPT_ATT_MUSTCHANGE,
  224. 'agent_id' => OPT_ATT_HIDDEN,
  225. 'agent_email' => OPT_ATT_HIDDEN,
  226. 'resolution_code' => OPT_ATT_HIDDEN,
  227. 'solution' => OPT_ATT_HIDDEN,
  228. 'user_satisfaction' => OPT_ATT_HIDDEN,
  229. 'user_commment' => OPT_ATT_HIDDEN,
  230. ),
  231. )
  232. );
  233. MetaModel::Init_DefineState(
  234. "escalated_tto",
  235. array(
  236. "attribute_inherit" => 'new',
  237. "attribute_list" => array(
  238. ),
  239. )
  240. );
  241. MetaModel::Init_DefineState(
  242. "assigned",
  243. array(
  244. "attribute_inherit" => 'new',
  245. "attribute_list" => array(
  246. 'title' => OPT_ATT_READONLY,
  247. 'caller_id' => OPT_ATT_READONLY,
  248. 'org_id' => OPT_ATT_READONLY,
  249. 'ticket_log' => OPT_ATT_NORMAL,
  250. 'description' => OPT_ATT_READONLY,
  251. 'agent_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  252. 'agent_email' => OPT_ATT_READONLY,
  253. 'workgroup_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  254. 'tto_escalation_deadline' => OPT_ATT_HIDDEN,
  255. 'ttr_escalation_deadline' => OPT_ATT_READONLY,
  256. ),
  257. )
  258. );
  259. MetaModel::Init_DefineState(
  260. "escalated_ttr",
  261. array(
  262. "attribute_inherit" => 'assigned',
  263. "attribute_list" => array(
  264. // MUST_PROMPT is not inherited...but does that make sense
  265. 'agent_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  266. 'workgroup_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  267. ),
  268. )
  269. );
  270. MetaModel::Init_DefineState(
  271. "frozen",
  272. array(
  273. "attribute_inherit" => 'assigned',
  274. "attribute_list" => array(
  275. ),
  276. )
  277. );
  278. MetaModel::Init_DefineState(
  279. "resolved",
  280. array(
  281. "attribute_inherit" => 'assigned',
  282. "attribute_list" => array(
  283. 'service_id' => OPT_ATT_READONLY,
  284. 'servicesubcategory_id' => OPT_ATT_READONLY,
  285. 'product' => OPT_ATT_READONLY,
  286. 'impact' => OPT_ATT_READONLY,
  287. 'workgroup_id' => OPT_ATT_READONLY,
  288. 'agent_id' => OPT_ATT_READONLY,
  289. 'urgency' => OPT_ATT_READONLY,
  290. 'resolution_code' => OPT_ATT_MUSTPROMPT,
  291. 'solution' => OPT_ATT_MUSTPROMPT,
  292. 'closure_deadline' => OPT_ATT_READONLY,
  293. 'ttr_escalation_deadline' => OPT_ATT_HIDDEN,
  294. ),
  295. )
  296. );
  297. MetaModel::Init_DefineState(
  298. "closed",
  299. array(
  300. "attribute_inherit" => 'resolved',
  301. "attribute_list" => array(
  302. 'ticket_log' => OPT_ATT_READONLY,
  303. 'user_satisfaction' => OPT_ATT_MUSTPROMPT,
  304. 'user_commment' => OPT_ATT_MUSTPROMPT,
  305. 'resolution_code' => OPT_ATT_READONLY,
  306. 'solution' => OPT_ATT_READONLY,
  307. 'close_date' => OPT_ATT_READONLY,
  308. 'closure_deadline' => OPT_ATT_HIDDEN,
  309. ),
  310. )
  311. );
  312. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_assign", array()));
  313. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_reassign", array()));
  314. MetaModel::Init_DefineStimulus(new StimulusInternal("ev_timeout", array()));
  315. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_resolve", array()));
  316. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_close", array()));
  317. MetaModel::Init_DefineTransition("new", "ev_assign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  318. MetaModel::Init_DefineTransition("new", "ev_timeout", array("target_state"=>"escalated_tto", "actions"=>array(), "user_restriction"=>null));
  319. MetaModel::Init_DefineTransition("escalated_tto", "ev_assign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  320. MetaModel::Init_DefineTransition("assigned", "ev_reassign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  321. MetaModel::Init_DefineTransition("assigned", "ev_timeout", array("target_state"=>"escalated_ttr", "actions"=>array(), "user_restriction"=>null));
  322. MetaModel::Init_DefineTransition("assigned", "ev_resolve", array("target_state"=>"resolved", "actions"=>array('SetClosureDeadline'), "user_restriction"=>null));
  323. MetaModel::Init_DefineTransition("escalated_ttr", "ev_reassign", array("target_state"=>"escalated_ttr", "actions"=>array(), "user_restriction"=>null));
  324. MetaModel::Init_DefineTransition("escalated_ttr", "ev_resolve", array("target_state"=>"resolved", "actions"=>array('SetClosureDeadline'), "user_restriction"=>null));
  325. MetaModel::Init_DefineTransition("resolved", "ev_reassign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  326. MetaModel::Init_DefineTransition("resolved", "ev_close", array("target_state"=>"closed", "actions"=>array('SetClosureDate'), "user_restriction"=>null));
  327. }
  328. // Lifecycle actions
  329. //
  330. public function SetClosureDeadline($sStimulusCode)
  331. {
  332. $iMaxWaitHours = 24;
  333. $this->Set('closure_deadline', time() + $iMaxWaitHours * 3600);
  334. return true;
  335. }
  336. public function SetClosureDate($sStimulusCode)
  337. {
  338. $this->Set('close_date', time());
  339. return true;
  340. }
  341. /**
  342. * Determines the shortest SLT, for this ticket, for the given metric. Returns null is no SLT was found
  343. * @param string $sMetric Type of metric 'TTO', 'TTR', etc as defined in the SLT class
  344. * @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
  345. */
  346. public function ComputeSLT($sMetric = 'TTO')
  347. {
  348. $aResult = null;
  349. if (MetaModel::IsValidClass('SLT'))
  350. {
  351. $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
  352. WHERE SLT.ticket_priority = :priority AND SLA.service_id = :service_id AND SLT.metric = :metric AND CustomerContract.org_id = :org_id";
  353. $oSLTSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL),
  354. array(),
  355. array(
  356. 'priority' => $this->Get('priority'),
  357. 'service_id' => $this->Get('service_id'),
  358. 'metric' => $sMetric,
  359. 'org_id' => $this->Get('org_id'),
  360. )
  361. );
  362. $iMinDuration = PHP_INT_MAX;
  363. $sSLTName = '';
  364. while($oSLT = $oSLTSet->Fetch())
  365. {
  366. $iDuration = (int)$oSLT->Get('value');
  367. $sUnit = $oSLT->Get('value_unit');
  368. //echo "<p>Found SLT: ".$oSLT->GetName()." - $iDuration ($sUnit)</p>\n";
  369. switch($sUnit)
  370. {
  371. case 'days':
  372. $iDuration = $iDuration * 24; // 24 hours in 1 days
  373. // Fall though
  374. case 'hours':
  375. $iDuration = $iDuration * 60; // 60 minutes in 1 hour
  376. // Fall though
  377. case 'minutes':
  378. $iDuration = $iDuration * 60;
  379. }
  380. if ($iDuration < $iMinDuration)
  381. {
  382. $iMinDuration = $iDuration;
  383. $sSLTName = $oSLT->GetName();
  384. }
  385. }
  386. if ($iMinDuration == PHP_INT_MAX)
  387. {
  388. $aResult = null;
  389. }
  390. else
  391. {
  392. $aResult = array('SLT' => $sSLTName, 'value' => $iMinDuration);
  393. }
  394. }
  395. return $aResult;
  396. }
  397. /**
  398. * Compute the priority of the ticket based on its impact and urgency
  399. * @return integer The priority of the ticket 1(high) .. 3(low)
  400. */
  401. public function ComputePriority()
  402. {
  403. // priority[impact][urgency]
  404. $aPriorities = array(
  405. // single person
  406. 1 => array(
  407. 1 => 1,
  408. 2 => 1,
  409. 3 => 2,
  410. ),
  411. // a group
  412. 2 => array(
  413. 1 => 1,
  414. 2 => 2,
  415. 3 => 3,
  416. ),
  417. // a departement!
  418. 3 => array(
  419. 1 => 2,
  420. 2 => 3,
  421. 3 => 3,
  422. ),
  423. );
  424. $iPriority = $aPriorities[(int)$this->Get('impact')][(int)$this->Get('urgency')];
  425. return $iPriority;
  426. }
  427. public function ComputeValues()
  428. {
  429. // Compute the priority of the ticket
  430. $this->Set('priority', $this->ComputePriority());
  431. // Compute the SLA deadlines, if any is applicable to this ticket
  432. $aSLT = $this->ComputeSLT('TTO');
  433. if ($aSLT != null)
  434. {
  435. //echo "<p>TTO: SLT found: {$aSLT['SLT']}, value: {$aSLT['value']}</p>\n";
  436. $iStartDate = AttributeDateTime::GetAsUnixSeconds($this->Get('start_date'));
  437. $this->Set('tto_escalation_deadline', $iStartDate + $aSLT['value']);
  438. }
  439. else
  440. {
  441. $this->Set('tto_escalation_deadline', null);
  442. }
  443. $aSLT = $this->ComputeSLT('TTR');
  444. if ($aSLT != null)
  445. {
  446. //echo "<p>TTR: SLT found: {$aSLT['SLT']}, value: {$aSLT['value']}</p>\n";
  447. $iStartDate = AttributeDateTime::GetAsUnixSeconds($this->Get('start_date'));
  448. $this->Set('ttr_escalation_deadline', $iStartDate + $aSLT['value']);
  449. }
  450. else
  451. {
  452. $this->Set('ttr_escalation_deadline', null);
  453. }
  454. }
  455. /**
  456. * Determines if the ticket must be hilighted in the list, if we're about to miss a SLA for instance
  457. */
  458. public function GetHilightClass()
  459. {
  460. $sHilightClass = '';
  461. switch($this->GetState())
  462. {
  463. case 'new':
  464. $oEscalationDeadline = $this->Get('tto_escalation_deadline');
  465. if ($oEscalationDeadline != null)
  466. {
  467. // A SLA is running
  468. $iStartDate = AttributeDateTime::GetAsUnixSeconds($this->Get('start_date'));
  469. $iEscalationDeadline = AttributeDateTime::GetAsUnixSeconds($oEscalationDeadline);
  470. $ratio = ($iEscalationDeadline - time())/($iEscalationDeadline - $iStartDate);
  471. if ($ratio <= 0)
  472. {
  473. $sHilightClass = HILIGHT_CLASS_CRITICAL;
  474. }
  475. else if ($ratio <= 0.25)
  476. {
  477. $sHilightClass = HILIGHT_CLASS_WARNING;
  478. }
  479. }
  480. break;
  481. case 'assigned':
  482. $oEscalationDeadline = $this->Get('ttr_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 'escalated_tto':
  500. case 'escalated_ttr':
  501. $sHilightClass = HILIGHT_CLASS_CRITICAL;
  502. break;
  503. }
  504. return $sHilightClass;
  505. }
  506. protected function OnInsert()
  507. {
  508. $this->Set('last_update', time());
  509. }
  510. protected function OnUpdate()
  511. {
  512. $this->Set('last_update', time());
  513. }
  514. /*
  515. EXAMPLE: OnInsert....
  516. protected function OnInsert()
  517. {
  518. // Romain: ajouter cette ligne
  519. $oToNotify = $this->Get('contacts_a_notifier');
  520. // Romain: ca c'etait pour verifier que ca fonctionne bien
  521. // $oFirstContact = MetaModel::GetObject('bizPerson', 6);
  522. // $oNewLink = new lnkContactTicket();
  523. // $oNewLink->Set('contact_id', 6);
  524. // $oNewLink->Set('role', 'created before');
  525. // $oToNotify->AddObject($oNewLink);
  526. $oImpactedInfras = DBObjectSet::FromLinkSet($this, 'impacted_infra_manual', 'ci_id');
  527. $aComputed = $oImpactedInfras->GetRelatedObjects('impacts', 10);
  528. if (array_key_exists('logRealObject', $aComputed))
  529. {
  530. foreach($aComputed['logRealObject'] as $iKey => $oObject)
  531. {
  532. if (MetaModel::IsParentClass('bizContact', get_class($oObject)))
  533. {
  534. $oNewLink = new lnkContactTicket();
  535. $oNewLink->Set('contact_id', $iKey);
  536. //$oNewLink->Set('ticket_id', $this->GetKey()); // unkown at that time!
  537. $oNewLink->Set('role', 'contact automatically computed');
  538. // Romain: transformer cette ligne
  539. $oToNotify->AddObject($oNewLink);
  540. }
  541. }
  542. // Romain: supprimer cette ligne
  543. // $this->Set('contacts_a_notifier', $oToNotify);
  544. }
  545. }
  546. */
  547. }
  548. ?>