Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 39 and 401]

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