Open Journal Systems  3.3.0
FormValidatorLength.inc.php
1 <?php
2 
16 import ('lib.pkp.classes.form.validation.FormValidator');
17 
19 
21  var $_comparator;
22 
24  var $_length;
25 
35  function __construct(&$form, $field, $type, $message, $comparator, $length) {
36  parent::__construct($form, $field, $type, $message);
37  $this->_comparator = $comparator;
38  $this->_length = $length;
39  }
40 
41 
42  //
43  // Setters and Getters
44  //
49  function getMessage() {
50  return __($this->_message, array('length' => $this->_length));
51  }
52 
53 
54  //
55  // Public methods
56  //
62  function isValid() {
63  if ($this->isEmptyAndOptional()) {
64  return true;
65 
66  } else {
67  $length = PKPString::strlen($this->getFieldValue());
68  switch ($this->_comparator) {
69  case '==':
70  return $length == $this->_length;
71  case '!=':
72  return $length != $this->_length;
73  case '<':
74  return $length < $this->_length;
75  case '>':
76  return $length > $this->_length;
77  case '<=':
78  return $length <= $this->_length;
79  case '>=':
80  return $length >= $this->_length;
81  }
82  return false;
83  }
84  }
85 }
86 
87 
FormValidatorLength\isValid
isValid()
Definition: FormValidatorLength.inc.php:68
FormValidatorLength
Form validation check that checks if a field's length meets certain requirements.
Definition: FormValidatorLength.inc.php:18
FormValidatorLength\$_comparator
$_comparator
Definition: FormValidatorLength.inc.php:24
PKPString\strlen
static strlen($string)
Definition: PKPString.inc.php:128
FormValidatorLength\__construct
__construct(&$form, $field, $type, $message, $comparator, $length)
Definition: FormValidatorLength.inc.php:41
FormValidatorLength\$_length
$_length
Definition: FormValidatorLength.inc.php:30
FormValidator
Class to represent a form validation check.
Definition: FormValidator.inc.php:23
FormValidatorLength\getMessage
getMessage()
Definition: FormValidatorLength.inc.php:55
FormValidator\isEmptyAndOptional
isEmptyAndOptional()
Definition: FormValidator.inc.php:165
FormValidator\getFieldValue
getFieldValue()
Definition: FormValidator.inc.php:154