protected function doExport($objEntity = null, array $arrFields = array())
 {
     switch ($this->type) {
         case Exporter::TYPE_ITEM:
             break;
         case Exporter::TYPE_LIST:
             $objDbResult = $this->getEntities();
             $arrDca = $GLOBALS['TL_DCA'][$this->linkedTable];
             if (!$objDbResult->numRows > 0) {
                 return;
             }
             $intCol = 0;
             $intRow = 1;
             // header
             if ($this->objConfig->addHeaderToExportTable) {
                 foreach ($this->arrHeaderFields as $varValue) {
                     $this->objPhpExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($intCol, $intRow, $varValue);
                     $this->processHeaderRow($intCol);
                     $intCol++;
                 }
                 $intRow++;
             }
             // body
             while ($objDbResult->next()) {
                 $arrRow = $objDbResult->row();
                 $intCol = 0;
                 foreach ($arrRow as $key => $varValue) {
                     $objDc = new \DC_Table($this->linkedTable);
                     $objDc->activeRecord = $objDbResult;
                     $objDc->id = $objDbResult->id;
                     $varValue = $this->localizeFields ? FormSubmission::prepareSpecialValueForPrint($varValue, $arrDca['fields'][$key], $this->linkedTable, $objDc) : $varValue;
                     if (is_array($varValue)) {
                         $varValue = Arrays::flattenArray($varValue);
                     }
                     $this->objPhpExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($intCol, $intRow, html_entity_decode($varValue));
                     $this->objPhpExcel->getActiveSheet()->getColumnDimension(\PHPExcel_Cell::stringFromColumnIndex($intCol))->setAutoSize(true);
                     $this->processBodyRow($intCol);
                     $intCol++;
                 }
                 $this->objPhpExcel->getActiveSheet()->getRowDimension($intRow)->setRowHeight(-1);
                 $intRow++;
             }
             $this->objPhpExcel->setActiveSheetIndex(0);
             $this->objPhpExcel->getActiveSheet()->setTitle('Export');
             return $this->objPhpExcel;
             break;
     }
     return false;
 }
 /**
  * Should only return the field value
  * @return string
  */
 public function generate()
 {
     $arrData = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strName];
     $value = FormSubmission::prepareSpecialValueForPrint($this->varValue, $arrData, $this->strTable, $this, $this->activeRecord);
     switch ($this->type) {
         case 'multifileupload':
             if ($this->fieldType == 'checkbox') {
                 $value = '<ul class="download-list">' . implode('', array_map(function ($val) {
                     return '<li>{{download::' . str_replace(\Environment::get('url') . '/', '', $val) . '}}</li>';
                 }, explode(', ', $value))) . '</ul>';
                 break;
             }
             $value = '{{download::' . str_replace(\Environment::get('url') . '/', '', $value) . '}}';
             break;
     }
     $value = class_exists('Contao\\StringUtil') ? \StringUtil::decodeEntities(\Controller::replaceInsertTags($value)) : \String::decodeEntities(\Controller::replaceInsertTags($value));
     if (!$value) {
         $value = '-';
     }
     return $value;
 }
 protected function exportAfterSubmission()
 {
     $objExportConfigs = FieldPaletteModel::findPublishedByPidAndTableAndField($this->objModule->id, 'tl_module', 'formHybridExportConfigs');
     if ($objExportConfigs !== null) {
         while ($objExportConfigs->next()) {
             $objConfig = ExporterModel::findByPk($objExportConfigs->formhybrid_formHybridExportConfigs_config);
             if ($objConfig !== null) {
                 $objConfig->type = Exporter::TYPE_ITEM;
                 $objConfig->linkedTable = $this->strTable;
                 // prepare fields for exporter
                 $arrExportFields = array();
                 foreach ($this->arrFields as $objWidget) {
                     $arrData = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$objWidget->name];
                     $arrExportFields[$objWidget->name] = array('raw' => $this->objActiveRecord->{$objWidget->name}, 'inputType' => $arrData['inputType'], 'formatted' => FormSubmission::prepareSpecialValueForPrint($this->objActiveRecord->{$objWidget->name}, $arrData, $this->strTable, $this));
                     if ($arrData['inputType'] != 'explanation') {
                         $arrExportFields[$objWidget->name]['label'] = $this->dca['fields'][$objWidget->name]['label'][0] ?: $objWidget->name;
                     }
                     if ($objWidget->subName) {
                         foreach ($this->arrSubFields[$objWidget->subName] as $objSubWidget) {
                             $arrData = $GLOBALS['TL_DCA'][$this->strTable][$objSubWidget->name];
                             $arrExportFields[$objSubWidget->name] = array('raw' => $this->objActiveRecord->{$objSubWidget->name}, 'inputType' => $arrData['inputType'], 'formatted' => FormSubmission::prepareSpecialValueForPrint($this->objActiveRecord->{$objSubWidget->name}, $arrData, $this->strTable, $this));
                             if ($arrData['inputType'] != 'explanation') {
                                 $arrExportFields[$objSubWidget->name]['label'] = $this->dca['fields'][$objSubWidget->name]['label'][0] ?: $objSubWidget->name;
                             }
                         }
                     }
                 }
                 $objExporter = ModuleExporter::export($objConfig, $this->objActiveRecord, $arrExportFields);
                 if ($objExportConfigs->formhybrid_formHybridExportConfigs_entityField) {
                     $objFile = FilesModel::findByPath($objExporter->getFileDir() . '/' . $objExporter->getFilename());
                     $this->objActiveRecord->{$objExportConfigs->formhybrid_formHybridExportConfigs_entityField} = $objFile->uuid;
                     $this->objActiveRecord->save();
                 }
             }
         }
     }
 }
 /**
  * @deprecated Use HeimrichHannot\Haste\Util\FormSubmission::tokenizeData()
  *
  * @param array  $arrSubmissionData
  * @param string $strPrefix
  *
  * @return array
  */
 public static function tokenizeData(array $arrSubmissionData = array(), $strPrefix = 'form')
 {
     return FormSubmission::tokenizeData($arrSubmissionData, $strPrefix);
 }
