portal.mkgtu.ru/common/components/EducationDocumentManager/EducationDocumentManager.php

37 lines
1.2 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\components\EducationDocumentManager;
use common\modules\abiturient\models\bachelor\BachelorApplication;
use common\modules\abiturient\models\bachelor\EducationData;
use Yii;
use yii\web\NotFoundHttpException;
class EducationDocumentManager
{
public static function DeleteEducationDocument(BachelorApplication $application, int $edu_id): bool
{
$result = false;
$tnEducationData = EducationData::tableName();
$edu = $application
->getEducations()
->notInEnlistedApp()
->andWhere(["{$tnEducationData}.id" => $edu_id])
->one();
if (empty($edu)) {
throw new NotFoundHttpException('Не найдена информация об образовании');
}
if ($edu->read_only) {
throw new NotFoundHttpException('Невозможно удалить документ помеченный как «Только для чтения»');
}
try {
$result = $edu->archive();
} catch (\Throwable $e) {
Yii::error("Не удалось удалить информацию об образовании: {$e->getMessage()}");
}
return $result;
}
}