trigger.class.inc.php 11 KB

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