trigger.class.inc.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /**
  3. * A user defined trigger, to customize the application
  4. * A trigger will activate an action
  5. *
  6. * @package iTopORM
  7. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  8. * @author Denis Flaven <denisflave@free.fr>
  9. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  10. * @link www.itop.com
  11. * @since 1.0
  12. * @version 1.1.1.1 $
  13. */
  14. class Trigger extends cmdbAbstractObject
  15. {
  16. public static function Init()
  17. {
  18. $aParams = array
  19. (
  20. "category" => "core/cmdb",
  21. "name" => "trigger",
  22. "description" => "Custom event handler",
  23. "key_type" => "autoincrement",
  24. "key_label" => "",
  25. "name_attcode" => "",
  26. "state_attcode" => "",
  27. "reconc_keys" => array(),
  28. "db_table" => "priv_trigger",
  29. "db_key_field" => "id",
  30. "db_finalclass_field" => "realclass",
  31. "display_template" => "",
  32. );
  33. MetaModel::Init_Params($aParams);
  34. //MetaModel::Init_InheritAttributes();
  35. MetaModel::Init_AddAttribute(new AttributeString("description", array("label"=>"Description", "description"=>"one line description", "allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  36. MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("linked_actions", array("label"=>"Triggered actions", "description"=>"Actions performed when the trigger is activated", "linked_class"=>"lnkTriggerAction", "ext_key_to_me"=>"trigger_id", "ext_key_to_remote"=>"action_id", "allowed_values"=>null, "count_min"=>1, "count_max"=>0, "depends_on"=>array())));
  37. //MetaModel::Init_InheritFilters();
  38. MetaModel::Init_AddFilterFromAttribute("description");
  39. // Display lists
  40. MetaModel::Init_SetZListItems('details', array('finalclass', 'description')); // Attributes to be displayed for the complete details
  41. MetaModel::Init_SetZListItems('list', array('finalclass', 'description')); // Attributes to be displayed for a list
  42. // Search criteria
  43. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  44. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  45. }
  46. public function DoActivate($aContextArgs)
  47. {
  48. // Find the related
  49. $oLinkedActions = $this->Get('linked_actions');
  50. while ($oLink = $oLinkedActions->Fetch())
  51. {
  52. $iActionId = $oLink->Get('action_id');
  53. $oAction = MetaModel::GetObject('Action', $iActionId);
  54. $oAction->DoExecute($this, $aContextArgs);
  55. }
  56. }
  57. }
  58. class TriggerOnStateChange extends Trigger
  59. {
  60. public static function Init()
  61. {
  62. $aParams = array
  63. (
  64. "category" => "core/cmdb",
  65. "name" => "Trigger on object state change",
  66. "description" => "Trigger on object state change",
  67. "key_type" => "autoincrement",
  68. "key_label" => "",
  69. "name_attcode" => "",
  70. "state_attcode" => "",
  71. "reconc_keys" => array(),
  72. "db_table" => "priv_trigger_onstatechange",
  73. "db_key_field" => "id",
  74. "db_finalclass_field" => "",
  75. "display_template" => "",
  76. );
  77. MetaModel::Init_Params($aParams);
  78. MetaModel::Init_InheritAttributes();
  79. MetaModel::Init_AddAttribute(new AttributeString("target_class", array("label"=>"Target class", "description"=>"label", "allowed_values"=>null, "sql"=>"target_class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  80. MetaModel::Init_AddAttribute(new AttributeString("state", array("label"=>"State", "description"=>"label", "allowed_values"=>null, "sql"=>"state", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  81. MetaModel::Init_InheritFilters();
  82. MetaModel::Init_AddFilterFromAttribute("target_class");
  83. MetaModel::Init_AddFilterFromAttribute("state");
  84. // Display lists
  85. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state')); // Attributes to be displayed for the complete details
  86. MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'state')); // Attributes to be displayed for a list
  87. // Search criteria
  88. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  89. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  90. }
  91. }
  92. class TriggerOnStateEnter extends TriggerOnStateChange
  93. {
  94. public static function Init()
  95. {
  96. $aParams = array
  97. (
  98. "category" => "core/cmdb",
  99. "name" => "Trigger on object entering a state",
  100. "description" => "Trigger on object state change - entering",
  101. "key_type" => "autoincrement",
  102. "key_label" => "",
  103. "name_attcode" => "",
  104. "state_attcode" => "",
  105. "reconc_keys" => array(),
  106. "db_table" => "priv_trigger_onstateenter",
  107. "db_key_field" => "id",
  108. "db_finalclass_field" => "",
  109. "display_template" => "",
  110. );
  111. MetaModel::Init_Params($aParams);
  112. MetaModel::Init_InheritAttributes();
  113. MetaModel::Init_InheritFilters();
  114. // Display lists
  115. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state')); // Attributes to be displayed for the complete details
  116. MetaModel::Init_SetZListItems('list', array('target_class', 'state')); // Attributes to be displayed for a list
  117. // Search criteria
  118. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  119. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  120. }
  121. }
  122. class TriggerOnStateLeave extends TriggerOnStateChange
  123. {
  124. public static function Init()
  125. {
  126. $aParams = array
  127. (
  128. "category" => "core/cmdb",
  129. "name" => "Trigger on object leaving a state",
  130. "description" => "Trigger on object state change - leaving",
  131. "key_type" => "autoincrement",
  132. "key_label" => "",
  133. "name_attcode" => "",
  134. "state_attcode" => "",
  135. "reconc_keys" => array(),
  136. "db_table" => "priv_trigger_onstateleave",
  137. "db_key_field" => "id",
  138. "db_finalclass_field" => "",
  139. "display_template" => "",
  140. );
  141. MetaModel::Init_Params($aParams);
  142. MetaModel::Init_InheritAttributes();
  143. MetaModel::Init_InheritFilters();
  144. // Display lists
  145. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state')); // Attributes to be displayed for the complete details
  146. MetaModel::Init_SetZListItems('list', array('target_class', 'state')); // Attributes to be displayed for a list
  147. // Search criteria
  148. // MetaModel::Init_SetZListItems('standard_search', array('')); // Criteria of the std search form
  149. // MetaModel::Init_SetZListItems('advanced_search', array('')); // Criteria of the advanced search form
  150. }
  151. }
  152. class lnkTriggerAction extends cmdbAbstractObject
  153. {
  154. public static function Init()
  155. {
  156. $aParams = array
  157. (
  158. "category" => "core/cmdb",
  159. "name" => "Actions-Trigger",
  160. "description" => "Link between a trigger and an action",
  161. "key_type" => "autoincrement",
  162. "key_label" => "Link ID",
  163. "name_attcode" => "",
  164. "state_attcode" => "",
  165. "reconc_keys" => array(""),
  166. "db_table" => "priv_link_action_trigger",
  167. "db_key_field" => "link_id",
  168. "db_finalclass_field" => "",
  169. "display_template" => "",
  170. );
  171. MetaModel::Init_Params($aParams);
  172. MetaModel::Init_AddAttribute(new AttributeExternalKey("action_id", array("targetclass"=>"Action", "jointype"=> '', "label"=>"Action", "description"=>"The action to be executed", "allowed_values"=>null, "sql"=>"action_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  173. MetaModel::Init_AddAttribute(new AttributeExternalField("action_name", array("label"=>"Action Name", "description"=>"Name of the action", "allowed_values"=>null, "extkey_attcode"=> 'action_id', "target_attcode"=>"name")));
  174. MetaModel::Init_AddAttribute(new AttributeExternalKey("trigger_id", array("targetclass"=>"Trigger", "jointype"=> '', "label"=>"Trigger", "description"=>"Trigger", "allowed_values"=>null, "sql"=>"trigger_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  175. MetaModel::Init_AddAttribute(new AttributeInteger("order", array("label"=>"Order", "description"=>"Actions execution order", "allowed_values"=>null, "sql"=>"order", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  176. MetaModel::Init_AddFilterFromAttribute("action_id");
  177. MetaModel::Init_AddFilterFromAttribute("trigger_id");
  178. // Display lists
  179. MetaModel::Init_SetZListItems('details', array('action_id', 'trigger_id', 'order')); // Attributes to be displayed for a list
  180. MetaModel::Init_SetZListItems('list', array('action_id', 'trigger_id', 'order')); // Attributes to be displayed for a list
  181. // Search criteria
  182. MetaModel::Init_SetZListItems('standard_search', array('action_id', 'trigger_id', 'order')); // Criteria of the std search form
  183. MetaModel::Init_SetZListItems('advanced_search', array('action_id', 'trigger_id', 'order')); // Criteria of the advanced search form
  184. }
  185. }
  186. ?>