/** * @param $intFid * @return array */ public static function getTranslationsByFid($intFid) { $arrData = array(); // Get translation object $objTranslation = \TranslationFieldsModel::findByFid($intFid); if ($objTranslation !== null) { while ($objTranslation->next()) { $arrData[$objTranslation->language] = $objTranslation->content; } } return $arrData; }
/** * @param $intFid * @param bool $onlyActiveLanguages * @return array */ public static function getTranslationsByFid($intFid, $onlyActiveLanguages = false) { // Get empty tranlation languages $arrData = self::getEmptyTranslationLanguages(); if (is_numeric($intFid) && $intFid > 0) { $objTranslation = \TranslationFieldsModel::findByFid($intFid); if ($objTranslation !== null) { while ($objTranslation->next()) { $arrData[$objTranslation->language] = $objTranslation->content; } } } // If only active languages should be returned if ($onlyActiveLanguages) { $arrActiveData = array(); $arrKeys = self::getTranslationLanguageKeys(); if (is_array($arrKeys) && count($arrKeys) > 0) { foreach ($arrKeys as $key) { $arrActiveData[$key] = !isset($arrData[$key]) ? '' : $arrData[$key]; } } // Replace data with active data $arrData = $arrActiveData; } // Return data array return $arrData; }
/** * @param $dc */ public static function deleteDataRecord($dc) { // If this is not the backend than return if (TL_MODE != 'BE') { return; } // Check if there is an active record if ($dc instanceof \DataContainer && $dc->activeRecord) { $intId = $dc->activeRecord->id; $strTable = $dc->table; $strModel = '\\' . \Model::getClassFromTable($strTable); $objTranslationController = new \TranslationController(); // Return if the class does not exist (#9 thanks to tsarma) if (!class_exists($strModel)) { return; } // Get object from model $objModel = $strModel::findByPk($intId); if ($objModel !== null) { $arrData = $objModel->row(); if (is_array($arrData) && count($arrData) > 0) { // Load current data container $objTranslationController->loadDataContainer($strTable); // Get tl_undo data $objUndo = \Database::getInstance()->prepare("SELECT * FROM tl_undo WHERE fromTable=? ORDER BY id DESC")->limit(1)->execute($dc->table); $arrSet = $objUndo->row(); // Deserialize tl_undo data $arrSet['data'] = deserialize($arrSet['data']); foreach ($arrData as $strField => $varValue) { switch ($GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['inputType']) { case 'TranslationInputUnit': case 'TranslationTextArea': case 'TranslationTextField': // Get translation values $objTranslation = \TranslationFieldsModel::findByFid($varValue); if ($objTranslation !== null) { while ($objTranslation->next()) { $t = \TranslationFieldsModel::getTable(); // Add cross table record to undo data $arrSet['data'][$t][] = $objTranslation->row(); // Delete translation $objTranslation->delete(); } } break; } } // Serialize tl_undo data $arrSet['data'] = serialize($arrSet['data']); // Update tl_undo \Database::getInstance()->prepare("UPDATE tl_undo %s WHERE id=?")->set($arrSet)->execute($objUndo->id); } } } }