OC_VCategories: sort categories in natural order using usort

Use usort to sort, so that the json encoding is an array.
This commit is contained in:
Bart Visscher 2012-04-12 23:02:24 +02:00
parent b2011bd0a0
commit 69d584331d
1 changed files with 2 additions and 1 deletions

View File

@ -64,6 +64,7 @@ class OC_VCategories {
*/
public function categories() {
OC_Log::write('core','OC_VCategories::categories: '.print_r($this->categories, true), OC_Log::DEBUG);
usort($this->categories, 'strnatcasecmp'); // usort to also renumber the keys
return $this->categories;
}
@ -96,7 +97,6 @@ class OC_VCategories {
}
if(count($newones) > 0) {
$this->categories = array_merge($this->categories, $newones);
natcasesort($this->categories); // Dunno if this is necessary
if($sync === true) {
$this->save();
}
@ -146,6 +146,7 @@ class OC_VCategories {
* @brief Save the list with categories
*/
private function save() {
usort($this->categories, 'strnatcasecmp'); // usort to also renumber the keys
$escaped_categories = serialize($this->categories);
OC_Log::write('core','OC_VCategories::save: '.print_r($this->categories, true), OC_Log::DEBUG);
OC_Preferences::setValue($this->user, $this->app, self::PREF_CATEGORIES_LABEL, $escaped_categories);