Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

   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  }