From 70083789cb82078c776b4f58745fad9a70fb203e Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Mon, 29 Dec 2014 16:59:22 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E5=8C=BF=E8=AF=84=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=9F=A5=E8=AF=A2=E6=9C=89=E9=94=99=202.=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=BD=93=E8=BA=AB=E4=BB=BD=E6=94=B9=E5=8F=98=E6=97=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=86=E6=95=B0=E5=88=9D=E5=A7=8B=E5=88=86?= =?UTF-8?q?=E6=95=B0=E4=B8=BA=E4=B9=8B=E5=89=8D=E8=BA=AB=E4=BB=BD=E7=9A=84?= =?UTF-8?q?=E8=AF=84=E5=88=86=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=B8=BA=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B9=8B=E5=89=8D=E8=BA=AB=E4=BB=BD=E7=9A=84=E8=AF=84?= =?UTF-8?q?=E5=88=86=E7=9A=84BUG=203.=E6=98=AF=E5=90=A6=E5=B7=B2=E7=BB=8F?= =?UTF-8?q?=E8=AF=84=E5=88=86=E5=88=A4=E6=96=AD=E5=A2=9E=E5=8A=A0=E5=9C=A8?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E8=A7=92=E8=89=B2=E4=B8=8B=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E8=AF=84=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bids_controller.rb | 6 ++--- app/controllers/homework_attach_controller.rb | 22 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index eaeca0e46..e3b8b9a66 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -493,17 +493,17 @@ class BidsController < ApplicationController @homework = HomeworkAttach.new @is_teacher = is_course_teacher(User.current,@bid.courses.first) if @is_teacher - all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, + all_homework_list = HomeworkAttach.find_by_sql("SELECT * FROM (SELECT homework_attaches.*, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY s_score DESC,created_at ASC) AS table1 WHERE table1.t_score IS NULL") @cur_type = 1 else - all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, + all_homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score, - (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id}) AS m_score + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id} AND is_teacher_score = #{@is_teacher ? 1 : 0}) AS m_score FROM homework_attaches INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id WHERE homework_attaches.bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id} ORDER BY s_score DESC") diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index fedc99030..9ca47afdd 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -86,7 +86,7 @@ class HomeworkAttachController < ApplicationController all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score, - (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id}) AS m_score + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id} AND is_teacher_score = 0) AS m_score FROM homework_attaches INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id WHERE homework_attaches.bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id} ORDER BY m_score DESC") @@ -353,11 +353,11 @@ class HomeworkAttachController < ApplicationController # 作业打分列表 @stars_reates = @homework.rates(:quality) #我的评分 - @has_evaluation = @stars_reates.where("rater_id = #{User.current.id}").first + @is_teacher = is_course_teacher User.current,@course + @has_evaluation = @stars_reates.where("rater_id = #{User.current.id} and is_teacher_score=#{@is_teacher ? 1 : 0}").first @m_score = @has_evaluation.nil? ? 0 : @has_evaluation.stars @teacher_stars = @stars_reates.where("is_teacher_score = 1") #老师评分列表 @student_stars = @stars_reates.where("is_teacher_score = 0") #学生评分列表 - @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 #留言 @@ -418,15 +418,15 @@ class HomeworkAttachController < ApplicationController @is_teacher,@is_anonymous_comments,@m_score = params[:is_teacher]=="true",params[:is_anonymous_comments]=="true",params[:stars_value] @cur_page,@cur_type = params[:cur_page] || 1,params[:cur_type] || 5 @homework = HomeworkAttach.find(params[:homework_id]) - + is_teacher = @is_teacher ? 1 : 0 #保存评分@homework.rate(@m_score.to_i,User.current.id,:quality, (@is_teacher ? 1 : 0)) if @m_score - if @homework.has_rated?(User.current, :quality) - rate = @homework.rates(:quality).where(:rater_id => User.current.id).first + rate = @homework.rates(:quality).where(:rater_id => User.current.id, :is_teacher_score => is_teacher).first + if rate rate.stars = @m_score rate.save! else - @homework.rates(:quality).new(:stars => @m_score, :rater_id => User.current.id, :is_teacher_score => (@is_teacher ? 1 : 0)).save! + @homework.rates(:quality).new(:stars => @m_score, :rater_id => User.current.id, :is_teacher_score => is_teacher).save! end end #保存评论 @@ -445,21 +445,21 @@ class HomeworkAttachController < ApplicationController @bid = @homework.bid get_not_batch_homework_list "s_socre","desc",@homework.bid_id elsif @cur_type == "2" #老师已批列表 - @result_homework = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, + @result_homework = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 and stars IS NOT NULL) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE id = #{@homework.id}").first elsif @cur_type == "3" #全部作业列表 - @result_homework = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, + @result_homework = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE id = #{@homework.id}").first elsif @cur_type == "4" #匿评作业列表 @is_student_batch_homework = true - @result_homework = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, + @result_homework = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score, - (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id}) AS m_score + (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id} AND is_teacher_score = #{is_teacher}) AS m_score FROM homework_attaches WHERE homework_attaches.id = #{@homework.id}").first else #其他的不用管