trustieplus/app/helpers/subjects_helper.rb

24 lines
766 B
Ruby

module SubjectsHelper
def subject_co_users subject
shixuns = Shixun.where(:id => subject.stage_shixuns.map(&:shixun_id))
co_users = User.where(:id => shixuns.map(&:user_id)).where("id != #{subject.user_id}")
end
def subject_data subject
result = {}
subject_choices = 0
subject_shixuns = 0
subject_score = 0
subject.stage_shixuns.each do |stage_shixun|
shixun = stage_shixun.shixun
subject_choices += shixun.challenges.where(:st => [1, 2]).count
subject_shixuns += shixun.challenges.where(:st => 0).count
subject_score += shixun.shixun_score
end
result[:subject_choices] = subject_choices
result[:subject_shixuns] = subject_shixuns
result[:subject_score] = subject_score
result
end
end