function __getItemsStaticTable($sTable, $sValueField = 'uid', $sWhere = '')
 {
     // Get user language
     if (TYPO3_MODE == 'FE') {
         $sLang = $GLOBALS['TSFE']->lang;
     } else {
         $sLang = $GLOBALS['LANG']->lang;
     }
     // Get field names
     $aFieldNames = tx_staticinfotables_div::getTCAlabelField($sTable, TRUE, $sLang);
     $sFields = implode(', ', $aFieldNames);
     // Get data from static table
     $aRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($sValueField . ', ' . $sFields, $sTable, $sWhere, '', $sFields);
     $aItems = array();
     if (empty($aRows)) {
         return $aItems;
     }
     // For each row
     foreach ($aRows as $aRow) {
         foreach ($aFieldNames as $sFieldName) {
             if ($aRow[$sFieldName]) {
                 // If exists
                 $sCaption = $aRow[$sFieldName];
                 break;
             }
         }
         $aTmp = array('caption' => $sCaption, 'value' => $aRow[$sValueField]);
         array_push($aItems, $aTmp);
     }
     return $aItems;
 }
 /**
  * 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
  */
 function getLanguages()
 {
     $where = '1=1';
     $table = 'static_languages';
     $lang = tx_staticinfotables_div::getCurrentLanguage();
     $nameArray = array();
     $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $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("','", t3lib_div::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) : t3lib_BEfunc::BEenableFields($table) . t3lib_BEfunc::deleteClause($table)));
     $prefixLabelWithCode = !$this->thisConfig['buttons.']['language.']['prefixLabelWithCode'] ? false : true;
     $postfixLabelWithCode = !$this->thisConfig['buttons.']['language.']['postfixLabelWithCode'] ? false : true;
     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);
     if ($this->htmlAreaRTE->is_FE()) {
         $GLOBALS['TSFE']->csConvObj->convArray($nameArray, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['charset'], $this->htmlAreaRTE->OutputCharset);
     } else {
         $GLOBALS['LANG']->csConvObj->convArray($nameArray, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['charset'], $GLOBALS['LANG']->charSet);
     }
     uasort($nameArray, 'strcoll');
     return $nameArray;
 }
	/**
	 * Function to use in own TCA definitions
	 * Adds additional select items
	 *
	 * 			items		reference to the array of items (label,value,icon)
	 * 			config		The config array for the field.
	 * 			TSconfig	The "itemsProcFunc." from fieldTSconfig of the field.
	 * 			table		Table name
	 * 			row		Record row
	 * 			field		Field name
	 *
	 * @param	array		itemsProcFunc data array:
	 * @return	void		The $items array may have been modified
	 */
	function selectItemsTCA ($params) {
		global $TCA;

		$where = '';
		$config = &$params['config'];
		$table = $config['itemsProcFunc_config']['table'];
		$tcaWhere = $config['itemsProcFunc_config']['where'];
		if ($tcaWhere)	{
			$where = tx_staticinfotables_div::replaceMarkersInSQL($tcaWhere, $params['table'], $params['row']);
		}

		if ($table) {
			$indexField = $config['itemsProcFunc_config']['indexField'];
			$indexField = $indexField ? $indexField : 'uid';

			$lang = strtolower(tx_staticinfotables_div::getCurrentLanguage());
			$titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang);
			$prefixedTitleFields = array();
			foreach ($titleFields as $titleField) {
				$prefixedTitleFields[] = $table.'.'.$titleField;
			}
			$fields = $table.'.'.$indexField.','.implode(',', $prefixedTitleFields);

			if ($config['itemsProcFunc_config']['prependHotlist']) {

				$limit = $config['itemsProcFunc_config']['hotlistLimit'];
				$limit = $limit ? $limit : '8';
				$app = $config['itemsProcFunc_config']['hotlistApp'];
				$app = $app ? $app : TYPO3_MODE;

				$res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
						$fields,
						$table,
						'tx_staticinfotables_hotlist',
						'',	// $foreign_table
						'AND tx_staticinfotables_hotlist.tablenames='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'tx_staticinfotables_hotlist').' AND tx_staticinfotables_hotlist.application='.$GLOBALS['TYPO3_DB']->fullQuoteStr($app,'tx_staticinfotables_hotlist'),
						'',
						'tx_staticinfotables_hotlist.sorting DESC',	// $orderBy
						$limit
					);

				$cnt = 0;
				$rows = array();
				while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{

					foreach ($titleFields as $titleField) {
						if ($row[$titleField]) {
							$rows[$row[$indexField]] = $row[$titleField];
							break;
						}
					}
					$cnt++;
				}
				$GLOBALS['TYPO3_DB']->sql_free_result($res);

				if (!isset($config['itemsProcFunc_config']['hotlistSort']) || $config['itemsProcFunc_config']['hotlistSort']) {
					asort ($rows);
				}

				foreach ($rows as $index => $title)	{
					$params['items'][] = array($title, $index, '');
					$cnt++;
				}
				if($cnt && !$config['itemsProcFunc_config']['hotlistOnly']) {
					$params['items'][] = array('--------------', '', '');
				}
			}

				// Set ORDER BY:
			$orderBy = $titleFields[0];

			if(!$config['itemsProcFunc_config']['hotlistOnly']) {
				$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, '1=1'.$where.t3lib_BEfunc::deleteClause($table), '', $orderBy);
				while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
					foreach ($titleFields as $titleField) {
						if ($row[$titleField]) {
							$params['items'][] = array($row[$titleField], $row[$indexField], '');
							break;
						}
					}
				}
				$GLOBALS['TYPO3_DB']->sql_free_result($res);
			}
		}
	}
Esempio n. 4
0
 /**
  * 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 = \tx_staticinfotables_div::getCurrentLanguage();
         $titleFields = \tx_staticinfotables_div::getTCAlabelField($table, TRUE, $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 = !$this->thisConfig['buttons.']['language.']['prefixLabelWithCode'] ? FALSE : TRUE;
         $postfixLabelWithCode = !$this->thisConfig['buttons.']['language.']['postfixLabelWithCode'] ? FALSE : TRUE;
         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;
 }
 /**
  * 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
  */
 function initLanguages($addWhere = '')
 {
     global $TYPO3_DB, $TSFE;
     $where = '1=1' . ($addWhere ? ' AND ' . $addWhere : '');
     $table = $this->tables['LANGUAGES'];
     $lang = $this->getCurrentLanguage();
     $nameArray = array();
     $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang);
     $prefixedTitleFields = array();
     foreach ($titleFields as $titleField) {
         $prefixedTitleFields[] = $table . '.' . $titleField;
     }
     $labelFields = implode(',', $prefixedTitleFields);
     $res = $TYPO3_DB->exec_SELECTquery($table . '.lg_iso_2,' . $table . '.lg_country_iso_2,' . $labelFields, $table, $where . ' AND lg_sacred = 0 AND lg_constructed = 0 ' . $TSFE->sys_page->enableFields($table));
     while ($row = $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] = $TSFE->csConv($row[$titleField], $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['charset']);
                 break;
             }
         }
     }
     $TYPO3_DB->sql_free_result($res);
     uasort($nameArray, 'strcoll');
     return $nameArray;
 }