- Added server side implementation of application sorting

- Filtering "remove"-function from arrays before sending them via json
This commit is contained in:
Andreas Stöckel 2010-06-16 12:07:50 +00:00
parent e5552d1b45
commit c953709866
2 changed files with 37 additions and 2 deletions

View File

@ -507,6 +507,30 @@ abstract class egw_framework
return egw::link($index,$GLOBALS['egw_info']['flags']['params'][$app]);
}
/**
* Internal usort callback function used to sort an array according to the
* user sort order
*/
private static function _sort_apparray($a, $b)
{
//Unserialize the user_apporder array
$arr = unserialize($GLOBALS['egw_info']['user']['preferences']['common']['user_apporder']);
$ind_a = isset($arr[$a['name']]) ? $arr[$a['name']] : null;
$ind_b = isset($arr[$b['name']]) ? $arr[$b['name']] : null;
if ($ind_a == $ind_b)
return 0;
if ($ind_a == null)
return -1;
if ($ind_b == null)
return 1;
return $ind_a > $ind_b ? 1 : -1;
}
/**
* Prepare an array with apps used to render the navbar
*
@ -578,6 +602,15 @@ abstract class egw_framework
}
}
}
//Sort the applications accordingly to their user sort setting
if ($GLOBALS['egw_info']['user']['preferences']['common']['user_apporder'])
{
//Sort the application array using the user_apporder array as sort index
uasort($apps, 'egw_framework::_sort_apparray');
}
if ($GLOBALS['egw_info']['flags']['currentapp'] == 'preferences' || $GLOBALS['egw_info']['flags']['currentapp'] == 'about')
{
$app = $app_title = 'EGroupware';

View File

@ -87,11 +87,13 @@ function egw_json_encode(input)
{
switch (input.constructor)
{
case Array:
case Array:
var buf = [];
for (var k in input)
{
buf.push(egw_json_encode(input[k]));
//Filter the remove function, which is added to arrays in egw_fw_classes
if (k != 'remove')
buf.push(egw_json_encode(input[k]));
}
return '[' + buf.join(',') + ']';