trigger.class.inc.php 9.8 KB

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