/** * @return void * @desc Create DataValidator objects to validate the edit control */ function CreateValidators() { # Validate fewer options for a new season than when editing, beacause a new season gets settings copied from last year to save time $b_is_new_season = !(bool) $this->GetDataObject()->GetId(); if (!$this->IsInternalPostback()) { require_once 'data/validation/required-field-validator.class.php'; require_once 'data/validation/length-validator.class.php'; require_once 'data/validation/numeric-validator.class.php'; $this->a_validators[] = new NumericValidator('competition', 'The competition identifier should be a number'); $this->a_validators[] = new RequiredFieldValidator('start', 'Please add the year the season starts', ValidatorMode::AllFields()); $this->a_validators[] = new NumericValidator('start', 'The start year must be a number'); $this->a_validators[] = new LengthValidator('start', 'The start year should be in YYYY format', 4, 4); $this->a_validators[] = new LengthValidator('intro', 'Please make the introduction shorter', 0, 10000); if (!$b_is_new_season) { $this->a_validators[] = new LengthValidator('results', 'Please make the results shorter', 0, 10000); foreach ($this->result_types as $o_result) { /* @var $o_result MatchResult */ $this->a_validators[] = new NumericValidator($this->GetNamingPrefix() . 'Result' . $o_result->GetResultType() . 'Home', 'The home points for ' . MatchResult::Text($o_result->GetResultType()) . ' must be a number. For example, \'2\', not \'two\'.'); $this->a_validators[] = new NumericValidator($this->GetNamingPrefix() . 'Result' . $o_result->GetResultType() . 'Away', 'The away points for ' . MatchResult::Text($o_result->GetResultType()) . ' must be a number. For example, \'2\', not \'two\'.'); } } } $a_aggregated_validators = array(); if (!$b_is_new_season) { $a_aggregated_validators = $this->adjustments_editor->GetValidators(); $a_aggregated_validators = array_merge($a_aggregated_validators, $this->match_types_editor->GetValidators()); $a_aggregated_validators = array_merge($a_aggregated_validators, $this->teams_editor->GetValidators()); } $this->a_validators = array_merge($this->a_validators, $a_aggregated_validators); }
/** * @return bool * @desc Check whether the field(s) are valid */ function IsValid() { // Cache validation so that multiple calls to IsValid don't process again if (isset($this->b_valid)) { return $this->b_valid; } if (is_array($this->a_keys) and is_array($this->a_data)) { if ($this->i_mode == ValidatorMode::SingleField()) { if (!isset($this->a_data[$this->a_keys[0]])) { $this->b_valid = $this->b_valid_if_not_found; } else { $this->b_valid = $this->Test($this->a_data[$this->a_keys[0]], $this->a_keys); } } elseif ($this->i_mode == ValidatorMode::AnyField()) { $b_valid = false; foreach ($this->a_keys as $s_key) { $b_valid = $b_valid || (isset($this->a_data[$s_key]) and $this->Test($this->a_data[$s_key], $this->a_keys)); } $this->b_valid = $b_valid; } elseif ($this->i_mode == ValidatorMode::AllFields()) { $b_valid = true; foreach ($this->a_keys as $s_key) { $b_valid = ($b_valid and (isset($this->a_data[$s_key]) and $this->Test($this->a_data[$s_key], $this->a_keys))); } $this->b_valid = $b_valid; } elseif ($this->i_mode == ValidatorMode::AllOrNothing()) { $b_valid = true; $b_expected = (isset($this->a_data[$this->a_keys[0]]) and $this->Test($this->a_data[$this->a_keys[0]], $this->a_keys)); $i_fields = count($this->a_keys); if ($i_fields > 1) { for ($i = 1; $i < $i_fields; $i++) { if ((isset($this->a_data[$this->a_keys[$i]]) and $this->Test($this->a_data[$this->a_keys[$i]], $this->a_keys)) != $b_expected) { $b_valid = false; } } } $this->b_valid = $b_valid; } elseif ($this->i_mode == ValidatorMode::MultiField()) { $this->b_valid = $this->Test($this->a_data, $this->a_keys); } } else { $this->b_valid = false; } return $this->b_valid; }
/** * @return void * @desc Create DataValidator objects to validate the edit control */ public function CreateValidators() { require_once 'data/validation/required-field-validator.class.php'; require_once 'data/validation/numeric-validator.class.php'; require_once 'data/validation/length-validator.class.php'; $this->a_validators = array(); $this->AddValidator(new RequiredFieldValidator($this->GetNamingPrefix() . 'Title', 'Please enter the tournament name', ValidatorMode::SingleField())); $this->AddValidator(new LengthValidator($this->GetNamingPrefix() . 'Title', 'Your tournament name should not be more than 200 characters long', 0, 200)); $player_type_required = new RequiredFieldValidator($this->GetNamingPrefix() . 'PlayerType', 'Please specify who can play in the tournament'); $player_type_required->SetValidIfNotFound(false); $this->AddValidator($player_type_required); $this->AddValidator(new NumericValidator($this->GetNamingPrefix() . 'Qualify', 'A number should represent who can play')); $this->AddValidator(new NumericValidator($this->GetNamingPrefix() . 'PlayerType', 'A number should represent the type of team')); $this->AddValidator(new NumericValidator($this->GetNamingPrefix() . 'Players', "The number of players per team should be in digits, for example '8' not 'eight'")); $this->AddValidator(new RequiredFieldValidator(array($this->GetNamingPrefix() . 'Start_day', $this->GetNamingPrefix() . 'Start_month', $this->GetNamingPrefix() . 'Start_year'), 'Please select a date for the match', ValidatorMode::AllFields())); $this->AddValidator(new RequiredFieldValidator(array($this->GetNamingPrefix() . 'Start_hour', $this->GetNamingPrefix() . 'Start_minute', $this->GetNamingPrefix() . 'Start_ampm'), 'If you know the match time select the hour, minute and am or pm. If not, leave all three blank.', ValidatorMode::AllOrNothing())); $this->AddValidator(new NumericValidator($this->GetNamingPrefix() . 'Ground', 'The ground should be a number')); $this->AddValidator(new LengthValidator($this->GetNamingPrefix() . 'Notes', 'Your match notes should not be more than 5000 characters long', 0, 5000)); }
/** * @return void * @desc Create DataValidator objects to validate the edit control */ function CreateValidators() { require_once 'data/validation/required-field-validator.class.php'; require_once 'data/validation/plain-text-validator.class.php'; require_once 'data/validation/length-validator.class.php'; require_once 'data/validation/numeric-validator.class.php'; # validate data $this->a_validators[] = new PlainTextValidator('paon', 'Please use only letters, numbers and simple punctuation in the building name or number'); $this->a_validators[] = new LengthValidator('paon', 'Please make the building name or number shorter', 0, 250); $this->a_validators[] = new PlainTextValidator('streetDescriptor', 'Please use only letters, numbers and simple punctuation in the street name'); $this->a_validators[] = new LengthValidator('streetDescriptor', 'Please make the street name shorter', 0, 250); $this->a_validators[] = new PlainTextValidator('locality', 'Please use only letters, numbers and simple punctuation in the village or part of town'); $this->a_validators[] = new LengthValidator('locality', 'Please make the village or part of town shorter', 0, 250); $this->a_validators[] = new RequiredFieldValidator('town', 'Please add the town'); $this->a_validators[] = new LengthValidator('town', 'Please make the town shorter', 0, 100); $this->a_validators[] = new PlainTextValidator('town', 'Please use only letters, numbers and simple punctuation in the town'); $this->a_validators[] = new PlainTextValidator('county', 'Please use only letters, numbers and simple punctuation in the county'); $this->a_validators[] = new LengthValidator('county', 'Please make the county shorter', 0, 100); $this->a_validators[] = new LengthValidator('postcode', 'Postcodes cannot be more than eight characters', 0, 8); # TODO: Add postcode validator $this->a_validators[] = new LengthValidator(array('lat', 'long'), 'Latitude and longitude must be 20 digits or fewer', 0, 20, ValidatorMode::AllFields()); $this->a_validators[] = new NumericValidator(array('lat', 'long'), 'Latitude and longitude must be a number', ValidatorMode::AllFields()); $this->a_validators[] = new LengthValidator(array('geoprecision'), 'Geo precision must be one character', 0, 1); $this->a_validators[] = new NumericValidator(array('geoprecision'), 'Geo precision must be a number'); /* public static final int MIN_LATITUDE = -90 * 1000000; public static final int MAX_LATITUDE = 90 * 1000000; public static final int MIN_LONGITUDE = -180 * 1000000; public static final int MAX_LONGITUDE = 180 * 1000000;*/ }
/** * @return void * @desc Create DataValidator objects to validate the edit control */ function CreateValidators() { require_once 'data/validation/required-field-validator.class.php'; require_once 'data/validation/length-validator.class.php'; require_once 'data/validation/numeric-validator.class.php'; $this->AddValidator(new RequiredFieldValidator('name', 'Please add the name of the school')); $this->AddValidator(new LengthValidator('name', 'Please make the school name shorter', 0, 100)); $this->AddValidator(new LengthValidator('street', 'Please make the road name shorter', 0, 250)); $this->AddValidator(new LengthValidator('locality', 'Please make the part of town shorter', 0, 250)); $this->AddValidator(new RequiredFieldValidator('town', 'Please add the town or village')); $this->AddValidator(new LengthValidator('town', 'Please make the town or village shorter', 0, 100)); $this->AddValidator(new LengthValidator('county', 'Please make the county shorter', 0, 100)); $this->AddValidator(new LengthValidator('postcode', 'Postcodes cannot be more than eight characters', 0, 8)); $this->AddValidator(new LengthValidator(array('latitude', 'longitude'), 'Latitude and longitude must be 20 digits or fewer', 0, 20, ValidatorMode::AllFields())); $this->AddValidator(new NumericValidator(array('latitude', 'longitude'), 'Latitude and longitude must be a number', ValidatorMode::AllFields())); $this->AddValidator(new LengthValidator(array('geoprecision'), 'Geo precision must be one character', 0, 1)); $this->AddValidator(new NumericValidator(array('geoprecision'), 'Geo precision must be a number')); }
/** * @return void * @desc Create DataValidator objects to validate the edit control */ public function CreateValidators() { require_once 'data/validation/required-field-validator.class.php'; require_once 'data/validation/numeric-validator.class.php'; require_once 'data/validation/length-validator.class.php'; $this->a_validators = array(); $this->a_validators[] = new RequiredFieldValidator(array($this->GetNamingPrefix() . 'Start_day', $this->GetNamingPrefix() . 'Start_month', $this->GetNamingPrefix() . 'Start_year'), 'Please select a date for the match', ValidatorMode::AllFields()); $this->a_validators[] = new RequiredFieldValidator(array($this->GetNamingPrefix() . 'Start_hour', $this->GetNamingPrefix() . 'Start_minute', $this->GetNamingPrefix() . 'Start_ampm'), 'If you know the match time select the hour, minute and am or pm. If not, leave all three blank.', ValidatorMode::AllOrNothing()); if (!$this->b_user_is_admin) { $this->a_validators[] = new RequiredFieldValidator($this->GetNamingPrefix() . 'Home', 'Please select a home team'); } $this->a_validators[] = new NumericValidator($this->GetNamingPrefix() . 'Home', 'The home team should be a number'); if (!$this->b_user_is_admin) { $this->a_validators[] = new RequiredFieldValidator($this->GetNamingPrefix() . 'Away', 'Please select an away team'); } $this->a_validators[] = new NumericValidator($this->GetNamingPrefix() . 'Away', 'The away team should be a number'); $this->a_validators[] = new NumericValidator($this->GetNamingPrefix() . 'Ground', 'The ground should be a number'); $this->a_validators[] = new LengthValidator($this->GetNamingPrefix() . 'Notes', 'Your match notes should not be more than 5000 characters long', 0, 5000); }