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\Style;
   4  
   5  /**
   6   * Class Style
   7   * Represents a style to be applied to a cell
   8   */
   9  class Style
  10  {
  11      /** Default font values */
  12      const DEFAULT_FONT_SIZE = 11;
  13      const DEFAULT_FONT_COLOR = Color::BLACK;
  14      const DEFAULT_FONT_NAME = 'Arial';
  15  
  16      /** @var int|null Style ID */
  17      private $id;
  18  
  19      /** @var bool Whether the font should be bold */
  20      private $fontBold = false;
  21      /** @var bool Whether the bold property was set */
  22      private $hasSetFontBold = false;
  23  
  24      /** @var bool Whether the font should be italic */
  25      private $fontItalic = false;
  26      /** @var bool Whether the italic property was set */
  27      private $hasSetFontItalic = false;
  28  
  29      /** @var bool Whether the font should be underlined */
  30      private $fontUnderline = false;
  31      /** @var bool Whether the underline property was set */
  32      private $hasSetFontUnderline = false;
  33  
  34      /** @var bool Whether the font should be struck through */
  35      private $fontStrikethrough = false;
  36      /** @var bool Whether the strikethrough property was set */
  37      private $hasSetFontStrikethrough = false;
  38  
  39      /** @var int Font size */
  40      private $fontSize = self::DEFAULT_FONT_SIZE;
  41      /** @var bool Whether the font size property was set */
  42      private $hasSetFontSize = false;
  43  
  44      /** @var string Font color */
  45      private $fontColor = self::DEFAULT_FONT_COLOR;
  46      /** @var bool Whether the font color property was set */
  47      private $hasSetFontColor = false;
  48  
  49      /** @var string Font name */
  50      private $fontName = self::DEFAULT_FONT_NAME;
  51      /** @var bool Whether the font name property was set */
  52      private $hasSetFontName = false;
  53  
  54      /** @var bool Whether specific font properties should be applied */
  55      private $shouldApplyFont = false;
  56  
  57      /** @var bool Whether the text should wrap in the cell (useful for long or multi-lines text) */
  58      private $shouldWrapText = false;
  59      /** @var bool Whether the wrap text property was set */
  60      private $hasSetWrapText = false;
  61  
  62      /** @var Border */
  63      private $border;
  64  
  65      /** @var bool Whether border properties should be applied */
  66      private $shouldApplyBorder = false;
  67  
  68      /** @var string Background color */
  69      private $backgroundColor;
  70  
  71      /** @var bool */
  72      private $hasSetBackgroundColor = false;
  73  
  74      /**
  75       * @return int|null
  76       */
  77      public function getId()
  78      {
  79          return $this->id;
  80      }
  81  
  82      /**
  83       * @param int $id
  84       * @return Style
  85       */
  86      public function setId($id)
  87      {
  88          $this->id = $id;
  89  
  90          return $this;
  91      }
  92  
  93      /**
  94       * @return Border
  95       */
  96      public function getBorder()
  97      {
  98          return $this->border;
  99      }
 100  
 101      /**
 102       * @param Border $border
 103       * @return Style
 104       */
 105      public function setBorder(Border $border)
 106      {
 107          $this->shouldApplyBorder = true;
 108          $this->border = $border;
 109  
 110          return $this;
 111      }
 112  
 113      /**
 114       * @return bool
 115       */
 116      public function shouldApplyBorder()
 117      {
 118          return $this->shouldApplyBorder;
 119      }
 120  
 121      /**
 122       * @return bool
 123       */
 124      public function isFontBold()
 125      {
 126          return $this->fontBold;
 127      }
 128  
 129      /**
 130       * @return Style
 131       */
 132      public function setFontBold()
 133      {
 134          $this->fontBold = true;
 135          $this->hasSetFontBold = true;
 136          $this->shouldApplyFont = true;
 137  
 138          return $this;
 139      }
 140  
 141      /**
 142       * @return bool
 143       */
 144      public function hasSetFontBold()
 145      {
 146          return $this->hasSetFontBold;
 147      }
 148  
 149      /**
 150       * @return bool
 151       */
 152      public function isFontItalic()
 153      {
 154          return $this->fontItalic;
 155      }
 156  
 157      /**
 158       * @return Style
 159       */
 160      public function setFontItalic()
 161      {
 162          $this->fontItalic = true;
 163          $this->hasSetFontItalic = true;
 164          $this->shouldApplyFont = true;
 165  
 166          return $this;
 167      }
 168  
 169      /**
 170       * @return bool
 171       */
 172      public function hasSetFontItalic()
 173      {
 174          return $this->hasSetFontItalic;
 175      }
 176  
 177      /**
 178       * @return bool
 179       */
 180      public function isFontUnderline()
 181      {
 182          return $this->fontUnderline;
 183      }
 184  
 185      /**
 186       * @return Style
 187       */
 188      public function setFontUnderline()
 189      {
 190          $this->fontUnderline = true;
 191          $this->hasSetFontUnderline = true;
 192          $this->shouldApplyFont = true;
 193  
 194          return $this;
 195      }
 196  
 197      /**
 198       * @return bool
 199       */
 200      public function hasSetFontUnderline()
 201      {
 202          return $this->hasSetFontUnderline;
 203      }
 204  
 205      /**
 206       * @return bool
 207       */
 208      public function isFontStrikethrough()
 209      {
 210          return $this->fontStrikethrough;
 211      }
 212  
 213      /**
 214       * @return Style
 215       */
 216      public function setFontStrikethrough()
 217      {
 218          $this->fontStrikethrough = true;
 219          $this->hasSetFontStrikethrough = true;
 220          $this->shouldApplyFont = true;
 221  
 222          return $this;
 223      }
 224  
 225      /**
 226       * @return bool
 227       */
 228      public function hasSetFontStrikethrough()
 229      {
 230          return $this->hasSetFontStrikethrough;
 231      }
 232  
 233      /**
 234       * @return int
 235       */
 236      public function getFontSize()
 237      {
 238          return $this->fontSize;
 239      }
 240  
 241      /**
 242       * @param int $fontSize Font size, in pixels
 243       * @return Style
 244       */
 245      public function setFontSize($fontSize)
 246      {
 247          $this->fontSize = $fontSize;
 248          $this->hasSetFontSize = true;
 249          $this->shouldApplyFont = true;
 250  
 251          return $this;
 252      }
 253  
 254      /**
 255       * @return bool
 256       */
 257      public function hasSetFontSize()
 258      {
 259          return $this->hasSetFontSize;
 260      }
 261  
 262      /**
 263       * @return string
 264       */
 265      public function getFontColor()
 266      {
 267          return $this->fontColor;
 268      }
 269  
 270      /**
 271       * Sets the font color.
 272       *
 273       * @param string $fontColor ARGB color (@see Color)
 274       * @return Style
 275       */
 276      public function setFontColor($fontColor)
 277      {
 278          $this->fontColor = $fontColor;
 279          $this->hasSetFontColor = true;
 280          $this->shouldApplyFont = true;
 281  
 282          return $this;
 283      }
 284  
 285      /**
 286       * @return bool
 287       */
 288      public function hasSetFontColor()
 289      {
 290          return $this->hasSetFontColor;
 291      }
 292  
 293      /**
 294       * @return string
 295       */
 296      public function getFontName()
 297      {
 298          return $this->fontName;
 299      }
 300  
 301      /**
 302       * @param string $fontName Name of the font to use
 303       * @return Style
 304       */
 305      public function setFontName($fontName)
 306      {
 307          $this->fontName = $fontName;
 308          $this->hasSetFontName = true;
 309          $this->shouldApplyFont = true;
 310  
 311          return $this;
 312      }
 313  
 314      /**
 315       * @return bool
 316       */
 317      public function hasSetFontName()
 318      {
 319          return $this->hasSetFontName;
 320      }
 321  
 322      /**
 323       * @return bool
 324       */
 325      public function shouldWrapText()
 326      {
 327          return $this->shouldWrapText;
 328      }
 329  
 330      /**
 331       * @param bool $shouldWrap Should the text be wrapped
 332       * @return Style
 333       */
 334      public function setShouldWrapText($shouldWrap = true)
 335      {
 336          $this->shouldWrapText = $shouldWrap;
 337          $this->hasSetWrapText = true;
 338  
 339          return $this;
 340      }
 341  
 342      /**
 343       * @return bool
 344       */
 345      public function hasSetWrapText()
 346      {
 347          return $this->hasSetWrapText;
 348      }
 349  
 350      /**
 351       * @return bool Whether specific font properties should be applied
 352       */
 353      public function shouldApplyFont()
 354      {
 355          return $this->shouldApplyFont;
 356      }
 357  
 358      /**
 359       * Sets the background color
 360       * @param string $color ARGB color (@see Color)
 361       * @return Style
 362       */
 363      public function setBackgroundColor($color)
 364      {
 365          $this->hasSetBackgroundColor = true;
 366          $this->backgroundColor = $color;
 367  
 368          return $this;
 369      }
 370  
 371      /**
 372       * @return string
 373       */
 374      public function getBackgroundColor()
 375      {
 376          return $this->backgroundColor;
 377      }
 378  
 379      /**
 380       * @return bool Whether the background color should be applied
 381       */
 382      public function shouldApplyBackgroundColor()
 383      {
 384          return $this->hasSetBackgroundColor;
 385      }
 386  }