Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 22, 2020 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/fb77506c5219bc2e82ebae4394407a58 to your computer and use it in GitHub Desktop.
Save parzibyte/fb77506c5219bc2e82ebae4394407a58 to your computer and use it in GitHub Desktop.
<?php
function saveAttendanceData($date, $employees)
{
deleteAttendanceDataByDate($date);
$db = getDatabase();
$db->beginTransaction();
$statement = $db->prepare("INSERT INTO employee_attendance(employee_id, date, status) VALUES (?, ?, ?)");
foreach ($employees as $employee) {
$statement->execute([$employee->id, $date, $employee->status]);
}
$db->commit();
return true;
}
function deleteAttendanceDataByDate($date)
{
$db = getDatabase();
$statement = $db->prepare("DELETE FROM employee_attendance WHERE date = ?");
return $statement->execute([$date]);
}
function getAttendanceDataByDate($date)
{
$db = getDatabase();
$statement = $db->prepare("SELECT employee_id, status FROM employee_attendance WHERE date = ?");
$statement->execute([$date]);
return $statement->fetchAll();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment