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 @exercise = Exercise.new respond_to do |format| format.html{render :layout => 'base_courses'} end end def create end def edit respond_to do |format| format.html{render :layout => 'base_courses'} end 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') @show_all = true; 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