From 569b9cd095a7b3c4701f520e0dd43c8b5cc2c404 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 15 Aug 2011 17:16:03 +0200 Subject: [PATCH] Make use of LanguageCategory objects LanguageFactory now uses LanguageCategory objects rather than arrays. --- .../lib/data/language/Language.class.php | 2 +- .../builder/LanguageCacheBuilder.class.php | 13 +++--- .../system/language/LanguageFactory.class.php | 42 +++++++++---------- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/wcfsetup/install/files/lib/data/language/Language.class.php b/wcfsetup/install/files/lib/data/language/Language.class.php index 7b55b817d6..16694313f1 100644 --- a/wcfsetup/install/files/lib/data/language/Language.class.php +++ b/wcfsetup/install/files/lib/data/language/Language.class.php @@ -138,7 +138,7 @@ class Language extends DatabaseObject { // rebuild language file $languageCategory = LanguageFactory::getCategory($category); - $this->editor->updateCategory(array($languageCategory['languageCategoryID']), array($this->packageID)); + $this->editor->updateCategory(array($languageCategory->languageCategoryID), array($this->packageID)); } // include language file diff --git a/wcfsetup/install/files/lib/system/cache/builder/LanguageCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/LanguageCacheBuilder.class.php index 1b13a47be3..f6b0efa2c3 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/LanguageCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/LanguageCacheBuilder.class.php @@ -1,5 +1,6 @@ prepareStatement($sql); - $statement->execute(); - while ($row = $statement->fetchArray()) { - // package to languages - $data['categories'][$row['languageCategory']] = $row; + $languageCategoryList = new LanguageCategoryList(); + $languageCategoryList->sqlLimit = 0; + $languageCategoryList->readObjects(); + foreach ($languageCategoryList->getObjects() as $languageCategory) { + $data['categories'][$languageCategory->languageCategory] = $languageCategory; } return $data; diff --git a/wcfsetup/install/files/lib/system/language/LanguageFactory.class.php b/wcfsetup/install/files/lib/system/language/LanguageFactory.class.php index de8672cbe3..64517a5504 100644 --- a/wcfsetup/install/files/lib/system/language/LanguageFactory.class.php +++ b/wcfsetup/install/files/lib/system/language/LanguageFactory.class.php @@ -36,13 +36,13 @@ abstract class LanguageFactory { private static $scriptingCompiler = null; /** - * Returns a Language-object for the requested language id. + * Returns a Language object for the language with the given id. * * @param integer $languageID * @return wcf\data\language\Language */ public static function getLanguage($languageID) { - if (self::$cache === null) self::loadCache(); + self::loadCache(); if (!isset(self::$languages[$languageID])) { $language = new Language($languageID); @@ -60,43 +60,38 @@ abstract class LanguageFactory { } /** - * Validates if given category is known. + * Returns true if the language category with the given name exists. * - * @param string $category + * @param string $categoryName * @return boolean */ - public static function isValidCategory($category) { + public static function isValidCategory($categoryName) { self::loadCache(); - return (isset(self::$cache['categories'][$category])) ? true : false; + return isset(self::$cache['categories'][$categoryName]); } /** - * Returns data for a specific category. + * Returns the language category with the given name. * - * @param string $category - * @return array + * @param string $categoryName + * @return wcf\data\language\category\LanguageCategory */ - public static function getCategory($category) { - if (isset(self::$cache['categories'][$category])) { - return self::$cache['categories'][$category]; + public static function getCategory($categoryName) { + if (isset(self::$cache['categories'][$categoryName])) { + return self::$cache['categories'][$categoryName]; } - return array(); + return null; } /** * Returns a list of available language categories. * - * @return array + * @return array */ public static function getCategories() { - $categories = array(); - foreach (self::$cache['categories'] as $categoryName => $category) { - $categories[$category['languageCategoryID']] = $categoryName; - } - - return $categories; + return self::$cache['categories']; } /** @@ -126,7 +121,7 @@ abstract class LanguageFactory { /** * Determines the preferred language of the current user. * - * @param array $availableLanguages + * @param array $availableLanguageCodes * @param string $defaultLanguageCode * @return string */ @@ -148,10 +143,11 @@ abstract class LanguageFactory { } /** - * Returns all available languages for given package + * Returns infos (code, id, encoding, etc) about all available languages + * for package with the given id. * * @param integer $packageID - * @return array $availableLanguages infos about each language (code, id, encoding, etc) + * @return array */ public static function getAvailableLanguages($packageID = PACKAGE_ID) { // get list of all available languages -- 2.20.1