/**
  * @param $table
  * @param $field
  */
 public static function convertTranslationField($table, $field)
 {
     $backup = $field . '_backup';
     $objDatabase = \Database::getInstance();
     // Backup the original column and then change the column type
     if (!$objDatabase->fieldExists($backup, $table, true)) {
         $objDatabase->query("ALTER TABLE `{$table}` ADD `{$backup}` text NULL");
         $objDatabase->query("UPDATE `{$table}` SET `{$backup}`=`{$field}`");
         $objDatabase->query("ALTER TABLE `{$table}` CHANGE `{$field}` `{$field}` int(10) unsigned NOT NULL default '0'");
         $objDatabase->query("UPDATE `{$table}` SET `{$field}`='0'");
     }
     $objRow = $objDatabase->query("SELECT id, {$backup} FROM {$table} WHERE {$backup}!=''");
     while ($objRow->next()) {
         if (is_numeric($objRow->{$backup})) {
             $intFid = $objRow->{$backup};
         } else {
             if (strlen($objRow->{$backup}) > 0) {
                 $intFid = \TranslationFieldsWidgetHelper::saveValuesAndReturnFid(\TranslationFieldsWidgetHelper::addValueToAllLanguages($objRow->{$backup}));
             } else {
                 $intFid = 0;
             }
         }
         $objDatabase->prepare("UPDATE {$table} SET {$field}=? WHERE id=?")->execute($intFid, $objRow->id);
     }
 }
