trigger.class.inc.php 12 KB

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