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\Writer\Common\Creator\Style;
   4  
   5  use Box\Spout\Common\Entity\Style\Border;
   6  use Box\Spout\Common\Entity\Style\Style;
   7  
   8  /**
   9   * Class StyleBuilder
  10   * Builder to create new styles
  11   */
  12  class StyleBuilder
  13  {
  14      /** @var Style Style to be created */
  15      protected $style;
  16  
  17      /**
  18       *
  19       */
  20      public function __construct()
  21      {
  22          $this->style = new Style();
  23      }
  24  
  25      /**
  26       * Makes the font bold.
  27       *
  28       * @return StyleBuilder
  29       */
  30      public function setFontBold()
  31      {
  32          $this->style->setFontBold();
  33  
  34          return $this;
  35      }
  36  
  37      /**
  38       * Makes the font italic.
  39       *
  40       * @return StyleBuilder
  41       */
  42      public function setFontItalic()
  43      {
  44          $this->style->setFontItalic();
  45  
  46          return $this;
  47      }
  48  
  49      /**
  50       * Makes the font underlined.
  51       *
  52       * @return StyleBuilder
  53       */
  54      public function setFontUnderline()
  55      {
  56          $this->style->setFontUnderline();
  57  
  58          return $this;
  59      }
  60  
  61      /**
  62       * Makes the font struck through.
  63       *
  64       * @return StyleBuilder
  65       */
  66      public function setFontStrikethrough()
  67      {
  68          $this->style->setFontStrikethrough();
  69  
  70          return $this;
  71      }
  72  
  73      /**
  74       * Sets the font size.
  75       *
  76       * @param int $fontSize Font size, in pixels
  77       * @return StyleBuilder
  78       */
  79      public function setFontSize($fontSize)
  80      {
  81          $this->style->setFontSize($fontSize);
  82  
  83          return $this;
  84      }
  85  
  86      /**
  87       * Sets the font color.
  88       *
  89       * @param string $fontColor ARGB color (@see Color)
  90       * @return StyleBuilder
  91       */
  92      public function setFontColor($fontColor)
  93      {
  94          $this->style->setFontColor($fontColor);
  95  
  96          return $this;
  97      }
  98  
  99      /**
 100       * Sets the font name.
 101       *
 102       * @param string $fontName Name of the font to use
 103       * @return StyleBuilder
 104       */
 105      public function setFontName($fontName)
 106      {
 107          $this->style->setFontName($fontName);
 108  
 109          return $this;
 110      }
 111  
 112      /**
 113       * Makes the text wrap in the cell if requested
 114       *
 115       * @param bool $shouldWrap Should the text be wrapped
 116       * @return StyleBuilder
 117       */
 118      public function setShouldWrapText($shouldWrap = true)
 119      {
 120          $this->style->setShouldWrapText($shouldWrap);
 121  
 122          return $this;
 123      }
 124  
 125      /**
 126       * Set a border
 127       *
 128       * @param Border $border
 129       * @return $this
 130       */
 131      public function setBorder(Border $border)
 132      {
 133          $this->style->setBorder($border);
 134  
 135          return $this;
 136      }
 137  
 138      /**
 139       *  Sets a background color
 140       *
 141       * @param string $color ARGB color (@see Color)
 142       * @return StyleBuilder
 143       */
 144      public function setBackgroundColor($color)
 145      {
 146          $this->style->setBackgroundColor($color);
 147  
 148          return $this;
 149      }
 150  
 151      /**
 152       * Returns the configured style. The style is cached and can be reused.
 153       *
 154       * @return Style
 155       */
 156      public function build()
 157      {
 158          return $this->style;
 159      }
 160  }