false ], [ [ 'code', 'email' ], 'string', 'max' => 255 ], [ ['questionary_id'], 'exist', 'skipOnError' => true, 'targetClass' => AbiturientQuestionary::class, 'targetAttribute' => ['questionary_id' => 'id'] ], [ ['address_data_id'], 'exist', 'skipOnError' => true, 'targetClass' => ParentAddressData::class, 'targetAttribute' => ['address_data_id' => 'id'] ], [ ['type_id'], 'exist', 'skipOnError' => true, 'targetClass' => FamilyType::class, 'targetAttribute' => ['type_id' => 'id'] ], [ ['passport_data_id'], 'exist', 'skipOnError' => true, 'targetClass' => ParentPassportData::class, 'targetAttribute' => ['passport_data_id' => 'id'] ], [ ['personal_data_id'], 'exist', 'skipOnError' => true, 'targetClass' => ParentPersonalData::class, 'targetAttribute' => ['personal_data_id' => 'id'] ], ]; } public function attributeLabels() { return [ 'type_id' => Yii::t('abiturient/questionary/parent-data', 'Подпись для поля "type_id" формы "Родитель": `Степень родства`'), 'typeName' => Yii::t('abiturient/questionary/parent-data', 'Подпись для поля "typeName" формы "Родитель": `Степень родства`'), 'email' => Yii::t('abiturient/questionary/parent-data', 'Подпись для поля "email" формы "Родитель": `Электронная почта`'), ]; } public function behaviors() { return [ \yii\behaviors\TimestampBehavior::class, ]; } public function getAddressData() { return $this->hasOne(ParentAddressData::class, ['id' => 'address_data_id']); } public function getPassportData() { return $this->hasOne(ParentPassportData::class, ['id' => 'passport_data_id']); } public function getPersonalData() { return $this->hasOne(ParentPersonalData::class, ['id' => 'personal_data_id']); } public function getAbiturientQuestionary() { return $this->hasOne(AbiturientQuestionary::class, ['id' => 'questionary_id']); } public function getType() { return $this->hasOne(FamilyType::class, ['id' => 'type_id']); } public function getParentRef() { if (!$this->parent_ref_id && $this->code) { $userReference = UserReferenceTypeManager::getUserReferenceFrom1CByGuid($this->code); if (isset($userReference)) { $this->parent_ref_id = $userReference->id; $this->save(true, ['parent_ref_id']); } } return $this->hasOne(StoredUserReferenceType::class, ['id' => 'parent_ref_id']); } public static function checkInterfaceVersion(string $method_name): void { $valid = false; try { $result = \Yii::$app->dictionaryManager->GetInterfaceVersion($method_name); $valid = version_compare($result, '0.0.18.8') >= 0; } catch (Throwable $e) { \Yii::error("Не удалось получить версию метода {$method_name}: {$e->getMessage()}"); $valid = false; } if (!$valid) { throw new UserException("Для корректной работы блока родителей необходимо установить все доступные патчи для 1С:Университет ПРОФ"); } } public function stringify(): string { $firstname = ArrayHelper::getValue($this, 'personalData.firstname'); $middlename = ArrayHelper::getValue($this, 'personalData.middlename'); $lastname = ArrayHelper::getValue($this, 'personalData.lastname'); $passportSeries = ArrayHelper::getValue($this, 'passportData.series'); $passportNumber = ArrayHelper::getValue($this, 'passportData.number'); return "$lastname $firstname $middlename ($passportSeries $passportNumber)"; } public function getChangeLoggedAttributes() { return [ 'email', 'type_id' => function ($model) { return ArrayHelper::getValue($model, 'type.name'); } ]; } public function getClassTypeForChangeHistory(): int { return ChangeHistoryClasses::CLASS_PARENT_DATA; } public function getRelationsInfo(): array { return [ new OneToOneRelationPresenter('addressData', [ 'parent_instance' => $this, 'child_class' => ParentAddressData::class, 'parent_column_name' => 'address_data_id', 'child_column_name' => 'id', ]), new OneToOneRelationPresenter('passportData', [ 'parent_instance' => $this, 'child_class' => ParentPassportData::class, 'parent_column_name' => 'passport_data_id', 'child_column_name' => 'id', ]), new OneToOneRelationPresenter('personalData', [ 'parent_instance' => $this, 'child_class' => ParentPersonalData::class, 'parent_column_name' => 'personal_data_id', 'child_column_name' => 'id', ]), ]; } public function getIdentityString(): string { $fio = ArrayHelper::getValue($this, 'personalData.fullName'); $type = ArrayHelper::getValue($this, 'type.uid'); $personalData = $this->personalData ? $this->personalData->getIdentityString() : ''; $passportData = $this->passportData ? $this->passportData->getIdentityString() : ''; $addressData = $this->addressData ? $this->addressData->getIdentityString() : ''; return "{$type}_{$fio}_{$personalData}_{$passportData}_{$addressData}"; } public function getVirtualProps(): array { return [ 'typeName' => function (ParentData $model) { return ArrayHelper::getValue($model, 'type.name'); } ]; } public function getEntityForDuplicatesFind(): EntityForDuplicatesFind { $passport = ArrayHelper::getValue($this, 'passportData', null); $passport_data = []; if ($passport) { $passport_data[] = [ 'type' => $passport->documentType, 'number' => (string)$passport->number, 'series' => (string)$passport->series, ]; } return new EntityForDuplicatesFind( (string)ArrayHelper::getValue($this, 'personalData.firstname'), (string)ArrayHelper::getValue($this, 'personalData.lastname'), (string)ArrayHelper::getValue($this, 'personalData.middlename'), (string)ArrayHelper::getValue($this, 'personalData.formated_birthdate'), (string)ArrayHelper::getValue($this, 'personalData.snils'), $passport_data ); } }