diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index d07ee9448..18d6a16ac 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -284,11 +284,6 @@ class HomeworkAttachController < ApplicationController end end - #获取指定作业的所有成员 - def users_for_homework homework - homework.nil? ? [] : (homework.users + [homework.user]) - end - #获取可选成员列表 #homework:作业 #users:该作业所有成员 @@ -359,53 +354,69 @@ class HomeworkAttachController < ApplicationController #显示作业信息 def show - if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first) - # 打分统计 - #stars_reates = @homework. rates(:quality) - #是否已经进行过评价 - temp = HomeworkAttach.find_by_sql("SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{@homework.id} AND rater_id = #{User.current.id}").first - @m_score = temp.nil? ? 0:temp.stars - @has_evaluation = @homework.has_rated?( User.current,:quality) - #@jours留言 is null条件用以兼容历史数据 - @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC") + if User.current.admin? || User.current.member_of_course?(@course) + # 作业打分列表 + @stars_reates = @homework.rates(:quality) + #我的评分 + @has_evaluation = @stars_reates.where("rater_id = #{User.current.id}").first + @m_score = @has_evaluation.nil? ? 0 : @has_evaluation.stars + teachers = find_course_teachers(@course) + @teacher_stars = @stars_reates.where("rater_id in (#{teachers})") #老师评分列表 + @student_stars = @stars_reates.where("rater_id not in (#{teachers})") #学生评分列表 + @is_teacher = is_course_teacher User.current,@course + @is_anonymous_comments = @bid.comment_status == 1 && !@homework.users.include?(User.current) && @homework.user != User.current && !@is_teacher #判断是不是匿评(开启匿评,当前用户不是作业的创建者或者参与者,不是老师) + jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")#jours留言 is null条件用以兼容历史数据 + @jour = paginateHelper jours,5 #留言 @cur_page = params[:cur_page] || 1 @cur_type = params[:cur_type] || 5 - @jour = paginateHelper @jours,5 - teachers = searchTeacherAndAssistant @course - @comprehensive_evaluation = [] - #JourForMessage的is_comprehensive_evaluation字段: - #1:老师评价 - #2:学生评价 - #3 || null:学生留言 - teachers.each do|teacher| - temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first - @comprehensive_evaluation << temp if temp - end - annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',') - unless annymous_users.nil? || annymous_users == "" - @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC") - end - #@totle_score = score_for_homework @homework - #@teaher_score = teacher_score_for_homework @homework - - #is_student = is_cur_course_student @homework.bid.courses.first - @is_teacher = is_course_teacher User.current,@homework.bid.courses.first - @is_anonymous_comments = @homework.bid.comment_status == 1 #是否开启了匿评 - #@is_comprehensive_evaluation 1:教师评论,2:学生匿评,3:学生留言 - if User.current.member_of_course?(@homework.bid.courses.first) - if @is_teacher - @is_comprehensive_evaluation = 1 #教师评论 - else - if @is_anonymous_comments && !@has_evaluation #是学生且开启了匿评且未进行评分 - @is_comprehensive_evaluation = 2 #匿评 - else #是学生未开启匿评或者已经进行评分 - @is_comprehensive_evaluation = 3 #留言 - end - end - else - @is_comprehensive_evaluation = 3 - end + #if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first) + # # 打分统计 + # #stars_reates = @homework. rates(:quality) + # #是否已经进行过评价 + # temp = HomeworkAttach.find_by_sql("SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{@homework.id} AND rater_id = #{User.current.id}").first + # @m_score = temp.nil? ? 0:temp.stars + # @has_evaluation = @homework.has_rated?( User.current,:quality) + # #@jours留言 is null条件用以兼容历史数据 + # @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC") + # @cur_page = params[:cur_page] || 1 + # @cur_type = params[:cur_type] || 5 + # @jour = paginateHelper @jours,5 + # + # teachers = searchTeacherAndAssistant @course + # @comprehensive_evaluation = [] + # #JourForMessage的is_comprehensive_evaluation字段: + # #1:老师评价 + # #2:学生评价 + # #3 || null:学生留言 + # teachers.each do|teacher| + # temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first + # @comprehensive_evaluation << temp if temp + # end + # annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',') + # unless annymous_users.nil? || annymous_users == "" + # @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC") + # end + # #@totle_score = score_for_homework @homework + # #@teaher_score = teacher_score_for_homework @homework + # + # #is_student = is_cur_course_student @homework.bid.courses.first + # @is_teacher = is_course_teacher User.current,@homework.bid.courses.first + # @is_anonymous_comments = @homework.bid.comment_status == 1 #是否开启了匿评 + # #@is_comprehensive_evaluation 1:教师评论,2:学生匿评,3:学生留言 + # if User.current.member_of_course?(@homework.bid.courses.first) + # if @is_teacher + # @is_comprehensive_evaluation = 1 #教师评论 + # else + # if @is_anonymous_comments && !@has_evaluation #是学生且开启了匿评且未进行评分 + # @is_comprehensive_evaluation = 2 #匿评 + # else #是学生未开启匿评或者已经进行评分 + # @is_comprehensive_evaluation = 3 #留言 + # end + # end + # else + # @is_comprehensive_evaluation = 3 + # end respond_to do |format| format.html @@ -622,5 +633,10 @@ class HomeworkAttachController < ApplicationController WHERE table1.t_score IS NULL") @homework_list = paginateHelper all_homework_list,10 end + + #获取指定作业的所有成员 + def users_for_homework homework + homework.nil? ? [] : (homework.users + [homework.user]) + end end diff --git a/app/helpers/homework_attach_helper.rb b/app/helpers/homework_attach_helper.rb index 1ab1cb928..4744df624 100644 --- a/app/helpers/homework_attach_helper.rb +++ b/app/helpers/homework_attach_helper.rb @@ -91,6 +91,11 @@ module HomeworkAttachHelper @m_score = temp.nil? ? 0:temp.stars.to_i end + #获取评分对应的评论 + def get_homework_review homework,is_teacher,user + homework.journals_for_messages.where("is_comprehensive_evaluation = #{is_teacher ? 1 : 2} and user_id = #{user.id}").order("created_on DESC").first + end + def convert_array array ary = "(" if array.nil? || array.count == 0 diff --git a/app/views/homework_attach/_addjour.html.erb b/app/views/homework_attach/_addjour.html.erb index 8949e1ac1..bb5b21f5f 100644 --- a/app/views/homework_attach/_addjour.html.erb +++ b/app/views/homework_attach/_addjour.html.erb @@ -1,35 +1,4 @@