问卷部分方法

sw_new_course
huang 10 years ago
parent 0316bf698f
commit 23ca20692f

@ -21,14 +21,12 @@ class ExerciseController < ApplicationController
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)
if has_commit_exercise?(@exercise.id, User.current.id) && (!User.current.admin?)
redirect_to poll_index_url(:course_id=> @course.id)
else
@can_edit_poll = (!has_commit_poll?(@poll.id,User.current.id)) || User.current.admin?
@percent = get_percent(@poll,User.current)
@can_edit_poll = (!has_commit_exercise?(@exercise.id,User.current.id)) || User.current.admin?
@percent = get_percent(@exercise,User.current)
poll_questions = @poll.poll_questions
@poll_questions = paginateHelper poll_questions,5 #分页
respond_to do |format|
@ -36,7 +34,6 @@ class ExerciseController < ApplicationController
end
end
end
end
def new
option = {
@ -45,8 +42,8 @@ class ExerciseController < ApplicationController
:course_id => @course.id,
:exercise_status => 1,
:user_id => User.current.id,
:start_at => "",
:end_at => ""
:time => "",
:end_time => ""
}
@exercise = Exercise.create option
if @exercise
@ -92,9 +89,65 @@ class ExerciseController < ApplicationController
#统计结果
def statistics_result
@exercise = Exercise.find(params[:id])
exercise_questions = @exercise.poll_questions
@exercise_questions = paginateHelper exercise_questions, 5
respond_to do |format|
format.html{render :layout => 'base_courses'}
end
end
#添加题目
#question_type 1单选 2多选 3填空题
def create_exercise_question
question_title = params[:exercise_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title]
option = {
:is_necessary => (params[:is_necessary]=="true" ? 1 : 0),
:question_title => question_title,
:question_type => params[:question_type] || 1,
:question_number => @poll.poll_questions.count + 1
}
@poll_questions = @poll.poll_questions.new option
if params[:question_answer]
for i in 1..params[:question_answer].count
answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
question_option = {
:answer_position => i,
:answer_text => answer
}
@poll_questions.poll_answers.new question_option
end
end
# 如果是插入的话那么从插入的这个id以后的question_num都将要+1
if params[:quest_id]
@is_insert = true
@poll.poll_questions.where("question_number > #{params[:quest_num].to_i}").update_all(" question_number = question_number + 1")
@poll_question_num = params[:quest_num].to_i
@poll_questions.question_number = params[:quest_num].to_i + 1
end
if @poll_questions.save
respond_to do |format|
format.js
end
end
end
#发布问卷
def publish_excercise
@exercise.exercise_status = 2
@exercise.publish_time = Time.now
if @exercise.save
if params[:is_remote]
redirect_to poll_index_url(:course_id => @course.id)
else
respond_to do |format|
format.js
end
end
end
end
def student_exercise_list
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
@exercise = Exercise.find params[:id]

@ -2,8 +2,8 @@
module ExerciseHelper
#判断用户是否已经提交了问卷
def has_commit_exercise?(poll_id,user_id)
pu = PollUser.find_by_poll_id_and_user_id(poll_id,user_id)
def has_commit_exercise?(exercise_id, user_id)
pu = PollUser.find_by_poll_id_and_user_id(excercise_id, user_id)
if pu.nil?
false
else

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20151116065904) do
ActiveRecord::Schema.define(:version => 20151116071721) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -241,58 +241,6 @@ ActiveRecord::Schema.define(:version => 20151116065904) do
add_index "changesets_issues", ["changeset_id", "issue_id"], :name => "changesets_issues_ids", :unique => true
create_table "code_review_assignments", :force => true do |t|
t.integer "issue_id"
t.integer "change_id"
t.integer "attachment_id"
t.string "file_path"
t.string "rev"
t.string "rev_to"
t.string "action_type"
t.integer "changeset_id"
end
create_table "code_review_project_settings", :force => true do |t|
t.integer "project_id"
t.integer "tracker_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "updated_by"
t.boolean "hide_code_review_tab", :default => false
t.integer "auto_relation", :default => 1
t.integer "assignment_tracker_id"
t.text "auto_assign"
t.integer "lock_version", :default => 0, :null => false
t.boolean "tracker_in_review_dialog", :default => false
end
create_table "code_review_user_settings", :force => true do |t|
t.integer "user_id", :default => 0, :null => false
t.integer "mail_notification", :default => 0, :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "code_reviews", :force => true do |t|
t.integer "project_id"
t.integer "change_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "line"
t.integer "updated_by_id"
t.integer "lock_version", :default => 0, :null => false
t.integer "status_changed_from"
t.integer "status_changed_to"
t.integer "issue_id"
t.string "action_type"
t.string "file_path"
t.string "rev"
t.string "rev_to"
t.integer "attachment_id"
t.integer "file_count", :default => 0, :null => false
t.boolean "diff_all"
end
create_table "comments", :force => true do |t|
t.string "commented_type", :limit => 30, :default => "", :null => false
t.integer "commented_id", :default => 0, :null => false

Loading…
Cancel
Save