Example #1
0
 /**
  * Check permissions for that entry
  * @return void
  */
 public static function check()
 {
     $session = \Session::getInstance()->getData();
     if (\Input::get('act') == 'delete' && in_array(\Input::get('id'), static::getUndeletableIds())) {
         \System::log('Product type ID ' . \Input::get('id') . ' is used in an order and can\'t be deleted', __METHOD__, TL_ERROR);
         \Controller::redirect('contao/main.php?act=error');
     } elseif (\Input::get('act') == 'deleteAll' && is_array($session['CURRENT']['IDS'])) {
         $arrDeletable = array_diff($session['CURRENT']['IDS'], static::getUndeletableIds());
         if (count($arrDeletable) != count($session['CURRENT']['IDS'])) {
             $session['CURRENT']['IDS'] = array_values($arrDeletable);
             \Session::getInstance()->setData($session);
             \Message::addInfo($GLOBALS['TL_LANG']['MSC']['undeletableRecords']);
         }
     }
     // Disable variants if no such attributes are available
     \Controller::loadDataContainer('tl_iso_product');
     $blnVariants = false;
     foreach ($GLOBALS['TL_DCA']['tl_iso_product']['fields'] as $strName => $arrConfig) {
         $objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$strName];
         if (null !== $objAttribute && $objAttribute->isVariantOption()) {
             $blnVariants = true;
             break;
         }
     }
     if (!$blnVariants) {
         \System::loadLanguageFile('explain');
         unset($GLOBALS['TL_DCA']['tl_iso_producttype']['subpalettes']['variants']);
         $GLOBALS['TL_DCA']['tl_iso_producttype']['fields']['variants']['input_field_callback'] = function ($dc) {
             // Make sure variants are disabled in this product type (see #1114)
             \Database::getInstance()->prepare("UPDATE " . $dc->table . " SET variants='' WHERE id=?")->execute($dc->id);
             return '<br><p class="tl_info">' . $GLOBALS['TL_LANG']['XPL']['noVariantAttributes'] . '</p>';
         };
     }
 }
