module Mobile module Entities class CourseDynamic < Grape::Entity include Redmine::I18n def self.course_dynamic_expose(field) expose field do |c,opt| # 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)) # end end end 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 :news_count course_dynamic_expose :document_count course_dynamic_expose :topic_count course_dynamic_expose :homework_count course_dynamic_expose :course_student_num course_dynamic_expose :time_from_now course_dynamic_expose :current_user_is_member course_dynamic_expose :current_user_is_teacher # 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 expose :topics,using:Mobile::Entities::Message do |f,opt| f[:topics] end expose :homeworks,using:Mobile::Entities::Homework do |f,opt| f[:homeworks] end expose :news,using:Mobile::Entities::News do |f,opt| f[:news] end expose :better_students,using:Mobile::Entities::User do |f,opt| f[:better_students] end expose :active_students,using:Mobile::Entities::User do |f,opt| f[:active_students] end end end end