From 1dc99837641d06fab7b4abc0770734397378991c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 14 Mar 2020 14:18:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=BE=E5=88=B0=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attendances_controller.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/attendances_controller.rb b/app/controllers/attendances_controller.rb index f265bd5a3..6e159cd77 100644 --- a/app/controllers/attendances_controller.rb +++ b/app/controllers/attendances_controller.rb @@ -8,16 +8,24 @@ class AttendancesController < ApplicationController current_date = Date.current current_end_time = Time.current.strftime("%H:%M:%S") + member = @course.students.find_by(user_id: current_user.id) + if params[:history] - @attendances = @course.course_attendances.where("attendance_date < '#{current_date}' or + if @user_course_identity == Course::STUDENT + history_attendance_ids = member.course_member_attendances.where(course_id: @course.id).pluck(:course_attendance_id) + + @attendances = @course.course_attendances.where(id: history_attendance_ids.uniq). + 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 else @attendances = @course.course_attendances.where("attendance_date > '#{current_date}' or (attendance_date = '#{current_date}' and end_time > '#{current_end_time}')") end if @user_course_identity == Course::STUDENT - member = @course.students.find_by(user_id: current_user.id) group_ids = [member&.course_group_id.to_i, 0] @attendances = @attendances.joins(:course_attendance_groups).where(course_attendance_groups: {course_group_id: group_ids})