2015-05-19 17:12:43 +08:00
|
|
|
class StudentWorkController < ApplicationController
|
|
|
|
layout "base_courses"
|
2015-05-26 18:14:53 +08:00
|
|
|
include StudentWorkHelper
|
2015-05-29 11:26:39 +08:00
|
|
|
require 'bigdecimal'
|
2015-05-20 17:53:01 +08:00
|
|
|
before_filter :find_homework, :only => [:new, :index, :create]
|
2015-05-28 16:10:40 +08:00
|
|
|
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]
|
2015-05-20 17:53:01 +08:00
|
|
|
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
2015-05-19 17:12:43 +08:00
|
|
|
|
|
|
|
def index
|
2015-05-28 11:07:28 +08:00
|
|
|
@order,@b_sort,@name = params[:order] || "final_score",params[:sort] || "desc",params[:name] || ""
|
2015-05-28 15:54:42 +08:00
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
|
|
|
#老师 || 非匿评作业 || 匿评结束 显示所有的作品
|
|
|
|
if @is_teacher || @homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 3
|
|
|
|
@stundet_works = search_homework_member @homework.student_works.order("#{@order} #{@b_sort}"),@name
|
|
|
|
else #学生
|
|
|
|
if @homework.homework_detail_manual.comment_status == 1 #未开启匿评,只显示我的作品
|
|
|
|
@stundet_works = @homework.student_works.where(:user_id => User.current.id)
|
|
|
|
elsif @homework.homework_detail_manual.comment_status == 2 #开启匿评,显示匿评作品和我的作品
|
|
|
|
my_work = @homework.student_works.where(:user_id => User.current.id)
|
|
|
|
@stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id}
|
|
|
|
end
|
|
|
|
end
|
2015-05-28 09:03:01 +08:00
|
|
|
@homework_commons = @course.homework_commons.order("created_at desc")
|
2015-05-28 11:07:28 +08:00
|
|
|
@score = @b_sort == "desc" ? "asc" : "desc"
|
2015-05-19 17:12:43 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
2015-05-28 11:07:28 +08:00
|
|
|
format.xls {
|
|
|
|
send_data(homework_to_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present",
|
2015-05-28 12:02:26 +08:00
|
|
|
:filename => "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@homework.name}#{l(:excel_homework_list)}.xls")
|
2015-05-28 11:07:28 +08:00
|
|
|
}
|
2015-05-19 17:12:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2015-05-21 17:28:38 +08:00
|
|
|
student_work = @homework.student_works.where("user_id = ?",User.current.id).first
|
|
|
|
if student_work.nil?
|
|
|
|
@stundet_work = StudentWork.new
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
end
|
|
|
|
else
|
|
|
|
render_403
|
2015-05-19 17:12:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-05-21 15:52:27 +08:00
|
|
|
if params[:student_work]
|
|
|
|
stundet_work = StudentWork.new
|
|
|
|
stundet_work.name = params[:student_work][:name]
|
|
|
|
stundet_work.description = params[:student_work][:description]
|
|
|
|
stundet_work.project_id = params[:student_work][:project_id]
|
|
|
|
stundet_work.homework_common_id = @homework.id
|
|
|
|
stundet_work.user_id = User.current.id
|
|
|
|
stundet_work.save_attachments(params[:attachments])
|
|
|
|
render_attachment_warning_if_needed(stundet_work)
|
|
|
|
if stundet_work.save
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
flash[:notice] = l(:notice_successful_create)
|
|
|
|
redirect_to student_work_index_url(:homework => @homework.id)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
flash[:notice] = l(:notice_failed_create)
|
|
|
|
redirect_to new_student_work_url(:homework => @homework.id)
|
|
|
|
}
|
|
|
|
end
|
2015-05-19 17:12:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2015-05-28 17:09:38 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
end
|
2015-05-19 17:12:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-05-28 17:09:38 +08:00
|
|
|
if params[:student_work]
|
|
|
|
@work.name = params[:student_work][:name]
|
|
|
|
@work.description = params[:student_work][:description]
|
|
|
|
@work.project_id = params[:student_work][:project]
|
|
|
|
@work.save_attachments(params[:attachments])
|
|
|
|
render_attachment_warning_if_needed(@work)
|
|
|
|
if @work.save
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
flash[:notice] = l(:notice_successful_edit)
|
|
|
|
redirect_to student_work_index_url(:homework => @homework.id)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
respond_to do |format|
|
|
|
|
format.html{redirect_to edit_student_work_url(@work)}
|
|
|
|
end
|
2015-05-19 17:12:43 +08:00
|
|
|
end
|
|
|
|
|
2015-05-20 17:53:01 +08:00
|
|
|
def show
|
2015-05-27 08:55:33 +08:00
|
|
|
@score = student_work_score @work,User.current
|
2015-05-28 15:54:42 +08:00
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
2015-05-21 17:17:54 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
2015-05-20 17:53:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2015-05-28 17:18:37 +08:00
|
|
|
if @work.destroy
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
redirect_to student_work_index_url(:homework => @homework.id)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2015-05-20 17:53:01 +08:00
|
|
|
end
|
|
|
|
|
2015-05-27 11:25:32 +08:00
|
|
|
#添加评分,已评分则为修改评分
|
2015-05-22 14:45:01 +08:00
|
|
|
def add_score
|
2015-05-27 16:01:00 +08:00
|
|
|
@score = student_work_score @work,User.current
|
2015-05-29 10:33:29 +08:00
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
2015-05-27 16:01:00 +08:00
|
|
|
if @score
|
|
|
|
@score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != ""
|
|
|
|
@score.score = params[:score] if params[:score]
|
|
|
|
@is_new = false
|
2015-05-26 18:14:53 +08:00
|
|
|
else
|
2015-05-27 16:01:00 +08:00
|
|
|
@score = StudentWorksScore.new
|
|
|
|
@score.score = params[:score] if params[:score]
|
|
|
|
@score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != ""
|
|
|
|
@score.user_id = User.current.id
|
|
|
|
@score.student_work_id = @work.id
|
2015-05-27 16:21:59 +08:00
|
|
|
role = User.current.members.where("course_id = ?",@course.id).first.roles.first.name
|
|
|
|
@score.reviewer_role = get_role_by_name(role)
|
2015-05-27 16:01:00 +08:00
|
|
|
@is_new = true
|
2015-05-26 18:14:53 +08:00
|
|
|
end
|
2015-05-26 17:51:56 +08:00
|
|
|
|
2015-05-27 16:01:00 +08:00
|
|
|
@score.save_attachments(params[:attachments])
|
|
|
|
render_attachment_warning_if_needed(@score)
|
2015-05-26 18:14:53 +08:00
|
|
|
|
2015-05-27 16:01:00 +08:00
|
|
|
if @score.save
|
2015-05-27 17:32:14 +08:00
|
|
|
case @score.reviewer_role
|
|
|
|
when 1 #教师评分:最后一个教师评分为最终评分
|
|
|
|
@work.teacher_score = @score.score
|
|
|
|
@work.final_score = @score.score
|
|
|
|
when 2 #教辅评分 教辅评分显示平均分
|
|
|
|
@work.teaching_asistant_score = @work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f
|
|
|
|
if @work.teacher_score.nil?
|
|
|
|
if @work.student_score.nil?
|
|
|
|
@work.final_score = @work.teaching_asistant_score
|
|
|
|
else
|
2015-05-29 11:26:39 +08:00
|
|
|
final_ta_score = BigDecimal.new("#{@work.teaching_asistant_score}") * BigDecimal.new("#{@homework.homework_detail_manual.ta_proportion}")
|
|
|
|
final_s_score = BigDecimal.new("#{@work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{@homework.homework_detail_manual.ta_proportion}"))
|
|
|
|
final_score = final_ta_score + final_s_score
|
|
|
|
@work.final_score = format("%.2f",final_score.to_f)
|
2015-05-27 17:32:14 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
when 3 #学生评分 学生评分显示平均分
|
|
|
|
@work.student_score = @work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f
|
|
|
|
if @work.teacher_score.nil?
|
|
|
|
if @work.teaching_asistant_score.nil?
|
|
|
|
@work.final_score = @work.student_score
|
|
|
|
else
|
2015-05-29 11:26:39 +08:00
|
|
|
final_ta_score = BigDecimal.new("#{@work.teaching_asistant_score}") * BigDecimal.new("#{@homework.homework_detail_manual.ta_proportion}")
|
|
|
|
final_s_score = BigDecimal.new("#{@work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{@homework.homework_detail_manual.ta_proportion}"))
|
|
|
|
final_score = final_ta_score + final_s_score
|
|
|
|
@work.final_score = format("%.2f",final_score.to_f)
|
2015-05-27 17:32:14 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if @work.save
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
2015-05-26 18:14:53 +08:00
|
|
|
end
|
2015-05-23 11:24:24 +08:00
|
|
|
end
|
|
|
|
end
|
2015-05-22 14:45:01 +08:00
|
|
|
|
2015-05-27 11:25:32 +08:00
|
|
|
#添加评分的回复
|
2015-05-23 11:24:24 +08:00
|
|
|
def add_score_reply
|
2015-05-27 15:11:11 +08:00
|
|
|
@score = StudentWorksScore.find params[:score_id]
|
2015-05-27 14:58:55 +08:00
|
|
|
@jour = @score.journals_for_messages.new(:user_id => User.current.id,:notes =>params[:message], :reply_id => 0)
|
|
|
|
if @jour.save
|
2015-05-29 11:00:35 +08:00
|
|
|
@status = 1
|
|
|
|
else
|
|
|
|
@status = 2
|
|
|
|
end
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
2015-05-23 11:24:24 +08:00
|
|
|
end
|
2015-05-22 14:45:01 +08:00
|
|
|
end
|
|
|
|
|
2015-05-27 11:25:32 +08:00
|
|
|
#删除评分的回复
|
|
|
|
def destroy_score_reply
|
2015-05-27 15:11:11 +08:00
|
|
|
@jour = JournalsForMessage.find params[:jour_id]
|
|
|
|
if @jour.destroy
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
2015-05-27 11:25:32 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-28 16:10:40 +08:00
|
|
|
#为作品点赞
|
|
|
|
def praise_student_work
|
|
|
|
pt = PraiseTread.new
|
|
|
|
pt.user_id = User.current.id
|
|
|
|
pt.praise_tread_object_id = @work.id
|
|
|
|
pt.praise_tread_object_type = "StudentWork"
|
|
|
|
pt.praise_or_tread = 1
|
|
|
|
if pt.save
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-19 17:12:43 +08:00
|
|
|
private
|
|
|
|
#获取作业
|
|
|
|
def find_homework
|
|
|
|
@homework = HomeworkCommon.find params[:homework]
|
|
|
|
@course = @homework.course
|
|
|
|
rescue
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
#获取作品
|
|
|
|
def find_work
|
|
|
|
@work = StudentWork.find params[:id]
|
2015-05-21 17:33:54 +08:00
|
|
|
@homework = @work.homework_common
|
|
|
|
@course = @homework.course
|
2015-05-19 17:12:43 +08:00
|
|
|
rescue
|
|
|
|
render_404
|
|
|
|
end
|
2015-05-20 17:53:01 +08:00
|
|
|
|
|
|
|
#是不是当前课程的成员
|
|
|
|
#当前课程成员才可以看到作品列表
|
|
|
|
def member_of_course
|
|
|
|
render_403 unless User.current.member_of_course? @course
|
|
|
|
end
|
|
|
|
|
|
|
|
#判断是不是当前作品的提交者
|
2015-05-28 17:18:37 +08:00
|
|
|
#提交者 && (非匿评作业 || 未开启匿评) 可以编辑作品
|
2015-05-20 17:53:01 +08:00
|
|
|
def author_of_work
|
2015-05-28 17:18:37 +08:00
|
|
|
render_403 unless User.current.id == @work.user_id && (@homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 1 )
|
2015-05-20 17:53:01 +08:00
|
|
|
end
|
2015-05-28 09:46:35 +08:00
|
|
|
|
|
|
|
#根据条件过滤作业结果
|
|
|
|
def search_homework_member homeworks,name
|
|
|
|
select_homework = homeworks.select{ |homework|
|
|
|
|
homework.user[:login].to_s.downcase.include?(name) || homework.user.user_extensions[:student_id].to_s.downcase.include?(name) || (homework.user[:lastname].to_s.downcase + homework.user[:firstname].to_s.downcase).include?(name)
|
|
|
|
}
|
|
|
|
select_homework
|
|
|
|
end
|
2015-05-28 11:07:28 +08:00
|
|
|
|
|
|
|
def homework_to_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_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),
|
|
|
|
l(:excel_t_score),l(:excel_ta_score),l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)])
|
|
|
|
count_row = 1
|
|
|
|
items.each do |homework|
|
|
|
|
sheet1[count_row,0]=homework.user.id
|
|
|
|
sheet1[count_row,1] = homework.user.lastname.to_s + homework.user.firstname.to_s
|
|
|
|
sheet1[count_row,2] = homework.user.login
|
|
|
|
sheet1[count_row,3] = homework.user.user_extensions.student_id
|
|
|
|
sheet1[count_row,4] = homework.user.mail
|
|
|
|
sheet1[count_row,5] = homework.name
|
|
|
|
sheet1[count_row,6] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score)
|
|
|
|
sheet1[count_row,7] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_score)
|
|
|
|
sheet1[count_row,8] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score)
|
|
|
|
sheet1[count_row,9] = homework.final_score.nil? ? l(:label_without_score) : format("%.2f",homework.final_score)
|
|
|
|
sheet1[count_row,10] = format_time(homework.created_at)
|
|
|
|
count_row += 1
|
|
|
|
end
|
|
|
|
book.write xls_report
|
|
|
|
xls_report.string
|
|
|
|
end
|
2015-05-19 17:12:43 +08:00
|
|
|
end
|