From f06df170cb287009ece7098ff2a28a7af2a0b545 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Mon, 14 Oct 2013 10:54:38 +0200 Subject: [PATCH 1/3] finally fix the app sorting --- lib/private/app.php | 33 +++++++++++++++++++++++++++++++++ settings/apps.php | 17 ----------------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/lib/private/app.php b/lib/private/app.php index b4a7199217..920906d883 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -752,9 +752,42 @@ class OC_App{ } else { $combinedApps = $appList; } + // bring the apps into the right order with a custom sort funtion + usort($combinedApps,'\OC_App::customSort'); + return $combinedApps; } + /** + * @brief: Internal custom sort funtion to bring the app into the right order. Should only be called by listAllApps + * @return array + */ + private static function customSort($a, $b) { + + // prio 1: active + if ($a['active'] != $b['active']) { + return $b['active'] - $a['active']; + } + + // prio 2: shipped + if ($a['shipped'] != $b['shipped']) { + $atemp = ($a['shipped']==true ? 1 : 0); + $btemp = ($b['shipped']==true ? 1 : 0); + return ($btemp - $atemp); + } + + // prio 3: recommended + if ($a['internalclass'] != $b['internalclass']) { + $atemp = ($a['internalclass']=='recommendedapp' ? 1 : 0); + $btemp = ($b['internalclass']=='recommendedapp' ? 1 : 0); + return ($btemp - $atemp); + } + + // prio 4: alphabetical + return strcmp($a['name'], $b['name']); + + } + /** * @brief: get a list of all apps on apps.owncloud.com * @return array, multi-dimensional array of apps. diff --git a/settings/apps.php b/settings/apps.php index 20b1288755..96b6d21b50 100644 --- a/settings/apps.php +++ b/settings/apps.php @@ -28,24 +28,7 @@ OC_App::loadApps(); OC_Util::addStyle( "settings", "settings" ); OC_App::setActiveNavigationEntry( "core_apps" ); -function app_sort( $a, $b ) { - - if ($a['active'] !== $b['active']) { - - return $b['active'] - $a['active']; - - } - - if ($a['internal'] !== $b['internal']) { - return $b['internal'] - $a['internal']; - } - - return strcmp($a['name'], $b['name']); - -} - $combinedApps = OC_App::listAllApps(); -usort( $combinedApps, 'app_sort' ); $tmpl = new OC_Template( "settings", "apps", "user" ); From a201a668781e1ae701718486feb536f606f5564c Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Mon, 14 Oct 2013 10:57:00 +0200 Subject: [PATCH 2/3] fix style --- lib/private/app.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/private/app.php b/lib/private/app.php index 920906d883..753114accb 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -753,7 +753,7 @@ class OC_App{ $combinedApps = $appList; } // bring the apps into the right order with a custom sort funtion - usort($combinedApps,'\OC_App::customSort'); + usort( $combinedApps, '\OC_App::customSort' ); return $combinedApps; } @@ -771,15 +771,15 @@ class OC_App{ // prio 2: shipped if ($a['shipped'] != $b['shipped']) { - $atemp = ($a['shipped']==true ? 1 : 0); - $btemp = ($b['shipped']==true ? 1 : 0); + $atemp = ($a['shipped'] == true ? 1 : 0); + $btemp = ($b['shipped'] == true ? 1 : 0); return ($btemp - $atemp); } // prio 3: recommended if ($a['internalclass'] != $b['internalclass']) { - $atemp = ($a['internalclass']=='recommendedapp' ? 1 : 0); - $btemp = ($b['internalclass']=='recommendedapp' ? 1 : 0); + $atemp = ($a['internalclass'] == 'recommendedapp' ? 1 : 0); + $btemp = ($b['internalclass'] == 'recommendedapp' ? 1 : 0); return ($btemp - $atemp); } From 258ccdfabed18077a2cd13c3f606473266e72f57 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Mon, 14 Oct 2013 11:15:04 +0200 Subject: [PATCH 3/3] case insensitive sort --- lib/private/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/app.php b/lib/private/app.php index 753114accb..1a242ad968 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -784,7 +784,7 @@ class OC_App{ } // prio 4: alphabetical - return strcmp($a['name'], $b['name']); + return strcasecmp($a['name'], $b['name']); }