diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 54346c0cc..35e034603 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -759,6 +759,7 @@ class ApplicationController < ActionController::Base end end + #查找首页相关信息 def find_first_page @first_page = FirstPage.find_by_page_type('project') diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e0d7feff5..ffdd51762 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -213,10 +213,10 @@ 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 = searchmember_by_name(@@member_scores, q) + @results = searchmember_by_name(student_homework_score, q) elsif params[:ingroup] @group = CourseGroup.find(params[:search_group_id]) - @results = @results =searchgroupmember_by_name(@@member_scores, @group, q) + @results =searchgroupmember_by_name(student_homework_score, @group, q) end @result_count = @results.count @@ -285,7 +285,7 @@ class CoursesController < ApplicationController member.course_group_id = group.id member.save @group = group - @members = searchStudent(@course) + @course_groups = @course.course_groups @membercount = @members.count search_group_members group @@ -298,7 +298,7 @@ class CoursesController < ApplicationController member.save @group = group @course_groups = @course.course_groups - @members = searchStudent(@course) + @membercount = @members.count search_group_members group end @@ -309,9 +309,9 @@ class CoursesController < ApplicationController @is_remote = true if params[:group_id] && params[:group_id] != "0" @group = CourseGroup.find(params[:group_id]) - @results = @@member_scores.find_all {|mem| mem.course_group_id == group.id} + @results = student_homework_score.find_all {|mem| mem.course_group_id == group.id} else - @results = @@member_scores + @results = student_homework_score end @@result = @results @@ -336,9 +336,8 @@ class CoursesController < ApplicationController @members = @teachers when '2' @subPage_title = l :label_student_list - teachers = @teachers.map{|teacher| teacher.user_id}.join(",") - @@member_scores = student_homework_score teachers - @members = @@member_scores + @members = student_homework_score + # @member_scores = @@member_scores # @members = searchStudent_sort(@course, 'desc', @@member_scores) @membercount = @members.count @@ -881,17 +880,12 @@ class CoursesController < ApplicationController end end - def student_homework_score 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") + def student_homework_score + #teachers = find_course_teachers(@course) + sql = ActiveRecord::Base.connection() + + homework_scores = Member.find_by_sql("call member_score(#{@course.id})") + sql.close() homework_scores end #获取课程的老师列表 @@ -908,7 +902,7 @@ class CoursesController < ApplicationController @members = searchStudent(@course) @membercount = @members.count - @results = @@member_scores.find_all {|mem| mem.course_group_id == group.id} + @results = student_homework_score.find_all {|mem| mem.course_group_id == group.id} @@result = @results @results = paginateHelper @results end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index d87992ec8..56f760e13 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -395,16 +395,18 @@ class FilesController < ApplicationController render :layout => 'base_courses' } end + else + show_attachments @containers + @attachtype = params[:type].to_i + @contenttype = params[:contentType].to_s + + respond_to do |format| + format.js + format.html + end end - show_attachments @containers - @attachtype = params[:type].to_i - @contenttype = params[:contentType].to_s - respond_to do |format| - format.js - format.html - end end end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index a5ae7d760..096ce7ad8 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -194,19 +194,23 @@ module CoursesHelper def searchmember_by_name members, name #searchPeopleByRoles(project, StudentRoles) mems = [] - members.each do |m| + if name != "" + 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 + else + mems = members end mems end def searchgroupmember_by_name members, name, group #searchPeopleByRoles(project, StudentRoles) mems = [] + if name != "" members.each do |m| if m.course_group_id == group.id username = m.user[:lastname].to_s + m.user[:firstname].to_s @@ -215,6 +219,9 @@ module CoursesHelper end end end + else + mems = members + end mems end def searchgroupstudent_by_name(group, project, name) diff --git a/app/views/courses/_member_list.html.erb b/app/views/courses/_member_list.html.erb index 9b3a0443d..860c86ba4 100644 --- a/app/views/courses/_member_list.html.erb +++ b/app/views/courses/_member_list.html.erb @@ -53,7 +53,7 @@ <% members.each do |member| %>
- <% next if member.new_record? %> + <%= member.user.nil? ? '' : (image_tag(url_to_avatar(member.user), :width => 40, :height => 40)) %> @@ -101,7 +101,7 @@
<% else %>

