Validate related competency ID.

@param int $data The related competency ID.
@return true|lang_string
329311
protected function validate_relatedcompetencyid($data) {

        if ($this->get('competencyid') == $data) {
            // A competency cannot be related to itself.
            return new lang_string('invaliddata', 'error');

        } if ($this->get('competencyid') > $data) {
            // The competency ID must be lower than the related competency ID.
            return new lang_string('invaliddata', 'error');

        } else if (!competency::record_exists($data)) {
            return new lang_string('invaliddata', 'error');

        } else if (!competency::share_same_framework(array($data, $this->get('competencyid')))) {
            // The competencies must belong to the same framework.
            return new lang_string('invaliddata', 'error');
        }

        return true;
    }
1111365
public function isValid($translations)
    {
        $this->message = null;

        if (empty($translations['General']['Locale'])) {
            $this->message = self::ERRORSTATE_LOCALEREQUIRED;
            return false;
        }

        if (empty($translations['General']['TranslatorName'])) {
            $this->message = self::ERRORSTATE_TRANSLATORINFOREQUIRED;
            return false;
        }

        /** @var LanguageDataProvider $languageDataProvider */
        $languageDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\LanguageDataProvider');
        /** @var RegionDataProvider $regionDataProvider */
        $regionDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider');

        $allLanguages = $languageDataProvider->getLanguageList();
        $allCountries = $regionDataProvider->getCountryList();

        if ('eo.UTF-8' === $translations['General']['Locale']) {
            return true;
        }

        if (!preg_match('/^([a-z]{2})_([A-Z]{2})\.UTF-8$/', $translations['General']['Locale'], $matches)) {
            $this->message = self::ERRORSTATE_LOCALEINVALID;
            return false;
        } else if (!array_key_exists($matches[1], $allLanguages)) {
            $this->message = self::ERRORSTATE_LOCALEINVALIDLANGUAGE;
            return false;
        } else if (!array_key_exists(strtolower($matches[2]), $allCountries)) {
            $this->message = self::ERRORSTATE_LOCALEINVALIDCOUNTRY;
            return false;
        }

        return true;
    }
985
function validation($data, $files) {
        global $COURSE;

        $errors = parent::validation($data, $files);

        if (array_key_exists('idnumber', $data)) {
            if ($data['id']) {
                $grade_item = new grade_item(array('id'=>$data['id'], 'courseid'=>$data['courseid']));
            } else {
                $grade_item = null;
            }
            if (!grade_verify_idnumber($data['idnumber'], $COURSE->id, $grade_item, null)) {
                $errors['idnumber'] = get_string('idnumbertaken');
            }
        }

        return $errors;
    }
708332
public function validate(array $data)
    {
        $rules = $this->getRules();
        foreach ($rules as $field => $rule) {
            if ((isset($rule['required']) && $rule['required'] === true && isset($data[$field]))
                || ((!isset($rule['required']) || !$rule['required'])) && isset($data[$field])) {
                foreach ($rule as $key => $value) {
                    if ($key !== 'required') {
                        foreach ($value as $validator) {
                            if (!is_array($validator)) {
                                $validator = [$validator];
                            }
                            if (!Validator::validate($validator[0], $field,
                                    $data, $validator)) {
                                $this->addError($field,
                                    isset($rule['errorMessage']) ? $rule['errorMessage']
                                            : false);
                            }
                        }
                    }
                }
            } elseif (isset($rule['required']) && $rule['required'] === true) {
                $this->addError($field,
                    isset($rule['errorMessage']) ? $rule['errorMessage'] : false);
            }
        }
        return !$this->hasErrors();
    }
216875
public function validate($data) {
    if ($data === NULL) throw $this->emptyException();
    if (!is_array($data)) throw $this->invalidArgument(1, $data, 'Array', __FUNCTION__);
    
    foreach ($this->languages as $lang) {
      if (!array_key_exists($lang, $data)) {
        throw $this->emptyException();
      }
      
      try {
        $data[$lang] = $this->wrappedRule->validate($data[$lang]);
      } catch (EmptyDataException $e) {
        throw $this->emptyException($e);
      }
    }
    
    return $data;
  }
1213855
public function validate(array $data = null)
    {
        $data = $data ?: $this->getInput();

        $this->validation = $this->validator->make($data, $this->rules(), $this->messages());

        if ($this->validation->fails())
        {
            $this->failed();

            return false;
        }

        return true;
    }
1284317
public function validate($data = null)
  {
    $this->reset();

    if (!$this->isSent($data)) {
      return false;
    }

    if (!$this->checkCaptcha($data)) {
      $this->addError($this->getErrCaptcha());
    }

    $data = $this->beforeValidation($this->getValuesForValidation($data));

    foreach ($this->fields as $field => $el) {
      $el->validate($data[$field]);
      unset($data[$field]);

      $this->data[$field] = $el->getValue(true);

      if ($err = $el->getErrors()) {
        foreach ($err as $str) {
          $this->addError($str);
        }
      }
    }

    // Если остались доп.поля после предвалидации - переносим к общим данным
    if (!empty($data)) {
      $this->data = array_merge($data, $this->data);
    }

    $this->data = $this->afterValidation($this->data);

    if ($this->isValid()) {
      $this->process();

      return $this->isValid();
    }

    return false;
  }
980540
public function validate($data) {
        global $DB, $SITE;
        $cleaned = clean_param($data, PARAM_TEXT);
        if ($cleaned === '') {
            return get_string('required');
        }
        if ($this->name ==='shortname' &&
                $DB->record_exists_sql('SELECT id from {course} WHERE shortname = ? AND id <> ?', array($data, $SITE->id))) {
            return get_string('shortnametaken', 'error', $data);
        }
        if ("$data" == "$cleaned") { // implicit conversion to string is needed to do exact comparison
            return true;
        } else {
            return get_string('validateerror', 'admin');
        }
    }
