Files
awo-hamburg-intranet/module/tasks/service/ApprovalService.php

65 lines
2.3 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
class ApprovalService
{
private TaskSubmissionRepository $submissionRepo;
private TaskAssignmentRepository $assignmentRepo;
private CompletionService $completionService;
public function __construct(
TaskSubmissionRepository $submissionRepo,
TaskAssignmentRepository $assignmentRepo,
CompletionService $completionService
) {
$this->submissionRepo = $submissionRepo;
$this->assignmentRepo = $assignmentRepo;
$this->completionService = $completionService;
}
public function approveSubmission(int $submissionId, int $adminContactId, string $note): void
{
$submission = $this->submissionRepo->findById($submissionId);
if ($submission === null) {
throw new RuntimeException('Submission nicht gefunden');
}
if ((string) $submission['status'] !== 'awaiting_approval') {
throw new RuntimeException('Submission ist nicht im Status awaiting_approval');
}
TaskCertDb::beginTransaction();
try {
$this->submissionRepo->review($submissionId, 'approved', $adminContactId, $note);
TaskCertDb::commit();
} catch (Throwable $throwable) {
TaskCertDb::rollback();
throw $throwable;
}
$this->completionService->refreshAssignmentAfterReview((int) $submission['assignment_id'], $submissionId);
}
public function rejectSubmission(int $submissionId, int $adminContactId, string $note): void
{
$submission = $this->submissionRepo->findById($submissionId);
if ($submission === null) {
throw new RuntimeException('Submission nicht gefunden');
}
if ((string) $submission['status'] !== 'awaiting_approval') {
throw new RuntimeException('Submission ist nicht im Status awaiting_approval');
}
TaskCertDb::beginTransaction();
try {
$this->submissionRepo->review($submissionId, 'rejected', $adminContactId, $note);
$this->assignmentRepo->updateStatus((int) $submission['assignment_id'], 'rejected', null);
TaskCertDb::commit();
} catch (Throwable $throwable) {
TaskCertDb::rollback();
throw $throwable;
}
}
}