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 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Style;
   4  
   5  use PhpOffice\PhpSpreadsheet\IComparable;
   6  use PhpOffice\PhpSpreadsheet\Spreadsheet;
   7  use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
   8  
   9  abstract class Supervisor implements IComparable
  10  {
  11      /**
  12       * Supervisor?
  13       *
  14       * @var bool
  15       */
  16      protected $isSupervisor;
  17  
  18      /**
  19       * Parent. Only used for supervisor.
  20       *
  21       * @var Spreadsheet|Style
  22       */
  23      protected $parent;
  24  
  25      /**
  26       * Parent property name.
  27       *
  28       * @var null|string
  29       */
  30      protected $parentPropertyName;
  31  
  32      /**
  33       * Create a new Supervisor.
  34       *
  35       * @param bool $isSupervisor Flag indicating if this is a supervisor or not
  36       *                                    Leave this value at default unless you understand exactly what
  37       *                                        its ramifications are
  38       */
  39      public function __construct($isSupervisor = false)
  40      {
  41          // Supervisor?
  42          $this->isSupervisor = $isSupervisor;
  43      }
  44  
  45      /**
  46       * Bind parent. Only used for supervisor.
  47       *
  48       * @param Spreadsheet|Style $parent
  49       * @param null|string $parentPropertyName
  50       *
  51       * @return $this
  52       */
  53      public function bindParent($parent, $parentPropertyName = null)
  54      {
  55          $this->parent = $parent;
  56          $this->parentPropertyName = $parentPropertyName;
  57  
  58          return $this;
  59      }
  60  
  61      /**
  62       * Is this a supervisor or a cell style component?
  63       *
  64       * @return bool
  65       */
  66      public function getIsSupervisor()
  67      {
  68          return $this->isSupervisor;
  69      }
  70  
  71      /**
  72       * Get the currently active sheet. Only used for supervisor.
  73       *
  74       * @return Worksheet
  75       */
  76      public function getActiveSheet()
  77      {
  78          return $this->parent->getActiveSheet();
  79      }
  80  
  81      /**
  82       * Get the currently active cell coordinate in currently active sheet.
  83       * Only used for supervisor.
  84       *
  85       * @return string E.g. 'A1'
  86       */
  87      public function getSelectedCells()
  88      {
  89          return $this->getActiveSheet()->getSelectedCells();
  90      }
  91  
  92      /**
  93       * Get the currently active cell coordinate in currently active sheet.
  94       * Only used for supervisor.
  95       *
  96       * @return string E.g. 'A1'
  97       */
  98      public function getActiveCell()
  99      {
 100          return $this->getActiveSheet()->getActiveCell();
 101      }
 102  
 103      /**
 104       * Implement PHP __clone to create a deep clone, not just a shallow copy.
 105       */
 106      public function __clone()
 107      {
 108          $vars = get_object_vars($this);
 109          foreach ($vars as $key => $value) {
 110              if ((is_object($value)) && ($key != 'parent')) {
 111                  $this->$key = clone $value;
 112              } else {
 113                  $this->$key = $value;
 114              }
 115          }
 116      }
 117  
 118      /**
 119       * Export style as array.
 120       *
 121       * Available to anything which extends this class:
 122       * Alignment, Border, Borders, Color, Fill, Font,
 123       * NumberFormat, Protection, and Style.
 124       */
 125      final public function exportArray(): array
 126      {
 127          return $this->exportArray1();
 128      }
 129  
 130      /**
 131       * Abstract method to be implemented in anything which
 132       * extends this class.
 133       *
 134       * This method invokes exportArray2 with the names and values
 135       * of all properties to be included in output array,
 136       * returning that array to exportArray, then to caller.
 137       */
 138      abstract protected function exportArray1(): array;
 139  
 140      /**
 141       * Populate array from exportArray1.
 142       * This method is available to anything which extends this class.
 143       * The parameter index is the key to be added to the array.
 144       * The parameter objOrValue is either a primitive type,
 145       * which is the value added to the array,
 146       * or a Style object to be recursively added via exportArray.
 147       *
 148       * @param mixed $objOrValue
 149       */
 150      final protected function exportArray2(array &$exportedArray, string $index, $objOrValue): void
 151      {
 152          if ($objOrValue instanceof self) {
 153              $exportedArray[$index] = $objOrValue->exportArray();
 154          } else {
 155              $exportedArray[$index] = $objOrValue;
 156          }
 157      }
 158  }