课程学生列表功能

This commit is contained in:
lizanle 2015-05-04 17:36:48 +08:00
parent f89a317a96
commit c353398d65
3 changed files with 66 additions and 1 deletions

View File

@ -240,6 +240,18 @@ module Mobile
present :status, 0
end
desc '课程学生'
params do
requires :token,type:String
requires :course_id,type:Integer,desc: '课程id'
end
get ":course_id/members" do
cs = CoursesService.new
count = cs.course_members params
present :data, count, with: Mobile::Entities::Member
present :status, 0
end
end
end
end

View File

@ -46,6 +46,7 @@ module Mobile
course_expose :term
course_expose :time
course_expose :updated_at
course_expose :course_student_num
expose :teacher, using: Mobile::Entities::User do |c, opt|
if c.is_a? ::Course
c.teacher

View File

@ -169,7 +169,7 @@ class CoursesService
unless (course.is_public == 1 || current_user.member_of_course?(course) || current_user.admin?)
raise '403'
end
{:course => course,:work_unit => work_unit, :img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course)}
{:course => course,:work_unit => work_unit, :img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course),:course_student_num => course ? course.student.count.to_s : 0}
end
#创建课程
@ -439,6 +439,11 @@ class CoursesService
result
end
# 课程学生列表
def course_members params
@all_members = student_homework_score(0,params[:course_id], 10,"desc")
end
private
def show_homework_info course,bid,current_user,is_course_teacher
author_real_name = bid.author.lastname + bid.author.firstname
@ -476,5 +481,52 @@ class CoursesService
end
def student_homework_score(groupid,course_id, nums, score_sort_by)
#teachers = find_course_teachers(@course)
#start_from = start_from * nums
sql_select = ""
if groupid == 0
if nums == 0
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 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 = #{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}"
end
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 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 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 = #{course_id} )
)
GROUP BY members.user_id ORDER BY score #{score_sort_by}"
end
sql = ActiveRecord::Base.connection()
homework_scores = Member.find_by_sql(sql_select)
sql.close()
homework_scores
end
end