dolibarr  16.0.5
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 <http://www.gnu.org/licenses/>.
22  */
23 
29 require_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  if ($nb > 0) {
111  setEventMessages($langs->trans('ContactAddedAutomatically', $nb), null, 'mesgs');
112  }
113  }
114  }
115  }
116  return 0;
117  }
118 }
db
$conf db
API class for accounts.
Definition: inc.php:41
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
Translate
Class to manage translations.
Definition: translate.class.php:30
name
$conf db name
Definition: repair.php:122
Conf
Class to stock current configuration.
Definition: conf.class.php:33
InterfaceContactRoles\__construct
__construct($db)
Constructor.
Definition: interface_90_modSociete_ContactRoles.class.php:41
InterfaceContactRoles
Class of triggered functions for agenda module.
Definition: interface_90_modSociete_ContactRoles.class.php:34
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
User
Class to manage Dolibarr users.
Definition: user.class.php:44
DolibarrTriggers
Class that all the triggers must extend.
Definition: dolibarrtriggers.class.php:21
InterfaceContactRoles\runTrigger
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr business event is done.
Definition: interface_90_modSociete_ContactRoles.class.php:68
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137