252237
public function validateCompatible(array $data)
    {
        if(!count($data)) {
            /**
             * Allow empty
             */
            return true;
        }
        $count = 0;
        foreach($data as $k=>$v) {
            foreach(array('name','channel','min','max') as $fld) {
                $$fld = trim($v[$fld]);
            }
            $count++;

            $res = $this->validateUrl($channel) && strlen($channel);
            if(!$res) {
                $this->addError("Invalid or empty channel in compat. #{$count}");
            }

            $res = $this->validatePackageName($name) && strlen($name);
            if(!$res) {
                $this->addError("Invalid or empty name in compat. #{$count}");
            }
            $res1 = $this->validateVersion($min);
            if(!$res1) {
                $this->addError("Invalid or empty minVersion in compat. #{$count}");
            }
            $res2 = $this->validateVersion($max);
            if(!$res2) {
                $this->addError("Invalid or empty maxVersion in compat. #{$count}");
            }
            if($res1 && $res2 && $this->versionLower($max, $min)) {
                $this->addError("Max version is lower than min in compat #{$count}");
            }

        }
        return ! $this->hasErrors();
    }
260364
protected function afterValidation($data)
  {
    if ($this->after_validation) {
      $data = call_user_func_array($this->after_validation, array($data, $this));
    }

    return $data;
  }
1091699
public function validate($data) {
        if (((string)(int)$data === (string)$data && $data > 0 && $data <= 10000)) {
            return true;
        } else {
            return get_string('gradepointmax_validateerror', 'grades');
        }
    }
238970
protected function validate(array &$data)
    {
        $messages = [];
        if (!empty($data['errors']) && !empty($data['activity']) && !empty($data['requests'])) {
            array_push($messages, ['warning', trans('It is recommended to periodically clean system logs.')]);
        }
        $data = array_merge($data, ['messages' => $messages]);
        return $data;
    }
313266
public function validate($data) {
        $parentvalidation = parent::validate($data);
        if ($parentvalidation === true) {
            if ($this->maxlength > 0) {
                // Max length check.
                $length = core_text::strlen($data);
                if ($length > $this->maxlength) {
                    return get_string('maximumchars', 'moodle',  $this->maxlength);
                }
                return true;
            } else {
                return true; // No max length check needed.
            }
        } else {
            return $parentvalidation;
        }
    }
991682
public function check($data)
    {
        foreach ($this->requiredFields as $field => $type)
        {
            if (! isset($data[$field]) || empty($data[$field]) || ! $this->isValid($data[$field], $type)) {

                throw new ValidatorException(ValidatorException::INVALID_INTEGRITY, $this->debugDump($field, $data));
            }
        }

        foreach ($this->optionalFields as $field => $expectedType)
        {
            if (! isset($data[$field])) {
                continue;
            }

            if (! $this->isValid($data[$field], $expectedType)) {
                throw new ValidatorException(ValidatorException::INVALID_INTEGRITY, $this->debugDump($field, $data));
            }
        }

        return true;
    }
806965
public function deserialize($data, CompetencyAbility $competencyAbility)
    {
        $this->sipe('id', 'setUuid', $data, $competencyAbility);

        $competency = isset($data['competency']['id']) ?
            $this->competencyRepo->findOneBy(['uuid' => $data['competency']['id']]) :
            null;
        $competencyAbility->setCompetency($competency);

        $level = isset($data['level']['id']) ?
            $this->levelRepo->findOneBy(['uuid' => $data['level']['id']]) :
            null;
        $competencyAbility->setLevel($level);

        $ability = isset($data['ability']['id']) ?
            $this->abilityRepo->findOneBy(['uuid' => $data['ability']['id']]) :
            null;

        if (!$ability) {
            $ability = new Ability();
        }
        $this->sipe('ability.id', 'setUuid', $data, $ability);
        $this->sipe('ability.name', 'setName', $data, $ability);
        $this->sipe('ability.minResourceCount', 'setMinResourceCount', $data, $ability);
        $this->sipe('ability.minEvaluatedResourceCount', 'setMinEvaluatedResourceCount', $data, $ability);
        $this->om->persist($ability);
        $competencyAbility->setAbility($ability);

        return $competencyAbility;
    }
276740
protected function validate_proficiency($value) {
        $grade = $this->get('grade');

        if ($grade !== null && $value === null) {
            // We must set a proficiency when we set a grade.
            return new lang_string('invaliddata', 'error');

        } else if ($grade === null && $value !== null) {
            // We must not set a proficiency when we don't set a grade.
            return new lang_string('invaliddata', 'error');
        }

        return true;
    }
328821
public function process_course_module_competency($data) {
        $data = (object) $data;

        // Mapping the competency by ID numbers.
        $framework = \core_competency\competency_framework::get_record(array('idnumber' => $data->frameworkidnumber));
        if (!$framework) {
            return;
        }
        $competency = \core_competency\competency::get_record(array('idnumber' => $data->idnumber,
            'competencyframeworkid' => $framework->get('id')));
        if (!$competency) {
            return;
        }

        $params = array(
            'competencyid' => $competency->get('id'),
            'cmid' => $this->task->get_moduleid()
        );
        $query = 'competencyid = :competencyid AND cmid = :cmid';
        $existing = \core_competency\course_module_competency::record_exists_select($query, $params);

        if (!$existing) {
            // Sortorder is ignored by precaution, anyway we should walk through the records in the right order.
            $record = (object) $params;
            $record->ruleoutcome = $data->ruleoutcome;
            $coursemodulecompetency = new \core_competency\course_module_competency(0, $record);
            $coursemodulecompetency->create();
        }
    }