dolibarr 24.0.0-beta
dolibarrtriggers.class.php
1<?php
2/* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
3 * Copyright (C) 2023-2024 William Mead <william.mead@manchenumerique.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
24abstract class DolibarrTriggers
25{
30 protected $db;
31
36 public $name;
37
42 public $description;
43
48 public $version;
49
54 public $picto;
55
60 public $family;
61
68 public $error;
69
74 public $errors;
75
80 public $warnings;
81
87 const VERSION_DEVELOPMENT = 'development';
88
94 const VERSION_EXPERIMENTAL = 'experimental';
95
101 const VERSION_DOLIBARR = 'dolibarr';
102
106 const VERSIONS = [
107 'dev' => 'development',
108 'exp' => 'experimental',
109 'prod' => 'dolibarr'
110 ];
111
117 public function __construct(DoliDB $db)
118 {
119 $this->db = $db;
120 $this->name = preg_replace('/^Interface/i', '', get_class($this));
121 $this->description = '';
122 $this->version = self::VERSIONS['dev'];
123 $this->picto = 'technic';
124 $this->family = '';
125 $this->error = '';
126 $this->errors = [];
127 }
128
134 public function getName()
135 {
136 return $this->name;
137 }
138
144 public function getDesc()
145 {
146 return $this->description;
147 }
148
154 public function getVersion()
155 {
156 global $langs;
157 $langs->load("admin");
158 switch ($this->version) { // TODO use a match expression @ Dolibarr minimum PHP v8.0
159 case self::VERSIONS['dev']:
160 return $langs->trans("VersionDevelopment");
161 case self::VERSIONS['exp']:
162 return $langs->trans("VersionExperimental");
163 case self::VERSIONS['prod']:
164 return DOL_VERSION;
165 default:
166 return $this->version;
167 }
168 }
169
177 {
178 if (!empty($object->error)) {
179 if (is_array($this->errors)) {
180 $this->errors = array_merge($this->errors, array($object->error));
181 } else {
182 $this->errors = array($object->error);
183 }
184 }
185 if (!empty($object->errors)) {
186 if (is_array($this->errors)) {
187 $this->errors = array_merge($this->errors, $object->errors);
188 } else {
189 $this->errors = $object->errors;
190 }
191 }
192 }
193
205 abstract public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf);
206}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to stock current configuration.
Class to manage Dolibarr database access.
Class that all triggers must inherit.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarr business event is done.
getName()
Returns the name of the trigger file.
getDesc()
Returns the description of trigger file.
__construct(DoliDB $db)
Constructor.
setErrorsFromObject($object)
setErrorsFromObject
getVersion()
Returns the version of the trigger file.
Class to manage translations.
Class to manage Dolibarr users.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133