model.itop-problem-mgmt.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Persistent classes for a CMDB
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. class Problem extends Ticket
  25. {
  26. public static function Init()
  27. {
  28. $aParams = array
  29. (
  30. "category" => "bizmodel,searchable,problemmgmt",
  31. "key_type" => "autoincrement",
  32. "name_attcode" => "ref",
  33. "state_attcode" => "status",
  34. "reconc_keys" => array("ref"),
  35. "db_table" => "ticket_problem",
  36. "db_key_field" => "id",
  37. "db_finalclass_field" => "",
  38. "display_template" => "",
  39. "icon" => "../modules/itop-problem-mgmt-1.0.0/images/problem.png",
  40. );
  41. MetaModel::Init_Params($aParams);
  42. MetaModel::Init_InheritAttributes();
  43. // MetaModel::Init_InheritLifecycle();
  44. MetaModel::Init_AddAttribute(new AttributeEnum("status", array("allowed_values"=>new ValueSetEnum('new,assigned,resolved,closed'), "sql"=>"status", "default_value"=>"new", "is_null_allowed"=>false, "depends_on"=>array())));
  45. 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())));
  46. 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())));
  47. 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"))));
  48. 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())));
  49. 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"))));
  50. 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())));
  51. MetaModel::Init_AddAttribute(new AttributeString("product", array("allowed_values"=>null, "sql"=>"product", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  52. 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())));
  53. 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())));
  54. 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())));
  55. 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"))));
  56. 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())));
  57. 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"))));
  58. 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())));
  59. 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())));
  60. 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())));
  61. 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())));
  62. MetaModel::Init_AddAttribute(new AttributeDateTime("close_date", array("allowed_values"=>null, "sql"=>"close_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  63. MetaModel::Init_AddAttribute(new AttributeDateTime("last_update", array("allowed_values"=>null, "sql"=>"last_update", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  64. MetaModel::Init_AddAttribute(new AttributeDateTime("assignment_date", array("allowed_values"=>null, "sql"=>"assignment_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  65. MetaModel::Init_AddAttribute(new AttributeDateTime("resolution_date", array("allowed_values"=>null, "sql"=>"resolution_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  66. MetaModel::Init_AddAttribute(new AttributeLinkedSet("knownerrors_list", array("linked_class"=>"KnownError", "ext_key_to_me"=>"problem_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array())));
  67. MetaModel::Init_SetZListItems('details', array('ref', 'title', 'org_id', 'description', 'ticket_log', 'start_date','knownerrors_list', 'document_list', 'ci_list', 'contact_list','incident_list', 'status', 'service_id', 'servicesubcategory_id','product', 'impact', 'urgency', 'priority', 'workgroup_id', 'agent_id', 'agent_email', 'related_change_id', 'close_date', 'last_update', 'assignment_date'));
  68. MetaModel::Init_SetZListItems('advanced_search', array('ref', 'title', 'org_id', 'start_date', 'status', 'service_id', 'servicesubcategory_id', 'product', 'impact', 'urgency', 'priority', 'workgroup_id', 'agent_id', 'agent_email', 'related_change_id', 'close_date'));
  69. MetaModel::Init_SetZListItems('standard_search', array('ref', 'title', 'org_id', 'start_date', 'status', 'service_id', 'servicesubcategory_id', 'product', 'impact', 'urgency', 'priority', 'workgroup_id', 'agent_id', 'agent_email', 'close_date'));
  70. MetaModel::Init_SetZListItems('list', array('title', 'org_id', 'start_date', 'status', 'service_id', 'priority'));
  71. // Lifecycle
  72. MetaModel::Init_DefineState(
  73. "new",
  74. array(
  75. "attribute_inherit" => null,
  76. "attribute_list" => array(
  77. 'ref' => OPT_ATT_READONLY,
  78. 'ticket_log' => OPT_ATT_HIDDEN,
  79. 'related_change_id' => OPT_ATT_HIDDEN,
  80. 'description' => OPT_ATT_MUSTCHANGE,
  81. 'contact_list' => OPT_ATT_READONLY,
  82. 'start_date' => OPT_ATT_READONLY,
  83. 'last_update' => OPT_ATT_READONLY,
  84. 'assignment_date' => OPT_ATT_HIDDEN,
  85. 'resolution_date' => OPT_ATT_HIDDEN,
  86. 'close_date' => OPT_ATT_HIDDEN,
  87. 'org_id' => OPT_ATT_MUSTCHANGE,
  88. 'service_id' => OPT_ATT_MUSTCHANGE,
  89. 'servicesubcategory_id' => OPT_ATT_MUSTCHANGE,
  90. 'product' => OPT_ATT_MUSTPROMPT,
  91. 'impact' => OPT_ATT_MUSTCHANGE,
  92. 'urgency' => OPT_ATT_MUSTCHANGE,
  93. 'priority' => OPT_ATT_READONLY,
  94. 'workgroup_id' => OPT_ATT_MUSTCHANGE,
  95. 'agent_id' => OPT_ATT_HIDDEN,
  96. 'agent_email' => OPT_ATT_HIDDEN,
  97. ),
  98. )
  99. );
  100. MetaModel::Init_DefineState(
  101. "assigned",
  102. array(
  103. "attribute_inherit" => 'new',
  104. "attribute_list" => array(
  105. 'title' => OPT_ATT_READONLY,
  106. 'org_id' => OPT_ATT_READONLY,
  107. 'ticket_log' => OPT_ATT_NORMAL,
  108. 'description' => OPT_ATT_READONLY,
  109. 'agent_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  110. 'agent_email' => OPT_ATT_READONLY,
  111. 'workgroup_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  112. 'related_change_id' => OPT_ATT_NORMAL,
  113. ),
  114. )
  115. );
  116. MetaModel::Init_DefineState(
  117. "resolved",
  118. array(
  119. "attribute_inherit" => 'assigned',
  120. "attribute_list" => array(
  121. 'service_id' => OPT_ATT_READONLY,
  122. 'servicesubcategory_id' => OPT_ATT_READONLY,
  123. 'product' => OPT_ATT_READONLY,
  124. 'impact' => OPT_ATT_READONLY,
  125. 'workgroup_id' => OPT_ATT_READONLY,
  126. 'agent_id' => OPT_ATT_READONLY,
  127. 'urgency' => OPT_ATT_READONLY,
  128. ),
  129. )
  130. );
  131. MetaModel::Init_DefineState(
  132. "closed",
  133. array(
  134. "attribute_inherit" => 'resolved',
  135. "attribute_list" => array(
  136. 'ticket_log' => OPT_ATT_READONLY,
  137. 'close_date' => OPT_ATT_READONLY,
  138. ),
  139. )
  140. );
  141. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_assign", array()));
  142. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_reassign", array()));
  143. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_resolve", array()));
  144. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_close", array()));
  145. MetaModel::Init_DefineTransition("new", "ev_assign", array("target_state"=>"assigned", "actions"=>array('SetAssignedDate'), "user_restriction"=>null));
  146. MetaModel::Init_DefineTransition("assigned", "ev_reassign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  147. MetaModel::Init_DefineTransition("assigned", "ev_resolve", array("target_state"=>"resolved", "actions"=>array('SetResolveDate'), "user_restriction"=>null));
  148. MetaModel::Init_DefineTransition("resolved", "ev_reassign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  149. MetaModel::Init_DefineTransition("resolved", "ev_close", array("target_state"=>"closed", "actions"=>array('SetClosureDate'), "user_restriction"=>null));
  150. }
  151. // Lifecycle actions
  152. //
  153. public function SetAssignedDate($sStimulusCode)
  154. {
  155. $this->Set('assignment_date', time());
  156. return true;
  157. }
  158. public function SetResolveDate($sStimulusCode)
  159. {
  160. $this->Set('resolution_date', time());
  161. return true;
  162. }
  163. public function SetClosureDate($sStimulusCode)
  164. {
  165. $this->Set('close_date', time());
  166. return true;
  167. }
  168. /** Compute the priority of the ticket based on its impact and urgency
  169. * @return integer The priority of the ticket 1(high) .. 3(low)
  170. */
  171. public function ComputePriority()
  172. {
  173. // priority[impact][urgency]
  174. $aPriorities = array(
  175. // single person
  176. 1 => array(
  177. 1 => 1,
  178. 2 => 1,
  179. 3 => 2,
  180. ),
  181. // a group
  182. 2 => array(
  183. 1 => 1,
  184. 2 => 2,
  185. 3 => 3,
  186. ),
  187. // a departement!
  188. 3 => array(
  189. 1 => 2,
  190. 2 => 3,
  191. 3 => 3,
  192. ),
  193. );
  194. $iPriority = $aPriorities[(int)$this->Get('impact')][(int)$this->Get('urgency')];
  195. return $iPriority;
  196. }
  197. public function ComputeValues()
  198. {
  199. // Compute the priority of the ticket
  200. $this->Set('priority', $this->ComputePriority());
  201. $sCurrRef = $this->Get('ref');
  202. if (strlen($sCurrRef) == 0)
  203. {
  204. $iKey = $this->GetKey();
  205. if ($iKey < 0)
  206. {
  207. // Object not yet in the Database
  208. $iKey = MetaModel::GetNextKey(get_class($this));
  209. }
  210. $sName = sprintf('P-%06d', $iKey);
  211. $this->Set('ref', $sName);
  212. }
  213. }
  214. }
  215. $oMyMenuGroup = new MenuGroup('ProblemManagement', 42 /* fRank */); // Will create if it does not exist
  216. $iIndex = $oMyMenuGroup->GetIndex();
  217. new TemplateMenuNode('Problem:Overview', '../modules/itop-problem-mgmt-1.0.0/overview.html', $iIndex /* oParent */, 0 /* fRank */);
  218. new NewObjectMenuNode('NewProblem', 'Problem', $iIndex, 1 /* fRank */);
  219. new SearchMenuNode('SearchProblems', 'Problem', $iIndex, 2 /* fRank */);
  220. $oShortcutNode = new TemplateMenuNode('Problem:Shortcuts', '', $iIndex, 5 /* fRank */);
  221. new OQLMenuNode('Problem:MyProblems', 'SELECT Problem WHERE agent_id = :current_contact_id AND status NOT IN ("closed", "resolved")', $oShortcutNode->GetIndex(), 1 /* fRank */);
  222. new OQLMenuNode('Problem:OpenProblems', 'SELECT Problem WHERE status IN ("new", "assigned", "resolved")', $oShortcutNode->GetIndex(), 2 /* fRank */);
  223. ?>