Load a set of DCA files
public static loadDataContainer ( string $strTable, boolean $blnNoCache = false ) | ||
$strTable | string | The table name |
$blnNoCache | boolean | If true, the cache will be bypassed |
/** * @param DataContainer $objDC * @return DataContainer */ public function translateDCObject(DataContainer $objDC) { // Get table $strTable = $objDC->current()->getTable(); // Load current data container Controller::loadDataContainer($strTable); if (count($GLOBALS['TL_DCA'][$strTable]['fields']) > 0) { foreach ($GLOBALS['TL_DCA'][$strTable]['fields'] as $field => $arrValues) { $objDC->{$field} = $this->translateField($arrValues['inputType'], $objDC->{$field}); } } return $objDC; }
/** * @param $strTable * @return array */ protected function getHelpwizardReferencesBy($strTable) { $arrReferences = array(); Controller::loadLanguageFile($strTable); Controller::loadDataContainer($strTable); if (isset($GLOBALS['TL_DCA'][$strTable]['fields']) && is_array($GLOBALS['TL_DCA'][$strTable]['fields'])) { foreach ($GLOBALS['TL_DCA'][$strTable]['fields'] as $strField => $arrValues) { $strLabel = $strField; if (isset($arrValues['label'][0]) && strlen($arrValues['label'][0])) { $strLabel = $arrValues['label'][0]; } $arrReferences[] = array(sprintf('{{%s::%s|%s}}', 'accountmail', $strField, 'refresh'), sprintf($GLOBALS['TL_LANG']['MSC']['helpwizard_insert_tag'], $strLabel)); } } return $arrReferences; }
/** * Registers callback for given table. * * @param string $table * @param callable $callback */ public function register($table, callable $callback) { Controller::loadDataContainer($table); $chain = function () use($callback) { $args = func_get_args(); $result = null; if (is_callable($this->previous)) { $result = $this->executeCallback($this->previous, $args); } return $this->executeCallback($callback, [$args, $result]); }; if (4 === $GLOBALS['TL_DCA'][$table]['list']['sorting']['mode']) { $this->previous = $GLOBALS['TL_DCA'][$table]['list']['sorting']['child_record_callback']; $GLOBALS['TL_DCA'][$table]['list']['sorting']['child_record_callback'] = $chain; } else { $this->previous = $GLOBALS['TL_DCA'][$table]['list']['label']['label_callback']; $GLOBALS['TL_DCA'][$table]['list']['label']['label_callback'] = $chain; } }
/** * Run the controller and parse the template */ public function run() { $template = new BackendTemplate('be_main'); $template->main = ''; // Ajax request if ($_POST && Environment::get('isAjaxRequest')) { $this->objAjax = new Ajax(Input::post('action')); $this->objAjax->executePreActions(); } $strTable = Input::get('table'); $strField = Input::get('field'); // Define the current ID define('CURRENT_ID', Input::get('table') ? $this->Session->get('CURRENT_ID') : Input::get('id')); Controller::loadDataContainer($strTable); $strDriver = 'DC_' . $GLOBALS['TL_DCA'][$strTable]['config']['dataContainer']; $objDca = new $strDriver($strTable); $objDca->field = $strField; // Set the active record if ($this->Database->tableExists($strTable)) { /** @var Model $strModel $strModel */ $strModel = Model::getClassFromTable($strTable); if (class_exists($strModel)) { $objModel = $strModel::findByPk(Input::get('id')); if ($objModel !== null) { $objDca->activeRecord = $objModel; } } } // AJAX request if ($_POST && Environment::get('isAjaxRequest')) { $this->objAjax->executePostActions($objDca); } $partial = new BackendTemplate('be_rte_table_editor'); $template->isPopup = true; $template->main = $partial->parse(); $template->theme = Backend::getTheme(); $template->base = Environment::get('base'); $template->language = $GLOBALS['TL_LANGUAGE']; $template->title = specialchars($GLOBALS['TL_LANG']['MSC']['pagepicker']); $template->charset = Config::get('characterSet'); Config::set('debugMode', false); $template->output(); }
/** * @return array */ protected function listAllTranslationFields() { $arrStructure = array(); $arrFiles = $this->listDataContainerArrayFiles(); if (is_array($arrFiles)) { foreach ($arrFiles as $strFile) { // Load data container Controller::loadDataContainer($strFile); $arrFields =& $GLOBALS['TL_DCA'][$strFile]['fields']; foreach ($arrFields as $strField => $varValue) { switch ($varValue['inputType']) { case 'TranslationInputUnit': case 'TranslationTextArea': case 'TranslationTextField': $arrStructure[$strFile][] = $strField; break; } } } } return $arrStructure; }
/** * getAlbums function. * * @access public * @return object */ public function getAlbums() { if (count($this->items) > 0) { $objAlbum = \Photoalbums2AlbumModel::findMultipleByIds($this->items); if ($objAlbum !== null) { while ($objAlbum->next()) { // Translate fields if ($objAlbum->current() instanceof \Photoalbums2\Photoalbums2AlbumModel) { Controller::loadDataContainer($objAlbum->current()->getTable()); $arrRow = \TranslationFields::translateDCArray($objAlbum->row(), $objAlbum->current()->getTable()); $objAlbum->setRow($arrRow); } // Get preview image as Pa2Image object $objImage = new \Pa2Image($objAlbum->previewImage); $objAlbum->objPreviewImage = $objImage->getPa2Image(); // Deserialize arrays $objAlbum->images = deserialize($objAlbum->images); $objAlbum->imageSort = deserialize($objAlbum->imageSort); // Set sortedImageIds $objPa2ImageSorter = new \Pa2ImageSorter($objAlbum->imageSortType, $objAlbum->images, $objAlbum->imageSort); $objAlbum->arrSortedImageUuids = $objPa2ImageSorter->getSortedUuids(); } $objAlbum->reset(); } return $objAlbum; } return null; }
/** * @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); } } } }
/** * Load a data container. * * @param LoadDataContainerEvent $event The event. * * @return void */ public function handleLoadDataContainer(LoadDataContainerEvent $event) { parent::loadDataContainer($event->getName(), $event->isCacheIgnored()); }
private function hasParent() { /** @var Model $class */ $class = $this->getModelClass(); $table = $class::getTable(); Controller::loadDataContainer($table); return '' !== (string) $GLOBALS['TL_DCA'][$table]['config']['ptable']; }