interface_50_modEventOrganization_EventOrganization.class.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. /**
  19. * \file htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php
  20. * \ingroup eventorganization
  21. * \brief Trigger file for Event Organization module
  22. */
  23. require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
  24. /**
  25. * Class of triggered functions for agenda module
  26. */
  27. class InterfaceEventOrganization extends DolibarrTriggers
  28. {
  29. /**
  30. * Constructor
  31. *
  32. * @param DoliDB $db Database handler
  33. */
  34. public function __construct($db)
  35. {
  36. $this->db = $db;
  37. $this->name = preg_replace('/^Interface/i', '', get_class($this));
  38. $this->family = "eventorganization";
  39. $this->description = "Triggers of this module to manage event organization triggers action";
  40. // 'development', 'experimental', 'dolibarr' or version
  41. $this->version = self::VERSION_DOLIBARR;
  42. $this->picto = 'action';
  43. }
  44. /**
  45. * Function called when a Dolibarrr business event is done.
  46. * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
  47. *
  48. * Following properties may be set before calling trigger. The may be completed by this trigger to be used for writing the event into database:
  49. * $object->actiontypecode (translation action code: AC_OTH, ...)
  50. * $object->actionmsg (note, long text)
  51. * $object->actionmsg2 (label, short text)
  52. * $object->sendtoid (id of contact or array of ids of contacts)
  53. * $object->socid (id of thirdparty)
  54. * $object->fk_project
  55. * $object->fk_element (ID of object to link action event to)
  56. * $object->elementtype (->element of object to link action to)
  57. * $object->module (if defined, elementtype in llx_actioncomm will be elementtype@module)
  58. *
  59. * @param string $action Event action code ('CONTRACT_MODIFY', 'RECRUITMENTCANDIDATURE_MODIFIY', ...)
  60. * @param Object $object Object
  61. * @param User $user Object user
  62. * @param Translate $langs Object langs
  63. * @param conf $conf Object conf
  64. * @return int <0 if KO, 0 if no triggered ran, >0 if OK
  65. */
  66. public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
  67. {
  68. if (empty($conf->eventorganization) || empty($conf->eventorganization->enabled)) {
  69. return 0; // Module not active, we do nothing
  70. }
  71. $error=0;
  72. // Actions
  73. if ($action == 'PROJECT_VALIDATE') {
  74. if (!empty($conf->global->EVENTORGANIZATION_TASK_LABEL) && !empty($object->usage_organize_event)) {
  75. $taskToDo = explode("\n", $conf->global->EVENTORGANIZATION_TASK_LABEL);
  76. if (is_array($taskToDo) && count($taskToDo)>0) {
  77. // Load translation files required by the page
  78. $langs->loadLangs(array("eventorganization"));
  79. $this->db->begin();
  80. foreach ($taskToDo as $taskLabel) {
  81. $task = new Task($this->db);
  82. $task->label = $taskLabel;
  83. $task->fk_project = $object->id;
  84. $defaultref = '';
  85. $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
  86. if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . $conf->global->PROJECT_TASK_ADDON . ".php")) {
  87. require_once DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . $conf->global->PROJECT_TASK_ADDON . '.php';
  88. $modTask = new $obj;
  89. $defaultref = $modTask->getNextValue($object->thirdparty, null);
  90. }
  91. if (is_numeric($defaultref) && $defaultref <= 0) {
  92. $defaultref = '';
  93. }
  94. $task->ref = $defaultref;
  95. // TODO Can set offset for start date or endline from setup of task to create when creating event
  96. $task->date_start = null;
  97. $task->date_end = null;
  98. $result = $task->create($user);
  99. if ($result < 0) {
  100. $this->errors=array_merge($this->errors, $task->errors);
  101. $error++;
  102. }
  103. }
  104. if (empty($error)) {
  105. $this->db->commit();
  106. return 1;
  107. } else {
  108. dol_syslog("InterfaceEventOrganization.class.php: ".implode(',', $this->errors), LOG_ERR);
  109. $this->db->rollback();
  110. return -1;
  111. }
  112. }
  113. }
  114. }
  115. return 0;
  116. }
  117. }