在线测验的自动发布和截止

This commit is contained in:
cxt 2015-12-03 19:08:15 +08:00
parent fd51b02e16
commit 838140ada8
2 changed files with 34 additions and 0 deletions

View File

@ -6,6 +6,14 @@ class ExerciseController < ApplicationController
include ExerciseHelper
def index
publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
publish_exercises.each do |exercise|
exercise.update_column('exercise_status', 2)
end
end_exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now)
end_exercises.each do |exercise|
exercise.update_column('exercise_status', 3)
end
if @course.is_public == 0 && !User.current.member_of_course?(@course)
render_403
return
@ -24,6 +32,14 @@ class ExerciseController < ApplicationController
end
def show
publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
publish_exercises.each do |exercise|
exercise.update_column('exercise_status', 2)
end
end_exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now)
end_exercises.each do |exercise|
exercise.update_column('exercise_status', 3)
end
unless User.current.member_of_course?(@course)
render_403
return

View File

@ -0,0 +1,18 @@
#coding=utf-8
namespace :exercise_publish do
desc "publish exercise and end exercise"
task :publish => :environment do
exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
exercises.each do |exercise|
exercise.update_column('exercise_status', 2)
end
end
task :end => :environment do
exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now)
exercises.each do |exercise|
exercise.update_column('exercise_status', 3)
end
end
end