|
|
|
@ -48,7 +48,7 @@ class HomeworkAttachController < ApplicationController
|
|
|
|
|
order_by = "created_at #{direction}"
|
|
|
|
|
end
|
|
|
|
|
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).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 and stars IS NOT NULL) AS t_score,
|
|
|
|
|
(SELECT 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 ORDER BY updated_at DESC limit 0,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 #{order_by}) AS table1
|
|
|
|
@ -80,7 +80,7 @@ class HomeworkAttachController < ApplicationController
|
|
|
|
|
order_by = "created_at #{direction}"
|
|
|
|
|
end
|
|
|
|
|
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 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 ORDER BY updated_at DESC limit 0,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 #{order_by}")
|
|
|
|
@ -101,7 +101,7 @@ class HomeworkAttachController < ApplicationController
|
|
|
|
|
def get_student_batch_homework
|
|
|
|
|
@is_student_batch_homework = true
|
|
|
|
|
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 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 ORDER BY updated_at DESC limit 0,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} AND is_teacher_score = 0) AS m_score
|
|
|
|
|
FROM homework_attaches
|
|
|
|
@ -119,14 +119,14 @@ class HomeworkAttachController < ApplicationController
|
|
|
|
|
def get_my_homework
|
|
|
|
|
@is_my_homework = true
|
|
|
|
|
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 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 ORDER BY updated_at DESC limit 0,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 homework_attaches.bid_id = #{@bid.id} AND homework_attaches.user_id = #{User.current.id}")
|
|
|
|
|
#如果我没有创建过作业,就检索我是否参与了某个作业
|
|
|
|
|
if all_homework_list.empty?
|
|
|
|
|
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 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 ORDER BY updated_at DESC limit 0,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
|
|
|
|
|
INNER JOIN homework_users ON homework_users.homework_attach_id = homework_attaches.id
|
|
|
|
@ -435,17 +435,19 @@ 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])
|
|
|
|
|
@stars_reates = @homework.rates(:quality)
|
|
|
|
|
homework = @homework
|
|
|
|
|
is_teacher = @is_teacher ? 1 : 0
|
|
|
|
|
#保存评分@homework.rate(@m_score.to_i,User.current.id,:quality, (@is_teacher ? 1 : 0))
|
|
|
|
|
if @m_score
|
|
|
|
|
rate = @homework.rates(:quality).where(:rater_id => User.current.id, :is_teacher_score => is_teacher).first
|
|
|
|
|
rate = @homework.rates(:quality).where(:rater_id => User.current.id, :is_teacher_score => is_teacher).first
|
|
|
|
|
if @m_score && rate.stars != @m_score
|
|
|
|
|
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).save!
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if homework.is_teacher_score == 0
|
|
|
|
|
if is_teacher == 1
|
|
|
|
|
homework.score = @m_score
|
|
|
|
@ -470,7 +472,6 @@ class HomeworkAttachController < ApplicationController
|
|
|
|
|
@homework.addjours User.current.id, params[:new_form][:user_message],0,@is_comprehensive_evaluation
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@stars_reates = @homework.rates(:quality)
|
|
|
|
|
@teacher_stars = @stars_reates.where("is_teacher_score = 1") #老师评分列表
|
|
|
|
|
@student_stars = @stars_reates.where("is_teacher_score = 0") #学生评分列表
|
|
|
|
|
jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")#jours留言 is null条件用以兼容历史数据
|
|
|
|
@ -481,18 +482,18 @@ class HomeworkAttachController < ApplicationController
|
|
|
|
|
get_not_batch_homework_list "s_socre","desc",@homework.bid_id
|
|
|
|
|
elsif @cur_type == "2" #老师已批列表
|
|
|
|
|
@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 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 ORDER BY updated_at DESC limit 0,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 == "3" #全部作业列表
|
|
|
|
|
@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 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 ORDER BY updated_at DESC limit 0,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.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 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 ORDER BY updated_at DESC limit 0,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} AND is_teacher_score = #{is_teacher}) AS m_score
|
|
|
|
|
FROM homework_attaches
|
|
|
|
@ -596,7 +597,7 @@ class HomeworkAttachController < ApplicationController
|
|
|
|
|
order_by = "created_at #{direction}"
|
|
|
|
|
end
|
|
|
|
|
@all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).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 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 ORDER BY updated_at DESC limit 0,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 #{order_by}) AS table1
|
|
|
|
|