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\Writer\XLSX\Helper;
   4  
   5  use Box\Spout\Common\Entity\Style\Border;
   6  use Box\Spout\Common\Entity\Style\BorderPart;
   7  
   8  class BorderHelper
   9  {
  10      public static $xlsxStyleMap = [
  11          Border::STYLE_SOLID => [
  12              Border::WIDTH_THIN   => 'thin',
  13              Border::WIDTH_MEDIUM => 'medium',
  14              Border::WIDTH_THICK  => 'thick',
  15          ],
  16          Border::STYLE_DOTTED => [
  17              Border::WIDTH_THIN   => 'dotted',
  18              Border::WIDTH_MEDIUM => 'dotted',
  19              Border::WIDTH_THICK  => 'dotted',
  20          ],
  21          Border::STYLE_DASHED => [
  22              Border::WIDTH_THIN   => 'dashed',
  23              Border::WIDTH_MEDIUM => 'mediumDashed',
  24              Border::WIDTH_THICK  => 'mediumDashed',
  25          ],
  26          Border::STYLE_DOUBLE => [
  27              Border::WIDTH_THIN   => 'double',
  28              Border::WIDTH_MEDIUM => 'double',
  29              Border::WIDTH_THICK  => 'double',
  30          ],
  31          Border::STYLE_NONE => [
  32              Border::WIDTH_THIN   => 'none',
  33              Border::WIDTH_MEDIUM => 'none',
  34              Border::WIDTH_THICK  => 'none',
  35          ],
  36      ];
  37  
  38      /**
  39       * @param BorderPart $borderPart
  40       * @return string
  41       */
  42      public static function serializeBorderPart(BorderPart $borderPart)
  43      {
  44          $borderStyle = self::getBorderStyle($borderPart);
  45  
  46          $colorEl = $borderPart->getColor() ? \sprintf('<color rgb="%s"/>', $borderPart->getColor()) : '';
  47          $partEl = \sprintf(
  48              '<%s style="%s">%s</%s>',
  49              $borderPart->getName(),
  50              $borderStyle,
  51              $colorEl,
  52              $borderPart->getName()
  53          );
  54  
  55          return $partEl . PHP_EOL;
  56      }
  57  
  58      /**
  59       * Get the style definition from the style map
  60       *
  61       * @param BorderPart $borderPart
  62       * @return string
  63       */
  64      protected static function getBorderStyle(BorderPart $borderPart)
  65      {
  66          return self::$xlsxStyleMap[$borderPart->getStyle()][$borderPart->getWidth()];
  67      }
  68  }