diff --git a/data/member_score.sql b/data/member_score.sql new file mode 100644 index 000000000..13858ccce --- /dev/null +++ b/data/member_score.sql @@ -0,0 +1,97 @@ + +DELIMITER $$ + +CREATE + /*[DEFINER = { user | CURRENT_USER }]*/ + PROCEDURE `member_score`(IN courseid INT) + /*LANGUAGE SQL + | [NOT] DETERMINISTIC + | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA } + | SQL SECURITY { DEFINER | INVOKER } + | COMMENT 'string'*/ + BEGIN + + CREATE TEMPORARY TABLE IF NOT EXISTS course_teachers ( + id INT + + ); + TRUNCATE TABLE course_teachers; + + CREATE TEMPORARY TABLE IF NOT EXISTS mems ( + id INT , + user_id INT, + course_id INT, + created_on DATETIME, + course_group_id INT, + score FLOAT DEFAULT 0 + ); + TRUNCATE TABLE mems; + + CREATE TEMPORARY TABLE IF NOT EXISTS mem_home ( + id INT, + user_id INT, + course_id INT, + created_on DATETIME, + course_group_id INT, + home_id INT, + score FLOAT DEFAULT 0 + ); + TRUNCATE TABLE mem_home; + + CREATE TEMPORARY TABLE IF NOT EXISTS t_scores ( + + home_id INT, + score FLOAT + ); + TRUNCATE TABLE t_scores; + + CREATE TEMPORARY TABLE IF NOT EXISTS s_scores ( + + home_id INT, + score FLOAT + ); + TRUNCATE TABLE s_scores; + + CREATE TEMPORARY TABLE IF NOT EXISTS scores ( + + user_id INT, + score FLOAT + ); + TRUNCATE TABLE scores; + + INSERT INTO course_teachers (SELECT members.user_id FROM members WHERE members.user_id NOT IN (SELECT student_id FROM students_for_courses WHERE course_id = courseid)); + + #查出所有的学生 + + INSERT INTO mems (id, user_id, course_id, created_on, course_group_id) + (SELECT members.id, members.user_id, members.course_id, members.created_on, members.course_group_id + FROM members WHERE course_id = courseid AND members.user_id NOT IN (SELECT id FROM course_teachers)); + + # 查出所有的学生列表及其作业 + INSERT INTO mem_home (id, user_id, course_id, created_on, course_group_id,home_id) + (SELECT members.id, members.user_id, members.course_id, members.created_on, members.course_group_id, homework_attaches.id + FROM members, homework_attaches WHERE course_id = courseid + AND members.user_id = homework_attaches.user_id AND members.user_id NOT IN (SELECT id FROM course_teachers) + AND homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses WHERE course_id = courseid )); + + INSERT INTO t_scores (home_id, score) (SELECT rateable_id,AVG(seems_rateable_rates.stars) + FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id IN (SELECT mem_home.home_id FROM mem_home) + AND rater_id IN (SELECT id FROM course_teachers) + GROUP BY rateable_id); + + INSERT INTO s_scores (home_id, score) (SELECT rateable_id,AVG(seems_rateable_rates.stars) + FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id IN (SELECT mem_home.home_id FROM mem_home) + AND rater_id NOT IN (SELECT id FROM course_teachers) + GROUP BY rateable_id) ; + + UPDATE mem_home, t_scores SET mem_home.score = t_scores.score WHERE mem_home.home_id = t_scores.home_id ; + + UPDATE mem_home, s_scores SET mem_home.score = s_scores.score WHERE mem_home.home_id = s_scores.home_id AND mem_home.score = 0; + + INSERT INTO scores (user_id, score) (SELECT user_id, SUM(score) FROM mem_home GROUP BY user_id); + UPDATE mems, scores SET mems.score = scores.score WHERE mems.user_id = scores.user_id; + + SELECT * FROM mems ORDER BY score DESC; + END$$ + +DELIMITER ; \ No newline at end of file