コード例 #1
0
 /**
  *
  * ctor
  * @param  cc_i_item $item
  * @param  cc_i_manifest $manifest
  * @param  string $rootpath
  * @param  string $path
  * @throws InvalidArgumentException
  */
 public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path)
 {
     $rpath = realpath($rootpath);
     if (empty($rpath)) {
         throw new InvalidArgumentException('Invalid path!');
     }
     $rpath2 = realpath($path);
     if (empty($rpath)) {
         throw new InvalidArgumentException('Invalid path!');
     }
     $doc = new XMLGenericDocument();
     if (!$doc->load($path . DIRECTORY_SEPARATOR . $this->defaultfile)) {
         throw new RuntimeException('File does not exist!');
     }
     $this->doc = $doc;
     $this->item = $item;
     $this->manifest = $manifest;
     $this->rootpath = $rpath;
     $this->path = $rpath2;
 }
コード例 #2
0
ファイル: cc_utils.php プロジェクト: JP-Git/moodle
 public static function embedded_mapping($packageroot, $contextid = null)
 {
     $main_file = $packageroot . DIRECTORY_SEPARATOR . 'files.xml';
     $mfile = new XMLGenericDocument();
     if (!$mfile->load($main_file)) {
         return false;
     }
     $query = "/files/file[filename!='.']";
     if (!empty($contextid)) {
         $query .= "[contextid='{$contextid}']";
     }
     $files = $mfile->nodeList($query);
     $depfiles = array();
     foreach ($files as $node) {
         $mainfile = intval($mfile->nodeValue('sortorder', $node));
         $filename = $mfile->nodeValue('filename', $node);
         $filepath = $mfile->nodeValue('filepath', $node);
         $source = $mfile->nodeValue('source', $node);
         $author = $mfile->nodeValue('author', $node);
         $license = $mfile->nodeValue('license', $node);
         $hashedname = $mfile->nodeValue('contenthash', $node);
         $hashpart = substr($hashedname, 0, 2);
         $location = 'files' . DIRECTORY_SEPARATOR . $hashpart . DIRECTORY_SEPARATOR . $hashedname;
         $type = $mfile->nodeValue('mimetype', $node);
         $depfiles[$filepath . $filename] = array($location, $mainfile == 1, strtolower(str_replace(' ', '_', $filename)), $type, $source, $author, $license, strtolower(str_replace(' ', '_', $filepath)));
     }
     return $depfiles;
 }
コード例 #3
0
ファイル: cc_convert_moodle2.php プロジェクト: evltuma/moodle
 /**
  *
  * Process the activites and create item structure
  * @param cc_i_item $item
  * @param array $sequence
  * @param string $packageroot - directory path
  * @throws DOMException
  */
 protected static function process_sequence(cc_i_item &$item, cc_i_manifest &$manifest, array $sequence, $packageroot, $outdir)
 {
     $moodle_backup = $packageroot . DIRECTORY_SEPARATOR . 'moodle_backup.xml';
     $doc = new XMLGenericDocument();
     if (!$doc->load($moodle_backup)) {
         return;
     }
     $activities = $doc->nodeList('/moodle_backup/information/contents/activities/activity');
     if (!empty($activities)) {
         $dpp = new XMLGenericDocument();
         foreach ($activities as $activity) {
             $moduleid = $doc->nodeValue('moduleid', $activity);
             if (in_array($moduleid, $sequence)) {
                 //detect activity type
                 $directory = $doc->nodeValue('directory', $activity);
                 $path = $packageroot . DIRECTORY_SEPARATOR . $directory;
                 $module_file = $path . DIRECTORY_SEPARATOR . 'module.xml';
                 if ($dpp->load($module_file)) {
                     $activity_type = $dpp->nodeValue('/module/modulename');
                     $activity_indentation = $dpp->nodeValue('/module/indent');
                     $aitem = self::item_indenter($item, $activity_indentation);
                     $caller = "cc_converter_{$activity_type}";
                     if (class_exists($caller)) {
                         $obj = new $caller($aitem, $manifest, $packageroot, $path);
                         if (!$obj->convert($outdir)) {
                             throw new RuntimeException("failed to convert {$activity_type}");
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #4
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();
 }
コード例 #5
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();
 }
コード例 #6
0
ファイル: cc_converters.php プロジェクト: evltuma/moodle
 /**
  *
  * Is the element visible in the course?
  * @throws RuntimeException
  * @return bool
  */
 protected function is_visible()
 {
     $tdoc = new XMLGenericDocument();
     if (!$tdoc->load($this->path . DIRECTORY_SEPARATOR . 'module.xml')) {
         throw new RuntimeException('File does not exist!');
     }
     $visible = (int) $tdoc->nodeValue('/module/visible');
     return $visible > 0;
 }