From 6553559929f76759cc83849f7bfe772154488058 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Fri, 4 Dec 2015 10:56:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 4 ++ app/controllers/users_controller.rb | 4 +- app/models/exercise.rb | 14 ++++ app/views/users/_user_message_course.html.erb | 70 +++++++++++++++++++ .../exercise_close_to_deadline_warn.rake | 22 ++++++ lib/tasks/exercise_publishtime.rake | 22 ++++++ 6 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 lib/tasks/exercise_close_to_deadline_warn.rake create mode 100644 lib/tasks/exercise_publishtime.rake diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 6d6d429b6..db09c50a5 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -316,6 +316,9 @@ class ExerciseController < ApplicationController @exercise.exercise_status = 2 @exercise.publish_time = Time.now if @exercise.save + @exercise.course.members.each do |m| + @exercise.course_messages << CourseMessage.create(:user_id =>m.user_id, :course_id => @exercise.course.id, :viewed => false,:status=>2) + end #redirect_to exercise_index_url(:course_id=> @course.id) respond_to do |format| format.js @@ -331,6 +334,7 @@ class ExerciseController < ApplicationController @exercise.exercise_questions.each do |exercise_question| exercise_question.exercise_answers.destroy_all end + @exercise.course_messages.destroy_all @exercise.exercise_users.destroy_all @exercise.exercise_status = 1 @exercise.publish_time = nil diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 626bb59fc..834009d71 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -92,7 +92,7 @@ class UsersController < ApplicationController end # 用户消息 - # 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅;works_reply:作品回复 + # 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅;works_reply:作品回复,exercise:课程测验 # issue:问题;journal:缺陷状态更新; forum:公共贴吧: user_feedback: 用户留言; new_reply:新闻回复(comment) def user_messages if !User.current.logged? @@ -128,7 +128,7 @@ class UsersController < ApplicationController #课程相关消息 when 'homework' - @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork') and user_id =?", @user).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') 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/exercise.rb b/app/models/exercise.rb index d23e8f115..c91e59fd9 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -6,4 +6,18 @@ class Exercise < ActiveRecord::Base has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number" has_many :exercise_users, :dependent => :destroy has_many :users, :through => :exercise_users #该测试被哪些用户提交答案过 + # 课程消息 + has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy + after_create :acts_as_course_message + def acts_as_course_message + if self.course + if self.exercise_status == 2 #未发布 + #self.course.members.each do |m| + self.course_messages << CourseMessage.create(:user_id => User.current.id, :course_id => self.course_id, :viewed => false,:status=>2) + #end + # else + # self.course_messages.destroy_all 这里的destory_all值得商榷。因为我这里是通过status来控制不同的status的 + end + end + end end diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb index 9f2c9b9ef..566677964 100644 --- a/app/views/users/_user_message_course.html.erb +++ b/app/views/users/_user_message_course.html.erb @@ -612,4 +612,74 @@
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> + + + <% if ma.course_message_type == "Exercise" && ma.status == 2 %> + + <% end %> + + + <% if ma.course_message_type == "Exercise" && ma.status == 3 %> + + <% end %> <% end %> \ No newline at end of file diff --git a/lib/tasks/exercise_close_to_deadline_warn.rake b/lib/tasks/exercise_close_to_deadline_warn.rake new file mode 100644 index 000000000..2af513ee8 --- /dev/null +++ b/lib/tasks/exercise_close_to_deadline_warn.rake @@ -0,0 +1,22 @@ +#coding=utf-8 + +namespace :exercise_deadline_warn do + desc "exercise deadline warn" + task :deadline_warn => :environment do + exercises = Exercise.where("date_format(end_time,'%Y-%m-%d')= '#{Date.today}'") #截止日期都是当天 23.59分,所以年月日相等的一定是今晚会截止的测验 + exercises.each do |exercise| + if exercise.exercise_status == 2 #发布的作业才能告给学生发截止消息 + course = exercise.course + course.members.each do |m| + #CourseMessage status 1 未发布 status 2 已发布 status 3 已发布快截止了 + exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 3) unless m.user.allowed_to?(:as_teacher,m) + end + # if homework.course_acts.size == 0 + # homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id) + # end + # 邮件通知 + #Mailer.run.homework_added(homework) + end + end + end +end \ No newline at end of file diff --git a/lib/tasks/exercise_publishtime.rake b/lib/tasks/exercise_publishtime.rake new file mode 100644 index 000000000..6cef511e2 --- /dev/null +++ b/lib/tasks/exercise_publishtime.rake @@ -0,0 +1,22 @@ +#coding=utf-8 + +namespace :exercise_publishtime do + desc "start publish exercise" + task :publish => :environment do + exercises = Exercise.where("date_format(publish_time,'%Y-%m-%d')= '#{Date.today}'") + exercises.each do |exercise| + if exercise.exercise_status == 1 #未发布 + exercise.update_column('exercise_status', 2) #改为发布 + course = exercise.course + course.members.each do |m| + exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2) + end + # if homework.course_acts.size == 0 + # homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id) + # end + # 邮件通知 + #Mailer.run.homework_added(homework) + end + end + end +end \ No newline at end of file