1 | <?php |
||
36 | class LanguageRepository { |
||
37 | |||
38 | protected static $instance; |
||
39 | |||
40 | /** |
||
41 | * Internal method to fetch all language rows from the database. |
||
42 | * |
||
43 | * @see self::$allLanguageRows |
||
44 | * @param void |
||
45 | * @return void |
||
46 | */ |
||
47 | protected function fetchAllLanguageRows() { |
||
62 | |||
63 | /** |
||
64 | * Returns an array with all languages depending on the cache setting directly from |
||
65 | * the database or cached. |
||
66 | * |
||
67 | * @return array |
||
68 | */ |
||
69 | protected function getCachedOrUncacheResults() { |
||
87 | |||
88 | /** |
||
89 | * This method returns an array with all available language objects in the system. |
||
90 | * |
||
91 | * @see tx_languagevisibility_language |
||
92 | * @return array |
||
93 | */ |
||
94 | public function getLanguages() { |
||
107 | |||
108 | /** |
||
109 | * Returns an array with all available languages of a backend user. |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | public function getLanguagesForBEUser() { |
||
131 | |||
132 | /** |
||
133 | * Retruns an instance of the language object for the default language. |
||
134 | * |
||
135 | * @param void |
||
136 | * @return tx_languagevisibility_language |
||
137 | */ |
||
138 | public function getDefaultLanguage() { |
||
147 | |||
148 | /** |
||
149 | * Returns an instance for a language by the id. |
||
150 | * Note: since the language is an value object all languages can be cached |
||
151 | * |
||
152 | * @param $id |
||
153 | * @return tx_languagevisibility_language |
||
154 | */ |
||
155 | public function getLanguageById($id) { |
||
156 | $cacheManager = CacheManager::getInstance(); |
||
157 | $cacheData = $cacheManager->get('languagesCache'); |
||
158 | $isCacheEnabled = $cacheManager->isCacheEnabled(); |
||
159 | $id = is_array($id) ? array_shift($id) : $id; |
||
160 | |||
161 | if (! $isCacheEnabled || ! isset($cacheData[$id])) { |
||
162 | if ($id == 0) { |
||
163 | $cacheData[$id] = $this->getDefaultLanguage(); |
||
164 | } else { |
||
165 | $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_language', 'uid=' . intval($id), '', '', ''); |
||
166 | $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); |
||
167 | $language = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('AOE\\Languagevisibility\\Language'); |
||
168 | |||
169 | $language->setData($row); |
||
170 | $cacheData[$id] = $language; |
||
171 | $GLOBALS['TYPO3_DB']->sql_free_result($res); |
||
172 | |||
173 | $cacheManager->set('languagesCache', $cacheData); |
||
174 | } |
||
175 | } |
||
176 | return $cacheData[$id]; |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * returns an instance of the language repository as singleton. |
||
181 | * |
||
182 | * @param void |
||
183 | * @return Languagerepository |
||
184 | */ |
||
185 | public static function makeInstance() { |
||
192 | } |
||
193 |