动态 api 隐藏 资源 讨论区

This commit is contained in:
lizanle 2015-07-02 17:31:30 +08:00
parent 664770c63f
commit 9eab8b92ca
3 changed files with 58 additions and 13 deletions

View File

@ -323,6 +323,19 @@ module Mobile
news = cs.students_score_list params,current_user
present :data,news,with:Mobile::Entities::User
end
desc '课程某次作业提交列表 并显示成绩'
params do
requires :token,type:String
requires :course_id,type:Integer,desc:'课程id'
requires :homework_id,type:Integer,desc:'作业id'
optional :page,type:Integer,desc:'页码'
end
get ':course_id/student_works_list' do
cs = CoursesService.new
student_works = cs.student_work_list params,current_user
present :data,student_works.all,with:Mobile::Entities::StudentWork
end
end
end
end

View File

@ -26,6 +26,8 @@ module Mobile
f.student_works.count
when :homework_status
get_homework_status f
when :homework_times
f.course.homework_commons.index(f) + 1
end
end
end

View File

@ -669,8 +669,8 @@ class CoursesService
homework_count = course.homework_commons.count
unless homework_count == 0
sql = "select users.*,sum(IFNULL(0,student_works.final_score))/#{homework_count} score from student_works left outer join users on student_works.user_id = users.id" <<
" where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{course.id}) GROUP BY student_works.user_id ORDER BY score limit 0,5"
latest_course_dynamics <<{:type=> 6,:time=>Time.now.to_s,:count=> 5,:better_students=> User.find_by_sql(sql)}
" where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{course.id}) GROUP BY student_works.user_id ORDER BY score limit 0,6"
latest_course_dynamics <<{:type=> 6,:time=>Time.now.to_s,:count=> 6,:better_students=> User.find_by_sql(sql)}
dynamics_count += 1
end
# 课程通知
@ -682,19 +682,19 @@ class CoursesService
end
# 课程讨论区
latest_message = course.boards.first.topics.page(1).per(2)
unless latest_message.first.nil?
latest_course_dynamics << {:type => 2, :time => latest_message.first.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count,
:topics => latest_message.all}
dynamics_count += 1
end
# latest_message = course.boards.first.topics.page(1).per(2)
# unless latest_message.first.nil?
# latest_course_dynamics << {:type => 2, :time => latest_message.first.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count,
# :topics => latest_message.all}
# dynamics_count += 1
# end
# 课程资源
latest_attachment = course.attachments.order("created_on desc").page(1).per(2)
unless latest_attachment.first.nil?
latest_course_dynamics << {:type => 3, :time => latest_attachment.first.created_on,:count =>course.attachments.count , :documents=>latest_attachment}
dynamics_count += 1
end
# latest_attachment = course.attachments.order("created_on desc").page(1).per(2)
# unless latest_attachment.first.nil?
# latest_course_dynamics << {:type => 3, :time => latest_attachment.first.created_on,:count =>course.attachments.count , :documents=>latest_attachment}
# dynamics_count += 1
# end
#课程作业 已经交的学生列表暂定显示6人未交的学生列表作业的状态
homeworks = course.homework_commons.page(1).per(2).order('created_at desc')
@ -722,5 +722,35 @@ class CoursesService
User.find_by_sql(sql)
end
# 获取某次作业的所有作业列表
def student_work_list params,current_user
is_teacher = User.current.allowed_to?(:as_teacher,Course.find(params[:course_id]))
homework = HomeworkCommon.find(params[:homework_id])
student_works = []
#老师 || 非匿评作业 || 匿评结束 显示所有的作品
show_all = is_teacher || homework.homework_type != 1 || homework.homework_detail_manual.comment_status == 3
if show_all
if homework.homework_type == 1 || is_teacher || current_user.admin?
student_works = homework.student_works.page(params[:page] || 1).per(10).order("final_score desc ")
else
my_work = homework.student_works.where(:user_id => current_user.id)
if my_work.empty?
student_works = []
else
student_works = homework.student_works.page(params[:page] || 1).per(10).order("final_score desc")
end
end
else #学生
if homework.homework_detail_manual.comment_status == 1 #未开启匿评,只显示我的作品
student_works = homework.student_works.where(:user_id => current_user.id).page(params[:page] || 1).per(10)
elsif homework.homework_detail_manual.comment_status == 2 #匿评列表,显示匿评作品和我的作品
#is_evaluation = true
my_work = homework.student_works.where(:user_id => current_user.id).page(params[:page] || 1).per(10)
student_works = my_work + current_user.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == homework.id}
end
end
student_works
end
end