Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401]

   1  <?php
   2  
   3  namespace Box\Spout\Common\Entity;
   4  
   5  use Box\Spout\Common\Entity\Style\Style;
   6  
   7  class Row
   8  {
   9      /**
  10       * The cells in this row
  11       * @var Cell[]
  12       */
  13      protected $cells = [];
  14  
  15      /**
  16       * The row style
  17       * @var Style
  18       */
  19      protected $style;
  20  
  21      /**
  22       * Row constructor.
  23       * @param Cell[] $cells
  24       * @param Style|null $style
  25       */
  26      public function __construct(array $cells, $style)
  27      {
  28          $this
  29              ->setCells($cells)
  30              ->setStyle($style);
  31      }
  32  
  33      /**
  34       * @return Cell[] $cells
  35       */
  36      public function getCells()
  37      {
  38          return $this->cells;
  39      }
  40  
  41      /**
  42       * @param Cell[] $cells
  43       * @return Row
  44       */
  45      public function setCells(array $cells)
  46      {
  47          $this->cells = [];
  48          foreach ($cells as $cell) {
  49              $this->addCell($cell);
  50          }
  51  
  52          return $this;
  53      }
  54  
  55      /**
  56       * @param Cell $cell
  57       * @param int $cellIndex
  58       * @return Row
  59       */
  60      public function setCellAtIndex(Cell $cell, $cellIndex)
  61      {
  62          $this->cells[$cellIndex] = $cell;
  63  
  64          return $this;
  65      }
  66  
  67      /**
  68       * @param int $cellIndex
  69       * @return Cell|null
  70       */
  71      public function getCellAtIndex($cellIndex)
  72      {
  73          return isset($this->cells[$cellIndex]) ? $this->cells[$cellIndex] : null;
  74      }
  75  
  76      /**
  77       * @param Cell $cell
  78       * @return Row
  79       */
  80      public function addCell(Cell $cell)
  81      {
  82          $this->cells[] = $cell;
  83  
  84          return $this;
  85      }
  86  
  87      /**
  88       * @return int
  89       */
  90      public function getNumCells()
  91      {
  92          return count($this->cells);
  93      }
  94  
  95      /**
  96       * @return Style
  97       */
  98      public function getStyle()
  99      {
 100          return $this->style;
 101      }
 102  
 103      /**
 104       * @param Style|null $style
 105       * @return Row
 106       */
 107      public function setStyle($style)
 108      {
 109          $this->style = $style ?: new Style();
 110  
 111          return $this;
 112      }
 113  
 114      /**
 115       * @return array The row values, as array
 116       */
 117      public function toArray()
 118      {
 119          return array_map(function (Cell $cell) {
 120              return $cell->getValue();
 121          }, $this->cells);
 122      }
 123  }