Files
ops-Gazelle/sections/apply/apply.php
2025-05-23 14:41:16 +02:00

41 lines
1.2 KiB
PHP

<?php
/** @phpstan-var \Gazelle\User $Viewer */
/** @phpstan-var \Twig\Environment $Twig */
declare(strict_types=1);
namespace Gazelle;
$appMan = new Manager\Applicant();
$roleMan = new Manager\ApplicantRole();
if (isset($_POST['auth'])) {
authorize();
$roleId = (int)($_POST['role'] ?? 0);
$body = trim($_POST['body'] ?? '');
if (!$roleId) {
$error = "You need to choose which role interests you.";
} elseif (strlen($body) < 80) {
$error = "You need to explain things a bit more.";
} else {
$role = $roleMan->findById($roleId);
if (is_null($role)) {
$error = "No such role.";
} elseif (!$role->isPublished()) {
$error = "That role is no longer open.";
} else {
header("Location: {$role->apply($Viewer, $body)->location()}");
exit;
}
}
}
echo $Twig->render('applicant/apply.twig', [
'body' => new Util\Textarea('body', $body ?? ''),
'error' => $error ?? null,
'list' => $roleMan->publishedList(),
'role' => $role ?? null,
'is_applicant' => $appMan->userIsApplicant($Viewer),
'viewer' => $Viewer,
]);