Example #2
0
 /**
  * Add this filter to the module's template or get the URL params
  * @param   array
  * @param   Contao\Template
  * @param   Contao\Module
  * @param   boolean
  * @return  mixed string|bool|void
  */
 public static function generateFilter(&$arrCategories, &$objTemplate, $objModule, $blnGenURL = false)
 {
     \System::loadLanguageFile(Product::getTable());
     \Controller::loadDataContainer(Product::getTable());
     $arrFields = deserialize($objModule->iso_sortingFields, true);
     if ($blnGenURL) {
         //return the URL fragment needed for this filter to pass to the lister
         if (\Input::post(static::$strKey) && in_array(str_replace(array('-asc', '-desc'), '', \Input::post(static::$strKey)), $arrFields)) {
             return static::$strKey . '/' . urlencode(\Input::post(static::$strKey));
         }
         return false;
     }
     $arrAvailable = array('' => $GLOBALS['TL_LANG']['MSC']['relevancyFilterLabel']);
     foreach ($arrFields as $field) {
         list($asc, $desc) = static::getSortingLabels($field);
         $strLabel = is_array($GLOBALS['TL_DCA'][Product::getTable()]['fields'][$field]['label']) ? $GLOBALS['TL_DCA'][Product::getTable()]['fields'][$field]['label'][0] : $field;
         $arrAvailable[$field . '-asc'] = $strLabel . ' ' . $asc;
         $arrAvailable[$field . '-desc'] = $strLabel . ' ' . $desc;
     }
     if (count($arrAvailable) > 0) {
         $objTemplate->hasSorting = true;
         $objTemplate->sort = $arrAvailable;
         $objTemplate->sortselected = \Input::get(static::$strKey) ?: ($objModule->iso_listingSortField ? $objModule->iso_listingSortField . '-' . strtolower($objModule->iso_listingSortDirection) : '');
         $objTemplate->psortLabel = $GLOBALS['TL_LANG']['MSC'][static::$strKey . 'FilterLabel'];
     }
 }
 public static function addShareFields($strDca)
 {
     \Controller::loadDataContainer($strDca);
     $arrDca =& $GLOBALS['TL_DCA'][$strDca];
     $arrDca['fields']['shareToken'] = array('eval' => array('doNotCopy' => true), 'sql' => "varchar(23) NOT NULL default ''");
     $arrDca['fields']['shareTokenTime'] = array('eval' => array('doNotCopy' => true), 'sql' => "int(10) unsigned NOT NULL default '0'");
 }
 public function getFilter($objModule)
 {
     \Controller::loadDataContainer('tl_calendar_events');
     $arrFilter = array();
     $arrFields = deserialize($objModule->formHybridEditable, true);
     // Return if there are no fields
     if (!is_array($arrFields) || empty($arrFields)) {
         return $arrFilter;
     }
     $objHelper = new EventFilterHelper();
     $arrEventTypeArchives = deserialize($objModule->cal_eventTypesArchive, true);
     foreach ($arrFields as $strKey) {
         $arrData = $GLOBALS['TL_DCA']['tl_calendar_events']['fields'][$strKey];
         if (!is_array($arrData) || empty($arrData)) {
             continue;
         }
         $arrFilter[$strKey] = $objHelper->getValueByDca(\Input::get($strKey), $arrData);
         if (!$objModule->cal_combineEventTypesArchive && count($arrEventTypeArchives) > 0 && strrpos($strKey, 'eventtypes', -strlen($strKey)) !== FALSE) {
             // unset eventtypes
             unset($arrFilter[$strKey]);
             // use multiple eventtypes
             foreach ($arrEventTypeArchives as $intArchive) {
                 $strArchiveKey = $strKey . '_' . $intArchive;
                 $arrFilter[$strArchiveKey] = $objHelper->getValueByDca(\Input::get($strArchiveKey), $arrData);
             }
         }
     }
     return $arrFilter;
 }
 /**
  * Generate the checkout step
  * @return  string
  */
 public function generate()
 {
     // Make sure field data is available
     \Controller::loadDataContainer('tl_iso_product_collection');
     \System::loadLanguageFile('tl_iso_product_collection');
     $objTemplate = new Template($this->strTemplate);
     $varValue = null;
     $objWidget = new FormTextArea(FormTextArea::getAttributesFromDca($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField], $this->strField, $varValue, $this->strField, $this->strTable, $this));
     $objWidget->storeValues = true;
     if (\Input::post('FORM_SUBMIT') == $this->strFormId) {
         $objWidget->validate();
         $varValue = $objWidget->value;
         // Do not submit the field if there are errors
         if ($objWidget->hasErrors()) {
             $doNotSubmit = true;
         } elseif ($objWidget->submitInput()) {
             $objOrder = Isotope::getCart()->getDraftOrder();
             // Store the form data
             $_SESSION['FORM_DATA'][$this->strField] = $varValue;
             // Set the correct empty value (see #6284, #6373)
             if ($varValue === '') {
                 $varValue = $objWidget->getEmptyValue();
             }
             // Set the new value
             if ($varValue !== $objOrder->{$this->strField}) {
                 $objOrder->{$this->strField};
             }
         }
     }
     $objTemplate->headline = $GLOBALS['TL_LANG'][$this->strTable][$this->strField][0];
     $objTemplate->customerNotes = $objWidget->parse();
     return $objTemplate->parse();
 }
 public static function run()
 {
     $objDatabase = \Database::getInstance();
     \Controller::loadDataContainer('tl_module');
     $arrRenameFields = array('tl_module' => array('jumpToSuccess' => array('name' => 'jumpTo', 'syncValue' => true), 'jumpToSuccessPreserveParams' => array('name' => 'formHybridJumpToPreserveParams', 'syncValue' => false), 'allowIdAsGetParameter' => array('name' => 'formHybridAllowIdAsGetParameter', 'syncValue' => true), 'idGetParameter' => array('name' => 'formHybridIdGetParameter', 'syncValue' => true), 'appendIdToUrlOnCreation' => array('name' => 'formHybridAppendIdToUrlOnCreation', 'syncValue' => true)));
     foreach ($arrRenameFields as $strTable => $arrFields) {
         if (!$objDatabase->tableExists($strTable)) {
             continue;
         }
         foreach ($arrFields as $strOldName => $arrConfig) {
             if (!$objDatabase->fieldExists($strOldName, $strTable)) {
                 continue;
             }
             $strNewName = $arrConfig['name'];
             $sql =& $GLOBALS['TL_DCA']['tl_module']['fields'][$strNewName]['sql'];
             if (!$objDatabase->fieldExists($arrConfig['name'], $strTable) && $sql) {
                 $sql =& $GLOBALS['TL_DCA']['tl_module']['fields'][$strNewName]['sql'];
                 $objDatabase->query("ALTER TABLE {$strTable} ADD `{$strNewName}` {$sql}");
             }
             if (!$arrConfig['syncValue']) {
                 continue;
             }
             $objDatabase->prepare('UPDATE ' . $strTable . ' SET ' . $arrConfig['name'] . ' = ' . $strOldName)->execute();
         }
     }
     return;
 }
 public function run($blnInstalled)
 {
     if ($blnInstalled) {
         \Controller::loadDataContainer('tl_iso_product');
         $arrFields = array();
         foreach ($GLOBALS['TL_DCA']['tl_iso_product']['fields'] as $field => $config) {
             if ($config['inputType'] == 'mediaManager') {
                 $arrFields[] = $field;
             }
         }
         if (empty($arrFields)) {
             return;
         }
         $objProducts = \Database::getInstance()->query("\n                SELECT * FROM tl_iso_product WHERE language=''\n            ");
         while ($objProducts->next()) {
             foreach ($arrFields as $field) {
                 $arrUpdate = array();
                 $arrData = deserialize($objProducts->{$field});
                 if (!empty($arrData) && is_array($arrData)) {
                     foreach ($arrData as $k => $image) {
                         if ($image['translate'] == '') {
                             $arrData[$k]['translate'] = 'none';
                         }
                     }
                     $arrUpdate[$field] = serialize($arrData);
                 }
             }
             if (!empty($arrUpdate)) {
                 \Database::getInstance()->prepare("UPDATE tl_iso_product %s WHERE id=?")->set($arrUpdate)->execute($objProducts->id);
             }
         }
     }
 }
 public static function run()
 {
     $objDatabase = \Database::getInstance();
     \Controller::loadDataContainer('tl_extcss');
     $arrFields = array('tl_extcss' => array('bootstrapVariablesSRC', 'observeFolderSRC'), 'tl_extcss_file' => array('src'), 'tl_extjs_file' => array('src'));
     if (version_compare(VERSION, '3.2', '>=')) {
         foreach ($arrFields as $strTable => $arrNames) {
             if (!$objDatabase->tableExists($strTable)) {
                 continue;
             }
             // convert file fields
             foreach ($objDatabase->listFields($strTable) as $arrField) {
                 // with extassets 1.1.1 bootstrapVariablesSRC changed to variablesSRC
                 if ($arrField['name'] == 'bootstrapVariablesSRC') {
                     if (!$objDatabase->fieldExists('variablesSRC', $strTable)) {
                         $sql =& $GLOBALS['TL_DCA']['tl_extcss']['fields']['variablesSRC']['sql'];
                         $objDatabase->query("ALTER TABLE {$strTable} ADD `variablesSRC` {$sql}");
                         $sql =& $GLOBALS['TL_DCA']['tl_extcss']['fields']['variablesOrderSRC']['sql'];
                         $objDatabase->query("ALTER TABLE {$strTable} ADD `variablesOrderSRC` {$sql}");
                     }
                     $objGroups = $objDatabase->execute('SELECT * FROM ' . $strTable . ' WHERE bootstrapVariablesSRC IS NOT NULL AND variablesSRC IS NULL');
                     while ($objGroups->next()) {
                         $variables = serialize(array($objGroups->bootstrapVariablesSRC));
                         $objDatabase->prepare('UPDATE ' . $strTable . ' SET variablesSRC = ?, variablesOrderSRC = ? WHERE id = ?')->execute($variables, $variables, $objGroups->id);
                     }
                     $objDatabase->query("ALTER TABLE {$strTable} DROP `bootstrapVariablesSRC`");
                 }
                 if (in_array($arrField['name'], $arrNames)) {
                     \Database\Updater::convertSingleField($strTable, $arrField['name']);
                 }
             }
         }
     }
     return;
 }
