@ -21,8 +21,14 @@ class HomeworkAttachController < ApplicationController
#获取未批作业列表
#获取未批作业列表
def get_not_batch_homework
def get_not_batch_homework
sort , direction = params [ :sort ] , params [ :direction ]
sort , direction = params [ :sort ] || " s_socre " , params [ :direction ] || " desc "
order_by = sort == 'socre' ? " s_score #{ direction } " : " created_at #{ direction } "
if sort == 't_socre'
order_by = " t_score #{ direction } "
elsif sort == 's_socre'
order_by = " s_score #{ direction } "
elsif sort == 'time'
order_by = " created_at #{ direction } "
end
teachers = find_course_teachers @course
teachers = find_course_teachers @course
all_homework_list = HomeworkAttach . eager_load ( :attachments , :user , :rate_averages ) . find_by_sql ( " SELECT * FROM (SELECT homework_attaches.*,
all_homework_list = HomeworkAttach . eager_load ( :attachments , :user , :rate_averages ) . find_by_sql ( " SELECT * FROM (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 IN #{teachers}) AS t_score,
@ -41,9 +47,14 @@ class HomeworkAttachController < ApplicationController
#获取已评作业列表
#获取已评作业列表
def get_batch_homeworks
def get_batch_homeworks
sort , direction = params [ :sort ] , params [ :direction ]
sort , direction = params [ :sort ] || " s_socre " , params [ :direction ] || " desc "
teacher_proportion = get_teacher_proportion @bid
if sort == 't_socre'
order_by = sort == 'socre' ? " (CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{ teacher_proportion } END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{ 1 - teacher_proportion } END) #{ direction } " : " created_at #{ direction } "
order_by = " t_score #{ direction } "
elsif sort == 's_socre'
order_by = " s_score #{ direction } "
elsif sort == 'time'
order_by = " created_at #{ direction } "
end
teachers = find_course_teachers @course
teachers = find_course_teachers @course
all_homework_list = HomeworkAttach . eager_load ( :attachments , :user , :rate_averages ) . find_by_sql ( " SELECT * FROM (SELECT homework_attaches.*,
all_homework_list = HomeworkAttach . eager_load ( :attachments , :user , :rate_averages ) . find_by_sql ( " SELECT * FROM (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} and stars IS NOT NULL) AS t_score,
( SELECT AVG ( stars ) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND rater_id IN #{teachers} and stars IS NOT NULL) AS t_score,
@ -62,9 +73,14 @@ class HomeworkAttachController < ApplicationController
#获取所有作业列表
#获取所有作业列表
def get_homeworks
def get_homeworks
sort , direction = params [ :sort ] , params [ :direction ]
sort , direction = params [ :sort ] || " s_socre " , params [ :direction ] || " desc "
teacher_proportion = get_teacher_proportion @bid
if sort == 't_socre'
order_by = sort == 'socre' ? " (CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{ teacher_proportion } END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{ 1 - teacher_proportion } END) #{ direction } " : " created_at #{ direction } "
order_by = " t_score #{ direction } "
elsif sort == 's_socre'
order_by = " s_score #{ direction } "
elsif sort == 'time'
order_by = " created_at #{ direction } "
end
teachers = find_course_teachers @course
teachers = find_course_teachers @course
all_homework_list = HomeworkAttach . eager_load ( :attachments , :user , :rate_averages ) . find_by_sql ( " SELECT homework_attaches.*,
all_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 in #{teachers}) AS t_score,
@ -90,7 +106,7 @@ class HomeworkAttachController < ApplicationController
( SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND rater_id = 3123 ) AS m_score
( SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND rater_id = 3123 ) AS m_score
FROM homework_attaches
FROM homework_attaches
INNER JOIN homework_evaluations ON homework_evaluations . homework_attach_id = homework_attaches . id
INNER JOIN homework_evaluations ON homework_evaluations . homework_attach_id = homework_attaches . id
WHERE homework_attaches . bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id} ) AS table1
WHERE homework_attaches . bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id} ORDER BY s_score DESC ) AS table1
WHERE table1 . m_score IS NULL " )
WHERE table1 . m_score IS NULL " )
@cur_page = params [ :page ] || 1
@cur_page = params [ :page ] || 1
@cur_type = 4
@cur_type = 4
@ -496,6 +512,26 @@ class HomeworkAttachController < ApplicationController
@totle_score = score_for_homework @homework
@totle_score = score_for_homework @homework
@teaher_score = teacher_score_for_homework @homework
@teaher_score = teacher_score_for_homework @homework
stars_reates = @homework . rates ( :quality )
is_student = is_cur_course_student @homework . bid . courses . first
is_teacher = is_course_teacher User . current , @homework . bid . courses . first
@has_evaluation = stars_reates . where ( " rater_id = ? " , User . current ) . count > 0
@is_anonymous_comments = @homework . bid . comment_status == 1 #是否开启了匿评
if ! User . current . member_of_course? ( @homework . bid . courses . first )
@is_comprehensive_evaluation = 3 #留言
elsif is_student && @is_anonymous_comments && ! @has_evaluation #是学生且开启了匿评且未进行评分
@is_comprehensive_evaluation = 2 #匿评
elsif is_student && @is_anonymous_comments && @has_evaluation #是学生且开启了匿评,但已评分
@is_comprehensive_evaluation = 3 #留言
elsif is_student && ! @is_anonymous_comments #是学生未开启匿评
@is_comprehensive_evaluation = 3 #留言
elsif is_teacher
@is_comprehensive_evaluation = 1 #教师评论
else
@is_comprehensive_evaluation = 3
end
respond_to do | format |
respond_to do | format |
format . js
format . js
end
end