From baaaf5b8775eac12ed5080a3b0a44986a86cfe30 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 4 Sep 2013 13:48:22 +0000 Subject: [PATCH] static method to get app-names as options, as from the widget itself --- .../class.etemplate_widget_menupopup.inc.php | 64 +++++++++++-------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/etemplate/inc/class.etemplate_widget_menupopup.inc.php b/etemplate/inc/class.etemplate_widget_menupopup.inc.php index 372935fba5..c7febf4a77 100644 --- a/etemplate/inc/class.etemplate_widget_menupopup.inc.php +++ b/etemplate/inc/class.etemplate_widget_menupopup.inc.php @@ -541,32 +541,7 @@ class etemplate_widget_menupopup extends etemplate_widget break; case 'select-app': // type2: 'user'=apps of current user, 'enabled', 'installed' (default), 'all' = not installed ones too - $apps = array(); - foreach ($GLOBALS['egw_info']['apps'] as $app => $data) - { - if ($type2 == 'enabled' && (!$data['enabled'] || !$data['status'] || $data['status'] == 3)) - { - continue; // app not enabled (user can not have run rights for these apps) - } - if ($type2 != 'user' || $GLOBALS['egw_info']['user']['apps'][$app]) - { - $apps[$app] = lang($app); - } - } - if ($type2 == 'all') - { - $dir = opendir(EGW_SERVER_ROOT); - while ($file = readdir($dir)) - { - if (@is_dir(EGW_SERVER_ROOT."/$file/setup") && $file[0] != '.' && - !isset($apps[$app = basename($file)])) - { - $apps[$app] = $app . ' (*)'; - } - } - closedir($dir); - } - natcasesort($apps); + $apps = self::app_options($type2); $options = is_array($options) ? $options+$apps : $apps; break; @@ -599,6 +574,43 @@ class etemplate_widget_menupopup extends etemplate_widget return $options; } + /** + * Get available apps as options + * + * @param string $type2='installed' 'user'=apps of current user, 'enabled', 'installed' (default), 'all' = not installed ones too + * @return array app => label pairs sorted by label + */ + public static function app_options($type2) + { + $apps = array(); + foreach ($GLOBALS['egw_info']['apps'] as $app => $data) + { + if ($type2 == 'enabled' && (!$data['enabled'] || !$data['status'] || $data['status'] == 3)) + { + continue; // app not enabled (user can not have run rights for these apps) + } + if ($type2 != 'user' || $GLOBALS['egw_info']['user']['apps'][$app]) + { + $apps[$app] = lang($app); + } + } + if ($type2 == 'all') + { + $dir = opendir(EGW_SERVER_ROOT); + while ($file = readdir($dir)) + { + if (@is_dir(EGW_SERVER_ROOT."/$file/setup") && $file[0] != '.' && + !isset($apps[$app = basename($file)])) + { + $apps[$app] = $app . ' (*)'; + } + } + closedir($dir); + } + natcasesort($apps); + return $apps; + } + /** * internal function to format account-data */