Example #9
0
 /**
  * Construct the model
  *
  * @param Result $objResult
  */
 public function __construct(Result $objResult = null)
 {
     parent::__construct($objResult);
     if (!is_array($GLOBALS['ISO_ADR'])) {
         \Controller::loadDataContainer(static::$strTable);
         \System::loadLanguageFile('addresses');
     }
 }
Example #10
0
 /**
  * Get SQL statement for a DCA field
  *
  * @param $strField
  * @param $strTable
  *
  * @return string
  */
 private function getSqlForField($strField, $strTable)
 {
     \Controller::loadDataContainer($strTable);
     $strSql = (string) $GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['sql'];
     if ($strSql == '') {
         throw new \LogicException('Field "' . $strField . '" is not defined in "' . $strTable . '"');
     }
     return $strSql;
 }
 /**
  * Add fieldpalette fields to tl_fieldpalette
  *
  * @param string $strTable
  *
  * @return boolean false if Datacontainer not supported
  */
 public function loadDataContainerHook($strTable)
 {
     if ($strTable !== \Config::get('fieldpalette_table')) {
         \Controller::loadDataContainer(\Config::get('fieldpalette_table'));
     }
     $dc =& $GLOBALS['TL_DCA'][\Config::get('fieldpalette_table')];
     // dynamically set fieldpalette fields from parent table
     if ($strTable == \Config::get('fieldpalette_table') && \Input::get('table') == \Config::get('fieldpalette_table')) {
         return FieldPalette::loadDynamicPaletteByParentTable(\Input::get('act'), $strTable, $dc);
     }
     FieldPalette::registerFieldPalette($dc, $strTable, $strTable);
 }
 public static function prepareData(\Model $objModel, $strTable, array $arrDca = array(), $objDc = null, $arrFields = array(), array $arrSkipFields = array())
 {
     if ($objDc === null) {
         $objDc = DC_Table::getInstanceFromModel($objModel);
     }
     if (empty($arrDca)) {
         \Controller::loadDataContainer($objModel->getTable());
         $arrDca = $GLOBALS['TL_DCA'][$objModel->getTable()];
     }
     $arrSubmissionData = array();
     $arrRow = $objModel->row();
     $arrSubmission = array();
     foreach (array_keys($arrRow) as $strName) {
         $varValue = $arrRow[$strName];
         if (empty($varValue)) {
             continue;
         }
         $arrData = $arrDca['fields'][$strName];
         $arrFieldData = static::prepareDataField($strName, $varValue, $arrData, $strTable, $objDc);
         $arrSubmissionData[$strName] = $arrFieldData;
         $strSubmission = $arrFieldData['submission'];
         $varValue = deserialize($varValue);
         // multicolumnwizard support
         if ($arrData['inputType'] == 'multiColumnWizard') {
             foreach ($varValue as $arrSet) {
                 if (!is_array($arrSet)) {
                     continue;
                 }
                 // new line
                 $strSubmission .= "\n";
                 foreach ($arrSet as $strSetName => $strSetValue) {
                     $arrSetData = $arrData['eval']['columnFields'][$strSetName];
                     $arrFieldData = static::prepareDataField($strSetName, $strSetValue, $arrSetData, $strTable, $objDc);
                     // intend new line
                     $strSubmission .= "\t" . $arrFieldData['submission'];
                 }
                 // new line
                 $strSubmission .= "\n";
             }
         }
         $arrSubmissionData['submission_all'] .= $strSubmission;
         if (in_array($strName, $arrFields) && !in_array($strName, $arrSkipFields)) {
             $arrSubmission[$strName] = $strSubmission;
         }
     }
     // order submission by arrFields
     $strSubmissionAll = '';
     foreach ($arrFields as $strName) {
         $strSubmissionAll .= $arrSubmission[$strName];
     }
     $arrSubmissionData['submission'] = $strSubmissionAll;
     return $arrSubmissionData;
 }
 public function getFilterFields(\DataContainer $dataContainer)
 {
     \Controller::loadDataContainer('tl_calendar_events');
     \Controller::loadLanguageFile('tl_calendar_events');
     global $container, $TL_LANG;
     $options = array('pid' => $TL_LANG['tl_module']['filterPropertyCalendar'], 'author' => $TL_LANG['tl_module']['filterPropertyAuthor'], 'startDate' => $TL_LANG['tl_module']['filterPropertyMonth']);
     /** @var EventDispatcher $eventDispatcher */
     $eventDispatcher = $container['event-dispatcher'];
     $event = new GetFilterOptionsEvent();
     $event->setOptions($options);
     $eventDispatcher->dispatch(GetFilterOptionsEvent::NAME, $event);
     return $event->getOptions();
 }
 public static function adjustPalettesForLists(\DataContainer $objDc)
 {
     \Controller::loadDataContainer('tl_module');
     \System::loadLanguageFile('tl_module');
     if (($objModule = \ModuleModel::findByPk($objDc->id)) !== null) {
         $arrDca =& $GLOBALS['TL_DCA']['tl_module'];
         if (\HeimrichHannot\Haste\Util\Module::isSubModuleOf($objModule->type, 'HeimrichHannot\\FrontendEdit\\ModuleList')) {
             $arrDca['palettes'][MODULE_FRONTENDEDIT_MEMBER_LIST] = str_replace('filterArchives', 'filterGroups', $arrDca['palettes'][MODULE_FRONTENDEDIT_MEMBER_LIST]);
             // override labels for suiting a list module
             $arrDca['fields']['formHybridAddDefaultValues']['label'] =& $GLOBALS['TL_LANG']['tl_module']['formHybridAddDefaultFilterValues'];
             $arrDca['fields']['formHybridDefaultValues']['label'] =& $GLOBALS['TL_LANG']['tl_module']['formHybridDefaultFilterValues'];
         }
     }
 }
 protected function createObjectFromMapping($arrSourceItem)
 {
     $objDatabase = \Database::getInstance();
     \Controller::loadDataContainer($this->dbTargetTable);
     $t = $this->dbTargetTable;
     $arrItem = array();
     foreach (deserialize($this->fileFieldMapping, true) as $arrConfig) {
         if ($arrConfig['type'] == 'source') {
             $varValue = $arrSourceItem[$arrConfig['source'] - 1];
         } else {
             if ($arrConfig['type'] == 'value' && !empty($arrConfig['value'])) {
                 $varValue = $arrConfig['value'];
             }
         }
         if ($varValue) {
             $varValue = $arrConfig['transformToArray'] ? serialize(explode($this->arrayDelimiter, $varValue)) : $varValue;
         }
         $this->setObjectValueFromMapping($arrItem, $varValue, $arrConfig['target']);
         if ($varValue === null) {
             unset($arrItem[$arrConfig['target']]);
             continue;
         }
     }
     if (!$this->dryRun) {
         if (!$this->skipInsertion) {
             $strQuery = "INSERT INTO {$t} (" . implode(',', array_keys($arrItem)) . ") VALUES(" . implode(',', array_map(function ($val) {
                 return "'" . str_replace("'", "''", $val) . "'";
             }, array_values($arrItem))) . ")";
             $arrItem['id'] = $objDatabase->execute($strQuery)->insertId;
         }
         // do after item has been created,
         $this->runAfterSaving($arrItem, $arrSourceItem);
         // save updates
         if (!$this->skipUpdateAfterSave) {
             $arrTargetItemPrepared = array();
             foreach ($arrItem as $strKey => $strVal) {
                 if ($strKey == 'id') {
                     continue;
                 }
                 $strVal = str_replace("'", "''", $strVal);
                 $arrTargetItemPrepared[] = "{$this->dbTargetTable}.{$strKey}='{$strVal}'";
             }
             // update all values to the db
             $strQuery = "UPDATE {$this->dbTargetTable} SET " . implode(',', $arrTargetItemPrepared) . " WHERE id=" . $arrItem['id'];
             \Database::getInstance()->execute($strQuery);
         }
     }
     return $arrItem;
 }
 /**
  * Initialize the object
  *
  * @param \ParticipationModel $objConfig
  */
 public function __construct($objConfig)
 {
     parent::__construct();
     if ($objConfig instanceof \Model) {
         $this->objModel = $objConfig;
     } elseif ($objConfig instanceof \Model\Collection) {
         $this->objModel = $objConfig->current();
     }
     $this->arrData = $objConfig->row();
     \Controller::loadDataContainer($objConfig->type);
     \Controller::loadLanguageFile('default');
     $this->strTable = $objConfig->type;
     $this->ptable = $GLOBALS['TL_DCA'][$this->strTable]['config']['ptable'];
     $this->ctable = $GLOBALS['TL_DCA'][$this->strTable]['config']['ctable'];
 }
