dolibarr  17.0.3
interface_99_modMyModule_MyModuleTriggers.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) ---Put here your own copyright and developer email---
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, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
33 require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
34 
35 
40 {
46  public function __construct($db)
47  {
48  $this->db = $db;
49 
50  $this->name = preg_replace('/^Interface/i', '', get_class($this));
51  $this->family = "demo";
52  $this->description = "MyModule triggers.";
53  // 'development', 'experimental', 'dolibarr' or version
54  $this->version = 'development';
55  $this->picto = 'mymodule@mymodule';
56  }
57 
63  public function getName()
64  {
65  return $this->name;
66  }
67 
73  public function getDesc()
74  {
75  return $this->description;
76  }
77 
78 
91  public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
92  {
93  if (empty($conf->mymodule) || empty($conf->mymodule->enabled)) {
94  return 0; // If module is not enabled, we do nothing
95  }
96 
97  // Put here code you want to execute when a Dolibarr business events occurs.
98  // Data and type of action are stored into $object and $action
99 
100  // You can isolate code for each action in a separate method: this method should be named like the trigger in camelCase.
101  // For example : COMPANY_CREATE => public function companyCreate($action, $object, User $user, Translate $langs, Conf $conf)
102  $methodName = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($action)))));
103  $callback = array($this, $methodName);
104  if (is_callable($callback)) {
105  dol_syslog(
106  "Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id
107  );
108 
109  return call_user_func($callback, $action, $object, $user, $langs, $conf);
110  };
111 
112  // Or you can execute some code here
113  switch ($action) {
114  // Users
115  //case 'USER_CREATE':
116  //case 'USER_MODIFY':
117  //case 'USER_NEW_PASSWORD':
118  //case 'USER_ENABLEDISABLE':
119  //case 'USER_DELETE':
120 
121  // Actions
122  //case 'ACTION_MODIFY':
123  //case 'ACTION_CREATE':
124  //case 'ACTION_DELETE':
125 
126  // Groups
127  //case 'USERGROUP_CREATE':
128  //case 'USERGROUP_MODIFY':
129  //case 'USERGROUP_DELETE':
130 
131  // Companies
132  //case 'COMPANY_CREATE':
133  //case 'COMPANY_MODIFY':
134  //case 'COMPANY_DELETE':
135 
136  // Contacts
137  //case 'CONTACT_CREATE':
138  //case 'CONTACT_MODIFY':
139  //case 'CONTACT_DELETE':
140  //case 'CONTACT_ENABLEDISABLE':
141 
142  // Products
143  //case 'PRODUCT_CREATE':
144  //case 'PRODUCT_MODIFY':
145  //case 'PRODUCT_DELETE':
146  //case 'PRODUCT_PRICE_MODIFY':
147  //case 'PRODUCT_SET_MULTILANGS':
148  //case 'PRODUCT_DEL_MULTILANGS':
149 
150  //Stock mouvement
151  //case 'STOCK_MOVEMENT':
152 
153  //MYECMDIR
154  //case 'MYECMDIR_CREATE':
155  //case 'MYECMDIR_MODIFY':
156  //case 'MYECMDIR_DELETE':
157 
158  // Sales orders
159  //case 'ORDER_CREATE':
160  //case 'ORDER_MODIFY':
161  //case 'ORDER_VALIDATE':
162  //case 'ORDER_DELETE':
163  //case 'ORDER_CANCEL':
164  //case 'ORDER_SENTBYMAIL':
165  //case 'ORDER_CLASSIFY_BILLED':
166  //case 'ORDER_SETDRAFT':
167  //case 'LINEORDER_INSERT':
168  //case 'LINEORDER_UPDATE':
169  //case 'LINEORDER_DELETE':
170 
171  // Supplier orders
172  //case 'ORDER_SUPPLIER_CREATE':
173  //case 'ORDER_SUPPLIER_MODIFY':
174  //case 'ORDER_SUPPLIER_VALIDATE':
175  //case 'ORDER_SUPPLIER_DELETE':
176  //case 'ORDER_SUPPLIER_APPROVE':
177  //case 'ORDER_SUPPLIER_REFUSE':
178  //case 'ORDER_SUPPLIER_CANCEL':
179  //case 'ORDER_SUPPLIER_SENTBYMAIL':
180  //case 'ORDER_SUPPLIER_RECEIVE':
181  //case 'LINEORDER_SUPPLIER_DISPATCH':
182  //case 'LINEORDER_SUPPLIER_CREATE':
183  //case 'LINEORDER_SUPPLIER_UPDATE':
184  //case 'LINEORDER_SUPPLIER_DELETE':
185 
186  // Proposals
187  //case 'PROPAL_CREATE':
188  //case 'PROPAL_MODIFY':
189  //case 'PROPAL_VALIDATE':
190  //case 'PROPAL_SENTBYMAIL':
191  //case 'PROPAL_CLOSE_SIGNED':
192  //case 'PROPAL_CLOSE_REFUSED':
193  //case 'PROPAL_DELETE':
194  //case 'LINEPROPAL_INSERT':
195  //case 'LINEPROPAL_UPDATE':
196  //case 'LINEPROPAL_DELETE':
197 
198  // SupplierProposal
199  //case 'SUPPLIER_PROPOSAL_CREATE':
200  //case 'SUPPLIER_PROPOSAL_MODIFY':
201  //case 'SUPPLIER_PROPOSAL_VALIDATE':
202  //case 'SUPPLIER_PROPOSAL_SENTBYMAIL':
203  //case 'SUPPLIER_PROPOSAL_CLOSE_SIGNED':
204  //case 'SUPPLIER_PROPOSAL_CLOSE_REFUSED':
205  //case 'SUPPLIER_PROPOSAL_DELETE':
206  //case 'LINESUPPLIER_PROPOSAL_INSERT':
207  //case 'LINESUPPLIER_PROPOSAL_UPDATE':
208  //case 'LINESUPPLIER_PROPOSAL_DELETE':
209 
210  // Contracts
211  //case 'CONTRACT_CREATE':
212  //case 'CONTRACT_MODIFY':
213  //case 'CONTRACT_ACTIVATE':
214  //case 'CONTRACT_CANCEL':
215  //case 'CONTRACT_CLOSE':
216  //case 'CONTRACT_DELETE':
217  //case 'LINECONTRACT_INSERT':
218  //case 'LINECONTRACT_UPDATE':
219  //case 'LINECONTRACT_DELETE':
220 
221  // Bills
222  //case 'BILL_CREATE':
223  //case 'BILL_MODIFY':
224  //case 'BILL_VALIDATE':
225  //case 'BILL_UNVALIDATE':
226  //case 'BILL_SENTBYMAIL':
227  //case 'BILL_CANCEL':
228  //case 'BILL_DELETE':
229  //case 'BILL_PAYED':
230  //case 'LINEBILL_INSERT':
231  //case 'LINEBILL_UPDATE':
232  //case 'LINEBILL_DELETE':
233 
234  //Supplier Bill
235  //case 'BILL_SUPPLIER_CREATE':
236  //case 'BILL_SUPPLIER_UPDATE':
237  //case 'BILL_SUPPLIER_DELETE':
238  //case 'BILL_SUPPLIER_PAYED':
239  //case 'BILL_SUPPLIER_UNPAYED':
240  //case 'BILL_SUPPLIER_VALIDATE':
241  //case 'BILL_SUPPLIER_UNVALIDATE':
242  //case 'LINEBILL_SUPPLIER_CREATE':
243  //case 'LINEBILL_SUPPLIER_UPDATE':
244  //case 'LINEBILL_SUPPLIER_DELETE':
245 
246  // Payments
247  //case 'PAYMENT_CUSTOMER_CREATE':
248  //case 'PAYMENT_SUPPLIER_CREATE':
249  //case 'PAYMENT_ADD_TO_BANK':
250  //case 'PAYMENT_DELETE':
251 
252  // Online
253  //case 'PAYMENT_PAYBOX_OK':
254  //case 'PAYMENT_PAYPAL_OK':
255  //case 'PAYMENT_STRIPE_OK':
256 
257  // Donation
258  //case 'DON_CREATE':
259  //case 'DON_UPDATE':
260  //case 'DON_DELETE':
261 
262  // Interventions
263  //case 'FICHINTER_CREATE':
264  //case 'FICHINTER_MODIFY':
265  //case 'FICHINTER_VALIDATE':
266  //case 'FICHINTER_DELETE':
267  //case 'LINEFICHINTER_CREATE':
268  //case 'LINEFICHINTER_UPDATE':
269  //case 'LINEFICHINTER_DELETE':
270 
271  // Members
272  //case 'MEMBER_CREATE':
273  //case 'MEMBER_VALIDATE':
274  //case 'MEMBER_SUBSCRIPTION':
275  //case 'MEMBER_MODIFY':
276  //case 'MEMBER_NEW_PASSWORD':
277  //case 'MEMBER_RESILIATE':
278  //case 'MEMBER_DELETE':
279 
280  // Categories
281  //case 'CATEGORY_CREATE':
282  //case 'CATEGORY_MODIFY':
283  //case 'CATEGORY_DELETE':
284  //case 'CATEGORY_SET_MULTILANGS':
285 
286  // Projects
287  //case 'PROJECT_CREATE':
288  //case 'PROJECT_MODIFY':
289  //case 'PROJECT_DELETE':
290 
291  // Project tasks
292  //case 'TASK_CREATE':
293  //case 'TASK_MODIFY':
294  //case 'TASK_DELETE':
295 
296  // Task time spent
297  //case 'TASK_TIMESPENT_CREATE':
298  //case 'TASK_TIMESPENT_MODIFY':
299  //case 'TASK_TIMESPENT_DELETE':
300  //case 'PROJECT_ADD_CONTACT':
301  //case 'PROJECT_DELETE_CONTACT':
302  //case 'PROJECT_DELETE_RESOURCE':
303 
304  // Shipping
305  //case 'SHIPPING_CREATE':
306  //case 'SHIPPING_MODIFY':
307  //case 'SHIPPING_VALIDATE':
308  //case 'SHIPPING_SENTBYMAIL':
309  //case 'SHIPPING_BILLED':
310  //case 'SHIPPING_CLOSED':
311  //case 'SHIPPING_REOPEN':
312  //case 'SHIPPING_DELETE':
313 
314  // and more...
315 
316  default:
317  dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id);
318  break;
319  }
320 
321  return 0;
322  }
323 }
db
$conf db
API class for accounts.
Definition: inc.php:41
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
InterfaceMyModuleTriggers\__construct
__construct($db)
Constructor.
Definition: interface_99_modMyModule_MyModuleTriggers.class.php:46
Translate
Class to manage translations.
Definition: translate.class.php:30
name
$conf db name
Definition: repair.php:122
Conf
Class to stock current configuration.
Definition: conf.class.php:33
InterfaceMyModuleTriggers\getDesc
getDesc()
Trigger description.
Definition: interface_99_modMyModule_MyModuleTriggers.class.php:73
InterfaceMyModuleTriggers
Class of triggers for MyModule module.
Definition: interface_99_modMyModule_MyModuleTriggers.class.php:39
InterfaceMyModuleTriggers\runTrigger
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr business event is done.
Definition: interface_99_modMyModule_MyModuleTriggers.class.php:91
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
User
Class to manage Dolibarr users.
Definition: user.class.php:46
DolibarrTriggers
Class that all the triggers must extend.
Definition: dolibarrtriggers.class.php:21
InterfaceMyModuleTriggers\getName
getName()
Trigger name.
Definition: interface_99_modMyModule_MyModuleTriggers.class.php:63