Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Style;
   4  
   5  use PhpOffice\PhpSpreadsheet\IComparable;
   6  
   7  class Conditional implements IComparable
   8  {
   9      // Condition types
  10      const CONDITION_NONE = 'none';
  11      const CONDITION_CELLIS = 'cellIs';
  12      const CONDITION_CONTAINSTEXT = 'containsText';
  13      const CONDITION_EXPRESSION = 'expression';
  14      const CONDITION_CONTAINSBLANKS = 'containsBlanks';
  15      const CONDITION_NOTCONTAINSBLANKS = 'notContainsBlanks';
  16  
  17      // Operator types
  18      const OPERATOR_NONE = '';
  19      const OPERATOR_BEGINSWITH = 'beginsWith';
  20      const OPERATOR_ENDSWITH = 'endsWith';
  21      const OPERATOR_EQUAL = 'equal';
  22      const OPERATOR_GREATERTHAN = 'greaterThan';
  23      const OPERATOR_GREATERTHANOREQUAL = 'greaterThanOrEqual';
  24      const OPERATOR_LESSTHAN = 'lessThan';
  25      const OPERATOR_LESSTHANOREQUAL = 'lessThanOrEqual';
  26      const OPERATOR_NOTEQUAL = 'notEqual';
  27      const OPERATOR_CONTAINSTEXT = 'containsText';
  28      const OPERATOR_NOTCONTAINS = 'notContains';
  29      const OPERATOR_BETWEEN = 'between';
  30      const OPERATOR_NOTBETWEEN = 'notBetween';
  31  
  32      /**
  33       * Condition type.
  34       *
  35       * @var string
  36       */
  37      private $conditionType = self::CONDITION_NONE;
  38  
  39      /**
  40       * Operator type.
  41       *
  42       * @var string
  43       */
  44      private $operatorType = self::OPERATOR_NONE;
  45  
  46      /**
  47       * Text.
  48       *
  49       * @var string
  50       */
  51      private $text;
  52  
  53      /**
  54       * Stop on this condition, if it matches.
  55       *
  56       * @var bool
  57       */
  58      private $stopIfTrue = false;
  59  
  60      /**
  61       * Condition.
  62       *
  63       * @var string[]
  64       */
  65      private $condition = [];
  66  
  67      /**
  68       * Style.
  69       *
  70       * @var Style
  71       */
  72      private $style;
  73  
  74      /**
  75       * Create a new Conditional.
  76       */
  77      public function __construct()
  78      {
  79          // Initialise values
  80          $this->style = new Style(false, true);
  81      }
  82  
  83      /**
  84       * Get Condition type.
  85       *
  86       * @return string
  87       */
  88      public function getConditionType()
  89      {
  90          return $this->conditionType;
  91      }
  92  
  93      /**
  94       * Set Condition type.
  95       *
  96       * @param string $pValue Condition type, see self::CONDITION_*
  97       *
  98       * @return $this
  99       */
 100      public function setConditionType($pValue)
 101      {
 102          $this->conditionType = $pValue;
 103  
 104          return $this;
 105      }
 106  
 107      /**
 108       * Get Operator type.
 109       *
 110       * @return string
 111       */
 112      public function getOperatorType()
 113      {
 114          return $this->operatorType;
 115      }
 116  
 117      /**
 118       * Set Operator type.
 119       *
 120       * @param string $pValue Conditional operator type, see self::OPERATOR_*
 121       *
 122       * @return $this
 123       */
 124      public function setOperatorType($pValue)
 125      {
 126          $this->operatorType = $pValue;
 127  
 128          return $this;
 129      }
 130  
 131      /**
 132       * Get text.
 133       *
 134       * @return string
 135       */
 136      public function getText()
 137      {
 138          return $this->text;
 139      }
 140  
 141      /**
 142       * Set text.
 143       *
 144       * @param string $value
 145       *
 146       * @return $this
 147       */
 148      public function setText($value)
 149      {
 150          $this->text = $value;
 151  
 152          return $this;
 153      }
 154  
 155      /**
 156       * Get StopIfTrue.
 157       *
 158       * @return bool
 159       */
 160      public function getStopIfTrue()
 161      {
 162          return $this->stopIfTrue;
 163      }
 164  
 165      /**
 166       * Set StopIfTrue.
 167       *
 168       * @param bool $value
 169       *
 170       * @return $this
 171       */
 172      public function setStopIfTrue($value)
 173      {
 174          $this->stopIfTrue = $value;
 175  
 176          return $this;
 177      }
 178  
 179      /**
 180       * Get Conditions.
 181       *
 182       * @return string[]
 183       */
 184      public function getConditions()
 185      {
 186          return $this->condition;
 187      }
 188  
 189      /**
 190       * Set Conditions.
 191       *
 192       * @param bool|float|int|string|string[] $pValue Condition
 193       *
 194       * @return $this
 195       */
 196      public function setConditions($pValue)
 197      {
 198          if (!is_array($pValue)) {
 199              $pValue = [$pValue];
 200          }
 201          $this->condition = $pValue;
 202  
 203          return $this;
 204      }
 205  
 206      /**
 207       * Add Condition.
 208       *
 209       * @param string $pValue Condition
 210       *
 211       * @return $this
 212       */
 213      public function addCondition($pValue)
 214      {
 215          $this->condition[] = $pValue;
 216  
 217          return $this;
 218      }
 219  
 220      /**
 221       * Get Style.
 222       *
 223       * @return Style
 224       */
 225      public function getStyle()
 226      {
 227          return $this->style;
 228      }
 229  
 230      /**
 231       * Set Style.
 232       *
 233       * @param Style $pValue
 234       *
 235       * @return $this
 236       */
 237      public function setStyle(?Style $pValue = null)
 238      {
 239          $this->style = $pValue;
 240  
 241          return $this;
 242      }
 243  
 244      /**
 245       * Get hash code.
 246       *
 247       * @return string Hash code
 248       */
 249      public function getHashCode()
 250      {
 251          return md5(
 252              $this->conditionType .
 253              $this->operatorType .
 254              implode(';', $this->condition) .
 255              $this->style->getHashCode() .
 256              __CLASS__
 257          );
 258      }
 259  
 260      /**
 261       * Implement PHP __clone to create a deep clone, not just a shallow copy.
 262       */
 263      public function __clone()
 264      {
 265          $vars = get_object_vars($this);
 266          foreach ($vars as $key => $value) {
 267              if (is_object($value)) {
 268                  $this->$key = clone $value;
 269              } else {
 270                  $this->$key = $value;
 271              }
 272          }
 273      }
 274  }