Example #17
0
 /**
  * Load all data containers
  */
 protected function loadDataContainers()
 {
     foreach (\ModuleLoader::getActive() as $module) {
         $dir = 'system/modules/' . $module . '/dca';
         if (!is_dir(TL_ROOT . '/' . $dir)) {
             continue;
         }
         foreach (scan(TL_ROOT . '/' . $dir) as $file) {
             if (substr($file, -4) != '.php') {
                 continue;
             }
             \Controller::loadDataContainer(substr($file, 0, -4));
         }
     }
 }
 public static function getParsedActivities($intCompany, \Module $objModule = null)
 {
     $strResult = '';
     \Controller::loadDataContainer('tl_company_activity');
     \System::loadLanguageFile('tl_company_activity');
     if (($objActivities = static::getActivities($intCompany)) !== null) {
         while ($objActivities->next()) {
             $objTemplate = new \FrontendTemplate('company_activity_default');
             $objTemplate->setData($objActivities->row());
             $objTemplate->module = $objModule;
             $strResult .= $objTemplate->parse();
         }
     }
     return $strResult;
 }
 public static function getMemberFieldsAsOptions()
 {
     \System::loadLanguageFile('tl_member');
     \Controller::loadDataContainer('tl_member');
     $arrOptions = array();
     $arrDca = $GLOBALS['TL_DCA']['tl_member'];
     foreach (array_merge($arrDca['palettes']['__selector__'], array_keys($arrDca['fields'])) as $strField) {
         $arrLabel = $arrDca['fields'][$strField]['label'];
         if (is_array($arrLabel)) {
             $arrLabel = $arrLabel[0];
         }
         $arrOptions[$strField] = $arrLabel ?: $strField;
     }
     asort($arrOptions);
     return array_unique($arrOptions);
 }
 /**
  * Initialize the object
  *
  * @param \ParticipationModel $objParticipation
  */
 public function __construct($objParticipation)
 {
     parent::__construct();
     if ($objParticipation instanceof \Model) {
         $this->objParticipation = $objParticipation;
     } elseif ($objParticipation instanceof \Model\Collection) {
         $this->objParticipation = $objParticipation->current();
     }
     $this->objParticipationArchive = $this->objParticipation->getRelated('pid');
     $this->arrData = $objParticipation->row();
     \Controller::loadDataContainer($objParticipation->targetType);
     \Controller::loadLanguageFile('default');
     $this->strTable = $objParticipation->targetType;
     $this->ptable = $GLOBALS['TL_DCA'][$this->targetType]['config']['ptable'];
     $this->ctable = $GLOBALS['TL_DCA'][$this->targetType]['config']['ctable'];
 }
 /**
  * Set the entity defaults from dca config (for new model entry)
  *
  * @param \Model $objModel
  *
  * @return \Model The modified model, containing the default values from all dca fields
  */
 public static function setDefaultsFromDca(\Model $objModel)
 {
     $strTable = $objModel->getTable();
     \Controller::loadDataContainer($strTable);
     // Get all default values for the new entry
     foreach ($GLOBALS['TL_DCA'][$strTable]['fields'] as $k => $v) {
         // Use array_key_exists here (see #5252)
         if (array_key_exists('default', $v)) {
             $objModel->{$k} = is_array($v['default']) ? serialize($v['default']) : $v['default'];
             // Encrypt the default value (see #3740)
             if ($GLOBALS['TL_DCA'][$strTable]['fields'][$k]['eval']['encrypt']) {
                 $objModel->{$k} = \Encryption::encrypt($objModel->{$k});
             }
         }
     }
     return $objModel;
 }
