|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 require_once 'cc_converters.php'; 00004 require_once 'cc_general.php'; 00005 require_once 'cc_asssesment.php'; 00006 00007 class cc_converter_quiz extends cc_converter { 00008 00009 public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path){ 00010 $this->cc_type = cc_version11::assessment; 00011 $this->defaultfile = 'quiz.xml'; 00012 $this->defaultname = assesment11_resurce_file::deafultname; 00013 parent::__construct($item, $manifest, $rootpath, $path); 00014 } 00015 00016 public function convert($outdir) { 00017 $rt = new assesment11_resurce_file(); 00018 $title = $this->doc->nodeValue('/activity/quiz/name'); 00019 $rt->set_title($title); 00020 00021 //metadata 00022 $metadata = new cc_assesment_metadata(); 00023 $rt->set_metadata($metadata); 00024 $metadata->enable_feedback(); 00025 $metadata->enable_hints(); 00026 $metadata->enable_solutions(); 00027 //attempts 00028 $max_attempts = (int)$this->doc->nodeValue('/activity/quiz/attempts_number'); 00029 if ($max_attempts > 0) { 00030 //qti does not support number of specific attempts bigger than 5 (??) 00031 if ($max_attempts > 5) { 00032 $max_attempts = cc_qti_values::unlimited; 00033 } 00034 $metadata->set_maxattempts($max_attempts); 00035 } 00036 //timelimit must be converted into minutes 00037 $timelimit = (int)floor((int)$this->doc->nodeValue('/activity/quiz/timelimit')/60); 00038 if ($timelimit > 0) { 00039 $metadata->set_timelimit($timelimit); 00040 $metadata->enable_latesubmissions(false); 00041 } 00042 00043 $contextid = $this->doc->nodeValue('/activity/@contextid'); 00044 $result = cc_helpers::process_linked_files( $this->doc->nodeValue('/activity/quiz/intro'), 00045 $this->manifest, 00046 $this->rootpath, 00047 $contextid, 00048 $outdir); 00049 cc_assesment_helper::add_assesment_description($rt, $result[0], cc_qti_values::htmltype); 00050 00051 //section 00052 $section = new cc_assesment_section(); 00053 $rt->set_section($section); 00054 00055 //Process the actual questions 00056 $ndeps = cc_assesment_helper::process_questions($this->doc, 00057 $this->manifest, 00058 $section, 00059 $this->rootpath, 00060 $contextid, 00061 $outdir); 00062 //store any additional dependencies 00063 $deps = array_merge($result[1], $ndeps); 00064 00065 //store everything 00066 $this->store($rt, $outdir, $title, $deps); 00067 return true; 00068 } 00069 }