/** * @return void * @desc Create DataValidator objects to validate the edit control */ public function CreateValidators() { require_once 'data/validation/numeric-validator.class.php'; require_once 'data/validation/length-validator.class.php'; require_once 'data/validation/required-field-validator.class.php'; $match = $this->GetDataObject(); /* @var $match Match */ $s_home_team = (is_object($match) and is_object($match->GetHomeTeam())) ? $match->GetHomeTeam()->GetName() : 'home team'; $s_away_team = (is_object($match) and is_object($match->GetAwayTeam())) ? $match->GetAwayTeam()->GetName() : 'away team'; $this->AddValidator(new NumericValidator($this->GetNamingPrefix() . 'Result', 'The result identifier must be a number')); $this->AddValidator(new LengthValidator($this->GetNamingPrefix() . 'Player', "The player of the match must be 100 characters or fewer.", 0, 100)); $this->AddValidator(new NumericValidator($this->GetNamingPrefix() . 'PlayerTeam', "The player of the match's team must be identified by a number")); $this->AddValidator(new RequiredFieldValidator(array($this->GetNamingPrefix() . 'Player', $this->GetNamingPrefix() . 'PlayerTeam'), "Please enter both the name and team of the player of the match.", ValidatorMode::AllOrNothing())); $this->AddValidator(new LengthValidator($this->GetNamingPrefix() . 'PlayerHome', "The {$s_home_team} player of the match must be 100 characters or fewer.", 0, 100)); $this->AddValidator(new LengthValidator($this->GetNamingPrefix() . 'PlayerAway', "The {$s_away_team} player of the match must be 100 characters or fewer.", 0, 100)); }
/** * Create validators to check a single team registration * * @param string $s_item_suffix */ protected function CreateValidatorsForItem($s_item_suffix = '') { require_once 'data/validation/required-field-validator.class.php'; require_once 'data/validation/numeric-validator.class.php'; $this->a_validators[] = new NumericValidator($this->GetNamingPrefix() . 'Team' . $s_item_suffix, 'The team identifier should be a number'); $this->a_validators[] = new RequiredFieldValidator(array($this->GetNamingPrefix() . 'Team' . $s_item_suffix), 'Please select a team to add', ValidatorMode::AllOrNothing()); }
/** * @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 */ 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); }
/** * Create validators to check a single points adjustment * * @param string $s_item_suffix */ protected function CreateValidatorsForItem($s_item_suffix = '') { 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'; require_once 'data/validation/numeric-range-validator.class.php'; $this->a_validators[] = new NumericValidator($this->GetNamingPrefix() . 'Points' . $s_item_suffix, 'The points adjustment must be a number. For example, \'2\', not \'two\''); $this->a_validators[] = new NumericRangeValidator($this->GetNamingPrefix() . 'Points' . $s_item_suffix, 'The points awarded or deducted must be one or more', 1, null); $this->a_validators[] = new NumericValidator($this->GetNamingPrefix() . 'Awarded' . $s_item_suffix, 'The points adjustment must be awarded or deducted'); $this->a_validators[] = new NumericValidator($this->GetNamingPrefix() . 'PointsTeam' . $s_item_suffix, 'The team identifier for the points adjustment should be a number'); $this->a_validators[] = new PlainTextValidator($this->GetNamingPrefix() . 'Reason' . $s_item_suffix, 'Please use only letters, numbers and simple punctuation in the reason for the points adjustment'); $this->a_validators[] = new LengthValidator($this->GetNamingPrefix() . 'Reason' . $s_item_suffix, 'The reason for the points adjustment should be 200 characters or fewer', 0, 200); $this->a_validators[] = new RequiredFieldValidator(array($this->GetNamingPrefix() . 'Points' . $s_item_suffix, $this->GetNamingPrefix() . 'PointsTeam' . $s_item_suffix, $this->GetNamingPrefix() . 'Reason' . $s_item_suffix), 'Please complete all fields to add a points adjustment', ValidatorMode::AllOrNothing()); }
/** * Create validators to check a single match * * @param string $s_item_suffix */ protected function CreateValidatorsForItem($s_item_suffix = '') { require_once 'data/validation/required-field-validator.class.php'; require_once 'data/validation/numeric-validator.class.php'; $this->a_validators[] = new NumericValidator($this->GetNamingPrefix() . 'MatchId' . $s_item_suffix, 'The match identifier should be a number'); $this->a_validators[] = new NumericValidator($this->GetNamingPrefix() . 'MatchOrder' . $s_item_suffix, 'The match order should be a number'); $this->a_validators[] = new RequiredFieldValidator(array($this->GetNamingPrefix() . 'HomeTeamId' . $s_item_suffix, $this->GetNamingPrefix() . 'AwayTeamId' . $s_item_suffix), 'Please select two teams to add a match', ValidatorMode::AllOrNothing()); }