From 0e7f7a42543e5cdbe313ab1fe6bbaa5a5a3f9376 Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Wed, 24 Dec 2014 18:31:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E3=80=8A=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E8=AF=84=E5=88=86=E3=80=8B=20Signed-off-by:=20alan=20<54753343?= =?UTF-8?q?4@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 83 +++++++++---------- app/helpers/courses_helper.rb | 41 +++++---- app/models/member.rb | 11 ++- app/views/courses/_member_list.html.erb | 2 +- .../courses/_member_list_detail.html.erb | 2 +- app/views/courses/_show_member_score.html.erb | 4 +- 6 files changed, 80 insertions(+), 63 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 13a79e0a0..ae6ad4ce3 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -213,12 +213,12 @@ class CoursesController < ApplicationController q = "#{params[:name].strip}" #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? if params[:incourse] - @results = searchStudent_by_name(@course, q) + @results = searchmember_by_name(@@member_scores, q) elsif params[:ingroup] @group = CourseGroup.find(params[:search_group_id]) - @results = searchgroupstudent_by_name(@group, @course, q) + @results = @results =searchgroupmember_by_name(@@member_scores, @group, q) end - @member_scores = @@member_scores + @result_count = @results.count @results = paginateHelper @results @@ -234,8 +234,7 @@ class CoursesController < ApplicationController end @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @is_remote = true - @members = searchStudent(@course) - @membercount = @members.count + @course_groups = @course.course_groups end @@ -244,8 +243,7 @@ class CoursesController < ApplicationController @subPage_title = l :label_student_list @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @is_remote = true - @members = searchStudent(@course) - @membercount = @members.count + @course_groups = @course.course_groups end @@ -258,8 +256,7 @@ class CoursesController < ApplicationController end @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @is_remote = true - @members = searchStudent(@course) - @membercount = @members.count + @course_groups = @course.course_groups end @@ -312,28 +309,18 @@ class CoursesController < ApplicationController @is_remote = true if params[:group_id] && params[:group_id] != "0" @group = CourseGroup.find(params[:group_id]) - @results = searchStudent_by_group(@group, @course) + @results = @@member_scores.find_all {|mem| mem.course_group_id == group.id} else - @results = searchStudent(@course) + @results = @@member_scores end @@result = @results - @member_scores = @@member_scores + @members = searchStudent(@course) @membercount = @members.count @results = paginateHelper @results end - def search_group_members group - @subPage_title = l :label_student_list - @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) - @@result = @results - @results = paginateHelper @results - end + + def member ## 有角色参数的才是课程,没有的就是项目 if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) @@ -350,8 +337,9 @@ class CoursesController < ApplicationController when '2' @subPage_title = l :label_student_list @@member_scores = student_homework_score - @member_scores = @@member_scores - @members = searchStudent_sort(@course, 'desc', @@member_scores) + @members = @@member_scores + # @member_scores = @@member_scores + # @members = searchStudent_sort(@course, 'desc', @@member_scores) @membercount = @members.count else @@ -375,7 +363,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 @@ -384,7 +372,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'} @@ -895,23 +883,34 @@ class CoursesController < ApplicationController def student_homework_score teachers = find_course_teachers(@course) - score_count = 0 - - homeworks = HomeworkAttach.find_by_sql("SELECT homework_attaches.id - 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)") - homeworks = homeworks.map {|homework| homework.id}.join(",") - homework_scores = HomeworkAttach.find_by_sql("SELECT homework_attaches.user_id, AVG(s1.stars) AS t_score, - AVG(s2.stars) AS s_score - FROM homework_attaches, seems_rateable_rates s1,seems_rateable_rates s2 WHERE - homework_attaches.id in (#{homeworks}) and s1.rateable_type = 'HomeworkAttach' and s1.rateable_id = homework_attaches.id - AND s1.rater_id IN (#{teachers}) and s2.rateable_type = 'HomeworkAttach' - and s2.rateable_id = homework_attaches.id - AND s2.rater_id not IN (#{teachers})") + homework_scores = Member.find_by_sql("SELECT id, user_id,course_id, course_group_id,created_on,IFNULL(SUM(CASE WHEN t_score <> 0 AND t_score IS NOT NULL THEN t_score ELSE s_score END),0) as score + FROM ( + SELECT members.id as id, members.user_id AS user_id, members.course_id AS course_id, members.created_on as created_on,members.course_group_id AS course_group_id, + (SELECT AVG(seems_rateable_rates.stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (3040,4762,4765)) AS t_score, + (SELECT AVG(seems_rateable_rates.stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (3040,4762,4765)) AS s_score + FROM `homework_attaches` , members + WHERE members.course_id = #{@course.id} + AND members.user_id NOT IN (#{teachers}) AND homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) + AND homework_attaches.user_id = members.user_id + ) AS table1 GROUP BY user_id ORDER BY score DESC") + homework_scores end #获取课程的老师列表 def find_course_teachers course searchTeacherAndAssistant(course).map{|teacher| teacher.user_id}.join(",") end + + #当加入,退出分班时查询分班的学生 + def search_group_members group + @subPage_title = l :label_student_list + @render_file = 'member_list' + @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' + @is_remote = true + + @members = searchStudent(@course) + @membercount = @members.count + @results = @@member_scores.find_all {|mem| mem.course_group_id == group.id} + @@result = @results + @results = paginateHelper @results + end end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 80925f55b..a5ae7d760 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -175,22 +175,7 @@ module CoursesHelper end members end - def searchStudent_sort project, sort_by, member_scores - #searchPeopleByRoles(project, StudentRoles) - members = [] - project.members.each do |m| - if m && m.user && m.user.allowed_to?(:as_student,project) - members << m - - end - end - 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 - members - end def searchStudent_by_name project, name @@ -206,6 +191,32 @@ module CoursesHelper end members end + def searchmember_by_name members, name + #searchPeopleByRoles(project, StudentRoles) + mems = [] + members.each do |m| + + username = m.user[:lastname].to_s + m.user[:firstname].to_s + if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name)) + mems << m + end + + end + mems + end + def searchgroupmember_by_name members, name, group + #searchPeopleByRoles(project, StudentRoles) + mems = [] + members.each do |m| + if m.course_group_id == group.id + username = m.user[:lastname].to_s + m.user[:firstname].to_s + if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name)) + mems << m + end + end + end + mems + end def searchgroupstudent_by_name(group, project, name) members = [] group.members.each do |m| diff --git a/app/models/member.rb b/app/models/member.rb index ac0e590e0..446bb02e7 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -115,9 +115,16 @@ class Member < ActiveRecord::Base end # 查找每个学生每个作业的评分 - def student_homework_score homework_scores + def student_homework_score score_count = 0 - homework_score = homework_scores.find_all { |e| e.user_id == self.user_id} + homework_score = HomeworkAttach.find_by_sql("SELECT bids.`name`, 0 as score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' + AND rateable_id = homework_attaches.id ) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' + AND rateable_id = homework_attaches.id ) 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_score.each do |homework| if !homework.t_score.nil? && homework.t_score != 0 score = homework.t_score diff --git a/app/views/courses/_member_list.html.erb b/app/views/courses/_member_list.html.erb index 3e8f5a359..25be8709f 100644 --- a/app/views/courses/_member_list.html.erb +++ b/app/views/courses/_member_list.html.erb @@ -68,7 +68,7 @@ <% end %> <% if @subPage_title == l(:label_student_list) %> - <%= link_to member.student_homework_score(@member_scores)[1].to_s, { + <%= link_to format("%0.2f",member.score.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 18ac99dd0..f37067cb5 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(@member_scores)[1].to_s, { + <%= link_to format("%0.2f",member.score.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 e20ac028b..57dd7b2be 100644 --- a/app/views/courses/_show_member_score.html.erb +++ b/app/views/courses/_show_member_score.html.erb @@ -39,7 +39,7 @@