dolibarr 20.0.0
interface_50_modEventOrganization_EventOrganization.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 Florian Henry <florian.henry@scopen.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
26require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
27
28
33{
39 public function __construct($db)
40 {
41 $this->db = $db;
42
43 $this->name = preg_replace('/^Interface/i', '', get_class($this));
44 $this->family = "eventorganization";
45 $this->description = "Triggers of this module to manage event organization triggers action";
46 $this->version = self::VERSIONS['prod'];
47 $this->picto = 'action';
48 }
49
72 public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
73 {
74 if (empty($conf->eventorganization) || empty($conf->eventorganization->enabled)) {
75 return 0; // Module not active, we do nothing
76 }
77
78 $error = 0;
79
80 // Actions
81 if ($action == 'PROJECT_VALIDATE') {
82 if (getDolGlobalString('EVENTORGANIZATION_TASK_LABEL') && !empty($object->usage_organize_event)) {
83 $taskToDo = explode("\n", getDolGlobalString('EVENTORGANIZATION_TASK_LABEL'));
84 if (is_array($taskToDo) && count($taskToDo) > 0) {
85 // Load translation files required by the page
86 $langs->loadLangs(array("eventorganization"));
87
88 $this->db->begin();
89 foreach ($taskToDo as $taskLabel) {
90 $task = new Task($this->db);
91 $task->label = $taskLabel;
92 $task->fk_project = $object->id;
93 $defaultref = '';
94 $obj = !getDolGlobalString('PROJECT_TASK_ADDON') ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
95 if (getDolGlobalString('PROJECT_TASK_ADDON') && is_readable(DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . getDolGlobalString('PROJECT_TASK_ADDON') . ".php")) {
96 require_once DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . getDolGlobalString('PROJECT_TASK_ADDON') . '.php';
97 $modTask = new $obj();
98 $defaultref = $modTask->getNextValue($object->thirdparty, null);
99 }
100 if (is_numeric($defaultref) && $defaultref <= 0) {
101 $defaultref = '';
102 }
103 $task->ref = $defaultref;
104
105 // TODO Can set offset for start date or endline from setup of task to create when creating event
106 $task->date_start = null;
107 $task->date_end = null;
108
109 $result = $task->create($user);
110 if ($result < 0) {
111 $this->errors = array_merge($this->errors, $task->errors);
112 $error++;
113 }
114 }
115
116 if (empty($error)) {
117 $this->db->commit();
118 return 1;
119 } else {
120 dol_syslog("InterfaceEventOrganization.class.php: ".implode(',', $this->errors), LOG_ERR);
121 $this->db->rollback();
122 return -1;
123 }
124 }
125 }
126 }
127 return 0;
128 }
129}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to stock current configuration.
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 tasks.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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:142