Qual: Removed hardcoded code for external module. Replaced by hook.

This commit is contained in:
Laurent Destailleur 2011-11-01 18:36:06 +01:00
parent 0cd241d3a3
commit 4c95c486f6
3 changed files with 45 additions and 62 deletions

View File

@ -55,7 +55,7 @@ class HookManager
* First, a hook is declared by a module by adding a constant MAIN_MODULE_MYMODULENAME_HOOKS
* with value 'nameofcontext1:nameofcontext2:...' 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
* When callHooks function is called, with 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.
*

View File

@ -130,24 +130,24 @@ class FormFile
/**
* Show the box with list of available documents for object
*
* @param modulepart propal, facture, facture_fourn, ...
* @param filename Sub dir to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if filedir already complete)
* @param filedir Dir to scan
* @param urlsource Url of origin page (for return)
* @param genallowed Generation is allowed (1/0 or array of formats)
* @param delallowed Remove is allowed (1/0)
* @param modelselected Model to preselect by default
* @param allowgenifempty Show warning if no model activated
* @param forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined)
* @param iconPDF Show only PDF icon with link (1/0)
* @param maxfilenamelength Max length for filename shown
* @param noform Do not output html form tags
* @param param More param on http links
* @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 hookmanager Object hook of external modules
* @return int <0 if KO, number of shown files if OK
* @param string $modulepart propal, facture, facture_fourn, ...
* @param string $filename Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if $filedir is already complete)
* @param string $filedir Directory to scan
* @param string $urlsource Url of origin page (for return)
* @param int $genallowed Generation is allowed (1/0 or array of formats)
* @param int $delallowed Remove is allowed (1/0)
* @param string $modelselected Model to preselect by default
* @param string $allowgenifempty Show warning if no model activated
* @param string $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined)
* @param int $iconPDF Show only PDF icon with link (1/0)
* @param int $maxfilenamelength Max length for filename shown
* @param string $noform Do not output html form tags
* @param string $param More param on http links
* @param string $title Title to show on top of form
* @param string $buttonlabel Label on submit button
* @param string $codelang Default language code to use on lang combo box if multilang is enabled
* @param HookManager $hookmanager Object hookmanager with instance of external modules hook classes
* @return int <0 if KO, number of shown files if OK
*/
function show_documents($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$hookmanager=false)
{
@ -160,24 +160,24 @@ class FormFile
* Return a string to show the box with list of available documents for object.
* This also set the property $this->numoffiles
*
* @param modulepart propal, facture, facture_fourn, ...
* @param filename Sub dir to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if filedir already complete)
* @param filedir Dir to scan
* @param urlsource Url of origin page (for return)
* @param genallowed Generation is allowed (1/0 or array of formats)
* @param delallowed Remove is allowed (1/0)
* @param modelselected Model to preselect by default
* @param allowgenifempty Show warning if no model activated
* @param forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined)
* @param iconPDF Show only PDF icon with link (1/0)
* @param maxfilenamelength Max length for filename shown
* @param noform Do not output html form tags
* @param param More param on http links
* @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 hookmanager Object hookmanager with instance of external modules hook classes
* @return string Output string.
* @param string $modulepart propal, facture, facture_fourn, ...
* @param string $filename Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if $filedir is already complete)
* @param string $filedir Directory to scan
* @param string $urlsource Url of origin page (for return)
* @param int $genallowed Generation is allowed (1/0 or array of formats)
* @param int $delallowed Remove is allowed (1/0)
* @param string $modelselected Model to preselect by default
* @param string $allowgenifempty Show warning if no model activated
* @param string $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined)
* @param int $iconPDF Show only PDF icon with link (1/0)
* @param int $maxfilenamelength Max length for filename shown
* @param string $noform Do not output html form tags
* @param string $param More param on http links
* @param string $title Title to show on top of form
* @param string $buttonlabel Label on submit button
* @param string $codelang Default language code to use on lang combo box if multilang is enabled
* @param HookManager $hookmanager Object hookmanager with instance of external modules hook classes
* @return string Output string with HTML array of documents (might be empty 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)
{
@ -213,7 +213,6 @@ class FormFile
if ($genallowed)
{
$modellist=array();
$cgvlist=array();
if ($modulepart == 'company')
{
@ -277,17 +276,6 @@ class FormFile
{
include_once(DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php');
$modellist=ModelePDFFactures::liste_modeles($this->db);
// This is to allow to join external files to invoices
if (! empty($conf->concatpdf->enabled))
{
$filescgv=glob($conf->concatpdf->dir_output."/invoices/*.pdf");
if ($filescgv) {
foreach ($filescgv as $cgvfilename) {
$cgvlist[] = basename($cgvfilename, ".pdf");
}
}
}
}
}
elseif ($modulepart == 'project')
@ -394,10 +382,6 @@ class FormFile
$modelselected=$arraykeys[0];
}
$out.= $html->selectarray('model',$modellist,$modelselected,$showempty,0,0);
if (count($cgvlist) > 0)
{
$out.= $html->selectarray('cgv',$cgvlist,"-1",1,0,1);
}
$out.= '</td>';
}
else

View File

@ -146,15 +146,14 @@ class Translate {
* tab_loaded is completed with $domain key.
* Value for hash are: 1:Loaded from disk, 2:Not found, 3:Loaded from cache
*
* @param domain File name to load (.lang file). Must be "file" or "file@module" if file is in a module directory.
* If $domain is "file@module" instead of "file" then we look for module lang file
* in htdocs/custom/modules/mymodule/langs/code_CODE/file.lang
* and in htdocs/mymodule/langs/code_CODE/file.lang for backward compatibility
* instead of file htdocs/langs/code_CODE/file.lang
* @param alt 0 (try xx_ZZ then 1), 1 (try xx_XX then 2), 2 (try en_US or fr_FR or es_ES)
* @param stopafterdirection Stop when the DIRECTION tag is found (optimize)
* @param forcelangdir To force a lang directory
* @return int <0 if KO, 0 if already loaded, >0 if OK
* @param string $domain File name to load (.lang file). Must be "file" or "file@module" for module language files:
* If $domain is "file@module" instead of "file" then we look for module lang file
* in htdocs/custom/modules/mymodule/langs/code_CODE/file.lang
* then in htdocs/module/langs/code_CODE/file.lang instead of htdocs/langs/code_CODE/file.lang
* @param string $alt 0 (try xx_ZZ then 1), 1 (try xx_XX then 2), 2 (try en_US or fr_FR or es_ES)
* @param int $stopafterdirection Stop when the DIRECTION tag is found (optimize speed)
* @param int $forcelangdir To force a different lang directory
* @return int <0 if KO, 0 if already loaded, >0 if OK
*/
function Load($domain,$alt=0,$stopafterdirection=0,$forcelangdir='')
{