show
This commit is contained in:
parent
21694daa59
commit
3deebf2006
|
@ -27,11 +27,19 @@ class ExerciseController < ApplicationController
|
|||
render_403
|
||||
return
|
||||
end
|
||||
|
||||
# 学生点击的时候即创建关联,自动保存
|
||||
#eu = ExerciseUser.create(:user_id => User.current, :exercise_id => @exercise.id, :start_at => Time.now, :status => false)
|
||||
|
||||
# 已提交问卷的用户不能再访问该界面
|
||||
if has_commit_exercise?(@exercise.id, User.current.id) && (!User.current.admin?)
|
||||
redirect_to exercise_index_url(:course_id=> @course.id)
|
||||
else
|
||||
if !@is_teacher && !has_click_exercise?(@exercise.id, User.current.id)
|
||||
eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false)
|
||||
end
|
||||
@can_edit_excercise = (!has_commit_exercise?(@exercise.id,User.current.id)) || User.current.admin?
|
||||
@exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
|
||||
# @percent = get_percent(@exercise,User.current)
|
||||
exercise_questions = @exercise.exercise_questions
|
||||
@exercise_questions = paginateHelper exercise_questions,5 #分页
|
||||
|
@ -411,6 +419,7 @@ class ExerciseController < ApplicationController
|
|||
def commit_exercise
|
||||
# 老师不需要提交
|
||||
if User.current.allowed_to?(:as_teacher,@course)
|
||||
|
||||
redirect_to exercise_url(@exercise)
|
||||
# REDO: 提示提交成功
|
||||
else
|
||||
|
|
|
@ -35,10 +35,21 @@ module ExerciseHelper
|
|||
end
|
||||
end
|
||||
|
||||
#判断用户是否已经提交了问卷
|
||||
# 判断用户是否已经提交了问卷
|
||||
# status 为0的时候是用户点击试卷。为1表示用户已经提交
|
||||
def has_commit_exercise?(exercise_id, user_id)
|
||||
pu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id, user_id)
|
||||
if pu.nil?
|
||||
pu = ExerciseUser.where("exercise_id=? and user_id=? and status=?",exercise_id, user_id, true)
|
||||
if pu.empty?
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
# 判断学生是否点击过问卷,点击则为他保存一个记录,记录start_at
|
||||
def has_click_exercise?(exercise_id, user_id)
|
||||
pu = ExerciseUser.where("exercise_id=? and user_id=? and status=?",exercise_id, user_id, false)
|
||||
if pu.empty?
|
||||
false
|
||||
else
|
||||
true
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddStatusToExerciseUser < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :exercise_users, :status, :integer
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20151119124148) do
|
||||
ActiveRecord::Schema.define(:version => 20151120021958) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
@ -563,6 +563,7 @@ ActiveRecord::Schema.define(:version => 20151119124148) do
|
|||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "end_at"
|
||||
t.integer "status"
|
||||
end
|
||||
|
||||
create_table "exercises", :force => true do |t|
|
||||
|
|
Loading…
Reference in New Issue