2015-05-26 18:14:53 +08:00
|
|
|
# encoding: utf-8
|
2015-05-21 11:58:34 +08:00
|
|
|
module StudentWorkHelper
|
|
|
|
def user_projects_option
|
|
|
|
cond = Project.visible_condition(User.current) + " AND projects.project_type <> 1"
|
|
|
|
memberships = User.current.memberships.all(:conditions => cond)
|
|
|
|
projects = memberships.map(&:project)
|
|
|
|
not_have_project = []
|
|
|
|
not_have_project << Setting.please_chose
|
|
|
|
not_have_project << 0
|
|
|
|
type = []
|
|
|
|
type << not_have_project
|
|
|
|
projects.each do |project|
|
|
|
|
if project != nil
|
|
|
|
option = []
|
|
|
|
option << project.name
|
|
|
|
option << project.id
|
|
|
|
type << option
|
|
|
|
end
|
|
|
|
end
|
|
|
|
type
|
|
|
|
end
|
2015-05-26 18:14:53 +08:00
|
|
|
|
|
|
|
#获取指定用户对某一作业的评分结果
|
|
|
|
def student_work_score work,user
|
|
|
|
StudentWorksScore.where(:user_id => user.id,:student_work_id => work.id).first
|
|
|
|
end
|
2015-05-27 11:25:32 +08:00
|
|
|
|
|
|
|
#获取指定评分的角色
|
|
|
|
def student_work_score_role score
|
|
|
|
case score.reviewer_role
|
|
|
|
when 1
|
|
|
|
role = "教师"
|
|
|
|
when 2
|
2015-05-27 16:21:59 +08:00
|
|
|
role = "助教"
|
2015-05-27 11:25:32 +08:00
|
|
|
when 3
|
|
|
|
role = "学生"
|
|
|
|
end
|
|
|
|
end
|
2015-05-27 16:21:59 +08:00
|
|
|
|
|
|
|
def get_role_by_name role
|
|
|
|
case role
|
|
|
|
when "Teacher"
|
|
|
|
result = 1
|
|
|
|
when "Manager"
|
|
|
|
result = 1
|
|
|
|
when "TeachingAsistant"
|
|
|
|
result = 2
|
|
|
|
when "Student"
|
|
|
|
result = 3
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
2015-05-28 16:10:40 +08:00
|
|
|
|
|
|
|
#获取赞的总数
|
|
|
|
def praise_homework_count obj_id
|
|
|
|
PraiseTread.where("praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'StudentWork'").count
|
|
|
|
end
|
|
|
|
|
|
|
|
#判断指定用户是不是已经赞过该作业
|
|
|
|
def is_praise_homework user_id, obj_id
|
|
|
|
PraiseTread.where("user_id = #{user_id} AND praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'StudentWork'").empty?
|
|
|
|
end
|
2015-06-18 17:56:28 +08:00
|
|
|
|
|
|
|
#获取指定学生在指定作业内应匿评的数量
|
|
|
|
def all_evaluation_count user,homework
|
|
|
|
StudentWorksEvaluationDistribution.joins(:student_work).where("student_works_evaluation_distributions.user_id = #{user.id} AND student_works.homework_common_id = #{homework.id}").count
|
|
|
|
end
|
|
|
|
|
|
|
|
#获取指定学生在指定作业内已匿评的数量
|
|
|
|
def has_evaluation_count user,homework
|
|
|
|
StudentWorksScore.joins(:student_work).where("student_works_scores.user_id = #{user.id} AND student_works.homework_common_id = #{homework.id}").count
|
|
|
|
end
|
2015-06-19 13:56:55 +08:00
|
|
|
|
|
|
|
#传入分数,获取对应颜色
|
|
|
|
def score_color score
|
|
|
|
if score
|
|
|
|
color = score >= 90 ? "c_red" : "c_green"
|
|
|
|
else
|
|
|
|
color = "c_grey"
|
|
|
|
end
|
|
|
|
color
|
|
|
|
end
|
2015-05-21 11:58:34 +08:00
|
|
|
end
|