socialforge/app/api/mobile/entities/course_dynamic.rb

90 lines
2.6 KiB
Ruby
Raw Normal View History

2015-02-06 15:52:34 +08:00
module Mobile
module Entities
class CourseDynamic < Grape::Entity
include Redmine::I18n
2015-02-06 15:52:34 +08:00
def self.course_dynamic_expose(field)
expose field do |c,opt|
2015-07-24 10:56:19 +08:00
# if field == :news_count
# obj = nil
# c[:dynamics].each do |d|
# if d[:type] == 1
# obj = d[:count]
# end
# end
# obj
# elsif field == :document_count
# obj = nil
# c[:dynamics].each do |d|
# if d[:type] == 3
# obj = d[:count]
# end
# end
# obj
# elsif field == :topic_count
# obj = nil
# c[:dynamics].each do |d|
# if d[:type] == 2
# obj = d[:count]
# end
# end
# obj
# elsif field == :homework_count
# obj = nil
# c[:dynamics].each do |d|
# if d[:type] == 4
# obj = d[:count]
# end
# end
# obj
# else
c[field] if (c.is_a?(Hash) && c.key?(field))
2015-07-24 10:56:19 +08:00
# end
2015-02-06 15:52:34 +08:00
end
end
course_dynamic_expose :course_name
2015-03-18 17:21:19 +08:00
course_dynamic_expose :course_term
course_dynamic_expose :course_time
course_dynamic_expose :course_id
course_dynamic_expose :course_img_url
course_dynamic_expose :message
2015-06-19 15:05:25 +08:00
course_dynamic_expose :news_count
course_dynamic_expose :document_count
2015-06-26 09:18:12 +08:00
course_dynamic_expose :topic_count
2015-06-19 15:05:25 +08:00
course_dynamic_expose :homework_count
course_dynamic_expose :course_student_num
course_dynamic_expose :time_from_now
2015-07-04 15:53:01 +08:00
course_dynamic_expose :current_user_is_member
course_dynamic_expose :current_user_is_teacher
2015-07-24 09:37:53 +08:00
# expose :documents,using:Mobile::Entities::Attachment do |f,opt|
# obj = nil
# f[:dynamics].each do |d|
# if d[:type] == 3
# obj = d[:documents]
# end
# end
# obj
# end
2015-06-30 15:17:22 +08:00
expose :topics,using:Mobile::Entities::Message do |f,opt|
2015-07-24 10:56:19 +08:00
f[:topics]
2015-06-19 15:05:25 +08:00
end
2015-06-30 15:17:22 +08:00
expose :homeworks,using:Mobile::Entities::Homework do |f,opt|
2015-07-24 10:56:19 +08:00
f[:homeworks]
2015-06-19 15:05:25 +08:00
end
expose :news,using:Mobile::Entities::News do |f,opt|
2015-07-24 10:56:19 +08:00
f[:news]
2015-06-19 15:05:25 +08:00
end
expose :better_students,using:Mobile::Entities::User do |f,opt|
2015-07-24 10:56:19 +08:00
f[:better_students]
end
expose :active_students,using:Mobile::Entities::User do |f,opt|
2015-07-24 10:56:19 +08:00
f[:active_students]
end
2015-02-06 15:52:34 +08:00
end
end
end