Beispiel #2
0
 /**
  * @param $strField
  */
 protected function addTranslationContentToField($strField)
 {
     if ($this->Config->get($strField) === null) {
         $arrValues = array();
         \System::loadLanguageFile('tl_email', 'de', true);
         $arrValues['de'] = $GLOBALS['TL_LANG']['tl_email']['defaultContents'][$strField];
         \System::loadLanguageFile('tl_email', 'en', true);
         $arrValues['en'] = $GLOBALS['TL_LANG']['tl_email']['defaultContents'][$strField];
         // Load translation file by current language
         \System::loadLanguageFile('tl_email', null, true);
         $this->Config->persist($strField, \TranslationFieldsWidgetHelper::saveValuesAndReturnFid($arrValues));
     }
 }
 /**
  * @return string
  */
 public function generate()
 {
     $type = $this->hideInput ? 'password' : 'text';
     // Get post array
     $arrPost = \Input::post($this->strName);
     // Get languages array with values
     $this->varValue = \TranslationFieldsWidgetHelper::getTranslationsByFid($this->varValue);
     // Generate langauge fields
     $arrLngInputs = \TranslationFieldsWidgetHelper::getInputTranslationLanguages($this->varValue);
     $arrFields = array();
     $i = 0;
     foreach ($arrLngInputs as $value) {
         $arrFields[] = sprintf('<div class="tf_field_wrap tf_field_wrap_%s%s"><input type="%s" name="%s[%s]" id="ctrl_%s" class="tf_field tl_text" value="%s"%s onfocus="Backend.getScrollOffset()"></div>', $value, $i > 0 ? ' hide' : '', $type, $this->strName, $value, $this->strId . '_' . $value, specialchars($arrPost[$value] !== null ? $arrPost[$value] : @$this->varValue[$value]), $this->getAttributes());
         $i++;
     }
     // Get language button
     $strLngButton = \TranslationFieldsWidgetHelper::getCurrentTranslationLanguageButton();
     // Get language list
     $strLngList = \TranslationFieldsWidgetHelper::getTranslationLanguagesList($this->varValue);
     return sprintf('<div id="ctrl_%s" class="tf_wrap tf_text_wrap%s">%s%s%s</div>%s', $this->strId, $this->strClass != '' ? ' ' . $this->strClass : '', implode(' ', $arrFields), $strLngButton, $strLngList, $this->wizard);
 }
 /**
  * @return string
  * @throws \Exception
  */
 public function generate()
 {
     // Get post array
     $arrPost = \Input::post($this->strName);
     // Get languages array with values
     $this->varValue = \TranslationFieldsWidgetHelper::getTranslationsByFid($this->varValue);
     // Generate langauge fields
     $arrLngInputs = \TranslationFieldsWidgetHelper::getInputTranslationLanguages($this->varValue);
     $arrFields = array();
     for ($i = 0; $i < count($arrLngInputs); $i++) {
         $value = $arrLngInputs[$i];
         $strRte = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['rte'];
         $key = 'ctrl_' . $this->strId . '_' . $value;
         $strScript = $this->getRteScriptByTranslatedField($strRte, $key);
         $arrFields[] = sprintf('<div class="tf_field_wrap tf_field_wrap_%s%s"><textarea name="%s[%s]" id="%s" class="tf_field tl_textarea" rows="%s" cols="%s"%s onfocus="Backend.getScrollOffset()">%s</textarea>%s</div>', $value, $i > 0 ? ' hide' : '', $this->strName, $value, $key, $this->intRows, $this->intCols, $this->getAttributes(), specialchars($arrPost[$value] !== null ? $arrPost[$value] : @$this->varValue[$value]), $strScript);
     }
     // Get language button
     $strLngButton = \TranslationFieldsWidgetHelper::getCurrentTranslationLanguageButton();
     // Get language list
     $strLngList = \TranslationFieldsWidgetHelper::getTranslationLanguagesList($this->varValue);
     return sprintf('<div id="ctrl_%s_tf" class="tf_wrap tf_textarea_wrap%s%s">%s%s%s</div>%s', $this->strId, $this->strClass != '' ? ' ' . $this->strClass : '', !empty($this->rte) ? ' rte' : '', implode(' ', $arrFields), $strLngButton, $strLngList, $this->wizard);
 }
 /**
  * @return string
  */
 public function generate()
 {
     $arrUnits = array();
     foreach ($this->arrUnits as $arrUnit) {
         $arrUnits[] = sprintf('<option value="%s"%s>%s</option>', specialchars($arrUnit['value']), $this->isSelected($arrUnit), $arrUnit['label']);
     }
     if (!is_array($this->varValue)) {
         $this->varValue = array('value' => $this->varValue);
     }
     // Get languages array with values
     $this->varValue['value'] = \TranslationFieldsWidgetHelper::getTranslationsByFid($this->varValue['value']);
     // Generate langauge fields
     $arrLngInputs = \TranslationFieldsWidgetHelper::getInputTranslationLanguages($this->varValue['value']);
     $arrFields = array();
     $i = 0;
     foreach ($arrLngInputs as $value) {
         $arrFields[] = sprintf('<div class="tf_field_wrap tf_field_wrap_%s%s"><input type="text" name="%s[value][%s]" id="ctrl_%s" class="tf_field tl_text_unit" value="%s"%s onfocus="Backend.getScrollOffset()"></div>', $value, $i > 0 ? ' hide' : '', $this->strName, $value, $this->strId . '_' . $value, specialchars(@$this->varValue['value'][$value]), $this->getAttributes());
         $i++;
     }
     $strUnit = sprintf('<select name="%s[unit]" class="tl_select_unit" onfocus="Backend.getScrollOffset()">%s</select>', $this->strName, implode('', $arrUnits));
     // Get language button
     $strLngButton = \TranslationFieldsWidgetHelper::getCurrentTranslationLanguageButton();
     // Get language list
     $strLngList = \TranslationFieldsWidgetHelper::getTranslationLanguagesList($this->varValue);
     return sprintf('<div id="ctrl_%s" class="tf_wrap tf_text_unit_wrap%s">%s %s%s%s</div>%s', $this->strId, $this->strClass != '' ? ' ' . $this->strClass : '', implode(' ', $arrFields), $strUnit, $strLngButton, $strLngList, $this->wizard);
 }