dolibarr  19.0.0-dev
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  *
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 
25 require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
26 
27 
32 {
38  public function __construct($db)
39  {
40  $this->db = $db;
41 
42  $this->name = preg_replace('/^Interface/i', '', get_class($this));
43  $this->family = "eventorganization";
44  $this->description = "Triggers of this module to manage event organization triggers action";
45  // 'development', 'experimental', 'dolibarr' or version
46  $this->version = self::VERSION_DOLIBARR;
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 (!empty($conf->global->EVENTORGANIZATION_TASK_LABEL) && !empty($object->usage_organize_event)) {
83  $taskToDo = explode("\n", $conf->global->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 = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
95  if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . $conf->global->PROJECT_TASK_ADDON . ".php")) {
96  require_once DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . $conf->global->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 }
Class to stock current configuration.
Definition: conf.class.php:34
Class that all the triggers must extend.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr business event is done.
Class to manage tasks.
Definition: task.class.php:40
Class to manage translations.
Class to manage Dolibarr users.
Definition: user.class.php:48
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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:123