dolibarr 21.0.0-alpha
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 *
7 * This file is an example to follow to add your own email selector inside
8 * the Dolibarr email tool.
9 * Follow instructions given in README file to know what to change to build
10 * your own emailing list selector.
11 * Code that need to be changed in this file are marked by "CHANGE THIS" tag.
12 */
13
21// Load Dolibarr Environment
22include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
23
24
29{
30 // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
31 public $name = 'AttendeesOfOrganizedEvent';
32 public $desc = "Attendees of an organized event";
33
34 public $require_admin = 0;
35
36 public $require_module = array(); // This module allows to select by categories must be also enabled if category module is not activated
37
41 public $picto = 'conferenceorbooth';
42
43 public $enabled = 'isModEnabled("eventorganization")';
44
45
51 public function __construct($db)
52 {
53 global $conf, $langs;
54 $langs->load('companies');
55
56 $this->db = $db;
57 }
58
59
60 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
67 public function add_to_target($mailing_id)
68 {
69 // phpcs:enable
70 global $conf, $langs;
71
72 $cibles = array();
73 $addDescription = '';
74
75 $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,";
76 $sql .= " 'eventorganizationattendee' as source";
77 $sql .= " FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee as e,";
78 $sql .= " ".MAIN_DB_PREFIX."projet as p";
79 $sql .= " WHERE e.email <> ''";
80 $sql .= " AND e.fk_project = p.rowid";
81 $sql .= " AND p.entity IN (".getEntity('project').")";
82 $sql .= " AND e.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";
83 if (GETPOSTINT('filter_eventorganization') > 0) {
84 $sql .= " AND e.fk_project = ".(GETPOSTINT('filter_eventorganization'));
85 }
86 if (empty($this->evenunsubscribe)) {
87 $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).")";
88 }
89 $sql .= " ORDER BY e.email";
90
91 // Stock recipients emails into targets table
92 $result = $this->db->query($sql);
93 if ($result) {
94 $num = $this->db->num_rows($result);
95 $i = 0;
96 $j = 0;
97
98 dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
99
100 $old = '';
101 while ($i < $num) {
102 $obj = $this->db->fetch_object($result);
103 if ($old != $obj->email) {
104 $otherTxt = ($obj->ref ? $langs->transnoentities("Project").'='.$obj->ref : '');
105 if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
106 $otherTxt .= ";";
107 }
108 $otherTxt .= $addDescription;
109 $cibles[$j] = array(
110 'email' => $obj->email,
111 'fk_project' => $obj->fk_project,
112 'lastname' => $obj->lastname,
113 'firstname' => $obj->firstname,
114 'other' => $otherTxt,
115 'source_url' => $this->url($obj->id, $obj->source),
116 'source_id' => $obj->id,
117 'source_type' => $obj->source
118 );
119 $old = $obj->email;
120 $j++;
121 }
122
123 $i++;
124 }
125 } else {
126 dol_syslog($this->db->error());
127 $this->error = $this->db->error();
128 return -1;
129 }
130
131 return parent::addTargetsToDatabase($mailing_id, $cibles);
132 }
133
134
143 public function getSqlArrayForStats()
144 {
145 // CHANGE THIS: Optional
146
147 //var $statssql=array();
148 //$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL";
149 return array();
150 }
151
152
161 public function getNbOfRecipients($sql = '')
162 {
163 global $conf;
164
165 $sql = "SELECT COUNT(DISTINCT(e.email)) as nb";
166 $sql .= " FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee as e, ";
167 $sql .= " ".MAIN_DB_PREFIX."projet as p";
168 $sql .= " WHERE e.email <> ''";
169 $sql .= " AND e.fk_project = p.rowid";
170 $sql .= " AND p.entity IN (".getEntity('project').")";
171 if (empty($this->evenunsubscribe)) {
172 $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).")";
173 }
174
175 //print $sql;
176
177 // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
178 return parent::getNbOfRecipients($sql);
179 }
180
187 public function formFilter()
188 {
189 global $conf, $langs;
190
191 $langs->load("companies");
192
193 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
194 $formproject = new FormProjets($this->db);
195
196 $s = img_picto($langs->trans("OrganizedEvent"), 'project', 'class="pictofixedwidth"');
197 $s .= $formproject->select_projects(-1, 0, "filter_eventorganization", 0, 0, $langs->trans("OrganizedEvent"), 1, 0, 0, 0, '', 1, 0, '', '', 'usage_organize_event=1');
198
199 return $s;
200 }
201
202
210 public function url($id, $sourcetype = 'thirdparty')
211 {
212 if ($sourcetype == 'project') {
213 return '<a href="'.DOL_URL_ROOT.'/eventorganization/conferenceorboothattendee_card.php?id='.((int) $id).'">'.img_object('', "eventorganization").'</a>';
214 }
215
216 return '';
217 }
218}
$id
Definition account.php:39
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.