2011-02-01 09:57:29 +08:00
|
|
|
#
|
2017-04-28 12:02:05 +08:00
|
|
|
# Copyright (C) 2011 - present Instructure, Inc.
|
2011-02-01 09:57:29 +08:00
|
|
|
#
|
|
|
|
# This file is part of Canvas.
|
|
|
|
#
|
|
|
|
# Canvas is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
# Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
2014-04-15 04:58:50 +08:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
|
2011-02-01 09:57:29 +08:00
|
|
|
|
2014-04-15 04:58:50 +08:00
|
|
|
IMPORT_JSON_DIR = File.dirname(__FILE__) + '/fixtures/importer/'
|
2011-02-01 09:57:29 +08:00
|
|
|
|
|
|
|
QUESTIONS = [
|
|
|
|
['calculated_complex', 'calculated_question'],
|
|
|
|
['calculated_simple', 'calculated_question'],
|
|
|
|
['essay'],
|
|
|
|
['file_upload', 'unsupported'],
|
|
|
|
['fill_in_multiple_blanks'],
|
|
|
|
['hot_spot', 'unsupported'],
|
|
|
|
['matching'],
|
|
|
|
['multiple_answers'],
|
|
|
|
['multiple_choice'],
|
|
|
|
['multiple_dropdowns'],
|
|
|
|
['numerical'],
|
|
|
|
['ordering', 'matching_question'],
|
|
|
|
['short_answer'],
|
|
|
|
['true_false'],
|
|
|
|
]
|
|
|
|
SYSTEMS = ['vista', 'bb8', 'bb9', 'angel']
|
|
|
|
|
|
|
|
def import_data_exists?(sub_folder, hash_name)
|
2015-04-28 00:59:20 +08:00
|
|
|
File.exist? File.join(IMPORT_JSON_DIR, sub_folder, "#{hash_name}.json")
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_import_data(sub_folder, hash_name)
|
|
|
|
json = File.open(File.join(IMPORT_JSON_DIR, sub_folder, "#{hash_name}.json")).read
|
|
|
|
data = JSON.parse(json)
|
|
|
|
data = data.with_indifferent_access if data.is_a? Hash
|
|
|
|
data
|
|
|
|
end
|
|
|
|
|
|
|
|
def import_example_questions(context)
|
2014-05-23 04:02:06 +08:00
|
|
|
questions = []
|
2011-02-01 09:57:29 +08:00
|
|
|
QUESTIONS.each do |question|
|
|
|
|
if import_data_exists?(['vista', 'quiz'], question[0])
|
|
|
|
q = get_import_data ['vista', 'quiz'], question[0]
|
2014-05-23 04:02:06 +08:00
|
|
|
questions << q
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
|
|
|
end
|
2014-05-23 04:02:06 +08:00
|
|
|
hash = {'assessment_questions' => {'assessment_questions' => questions}}
|
2015-06-04 21:51:57 +08:00
|
|
|
Importers::AssessmentQuestionImporter.process_migration(hash, @migration)
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_import_context(system=nil)
|
|
|
|
context = course_model
|
|
|
|
context.import_source == :webct if system == 'vista'
|
2015-06-04 21:51:57 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
context
|
|
|
|
end
|
2017-06-03 06:38:02 +08:00
|
|
|
|
|
|
|
class ImportHelper
|
|
|
|
def self.get_import_data_xml(sub_folder, file_name)
|
|
|
|
File.open(File.join(IMPORT_JSON_DIR, sub_folder, "#{file_name}.xml")) { |f| Nokogiri::XML(f) }
|
|
|
|
end
|
|
|
|
end
|