|
|
|
@ -127,27 +127,37 @@ class CollegesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
# 在线课堂
|
|
|
|
|
def course_statistics
|
|
|
|
|
courses = Course.where(school_id: @school.id, is_delete: 0)
|
|
|
|
|
|
|
|
|
|
@obj_count = courses.count
|
|
|
|
|
|
|
|
|
|
courses = courses.joins(shixun_homework_commons: :student_works)
|
|
|
|
|
.joins('join games on games.myshixun_id = student_works.myshixun_id')
|
|
|
|
|
.select('courses.id, courses.name, courses.is_end, sum(games.evaluate_count) evaluating_count')
|
|
|
|
|
.group('courses.id').order('is_end asc, evaluating_count desc')
|
|
|
|
|
|
|
|
|
|
@obj_pages = Paginator.new @obj_count, 8, params['page']
|
|
|
|
|
@courses = courses.limit(@obj_pages.per_page).offset(@obj_pages.offset)
|
|
|
|
|
|
|
|
|
|
course_ids = @courses.map(&:id)
|
|
|
|
|
@student_count = StudentsForCourse.where(course_id: course_ids).group(:course_id).count
|
|
|
|
|
@shixun_work_count = HomeworkCommon.where(homework_type: 4, course_id: course_ids).group(:course_id).count
|
|
|
|
|
@attachment_count = Attachment.where(container_id: course_ids, container_type: 'Course').group(:container_id).count
|
|
|
|
|
@message_count = Message.joins(:board).where(boards: { parent_id: 0, course_id: course_ids }).group('boards.course_id').count
|
|
|
|
|
@active_time = CourseActivity.where(course_id: course_ids).group(:course_id).maximum(:created_at)
|
|
|
|
|
@exercise_count = Exercise.where(course_id: course_ids).group(:course_id).count
|
|
|
|
|
@poll_count = Poll.where(course_id: course_ids).group(:course_id).count
|
|
|
|
|
@other_work_count = HomeworkCommon.where(homework_type: [1,3], course_id: course_ids).group(:course_id).count
|
|
|
|
|
@courses = Course.find_by_sql("SELECT c.id, (select concat(lastname,firstname) from users u where u.id=c.tea_id) as username,
|
|
|
|
|
(select count(sfc.id) from students_for_courses sfc where c.id=sfc.course_id group by c.id) as student_count,
|
|
|
|
|
(select count(hc.id) from homework_commons hc where c.id=hc.course_id and hc.homework_type=4 group by c.id) as hcm_count,
|
|
|
|
|
(select count(hc.id) from homework_commons hc where c.id=hc.course_id and hc.homework_type in (1,3) group by c.id) as hcm_nonshixun_count,
|
|
|
|
|
(select count(e.id) from exercises e where c.id=e.course_id group by c.id) as exercises_count,
|
|
|
|
|
(select count(p.id) from polls p where c.id=p.course_id group by c.id) as polls_count,
|
|
|
|
|
(select count(a.id) from attachments a where c.id=a.container_id and a.container_type='Course' group by c.id) as attachments_count,
|
|
|
|
|
(select count(m.id) from messages m inner join boards b on b.id=m.board_id and b.parent_id=0 where b.course_id=c.id group by c.id) as messages_count,
|
|
|
|
|
c.tea_id, c.name, c.is_end,
|
|
|
|
|
(SELECT MAX(created_at) FROM `course_activities` ca WHERE ca.course_id = c.id) AS update_time
|
|
|
|
|
FROM `courses` c WHERE c.school_id = #{@school.id} and c.is_delete = 0")
|
|
|
|
|
|
|
|
|
|
@courses.each do |course|
|
|
|
|
|
course[:evaluating_count] = Output.find_by_sql("select sum(g.evaluate_count) as evaluating_count from games g inner join
|
|
|
|
|
(select myshixun_id from student_works sw inner join homework_commons hc on sw.homework_common_id=hc.id and
|
|
|
|
|
sw.myshixun_id !=0 and hc.course_id=#{course.id} and homework_type=4) aa on g.myshixun_id=aa.myshixun_id").first.try(:evaluating_count).to_i
|
|
|
|
|
course[:task_count] = course.hcm_count.to_i + course.attachments_count.to_i + course.messages_count.to_i + course.hcm_nonshixun_count.to_i + course.exercises_count.to_i + course.polls_count.to_i
|
|
|
|
|
end
|
|
|
|
|
@courses = @courses.sort{|x,y| [y[:evaluating_count], y[:task_count]] <=> [x[:evaluating_count], x[:task_count]] }
|
|
|
|
|
@courses = @courses.sort_by { |course| course.is_end ? 1 : 0 }
|
|
|
|
|
|
|
|
|
|
# SELECT c.id, (select concat(firstname,lastname) from users u where u.id=c.tea_id) as username,
|
|
|
|
|
# (select count(sfc.id) from students_for_courses sfc where c.id=sfc.course_id group by c.id) as student_count,
|
|
|
|
|
# (select count(hc.id) from homework_commons hc where c.id=hc.course_id and hc.homework_type=4 group by c.id) as hcm_count,
|
|
|
|
|
# c.tea_id, c.name, c.is_end,
|
|
|
|
|
# (SELECT MAX(created_at) FROM `course_activities` ca WHERE ca.course_id = c.id) AS update_time
|
|
|
|
|
# FROM `courses` c WHERE (c.school_id = 117 and c.is_delete = 0) ORDER BY update_time desc LIMIT 8 OFFSET 0
|
|
|
|
|
|
|
|
|
|
# @courses = Course.where("courses.school_id = #{@department.school_id} and courses.is_delete = 0").select("courses.id, courses.tea_id, courses.name, courses.is_end,
|
|
|
|
|
# (SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS update_time").order("update_time desc")
|
|
|
|
|
@courses = paginateHelper @courses, 8
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 学生实训
|
|
|
|
|