# encoding: utf-8
module HomeworkCommonHelper
#获取匿评相关连接代码
def homework_anonymous_comment homework
if homework.homework_type == 1 && homework.homework_detail_manual #匿评作业
if homework.student_works.count >= 2 #作业份数大于2
case homework.homework_detail_manual.comment_status
when 1
link = link_to '启动匿评', alert_anonymous_comment_homework_common_path(homework), id: "#{homework.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'fr mr10 work_edit'
when 2
link = link_to '关闭匿评', alert_anonymous_comment_homework_common_path(homework), id: "#{homework.id}_stop_anonymous_comment", remote: true,:class => 'fr mr10 work_edit'
when 3
link = "匿评结束".html_safe
end
else
link = "启动匿评".html_safe
end
else
link = "启动匿评".html_safe
end
link
end
def student_new_homework homework
work = cur_user_works_for_homework homework
if work.nil?
link_to l(:label_commit_homework), new_student_work_path(:homework => homework.id),:class => 'fr mr10 work_edit'
else
if homework.homework_type == 2 && homework.homework_detail_manual && homework.homework_detail_manual.comment_status != 1 #匿评作业,且作业状态不是在开启匿评之前
"#{l(:label_edit_homework)}".html_safe
else
link_to l(:label_edit_homework), edit_student_work_path(work.id),:class => 'fr mr10 work_edit'
end
end
end
def student_anonymous_comment homework
if homework.homework_type == 1 && homework.homework_detail_manual
case homework.homework_detail_manual.comment_status
when 1
"未开启匿评".html_safe
when 2
"正在匿评中".html_safe
when 3
"匿评已结束".html_safe
end
elsif homework.homework_type == 0
"未启用匿评".html_safe
elsif homework.homework_type == 2
"编程作业".html_safe
end
end
#获取当前用户在指定作业下提交的作业的集合
def cur_user_works_for_homework homework
homework.student_works.where("user_id = ?",User.current).first
end
#迟交扣分下拉框
def late_penalty_option
type = []
for i in (1..5)
option = []
option << i
option << i
type << option
end
type
end
#教辅评分比例下拉框
def ta_proportion_option
type = []
i = 10
while i <= 100
option = []
option << i.to_s + "%"
option << i.to_f / 100
type << option
i += 10
end
type
end
#缺评扣分
def absence_penalty_option
type = []
i = 1
while i <= 5
option = []
option << i
option << i
type << option
i += 1
end
type
end
end