2015-02-06 15:52:34 +08:00
|
|
|
module Mobile
|
|
|
|
module Entities
|
|
|
|
class CourseDynamic < Grape::Entity
|
2015-03-09 15:23:24 +08:00
|
|
|
include Redmine::I18n
|
2015-02-06 15:52:34 +08:00
|
|
|
def self.course_dynamic_expose(field)
|
|
|
|
expose field do |c,opt|
|
2015-03-09 15:23:24 +08:00
|
|
|
if field == :update_time
|
|
|
|
(format_time(c[field]) if (c.is_a?(Hash) && c.key?(field)))
|
2015-06-19 15:05:25 +08:00
|
|
|
elsif 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
|
2015-06-26 09:18:12 +08:00
|
|
|
elsif field == :topic_count
|
2015-06-19 15:05:25 +08:00
|
|
|
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
|
2015-03-09 15:23:24 +08:00
|
|
|
else
|
|
|
|
c[field] if (c.is_a?(Hash) && c.key?(field))
|
|
|
|
end
|
|
|
|
|
2015-02-06 15:52:34 +08:00
|
|
|
end
|
|
|
|
end
|
2015-03-01 16:32:10 +08:00
|
|
|
course_dynamic_expose :type
|
|
|
|
course_dynamic_expose :count
|
2015-02-06 15:52:34 +08:00
|
|
|
course_dynamic_expose :course_name
|
2015-03-18 17:21:19 +08:00
|
|
|
course_dynamic_expose :course_term
|
|
|
|
course_dynamic_expose :course_time
|
2015-03-01 16:32:10 +08:00
|
|
|
course_dynamic_expose :course_id
|
|
|
|
course_dynamic_expose :course_img_url
|
2015-03-09 15:23:24 +08:00
|
|
|
course_dynamic_expose :message
|
|
|
|
course_dynamic_expose :update_time
|
2015-06-19 15:05:25 +08:00
|
|
|
course_dynamic_expose :count
|
|
|
|
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
|
2015-07-04 15:53:01 +08:00
|
|
|
|
|
|
|
course_dynamic_expose :current_user_is_member
|
|
|
|
course_dynamic_expose :current_user_is_teacher
|
2015-06-19 15:05:25 +08:00
|
|
|
#在dynamics里解析出四种动态
|
2015-06-30 15:17:22 +08:00
|
|
|
expose :documents,using:Mobile::Entities::Attachment do |f,opt|
|
2015-06-19 15:05:25 +08:00
|
|
|
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-06-19 15:05:25 +08:00
|
|
|
obj = nil
|
|
|
|
f[:dynamics].each do |d|
|
|
|
|
if d[:type] == 2
|
2015-06-30 15:17:22 +08:00
|
|
|
obj = d[:topics]
|
2015-06-19 15:05:25 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
obj
|
|
|
|
end
|
2015-06-30 15:17:22 +08:00
|
|
|
expose :homeworks,using:Mobile::Entities::Homework do |f,opt|
|
2015-06-19 15:05:25 +08:00
|
|
|
obj = nil
|
|
|
|
f[:dynamics].each do |d|
|
|
|
|
if d[:type] == 4
|
2015-06-30 15:17:22 +08:00
|
|
|
obj = d[:homeworks]
|
2015-06-19 15:05:25 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
obj
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :news,using:Mobile::Entities::News do |f,opt|
|
|
|
|
obj = nil
|
|
|
|
f[:dynamics].each do |d|
|
|
|
|
if d[:type] == 1
|
2015-06-30 15:17:22 +08:00
|
|
|
obj = d[:news]
|
2015-06-19 15:05:25 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
obj
|
|
|
|
end
|
|
|
|
|
2015-07-01 16:56:03 +08:00
|
|
|
expose :better_students,using:Mobile::Entities::User do |f,opt|
|
|
|
|
obj = nil
|
|
|
|
f[:dynamics].each do |d|
|
|
|
|
if d[:type] == 6
|
|
|
|
obj = d[:better_students]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
obj
|
|
|
|
end
|
|
|
|
|
2015-02-06 15:52:34 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|