Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_course
cxt 5 years ago
commit bfd5c4748a

@ -384,24 +384,22 @@ class ExerciseQuestionsController < ApplicationController
begin begin
opr = params[:opr] opr = params[:opr]
current_q_p = @exercise_question.question_number.to_i #问题的当前位置 current_q_p = @exercise_question.question_number.to_i #问题的当前位置
# last_q_p = @exercise.exercise_questions.find_by_custom("question_number",(current_q_p - 1)).first # 当前问题的前一个问题
# next_q_p = @exercise.exercise_questions.find_by_custom("question_number",(current_q_p + 1)).first # 当前问题的后一个问题
last_q_p = @exercise.exercise_questions.last_exercise(current_q_p) # 当前问题的前一个问题
next_q_p = @exercise.exercise_questions.next_exercise(current_q_p) # 当前问题的后一个问题
if @exercise.exercise_status.to_i == 1 if @exercise.exercise_status.to_i == 1
if opr.present? if opr.present?
if opr.to_s == "up" if opr.to_s == "up"
last_q_p = @exercise.exercise_questions.find_by(question_number: (current_q_p - 1)) # 当前问题的前一个问题
if last_q_p.present? if last_q_p.present?
@exercise_question.update_attribute('question_number', (current_q_p - 1)) @exercise_question.update_attribute('question_number', (current_q_p - 1))
last_q_p.update_attribute('question_number', (@exercise_question.question_number.to_i + 1)) # 重新获取当前问题的位置 last_q_p.update_attribute('question_number', current_q_p) # 重新获取当前问题的位置
normal_status(0, "问题上移成功!") normal_status(0, "问题上移成功!")
else else
normal_status(-1, "移动失败,已经是第一个问题了!") normal_status(-1, "移动失败,已经是第一个问题了!")
end end
elsif opr.to_s == "down" elsif opr.to_s == "down"
next_q_p = @exercise.exercise_questions.find_by(question_number: (current_q_p + 1)) # 当前问题的前一个问题
if next_q_p.present? if next_q_p.present?
@exercise_question.update_attribute('question_number', (current_q_p + 1)) @exercise_question.update_attribute('question_number', (current_q_p + 1))
next_q_p.update_attribute('question_number', (@exercise_question.question_number.to_i - 1)) next_q_p.update_attribute('question_number', current_q_p)
normal_status(0, "问题下移成功!") normal_status(0, "问题下移成功!")
else else
normal_status(-1, "移动失败,已经是最后一个问题了!") normal_status(-1, "移动失败,已经是最后一个问题了!")

@ -223,7 +223,7 @@ class GraduationTopicsController < ApplicationController
# 已加入的更新,未加入的新建 # 已加入的更新,未加入的新建
if topic_bank.present? if topic_bank.present?
topic_bank.update_attributes(name: topic, description: topic.description, topic_bank.update_attributes(name: topic.name, description: topic.description,
topic_source: topic.topic_source, topic_source: topic.topic_source,
topic_property_first: topic.topic_property_first, topic_property_first: topic.topic_property_first,
topic_property_second: topic.topic_property_second, topic_property_second: topic.topic_property_second,
@ -234,7 +234,7 @@ class GraduationTopicsController < ApplicationController
course_list_id: @course.course_list_id) course_list_id: @course.course_list_id)
topic_bank.attachments.destroy_all topic_bank.attachments.destroy_all
else else
topic_bank = GtopicBank.new(name: topic, description: topic.description, topic_bank = GtopicBank.new(name: topic.name, description: topic.description,
topic_source: topic.topic_source, topic_source: topic.topic_source,
topic_property_first: topic.topic_property_first, topic_property_first: topic.topic_property_first,
topic_property_second: topic.topic_property_second, topic_property_second: topic.topic_property_second,

@ -197,22 +197,23 @@ class PollQuestionsController < ApplicationController
begin begin
opr = params[:opr] opr = params[:opr]
current_q_p = @poll_question.question_number.to_i #问题的当前位置 current_q_p = @poll_question.question_number.to_i #问题的当前位置
last_q_p = @poll.poll_questions.last_poll(current_q_p) #当前问题的前一个问题
next_q_p = @poll.poll_questions.next_poll(current_q_p) # 当前问题的后一个问题
if @poll.polls_status.to_i == 1 if @poll.polls_status.to_i == 1
if opr.present? if opr.present?
if opr.to_s == "up" if opr.to_s == "up"
last_q_p = @poll.poll_questions.find_by(question_number: (current_q_p-1)) #当前问题的前一个问题
if last_q_p.present? if last_q_p.present?
@poll_question.update_attribute(:question_number, (current_q_p - 1)) @poll_question.update_attribute("question_number", (current_q_p - 1))
last_q_p.update_attribute(:question_number, (@poll_question.question_number.to_i + 1)) # 重新获取当前问题的位置 last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置
normal_status(0, "问题上移成功!") normal_status(0, "问题上移成功!")
else else
normal_status(-1, "移动失败,已经是第一个问题了!") normal_status(-1, "移动失败,已经是第一个问题了!")
end end
elsif opr.to_s == "down" elsif opr.to_s == "down"
next_q_p = @poll.poll_questions.find_by(question_number: (current_q_p+1)) #当前问题的后一个问题
if next_q_p.present? if next_q_p.present?
@poll_question.update_attribute(:question_number, (current_q_p + 1)) @poll_question.update_attribute("question_number", (current_q_p + 1))
next_q_p.update_attribute(:question_number, (@poll_question.question_number.to_i - 1)) next_q_p.update_attribute("question_number", current_q_p)
normal_status(0, "问题下移成功!") normal_status(0, "问题下移成功!")
else else
normal_status(-1, "移动失败,已经是最后一个问题了!") normal_status(-1, "移动失败,已经是最后一个问题了!")

@ -15,8 +15,8 @@ class ExerciseQuestion < ApplicationRecord
scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题
scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题
scope :next_exercise, lambda {|k| where("question_number > ?",k).first} # scope :next_exercise, lambda {|k| where("question_number > ?",k).first}
scope :last_exercise, lambda {|k| where("question_number < ?",k).last} # scope :last_exercise, lambda {|k| where("question_number < ?",k).last}
def question_type_name def question_type_name
case self.question_type case self.question_type

@ -8,8 +8,6 @@ class PollQuestion < ApplicationRecord
scope :ques_count, lambda {|k| where("question_type = ?",k)} scope :ques_count, lambda {|k| where("question_type = ?",k)}
scope :ques_necessary, -> {where("is_necessary = ?",1)} scope :ques_necessary, -> {where("is_necessary = ?",1)}
scope :insert_question, lambda {|k| where("question_number > ?",k)} scope :insert_question, lambda {|k| where("question_number > ?",k)}
scope :next_poll, lambda {|k| where("question_number > ?",k).first}
scope :last_poll, lambda {|k| where("question_number < ?",k).last}
def question_type_name def question_type_name
case self.question_type case self.question_type

Loading…
Cancel
Save