portal.mkgtu.ru/common/modules/abiturient/validators/CompetitiveGroupEntranceTes...

56 lines
1.4 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace common\modules\abiturient\validators;
use common\modules\abiturient\models\bachelor\EgeResult;
use common\modules\abiturient\views\bachelor\assets\CompetitiveGroupEntranceTestsValidatorAsset;
use Yii;
use yii\validators\Validator;
use yii\web\View;
class CompetitiveGroupEntranceTestsValidator extends Validator
{
private $errorMessage;
public function init()
{
parent::init();
$this->errorMessage = Yii::t(
'abiturient/bachelor/ege/ege-result',
'Подсказка с ошибкой для поля "cget_discipline_id"; формы ВИ: `Выберите вступительное испытание.`'
);
}
public function validateAttribute($model, $attribute)
{
if (empty($model->cget_discipline_id) || $model->cget_discipline_id == 0) {
$model->addError($attribute, $this->errorMessage);
}
}
public function clientValidateAttribute($model, $attribute, $view)
{
CompetitiveGroupEntranceTestsValidatorAsset::register($view);
$errorMessage = json_encode($this->errorMessage, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
return "
var result = window.disciplineValidator(\"{$model->index}\");
if (result) {
messages.push('{$errorMessage}');
}
";
}
}