trigger.class.inc.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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" => "description",
  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 TriggerOnObject extends Trigger
  59. {
  60. public static function Init()
  61. {
  62. $aParams = array
  63. (
  64. "category" => "core/cmdb",
  65. "name" => "Trigger on a class of objects",
  66. "description" => "Trigger on a given class of objects",
  67. "key_type" => "autoincrement",
  68. "key_label" => "",
  69. "name_attcode" => "",
  70. "state_attcode" => "",
  71. "reconc_keys" => array(),
  72. "db_table" => "priv_trigger_onobject",
  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 AttributeClass("target_class", array("label"=>"Target class", "description"=>"label", "class_category"=>"bizmodel", "more_values"=>null, "sql"=>"target_class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  80. MetaModel::Init_InheritFilters();
  81. MetaModel::Init_AddFilterFromAttribute("target_class");
  82. // Display lists
  83. MetaModel::Init_SetZListItems('details', array('description', 'target_class')); // Attributes to be displayed for the complete details
  84. MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'description')); // Attributes to be displayed for a list
  85. // Search criteria
  86. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  87. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  88. }
  89. }
  90. class TriggerOnStateChange extends TriggerOnObject
  91. {
  92. public static function Init()
  93. {
  94. $aParams = array
  95. (
  96. "category" => "core/cmdb",
  97. "name" => "Trigger on object state change",
  98. "description" => "Trigger on object state change",
  99. "key_type" => "autoincrement",
  100. "key_label" => "",
  101. "name_attcode" => "",
  102. "state_attcode" => "",
  103. "reconc_keys" => array(),
  104. "db_table" => "priv_trigger_onstatechange",
  105. "db_key_field" => "id",
  106. "db_finalclass_field" => "",
  107. "display_template" => "",
  108. );
  109. MetaModel::Init_Params($aParams);
  110. MetaModel::Init_InheritAttributes();
  111. 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())));
  112. MetaModel::Init_InheritFilters();
  113. MetaModel::Init_AddFilterFromAttribute("state");
  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('finalclass', 'target_class', 'state', 'description')); // 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 TriggerOnStateEnter extends TriggerOnStateChange
  123. {
  124. public static function Init()
  125. {
  126. $aParams = array
  127. (
  128. "category" => "core/cmdb",
  129. "name" => "Trigger on object entering a state",
  130. "description" => "Trigger on object state change - entering",
  131. "key_type" => "autoincrement",
  132. "key_label" => "",
  133. "name_attcode" => "",
  134. "state_attcode" => "",
  135. "reconc_keys" => array(),
  136. "db_table" => "priv_trigger_onstateenter",
  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', 'description')); // Attributes to be displayed for a list
  147. // Search criteria
  148. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  149. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  150. }
  151. }
  152. class TriggerOnStateLeave extends TriggerOnStateChange
  153. {
  154. public static function Init()
  155. {
  156. $aParams = array
  157. (
  158. "category" => "core/cmdb",
  159. "name" => "Trigger on object leaving a state",
  160. "description" => "Trigger on object state change - leaving",
  161. "key_type" => "autoincrement",
  162. "key_label" => "",
  163. "name_attcode" => "",
  164. "state_attcode" => "",
  165. "reconc_keys" => array(),
  166. "db_table" => "priv_trigger_onstateleave",
  167. "db_key_field" => "id",
  168. "db_finalclass_field" => "",
  169. "display_template" => "",
  170. );
  171. MetaModel::Init_Params($aParams);
  172. MetaModel::Init_InheritAttributes();
  173. MetaModel::Init_InheritFilters();
  174. // Display lists
  175. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state')); // Attributes to be displayed for the complete details
  176. MetaModel::Init_SetZListItems('list', array('target_class', 'state', 'description')); // Attributes to be displayed for a list
  177. // Search criteria
  178. // MetaModel::Init_SetZListItems('standard_search', array('')); // Criteria of the std search form
  179. // MetaModel::Init_SetZListItems('advanced_search', array('')); // Criteria of the advanced search form
  180. }
  181. }
  182. class TriggerOnObjectCreate extends TriggerOnObject
  183. {
  184. public static function Init()
  185. {
  186. $aParams = array
  187. (
  188. "category" => "core/cmdb",
  189. "name" => "Trigger on object creation",
  190. "description" => "Trigger on object creation of [a child class of] the given class",
  191. "key_type" => "autoincrement",
  192. "key_label" => "",
  193. "name_attcode" => "",
  194. "state_attcode" => "",
  195. "reconc_keys" => array(),
  196. "db_table" => "priv_trigger_onobjcreate",
  197. "db_key_field" => "id",
  198. "db_finalclass_field" => "",
  199. "display_template" => "",
  200. );
  201. MetaModel::Init_Params($aParams);
  202. MetaModel::Init_InheritAttributes();
  203. MetaModel::Init_InheritFilters();
  204. // Display lists
  205. MetaModel::Init_SetZListItems('details', array('description', 'target_class')); // Attributes to be displayed for the complete details
  206. MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'description')); // Attributes to be displayed for a list
  207. // Search criteria
  208. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  209. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  210. }
  211. }
  212. class lnkTriggerAction extends cmdbAbstractObject
  213. {
  214. public static function Init()
  215. {
  216. $aParams = array
  217. (
  218. "category" => "core/cmdb",
  219. "name" => "Actions-Trigger",
  220. "description" => "Link between a trigger and an action",
  221. "key_type" => "autoincrement",
  222. "key_label" => "Link ID",
  223. "name_attcode" => "",
  224. "state_attcode" => "",
  225. "reconc_keys" => array(""),
  226. "db_table" => "priv_link_action_trigger",
  227. "db_key_field" => "link_id",
  228. "db_finalclass_field" => "",
  229. "display_template" => "",
  230. );
  231. MetaModel::Init_Params($aParams);
  232. 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())));
  233. 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")));
  234. 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())));
  235. MetaModel::Init_AddAttribute(new AttributeExternalField("trigger_name", array("label"=>"Trigger Name", "description"=>"Name of the trigger", "allowed_values"=>null, "extkey_attcode"=> 'trigger_id', "target_attcode"=>"description")));
  236. 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())));
  237. MetaModel::Init_AddFilterFromAttribute("action_id");
  238. MetaModel::Init_AddFilterFromAttribute("trigger_id");
  239. MetaModel::Init_AddFilterFromAttribute("order");
  240. // Display lists
  241. MetaModel::Init_SetZListItems('details', array('action_id', 'trigger_id', 'order')); // Attributes to be displayed for a list
  242. MetaModel::Init_SetZListItems('list', array('action_name', 'trigger_name', 'order')); // Attributes to be displayed for a list
  243. // Search criteria
  244. MetaModel::Init_SetZListItems('standard_search', array('action_id', 'trigger_id', 'order')); // Criteria of the std search form
  245. MetaModel::Init_SetZListItems('advanced_search', array('action_id', 'trigger_id', 'order')); // Criteria of the advanced search form
  246. }
  247. }
  248. ?>