@@ -17,104 +17,104 @@ |
||
| 17 | 17 | class ToXlsViewHelper extends AbstractToFormatViewHelper |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Render a CSV export request. |
|
| 22 | - * |
|
| 23 | - * @return boolean |
|
| 24 | - * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 25 | - */ |
|
| 26 | - public function render() |
|
| 27 | - { |
|
| 28 | - |
|
| 29 | - $objects = $this->templateVariableContainer->get('objects'); |
|
| 30 | - |
|
| 31 | - // Make sure we have something to process... |
|
| 32 | - if (!empty($objects)) { |
|
| 33 | - |
|
| 34 | - // Initialization step. |
|
| 35 | - $this->initializeEnvironment($objects); |
|
| 36 | - $this->exportFileNameAndPath .= '.xls'; // add extension to the file. |
|
| 37 | - |
|
| 38 | - // Write the exported data to a CSV file. |
|
| 39 | - $this->writeXlsFile($objects); |
|
| 40 | - |
|
| 41 | - // We must generate a zip archive since there are files included. |
|
| 42 | - if ($this->hasCollectedFiles()) { |
|
| 43 | - |
|
| 44 | - $this->writeZipFile(); |
|
| 45 | - $this->sendZipHttpHeaders(); |
|
| 46 | - |
|
| 47 | - readfile($this->zipFileNameAndPath); |
|
| 48 | - } else { |
|
| 49 | - $this->sendXlsHttpHeaders(); |
|
| 50 | - readfile($this->exportFileNameAndPath); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - GeneralUtility::rmdir($this->temporaryDirectory, true); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Write the CSV file to a temporary location. |
|
| 59 | - * |
|
| 60 | - * @param array $objects |
|
| 61 | - * @return void |
|
| 62 | - * @throws \InvalidArgumentException |
|
| 63 | - */ |
|
| 64 | - protected function writeXlsFile(array $objects) |
|
| 65 | - { |
|
| 66 | - |
|
| 67 | - /** @var SpreadSheetService $spreadSheet */ |
|
| 68 | - $spreadSheet = GeneralUtility::makeInstance(SpreadSheetService::class); |
|
| 69 | - |
|
| 70 | - // Handle object header, get the first object and get the list of fields. |
|
| 71 | - /** @var \Fab\Vidi\Domain\Model\Content $object */ |
|
| 72 | - $object = reset($objects); |
|
| 73 | - $spreadSheet->addRow($object->toFields()); |
|
| 74 | - |
|
| 75 | - $this->checkWhetherObjectMayIncludeFiles($object); |
|
| 76 | - |
|
| 77 | - foreach ($objects as $object) { |
|
| 78 | - if ($this->hasFileFields()) { |
|
| 79 | - $this->collectFiles($object); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - // Make sure we have a flat array of values for the CSV purpose. |
|
| 83 | - $flattenValues = []; |
|
| 84 | - foreach ($object->toValues() as $fieldName => $value) { |
|
| 85 | - if (is_array($value)) { |
|
| 86 | - $flattenValues[$fieldName] = implode(', ', $value); |
|
| 87 | - } else { |
|
| 88 | - $flattenValues[$fieldName] = $value; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - $spreadSheet->addRow($flattenValues); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - file_put_contents($this->exportFileNameAndPath, $spreadSheet->toString()); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @return void |
|
| 100 | - * @throws \InvalidArgumentException |
|
| 101 | - * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 102 | - */ |
|
| 103 | - protected function sendXlsHttpHeaders() |
|
| 104 | - { |
|
| 105 | - |
|
| 106 | - /** @var \TYPO3\CMS\Extbase\Mvc\Web\Response $response */ |
|
| 107 | - $response = $this->templateVariableContainer->get('response'); |
|
| 108 | - $response->setHeader('Pragma', 'public'); |
|
| 109 | - $response->setHeader('Expires', '0'); |
|
| 110 | - $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0'); |
|
| 111 | - $response->setHeader('Content-Type', 'application/vnd.ms-excel'); |
|
| 112 | - $response->setHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"'); |
|
| 113 | - $response->setHeader('Content-Length', filesize($this->exportFileNameAndPath)); |
|
| 114 | - $response->setHeader('Content-Description', 'File Transfer'); |
|
| 115 | - $response->setHeader('Content-Transfer-Encoding', 'binary'); |
|
| 116 | - |
|
| 117 | - $response->sendHeaders(); |
|
| 118 | - } |
|
| 20 | + /** |
|
| 21 | + * Render a CSV export request. |
|
| 22 | + * |
|
| 23 | + * @return boolean |
|
| 24 | + * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 25 | + */ |
|
| 26 | + public function render() |
|
| 27 | + { |
|
| 28 | + |
|
| 29 | + $objects = $this->templateVariableContainer->get('objects'); |
|
| 30 | + |
|
| 31 | + // Make sure we have something to process... |
|
| 32 | + if (!empty($objects)) { |
|
| 33 | + |
|
| 34 | + // Initialization step. |
|
| 35 | + $this->initializeEnvironment($objects); |
|
| 36 | + $this->exportFileNameAndPath .= '.xls'; // add extension to the file. |
|
| 37 | + |
|
| 38 | + // Write the exported data to a CSV file. |
|
| 39 | + $this->writeXlsFile($objects); |
|
| 40 | + |
|
| 41 | + // We must generate a zip archive since there are files included. |
|
| 42 | + if ($this->hasCollectedFiles()) { |
|
| 43 | + |
|
| 44 | + $this->writeZipFile(); |
|
| 45 | + $this->sendZipHttpHeaders(); |
|
| 46 | + |
|
| 47 | + readfile($this->zipFileNameAndPath); |
|
| 48 | + } else { |
|
| 49 | + $this->sendXlsHttpHeaders(); |
|
| 50 | + readfile($this->exportFileNameAndPath); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + GeneralUtility::rmdir($this->temporaryDirectory, true); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Write the CSV file to a temporary location. |
|
| 59 | + * |
|
| 60 | + * @param array $objects |
|
| 61 | + * @return void |
|
| 62 | + * @throws \InvalidArgumentException |
|
| 63 | + */ |
|
| 64 | + protected function writeXlsFile(array $objects) |
|
| 65 | + { |
|
| 66 | + |
|
| 67 | + /** @var SpreadSheetService $spreadSheet */ |
|
| 68 | + $spreadSheet = GeneralUtility::makeInstance(SpreadSheetService::class); |
|
| 69 | + |
|
| 70 | + // Handle object header, get the first object and get the list of fields. |
|
| 71 | + /** @var \Fab\Vidi\Domain\Model\Content $object */ |
|
| 72 | + $object = reset($objects); |
|
| 73 | + $spreadSheet->addRow($object->toFields()); |
|
| 74 | + |
|
| 75 | + $this->checkWhetherObjectMayIncludeFiles($object); |
|
| 76 | + |
|
| 77 | + foreach ($objects as $object) { |
|
| 78 | + if ($this->hasFileFields()) { |
|
| 79 | + $this->collectFiles($object); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + // Make sure we have a flat array of values for the CSV purpose. |
|
| 83 | + $flattenValues = []; |
|
| 84 | + foreach ($object->toValues() as $fieldName => $value) { |
|
| 85 | + if (is_array($value)) { |
|
| 86 | + $flattenValues[$fieldName] = implode(', ', $value); |
|
| 87 | + } else { |
|
| 88 | + $flattenValues[$fieldName] = $value; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + $spreadSheet->addRow($flattenValues); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + file_put_contents($this->exportFileNameAndPath, $spreadSheet->toString()); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @return void |
|
| 100 | + * @throws \InvalidArgumentException |
|
| 101 | + * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 102 | + */ |
|
| 103 | + protected function sendXlsHttpHeaders() |
|
| 104 | + { |
|
| 105 | + |
|
| 106 | + /** @var \TYPO3\CMS\Extbase\Mvc\Web\Response $response */ |
|
| 107 | + $response = $this->templateVariableContainer->get('response'); |
|
| 108 | + $response->setHeader('Pragma', 'public'); |
|
| 109 | + $response->setHeader('Expires', '0'); |
|
| 110 | + $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0'); |
|
| 111 | + $response->setHeader('Content-Type', 'application/vnd.ms-excel'); |
|
| 112 | + $response->setHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"'); |
|
| 113 | + $response->setHeader('Content-Length', filesize($this->exportFileNameAndPath)); |
|
| 114 | + $response->setHeader('Content-Description', 'File Transfer'); |
|
| 115 | + $response->setHeader('Content-Transfer-Encoding', 'binary'); |
|
| 116 | + |
|
| 117 | + $response->sendHeaders(); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | } |
@@ -18,59 +18,59 @@ |
||
| 18 | 18 | class ToJsonViewHelper extends AbstractViewHelper |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Render a Json response |
|
| 23 | - * |
|
| 24 | - * @return boolean |
|
| 25 | - * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 26 | - */ |
|
| 27 | - public function render() |
|
| 28 | - { |
|
| 21 | + /** |
|
| 22 | + * Render a Json response |
|
| 23 | + * |
|
| 24 | + * @return boolean |
|
| 25 | + * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 26 | + */ |
|
| 27 | + public function render() |
|
| 28 | + { |
|
| 29 | 29 | |
| 30 | - $objects = $this->templateVariableContainer->get('objects'); |
|
| 31 | - $columns = $this->templateVariableContainer->get('columns'); |
|
| 32 | - $output = array( |
|
| 33 | - 'sEcho' => $this->getNextTransactionId(), |
|
| 34 | - 'iTotalRecords' => $this->templateVariableContainer->get('numberOfObjects'), |
|
| 35 | - 'iTotalDisplayRecords' => $this->templateVariableContainer->get('numberOfObjects'), |
|
| 36 | - 'iNumberOfRecords' => count($objects), |
|
| 37 | - 'aaData' => $this->getRowsViewHelper()->render($objects, $columns), |
|
| 38 | - ); |
|
| 30 | + $objects = $this->templateVariableContainer->get('objects'); |
|
| 31 | + $columns = $this->templateVariableContainer->get('columns'); |
|
| 32 | + $output = array( |
|
| 33 | + 'sEcho' => $this->getNextTransactionId(), |
|
| 34 | + 'iTotalRecords' => $this->templateVariableContainer->get('numberOfObjects'), |
|
| 35 | + 'iTotalDisplayRecords' => $this->templateVariableContainer->get('numberOfObjects'), |
|
| 36 | + 'iNumberOfRecords' => count($objects), |
|
| 37 | + 'aaData' => $this->getRowsViewHelper()->render($objects, $columns), |
|
| 38 | + ); |
|
| 39 | 39 | |
| 40 | - $this->setHttpHeaders(); |
|
| 41 | - return json_encode($output); |
|
| 42 | - } |
|
| 40 | + $this->setHttpHeaders(); |
|
| 41 | + return json_encode($output); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return int |
|
| 46 | - */ |
|
| 47 | - protected function getNextTransactionId() |
|
| 48 | - { |
|
| 49 | - $transaction = 0; |
|
| 50 | - if (GeneralUtility::_GET('sEcho')) { |
|
| 51 | - $transaction = (int)GeneralUtility::_GET('sEcho') + 1; |
|
| 52 | - } |
|
| 53 | - return $transaction; |
|
| 54 | - } |
|
| 44 | + /** |
|
| 45 | + * @return int |
|
| 46 | + */ |
|
| 47 | + protected function getNextTransactionId() |
|
| 48 | + { |
|
| 49 | + $transaction = 0; |
|
| 50 | + if (GeneralUtility::_GET('sEcho')) { |
|
| 51 | + $transaction = (int)GeneralUtility::_GET('sEcho') + 1; |
|
| 52 | + } |
|
| 53 | + return $transaction; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @return void |
|
| 58 | - * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 59 | - * @throws \InvalidArgumentException |
|
| 60 | - */ |
|
| 61 | - protected function setHttpHeaders() |
|
| 62 | - { |
|
| 63 | - /** @var \TYPO3\CMS\Extbase\Mvc\Web\Response $response */ |
|
| 64 | - $response = $this->templateVariableContainer->get('response'); |
|
| 65 | - $response->setHeader('Content-Type', 'application/json'); |
|
| 66 | - $response->sendHeaders(); |
|
| 67 | - } |
|
| 56 | + /** |
|
| 57 | + * @return void |
|
| 58 | + * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 59 | + * @throws \InvalidArgumentException |
|
| 60 | + */ |
|
| 61 | + protected function setHttpHeaders() |
|
| 62 | + { |
|
| 63 | + /** @var \TYPO3\CMS\Extbase\Mvc\Web\Response $response */ |
|
| 64 | + $response = $this->templateVariableContainer->get('response'); |
|
| 65 | + $response->setHeader('Content-Type', 'application/json'); |
|
| 66 | + $response->sendHeaders(); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @return RowsViewHelper |
|
| 71 | - */ |
|
| 72 | - protected function getRowsViewHelper() |
|
| 73 | - { |
|
| 74 | - return $this->objectManager->get(RowsViewHelper::class); |
|
| 75 | - } |
|
| 69 | + /** |
|
| 70 | + * @return RowsViewHelper |
|
| 71 | + */ |
|
| 72 | + protected function getRowsViewHelper() |
|
| 73 | + { |
|
| 74 | + return $this->objectManager->get(RowsViewHelper::class); |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -23,173 +23,173 @@ |
||
| 23 | 23 | abstract class AbstractToFormatViewHelper extends AbstractViewHelper |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Store fields of type "file". |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $fileTypeProperties = []; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var File[] |
|
| 35 | - */ |
|
| 36 | - protected $collectedFiles = []; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected $exportFileNameAndPath; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - protected $zipFileNameAndPath; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 51 | - protected $temporaryDirectory; |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Write the zip file to a temporary location. |
|
| 56 | - * |
|
| 57 | - * @return void |
|
| 58 | - * @throws \RuntimeException |
|
| 59 | - */ |
|
| 60 | - protected function writeZipFile() |
|
| 61 | - { |
|
| 62 | - |
|
| 63 | - $zip = new \ZipArchive(); |
|
| 64 | - $zip->open($this->zipFileNameAndPath, \ZipArchive::CREATE); |
|
| 65 | - |
|
| 66 | - // Add the CSV content into the zipball. |
|
| 67 | - $zip->addFile($this->exportFileNameAndPath, basename($this->exportFileNameAndPath)); |
|
| 68 | - |
|
| 69 | - // Add the files into the zipball. |
|
| 70 | - foreach ($this->collectedFiles as $file) { |
|
| 71 | - $zip->addFile($file->getForLocalProcessing(false), $file->getIdentifier()); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - $zip->close(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Initialize some properties |
|
| 79 | - * |
|
| 80 | - * @param array $objects |
|
| 81 | - * @return void |
|
| 82 | - */ |
|
| 83 | - protected function initializeEnvironment(array $objects) |
|
| 84 | - { |
|
| 85 | - |
|
| 86 | - /** @var \Fab\Vidi\Domain\Model\Content $object */ |
|
| 87 | - $object = reset($objects); |
|
| 88 | - |
|
| 89 | - $this->temporaryDirectory = PATH_site . 'typo3temp/' . uniqid() . '/'; |
|
| 90 | - GeneralUtility::mkdir($this->temporaryDirectory); |
|
| 91 | - |
|
| 92 | - // Compute file name and path variable |
|
| 93 | - $this->exportFileNameAndPath = $this->temporaryDirectory . $object->getDataType() . '-' . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']); |
|
| 94 | - |
|
| 95 | - // Compute file name and path variable for zip |
|
| 96 | - $zipFileName = $object->getDataType() . '-' . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']) . '.zip'; |
|
| 97 | - $this->zipFileNameAndPath = $this->temporaryDirectory . $zipFileName; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Fetch the files given an object. |
|
| 102 | - * |
|
| 103 | - * @param \Fab\Vidi\Domain\Model\Content $object |
|
| 104 | - * @return void |
|
| 105 | - */ |
|
| 106 | - protected function collectFiles(Content $object) |
|
| 107 | - { |
|
| 108 | - foreach ($this->fileTypeProperties as $property) { |
|
| 109 | - $files = FileReferenceService::getInstance()->findReferencedBy($property, $object); |
|
| 110 | - foreach ($files as $file) { |
|
| 111 | - $this->collectedFiles[$file->getUid()] = $file; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Tells whether the object has fields containing files. |
|
| 118 | - * |
|
| 119 | - * @return boolean |
|
| 120 | - */ |
|
| 121 | - protected function hasCollectedFiles() |
|
| 122 | - { |
|
| 123 | - return !empty($this->collectedFiles); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Tells whether the object has fields containing files. |
|
| 128 | - * |
|
| 129 | - * @return boolean |
|
| 130 | - */ |
|
| 131 | - protected function hasFileFields() |
|
| 132 | - { |
|
| 133 | - return !empty($this->fileTypeProperties); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Check whether the given object is meant to include files in some fields. |
|
| 138 | - * |
|
| 139 | - * @param Content $object |
|
| 140 | - * @return void |
|
| 141 | - * @throws \Fab\Vidi\Exception\NotExistingClassException |
|
| 142 | - */ |
|
| 143 | - protected function checkWhetherObjectMayIncludeFiles(Content $object) |
|
| 144 | - { |
|
| 145 | - if (Tca::grid($object->getDataType())->areFilesIncludedInExport()) { |
|
| 146 | - foreach ($object->toFields() as $fieldName) { |
|
| 147 | - $fieldType = Tca::table($object->getDataType())->field($fieldName)->getType(); |
|
| 148 | - |
|
| 149 | - if ($fieldType === FieldType::FILE) { |
|
| 150 | - $this->fileTypeProperties[] = GeneralUtility::camelCaseToLowerCaseUnderscored($fieldName); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @return void |
|
| 158 | - * @throws \InvalidArgumentException |
|
| 159 | - * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 160 | - */ |
|
| 161 | - protected function sendZipHttpHeaders() |
|
| 162 | - { |
|
| 163 | - |
|
| 164 | - /** @var \TYPO3\CMS\Extbase\Mvc\Web\Response $response */ |
|
| 165 | - $response = $this->templateVariableContainer->get('response'); |
|
| 166 | - $response->setHeader('Pragma', 'public'); |
|
| 167 | - $response->setHeader('Expires', '0'); |
|
| 168 | - $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0'); |
|
| 169 | - $response->setHeader('Content-Type', 'application/zip'); |
|
| 170 | - $response->setHeader('Content-Disposition', 'attachment; filename="' . basename($this->zipFileNameAndPath) . '"'); |
|
| 171 | - $response->setHeader('Content-Length', filesize($this->zipFileNameAndPath)); |
|
| 172 | - $response->setHeader('Content-Description', 'File Transfer'); |
|
| 173 | - $response->setHeader('Content-Transfer-Encoding', 'binary'); |
|
| 174 | - |
|
| 175 | - $response->sendHeaders(); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @return RowsViewHelper |
|
| 180 | - */ |
|
| 181 | - protected function getRowsViewHelper() |
|
| 182 | - { |
|
| 183 | - return $this->objectManager->get(RowsViewHelper::class); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Returns a pointer to the database. |
|
| 188 | - * |
|
| 189 | - * @return \TYPO3\CMS\Core\Database\DatabaseConnection |
|
| 190 | - */ |
|
| 191 | - protected function getDatabaseConnection() |
|
| 192 | - { |
|
| 193 | - return $GLOBALS['TYPO3_DB']; |
|
| 194 | - } |
|
| 26 | + /** |
|
| 27 | + * Store fields of type "file". |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $fileTypeProperties = []; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var File[] |
|
| 35 | + */ |
|
| 36 | + protected $collectedFiles = []; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected $exportFileNameAndPath; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + protected $zipFileNameAndPath; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | + protected $temporaryDirectory; |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Write the zip file to a temporary location. |
|
| 56 | + * |
|
| 57 | + * @return void |
|
| 58 | + * @throws \RuntimeException |
|
| 59 | + */ |
|
| 60 | + protected function writeZipFile() |
|
| 61 | + { |
|
| 62 | + |
|
| 63 | + $zip = new \ZipArchive(); |
|
| 64 | + $zip->open($this->zipFileNameAndPath, \ZipArchive::CREATE); |
|
| 65 | + |
|
| 66 | + // Add the CSV content into the zipball. |
|
| 67 | + $zip->addFile($this->exportFileNameAndPath, basename($this->exportFileNameAndPath)); |
|
| 68 | + |
|
| 69 | + // Add the files into the zipball. |
|
| 70 | + foreach ($this->collectedFiles as $file) { |
|
| 71 | + $zip->addFile($file->getForLocalProcessing(false), $file->getIdentifier()); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + $zip->close(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Initialize some properties |
|
| 79 | + * |
|
| 80 | + * @param array $objects |
|
| 81 | + * @return void |
|
| 82 | + */ |
|
| 83 | + protected function initializeEnvironment(array $objects) |
|
| 84 | + { |
|
| 85 | + |
|
| 86 | + /** @var \Fab\Vidi\Domain\Model\Content $object */ |
|
| 87 | + $object = reset($objects); |
|
| 88 | + |
|
| 89 | + $this->temporaryDirectory = PATH_site . 'typo3temp/' . uniqid() . '/'; |
|
| 90 | + GeneralUtility::mkdir($this->temporaryDirectory); |
|
| 91 | + |
|
| 92 | + // Compute file name and path variable |
|
| 93 | + $this->exportFileNameAndPath = $this->temporaryDirectory . $object->getDataType() . '-' . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']); |
|
| 94 | + |
|
| 95 | + // Compute file name and path variable for zip |
|
| 96 | + $zipFileName = $object->getDataType() . '-' . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']) . '.zip'; |
|
| 97 | + $this->zipFileNameAndPath = $this->temporaryDirectory . $zipFileName; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Fetch the files given an object. |
|
| 102 | + * |
|
| 103 | + * @param \Fab\Vidi\Domain\Model\Content $object |
|
| 104 | + * @return void |
|
| 105 | + */ |
|
| 106 | + protected function collectFiles(Content $object) |
|
| 107 | + { |
|
| 108 | + foreach ($this->fileTypeProperties as $property) { |
|
| 109 | + $files = FileReferenceService::getInstance()->findReferencedBy($property, $object); |
|
| 110 | + foreach ($files as $file) { |
|
| 111 | + $this->collectedFiles[$file->getUid()] = $file; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Tells whether the object has fields containing files. |
|
| 118 | + * |
|
| 119 | + * @return boolean |
|
| 120 | + */ |
|
| 121 | + protected function hasCollectedFiles() |
|
| 122 | + { |
|
| 123 | + return !empty($this->collectedFiles); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Tells whether the object has fields containing files. |
|
| 128 | + * |
|
| 129 | + * @return boolean |
|
| 130 | + */ |
|
| 131 | + protected function hasFileFields() |
|
| 132 | + { |
|
| 133 | + return !empty($this->fileTypeProperties); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Check whether the given object is meant to include files in some fields. |
|
| 138 | + * |
|
| 139 | + * @param Content $object |
|
| 140 | + * @return void |
|
| 141 | + * @throws \Fab\Vidi\Exception\NotExistingClassException |
|
| 142 | + */ |
|
| 143 | + protected function checkWhetherObjectMayIncludeFiles(Content $object) |
|
| 144 | + { |
|
| 145 | + if (Tca::grid($object->getDataType())->areFilesIncludedInExport()) { |
|
| 146 | + foreach ($object->toFields() as $fieldName) { |
|
| 147 | + $fieldType = Tca::table($object->getDataType())->field($fieldName)->getType(); |
|
| 148 | + |
|
| 149 | + if ($fieldType === FieldType::FILE) { |
|
| 150 | + $this->fileTypeProperties[] = GeneralUtility::camelCaseToLowerCaseUnderscored($fieldName); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @return void |
|
| 158 | + * @throws \InvalidArgumentException |
|
| 159 | + * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 160 | + */ |
|
| 161 | + protected function sendZipHttpHeaders() |
|
| 162 | + { |
|
| 163 | + |
|
| 164 | + /** @var \TYPO3\CMS\Extbase\Mvc\Web\Response $response */ |
|
| 165 | + $response = $this->templateVariableContainer->get('response'); |
|
| 166 | + $response->setHeader('Pragma', 'public'); |
|
| 167 | + $response->setHeader('Expires', '0'); |
|
| 168 | + $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0'); |
|
| 169 | + $response->setHeader('Content-Type', 'application/zip'); |
|
| 170 | + $response->setHeader('Content-Disposition', 'attachment; filename="' . basename($this->zipFileNameAndPath) . '"'); |
|
| 171 | + $response->setHeader('Content-Length', filesize($this->zipFileNameAndPath)); |
|
| 172 | + $response->setHeader('Content-Description', 'File Transfer'); |
|
| 173 | + $response->setHeader('Content-Transfer-Encoding', 'binary'); |
|
| 174 | + |
|
| 175 | + $response->sendHeaders(); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @return RowsViewHelper |
|
| 180 | + */ |
|
| 181 | + protected function getRowsViewHelper() |
|
| 182 | + { |
|
| 183 | + return $this->objectManager->get(RowsViewHelper::class); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Returns a pointer to the database. |
|
| 188 | + * |
|
| 189 | + * @return \TYPO3\CMS\Core\Database\DatabaseConnection |
|
| 190 | + */ |
|
| 191 | + protected function getDatabaseConnection() |
|
| 192 | + { |
|
| 193 | + return $GLOBALS['TYPO3_DB']; |
|
| 194 | + } |
|
| 195 | 195 | } |
@@ -16,100 +16,100 @@ |
||
| 16 | 16 | class ToCsvViewHelper extends AbstractToFormatViewHelper |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Render a CSV export request. |
|
| 21 | - * |
|
| 22 | - * @return boolean |
|
| 23 | - * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 24 | - */ |
|
| 25 | - public function render() |
|
| 26 | - { |
|
| 27 | - |
|
| 28 | - $objects = $this->templateVariableContainer->get('objects'); |
|
| 29 | - |
|
| 30 | - // Make sure we have something to process... |
|
| 31 | - if (!empty($objects)) { |
|
| 32 | - |
|
| 33 | - // Initialization step. |
|
| 34 | - $this->initializeEnvironment($objects); |
|
| 35 | - $this->exportFileNameAndPath .= '.csv'; // add extension to the file. |
|
| 36 | - |
|
| 37 | - // Write the exported data to a CSV file. |
|
| 38 | - $this->writeCsvFile($objects); |
|
| 39 | - |
|
| 40 | - // We must generate a zip archive since there are files included. |
|
| 41 | - if ($this->hasCollectedFiles()) { |
|
| 42 | - |
|
| 43 | - $this->writeZipFile(); |
|
| 44 | - $this->sendZipHttpHeaders(); |
|
| 45 | - |
|
| 46 | - readfile($this->zipFileNameAndPath); |
|
| 47 | - } else { |
|
| 48 | - $this->sendCsvHttpHeaders(); |
|
| 49 | - readfile($this->exportFileNameAndPath); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - GeneralUtility::rmdir($this->temporaryDirectory, true); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Write the CSV file to a temporary location. |
|
| 58 | - * |
|
| 59 | - * @param array $objects |
|
| 60 | - * @return void |
|
| 61 | - * @throws \Exception |
|
| 62 | - */ |
|
| 63 | - protected function writeCsvFile(array $objects) |
|
| 64 | - { |
|
| 65 | - |
|
| 66 | - // Create a file pointer |
|
| 67 | - $output = fopen($this->exportFileNameAndPath, 'w'); |
|
| 68 | - |
|
| 69 | - // Handle CSV header, get the first object and get the list of fields. |
|
| 70 | - /** @var \Fab\Vidi\Domain\Model\Content $object */ |
|
| 71 | - $object = reset($objects); |
|
| 72 | - fputcsv($output, $object->toFields()); |
|
| 73 | - $this->checkWhetherObjectMayIncludeFiles($object); |
|
| 74 | - |
|
| 75 | - foreach ($objects as $object) { |
|
| 76 | - if ($this->hasFileFields()) { |
|
| 77 | - $this->collectFiles($object); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // Make sure we have a flat array of values for the CSV purpose. |
|
| 81 | - $flattenValues = []; |
|
| 82 | - foreach ($object->toValues() as $fieldName => $value) { |
|
| 83 | - if (is_array($value)) { |
|
| 84 | - $flattenValues[$fieldName] = implode(', ', $value); |
|
| 85 | - } else { |
|
| 86 | - $flattenValues[$fieldName] = str_replace("\n", "\r", $value); // for Excel purpose. |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - fputcsv($output, $flattenValues); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // close file handler |
|
| 94 | - fclose($output); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @return void |
|
| 99 | - * @throws \InvalidArgumentException |
|
| 100 | - * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 101 | - */ |
|
| 102 | - protected function sendCsvHttpHeaders() |
|
| 103 | - { |
|
| 104 | - |
|
| 105 | - /** @var \TYPO3\CMS\Extbase\Mvc\Web\Response $response */ |
|
| 106 | - $response = $this->templateVariableContainer->get('response'); |
|
| 107 | - $response->setHeader('Content-Type', 'application/csv'); |
|
| 108 | - $response->setHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"'); |
|
| 109 | - $response->setHeader('Content-Length', filesize($this->exportFileNameAndPath)); |
|
| 110 | - $response->setHeader('Content-Description', 'File Transfer'); |
|
| 111 | - |
|
| 112 | - $response->sendHeaders(); |
|
| 113 | - } |
|
| 19 | + /** |
|
| 20 | + * Render a CSV export request. |
|
| 21 | + * |
|
| 22 | + * @return boolean |
|
| 23 | + * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 24 | + */ |
|
| 25 | + public function render() |
|
| 26 | + { |
|
| 27 | + |
|
| 28 | + $objects = $this->templateVariableContainer->get('objects'); |
|
| 29 | + |
|
| 30 | + // Make sure we have something to process... |
|
| 31 | + if (!empty($objects)) { |
|
| 32 | + |
|
| 33 | + // Initialization step. |
|
| 34 | + $this->initializeEnvironment($objects); |
|
| 35 | + $this->exportFileNameAndPath .= '.csv'; // add extension to the file. |
|
| 36 | + |
|
| 37 | + // Write the exported data to a CSV file. |
|
| 38 | + $this->writeCsvFile($objects); |
|
| 39 | + |
|
| 40 | + // We must generate a zip archive since there are files included. |
|
| 41 | + if ($this->hasCollectedFiles()) { |
|
| 42 | + |
|
| 43 | + $this->writeZipFile(); |
|
| 44 | + $this->sendZipHttpHeaders(); |
|
| 45 | + |
|
| 46 | + readfile($this->zipFileNameAndPath); |
|
| 47 | + } else { |
|
| 48 | + $this->sendCsvHttpHeaders(); |
|
| 49 | + readfile($this->exportFileNameAndPath); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + GeneralUtility::rmdir($this->temporaryDirectory, true); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Write the CSV file to a temporary location. |
|
| 58 | + * |
|
| 59 | + * @param array $objects |
|
| 60 | + * @return void |
|
| 61 | + * @throws \Exception |
|
| 62 | + */ |
|
| 63 | + protected function writeCsvFile(array $objects) |
|
| 64 | + { |
|
| 65 | + |
|
| 66 | + // Create a file pointer |
|
| 67 | + $output = fopen($this->exportFileNameAndPath, 'w'); |
|
| 68 | + |
|
| 69 | + // Handle CSV header, get the first object and get the list of fields. |
|
| 70 | + /** @var \Fab\Vidi\Domain\Model\Content $object */ |
|
| 71 | + $object = reset($objects); |
|
| 72 | + fputcsv($output, $object->toFields()); |
|
| 73 | + $this->checkWhetherObjectMayIncludeFiles($object); |
|
| 74 | + |
|
| 75 | + foreach ($objects as $object) { |
|
| 76 | + if ($this->hasFileFields()) { |
|
| 77 | + $this->collectFiles($object); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // Make sure we have a flat array of values for the CSV purpose. |
|
| 81 | + $flattenValues = []; |
|
| 82 | + foreach ($object->toValues() as $fieldName => $value) { |
|
| 83 | + if (is_array($value)) { |
|
| 84 | + $flattenValues[$fieldName] = implode(', ', $value); |
|
| 85 | + } else { |
|
| 86 | + $flattenValues[$fieldName] = str_replace("\n", "\r", $value); // for Excel purpose. |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + fputcsv($output, $flattenValues); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // close file handler |
|
| 94 | + fclose($output); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @return void |
|
| 99 | + * @throws \InvalidArgumentException |
|
| 100 | + * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 101 | + */ |
|
| 102 | + protected function sendCsvHttpHeaders() |
|
| 103 | + { |
|
| 104 | + |
|
| 105 | + /** @var \TYPO3\CMS\Extbase\Mvc\Web\Response $response */ |
|
| 106 | + $response = $this->templateVariableContainer->get('response'); |
|
| 107 | + $response->setHeader('Content-Type', 'application/csv'); |
|
| 108 | + $response->setHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"'); |
|
| 109 | + $response->setHeader('Content-Length', filesize($this->exportFileNameAndPath)); |
|
| 110 | + $response->setHeader('Content-Description', 'File Transfer'); |
|
| 111 | + |
|
| 112 | + $response->sendHeaders(); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | 115 | } |
@@ -16,121 +16,121 @@ |
||
| 16 | 16 | class ToXmlViewHelper extends AbstractToFormatViewHelper |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Render an XML export. |
|
| 21 | - * |
|
| 22 | - * @return boolean |
|
| 23 | - * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 24 | - */ |
|
| 25 | - public function render() |
|
| 26 | - { |
|
| 27 | - |
|
| 28 | - $objects = $this->templateVariableContainer->get('objects'); |
|
| 29 | - |
|
| 30 | - // Make sure we have something to process... |
|
| 31 | - if (!empty($objects)) { |
|
| 32 | - |
|
| 33 | - // Initialization step. |
|
| 34 | - $this->initializeEnvironment($objects); |
|
| 35 | - $this->exportFileNameAndPath .= '.xml'; // add extension to the file. |
|
| 36 | - |
|
| 37 | - // Write the exported data to a XML file. |
|
| 38 | - $this->writeXmlFile($objects); |
|
| 39 | - |
|
| 40 | - // We must generate a zip archive since there are files included. |
|
| 41 | - if ($this->hasCollectedFiles()) { |
|
| 42 | - |
|
| 43 | - $this->writeZipFile(); |
|
| 44 | - $this->sendZipHttpHeaders(); |
|
| 45 | - |
|
| 46 | - readfile($this->zipFileNameAndPath); |
|
| 47 | - } else { |
|
| 48 | - $this->sendXmlHttpHeaders(); |
|
| 49 | - readfile($this->exportFileNameAndPath); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - GeneralUtility::rmdir($this->temporaryDirectory, true); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Write the XML file to a temporary location. |
|
| 58 | - * |
|
| 59 | - * @param array $objects |
|
| 60 | - * @return void |
|
| 61 | - */ |
|
| 62 | - protected function writeXmlFile(array $objects) |
|
| 63 | - { |
|
| 64 | - |
|
| 65 | - // Get first object of $objects to check whether it contains possible files to include. |
|
| 66 | - /** @var \Fab\Vidi\Domain\Model\Content $object */ |
|
| 67 | - $object = reset($objects); |
|
| 68 | - $this->checkWhetherObjectMayIncludeFiles($object); |
|
| 69 | - |
|
| 70 | - $items = []; |
|
| 71 | - foreach ($objects as $object) { |
|
| 72 | - if ($this->hasFileFields()) { |
|
| 73 | - $this->collectFiles($object); |
|
| 74 | - } |
|
| 75 | - $items[] = $object->toValues(); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $xml = new \SimpleXMLElement('<items/>'); |
|
| 79 | - $xml = $this->arrayToXml($items, $xml); |
|
| 80 | - file_put_contents($this->exportFileNameAndPath, $this->formatXml($xml->asXML())); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /* |
|
| 19 | + /** |
|
| 20 | + * Render an XML export. |
|
| 21 | + * |
|
| 22 | + * @return boolean |
|
| 23 | + * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 24 | + */ |
|
| 25 | + public function render() |
|
| 26 | + { |
|
| 27 | + |
|
| 28 | + $objects = $this->templateVariableContainer->get('objects'); |
|
| 29 | + |
|
| 30 | + // Make sure we have something to process... |
|
| 31 | + if (!empty($objects)) { |
|
| 32 | + |
|
| 33 | + // Initialization step. |
|
| 34 | + $this->initializeEnvironment($objects); |
|
| 35 | + $this->exportFileNameAndPath .= '.xml'; // add extension to the file. |
|
| 36 | + |
|
| 37 | + // Write the exported data to a XML file. |
|
| 38 | + $this->writeXmlFile($objects); |
|
| 39 | + |
|
| 40 | + // We must generate a zip archive since there are files included. |
|
| 41 | + if ($this->hasCollectedFiles()) { |
|
| 42 | + |
|
| 43 | + $this->writeZipFile(); |
|
| 44 | + $this->sendZipHttpHeaders(); |
|
| 45 | + |
|
| 46 | + readfile($this->zipFileNameAndPath); |
|
| 47 | + } else { |
|
| 48 | + $this->sendXmlHttpHeaders(); |
|
| 49 | + readfile($this->exportFileNameAndPath); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + GeneralUtility::rmdir($this->temporaryDirectory, true); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Write the XML file to a temporary location. |
|
| 58 | + * |
|
| 59 | + * @param array $objects |
|
| 60 | + * @return void |
|
| 61 | + */ |
|
| 62 | + protected function writeXmlFile(array $objects) |
|
| 63 | + { |
|
| 64 | + |
|
| 65 | + // Get first object of $objects to check whether it contains possible files to include. |
|
| 66 | + /** @var \Fab\Vidi\Domain\Model\Content $object */ |
|
| 67 | + $object = reset($objects); |
|
| 68 | + $this->checkWhetherObjectMayIncludeFiles($object); |
|
| 69 | + |
|
| 70 | + $items = []; |
|
| 71 | + foreach ($objects as $object) { |
|
| 72 | + if ($this->hasFileFields()) { |
|
| 73 | + $this->collectFiles($object); |
|
| 74 | + } |
|
| 75 | + $items[] = $object->toValues(); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $xml = new \SimpleXMLElement('<items/>'); |
|
| 79 | + $xml = $this->arrayToXml($items, $xml); |
|
| 80 | + file_put_contents($this->exportFileNameAndPath, $this->formatXml($xml->asXML())); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /* |
|
| 84 | 84 | * Convert an array to xml |
| 85 | 85 | * |
| 86 | 86 | * @return \SimpleXMLElement |
| 87 | 87 | */ |
| 88 | - protected function arrayToXml($array, \SimpleXMLElement $xml) |
|
| 89 | - { |
|
| 90 | - foreach ($array as $key => $value) { |
|
| 91 | - if (is_array($value)) { |
|
| 92 | - $key = is_numeric($key) ? 'item' : $key; |
|
| 93 | - $subNode = $xml->addChild($key); |
|
| 94 | - $this->arrayToXml($value, $subNode); |
|
| 95 | - } else { |
|
| 96 | - $key = is_numeric($key) ? 'item' : $key; |
|
| 97 | - $xml->addChild($key, "$value"); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - return $xml; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /* |
|
| 88 | + protected function arrayToXml($array, \SimpleXMLElement $xml) |
|
| 89 | + { |
|
| 90 | + foreach ($array as $key => $value) { |
|
| 91 | + if (is_array($value)) { |
|
| 92 | + $key = is_numeric($key) ? 'item' : $key; |
|
| 93 | + $subNode = $xml->addChild($key); |
|
| 94 | + $this->arrayToXml($value, $subNode); |
|
| 95 | + } else { |
|
| 96 | + $key = is_numeric($key) ? 'item' : $key; |
|
| 97 | + $xml->addChild($key, "$value"); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + return $xml; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /* |
|
| 104 | 104 | * Format the XML so that is looks human friendly. |
| 105 | 105 | * |
| 106 | 106 | * @param string $xml |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | - protected function formatXml($xml) |
|
| 110 | - { |
|
| 111 | - $dom = new \DOMDocument("1.0"); |
|
| 112 | - $dom->preserveWhiteSpace = false; |
|
| 113 | - $dom->formatOutput = true; |
|
| 114 | - $dom->loadXML($xml); |
|
| 115 | - return $dom->saveXML(); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @return void |
|
| 120 | - * @throws \InvalidArgumentException |
|
| 121 | - * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 122 | - */ |
|
| 123 | - protected function sendXmlHttpHeaders() |
|
| 124 | - { |
|
| 125 | - |
|
| 126 | - /** @var \TYPO3\CMS\Extbase\Mvc\Web\Response $response */ |
|
| 127 | - $response = $this->templateVariableContainer->get('response'); |
|
| 128 | - $response->setHeader('Content-Type', 'application/xml'); |
|
| 129 | - $response->setHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"'); |
|
| 130 | - $response->setHeader('Content-Length', filesize($this->exportFileNameAndPath)); |
|
| 131 | - $response->setHeader('Content-Description', 'File Transfer'); |
|
| 132 | - |
|
| 133 | - $response->sendHeaders(); |
|
| 134 | - } |
|
| 109 | + protected function formatXml($xml) |
|
| 110 | + { |
|
| 111 | + $dom = new \DOMDocument("1.0"); |
|
| 112 | + $dom->preserveWhiteSpace = false; |
|
| 113 | + $dom->formatOutput = true; |
|
| 114 | + $dom->loadXML($xml); |
|
| 115 | + return $dom->saveXML(); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @return void |
|
| 120 | + * @throws \InvalidArgumentException |
|
| 121 | + * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException |
|
| 122 | + */ |
|
| 123 | + protected function sendXmlHttpHeaders() |
|
| 124 | + { |
|
| 125 | + |
|
| 126 | + /** @var \TYPO3\CMS\Extbase\Mvc\Web\Response $response */ |
|
| 127 | + $response = $this->templateVariableContainer->get('response'); |
|
| 128 | + $response->setHeader('Content-Type', 'application/xml'); |
|
| 129 | + $response->setHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"'); |
|
| 130 | + $response->setHeader('Content-Length', filesize($this->exportFileNameAndPath)); |
|
| 131 | + $response->setHeader('Content-Description', 'File Transfer'); |
|
| 132 | + |
|
| 133 | + $response->sendHeaders(); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | 136 | } |
@@ -18,76 +18,76 @@ |
||
| 18 | 18 | class ConfigurationUtility implements SingletonInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $extensionKey = 'vidi'; |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $extensionKey = 'vidi'; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $configuration = []; |
|
| 26 | + /** |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $configuration = []; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Returns a class instance. |
|
| 33 | - * |
|
| 34 | - * @return ConfigurationUtility |
|
| 35 | - * @throws \InvalidArgumentException |
|
| 36 | - */ |
|
| 37 | - static public function getInstance() |
|
| 38 | - { |
|
| 39 | - return GeneralUtility::makeInstance(self::class); |
|
| 40 | - } |
|
| 31 | + /** |
|
| 32 | + * Returns a class instance. |
|
| 33 | + * |
|
| 34 | + * @return ConfigurationUtility |
|
| 35 | + * @throws \InvalidArgumentException |
|
| 36 | + */ |
|
| 37 | + static public function getInstance() |
|
| 38 | + { |
|
| 39 | + return GeneralUtility::makeInstance(self::class); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Constructor |
|
| 44 | - * |
|
| 45 | - * @return ConfigurationUtility |
|
| 46 | - */ |
|
| 47 | - public function __construct() |
|
| 48 | - { |
|
| 42 | + /** |
|
| 43 | + * Constructor |
|
| 44 | + * |
|
| 45 | + * @return ConfigurationUtility |
|
| 46 | + */ |
|
| 47 | + public function __construct() |
|
| 48 | + { |
|
| 49 | 49 | |
| 50 | - /** @var ObjectManager $objectManager */ |
|
| 51 | - $objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
|
| 50 | + /** @var ObjectManager $objectManager */ |
|
| 51 | + $objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
|
| 52 | 52 | |
| 53 | - /** @var \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility */ |
|
| 54 | - $configurationUtility = $objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class); |
|
| 55 | - $configuration = $configurationUtility->getCurrentConfiguration($this->extensionKey); |
|
| 53 | + /** @var \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility */ |
|
| 54 | + $configurationUtility = $objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class); |
|
| 55 | + $configuration = $configurationUtility->getCurrentConfiguration($this->extensionKey); |
|
| 56 | 56 | |
| 57 | - // Fill up configuration array with relevant values. |
|
| 58 | - foreach ($configuration as $key => $data) { |
|
| 59 | - $this->configuration[$key] = $data['value']; |
|
| 60 | - } |
|
| 61 | - } |
|
| 57 | + // Fill up configuration array with relevant values. |
|
| 58 | + foreach ($configuration as $key => $data) { |
|
| 59 | + $this->configuration[$key] = $data['value']; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Returns a setting key. |
|
| 65 | - * |
|
| 66 | - * @param string $key |
|
| 67 | - * @return array |
|
| 68 | - */ |
|
| 69 | - public function get($key) |
|
| 70 | - { |
|
| 71 | - return isset($this->configuration[$key]) ? $this->configuration[$key] : null; |
|
| 72 | - } |
|
| 63 | + /** |
|
| 64 | + * Returns a setting key. |
|
| 65 | + * |
|
| 66 | + * @param string $key |
|
| 67 | + * @return array |
|
| 68 | + */ |
|
| 69 | + public function get($key) |
|
| 70 | + { |
|
| 71 | + return isset($this->configuration[$key]) ? $this->configuration[$key] : null; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Set a setting key. |
|
| 76 | - * |
|
| 77 | - * @param string $key |
|
| 78 | - * @param mixed $value |
|
| 79 | - * @return void |
|
| 80 | - */ |
|
| 81 | - public function set($key, $value) |
|
| 82 | - { |
|
| 83 | - $this->configuration[$key] = $value; |
|
| 84 | - } |
|
| 74 | + /** |
|
| 75 | + * Set a setting key. |
|
| 76 | + * |
|
| 77 | + * @param string $key |
|
| 78 | + * @param mixed $value |
|
| 79 | + * @return void |
|
| 80 | + */ |
|
| 81 | + public function set($key, $value) |
|
| 82 | + { |
|
| 83 | + $this->configuration[$key] = $value; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * @return array |
|
| 88 | - */ |
|
| 89 | - public function getConfiguration() |
|
| 90 | - { |
|
| 91 | - return $this->configuration; |
|
| 92 | - } |
|
| 86 | + /** |
|
| 87 | + * @return array |
|
| 88 | + */ |
|
| 89 | + public function getConfiguration() |
|
| 90 | + { |
|
| 91 | + return $this->configuration; |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -17,17 +17,17 @@ |
||
| 17 | 17 | class MassEditMenuItem extends AbstractComponentView |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Renders a "mass edit" menu item to be placed in the grid menu. |
|
| 22 | - * |
|
| 23 | - * @return string |
|
| 24 | - * @throws \InvalidArgumentException |
|
| 25 | - */ |
|
| 26 | - public function render() |
|
| 27 | - { |
|
| 28 | - return sprintf('<li><a href="#" class="mass-edit">%s %s (not implemented)</a></li>', |
|
| 29 | - $this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL), |
|
| 30 | - $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:edit') |
|
| 31 | - ); |
|
| 32 | - } |
|
| 20 | + /** |
|
| 21 | + * Renders a "mass edit" menu item to be placed in the grid menu. |
|
| 22 | + * |
|
| 23 | + * @return string |
|
| 24 | + * @throws \InvalidArgumentException |
|
| 25 | + */ |
|
| 26 | + public function render() |
|
| 27 | + { |
|
| 28 | + return sprintf('<li><a href="#" class="mass-edit">%s %s (not implemented)</a></li>', |
|
| 29 | + $this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL), |
|
| 30 | + $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:edit') |
|
| 31 | + ); |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -17,20 +17,20 @@ |
||
| 17 | 17 | class ExportXlsMenuItem extends AbstractComponentView |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Renders a "xls export" item to be placed in the menu. |
|
| 22 | - * Only the admin is allowed to export for now as security is not handled. |
|
| 23 | - * |
|
| 24 | - * @return string |
|
| 25 | - * @throws \InvalidArgumentException |
|
| 26 | - */ |
|
| 27 | - public function render() |
|
| 28 | - { |
|
| 29 | - $result = sprintf('<li><a href="#" class="export-xls" data-format="xls">%s %s</a></li>', |
|
| 30 | - $this->getIconFactory()->getIcon('mimetypes-excel', Icon::SIZE_SMALL), |
|
| 31 | - $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:export-xls') |
|
| 32 | - ); |
|
| 33 | - return $result; |
|
| 34 | - } |
|
| 20 | + /** |
|
| 21 | + * Renders a "xls export" item to be placed in the menu. |
|
| 22 | + * Only the admin is allowed to export for now as security is not handled. |
|
| 23 | + * |
|
| 24 | + * @return string |
|
| 25 | + * @throws \InvalidArgumentException |
|
| 26 | + */ |
|
| 27 | + public function render() |
|
| 28 | + { |
|
| 29 | + $result = sprintf('<li><a href="#" class="export-xls" data-format="xls">%s %s</a></li>', |
|
| 30 | + $this->getIconFactory()->getIcon('mimetypes-excel', Icon::SIZE_SMALL), |
|
| 31 | + $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:export-xls') |
|
| 32 | + ); |
|
| 33 | + return $result; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | } |
@@ -19,47 +19,47 @@ |
||
| 19 | 19 | class ClipboardMenuItem extends AbstractComponentView |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Renders a "mass delete" menu item to be placed in the grid menu. |
|
| 24 | - * |
|
| 25 | - * @return string |
|
| 26 | - * @throws \InvalidArgumentException |
|
| 27 | - */ |
|
| 28 | - public function render() |
|
| 29 | - { |
|
| 30 | - $output = ''; |
|
| 31 | - if ($this->getMediaModule()->hasFolderTree()) { |
|
| 32 | - $output = sprintf('<li><a href="%s" class="clipboard-save" >%s %s</a>', |
|
| 33 | - $this->getSaveInClipboardUri(), |
|
| 34 | - $this->getIconFactory()->getIcon('actions-document-paste-after', Icon::SIZE_SMALL), |
|
| 35 | - $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:save') |
|
| 36 | - ); |
|
| 37 | - } |
|
| 38 | - return $output; |
|
| 39 | - } |
|
| 22 | + /** |
|
| 23 | + * Renders a "mass delete" menu item to be placed in the grid menu. |
|
| 24 | + * |
|
| 25 | + * @return string |
|
| 26 | + * @throws \InvalidArgumentException |
|
| 27 | + */ |
|
| 28 | + public function render() |
|
| 29 | + { |
|
| 30 | + $output = ''; |
|
| 31 | + if ($this->getMediaModule()->hasFolderTree()) { |
|
| 32 | + $output = sprintf('<li><a href="%s" class="clipboard-save" >%s %s</a>', |
|
| 33 | + $this->getSaveInClipboardUri(), |
|
| 34 | + $this->getIconFactory()->getIcon('actions-document-paste-after', Icon::SIZE_SMALL), |
|
| 35 | + $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:save') |
|
| 36 | + ); |
|
| 37 | + } |
|
| 38 | + return $output; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @return string |
|
| 43 | - * @throws \InvalidArgumentException |
|
| 44 | - */ |
|
| 45 | - protected function getSaveInClipboardUri() |
|
| 46 | - { |
|
| 47 | - $additionalParameters = array( |
|
| 48 | - $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 49 | - 'controller' => 'Clipboard', |
|
| 50 | - 'action' => 'save', |
|
| 51 | - 'format' => 'json', |
|
| 52 | - ), |
|
| 53 | - ); |
|
| 54 | - return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 55 | - } |
|
| 41 | + /** |
|
| 42 | + * @return string |
|
| 43 | + * @throws \InvalidArgumentException |
|
| 44 | + */ |
|
| 45 | + protected function getSaveInClipboardUri() |
|
| 46 | + { |
|
| 47 | + $additionalParameters = array( |
|
| 48 | + $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 49 | + 'controller' => 'Clipboard', |
|
| 50 | + 'action' => 'save', |
|
| 51 | + 'format' => 'json', |
|
| 52 | + ), |
|
| 53 | + ); |
|
| 54 | + return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @return MediaModule |
|
| 59 | - * @throws \InvalidArgumentException |
|
| 60 | - */ |
|
| 61 | - protected function getMediaModule() |
|
| 62 | - { |
|
| 63 | - return GeneralUtility::makeInstance(MediaModule::class); |
|
| 64 | - } |
|
| 57 | + /** |
|
| 58 | + * @return MediaModule |
|
| 59 | + * @throws \InvalidArgumentException |
|
| 60 | + */ |
|
| 61 | + protected function getMediaModule() |
|
| 62 | + { |
|
| 63 | + return GeneralUtility::makeInstance(MediaModule::class); |
|
| 64 | + } |
|
| 65 | 65 | } |