Files
awo-hamburg-intranet/module/tasks/endpoints/user/request_manual_approval.php

44 lines
1.2 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
require_once dirname(dirname(__DIR__)) . '/bootstrap.php';
if (!TaskCertRequest::isPost()) {
TaskCertResponse::error('Methode nicht erlaubt', 405);
}
$auth = TaskCertAuthContext::fromGlobals();
if (!$auth->isLoggedIn()) {
TaskCertResponse::error('Nicht eingeloggt', 401);
}
TaskCertCsrf::assertValidFromRequest(true);
$assignmentId = TaskCertRequest::postInt('assignment_id', 0);
$methodId = TaskCertRequest::postInt('method_id', 0);
$note = TaskCertRequest::postString('note', '');
if ($assignmentId <= 0 || $methodId <= 0) {
TaskCertResponse::error('Ungültige assignment_id oder method_id', 400);
}
try {
$services = task_cert_services();
$submissionId = $services['completionService']->requestManualApproval($assignmentId, $methodId, $note);
$redirectTo = TaskCertRequest::postString('redirect_to', '');
if ($redirectTo !== '') {
TaskCertResponse::redirect($redirectTo);
}
TaskCertResponse::json([
'success' => true,
'submission_id' => $submissionId,
]);
} catch (Throwable $throwable) {
TaskCertResponse::json([
'success' => false,
'error' => $throwable->getMessage(),
], 400);
}