Example #22
0
 /**
  * Construct mapper from DCA fields
  *
  * @param string $strTable
  *
  * @throws \Exception
  */
 public function __construct($strTable)
 {
     if (!is_array($GLOBALS['TL_DCA'][$strTable])) {
         \Controller::loadDataContainer($strTable);
     }
     if (!is_array($GLOBALS['TL_DCA'][$strTable]['fields'])) {
         throw new \Exception('DCA for table "' . $strTable . '" does not have any fields.');
     }
     $this->arrMap = array();
     // Build the mapper
     foreach ($GLOBALS['TL_DCA'][$strTable]['fields'] as $k => $v) {
         if (!is_array($v['eval']) || !array_key_exists('haste_csv_position', $v['eval'])) {
             continue;
         }
         $this->arrMap[$k] = $v['eval']['haste_csv_position'];
     }
 }
 /**
  * Constructor.
  *
  * @param \ModuleModel|object $objModule
  * @param string $strColumn
  */
 public function __construct($objModule, $strColumn = 'main')
 {
     parent::__construct($objModule, $strColumn);
     \Controller::loadDataContainer('tl_iso_product');
     \System::loadLanguageFile('tl_iso_product');
     $this->iso_filterFields = deserialize($this->iso_filterFields);
     $this->iso_sortingFields = deserialize($this->iso_sortingFields);
     $this->iso_searchFields = deserialize($this->iso_searchFields);
     if (!is_array($this->iso_filterFields)) {
         $this->iso_filterFields = array();
     }
     if (!is_array($this->iso_sortingFields)) {
         $this->iso_sortingFields = array();
     }
     if (!is_array($this->iso_searchFields)) {
         $this->iso_searchFields = array();
     }
 }
 public static function getParentEntitiesAsOptions(\DataContainer $objDc)
 {
     $arrOptions = array();
     $arrTitleSynonyms = array('title', 'headline', 'name');
     if (($strParentTable = $objDc->activeRecord->parentTable) && ($strClass = \Model::getClassFromTable($strParentTable))) {
         \Controller::loadDataContainer($strParentTable);
         if (($objEntities = $strClass::findAll()) !== null) {
             foreach ($arrTitleSynonyms as $strField) {
                 if (\Database::getInstance()->fieldExists($strField, $strParentTable)) {
                     $arrOptions = $objEntities->fetchEach($strField);
                     asort($arrOptions);
                     break;
                 }
             }
         }
     }
     return $arrOptions;
 }
