public static getClassFromTable ( string $strTable ) : string | ||
$strTable | string | The table name |
Résultat | string | The model class name |
public static function getClassFromTable($strTable)
{
if (isset(static::$arrClassNames[$strTable])) {
return static::$arrClassNames[$strTable];
}
if (isset($GLOBALS['TL_MODELS'][$strTable])) {
static::$arrClassNames[$strTable] = $GLOBALS['TL_MODELS'][$strTable];
// see 4796
return static::$arrClassNames[$strTable];
} else {
$arrChunks = explode('_', $strTable);
if ($arrChunks[0] == 'tl') {
array_shift($arrChunks);
}
static::$arrClassNames[$strTable] = implode('', array_map('ucfirst', $arrChunks)) . 'Model';
return static::$arrClassNames[$strTable];
}
}
/** * @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); // 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 Controller::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) { $strInputType = $GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['inputType']; switch ($strInputType) { case 'TranslationInputUnit': case 'TranslationTextArea': case 'TranslationTextField': $intFid = $varValue; if ($strInputType == 'TranslationInputUnit') { $arrDeserialized = deserialize($varValue); $intFid = $arrDeserialized['value']; } // Get translation values $objTranslation = TranslationFieldsModel::findByFid($intFid); 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); } } } }