增加缺评排序,优化获取已评、未评、缺评的数量的方法

This commit is contained in:
sw 2015-06-19 09:56:39 +08:00
parent 43363e8bcb
commit c64b761f46
2 changed files with 17 additions and 11 deletions

View File

@ -236,7 +236,17 @@ class StudentWorkController < ApplicationController
#评价列表显示
def student_work_absence_penalty
render_403 unless User.current.allowed_to?(:as_teacher,@course)
@stundet_works = @homework.student_works
order = params[:order] || "desc"
work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")"
@stundet_works = StudentWork.find_by_sql("SELECT *,(all_count - has_count) AS absence FROM(
SELECT * ,
(SELECT COUNT(*) FROM `student_works_evaluation_distributions` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS all_count,
(SELECT COUNT(*) FROM `student_works_scores` WHERE user_id = student_works.user_id AND student_work_id IN #{work_ids}) AS has_count
FROM `student_works`
WHERE homework_common_id = 213
) AS table_1
ORDER BY absence #{order}")
@order = order == "desc" ? "asc" : "desc"
respond_to do |format|
format.html
end

View File

@ -20,7 +20,8 @@
<a href="javascript:void(0)">实评</a>
</li>
<li class="ml30">
<a href="javascript:void(0)">缺评</a>
<%= link_to "缺评",student_work_absence_penalty_student_work_index_path(:homework => @homework.id,:order => @order)%>
<a href="javascript:void(0);" class="<%= @order == 'desc' ? 'st_up' : 'st_down'%>" ></a>
</li>
</ul>
<div class="cl"></div><!--st_box_top end-->
@ -35,19 +36,14 @@
<li class=" hwork_name_ab ">
<%= link_to student_work.user.show_name,user_path(student_work.user),:title => student_work.user.show_name, :class => "c_blue02"%>
</li>
<%
all_count = all_evaluation_count student_work.user,@homework
has_count = has_evaluation_count student_work.user,@homework
absence = all_count - has_count
%>
<li class="absence c_grey">
<%= all_count%>
<%= student_work.all_count%>
</li>
<li class="absence c_grey">
<%= has_count%>
<%= student_work.has_count%>
</li>
<li class="absence <%= absence == 0 ? 'c_green' : 'c_red'%>">
<%= absence%>
<li class="absence <%= student_work.absence == 0 ? 'c_green' : 'c_red'%>">
<%= student_work.absence%>
</li>
</ul>
<% end%>