课程动态接口修改为用户所有课程动态接口

This commit is contained in:
z9hang 2015-03-03 09:11:47 +08:00
parent 18271946d7
commit 32264fb4a6
2 changed files with 29 additions and 15 deletions

View File

@ -213,7 +213,7 @@ module Mobile
present :status, 0 present :status, 0
end end
desc '课程动态' desc '用户课程动态'
params do params do
requires :token, type: String requires :token, type: String
end end

View File

@ -333,10 +333,22 @@ class CoursesService
end end
def course_dynamic(params,current_user) def course_dynamic(params,current_user)
course = Course.find(params[:id])
if current_user.nil? || !(current_user.admin? || course.is_public == 1 || (course.is_public == 0 && current_user.member_of_course?(course))) @user = User.find(params[:id])
raise '403' if !current_user.admin? && !@user.active?
raise '404'
return
end end
if current_user == @user || current_user.admin?
membership = @user.coursememberships.all
else
membership = @user.coursememberships.all(:conditions => Course.visible_condition(current_user))
end
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
result = []
membership.each do |mp|
course = mp.course
unless current_user.nil? || !(current_user.admin? || course.is_public == 1 || (course.is_public == 0 && current_user.member_of_course?(course)))
count,is_teacher = get_course_anonymous_evaluation current_user,course count,is_teacher = get_course_anonymous_evaluation current_user,course
if is_teacher if is_teacher
student_commit_number = count student_commit_number = count
@ -345,12 +357,14 @@ class CoursesService
end end
news_count = course.news.count news_count = course.news.count
message_count = course.journals_for_messages.count message_count = course.journals_for_messages.count
result = []
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 1,:count => message_count} result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 1,:count => message_count}
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 2,:count => need_anonymous_comments_count} result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 2,:count => need_anonymous_comments_count}
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 3,:count => student_commit_number} result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 3,:count => student_commit_number}
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 4,:count => news_count} result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 4,:count => news_count}
#{:course_name => course.name,:need_anonymous_comments_count=>need_anonymous_comments_count,:student_commit_number=>student_commit_number,:news_count=> news_count,:message_count=>message_count} #{:course_name => course.name,:need_anonymous_comments_count=>need_anonymous_comments_count,:student_commit_number=>student_commit_number,:news_count=> news_count,:message_count=>message_count}
end
end
result result
end end