MDL-29956: Implement export of Quiz activity (r16977, r17032)
This commit is contained in:
committed by
Eloy Lafuente (stronk7)
parent
42dffc6feb
commit
91e6ca6e71
@@ -37,4 +37,5 @@ require_once($CFG->dirroot .'/backup/cc/cc_lib/cc_converter_lti.php');
|
||||
require_once($CFG->dirroot .'/backup/cc/cc_lib/cc_converter_forum.php');
|
||||
require_once($CFG->dirroot .'/backup/cc/cc_lib/cc_converter_url.php');
|
||||
require_once($CFG->dirroot .'/backup/cc/cc_lib/cc_converter_resource.php');
|
||||
require_once($CFG->dirroot .'/backup/cc/cc_lib/cc_converter_quiz.php');
|
||||
require_once($CFG->dirroot .'/backup/cc/cc_lib/cc_convert_moodle2.php');
|
||||
|
||||
+2303
-38
File diff suppressed because it is too large
Load Diff
@@ -155,11 +155,9 @@ abstract class cc_convert_moodle2 {
|
||||
$caller = "cc_converter_{$activity_type}";
|
||||
if (class_exists($caller)) {
|
||||
$obj = new $caller($aitem, $manifest, $packageroot, $path);
|
||||
if ( !$obj->convert($outdir) ) {
|
||||
echo "failed to convert {$activity_type}".PHP_EOL;
|
||||
if (!$obj->convert($outdir)) {
|
||||
throw new RuntimeException("failed to convert {$activity_type}");
|
||||
}
|
||||
} else {
|
||||
echo "skipped {$activity_type}".PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,12 +35,18 @@ class cc_converter_lti extends cc_converter {
|
||||
|
||||
public function convert($outdir) {
|
||||
$rt = new basicltil1_resurce_file();
|
||||
$contextid = $this->doc->nodeValue('/activity/@contextid');
|
||||
$title = $this->doc->nodeValue('/activity/lti/name');
|
||||
$rt->set_title($title);
|
||||
$rt->set_description($this->doc->nodeValue('/activity/lti/intro'));
|
||||
$result = cc_helpers::process_linked_files($text,
|
||||
$this->manifest,
|
||||
$this->rootpath,
|
||||
$contextid,
|
||||
$outdir);
|
||||
$rt->set_description($result[0]);
|
||||
$rt->set_launch_url($this->doc->nodeValue('/activity/lti/toolurl'));
|
||||
$rt->set_launch_icon('');
|
||||
$this->store($rt, $outdir, $title);
|
||||
$this->store($rt, $outdir, $title, $result[1]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
require_once 'cc_converters.php';
|
||||
require_once 'cc_general.php';
|
||||
require_once 'cc_asssesment.php';
|
||||
|
||||
class cc_converter_quiz extends cc_converter {
|
||||
|
||||
public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path){
|
||||
$this->cc_type = cc_version11::assessment;
|
||||
$this->defaultfile = 'quiz.xml';
|
||||
$this->defaultname = assesment11_resurce_file::deafultname;
|
||||
parent::__construct($item, $manifest, $rootpath, $path);
|
||||
}
|
||||
|
||||
public function convert($outdir) {
|
||||
$rt = new assesment11_resurce_file();
|
||||
$title = $this->doc->nodeValue('/activity/quiz/name');
|
||||
$rt->set_title($title);
|
||||
|
||||
//metadata
|
||||
$metadata = new cc_assesment_metadata();
|
||||
$rt->set_metadata($metadata);
|
||||
$metadata->enable_feedback();
|
||||
$metadata->enable_hints();
|
||||
$metadata->enable_solutions();
|
||||
//attempts
|
||||
$max_attempts = (int)$this->doc->nodeValue('/activity/quiz/attempts_number');
|
||||
if ($max_attempts > 0) {
|
||||
//qti does not support number of specific attempts bigger than 5 (??)
|
||||
if ($max_attempts > 5) {
|
||||
$max_attempts = cc_qti_values::unlimited;
|
||||
}
|
||||
$metadata->set_maxattempts($max_attempts);
|
||||
}
|
||||
//timelimit must be converted into minutes
|
||||
$timelimit = (int)floor((int)$this->doc->nodeValue('/activity/quiz/timelimit')/60);
|
||||
if ($timelimit > 0) {
|
||||
$metadata->set_timelimit($timelimit);
|
||||
$metadata->enable_latesubmissions(false);
|
||||
}
|
||||
|
||||
$contextid = $this->doc->nodeValue('/activity/@contextid');
|
||||
$result = cc_helpers::process_linked_files( $this->doc->nodeValue('/activity/quiz/intro'),
|
||||
$this->manifest,
|
||||
$this->rootpath,
|
||||
$contextid,
|
||||
$outdir);
|
||||
cc_assesment_helper::add_assesment_description($rt, $result[0], cc_qti_values::htmltype);
|
||||
|
||||
//section
|
||||
$section = new cc_assesment_section();
|
||||
$rt->set_section($section);
|
||||
|
||||
//Process the actual questions
|
||||
$ndeps = cc_assesment_helper::process_questions($this->doc,
|
||||
$this->manifest,
|
||||
$section,
|
||||
$this->rootpath,
|
||||
$contextid,
|
||||
$outdir);
|
||||
//store any additional dependencies
|
||||
$deps = array_merge($result[1], $ndeps);
|
||||
|
||||
//store everything
|
||||
$this->store($rt, $outdir, $title, $deps);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -82,10 +82,11 @@ abstract class cc_helpers {
|
||||
public static function embedded_files($html) {
|
||||
$result = array();
|
||||
$doc = new XMLGenericDocument();
|
||||
if ($doc->loadHTML($html)) {
|
||||
$list = $doc->nodeList("//img[starts-with(@src,'@@PLUGINFILE@@')]/@src");
|
||||
if (!empty($html) && $doc->loadHTML($html)) {
|
||||
$list = $doc->nodeList("//img[starts-with(@src,'@@PLUGINFILE@@')]/@src | //a[starts-with(@href,'@@PLUGINFILE@@')]/@href");
|
||||
foreach ($list as $filelink) {
|
||||
$result[] = str_replace('@@PLUGINFILE@@', '', $filelink->nodeValue);
|
||||
$rawvalue = rawurldecode(str_replace('@@PLUGINFILE@@', '', $filelink->nodeValue));
|
||||
$result[] = $rawvalue;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
@@ -226,7 +227,7 @@ abstract class cc_helpers {
|
||||
*/
|
||||
$lfiles = self::embedded_files($content);
|
||||
$text = $content;
|
||||
$deps = null;
|
||||
$deps = array();
|
||||
if (!empty($lfiles)) {
|
||||
$files = self::handle_static_content($manifest,
|
||||
$packageroot,
|
||||
@@ -234,12 +235,14 @@ abstract class cc_helpers {
|
||||
$outdir);
|
||||
foreach ($lfiles as $lfile) {
|
||||
if (array_key_exists($lfile, $files)) {
|
||||
$text = str_replace('@@PLUGINFILE@@'.$lfile,
|
||||
'$IMS-CC-FILEBASE$../'.$files[$lfile][1],
|
||||
$text);
|
||||
$filename = rawurlencode(basename($lfile));
|
||||
$content = str_replace('@@PLUGINFILE@@/'.$filename,
|
||||
'$IMS-CC-FILEBASE$../'.$files[$lfile][1],
|
||||
$content);
|
||||
$deps[] = $files[$lfile][0];
|
||||
}
|
||||
}
|
||||
$text = $content;
|
||||
}
|
||||
return array($text, $deps);
|
||||
}
|
||||
@@ -381,3 +384,50 @@ class pkg_static_resources {
|
||||
$this->finished = false ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class pkg_resource_dependencies {
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $values = array();
|
||||
|
||||
/**
|
||||
* @var pkg_resource_dependencies
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
private function __clone() {
|
||||
}
|
||||
private function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return pkg_resource_dependencies
|
||||
*/
|
||||
public static function instance() {
|
||||
if (empty(self::$instance)) {
|
||||
$c = __CLASS__;
|
||||
self::$instance = new $c();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $deps
|
||||
*/
|
||||
public function add(array $deps) {
|
||||
$this->values = array_merge($this->values, $deps);
|
||||
}
|
||||
|
||||
public function reset() {
|
||||
$this->values = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function get_deps() {
|
||||
return $this->values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @package backup-convert
|
||||
* @subpackage cc-library
|
||||
* @copyright 2011 Darko Miletic <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
* Implementation of Common Cartridge library based on
|
||||
* {@link http://www.imsglobal.org/cc/ IMS Common Cartridge Standard v1.2}
|
||||
*
|
||||
* @author Darko Miletic
|
||||
* @author Daniel Muhlrad ([email protected])
|
||||
* @version 1.0
|
||||
* @copyright 2009 {@link http://www.uvcms.com UVCMS e-learning}
|
||||
* @package cc_library
|
||||
*
|
||||
*/
|
||||
|
||||
require_once 'gral_lib/cssparser.php';
|
||||
|
||||
@@ -207,11 +198,6 @@ class XMLGenericDocument {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// public function nodeValue($path,$count = 1,$node=null){
|
||||
// $nd = $this->node($path,$count,$node);
|
||||
// return $this->nodeTextValue($nd);
|
||||
// }
|
||||
|
||||
/**
|
||||
*
|
||||
* Get's text value of the node based on xpath query
|
||||
@@ -221,7 +207,7 @@ class XMLGenericDocument {
|
||||
* @return string
|
||||
*/
|
||||
public function nodeValue($path, $node = null, $count = 1){
|
||||
$nd = $this->node($path,$count,$node);
|
||||
$nd = $this->node($path, $node, $count);
|
||||
return $this->nodeTextValue($nd);
|
||||
}
|
||||
|
||||
@@ -251,11 +237,11 @@ class XMLGenericDocument {
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param string $path
|
||||
* @param int $count
|
||||
* @param DOMNode $nd
|
||||
* @param int $count
|
||||
* @return DOMNode
|
||||
*/
|
||||
public function node($path, $count = 1, $nd=null) {
|
||||
public function node($path, $nd = null, $count = 1) {
|
||||
$result = null;
|
||||
$resultlist = $this->nodeList($path,$nd);
|
||||
if ( is_object($resultlist) &&
|
||||
@@ -295,7 +281,7 @@ class XMLGenericDocument {
|
||||
*/
|
||||
public function create_attribute_ns($namespace, $name, $value = null) {
|
||||
$result = $this->doc->createAttributeNS($namespace, $name);
|
||||
if (!empty($value)) {
|
||||
if (!is_null($value)) {
|
||||
$result->nodeValue = $value;
|
||||
}
|
||||
return $result;
|
||||
@@ -310,7 +296,7 @@ class XMLGenericDocument {
|
||||
*/
|
||||
public function create_attribute($name, $value = null) {
|
||||
$result = $this->doc->createAttribute($name);
|
||||
if (!empty($value)) {
|
||||
if (!is_null($value)) {
|
||||
$result->nodeValue = $value;
|
||||
}
|
||||
return $result;
|
||||
@@ -327,7 +313,7 @@ class XMLGenericDocument {
|
||||
*/
|
||||
public function append_new_element_ns(DOMNode &$parentnode, $namespace, $name, $value = null) {
|
||||
$newnode = null;
|
||||
if (empty($value)) {
|
||||
if (is_null($value)) {
|
||||
$newnode = $this->doc->createElementNS($namespace, $name);
|
||||
} else {
|
||||
$newnode = $this->doc->createElementNS($namespace, $name, $value);
|
||||
@@ -335,6 +321,23 @@ class XMLGenericDocument {
|
||||
return $parentnode->appendChild($newnode);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* New node with CDATA content
|
||||
* @param DOMNode $parentnode
|
||||
* @param string $namespace
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function append_new_element_ns_cdata(DOMNode &$parentnode, $namespace, $name, $value = null) {
|
||||
$newnode = $this->doc->createElementNS($namespace, $name);
|
||||
if (!is_null($value)) {
|
||||
$cdata = $this->doc->createCDATASection($value);
|
||||
$newnode->appendChild($cdata);
|
||||
}
|
||||
return $parentnode->appendChild($newnode);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Adds new node
|
||||
@@ -345,7 +348,7 @@ class XMLGenericDocument {
|
||||
*/
|
||||
public function append_new_element(DOMNode &$parentnode, $name, $value = null) {
|
||||
$newnode = null;
|
||||
if (empty($value)) {
|
||||
if (is_null($value)) {
|
||||
$newnode = $this->doc->createElement($name);
|
||||
} else {
|
||||
$newnode = $this->doc->createElement($name, $value);
|
||||
|
||||
@@ -206,6 +206,8 @@ $string['rootsettingcomments'] = 'Include comments';
|
||||
$string['rootsettinguserscompletion'] = 'Include user completion details';
|
||||
$string['rootsettinglogs'] = 'Include course logs';
|
||||
$string['rootsettinggradehistories'] = 'Include grade history';
|
||||
$string['rootsettingimscc1'] = 'Convert to IMS Common Cartridge 1.0';
|
||||
$string['rootsettingimscc11'] = 'Convert to IMS Common Cartridge 1.1';
|
||||
$string['storagecourseonly'] = 'Course backup filearea';
|
||||
$string['storagecourseandexternal'] = 'Course backup filearea and the specified directory';
|
||||
$string['storageexternalonly'] = 'Specified directory for automated backups';
|
||||
|
||||
Reference in New Issue
Block a user