Custom validation.

@throws \coding_exception
@return void
320170
protected function validate_data() {
        parent::validate_data();

        if (!isset($this->relateduserid)) {
            debugging('The \'relateduserid\' value must be specified in the event.', DEBUG_DEVELOPER);
            $this->relateduserid = $this->objectid;
        }
    }
120414
private static function validation()
    {
        $files = ['Validator', 'ValidationResult'];
        $folder = static::$root.'Validation'.'/';

        self::call($files, $folder);

        //Initiate the validation surface
        Validator::ini();
    }
71539
protected function init() {
        $this->data['crud'] = 'r';
        $this->data['edulevel'] = self::LEVEL_OTHER;
        if (strstr($this->component, 'mod_') === false) {
            throw new \coding_exception('The event name or namespace is invalid.');
        } else {
            $this->modname = str_replace('mod_', '', $this->component);
        }
    }
217629
protected function validate_data() {
        parent::validate_data();

        if (!in_array($this->other['cmielement'],
                array('cmi.completion_status', 'cmi.core.lesson_status', 'cmi.success_status'))) {
            throw new \coding_exception(
                "The 'cmielement' must represents a valid CMI status element ({$this->other['cmielement']}).");
        }

        if (!in_array($this->other['cmivalue'],
                array('passed', 'completed', 'failed', 'incomplete', 'browsed', 'not attempted', 'unknown'))) {
            throw new \coding_exception(
                "The 'cmivalue' must represents a valid CMI status value ({$this->other['cmivalue']}).");
        }
    }
1185372
protected function prepareForValidation(): void
    {
        $data = $this->all();
        $duration = explode(' - ', $data['duration']);

        $data['starts_at'] = (new Carbon($duration[0]))->toDateTimeString();
        $data['ends_at'] = (new Carbon($duration[1]))->toDateTimeString();

        $this->replace($data);
    }
192085
protected function validate_data() {
        if ($this->other === null) {
            throw new \coding_exception('The \'competencyid\' and \'planid\' values must be set.');
        }

        if (!isset($this->other['competencyid'])) {
            throw new \coding_exception('The \'competencyid\' value must be set.');
        }

        if (!isset($this->other['planid'])) {
            throw new \coding_exception('The \'planid\' value must be set.');
        }
    }
1182862
public function validateTemplate()
    {
        $templates = $this->templates;
        if (!isset($templates[$this->template])) {
            $this->addError('template', 'Invalid template selection.');
        } else {
            $templatePath = $this->templates[$this->template];
            foreach ($this->requiredTemplates() as $template) {
                if (!is_file(Yii::getAlias($templatePath . '/' . $template))) {
                    $this->addError('template', "Unable to find the required code template file '$template'.");
                }
            }
        }
    }
27359
private function validate()
    {
        if ($this->hasValidated) {
            return;
        }

        $this->checkDepth();

        foreach ($this->schema as $rule => $parameter) {
            $this->currentKeyword   = $rule;
            $this->currentParameter = $parameter;
            $this->mergeErrors($this->validateRule($rule, $parameter));
            $this->currentKeyword = $this->currentParameter = null;
        }

        $this->hasValidated = true;
    }
801360
private final function loadValidation(): void
    {
        $this->validation = new Validation();

        $rules = $this->config->get('validation.rules');
        if ($rules != null) {
            $this->validation->setRules($rules);
        }
    }
1339676
public function setupDefaultValidation() {
		$validator = $this->_table->getValidator('default');
		$validator = $this->validationUserName($validator);
		$validator = $this->validationPassword($validator);
		$validator = $this->validationConfirmPassword($validator);
		$this->validationEmail($validator);
	}
71394
public function validate() {
		if( $this->error ) {
			switch( $this->error ) {
				case UPLOAD_ERR_INI_SIZE:
				case UPLOAD_ERR_FORM_SIZE: {
					throw new UserException('fileTooBig');
					break;
				}
				case UPLOAD_ERR_PARTIAL:
				case UPLOAD_ERR_NO_FILE: {
					throw new UserException('transfertIssue');
					break;
				}
				default: {
					// UPLOAD_ERR_NO_TMP_DIR UPLOAD_ERR_CANT_WRITE UPLOAD_ERR_EXTENSION
					// http://php.net/manual/fr/features.file-upload.errors.php
					log_error("Server upload error (error={$this->error}, name={$this->fileName})", 'Uploading file', false);
					throw new UserException('serverIssue');
				}
			}
		}
		
		if( $this->expectedType !== NULL ) {
			if( $this->getType() !== $this->expectedType ) {
				throw new UserException('invalidType');
			}
		}
		if( $this->allowedExtensions !== NULL ) {
			$ext = $this->getExtension();
			if( $ext === $this->allowedExtensions || (is_array($this->allowedExtensions) && !in_array($ext, $this->allowedExtensions)) ) {
				throw new UserException('invalidExtension');
			}
		}
		if( $this->allowedMimeTypes !== NULL) {
			$mt = $this->getMIMEType();
			if( $mt === $this->allowedMimeTypes || (is_array($this->allowedMimeTypes) && !in_array($mt, $this->allowedMimeTypes)) ) {
				throw new UserException('invalidMimeType');	
			}
		}
	}
