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\ODS\Helper;
   4  
   5  use Box\Spout\Common\Entity\Style\Border;
   6  use Box\Spout\Common\Entity\Style\BorderPart;
   7  
   8  /**
   9   * Class BorderHelper
  10   *
  11   * The fo:border, fo:border-top, fo:border-bottom, fo:border-left and fo:border-right attributes
  12   * specify border properties
  13   * http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#__RefHeading__1419780_253892949
  14   *
  15   * Example table-cell-properties
  16   *
  17   * <style:table-cell-properties
  18   * fo:border-bottom="0.74pt solid #ffc000" style:diagonal-bl-tr="none"
  19   * style:diagonal-tl-br="none" fo:border-left="none" fo:border-right="none"
  20   * style:rotation-align="none" fo:border-top="none"/>
  21   */
  22  class BorderHelper
  23  {
  24      /**
  25       * Width mappings
  26       *
  27       * @var array
  28       */
  29      protected static $widthMap = [
  30          Border::WIDTH_THIN   => '0.75pt',
  31          Border::WIDTH_MEDIUM => '1.75pt',
  32          Border::WIDTH_THICK  => '2.5pt',
  33      ];
  34  
  35      /**
  36       * Style mapping
  37       *
  38       * @var array
  39       */
  40      protected static $styleMap = [
  41          Border::STYLE_SOLID  => 'solid',
  42          Border::STYLE_DASHED => 'dashed',
  43          Border::STYLE_DOTTED => 'dotted',
  44          Border::STYLE_DOUBLE => 'double',
  45      ];
  46  
  47      /**
  48       * @param BorderPart $borderPart
  49       * @return string
  50       */
  51      public static function serializeBorderPart(BorderPart $borderPart)
  52      {
  53          $definition = 'fo:border-%s="%s"';
  54  
  55          if ($borderPart->getStyle() === Border::STYLE_NONE) {
  56              $borderPartDefinition = \sprintf($definition, $borderPart->getName(), 'none');
  57          } else {
  58              $attributes = [
  59                  self::$widthMap[$borderPart->getWidth()],
  60                  self::$styleMap[$borderPart->getStyle()],
  61                  '#' . $borderPart->getColor(),
  62              ];
  63              $borderPartDefinition = \sprintf($definition, $borderPart->getName(), \implode(' ', $attributes));
  64          }
  65  
  66          return $borderPartDefinition;
  67      }
  68  }