Exemplo n.º 1
0
 /**
  * Destroys the MetaModel table and all associated entries in child tables like filter-, render- and dcasettings.
  *
  * @param DC_General $objDC the datacontainer where the model is loaded.
  *
  * @return void
  */
 public function onDeleteCallback(DC_General $objDC)
 {
     $objMetaModel = MetaModelFactory::byId($objDC->getId());
     if ($objMetaModel) {
         // TODO: implement IMetaModel*::suicide() to delete all entries in secondary tables (complex attributes), better than here in an callback.
         foreach ($objMetaModel->getAttributes() as $objAttribute) {
             $objAttribute->destroyAUX();
         }
         MetaModelTableManipulation::deleteTable($objMetaModel->getTableName());
         $this->Database->prepare('DELETE FROM tl_metamodel_attribute WHERE pid=?')->executeUncached($objMetaModel->get('id'));
         $this->Database->prepare('DELETE FROM tl_metamodel_dca_combine WHERE pid=?')->executeUncached($objMetaModel->get('id'));
         // delete everything from dca settings
         $arrIds = $this->Database->prepare('SELECT id FROM tl_metamodel_dca WHERE pid=?')->executeUncached($objMetaModel->get('id'))->fetchEach('id');
         if ($arrIds) {
             $this->Database->prepare(sprintf('DELETE FROM tl_metamodel_dcasetting WHERE pid IN (%s)', implode(',', $arrIds)))->executeUncached();
         }
         $this->Database->prepare('DELETE FROM tl_metamodel_dca WHERE pid=?')->executeUncached($objMetaModel->get('id'));
         // delete everything from render settings
         $arrIds = $this->Database->prepare('SELECT id FROM tl_metamodel_rendersettings WHERE pid=?')->executeUncached($objMetaModel->get('id'))->fetchEach('id');
         if ($arrIds) {
             $this->Database->prepare(sprintf('DELETE FROM tl_metamodel_rendersetting WHERE pid IN (%s)', implode(',', $arrIds)))->executeUncached();
         }
         $this->Database->prepare('DELETE FROM tl_metamodel_rendersettings WHERE pid=?')->executeUncached($objMetaModel->get('id'));
         // delete everything from filter settings
         $arrIds = $this->Database->prepare('SELECT id FROM tl_metamodel_filter WHERE pid=?')->executeUncached($objMetaModel->get('id'))->fetchEach('id');
         if ($arrIds) {
             $this->Database->prepare(sprintf('DELETE FROM tl_metamodel_filtersetting WHERE pid IN (%s)', implode(',', $arrIds)))->executeUncached();
         }
         $this->Database->prepare('DELETE FROM tl_metamodel_filter WHERE pid=?')->executeUncached($objMetaModel->get('id'));
     }
 }
