-
-
Save parzibyte/fb77506c5219bc2e82ebae4394407a58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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