This commit is contained in:
sw 2014-12-31 16:01:18 +08:00
commit fc7447ba6b
6 changed files with 29 additions and 42 deletions

View File

@ -399,7 +399,7 @@ class CoursesController < ApplicationController
@results = paginateHelper_for_members @results, 10
else
@group = Group.find(group_id)
@group = CourseGroup.find(group_id)
@results = student_homework_score(group_id, 0, 0,@score_sort_by)
@results = paginateHelper @results, 10
end
@ -913,22 +913,22 @@ class CoursesController < ApplicationController
if groupid == 0
if nums == 0
sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches
WHERE members.course_id = 122 AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = 122) AND members.user_id = homework_attaches.user_id GROUP BY members.user_id
UNION
SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = 122 AND
students_for_courses.course_id = 122 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 = 122 )
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 = 122 AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = 122) AND members.user_id = homework_attaches.user_id GROUP BY members.user_id
UNION
SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = 122 AND
students_for_courses.course_id = 122 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 = 122 )
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}"
@ -936,13 +936,13 @@ GROUP BY members.user_id ORDER BY score #{score_sort_by} limit #{start_from}, #{
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 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
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 = 122 )
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}"
end

View File

@ -453,7 +453,9 @@ class HomeworkAttachController < ApplicationController
homework.score = @m_score
homework.is_teacher_score = 1
else
homework.score = @stars_reates.select("avg(stars)")
sql = "SELECT AVG(stars) as stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{homework.id}"
score= HomeworkAttach.find_by_sql(sql).first.stars
homework.score = score
end
else
if is_teacher == 1

View File

@ -117,25 +117,16 @@ class Member < ActiveRecord::Base
# 查找每个学生每个作业的评分
def student_homework_score
score_count = 0
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
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.each do |homework|
if !homework.t_score.nil? && homework.t_score != 0
score = homework.t_score
else
if !homework.s_score.nil?
score= homework.s_score
else
score = 0
end
mem_score = 0
if homework[:score]
mem_score = homework[:score]
end
score_count = score_count + score
score_count = score_count + mem_score
end
[homework_score, format("%0.2f", score_count)]
end

View File

@ -39,6 +39,8 @@
<li class="ml50">
</li>
<li class="ml50" style="margin-left: 470px">
</li>
<li class="ml50" style="margin-left: 80%">
<a href="#" >加入时间</a>
</li>
<% end %>

View File

@ -40,16 +40,8 @@
<ul class="tscore_box">
<li ><span class="c_blue02 w280">作业名称</span><span class="c_blue02 w70">得分</span></li>
<% @member_score.student_homework_score[0].each do |homework_score| %>
<% if !homework_score.t_score.nil? && homework_score.t_score != 0 %>
<% score = homework_score.t_score %>
<% else %>
<% if !homework_score.s_score.nil? %>
<% score = homework_score.s_score %>
<% else %>
<% score = 0 %>
<% end %>
<% end %>
<li><span class="c_grey02 w280"><%= homework_score.name %></span><span class="c_red w70"><%= format("%0.2f",score) %></span></li>
<li><span class="c_grey02 w280"><%= homework_score.name %></span><span class="c_red w70"><%= format("%0.2f",homework_score[:score].nil? ? 0 : homework_score[:score]) %></span></li>
<% end %>
<li><span class="c_blue03 w280">作业积分(总得分)</span><span class="c_red w70"><%= @member_score.student_homework_score[1] %></span></li>
</ul>

View File

@ -19,7 +19,7 @@
<div class=" ">
<%= link_to_attachment file, :download => true,:text => truncate(file.filename,length: 35, omission: '...'), :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %>
<% if User.current.logged? %>
<% if is_course_teacher(User.current,@course) && file.author_id == User.current.id && course_contains_attachment?(@course,file) %>
<% if (is_course_teacher(User.current,@course) || file.author_id == User.current.id) && course_contains_attachment?(@course,file) %>
<%= link_to("选入我的其他课程",quote_resource_show_course_file_path(@course,file),:class => "f_l re_select",:remote => true) if has_course?(User.current,file) %>
<% if delete_allowed && file.container_id == @course.id && file.container_type == "Course" %>