Language object cache added
authorMarcel Werk <burntime@woltlab.com>
Thu, 22 Sep 2011 20:30:01 +0000 (22:30 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 22 Sep 2011 20:30:01 +0000 (22:30 +0200)
wcfsetup/install/files/lib/system/cache/builder/LanguageCacheBuilder.class.php
wcfsetup/install/files/lib/system/language/LanguageFactory.class.php

index 13864d7b9e24d1bb3635ffce6337df6ba2b75043..e452a8369612f501dc79ec3103131cff1e54e3b4 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\cache\builder;
 use wcf\data\language\category\LanguageCategoryList;
+use wcf\data\language\LanguageList;
 use wcf\system\WCF;
 
 /**
@@ -43,36 +44,21 @@ class LanguageCacheBuilder implements ICacheBuilder {
                                $data['packages'][$row['packageID']] = array();
                        }
                        $data['packages'][$row['packageID']][] = $row['languageID'];
-                       
-                       // language to packages
-                       if (!isset($languageToPackages[$row['languageID']])) {
-                               $languageToPackages[$row['languageID']] = array();
-                       }
-                       $languageToPackages[$row['languageID']][] = $row['packageID'];
                }
                
                // get languages
-               $sql = "SELECT  *
-                       FROM    wcf".WCF_N."_language";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute();
-               while ($row = $statement->fetchArray()) {
-                       // language data
-                       $data['languages'][$row['languageID']] = $row;
-                       
-                       // language to packages
-                       if (!isset($languageToPackages[$row['languageID']])) {
-                               $languageToPackages[$row['languageID']] = array();
-                       }
-                       $data['languages'][$row['languageID']]['packages'] = $languageToPackages[$row['languageID']];
-                       
+               $languageList = new LanguageList();
+               $languageList->sqlLimit = 0;
+               $languageList->readObjects();
+               $data['languages'] = $languageList->getObjects();
+               foreach ($languageList->getObjects() as $language) {
                        // default language
-                       if ($row['isDefault']) {
-                               $data['default'] = $row['languageID'];
+                       if ($language->isDefault) {
+                               $data['default'] = $language->languageID;
                        }
                        
                        // language code to language id
-                       $data['codes'][$row['languageCode']] = $row['languageID'];
+                       $data['codes'][$language->languageCode] = $language->languageID;
                }
                
                // get language categories
index 2ed6c297fa1bf2af77757dbca07668d1beabda4b..7b4ea48460578aefd6e01ac827aa0e2721841a98 100644 (file)
@@ -52,12 +52,11 @@ class LanguageFactory extends SingletonFactory {
         */
        public function getLanguage($languageID) {
                if (!isset($this->languages[$languageID])) {
-                       $language = new Language($languageID);
-                       if (!$language->languageID) {
+                       if (!isset($this->cache['languages'][$languageID])) {
                                return null;
                        }
                        
-                       $this->languages[$language->languageID] = $language;
+                       $this->languages[$languageID] = $this->cache['languages'][$languageID];
                }
                
                return $this->languages[$languageID];
@@ -147,14 +146,14 @@ class LanguageFactory extends SingletonFactory {
                }
                
                // get default language
-               $defaultLanguageCode = $this->cache['languages'][$this->cache['default']]['languageCode'];
+               $defaultLanguageCode = $this->cache['languages'][$this->cache['default']]->languageCode;
                
                // get preferred language
                $languageCode = self::getPreferredLanguage($availableLanguageCodes, $defaultLanguageCode);
                
                // get language id of preferred language
                foreach ($this->cache['languages'] as $key => $language) {
-                       if ($language['languageCode'] == $languageCode) {
+                       if ($language->languageCode == $languageCode) {
                                return $key;
                        }
                }
@@ -268,7 +267,7 @@ class LanguageFactory extends SingletonFactory {
                $availableLanguages = array();
                if (isset($this->cache['packages'][$packageID])) {
                        foreach ($this->cache['packages'][$packageID] as $availableLanguageID) {
-                               if ($this->cache['languages'][$availableLanguageID]['hasContent']) {
+                               if ($this->cache['languages'][$availableLanguageID]->hasContent) {
                                        $availableLanguages[$availableLanguageID] = $this->getLanguage($availableLanguageID);
                                }
                        }