model.itop-tickets.php 33 KB

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