diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 59acc188b..e971970bc 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -357,26 +357,44 @@ module CoursesHelper #获取作业的互评得分 def student_score_for_homework homework - member = searchTeacherAndAssistant(homework.bid.courses.first).first#searchPeopleByRoles(homework.bid.courses.first,TeacherRoles).first - if member.nil? - return "0.00" + #member = searchTeacherAndAssistant(homework.bid.courses.first).first#searchPeopleByRoles(homework.bid.courses.first,TeacherRoles).first + #if member.nil? + # return "0.00" + #end + #student_stars = homework.rates(:quality).where("rater_id <> #{member.user_id}").select("stars") + members = searchStudent(homework.bid.courses.first) + user_ids = [] + members.each do |user| + user_ids << user.user_id end - student_stars = homework.rates(:quality).where("rater_id <> #{member.user_id}").select("stars") + student_stars = homework.rates(:quality).where("rater_id in (:user_ids)",{:user_ids => user_ids}).select("stars") student_stars_count = 0 student_stars.each do |star| student_stars_count = student_stars_count + star.stars end return format("%.2f",student_stars_count / (student_stars.count == 0 ? 1 : student_stars.count)) + + + end #获取作业的教师评分 + #多个教师只获取一份教师评分 def teacher_score_for_homework homework - member = searchTeacherAndAssistant(homework.bid.courses.first).first#searchPeopleByRoles(homework.bid.courses.first,TeacherRoles).first - if member.nil? - return "0.00" + members = searchTeacherAndAssistant(homework.bid.courses.first)#searchPeopleByRoles(homework.bid.courses.first,TeacherRoles).first + #if member.nil? + # return "0.00" + #end + teacher_ids = [] + members.each do |user| + teacher_ids << user.user_id + end + teacher_stars = homework.rates(:quality).where("rater_id in (:teacher_ids)",{:teacher_ids => teacher_ids}).select("stars") + teacher_stars_count = 0 + teacher_stars.each do |star| + teacher_stars_count = teacher_stars_count + star.stars end - teacher_stars = homework.rates(:quality).where("rater_id = #{member.user_id}").select("stars").first - return format("%.2f",teacher_stars == nil ? 0 : teacher_stars.stars) + return format("%.2f",teacher_stars_count) end #获取指定项目的得分 diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index a8f1f4356..8b241030a 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -117,9 +117,9 @@