From 6d5e2e3ba74b5d4b190b9fff94ad096be94a9128 Mon Sep 17 00:00:00 2001 From: Leone25 <39310565+Leone25@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:38:09 +0200 Subject: [PATCH] added exporting --- src/PageCandidates.php | 59 ++++++++++++++++++++++++++++++++++++++++++ src/PagePosition.php | 6 ++--- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/PageCandidates.php b/src/PageCandidates.php index b472587..a6cb0b9 100644 --- a/src/PageCandidates.php +++ b/src/PageCandidates.php @@ -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 { @@ -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']])); } } diff --git a/src/PagePosition.php b/src/PagePosition.php index d279e8f..a0336a4 100644 --- a/src/PagePosition.php +++ b/src/PagePosition.php @@ -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 @@ -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) {