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\Cell;
   4  
   5  class DataValidation
   6  {
   7      // Data validation types
   8      const TYPE_NONE = 'none';
   9      const TYPE_CUSTOM = 'custom';
  10      const TYPE_DATE = 'date';
  11      const TYPE_DECIMAL = 'decimal';
  12      const TYPE_LIST = 'list';
  13      const TYPE_TEXTLENGTH = 'textLength';
  14      const TYPE_TIME = 'time';
  15      const TYPE_WHOLE = 'whole';
  16  
  17      // Data validation error styles
  18      const STYLE_STOP = 'stop';
  19      const STYLE_WARNING = 'warning';
  20      const STYLE_INFORMATION = 'information';
  21  
  22      // Data validation operators
  23      const OPERATOR_BETWEEN = 'between';
  24      const OPERATOR_EQUAL = 'equal';
  25      const OPERATOR_GREATERTHAN = 'greaterThan';
  26      const OPERATOR_GREATERTHANOREQUAL = 'greaterThanOrEqual';
  27      const OPERATOR_LESSTHAN = 'lessThan';
  28      const OPERATOR_LESSTHANOREQUAL = 'lessThanOrEqual';
  29      const OPERATOR_NOTBETWEEN = 'notBetween';
  30      const OPERATOR_NOTEQUAL = 'notEqual';
  31  
  32      /**
  33       * Formula 1.
  34       *
  35       * @var string
  36       */
  37      private $formula1 = '';
  38  
  39      /**
  40       * Formula 2.
  41       *
  42       * @var string
  43       */
  44      private $formula2 = '';
  45  
  46      /**
  47       * Type.
  48       *
  49       * @var string
  50       */
  51      private $type = self::TYPE_NONE;
  52  
  53      /**
  54       * Error style.
  55       *
  56       * @var string
  57       */
  58      private $errorStyle = self::STYLE_STOP;
  59  
  60      /**
  61       * Operator.
  62       *
  63       * @var string
  64       */
  65      private $operator = self::OPERATOR_BETWEEN;
  66  
  67      /**
  68       * Allow Blank.
  69       *
  70       * @var bool
  71       */
  72      private $allowBlank = false;
  73  
  74      /**
  75       * Show DropDown.
  76       *
  77       * @var bool
  78       */
  79      private $showDropDown = false;
  80  
  81      /**
  82       * Show InputMessage.
  83       *
  84       * @var bool
  85       */
  86      private $showInputMessage = false;
  87  
  88      /**
  89       * Show ErrorMessage.
  90       *
  91       * @var bool
  92       */
  93      private $showErrorMessage = false;
  94  
  95      /**
  96       * Error title.
  97       *
  98       * @var string
  99       */
 100      private $errorTitle = '';
 101  
 102      /**
 103       * Error.
 104       *
 105       * @var string
 106       */
 107      private $error = '';
 108  
 109      /**
 110       * Prompt title.
 111       *
 112       * @var string
 113       */
 114      private $promptTitle = '';
 115  
 116      /**
 117       * Prompt.
 118       *
 119       * @var string
 120       */
 121      private $prompt = '';
 122  
 123      /**
 124       * Create a new DataValidation.
 125       */
 126      public function __construct()
 127      {
 128      }
 129  
 130      /**
 131       * Get Formula 1.
 132       *
 133       * @return string
 134       */
 135      public function getFormula1()
 136      {
 137          return $this->formula1;
 138      }
 139  
 140      /**
 141       * Set Formula 1.
 142       *
 143       * @param string $value
 144       *
 145       * @return $this
 146       */
 147      public function setFormula1($value)
 148      {
 149          $this->formula1 = $value;
 150  
 151          return $this;
 152      }
 153  
 154      /**
 155       * Get Formula 2.
 156       *
 157       * @return string
 158       */
 159      public function getFormula2()
 160      {
 161          return $this->formula2;
 162      }
 163  
 164      /**
 165       * Set Formula 2.
 166       *
 167       * @param string $value
 168       *
 169       * @return $this
 170       */
 171      public function setFormula2($value)
 172      {
 173          $this->formula2 = $value;
 174  
 175          return $this;
 176      }
 177  
 178      /**
 179       * Get Type.
 180       *
 181       * @return string
 182       */
 183      public function getType()
 184      {
 185          return $this->type;
 186      }
 187  
 188      /**
 189       * Set Type.
 190       *
 191       * @param string $value
 192       *
 193       * @return $this
 194       */
 195      public function setType($value)
 196      {
 197          $this->type = $value;
 198  
 199          return $this;
 200      }
 201  
 202      /**
 203       * Get Error style.
 204       *
 205       * @return string
 206       */
 207      public function getErrorStyle()
 208      {
 209          return $this->errorStyle;
 210      }
 211  
 212      /**
 213       * Set Error style.
 214       *
 215       * @param string $value see self::STYLE_*
 216       *
 217       * @return $this
 218       */
 219      public function setErrorStyle($value)
 220      {
 221          $this->errorStyle = $value;
 222  
 223          return $this;
 224      }
 225  
 226      /**
 227       * Get Operator.
 228       *
 229       * @return string
 230       */
 231      public function getOperator()
 232      {
 233          return $this->operator;
 234      }
 235  
 236      /**
 237       * Set Operator.
 238       *
 239       * @param string $value
 240       *
 241       * @return $this
 242       */
 243      public function setOperator($value)
 244      {
 245          $this->operator = $value;
 246  
 247          return $this;
 248      }
 249  
 250      /**
 251       * Get Allow Blank.
 252       *
 253       * @return bool
 254       */
 255      public function getAllowBlank()
 256      {
 257          return $this->allowBlank;
 258      }
 259  
 260      /**
 261       * Set Allow Blank.
 262       *
 263       * @param bool $value
 264       *
 265       * @return $this
 266       */
 267      public function setAllowBlank($value)
 268      {
 269          $this->allowBlank = $value;
 270  
 271          return $this;
 272      }
 273  
 274      /**
 275       * Get Show DropDown.
 276       *
 277       * @return bool
 278       */
 279      public function getShowDropDown()
 280      {
 281          return $this->showDropDown;
 282      }
 283  
 284      /**
 285       * Set Show DropDown.
 286       *
 287       * @param bool $value
 288       *
 289       * @return $this
 290       */
 291      public function setShowDropDown($value)
 292      {
 293          $this->showDropDown = $value;
 294  
 295          return $this;
 296      }
 297  
 298      /**
 299       * Get Show InputMessage.
 300       *
 301       * @return bool
 302       */
 303      public function getShowInputMessage()
 304      {
 305          return $this->showInputMessage;
 306      }
 307  
 308      /**
 309       * Set Show InputMessage.
 310       *
 311       * @param bool $value
 312       *
 313       * @return $this
 314       */
 315      public function setShowInputMessage($value)
 316      {
 317          $this->showInputMessage = $value;
 318  
 319          return $this;
 320      }
 321  
 322      /**
 323       * Get Show ErrorMessage.
 324       *
 325       * @return bool
 326       */
 327      public function getShowErrorMessage()
 328      {
 329          return $this->showErrorMessage;
 330      }
 331  
 332      /**
 333       * Set Show ErrorMessage.
 334       *
 335       * @param bool $value
 336       *
 337       * @return $this
 338       */
 339      public function setShowErrorMessage($value)
 340      {
 341          $this->showErrorMessage = $value;
 342  
 343          return $this;
 344      }
 345  
 346      /**
 347       * Get Error title.
 348       *
 349       * @return string
 350       */
 351      public function getErrorTitle()
 352      {
 353          return $this->errorTitle;
 354      }
 355  
 356      /**
 357       * Set Error title.
 358       *
 359       * @param string $value
 360       *
 361       * @return $this
 362       */
 363      public function setErrorTitle($value)
 364      {
 365          $this->errorTitle = $value;
 366  
 367          return $this;
 368      }
 369  
 370      /**
 371       * Get Error.
 372       *
 373       * @return string
 374       */
 375      public function getError()
 376      {
 377          return $this->error;
 378      }
 379  
 380      /**
 381       * Set Error.
 382       *
 383       * @param string $value
 384       *
 385       * @return $this
 386       */
 387      public function setError($value)
 388      {
 389          $this->error = $value;
 390  
 391          return $this;
 392      }
 393  
 394      /**
 395       * Get Prompt title.
 396       *
 397       * @return string
 398       */
 399      public function getPromptTitle()
 400      {
 401          return $this->promptTitle;
 402      }
 403  
 404      /**
 405       * Set Prompt title.
 406       *
 407       * @param string $value
 408       *
 409       * @return $this
 410       */
 411      public function setPromptTitle($value)
 412      {
 413          $this->promptTitle = $value;
 414  
 415          return $this;
 416      }
 417  
 418      /**
 419       * Get Prompt.
 420       *
 421       * @return string
 422       */
 423      public function getPrompt()
 424      {
 425          return $this->prompt;
 426      }
 427  
 428      /**
 429       * Set Prompt.
 430       *
 431       * @param string $value
 432       *
 433       * @return $this
 434       */
 435      public function setPrompt($value)
 436      {
 437          $this->prompt = $value;
 438  
 439          return $this;
 440      }
 441  
 442      /**
 443       * Get hash code.
 444       *
 445       * @return string Hash code
 446       */
 447      public function getHashCode()
 448      {
 449          return md5(
 450              $this->formula1 .
 451              $this->formula2 .
 452              $this->type .
 453              $this->errorStyle .
 454              $this->operator .
 455              ($this->allowBlank ? 't' : 'f') .
 456              ($this->showDropDown ? 't' : 'f') .
 457              ($this->showInputMessage ? 't' : 'f') .
 458              ($this->showErrorMessage ? 't' : 'f') .
 459              $this->errorTitle .
 460              $this->error .
 461              $this->promptTitle .
 462              $this->prompt .
 463              __CLASS__
 464          );
 465      }
 466  
 467      /**
 468       * Implement PHP __clone to create a deep clone, not just a shallow copy.
 469       */
 470      public function __clone()
 471      {
 472          $vars = get_object_vars($this);
 473          foreach ($vars as $key => $value) {
 474              if (is_object($value)) {
 475                  $this->$key = clone $value;
 476              } else {
 477                  $this->$key = $value;
 478              }
 479          }
 480      }
 481  }