Пример #1
0
 /**
  * @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);
     }
 }
Пример #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));
     }
 }
 /**
  * @param mixed $varInput
  * @return mixed
  */
 protected function validator($varInput)
 {
     // Get array with language id
     $arrData = $this->activeRecord ? $this->activeRecord->{$this->strName} : $GLOBALS['TL_CONFIG'][$this->strName];
     if (is_array($varInput['value'])) {
         // Check if translation fields should not be empty saved
         if (!$GLOBALS['TL_CONFIG']['dontfillEmptyTranslationFields']) {
             // Fill all empty fields with the content of the fallback field
             $varInput['value'] = \TranslationFieldsWidgetHelper::addFallbackValueToEmptyField($varInput['value']);
             parent::validator($varInput['value']);
         } else {
             // Check only the first field
             parent::validator($varInput['value'][key($varInput['value'])]);
         }
     }
     $arrData = deserialize($arrData);
     // Save values and return fid
     $varInput['value'] = \TranslationFieldsWidgetHelper::saveValuesAndReturnFid($varInput['value'], $arrData['value']);
     return $varInput;
 }
 /**
  * @param mixed $varInput
  * @return mixed
  */
 protected function validator($varInput)
 {
     // Get language id
     $intId = $this->activeRecord ? $this->activeRecord->{$this->strName} : $GLOBALS['TL_CONFIG'][$this->strName];
     // Check if translation fields should not be empty saved
     if (!$GLOBALS['TL_CONFIG']['dontfillEmptyTranslationFields']) {
         // Fill all empty fields with the content of the fallback field
         $varInput = \TranslationFieldsWidgetHelper::addFallbackValueToEmptyField($varInput);
         parent::validator($varInput);
     } else {
         // Check only the first field
         parent::validator($varInput[key($varInput)]);
     }
     // Check if array
     if (is_array($varInput)) {
         if (!parent::hasErrors()) {
             // Save values and return fid
             return \TranslationFieldsWidgetHelper::saveValuesAndReturnFid($varInput, $intId);
         }
     }
     return $intId;
 }