2015-06-19 15:05:25 +08:00
|
|
|
|
# 这个模块由于作业模块的改变,里边的注释以及属性不可信
|
2015-01-20 15:17:02 +08:00
|
|
|
|
module Mobile
|
|
|
|
|
module Entities
|
|
|
|
|
class Homework < Grape::Entity
|
2015-03-03 17:36:05 +08:00
|
|
|
|
include Redmine::I18n
|
2015-06-30 15:17:22 +08:00
|
|
|
|
include ApplicationHelper
|
|
|
|
|
include ApiHelper
|
2015-01-20 15:17:02 +08:00
|
|
|
|
def self.homework_expose(field)
|
|
|
|
|
expose field do |f,opt|
|
|
|
|
|
if f.is_a?(Hash) && f.key?(field)
|
2015-03-03 17:36:05 +08:00
|
|
|
|
if field == :created_on
|
|
|
|
|
format_time(f[field])
|
|
|
|
|
else
|
|
|
|
|
f[field]
|
|
|
|
|
end
|
2015-06-08 17:16:34 +08:00
|
|
|
|
elsif f.is_a?(::HomeworkCommon)
|
2015-01-21 11:28:09 +08:00
|
|
|
|
if f.respond_to?(field)
|
|
|
|
|
f.send(field)
|
|
|
|
|
else
|
2015-06-19 15:05:25 +08:00
|
|
|
|
case field
|
|
|
|
|
when :homework_name
|
|
|
|
|
f.send(:name)
|
|
|
|
|
when :homework_notsubmit_num
|
|
|
|
|
f.course.members.count - f.student_works.count
|
2015-06-30 15:17:22 +08:00
|
|
|
|
when :homework_submit_num
|
|
|
|
|
f.student_works.count
|
2015-07-04 15:53:01 +08:00
|
|
|
|
when :homework_status_student
|
2015-06-30 15:17:22 +08:00
|
|
|
|
get_homework_status f
|
2015-07-02 17:31:30 +08:00
|
|
|
|
when :homework_times
|
|
|
|
|
f.course.homework_commons.index(f) + 1
|
2015-07-04 15:53:01 +08:00
|
|
|
|
when :homework_status_teacher
|
2015-07-03 12:22:33 +08:00
|
|
|
|
homework_status_desc f
|
2015-07-07 17:18:29 +08:00
|
|
|
|
when :student_evaluation_part
|
|
|
|
|
get_evaluation_part f ,3
|
|
|
|
|
when :ta_evaluation_part
|
|
|
|
|
get_evaluation_part f , 2
|
|
|
|
|
when :homework_anony_type
|
|
|
|
|
val = f.homework_type == 1 && !f.homework_detail_manual.nil?
|
|
|
|
|
val
|
2016-07-14 16:54:43 +08:00
|
|
|
|
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
|
2015-06-19 15:05:25 +08:00
|
|
|
|
end
|
2015-01-21 11:28:09 +08:00
|
|
|
|
end
|
2015-01-20 15:17:02 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
#作业id
|
|
|
|
|
homework_expose :id
|
|
|
|
|
#课程名称
|
|
|
|
|
homework_expose :course_name
|
2015-03-03 17:36:05 +08:00
|
|
|
|
|
2016-09-19 13:53:15 +08:00
|
|
|
|
homework_expose :syllabus_title
|
|
|
|
|
|
2015-03-03 17:36:05 +08:00
|
|
|
|
homework_expose :course_id
|
2015-03-01 17:31:38 +08:00
|
|
|
|
#作业发布者
|
|
|
|
|
expose :author,using: Mobile::Entities::User do |f, opt|
|
|
|
|
|
f[:author]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#作业发布者真名
|
|
|
|
|
homework_expose :author_real_name
|
|
|
|
|
|
2015-01-20 15:17:02 +08:00
|
|
|
|
#作业次数
|
|
|
|
|
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
|
2015-01-30 16:58:05 +08:00
|
|
|
|
|
2015-03-03 17:36:05 +08:00
|
|
|
|
homework_expose :created_on
|
|
|
|
|
homework_expose :deadline
|
|
|
|
|
|
2015-03-04 17:04:07 +08:00
|
|
|
|
expose :jours,using: Mobile::Entities::Jours do |f, opt|
|
|
|
|
|
f[:jours] if f.is_a?(Hash) && f.key?(:jours)
|
|
|
|
|
end
|
|
|
|
|
|
2015-01-30 16:58:05 +08:00
|
|
|
|
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
|
|
|
|
|
|
2015-06-30 15:17:22 +08:00
|
|
|
|
homework_expose :homework_submit_num
|
2015-06-19 15:05:25 +08:00
|
|
|
|
homework_expose :homework_notsubmit_num
|
|
|
|
|
|
2015-07-07 17:18:29 +08:00
|
|
|
|
homework_expose :homework_status_student #学生看到的作业的状态
|
2015-07-04 15:53:01 +08:00
|
|
|
|
homework_expose :homework_status_teacher #老师看到的状态
|
2015-06-26 09:18:12 +08:00
|
|
|
|
|
2015-07-07 17:18:29 +08:00
|
|
|
|
homework_expose :student_evaluation_part #学生匿评比率
|
|
|
|
|
homework_expose :ta_evaluation_part #教辅评价比率
|
|
|
|
|
|
|
|
|
|
homework_expose :homework_anony_type #是否是匿评作业
|
|
|
|
|
|
2016-07-12 10:25:18 +08:00
|
|
|
|
homework_expose :coursename #所属班级名
|
|
|
|
|
|
2016-07-18 14:24:59 +08:00
|
|
|
|
expose :current_user_is_teacher, if: lambda { |instance, options| options[:user] } do |instance, options|
|
2016-07-21 15:21:09 +08:00
|
|
|
|
if instance[:current_user_is_teacher].nil?
|
|
|
|
|
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-07-18 14:24:59 +08:00
|
|
|
|
end
|
2015-01-20 15:17:02 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|