diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e79ca2caa..c50946dda 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -218,6 +218,7 @@ class CoursesController < ApplicationController @group = CourseGroup.find(params[:search_group_id]) @results = searchgroupstudent_by_name(@group, @course, q) end + @member_scores = @@member_scores @result_count = @results.count @results = paginateHelper @results @@ -316,6 +317,7 @@ class CoursesController < ApplicationController @results = searchStudent(@course) end @@result = @results + @member_scores = @@member_scores @members = searchStudent(@course) @membercount = @members.count @results = paginateHelper @results @@ -325,6 +327,7 @@ class CoursesController < ApplicationController @render_file = 'member_list' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @is_remote = true + @member_scores = @@member_scores @members = searchStudent(@course) @membercount = @members.count @results = searchStudent_by_group(group, @course) @@ -346,8 +349,9 @@ class CoursesController < ApplicationController @members = searchTeacherAndAssistant(@course) when '2' @subPage_title = l :label_student_list - - @members = searchStudent_sort(@course, 'desc') + @@member_scores = student_homework_score + @member_scores = @@member_scores + @members = searchStudent_sort(@course, 'desc', @@member_scores) @membercount = @members.count else @@ -371,6 +375,7 @@ class CoursesController < ApplicationController @show_serch = params[:role] == '2' @subPage_title = l :label_student_list @render_file = 'member_list' + @member_scores = @@member_scores unless @@result.nil? @results = @@result.reverse @@result = @results @@ -379,6 +384,7 @@ class CoursesController < ApplicationController end # 显示每个学生的作业评分详情 def show_member_score + @member_scores = @@member_scores @member_score = Member.find(params[:member_id]) if params[:member_id] respond_to do |format| format.html {render :layout => 'course_base'} @@ -886,5 +892,22 @@ class CoursesController < ApplicationController end end + def student_homework_score + teachers = find_course_teachers(@course) + score_count = 0 + homework_scores = HomeworkAttach.find_by_sql("SELECT homework_attaches.user_id as user_id,homework_attaches.bid_id as bid_id, bids.name as name, + (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 + FROM homework_attaches, bids where + homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses where course_id = #{@course.id} + and homework_attaches.bid_id = bids.id)") + homework_scores + end + #获取课程的老师列表 + def find_course_teachers course + searchTeacherAndAssistant(course).map{|teacher| teacher.user_id}.join(",") + end end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index ec3b9aad6..80925f55b 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -175,7 +175,7 @@ module CoursesHelper end members end - def searchStudent_sort project, sort_by + def searchStudent_sort project, sort_by, member_scores #searchPeopleByRoles(project, StudentRoles) members = [] @@ -185,7 +185,7 @@ module CoursesHelper end end - members.sort!{ |mem1, mem2| mem1.student_homework_score[1].to_f <=> mem2.student_homework_score[1].to_f} + members.sort!{ |mem1, mem2| mem1.student_homework_score(member_scores)[1].to_f <=> mem2.student_homework_score(member_scores)[1].to_f} if sort_by == "desc" members.reverse! end diff --git a/app/models/member.rb b/app/models/member.rb index 32d0f5c73..ac0e590e0 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -115,19 +115,10 @@ class Member < ActiveRecord::Base end # 查找每个学生每个作业的评分 - def student_homework_score - teachers = find_course_teachers(self.course) - + def student_homework_score homework_scores score_count = 0 - homework_scores = HomeworkAttach.find_by_sql("SELECT homework_attaches.bid_id as bid_id, bids.name as name, - (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 - FROM homework_attaches, bids where homework_attaches.user_id = #{self.user_id} - and homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses where course_id = #{self.course_id} - and homework_attaches.bid_id = bids.id)") - homework_scores.each do |homework| + homework_score = homework_scores.find_all { |e| e.user_id == self.user_id} + homework_score.each do |homework| if !homework.t_score.nil? && homework.t_score != 0 score = homework.t_score else @@ -139,7 +130,7 @@ class Member < ActiveRecord::Base end score_count = score_count + score end - [homework_scores, format("%0.2f", score_count)] + [homework_score, format("%0.2f", score_count)] end protected @@ -148,10 +139,7 @@ class Member < ActiveRecord::Base end - #获取课程的老师列表 - def find_course_teachers course - searchTeacherAndAssistant(course).map{|teacher| teacher.user_id}.join(",") - end + def searchTeacherAndAssistant project #searchPeopleByRoles(project, TeacherRoles) members = [] diff --git a/app/views/courses/_member_list.html.erb b/app/views/courses/_member_list.html.erb index 2ee9e3aad..e2fe88d09 100644 --- a/app/views/courses/_member_list.html.erb +++ b/app/views/courses/_member_list.html.erb @@ -78,7 +78,7 @@ <% end %> <% if @subPage_title == l(:label_student_list) %> - <%= link_to member.student_homework_score[1].to_s, { + <%= link_to member.student_homework_score(@member_scores)[1].to_s, { :action => 'show_member_score', :member_id => member.id, :remote => true}, diff --git a/app/views/courses/_member_list_detail.html.erb b/app/views/courses/_member_list_detail.html.erb index 47407c01b..18ac99dd0 100644 --- a/app/views/courses/_member_list_detail.html.erb +++ b/app/views/courses/_member_list_detail.html.erb @@ -27,7 +27,7 @@ <% end %> <% if @subPage_title == l(:label_student_list) %> - <%= link_to member.student_homework_score[1].to_s, { + <%= link_to member.student_homework_score(@member_scores)[1].to_s, { :action => 'show_member_score', :member_id => member.id, :remote => true}, diff --git a/app/views/courses/_show_member_score.html.erb b/app/views/courses/_show_member_score.html.erb index 57dd7b2be..e20ac028b 100644 --- a/app/views/courses/_show_member_score.html.erb +++ b/app/views/courses/_show_member_score.html.erb @@ -39,7 +39,7 @@