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.
educoder/app/views/admins/courses/index.xlsx.axlsx

41 lines
1.7 KiB

wb = xlsx_package.workbook
wb.styles do |s|
blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 25,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center}
wb.add_worksheet(name: "课堂列表") do |sheet|
sheet.add_row %w(ID 课堂名称 老师 学生 分班数 资源 公告 视频 视频学习时长 直播 普通作业 分组作业 实训作业 实训作业已发布数 作品数 试卷 评测次数 讨论数 私有 状态 单位 部门 创建者 创建时间), :height => 25,:style => blue_cell
@courses.each do |course|
course_board = course.course_board
topic_count = course_board.present? ? course_board.messages.size : 0
data = [
course.id,
course.name,
course.teacher_course_members.size,
course.students.size,
course.course_groups_count,
get_attachment_count(course, 0),
course.informs.size,
course.course_videos.size,
course.course_videos.map{|cv| cv.watch_course_videos.map(&:total_duration).sum }.sum.round,
course.live_links.size,
course.course_homework_count("normal"),
course.course_homework_count("group"),
course.course_homework_count("practice"),
course.published_course_homework_count("practice"),
course.student_works_count,
course.exercises_count,
course.evaluate_count,
topic_count,
course.is_public == 1 ? "--" : "√",
course.is_end ? "已结束" : "正在进行",
course.school&.name,
course.teacher&.department_name,
course.teacher&.real_name,
course.created_at&.strftime('%Y-%m-%d %H:%M'),
]
sheet.add_row(data)
end
end
end