static method to get app-names as options, as from the widget itself

This commit is contained in:
Ralf Becker 2013-09-04 13:48:22 +00:00
parent ed0abde9ae
commit baaaf5b877

View File

@ -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
*/