129 lines
3.6 KiB
Ruby
129 lines
3.6 KiB
Ruby
module Mobile
|
|
module Entities
|
|
class CourseDynamic < Grape::Entity
|
|
include Redmine::I18n
|
|
def self.course_dynamic_expose(field)
|
|
expose field do |c,opt|
|
|
if field == :update_time
|
|
(format_time(c[field]) if (c.is_a?(Hash) && c.key?(field)))
|
|
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
|
|
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
|
|
elsif field == :homework_submit_num
|
|
obj = nil
|
|
c[:dynamics].each do |d|
|
|
if d[:type] == 4
|
|
obj = d[:submit_count]
|
|
end
|
|
end
|
|
obj
|
|
elsif field == :homework_submit_students
|
|
obj = nil
|
|
c[:dynamics].each do |d|
|
|
if d[:type] == 4
|
|
obj = d[:studentlist]
|
|
end
|
|
end
|
|
obj
|
|
elsif field == :homework_status
|
|
obj = nil
|
|
c[:dynamics].each do |d|
|
|
if d[:type] == 4
|
|
obj = d[:homework_status]
|
|
end
|
|
end
|
|
obj
|
|
else
|
|
c[field] if (c.is_a?(Hash) && c.key?(field))
|
|
end
|
|
|
|
end
|
|
end
|
|
course_dynamic_expose :type
|
|
course_dynamic_expose :count
|
|
course_dynamic_expose :course_name
|
|
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
|
|
course_dynamic_expose :update_time
|
|
course_dynamic_expose :count
|
|
course_dynamic_expose :news_count
|
|
course_dynamic_expose :document_count
|
|
course_dynamic_expose :topic_count
|
|
course_dynamic_expose :homework_count
|
|
course_dynamic_expose :homework_submit_students
|
|
course_dynamic_expose :homework_submit_num
|
|
course_dynamic_expose :homework_status
|
|
#在dynamics里解析出四种动态
|
|
expose :document,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
|
|
expose :topic,using:Mobile::Entities::Message do |f,opt|
|
|
obj = nil
|
|
f[:dynamics].each do |d|
|
|
if d[:type] == 2
|
|
obj = d[:topic]
|
|
end
|
|
end
|
|
obj
|
|
end
|
|
expose :homework,using:Mobile::Entities::Homework do |f,opt|
|
|
obj = nil
|
|
f[:dynamics].each do |d|
|
|
if d[:type] == 4
|
|
obj = d[:homework]
|
|
end
|
|
end
|
|
obj
|
|
end
|
|
|
|
expose :news,using:Mobile::Entities::News do |f,opt|
|
|
obj = nil
|
|
f[:dynamics].each do |d|
|
|
if d[:type] == 1
|
|
obj = d
|
|
end
|
|
end
|
|
obj
|
|
end
|
|
|
|
end
|
|
end
|
|
end |