]> source.dussan.org Git - nextcloud-server.git/commitdiff
finally fix the app sorting
authorFrank Karlitschek <frank@owncloud.org>
Mon, 14 Oct 2013 08:54:38 +0000 (10:54 +0200)
committerFrank Karlitschek <frank@owncloud.org>
Mon, 14 Oct 2013 08:54:38 +0000 (10:54 +0200)
lib/private/app.php
settings/apps.php

index b4a719921788689d6bc32e2c489620d25edcdb82..920906d88366ed71972c55b8424837c50417e513 100644 (file)
@@ -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.
index 20b128875541fff881bf74b98a48ba432dd80adf..96b6d21b50214d717423a27aa32d1a894543778d 100644 (file)
@@ -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" );