You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.6 KiB
39 lines
1.6 KiB
5 years ago
|
class AttendancesController < ApplicationController
|
||
|
before_action :require_login
|
||
|
before_action :find_course, only: [:index, :student_attendances, :history_attendances]
|
||
|
before_action :find_attendance, except: [:index, :student_attendances, :history_attendances]
|
||
|
before_action :user_course_identity
|
||
|
|
||
|
def index
|
||
|
current_date = Date.current
|
||
|
current_end_time = Time.current.strftime("%H:%M:%S")
|
||
|
|
||
|
if params[:history]
|
||
|
@attendances = @course.course_attendances.where("attendance_date < '#{current_date}' or
|
||
|
(attendance_date = '#{current_date}' and end_time < '#{current_end_time}')")
|
||
|
else
|
||
|
@attendances = @course.course_attendances.where("attendance_date > '#{current_date}' or
|
||
|
(attendance_date = '#{current_date}' and end_time > '#{current_end_time}')")
|
||
|
end
|
||
|
@attendances_count = @attendances.size
|
||
|
|
||
|
@attendances = @attendances.order("attendance_date desc, start_time desc")
|
||
|
@attendances = paginate @attendances.includes(:user, :course_member_attendances)
|
||
|
end
|
||
|
|
||
|
def history_attendances
|
||
|
current_date = Date.current
|
||
|
current_end_time = Time.current.strftime("%H:%M:%S")
|
||
|
|
||
|
@history_attendances = @course.course_attendances.where("attendance_date < '#{current_date}' or
|
||
|
(attendance_date = '#{current_date}' and end_time < '#{current_end_time}')").order("id desc")
|
||
|
@all_history_count = @history_attendances.size
|
||
|
@history_attendances = paginate @history_attendances.includes(:course_member_attendances)
|
||
|
end
|
||
|
|
||
|
private
|
||
|
def find_attendance
|
||
|
@attendance = CourseAttendance.find params[:id]
|
||
|
@course = @attendance.course
|
||
|
end
|
||
|
end
|