Example #25
0
 /**
  * Auto-format model data based on DCA config
  * @param   \Model
  * @param   callable
  * @return  \ArrayObject
  */
 public static function generate(\Model $objModel = null, $varCallable = null)
 {
     if (null === $objModel) {
         return new \ArrayObject(array(), \ArrayObject::ARRAY_AS_PROPS);
     }
     $strTable = $objModel->getTable();
     $objDca = new \DcaExtractor($strTable);
     $arrRelations = $objDca->getRelations();
     $arrData = array();
     \System::loadLanguageFile($strTable);
     \Controller::loadDataContainer($strTable);
     $arrFields =& $GLOBALS['TL_DCA'][$strTable]['fields'];
     foreach ($objModel->row() as $strField => $varValue) {
         $arrAdditional = array();
         $strLabel = Format::dcaLabel($strTable, $strField);
         if (isset($arrRelations[$strField])) {
             $objRelated = $objModel->getRelated($strField);
             if ($objRelated == null) {
                 $arrData[$strField] = new Plain('', $strLabel, $arrAdditional);
             } elseif ($objRelated instanceof \Model\Collection) {
                 $arrCollection = array();
                 foreach ($objRelated as $objRelatedModel) {
                     $arrCollection[] = new Relation($objRelatedModel, '', array(), $varCallable);
                 }
                 $arrData[$strField] = new Collection($arrCollection, $strLabel);
             } else {
                 $arrData[$strField] = new Relation($objRelated, $strLabel, array(), $varCallable);
             }
             continue;
         }
         $arrAdditional['formatted'] = Format::dcaValue($strTable, $strField, $varValue);
         if (in_array($arrFields[$strField]['eval']['rgxp'], array('date', 'datim', 'time'))) {
             $arrData[$strField] = new Timestamp($varValue, $strLabel, $arrAdditional);
         } else {
             $arrData[$strField] = new Plain($varValue, $strLabel, $arrAdditional);
         }
     }
     if (null !== $varCallable) {
         call_user_func_array($varCallable, array($objModel, &$arrData));
     }
     return new \ArrayObject($arrData, \ArrayObject::ARRAY_AS_PROPS);
 }
 protected function createObjectFromMapping($objSourceItem)
 {
     $objDatabase = \Database::getInstance();
     \Controller::loadDataContainer($this->dbTargetTable);
     $dca = $GLOBALS['TL_DCA'][$this->dbTargetTable];
     $t = $this->dbTargetTable;
     $arrItem = array();
     foreach ($this->arrMapping as $key => $col) {
         $value = $this->setValueByType($objSourceItem->{$key}, $dca['fields'][$key], $arrItem, $objSourceItem);
         $this->setObjectValueFromMapping($arrItem, $value, $key);
         if ($value === null) {
             unset($arrItem[$key]);
             continue;
         }
     }
     if (!$this->dryRun) {
         if (!$this->skipInsertion) {
             $strQuery = "INSERT INTO {$t} (" . implode(',', array_keys($arrItem)) . ") VALUES(" . implode(',', array_map(function ($val) {
                 return "'" . str_replace("'", "''", $val) . "'";
             }, array_values($arrItem))) . ")";
             $arrItem['id'] = $objDatabase->execute($strQuery)->insertId;
         }
         // do after item has been created,
         $this->runAfterSaving($arrItem, $objSourceItem);
         // save updates
         if (!$this->skipUpdateAfterSave) {
             $arrTargetItemPrepared = array();
             foreach ($arrItem as $strKey => $strVal) {
                 if ($strKey == 'id') {
                     continue;
                 }
                 $strVal = str_replace("'", "''", $strVal);
                 $arrTargetItemPrepared[] = "{$this->dbTargetTable}.{$strKey}='{$strVal}'";
             }
             // update all values to the db
             $strQuery = "UPDATE {$this->dbTargetTable} SET " . implode(',', $arrTargetItemPrepared) . " WHERE id=" . $arrItem['id'];
             \Database::getInstance()->execute($strQuery);
         }
     }
     return $arrItem;
 }
 public static function importMemberFields()
 {
     $arrDca =& $GLOBALS['TL_DCA']['tl_company'];
     \Controller::loadDataContainer('tl_member');
     \System::loadLanguageFile('tl_member');
     // fields
     $blnChangeMandatoryAddressFields = \Config::get('companyChangeMandatoryMemberFields');
     $arrMandatoryAddressFields = deserialize(\Config::get('companyMandatoryMemberFields'), true);
     $arrAddressFields = \Config::get('companyMemberFields');
     if ($arrAddressFields === null) {
         $arrAddressFields = serialize(array_keys(static::getMemberFields()));
     }
     $arrFields = array();
     foreach (deserialize($arrAddressFields, true) as $strName) {
         $strNameContact = 'contact' . ucfirst($strName);
         $arrFields[$strNameContact] = $GLOBALS['TL_DCA']['tl_member']['fields'][$strName];
         if ($blnChangeMandatoryAddressFields && is_array($arrMandatoryAddressFields)) {
             $arrFields[$strNameContact]['eval']['mandatory'] = in_array($strName, $arrMandatoryAddressFields);
         }
     }
     Arrays::insertInArrayByName($arrDca['fields'], 'tstamp', $arrFields, 1);
 }
 public function getEditable($dc)
 {
     if (!$dc) {
         $objModule = \ModuleModel::findByPk(\Input::get('id'));
         if ($objModule === null) {
             return array();
         }
         $dc = new HeimrichHannot\FormHybrid\DC_Hybrid('tl_module', $objModule);
     }
     $strPalette = $dc->activeRecord->type == 'eventfilter' ? 'eventfilter' : 'default';
     \Controller::loadDataContainer('tl_calendar_events');
     $arrFields = HeimrichHannot\FormHybrid\FormHelper::getPaletteFields('tl_calendar_events', $GLOBALS['TL_DCA']['tl_calendar_events']['palettes'][$strPalette]);
     if (is_array($GLOBALS['TL_DCA']['tl_calendar_events']['subpalettes'])) {
         $arrSubPalettes = array_keys($GLOBALS['TL_DCA']['tl_calendar_events']['subpalettes']);
         // ignore subpalettes not in palette
         $arrSubPalettes = HeimrichHannot\FormHybrid\FormHelper::getFilteredSubPalettes($arrSubPalettes, $arrFields, $dc);
         foreach ($arrSubPalettes as $strSubPalette) {
             $arrFields = array_merge($arrFields, HeimrichHannot\FormHybrid\FormHelper::getPaletteFields('tl_calendar_events', $GLOBALS['TL_DCA']['tl_calendar_events']['subpalettes'][$strSubPalette]));
         }
     }
     var_dump($arrFields);
     return $arrFields;
 }
