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.

Differences Between: [Versions 310 and 401] [Versions 39 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 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 specific cell alignment should be applied */
  58      private $shouldApplyCellAlignment = false;
  59      /** @var string Cell alignment */
  60      private $cellAlignment;
  61      /** @var bool Whether the cell alignment property was set */
  62      private $hasSetCellAlignment = false;
  63  
  64      /** @var bool Whether the text should wrap in the cell (useful for long or multi-lines text) */
  65      private $shouldWrapText = false;
  66      /** @var bool Whether the wrap text property was set */
  67      private $hasSetWrapText = false;
  68  
  69      /** @var Border */
  70      private $border;
  71  
  72      /** @var bool Whether border properties should be applied */
  73      private $shouldApplyBorder = false;
  74  
  75      /** @var string Background color */
  76      private $backgroundColor;
  77  
  78      /** @var bool */
  79      private $hasSetBackgroundColor = false;
  80  
  81      /** @var string Format */
  82      private $format;
  83  
  84      /** @var bool */
  85      private $hasSetFormat = false;
  86  
  87      /** @var bool */
  88      private $isRegistered = false;
  89  
  90      /** @var bool */
  91      private $isEmpty = true;
  92  
  93      /**
  94       * @return int|null
  95       */
  96      public function getId()
  97      {
  98          return $this->id;
  99      }
 100  
 101      /**
 102       * @param int $id
 103       * @return Style
 104       */
 105      public function setId($id)
 106      {
 107          $this->id = $id;
 108  
 109          return $this;
 110      }
 111  
 112      /**
 113       * @return Border
 114       */
 115      public function getBorder()
 116      {
 117          return $this->border;
 118      }
 119  
 120      /**
 121       * @param Border $border
 122       * @return Style
 123       */
 124      public function setBorder(Border $border)
 125      {
 126          $this->shouldApplyBorder = true;
 127          $this->border = $border;
 128          $this->isEmpty = false;
 129  
 130          return $this;
 131      }
 132  
 133      /**
 134       * @return bool
 135       */
 136      public function shouldApplyBorder()
 137      {
 138          return $this->shouldApplyBorder;
 139      }
 140  
 141      /**
 142       * @return bool
 143       */
 144      public function isFontBold()
 145      {
 146          return $this->fontBold;
 147      }
 148  
 149      /**
 150       * @return Style
 151       */
 152      public function setFontBold()
 153      {
 154          $this->fontBold = true;
 155          $this->hasSetFontBold = true;
 156          $this->shouldApplyFont = true;
 157          $this->isEmpty = false;
 158  
 159          return $this;
 160      }
 161  
 162      /**
 163       * @return bool
 164       */
 165      public function hasSetFontBold()
 166      {
 167          return $this->hasSetFontBold;
 168      }
 169  
 170      /**
 171       * @return bool
 172       */
 173      public function isFontItalic()
 174      {
 175          return $this->fontItalic;
 176      }
 177  
 178      /**
 179       * @return Style
 180       */
 181      public function setFontItalic()
 182      {
 183          $this->fontItalic = true;
 184          $this->hasSetFontItalic = true;
 185          $this->shouldApplyFont = true;
 186          $this->isEmpty = false;
 187  
 188          return $this;
 189      }
 190  
 191      /**
 192       * @return bool
 193       */
 194      public function hasSetFontItalic()
 195      {
 196          return $this->hasSetFontItalic;
 197      }
 198  
 199      /**
 200       * @return bool
 201       */
 202      public function isFontUnderline()
 203      {
 204          return $this->fontUnderline;
 205      }
 206  
 207      /**
 208       * @return Style
 209       */
 210      public function setFontUnderline()
 211      {
 212          $this->fontUnderline = true;
 213          $this->hasSetFontUnderline = true;
 214          $this->shouldApplyFont = true;
 215          $this->isEmpty = false;
 216  
 217          return $this;
 218      }
 219  
 220      /**
 221       * @return bool
 222       */
 223      public function hasSetFontUnderline()
 224      {
 225          return $this->hasSetFontUnderline;
 226      }
 227  
 228      /**
 229       * @return bool
 230       */
 231      public function isFontStrikethrough()
 232      {
 233          return $this->fontStrikethrough;
 234      }
 235  
 236      /**
 237       * @return Style
 238       */
 239      public function setFontStrikethrough()
 240      {
 241          $this->fontStrikethrough = true;
 242          $this->hasSetFontStrikethrough = true;
 243          $this->shouldApplyFont = true;
 244          $this->isEmpty = false;
 245  
 246          return $this;
 247      }
 248  
 249      /**
 250       * @return bool
 251       */
 252      public function hasSetFontStrikethrough()
 253      {
 254          return $this->hasSetFontStrikethrough;
 255      }
 256  
 257      /**
 258       * @return int
 259       */
 260      public function getFontSize()
 261      {
 262          return $this->fontSize;
 263      }
 264  
 265      /**
 266       * @param int $fontSize Font size, in pixels
 267       * @return Style
 268       */
 269      public function setFontSize($fontSize)
 270      {
 271          $this->fontSize = $fontSize;
 272          $this->hasSetFontSize = true;
 273          $this->shouldApplyFont = true;
 274          $this->isEmpty = false;
 275  
 276          return $this;
 277      }
 278  
 279      /**
 280       * @return bool
 281       */
 282      public function hasSetFontSize()
 283      {
 284          return $this->hasSetFontSize;
 285      }
 286  
 287      /**
 288       * @return string
 289       */
 290      public function getFontColor()
 291      {
 292          return $this->fontColor;
 293      }
 294  
 295      /**
 296       * Sets the font color.
 297       *
 298       * @param string $fontColor ARGB color (@see Color)
 299       * @return Style
 300       */
 301      public function setFontColor($fontColor)
 302      {
 303          $this->fontColor = $fontColor;
 304          $this->hasSetFontColor = true;
 305          $this->shouldApplyFont = true;
 306          $this->isEmpty = false;
 307  
 308          return $this;
 309      }
 310  
 311      /**
 312       * @return bool
 313       */
 314      public function hasSetFontColor()
 315      {
 316          return $this->hasSetFontColor;
 317      }
 318  
 319      /**
 320       * @return string
 321       */
 322      public function getFontName()
 323      {
 324          return $this->fontName;
 325      }
 326  
 327      /**
 328       * @param string $fontName Name of the font to use
 329       * @return Style
 330       */
 331      public function setFontName($fontName)
 332      {
 333          $this->fontName = $fontName;
 334          $this->hasSetFontName = true;
 335          $this->shouldApplyFont = true;
 336          $this->isEmpty = false;
 337  
 338          return $this;
 339      }
 340  
 341      /**
 342       * @return bool
 343       */
 344      public function hasSetFontName()
 345      {
 346          return $this->hasSetFontName;
 347      }
 348  
 349      /**
 350       * @return string
 351       */
 352      public function getCellAlignment()
 353      {
 354          return $this->cellAlignment;
 355      }
 356  
 357      /**
 358       * @param string $cellAlignment The cell alignment
 359       *
 360       * @return Style
 361       */
 362      public function setCellAlignment($cellAlignment)
 363      {
 364          $this->cellAlignment = $cellAlignment;
 365          $this->hasSetCellAlignment = true;
 366          $this->shouldApplyCellAlignment = true;
 367          $this->isEmpty = false;
 368  
 369          return $this;
 370      }
 371  
 372      /**
 373       * @return bool
 374       */
 375      public function hasSetCellAlignment()
 376      {
 377          return $this->hasSetCellAlignment;
 378      }
 379  
 380      /**
 381       * @return bool Whether specific cell alignment should be applied
 382       */
 383      public function shouldApplyCellAlignment()
 384      {
 385          return $this->shouldApplyCellAlignment;
 386      }
 387  
 388      /**
 389       * @return bool
 390       */
 391      public function shouldWrapText()
 392      {
 393          return $this->shouldWrapText;
 394      }
 395  
 396      /**
 397       * @param bool $shouldWrap Should the text be wrapped
 398       * @return Style
 399       */
 400      public function setShouldWrapText($shouldWrap = true)
 401      {
 402          $this->shouldWrapText = $shouldWrap;
 403          $this->hasSetWrapText = true;
 404          $this->isEmpty = false;
 405  
 406          return $this;
 407      }
 408  
 409      /**
 410       * @return bool
 411       */
 412      public function hasSetWrapText()
 413      {
 414          return $this->hasSetWrapText;
 415      }
 416  
 417      /**
 418       * @return bool Whether specific font properties should be applied
 419       */
 420      public function shouldApplyFont()
 421      {
 422          return $this->shouldApplyFont;
 423      }
 424  
 425      /**
 426       * Sets the background color
 427       * @param string $color ARGB color (@see Color)
 428       * @return Style
 429       */
 430      public function setBackgroundColor($color)
 431      {
 432          $this->hasSetBackgroundColor = true;
 433          $this->backgroundColor = $color;
 434          $this->isEmpty = false;
 435  
 436          return $this;
 437      }
 438  
 439      /**
 440       * @return string
 441       */
 442      public function getBackgroundColor()
 443      {
 444          return $this->backgroundColor;
 445      }
 446  
 447      /**
 448       * @return bool Whether the background color should be applied
 449       */
 450      public function shouldApplyBackgroundColor()
 451      {
 452          return $this->hasSetBackgroundColor;
 453      }
 454  
 455      /**
 456       * Sets format
 457       * @param string $format
 458       * @return Style
 459       */
 460      public function setFormat($format)
 461      {
 462          $this->hasSetFormat = true;
 463          $this->format = $format;
 464          $this->isEmpty = false;
 465  
 466          return $this;
 467      }
 468  
 469      /**
 470       * @return string
 471       */
 472      public function getFormat()
 473      {
 474          return $this->format;
 475      }
 476  
 477      /**
 478       * @return bool Whether format should be applied
 479       */
 480      public function shouldApplyFormat()
 481      {
 482          return $this->hasSetFormat;
 483      }
 484  
 485      /**
 486       * @return bool
 487       */
 488      public function isRegistered() : bool
 489      {
 490          return $this->isRegistered;
 491      }
 492  
 493      public function markAsRegistered(?int $id) : void
 494      {
 495          $this->setId($id);
 496          $this->isRegistered = true;
 497      }
 498  
 499      public function unmarkAsRegistered() : void
 500      {
 501          $this->setId(0);
 502          $this->isRegistered = false;
 503      }
 504  
 505      public function isEmpty() : bool
 506      {
 507          return $this->isEmpty;
 508      }
 509  }