diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index d07ee9448..4a070cb39 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,21 @@ 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 respond_to do |format| format.html @@ -418,27 +381,40 @@ class HomeworkAttachController < ApplicationController #删除留言 def destroy_jour - @homework = HomeworkAttach.find(params[:jour_id]) - @course=@homework.bid.courses.first + @homework = HomeworkAttach.find(params[:homework_id]) @journal_destroyed = JournalsForMessage.find(params[:object_id]) - @is_comprehensive_evaluation = @journal_destroyed.is_comprehensive_evaluation - @journal_destroyed.destroy - if @is_comprehensive_evaluation == 3 - @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC") - @jour = paginateHelper @jours,5 - elsif @is_comprehensive_evaluation == 2 - annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',') - unless annymous_users.nil? || annymous_users.count == "" - @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC") - end - elsif @is_comprehensive_evaluation == 1 - teachers = searchTeacherAndAssistant @course - @comprehensive_evaluation = [] - 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 + if @journal_destroyed.is_comprehensive_evaluation == 3 && @journal_destroyed.destroy + render_403 unless User.current == @journal_destroyed.user || User.current.admin? + teachers = find_course_teachers(@homework.bid.courses.first) + @stars_reates = @homework.rates(:quality) + @teacher_stars = @stars_reates.where("rater_id in (#{teachers})") #老师评分列表 + @student_stars = @stars_reates.where("rater_id not in (#{teachers})") #学生评分列表 + 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 #留言 + else + render_404 end + + #@course=@homework.bid.courses.first + #@journal_destroyed = JournalsForMessage.find(params[:object_id]) + #@is_comprehensive_evaluation = @journal_destroyed.is_comprehensive_evaluation + #@journal_destroyed.destroy + #if @is_comprehensive_evaluation == 3 + # @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC") + # @jour = paginateHelper @jours,5 + #elsif @is_comprehensive_evaluation == 2 + # annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',') + # unless annymous_users.nil? || annymous_users.count == "" + # @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC") + # end + #elsif @is_comprehensive_evaluation == 1 + # teachers = searchTeacherAndAssistant @course + # @comprehensive_evaluation = [] + # 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 + #end respond_to do |format| format.js end @@ -446,79 +422,49 @@ class HomeworkAttachController < ApplicationController #添加留言 def addjours - @homework = HomeworkAttach.find(params[:jour_id]) + @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]) + #保存评分 - @homework.rate(params[:stars_value],User.current.id,:quality) if params[:stars_value] && params[:stars_value] != "0" + @homework.rate(@m_score,User.current.id,:quality) if @m_score && @m_score != "0" #保存评论 - @cur_is_comprehensive_evaluation = params[:is_comprehensive_evaluation] - if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" #有没有留言 - @homework.addjours User.current.id, params[:new_form][:user_message],0,@cur_is_comprehensive_evaluation + @is_comprehensive_evaluation = @is_teacher ? 1 : (@is_anonymous_comments ? 2 : 3) #判断当前评论是老师评论?匿评?留言 + if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" #有没有留言 + @homework.addjours User.current.id, params[:new_form][:user_message],0,@is_comprehensive_evaluation end - @cur_page = params[:cur_page] || 1 - @cur_type = params[:cur_type] || 5 - teachers = searchTeacherAndAssistant @homework.bid.courses.first - if @cur_is_comprehensive_evaluation == "3" - @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC") - @jour = paginateHelper @jours,5 - elsif @cur_is_comprehensive_evaluation == "2" - 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 - @m_score = params[:stars_value].to_i - elsif @cur_is_comprehensive_evaluation == "1" - @comprehensive_evaluation = [] - 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 - end + teachers = find_course_teachers(@homework.bid.courses.first) + @stars_reates = @homework.rates(:quality) + @teacher_stars = @stars_reates.where("rater_id in (#{teachers})") #老师评分列表 + @student_stars = @stars_reates.where("rater_id not in (#{teachers})") #学生评分列表 + 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 #留言 - 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 - - #teachers = find_course_teachers @homework.bid.courses.first - teachers_str = teachers.map{|teacher| teacher.user_id}.join(",") if @cur_type == "1" #如果当前是老师未批列表,需要刷新整个作业列表界面 @bid = @homework.bid - get_not_batch_homework_list "s_socre","desc",teachers_str,@homework.bid_id + get_not_batch_homework_list "s_socre","desc",teachers,@homework.bid_id elsif @cur_type == "2" #老师已批列表 @result_homework = 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 rater_id IN (#{teachers_str}) 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 rater_id NOT IN (#{teachers_str})) AS s_score + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers}) 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 rater_id NOT IN (#{teachers})) 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.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in (#{teachers_str})) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in (#{teachers_str})) AS s_score + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in (#{teachers})) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in (#{teachers})) 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.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers_str})) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers_str})) AS s_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers})) AS t_score, + (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) 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 FROM homework_attaches WHERE homework_attaches.id = #{@homework.id}").first else #其他的不用管 end - respond_to do |format| format.js end @@ -622,5 +568,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/files_helper.rb b/app/helpers/files_helper.rb index 5683b9a05..2cd6b4400 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -1,5 +1,6 @@ # encoding: utf-8 module FilesHelper + include AttachmentsHelper def downloadAll containers paths = [] @@ -54,11 +55,11 @@ module FilesHelper s.html_safe end - #判断用户是否拥有除current_course以外的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期 - def has_course? user,current_course + #判断用户是否拥有不包含当前资源的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期 + def has_course? user,file result = false user.courses.each do |course| - if current_course.id != course.id && is_course_teacher(User.current,course) && course_in_current_or_next_term(course) + if !course_contains_attachment?(course,file) && is_course_teacher(User.current,course) && course_in_current_or_next_term(course) return true 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/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 58fbcb2e9..a006ef8ab 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -20,7 +20,7 @@ <%= link_to_attachment file, :download => true,:text => truncate(file.filename,length: 35, omission: '...'), :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %> <% if User.current.logged? %> <% if is_course_teacher(User.current,@course) && file.author_id == User.current.id %> - <%= link_to("选入我的其他课程",quote_resource_show_course_file_path(@course,file),:class => "f_l re_select",:remote => true) if has_course?(User.current,@course) %> + <%= link_to("选入我的其他课程",quote_resource_show_course_file_path(@course,file),:class => "f_l re_select",:remote => true) if has_course?(User.current,file) %> <% if delete_allowed && file.container_id == @course.id && file.container_type == "Course" %> @@ -30,7 +30,7 @@ <% end %> <% else %> - <%= link_to("选入我的课程",quote_resource_show_course_file_path(@course,file),:class => "f_l re_select",:remote => true) if has_course?(User.current,@course) %> + <%= link_to("选入我的课程",quote_resource_show_course_file_path(@course,file),:class => "f_l re_select",:remote => true) if has_course?(User.current,file) %> <% end %> <% else %> <% end %> diff --git a/app/views/homework_attach/_addjour.html.erb b/app/views/homework_attach/_addjour.html.erb index 79a7711c7..f2a3a9542 100644 --- a/app/views/homework_attach/_addjour.html.erb +++ b/app/views/homework_attach/_addjour.html.erb @@ -1,35 +1,4 @@