exercise新增、update
This commit is contained in:
parent
167d001b3f
commit
0316bf698f
|
@ -16,11 +16,42 @@ class ExerciseController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
|
||||
@exercise = Exercise.find params[:id]
|
||||
if @exercise.exercise_status != 2 && (!User.current.allowed_to?(:as_teacher,@course) || User.current.admin?)
|
||||
render_403
|
||||
return
|
||||
end
|
||||
# 问卷消息状态更新
|
||||
# REDO:问卷添加消息
|
||||
#已提交问卷的用户不能再访问该界面
|
||||
if has_commit_exercise?(@poll.id,User.current.id) && (!User.current.admin?)
|
||||
redirect_to poll_index_url(:polls_type => "Course", :polls_group_id => @course.id)
|
||||
else
|
||||
@can_edit_poll = (!has_commit_poll?(@poll.id,User.current.id)) || User.current.admin?
|
||||
@percent = get_percent(@poll,User.current)
|
||||
poll_questions = @poll.poll_questions
|
||||
@poll_questions = paginateHelper poll_questions,5 #分页
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'base_courses'}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
|
||||
option = {
|
||||
:exercise_name => "",
|
||||
:exercise_description => "",
|
||||
:course_id => @course.id,
|
||||
:exercise_status => 1,
|
||||
:user_id => User.current.id,
|
||||
:start_at => "",
|
||||
:end_at => ""
|
||||
}
|
||||
@exercise = Exercise.create option
|
||||
if @exercise
|
||||
redirect_to edit_exercise_url @exercise.id
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
|
@ -32,11 +63,31 @@ class ExerciseController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
|
||||
@exercise.exercise_name = params[:exercise_name]
|
||||
@exercise.exercise_description = params[:exercise_name]
|
||||
@exercise.start_at = params[:start_at]
|
||||
@exercise.end_at = params[:end_at]
|
||||
if @exercise.save
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
else
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
||||
if @exercise && @exercise.destroy
|
||||
if @is_teacher
|
||||
polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}")
|
||||
else
|
||||
polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status = 2")
|
||||
end
|
||||
@polls = paginateHelper polls,20 #分页
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#统计结果
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
# encoding: utf-8
|
||||
module ExerciseHelper
|
||||
|
||||
#判断用户是否已经提交了问卷
|
||||
def has_commit_exercise?(poll_id,user_id)
|
||||
pu = PollUser.find_by_poll_id_and_user_id(poll_id,user_id)
|
||||
if pu.nil?
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue