/** * Getting all languages into an array * where the key is the ISO alpha-2 code of the language * and where the value are the name of the language in the current language * Note: we exclude sacred and constructed languages * * @param string additional WHERE clause * @return array An array of names of languages */ public function initLanguages($addWhere = '') { $where = '1=1' . ($addWhere ? ' AND ' . $addWhere : ''); $table = $this->tables['LANGUAGES']; $lang = LocalizationUtility::getCurrentLanguage(); $lang = LocalizationUtility::getIsoLanguageKey($lang); $nameArray = array(); $titleFields = LocalizationUtility::getLabelFields($table, $lang); $prefixedTitleFields = array(); foreach ($titleFields as $titleField) { $prefixedTitleFields[] = $table . '.' . $titleField; } $labelFields = implode(',', $prefixedTitleFields); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($table . '.lg_iso_2,' . $table . '.lg_country_iso_2,' . $labelFields, $table, $where . ' AND lg_sacred = 0 AND lg_constructed = 0 ' . \SJBR\StaticInfoTables\Utility\TcaUtility::getEnableFields($table)); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $code = $row['lg_iso_2'] . ($row['lg_country_iso_2'] ? '_' . $row['lg_country_iso_2'] : ''); foreach ($titleFields as $titleField) { if ($row[$titleField]) { $nameArray[$code] = $row[$titleField]; break; } } } $GLOBALS['TYPO3_DB']->sql_free_result($res); uasort($nameArray, 'strcoll'); return $nameArray; }
/** * Get the localized value for the label field * * @param array $identifiers An array with key 1- 'uid' containing a uid and/or 2- 'iso' containing one or two iso codes (i.e. country zone code and country code, or language code and country code) * @param string $tableName The name of the table * @param string language ISO code * @param boolean local name only - if set local labels are returned * @return string the value for the label field */ public static function getLabelFieldValue($identifiers, $tableName, $language, $local = FALSE) { $value = ''; $labelFields = self::getLabelFields($tableName, $language, $local); if (count($labelFields)) { // Build the list of fields $prefixedLabelFields = array(); foreach ($labelFields as $labelField) { $prefixedLabelFields[] = $tableName . '.' . $labelField; } $fields = $tableName . '.uid,' . implode(',', $prefixedLabelFields); //Build the where clause $whereClause = ''; if ($identifiers['uid']) { $whereClause .= $tableName . '.uid = ' . intval($identifiers['uid']); } else { if (!empty($identifiers['iso'])) { $isoCode = is_array($identifiers['iso']) ? $identifiers['iso'] : array($identifiers['iso']); foreach ($isoCode as $index => $code) { if ($code) { $field = self::getIsoCodeField($tableName, $code, $index); if ($field) { $whereClause .= ($whereClause ? ' AND ' : '') . $tableName . '.' . $field . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($code, $tableName); } } } } } // Get the entity if ($whereClause) { $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($fields, $tableName, $whereClause . \SJBR\StaticInfoTables\Utility\TcaUtility::getEnableFields($tableName)); if (is_array($rows) && count($rows)) { foreach ($labelFields as $labelField) { if ($rows[0][$labelField]) { $value = $rows[0][$labelField]; break; } } } } } return $value; }