You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/helpers/subjects_helper.rb

35 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

module SubjectsHelper
# 实训路径的发布状态
def publish_status subject, is_manager, user, shixuns
status = -1
if is_manager
status = 0 if subject.status == 0 && shixuns.count > 0
status = 1 if subject.status == 1
status = 2 if subject.status == 2 && user.admin?
end
status
end
# 实训路径的所有用户获得的标签
def user_shixun_tags challenge_ids, user_id
ChallengeTag.joins("join games on challenge_tags.challenge_id = games.challenge_id").
where(challenge_id: challenge_ids, games: {status: 2, user_id: user_id}).pluck("challenge_tags.name").uniq
end
# 金课的课堂状态 0未开课1进行中2已结束
def subject_course_status course
if course.is_end
{status: 2, time: ""}
elsif course.start_date && course.start_date > Date.today
{status: 0, time: ""}
elsif course.start_date && course.start_date <= Date.today && course.end_date >= Date.today
sum_week = (((course.end_date - course.start_date).to_i + 1) / 7.0).ceil
curr_week = (((Date.today - course.start_date).to_i + 1) / 7.0).ceil
{status: 1, time: "进行至第#{curr_week}周,共#{sum_week}"}
else
{status: -1, time: ""}
end
end
end