2015-11-13 16:40:39 +08:00
|
|
|
class ExerciseController < ApplicationController
|
|
|
|
layout "base_courses"
|
|
|
|
|
2015-11-17 09:33:40 +08:00
|
|
|
before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list]
|
2015-11-13 16:40:39 +08:00
|
|
|
def index
|
2015-11-13 17:23:52 +08:00
|
|
|
@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
|
2015-11-13 16:40:39 +08:00
|
|
|
end
|
2015-11-13 17:23:52 +08:00
|
|
|
|
2015-11-13 16:40:39 +08:00
|
|
|
def show
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2015-11-17 15:18:07 +08:00
|
|
|
@exercise = Exercise.new
|
|
|
|
respond_to do |format|
|
|
|
|
format.html{render :layout => 'base_courses'}
|
|
|
|
end
|
2015-11-13 16:40:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2015-11-17 15:18:07 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html{render :layout => 'base_courses'}
|
|
|
|
end
|
2015-11-13 16:40:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-11-13 17:23:52 +08:00
|
|
|
#统计结果
|
|
|
|
def statistics_result
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-11-17 09:33:40 +08:00
|
|
|
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')
|
2015-11-17 15:18:07 +08:00
|
|
|
@show_all = true;
|
2015-11-17 09:33:40 +08:00
|
|
|
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
|
|
|
|
|
2015-11-13 16:40:39 +08:00
|
|
|
private
|
|
|
|
def find_course
|
|
|
|
@course = Course.find params[:course_id]
|
|
|
|
rescue Exception => e
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|