trigger.class.inc.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Persistent class Trigger and derived
  18. * User defined triggers, that may be used in conjunction with user defined actions
  19. *
  20. * @author Erwan Taloc <erwan.taloc@combodo.com>
  21. * @author Romain Quetiez <romain.quetiez@combodo.com>
  22. * @author Denis Flaven <denis.flaven@combodo.com>
  23. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  24. */
  25. /**
  26. * A user defined trigger, to customize the application
  27. * A trigger will activate an action
  28. *
  29. * @package iTopORM
  30. */
  31. class Trigger extends cmdbAbstractObject
  32. {
  33. public static function Init()
  34. {
  35. $aParams = array
  36. (
  37. "category" => "core/cmdb",
  38. "key_type" => "autoincrement",
  39. "key_label" => "",
  40. "name_attcode" => "description",
  41. "state_attcode" => "",
  42. "reconc_keys" => array(),
  43. "db_table" => "priv_trigger",
  44. "db_key_field" => "id",
  45. "db_finalclass_field" => "realclass",
  46. "display_template" => "",
  47. );
  48. MetaModel::Init_Params($aParams);
  49. //MetaModel::Init_InheritAttributes();
  50. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  51. 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())));
  52. // Display lists
  53. MetaModel::Init_SetZListItems('details', array('finalclass', 'description')); // Attributes to be displayed for the complete details
  54. MetaModel::Init_SetZListItems('list', array('finalclass', 'description')); // Attributes to be displayed for a list
  55. // Search criteria
  56. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  57. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  58. }
  59. public function DoActivate($aContextArgs)
  60. {
  61. // Find the related
  62. $oLinkedActions = $this->Get('linked_actions');
  63. while ($oLink = $oLinkedActions->Fetch())
  64. {
  65. $iActionId = $oLink->Get('action_id');
  66. $oAction = MetaModel::GetObject('Action', $iActionId);
  67. if ($oAction->IsActive())
  68. {
  69. $oAction->DoExecute($this, $aContextArgs);
  70. }
  71. }
  72. }
  73. }
  74. class TriggerOnObject extends Trigger
  75. {
  76. public static function Init()
  77. {
  78. $aParams = array
  79. (
  80. "category" => "core/cmdb",
  81. "key_type" => "autoincrement",
  82. "key_label" => "",
  83. "name_attcode" => "",
  84. "state_attcode" => "",
  85. "reconc_keys" => array(),
  86. "db_table" => "priv_trigger_onobject",
  87. "db_key_field" => "id",
  88. "db_finalclass_field" => "",
  89. "display_template" => "",
  90. );
  91. MetaModel::Init_Params($aParams);
  92. MetaModel::Init_InheritAttributes();
  93. 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())));
  94. // Display lists
  95. MetaModel::Init_SetZListItems('details', array('description', 'target_class')); // Attributes to be displayed for the complete details
  96. MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'description')); // Attributes to be displayed for a list
  97. // Search criteria
  98. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  99. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  100. }
  101. }
  102. class TriggerOnStateChange extends TriggerOnObject
  103. {
  104. public static function Init()
  105. {
  106. $aParams = array
  107. (
  108. "category" => "core/cmdb",
  109. "key_type" => "autoincrement",
  110. "key_label" => "",
  111. "name_attcode" => "",
  112. "state_attcode" => "",
  113. "reconc_keys" => array(),
  114. "db_table" => "priv_trigger_onstatechange",
  115. "db_key_field" => "id",
  116. "db_finalclass_field" => "",
  117. "display_template" => "",
  118. );
  119. MetaModel::Init_Params($aParams);
  120. MetaModel::Init_InheritAttributes();
  121. MetaModel::Init_AddAttribute(new AttributeString("state", array("allowed_values"=>null, "sql"=>"state", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  122. // Display lists
  123. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state')); // Attributes to be displayed for the complete details
  124. MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'state', 'description')); // Attributes to be displayed for a list
  125. // Search criteria
  126. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  127. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  128. }
  129. }
  130. class TriggerOnStateEnter extends TriggerOnStateChange
  131. {
  132. public static function Init()
  133. {
  134. $aParams = array
  135. (
  136. "category" => "core/cmdb",
  137. "key_type" => "autoincrement",
  138. "key_label" => "",
  139. "name_attcode" => "",
  140. "state_attcode" => "",
  141. "reconc_keys" => array(),
  142. "db_table" => "priv_trigger_onstateenter",
  143. "db_key_field" => "id",
  144. "db_finalclass_field" => "",
  145. "display_template" => "",
  146. );
  147. MetaModel::Init_Params($aParams);
  148. MetaModel::Init_InheritAttributes();
  149. // Display lists
  150. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state')); // Attributes to be displayed for the complete details
  151. MetaModel::Init_SetZListItems('list', array('target_class', 'state', 'description')); // Attributes to be displayed for a list
  152. // Search criteria
  153. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  154. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  155. }
  156. }
  157. class TriggerOnStateLeave extends TriggerOnStateChange
  158. {
  159. public static function Init()
  160. {
  161. $aParams = array
  162. (
  163. "category" => "core/cmdb",
  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. // Display lists
  177. MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state')); // Attributes to be displayed for the complete details
  178. MetaModel::Init_SetZListItems('list', array('target_class', 'state', 'description')); // Attributes to be displayed for a list
  179. // Search criteria
  180. // MetaModel::Init_SetZListItems('standard_search', array('')); // Criteria of the std search form
  181. // MetaModel::Init_SetZListItems('advanced_search', array('')); // Criteria of the advanced search form
  182. }
  183. }
  184. class TriggerOnObjectCreate extends TriggerOnObject
  185. {
  186. public static function Init()
  187. {
  188. $aParams = array
  189. (
  190. "category" => "core/cmdb",
  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. // Display lists
  204. MetaModel::Init_SetZListItems('details', array('description', 'target_class')); // Attributes to be displayed for the complete details
  205. MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'description')); // Attributes to be displayed for a list
  206. // Search criteria
  207. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  208. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  209. }
  210. }
  211. class lnkTriggerAction extends cmdbAbstractObject
  212. {
  213. public static function Init()
  214. {
  215. $aParams = array
  216. (
  217. "category" => "core/cmdb",
  218. "key_type" => "autoincrement",
  219. "key_label" => "Link ID",
  220. "name_attcode" => "",
  221. "state_attcode" => "",
  222. "reconc_keys" => array(""),
  223. "db_table" => "priv_link_action_trigger",
  224. "db_key_field" => "link_id",
  225. "db_finalclass_field" => "",
  226. "display_template" => "",
  227. );
  228. MetaModel::Init_Params($aParams);
  229. 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())));
  230. MetaModel::Init_AddAttribute(new AttributeExternalField("action_name", array("allowed_values"=>null, "extkey_attcode"=> 'action_id', "target_attcode"=>"name")));
  231. 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())));
  232. MetaModel::Init_AddAttribute(new AttributeExternalField("trigger_name", array("allowed_values"=>null, "extkey_attcode"=> 'trigger_id', "target_attcode"=>"description")));
  233. MetaModel::Init_AddAttribute(new AttributeInteger("order", array("allowed_values"=>null, "sql"=>"order", "default_value"=>0, "is_null_allowed"=>true, "depends_on"=>array())));
  234. // Display lists
  235. MetaModel::Init_SetZListItems('details', array('action_id', 'trigger_id', 'order')); // Attributes to be displayed for a list
  236. MetaModel::Init_SetZListItems('list', array('action_name', 'trigger_name', 'order')); // Attributes to be displayed for a list
  237. // Search criteria
  238. MetaModel::Init_SetZListItems('standard_search', array('action_id', 'trigger_id', 'order')); // Criteria of the std search form
  239. MetaModel::Init_SetZListItems('advanced_search', array('action_id', 'trigger_id', 'order')); // Criteria of the advanced search form
  240. }
  241. }
  242. ?>