/** * @return string */ public function generate() { $allowedDCA = array('tl_module', 'tl_page'); $doNotSetByType = array('wrapper_field', 'legend_start', 'legend_end', 'widget', 'fulltext_search', 'map_field', 'geo_locator'); $doNotSetByID = array('orderBy', 'sorting_fields', 'pagination', 'auto_item', 'auto_page'); if (!in_array($this->strTable, $allowedDCA)) { return 'Taxonomy field is not allowed to used in ' . $this->strTable; } // contao if (!is_array($this->varValue)) { $this->varValue = array(array('')); } $this->import('Database'); $moduleDB = null; if ($this->strTable == 'tl_module') { $moduleDB = $this->Database->prepare("SELECT f_select_module, f_select_wrapper FROM tl_module WHERE id = ?")->execute($this->currentRecord)->row(); } $modulename = $moduleDB ? $moduleDB['f_select_module'] : ''; $wrapperID = $moduleDB ? $moduleDB['f_select_wrapper'] : ''; if ($this->strTable == 'tl_module' && (!$modulename || !$wrapperID)) { return '<p>Please select Backend Modul</p>'; } if ($this->strTable == 'tl_module' && !$this->Database->tableExists($modulename)) { return '<p>' . $modulename . ' do not exist! </p>'; } $modeSettingsDB = null; // if ($this->strTable == 'tl_module') { $modeSettingsDB = $this->Database->prepare('SELECT tl_fmodules.tablename, tl_fmodules.id AS fmoduleID, tl_fmodules_filters.* FROM tl_fmodules JOIN tl_fmodules_filters ON tl_fmodules.id = tl_fmodules_filters.pid WHERE tablename = ? ORDER BY sorting')->execute($modulename); $this->arrWrapper = $this->Database->prepare('SELECT * FROM ' . $modulename . ' WHERE id = ?')->execute($wrapperID)->row(); } // if ($this->strTable == 'tl_page') { $modeSettingsDB = $this->Database->prepare('SELECT tl_fmodules.tablename, tl_fmodules.id AS fmoduleID, tl_fmodules_filters.* FROM tl_fmodules JOIN tl_fmodules_filters ON tl_fmodules.id = tl_fmodules_filters.pid ORDER BY sorting')->execute(); } // if ($this->arrWrapper == null && $this->strTable == 'tl_page') { $options = array(); while ($modeSettingsDB->next()) { if (in_array($modeSettingsDB->fieldID, $doNotSetByID)) { continue; } if (in_array($modeSettingsDB->type, $doNotSetByType)) { continue; } $options[$modeSettingsDB->fieldID] = $this->Database->prepare('SELECT ' . $modeSettingsDB->fieldID . ' FROM ' . $modeSettingsDB->tablename . '')->execute()->row()[$modeSettingsDB->fieldID]; } $this->arrWrapper = $options; $modeSettingsDB->reset(); } $savedValues = $this->varValue; $defaultSet = array('filterValue' => '', 'overwrite' => '0'); if ($modeSettingsDB->count() < 1) { return 'no fields found'; } $input = array(); foreach ($savedValues as $fid => $savedValue) { $input[$fid] = $savedValue; } while ($modeSettingsDB->next()) { if ($modeSettingsDB->dataFromTaxonomy == '1' && $this->strTable == 'tl_page') { continue; } if ($modeSettingsDB->reactToTaxonomy == '1' && $this->strTable == 'tl_page') { continue; } if (in_array($modeSettingsDB->fieldID, $doNotSetByID)) { continue; } if (in_array($modeSettingsDB->type, $doNotSetByType)) { continue; } $options = $this->arrWrapper[$modeSettingsDB->fieldID]; $viewObject = array("active" => $input[$modeSettingsDB->fieldID]['active'] ? '1' : '0', "fieldID" => $modeSettingsDB->fieldID, "type" => $modeSettingsDB->type, "title" => $modeSettingsDB->title, "negate" => $modeSettingsDB->negate, "description" => $modeSettingsDB->description, 'dataFromTable' => $modeSettingsDB->dataFromTable, "fieldAppearance" => $modeSettingsDB->fieldAppearance, "isInteger" => $modeSettingsDB->isInteger, "addTime" => $modeSettingsDB->addTime, "dataFromTaxonomy" => $modeSettingsDB->dataFromTaxonomy, "reactToTaxonomy" => $modeSettingsDB->reactToTaxonomy, "reactToField" => $modeSettingsDB->reactToField, "options" => !deserialize($options) ? array() : deserialize($options), "set" => $input[$modeSettingsDB->fieldID]['set'] ? $input[$modeSettingsDB->fieldID]['set'] : $defaultSet); if ($viewObject['fieldID'] == 'address_country') { $countries = $this->getCountries(); $viewObject['options'] = DiverseFunction::conformOptionsArray($countries); } $this->modeViewObject[] = $viewObject; } $return = '<div> <div> <div id="ctrl_' . $this->strId . '"> ' . $this->setModeBlocks() . ' </div> </div> </div>'; return $return; }