86 lines
2.7 KiB
Ruby
86 lines
2.7 KiB
Ruby
Rails.application.routes.draw do
|
|
|
|
locales = Site.first.in_use_locales rescue I18n.available_locales
|
|
Thread.new do
|
|
surveys = QuestionnaireSurvey.where(:already_fix_data.in=>[nil,false]).to_a
|
|
surveys.each do |survey|
|
|
group_data = survey.survey_answers.asc(:updated_at).group_by(&:user)
|
|
group_data.each do |user_id,survey_answers|
|
|
if user_id.blank?
|
|
survey_answers.each do |survey_answer|
|
|
info = {:questionnaire_survey_id=>survey.id,:user=>user_id,:survey_answer_ids=>[survey_answer.id]}
|
|
answer_group = SurveyAnswerGroup.where(info).first
|
|
if answer_group.nil?
|
|
info.delete(:survey_answer_ids)
|
|
answer_group = SurveyAnswerGroup.new(info)
|
|
end
|
|
answer_group.last_modified = survey_answer.updated_at
|
|
answer_group.survey_answer_ids = [survey_answer.id]
|
|
answer_group.save
|
|
end
|
|
else
|
|
info = {:questionnaire_survey_id=>survey.id,:user=>user_id}
|
|
answer_group = SurveyAnswerGroup.where(info).first
|
|
if answer_group.nil?
|
|
answer_group = SurveyAnswerGroup.new(info)
|
|
end
|
|
answer_group.last_modified = survey_answers.last.updated_at
|
|
answer_group.survey_answer_ids = survey_answers.map{|a| a.id}
|
|
answer_group.save
|
|
end
|
|
survey_answers.each_with_index{|a,i| a.updated_at = a.created_at;a.save}
|
|
end
|
|
survey.already_fix_data = true
|
|
survey.survey_questions.each do |q|
|
|
q.survey_question_options.where("name.zh_tw.zh_tw"=>//).destroy
|
|
q.survey_question_options.where("name.en.en"=>//).destroy
|
|
end
|
|
survey.save
|
|
end
|
|
end
|
|
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
|
namespace :admin do
|
|
get "surveys/checkforthread", to: "surveys#checkforthread"
|
|
resources :surveys do
|
|
collection do
|
|
get 'delete'
|
|
end
|
|
member do
|
|
get 'export'
|
|
get 'set_answers'
|
|
get 'set_sections'
|
|
get 'add_section'
|
|
get 'pagination_setting'
|
|
patch 'save_pagination_setting'
|
|
post 'create_section'
|
|
delete 'delete_section'
|
|
get 'edit_section'
|
|
patch 'update_section'
|
|
get 'jump'
|
|
get 'duplicate_it'
|
|
get 'answer_sets'
|
|
get 'answer_set'
|
|
get 'answer_list'
|
|
get 'export_answers'
|
|
end
|
|
resources :answers, :controller => :surveys_answers do
|
|
collection do
|
|
get 'delete'
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
resources :surveys do
|
|
collection do
|
|
get ':slug_title-:uid', to: 'surveys#show'
|
|
end
|
|
member do
|
|
get 'result'
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
end
|