Exemplo n.º 5
0
 /**
  * Return the Submission of the form, if nothing was submitted, return null
  *
  * @param bool $blnFormatted    set false, if the real value should be set
  * @param bool $blnSkipDefaults skip default values, helpful if nothing was submitted
  *
  * @return \FilesModel|Submission|\Model|null
  */
 public function getSubmission($blnFormatted = true, $blnSkipDefaults = false)
 {
     $arrSubmission = $this->arrSubmission;
     if (!$this->isSubmitted()) {
         $arrSubmission = $blnSkipDefaults ? array() : $this->getDefaults();
     }
     if (($this->hasNoEntity() || !$this->hasDatabaseTable()) && is_array($arrSubmission)) {
         $arrDca = $this->getDca();
         if (empty($arrSubmission)) {
             return null;
         }
         $objSubmission = new Submission();
         foreach ($arrSubmission as $strField => $varValue) {
             $arrData = $arrDca['fields'][$strField];
             if (is_array($arrData['options']) && !Validator::isValidOption($varValue, $arrData, $this)) {
                 continue;
             }
             if ($blnFormatted) {
                 $objSubmission->{$strField} = FormSubmission::prepareSpecialValueForPrint($varValue, $arrData, $this->strTable, $this);
             } else {
                 $objSubmission->{$strField} = $varValue;
             }
         }
     }
     return !$this->hasDatabaseTable() || $this->hasNoEntity() ? $objSubmission : $this->objActiveRecord;
 }
 protected function exportToDownload()
 {
     $strTmpFile = 'system/tmp/' . $this->strFilename;
     $strTmpFolder = str_replace('.' . $this->compressionType, '', $strTmpFile);
     $arrExportFields = array();
     $arrDca = $GLOBALS['TL_DCA'][$this->linkedTable]['fields'];
     foreach (deserialize($this->tableFieldsForExport, true) as $strField) {
         if (strpos($strField, EXPORTER_RAW_FIELD_SUFFIX) !== false) {
             $arrExportFields[] = str_replace(EXPORTER_RAW_FIELD_SUFFIX, '', $strField) . ' AS ' . $strField;
         } else {
             $arrExportFields[] = $strField;
         }
     }
     $objDbResult = \Database::getInstance()->prepare("SELECT " . implode(',', $arrExportFields) . " FROM " . $this->linkedTable)->execute();
     if (!$objDbResult->numRows > 0) {
         return;
     }
     switch ($this->compressionType) {
         default:
             $objZip = new ZipWriter($strTmpFile);
             break;
     }
     // write files
     while ($objDbResult->next()) {
         $arrRow = $objDbResult->row();
         foreach ($arrRow as $key => $varValue) {
             $objDc = new DC_Table($this->linkedTable);
             $objDc->activeRecord = $objDbResult;
             $varValue = FormSubmission::prepareSpecialValueForPrint($varValue, $arrDca['fields'][$key], $this->linkedTable, $objDc);
             if (!is_array($varValue)) {
                 $varValue = array($varValue);
             }
             foreach ($varValue as $strPath) {
                 if ($strPath && ($objFile = new \File($strPath, true)) !== null && $objFile->exists()) {
                     if (isset($GLOBALS['TL_HOOKS']['exporter_modifyMediaFilename']) && is_array($GLOBALS['TL_HOOKS']['exporter_modifyMediaFilename'])) {
                         foreach ($GLOBALS['TL_HOOKS']['exporter_modifyMediaFilename'] as $callback) {
                             $objCallback = \System::importStatic($callback[0]);
                             $strFixedFilename = $objCallback->{$callback}[1]($objFile, $key, $strPath, $this);
                             if ($strFixedFilename) {
                                 $strTmpFixedFilename = $strTmpFolder . '/' . ltrim($strFixedFilename, '/');
                                 $objFile->copyTo($strTmpFixedFilename);
                                 $objFile->path = $strTmpFixedFilename;
                             }
                         }
                     }
                     switch ($this->compressionType) {
                         default:
                             $objZip->addFile($objFile->path);
                             break;
                     }
                 }
             }
         }
     }
     switch ($this->compressionType) {
         default:
             $objZip->close();
             break;
     }
     $objTmpFolder = new \Folder($strTmpFolder);
     if (is_dir(TL_ROOT . '/' . $objTmpFolder->path)) {
         $objTmpFolder->delete();
     }
     $objFile = new \File($strTmpFile);
     $objFile->sendToBrowser();
 }
 protected function generateItemLabel($objRow, $folderAttribute)
 {
     $blnProtected = false;
     $showFields = $this->arrDca['list']['label']['fields'];
     $dc = new DC_Table(\Config::get('fieldpalette_table'));
     $dc->id = $this->currentRecord;
     $dc->activeRecord = $objRow;
     foreach ($showFields as $k => $v) {
         $args[$k] = FormSubmission::prepareSpecialValueForPrint($objRow->{$v}, $this->arrDca['fields'][$v], $this->strTable, $dc);
     }
     $label = vsprintf(strlen($this->arrDca['list']['label']['format']) ? $this->arrDca['list']['label']['format'] : '%s', $args);
     // Shorten the label if it is too long
     if ($this->arrDca['list']['label']['maxCharacters'] > 0 && $this->arrDca['list']['label']['maxCharacters'] < utf8_strlen(strip_tags($label))) {
         $label = trim(\StringUtil::substrHtml($label, $this->arrDca['list']['label']['maxCharacters'])) . ' …';
     }
     // Call the label_callback ($row, $label, $this)
     if (is_array($this->arrDca['list']['label']['label_callback'])) {
         $strClass = $this->arrDca['list']['label']['label_callback'][0];
         $strMethod = $this->arrDca['list']['label']['label_callback'][1];
         $this->import($strClass);
         return $this->{$strClass}->{$strMethod}($objRow->row(), $label, $this, $folderAttribute, false, $blnProtected);
     } elseif (is_callable($this->arrDca['list']['label']['label_callback'])) {
         return $this->arrDca['list']['label']['label_callback']($objRow->row(), $label, $this, $folderAttribute, false, $blnProtected);
     } else {
         return $label;
     }
     return $label;
 }
 protected function parseItem($objItem, $strClass = '', $intCount = 0)
 {
     // work on a cloned item for supporting multiple reader modules on a single page
     $objItemTmp = unserialize(serialize($objItem));
     // prepare item
     $objDc = new \DC_Table($this->formHybridDataContainer);
     $objDc->activeRecord = $objItemTmp;
     // untransformed values in the raw array
     $objItemTmp->raw = $objItemTmp->row();
     // transform and escape values
     foreach ($objItemTmp->row() as $strField => $varValue) {
         if ($strField == 'raw') {
             continue;
         }
         $varValue = FormSubmission::prepareSpecialValueForPrint($varValue, $this->dca['fields'][$strField], $this->formHybridDataContainer, $objDc, $objItemTmp);
         $objItemTmp->{$strField} = FormHelper::escapeAllEntities($this->formHybridDataContainer, $strField, $varValue);
     }
     if ($this->publishedField) {
         $objItemTmp->isPublished = $this->invertPublishedField ? !$objItemTmp->{$this->publishedField} : $objItemTmp->{$this->publishedField};
     }
     $objTemplate = new \FrontendTemplate($this->itemTemplate ?: 'formhybrid_reader_default');
     // items contain module and item params (higher priority: item)
     $objTemplate->setData($objItemTmp->row() + $this->arrData);
     $objTemplate->class = $strClass;
     $objTemplate->formHybridDataContainer = $this->formHybridDataContainer;
     $objTemplate->useDummyImage = $this->useDummyImage;
     $objTemplate->dummyImage = $this->dummyImage;
     $objTemplate->imgSize = deserialize($this->imgSize, true);
     $this->runBeforeTemplateParsing($objTemplate, $objItemTmp);
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['parseItems']) && is_array($GLOBALS['TL_HOOKS']['parseItems'])) {
         foreach ($GLOBALS['TL_HOOKS']['parseItems'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($objTemplate, $objItemTmp, $this);
         }
     }
     return $objTemplate->parse();
 }
 protected function generateFields($objItem)
 {
     $arrItem = array();
     $arrDca =& $GLOBALS['TL_DCA'][$this->formHybridDataContainer];
     // always add id
     $arrItem['raw']['id'] = $objItem->id;
     $objDc = new \DC_Table($this->formHybridDataContainer);
     $objDc->activeRecord = $objItem;
     if ($this->isTableList) {
         foreach ($this->arrTableFields as $strField) {
             $arrItem['fields'][$strField] = FormSubmission::prepareSpecialValueForPrint($objItem->{$strField}, $this->dca['fields'][$strField], $this->formHybridDataContainer, $objDc, $objItem);
             if (is_array($arrDca['fields'][$strField]['load_callback'])) {
                 foreach ($arrDca['fields'][$strField]['load_callback'] as $callback) {
                     $this->import($callback[0]);
                     $arrItem['fields'][$strField] = $this->{$callback}[0]->{$callback}[1]($arrItem['fields'][$strField], $objDc);
                 }
             }
             // anti-xss: escape everything besides some tags
             $arrItem['fields'][$strField] = FormHelper::escapeAllEntities($this->formHybridDataContainer, $strField, $arrItem['fields'][$strField]);
         }
     } else {
         foreach ($arrDca['fields'] as $strField => $arrData) {
             $arrItem['fields'][$strField] = FormSubmission::prepareSpecialValueForPrint($objItem->{$strField}, $this->dca['fields'][$strField], $this->formHybridDataContainer, $objDc, $objItem);
             // anti-xss: escape everything besides some tags
             $arrItem['fields'][$strField] = FormHelper::escapeAllEntities($this->formHybridDataContainer, $strField, $arrItem['fields'][$strField]);
         }
     }
     // add raw values
     foreach ($GLOBALS['TL_DCA'][$this->formHybridDataContainer]['fields'] as $strField => $arrData) {
         $arrItem['raw'][$strField] = $objItem->{$strField};
     }
     if ($this->publishedField) {
         $arrItem['isPublished'] = $this->invertPublishedField ? !$objItem->{$this->publishedField} : $objItem->{$this->publishedField};
     }
     return $arrItem;
 }