dolibarr 21.0.0-alpha
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 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
23abstract class DolibarrTriggers
24{
29 protected $db;
30
35 public $name;
36
41 public $description;
42
47 public $version;
48
53 public $picto;
54
59 public $family;
60
67 public $error;
68
73 public $errors;
74
80 const VERSION_DEVELOPMENT = 'development';
81
87 const VERSION_EXPERIMENTAL = 'experimental';
88
94 const VERSION_DOLIBARR = 'dolibarr';
95
99 const VERSIONS = [
100 'dev' => 'development',
101 'exp' => 'experimental',
102 'prod' => 'dolibarr'
103 ];
104
110 public function __construct(DoliDB $db)
111 {
112 $this->db = $db;
113 $this->name = preg_replace('/^Interface/i', '', get_class($this));
114 $this->description = '';
115 $this->version = self::VERSIONS['dev'];
116 $this->picto = 'technic';
117 $this->family = '';
118 $this->error = '';
119 $this->errors = [];
120 }
121
127 public function getName()
128 {
129 return $this->name;
130 }
131
137 public function getDesc()
138 {
139 return $this->description;
140 }
141
147 public function getVersion()
148 {
149 global $langs;
150 $langs->load("admin");
151 switch ($this->version) { // TODO use a match expression @ Dolibarr minimum PHP v8.0
152 case self::VERSIONS['dev']:
153 return $langs->trans("VersionDevelopment");
154 case self::VERSIONS['exp']:
155 return $langs->trans("VersionExperimental");
156 case self::VERSIONS['prod']:
157 return DOL_VERSION;
158 default:
159 return $this->version;
160 }
161 }
162
170 {
171 if (!empty($object->error)) {
172 $this->errors = array_merge($this->errors, array($object->error));
173 }
174 if (!empty($object->errors)) {
175 $this->errors = array_merge($this->errors, $object->errors);
176 }
177 }
178
190 abstract public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf);
191}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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.
setErrorsFromObject(CommonObject $object)
setErrorsFromObject
__construct(DoliDB $db)
Constructor.
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.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140