484138
protected function validateRanges()
    {
        if (!$this->isStartTimeValid()) {
            $message = sprintf(
                Swat::_(
                    'The time you have entered is invalid. ' .
                        'It must be on or after %s.'
                ),
                $this->getFormattedTime($this->valid_range_start)
            );

            $this->addMessage(new SwatMessage($message, 'error'));
        } elseif (!$this->isEndTimeValid()) {
            $message = sprintf(
                Swat::_(
                    'The time you have entered is invalid. ' .
                        'It must be on or before %s.'
                ),
                $this->getFormattedTime($this->valid_range_end)
            );

            $this->addMessage(new SwatMessage($message, 'error'));
        }
    }
1084101
protected function validate_after_order() {
        $nodearray = $this->nodes;
        foreach ($this->nodes as $node) {
            $after = $node->after;
            if (!empty($after)) {
                if (empty($nodearray[$after])) {
                    throw new \coding_exception('node {$node->name} specified contains invalid \'after\' property');
                } else {
                    // Valid node found.
                    $afternode = $nodearray[$after];
                    $beforecontent = $node->content;
                    $aftercontent = $afternode->content;

                    if ((empty($beforecontent) && !empty($aftercontent)) || (!empty($beforecontent) && empty($aftercontent))) {
                        // Only node with content are allowed after content nodes. Same goes for no content nodes.
                        throw new \coding_exception('node {$node->name} specified contains invalid \'after\' property');
                    }
                }
            }
        }
    }
1253243
protected function validate_data() {
        parent::validate_data();

        if (!isset($this->relateduserid)) {
            debugging('The \'relateduserid\' value must be specified in the event.', DEBUG_DEVELOPER);
            $this->relateduserid = $this->objectid;
        }

        if (!isset($this->other['username'])) {
            throw new \coding_exception('The \'username\' value must be set in other.');
        }

        if (!isset($this->other['email'])) {
            throw new \coding_exception('The \'email\' value must be set in other.');
        }

        if (!isset($this->other['idnumber'])) {
            throw new \coding_exception('The \'idnumber\' value must be set in other.');
        }

        if (!isset($this->other['picture'])) {
            throw new \coding_exception('The \'picture\' value must be set in other.');
        }

        if (!isset($this->other['mnethostid'])) {
            throw new \coding_exception('The \'mnethostid\' value must be set in other.');
        }
    }
677450
private function validate()
    {
        if (!class_exists($this->class)) {
            throw new \RuntimeException(sprintf('Class %s does not exist, is this the correct namespace?', $this->class));
        }
        if (!in_array($this->method, get_class_methods($this->class))) {
            throw new \RuntimeException(sprintf('The method "%s" does not exist in "%s" class.', $this->method, $this->class));
        }
    }
79882
public function validate() {

		if ($this->getEndAction() === null) {
			throw new ValidationException("'endAction' can't be null", 'endAction', $this);
		}
		if ($this->getPlannedEndDate() === null) {
			throw new ValidationException("'plannedEndDate' can't be null", 'plannedEndDate', $this);
		}
		if ($this->getSubscription() === null) {
			throw new ValidationException("'subscription' can't be null", 'subscription', $this);
		}
	}
1193134
public function validate() : void
    {
        if (null === $this->is_valid) {
            if (null === $this->user_value && null !== $this->default_value) {
                // There is a preset value, and its not being changed
                $this->is_valid = true;
            } elseif (true == $this->user_value || 1 == $this->user_value) {
                $this->user_value = 1;
                $this->is_valid = true;
            } elseif (false == $this->user_value || 0 == $this->user_value || '' == $this->user_value) {
                $this->user_value = 0;
                $this->is_valid = true;
            } elseif (false == $this->validator) {
                // This field does not get validated
                $this->is_valid = true;
            } else {
                $this->is_valid = false;
                $this->error = 'The provided value is not valid. Please enter a valid value.';
            }
        }

        // Check if the input is different from the default value
        if ($this->is_valid && null !== $this->user_value) {
            $this->is_changed = ($this->default_value != $this->user_value);
        }
    }