Skip to content

Commit

Permalink
added exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Leone25 committed Sep 24, 2024
1 parent 3f24fe8 commit 6d5e2e3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
59 changes: 59 additions & 0 deletions src/PageCandidates.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Psr\Http\Server\RequestHandlerInterface;
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Diactoros\Response\RedirectResponse;
use Laminas\Diactoros\Response\TextResponse;
use Laminas\Diactoros\Response\JsonResponse;

class PageCandidates implements RequestHandlerInterface
{
Expand Down Expand Up @@ -197,6 +199,63 @@ public function handle(ServerRequestInterface $request): ResponseInterface
}

$users = $db->getUsersWithNotesAndEvaluations($_SESSION['uid']);
if (isset($GET['format'])) {
$usersWithDetails = [];
foreach ($users as $user) {
$userInfo = $db->getUser($user["id"]); // 'id', 'name', 'surname', 'degreecourse', 'year', 'matricola','area', 'letter', 'published', 'status', 'hold', 'recruiter', 'recruitertg', 'submitted', 'visiblenotes', 'emailed', 'invitelink'
$interviewInfo = $db->getInterview($user["id"]); // "id","when","status","recruiter","recruitertg","answers","hold","safetyTestDate"
$details = [
"id" => $userInfo->id,
"name" => $userInfo->name,
"surname" => $userInfo->surname,
"degreeCourse" => $userInfo->degreecourse,
"year" => $userInfo->year,
"matricola" => $userInfo->matricola,
"area" => $userInfo->area,
"letter" => $userInfo->letter,
"submitted" => $userInfo->submitted,
"hold" => $userInfo->hold ? 'Yes' : 'No',
"published" => $userInfo->published ? 'Yes' : 'No',
"recruiter" => $userInfo->recruiter,
"recruiterTg" => $userInfo->recruitertg,
"visibleNotes" => $userInfo->visiblenotes,
"emailed" => $userInfo->emailed ? 'Yes' : 'No',
"inviteLink" => $userInfo->invitelink,
"interviewNotes" => $interviewInfo->answers,
"interviewHold" => $interviewInfo->hold ? 'Yes' : 'No',
"saftyTestDate" => $interviewInfo->safetyTestDate,
];
if ($userInfo->status === true) {
$details["applicationStatus"] = 'Approved';
} elseif ($userInfo->status === false) {
$details["applicationStatus"] = 'Rejected';
} else {
$details["applicationStatus"] = 'Pending';
}
if ($interviewInfo->status === true) {
$details["interviewStatus"] = 'Approved';
} elseif ($interviewInfo->status === false) {
$details["interviewStatus"] = 'Rejected';
} else {
$details["interviewStatus"] = 'Pending';
}
if ($interviewInfo->when !== null) {
$details["interviewDate"] = $interviewInfo->when->format('Y-m-d H:i');
} else {
$details["interviewDate"] = null;
}
$usersWithDetails[] = $details;
}
if ($GET['format'] == 'csv') {
$csv = "Id, Name, Surname, Degree Course, Year, Matricola, Area, Letter, Submitted, Hold, Published, Recruiter, Recruiter Telegram, Visible Notes, Emailed, Invite Link, Interview Notes, Interview Hold, Safety Test Date, Application Status, Interview Status, Interview Date\n";
foreach ($usersWithDetails as $user) {
$csv .= '"' . $user['id'] . '","' . $user['name'] . '","' . $user['surname'] . '","' . $user['degreeCourse'] . '","' . $user['year'] . '","' . $user['matricola'] . '","' . $user['area'] . '","' . $user['letter'] . '","' . $user['submitted'] . '","' . $user['hold'] . '","' . $user['published'] . '","' . $user['recruiter'] . '","' . $user['recruiterTg'] . '","' . $user['visibleNotes'] . '","' . $user['emailed'] . '","' . $user['inviteLink'] . '","' . $user['interviewNotes'] . '","' . $user['interviewHold'] . '","' . $user['saftyTestDate'] . '","' . $user['applicationStatus'] . '","' . $user['interviewStatus'] . '","' . $user['interviewDate'] . "\"\n";
}
return new TextResponse($csv, 200, ['Content-Type' => 'text/csv']);
} elseif ($GET['format'] == 'json') {
return new JsonResponse($usersWithDetails);
}
}
return new HtmlResponse($template->render('candidates', ['users' => $users, 'myuser' => $_SESSION['uid'], 'myname' => $_SESSION['cn']]));
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/PagePosition.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
// Delete position
$db->deletePosition($_GET['id']);
return new RedirectResponse('settings.php', 303);
}
}
if (isset($POST['id'])) {
// Update the id of the position
// Make sure the id is url safe (aka keep only lowercase letters and dashes) and replace spaces with dashes
Expand All @@ -67,12 +67,12 @@ public function handle(ServerRequestInterface $request): ResponseInterface
return new RedirectResponse('position.php?id=' . $newId, 303);
}
}
}
}
if (isset($POST['index'])) {
// Update the index of the position
$db->updatePositionIndex($_GET['id'], $POST['index']);
$changed = true;
}
}
if (isset($POST['translation'])) {
// Figure out which translation has been changed and update it
foreach (Template::SUPPORTED_LOCALES as $locale) {
Expand Down

0 comments on commit 6d5e2e3

Please sign in to comment.