diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 2997f4205..e3b8b9a66 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -492,27 +492,18 @@ class BidsController < ApplicationController if @bid.homework_type @homework = HomeworkAttach.new @is_teacher = is_course_teacher(User.current,@bid.courses.first) - teachers = "(" - teacher_members = searchTeacherAndAssistant(@bid.courses.first) - teacher_members.each do |member| - if member == teacher_members.last - teachers += member.user_id.to_s + ")" - else - teachers += member.user_id.to_s + "," - end - end if @is_teacher - all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score + all_homework_list = HomeworkAttach.find_by_sql("SELECT * FROM (SELECT homework_attaches.*, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY s_score DESC,created_at ASC) AS table1 WHERE table1.t_score IS NULL") @cur_type = 1 else - all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score, - (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id}) AS m_score + all_homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id} AND is_teacher_score = #{@is_teacher ? 1 : 0}) AS m_score FROM homework_attaches INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id WHERE homework_attaches.bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id} ORDER BY s_score DESC") @@ -1056,17 +1047,8 @@ class BidsController < ApplicationController elsif @bid.comment_status == 1 @totle_size = 0 @bid.homeworks.map { |homework| @totle_size += homework.homework_evaluations.count} - teachers = "(" - teacher_members = searchTeacherAndAssistant(@course) - teacher_members.each do |member| - if member == teacher_members.last - teachers += member.user_id.to_s + ")" - else - teachers += member.user_id.to_s + "," - end - end @cur_size = 0 - @bid.homeworks.map { |homework| @cur_size += homework.rates(:quality).where("seems_rateable_rates.rater_id not in #{teachers}").count} + @bid.homeworks.map { |homework| @cur_size += homework.rates(:quality).where("seems_rateable_rates.rater_id is_teacher_score = 0").count} end @percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100) respond_to do |format| diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 5c4542944..a8e5cf352 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -22,8 +22,7 @@ class HomeworkAttachController < ApplicationController #获取未批作业列表 def get_not_batch_homework sort, direction = params[:sort] || "s_socre", params[:direction] || "desc" - teachers = find_course_teachers @course - get_not_batch_homework_list sort,direction,teachers, @bid.id + get_not_batch_homework_list sort,direction, @bid.id @cur_page = params[:page] || 1 @cur_type = 1 @direction = direction == 'asc'? 'desc' : 'asc' @@ -42,10 +41,9 @@ class HomeworkAttachController < ApplicationController elsif sort == 'time' order_by = "created_at #{direction}" end - teachers = find_course_teachers @course all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers}) and stars IS NOT NULL) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 and stars IS NOT NULL) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY #{order_by}) AS table1 WHERE table1.t_score IS NOT NULL") @@ -55,7 +53,29 @@ class HomeworkAttachController < ApplicationController @direction = direction == 'asc'? 'desc' : 'asc' respond_to do |format| format.js + format.csv { + send_data(homework_to_csv(all_homework_list), :type => 'text/csv; header=present', :filename => 'issues.csv') + } + end + end + + def homework_to_csv items + encoding = l(:general_csv_encoding) + columns = ["student_id","user_name","login","student_num","mail","work_name","teacher_score","ni_score","commit_time"] + + + export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| + # csv header fields + csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c, encoding) } + # csv lines + items.each do |homework| + csv << [homework.user.id,Redmine::CodesetUtil.from_utf8(homework.user.lastname.to_s + homework.user.firstname.to_s, encoding),Redmine::CodesetUtil.from_utf8(homework.user.login, encoding), + Redmine::CodesetUtil.from_utf8(homework.user.user_extensions.student_id, encoding),Redmine::CodesetUtil.from_utf8(homework.user.mail, encoding),Redmine::CodesetUtil.from_utf8(homework.name, encoding), + Redmine::CodesetUtil.from_utf8((homework.t_score.nil? || (homework.t_score && homework.t_score.to_i == 0)) ? l(:label_without_score) : format("%.2f",homework.t_score), encoding), + Redmine::CodesetUtil.from_utf8( homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score), encoding),Redmine::CodesetUtil.from_utf8(format_time(homework.created_at), encoding)] + end end + export end #获取所有作业列表 @@ -68,10 +88,9 @@ class HomeworkAttachController < ApplicationController elsif sort == 'time' order_by = "created_at #{direction}" end - teachers = find_course_teachers @course all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in (#{teachers})) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in (#{teachers})) AS s_score + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY #{order_by}") @cur_page = params[:page] || 1 @@ -86,11 +105,10 @@ class HomeworkAttachController < ApplicationController #获取学生匿评列表 def get_student_batch_homework @is_student_batch_homework = true - teachers = find_course_teachers @course all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers})) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score, - (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id}) AS m_score + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id} AND is_teacher_score = 0) AS m_score FROM homework_attaches INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id WHERE homework_attaches.bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id} ORDER BY m_score DESC") @@ -105,17 +123,16 @@ class HomeworkAttachController < ApplicationController #获取我的作业 def get_my_homework @is_my_homework = true - teachers = find_course_teachers @course all_homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers})) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE homework_attaches.bid_id = #{@bid.id} AND homework_attaches.user_id = #{User.current.id}") #如果我没有创建过作业,就检索我是否参与了某个作业 if all_homework_list.empty? all_homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers})) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches INNER JOIN homework_users ON homework_users.homework_attach_id = homework_attaches.id WHERE homework_attaches.bid_id = #{@bid.id} AND homework_users.user_id = #{User.current.id}") @@ -358,12 +375,11 @@ class HomeworkAttachController < ApplicationController # 作业打分列表 @stars_reates = @homework.rates(:quality) #我的评分 - @has_evaluation = @stars_reates.where("rater_id = #{User.current.id}").first - @m_score = @has_evaluation.nil? ? 0 : @has_evaluation.stars - teachers = find_course_teachers(@course) - @teacher_stars = @stars_reates.where("rater_id in (#{teachers})") #老师评分列表 - @student_stars = @stars_reates.where("rater_id not in (#{teachers})") #学生评分列表 @is_teacher = is_course_teacher User.current,@course + @has_evaluation = @stars_reates.where("rater_id = #{User.current.id} and is_teacher_score=#{@is_teacher ? 1 : 0}").first + @m_score = @has_evaluation.nil? ? 0 : @has_evaluation.stars + @teacher_stars = @stars_reates.where("is_teacher_score = 1") #老师评分列表 + @student_stars = @stars_reates.where("is_teacher_score = 0") #学生评分列表 @is_anonymous_comments = @bid.comment_status == 1 && !@homework.users.include?(User.current) && @homework.user != User.current && !@is_teacher #判断是不是匿评(开启匿评,当前用户不是作业的创建者或者参与者,不是老师) jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")#jours留言 is null条件用以兼容历史数据 @jour = paginateHelper jours,5 #留言 @@ -385,10 +401,9 @@ class HomeworkAttachController < ApplicationController @journal_destroyed = JournalsForMessage.find(params[:object_id]) if @journal_destroyed.is_comprehensive_evaluation == 3 && @journal_destroyed.destroy render_403 unless User.current == @journal_destroyed.user || User.current.admin? - teachers = find_course_teachers(@homework.bid.courses.first) @stars_reates = @homework.rates(:quality) - @teacher_stars = @stars_reates.where("rater_id in (#{teachers})") #老师评分列表 - @student_stars = @stars_reates.where("rater_id not in (#{teachers})") #学生评分列表 + @teacher_stars = @stars_reates.where("is_teacher_score = 1)") #老师评分列表 + @student_stars = @stars_reates.where("is_teacher_score = 0") #学生评分列表 jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")#jours留言 is null条件用以兼容历史数据 @jour = paginateHelper jours,5 #留言 else @@ -425,41 +440,48 @@ class HomeworkAttachController < ApplicationController @is_teacher,@is_anonymous_comments,@m_score = params[:is_teacher]=="true",params[:is_anonymous_comments]=="true",params[:stars_value] @cur_page,@cur_type = params[:cur_page] || 1,params[:cur_type] || 5 @homework = HomeworkAttach.find(params[:homework_id]) - - #保存评分 - @homework.rate(@m_score.to_i,User.current.id,:quality) if @m_score + is_teacher = @is_teacher ? 1 : 0 + #保存评分@homework.rate(@m_score.to_i,User.current.id,:quality, (@is_teacher ? 1 : 0)) + if @m_score + rate = @homework.rates(:quality).where(:rater_id => User.current.id, :is_teacher_score => is_teacher).first + if rate + rate.stars = @m_score + rate.save! + else + @homework.rates(:quality).new(:stars => @m_score, :rater_id => User.current.id, :is_teacher_score => is_teacher).save! + end + end #保存评论 @is_comprehensive_evaluation = @is_teacher ? 1 : (@is_anonymous_comments ? 2 : 3) #判断当前评论是老师评论?匿评?留言 if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" #有没有留言 @homework.addjours User.current.id, params[:new_form][:user_message],0,@is_comprehensive_evaluation end - teachers = find_course_teachers(@homework.bid.courses.first) @stars_reates = @homework.rates(:quality) - @teacher_stars = @stars_reates.where("rater_id in (#{teachers})") #老师评分列表 - @student_stars = @stars_reates.where("rater_id not in (#{teachers})") #学生评分列表 + @teacher_stars = @stars_reates.where("is_teacher_score = 1") #老师评分列表 + @student_stars = @stars_reates.where("is_teacher_score = 0") #学生评分列表 jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")#jours留言 is null条件用以兼容历史数据 @jour = paginateHelper jours,5 #留言 if @cur_type == "1" #如果当前是老师未批列表,需要刷新整个作业列表界面 @bid = @homework.bid - get_not_batch_homework_list "s_socre","desc",teachers,@homework.bid_id + get_not_batch_homework_list "s_socre","desc",@homework.bid_id elsif @cur_type == "2" #老师已批列表 - @result_homework = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers}) and stars IS NOT NULL) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score + @result_homework = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 and stars IS NOT NULL) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE id = #{@homework.id}").first elsif @cur_type == "3" #全部作业列表 - @result_homework = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in (#{teachers})) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in (#{teachers})) AS s_score + @result_homework = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE id = #{@homework.id}").first elsif @cur_type == "4" #匿评作业列表 @is_student_batch_homework = true - @result_homework = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers})) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score, - (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id}) AS m_score + @result_homework = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score, + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id} AND is_teacher_score = #{is_teacher}) AS m_score FROM homework_attaches WHERE homework_attaches.id = #{@homework.id}").first else #其他的不用管 @@ -552,7 +574,7 @@ class HomeworkAttachController < ApplicationController teacher_proportion end - def get_not_batch_homework_list sort,direction,teachers,bid_id + def get_not_batch_homework_list sort,direction,bid_id if sort == 't_socre' order_by = "t_score #{direction}" elsif sort == 's_socre' @@ -561,8 +583,8 @@ class HomeworkAttachController < ApplicationController order_by = "created_at #{direction}" end all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers})) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{bid_id} ORDER BY #{order_by}) AS table1 WHERE table1.t_score IS NULL") diff --git a/app/models/seems_rateable_rates.rb b/app/models/seems_rateable_rates.rb new file mode 100644 index 000000000..664f987ba --- /dev/null +++ b/app/models/seems_rateable_rates.rb @@ -0,0 +1,3 @@ +class SeemsRateableRates < ActiveRecord::Base + attr_accessible :rater_id, :rateable_id, :rateable_type, :stars, :dimension, :is_teacher_score +end diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index ea1f9b770..202a2ee91 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -62,11 +62,6 @@ :is_student_batch_homework => @is_student_batch_homework}%> - <% if @is_teacher %> - - <% end %>