dolibarr  20.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  *
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 
22 abstract class DolibarrTriggers
23 {
28  protected $db;
29 
34  public $name;
35 
40  public $description;
41 
46  public $version;
47 
52  public $picto;
53 
58  public $family;
59 
66  public $error;
67 
72  public $errors;
73 
79  const VERSION_DEVELOPMENT = 'development';
80 
86  const VERSION_EXPERIMENTAL = 'experimental';
87 
93  const VERSION_DOLIBARR = 'dolibarr';
94 
98  const VERSIONS = [
99  'dev' => 'development',
100  'exp' => 'experimental',
101  'prod' => 'dolibarr'
102  ];
103 
109  public function __construct(DoliDB $db)
110  {
111  $this->db = $db;
112  $this->name = preg_replace('/^Interface/i', '', get_class($this));
113  $this->description = '';
114  $this->version = self::VERSIONS['dev'];
115  $this->picto = 'technic';
116  $this->family = '';
117  $this->error = '';
118  $this->errors = [];
119  }
120 
126  public function getName()
127  {
128  return $this->name;
129  }
130 
136  public function getDesc()
137  {
138  return $this->description;
139  }
140 
146  public function getVersion()
147  {
148  global $langs;
149  $langs->load("admin");
150  switch ($this->version) { // TODO use a match expression @ Dolibarr minimum PHP v8.0
151  case self::VERSIONS['dev']:
152  return $langs->trans("VersionDevelopment");
153  case self::VERSIONS['exp']:
154  return $langs->trans("VersionExperimental");
155  case self::VERSIONS['prod']:
156  return DOL_VERSION;
157  default:
158  return $this->version;
159  }
160  }
161 
169  {
170  if (!empty($object->error)) {
171  $this->errors = array_merge($this->errors, array($object->error));
172  }
173  if (!empty($object->errors)) {
174  $this->errors = array_merge($this->errors, $object->errors);
175  }
176  }
177 
189  abstract public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf);
190 }
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.
Definition: conf.class.php:34
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.
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.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:126