dolibarr  18.0.6
eventorganization.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2018-2018 Andre Schild <a.schild@aarboard.ch>
3  * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  *
6  * This file is an example to follow to add your own email selector inside
7  * the Dolibarr email tool.
8  * Follow instructions given in README file to know what to change to build
9  * your own emailing list selector.
10  * Code that need to be changed in this file are marked by "CHANGE THIS" tag.
11  */
12 
20 // Load Dolibarr Environment
21 include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
22 
23 
28 {
29  // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
30  public $name = 'AttendeesOfOrganizedEvent';
31  public $desc = "Attendees of an organized event";
32 
33  public $require_admin = 0;
34 
35  public $require_module = array(); // This module allows to select by categories must be also enabled if category module is not activated
36 
40  public $picto = 'conferenceorbooth';
41 
45  public $db;
46 
47  public $enabled = 'isModEnabled("eventorganization")';
48 
49 
55  public function __construct($db)
56  {
57  global $conf, $langs;
58  $langs->load('companies');
59 
60  $this->db = $db;
61  }
62 
63 
64  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
71  public function add_to_target($mailing_id)
72  {
73  // phpcs:enable
74  global $conf, $langs;
75 
76  $cibles = array();
77  $addDescription = '';
78 
79  $sql = "SELECT p.ref, p.entity, e.rowid as id, e.fk_project, e.email as email, e.email_company as company_name, e.firstname as firstname, e.lastname as lastname,";
80  $sql .= " 'eventorganizationattendee' as source";
81  $sql .= " FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee as e,";
82  $sql .= " ".MAIN_DB_PREFIX."projet as p";
83  $sql .= " WHERE e.email <> ''";
84  $sql .= " AND e.fk_project = p.rowid";
85  $sql .= " AND p.entity IN (".getEntity('project').")";
86  $sql .= " AND e.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";
87  if (GETPOST('filter_eventorganization', 'int') > 0) {
88  $sql .= " AND e.fk_project = ".((int) GETPOST('filter_eventorganization', 'int'));
89  }
90  if (empty($this->evenunsubscribe)) {
91  $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = e.email and mu.entity = ".((int) $conf->entity).")";
92  }
93  $sql .= " ORDER BY e.email";
94 
95  // Stock recipients emails into targets table
96  $result = $this->db->query($sql);
97  if ($result) {
98  $num = $this->db->num_rows($result);
99  $i = 0;
100  $j = 0;
101 
102  dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
103 
104  $old = '';
105  while ($i < $num) {
106  $obj = $this->db->fetch_object($result);
107  if ($old <> $obj->email) {
108  $otherTxt = ($obj->ref ? $langs->transnoentities("Project").'='.$obj->ref : '');
109  if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
110  $otherTxt .= ";";
111  }
112  $otherTxt .= $addDescription;
113  $cibles[$j] = array(
114  'email' => $obj->email,
115  'fk_project' => $obj->fk_project,
116  'lastname' => $obj->lastname,
117  'firstname' => $obj->firstname,
118  'other' => $otherTxt,
119  'source_url' => $this->url($obj->id, $obj->source),
120  'source_id' => $obj->id,
121  'source_type' => $obj->source
122  );
123  $old = $obj->email;
124  $j++;
125  }
126 
127  $i++;
128  }
129  } else {
130  dol_syslog($this->db->error());
131  $this->error = $this->db->error();
132  return -1;
133  }
134 
135  return parent::addTargetsToDatabase($mailing_id, $cibles);
136  }
137 
138 
147  public function getSqlArrayForStats()
148  {
149  // CHANGE THIS: Optionnal
150 
151  //var $statssql=array();
152  //$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL";
153  return array();
154  }
155 
156 
165  public function getNbOfRecipients($sql = '')
166  {
167  $sql = "SELECT COUNT(DISTINCT(e.email)) as nb";
168  $sql .= " FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee as e, ";
169  $sql .= " ".MAIN_DB_PREFIX."projet as p";
170  $sql .= " WHERE e.email <> ''";
171  $sql .= " AND e.fk_project = p.rowid";
172  $sql .= " AND p.entity IN (".getEntity('project').")";
173  if (empty($this->evenunsubscribe)) {
174  $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = e.email and mu.entity = ".((int) $conf->entity).")";
175  }
176 
177  //print $sql;
178 
179  // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
180  return parent::getNbOfRecipients($sql);
181  }
182 
189  public function formFilter()
190  {
191  global $conf, $langs;
192 
193  $langs->load("companies");
194 
195  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
196  $formproject = new FormProjets($this->db);
197 
198  $s = img_picto($langs->trans("OrganizedEvent"), 'project', 'class="pictofixedwidth"');
199  $s .= $formproject->select_projects(-1, 0, "filter_eventorganization", 0, 0, $langs->trans("OrganizedEvent"), 1, 0, 0, 0, '', 1, 0, '', '', 'usage_organize_event=1');
200 
201  return $s;
202  }
203 
204 
212  public function url($id, $sourcetype = 'thirdparty')
213  {
214  if ($sourcetype == 'project') {
215  return '<a href="'.DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_card.php?id='.((int) $id).'">'.img_object('', "eventorganization").'</a>';
216  }
217 
218  return '';
219  }
220 }
Class to manage building of HTML components.
Parent class of emailing target selectors modules.
Class to manage a list of personalised recipients for mailing feature.
add_to_target($mailing_id)
This is the main function that returns the array of emails.
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
getNbOfRecipients($sql='')
Return here number of distinct emails returned by your selector.
formFilter()
This is to add a form filter to provide variant of selector If used, the HTML select must be called "...
url($id, $sourcetype='thirdparty')
Can include an URL link on each record provided by selector shown on target page.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.