Qual: Doxygen

Qual: Uniformize some code
This commit is contained in:
Laurent Destailleur
2011-10-14 18:51:20 +02:00
parent 15db353eb4
commit 0bc80e9bec
13 changed files with 74 additions and 76 deletions

View File

@@ -93,7 +93,9 @@ class modMyModule extends DolibarrModules
// Constants // Constants
// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive) // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
// Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1), // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
// 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) ); // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0)
// 2=>array('MAIN_MODULE_MYMODULE_HOOKS','chaine','hookcontext1:hookcontext2','To say: This module manage hooks in hookcontext1 and hookcontext2',1,'current',1)
// );
$this->const = array(); $this->const = array();
// Array to add new pages in new tabs // Array to add new pages in new tabs

View File

@@ -436,7 +436,7 @@ class Adherent extends CommonObject
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db); $hookmanager=new HookManager($this->db);
$hookmanager->callHooks(array('member_extrafields')); $hookmanager->callHooks(array('memberdao'));
$parameters=array('socid'=>$socid); $parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook)) if (empty($reshook))

View File

@@ -82,7 +82,7 @@ if ($rowid)
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($db); $hookmanager=new HookManager($db);
$hookmanager->callHooks(array('member_extrafields')); $hookmanager->callHooks(array('membercard'));
/* /*
@@ -1031,7 +1031,7 @@ if ($action == 'edit')
print '</td></tr>'; print '</td></tr>';
print '</table>'; print '</table>';
print '<br><center>'; print '<br><center>';
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">'; print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print ' &nbsp; &nbsp; &nbsp; '; print ' &nbsp; &nbsp; &nbsp; ';

View File

@@ -859,10 +859,9 @@ class Commande extends CommonObject
* Load an object from a proposal and create a new order into database * Load an object from a proposal and create a new order into database
* *
* @param Object $object Object source * @param Object $object Object source
* @param HookManager $hookmanager Hook manager instance
* @return int <0 if KO, 0 if nothing done, 1 if OK * @return int <0 if KO, 0 if nothing done, 1 if OK
*/ */
function createFromProposal($object,$hookmanager=false) function createFromProposal($object)
{ {
global $conf,$user,$langs; global $conf,$user,$langs;
@@ -919,13 +918,14 @@ class Commande extends CommonObject
if ($ret > 0) if ($ret > 0)
{ {
// Hook of thirdparty module // Actions hooked (by external module)
if (is_object($hookmanager)) include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
{ $hookmanager=new HookManager($this->db);
$parameters=array('objFrom'=>$object); $hookmanager->callHooks(array('orderdao'));
$reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) $error++; $parameters=array('objFrom'=>$object);
} $reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) $error++;
if (! $error) if (! $error)
{ {
@@ -2222,7 +2222,7 @@ class Commande extends CommonObject
$staticline=new OrderLine($this->db); $staticline=new OrderLine($this->db);
$staticline->fetch($rowid); $staticline->fetch($rowid);
$this->line->oldline = $staticline; $this->line->oldline = $staticline;
// Reorder if fk_parent_line change // Reorder if fk_parent_line change
if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
{ {
@@ -2259,7 +2259,7 @@ class Commande extends CommonObject
{ {
// Reorder if child line // Reorder if child line
if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); if (! empty($fk_parent_line)) $this->line_order(true,'DESC');
// Mise a jour info denormalisees // Mise a jour info denormalisees
$this->update_price(1); $this->update_price(1);

View File

@@ -599,10 +599,9 @@ class Facture extends CommonObject
* Load an object from an order and create a new invoice into database * Load an object from an order and create a new invoice into database
* *
* @param Object $object Object source * @param Object $object Object source
* @param HookManager $hookmanager Hook manager instance
* @return int <0 if KO, 0 if nothing done, 1 if OK * @return int <0 if KO, 0 if nothing done, 1 if OK
*/ */
function createFromOrder($object, $hookmanager=false) function createFromOrder($object)
{ {
global $conf,$user,$langs; global $conf,$user,$langs;
@@ -660,13 +659,14 @@ class Facture extends CommonObject
if ($ret > 0) if ($ret > 0)
{ {
// Hook of thirdparty module // Actions hooked (by external module)
if (is_object($hookmanager)) include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
{ $hookmanager=new HookManager($this->db);
$parameters=array('objFrom'=>$object); $hookmanager->callHooks(array('invoicedao'));
$reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) $error++; $parameters=array('objFrom'=>$object);
} $reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) $error++;
if (! $error) if (! $error)
{ {
@@ -2016,7 +2016,7 @@ class Facture extends CommonObject
$staticline=new FactureLigne($this->db); $staticline=new FactureLigne($this->db);
$staticline->fetch($rowid); $staticline->fetch($rowid);
$this->line->oldline = $staticline; $this->line->oldline = $staticline;
// Reorder if fk_parent_line change // Reorder if fk_parent_line change
if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
{ {
@@ -2053,7 +2053,7 @@ class Facture extends CommonObject
{ {
// Reorder if child line // Reorder if child line
if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); if (! empty($fk_parent_line)) $this->line_order(true,'DESC');
// Mise a jour info denormalisees au niveau facture // Mise a jour info denormalisees au niveau facture
$this->update_price(1); $this->update_price(1);
$this->db->commit(); $this->db->commit();

View File

@@ -967,7 +967,7 @@ abstract class CommonObject
{ {
$sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql.= ' WHERE rowid ='.$rowid; $sql.= ' WHERE rowid ='.$rowid;
dol_syslog(get_class($this)."::getRangOfLine sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::getRangOfLine sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
@@ -1010,7 +1010,7 @@ abstract class CommonObject
$sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id; $sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
$sql.= ' AND fk_parent_line = '.$fk_parent_line; $sql.= ' AND fk_parent_line = '.$fk_parent_line;
dol_syslog(get_class($this)."::line_max sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::line_max sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
@@ -1031,7 +1031,7 @@ abstract class CommonObject
{ {
$sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id; $sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
dol_syslog(get_class($this)."::line_max sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::line_max sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
@@ -1771,6 +1771,7 @@ abstract class CommonObject
* TODO Move this into an output class file (htmlline.class.php) * TODO Move this into an output class file (htmlline.class.php)
* If lines are into a template, title must also be into a template * If lines are into a template, title must also be into a template
* But for the moment we don't know if it'st possible as we keep a method available on overloaded objects. * But for the moment we don't know if it'st possible as we keep a method available on overloaded objects.
*
* @param $action Action code * @param $action Action code
* @param $seller Object of seller third party * @param $seller Object of seller third party
* @param $buyer Object of buyer third party * @param $buyer Object of buyer third party

View File

@@ -28,20 +28,20 @@
* \class HookManager * \class HookManager
* \brief Class to manage hooks * \brief Class to manage hooks
*/ */
class HookManager class HookManager
{ {
var $db; var $db;
var $linkedObjectBlock; // Context hookmanager was created for ('thirdpartycard', 'thirdpartydao', ...)
var $objectid; var $contextarray=array();
// Array with instantiated classes // Array with instantiated classes
var $hooks=array(); var $hooks=array();
/** /**
* Constructeur de la classe * Constructor
* @param DB Handler acces base de donnees *
* @param DoliDB $DB Handler acces base de donnees
*/ */
function HookManager($DB) function HookManager($DB)
{ {
@@ -50,27 +50,30 @@ class HookManager
/** /**
* Init array this->hooks with instantiated controler * Init array this->hooks with instantiated action controlers.
* *
* First, a hook is declared by a module by adding a constant MAIN_MODULE_MYMODULENAME_HOOKS * First, a hook is declared by a module by adding a constant MAIN_MODULE_MYMODULENAME_HOOKS
* with value nameofhookkey1:nameofhookkey2:...:nameofhookkeyn. * with value 'nameofcontext1:nameofcontext2:...' or 'all' into $this->const of module descriptor file.
* This add into conf->hooks_modules an entrie ('modulename'=>nameofhookkey) * This make conf->hooks_modules loaded with an entry ('modulename'=>array(nameofcontext1,nameofcontext2,...))
* Then, when this function is called, an array this->hooks is defined with instance of controler * When this function is called by callHooks(list_of_contexts), an array this->hooks is defined with instance of controler
* classes that support the hook called * class found into file /mymodule/class/actions_mymodule.class.php (if module has declared the context as a managed context).
* Then when a hook is executeHook('aMethod'...) is called, the method aMethod found into class will be executed.
* *
* @param arraytype Array list of searched hooks tab/features. For example: 'thirdpartytab', 'thirdparty',... * @param array $arraytype Array list of searched hooks tab/features. For example: 'thirdpartycard' (for hook methods into page card thirdparty), 'thirdpartydao' (for hook methods into Societe), ...
* @return int Always 1 * @return int Always 1
*/ */
function callHooks($arraytype) function callHooks($arraytype)
{ {
global $conf; global $conf;
// Test if ther is hooks to manage // Test if there is hooks to manage
if (! is_array($conf->hooks_modules) || empty($conf->hooks_modules)) return; if (! is_array($conf->hooks_modules) || empty($conf->hooks_modules)) return;
// For backward compatibility // For backward compatibility
if (! is_array($arraytype)) $arraytype=array($arraytype); if (! is_array($arraytype)) $arraytype=array($arraytype);
$this->contextarray=array_merge($arraytype,$this->contextarray);
$i=0; $i=0;
foreach($conf->hooks_modules as $module => $hooks) foreach($conf->hooks_modules as $module => $hooks)
{ {
@@ -78,7 +81,7 @@ class HookManager
{ {
foreach($arraytype as $type) foreach($arraytype as $type)
{ {
if (in_array($type,$hooks)) if (in_array($type,$hooks)) // We instantiate action class only if hook is required
{ {
$path = '/'.$module.'/class/'; $path = '/'.$module.'/class/';
$actionfile = 'actions_'.$module.'.class.php'; $actionfile = 'actions_'.$module.'.class.php';
@@ -116,13 +119,14 @@ class HookManager
/** /**
* Execute hooks (if the were initialized) for the given method * Execute hooks (if the were initialized) for the given method
* @param method Method name to hook ('doActions', 'printSearchForm', ...) *
* @param parameters Array of parameters * @param string $method Name of method hooked ('doActions', 'printSearchForm', 'showInputField', ...)
* @param action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...) * @param array $parameters Array of parameters
* @param object Object to use hooks on * @param Object &$object Object to use hooks on
* @param string For doActions,showInputField,showOutputField: Return 0 if we want to keep doing standard actions, >0 if if want to stop standard actions, >0 means KO. * @param string &$action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...)
* For printSearchForm,printLeftBlock: Return HTML string. * @return mixed For doActions,showInputField,showOutputField: Return 0 if we want to keep standard actions, >0 if if want to stop standard actions, <0 means KO.
* $this->error or this->errors are also defined with hooks errors. * For printSearchForm,printLeftBlock: Return HTML string.
* $this->error or this->errors are also defined by class called by this function if error.
*/ */
function executeHooks($method, $parameters=false, &$object='', &$action='') function executeHooks($method, $parameters=false, &$object='', &$action='')
{ {
@@ -130,7 +134,8 @@ class HookManager
if (! is_array($this->hooks) || empty($this->hooks)) return ''; if (! is_array($this->hooks) || empty($this->hooks)) return '';
dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action); $parameters['context']=join(':',$this->contextarray);
dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']);
// Loop on each hook // Loop on each hook
$resaction=0; $resprint=''; $resaction=0; $resprint='';

View File

@@ -177,7 +177,7 @@ class FormFile
* @param title Title to show on top of form * @param title Title to show on top of form
* @param buttonlabel Label on submit button * @param buttonlabel Label on submit button
* @param codelang Default language code to use on lang combo box if multilang is enabled * @param codelang Default language code to use on lang combo box if multilang is enabled
* @param hooks Object hook of external modules * @param hookmanager Object hookmanager with instance of external modules hook classes
* @return string Output string. * @return string Output string.
*/ */
function showdocuments($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$hookmanager=false) function showdocuments($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$hookmanager=false)

View File

@@ -85,6 +85,7 @@ class InterfaceWorkflowManager
/** /**
* Function called when a Dolibarrr business event is done. * Function called when a Dolibarrr business event is done.
* All functions "run_trigger" are triggered if file is inside directory htdocs/includes/triggers * All functions "run_trigger" are triggered if file is inside directory htdocs/includes/triggers
*
* @param action Event code (COMPANY_CREATE, PROPAL_VALIDATE, ...) * @param action Event code (COMPANY_CREATE, PROPAL_VALIDATE, ...)
* @param object Object action is done on * @param object Object action is done on
* @param user Object user * @param user Object user
@@ -103,15 +104,10 @@ class InterfaceWorkflowManager
if (! empty($conf->commande->enabled) && ! empty($conf->global->WORKFLOW_PROPAL_AUTOCREATE_ORDER)) if (! empty($conf->commande->enabled) && ! empty($conf->global->WORKFLOW_PROPAL_AUTOCREATE_ORDER))
{ {
include_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'); include_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php');
$order = new Commande($this->db); $newobject = new Commande($this->db);
// Actions on extra fields (by external module or standard code) $ret=$newobject->createFromProposal($object);
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
$hookmanager=new HookManager($this->db);
$hookmanager->callHooks(array('ordercard'));
$ret=$order->createFromProposal($object,$hookmanager);
if ($ret < 0) { $this->error=$invoice->error; $this->errors[]=$invoice->error; }
return $ret; return $ret;
} }
} }
@@ -123,15 +119,10 @@ class InterfaceWorkflowManager
if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_ORDER_AUTOCREATE_INVOICE)) if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_ORDER_AUTOCREATE_INVOICE))
{ {
include_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'); include_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php');
$invoice = new Facture($this->db); $newobject = new Facture($this->db);
// Actions on extra fields (by external module or standard code) $ret=$newobject->createFromOrder($object);
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
$hookmanager=new HookManager($this->db);
$hookmanager->callHooks(array('invoicecard'));
$ret=$invoice->createFromOrder($object,$hookmanager);
if ($ret < 0) { $this->error=$invoice->error; $this->errors[]=$invoice->error; }
return $ret; return $ret;
} }
} }

View File

@@ -582,7 +582,7 @@ class Product extends CommonObject
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db); $hookmanager=new HookManager($this->db);
$hookmanager->callHooks(array('product')); $hookmanager->callHooks(array('productdao'));
$parameters=array(); $action='delete'; $parameters=array(); $action='delete';
$reshook=$hookmanager->executeHooks('deleteProduct',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('deleteProduct',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (! empty($hookmanager->error)) if (! empty($hookmanager->error))

View File

@@ -73,7 +73,7 @@ $result=restrictedArea($user,'produit|service',$value,'product','','',$type, $ob
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($db); $hookmanager=new HookManager($db);
$hookmanager->callHooks(array('product')); $hookmanager->callHooks(array('productcard'));

View File

@@ -546,7 +546,7 @@ class Societe extends CommonObject
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db); $hookmanager=new HookManager($this->db);
$hookmanager->callHooks(array('thirdparty_extrafields')); $hookmanager->callHooks(array('thirdpartydao'));
$parameters=array('socid'=>$socid); $parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook)) if (empty($reshook))
@@ -951,7 +951,7 @@ class Societe extends CommonObject
// Additionnal action by hooks // Additionnal action by hooks
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db); $hookmanager=new HookManager($this->db);
$hookmanager->callHooks(array('thirdparty')); $hookmanager->callHooks(array('thirdpartydao'));
$parameters=array(); $action='delete'; $parameters=array(); $action='delete';
$reshook=$hookmanager->executeHooks('deleteThirdparty',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('deleteThirdparty',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (! empty($hookmanager->error)) if (! empty($hookmanager->error))

View File

@@ -71,8 +71,7 @@ $result = restrictedArea($user, 'societe', $socid, '', '', '', '', $objcanvas);
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($db); $hookmanager=new HookManager($db);
// TODO: Remove callHooks and add page into executeHooks $hookmanager->callHooks(array('thirdpartycard'));
$hookmanager->callHooks(array('thirdpartycard','thirdparty_extrafields'));
/* /*