model.itop-problem-mgmt.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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('document_list', 'ci_list', 'contact_list','incident_list',
  68. 'col:col1' => array(
  69. 'fieldset:Ticket:baseinfo' => array('ref','title','org_id','status','priority','service_id','servicesubcategory_id','product' ),
  70. 'fieldset:Ticket:moreinfo' => array('impact','urgency','description',),
  71. ),
  72. 'col:col2' => array(
  73. 'fieldset:Ticket:date' => array('start_date','last_update','assignment_date','close_date',),
  74. 'fieldset:Ticket:contact' => array('workgroup_id','agent_id',),
  75. 'fieldset:Ticket:relation' => array('related_change_id',),
  76. )
  77. ));
  78. // 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'));
  79. 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'));
  80. 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'));
  81. MetaModel::Init_SetZListItems('list', array('title', 'org_id', 'start_date', 'status', 'service_id', 'priority'));
  82. // Lifecycle
  83. MetaModel::Init_DefineState(
  84. "new",
  85. array(
  86. "attribute_inherit" => null,
  87. "attribute_list" => array(
  88. 'ref' => OPT_ATT_READONLY,
  89. 'ticket_log' => OPT_ATT_HIDDEN,
  90. 'related_change_id' => OPT_ATT_HIDDEN,
  91. 'description' => OPT_ATT_MUSTCHANGE,
  92. 'start_date' => OPT_ATT_READONLY,
  93. 'last_update' => OPT_ATT_READONLY,
  94. 'assignment_date' => OPT_ATT_HIDDEN,
  95. 'resolution_date' => OPT_ATT_HIDDEN,
  96. 'close_date' => OPT_ATT_HIDDEN,
  97. 'org_id' => OPT_ATT_MUSTCHANGE,
  98. 'service_id' => OPT_ATT_MUSTCHANGE,
  99. 'servicesubcategory_id' => OPT_ATT_MUSTCHANGE,
  100. 'product' => OPT_ATT_MUSTPROMPT,
  101. 'impact' => OPT_ATT_MUSTCHANGE,
  102. 'urgency' => OPT_ATT_MUSTCHANGE,
  103. 'priority' => OPT_ATT_READONLY,
  104. 'workgroup_id' => OPT_ATT_MUSTCHANGE,
  105. 'agent_id' => OPT_ATT_HIDDEN,
  106. 'agent_email' => OPT_ATT_HIDDEN,
  107. ),
  108. )
  109. );
  110. MetaModel::Init_DefineState(
  111. "assigned",
  112. array(
  113. "attribute_inherit" => 'new',
  114. "attribute_list" => array(
  115. 'title' => OPT_ATT_READONLY,
  116. 'org_id' => OPT_ATT_READONLY,
  117. 'ticket_log' => OPT_ATT_NORMAL,
  118. 'assignment_date' => OPT_ATT_READONLY,
  119. 'description' => OPT_ATT_READONLY,
  120. 'agent_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  121. 'agent_email' => OPT_ATT_READONLY,
  122. 'workgroup_id' => OPT_ATT_MUSTPROMPT | OPT_ATT_MANDATORY,
  123. 'related_change_id' => OPT_ATT_NORMAL,
  124. ),
  125. )
  126. );
  127. MetaModel::Init_DefineState(
  128. "resolved",
  129. array(
  130. "attribute_inherit" => 'assigned',
  131. "attribute_list" => array(
  132. 'service_id' => OPT_ATT_READONLY,
  133. 'servicesubcategory_id' => OPT_ATT_READONLY,
  134. 'product' => OPT_ATT_READONLY,
  135. 'impact' => OPT_ATT_READONLY,
  136. 'workgroup_id' => OPT_ATT_READONLY,
  137. 'agent_id' => OPT_ATT_READONLY,
  138. 'urgency' => OPT_ATT_READONLY,
  139. ),
  140. )
  141. );
  142. MetaModel::Init_DefineState(
  143. "closed",
  144. array(
  145. "attribute_inherit" => 'resolved',
  146. "attribute_list" => array(
  147. 'ticket_log' => OPT_ATT_READONLY,
  148. 'close_date' => OPT_ATT_READONLY,
  149. ),
  150. )
  151. );
  152. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_assign", array()));
  153. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_reassign", array()));
  154. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_resolve", array()));
  155. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_close", array()));
  156. MetaModel::Init_DefineTransition("new", "ev_assign", array("target_state"=>"assigned", "actions"=>array('SetAssignedDate'), "user_restriction"=>null));
  157. MetaModel::Init_DefineTransition("assigned", "ev_reassign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  158. MetaModel::Init_DefineTransition("assigned", "ev_resolve", array("target_state"=>"resolved", "actions"=>array('SetResolveDate'), "user_restriction"=>null));
  159. MetaModel::Init_DefineTransition("resolved", "ev_reassign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  160. MetaModel::Init_DefineTransition("resolved", "ev_close", array("target_state"=>"closed", "actions"=>array('SetClosureDate'), "user_restriction"=>null));
  161. }
  162. // Lifecycle actions
  163. //
  164. public function SetAssignedDate($sStimulusCode)
  165. {
  166. $this->Set('assignment_date', time());
  167. return true;
  168. }
  169. public function SetResolveDate($sStimulusCode)
  170. {
  171. $this->Set('resolution_date', time());
  172. return true;
  173. }
  174. public function SetClosureDate($sStimulusCode)
  175. {
  176. $this->Set('close_date', time());
  177. return true;
  178. }
  179. /** Compute the priority of the ticket based on its impact and urgency
  180. * @return integer The priority of the ticket 1(high) .. 3(low)
  181. */
  182. public function ComputePriority()
  183. {
  184. // priority[impact][urgency]
  185. $aPriorities = array(
  186. // single person
  187. 1 => array(
  188. 1 => 1,
  189. 2 => 1,
  190. 3 => 2,
  191. ),
  192. // a group
  193. 2 => array(
  194. 1 => 1,
  195. 2 => 2,
  196. 3 => 3,
  197. ),
  198. // a departement!
  199. 3 => array(
  200. 1 => 2,
  201. 2 => 3,
  202. 3 => 3,
  203. ),
  204. );
  205. $iPriority = $aPriorities[(int)$this->Get('impact')][(int)$this->Get('urgency')];
  206. return $iPriority;
  207. }
  208. public function ComputeValues()
  209. {
  210. // Compute the priority of the ticket
  211. $this->Set('priority', $this->ComputePriority());
  212. $sCurrRef = $this->Get('ref');
  213. if (strlen($sCurrRef) == 0)
  214. {
  215. $iKey = $this->GetKey();
  216. if ($iKey < 0)
  217. {
  218. // Object not yet in the Database
  219. $iKey = MetaModel::GetNextKey(get_class($this));
  220. }
  221. $sName = sprintf('P-%06d', $iKey);
  222. $this->Set('ref', $sName);
  223. }
  224. }
  225. }
  226. $oMyMenuGroup = new MenuGroup('ProblemManagement', 42 /* fRank */); // Will create if it does not exist
  227. $iIndex = $oMyMenuGroup->GetIndex();
  228. new TemplateMenuNode('Problem:Overview', '../modules/itop-problem-mgmt-1.0.0/overview.html', $iIndex /* oParent */, 0 /* fRank */);
  229. new NewObjectMenuNode('NewProblem', 'Problem', $iIndex, 1 /* fRank */);
  230. new SearchMenuNode('SearchProblems', 'Problem', $iIndex, 2 /* fRank */);
  231. $oShortcutNode = new TemplateMenuNode('Problem:Shortcuts', '', $iIndex, 5 /* fRank */);
  232. new OQLMenuNode('Problem:MyProblems', 'SELECT Problem WHERE agent_id = :current_contact_id AND status NOT IN ("closed", "resolved")', $oShortcutNode->GetIndex(), 1 /* fRank */);
  233. new OQLMenuNode('Problem:OpenProblems', 'SELECT Problem WHERE status IN ("new", "assigned", "resolved")', $oShortcutNode->GetIndex(), 2 /* fRank */);
  234. ?>