From e6af34e9f8be3a9269d889f05b7fccf6f72b6bab Mon Sep 17 00:00:00 2001
From: sw <939547590@qq.com>
Date: Tue, 2 Jun 2015 16:22:15 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E5=88=97=E8=A1=A8=E6=98=BE?=
=?UTF-8?q?=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/courses_controller.rb | 63 ++++++++--------------
app/models/member.rb | 9 ++--
app/views/courses/show_member_score.js.erb | 2 +-
public/stylesheets/public.css | 1 +
4 files changed, 29 insertions(+), 46 deletions(-)
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index e2728f0c5..333ad77b1 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -298,7 +298,6 @@ class CoursesController < ApplicationController
else
page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1)
@results = student_homework_score(0,page_from, 10,"desc")
- @results = paginateHelper_for_members @results, 10
end
end
@@ -317,14 +316,11 @@ class CoursesController < ApplicationController
when '1'
@subPage_title = l :label_teacher_list
@all_members = searchTeacherAndAssistant(@course)
- #@members = paginateHelper @all_members, 10
@members = @all_members
when '2'
@subPage_title = l :label_student_list
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
@all_members = student_homework_score(0,page, 10,"desc")
- # @all_members = @course.members
- # @members = paginateHelper_for_members @all_members, 10
@members = @all_members
end
respond_to do |format|
@@ -379,11 +375,9 @@ class CoursesController < ApplicationController
if group_id == '0'
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
@results = student_homework_score(0,page, 10,@score_sort_by)
- @results = paginateHelper_for_members @results, 10
else
@group = CourseGroup.find(group_id)
@results = student_homework_score(group_id, 0, 0,@score_sort_by)
- @results = paginateHelper @results, 10
end
end
end
@@ -837,44 +831,32 @@ class CoursesController < ApplicationController
end
def student_homework_score(groupid,start_from, nums, score_sort_by)
- #teachers = find_course_teachers(@course)
start_from = start_from * nums
sql_select = ""
if groupid == 0
- if nums == 0
- sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches
- WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id
- AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) GROUP BY members.user_id
- UNION all
- SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} AND
- students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND
- members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} )
- )
- GROUP BY members.user_id ORDER BY score #{score_sort_by}"
- else
- sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches
- WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id
- AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) GROUP BY members.user_id
- UNION all
- SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} AND
- students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND
- members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} )
- )
- GROUP BY members.user_id ORDER BY score #{score_sort_by} " #limit #{start_from}, #{nums}"
-
- end
+ sql_select = "SELECT members.*,(
+ SELECT SUM(student_works.final_score)
+ FROM student_works,homework_commons
+ WHERE student_works.homework_common_id = homework_commons.id
+ AND homework_commons.course_id = #{@course.id}
+ AND student_works.user_id = members.user_id
+ ) AS score
+ FROM members
+ JOIN students_for_courses
+ ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id
+ WHERE members.course_id = #{@course.id} ORDER BY score #{score_sort_by}"
else
- sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches
- WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id
- and members.course_group_id = #{groupid} AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id})
- GROUP BY members.user_id
- UNION all
- SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id}
- and members.course_group_id = #{groupid} AND
- students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND
- members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} )
- )
- GROUP BY members.user_id ORDER BY score #{score_sort_by}"
+ sql_select = "SELECT members.*,(
+ SELECT SUM(student_works.final_score)
+ FROM student_works,homework_commons
+ WHERE student_works.homework_common_id = homework_commons.id
+ AND homework_commons.course_id = #{@course.id}
+ AND student_works.user_id = members.user_id
+ ) AS score
+ FROM members
+ JOIN students_for_courses
+ ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id
+ WHERE members.course_id = #{@course.id} AND members.course_group_id = #{groupid} ORDER BY score #{score_sort_by}"
end
sql = ActiveRecord::Base.connection()
homework_scores = Member.find_by_sql(sql_select)
@@ -896,7 +878,6 @@ class CoursesController < ApplicationController
@score_sort_by = "desc"
page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1)
@results = student_homework_score(group.id,0,0, "desc")
- @results = paginateHelper @results, 10
end
diff --git a/app/models/member.rb b/app/models/member.rb
index f1a139f74..2936392ab 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -117,10 +117,11 @@ class Member < ActiveRecord::Base
# 查找每个学生每个作业的评分
def student_homework_score
score_count = 0
- homework_score = HomeworkAttach.find_by_sql("SELECT bids.name, homework_attaches.score as 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 = StudentWork.find_by_sql("SELECT homework_commons.name,student_works.final_score as score
+ FROM student_works,homework_commons
+ WHERE student_works.homework_common_id = homework_commons.id
+ AND homework_commons.course_id = #{self.course_id}
+ AND student_works.user_id = #{self.user_id}")
homework_score.each do |homework|
mem_score = 0
if homework[:score]
diff --git a/app/views/courses/show_member_score.js.erb b/app/views/courses/show_member_score.js.erb
index 87e728901..083f070c2 100644
--- a/app/views/courses/show_member_score.js.erb
+++ b/app/views/courses/show_member_score.js.erb
@@ -7,7 +7,7 @@ showModal('ajax-modal', '400px');
//$('#ajax-modal').css('height','569px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("" +
-"");
+"");
//$('#ajax-modal').parent().removeClass();
$('#ajax-modal').parent().css("top","30%").css("left","40%").css("position","fixed");
$('#ajax-modal').parent().addClass("new-watcher");
diff --git a/public/stylesheets/public.css b/public/stylesheets/public.css
index 44ca87526..d6e6907fa 100644
--- a/public/stylesheets/public.css
+++ b/public/stylesheets/public.css
@@ -6,6 +6,7 @@ table,tr,td{border:0;cellspacing:0; cellpadding:0;}
ol,ul,li{ list-style-type:none}
a:link,a:visited{color:#7f7f7f;text-decoration:none;}
a:hover,a:active{color:#000;}
+a:hover {text-decoration: none; }
textarea {resize: none;}
/*常用*/