Skip to content

Commit

Permalink
feat: add an option for force an attendance log outside the session p…
Browse files Browse the repository at this point in the history
…eriod (#10)
  • Loading branch information
xmnlab authored Nov 25, 2023
1 parent 685a430 commit e9eec74
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/lib/attendance.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ public function insert(bool $force=false): Attendance
$personId = $this->person->id;
$sessionId = $this->eventSession->id;
$logTime = convert_to_utc0($this->logTime)->format('Y-m-d H:i:s');

$attendanceCheck = Attendance::get([
"person_id" => $personId,
"event_session_id" => $sessionId,
]);

if ($attendanceCheck !== null) {
throw new Exception("Attendance already logged.");
}

$insertQuery = "
INSERT INTO attendance (
person_id, event_session_id, log_time
Expand Down
26 changes: 22 additions & 4 deletions src/templates/attendance/form.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
include dirname(__DIR__) . "/header.php";
session_start();

require_once dirname(dirname(__DIR__)) . "/lib/attendance.php";
require_once dirname(dirname(__DIR__)) . "/lib/person.php";
require_once dirname(dirname(__DIR__)) . "/lib/event.php";
Expand All @@ -10,16 +11,27 @@
$personId = $_POST['person'];
$eventId = $_POST['event'];
$eventSessionId = $_POST['event_session'];
$force = $_POST['force'];

$person = Person::get(["id" => $personId]);
$eventSession = EventSession::get(["id" => $eventSessionId]);

// Log the attendance
try {
Attendance::log($person, $eventSession);
echo '<p class="alert alert-success">Attendance logged successfully!</p>';
if ($force == "1") {
Attendance::log_force($person, $eventSession);
} else {
Attendance::log($person, $eventSession);
}
$_SESSION['message'] = [
"type" => "success",
"text" => "Attendance logged successfully!",
];
} catch (Exception $e) {
echo '<p class="alert alert-danger">' . $e->getMessage() . '</p>';
$_SESSION['message'] = [
"type" => "error",
"text" => $e->getMessage(),
];
}
}

Expand All @@ -29,6 +41,7 @@
$eventList = [EventSangha::get(["id" => 1])];
$eventSessionList = EventSession::list(["event_id" => 1]);

include dirname(__DIR__) . "/header.php";
?>

<h1>Attendance Log</h1>
Expand Down Expand Up @@ -68,6 +81,11 @@
</select>
</div>

<div class="mb-3">
<label for="event_session" class="form-label">Force:</label>
<input type="checkbox" name="force" value="1" />
</div>

<div class="mb-3">
<button type="submit" class="btn btn-primary">Log</button>
</div>
Expand Down

0 comments on commit e9eec74

Please sign in to comment.