dolibarr 18.0.6
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 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
30
35{
41 public function __construct($db)
42 {
43 $this->db = $db;
44
45 $this->name = preg_replace('/^Interface/i', '', get_class($this));
46 $this->family = "agenda";
47 $this->description = "Triggers of this module auto link contact to company.";
48 // 'development', 'experimental', 'dolibarr' or version
49 $this->version = self::VERSION_DOLIBARR;
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}
Class to stock current configuration.
Class to manage contact/addresses.
Class that all the triggers must extend.
Class of triggered functions for agenda module.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr 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:123