Exemplo n.º 2
0
 /**
  * Auto-Generate an alias for an entity.
  *
  * @param string      $alias
  * @param \DC_General $dc
  *
  * @return string
  * @throws Exception
  */
 public static function generateAlias($alias, \DC_General $dc)
 {
     /** @var EntityInterface $entity */
     $entity = $dc->getCurrentModel()->getEntity();
     $autoAlias = false;
     // Generate alias if there is none
     if (!strlen($alias)) {
         $autoAlias = true;
         if ($entity->__has('title')) {
             $alias = standardize($entity->getTitle());
         } elseif ($entity->__has('name')) {
             $alias = standardize($entity->getName());
         } else {
             return '';
         }
     }
     $entityClass = new \ReflectionClass($entity);
     $keys = explode(',', $entityClass->getConstant('KEY'));
     $entityManager = EntityHelper::getEntityManager();
     $queryBuilder = $entityManager->createQueryBuilder();
     $queryBuilder->select('COUNT(e.' . $keys[0] . ')')->from($entityClass->getName(), 'e')->where($queryBuilder->expr()->eq('e.alias', ':alias'))->setParameter(':alias', $alias);
     static::extendQueryWhereId($queryBuilder, $dc->getCurrentModel()->getID(), $entity);
     $query = $queryBuilder->getQuery();
     $duplicateCount = $query->getResult(Query::HYDRATE_SINGLE_SCALAR);
     // Check whether the news alias exists
     if ($duplicateCount && !$autoAlias) {
         throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $alias));
     }
     // Add ID to alias
     if ($duplicateCount && $autoAlias) {
         $alias .= '-' . $dc->getCurrentModel()->getID();
     }
     return $alias;
 }
 /**
  * Call the onmodel_update.
  * NOTE: the fact that this method has been called does not mean the values of the model have been changed
  * it merely just tells "we have loaded a model (from memory or database) and updated it's properties with
  * those from the POST data".
  *
  * @param InterfaceGeneralModel $objModel The model that has been updated.
  *
  * @return void
  */
 public function onModelUpdateCallback($objModel)
 {
     // Load DCA
     $arrDCA = $this->objDC->getDCA();
     // Call the oncreate_callback
     if (is_array($arrDCA['config']['onmodel_update'])) {
         foreach ($arrDCA['config']['onmodel_update'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($objModel, $this->objDC);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Returns an array with all valid tables that can be used as parent table.
  *
  * Excludes the metamodel table itself in ctable mode, as that one would be "selftree" then and not ctable.
  *
  * @param DC_General $objDC The general DataContainer calling us.
  *
  * @return string[] the tables.
  */
 public function getTables(DC_General $objDC)
 {
     if ($objDC->getCurrentModel()->getProperty('rendertype') == 'ctable') {
         $blnOmit = $this->getMetaModel($objDC)->getTableName();
     }
     $tables = array();
     foreach ($this->Database->listTables() as $table) {
         if (!($blnOmit && $blnOmit == $table)) {
             $tables[$table] = $table;
         }
     }
     return $tables;
 }
Exemplo n.º 5
0
 /**
  * Get a subpalette
  */
 protected function toggleSubpaletteExtended()
 {
     $strMethod = $this->Input->get('act') == 'editAll' ? 'editAll' : 'edit';
     $strSelector = $this->Input->post('FORM_INPUTS');
     $strSelector = reset($strSelector);
     $intPos = strrpos($strSelector, '_');
     // TODO: what was $intID intended for? Is there code missing here?
     $intID = substr($strSelector, $intPos + 1);
     if (!is_numeric($intID)) {
         $intID = base64_decode(str_replace('_', '=', substr($intID, 1)));
     }
     $strSelector = substr($strSelector, 0, $intPos);
     $this->mixContent = $this->objDC->generateAjaxPalette($strMethod, $strSelector);
 }
 /**
  * Callback and startpoint for this programm.
  * 
  * @param DC_General $objDC
  * 
  * @return array
  */
 public function generateBreadcrumbItems($objDC)
 {
     // Store init id.
     $this->intID = $objDC->getId();
     $arrReturn = array();
     // Build navigation.
     // Each get*Level() call will alter the id property to the next pid.
     switch ($objDC->getTable()) {
         case 'tl_metamodel_attribute':
             $arrReturn[] = $this->getSecondLevel('tl_metamodel_attribute', 'fields.png');
             break;
         case 'tl_metamodel_rendersetting':
             $arrReturn[] = $this->getThirdLevel('tl_metamodel_rendersetting', 'tl_metamodel_rendersettings', 'render_setting.png');
         case 'tl_metamodel_rendersettings':
             $arrReturn[] = $this->getSecondLevel('tl_metamodel_rendersettings', 'render_settings.png');
             break;
         case 'tl_metamodel_dcasetting':
             if (Input::getInstance()->get('subpaletteid')) {
                 $arrReturn[] = $this->getFourthLevel('metamodel_dcasetting_subpalette', 'tl_metamodel_dcasetting', 'dca_subpalette.png');
             }
             $arrReturn[] = $this->getThirdLevel('tl_metamodel_dcasetting', 'tl_metamodel_dca', 'dca_setting.png');
         case 'tl_metamodel_dca':
             $arrReturn[] = $this->getSecondLevel('tl_metamodel_dca', 'dca.png');
             break;
         case 'tl_metamodel_filtersetting':
             $arrReturn[] = $this->getThirdLevel('tl_metamodel_filtersetting', 'tl_metamodel_filter', 'filter_setting.png');
         case 'tl_metamodel_filter':
             $arrReturn[] = $this->getSecondLevel('tl_metamodel_filter', 'filter.png');
             break;
         default:
             break;
     }
     // Always add root from mm as first entry.
     $arrReturn[] = $this->getFirstLevel();
     // Return array.
     return array_reverse($arrReturn);
 }
 /**
  * Callback when an item is opened in edit view.
  * This method filters invariant attributes from the palette, when editing a variant.
  *
  * @param string the input palette
  *
  * @return string the filtered palette.
  */
 public function parseRootPaletteCallback($arrPalette)
 {
     $objModelRow = $this->objDC->getCurrentModel();
     if ($objModelRow) {
         $objNativeItem = $objModelRow->getItem();
         $objMetaModel = $objNativeItem->getMetaModel();
         if ($objMetaModel->hasVariants() && !$objNativeItem->isVariantBase()) {
             // loop over all attributes and remove those from rendering that are invariant.
             foreach (array_keys($objMetaModel->getInVariantAttributes()) as $strAttrName) {
                 foreach ($arrPalette as $intKey => $arrPaletteDef) {
                     $this->removeAttributeFromPalette($strAttrName, $arrPalette[$intKey]['palette']);
                     if (!count($arrPalette[$intKey]['palette'])) {
                         unset($arrPalette[$intKey]);
                     }
                 }
             }
         }
     }
     $arrPalette = parent::parseRootPaletteCallback($arrPalette);
     return $arrPalette;
 }
Exemplo n.º 8
0
 /**
  * Get the breadcrumb navigation by callback
  *
  * @return string
  */
 protected function breadcrumb()
 {
     // Load DCA
     $arrDCA = $this->objDC->getDCA();
     $arrCallback = $arrDCA['list']['presentation']['breadcrumb_callback'];
     if (!is_array($arrCallback) || count($arrCallback) == 0) {
         return null;
     }
     // Get data from callback
     $strClass = $arrCallback[0];
     $strMethod = $arrCallback[1];
     $this->import($strClass);
     $arrReturn = $this->{$strClass}->{$strMethod}($this->objDC);
     // Check if we have a result with elements
     if (!is_array($arrReturn) || count($arrReturn) == 0) {
         return null;
     }
     // Include the breadcrumb css
     $GLOBALS['TL_CSS'][] = 'system/modules/generalDriver/html/css/generalBreadcrumb.css';
     // Build template
     $objTemplate = new BackendTemplate('dcbe_general_breadcrumb');
     $objTemplate->elements = $arrReturn;
     return $objTemplate->parse();
 }
Exemplo n.º 9
0
 /**
  * Return the paste page button
  * @param DataContainer
  * @param array
  * @param string
  * @param boolean
  * @param array
  * @return string
  */
 public function pasteButton(DC_General $objDC, $arrRow, $strTable, $cr, $arrClipboard = false)
 {
     $disablePA = true;
     $disablePI = true;
     // FIXME: whoa, this is hacky, the DC should provide a better way to obtain all of this.
     $objSrcProvider = $objDC->getDataProvider($strTable);
     if ($this->Input->get('source')) {
         $objModel = $objSrcProvider->fetch($objSrcProvider->getEmptyConfig()->setId($this->Input->get('source')));
     } else {
         $objModel = null;
     }
     if ($objModel && isset($arrRow['id']) && strlen($arrRow['id']) && $arrRow['id'] != $objModel->getID()) {
         // Insert a varbase after any other varbase, for sorting.
         if ($objModel->getProperty('varbase') == 1 && $arrRow['id'] != $objModel->getID() && $arrRow['varbase'] != 0) {
             $disablePA = false;
         } else {
             if ($objModel->getProperty('varbase') == 0 && $arrRow['vargroup'] == $objModel->getProperty('vargroup') && $arrRow['varbase'] != 1) {
                 $disablePA = false;
             }
         }
     } else {
         $disablePA = false;
         $disablePI = !($arrRow['varbase'] == 1);
     }
     // Return the buttons
     $imagePasteAfter = $this->generateImage('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$strTable]['pasteafter'][1], $arrRow['id']), 'class="blink"');
     $imagePasteInto = $this->generateImage('pasteinto.gif', sprintf($GLOBALS['TL_LANG'][$strTable]['pasteinto'][1], $arrRow['id']), 'class="blink"');
     $strAdd2UrlAfter = sprintf('act=%s&mode=1&pid=%s&after=%s&source=%s&childs=%s', $arrClipboard['mode'], $arrClipboard['id'], $arrRow['id'], $arrClipboard['source'], $arrClipboard['childs']);
     $strAdd2UrlInto = sprintf('act=%s&mode=2&pid=%s&after=%s&source=%s&childs=%s', $arrClipboard['mode'], $arrClipboard['id'], $arrRow['id'], $arrClipboard['source'], $arrClipboard['childs']);
     if ($arrClipboard['pdp'] != '') {
         $strAdd2UrlAfter .= '&pdp=' . $arrClipboard['pdp'];
         $strAdd2UrlInto .= '&pdp=' . $arrClipboard['pdp'];
     }
     if ($arrClipboard['cdp'] != '') {
         $strAdd2UrlAfter .= '&cdp=' . $arrClipboard['cdp'];
         $strAdd2UrlInto .= '&cdp=' . $arrClipboard['cdp'];
     }
     $strPasteBtn = '';
     if ($disablePA) {
         $strPasteBtn = $this->generateImage('pasteafter_.gif', '', 'class="blink"') . ' ';
     } else {
         $strPasteBtn = sprintf(' <a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ', $this->addToUrl($strAdd2UrlAfter), specialchars($GLOBALS['TL_LANG'][$strTable]['pasteafter'][0]), $imagePasteAfter);
     }
     if ($disablePI) {
         $strPasteBtn .= $this->generateImage('pasteinto_.gif', '', 'class="blink"') . ' ';
     } else {
         $strPasteBtn .= sprintf(' <a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ', $this->addToUrl($strAdd2UrlInto), specialchars($GLOBALS['TL_LANG'][$strTable]['pasteinto'][0]), $imagePasteInto);
     }
     // special case, the root paste into.
     if (!(isset($arrRow['id']) && strlen($arrRow['id']))) {
         if ($objModel && $objModel->getProperty('varbase') == 1) {
             $strPasteBtn = sprintf(' <a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ', $this->addToUrl(sprintf('act=%s&amp;mode=2&amp;after=0&amp;pid=0&amp;id=%s&amp;childs=%s', $arrClipboard['mode'], $arrClipboard['id'], $arrClipboard['childs'])), specialchars($GLOBALS['TL_LANG'][$strTable]['pasteinto'][0]), $imagePasteInto);
         } elseif (!$objModel) {
             $strPasteBtn = sprintf(' <a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ', $this->addToUrl(sprintf('act=%s&amp;mode=2&amp;after=0&amp;pid=0&amp;id=%s&amp;childs=%s', $arrClipboard['mode'], $arrClipboard['id'], $arrClipboard['childs'])), specialchars($GLOBALS['TL_LANG'][$strTable]['pasteinto'][0]), $imagePasteInto);
         } else {
             $strPasteBtn = $this->generateImage('pasteinto_.gif', '', 'class="blink"') . ' ';
         }
     }
     return $strPasteBtn;
 }
 /**
  * Add sorting options to filter menu
  *
  * @param array $arrSortingFields
  * @param array $arrSession
  * @param string $strFilter
  * @return array
  */
 protected function filterMenuAddOptions($arrSortingFields, $arrSession, $strFilter)
 {
     $arrPanelView = array();
     // Add sorting options
     foreach ($arrSortingFields as $cnt => $field) {
         $arrProcedure = array();
         if ($this->getDC()->arrDCA['list']['sorting']['mode'] == 4) {
             $arrProcedure[] = array('operation' => '=', 'property' => 'pid', 'value' => CURRENT_ID);
         }
         if (!is_null($this->getDC()->getRootIds()) && is_array($this->getDC()->getRootIds())) {
             $arrProcedure[] = array('operation' => 'IN', 'property' => 'id', 'values' => array_map('intval', $this->getDC()->getRootIds()));
         }
         foreach ((array) $this->getFilter() as $arrSubFilter) {
             if ($arrSubFilter['property'] != $field) {
                 $arrProcedure[] = $arrSubFilter;
             }
         }
         $objCollection = $this->getDC()->getDataProvider()->getFilterOptions($this->getDC()->getDataProvider()->getEmptyConfig()->setFields(array($field))->setFilter($arrProcedure));
         // Begin select menu
         $arrPanelView[$field] = array('select' => array('name' => $field, 'id' => $field, 'class' => 'tl_select' . (isset($arrSession['filter'][$strFilter][$field]) ? ' active' : '')), 'option' => array(array('value' => 'tl_' . $field, 'content' => is_array($this->getDC()->arrDCA['fields'][$field]['label']) ? $this->getDC()->arrDCA['fields'][$field]['label'][0] : $this->getDC()->arrDCA['fields'][$field]['label']), array('value' => 'tl_' . $field, 'content' => '---')));
         if ($objCollection->length() > 0) {
             $options = array();
             foreach ($objCollection as $intIndex => $objModel) {
                 $options[$intIndex] = $objModel->getProperty($field);
             }
             // Sort by day
             if (in_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['flag'], array(5, 6))) {
                 $this->arrColSort = array('field' => $field, 'reverse' => $this->getDC()->arrDCA['fields'][$field]['flag'] == 6 ? true : false);
                 $objCollection->sort(array($this, 'sortCollection'));
                 foreach ($objCollection as $intIndex => $objModel) {
                     if ($objModel->getProperty($field) == '') {
                         $options[$objModel->getProperty($field)] = '-';
                     } else {
                         $options[$objModel->getProperty($field)] = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $objModel->getProperty($field));
                     }
                     unset($options[$intIndex]);
                 }
             } elseif (in_array($this->getDC()->arrDCA['fields'][$field]['flag'], array(7, 8))) {
                 $this->arrColSort = array('field' => $field, 'reverse' => $this->getDC()->arrDCA['fields'][$field]['flag'] == 8 ? true : false);
                 $objCollection->sort(array($this, 'sortCollection'));
                 foreach ($objCollection as $intIndex => $objModel) {
                     if ($objModel->getProperty($field) == '') {
                         $options[$objModel->getProperty($field)] = '-';
                     } else {
                         $options[$objModel->getProperty($field)] = date('Y-m', $objModel->getProperty($field));
                         $intMonth = date('m', $objModel->getProperty($field)) - 1;
                         if (isset($GLOBALS['TL_LANG']['MONTHS'][$intMonth])) {
                             $options[$objModel->getProperty($field)] = $GLOBALS['TL_LANG']['MONTHS'][$intMonth] . ' ' . date('Y', $objModel->getProperty($field));
                         }
                     }
                     unset($options[$intIndex]);
                 }
             } elseif (in_array($this->getDC()->arrDCA['fields'][$field]['flag'], array(9, 10))) {
                 $this->arrColSort = array('field' => $field, 'reverse' => $this->getDC()->arrDCA['fields'][$field]['flag'] == 10 ? true : false);
                 $objCollection->sort(array($this, 'sortCollection'));
                 foreach ($objCollection as $intIndex => $objModel) {
                     if ($objModel->getProperty($field) == '') {
                         $options[$objModel->getProperty($field)] = '-';
                     } else {
                         $options[$objModel->getProperty($field)] = date('Y', $objModel->getProperty($field));
                     }
                     unset($options[$intIndex]);
                 }
             }
             // Manual filter
             if ($this->getDC()->arrDCA['fields'][$field]['eval']['multiple']) {
                 $moptions = array();
                 foreach ($objCollection as $objModel) {
                     if (isset($this->getDC()->arrDCA['fields'][$field]['eval']['csv'])) {
                         $doptions = trimsplit($this->getDC()->arrDCA['fields'][$field]['eval']['csv'], $objModel->getProperty($field));
                     } else {
                         $doptions = deserialize($objModel->getProperty($field));
                     }
                     if (is_array($doptions)) {
                         $moptions = array_merge($moptions, $doptions);
                     }
                 }
                 $options = $moptions;
             }
             $options = array_unique($options);
             $arrOptionsCallback = array();
             // Load options callback
             if (is_array($this->getDC()->arrDCA['fields'][$field]['options_callback']) && !$this->getDC()->arrDCA['fields'][$field]['reference']) {
                 $arrOptionsCallback = $this->getDC()->getCallbackClass()->optionsCallback($field);
                 // Sort options according to the keys of the callback array
                 if (!is_null($arrOptionsCallback)) {
                     $options = array_intersect(array_keys($arrOptionsCallback), $options);
                 }
             }
             $arrOptions = array();
             $arrSortOptions = array();
             $blnDate = in_array($this->getDC()->arrDCA['fields'][$field]['flag'], array(5, 6, 7, 8, 9, 10));
             // Options
             foreach ($options as $kk => $vv) {
                 $value = $blnDate ? $kk : $vv;
                 // Replace the ID with the foreign key
                 if (isset($this->getDC()->arrDCA['fields'][$field]['foreignKey'])) {
                     $key = explode('.', $this->getDC()->arrDCA['fields'][$field]['foreignKey'], 2);
                     $objModel = $this->getDC()->getDataProvider($key[0])->fetch($this->getDC()->getDataProvider($key[0])->getEmptyConfig()->setId($vv)->setFields(array($key[1] . ' AS value')));
                     if ($objModel->hasProperties()) {
                         $vv = $objModel->getProperty('value');
                     }
                 } elseif ($this->getDC()->arrDCA['fields'][$field]['eval']['isBoolean'] || $this->getDC()->arrDCA['fields'][$field]['inputType'] == 'checkbox' && !$this->getDC()->arrDCA['fields'][$field]['eval']['multiple']) {
                     $vv = $vv != '' ? $GLOBALS['TL_LANG']['MSC']['yes'] : $GLOBALS['TL_LANG']['MSC']['no'];
                 } elseif (is_array($arrOptionsCallback) && !empty($arrOptionsCallback)) {
                     $vv = $arrOptionsCallback[$vv];
                 } elseif ($field == 'pid') {
                     // Load language file and data container array of the parent table
                     $this->loadLanguageFile($this->getDC()->getParentTable());
                     $this->loadDataContainer($this->getDC()->getParentTable());
                     $objParentDC = new DC_General($this->getDC()->getParentTable());
                     $arrParentDca = $objParentDC->getDCA();
                     $showFields = $arrParentDca['list']['label']['fields'];
                     if (!$showFields[0]) {
                         $showFields[0] = 'id';
                     }
                     $objModel = $this->getDC()->getDataProvider('parent')->fetch($this->getDC()->getDataProvider('parent')->getEmptyConfig()->setId($vv)->setFields(array($showFields[0])));
                     if ($objModel->hasProperties()) {
                         $vv = $objModel->getProperty($showFields[0]);
                     }
                 }
                 $strOptionsLabel = '';
                 // Use reference array
                 if (isset($this->getDC()->arrDCA['fields'][$field]['reference'])) {
                     $strOptionsLabel = is_array($this->getDC()->arrDCA['fields'][$field]['reference'][$vv]) ? $this->getDC()->arrDCA['fields'][$field]['reference'][$vv][0] : $this->getDC()->arrDCA['fields'][$field]['reference'][$vv];
                 } elseif ($this->getDC()->arrDCA['fields'][$field]['eval']['isAssociative'] || array_is_assoc($this->getDC()->arrDCA['fields'][$field]['options'])) {
                     $strOptionsLabel = $this->getDC()->arrDCA['fields'][$field]['options'][$vv];
                 }
                 // No empty options allowed
                 if (!strlen($strOptionsLabel)) {
                     // FIXME: this is a rather evil hack but I ended up here with an array containing files.
                     // This usually reensembles an invalid setup but we should not raise warnings then but cope
                     // correctly with it. For the moment, we simply ignore such data we can not handle.
                     if (!is_string($vv)) {
                         continue;
                     }
                     $strOptionsLabel = strlen($vv) ? $vv : '-';
                 }
                 $arrOptions[utf8_romanize($strOptionsLabel)] = array('value' => specialchars($value), 'select' => isset($arrSession['filter'][$strFilter][$field]) && $value == $arrSession['filter'][$strFilter][$field] ? ' selected="selected"' : '', 'content' => $strOptionsLabel);
                 $arrSortOptions[] = utf8_romanize($strOptionsLabel);
             }
             // Sort by option values
             if (!$blnDate) {
                 natcasesort($arrSortOptions);
                 if (in_array($this->getDC()->arrDCA['fields'][$field]['flag'], array(2, 4, 12))) {
                     $arrSortOptions = array_reverse($arrSortOptions, true);
                 }
             }
             foreach ($arrSortOptions as $value) {
                 $arrPanelView[$field]['option'][] = $arrOptions[$value];
             }
         }
         // Force a line-break after six elements
         if (($cnt + 1) % 6 == 0) {
             $arrPanelView[] = 'new';
         }
     }
     return $arrPanelView;
 }
 /**
  * Create a variant of the model currently loaded.
  *
  * @param DC_General $objDC The data container holding the current model.
  *
  * @return void
  */
 public function createvariant(DC_General $objDC)
 {
     // Check if table is editable.
     if (!$objDC->isEditable()) {
         $this->log('Table ' . $objDC->getTable() . ' is not editable', 'DC_General - Controller - edit()', TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     // Load fields.
     $objDC->loadEditableFields();
     $objDC->setWidgetID($objDC->getId());
     // Check if we have fields.
     if (!$objDC->hasEditableFields()) {
         $this->redirect($this->getReferer());
     }
     // Load rich text editor.
     $objDC->preloadTinyMce();
     // Set buttons.
     $objDC->addButton('save');
     $objDC->addButton('saveNclose');
     // Load record from data provider.
     $objDBModel = $objDC->getDataProvider()->createVariant($objDC->getDataProvider()->getEmptyConfig()->setId($objDC->getId()));
     if ($objDBModel == null) {
         $objDBModel = $objDC->getDataProvider()->getEmptyModel();
     }
     $objDC->setCurrentModel($objDBModel);
     // Check if we have a auto submit.
     if ($objDC->isAutoSubmitted()) {
         // Process input and update changed properties.
         foreach (array_keys($objDC->getFieldList()) as $key) {
             $varNewValue = $objDC->processInput($key);
             if ($objDBModel->getProperty($key) != $varNewValue) {
                 $objDBModel->setProperty($key, $varNewValue);
             }
         }
         $objDC->setCurrentModel($objDBModel);
     }
     // Check submit.
     if ($objDC->isSubmitted() == true) {
         // @codingStandardsIgnoreStart - we know that access to $_POST is discouraged.
         if (isset($_POST['save'])) {
             $this->getDC()->updateModelFromPOST();
             // Process input and update changed properties.
             if ($this->doSave($objDC) !== false) {
                 // Call the on create callbacks.
                 $objDC->getCallbackClass()->oncreateCallback($objDBModel->getID(), $objDBModel->getPropertiesAsArray());
                 // Log the creation.
                 $this->log(sprintf('A new entry in table "%s" has been created (ID: %s)', $objDC->getTable(), $objDBModel->getID()), 'DC_General - Controller - createvariant()', TL_GENERAL);
                 // Redirect to edit mode.
                 $this->redirect($this->addToUrl('id=' . $objDBModel->getID() . '&amp;act=edit'));
             }
         } elseif (isset($_POST['saveNclose'])) {
             $this->getDC()->updateModelFromPOST();
             // Process input and update changed properties.
             if ($this->doSave($objDC) !== false) {
                 setcookie('BE_PAGE_OFFSET', 0, 0, '/');
                 // @codingStandardsIgnoreStart - we know that access to $_SESSION is discouraged.
                 $_SESSION['TL_INFO'] = array();
                 $_SESSION['TL_ERROR'] = array();
                 $_SESSION['TL_CONFIRM'] = array();
                 // @codingStandardsIgnoreEnd
                 $this->redirect($this->getReferer());
             }
         }
         // Maybe Callbacks?
     }
 }