diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 4a9e3bb1f..b2ecf7cba 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -4,14 +4,61 @@ class HomeworkAttachController < ApplicationController ############################### before_filter :can_show_course,except: [] #判断当前角色权限时需先找到当前操作的project - before_filter :find_course_by_bid_id, :only => [:new,:get_not_batch_homework] + before_filter :find_course_by_bid_id, :only => [:new,:get_not_batch_homework,:get_batch_homeworks,:get_homeworks,:get_homework_jours] before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users] #判断当前角色是否有操作权限 #勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy] #获取未批作业列表 def get_not_batch_homework - @homeworks = HomeworkAttach.all + teachers = find_course_teachers @course + limit = 10 + start_item = params['page'].nil? ? 0 : (params['page'].to_i - 1) * limit + @homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in #{teachers}) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in #{teachers}) AS s_score + FROM homework_attaches WHERE bid_id = #{@bid.id} + ORDER BY s_score DESC,created_at ASC + limit #{start_item}, #{limit}") + respond_to do |format| + format.js + end + end + + #获取已评作业列表 + def get_batch_homeworks + teachers = find_course_teachers @course + limit = 10 + start_item = params['page'].nil? ? 0 : (params['page'].to_i - 1) * limit + @homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in #{teachers}) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in #{teachers}) AS s_score + FROM homework_attaches WHERE bid_id = #{@bid.id} + ORDER BY s_score DESC,created_at ASC + limit #{start_item}, #{limit}") + respond_to do |format| + format.js + end + end + + #获取所有作业列表 + def get_homeworks + teachers = find_course_teachers @course + limit = 10 + start_item = params['page'].nil? ? 0 : (params['page'].to_i - 1) * limit + @homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in #{teachers}) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in #{teachers}) AS s_score + FROM homework_attaches WHERE bid_id = #{@bid.id} + ORDER BY s_score DESC,created_at ASC + limit #{start_item}, #{limit}") + respond_to do |format| + format.js + end + end + + #获取作业的留言列表 + def get_homework_jours respond_to do |format| format.js end @@ -328,7 +375,7 @@ class HomeworkAttachController < ApplicationController def find_course_by_bid_id @bid = Bid.find(params[:id]) - @course = @bid.courses[0] + @course = @bid.courses.first rescue ActiveRecord::RecordNotFound render_404 end @@ -337,5 +384,19 @@ class HomeworkAttachController < ApplicationController @homework = HomeworkAttach.find(params[:id]) @course = @homework.bid.courses[0] end + + #获取课程的老师列表 + def find_course_teachers course + teachers = "(" + teacher_members = searchTeacherAndAssistant(course) + teacher_members.each do |member| + if member == teacher_members.last + teachers += member.user_id.to_s + ")" + else + teachers += member.user_id.to_s + "," + end + end + teachers + end end diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 947dd455f..46bdf4b3d 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -2,20 +2,8 @@