Example #29
0
 public static function initialize()
 {
     if (static::$blnInitialized === false) {
         static::$blnInitialized = true;
         // Make sure field data is available
         \Controller::loadDataContainer('tl_iso_product');
         \System::loadLanguageFile('tl_iso_product');
         // Initialize request cache for product list filters
         if (\Input::get('isorc') != '') {
             if (static::getRequestCache()->isEmpty()) {
                 global $objPage;
                 $objPage->noSearch = 1;
             } elseif (static::getRequestCache()->id != \Input::get('isorc')) {
                 unset($_GET['isorc']);
                 // Unset the language parameter
                 if ($GLOBALS['TL_CONFIG']['addLanguageToUrl']) {
                     unset($_GET['language']);
                 }
                 $strQuery = http_build_query($_GET);
                 \Controller::redirect(preg_replace('/\\?.*$/i', '', \Environment::get('request') . ($strQuery ? '?' . $strQuery : '')));
             }
         }
     }
 }
 public static function getModelValuesAsStringArray(\Model $objModel, array $arrSkipFields = array())
 {
     $arrValues = array();
     \Controller::loadDataContainer($objModel::getTable());
     foreach ($objModel->row() as $key => $value) {
         if (!isset($GLOBALS['TL_DCA'][$objModel::getTable()]['fields'][$key])) {
             continue;
         }
         $arrData = $GLOBALS['TL_DCA'][$objModel::getTable()]['fields'][$key];
         if (!isset($arrData['inputType']) || in_array($key, $arrSkipFields)) {
             continue;
         }
         if ($arrData['eval']['rgxp'] == 'digit') {
             $value = intval($value);
         }
         if ($arrData['inputType'] == 'checkbox' && !$arrData['eval']['multiple']) {
             $value = $value ? 'true' : 'false';
         }
         if ($arrData['eval']['multiple'] || $arrData['inputType'] == 'multiColumnWizard') {
             $value = deserialize($value, true);
         }
         // check type as well, otherwise
         if ($value === '') {
             continue;
         }
         $arrValues[$key] = $value;
     }
     return $arrValues;
 }