This commit is contained in:
sw 2014-12-26 15:37:22 +08:00
commit 2e1387b9e4
6 changed files with 133 additions and 32 deletions

View File

@ -759,6 +759,7 @@ class ApplicationController < ActionController::Base
end end
end end
#查找首页相关信息 #查找首页相关信息
def find_first_page def find_first_page
@first_page = FirstPage.find_by_page_type('project') @first_page = FirstPage.find_by_page_type('project')

View File

@ -213,10 +213,10 @@ class CoursesController < ApplicationController
q = "#{params[:name].strip}" q = "#{params[:name].strip}"
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
if params[:incourse] if params[:incourse]
@results = searchmember_by_name(@@member_scores, q) @results = searchmember_by_name(student_homework_score, q)
elsif params[:ingroup] elsif params[:ingroup]
@group = CourseGroup.find(params[:search_group_id]) @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 end
@result_count = @results.count @result_count = @results.count
@ -285,7 +285,7 @@ class CoursesController < ApplicationController
member.course_group_id = group.id member.course_group_id = group.id
member.save member.save
@group = group @group = group
@members = searchStudent(@course)
@course_groups = @course.course_groups @course_groups = @course.course_groups
@membercount = @members.count @membercount = @members.count
search_group_members group search_group_members group
@ -298,7 +298,7 @@ class CoursesController < ApplicationController
member.save member.save
@group = group @group = group
@course_groups = @course.course_groups @course_groups = @course.course_groups
@members = searchStudent(@course)
@membercount = @members.count @membercount = @members.count
search_group_members group search_group_members group
end end
@ -309,9 +309,9 @@ class CoursesController < ApplicationController
@is_remote = true @is_remote = true
if params[:group_id] && params[:group_id] != "0" if params[:group_id] && params[:group_id] != "0"
@group = CourseGroup.find(params[:group_id]) @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 else
@results = @@member_scores @results = student_homework_score
end end
@@result = @results @@result = @results
@ -336,9 +336,8 @@ class CoursesController < ApplicationController
@members = @teachers @members = @teachers
when '2' when '2'
@subPage_title = l :label_student_list @subPage_title = l :label_student_list
teachers = @teachers.map{|teacher| teacher.user_id}.join(",") @members = student_homework_score
@@member_scores = student_homework_score teachers
@members = @@member_scores
# @member_scores = @@member_scores # @member_scores = @@member_scores
# @members = searchStudent_sort(@course, 'desc', @@member_scores) # @members = searchStudent_sort(@course, 'desc', @@member_scores)
@membercount = @members.count @membercount = @members.count
@ -881,17 +880,12 @@ class CoursesController < ApplicationController
end end
end end
def student_homework_score teachers def student_homework_score
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 #teachers = find_course_teachers(@course)
FROM ( sql = ActiveRecord::Base.connection()
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, homework_scores = Member.find_by_sql("call member_score(#{@course.id})")
(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 sql.close()
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 homework_scores
end end
#获取课程的老师列表 #获取课程的老师列表
@ -908,7 +902,7 @@ class CoursesController < ApplicationController
@members = searchStudent(@course) @members = searchStudent(@course)
@membercount = @members.count @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 @@result = @results
@results = paginateHelper @results @results = paginateHelper @results
end end

View File

@ -395,16 +395,18 @@ class FilesController < ApplicationController
render :layout => 'base_courses' render :layout => 'base_courses'
} }
end 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 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
end end

View File

@ -194,19 +194,23 @@ module CoursesHelper
def searchmember_by_name members, name def searchmember_by_name members, name
#searchPeopleByRoles(project, StudentRoles) #searchPeopleByRoles(project, StudentRoles)
mems = [] mems = []
members.each do |m| if name != ""
members.each do |m|
username = m.user[:lastname].to_s + m.user[:firstname].to_s 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)) if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name))
mems << m mems << m
end end
end
else
mems = members
end end
mems mems
end end
def searchgroupmember_by_name members, name, group def searchgroupmember_by_name members, name, group
#searchPeopleByRoles(project, StudentRoles) #searchPeopleByRoles(project, StudentRoles)
mems = [] mems = []
if name != ""
members.each do |m| members.each do |m|
if m.course_group_id == group.id if m.course_group_id == group.id
username = m.user[:lastname].to_s + m.user[:firstname].to_s username = m.user[:lastname].to_s + m.user[:firstname].to_s
@ -215,6 +219,9 @@ module CoursesHelper
end end
end end
end end
else
mems = members
end
mems mems
end end
def searchgroupstudent_by_name(group, project, name) def searchgroupstudent_by_name(group, project, name)

View File

@ -53,7 +53,7 @@
<% members.each do |member| %> <% members.each do |member| %>
<div class="cl"></div><!--st_box_top end--> <div class="cl"></div><!--st_box_top end-->
<div class="st_boxlist"> <div class="st_boxlist">
<% next if member.new_record? %>
<a href="#" class="st_img" style="float:left;"> <a href="#" class="st_img" style="float:left;">
<%= member.user.nil? ? '' : (image_tag(url_to_avatar(member.user), :width => 40, :height => 40)) %> <%= member.user.nil? ? '' : (image_tag(url_to_avatar(member.user), :width => 40, :height => 40)) %>
</a> </a>
@ -101,7 +101,7 @@
</div> </div>
</div> </div>
<div class="pagination"> <div class="pagination">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %> <%= pagination_links_full @obj_pages, @obj_count, :remote =>true, :per_page_links => false %>
</div> </div>
<% else %> <% else %>
<p class="nodata"> <p class="nodata">

97
data/member_score.sql Normal file
View File

@ -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 ;