dolibarr 21.0.0-beta
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This file is an example to follow to add your own email selector inside
9 * the Dolibarr email tool.
10 * Follow instructions given in README file to know what to change to build
11 * your own emailing list selector.
12 * Code that need to be changed in this file are marked by "CHANGE THIS" tag.
13 */
14
22// Load Dolibarr Environment
23include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
24
25
30{
31 // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
32 public $name = 'AttendeesOfOrganizedEvent';
33 public $desc = "Attendees of an organized event";
34
38 public $require_admin = 0;
39
43 public $require_module = array();
44
48 public $picto = 'conferenceorbooth';
49
53 public $enabled = 'isModEnabled("eventorganization")';
54
55
61 public function __construct($db)
62 {
63 global $conf, $langs;
64 $langs->load('companies');
65
66 $this->db = $db;
67 }
68
69
70 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
77 public function add_to_target($mailing_id)
78 {
79 // phpcs:enable
80 global $conf, $langs;
81
82 $cibles = array();
83 $addDescription = '';
84
85 $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,";
86 $sql .= " 'eventorganizationattendee' as source";
87 $sql .= " FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee as e,";
88 $sql .= " ".MAIN_DB_PREFIX."projet as p";
89 $sql .= " WHERE e.email <> ''";
90 $sql .= " AND e.fk_project = p.rowid";
91 $sql .= " AND p.entity IN (".getEntity('project').")";
92 $sql .= " AND e.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";
93 if (GETPOSTINT('filter_eventorganization') > 0) {
94 $sql .= " AND e.fk_project = ".(GETPOSTINT('filter_eventorganization'));
95 }
96 if (empty($this->evenunsubscribe)) {
97 $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).")";
98 }
99 $sql .= " ORDER BY e.email";
100
101 // Stock recipients emails into targets table
102 $result = $this->db->query($sql);
103 if ($result) {
104 $num = $this->db->num_rows($result);
105 $i = 0;
106 $j = 0;
107
108 dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
109
110 $old = '';
111 while ($i < $num) {
112 $obj = $this->db->fetch_object($result);
113 if ($old != $obj->email) {
114 $otherTxt = ($obj->ref ? $langs->transnoentities("Project").'='.$obj->ref : '');
115 if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
116 $otherTxt .= ";";
117 }
118 $otherTxt .= $addDescription;
119 $cibles[$j] = array(
120 'email' => $obj->email,
121 'fk_project' => (int) $obj->fk_project,
122 'lastname' => $obj->lastname,
123 'firstname' => $obj->firstname,
124 'other' => $otherTxt,
125 'source_url' => $this->url($obj->id, $obj->source),
126 'source_id' => (int) $obj->id,
127 'source_type' => $obj->source
128 );
129 $old = $obj->email;
130 $j++;
131 }
132
133 $i++;
134 }
135 } else {
136 dol_syslog($this->db->error());
137 $this->error = $this->db->error();
138 return -1;
139 }
140
141 return parent::addTargetsToDatabase($mailing_id, $cibles);
142 }
143
144
153 public function getSqlArrayForStats()
154 {
155 // CHANGE THIS: Optional
156
157 //var $statssql=array();
158 //$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL";
159 return array();
160 }
161
162
171 public function getNbOfRecipients($sql = '')
172 {
173 global $conf;
174
175 $sql = "SELECT COUNT(DISTINCT(e.email)) as nb";
176 $sql .= " FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee as e, ";
177 $sql .= " ".MAIN_DB_PREFIX."projet as p";
178 $sql .= " WHERE e.email <> ''";
179 $sql .= " AND e.fk_project = p.rowid";
180 $sql .= " AND p.entity IN (".getEntity('project').")";
181 if (empty($this->evenunsubscribe)) {
182 $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).")";
183 }
184
185 //print $sql;
186
187 // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
188 return parent::getNbOfRecipients($sql);
189 }
190
197 public function formFilter()
198 {
199 global $conf, $langs;
200
201 $langs->load("companies");
202
203 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
204 $formproject = new FormProjets($this->db);
205
206 $s = img_picto($langs->trans("OrganizedEvent"), 'project', 'class="pictofixedwidth"');
207 $s .= $formproject->select_projects(-1, 0, "filter_eventorganization", 0, 0, $langs->trans("OrganizedEvent"), 1, 0, 0, 0, '', 1, 0, '', '', 'usage_organize_event=1');
208
209 return $s;
210 }
211
212
220 public function url($id, $sourcetype = 'thirdparty')
221 {
222 if ($sourcetype == 'project') {
223 return '<a href="'.DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_card.php?id='.((int) $id).'">'.img_object('', "eventorganization").'</a>';
224 }
225
226 return '';
227 }
228}
$id
Definition account.php:48
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=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79