model.itop-change-mgmt.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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 Change extends Ticket
  25. {
  26. public static function Init()
  27. {
  28. $aParams = array
  29. (
  30. "category" => "bizmodel,searchable,changemgmt",
  31. "key_type" => "autoincrement",
  32. "name_attcode" => "ref",
  33. "state_attcode" => "status",
  34. "reconc_keys" => array("ref"),
  35. "db_table" => "change",
  36. "db_key_field" => "id",
  37. "db_finalclass_field" => "",
  38. "display_template" => "",
  39. "icon" => "../modules/itop-change-mgmt-1.0.0/images/change.png",
  40. );
  41. MetaModel::Init_Params($aParams);
  42. MetaModel::Init_InheritAttributes();
  43. MetaModel::Init_AddAttribute(new AttributeEnum("status", array("allowed_values"=>new ValueSetEnum('approved,assigned,closed,implemented,monitored,new,notapproved,plannedscheduled,rejected,validated'), "sql"=>"status", "default_value"=>"new", "is_null_allowed"=>true, "depends_on"=>array())));
  44. MetaModel::Init_AddAttribute(new AttributeString("reason", array("allowed_values"=>null, "sql"=>"reason", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  45. MetaModel::Init_AddAttribute(new AttributeExternalKey("requestor_id", array("targetclass"=>"Person", "jointype"=>null, "allowed_values"=>new ValueSetObjects('SELECT Person AS p WHERE p.org_id = :this->org_id'), "sql"=>"requestor_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array("org_id"))));
  46. MetaModel::Init_AddAttribute(new AttributeExternalField("requestor_email", array("allowed_values"=>null, "extkey_attcode"=>"requestor_id", "target_attcode"=>"email", "is_null_allowed"=>true, "depends_on"=>array())));
  47. 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())));
  48. 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())));
  49. MetaModel::Init_AddAttribute(new AttributeExternalKey("workgroup_id", array("targetclass"=>"Team", "jointype"=>null, "allowed_values"=>null, "sql"=>"workgroup_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  50. 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())));
  51. MetaModel::Init_AddAttribute(new AttributeDateTime("creation_date", array("allowed_values"=>null, "sql"=>"creation_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  52. MetaModel::Init_AddAttribute(new AttributeDateTime("last_update", array("allowed_values"=>null, "sql"=>"last_update", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  53. MetaModel::Init_AddAttribute(new AttributeDateTime("start_date", array("allowed_values"=>null, "sql"=>"start_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  54. MetaModel::Init_AddAttribute(new AttributeDateTime("end_date", array("allowed_values"=>null, "sql"=>"end_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  55. MetaModel::Init_AddAttribute(new AttributeDateTime("close_date", array("allowed_values"=>null, "sql"=>"close_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  56. MetaModel::Init_AddAttribute(new AttributeString("impact", array("allowed_values"=>null, "sql"=>"impact", "default_value"=>"", "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("supervisor_group_id", array("targetclass"=>"Team", "jointype"=>null, "allowed_values"=>null, "sql"=>"supervisor_group_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  61. MetaModel::Init_AddAttribute(new AttributeExternalField("supervisor_group_name", array("allowed_values"=>null, "extkey_attcode"=>"supervisor_group_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
  62. MetaModel::Init_AddAttribute(new AttributeExternalKey("supervisor_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->supervisor_group_id'), "sql"=>"supervisor_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array("supervisor_group_id"))));
  63. MetaModel::Init_AddAttribute(new AttributeExternalField("supervisor_email", array("allowed_values"=>null, "extkey_attcode"=>"supervisor_id", "target_attcode"=>"email", "is_null_allowed"=>true, "depends_on"=>array())));
  64. MetaModel::Init_AddAttribute(new AttributeExternalKey("manager_group_id", array("targetclass"=>"Team", "jointype"=>null, "allowed_values"=>null, "sql"=>"manager_group_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  65. MetaModel::Init_AddAttribute(new AttributeExternalField("manager_group_name", array("allowed_values"=>null, "extkey_attcode"=>"manager_group_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
  66. MetaModel::Init_AddAttribute(new AttributeExternalKey("manager_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->manager_group_id'), "sql"=>"manager_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array("manager_group_id"))));
  67. MetaModel::Init_AddAttribute(new AttributeExternalField("manager_email", array("allowed_values"=>null, "extkey_attcode"=>"manager_id", "target_attcode"=>"email", "is_null_allowed"=>true, "depends_on"=>array())));
  68. MetaModel::Init_AddAttribute(new AttributeEnum("outage", array("allowed_values"=>new ValueSetEnum('yes,no'), "sql"=>"outage", "default_value"=>"no", "is_null_allowed"=>false, "depends_on"=>array())));
  69. MetaModel::Init_AddAttribute(new AttributeText("fallback", array("allowed_values"=>null, "sql"=>"fallback", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  70. MetaModel::Init_SetZListItems('details', array('title', 'org_id', 'description','ticket_log', 'start_date','end_date', 'document_list', 'ci_list', 'contact_list','incident_list', 'status', 'reason', 'requestor_id', 'workgroup_id', 'creation_date', 'last_update', 'close_date', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage', 'fallback'));
  71. MetaModel::Init_SetZListItems('advanced_search', array('finalclass', 'ref', 'title', 'org_id', 'start_date', 'end_date','status', 'reason', 'requestor_id', 'workgroup_id', 'creation_date', 'last_update', 'close_date', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage'));
  72. MetaModel::Init_SetZListItems('standard_search', array('finalclass', 'ref', 'title', 'org_id', 'start_date', 'end_date','status', 'reason', 'requestor_id', 'workgroup_id', 'creation_date', 'close_date', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage'));
  73. MetaModel::Init_SetZListItems('list', array('finalclass', 'title', 'start_date', 'status'));
  74. MetaModel::Init_DefineState(
  75. "new",
  76. array(
  77. "attribute_inherit" => null,
  78. "attribute_list" => array(
  79. 'start_date' => OPT_ATT_HIDDEN,
  80. 'ticket_log' => OPT_ATT_HIDDEN,
  81. 'impact' => OPT_ATT_HIDDEN,
  82. 'outage' => OPT_ATT_HIDDEN,
  83. 'fallback' => OPT_ATT_HIDDEN,
  84. 'ref' => OPT_ATT_READONLY,
  85. 'requestor_id' => OPT_ATT_MANDATORY,
  86. 'title' => OPT_ATT_MANDATORY,
  87. 'reason' => OPT_ATT_MANDATORY,
  88. 'workgroup_id' => OPT_ATT_HIDDEN,
  89. 'creation_date' => OPT_ATT_READONLY,
  90. 'last_update' => OPT_ATT_READONLY,
  91. 'end_date' => OPT_ATT_HIDDEN,
  92. 'close_date' => OPT_ATT_HIDDEN,
  93. 'agent_id' => OPT_ATT_HIDDEN,
  94. 'agent_email' => OPT_ATT_HIDDEN,
  95. 'supervisor_group_id' => OPT_ATT_HIDDEN,
  96. 'supervisor_id' => OPT_ATT_HIDDEN,
  97. 'manager_group_id' => OPT_ATT_HIDDEN,
  98. 'manager_id' => OPT_ATT_HIDDEN,
  99. ),
  100. )
  101. );
  102. MetaModel::Init_DefineState(
  103. "validated",
  104. array(
  105. "attribute_inherit" => 'new',
  106. "attribute_list" => array(
  107. 'title' => OPT_ATT_READONLY,
  108. 'reason' => OPT_ATT_READONLY,
  109. 'workgroup_id' => OPT_ATT_MANDATORY,
  110. 'supervisor_group_id' => OPT_ATT_MANDATORY,
  111. 'manager_group_id' => OPT_ATT_MANDATORY,
  112. 'description' => OPT_ATT_READONLY,
  113. 'requestor_id' => OPT_ATT_READONLY,
  114. 'title' => OPT_ATT_MANDATORY,
  115. ),
  116. )
  117. );
  118. MetaModel::Init_DefineState(
  119. "rejected",
  120. array(
  121. "attribute_inherit" => 'new',
  122. "attribute_list" => array(
  123. ),
  124. )
  125. );
  126. MetaModel::Init_DefineState(
  127. "assigned",
  128. array(
  129. "attribute_inherit" => 'validated',
  130. "attribute_list" => array(
  131. 'workgroup_id' => OPT_ATT_MANDATORY,
  132. 'agent_id' => OPT_ATT_MUSTCHANGE,
  133. 'supervisor_id' => OPT_ATT_MUSTCHANGE,
  134. 'manager_id' => OPT_ATT_MUSTCHANGE,
  135. 'description' => OPT_ATT_READONLY,
  136. 'requestor_id' => OPT_ATT_READONLY,
  137. ),
  138. )
  139. );
  140. MetaModel::Init_DefineState(
  141. "plannedscheduled",
  142. array(
  143. "attribute_inherit" => 'assigned',
  144. "attribute_list" => array(
  145. 'ticket_log' => OPT_ATT_MANDATORY,
  146. 'requestor_id' => OPT_ATT_READONLY,
  147. 'org_id' => OPT_ATT_READONLY,
  148. 'workgroup_id' => OPT_ATT_READONLY,
  149. 'start_date' => OPT_ATT_MANDATORY,
  150. 'end_date' => OPT_ATT_MANDATORY,
  151. 'impact' => OPT_ATT_MANDATORY,
  152. 'agent_id' => OPT_ATT_MANDATORY,
  153. 'supervisor_group_id' => OPT_ATT_MANDATORY,
  154. 'supervisor_id' => OPT_ATT_MANDATORY,
  155. 'manager_group_id' => OPT_ATT_MANDATORY,
  156. 'manager_id' => OPT_ATT_MANDATORY,
  157. 'fallback' => OPT_ATT_MANDATORY,
  158. 'outage' => OPT_ATT_MUSTPROMPT,
  159. ),
  160. )
  161. );
  162. MetaModel::Init_DefineState(
  163. "approved",
  164. array(
  165. "attribute_inherit" => 'plannedscheduled',
  166. "attribute_list" => array(
  167. 'start_date' => OPT_ATT_READONLY,
  168. 'end_date' => OPT_ATT_MANDATORY,
  169. 'impact' => OPT_ATT_READONLY,
  170. 'supervisor_group_id' => OPT_ATT_READONLY,
  171. 'supervisor_id' => OPT_ATT_READONLY,
  172. 'manager_group_id' => OPT_ATT_READONLY,
  173. 'manager_id' => OPT_ATT_READONLY,
  174. 'outage' => OPT_ATT_READONLY,
  175. ),
  176. )
  177. );
  178. MetaModel::Init_DefineState(
  179. "notapproved",
  180. array(
  181. "attribute_inherit" => 'plannedscheduled',
  182. "attribute_list" => array(
  183. 'impact' => OPT_ATT_READONLY,
  184. 'supervisor_group_id' => OPT_ATT_READONLY,
  185. 'supervisor_id' => OPT_ATT_READONLY,
  186. 'manager_group_id' => OPT_ATT_READONLY,
  187. 'manager_id' => OPT_ATT_READONLY,
  188. ),
  189. )
  190. );
  191. MetaModel::Init_DefineState(
  192. "implemented",
  193. array(
  194. "attribute_inherit" => 'approved',
  195. "attribute_list" => array(
  196. ),
  197. )
  198. );
  199. MetaModel::Init_DefineState(
  200. "monitored",
  201. array(
  202. "attribute_inherit" => 'implemented',
  203. "attribute_list" => array(
  204. 'end_date' => OPT_ATT_READONLY,
  205. 'agent_id' => OPT_ATT_READONLY,
  206. 'fallback' => OPT_ATT_READONLY,
  207. ),
  208. )
  209. );
  210. MetaModel::Init_DefineState(
  211. "closed",
  212. array(
  213. "attribute_inherit" => 'monitored',
  214. "attribute_list" => array(
  215. 'ticket_log' => OPT_ATT_READONLY,
  216. 'close_date' => OPT_ATT_READONLY,
  217. ),
  218. )
  219. );
  220. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_validate", array()));
  221. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_reject", array()));
  222. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_assign", array()));
  223. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_reopen", array()));
  224. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_plan", array()));
  225. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_approve", array()));
  226. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_replan", array()));
  227. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_notapprove", array()));
  228. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_implement", array()));
  229. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_monitor", array()));
  230. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_finish", array()));
  231. }
  232. public function SetClosureDate($sStimulusCode)
  233. {
  234. $this->Set('close_date', time());
  235. return true;
  236. }
  237. protected function OnInsert()
  238. {
  239. $oToNotify = $this->Get('contact_list');
  240. $oToImpact = $this->Get('ci_list');
  241. $oImpactedInfras = DBObjectSet::FromLinkSet($this, 'ci_list', 'ci_id');
  242. $aComputed = $oImpactedInfras->GetRelatedObjects('impacts', 10);
  243. if (isset($aComputed['FunctionalCI']) && is_array($aComputed['FunctionalCI']))
  244. {
  245. foreach($aComputed['FunctionalCI'] as $iKey => $oObject)
  246. {
  247. $oNewLink = new lnkTicketToCI();
  248. $oNewLink->Set('ci_id', $iKey);
  249. $oToImpact->AddObject($oNewLink);
  250. }
  251. }
  252. if (isset($aComputed['Contact']) && is_array($aComputed['Contact']))
  253. {
  254. foreach($aComputed['Contact'] as $iKey => $oObject)
  255. {
  256. $oNewLink = new lnkTicketToContact();
  257. $oNewLink->Set('contact_id', $iKey);
  258. $oNewLink->Set('role', 'contact automatically computed');
  259. $oToNotify->AddObject($oNewLink);
  260. }
  261. }
  262. $this->Set('creation_date', time());
  263. $this->Set('last_update', time());
  264. }
  265. protected function OnUpdate()
  266. {
  267. $this->Set('last_update', time());
  268. }
  269. public function ComputeValues()
  270. {
  271. $sCurrRef = $this->Get('ref');
  272. if (strlen($sCurrRef) == 0)
  273. {
  274. $iKey = $this->GetKey();
  275. if ($iKey < 0)
  276. {
  277. // Object not yet in the Database
  278. $iKey = MetaModel::GetNextKey(get_class($this));
  279. }
  280. $sName = sprintf('C-%06d', $iKey);
  281. $this->Set('ref', $sName);
  282. }
  283. }
  284. /**
  285. * Get the icon representing this object
  286. * @param boolean $bImgTag If true the result is a full IMG tag (or an emtpy string if no icon is defined)
  287. * @return string Either the full IMG tag ($bImgTag == true) or just the path to the icon file
  288. */
  289. public function GetIcon($bImgTag = true)
  290. {
  291. $sStatus = $this->Get('status');
  292. switch($this->GetState())
  293. {
  294. case 'approved':
  295. case 'implemented':
  296. case 'monitored':
  297. $sIcon = self::MakeIconFromName('change-approved.png');
  298. break;
  299. case 'rejected':
  300. case 'notapproved':
  301. $sIcon = self::MakeIconFromName('change-rejected.png');
  302. break;
  303. case 'closed':
  304. $sIcon = self::MakeIconFromName('change-closed.png');
  305. break;
  306. default:
  307. $sIcon = MetaModel::GetClassIcon(get_class($this), $bImgTag);
  308. }
  309. return $sIcon;
  310. }
  311. protected static function MakeIconFromName($sIconName, $bImgTag = true)
  312. {
  313. $sIcon = '';
  314. if ($sIconName != '')
  315. {
  316. $sPath = '../modules/itop-change-mgmt-1.0.0/images/'.$sIconName;
  317. if ($bImgTag)
  318. {
  319. $sIcon = "<img src=\"$sPath\" style=\"vertical-align:middle;\"/>";
  320. }
  321. else
  322. {
  323. $sIcon = $sPath;
  324. }
  325. }
  326. return $sIcon;
  327. }
  328. }
  329. class RoutineChange extends Change
  330. {
  331. public static function Init()
  332. {
  333. $aParams = array
  334. (
  335. "category" => "bizmodel,searchable,changemgmt",
  336. "key_type" => "autoincrement",
  337. "name_attcode" => "ref",
  338. "state_attcode" => "",
  339. "reconc_keys" => array("ref"),
  340. "db_table" => "change_routine",
  341. "db_key_field" => "id",
  342. "db_finalclass_field" => "",
  343. "display_template" => "",
  344. );
  345. MetaModel::Init_Params($aParams);
  346. MetaModel::Init_InheritAttributes();
  347. MetaModel::Init_InheritLifecycle();
  348. MetaModel::Init_SetZListItems('details', array('title', 'org_id', 'description','ticket_log', 'start_date', 'end_date','document_list', 'ci_list', 'contact_list','incident_list', 'status', 'reason', 'requestor_id', 'workgroup_id', 'creation_date', 'last_update', 'close_date', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage', 'fallback'));
  349. MetaModel::Init_SetZListItems('advanced_search', array('ref', 'title', 'org_id', 'start_date', 'end_date','status', 'reason', 'requestor_id', 'workgroup_id', 'creation_date', 'last_update', 'close_date', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage'));
  350. MetaModel::Init_SetZListItems('standard_search', array('ref', 'title', 'org_id', 'start_date','end_date', 'status', 'reason', 'requestor_id', 'workgroup_id', 'creation_date', 'last_update', 'close_date', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage'));
  351. MetaModel::Init_SetZListItems('list', array('title', 'org_id', 'start_date', 'status', 'requestor_id'));
  352. MetaModel::Init_DefineTransition("new", "ev_assign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  353. MetaModel::Init_DefineTransition("assigned", "ev_plan", array("target_state"=>"plannedscheduled", "actions"=>array(), "user_restriction"=>null));
  354. MetaModel::Init_DefineTransition("plannedscheduled", "ev_implement", array("target_state"=>"implemented", "actions"=>array(), "user_restriction"=>null));
  355. MetaModel::Init_DefineTransition("implemented", "ev_monitor", array("target_state"=>"monitored", "actions"=>array(), "user_restriction"=>null));
  356. MetaModel::Init_DefineTransition("implemented", "ev_finish", array("target_state"=>"closed", "actions"=>array('SetClosureDate'), "user_restriction"=>null));
  357. MetaModel::Init_DefineTransition("monitored", "ev_finish", array("target_state"=>"closed", "actions"=>array('SetClosureDate'), "user_restriction"=>null));
  358. }
  359. }
  360. abstract class ApprovedChange extends Change
  361. {
  362. public static function Init()
  363. {
  364. $aParams = array
  365. (
  366. "category" => "bizmodel,searchable,changemgmt",
  367. "key_type" => "autoincrement",
  368. "name_attcode" => "ref",
  369. "state_attcode" => "",
  370. "reconc_keys" => array("ref"),
  371. "db_table" => "change_approved",
  372. "db_key_field" => "id",
  373. "db_finalclass_field" => "",
  374. "display_template" => "",
  375. );
  376. MetaModel::Init_Params($aParams);
  377. MetaModel::Init_InheritAttributes();
  378. MetaModel::Init_InheritLifecycle();
  379. MetaModel::Init_AddAttribute(new AttributeDateTime("approval_date", array("allowed_values"=>null, "sql"=>"approval_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  380. MetaModel::Init_AddAttribute(new AttributeString("approval_comment", array("allowed_values"=>null, "sql"=>"approval_comment", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  381. MetaModel::Init_SetZListItems('details', array('title', 'org_id', 'description','ticket_log', 'start_date', 'end_date','document_list', 'ci_list', 'contact_list','incident_list', 'status', 'reason', 'requestor_id', 'workgroup_id', 'creation_date', 'last_update', 'close_date', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage', 'fallback', 'approval_date', 'approval_comment'));
  382. MetaModel::Init_SetZListItems('advanced_search', array('ref', 'title', 'org_id', 'start_date','end_date', 'status', 'reason', 'requestor_id', 'workgroup_id', 'close_date', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage','approval_date'));
  383. MetaModel::Init_SetZListItems('standard_search', array('ref', 'title', 'org_id', 'start_date','end_date', 'status', 'reason', 'requestor_id', 'workgroup_id', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage', 'approval_date'));
  384. MetaModel::Init_SetZListItems('list', array('title', 'org_id', 'start_date', 'status', 'requestor_id'));
  385. MetaModel::Init_OverloadStateAttribute('new', 'approval_date', OPT_ATT_HIDDEN);
  386. MetaModel::Init_OverloadStateAttribute('new', 'approval_comment', OPT_ATT_HIDDEN);
  387. MetaModel::Init_OverloadStateAttribute('validated', 'approval_date', OPT_ATT_HIDDEN);
  388. MetaModel::Init_OverloadStateAttribute('validated', 'approval_comment', OPT_ATT_HIDDEN);
  389. MetaModel::Init_OverloadStateAttribute('rejected', 'approval_date', OPT_ATT_HIDDEN);
  390. MetaModel::Init_OverloadStateAttribute('rejected', 'approval_comment', OPT_ATT_HIDDEN);
  391. MetaModel::Init_OverloadStateAttribute('assigned', 'approval_date', OPT_ATT_HIDDEN);
  392. MetaModel::Init_OverloadStateAttribute('assigned', 'approval_comment', OPT_ATT_HIDDEN);
  393. MetaModel::Init_OverloadStateAttribute('plannedscheduled', 'approval_date', OPT_ATT_HIDDEN);
  394. MetaModel::Init_OverloadStateAttribute('plannedscheduled', 'approval_comment', OPT_ATT_HIDDEN);
  395. MetaModel::Init_OverloadStateAttribute('notapproved', 'approval_date', OPT_ATT_HIDDEN);
  396. MetaModel::Init_OverloadStateAttribute('notapproved', 'approval_comment', OPT_ATT_HIDDEN);
  397. MetaModel::Init_OverloadStateAttribute('approved', 'approval_date', OPT_ATT_MANDATORY);
  398. MetaModel::Init_OverloadStateAttribute('approved', 'approval_comment', OPT_ATT_MANDATORY);
  399. MetaModel::Init_OverloadStateAttribute('implemented', 'approval_date', OPT_ATT_READONLY);
  400. MetaModel::Init_OverloadStateAttribute('implemented', 'approval_comment', OPT_ATT_READONLY);
  401. MetaModel::Init_OverloadStateAttribute('monitored', 'approval_date', OPT_ATT_READONLY);
  402. MetaModel::Init_OverloadStateAttribute('monitored', 'approval_comment', OPT_ATT_READONLY);
  403. MetaModel::Init_OverloadStateAttribute('closed', 'approval_date', OPT_ATT_READONLY);
  404. MetaModel::Init_OverloadStateAttribute('closed', 'approval_comment', OPT_ATT_READONLY);
  405. }
  406. }
  407. class NormalChange extends ApprovedChange
  408. {
  409. public static function Init()
  410. {
  411. $aParams = array
  412. (
  413. "category" => "bizmodel,searchable,changemgmt",
  414. "key_type" => "autoincrement",
  415. "name_attcode" => "ref",
  416. "state_attcode" => "",
  417. "reconc_keys" => array("ref"),
  418. "db_table" => "change_normal",
  419. "db_key_field" => "id",
  420. "db_finalclass_field" => "",
  421. "display_template" => "",
  422. );
  423. MetaModel::Init_Params($aParams);
  424. MetaModel::Init_InheritAttributes();
  425. MetaModel::Init_InheritLifecycle();
  426. MetaModel::Init_AddAttribute(new AttributeDateTime("acceptance_date", array("allowed_values"=>null, "sql"=>"acceptance_date", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  427. MetaModel::Init_AddAttribute(new AttributeString("acceptance_comment", array("allowed_values"=>null, "sql"=>"acceptance_comment", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
  428. MetaModel::Init_SetZListItems('details', array('title', 'org_id', 'description','ticket_log', 'start_date','end_date', 'document_list', 'ci_list', 'contact_list','incident_list', 'status', 'reason', 'requestor_id', 'workgroup_id', 'creation_date', 'last_update','close_date', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage', 'fallback', 'approval_date', 'approval_comment', 'acceptance_date', 'acceptance_comment'));
  429. MetaModel::Init_SetZListItems('advanced_search', array('ref', 'title', 'org_id', 'start_date', 'end_date','status', 'reason', 'requestor_id', 'workgroup_id', 'creation_date', 'last_update', 'close_date', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage'));
  430. MetaModel::Init_SetZListItems('standard_search', array('ref', 'title', 'org_id', 'start_date','end_date', 'status', 'reason', 'requestor_id', 'workgroup_id', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage'));
  431. MetaModel::Init_SetZListItems('list', array('title', 'org_id', 'start_date', 'status', 'requestor_id'));
  432. MetaModel::Init_OverloadStateAttribute('new', 'acceptance_date', OPT_ATT_HIDDEN);
  433. MetaModel::Init_OverloadStateAttribute('new', 'acceptance_comment', OPT_ATT_HIDDEN);
  434. MetaModel::Init_OverloadStateAttribute('validated', 'acceptance_date', OPT_ATT_MANDATORY);
  435. MetaModel::Init_OverloadStateAttribute('validated', 'acceptance_comment', OPT_ATT_MANDATORY);
  436. MetaModel::Init_OverloadStateAttribute('rejected', 'acceptance_date', OPT_ATT_HIDDEN);
  437. MetaModel::Init_OverloadStateAttribute('rejected', 'acceptance_comment', OPT_ATT_HIDDEN);
  438. MetaModel::Init_OverloadStateAttribute('plannedscheduled', 'acceptance_date', OPT_ATT_READONLY);
  439. MetaModel::Init_OverloadStateAttribute('plannedscheduled', 'acceptance_comment', OPT_ATT_READONLY);
  440. MetaModel::Init_OverloadStateAttribute('approved', 'acceptance_date', OPT_ATT_READONLY);
  441. MetaModel::Init_OverloadStateAttribute('approved', 'acceptance_comment', OPT_ATT_READONLY);
  442. MetaModel::Init_OverloadStateAttribute('notapproved', 'acceptance_date', OPT_ATT_READONLY);
  443. MetaModel::Init_OverloadStateAttribute('notapproved', 'acceptance_comment', OPT_ATT_READONLY);
  444. MetaModel::Init_OverloadStateAttribute('implemented', 'acceptance_date', OPT_ATT_READONLY);
  445. MetaModel::Init_OverloadStateAttribute('implemented', 'acceptance_comment', OPT_ATT_READONLY);
  446. MetaModel::Init_OverloadStateAttribute('monitored', 'acceptance_date', OPT_ATT_READONLY);
  447. MetaModel::Init_OverloadStateAttribute('monitored', 'acceptance_comment', OPT_ATT_READONLY);
  448. MetaModel::Init_OverloadStateAttribute('closed', 'acceptance_date', OPT_ATT_READONLY);
  449. MetaModel::Init_OverloadStateAttribute('closed', 'acceptance_comment', OPT_ATT_READONLY);
  450. MetaModel::Init_DefineTransition("new", "ev_validate", array("target_state"=>"validated", "actions"=>array(), "user_restriction"=>null));
  451. MetaModel::Init_DefineTransition("new", "ev_reject", array("target_state"=>"rejected", "actions"=>array(), "user_restriction"=>null));
  452. MetaModel::Init_DefineTransition("rejected", "ev_reopen", array("target_state"=>"new", "actions"=>array(), "user_restriction"=>null));
  453. MetaModel::Init_DefineTransition("validated", "ev_assign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  454. MetaModel::Init_DefineTransition("assigned", "ev_plan", array("target_state"=>"plannedscheduled", "actions"=>array(), "user_restriction"=>null));
  455. MetaModel::Init_DefineTransition("plannedscheduled", "ev_approve", array("target_state"=>"approved", "actions"=>array(), "user_restriction"=>null));
  456. MetaModel::Init_DefineTransition("plannedscheduled", "ev_notapprove", array("target_state"=>"notapproved", "actions"=>array(), "user_restriction"=>null));
  457. MetaModel::Init_DefineTransition("notapproved", "ev_replan", array("target_state"=>"plannedscheduled", "actions"=>array(), "user_restriction"=>null));
  458. MetaModel::Init_DefineTransition("approved", "ev_implement", array("target_state"=>"implemented", "actions"=>array(), "user_restriction"=>null));
  459. MetaModel::Init_DefineTransition("implemented", "ev_monitor", array("target_state"=>"monitored", "actions"=>array(), "user_restriction"=>null));
  460. MetaModel::Init_DefineTransition("implemented", "ev_finish", array("target_state"=>"closed", "actions"=>array('SetClosureDate'), "user_restriction"=>null));
  461. MetaModel::Init_DefineTransition("monitored", "ev_finish", array("target_state"=>"closed", "actions"=>array('SetClosureDate'), "user_restriction"=>null));
  462. }
  463. }
  464. class EmergencyChange extends ApprovedChange
  465. {
  466. public static function Init()
  467. {
  468. $aParams = array
  469. (
  470. "category" => "bizmodel,searchable,changemgmt",
  471. "key_type" => "autoincrement",
  472. "name_attcode" => "ref",
  473. "state_attcode" => "",
  474. "reconc_keys" => array("ref"),
  475. "db_table" => "change_emergency",
  476. "db_key_field" => "id",
  477. "db_finalclass_field" => "",
  478. "display_template" => "",
  479. );
  480. MetaModel::Init_Params($aParams);
  481. MetaModel::Init_InheritAttributes();
  482. MetaModel::Init_InheritLifecycle();
  483. MetaModel::Init_SetZListItems('details', array('title', 'org_id', 'description','ticket_log', 'start_date', 'end_date','document_list', 'ci_list', 'contact_list','incident_list', 'status', 'reason', 'requestor_id', 'workgroup_id', 'creation_date', 'last_update', 'close_date', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage', 'fallback', 'approval_date', 'approval_comment'));
  484. MetaModel::Init_SetZListItems('advanced_search', array('ref', 'title', 'org_id', 'start_date','end_date', 'status', 'reason', 'requestor_id', 'workgroup_id', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage', 'approval_date'));
  485. MetaModel::Init_SetZListItems('standard_search', array('ref', 'title', 'org_id', 'start_date', 'end_date','status', 'reason', 'requestor_id', 'workgroup_id', 'creation_date', 'last_update', 'close_date', 'impact', 'agent_id', 'agent_email', 'supervisor_group_id', 'supervisor_id', 'manager_group_id', 'manager_id', 'outage', 'approval_date'));
  486. MetaModel::Init_SetZListItems('list', array('title', 'org_id', 'start_date', 'status', 'requestor_id'));
  487. MetaModel::Init_DefineTransition("new", "ev_assign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  488. MetaModel::Init_DefineTransition("assigned", "ev_plan", array("target_state"=>"plannedscheduled", "actions"=>array(), "user_restriction"=>null));
  489. MetaModel::Init_DefineTransition("plannedscheduled", "ev_approve", array("target_state"=>"approved", "actions"=>array(), "user_restriction"=>null));
  490. MetaModel::Init_DefineTransition("plannedscheduled", "ev_notapprove", array("target_state"=>"notapproved", "actions"=>array(), "user_restriction"=>null));
  491. MetaModel::Init_DefineTransition("notapproved", "ev_replan", array("target_state"=>"plannedscheduled", "actions"=>array(), "user_restriction"=>null));
  492. MetaModel::Init_DefineTransition("approved", "ev_implement", array("target_state"=>"implemented", "actions"=>array(), "user_restriction"=>null));
  493. MetaModel::Init_DefineTransition("implemented", "ev_monitor", array("target_state"=>"monitored", "actions"=>array(), "user_restriction"=>null));
  494. MetaModel::Init_DefineTransition("implemented", "ev_finish", array("target_state"=>"closed", "actions"=>array('SetClosureDate'), "user_restriction"=>null));
  495. MetaModel::Init_DefineTransition("monitored", "ev_finish", array("target_state"=>"closed", "actions"=>array('SetClosureDate'), "user_restriction"=>null));
  496. }
  497. }
  498. $oMyMenuGroup = new MenuGroup('ChangeManagement', 50 /* fRank */);
  499. new TemplateMenuNode('Change:Overview', '../modules/itop-change-mgmt-1.0.0/overview.html', $oMyMenuGroup->GetIndex() /* oParent */, 0 /* fRank */);
  500. new NewObjectMenuNode('NewChange', 'Change', $oMyMenuGroup->GetIndex(), 1 /* fRank */);
  501. new SearchMenuNode('SearchChanges', 'Change', $oMyMenuGroup->GetIndex(), 2 /* fRank */);
  502. $oShortcutNode = new TemplateMenuNode('Change:Shortcuts', '', $oMyMenuGroup->GetIndex(), 3 /* fRank */);
  503. $oNode = new OQLMenuNode('MyChanges', 'SELECT Change WHERE agent_id = :current_contact_id AND status NOT IN ("closed", "resolved")', $oShortcutNode->GetIndex(), 1 /* fRank */);
  504. $oNode->SetParameters(array('auto_reload' => 'fast'));
  505. $oNode = new OQLMenuNode('Changes', 'SELECT Change WHERE status != "closed"', $oShortcutNode->GetIndex(), 2 /* fRank */);
  506. $oNode->SetParameters(array('auto_reload' => 'fast'));
  507. $oNode = new OQLMenuNode('WaitingApproval', 'SELECT ApprovedChange WHERE status IN ("plannedscheduled")', $oShortcutNode->GetIndex(), 3 /* fRank */);
  508. $oNode->SetParameters(array('auto_reload' => 'fast'));
  509. $oNode = new OQLMenuNode('WaitingAcceptance', 'SELECT NormalChange WHERE status IN ("new")', $oShortcutNode->GetIndex(), 4 /* fRank */);
  510. $oNode->SetParameters(array('auto_reload' => 'fast'));
  511. ?>