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
// 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),
// 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();
// 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)
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db);
$hookmanager->callHooks(array('member_extrafields'));
$hookmanager->callHooks(array('memberdao'));
$parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
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
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($db);
$hookmanager->callHooks(array('member_extrafields'));
$hookmanager->callHooks(array('membercard'));
/*

View File

@@ -859,10 +859,9 @@ class Commande extends CommonObject
* Load an object from a proposal and create a new order into database
*
* @param Object $object Object source
* @param HookManager $hookmanager Hook manager instance
* @return int <0 if KO, 0 if nothing done, 1 if OK
*/
function createFromProposal($object,$hookmanager=false)
function createFromProposal($object)
{
global $conf,$user,$langs;
@@ -919,13 +918,14 @@ class Commande extends CommonObject
if ($ret > 0)
{
// Hook of thirdparty module
if (is_object($hookmanager))
{
// Actions hooked (by external module)
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db);
$hookmanager->callHooks(array('orderdao'));
$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)
{

View File

@@ -599,10 +599,9 @@ class Facture extends CommonObject
* Load an object from an order and create a new invoice into database
*
* @param Object $object Object source
* @param HookManager $hookmanager Hook manager instance
* @return int <0 if KO, 0 if nothing done, 1 if OK
*/
function createFromOrder($object, $hookmanager=false)
function createFromOrder($object)
{
global $conf,$user,$langs;
@@ -660,13 +659,14 @@ class Facture extends CommonObject
if ($ret > 0)
{
// Hook of thirdparty module
if (is_object($hookmanager))
{
// Actions hooked (by external module)
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db);
$hookmanager->callHooks(array('invoicedao'));
$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)
{

View File

@@ -1771,6 +1771,7 @@ abstract class CommonObject
* TODO Move this into an output class file (htmlline.class.php)
* 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.
*
* @param $action Action code
* @param $seller Object of seller third party
* @param $buyer Object of buyer third party

View File

@@ -28,20 +28,20 @@
* \class HookManager
* \brief Class to manage hooks
*/
class HookManager
{
var $db;
var $linkedObjectBlock;
var $objectid;
// Context hookmanager was created for ('thirdpartycard', 'thirdpartydao', ...)
var $contextarray=array();
// Array with instantiated classes
var $hooks=array();
/**
* Constructeur de la classe
* @param DB Handler acces base de donnees
* Constructor
*
* @param DoliDB $DB Handler acces base de donnees
*/
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
* with value nameofhookkey1:nameofhookkey2:...:nameofhookkeyn.
* This add into conf->hooks_modules an entrie ('modulename'=>nameofhookkey)
* Then, when this function is called, an array this->hooks is defined with instance of controler
* classes that support the hook called
* with value 'nameofcontext1:nameofcontext2:...' or 'all' into $this->const of module descriptor file.
* This make conf->hooks_modules loaded with an entry ('modulename'=>array(nameofcontext1,nameofcontext2,...))
* When this function is called by callHooks(list_of_contexts), an array this->hooks is defined with instance of controler
* 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
*/
function callHooks($arraytype)
{
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;
// For backward compatibility
if (! is_array($arraytype)) $arraytype=array($arraytype);
$this->contextarray=array_merge($arraytype,$this->contextarray);
$i=0;
foreach($conf->hooks_modules as $module => $hooks)
{
@@ -78,7 +81,7 @@ class HookManager
{
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/';
$actionfile = 'actions_'.$module.'.class.php';
@@ -116,13 +119,14 @@ class HookManager
/**
* Execute hooks (if the were initialized) for the given method
* @param method Method name to hook ('doActions', 'printSearchForm', ...)
* @param parameters Array of parameters
* @param action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...)
* @param 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 $method Name of method hooked ('doActions', 'printSearchForm', 'showInputField', ...)
* @param array $parameters Array of parameters
* @param Object &$object Object to use hooks on
* @param string &$action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...)
* @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.
* For printSearchForm,printLeftBlock: Return HTML string.
* $this->error or this->errors are also defined with hooks errors.
* $this->error or this->errors are also defined by class called by this function if error.
*/
function executeHooks($method, $parameters=false, &$object='', &$action='')
{
@@ -130,7 +134,8 @@ class HookManager
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
$resaction=0; $resprint='';

View File

@@ -177,7 +177,7 @@ class FormFile
* @param title Title to show on top of form
* @param buttonlabel Label on submit button
* @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.
*/
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.
* All functions "run_trigger" are triggered if file is inside directory htdocs/includes/triggers
*
* @param action Event code (COMPANY_CREATE, PROPAL_VALIDATE, ...)
* @param object Object action is done on
* @param user Object user
@@ -103,15 +104,10 @@ class InterfaceWorkflowManager
if (! empty($conf->commande->enabled) && ! empty($conf->global->WORKFLOW_PROPAL_AUTOCREATE_ORDER))
{
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)
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$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; }
$ret=$newobject->createFromProposal($object);
if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
return $ret;
}
}
@@ -123,15 +119,10 @@ class InterfaceWorkflowManager
if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_ORDER_AUTOCREATE_INVOICE))
{
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)
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$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; }
$ret=$newobject->createFromOrder($object);
if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
return $ret;
}
}

View File

@@ -582,7 +582,7 @@ class Product extends CommonObject
// Actions on extra fields (by external module or standard code)
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db);
$hookmanager->callHooks(array('product'));
$hookmanager->callHooks(array('productdao'));
$parameters=array(); $action='delete';
$reshook=$hookmanager->executeHooks('deleteProduct',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
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
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$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)
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db);
$hookmanager->callHooks(array('thirdparty_extrafields'));
$hookmanager->callHooks(array('thirdpartydao'));
$parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
@@ -951,7 +951,7 @@ class Societe extends CommonObject
// Additionnal action by hooks
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db);
$hookmanager->callHooks(array('thirdparty'));
$hookmanager->callHooks(array('thirdpartydao'));
$parameters=array(); $action='delete';
$reshook=$hookmanager->executeHooks('deleteThirdparty',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
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
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($db);
// TODO: Remove callHooks and add page into executeHooks
$hookmanager->callHooks(array('thirdpartycard','thirdparty_extrafields'));
$hookmanager->callHooks(array('thirdpartycard'));
/*