From c2e21f7a0cfc339c2437096ebabf5d6ca0b194ec Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Tue, 30 Jun 2015 15:30:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=BA=E8=AF=84=E5=88=97=E8=A1=A8=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 62 ++++++++++++++++++- app/views/student_work/index.html.erb | 2 + .../student_work_absence_penalty.html.erb | 6 +- config/locales/zh.yml | 5 ++ config/routes.rb | 2 + 5 files changed, 71 insertions(+), 6 deletions(-) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 568357b3c..f9f91f39c 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -2,10 +2,11 @@ class StudentWorkController < ApplicationController layout "base_courses" include StudentWorkHelper require 'bigdecimal' - before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty] + before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list] before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work] before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] + before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list] def index @order,@b_sort,@name = params[:order] || "final_score",params[:sort] || "desc",params[:name] || "" @@ -241,9 +242,8 @@ class StudentWorkController < ApplicationController end end - #评价列表显示 + #缺评列表显示 def student_work_absence_penalty - render_403 unless User.current.allowed_to?(:as_teacher,@course) order = params[:order] || "desc" if @homework.student_works.empty? @stundet_works = [] @@ -264,6 +264,34 @@ class StudentWorkController < ApplicationController end end + #导出缺评列表 + def absence_penalty_list + if @homework.student_works.empty? + @stundet_works = [] + else + work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" + @stundet_works = StudentWork.find_by_sql("SELECT * FROM (SELECT *,(all_count - has_count) AS absence FROM( + SELECT * , + (SELECT evaluation_num FROM homework_detail_manuals WHERE homework_detail_manuals.homework_common_id = #{@homework.id}) AS all_count, + (SELECT COUNT(*) FROM `student_works_scores` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS has_count + FROM `student_works` + WHERE homework_common_id = #{@homework.id} + ) AS table_1) AS table_2 + where absence > 0 order by absence") + end + respond_to do |format| + format.xls { + send_data(absence_penalty_list_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present", + :filename => "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@homework.name}#{l(:excel_homework_list)}.xls") + } + end + end + + #导出匿评列表 + def evaluation_list + + end + private #获取作业 def find_homework @@ -293,6 +321,10 @@ class StudentWorkController < ApplicationController render_403 unless (User.current.id == @work.user_id || User.current.admin?) && (@homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 1 ) end + def teacher_of_course + render_403 unless User.current.allowed_to?(:as_teacher,@course) + end + #根据条件过滤作业结果 def search_homework_member homeworks,name name = name.downcase @@ -302,6 +334,7 @@ class StudentWorkController < ApplicationController select_homework end + #作品列表转换为excel def homework_to_xls items xls_report = StringIO.new book = Spreadsheet::Workbook.new @@ -328,4 +361,27 @@ class StudentWorkController < ApplicationController book.write xls_report xls_report.string end + + #缺评列表转换为excel + def absence_penalty_list_xls items + xls_report = StringIO.new + book = Spreadsheet::Workbook.new + sheet1 = book.create_worksheet :name => "homework" + blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 + sheet1.row(0).default_format = blue + + sheet1.row(0).concat([l(:excel_student_id),l(:excel_nickname),l(:excel_user_name),l(:lable_all_penalty),l(:lable_has_penalty),l(:lable_absence_penalty)]) + count_row = 1 + items.each do |homework| + sheet1[count_row,0]=homework.user.user_extensions.student_id + sheet1[count_row,1]=homework.user.login + sheet1[count_row,2]=homework.user.lastname.to_s + homework.user.firstname.to_s + sheet1[count_row,3]=homework.all_count + sheet1[count_row,4]=homework.has_count + sheet1[count_row,5]=homework.absence + count_row += 1 + end + book.write xls_report + xls_report.string + end end \ No newline at end of file diff --git a/app/views/student_work/index.html.erb b/app/views/student_work/index.html.erb index 2d26601d1..f6eabdab1 100644 --- a/app/views/student_work/index.html.erb +++ b/app/views/student_work/index.html.erb @@ -71,6 +71,8 @@ <%= link_to l(:label_list), student_work_index_path(:homework => @homework.id,:order => @order, :sort => @b_sort, :name => @name, :format => 'xls'),:class=>'down_btn fr'%> + <%= link_to "匿评", student_work_index_path(:homework => @homework.id,:order => @order, :sort => @b_sort, :name => @name, :format => 'xls'),:class=>'down_btn fr'%> + <%= link_to "缺评", absence_penalty_list_student_work_index_path(:homework => @homework.id, :format => 'xls'),:class=>'down_btn fr'%> 导出全部: <% end%> diff --git a/app/views/student_work/student_work_absence_penalty.html.erb b/app/views/student_work/student_work_absence_penalty.html.erb index e9054561f..967480552 100644 --- a/app/views/student_work/student_work_absence_penalty.html.erb +++ b/app/views/student_work/student_work_absence_penalty.html.erb @@ -14,13 +14,13 @@ 姓名
  • - 应评 + <%= l(:lable_all_penalty)%>
  • - 实评 + <%= l(:lable_has_penalty)%>
  • - <%= link_to "缺评",student_work_absence_penalty_student_work_index_path(:homework => @homework.id,:order => @order)%> + <%= link_to l(:lable_absence_penalty),student_work_absence_penalty_student_work_index_path(:homework => @homework.id,:order => @order)%>
  • diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 568690638..9209e0d51 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2006,3 +2006,8 @@ zh: error_upload_avatar_to_large: "超过大小限制 (%{max_size})" not_valid_image_file: 不是有效的图片文件 + + lable_all_penalty: 应评 + lable_has_penalty: 实评 + lable_absence_penalty: 缺评 + diff --git a/config/routes.rb b/config/routes.rb index b5a244345..8b8d4a401 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -98,6 +98,8 @@ RedmineApp::Application.routes.draw do post 'add_score_reply' get 'destroy_score_reply' get 'student_work_absence_penalty' + get 'absence_penalty_list' + get 'evaluation_list' end end