Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 402 and 403]

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  namespace OpenSpout\Writer\ODS\Manager;
   6  
   7  use OpenSpout\Writer\Common\Entity\Workbook;
   8  use OpenSpout\Writer\Common\Manager\AbstractWorkbookManager;
   9  use OpenSpout\Writer\Common\Manager\Style\StyleMerger;
  10  use OpenSpout\Writer\ODS\Helper\FileSystemHelper;
  11  use OpenSpout\Writer\ODS\Manager\Style\StyleManager;
  12  use OpenSpout\Writer\ODS\Options;
  13  
  14  /**
  15   * @internal
  16   *
  17   * @property WorksheetManager $worksheetManager
  18   * @property FileSystemHelper $fileSystemHelper
  19   * @property StyleManager     $styleManager
  20   */
  21  final class WorkbookManager extends AbstractWorkbookManager
  22  {
  23      /**
  24       * Maximum number of rows a ODS sheet can contain.
  25       *
  26       * @see https://ask.libreoffice.org/en/question/8631/upper-limit-to-number-of-rows-in-calc/
  27       */
  28      private static int $maxRowsPerWorksheet = 1048576;
  29  
  30      public function __construct(
  31          Workbook $workbook,
  32          Options $options,
  33          WorksheetManager $worksheetManager,
  34          StyleManager $styleManager,
  35          StyleMerger $styleMerger,
  36          FileSystemHelper $fileSystemHelper
  37      ) {
  38          parent::__construct(
  39              $workbook,
  40              $options,
  41              $worksheetManager,
  42              $styleManager,
  43              $styleMerger,
  44              $fileSystemHelper
  45          );
  46      }
  47  
  48      /**
  49       * @return int Maximum number of rows/columns a sheet can contain
  50       */
  51      protected function getMaxRowsPerWorksheet(): int
  52      {
  53          return self::$maxRowsPerWorksheet;
  54      }
  55  
  56      /**
  57       * Writes all the necessary files to disk and zip them together to create the final file.
  58       *
  59       * @param resource $finalFilePointer Pointer to the spreadsheet that will be created
  60       */
  61      protected function writeAllFilesToDiskAndZipThem($finalFilePointer): void
  62      {
  63          $worksheets = $this->getWorksheets();
  64          $numWorksheets = \count($worksheets);
  65  
  66          $this->fileSystemHelper
  67              ->createContentFile($this->worksheetManager, $this->styleManager, $worksheets)
  68              ->deleteWorksheetTempFolder()
  69              ->createStylesFile($this->styleManager, $numWorksheets)
  70              ->zipRootFolderAndCopyToStream($finalFilePointer)
  71          ;
  72      }
  73  }