Uniformize code and doxygen

This commit is contained in:
Laurent Destailleur 2011-11-13 11:45:25 +01:00
parent 40a4bcec04
commit b81938fe95
11 changed files with 297 additions and 222 deletions

View File

@ -42,12 +42,25 @@ class mailing_contacts1 extends MailingTargets
var $db; var $db;
function mailing_contacts1($DB) /**
* Constructor
*
* @param DoliDB $db Database handler
*/
function mailing_contacts1($db)
{ {
$this->db=$DB; $this->db=$db;
} }
/**
* On the main mailing area, there is a box with statistics.
* If you want to add a line in this report you must provide an
* array of SQL request that returns two field:
* One called "label", One called "nb".
*
* @return array Array with SQL requests
*/
function getSqlArrayForStats() function getSqlArrayForStats()
{ {
global $conf, $langs; global $conf, $langs;

View File

@ -41,9 +41,14 @@ class mailing_contacts2 extends MailingTargets
var $db; var $db;
function mailing_contacts2($DB) /**
* Constructor
*
* @param DoliDB $db Database handler
*/
function mailing_contacts2($db)
{ {
$this->db=$DB; $this->db=$db;
} }
@ -109,11 +114,12 @@ class mailing_contacts2 extends MailingTargets
/** /**
* On the main mailing area, there is a box with statistics. * On the main mailing area, there is a box with statistics.
* If you want to add a line in this report you must provide an * If you want to add a line in this report you must provide an
* array of SQL request that returns two field: * array of SQL request that returns two field:
* One called "label", One called "nb". * One called "label", One called "nb".
* @return array *
* @return array Array with SQL requests
*/ */
function getSqlArrayForStats() function getSqlArrayForStats()
{ {

View File

@ -41,12 +41,16 @@ class mailing_contacts3 extends MailingTargets
var $db; var $db;
function mailing_contacts3($DB) /**
* Constructor
*
* @param DoliDB $db Database handler
*/
function mailing_contacts3($db)
{ {
$this->db=$DB; $this->db=$db;
} }
/** /**
* \brief Renvoie url lien vers fiche de la source du destinataire du mailing * \brief Renvoie url lien vers fiche de la source du destinataire du mailing
* \return string Url lien * \return string Url lien
@ -114,13 +118,14 @@ class mailing_contacts3 extends MailingTargets
/** /**
* On the main mailing area, there is a box with statistics. * On the main mailing area, there is a box with statistics.
* If you want to add a line in this report you must provide an * If you want to add a line in this report you must provide an
* array of SQL request that returns two field: * array of SQL request that returns two field:
* One called "label", One called "nb". * One called "label", One called "nb".
* @return array *
* @return array Array with SQL requests
*/ */
function getSqlArrayForStats() function getSqlArrayForStats()
{ {
global $conf, $langs; global $conf, $langs;

View File

@ -51,10 +51,11 @@ class mailing_example extends MailingTargets
/** /**
* \brief This is the main function that returns the array of emails * This is the main function that returns the array of emails
* \param mailing_id Id of mailing. No need to use it. *
* \param filterarray If you used the formFilter function. Empty otherwise. * @param mailing_id Id of mailing. No need to use it.
* \return int <0 if error, number of emails added if ok * @param filterarray If you used the formFilter function. Empty otherwise.
* @return int <0 if error, number of emails added if ok
*/ */
function add_to_target($mailing_id,$filtersarray=array()) function add_to_target($mailing_id,$filtersarray=array())
{ {
@ -77,11 +78,12 @@ class mailing_example extends MailingTargets
/** /**
* \brief On the main mailing area, there is a box with statistics. * On the main mailing area, there is a box with statistics.
* If you want to add a line in this report you must provide an * If you want to add a line in this report you must provide an
* array of SQL request that returns two field: * array of SQL request that returns two field:
* One called "label", One called "nb". * One called "label", One called "nb".
* \return array *
* @return array Array with SQL requests
*/ */
function getSqlArrayForStats() function getSqlArrayForStats()
{ {
@ -93,11 +95,12 @@ class mailing_example extends MailingTargets
} }
/* /**
* \brief Return here number of distinct emails returned by your selector. * Return here number of distinct emails returned by your selector.
* For example if this selector is used to extract 500 different * For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500. * emails from a text file, this function must return 500.
* \return int *
* @return int
*/ */
function getNbOfRecipients() function getNbOfRecipients()
{ {
@ -109,9 +112,10 @@ class mailing_example extends MailingTargets
} }
/** /**
* \brief This is to add a form filter to provide variant of selector * This is to add a form filter to provide variant of selector
* If used, the HTML select must be called "filter" * If used, the HTML select must be called "filter"
* \return string A html select zone *
* @return string A html select zone
*/ */
function formFilter() function formFilter()
{ {
@ -123,9 +127,10 @@ class mailing_example extends MailingTargets
/** /**
* \brief Can include an URL link on each record provided by selector * Can include an URL link on each record provided by selector
* shown on target page. * shown on target page.
* \return string Url link *
* @return string Url link
*/ */
function url($id) function url($id)
{ {

View File

@ -47,13 +47,26 @@ class mailing_fraise extends MailingTargets
var $db; var $db;
function mailing_fraise($DB) /**
* Constructor
*
* @param DoliDB $db Database handler
*/
function mailing_fraise($db)
{ {
$this->db=$DB; $this->db=$db;
} }
function getSqlArrayForStats() /**
* On the main mailing area, there is a box with statistics.
* If you want to add a line in this report you must provide an
* array of SQL request that returns two field:
* One called "label", One called "nb".
*
* @return array Array with SQL requests
*/
function getSqlArrayForStats()
{ {
global $langs; global $langs;

View File

@ -40,11 +40,11 @@ class mailing_framboise extends MailingTargets
/** /**
* Constructor * Constructor
* *
* @param DoliDB $DB Database handler * @param DoliDB $db Database handler
*/ */
function mailing_framboise($DB) function mailing_framboise($db)
{ {
$this->db=$DB; $this->db=$db;
} }
@ -117,12 +117,13 @@ class mailing_framboise extends MailingTargets
} }
/** /**
* \brief On the main mailing area, there is a box with statistics. * On the main mailing area, there is a box with statistics.
* If you want to add a line in this report you must provide an * If you want to add a line in this report you must provide an
* array of SQL request that returns two field: * array of SQL request that returns two field:
* One called "label", One called "nb". * One called "label", One called "nb".
* \return array *
* @return array Array with SQL requests
*/ */
function getSqlArrayForStats() function getSqlArrayForStats()
{ {

View File

@ -39,11 +39,11 @@ class MailingTargets // This can't be abstract as it is used for some method
/** /**
* Constructor * Constructor
* *
* @param DoliDB $DB Database handler * @param DoliDB $db Database handler
*/ */
function MailingTargets($DB) function MailingTargets($db)
{ {
$this->db = $DB; $this->db = $db;
} }
/** /**

View File

@ -40,12 +40,25 @@ class mailing_peche extends MailingTargets
var $db; var $db;
function mailing_peche($DB) /**
* Constructor
*
* @param DoliDB $db Database handler
*/
function mailing_peche($db)
{ {
$this->db=$DB; $this->db=$db;
} }
/**
* On the main mailing area, there is a box with statistics.
* If you want to add a line in this report you must provide an
* array of SQL request that returns two field:
* One called "label", One called "nb".
*
* @return array Array with SQL requests
*/
function getSqlArrayForStats() function getSqlArrayForStats()
{ {
global $langs; global $langs;

View File

@ -40,12 +40,25 @@ class mailing_pomme extends MailingTargets
var $db; var $db;
function mailing_pomme($DB) /**
* Constructor
*
* @param DoliDB $db Database handler
*/
function mailing_pomme($db)
{ {
$this->db=$DB; $this->db=$db;
} }
/**
* On the main mailing area, there is a box with statistics.
* If you want to add a line in this report you must provide an
* array of SQL request that returns two field:
* One called "label", One called "nb".
*
* @return array Array with SQL requests
*/
function getSqlArrayForStats() function getSqlArrayForStats()
{ {
global $conf, $langs; global $conf, $langs;

View File

@ -37,9 +37,14 @@ class mailing_thirdparties extends MailingTargets
var $db; var $db;
function mailing_thirdparties($DB) /**
* Constructor
*
* @param DoliDB $DB Database handler
*/
function mailing_thirdparties($db)
{ {
$this->db=$DB; $this->db=$db;
} }
@ -112,12 +117,13 @@ class mailing_thirdparties extends MailingTargets
} }
/** /**
* \brief On the main mailing area, there is a box with statistics. * On the main mailing area, there is a box with statistics.
* If you want to add a line in this report you must provide an * If you want to add a line in this report you must provide an
* array of SQL request that returns two field: * array of SQL request that returns two field:
* One called "label", One called "nb". * One called "label", One called "nb".
* \return array *
* @return array Array with SQL requests
*/ */
function getSqlArrayForStats() function getSqlArrayForStats()
{ {

View File

@ -1,12 +1,12 @@
<?php <?php
/* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This file is an example to follow to add your own email selector inside * This file is an example to follow to add your own email selector inside
* the Dolibarr email tool. * the Dolibarr email tool.
* Follow instructions given in README file to know what to change to build * Follow instructions given in README file to know what to change to build
* your own emailing list selector. * your own emailing list selector.
* Code that need to be changed in this file are marked by "CHANGE THIS" tag. * Code that need to be changed in this file are marked by "CHANGE THIS" tag.
*/ */
/** /**
* \file htdocs/core/modules/mailings/thirdparties_services_expired.modules.php * \file htdocs/core/modules/mailings/thirdparties_services_expired.modules.php
@ -23,71 +23,70 @@ require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");
*/ */
class mailing_thirdparties_services_expired extends MailingTargets class mailing_thirdparties_services_expired extends MailingTargets
{ {
var $name='DolibarrContractsLinesExpired'; var $name='DolibarrContractsLinesExpired';
var $desc='Third parties with expired contract\'s lines'; var $desc='Third parties with expired contract\'s lines';
var $require_admin=0; var $require_admin=0;
var $require_module=array('contrat'); var $require_module=array('contrat');
var $picto='company'; var $picto='company';
var $db; var $db;
var $arrayofproducts=array(); var $arrayofproducts=array();
/** /**
* Constructor * Constructor
* *
* @param DoliDB $DB Database handler * @param DoliDB $db Database handler
* @return mailing_thirdparties_services_expired */
*/ function mailing_thirdparties_services_expired($db)
function mailing_thirdparties_services_expired($DB) {
{ $this->db=$db;
$this->db=$DB;
$this->arrayofproducts=array(); $this->arrayofproducts=array();
// List of services // List of services
$sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product"; $sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product";
$sql.= " WHERE fk_product_type = 1"; $sql.= " WHERE fk_product_type = 1";
$sql.= " ORDER BY ref"; $sql.= " ORDER BY ref";
$result=$this->db->query($sql); $result=$this->db->query($sql);
if ($result) if ($result)
{ {
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
dol_syslog("dolibarr_services_expired.modules.php:mailing_dolibarr_services_expired ".$num." services found"); dol_syslog("dolibarr_services_expired.modules.php:mailing_dolibarr_services_expired ".$num." services found");
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$i++; $i++;
$this->arrayofproducts[$i]=$obj->ref; $this->arrayofproducts[$i]=$obj->ref;
} }
} }
else else
{ {
dol_print_error($this->db); dol_print_error($this->db);
} }
} }
/** /**
* \brief This is the main function that returns the array of emails * \brief This is the main function that returns the array of emails
* \param mailing_id Id of mailing. No need to use it. * \param mailing_id Id of mailing. No need to use it.
* \param filterarray If you used the formFilter function. Empty otherwise. * \param filterarray If you used the formFilter function. Empty otherwise.
* \return int <0 if error, number of emails added if ok * \return int <0 if error, number of emails added if ok
*/ */
function add_to_target($mailing_id,$filtersarray=array()) function add_to_target($mailing_id,$filtersarray=array())
{ {
$target = array(); $target = array();
// ----- Your code start here ----- // ----- Your code start here -----
$cibles = array(); $cibles = array();
$j = 0; $j = 0;
$product=''; $product='';
foreach($filtersarray as $key) foreach($filtersarray as $key)
{ {
if ($key == '0') return "Error: You must choose a filter"; if ($key == '0') return "Error: You must choose a filter";
$product=$this->arrayofproducts[$key]; $product=$this->arrayofproducts[$key];
@ -95,139 +94,140 @@ class mailing_thirdparties_services_expired extends MailingTargets
$now=dol_now(); $now=dol_now();
// La requete doit retourner: id, email, name // La requete doit retourner: id, email, name
$sql = " select s.rowid as id, s.email, s.nom as name, cd.rowid as cdid, cd.date_ouverture, cd.date_fin_validite, cd.fk_contrat"; $sql = " select s.rowid as id, s.email, s.nom as name, cd.rowid as cdid, cd.date_ouverture, cd.date_fin_validite, cd.fk_contrat";
$sql.= " from ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c,"; $sql.= " from ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c,";
$sql.= " ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p"; $sql.= " ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p";
$sql.= " where s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''"; $sql.= " where s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''";
$sql.= " AND cd.statut= 4 AND cd.fk_product=p.rowid AND p.ref = '".$product."'"; $sql.= " AND cd.statut= 4 AND cd.fk_product=p.rowid AND p.ref = '".$product."'";
$sql.= " AND cd.date_fin_validite < '".$this->db->idate($now)."'"; $sql.= " AND cd.date_fin_validite < '".$this->db->idate($now)."'";
$sql.= " ORDER BY s.email"; $sql.= " ORDER BY s.email";
// Stocke destinataires dans cibles // Stocke destinataires dans cibles
$result=$this->db->query($sql); $result=$this->db->query($sql);
if ($result) if ($result)
{ {
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
$i = 0; $i = 0;
dol_syslog(get_class($this)."::add_to_target ".$num." targets found"); dol_syslog(get_class($this)."::add_to_target ".$num." targets found");
$old = ''; $old = '';
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
if ($old <> $obj->email) if ($old <> $obj->email)
{ {
$cibles[$j] = array( $cibles[$j] = array(
'email' => $obj->email, 'email' => $obj->email,
'name' => $obj->name, 'name' => $obj->name,
'other' => 'other' =>
('StartDate='.dol_print_date($this->db->jdate($obj->date_ouverture),'day')).';'. ('StartDate='.dol_print_date($this->db->jdate($obj->date_ouverture),'day')).';'.
('EndDate='.dol_print_date($this->db->jdate($obj->date_fin_validite),'day')).';'. ('EndDate='.dol_print_date($this->db->jdate($obj->date_fin_validite),'day')).';'.
('Contract='.$obj->fk_contrat).';'. ('Contract='.$obj->fk_contrat).';'.
('ContactLine='.$obj->cdid), ('ContactLine='.$obj->cdid),
'source_url' => $this->url($obj->id), 'source_url' => $this->url($obj->id),
'source_id' => $obj->id, 'source_id' => $obj->id,
'source_type' => 'thirdparty' 'source_type' => 'thirdparty'
); );
$old = $obj->email; $old = $obj->email;
$j++; $j++;
} }
$i++; $i++;
} }
} }
else else
{ {
dol_syslog($this->db->error()); dol_syslog($this->db->error());
$this->error=$this->db->error(); $this->error=$this->db->error();
return -1; return -1;
} }
// ----- Your code end here ----- // ----- Your code end here -----
return parent::add_to_target($mailing_id, $cibles); return parent::add_to_target($mailing_id, $cibles);
} }
/** /**
* \brief On the main mailing area, there is a box with statistics. * On the main mailing area, there is a box with statistics.
* If you want to add a line in this report you must provide an * If you want to add a line in this report you must provide an
* array of SQL request that returns two field: * array of SQL request that returns two field:
* One called "label", One called "nb". * One called "label", One called "nb".
* \return array *
*/ * @return array Array with SQL requests
function getSqlArrayForStats() */
{ function getSqlArrayForStats()
{
//var $statssql=array(); //var $statssql=array();
//$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL"; //$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL";
return array(); return array();
} }
/** /**
* \brief Return here number of distinct emails returned by your selector. * \brief Return here number of distinct emails returned by your selector.
* For example if this selector is used to extract 500 different * For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500. * emails from a text file, this function must return 500.
* \return int * \return int
*/ */
function getNbOfRecipients($filter=1,$option='') function getNbOfRecipients($filter=1,$option='')
{ {
$now=dol_now(); $now=dol_now();
// Example: return parent::getNbOfRecipients("SELECT count(*) as nb from dolibarr_table"); // Example: return parent::getNbOfRecipients("SELECT count(*) as nb from dolibarr_table");
// Example: return 500; // Example: return 500;
$sql = " select count(*) as nb"; $sql = " select count(*) as nb";
$sql.= " from ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c,"; $sql.= " from ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c,";
$sql.= " ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p"; $sql.= " ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p";
$sql.= " where s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''"; $sql.= " where s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''";
$sql.= " AND cd.statut= 4 AND cd.fk_product=p.rowid"; $sql.= " AND cd.statut= 4 AND cd.fk_product=p.rowid";
$sql.= " AND p.ref in ('".join("','",$this->arrayofproducts)."')"; $sql.= " AND p.ref in ('".join("','",$this->arrayofproducts)."')";
$sql.= " AND cd.date_fin_validite < '".$this->db->idate($now)."'"; $sql.= " AND cd.date_fin_validite < '".$this->db->idate($now)."'";
//print $sql; //print $sql;
$a=parent::getNbOfRecipients($sql); $a=parent::getNbOfRecipients($sql);
return $a; return $a;
} }
/** /**
* \brief This is to add a form filter to provide variant of selector * \brief This is to add a form filter to provide variant of selector
* If used, the HTML select must be called "filter" * If used, the HTML select must be called "filter"
* \return string A html select zone * \return string A html select zone
*/ */
function formFilter() function formFilter()
{ {
global $langs; global $langs;
$s=''; $s='';
$s.='<select name="filter" class="flat">'; $s.='<select name="filter" class="flat">';
if (count($this->arrayofproducts)) $s.='<option value="0">&nbsp;</option>'; if (count($this->arrayofproducts)) $s.='<option value="0">&nbsp;</option>';
else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>';
foreach($this->arrayofproducts as $key => $val) foreach($this->arrayofproducts as $key => $val)
{ {
$s.='<option value="'.$key.'">'.$val.'</option>'; $s.='<option value="'.$key.'">'.$val.'</option>';
} }
$s.='</select>'; $s.='</select>';
return $s; return $s;
} }
/** /**
* \brief Can include an URL link on each record provided by selector * \brief Can include an URL link on each record provided by selector
* shown on target page. * shown on target page.
* \return string Url link * \return string Url link
*/ */
function url($id) function url($id)
{ {
//$companystatic=new Societe($this->db); //$companystatic=new Societe($this->db);
//$companystatic->id=$id; //$companystatic->id=$id;
//$companystatic->nom=''; //$companystatic->nom='';
//return $companystatic->getNomUrl(1); // Url too long //return $companystatic->getNomUrl(1); // Url too long
return '<a href="'.DOL_URL_ROOT.'/societe/soc.php?socid='.$id.'">'.img_object('',"company").'</a>'; return '<a href="'.DOL_URL_ROOT.'/societe/soc.php?socid='.$id.'">'.img_object('',"company").'</a>';
} }
} }