| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\OpenSpout\Writer\ODS\Manager; |
| 4 |
|
| 5 |
use FluentCart\OpenSpout\Writer\Common\Entity\Sheet; |
| 6 |
use FluentCart\OpenSpout\Writer\Common\Manager\WorkbookManagerAbstract; |
| 7 |
use FluentCart\OpenSpout\Writer\ODS\Helper\FileSystemHelper; |
| 8 |
use FluentCart\OpenSpout\Writer\ODS\Manager\Style\StyleManager; |
| 9 |
/** |
| 10 |
* ODS workbook manager, providing the interfaces to work with workbook. |
| 11 |
*/ |
| 12 |
class WorkbookManager extends WorkbookManagerAbstract |
| 13 |
{ |
| 14 |
/** |
| 15 |
* Maximum number of rows a ODS sheet can contain. |
| 16 |
* |
| 17 |
* @see https://ask.libreoffice.org/en/question/8631/upper-limit-to-number-of-rows-in-calc/ |
| 18 |
*/ |
| 19 |
protected static $maxRowsPerWorksheet = 1048576; |
| 20 |
/** @var WorksheetManager Object used to manage worksheets */ |
| 21 |
protected $worksheetManager; |
| 22 |
/** @var FileSystemHelper Helper to perform file system operations */ |
| 23 |
protected $fileSystemHelper; |
| 24 |
/** @var StyleManager Manages styles */ |
| 25 |
protected $styleManager; |
| 26 |
/** |
| 27 |
* @return string The file path where the data for the given sheet will be stored |
| 28 |
*/ |
| 29 |
public function getWorksheetFilePath(Sheet $sheet) |
| 30 |
{ |
| 31 |
$sheetsContentTempFolder = $this->fileSystemHelper->getSheetsContentTempFolder(); |
| 32 |
return $sheetsContentTempFolder . '/sheet' . $sheet->getIndex() . '.xml'; |
| 33 |
} |
| 34 |
/** |
| 35 |
* @return int Maximum number of rows/columns a sheet can contain |
| 36 |
*/ |
| 37 |
protected function getMaxRowsPerWorksheet() |
| 38 |
{ |
| 39 |
return self::$maxRowsPerWorksheet; |
| 40 |
} |
| 41 |
/** |
| 42 |
* Writes all the necessary files to disk and zip them together to create the final file. |
| 43 |
* |
| 44 |
* @param resource $finalFilePointer Pointer to the spreadsheet that will be created |
| 45 |
*/ |
| 46 |
protected function writeAllFilesToDiskAndZipThem($finalFilePointer) |
| 47 |
{ |
| 48 |
$worksheets = $this->getWorksheets(); |
| 49 |
$numWorksheets = \count($worksheets); |
| 50 |
$this->fileSystemHelper->createContentFile($this->worksheetManager, $this->styleManager, $worksheets)->deleteWorksheetTempFolder()->createStylesFile($this->styleManager, $numWorksheets)->zipRootFolderAndCopyToStream($finalFilePointer); |
| 51 |
} |
| 52 |
} |
| 53 |
|