增加获取用户在指定课程内作业数量的接口
This commit is contained in:
parent
0b41afa571
commit
4cdb3c83dd
|
@ -37,4 +37,28 @@ module ApiHelper
|
|||
end
|
||||
result
|
||||
end
|
||||
|
||||
#########################################################
|
||||
#sw
|
||||
#获取课程未匿评数量
|
||||
#param: user => "用户", course_id => "查询的课程ID"
|
||||
#return: 作业的数量
|
||||
#########################################################
|
||||
def get_course_anonymous_evaluation user,course_id
|
||||
course = Course.find course_id
|
||||
count = 0
|
||||
if course
|
||||
is_teacher = is_course_teacher user,course
|
||||
if is_teacher #如果是老师,显示学生提交的作业数
|
||||
course.homeworks.each do |bid|
|
||||
count += bid.homeworks.count
|
||||
end
|
||||
else #如果是学生,显示未匿评的数量
|
||||
course.homeworks.each do |bid|
|
||||
count += get_student_not_batch_homework_list bid,user
|
||||
end
|
||||
end
|
||||
end
|
||||
count
|
||||
end
|
||||
end
|
|
@ -130,4 +130,22 @@ module HomeworkAttachHelper
|
|||
WHERE homework_attaches.bid_id = #{bid.id} AND homework_evaluations.user_id = #{user.id} ORDER BY m_score DESC")
|
||||
student_batch_homework_list
|
||||
end
|
||||
|
||||
#########################################################
|
||||
#sw
|
||||
#获取学生未进行匿评的数量
|
||||
#param: bid => 作业 user => 用户
|
||||
#return 指定用户未进行匿评的作业的数量
|
||||
#user必须是学生用户
|
||||
#######################################################
|
||||
def get_student_not_batch_homework_list bid,user
|
||||
HomeworkAttach.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 is_teacher_score = 1) AS t_score,
|
||||
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score,
|
||||
(SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{user.id} AND is_teacher_score = 0) AS m_score
|
||||
FROM homework_attaches
|
||||
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.id}) AS table1
|
||||
WHERE table1.m_score IS NULL").count
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue