entirelyRemoveAppFromOneS(); } if (!$status) { throw new ServerErrorHttpException("Не удалось вернуть заявление на модерацию по причине: " . $message); } $application->status = ApplicationInterface::STATUS_SENT_AFTER_NOT_APPROVED; $application->draft_status = IDraftable::DRAFT_STATUS_SENT; $application->sent_at = time(); if (!$application->save()) { throw new RecordNotValid($application); } $application = DraftsManager::createArchivePoint( $application, DraftsManager::REASON_SENT, IDraftable::DRAFT_STATUS_SENT ); DraftsManager::clearOldModerations($application, $currentUser, DraftsManager::REASON_SENT); DraftsManager::clearOldSendings($application, $currentUser, DraftsManager::REASON_SENT); if ($remove_from_one_s) { DraftsManager::removeOldApproved($application, $currentUser, DraftsManager::REASON_APPROVED); } $application->type->toggleResubmitPermissions($application->user, true); return $application; } public function getAllModelForView(?int $applicationId): array { $application = BachelorApplication::findOne($applicationId); $questionary = $application->abiturientQuestionary; return [ 'application' => $application, 'questionary' => $questionary, 'regulations' => $this->getRegulations($application, $questionary), 'moderatingAppId' => $this->getModeratingApplicationId($application), 'individualAchievements' => new ActiveDataProvider([ 'query' => $application->getIndividualAchievements() ]), ]; } public function getArchiveApplicationForView(?int $userId, ?int $applicationId, Controller $controller): array { $tnBachelorApplication = BachelorApplication::tableName(); $applicationTypeQueryFilter = BachelorApplication::find() ->select('type_id') ->andWhere([ "{$tnBachelorApplication}.id" => $applicationId, "{$tnBachelorApplication}.user_id" => $userId, ]); $applications = BachelorApplication::find() ->andWhere(["{$tnBachelorApplication}.user_id" => $userId]) ->andWhere(["{$tnBachelorApplication}.parent_draft_id" => null]) ->andWhere(['IN', "{$tnBachelorApplication}.type_id", $applicationTypeQueryFilter]) ->orderBy(["{$tnBachelorApplication}.created_at" => SORT_ASC]) ->all(); return BachelorApplication::getApplicationArchiveNode($applications, $applicationId, $controller); } private function getModeratingApplicationId(BachelorApplication $application): ?int { $moderatingAppId = null; $moderatingApp = DraftsManager::getApplicationDraftByOtherDraft( $application, $application->getDraftStatusToModerate() ); if ($moderatingApp) { $moderatingAppId = $moderatingApp->id; } return $moderatingAppId; } private function getRegulations(BachelorApplication $application, AbiturientQuestionary $questionary): array { $regulations = UserRegulationRepository::GetAllUserRegulationsByRelatedEntity( $questionary, array_keys(RegulationRelationManager::GetRelatedList()), $application ); foreach ($regulations as $regulation) { if ($regulation->regulation->attachment_type !== null && $regulation->getAttachments()->exists()) { $newAttachment = new Attachment(); $newAttachment->owner_id = $application->user_id; $newAttachment->attachment_type_id = $regulation->regulation->attachment_type; $regulation->setRawAttachment($newAttachment); } } return $regulations; } }