コード例 #1
0
ファイル: cc_asssesment.php プロジェクト: evltuma/moodle
 /**
  *
  * Enter description here ...
  * @param XMLGenericDocument $qdoc
  * @param unknown_type $manifest
  * @param cc_assesment_section $section
  * @param unknown_type $rootpath
  * @param unknown_type $contextid
  * @param unknown_type $outdir
  */
 public static function process_questions(&$qdoc, &$manifest, cc_assesment_section &$section, $rootpath, $contextid, $outdir)
 {
     $question_file = $rootpath . DIRECTORY_SEPARATOR . 'questions.xml';
     //load questions file
     $questions = new XMLGenericDocument();
     if (!$questions->load($question_file)) {
         return false;
     }
     pkg_resource_dependencies::instance()->reset();
     $questioncount = 0;
     $questionforexport = 0;
     $qids = $qdoc->nodeList('//question_instances//questionid');
     foreach ($qids as $qid) {
         /** @var DOMNode $qid */
         $value = $qid->nodeValue;
         if (intval($value) == 0) {
             continue;
         }
         $question_node = $questions->node("//question_category/questions/question[@id='{$value}']");
         if (empty($question_node)) {
             continue;
         }
         ++$questionforexport;
         //process question
         //question type
         $qtype = $questions->nodeValue('qtype', $question_node);
         $question_processor = null;
         switch ($qtype) {
             case 'multichoice':
                 $single_correct_answer = (int) $questions->nodeValue('plugin_qtype_multichoice_question/multichoice/single', $question_node) > 0;
                 //TODO: Add checking for the nunmber of valid responses
                 //If question is marked as multi response but contains only one valid answer it
                 //should be handle as single response - classic multichoice
                 if ($single_correct_answer) {
                     $question_processor = new cc_assesment_question_multichoice($qdoc, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);
                 } else {
                     $question_processor = new cc_assesment_question_multichoice_multiresponse($qdoc, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);
                 }
                 $question_processor->generate();
                 ++$questioncount;
                 break;
             case 'truefalse':
                 $question_processor = new cc_assesment_question_truefalse($qdoc, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);
                 $question_processor->generate();
                 ++$questioncount;
                 break;
             case 'essay':
                 $question_processor = new cc_assesment_question_essay($qdoc, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);
                 $question_processor->generate();
                 ++$questioncount;
                 break;
             case 'shortanswer':
                 //This is rather ambiguos since shortanswer supports partial pattern match
                 //In order to detect pattern match we need to scan for all the responses
                 //if at least one of the responses uses wildcards it should be treated as
                 //pattern match, otherwise it should be simple fill in the blank
                 if (self::has_matching_element($questions, $question_node)) {
                     //$question_processor = new cc_assesment_question_patternmatch($qdoc, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);
                     $questionforexport--;
                 } else {
                     $question_processor = new cc_assesment_question_sfib($qdoc, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);
                 }
                 if (!empty($question_processor)) {
                     $question_processor->generate();
                     ++$questioncount;
                 }
                 break;
             default:
                 break;
         }
     }
     //return dependencies
     return $questioncount == 0 || $questioncount != $questionforexport ? false : pkg_resource_dependencies::instance()->get_deps();
 }
コード例 #2
0
 /**
  *
  * Enter description here ...
  * @param unknown_type $qdoc
  * @param unknown_type $manifest
  * @param cc_assesment_section $section
  * @param unknown_type $rootpath
  * @param unknown_type $contextid
  * @param unknown_type $outdir
  */
 public static function process_questions(&$qdoc, &$manifest, cc_assesment_section &$section, $rootpath, $contextid, $outdir)
 {
     $question_file = $rootpath . DIRECTORY_SEPARATOR . 'questions.xml';
     //load questions file
     $questions = new XMLGenericDocument();
     if (!$questions->load($question_file)) {
         return false;
     }
     pkg_resource_dependencies::instance()->reset();
     $qids = explode(',', $qdoc->nodeValue('/activity/quiz/questions'));
     foreach ($qids as $value) {
         if (intval($value) == 0) {
             continue;
         }
         $question_node = $questions->node("//question_category/questions/question[@id='{$value}']");
         if (empty($question_node)) {
             continue;
         }
         //process question
         //question type
         $qtype = $questions->nodeValue('qtype', $question_node);
         $question_processor = null;
         switch ($qtype) {
             case 'multichoice':
                 $single_correct_answer = (int) $questions->nodeValue('plugin_qtype_multichoice_question/multichoice/single', $question_node) > 0;
                 if ($single_correct_answer) {
                     $question_processor = new cc_assesment_question_multichoice($qdoc, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);
                     $question_processor->generate();
                 } else {
                     //TODO: implement
                 }
                 break;
             default:
                 break;
         }
     }
     //return dependencies
     return pkg_resource_dependencies::instance()->get_deps();
 }