|  |  |  | @ -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 | 
			
		
	
	
		
			
				
					|  |  |  | 
 |