mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
attendance card
This commit is contained in:
+84
-6
@@ -28,18 +28,96 @@ parked();
|
||||
// stderr($lang_attendance['sorry'], $lang_attendance['already_attended']);
|
||||
//}
|
||||
|
||||
\Nexus\Nexus::css('vendor/fullcalendar-5.10.2/main.min.css', 'header', true);
|
||||
\Nexus\Nexus::js('vendor/fullcalendar-5.10.2/main.min.js', 'footer', true);
|
||||
\Nexus\Nexus::js('vendor/fullcalendar-5.10.2/locales/zh-cn.js', 'footer', true);
|
||||
|
||||
$today = \Carbon\Carbon::today();
|
||||
$tomorrow = \Carbon\Carbon::tomorrow();
|
||||
$end = $today->clone()->endOfMonth();
|
||||
$start = $today->clone()->subMonth(2);
|
||||
$rep = new \App\Repositories\AttendanceRepository();
|
||||
$result = $rep->attend($CURUSER['id']);
|
||||
if ($result->is_updated) {
|
||||
$count = $result->total_days;
|
||||
$cdays = $result->days;
|
||||
$points = $result->points;
|
||||
$attendance = $rep->attend($CURUSER['id']);
|
||||
$logs = $attendance->logs()->where('date', '>=', $start->format('Y-m-d'))->get()->keyBy('date');
|
||||
$interval = new \DateInterval('P1D');
|
||||
$period = new \DatePeriod($start, $interval, $end);
|
||||
$events = [];
|
||||
foreach ($period as $value) {
|
||||
if ($value->gte($tomorrow)) {
|
||||
continue;
|
||||
}
|
||||
$checkDate = $value->format('Y-m-d');
|
||||
$eventBase = ['start' => $checkDate, 'end' => $checkDate];
|
||||
if ($logs->has($checkDate)) {
|
||||
$logValue = $logs->get($checkDate);
|
||||
$events[] = array_merge($eventBase, ['display' => 'background']);
|
||||
if ($logValue->points > 0) {
|
||||
$events[] = array_merge($eventBase, ['title' => $logValue->points]);
|
||||
}
|
||||
if ($logValue->is_retroactive) {
|
||||
$events[] = array_merge($eventBase, ['title' => $lang_attendance['retroactive_event_text'], 'display' => 'list-item']);
|
||||
}
|
||||
} else {
|
||||
$events[] = array_merge($eventBase, ['groupId' => 'to_do', 'display' => 'list-item']);
|
||||
}
|
||||
}
|
||||
$eventStr = json_encode($events);
|
||||
$validRangeStr = json_encode(['start' => $start->format('Y-m-d'), 'end' => $end->format('Y-m-d')]);
|
||||
|
||||
$js = <<<EOP
|
||||
let events = JSON.parse('$eventStr')
|
||||
let validRange = JSON.parse('$validRangeStr')
|
||||
let confirmText = "{$lang_attendance['retroactive_confirm_tip']}"
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var calendarEl = document.getElementById('calendar');
|
||||
var calendar = new FullCalendar.Calendar(calendarEl, {
|
||||
initialView: 'dayGridMonth',
|
||||
locale: 'zh-cn',
|
||||
events: events,
|
||||
validRange: validRange,
|
||||
eventClick: function(info) {
|
||||
console.log(info.event);
|
||||
if (info.event.groupId == 'to_do') {
|
||||
retroactive(info.event.start)
|
||||
}
|
||||
}
|
||||
});
|
||||
calendar.render();
|
||||
});
|
||||
|
||||
function retroactive(start) {
|
||||
let year = start.getFullYear()
|
||||
let month = start.getMonth() + 1
|
||||
let day = start.getDate()
|
||||
let date = year + '-' + month + '-' + day
|
||||
if (!window.confirm(confirmText + date + ' ?')) {
|
||||
console.log("cancel")
|
||||
return
|
||||
}
|
||||
jQuery.post('ajax.php', {params: {timestamp: start.getTime()}, action: 'attendanceRetroactive'}, function (response) {
|
||||
console.log(response);
|
||||
if (response.ret != 0) {
|
||||
alert(response.msg)
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
}, 'json')
|
||||
}
|
||||
EOP;
|
||||
|
||||
\Nexus\Nexus::js($js, 'footer', false);
|
||||
|
||||
if (1) {
|
||||
$count = $attendance->total_days;
|
||||
$cdays = $attendance->days;
|
||||
$points = $attendance->points;
|
||||
|
||||
stdhead($lang_attendance['title']);
|
||||
begin_main_frame();
|
||||
begin_frame($lang_attendance['success']);
|
||||
printf('<p>'.$lang_attendance['attend_info'].'</p>', $count, $cdays, $points);
|
||||
printf('<p>'.$lang_attendance['attend_info'].$lang_attendance['retroactive_description'].'</p>', $count, $cdays, $points, $CURUSER['attendance_card']);
|
||||
end_frame();
|
||||
echo '<div style="display: flex;justify-content: center;padding: 20px 0"><div id="calendar" style="width: 60%"></div></div>';
|
||||
echo '<ul>';
|
||||
printf('<li>'.$lang_attendance['initial'].'</li>', $attendance_initial_bonus);
|
||||
printf('<li>'.$lang_attendance['steps'].'</li>', $attendance_step_bonus, $attendance_max_bonus);
|
||||
|
||||
Reference in New Issue
Block a user