summaryrefslogtreecommitdiff
path: root/app/Module.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@gmail.com>2015-04-03 19:55:45 +0100
committerGreg Roach <fisharebest@gmail.com>2015-04-03 19:55:45 +0100
commit08c48399c33069368e86dc5a8eab80844f782f7c (patch)
treeddcbea2fe58be8236c6c049c7732534dd11780d3 /app/Module.php
parentbeb72eac64b9d502b78fbff300f845e8524ead19 (diff)
downloadwebtrees-08c48399c33069368e86dc5a8eab80844f782f7c.tar.gz
webtrees-08c48399c33069368e86dc5a8eab80844f782f7c.tar.bz2
webtrees-08c48399c33069368e86dc5a8eab80844f782f7c.zip
Fix #517, #544 - sorting of modules in admin pages
Diffstat (limited to 'app/Module.php')
-rw-r--r--app/Module.php31
1 files changed, 30 insertions, 1 deletions
diff --git a/app/Module.php b/app/Module.php
index b901648b62..43f4e169b2 100644
--- a/app/Module.php
+++ b/app/Module.php
@@ -59,7 +59,7 @@ class Module {
}
/**
- * Get a list of modules which (a) provide a specific function chart and (b) we have permission to see.
+ * Get a list of modules which (a) provide a specific function and (b) we have permission to see.
*
* We cannot currently use auto-loading for modules, as there may be user-defined
* modules about which the auto-loader knows nothing.
@@ -90,6 +90,35 @@ class Module {
$array[$module_name] = $module;
}
}
+ }
+
+ /**
+ * Get a list of all modules, enabled or not, which provide a specific function.
+ *
+ * We cannot currently use auto-loading for modules, as there may be user-defined
+ * modules about which the auto-loader knows nothing.
+ *
+ * @param string $component The type of module, such as "tab", "report" or "menu"
+ *
+ * @return AbstractModule[]
+ */
+ public static function getAllModulesByComponent($component) {
+ $module_names = Database::prepare(
+ "SELECT SQL_CACHE module_name" .
+ " FROM `##module`" .
+ " ORDER BY CASE :component WHEN 'menu' THEN menu_order WHEN 'sidebar' THEN sidebar_order WHEN 'tab' THEN tab_order ELSE 0 END, module_name"
+ )->execute(array(
+ 'component' => $component,
+ ))->fetchOneColumn();
+
+ $array = array();
+ foreach ($module_names as $module_name) {
+ $interface = __NAMESPACE__ . '\Module' . ucfirst($component) . 'Interface';
+ $module = self::getModuleByName($module_name);
+ if ($module instanceof $interface) {
+ $array[$module_name] = $module;
+ }
+ }
// The order of menus/sidebars/tabs is defined in the database. Others are sorted by name.
if ($component !== 'menu' && $component !== 'sidebar' && $component !== 'tab') {