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.
   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting;
   4  
   5  use PhpOffice\PhpSpreadsheet\Cell\Cell;
   6  use PhpOffice\PhpSpreadsheet\Style\Conditional;
   7  use PhpOffice\PhpSpreadsheet\Style\Style;
   8  
   9  class CellStyleAssessor
  10  {
  11      /**
  12       * @var CellMatcher
  13       */
  14      protected $cellMatcher;
  15  
  16      /**
  17       * @var StyleMerger
  18       */
  19      protected $styleMerger;
  20  
  21      public function __construct(Cell $cell, string $conditionalRange)
  22      {
  23          $this->cellMatcher = new CellMatcher($cell, $conditionalRange);
  24          $this->styleMerger = new StyleMerger($cell->getStyle());
  25      }
  26  
  27      /**
  28       * @param Conditional[] $conditionalStyles
  29       */
  30      public function matchConditions(array $conditionalStyles = []): Style
  31      {
  32          foreach ($conditionalStyles as $conditional) {
  33              /** @var Conditional $conditional */
  34              if ($this->cellMatcher->evaluateConditional($conditional) === true) {
  35                  // Merging the conditional style into the base style goes in here
  36                  $this->styleMerger->mergeStyle($conditional->getStyle());
  37                  if ($conditional->getStopIfTrue() === true) {
  38                      break;
  39                  }
  40              }
  41          }
  42  
  43          return $this->styleMerger->getStyle();
  44      }
  45  }