PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.5
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.5
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / Spout / Writer / ODS / Internal / Workbook.php

Workbook.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.5, at app/Services/Spout/Writer/ODS/Internal/Workbook.php

120 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Box\Spout\Writer\ODS\Internal;
4
5 use Box\Spout\Writer\Common\Internal\AbstractWorkbook;
6 use Box\Spout\Writer\ODS\Helper\FileSystemHelper;
7 use Box\Spout\Writer\ODS\Helper\StyleHelper;
8 use Box\Spout\Writer\Common\Sheet;
9
10 /**
11 * Class Workbook
12 * Represents a workbook within a ODS file.
13 * It provides the functions to work with worksheets.
14 *
15 * @package Box\Spout\Writer\ODS\Internal
16 */
17 class Workbook extends AbstractWorkbook
18 {
19 /**
20 * Maximum number of rows a ODS sheet can contain
21 * @see https://ask.libreoffice.org/en/question/8631/upper-limit-to-number-of-rows-in-calc/
22 */
23 protected static $maxRowsPerWorksheet = 1048576;
24
25 /** @var \Box\Spout\Writer\ODS\Helper\FileSystemHelper Helper to perform file system operations */
26 protected $fileSystemHelper;
27
28 /** @var \Box\Spout\Writer\ODS\Helper\StyleHelper Helper to apply styles */
29 protected $styleHelper;
30
31 /**
32 * @param string $tempFolder
33 * @param bool $shouldCreateNewSheetsAutomatically
34 * @param \Box\Spout\Writer\Style\Style $defaultRowStyle
35 * @throws \Box\Spout\Common\Exception\IOException If unable to create at least one of the base folders
36 */
37 public function __construct($tempFolder, $shouldCreateNewSheetsAutomatically, $defaultRowStyle)
38 {
39 parent::__construct($shouldCreateNewSheetsAutomatically, $defaultRowStyle);
40
41 $this->fileSystemHelper = new FileSystemHelper($tempFolder);
42 $this->fileSystemHelper->createBaseFilesAndFolders();
43
44 $this->styleHelper = new StyleHelper($defaultRowStyle);
45 }
46
47 /**
48 * @return \Box\Spout\Writer\ODS\Helper\StyleHelper Helper to apply styles to ODS files
49 */
50 protected function getStyleHelper()
51 {
52 return $this->styleHelper;
53 }
54
55 /**
56 * @return int Maximum number of rows/columns a sheet can contain
57 */
58 protected function getMaxRowsPerWorksheet()
59 {
60 return self::$maxRowsPerWorksheet;
61 }
62
63 /**
64 * Creates a new sheet in the workbook. The current sheet remains unchanged.
65 *
66 * @return Worksheet The created sheet
67 * @throws \Box\Spout\Common\Exception\IOException If unable to open the sheet for writing
68 */
69 public function addNewSheet()
70 {
71 $newSheetIndex = count($this->worksheets);
72 $sheet = new Sheet($newSheetIndex, $this->internalId);
73
74 $sheetsContentTempFolder = $this->fileSystemHelper->getSheetsContentTempFolder();
75 $worksheet = new Worksheet($sheet, $sheetsContentTempFolder);
76 $this->worksheets[] = $worksheet;
77
78 return $worksheet;
79 }
80
81 /**
82 * Closes the workbook and all its associated sheets.
83 * All the necessary files are written to disk and zipped together to create the ODS file.
84 * All the temporary files are then deleted.
85 *
86 * @param resource $finalFilePointer Pointer to the ODS that will be created
87 * @return void
88 */
89 public function close($finalFilePointer)
90 {
91 /** @var Worksheet[] $worksheets */
92 $worksheets = $this->worksheets;
93 $numWorksheets = count($worksheets);
94
95 foreach ($worksheets as $worksheet) {
96 $worksheet->close();
97 }
98
99 // Finish creating all the necessary files before zipping everything together
100 $this->fileSystemHelper
101 ->createContentFile($worksheets, $this->styleHelper)
102 ->deleteWorksheetTempFolder()
103 ->createStylesFile($this->styleHelper, $numWorksheets)
104 ->zipRootFolderAndCopyToStream($finalFilePointer);
105
106 $this->cleanupTempFolder();
107 }
108
109 /**
110 * Deletes the root folder created in the temp folder and all its contents.
111 *
112 * @return void
113 */
114 protected function cleanupTempFolder()
115 {
116 $xlsxRootFolder = $this->fileSystemHelper->getRootFolder();
117 $this->fileSystemHelper->deleteFolderRecursively($xlsxRootFolder);
118 }
119 }
120