2016-06-27 16:03:07 +08:00
|
|
|
module Mobile
|
|
|
|
module Entities
|
|
|
|
class Exercise < Grape::Entity
|
2016-07-14 16:54:43 +08:00
|
|
|
include Redmine::I18n
|
|
|
|
include ApplicationHelper
|
|
|
|
include ApiHelper
|
|
|
|
def self.exercise_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?(::Exercise)
|
|
|
|
if f.respond_to?(field)
|
|
|
|
f.send(field)
|
|
|
|
else
|
|
|
|
case field
|
|
|
|
when :coursename
|
|
|
|
f.course.nil? ? "" : f.course.name
|
2016-09-19 13:53:15 +08:00
|
|
|
when :syllabus_title
|
|
|
|
f.course.nil? ? "" : f.course.syllabus.nil? ? "" : f.course.syllabus.title
|
2016-07-14 16:54:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-27 16:03:07 +08:00
|
|
|
expose :exercise_name
|
|
|
|
expose :exercise_description
|
2016-07-14 16:54:43 +08:00
|
|
|
exercise_expose :coursename #所属班级名
|
2016-09-19 13:53:15 +08:00
|
|
|
exercise_expose :syllabus_title
|
2016-07-18 14:24:59 +08:00
|
|
|
|
|
|
|
expose :current_user_is_teacher, if: lambda { |instance, options| options[:user] } do |instance, options|
|
|
|
|
current_user = options[:user]
|
|
|
|
current_user_is_teacher = false
|
|
|
|
current_user_is_teacher = is_course_teacher(current_user,instance.course)
|
|
|
|
current_user_is_teacher
|
|
|
|
end
|
|
|
|
|
2016-06-27 16:03:07 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|