dolibarr  16.0.5
example.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This file is an example to follow to add your own email selector inside
5  * the Dolibarr email tool.
6  * Follow instructions given in README file to know what to change to build
7  * your own emailing list selector.
8  * Code that need to be changed in this file are marked by "CHANGE THIS" tag.
9  */
10 
17 include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
18 
19 
20 // CHANGE THIS: Class name must be called mailing_xxx with xxx=name of your selector
21 
27 {
28  // CHANGE THIS: Put here a name not already used
29  public $name = 'example';
30  // CHANGE THIS: Put here a description of your selector module.
31  // This label is used if no translation is found for key MailingModuleDescXXX where XXX=name is found
32  public $desc = 'Put here a description';
33  // CHANGE THIS: Set to 1 if selector is available for admin users only
34  public $require_admin = 0;
35  // CHANGE THIS: Add a tooltip language key to add a tooltip help icon after the email target selector
36  public $tooltip = 'MyTooltipLangKey';
37 
38  public $require_module = array();
39 
43  public $picto = '';
44 
48  public $db;
49 
50 
51  // CHANGE THIS: Constructor name must be called mailing_xxx with xxx=name of your selector
57  public function __construct($db)
58  {
59  $this->db = $db;
60  }
61 
62 
63  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
70  public function add_to_target($mailing_id)
71  {
72  // phpcs:enable
73  $target = array();
74 
75  // CHANGE THIS
76  // ----- Your code start here -----
77 
78  // You must fill the $target array with record like this
79  // $target[0]=array('email'=>'email_0','name'=>'name_0','firstname'=>'firstname_0', 'other'=>'other_0');
80  // ...
81  // $target[n]=array('email'=>'email_n','name'=>'name_n','firstname'=>'firstname_n', 'other'=>'other_n');
82 
83  // Example: $target[0]=array('email'=>'myemail@example.com', 'name'=>'Doe', 'firstname'=>'John', 'other'=>'Other information');
84 
85  // ----- Your code end here -----
86 
87  return parent::addTargetsToDatabase($mailing_id, $target);
88  }
89 
90 
99  public function getSqlArrayForStats()
100  {
101  // CHANGE THIS: Optionnal
102 
103  //var $statssql=array();
104  //$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL";
105  return array();
106  }
107 
108 
117  public function getNbOfRecipients($sql = '')
118  {
119  // CHANGE THIS: Optionnal
120 
121  // Example: return parent::getNbOfRecipients("SELECT count(*) as nb from dolibarr_table");
122  // Example: return 500;
123  return '?';
124  }
125 
132  public function formFilter()
133  {
134  // CHANGE THIS: Optionnal
135 
136  $s = '';
137  return $s;
138  }
139 
140 
148  public function url($id)
149  {
150  // CHANGE THIS: Optionnal
151 
152  return '';
153  }
154 }
db
$conf db
API class for accounts.
Definition: inc.php:41
mailing_example\url
url($id)
Can include an URL link on each record provided by selector shown on target page.
Definition: example.modules.php:148
MailingTargets
Parent class of emailing target selectors modules.
Definition: modules_mailings.php:32
mailing_example\getNbOfRecipients
getNbOfRecipients($sql='')
Return here number of distinct emails returned by your selector.
Definition: example.modules.php:117
mailing_example\formFilter
formFilter()
This is to add a form filter to provide variant of selector If used, the HTML select must be called "...
Definition: example.modules.php:132
mailing_example
Class to manage a list of personalised recipients for mailing feature.
Definition: example.modules.php:26
mailing_example\add_to_target
add_to_target($mailing_id)
This is the main function that returns the array of emails.
Definition: example.modules.php:70
mailing_example\getSqlArrayForStats
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
Definition: example.modules.php:99
mailing_example\__construct
__construct($db)
Constructor.
Definition: example.modules.php:57