/** * Gets the localized name of the entity * * @return string */ public function getNameLocalized() { $language = LocalizationUtility::getCurrentLanguage(); $labelFields = LocalizationUtility::getLabelFields($this->tableName, $language); foreach ($labelFields as $labelField) { if ($this->_hasProperty($this->columnsMapping[$labelField]['mapOnProperty'])) { $value = $this->_getProperty($this->columnsMapping[$labelField]['mapOnProperty']); if ($value) { $this->nameLocalized = $value; break; } } } return $this->nameLocalized; }
/** * 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 * * @return array An array of names of languages */ protected function getLanguages() { $databaseConnection = $this->getDatabaseConnection(); $nameArray = array(); if (ExtensionManagementUtility::isLoaded('static_info_tables')) { $where = '1=1'; $table = 'static_languages'; $lang = LocalizationUtility::getCurrentLanguage(); $titleFields = LocalizationUtility::getLabelFields($table, $lang); $prefixedTitleFields = array(); foreach ($titleFields as $titleField) { $prefixedTitleFields[] = $table . '.' . $titleField; } $labelFields = implode(',', $prefixedTitleFields); // Restrict to certain languages if (is_array($this->configuration['thisConfig']['buttons.']) && is_array($this->configuration['thisConfig']['buttons.']['language.']) && isset($this->configuration['thisConfig']['buttons.']['language.']['restrictToItems'])) { $languageList = implode('\',\'', GeneralUtility::trimExplode(',', $databaseConnection->fullQuoteStr(strtoupper($this->configuration['thisConfig']['buttons.']['language.']['restrictToItems']), $table))); $where .= ' AND ' . $table . '.lg_iso_2 IN (' . $languageList . ')'; } $res = $databaseConnection->exec_SELECTquery($table . '.lg_iso_2,' . $table . '.lg_country_iso_2,' . $labelFields, $table, $where . ' AND lg_constructed = 0 ' . BackendUtility::BEenableFields($table) . BackendUtility::deleteClause($table)); $prefixLabelWithCode = (bool) $this->configuration['thisConfig']['buttons.']['language.']['prefixLabelWithCode']; $postfixLabelWithCode = (bool) $this->configuration['thisConfig']['buttons.']['language.']['postfixLabelWithCode']; while ($row = $databaseConnection->sql_fetch_assoc($res)) { $code = strtolower($row['lg_iso_2']) . ($row['lg_country_iso_2'] ? '-' . strtoupper($row['lg_country_iso_2']) : ''); foreach ($titleFields as $titleField) { if ($row[$titleField]) { $nameArray[$code] = $prefixLabelWithCode ? $code . ' - ' . $row[$titleField] : ($postfixLabelWithCode ? $row[$titleField] . ' - ' . $code : $row[$titleField]); break; } } } $databaseConnection->sql_free_result($res); uasort($nameArray, 'strcoll'); } return $nameArray; }
/** * 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 * * @return array An array of names of languages * @todo Define visibility */ public function getLanguages() { $nameArray = array(); if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) { $where = '1=1'; $table = 'static_languages'; $lang = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getCurrentLanguage(); $titleFields = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getLabelFields($table, $lang); $prefixedTitleFields = array(); foreach ($titleFields as $titleField) { $prefixedTitleFields[] = $table . '.' . $titleField; } $labelFields = implode(',', $prefixedTitleFields); // Restrict to certain languages if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['language.']) && isset($this->thisConfig['buttons.']['language.']['restrictToItems'])) { $languageList = implode('\',\'', \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_DB']->fullQuoteStr(strtoupper($this->thisConfig['buttons.']['language.']['restrictToItems']), $table))); $where .= ' AND ' . $table . '.lg_iso_2 IN (' . $languageList . ')'; } $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($table . '.lg_iso_2,' . $table . '.lg_country_iso_2,' . $labelFields, $table, $where . ' AND lg_constructed = 0 ' . ($this->htmlAreaRTE->is_FE() ? $GLOBALS['TSFE']->sys_page->enableFields($table) : \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields($table) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table))); $prefixLabelWithCode = (bool) $this->thisConfig['buttons.']['language.']['prefixLabelWithCode']; $postfixLabelWithCode = (bool) $this->thisConfig['buttons.']['language.']['postfixLabelWithCode']; while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $code = strtolower($row['lg_iso_2']) . ($row['lg_country_iso_2'] ? '-' . strtoupper($row['lg_country_iso_2']) : ''); foreach ($titleFields as $titleField) { if ($row[$titleField]) { $nameArray[$code] = $prefixLabelWithCode ? $code . ' - ' . $row[$titleField] : ($postfixLabelWithCode ? $row[$titleField] . ' - ' . $code : $row[$titleField]); break; } } } $GLOBALS['TYPO3_DB']->sql_free_result($res); uasort($nameArray, 'strcoll'); } return $nameArray; }
/** * @deprecated since 6.0, will be removed two versions later - Use \SJBR\StaticInfoTables\Utility\LocalizationUtility::getLabelFields instead */ public static function getTCAlabelField($tableName, $loadTCA = TRUE, $lang = '', $local = FALSE) { \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction(); return parent::getLabelFields($tableName, $lang, $local); }
/** * 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 * * @return array An array of names of languages */ protected function getLanguages() { $nameArray = []; if (ExtensionManagementUtility::isLoaded('static_info_tables')) { $table = 'static_languages'; $lang = LocalizationUtility::getCurrentLanguage(); $titleFields = LocalizationUtility::getLabelFields($table, $lang); $labelFields = []; foreach ($titleFields as $titleField) { $labelFields[] = $table . '.' . $titleField; } $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); $queryBuilder->select($table . '.lg_iso_2', $table . '.lg_country_iso_2')->addSelect(...$labelFields)->from($table)->where($queryBuilder->expr()->eq('lg_constructed', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))); // Restrict to certain languages if (is_array($this->configuration['thisConfig']['buttons.']) && is_array($this->configuration['thisConfig']['buttons.']['language.']) && isset($this->configuration['thisConfig']['buttons.']['language.']['restrictToItems'])) { $languageList = GeneralUtility::trimExplode(',', strtoupper($this->configuration['thisConfig']['buttons.']['language.']['restrictToItems'])); $queryBuilder->andWhere($queryBuilder->expr()->in($table . '.lg_iso_2', $queryBuilder->createNamedParameter($languageList, Connection::PARAM_STR_ARRAY))); } $result = $queryBuilder->execute(); $prefixLabelWithCode = (bool) $this->configuration['thisConfig']['buttons.']['language.']['prefixLabelWithCode']; $postfixLabelWithCode = (bool) $this->configuration['thisConfig']['buttons.']['language.']['postfixLabelWithCode']; while ($row = $result->fetch()) { $code = strtolower($row['lg_iso_2']) . ($row['lg_country_iso_2'] ? '-' . strtoupper($row['lg_country_iso_2']) : ''); foreach ($titleFields as $titleField) { if ($row[$titleField]) { $nameArray[$code] = $prefixLabelWithCode ? $code . ' - ' . $row[$titleField] : ($postfixLabelWithCode ? $row[$titleField] . ' - ' . $code : $row[$titleField]); break; } } } uasort($nameArray, 'strcoll'); } return $nameArray; }
/** * Prepares the clause by which the result elements are sorted. See description of ORDER BY in * SQL standard for reference. * * @return void */ protected function prepareOrderByStatement() { if ($GLOBALS['TCA'][$this->table]['ctrl']['label']) { $this->orderByStatement = $GLOBALS['TCA'][$this->table]['ctrl']['label']; } // Get the label field for the current language, if any is available $lang = LocalizationUtility::getCurrentLanguage(); $lang = LocalizationUtility::getIsoLanguageKey($lang); $labelFields = LocalizationUtility::getLabelFields($this->table, $lang); $this->orderByStatement = implode(',', $labelFields); }
/** * 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; }