diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 9393339a8..e5e1bf391 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -63,7 +63,7 @@ class StudentWorkController < ApplicationController journal_for_teacher.update_attributes(:viewed => true) end #不能参与作业匿评消息状态更新 - no_evaluation = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @homework.course, "NoEvaluation", 0) + no_evaluation = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =? and status =?", User.current.id, @homework.course, "StudentWork", 0, 0) no_evaluation.update_all(:viewed => true) # 作品留言 # 消息end @@ -144,6 +144,10 @@ class StudentWorkController < ApplicationController end def new + #更新消息 + noEvaluation = @homework.course_messages.where("user_id =? and viewed =?", User.current.id, 0) + noEvaluation.update_all(:viewed => true) + if @homework.homework_type==2 redirect_to new_user_commit_homework_users_path(homework_id: @homework.id) return diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ef3210719..7adba7cbf 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -128,7 +128,7 @@ class UsersController < ApplicationController #课程相关消息 when 'homework' - @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','NoEvaluation') and user_id =?", @user).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork') and user_id =?", @user).order("created_at desc") when 'course_message' @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user).order("created_at desc") when 'course_news' diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 700613792..010ede635 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -8,6 +8,8 @@ class StudentWork < ActiveRecord::Base has_many :student_works_scores, :dependent => :destroy belongs_to :project has_many :student_work_tests, order: 'id desc' + # course's message + has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy before_destroy :delete_praise before_save :set_program_score, :set_src @@ -138,10 +140,10 @@ class StudentWork < ActiveRecord::Base end end + # status == 0 : delay def act_as_message if self.created_at > self.homework_common.end_time + 1 - CourseMessage.create(:user_id => self.user_id, :course_id => self.homework_common.course_id, - :course_message_id => self.id, :course_message_type => 'NoEvaluation',:viewed => false) + self.course_messages << CourseMessage.new(:user_id => self.user_id, :course_id => self.homework_common.course_id, :viewed => false, :status => false) end end end diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb index 6c22976fd..86b44f66d 100644 --- a/app/views/users/_user_message_course.html.erb +++ b/app/views/users/_user_message_course.html.erb @@ -37,7 +37,7 @@