You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trustieforge/app/controllers/exercise_controller.rb

70 lines
1.7 KiB

class ExerciseController < ApplicationController
layout "base_courses"
before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list]
def index
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
if @is_teacher
exercises = @course.exercises
else
exercises = @course.exercises.where(:exercise_status => 1)
end
@exercises = paginateHelper exercises,20 #分页
respond_to do |format|
format.html
end
end
def show
end
def new
end
def create
end
def edit
end
def update
end
def destroy
end
#统计结果
def statistics_result
end
def student_exercise_list
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
@exercise = Exercise.find params[:id]
@all_exercises = @course.exercises.order("created_at desc")
@exercise_count = @exercise.exercise_users.where('score is not NULL').count
if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && Time.parse(@exercise.end_time.to_s).strftime("%Y-%m-%d-%H-%M-%S") <= Time.now.strftime("%Y-%m-%d-%H-%M-%S"))
@exercise_users_list = @exercise.exercise_users.where('score is not NULL')
elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && Time.parse(@exercise.end_time.to_s).strftime("%Y-%m-%d-%H-%M-%S") > Time.now.strftime("%Y-%m-%d-%H-%M-%S")
@exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id)
else
@exercise_users_list = []
end
respond_to do |format|
format.html
end
end
private
def find_course
@course = Course.find params[:course_id]
rescue Exception => e
render_404
end
end