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