diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 3d60ed6ec..049118784 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -688,11 +688,11 @@ end end @search = params[:search] # 搜索字 @keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/课程名搜索 - status = params[:status].to_i - courselist = params[:course_list] + @status = params[:status] + @courselist = params[:course_list] + @school_id = params[:school_id] if params[:school_id] && params[:school_id] != '' - @school_id = params[:school_id] @courses = Course.joins("join users u on courses.tea_id = u.id").joins("join user_extensions ue on u.id = ue.user_id").where("ue.school_id = #{params[:school_id]}") end @@ -701,12 +701,11 @@ end end if params[:course_list] && params[:course_list] != '' - @courses = @courses.where(:course_list_id => courselist) + @courses = @courses.where(:course_list_id => @courselist) end if params[:status] && params[:status]!='' - @status = params[:status] - @courses =@courses.where(:is_end =>status) + @courses =@courses.where(:is_end => @status.to_i) end if "u_name" == @keyword if @search.blank? @@ -719,6 +718,7 @@ end @courses= @courses.where("name like '%#{@search}%'") end @courses = @courses.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").reorder("updatetime #{@sx_order}") + @export_courses = @courses @courses_count = @courses.count limit = 20 @is_remote = true @@ -728,6 +728,11 @@ end respond_to do |format| format.js format.html + format.xls{ + @export_courses = @export_courses.all + filename = "#{l(:label_course_list_xls)}.xls" + send_data(course_list_xls(@export_courses), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename)) + } end end @@ -1379,28 +1384,29 @@ end render_404 end - def course_list_xls course + def course_list_xls courses xls_report = StringIO.new book = Spreadsheet::Workbook.new sheet1 = book.create_worksheet :name => "course" blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 sheet1.row(0).default_format = blue - sheet1.row(0).concat([l(:issue_xls_id),l(:issue_xls_tracker_id),l(:issue_xls_title),l(:issue_xls_description),l(:issue_xls_status),l(:issue_xls_assign),l(:issue_xls_priority),l(:issue_xls_author),l(:issue_xls_created_at),l(:milestone),l(:issue_xls_start),l(:issue_xls_due),l(:issue_xls_ratio)]) + sheet1.row(0).concat(["ID","课堂名称","成员","资源","普通作业"," 实训作业","试卷","私有","状态","创建者单位","创建者","动态时间"]) count_row = 1 - issues.each do |issue| - sheet1[count_row,0] = issue.id - sheet1[count_row,1] = issue_tracker_change(issue.tracker_id) - sheet1[count_row,2] = issue.subject - sheet1[count_row,3] = (issue.description.gsub(/<\/?.*?>/,"")).html_safe - sheet1[count_row,4] = issue_status_change(issue.status_id) - sheet1[count_row,5] = issue.assigned_to.try(:show_name) - sheet1[count_row,6] = issue_priority_change(issue.priority_id) - sheet1[count_row,7] = issue.author.show_name - sheet1[count_row,8] = issue.created_on.nil? ? issue.created_on : issue.created_on.strftime('%Y-%m-%d %H:%M:%S') - sheet1[count_row,9] = issue.fixed_version.try(:name) - sheet1[count_row,10] = issue.start_date.nil? ? issue.start_date : issue.start_date.strftime('%Y-%m-%d') - sheet1[count_row,11] = issue.due_date.nil? ? issue.due_date : issue.due_date.strftime('%Y-%m-%d') - sheet1[count_row,12] = issue_ratio_change(issue.done_ratio, issue.status_id) + courses.each do |course| + school = course.teacher.try(:user_extensions).try(:school).try(:name).blank? ? "--" : course.teacher.school_name + teacher_name = course.teacher ? course.teacher.show_real_name : "" + sheet1[count_row,0] = course.id + sheet1[count_row,1] = course.name + sheet1[count_row,2] = course.members.count + sheet1[count_row,3] = course.attachments.count + sheet1[count_row,4] = course.homework_commons.where(:homework_type => 1).count + sheet1[count_row,5] = course.homework_commons.where(:homework_type => 4).count + sheet1[count_row,6] = course.exercises.count + sheet1[count_row,7] = course.is_public.to_i == 1 ? '否' : '是' + sheet1[count_row,8] = course.is_end ? "已结束" : "正在进行" + sheet1[count_row,9] = school + sheet1[count_row,10] = teacher_name + sheet1[count_row,11] = format_time(course.updatetime) count_row += 1 end book.write xls_report diff --git a/app/views/managements/classroom_classment.html.erb b/app/views/managements/classroom_classment.html.erb index e8f8eae86..19eea2798 100644 --- a/app/views/managements/classroom_classment.html.erb +++ b/app/views/managements/classroom_classment.html.erb @@ -34,7 +34,19 @@ - <%#= link_to "导出Excel", export_excel_managements_path(:format => "xls"), :class => "task-btn task-btn-blue ml5 mt3 fr mb5 mr30" %> +