trigger.class.inc.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. "key_type" => "autoincrement",
  22. "key_label" => "",
  23. "name_attcode" => "description",
  24. "state_attcode" => "",
  25. "reconc_keys" => array(),
  26. "db_table" => "priv_trigger",
  27. "db_key_field" => "id",
  28. "db_finalclass_field" => "realclass",
  29. "display_template" => "",
  30. );
  31. MetaModel::Init_Params($aParams);
  32. //MetaModel::Init_InheritAttributes();
  33. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  34. MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("linked_actions", array("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())));
  35. //MetaModel::Init_InheritFilters();
  36. MetaModel::Init_AddFilterFromAttribute("description");
  37. // Display lists
  38. MetaModel::Init_SetZListItems('details', array('finalclass', 'description')); // Attributes to be displayed for the complete details
  39. MetaModel::Init_SetZListItems('list', array('finalclass', 'description')); // Attributes to be displayed for a list
  40. // Search criteria
  41. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  42. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  43. }
  44. public function DoActivate($aContextArgs)
  45. {
  46. // Find the related
  47. $oLinkedActions = $this->Get('linked_actions');
  48. while ($oLink = $oLinkedActions->Fetch())
  49. {
  50. $iActionId = $oLink->Get('action_id');
  51. $oAction = MetaModel::GetObject('Action', $iActionId);
  52. if ($oAction->IsActive())
  53. {
  54. $oAction->DoExecute($this, $aContextArgs);
  55. }
  56. }
  57. }
  58. }
  59. class TriggerOnObject extends Trigger
  60. {
  61. public static function Init()
  62. {
  63. $aParams = array
  64. (
  65. "category" => "core/cmdb",
  66. "key_type" => "autoincrement",
  67. "key_label" => "",
  68. "name_attcode" => "",
  69. "state_attcode" => "",
  70. "reconc_keys" => array(),
  71. "db_table" => "priv_trigger_onobject",
  72. "db_key_field" => "id",
  73. "db_finalclass_field" => "",
  74. "display_template" => "",
  75. );
  76. MetaModel::Init_Params($aParams);
  77. MetaModel::Init_InheritAttributes();
  78. MetaModel::Init_AddAttribute(new AttributeClass("target_class", array("class_category"=>"bizmodel", "more_values"=>null, "sql"=>"target_class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  79. MetaModel::Init_InheritFilters();
  80. MetaModel::Init_AddFilterFromAttribute("target_class");
  81. // Display lists
  82. MetaModel::Init_SetZListItems('details', array('description', 'target_class')); // Attributes to be displayed for the complete details
  83. MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'description')); // Attributes to be displayed for a list
  84. // Search criteria
  85. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  86. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  87. }
  88. }
  89. class TriggerOnStateChange extends TriggerOnObject
  90. {
  91. public static function Init()
  92. {
  93. $aParams = array
  94. (
  95. "category" => "core/cmdb",
  96. "key_type" => "autoincrement",
  97. "key_label" => "",
  98. "name_attcode" => "",
  99. "state_attcode" => "",
  100. "reconc_keys" => array(),
  101. "db_table" => "priv_trigger_onstatechange",
  102. "db_key_field" => "id",
  103. "db_finalclass_field" => "",
  104. "display_template" => "",
  105. );
  106. MetaModel::Init_Params($aParams);
  107. MetaModel::Init_InheritAttributes();
  108. MetaModel::Init_AddAttribute(new AttributeString("state", array("allowed_values"=>null, "sql"=>"state", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  109. MetaModel::Init_InheritFilters();
  110. MetaModel::Init_AddFilterFromAttribute("state");
  111. // Display lists
  112. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state')); // Attributes to be displayed for the complete details
  113. MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'state', 'description')); // Attributes to be displayed for a list
  114. // Search criteria
  115. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  116. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  117. }
  118. }
  119. class TriggerOnStateEnter extends TriggerOnStateChange
  120. {
  121. public static function Init()
  122. {
  123. $aParams = array
  124. (
  125. "category" => "core/cmdb",
  126. "key_type" => "autoincrement",
  127. "key_label" => "",
  128. "name_attcode" => "",
  129. "state_attcode" => "",
  130. "reconc_keys" => array(),
  131. "db_table" => "priv_trigger_onstateenter",
  132. "db_key_field" => "id",
  133. "db_finalclass_field" => "",
  134. "display_template" => "",
  135. );
  136. MetaModel::Init_Params($aParams);
  137. MetaModel::Init_InheritAttributes();
  138. MetaModel::Init_InheritFilters();
  139. // Display lists
  140. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state')); // Attributes to be displayed for the complete details
  141. MetaModel::Init_SetZListItems('list', array('target_class', 'state', 'description')); // Attributes to be displayed for a list
  142. // Search criteria
  143. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  144. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  145. }
  146. }
  147. class TriggerOnStateLeave extends TriggerOnStateChange
  148. {
  149. public static function Init()
  150. {
  151. $aParams = array
  152. (
  153. "category" => "core/cmdb",
  154. "key_type" => "autoincrement",
  155. "key_label" => "",
  156. "name_attcode" => "",
  157. "state_attcode" => "",
  158. "reconc_keys" => array(),
  159. "db_table" => "priv_trigger_onstateleave",
  160. "db_key_field" => "id",
  161. "db_finalclass_field" => "",
  162. "display_template" => "",
  163. );
  164. MetaModel::Init_Params($aParams);
  165. MetaModel::Init_InheritAttributes();
  166. MetaModel::Init_InheritFilters();
  167. // Display lists
  168. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state')); // Attributes to be displayed for the complete details
  169. MetaModel::Init_SetZListItems('list', array('target_class', 'state', 'description')); // Attributes to be displayed for a list
  170. // Search criteria
  171. // MetaModel::Init_SetZListItems('standard_search', array('')); // Criteria of the std search form
  172. // MetaModel::Init_SetZListItems('advanced_search', array('')); // Criteria of the advanced search form
  173. }
  174. }
  175. class TriggerOnObjectCreate extends TriggerOnObject
  176. {
  177. public static function Init()
  178. {
  179. $aParams = array
  180. (
  181. "category" => "core/cmdb",
  182. "key_type" => "autoincrement",
  183. "key_label" => "",
  184. "name_attcode" => "",
  185. "state_attcode" => "",
  186. "reconc_keys" => array(),
  187. "db_table" => "priv_trigger_onobjcreate",
  188. "db_key_field" => "id",
  189. "db_finalclass_field" => "",
  190. "display_template" => "",
  191. );
  192. MetaModel::Init_Params($aParams);
  193. MetaModel::Init_InheritAttributes();
  194. MetaModel::Init_InheritFilters();
  195. // Display lists
  196. MetaModel::Init_SetZListItems('details', array('description', 'target_class')); // Attributes to be displayed for the complete details
  197. MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'description')); // Attributes to be displayed for a list
  198. // Search criteria
  199. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  200. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  201. }
  202. }
  203. class lnkTriggerAction extends cmdbAbstractObject
  204. {
  205. public static function Init()
  206. {
  207. $aParams = array
  208. (
  209. "category" => "core/cmdb",
  210. "key_type" => "autoincrement",
  211. "key_label" => "Link ID",
  212. "name_attcode" => "",
  213. "state_attcode" => "",
  214. "reconc_keys" => array(""),
  215. "db_table" => "priv_link_action_trigger",
  216. "db_key_field" => "link_id",
  217. "db_finalclass_field" => "",
  218. "display_template" => "",
  219. );
  220. MetaModel::Init_Params($aParams);
  221. MetaModel::Init_AddAttribute(new AttributeExternalKey("action_id", array("targetclass"=>"Action", "jointype"=> '', "allowed_values"=>null, "sql"=>"action_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  222. MetaModel::Init_AddAttribute(new AttributeExternalField("action_name", array("allowed_values"=>null, "extkey_attcode"=> 'action_id', "target_attcode"=>"name")));
  223. MetaModel::Init_AddAttribute(new AttributeExternalKey("trigger_id", array("targetclass"=>"Trigger", "jointype"=> '', "allowed_values"=>null, "sql"=>"trigger_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  224. MetaModel::Init_AddAttribute(new AttributeExternalField("trigger_name", array("allowed_values"=>null, "extkey_attcode"=> 'trigger_id', "target_attcode"=>"description")));
  225. MetaModel::Init_AddAttribute(new AttributeInteger("order", array("allowed_values"=>null, "sql"=>"order", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  226. MetaModel::Init_AddFilterFromAttribute("action_id");
  227. MetaModel::Init_AddFilterFromAttribute("trigger_id");
  228. MetaModel::Init_AddFilterFromAttribute("order");
  229. // Display lists
  230. MetaModel::Init_SetZListItems('details', array('action_id', 'trigger_id', 'order')); // Attributes to be displayed for a list
  231. MetaModel::Init_SetZListItems('list', array('action_name', 'trigger_name', 'order')); // Attributes to be displayed for a list
  232. // Search criteria
  233. MetaModel::Init_SetZListItems('standard_search', array('action_id', 'trigger_id', 'order')); // Criteria of the std search form
  234. MetaModel::Init_SetZListItems('advanced_search', array('action_id', 'trigger_id', 'order')); // Criteria of the advanced search form
  235. }
  236. }
  237. ?>