Commit 2b4c4d5b by pupi1985

Added a function to load all modules with a given method.

Made the option_default search use that new function.
Modified read access to the global $qa_modules variable to start hiding implementation details.
parent e576e104
...@@ -487,15 +487,12 @@ ...@@ -487,15 +487,12 @@
break; break;
default: // call option_default method in any registered modules default: // call option_default method in any registered modules
$moduletypes=qa_list_module_types(); $modules = qa_load_all_modules_with('option_default'); // Loads all modules with the 'option_default' method
foreach ($moduletypes as $moduletype) { foreach ($modules as $module) {
$modules=qa_load_modules_with($moduletype, 'option_default'); $value = $module->option_default($name);
if (strlen($value)) {
foreach ($modules as $module) { return $value;
$value=$module->option_default($name);
if (strlen($value))
return $value;
} }
} }
...@@ -792,4 +789,4 @@ ...@@ -792,4 +789,4 @@
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
...@@ -612,14 +612,30 @@ ...@@ -612,14 +612,30 @@
// Functions for listing, loading and getting info on modules // Functions for listing, loading and getting info on modules
function qa_list_all_registered_modules_info()
/*
Return an array with all registered modules' information
*/
{
global $qa_modules;
return $qa_modules;
}
function qa_list_module_types() function qa_list_module_types()
/* /*
Return an array of all the module types for which at least one module has been registered Return an array of all the module types for which at least one module has been registered
*/ */
{ {
global $qa_modules; return array_keys(qa_list_all_registered_modules_info());
}
return array_keys($qa_modules);
function qa_list_module_types()
/*
Return an array of all the module types for which at least one module has been registered
*/
{
return array_keys(qa_list_all_registered_modules_info());
} }
...@@ -628,9 +644,8 @@ ...@@ -628,9 +644,8 @@
Return a list of names of registered modules of $type Return a list of names of registered modules of $type
*/ */
{ {
global $qa_modules; $modules = qa_list_all_registered_modules_info();
return is_array(@$modules[$type]) ? array_keys($modules[$type]) : array();
return is_array(@$qa_modules[$type]) ? array_keys($qa_modules[$type]) : array();
} }
...@@ -639,8 +654,8 @@ ...@@ -639,8 +654,8 @@
Return an array containing information about the module of $type named $name Return an array containing information about the module of $type named $name
*/ */
{ {
global $qa_modules; $modules = qa_list_all_registered_modules_info();
return @$qa_modules[$type][$name]; return @$modules[$type][$name];
} }
...@@ -673,8 +688,29 @@ ...@@ -673,8 +688,29 @@
return null; return null;
} }
function qa_load_all_modules_with($method)
/*
Return an array of instantiated clases for modules which have defined $method
(all modules are loaded but not included in the returned array)
*/
{
$modules = array();
$registeredmodules = qa_list_all_registered_modules_info();
foreach ($registeredmodules as $moduletype => $modulesinfo) {
foreach ($modulesinfo as $modulename => $moduleinfo) {
$module = qa_load_module($moduletype, $modulename);
if (method_exists($module, $method))
$modules[$moduletype] = $module;
}
}
return $modules;
}
function qa_load_modules_with($type, $method) function qa_load_modules_with($type, $method)
/* /*
Return an array of instantiated clases for modules of $type which have defined $method Return an array of instantiated clases for modules of $type which have defined $method
...@@ -1466,4 +1502,4 @@ ...@@ -1466,4 +1502,4 @@
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment