/** * Generate header depending on download handling setting in TS * * Functionality is taken from FPDF! * * @throws Exception */ protected function sendHeader() { switch ($this->exportConfiguration->getDownloadType()) { case Tx_PtExtlist_Domain_Configuration_Export_ExportConfig::OPEN_IN_BROWSER: if ($this->exportConfiguration->getContentType()) { header('Content-Type: ' . $this->exportConfiguration->getContentType()); } if (headers_sent()) { throw new Exception('Some data has already been output to browser, can\'t send Export file.', 1283945901); } header('Content-disposition: inline; filename="' . $this->getFilenameFromTs() . '"'); break; case Tx_PtExtlist_Domain_Configuration_Export_ExportConfig::FORCE_DOWNLOAD: if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { header('Content-Type: application/force-download, charset=' . $this->exportConfiguration->getSettings('outputEncoding')); } else { header('Content-Type: application/octet-stream, charset=' . $this->exportConfiguration->getSettings('outputEncoding')); } header('Content-disposition: attachment; filename="' . $this->getFilenameFromTs() . '"'); break; default: throw new Exception('No valid download handling set for Export file!', 1283945902); } }
/** * @param string $exportIdentifier * @return string * @throws Exception */ public function downloadAction($exportIdentifier) { $exportSettingsPath = $this->extlistTypoScriptSettingsPath . '.export.exportConfigs.' . $exportIdentifier; $exportSettings = \PunktDe\PtExtbase\Utility\NamespaceUtility::getArrayContentByArrayAndNamespace($this->settings, $exportSettingsPath); if (!is_array($exportSettings) || empty($exportSettings)) { throw new Exception('No export settings found within the path ' . $exportSettingsPath, 1331644291); } $exportConfig = new Tx_PtExtlist_Domain_Configuration_Export_ExportConfig($this->configurationBuilder, $exportSettings); if (array_key_exists('exportListSettingsPath', $exportSettings)) { $exportListSettings = \PunktDe\PtExtbase\Utility\NamespaceUtility::getArrayContentByArrayAndNamespace($this->settings, $exportSettings['exportListSettingsPath']); } else { $exportListSettings = $this->configurationBuilder->getSettings(); } $extListContext = Tx_PtExtlist_ExtlistContext_ExtlistContextFactory::getContextByCustomConfiguration($exportListSettings, $this->listIdentifier, false); $list = $extListContext->getList(true); $view = $this->objectManager->get($exportConfig->getViewClassName()); $view->setConfigurationBuilder($extListContext->getConfigurationBuilder()); $view->setExportConfiguration($exportConfig); $view->assign('listHeader', $list->getListHeader()); $view->assign('listCaptions', $list->getRenderedListHeader()); $view->assign('listData', $list->getRenderedListData()); $view->assign('aggregateRows', $list->getRenderedAggregateListData()); return $view->render(); }