课堂签到动态

video_log
cxt 5 years ago
parent bf6d455e04
commit 9bde634789

@ -8,18 +8,32 @@ class Weapps::CoursesController < Weapps::BaseController
def course_activities
@course = current_course
homework_commons = @course.homework_commons.where(homework_type: ["practice", "normal"]).homework_published
member = @course.course_members.find_by(user_id: current_user.id, is_active: 1)
# 签到数据
attendances = @course.course_attendances
current_date = Date.current
current_end_time = Time.current.strftime("%H:%M:%S")
if @user_course_identity == Course::STUDENT
attendances = attendances.joins(:course_attendance_groups).where(course_attendance_groups: {course_group_id: member.try(:course_group_id).to_i})
.where("attendance_date < '#{current_date}' or (attendance_date = '#{current_date}' and start_time < '#{current_end_time}')")
end
attendance_ids = attendances.blank? ? "(-1)" : "(" + attendances.pluck(:id).join(",") + ")"
homework_commons = @course.homework_commons.where(homework_type: ["practice", "normal"]).homework_published
if (@user_course_identity == Course::STUDENT && member.try(:course_group_id).to_i == 0) || @user_course_identity > Course::STUDENT
homework_commons = homework_commons.unified_setting
elsif @user_course_identity == Course::STUDENT
not_homework_ids = @course.homework_group_settings.none_published.where("course_group_id = #{member.try(:course_group_id)}").pluck(:homework_common_id)
not_homework_ids = @course.homework_group_settings.none_published.where("course_group_id = #{member.try(:course_group_id)}")
.pluck(:homework_common_id)
homework_commons = homework_commons.where.not(id: not_homework_ids)
end
homework_ids = homework_commons.blank? ? "(-1)" : "(" + homework_commons.pluck(:id).join(",") + ")"
activities = @course.course_activities.where("course_act_type in ('Course', 'CourseMessage') or
(course_act_type = 'HomeworkCommon' and course_act_id in #{homework_ids})").order("id desc")
(course_act_type = 'HomeworkCommon' and course_act_id in #{homework_ids}) or
(course_act_type = 'CourseAttendance' and course_act_id in #{attendance_ids})").order("id desc")
@activities_count = activities.size
@activities = paginate activities.includes(:course_act, user: :user_extension)
end

@ -2,10 +2,11 @@ class CourseActivity < ApplicationRecord
belongs_to :course_act, polymorphic: true
belongs_to :course
belongs_to :user
belongs_to :exercise
belongs_to :poll
belongs_to :course_message
belongs_to :homework_common
belongs_to :exercise, optional: true
belongs_to :poll, optional: true
belongs_to :course_message, optional: true
belongs_to :homework_common, optional: true
belongs_to :course_attendance, optional: true
# after_create :add_course_lead

@ -9,13 +9,15 @@ class CourseAttendance < ApplicationRecord
has_many :course_attendance_groups, dependent: :destroy
has_many :course_member_attendances, dependent: :destroy
has_one :course_act, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
validates :name, presence: true
validates :mode, presence: true
validates :attendance_date, presence: true
validates :start_time, presence: true
validates :end_time, presence: true
after_create :generate_attendance_code
after_create :generate_attendance_code, :act_as_course_activity
# 正常签到人数
def normal_count
@ -43,6 +45,11 @@ class CourseAttendance < ApplicationRecord
a_start_time < Time.current && Time.current < a_end_time
end
#课程动态公共表记录
def act_as_course_activity
CourseActivity.create(user_id: user_id, course_id: course_id, course_act: self)
end
# 延迟生成邀请码
def attendance_code
return generate_attendance_code

Loading…
Cancel
Save