Merge branch 'sw_new_course' of http://repository.trustie.net/xianbo/trustie2 into sw_new_course

This commit is contained in:
cxt 2015-11-17 18:23:07 +08:00
commit b3e6bf40ff
3 changed files with 148 additions and 57 deletions

View File

@ -16,7 +16,23 @@ 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
# 已提交问卷的用户不能再访问该界面
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_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|
format.html {render :layout => 'base_courses'}
end
end
end
def new
@ -55,7 +71,17 @@ 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
@ -64,7 +90,113 @@ 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 = {
:question_title => question_title,
:question_type => params[:question_type] || 1,
:question_number => @exercise.exercise_questions.count + 1
}
@exercise_questions = @exercise.exercise_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
}
@exercise_questions.poll_answers.new question_option
end
end
# 如果是插入的话那么从插入的这个id以后的question_num都将要+1
if params[:quest_id]
@is_insert = true
@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i}").update_all(" question_number = question_number + 1")
# @exercise_question_num = params[:quest_num].to_i
@exercise_questions.question_number = params[:quest_num].to_i + 1
end
if @poll_questions.save
respond_to do |format|
format.js
end
end
end
# 修改题目
# params[:exercise_question] The id of exercise_question
# params[:question_answer] eg:A、B、C选项
def update_exercise_question
@exercise_question = ExerciseQuestion.find params[:exercise_question]
@exercise_questions.question_title = params[:exercise_questions_title].nil? || params[:exercise_questions_title].empty? ? l(:label_enter_single_title) : params[:exercise_questions_title]
################处理选项
if params[:question_answer]
@exercise_question.exercise_answers.each do |answer|
answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
end
# 界面需要判断选择题至少有一个选项
for i in 1..params[:question_answer].count
question = @exercise_question.exercise_answers.find_by_id params[:question_answer].keys[i-1]
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]
if question
question.exercise_choices_id = i
question.answer_text = answer
question.save
else
question_option = {
:exercise_choices_id => i,
:answer_text => answer
}
@exercise_question.exercise_answers.new question_option
end
end
end
@exercise_question.save
respond_to do |format|
format.js
end
end
# 删除题目
def delete_exercise_question
@exercise_question = ExerciseQuestion.find params[:exercise_question]
@exercise = @exercise_question.exercise
exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}")
poll_questions.each do |question|
question.question_number -= 1
question.save
end
if @poll_question && @poll_question.destroy
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

View File

@ -1,3 +1,14 @@
# encoding: utf-8
module ExerciseHelper
#判断用户是否已经提交了问卷
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
true
end
end
end

View File

@ -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