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

90 lines
3.0 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 这个模块由于作业模块的改变,里边的注释以及属性不可信
module Mobile
module Entities
class Homework < Grape::Entity
include Redmine::I18n
include ApplicationHelper
include ApiHelper
def self.homework_expose(field)
expose field do |f,opt|
if f.is_a?(Hash) && f.key?(field)
if field == :created_on
format_time(f[field])
else
f[field]
end
elsif f.is_a?(::HomeworkCommon)
if f.respond_to?(field)
f.send(field)
else
case field
when :homework_name
f.send(:name)
when :homework_notsubmit_num
f.course.members.count - f.student_works.count
when :homework_submit_num
f.student_works.count
when :homework_status
get_homework_status f
when :homework_times
f.course.homework_commons.index(f) + 1
when :homework_status_desc
homework_status_desc f
end
end
end
end
end
#作业id
homework_expose :id
#课程名称
homework_expose :course_name
homework_expose :course_id
#作业发布者
expose :author,using: Mobile::Entities::User do |f, opt|
f[:author]
end
#作业发布者真名
homework_expose :author_real_name
#作业次数
homework_expose :homework_times
#作业名称
homework_expose :homework_name
#已提交的作业数量
homework_expose :homework_count
#学生提问数量
homework_expose :student_questions_count
#作业描述
homework_expose :description
#作业是否启用匿评功能 0不启用1启用
homework_expose :open_anonymous_evaluation
#作业状态 0:新建1已开启匿评2已关闭匿评
#只有作业启用了匿评功能且当前用户是课程老师且已提交的作品数量大于或等于2才能开启匿评
homework_expose :homework_state
homework_expose :created_on
homework_expose :deadline
expose :jours,using: Mobile::Entities::Jours do |f, opt|
f[:jours] if f.is_a?(Hash) && f.key?(:jours)
end
expose :homework_for_anonymous_comments,using: Mobile::Entities::HomeworkAttach do |f, opt|
f[:homework_for_anonymous_comments] if f.is_a?(Hash) && f.key?(:homework_for_anonymous_comments)
end
homework_expose :homework_submit_num
homework_expose :homework_notsubmit_num
expose :submit_student_list ,using: Mobile::Entities::User do |f,opt|
get_submit_sutdent_list f
end
homework_expose :homework_status #作业的状态
homework_expose :homework_status_desc #状态的解释
end
end
end