dolibarr 21.0.0-alpha
interface_90_modSociete_ContactRoles.class.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2013 Cedric GROSS <c.gross@kreiz-it.fr>
7 * Copyright (C) 2014 Marcos GarcĂ­a <marcosgdf@gmail.com>
8 * Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
9 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
30require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
31
36{
42 public function __construct($db)
43 {
44 $this->db = $db;
45
46 $this->name = preg_replace('/^Interface/i', '', get_class($this));
47 $this->family = "agenda";
48 $this->description = "Triggers of this module auto link contact to company.";
49 $this->version = self::VERSIONS['prod'];
50 $this->picto = 'company';
51 }
52
68 public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
69 {
70 if ($action === 'PROPAL_CREATE' || $action === 'ORDER_CREATE' || $action === 'BILL_CREATE'
71 || $action === 'ORDER_SUPPLIER_CREATE' || $action === 'BILL_SUPPLIER_CREATE' || $action === 'PROPOSAL_SUPPLIER_CREATE'
72 || $action === 'CONTRACT_CREATE' || $action === 'FICHINTER_CREATE' || $action === 'PROJECT_CREATE' || $action === 'TICKET_CREATE') {
73 dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id);
74
75 $socid = (property_exists($object, 'socid') ? $object->socid : $object->fk_soc);
76
77 if (!empty($socid) && $socid > 0) {
78 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
79 $contactdefault = new Contact($this->db);
80 $contactdefault->socid = $socid;
81
82 $TContact = array();
83 if (method_exists($contactdefault, 'getContactRoles')) { // For backward compatibility
84 $TContact = $contactdefault->getContactRoles($object->element);
85 }
86
87 if (is_array($TContact) && !empty($TContact)) {
88 $TContactAlreadyLinked = array();
89
90 if ($object->id > 0) {
91 $TContactAlreadyLinked = array_merge($object->liste_contact(-1, 'external'), $object->liste_contact(-1, 'internal'));
92 }
93
94 foreach ($TContact as $i => $infos) {
95 foreach ($TContactAlreadyLinked as $contactData) {
96 if ($contactData['id'] == $infos['fk_socpeople'] && $contactData['fk_c_type_contact'] == $infos['type_contact']) {
97 unset($TContact[$i]);
98 }
99 }
100 }
101
102 $nb = 0;
103 foreach ($TContact as $infos) {
104 $res = $object->add_contact($infos['fk_socpeople'], $infos['type_contact']);
105 if ($res > 0) {
106 $nb++;
107 }
108 }
109
110 // We disable this message, it shows the message in api, public page or batch actions when it should not.
111 // Message setting must be done by the calling GUI page and not set inside the trigger.
112 /*
113 if ($nb > 0) {
114 setEventMessages($langs->trans('ContactAddedAutomatically', $nb), null, 'mesgs');
115 }
116 */
117 }
118 }
119 }
120 return 0;
121 }
122}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to stock current configuration.
Class to manage contact/addresses.
Class that all triggers must inherit.
Class of triggered functions for agenda module.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarr business event is done.
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.
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