修改用户课程动态接口返回数据
This commit is contained in:
parent
610746301f
commit
d96b87cf42
|
@ -1,9 +1,15 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class CourseDynamic < Grape::Entity
|
||||
include Redmine::I18n
|
||||
def self.course_dynamic_expose(field)
|
||||
expose field do |c,opt|
|
||||
c[field] if (c.is_a?(Hash) && c.key?(field))
|
||||
if field == :update_time
|
||||
(format_time(c[field]) if (c.is_a?(Hash) && c.key?(field)))
|
||||
else
|
||||
c[field] if (c.is_a?(Hash) && c.key?(field))
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
course_dynamic_expose :type
|
||||
|
@ -11,6 +17,8 @@ module Mobile
|
|||
course_dynamic_expose :course_name
|
||||
course_dynamic_expose :course_id
|
||||
course_dynamic_expose :course_img_url
|
||||
course_dynamic_expose :message
|
||||
course_dynamic_expose :update_time
|
||||
end
|
||||
end
|
||||
end
|
|
@ -344,25 +344,80 @@ class CoursesService
|
|||
else
|
||||
membership = @user.coursememberships.all(:conditions => Course.visible_condition(current_user))
|
||||
end
|
||||
if membership.nil? || membership.count == 0
|
||||
raise l(:label_no_courses,:locale => current_user.language.nil? ? 'zh':current_user.language)
|
||||
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
|
||||
if is_teacher
|
||||
student_commit_number = count
|
||||
else
|
||||
need_anonymous_comments_count = count
|
||||
#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
|
||||
# if is_teacher
|
||||
# student_commit_number = count
|
||||
# else
|
||||
# need_anonymous_comments_count = count
|
||||
# end
|
||||
# news_count = course.news.count
|
||||
# message_count = course.journals_for_messages.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 => 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}
|
||||
# #{: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
|
||||
latest_course_dynamics = []
|
||||
latest_news = course.news.order("created_on desc").first
|
||||
unless latest_news.nil?
|
||||
latest_course_dynamics << {:type => 1,:time => latest_news.created_on,:message => l(:label_recently_updated_notification,:locale => current_user.language.nil? ? 'zh':current_user.language)}
|
||||
end
|
||||
latest_message = course.journals_for_messages.order("created_on desc").first
|
||||
unless latest_message.nil?
|
||||
latest_course_dynamics << {:type => 2,:time => latest_message.created_on,:message => l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)}
|
||||
end
|
||||
latest_attachment = course.attachments.order("created_on desc").first
|
||||
unless latest_attachment.nil?
|
||||
latest_course_dynamics << {:type => 3,:time => latest_attachment.created_on,:message => l(:label_recently_updated_courseware,:locale => current_user.language.nil? ? 'zh':current_user.language)}
|
||||
end
|
||||
latest_bid = course.homeworks.order('updated_on DESC').first
|
||||
unless latest_bid.nil?
|
||||
latest_course_dynamics << {:type => 4,:time => latest_bid.updated_on,:message => l(:label_recently_updated_homework,:locale => current_user.language.nil? ? 'zh':current_user.language)}
|
||||
end
|
||||
#每个作业中的最新留言
|
||||
messages = []
|
||||
course.homeworks.each do |bid|
|
||||
jour = bid.journals_for_messages.order("created_on desc").first
|
||||
unless jour.nil?
|
||||
messages << jour
|
||||
end
|
||||
news_count = course.news.count
|
||||
message_count = course.journals_for_messages.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 => 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}
|
||||
#{: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
|
||||
unless messages.count == 0
|
||||
messages.sort!{|order,newer| newer.created_on <=> order.created_on}
|
||||
end
|
||||
latest_bid_message = messages.first
|
||||
unless latest_bid_message.nil?
|
||||
latest_course_dynamics << {:type => 2,:time => latest_bid_message.created_on,:message => l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)}
|
||||
end
|
||||
#每个作业中学生最后提交的作业
|
||||
homeworks = []
|
||||
course.homeworks.each do |bid|
|
||||
homework_attach = bid.homeworks.order('updated_at DESC').first
|
||||
unless homework_attach.nil?
|
||||
homeworks << homework_attach
|
||||
end
|
||||
end
|
||||
unless homeworks.count == 0
|
||||
homeworks.sort!{|order,newer| newer.updated_at <=> order.updated_at}
|
||||
end
|
||||
latest_homework_attach = homeworks.first
|
||||
unless latest_homework_attach.nil?
|
||||
latest_course_dynamics << {:type => 4,:time => latest_homework_attach.updated_at,:message => l(:label_recently_updated_homework,:locale => current_user.language.nil? ? 'zh':current_user.language)}
|
||||
end
|
||||
latest_course_dynamics.sort!{|order,newer| newer[:time] <=> order[:time]}
|
||||
latest_course_dynamic = latest_course_dynamics.first
|
||||
unless latest_course_dynamic.nil?
|
||||
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => latest_course_dynamic[:type],:update_time => latest_course_dynamic[:time],:message => latest_course_dynamic[:message],:count => nil}
|
||||
end
|
||||
end
|
||||
result
|
||||
|
|
|
@ -1876,3 +1876,10 @@ en:
|
|||
label_submit_comments: Submit_comments
|
||||
label_course_empty_select: You have not selected course!
|
||||
label_enterprise_page_made: enterprise_page
|
||||
|
||||
#api
|
||||
label_recently_updated_notification: Recently updated notification
|
||||
label_recently_updated_homework: Recently updated the homework
|
||||
label_recently_updated_message: Recently updated the message
|
||||
label_recently_updated_courseware: Recently updated the courseware
|
||||
label_no_courses: You do not participate in any course, please search the curriculum, course, or create a course!
|
||||
|
|
|
@ -2569,3 +2569,10 @@ zh:
|
|||
label_part_enterprise_tips: 您可能对系统的其它项目感兴趣!
|
||||
label_enterprise_nil: 该模块为最新上线模块,目前还没有创建企业项目!
|
||||
label_enterprises: 组织
|
||||
|
||||
#api
|
||||
label_recently_updated_notification: 最近更新了通知
|
||||
label_recently_updated_homework: 最近更新了作业
|
||||
label_recently_updated_message: 最近更新了留言
|
||||
label_recently_updated_courseware: 最近更新了课件
|
||||
label_no_courses: 您没有参与任何课程,请搜索课程、加入课程,或者创建课程吧!
|
||||
|
|
Loading…
Reference in New Issue