MDL-44630: Review changes
* Fixing coding style violations. * Fixing DOMDocument warning.
This commit is contained in:
@@ -13,13 +13,14 @@
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Main include for IMS Common Cartridge export classes
|
||||
*
|
||||
* @package backup-convert
|
||||
* @copyright 2011 Darko Miletic <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
* Main include for IMS Common Cartridge export classes
|
||||
*
|
||||
* @package backup-convert
|
||||
* @copyright 2011 Darko Miletic <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once($CFG->dirroot .'/backup/cc/cc_lib/xmlbase.php');
|
||||
require_once($CFG->dirroot .'/backup/cc/cc_lib/cc_resources.php');
|
||||
|
||||
@@ -31,7 +31,7 @@ class cc_assesment_question_essay extends cc_assesment_question_proc_base {
|
||||
|
||||
public function on_generate_metadata() {
|
||||
parent::on_generate_metadata();
|
||||
//Mark essay for manual grading
|
||||
// Mark essay for manual grading.
|
||||
$this->qmetadata->enable_scoringpermitted();
|
||||
$this->qmetadata->enable_computerscored(false);
|
||||
}
|
||||
@@ -49,12 +49,12 @@ class cc_assesment_question_essay extends cc_assesment_question_proc_base {
|
||||
public function on_generate_response_processing() {
|
||||
parent::on_generate_response_processing();
|
||||
|
||||
//respconditions
|
||||
// Response conditions.
|
||||
if (!empty($this->general_feedback)) {
|
||||
$qrespcondition = new cc_assesment_respconditiontype();
|
||||
$qrespcondition->set_title('General feedback');
|
||||
$this->qresprocessing->add_respcondition($qrespcondition);
|
||||
//define the condition for success
|
||||
// Define the condition for success.
|
||||
$qconditionvar = new cc_assignment_conditionvar();
|
||||
$qrespcondition->set_conditionvar($qconditionvar);
|
||||
$qother = new cc_assignment_conditionvar_othertype();
|
||||
|
||||
@@ -21,13 +21,16 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
|
||||
|
||||
require_once 'cc_asssesment.php';
|
||||
require_once('cc_asssesment.php');
|
||||
|
||||
class cc_assesment_question_sfib extends cc_assesment_question_proc_base {
|
||||
public function __construct($quiz, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir) {
|
||||
parent::__construct($quiz, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);
|
||||
$this->qtype = cc_qti_profiletype::field_entry;
|
||||
$this->correct_answer_node_id = $this->questions->nodeValue('plugin_qtype_truefalse_question/truefalse/trueanswer', $this->question_node);
|
||||
$this->correct_answer_node_id = $this->questions->nodeValue(
|
||||
'plugin_qtype_truefalse_question/truefalse/trueanswer',
|
||||
$this->question_node
|
||||
);
|
||||
$maximum_quiz_grade = (int)$this->quiz->nodeValue('/activity/quiz/grade');
|
||||
$this->total_grade_value = ($maximum_quiz_grade + 1).'.0000000';
|
||||
}
|
||||
@@ -45,10 +48,9 @@ class cc_assesment_question_sfib extends cc_assesment_question_proc_base {
|
||||
parent::on_generate_presentation();
|
||||
$response_str = new cc_assesment_response_strtype();
|
||||
$response_fib = new cc_assesment_render_fibtype();
|
||||
/**
|
||||
* The standard requires that only rows attribute must be set
|
||||
* The rest may or may not be configured. For the sake of brevity we leave it empty.
|
||||
*/
|
||||
|
||||
// The standard requires that only rows attribute must be set,
|
||||
// the rest may or may not be configured. For the sake of brevity we leave it empty.
|
||||
$response_fib->set_rows(1);
|
||||
$response_str->set_render_fib($response_fib);
|
||||
$this->qpresentation->set_response_str($response_str);
|
||||
@@ -56,7 +58,7 @@ class cc_assesment_question_sfib extends cc_assesment_question_proc_base {
|
||||
|
||||
public function on_generate_feedbacks() {
|
||||
parent::on_generate_feedbacks();
|
||||
//Question combined feedbacks
|
||||
// Question combined feedback.
|
||||
$responsenodes = $this->questions->nodeList('plugin_qtype_shortanswer_question//answer', $this->question_node);
|
||||
$count = 0;
|
||||
foreach ($responsenodes as $respnode) {
|
||||
@@ -95,17 +97,14 @@ class cc_assesment_question_sfib extends cc_assesment_question_proc_base {
|
||||
public function on_generate_response_processing() {
|
||||
parent::on_generate_response_processing();
|
||||
|
||||
//respconditions
|
||||
/**
|
||||
* General unconditional feedback must be added as a first respcondition
|
||||
* without any condition and just displayfeedback (if exists)
|
||||
*/
|
||||
// General unconditional feedback must be added as a first respcondition
|
||||
// without any condition and just displayfeedback (if exists).
|
||||
if (!empty($this->general_feedback)) {
|
||||
$qrespcondition = new cc_assesment_respconditiontype();
|
||||
$qrespcondition->set_title('General feedback');
|
||||
$this->qresprocessing->add_respcondition($qrespcondition);
|
||||
$qrespcondition->enable_continue();
|
||||
//define the condition for success
|
||||
// Define the condition for success.
|
||||
$qconditionvar = new cc_assignment_conditionvar();
|
||||
$qrespcondition->set_conditionvar($qconditionvar);
|
||||
$qother = new cc_assignment_conditionvar_othertype();
|
||||
@@ -116,10 +115,15 @@ class cc_assesment_question_sfib extends cc_assesment_question_proc_base {
|
||||
$qdisplayfeedback->set_linkrefid('general_fb');
|
||||
}
|
||||
|
||||
//Answer separate conditions
|
||||
$correct_responses = $this->questions->nodeList('plugin_qtype_shortanswer_question//answer[fraction=1]', $this->question_node);
|
||||
$incorrect_responses = $this->questions->nodeList('plugin_qtype_shortanswer_question//answer[fraction<1]', $this->question_node);
|
||||
$items = array(array($correct_responses ,$this->correct_feedbacks), array($incorrect_responses, $this->incorrect_feedbacks));
|
||||
// Answer separate conditions.
|
||||
$correct_responses = $this->questions->nodeList(
|
||||
'plugin_qtype_shortanswer_question//answer[fraction=1]', $this->question_node);
|
||||
$incorrect_responses = $this->questions->nodeList(
|
||||
'plugin_qtype_shortanswer_question//answer[fraction<1]', $this->question_node);
|
||||
$items = array(
|
||||
array($correct_responses, $this->correct_feedbacks),
|
||||
array($incorrect_responses, $this->incorrect_feedbacks)
|
||||
);
|
||||
foreach ($items as $respfeed) {
|
||||
foreach ($respfeed[0] as $coresponse) {
|
||||
$qrespcondition = new cc_assesment_respconditiontype();
|
||||
@@ -141,24 +145,21 @@ class cc_assesment_question_sfib extends cc_assesment_question_proc_base {
|
||||
}
|
||||
}
|
||||
}
|
||||
//success condition
|
||||
/**
|
||||
* For all question types outside of the Essay question, scoring is done in a
|
||||
* single <respcondition> with a continue flag set to No. The outcome is always
|
||||
* a variable named SCORE which value must be set to 100 in case of correct answer.
|
||||
* Partial scores (not 0 or 100) are not supported.
|
||||
*/
|
||||
// Success condition.
|
||||
// For all question types outside of the Essay question, scoring is done in a
|
||||
// single <respcondition> with a continue flag set to No. The outcome is always
|
||||
// a variable named SCORE which value must be set to 100 in case of correct answer.
|
||||
// Partial scores (not 0 or 100) are not supported.
|
||||
$qrespcondition = new cc_assesment_respconditiontype();
|
||||
$qrespcondition->set_title('Correct');
|
||||
$this->qresprocessing->add_respcondition($qrespcondition);
|
||||
$qrespcondition->enable_continue(false);
|
||||
$qsetvar = new cc_assignment_setvartype(100);
|
||||
$qrespcondition->add_setvar($qsetvar);
|
||||
//define the condition for success
|
||||
// Define the condition for success.
|
||||
$qconditionvar = new cc_assignment_conditionvar();
|
||||
$qrespcondition->set_conditionvar($qconditionvar);
|
||||
//No case sensitivity as stated in documentation
|
||||
//$case_sensitive = $this->questions->nodeValue('plugin_qtype_shortanswer_question//shortanswer/usecase', $this->question_node)==1;
|
||||
|
||||
foreach ($correct_responses as $coresponse) {
|
||||
$respc = $this->questions->nodeValue('answertext', $coresponse);
|
||||
$qvarequal = new cc_assignment_conditionvar_varequaltype($respc);
|
||||
@@ -167,12 +168,11 @@ class cc_assesment_question_sfib extends cc_assesment_question_proc_base {
|
||||
$qvarequal->enable_case(false);
|
||||
}
|
||||
|
||||
//Add incorrect handling
|
||||
// Add incorrect handling.
|
||||
$qrespcondition = new cc_assesment_respconditiontype();
|
||||
//$qrespcondition->set_title('General feedback');
|
||||
$this->qresprocessing->add_respcondition($qrespcondition);
|
||||
$qrespcondition->enable_continue(false);
|
||||
//define the condition for faliure
|
||||
// Define the condition for failure.
|
||||
$qconditionvar = new cc_assignment_conditionvar();
|
||||
$qrespcondition->set_conditionvar($qconditionvar);
|
||||
$qother = new cc_assignment_conditionvar_othertype();
|
||||
|
||||
@@ -21,28 +21,29 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
|
||||
|
||||
require_once 'cc_asssesment.php';
|
||||
require_once('cc_asssesment.php');
|
||||
|
||||
class cc_assesment_question_truefalse extends cc_assesment_question_proc_base {
|
||||
public function __construct($quiz, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir) {
|
||||
parent::__construct($quiz, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);
|
||||
$this->qtype = cc_qti_profiletype::true_false;
|
||||
$this->correct_answer_node_id = $this->questions->nodeValue('plugin_qtype_truefalse_question/truefalse/trueanswer', $this->question_node);
|
||||
$this->correct_answer_node_id = $this->questions->nodeValue(
|
||||
'plugin_qtype_truefalse_question/truefalse/trueanswer', $this->question_node);
|
||||
$maximum_quiz_grade = (int)$this->quiz->nodeValue('/activity/quiz/grade');
|
||||
$this->total_grade_value = ($maximum_quiz_grade + 1).'.0000000';
|
||||
}
|
||||
|
||||
public function on_generate_answers() {
|
||||
//add responses holder
|
||||
// Add responses holder.
|
||||
$qresponse_lid = new cc_response_lidtype();
|
||||
$this->qresponse_lid = $qresponse_lid;
|
||||
$this->qpresentation->set_response_lid($qresponse_lid);
|
||||
$qresponse_choice = new cc_assesment_render_choicetype();
|
||||
$qresponse_lid->set_render_choice($qresponse_choice);
|
||||
//Mark that question has only one correct answer -
|
||||
//which applies for multiple choice and yes/no questions
|
||||
// Mark that question has only one correct answer -
|
||||
// which applies for multiple choice and yes/no questions.
|
||||
$qresponse_lid->set_rcardinality(cc_qti_values::Single);
|
||||
//are we to shuffle the responses?
|
||||
// Are we to shuffle the responses?
|
||||
$shuffle_answers = (int)$this->quiz->nodeValue('/activity/quiz/shuffleanswers') > 0;
|
||||
$qresponse_choice->enable_shuffle($shuffle_answers);
|
||||
$answerlist = array();
|
||||
@@ -59,7 +60,7 @@ class cc_assesment_question_truefalse extends cc_assesment_question_proc_base {
|
||||
if (empty($this->correct_answer_ident) && $id) {
|
||||
$this->correct_answer_ident = $answer_ident;
|
||||
}
|
||||
//add answer specific feedbacks if not empty
|
||||
// Add answer specific feedback if not empty.
|
||||
$content = $this->questions->nodeValue('feedback', $node);
|
||||
if (!empty($content)) {
|
||||
$result = cc_helpers::process_linked_files( $content,
|
||||
@@ -87,17 +88,15 @@ class cc_assesment_question_truefalse extends cc_assesment_question_proc_base {
|
||||
public function on_generate_response_processing() {
|
||||
parent::on_generate_response_processing();
|
||||
|
||||
//respconditions
|
||||
/**
|
||||
* General unconditional feedback must be added as a first respcondition
|
||||
* without any condition and just displayfeedback (if exists)
|
||||
*/
|
||||
// Response conditions.
|
||||
// General unconditional feedback must be added as a first respcondition
|
||||
// without any condition and just displayfeedback (if exists).
|
||||
if (!empty($this->general_feedback)) {
|
||||
$qrespcondition = new cc_assesment_respconditiontype();
|
||||
$qrespcondition->set_title('General feedback');
|
||||
$this->qresprocessing->add_respcondition($qrespcondition);
|
||||
$qrespcondition->enable_continue();
|
||||
//define the condition for success
|
||||
// Define the condition for success.
|
||||
$qconditionvar = new cc_assignment_conditionvar();
|
||||
$qrespcondition->set_conditionvar($qconditionvar);
|
||||
$qother = new cc_assignment_conditionvar_othertype();
|
||||
@@ -108,23 +107,21 @@ class cc_assesment_question_truefalse extends cc_assesment_question_proc_base {
|
||||
$qdisplayfeedback->set_linkrefid('general_fb');
|
||||
}
|
||||
|
||||
//success condition
|
||||
/**
|
||||
* For all question types outside of the Essay question, scoring is done in a
|
||||
* single <respcondition> with a continue flag set to No. The outcome is always
|
||||
* a variable named SCORE which value must be set to 100 in case of correct answer.
|
||||
* Partial scores (not 0 or 100) are not supported.
|
||||
*/
|
||||
// Success condition.
|
||||
// For all question types outside of the Essay question, scoring is done in a
|
||||
// single <respcondition> with a continue flag set to No. The outcome is always
|
||||
// a variable named SCORE which value must be set to 100 in case of correct answer.
|
||||
// Partial scores (not 0 or 100) are not supported.
|
||||
$qrespcondition = new cc_assesment_respconditiontype();
|
||||
$qrespcondition->set_title('Correct');
|
||||
$this->qresprocessing->add_respcondition($qrespcondition);
|
||||
$qrespcondition->enable_continue(false);
|
||||
$qsetvar = new cc_assignment_setvartype(100);
|
||||
$qrespcondition->add_setvar($qsetvar);
|
||||
//define the condition for success
|
||||
// Define the condition for success.
|
||||
$qconditionvar = new cc_assignment_conditionvar();
|
||||
$qrespcondition->set_conditionvar($qconditionvar);
|
||||
//TODO: recheck this
|
||||
// TODO: recheck this.
|
||||
$qvarequal = new cc_assignment_conditionvar_varequaltype($this->correct_answer_ident);
|
||||
$qconditionvar->set_varequal($qvarequal);
|
||||
$qvarequal->set_respident($this->qresponse_lid->get_ident());
|
||||
@@ -143,7 +140,7 @@ class cc_assesment_question_truefalse extends cc_assesment_question_proc_base {
|
||||
$qdisplayfeedback->set_linkrefid($ident);
|
||||
}
|
||||
|
||||
//rest of the conditions
|
||||
// Rest of the conditions.
|
||||
foreach ($this->answerlist as $ident => $refid) {
|
||||
if ($ident == $this->correct_answer_ident) {
|
||||
continue;
|
||||
@@ -153,7 +150,7 @@ class cc_assesment_question_truefalse extends cc_assesment_question_proc_base {
|
||||
$this->qresprocessing->add_respcondition($qrespcondition);
|
||||
$qsetvar = new cc_assignment_setvartype(0);
|
||||
$qrespcondition->add_setvar($qsetvar);
|
||||
//define the condition for fail
|
||||
// Define the condition for fail.
|
||||
$qconditionvar = new cc_assignment_conditionvar();
|
||||
$qrespcondition->set_conditionvar($qconditionvar);
|
||||
$qvarequal = new cc_assignment_conditionvar_varequaltype($ident);
|
||||
|
||||
@@ -21,15 +21,15 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
|
||||
|
||||
require_once 'cc_utils.php';
|
||||
require_once 'cc_general.php';
|
||||
require_once('cc_utils.php');
|
||||
require_once('cc_general.php');
|
||||
|
||||
abstract class cc_xml_namespace {
|
||||
const xml = 'http://www.w3.org/XML/1998/namespace';
|
||||
}
|
||||
|
||||
abstract class cc_qti_metadata {
|
||||
//assesment
|
||||
// Assessment.
|
||||
const qmd_assessmenttype = 'qmd_assessmenttype';
|
||||
const qmd_scoretype = 'qmd_scoretype';
|
||||
const qmd_feedbackpermitted = 'qmd_feedbackpermitted';
|
||||
@@ -40,7 +40,7 @@ abstract class cc_qti_metadata {
|
||||
const cc_maxattempts = 'cc_maxattempts';
|
||||
const cc_profile = 'cc_profile';
|
||||
|
||||
//item
|
||||
// Items.
|
||||
const cc_weighting = 'cc_weighting';
|
||||
const qmd_scoringpermitted = 'qmd_scoringpermitted';
|
||||
const qmd_computerscored = 'qmd_computerscored';
|
||||
|
||||
@@ -14,18 +14,18 @@
|
||||
// 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 2012 Darko Miletic <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
* @package backup-convert
|
||||
* @subpackage cc-library
|
||||
* @copyright 2012 Darko Miletic <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once 'cc_converters.php';
|
||||
require_once 'cc_general.php';
|
||||
require_once('cc_converters.php');
|
||||
require_once('cc_general.php');
|
||||
|
||||
class cc_converter_folder extends cc_converter {
|
||||
|
||||
public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path){
|
||||
public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path) {
|
||||
$this->defaultfile = 'folder.xml';
|
||||
parent::__construct($item, $manifest, $rootpath, $path);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,36 @@
|
||||
<?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/>.
|
||||
|
||||
require_once 'cc_converters.php';
|
||||
require_once 'cc_general.php';
|
||||
require_once 'cc_asssesment.php';
|
||||
require_once 'cc_assesment_truefalse.php';
|
||||
require_once 'cc_assesment_essay.php';
|
||||
require_once 'cc_assesment_sfib.php';
|
||||
/**
|
||||
* @package backup-convert
|
||||
* @subpackage cc-library
|
||||
* @copyright 2012 Darko Miletic <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once('cc_converters.php');
|
||||
require_once('cc_general.php');
|
||||
require_once('cc_asssesment.php');
|
||||
require_once('cc_assesment_truefalse.php');
|
||||
require_once('cc_assesment_essay.php');
|
||||
require_once('cc_assesment_sfib.php');
|
||||
|
||||
class cc_converter_quiz extends cc_converter {
|
||||
|
||||
public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path){
|
||||
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;
|
||||
@@ -21,23 +42,23 @@ class cc_converter_quiz extends cc_converter {
|
||||
$title = $this->doc->nodeValue('/activity/quiz/name');
|
||||
$rt->set_title($title);
|
||||
|
||||
//metadata
|
||||
// Metadata.
|
||||
$metadata = new cc_assesment_metadata();
|
||||
$rt->set_metadata($metadata);
|
||||
$metadata->enable_feedback();
|
||||
$metadata->enable_hints();
|
||||
$metadata->enable_solutions();
|
||||
//attempts
|
||||
// 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 (??)
|
||||
// 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);
|
||||
// Time limit 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);
|
||||
@@ -51,11 +72,11 @@ class cc_converter_quiz extends cc_converter {
|
||||
$outdir);
|
||||
cc_assesment_helper::add_assesment_description($rt, $result[0], cc_qti_values::htmltype);
|
||||
|
||||
//section
|
||||
// Section.
|
||||
$section = new cc_assesment_section();
|
||||
$rt->set_section($section);
|
||||
|
||||
//Process the actual questions
|
||||
// Process the actual questions.
|
||||
$ndeps = cc_assesment_helper::process_questions($this->doc,
|
||||
$this->manifest,
|
||||
$section,
|
||||
@@ -63,14 +84,14 @@ class cc_converter_quiz extends cc_converter {
|
||||
$contextid,
|
||||
$outdir);
|
||||
if ($ndeps === false) {
|
||||
//No exportable questions in quizz or quizz has no questions
|
||||
//so just skip it
|
||||
// No exportable questions in quiz or quiz has no questions
|
||||
// so just skip it.
|
||||
return true;
|
||||
}
|
||||
//store any additional dependencies
|
||||
// Store any additional dependencies.
|
||||
$deps = array_merge($result[1], $ndeps);
|
||||
|
||||
//store everything
|
||||
// Store everything.
|
||||
$this->store($rt, $outdir, $title, $deps);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -14,18 +14,18 @@
|
||||
// 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
|
||||
*/
|
||||
* @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
|
||||
*/
|
||||
|
||||
require_once 'cc_converters.php';
|
||||
require_once 'cc_general.php';
|
||||
require_once('cc_converters.php');
|
||||
require_once('cc_general.php');
|
||||
|
||||
class cc_converter_resource extends cc_converter {
|
||||
|
||||
public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path){
|
||||
public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path) {
|
||||
$this->cc_type = cc_version11::webcontent;
|
||||
$this->defaultfile = 'resource.xml';
|
||||
parent::__construct($item, $manifest, $rootpath, $path);
|
||||
@@ -40,7 +40,7 @@ class cc_converter_resource extends cc_converter {
|
||||
$outdir);
|
||||
$deps = null;
|
||||
$resvalue = null;
|
||||
foreach ($files as $vfile => $values) {
|
||||
foreach ($files as $values) {
|
||||
if ($values[2]) {
|
||||
$resvalue = $values[0];
|
||||
break;
|
||||
@@ -52,7 +52,7 @@ class cc_converter_resource extends cc_converter {
|
||||
$resitem->title = $title;
|
||||
$this->item->add_child_item($resitem);
|
||||
|
||||
//checking the visibility
|
||||
// Checking the visibility.
|
||||
$this->manifest->update_instructoronly($resvalue, !$this->is_visible());
|
||||
|
||||
return true;
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
// 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
|
||||
*/
|
||||
* @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
|
||||
*/
|
||||
|
||||
require_once 'cc_interfaces.php';
|
||||
require_once('cc_interfaces.php');
|
||||
|
||||
abstract class cc_converter {
|
||||
/**
|
||||
@@ -81,7 +81,7 @@ abstract class cc_converter {
|
||||
* @param string $path
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path){
|
||||
public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path) {
|
||||
$rpath = realpath($rootpath);
|
||||
if (empty($rpath)) {
|
||||
throw new InvalidArgumentException('Invalid path!');
|
||||
|
||||
@@ -14,21 +14,19 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* Manifest management
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
|
||||
require_once 'cc_utils.php';
|
||||
require_once 'xmlbase.php';
|
||||
require_once 'cc_resources.php';
|
||||
require_once 'cc_version_base.php';
|
||||
require_once 'gral_lib/pathutils.php';
|
||||
* Manifest management
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
require_once('cc_utils.php');
|
||||
require_once('xmlbase.php');
|
||||
require_once('cc_resources.php');
|
||||
require_once('cc_version_base.php');
|
||||
require_once('gral_lib/pathutils.php');
|
||||
|
||||
/**
|
||||
* Manifest Class
|
||||
@@ -44,16 +42,15 @@ class cc_manifest extends XMLGenericDocument implements cc_i_manifest {
|
||||
private $ares = array();
|
||||
private $mainidentifier = null;
|
||||
|
||||
public function __construct($ccver = cc_version::v1,$activemanifest=null,
|
||||
$parentmanifest=null,$parentparentmanifest=null) {
|
||||
public function __construct($ccver = cc_version::v1, $activemanifest=null,
|
||||
$parentmanifest=null, $parentparentmanifest=null) {
|
||||
|
||||
if (is_int($ccver)){
|
||||
if (is_int($ccver)) {
|
||||
$this->ccversion=$ccver;
|
||||
$classname = "cc_version{$ccver}";
|
||||
$this->ccobj = new $classname;
|
||||
parent::__construct('UTF-8',true);
|
||||
} else
|
||||
if (is_object($ccver) && (get_class($ccver)=='cc_manifest')){
|
||||
parent::__construct('UTF-8', true);
|
||||
} else if (is_object($ccver) && (get_class($ccver)=='cc_manifest')) {
|
||||
$this->doc = $ccver->doc;
|
||||
$this->rootmanifest = $ccver->rootmanifest;
|
||||
$this->activemanifest = $activemanifest;
|
||||
@@ -65,19 +62,14 @@ class cc_manifest extends XMLGenericDocument implements cc_i_manifest {
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register Namespace for use XPATH
|
||||
*
|
||||
*/
|
||||
public function register_namespaces_for_xpath(){
|
||||
public function register_namespaces_for_xpath() {
|
||||
$scnam = $this->activemanifest->get_cc_namespaces();
|
||||
foreach ($scnam as $key => $value){
|
||||
$this->registerNS($key,$value);
|
||||
foreach ($scnam as $key => $value) {
|
||||
$this->registerNS($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,11 +86,11 @@ class cc_manifest extends XMLGenericDocument implements cc_i_manifest {
|
||||
*
|
||||
* @param cc_i_metadata_manifest $met
|
||||
*/
|
||||
public function add_metadata_manifest (cc_i_metadata_manifest $met){
|
||||
public function add_metadata_manifest(cc_i_metadata_manifest $met) {
|
||||
$metanode = $this->node("//imscc:manifest[@identifier='".
|
||||
$this->activemanifest->manifestID().
|
||||
"']/imscc:metadata");
|
||||
$nmeta = $this->activemanifest->create_metadata_node($met,$this->doc,$metanode);
|
||||
$nmeta = $this->activemanifest->create_metadata_node($met, $this->doc, $metanode);
|
||||
$metanode->appendChild($nmeta);
|
||||
}
|
||||
|
||||
@@ -109,18 +101,18 @@ class cc_manifest extends XMLGenericDocument implements cc_i_manifest {
|
||||
* @param cc_i_metadata_resource $met
|
||||
* @param string $identifier
|
||||
*/
|
||||
public function add_metadata_resource (cc_i_metadata_resource $met,$identifier){
|
||||
$metanode = $this->node("//imscc:resource".
|
||||
"[@identifier='".
|
||||
$identifier.
|
||||
"']");
|
||||
$metanode2 = $this->node("//imscc:resource".
|
||||
"[@identifier='".
|
||||
$identifier.
|
||||
"']/imscc:file");
|
||||
$nspaces = $this->activemanifest->get_cc_namespaces();
|
||||
$dnode = $this->append_new_element_ns($metanode2, $nspaces['imscc'], 'metadata');
|
||||
$this->activemanifest->create_metadata_resource_node($met, $this->doc, $dnode);
|
||||
public function add_metadata_resource(cc_i_metadata_resource $met, $identifier) {
|
||||
$metanode = $this->node("//imscc:resource".
|
||||
"[@identifier='".
|
||||
$identifier.
|
||||
"']");
|
||||
$metanode2 = $this->node("//imscc:resource".
|
||||
"[@identifier='".
|
||||
$identifier.
|
||||
"']/imscc:file");
|
||||
$nspaces = $this->activemanifest->get_cc_namespaces();
|
||||
$dnode = $this->append_new_element_ns($metanode2, $nspaces['imscc'], 'metadata');
|
||||
$this->activemanifest->create_metadata_resource_node($met, $this->doc, $dnode);
|
||||
}
|
||||
|
||||
|
||||
@@ -131,46 +123,56 @@ class cc_manifest extends XMLGenericDocument implements cc_i_manifest {
|
||||
* @param string $identifier
|
||||
* @param string $filename
|
||||
*/
|
||||
public function add_metadata_file (cc_i_metadata_file $met,$identifier,$filename){
|
||||
public function add_metadata_file(cc_i_metadata_file $met, $identifier, $filename) {
|
||||
|
||||
if (empty($met) || empty($identifier) || empty($filename)){
|
||||
if (empty($met) || empty($identifier) || empty($filename)) {
|
||||
throw new Exception('Try to add a metadata file with nulls values given!');
|
||||
}
|
||||
|
||||
$metanode = $this->node("//imscc:resource".
|
||||
"[@identifier='".
|
||||
$identifier.
|
||||
"']/imscc:file".
|
||||
"[@href='".
|
||||
$filename.
|
||||
"']");
|
||||
"[@identifier='".
|
||||
$identifier.
|
||||
"']/imscc:file".
|
||||
"[@href='".
|
||||
$filename.
|
||||
"']");
|
||||
|
||||
$nspaces = $this->activemanifest->get_cc_namespaces();
|
||||
$dnode = $this->doc->createElementNS($nspaces['imscc'], "metadata");
|
||||
$nspaces = $this->activemanifest->get_cc_namespaces();
|
||||
$dnode = $this->doc->createElementNS($nspaces['imscc'], "metadata");
|
||||
|
||||
$metanode->appendChild($dnode);
|
||||
$metanode->appendChild($dnode);
|
||||
|
||||
$this->activemanifest->create_metadata_file_node($met,$this->doc,$dnode);
|
||||
$this->activemanifest->create_metadata_file_node($met, $this->doc, $dnode);
|
||||
}
|
||||
|
||||
|
||||
public function on_create (){
|
||||
public function on_create() {
|
||||
$this->activemanifest = cc_builder_creator::factory($this->ccversion);
|
||||
$this->rootmanifest = $this->activemanifest;
|
||||
$result = $this->activemanifest->create_manifest($this->doc);
|
||||
$this->register_namespaces_for_xpath();
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public function get_relative_base_path() {
|
||||
return $this->activemanifest->base();
|
||||
}
|
||||
|
||||
public function get_relative_base_path() {return $this->activemanifest->base();}
|
||||
public function parent_manifest () {return new cc_manifest($this,$this->parentmanifest,$this->parentparentmanifest);}
|
||||
public function root_manifest () {return new cc_manifest($this,$this->rootmanifest);}
|
||||
public function manifestID () {return $this->activemanifest->manifestID();}
|
||||
public function get_manifest_namespaces() {return $this->rootmanifest->get_cc_namespaces(); }
|
||||
public function parent_manifest() {
|
||||
return new cc_manifest($this, $this->parentmanifest, $this->parentparentmanifest);
|
||||
}
|
||||
|
||||
public function root_manifest() {
|
||||
return new cc_manifest($this, $this->rootmanifest);
|
||||
}
|
||||
|
||||
public function manifestID() {
|
||||
return $this->activemanifest->manifestID();
|
||||
}
|
||||
|
||||
public function get_manifest_namespaces() {
|
||||
return $this->rootmanifest->get_cc_namespaces();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new organization
|
||||
@@ -178,28 +180,24 @@ class cc_manifest extends XMLGenericDocument implements cc_i_manifest {
|
||||
* @param cc_i_organization $org
|
||||
*/
|
||||
public function add_new_organization(cc_i_organization &$org) {
|
||||
$norg = $this->activemanifest->create_organization_node($org,$this->doc);
|
||||
$norg = $this->activemanifest->create_organization_node($org, $this->doc);
|
||||
$orgnode = $this->node("//imscc:manifest[@identifier='".
|
||||
$this->activemanifest->manifestID().
|
||||
"']/imscc:organizations");
|
||||
$this->activemanifest->manifestID().
|
||||
"']/imscc:organizations");
|
||||
$orgnode->appendChild($norg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function get_resources($searchspecific='') {
|
||||
$reslist = $this->get_resource_list($searchspecific);
|
||||
$resourcelist = array();
|
||||
foreach ($reslist as $resourceitem) {
|
||||
$resourcelist[]=new cc_resource($this, $resourceitem);
|
||||
$resourcelist[] = new cc_resource($this, $resourceitem);
|
||||
}
|
||||
return $resourcelist;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function get_cc_namespace_path($nsname) {
|
||||
if (is_string($nsname) && (!empty($nsname))){
|
||||
if (is_string($nsname) && (!empty($nsname))) {
|
||||
$scnam = $this->activemanifest->get_cc_namespaces();
|
||||
return $scnam[$nsname];
|
||||
}
|
||||
@@ -207,24 +205,22 @@ class cc_manifest extends XMLGenericDocument implements cc_i_manifest {
|
||||
}
|
||||
|
||||
|
||||
public function get_resource_list($searchspecific=''){
|
||||
public function get_resource_list($searchspecific = '') {
|
||||
return $this->nodeList("//imscc:manifest[@identifier='".
|
||||
$this->activemanifest->manifestID().
|
||||
"']/imscc:resources/imscc:resource".$searchspecific);
|
||||
}
|
||||
|
||||
|
||||
public function on_load (){
|
||||
public function on_load() {
|
||||
$this->register_namespaces_for_xpath();
|
||||
$this->fill_manifest();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function on_save (){
|
||||
public function on_save() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a resource to the manifest
|
||||
*
|
||||
@@ -233,19 +229,19 @@ class cc_manifest extends XMLGenericDocument implements cc_i_manifest {
|
||||
* @param string $type
|
||||
* @return array
|
||||
*/
|
||||
public function add_resource (cc_i_resource $res, $identifier=null, $type='webcontent'){
|
||||
public function add_resource(cc_i_resource $res, $identifier = null, $type = 'webcontent') {
|
||||
|
||||
if (!$this->ccobj->valid($type)){
|
||||
throw new Exception("Type invalid...");
|
||||
if (!$this->ccobj->valid($type)) {
|
||||
throw new Exception("Type invalid...");
|
||||
}
|
||||
|
||||
if ($res == null){
|
||||
if ($res == null) {
|
||||
throw new Exception('Invalid Resource or dont give it');
|
||||
}
|
||||
$rst = $res;
|
||||
|
||||
//TODO: This has to be reviewed since it does not handle properly mutiple file
|
||||
// dependencies
|
||||
// TODO: This has to be reviewed since it does not handle multiple files properly.
|
||||
// Dependencies.
|
||||
if (is_object($identifier)) {
|
||||
$this->activemanifest->create_resource_node($rst, $this->doc, $identifier);
|
||||
} else {
|
||||
@@ -259,7 +255,7 @@ class cc_manifest extends XMLGenericDocument implements cc_i_manifest {
|
||||
$this->activemanifest->create_resource_node($rst, $this->doc, $nresnode);
|
||||
foreach ($rst->files as $file) {
|
||||
$ident = $this->get_identifier_by_filename($file);
|
||||
if($ident == null){
|
||||
if ($ident == null) {
|
||||
$newres = new cc_resource($rst->manifestroot, $file);
|
||||
if (!cc_helpers::is_html($file)) {
|
||||
$newres->href = null;
|
||||
@@ -274,11 +270,9 @@ class cc_manifest extends XMLGenericDocument implements cc_i_manifest {
|
||||
return $tmparray;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function check_if_exist_in_other($name, $identifier){
|
||||
private function check_if_exist_in_other($name, $identifier) {
|
||||
$status = array();
|
||||
foreach ($this->activemanifest->resources as $value){
|
||||
foreach ($this->activemanifest->resources as $value) {
|
||||
if (($value->identifier != $identifier) && isset($value->files[$name])) {
|
||||
$status[] = $value->identifier;
|
||||
}
|
||||
@@ -286,23 +280,21 @@ class cc_manifest extends XMLGenericDocument implements cc_i_manifest {
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
private function replace_file_x_dependency($depen,$name){
|
||||
foreach ($depen as $key => $value){
|
||||
private function replace_file_x_dependency($depen, $name) {
|
||||
foreach ($depen as $key => $value) {
|
||||
($key);
|
||||
$ident = $this->get_identifier_by_filename($name);
|
||||
$ident = $this->get_identifier_by_filename($name);
|
||||
$this->activemanifest->resources[$value]->files =
|
||||
$this->array_remove_by_value($this->activemanifest->resources[$value]->files,$name);
|
||||
if (!in_array($ident,$this->activemanifest->resources[$value]->dependency)){
|
||||
array_push($this->activemanifest->resources[$value]->dependency,$ident);
|
||||
$this->array_remove_by_value($this->activemanifest->resources[$value]->files, $name);
|
||||
if (!in_array($ident, $this->activemanifest->resources[$value]->dependency)) {
|
||||
array_push($this->activemanifest->resources[$value]->dependency, $ident);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private function get_identifier_by_filename($name){
|
||||
private function get_identifier_by_filename($name) {
|
||||
$result = null;
|
||||
if (isset($this->activemanifest->resources_ind[$name])) {
|
||||
$result = $this->activemanifest->resources_ind[$name];
|
||||
@@ -310,16 +302,12 @@ class cc_manifest extends XMLGenericDocument implements cc_i_manifest {
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function array_remove_by_value($arr,$value) {
|
||||
return array_values(array_diff($arr,array($value)));
|
||||
|
||||
private function array_remove_by_value($arr, $value) {
|
||||
return array_values(array_diff($arr, array($value)));
|
||||
}
|
||||
|
||||
private function array_remove_by_key($arr,$key) {
|
||||
return array_values(array_diff_key($arr,array($key)));
|
||||
|
||||
private function array_remove_by_key($arr, $key) {
|
||||
return array_values(array_diff_key($arr, array($key)));
|
||||
}
|
||||
|
||||
public function update_instructoronly($identifier, $value = false) {
|
||||
@@ -334,20 +322,17 @@ class cc_manifest extends XMLGenericDocument implements cc_i_manifest {
|
||||
*
|
||||
* @return DOMNode
|
||||
*/
|
||||
public function put_nodes (){
|
||||
public function put_nodes() {
|
||||
|
||||
$resnodestr = "//imscc:manifest[@identifier='".$this->activemanifest->manifestID().
|
||||
"']/imscc:resources";
|
||||
"']/imscc:resources";
|
||||
$resnode = $this->node($resnodestr);
|
||||
|
||||
foreach ($this->activemanifest->resources as $k => $v){
|
||||
foreach ($this->activemanifest->resources as $k => $v) {
|
||||
($k);
|
||||
$depen = $this->check_if_exist_in_other($v->files[0], $v->identifier);
|
||||
if (!empty($depen)){
|
||||
$this->replace_file_x_dependency($depen,$v->files[0]);
|
||||
// coloca aca como type = webcontent porque son archivos dependientes
|
||||
// quizas aqui habria q ver de que type es el que vino y segun eso, ponerlo
|
||||
// en associatedcontent o en webcontent
|
||||
if (!empty($depen)) {
|
||||
$this->replace_file_x_dependency($depen, $v->files[0]);
|
||||
$v->type = 'webcontent';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once 'cc_general.php';
|
||||
require_once('cc_general.php');
|
||||
|
||||
class page11_resurce_file extends general_cc_file {
|
||||
protected $rootns = 'xmlns';
|
||||
@@ -31,7 +31,7 @@ class page11_resurce_file extends general_cc_file {
|
||||
protected $intro = null;
|
||||
|
||||
public function set_content($value) {
|
||||
//we are not cleaning up this one on purporse.
|
||||
// We are not cleaning up this one on purpose.
|
||||
$this->content = $value;
|
||||
}
|
||||
|
||||
@@ -58,38 +58,38 @@ class page11_resurce_file extends general_cc_file {
|
||||
public function on_save() {
|
||||
|
||||
$rns = $this->ccnamespaces[$this->rootns];
|
||||
//Add the basic tags
|
||||
// Add the basic tags.
|
||||
$head = $this->append_new_element_ns($this->root, $rns, 'head');
|
||||
$this->append_new_attribute_ns($head, $rns, 'profile', 'http://dublincore.org/documents/dc-html/');
|
||||
|
||||
//Linking Dublin Core Metadata 1.1
|
||||
// Linking Dublin Core Metadata 1.1.
|
||||
$link_dc = $this->append_new_element_ns($head, $rns, 'link');
|
||||
$this->append_new_attribute_ns($link_dc, $rns, 'rel', 'schema.DC');
|
||||
$this->append_new_attribute_ns($link_dc, $rns, 'href', 'http://purl.org/dc/elements/1.1/');
|
||||
$link_dcterms = $this->append_new_element_ns($head, $rns, 'link');
|
||||
$this->append_new_attribute_ns($link_dcterms, $rns, 'rel', 'schema.DCTERMS');
|
||||
$this->append_new_attribute_ns($link_dcterms, $rns, 'href', 'http://purl.org/dc/terms/');
|
||||
//Content type
|
||||
// Content type.
|
||||
$meta_type = $this->append_new_element_ns($head, $rns, 'meta');
|
||||
$this->append_new_attribute_ns($meta_type, $rns, 'name' , 'DC.type' );
|
||||
$this->append_new_attribute_ns($meta_type, $rns, 'scheme' , 'DCTERMS.DCMIType');
|
||||
$this->append_new_attribute_ns($meta_type, $rns, 'content', 'Text' );
|
||||
$this->append_new_attribute_ns($meta_type, $rns, 'name', 'DC.type');
|
||||
$this->append_new_attribute_ns($meta_type, $rns, 'scheme', 'DCTERMS.DCMIType');
|
||||
$this->append_new_attribute_ns($meta_type, $rns, 'content', 'Text');
|
||||
|
||||
//Content description
|
||||
// Content description.
|
||||
if (!empty($this->intro)) {
|
||||
$meta_description = $this->append_new_element_ns($head, $rns , 'meta' );
|
||||
$this->append_new_attribute_ns($meta_description, $rns, 'name' , 'DC.description');
|
||||
$this->append_new_attribute_ns($meta_description, $rns, 'content', $this->intro );
|
||||
$meta_description = $this->append_new_element_ns($head, $rns, 'meta');
|
||||
$this->append_new_attribute_ns($meta_description, $rns, 'name', 'DC.description');
|
||||
$this->append_new_attribute_ns($meta_description, $rns, 'content', $this->intro);
|
||||
}
|
||||
|
||||
$meta = $this->append_new_element_ns($head, $rns, 'meta');
|
||||
$this->append_new_attribute_ns($meta, $rns, 'http-equiv', 'Content-type');
|
||||
$this->append_new_attribute_ns($meta, $rns, 'content', 'text/html; charset=UTF-8');
|
||||
//set the title
|
||||
// Set the title.
|
||||
$title = $this->append_new_element_ns($head, $rns, 'title', $this->title);
|
||||
$body = $this->append_new_element_ns($this->root, $rns, 'body');
|
||||
//We are unable to use DOM for embedding HTML due to numerous content errors
|
||||
//Therefore we place a dummy tag that will be later replaced with the real content
|
||||
// We are unable to use DOM for embedding HTML due to numerous content errors.
|
||||
// Therefore we place a dummy tag that will be later replaced with the real content.
|
||||
$this->append_new_element_ns($body, $rns, 'div', '##REPLACE##');
|
||||
|
||||
return true;
|
||||
|
||||
@@ -15,19 +15,19 @@
|
||||
// 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
|
||||
*/
|
||||
* @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
|
||||
*/
|
||||
|
||||
require_once 'cc_interfaces.php';
|
||||
require_once 'xmlbase.php';
|
||||
require_once 'gral_lib/pathutils.php';
|
||||
require_once 'gral_lib/ccdependencyparser.php';
|
||||
require_once 'cc_version_base.php';
|
||||
require_once 'cc_version1.php';
|
||||
require_once 'cc_manifest.php';
|
||||
require_once('cc_interfaces.php');
|
||||
require_once('xmlbase.php');
|
||||
require_once('gral_lib/pathutils.php');
|
||||
require_once('gral_lib/ccdependencyparser.php');
|
||||
require_once('cc_version_base.php');
|
||||
require_once('cc_version1.php');
|
||||
require_once('cc_manifest.php');
|
||||
|
||||
/**
|
||||
* Common Cartridge Version
|
||||
@@ -82,19 +82,20 @@ class cc11_resource_type {
|
||||
*/
|
||||
class cc_resource implements cc_i_resource {
|
||||
|
||||
public $identifier = null;
|
||||
public $type = null;
|
||||
public $dependency = array();
|
||||
public $identifierref = null;
|
||||
public $href = null;
|
||||
public $base = null;
|
||||
public $persiststate = null;
|
||||
public $filename = null;
|
||||
public $files = array();
|
||||
public $isempty = null;
|
||||
public $manifestroot = null;
|
||||
public $folder = null;
|
||||
public $instructoronly = false;
|
||||
public $identifier = null;
|
||||
public $type = null;
|
||||
public $dependency = array();
|
||||
public $identifierref = null;
|
||||
public $href = null;
|
||||
public $base = null;
|
||||
public $persiststate = null;
|
||||
public $metadata = array();
|
||||
public $filename = null;
|
||||
public $files = array();
|
||||
public $isempty = null;
|
||||
public $manifestroot = null;
|
||||
public $folder = null;
|
||||
public $instructoronly = false;
|
||||
|
||||
private $throwonerror = true;
|
||||
|
||||
@@ -102,10 +103,10 @@ class cc_resource implements cc_i_resource {
|
||||
$this->throwonerror = $throwonerror;
|
||||
if (is_string($manifest)) {
|
||||
$this->folder = $folder;
|
||||
$this->process_resource($manifest, $file,$folder);
|
||||
$this->process_resource($manifest, $file, $folder);
|
||||
$this->manifestroot = $manifest;
|
||||
} else if (is_object($manifest)) {
|
||||
$this->import_resource($file,$manifest.$folder);
|
||||
$this->import_resource($file, $manifest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,12 +116,10 @@ class cc_resource implements cc_i_resource {
|
||||
* @param string $fname
|
||||
* @param string $location
|
||||
*/
|
||||
public function add_resource ($fname, $location =''){
|
||||
$this->process_resource($fname,$location);
|
||||
|
||||
public function add_resource ($fname, $location ='') {
|
||||
$this->process_resource($fname, $location, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Import a resource
|
||||
*
|
||||
@@ -131,10 +130,10 @@ class cc_resource implements cc_i_resource {
|
||||
|
||||
$searchstr = "//imscc:manifest[@identifier='".$doc->manifestID().
|
||||
"']/imscc:resources/imscc:resource";
|
||||
$this->identifier = $this->get_attr_value($node,"identifier");
|
||||
$this->type = $this->get_attr_value($node,"type");
|
||||
$this->href = $this->get_attr_value($node,"href");
|
||||
$this->base = $this->get_attr_value($node,"base");
|
||||
$this->identifier = $this->get_attr_value($node, "identifier");
|
||||
$this->type = $this->get_attr_value($node, "type");
|
||||
$this->href = $this->get_attr_value($node, "href");
|
||||
$this->base = $this->get_attr_value($node, "base");
|
||||
$this->persiststate = null;
|
||||
$nodo = $doc->nodeList($searchstr."[@identifier='".
|
||||
$this->identifier."']/metadata/@href");
|
||||
@@ -155,7 +154,6 @@ class cc_resource implements cc_i_resource {
|
||||
$this->isempty = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a attribute value
|
||||
*
|
||||
@@ -165,12 +163,12 @@ class cc_resource implements cc_i_resource {
|
||||
* @return string
|
||||
*/
|
||||
public function get_attr_value(&$nod, $name, $ns=null) {
|
||||
return is_null($ns) ?
|
||||
($nod->hasAttribute($name) ? $nod->getAttribute($name) : null) :
|
||||
($nod->hasAttributeNS($ns, $name) ? $nod->getAttributeNS($ns, $name) : null);
|
||||
if (is_null($ns)) {
|
||||
return ($nod->hasAttribute($name) ? $nod->getAttribute($name) : null);
|
||||
}
|
||||
return ($nod->hasAttributeNS($ns, $name) ? $nod->getAttributeNS($ns, $name) : null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process a resource
|
||||
*
|
||||
@@ -180,12 +178,12 @@ class cc_resource implements cc_i_resource {
|
||||
*/
|
||||
public function process_resource($manifestroot, &$fname, $folder) {
|
||||
$file = empty($folder) ? $manifestroot.'/'.$fname : $manifestroot.'/'.$folder.'/'.$fname;
|
||||
if (!file_exists($file) && $this->throwonerror){
|
||||
if (!file_exists($file) && $this->throwonerror) {
|
||||
throw new Exception('The file doesnt exist!');
|
||||
}
|
||||
|
||||
GetDepFiles($manifestroot, $fname, $this->folder, $this->files);
|
||||
array_unshift($this->files,$folder.$fname);
|
||||
array_unshift($this->files, $folder.$fname);
|
||||
$this->init_empty_new();
|
||||
$this->href = $folder.$fname;
|
||||
$this->identifierref = $folder.$fname;
|
||||
@@ -197,43 +195,41 @@ class cc_resource implements cc_i_resource {
|
||||
public function adjust_path($mroot, $fname) {
|
||||
$result = null;
|
||||
if (file_exists($fname->filename)) {
|
||||
$result = pathDiff($fname->filename,$mroot);
|
||||
$result = pathDiff($fname->filename, $mroot);
|
||||
|
||||
} else if (file_exists($mroot.$fname->filename) || file_exists($mroot.DIRECTORY_SEPARATOR.$fname->filename)) {
|
||||
$result = trim(toUrlPath($fname->filename),"/");
|
||||
$result = $fname->filename;
|
||||
toUrlPath($result);
|
||||
$result = trim($result, "/");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function init_clean() {
|
||||
$this->identifier = null;
|
||||
$this->type = null;
|
||||
$this->href = null;
|
||||
$this->base = null;
|
||||
$this->metadata = array();
|
||||
$this->dependency = array();
|
||||
$this->identifierref = null;
|
||||
$this->persiststate = null;
|
||||
$this->filename = '';
|
||||
$this->files = array();
|
||||
$this->isempty = true;
|
||||
$this->identifier = null;
|
||||
$this->type = null;
|
||||
$this->href = null;
|
||||
$this->base = null;
|
||||
$this->metadata = array();
|
||||
$this->dependency = array();
|
||||
$this->identifierref = null;
|
||||
$this->persiststate = null;
|
||||
$this->filename = '';
|
||||
$this->files = array();
|
||||
$this->isempty = true;
|
||||
}
|
||||
|
||||
|
||||
public function init_empty_new() {
|
||||
$this->identifier = cc_helpers::uuidgen('I_', '_R');
|
||||
$this->type = null;
|
||||
$this->href = null;
|
||||
$this->persiststate = null;
|
||||
$this->filename = null;
|
||||
$this->isempty = false;
|
||||
$this->identifierref = null;
|
||||
$this->identifier = cc_helpers::uuidgen('I_', '_R');
|
||||
$this->type = null;
|
||||
$this->href = null;
|
||||
$this->persiststate = null;
|
||||
$this->filename = null;
|
||||
$this->isempty = false;
|
||||
$this->identifierref = null;
|
||||
}
|
||||
|
||||
public function get_manifestroot(){
|
||||
public function get_manifestroot() {
|
||||
return $this->manifestroot;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,13 +15,13 @@
|
||||
// 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
|
||||
*/
|
||||
* @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
|
||||
*/
|
||||
|
||||
require_once 'xmlbase.php';
|
||||
require_once('xmlbase.php');
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -32,8 +32,8 @@ require_once 'xmlbase.php';
|
||||
abstract class cc_helpers {
|
||||
|
||||
/**
|
||||
*
|
||||
* Checks extension of the supplied filename
|
||||
*
|
||||
* @param string $filename
|
||||
*/
|
||||
public static function is_html($filename) {
|
||||
@@ -42,7 +42,6 @@ abstract class cc_helpers {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates unique identifier
|
||||
* @param string $prefix
|
||||
* @param string $suffix
|
||||
@@ -50,17 +49,16 @@ abstract class cc_helpers {
|
||||
*/
|
||||
public static function uuidgen($prefix = '', $suffix = '', $uppercase = true) {
|
||||
$uuid = trim(sprintf('%s%04x%04x%s', $prefix, mt_rand(0, 65535), mt_rand(0, 65535), $suffix));
|
||||
$result = $uppercase ? strtoupper($uuid) : strtolower($uuid) ;
|
||||
$result = $uppercase ? strtoupper($uuid) : strtolower($uuid);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Creates new folder with random name
|
||||
* @param string $where
|
||||
* @param string $prefix
|
||||
* @param string $suffix
|
||||
* @return mixed - directory short name or false in case of faliure
|
||||
* @return mixed - directory short name or false in case of failure
|
||||
*/
|
||||
public static function randomdir($where, $prefix = '', $suffix = '') {
|
||||
global $CFG;
|
||||
@@ -145,12 +143,12 @@ abstract class cc_helpers {
|
||||
$type = $mfile->nodeValue('mimetype', $node);
|
||||
$depfiles[$filepath.$filename] = array( $location,
|
||||
($mainfile == 1),
|
||||
strtolower(str_replace(' ', '_',$filename)),
|
||||
strtolower(str_replace(' ', '_', $filename)),
|
||||
$type,
|
||||
$source,
|
||||
$author,
|
||||
$license,
|
||||
strtolower(str_replace(' ', '_',$filepath)));
|
||||
strtolower(str_replace(' ', '_', $filepath)));
|
||||
}
|
||||
|
||||
return $depfiles;
|
||||
@@ -210,23 +208,21 @@ abstract class cc_helpers {
|
||||
* @param boolean $allinone
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public static function handle_static_content(cc_i_manifest &$manifest, $packageroot, $contextid, $outdir, $allinone = true){
|
||||
cc_helpers::add_files($manifest, $packageroot, $outdir, $allinone);
|
||||
public static function handle_static_content(cc_i_manifest &$manifest, $packageroot, $contextid, $outdir, $allinone = true) {
|
||||
self::add_files($manifest, $packageroot, $outdir, $allinone);
|
||||
return pkg_static_resources::instance()->get_values();
|
||||
}
|
||||
|
||||
public static function handle_resource_content(cc_i_manifest &$manifest, $packageroot, $contextid, $outdir, $allinone = true){
|
||||
public static function handle_resource_content(cc_i_manifest &$manifest, $packageroot, $contextid, $outdir, $allinone = true) {
|
||||
$result = array();
|
||||
cc_helpers::add_files($manifest, $packageroot, $outdir, $allinone);
|
||||
$files = cc_helpers::embedded_mapping($packageroot, $contextid);
|
||||
//$rdir = $allinone ? new cc_resource_location($outdir) : null;
|
||||
self::add_files($manifest, $packageroot, $outdir, $allinone);
|
||||
$files = self::embedded_mapping($packageroot, $contextid);
|
||||
$rootnode = null;
|
||||
$rootvals = null;
|
||||
$depfiles = array();
|
||||
$depres = array();
|
||||
$flocation = null;
|
||||
foreach ($files as $virtual => $values) {
|
||||
$clean_filename = $values[2];
|
||||
$vals = pkg_static_resources::instance()->get_identifier($virtual);
|
||||
$resource = $vals[3];
|
||||
$identifier = $resource->identifier;
|
||||
@@ -250,17 +246,16 @@ abstract class cc_helpers {
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function process_linked_files($content, cc_i_manifest &$manifest, $packageroot, $contextid, $outdir, $webcontent = false) {
|
||||
/**
|
||||
- detect all embedded files
|
||||
- locate their physical counterparts in moodle 2 backup
|
||||
- copy all files in the cc package stripping any spaces and using inly lowercase letters
|
||||
- add those files as resources of the type webcontent to the manifest
|
||||
- replace the links to the resourcse using $IMS-CC-FILEBASE$ and their new locations
|
||||
- cc_resource has array of files and array of dependencies
|
||||
- most likely we would need to add all files as independent resources and than
|
||||
attach them all as dependencies to the forum tag
|
||||
*/
|
||||
public static function process_linked_files($content, cc_i_manifest &$manifest, $packageroot,
|
||||
$contextid, $outdir, $webcontent = false) {
|
||||
// Detect all embedded files
|
||||
// locate their physical counterparts in moodle 2 backup
|
||||
// copy all files in the cc package stripping any spaces and using only lowercase letters
|
||||
// add those files as resources of the type webcontent to the manifest
|
||||
// replace the links to the resource using $IMS-CC-FILEBASE$ and their new locations
|
||||
// cc_resource has array of files and array of dependencies
|
||||
// most likely we would need to add all files as independent resources and than
|
||||
// attach them all as dependencies to the forum tag.
|
||||
$lfiles = self::embedded_files($content);
|
||||
$text = $content;
|
||||
$deps = array();
|
||||
@@ -272,12 +267,12 @@ abstract class cc_helpers {
|
||||
$replaceprefix = $webcontent ? '' : '$IMS-CC-FILEBASE$';
|
||||
foreach ($lfiles as $lfile) {
|
||||
if (isset($files[$lfile])) {
|
||||
$filename = str_replace('%2F', '/',rawurlencode($lfile));
|
||||
$filename = str_replace('%2F', '/', rawurlencode($lfile));
|
||||
$content = str_replace('@@PLUGINFILE@@'.$filename,
|
||||
$replaceprefix.'../'.$files[$lfile][1],
|
||||
$content);
|
||||
//for the legacy stuff
|
||||
$content = str_replace('$@FILEPHP@$'.str_replace('/','$@SLASH@$',$filename),
|
||||
// For the legacy stuff.
|
||||
$content = str_replace('$@FILEPHP@$'.str_replace('/', '$@SLASH@$', $filename),
|
||||
$replaceprefix.'../'.$files[$lfile][1],
|
||||
$content);
|
||||
$deps[] = $files[$lfile][0];
|
||||
@@ -380,8 +375,11 @@ class pkg_static_resources {
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
private function __clone() {}
|
||||
private function __construct() {}
|
||||
private function __clone() {
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return pkg_static_resources
|
||||
@@ -418,15 +416,15 @@ class pkg_static_resources {
|
||||
|
||||
public function reset() {
|
||||
$this->values = array();
|
||||
$this->finished = false ;
|
||||
$this->finished = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class pkg_resource_dependencies {
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
* @var array
|
||||
*/
|
||||
private $values = array();
|
||||
|
||||
/**
|
||||
|
||||
+158
-202
@@ -15,16 +15,15 @@
|
||||
// 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
|
||||
*/
|
||||
|
||||
require_once 'cc_utils.php';
|
||||
require_once 'cc_version_base.php';
|
||||
require_once 'cc_organization.php';
|
||||
* @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
|
||||
*/
|
||||
|
||||
require_once('cc_utils.php');
|
||||
require_once('cc_version_base.php');
|
||||
require_once('cc_organization.php');
|
||||
|
||||
/**
|
||||
* Version 1 class of Common Cartridge
|
||||
@@ -63,79 +62,79 @@ class cc_version1 extends cc_version_base {
|
||||
'xsi' => 'http://www.w3.org/2001/XMLSchema-instance'
|
||||
);
|
||||
|
||||
$this->ccnsnames = array('imscc' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/imscp_v1p2_localised.xsd' ,
|
||||
'lom' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_2/lomLoose_localised.xsd' ,
|
||||
'lomimscc' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_1/lomLoose_localised.xsd',
|
||||
'voc' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_2/vocab/loose.xsd'
|
||||
);
|
||||
$this->ccnsnames = array(
|
||||
'imscc' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/imscp_v1p2_localised.xsd',
|
||||
'lom' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_2/lomLoose_localised.xsd',
|
||||
'lomimscc' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_1/lomLoose_localised.xsd',
|
||||
'voc' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_2/vocab/loose.xsd'
|
||||
);
|
||||
|
||||
$this->ccversion = '1.0.0';
|
||||
$this->camversion = '1.0.0';
|
||||
$this->_generator = 'Moodle 2 Common Cartridge generator';
|
||||
}
|
||||
|
||||
protected function on_create(DOMDocument &$doc, $rootmanifestnode=null,$nmanifestID=null) {
|
||||
$doc->formatOutput = true;
|
||||
$doc->preserveWhiteSpace = true;
|
||||
protected function on_create(DOMDocument &$doc, $rootmanifestnode = null, $nmanifestID = null) {
|
||||
$doc->formatOutput = true;
|
||||
$doc->preserveWhiteSpace = true;
|
||||
|
||||
|
||||
$this->manifestID = is_null($nmanifestID) ? cc_helpers::uuidgen('M_') : $nmanifestID;
|
||||
$mUUID = $doc->createAttribute('identifier');
|
||||
$mUUID->nodeValue = $this->manifestID;
|
||||
$this->manifestID = is_null($nmanifestID) ? cc_helpers::uuidgen('M_') : $nmanifestID;
|
||||
$mUUID = $doc->createAttribute('identifier');
|
||||
$mUUID->nodeValue = $this->manifestID;
|
||||
|
||||
|
||||
if (is_null($rootmanifestnode)) {
|
||||
if (!empty($this->_generator)) {
|
||||
$comment = $doc->createComment($this->_generator);
|
||||
$doc->appendChild($comment);
|
||||
}
|
||||
if (is_null($rootmanifestnode)) {
|
||||
if (!empty($this->_generator)) {
|
||||
$comment = $doc->createComment($this->_generator);
|
||||
$doc->appendChild($comment);
|
||||
}
|
||||
|
||||
$rootel = $doc->createElementNS($this->ccnamespaces['imscc'],'manifest');
|
||||
$rootel->appendChild($mUUID);
|
||||
$doc->appendChild($rootel);
|
||||
$rootel = $doc->createElementNS($this->ccnamespaces['imscc'], 'manifest');
|
||||
$rootel->appendChild($mUUID);
|
||||
$doc->appendChild($rootel);
|
||||
|
||||
//add all namespaces
|
||||
foreach ($this->ccnamespaces as $key => $value) {
|
||||
$dummy_attr = $key.":dummy";
|
||||
$doc->createAttributeNS($value,$dummy_attr);
|
||||
}
|
||||
// Add all namespaces.
|
||||
foreach ($this->ccnamespaces as $key => $value) {
|
||||
$dummy_attr = $key.":dummy";
|
||||
$doc->createAttributeNS($value, $dummy_attr);
|
||||
}
|
||||
|
||||
// add location of schemas
|
||||
$schemaLocation='';
|
||||
foreach ($this->ccnsnames as $key => $value) {
|
||||
$vt = empty($schemaLocation) ? '' : ' ';
|
||||
$schemaLocation .= $vt.$this->ccnamespaces[$key].' '.$value;
|
||||
}
|
||||
$aSchemaLoc = $doc->createAttributeNS($this->ccnamespaces['xsi'],'xsi:schemaLocation');
|
||||
$aSchemaLoc->nodeValue=$schemaLocation;
|
||||
$rootel->appendChild($aSchemaLoc);
|
||||
// Add location of schemas.
|
||||
$schemaLocation = '';
|
||||
foreach ($this->ccnsnames as $key => $value) {
|
||||
$vt = empty($schemaLocation) ? '' : ' ';
|
||||
$schemaLocation .= $vt.$this->ccnamespaces[$key].' '.$value;
|
||||
}
|
||||
$aSchemaLoc = $doc->createAttributeNS($this->ccnamespaces['xsi'], 'xsi:schemaLocation');
|
||||
$aSchemaLoc->nodeValue = $schemaLocation;
|
||||
$rootel->appendChild($aSchemaLoc);
|
||||
|
||||
} else {
|
||||
$rootel = $doc->createElementNS($this->ccnamespaces['imscc'],'imscc:manifest');
|
||||
$rootel->appendChild($mUUID);
|
||||
}
|
||||
} else {
|
||||
$rootel = $doc->createElementNS($this->ccnamespaces['imscc'], 'imscc:manifest');
|
||||
$rootel->appendChild($mUUID);
|
||||
}
|
||||
|
||||
$metadata = $doc->createElementNS($this->ccnamespaces['imscc'],'metadata');
|
||||
$schema = $doc->createElementNS($this->ccnamespaces['imscc'],'schema','IMS Common Cartridge');
|
||||
$schemaversion = $doc->createElementNS($this->ccnamespaces['imscc'],'schemaversion',$this->ccversion);
|
||||
$metadata = $doc->createElementNS($this->ccnamespaces['imscc'], 'metadata');
|
||||
$schema = $doc->createElementNS($this->ccnamespaces['imscc'], 'schema', 'IMS Common Cartridge');
|
||||
$schemaversion = $doc->createElementNS($this->ccnamespaces['imscc'], 'schemaversion', $this->ccversion);
|
||||
|
||||
$metadata->appendChild($schema);
|
||||
$metadata->appendChild($schemaversion);
|
||||
$rootel->appendChild($metadata);
|
||||
$metadata->appendChild($schema);
|
||||
$metadata->appendChild($schemaversion);
|
||||
$rootel->appendChild($metadata);
|
||||
|
||||
if (!is_null($rootmanifestnode)) {
|
||||
$rootmanifestnode->appendChild($rootel);
|
||||
}
|
||||
if (!is_null($rootmanifestnode)) {
|
||||
$rootmanifestnode->appendChild($rootel);
|
||||
}
|
||||
|
||||
$organizations = $doc->createElementNS($this->ccnamespaces['imscc'],'organizations');
|
||||
$rootel->appendChild($organizations);
|
||||
$resources = $doc->createElementNS($this->ccnamespaces['imscc'],'resources');
|
||||
$rootel->appendChild($resources);
|
||||
$organizations = $doc->createElementNS($this->ccnamespaces['imscc'], 'organizations');
|
||||
$rootel->appendChild($organizations);
|
||||
$resources = $doc->createElementNS($this->ccnamespaces['imscc'], 'resources');
|
||||
$rootel->appendChild($resources);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected function update_attribute(DOMDocument &$doc, $attrname, $attrvalue, DOMElement &$node) {
|
||||
$busenew = (is_object($node) && $node->hasAttribute($attrname));
|
||||
$nResult = null;
|
||||
@@ -151,14 +150,14 @@ class cc_version1 extends cc_version_base {
|
||||
return $nResult;
|
||||
}
|
||||
|
||||
|
||||
protected function update_attribute_ns(DOMDocument &$doc, $attrname, $attrnamespace,$attrvalue, DOMElement &$node) {
|
||||
$busenew = (is_object($node) && $node->hasAttributeNS($attrnamespace, $attrname));
|
||||
$nResult = null;
|
||||
if (!$busenew && is_null($attrvalue)) {
|
||||
$node->removeAttributeNS($attrnamespace, $attrname);
|
||||
} else {
|
||||
$nResult = $busenew ? $node->getAttributeNodeNS($attrnamespace, $attrname) : $doc->createAttributeNS($attrnamespace, $attrname);
|
||||
$nResult = $busenew ? $node->getAttributeNodeNS($attrnamespace, $attrname) :
|
||||
$doc->createAttributeNS($attrnamespace, $attrname);
|
||||
$nResult->nodeValue = $attrvalue;
|
||||
if (!$busenew) {
|
||||
$node->appendChild($nResult);
|
||||
@@ -167,21 +166,19 @@ class cc_version1 extends cc_version_base {
|
||||
return $nResult;
|
||||
}
|
||||
|
||||
|
||||
protected function get_child_node(DOMDocument &$doc, $itemname, DOMElement &$node) {
|
||||
$nlist = $node->getElementsByTagName($itemname);
|
||||
$item = is_object($nlist) && ($nlist->length > 0) ? $nlist->item(0) : null;
|
||||
return $item;
|
||||
}
|
||||
|
||||
|
||||
protected function update_child_item(DOMDocument &$doc, $itemname, $itemvalue, DOMElement &$node, $attrtostore=null) {
|
||||
$tnode = $this->get_child_node($doc,'title',$node);
|
||||
$tnode = $this->get_child_node($doc, 'title', $node);
|
||||
$usenew = is_null($tnode);
|
||||
$tnode = $usenew ? $doc->createElementNS($this->ccnamespaces['imscc'], $itemname) : $tnode;
|
||||
if (!is_null($attrtostore)) {
|
||||
foreach ($attrtostore as $key => $value) {
|
||||
$this->update_attribute($doc,$key,$value,$tnode);
|
||||
$this->update_attribute($doc, $key, $value, $tnode);
|
||||
}
|
||||
}
|
||||
$tnode->nodeValue = $itemvalue;
|
||||
@@ -190,7 +187,6 @@ class cc_version1 extends cc_version_base {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function update_items($items, DOMDocument &$doc, DOMElement &$xmlnode) {
|
||||
foreach ($items as $key => $item) {
|
||||
$itemnode = $doc->createElementNS($this->ccnamespaces['imscc'], 'item');
|
||||
@@ -210,7 +206,6 @@ class cc_version1 extends cc_version_base {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a Resource (How to)
|
||||
*
|
||||
@@ -222,23 +217,23 @@ class cc_version1 extends cc_version_base {
|
||||
protected function create_resource(cc_i_resource &$res, DOMDocument &$doc, $xmlnode=null) {
|
||||
$usenew = is_object($xmlnode);
|
||||
$dnode = $usenew ? $xmlnode : $doc->createElementNS($this->ccnamespaces['imscc'], "resource");
|
||||
$this->update_attribute($doc,'identifier',$res->identifier,$dnode);
|
||||
$this->update_attribute($doc,'type' ,$res->type ,$dnode);
|
||||
!is_null($res->href) ? $this->update_attribute($doc,'href',$res->href,$dnode): null;
|
||||
$this->update_attribute($doc,'base' ,$res->base ,$dnode);
|
||||
$this->update_attribute($doc, 'identifier', $res->identifier, $dnode);
|
||||
$this->update_attribute($doc, 'type', $res->type, $dnode);
|
||||
!is_null($res->href) ? $this->update_attribute($doc, 'href', $res->href, $dnode) : null;
|
||||
$this->update_attribute($doc, 'base', $res->base, $dnode);
|
||||
|
||||
foreach ($res->files as $file) {
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['imscc'],'file');
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['imscc'], 'file');
|
||||
$ndatt = $doc->createAttribute('href');
|
||||
$ndatt->nodeValue = $file;
|
||||
$nd->appendChild($ndatt);
|
||||
$dnode->appendChild($nd);
|
||||
}
|
||||
$this->resources[$res->identifier] = $res;
|
||||
$this->resources[$res->identifier] = $res;
|
||||
$this->resources_ind[$res->files[0]] = $res->identifier;
|
||||
|
||||
foreach ($res->dependency as $dependency){
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['imscc'],'dependency');
|
||||
foreach ($res->dependency as $dependency) {
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['imscc'], 'dependency');
|
||||
$ndatt = $doc->createAttribute('identifierref');
|
||||
$ndatt->nodeValue = $dependency;
|
||||
$nd->appendChild($ndatt);
|
||||
@@ -248,8 +243,6 @@ class cc_version1 extends cc_version_base {
|
||||
return $dnode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create an Item Folder (How To)
|
||||
*
|
||||
@@ -257,25 +250,22 @@ class cc_version1 extends cc_version_base {
|
||||
* @param DOMDocument $doc
|
||||
* @param DOMElement $xmlnode
|
||||
*/
|
||||
protected function create_item_folder (cc_i_organization &$org, DOMDocument &$doc, DOMElement &$xmlnode=null){
|
||||
protected function create_item_folder(cc_i_organization &$org, DOMDocument &$doc, DOMElement &$xmlnode = null) {
|
||||
|
||||
$itemfoldernode = $doc->createElementNS($this->ccnamespaces['imscc'],'item');
|
||||
$this->update_attribute($doc,'identifier', "root", $itemfoldernode);
|
||||
$itemfoldernode = $doc->createElementNS($this->ccnamespaces['imscc'], 'item');
|
||||
$this->update_attribute($doc, 'identifier', "root", $itemfoldernode);
|
||||
|
||||
if ($org->has_items()) {
|
||||
$this->update_items($org->itemlist, $doc, $itemfoldernode);
|
||||
}
|
||||
if (is_null($this->organizations)) {
|
||||
$this->organizations = array();
|
||||
}
|
||||
$this->organizations[$org->identifier] = $org;
|
||||
if ($org->has_items()) {
|
||||
$this->update_items($org->itemlist, $doc, $itemfoldernode);
|
||||
}
|
||||
if (is_null($this->organizations)) {
|
||||
$this->organizations = array();
|
||||
}
|
||||
$this->organizations[$org->identifier] = $org;
|
||||
|
||||
$xmlnode->appendChild($itemfoldernode);
|
||||
$xmlnode->appendChild($itemfoldernode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create an Organization (How To)
|
||||
*
|
||||
@@ -284,21 +274,18 @@ class cc_version1 extends cc_version_base {
|
||||
* @param object $xmlnode
|
||||
* @return DOMNode
|
||||
*/
|
||||
protected function create_organization (cc_i_organization &$org, DOMDocument &$doc, $xmlnode=null){
|
||||
protected function create_organization(cc_i_organization &$org, DOMDocument &$doc, $xmlnode = null) {
|
||||
|
||||
$usenew = is_object($xmlnode);
|
||||
$dnode = $usenew ? $xmlnode : $doc->createElementNS($this->ccnamespaces['imscc'], "organization");
|
||||
$this->update_attribute($doc,'identifier' ,$org->identifier,$dnode);
|
||||
$this->update_attribute($doc,'structure' ,$org->structure ,$dnode);
|
||||
$this->update_attribute($doc, 'identifier', $org->identifier, $dnode);
|
||||
$this->update_attribute($doc, 'structure', $org->structure, $dnode);
|
||||
|
||||
$this->create_item_folder($org,$doc,$dnode);
|
||||
$this->create_item_folder($org, $doc, $dnode);
|
||||
|
||||
return $dnode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create Metadata For Manifest (How To)
|
||||
*
|
||||
@@ -307,28 +294,26 @@ class cc_version1 extends cc_version_base {
|
||||
* @param object $xmlnode
|
||||
* @return DOMNode
|
||||
*/
|
||||
protected function create_metadata_manifest (cc_i_metadata_manifest $met,DOMDocument &$doc,$xmlnode=null) {
|
||||
protected function create_metadata_manifest(cc_i_metadata_manifest $met, DOMDocument &$doc, $xmlnode = null) {
|
||||
|
||||
$dnode = $doc->createElementNS($this->ccnamespaces['lomimscc'], "lom");
|
||||
$dnode = $doc->createElementNS($this->ccnamespaces['lomimscc'], "lom");
|
||||
if (!empty($xmlnode)) {
|
||||
$xmlnode->appendChild($dnode);
|
||||
}
|
||||
$dnodegeneral = empty($met->arraygeneral ) ? null : $this->create_metadata_general ($met, $doc, $xmlnode);
|
||||
$dnodetechnical = empty($met->arraytech ) ? null : $this->create_metadata_technical($met, $doc, $xmlnode);
|
||||
$dnoderights = empty($met->arrayrights ) ? null : $this->create_metadata_rights ($met, $doc, $xmlnode);
|
||||
$dnodegeneral = empty($met->arraygeneral) ? null : $this->create_metadata_general($met, $doc, $xmlnode);
|
||||
$dnodetechnical = empty($met->arraytech) ? null : $this->create_metadata_technical($met, $doc, $xmlnode);
|
||||
$dnoderights = empty($met->arrayrights) ? null : $this->create_metadata_rights($met, $doc, $xmlnode);
|
||||
$dnodelifecycle = empty($met->arraylifecycle) ? null : $this->create_metadata_lifecycle($met, $doc, $xmlnode);
|
||||
|
||||
!is_null($dnodegeneral)?$dnode->appendChild($dnodegeneral):null;
|
||||
!is_null($dnodetechnical)?$dnode->appendChild($dnodetechnical):null;
|
||||
!is_null($dnoderights)?$dnode->appendChild($dnoderights):null;
|
||||
!is_null($dnodelifecycle)?$dnode->appendChild($dnodelifecycle):null;
|
||||
!is_null($dnodegeneral) ? $dnode->appendChild($dnodegeneral) : null;
|
||||
!is_null($dnodetechnical) ? $dnode->appendChild($dnodetechnical) : null;
|
||||
!is_null($dnoderights) ? $dnode->appendChild($dnoderights) : null;
|
||||
!is_null($dnodelifecycle) ? $dnode->appendChild($dnodelifecycle) : null;
|
||||
|
||||
return $dnode;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create Metadata For Resource (How To)
|
||||
*
|
||||
@@ -337,19 +322,16 @@ class cc_version1 extends cc_version_base {
|
||||
* @param object $xmlnode
|
||||
* @return DOMNode
|
||||
*/
|
||||
protected function create_metadata_resource (cc_i_metadata_resource $met,DOMDocument &$doc,$xmlnode=null) {
|
||||
protected function create_metadata_resource(cc_i_metadata_resource $met, DOMDocument &$doc, $xmlnode = null) {
|
||||
|
||||
$dnode = $doc->createElementNS($this->ccnamespaces['lom'], "lom");
|
||||
|
||||
!empty($xmlnode)? $xmlnode->appendChild($dnode):null;
|
||||
!empty($met->arrayeducational) ? $this->create_metadata_educational($met,$doc,$dnode):null;
|
||||
!empty($xmlnode) ? $xmlnode->appendChild($dnode) : null;
|
||||
!empty($met->arrayeducational) ? $this->create_metadata_educational($met, $doc, $dnode) : null;
|
||||
|
||||
return $dnode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create Metadata For File (How To)
|
||||
*
|
||||
@@ -358,19 +340,16 @@ class cc_version1 extends cc_version_base {
|
||||
* @param Object $xmlnode
|
||||
* @return DOMNode
|
||||
*/
|
||||
protected function create_metadata_file (cc_i_metadata_file $met,DOMDocument &$doc,$xmlnode=null) {
|
||||
protected function create_metadata_file(cc_i_metadata_file $met, DOMDocument &$doc, $xmlnode = null) {
|
||||
|
||||
$dnode = $doc->createElementNS($this->ccnamespaces['lom'], "lom");
|
||||
|
||||
!empty($xmlnode)? $xmlnode->appendChild($dnode):null;
|
||||
!empty($met->arrayeducational) ? $this->create_metadata_educational($met,$doc,$dnode):null;
|
||||
!empty($xmlnode) ? $xmlnode->appendChild($dnode) : null;
|
||||
!empty($met->arrayeducational) ? $this->create_metadata_educational($met, $doc, $dnode) : null;
|
||||
|
||||
return $dnode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create General Metadata (How To)
|
||||
*
|
||||
@@ -379,48 +358,43 @@ class cc_version1 extends cc_version_base {
|
||||
* @param object $xmlnode
|
||||
* @return DOMNode
|
||||
*/
|
||||
protected function create_metadata_general($met,DOMDocument &$doc,$xmlnode){
|
||||
($xmlnode);
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['lomimscc'],'general');
|
||||
protected function create_metadata_general($met, DOMDocument &$doc, $xmlnode) {
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'general');
|
||||
|
||||
foreach ($met->arraygeneral as $name => $value) {
|
||||
!is_array($value)?$value =array($value):null;
|
||||
foreach ($value as $k => $v){
|
||||
($k);
|
||||
if ($name != 'language' && $name != 'catalog' && $name != 'entry'){
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'],$name);
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'],'string',$v[1]);
|
||||
!is_array($value) ? $value = array($value) : null;
|
||||
foreach ($value as $v) {
|
||||
if ($name != 'language' && $name != 'catalog' && $name != 'entry') {
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name);
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'string', $v[1]);
|
||||
$ndatt = $doc->createAttribute('language');
|
||||
$ndatt->nodeValue = $v[0];
|
||||
$nd3->appendChild($ndatt);
|
||||
$nd2->appendChild($nd3);
|
||||
$nd->appendChild($nd2);
|
||||
}else{
|
||||
if ($name == 'language'){
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'],$name,$v[0]);
|
||||
} else {
|
||||
if ($name == 'language') {
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name, $v[0]);
|
||||
$nd->appendChild($nd2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($met->arraygeneral['catalog']) || !empty($met->arraygeneral['entry'])){
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'],'identifier');
|
||||
if (!empty($met->arraygeneral['catalog']) || !empty($met->arraygeneral['entry'])) {
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'identifier');
|
||||
$nd->appendChild($nd2);
|
||||
if (!empty($met->arraygeneral['catalog'])){
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'],'catalog',$met->arraygeneral['catalog'][0][0]);
|
||||
if (!empty($met->arraygeneral['catalog'])) {
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'catalog', $met->arraygeneral['catalog'][0][0]);
|
||||
$nd2->appendChild($nd3);
|
||||
}
|
||||
if (!empty($met->arraygeneral['entry'])){
|
||||
$nd4 = $doc->createElementNS($this->ccnamespaces['lomimscc'],'entry',$met->arraygeneral['entry'][0][0]);
|
||||
if (!empty($met->arraygeneral['entry'])) {
|
||||
$nd4 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'entry', $met->arraygeneral['entry'][0][0]);
|
||||
$nd2->appendChild($nd4);
|
||||
}
|
||||
}
|
||||
return $nd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create Technical Metadata (How To)
|
||||
*
|
||||
@@ -429,26 +403,21 @@ class cc_version1 extends cc_version_base {
|
||||
* @param object $xmlnode
|
||||
* @return DOMNode
|
||||
*/
|
||||
protected function create_metadata_technical($met,DOMDocument &$doc,$xmlnode){
|
||||
($xmlnode);
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['lomimscc'],'technical');
|
||||
protected function create_metadata_technical($met, DOMDocument &$doc, $xmlnode) {
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'technical');
|
||||
$xmlnode->appendChild($nd);
|
||||
|
||||
foreach ($met->arraytech as $name => $value) {
|
||||
($name);
|
||||
!is_array($value)?$value =array($value):null;
|
||||
foreach ($value as $k => $v){
|
||||
($k);
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'],$name,$v[0]);
|
||||
$nd->appendChild($nd2);
|
||||
!is_array($value) ? $value = array($value) : null;
|
||||
foreach ($value as $v) {
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name, $v[0]);
|
||||
$nd->appendChild($nd2);
|
||||
}
|
||||
}
|
||||
return $nd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create Rights Metadata (How To)
|
||||
*
|
||||
@@ -457,26 +426,24 @@ class cc_version1 extends cc_version_base {
|
||||
* @param object $xmlnode
|
||||
* @return DOMNode
|
||||
*/
|
||||
protected function create_metadata_rights($met,DOMDocument &$doc,$xmlnode){
|
||||
($xmlnode);
|
||||
protected function create_metadata_rights($met, DOMDocument &$doc, $xmlnode) {
|
||||
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['lomimscc'],'rights');
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'rights');
|
||||
|
||||
foreach ($met->arrayrights as $name => $value) {
|
||||
!is_array($value)?$value =array($value):null;
|
||||
foreach ($value as $k => $v){
|
||||
($k);
|
||||
if ($name == 'description'){
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'],$name);
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'],'string',$v[1]);
|
||||
!is_array($value) ? $value = array($value) : null;
|
||||
foreach ($value as $v) {
|
||||
if ($name == 'description') {
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name);
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'string', $v[1]);
|
||||
$ndatt = $doc->createAttribute('language');
|
||||
$ndatt->nodeValue = $v[0];
|
||||
$nd3->appendChild($ndatt);
|
||||
$nd2->appendChild($nd3);
|
||||
$nd->appendChild($nd2);
|
||||
}elseif ($name == 'copyrightAndOtherRestrictions' || $name == 'cost'){
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'],$name);
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'],'value',$v[0]);
|
||||
} else if ($name == 'copyrightAndOtherRestrictions' || $name == 'cost') {
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name);
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'value', $v[0]);
|
||||
$nd2->appendChild($nd3);
|
||||
$nd->appendChild($nd2);
|
||||
}
|
||||
@@ -485,44 +452,38 @@ class cc_version1 extends cc_version_base {
|
||||
return $nd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create LifeCyle Metadata (How To)
|
||||
* Create Lifecycle Metadata (How To)
|
||||
*
|
||||
* @param object $met
|
||||
* @param DOMDocument $doc
|
||||
* @param object $xmlnode
|
||||
* @return DOMNode
|
||||
*/
|
||||
protected function create_metadata_lifecycle($met,DOMDocument &$doc,$xmlnode){
|
||||
($xmlnode);
|
||||
protected function create_metadata_lifecycle($met, DOMDocument &$doc, $xmlnode) {
|
||||
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['lomimscc'],'lifeCycle');
|
||||
$nd2= $doc->createElementNS($this->ccnamespaces['lomimscc'],'contribute');
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'lifeCycle');
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'contribute');
|
||||
|
||||
|
||||
$nd->appendChild ($nd2);
|
||||
$xmlnode->appendChild ($nd);
|
||||
$nd->appendChild($nd2);
|
||||
$xmlnode->appendChild($nd);
|
||||
|
||||
foreach ($met->arraylifecycle as $name => $value) {
|
||||
!is_array($value)?$value =array($value):null;
|
||||
foreach ($value as $k => $v){
|
||||
($k);
|
||||
if ($name == 'role'){
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'],$name);
|
||||
!is_array($value) ? $value = array($value) : null;
|
||||
foreach ($value as $v) {
|
||||
if ($name == 'role') {
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name);
|
||||
$nd2->appendChild($nd3);
|
||||
$nd4 = $doc->createElementNS($this->ccnamespaces['lomimscc'],'value',$v[0]);
|
||||
$nd4 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'value', $v[0]);
|
||||
$nd3->appendChild($nd4);
|
||||
}else{
|
||||
if ($name == 'date'){
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'],$name);
|
||||
} else {
|
||||
if ($name == 'date') {
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name);
|
||||
$nd2->appendChild($nd3);
|
||||
$nd4 = $doc->createElementNS($this->ccnamespaces['lomimscc'],'dateTime',$v[0]);
|
||||
$nd4 = $doc->createElementNS($this->ccnamespaces['lomimscc'], 'dateTime', $v[0]);
|
||||
$nd3->appendChild($nd4);
|
||||
}else{
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'],$name,$v[0]);
|
||||
} else {
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['lomimscc'], $name, $v[0]);
|
||||
$nd2->appendChild($nd3);
|
||||
}
|
||||
}
|
||||
@@ -531,9 +492,6 @@ class cc_version1 extends cc_version_base {
|
||||
return $nd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create Education Metadata (How To)
|
||||
*
|
||||
@@ -542,24 +500,22 @@ class cc_version1 extends cc_version_base {
|
||||
* @param object $xmlnode
|
||||
* @return DOMNode
|
||||
*/
|
||||
public function create_metadata_educational ($met,DOMDocument &$doc, $xmlnode){
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['lom'],'educational');
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lom'],'intendedEndUserRole');
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['voc'],'vocabulary');
|
||||
public function create_metadata_educational($met, DOMDocument &$doc, $xmlnode) {
|
||||
$nd = $doc->createElementNS($this->ccnamespaces['lom'], 'educational');
|
||||
$nd2 = $doc->createElementNS($this->ccnamespaces['lom'], 'intendedEndUserRole');
|
||||
$nd3 = $doc->createElementNS($this->ccnamespaces['voc'], 'vocabulary');
|
||||
|
||||
$xmlnode->appendChild($nd);
|
||||
$nd->appendChild($nd2);
|
||||
$nd2->appendChild($nd3);
|
||||
|
||||
foreach ($met->arrayeducational as $name => $value) {
|
||||
!is_array($value)?$value =array($value):null;
|
||||
foreach ($value as $k => $v){
|
||||
($k);
|
||||
$nd4 = $doc->createElementNS($this->ccnamespaces['voc'],$name,$v[0]);
|
||||
!is_array($value) ? $value = array($value) : null;
|
||||
foreach ($value as $v) {
|
||||
$nd4 = $doc->createElementNS($this->ccnamespaces['voc'], $name, $v[0]);
|
||||
$nd3->appendChild($nd4);
|
||||
}
|
||||
}
|
||||
return $nd;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,14 +15,13 @@
|
||||
// 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
|
||||
*/
|
||||
|
||||
require_once 'cc_version1.php';
|
||||
* @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
|
||||
*/
|
||||
|
||||
require_once('cc_version1.php');
|
||||
|
||||
/**
|
||||
* Version 1.1 class of Common Cartridge
|
||||
@@ -46,11 +45,11 @@ class cc_version11 extends cc_version1 {
|
||||
self::basiclti);
|
||||
|
||||
/**
|
||||
* Validate if the type are valid or not
|
||||
*
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
* Validate if the type are valid or not
|
||||
*
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
public function valid($type) {
|
||||
return in_array($type, self::$checker);
|
||||
}
|
||||
@@ -78,9 +77,8 @@ class cc_version11 extends cc_version1 {
|
||||
$this->update_attribute($doc, 'identifier' , $key , $itemnode);
|
||||
$this->update_attribute($doc, 'identifierref', $item->identifierref, $itemnode);
|
||||
if (!is_null($item->title)) {
|
||||
$titlenode = $doc->createElementNS($this->ccnamespaces['imscc'],
|
||||
'title',
|
||||
$item->title);
|
||||
$titlenode = $doc->createElementNS($this->ccnamespaces['imscc'], 'title');
|
||||
$titlenode->appendChild(new DOMText($item->title));
|
||||
$itemnode->appendChild($titlenode);
|
||||
}
|
||||
if ($item->has_child_items()) {
|
||||
@@ -91,25 +89,25 @@ class cc_version11 extends cc_version1 {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Education Metadata (How To)
|
||||
*
|
||||
* @param object $met
|
||||
* @param DOMDocument $doc
|
||||
* @param object $xmlnode
|
||||
* @return DOMNode
|
||||
*/
|
||||
public function create_metadata_educational ($met, DOMDocument &$doc, $xmlnode){
|
||||
$metadata = $doc->createElementNS($this->ccnamespaces['imscc'] ,'metadata');
|
||||
* Create Education Metadata (How To)
|
||||
*
|
||||
* @param object $met
|
||||
* @param DOMDocument $doc
|
||||
* @param object $xmlnode
|
||||
* @return DOMNode
|
||||
*/
|
||||
public function create_metadata_educational($met, DOMDocument &$doc, $xmlnode) {
|
||||
$metadata = $doc->createElementNS($this->ccnamespaces['imscc'], 'metadata');
|
||||
$xmlnode->insertBefore($metadata, $xmlnode->firstChild);
|
||||
$lom = $doc->createElementNS($this->ccnamespaces['lom'] ,'lom');
|
||||
$lom = $doc->createElementNS($this->ccnamespaces['lom'], 'lom');
|
||||
$metadata->appendChild($lom);
|
||||
$educational = $doc->createElementNS($this->ccnamespaces['lom'] ,'educational');
|
||||
$educational = $doc->createElementNS($this->ccnamespaces['lom'], 'educational');
|
||||
$lom->appendChild($educational);
|
||||
|
||||
foreach ($met->arrayeducational as $name => $value) {
|
||||
!is_array($value)?$value =array($value):null;
|
||||
foreach ($value as $v){
|
||||
$userrole = $doc->createElementNS($this->ccnamespaces['lom'],'intendedEndUserRole');
|
||||
foreach ($met->arrayeducational as $value) {
|
||||
!is_array($value) ? $value = array($value) : null;
|
||||
foreach ($value as $v) {
|
||||
$userrole = $doc->createElementNS($this->ccnamespaces['lom'], 'intendedEndUserRole');
|
||||
$educational->appendChild($userrole);
|
||||
$nd4 = $doc->createElementNS($this->ccnamespaces['lom'], 'source', 'IMSGLC_CC_Rolesv1p1');
|
||||
$nd5 = $doc->createElementNS($this->ccnamespaces['lom'], 'value', $v[0]);
|
||||
|
||||
@@ -29,86 +29,86 @@ require_once 'cc_organization.php';
|
||||
*
|
||||
*/
|
||||
abstract class cc_version_base {
|
||||
protected $_generator = null;
|
||||
protected $ccnamespaces = array();
|
||||
protected $isrootmanifest = false;
|
||||
protected $manifestID = null;
|
||||
protected $organizationid = null;
|
||||
public $resources = null;
|
||||
public $resources_ind = null;
|
||||
protected $metadata = null;
|
||||
public $organizations = null;
|
||||
protected $base = null;
|
||||
public $ccversion = null;
|
||||
public $camversion = null;
|
||||
protected $_generator = null;
|
||||
protected $ccnamespaces = array();
|
||||
protected $isrootmanifest = false;
|
||||
protected $manifestID = null;
|
||||
protected $organizationid = null;
|
||||
public $resources = null;
|
||||
public $resources_ind = null;
|
||||
protected $metadata = null;
|
||||
public $organizations = null;
|
||||
protected $base = null;
|
||||
public $ccversion = null;
|
||||
public $camversion = null;
|
||||
|
||||
|
||||
abstract protected function on_create(DOMDocument &$doc,$rootmanifestnode=null,$nmanifestID=null);
|
||||
abstract protected function on_create(DOMDocument &$doc, $rootmanifestnode = null, $nmanifestID = null);
|
||||
|
||||
abstract protected function create_metadata_manifest (cc_i_metadata_manifest $met,DOMDocument &$doc,$xmlnode=null);
|
||||
abstract protected function create_metadata_manifest(cc_i_metadata_manifest $met, DOMDocument &$doc, $xmlnode = null);
|
||||
|
||||
abstract protected function create_metadata_resource (cc_i_metadata_resource $met,DOMDocument &$doc,$xmlnode=null);
|
||||
abstract protected function create_metadata_resource(cc_i_metadata_resource $met, DOMDocument &$doc, $xmlnode = null);
|
||||
|
||||
abstract protected function create_metadata_file (cc_i_metadata_file $met,DOMDocument &$doc,$xmlnode=null);
|
||||
abstract protected function create_metadata_file(cc_i_metadata_file $met, DOMDocument &$doc, $xmlnode = null);
|
||||
|
||||
abstract protected function create_resource(cc_i_resource &$res, DOMDocument &$doc, $xmlnode=null);
|
||||
|
||||
abstract protected function create_organization(cc_i_organization &$org, DOMDocument &$doc, $xmlnode=null);
|
||||
|
||||
public function get_cc_namespaces(){
|
||||
public function get_cc_namespaces() {
|
||||
return $this->ccnamespaces;
|
||||
}
|
||||
|
||||
public function create_manifest(DOMDocument &$doc,$rootmanifestnode=null){
|
||||
return $this->on_create($doc,$rootmanifestnode);
|
||||
public function create_manifest(DOMDocument &$doc, $rootmanifestnode = null) {
|
||||
return $this->on_create($doc, $rootmanifestnode);
|
||||
}
|
||||
|
||||
public function create_resource_node(cc_i_resource &$res, DOMDocument &$doc, $xmlnode = null) {
|
||||
return $this->create_resource($res,$doc,$xmlnode);
|
||||
return $this->create_resource($res, $doc, $xmlnode);
|
||||
}
|
||||
|
||||
|
||||
public function create_metadata_node (&$met, DOMDocument &$doc, $xmlnode = null){
|
||||
return $this->create_metadata_manifest($met,$doc,$xmlnode);
|
||||
public function create_metadata_node(&$met, DOMDocument &$doc, $xmlnode = null) {
|
||||
return $this->create_metadata_manifest($met, $doc, $xmlnode);
|
||||
}
|
||||
|
||||
public function create_metadata_resource_node (&$met, DOMDocument &$doc, $xmlnode = null){
|
||||
return $this->create_metadata_resource($met,$doc,$xmlnode);
|
||||
public function create_metadata_resource_node(&$met, DOMDocument &$doc, $xmlnode = null) {
|
||||
return $this->create_metadata_resource($met, $doc, $xmlnode);
|
||||
}
|
||||
|
||||
public function create_metadata_file_node (&$met, DOMDocument &$doc, $xmlnode = null){
|
||||
return $this->create_metadata_file($met,$doc,$xmlnode);
|
||||
public function create_metadata_file_node(&$met, DOMDocument &$doc, $xmlnode = null) {
|
||||
return $this->create_metadata_file($met, $doc, $xmlnode);
|
||||
}
|
||||
|
||||
public function create_organization_node(cc_i_organization &$org, DOMDocument &$doc, $xmlnode = null) {
|
||||
return $this->create_organization($org,$doc,$xmlnode);
|
||||
return $this->create_organization($org, $doc, $xmlnode);
|
||||
}
|
||||
|
||||
public function manifestID(){
|
||||
public function manifestID() {
|
||||
return $this->manifestID;
|
||||
}
|
||||
|
||||
public function set_manifestID($id){
|
||||
public function set_manifestID($id) {
|
||||
$this->manifestID = $id;
|
||||
}
|
||||
|
||||
public function get_base(){
|
||||
public function get_base() {
|
||||
return $this->base;
|
||||
}
|
||||
|
||||
public function set_base($baseval){
|
||||
public function set_base($baseval) {
|
||||
$this->base = $baseval;
|
||||
}
|
||||
|
||||
public function import_resources(DOMElement &$node, cc_i_manifest &$doc) {
|
||||
if (is_null($this->resources)){
|
||||
if (is_null($this->resources)) {
|
||||
$this->resources = array();
|
||||
}
|
||||
$nlist = $node->getElementsByTagNameNS($this->ccnamespaces['imscc'],'resource');
|
||||
$nlist = $node->getElementsByTagNameNS($this->ccnamespaces['imscc'], 'resource');
|
||||
if (is_object($nlist)) {
|
||||
foreach ($nlist as $nd) {
|
||||
$sc = new cc_resource($doc,$nd);
|
||||
$this->resources[$sc->identifier]=$sc;
|
||||
$sc = new cc_resource($doc, $nd);
|
||||
$this->resources[$sc->identifier] = $sc;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,11 +117,11 @@ abstract class cc_version_base {
|
||||
if (is_null($this->organizations)) {
|
||||
$this->organizations = array();
|
||||
}
|
||||
$nlist = $node->getElementsByTagNameNS($this->ccnamespaces['imscc'],'organization');
|
||||
$nlist = $node->getElementsByTagNameNS($this->ccnamespaces['imscc'], 'organization');
|
||||
if (is_object($nlist)) {
|
||||
foreach ($nlist as $nd) {
|
||||
$sc = new cc_organization($nd,$doc);
|
||||
$this->organizations[$sc->identifier]=$sc;
|
||||
$sc = new cc_organization($nd, $doc);
|
||||
$this->organizations[$sc->identifier] = $sc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,17 +14,15 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require_once dirname(__FILE__) .'/../xmlbase.php';
|
||||
require_once 'cssparser.php';
|
||||
require_once 'pathutils.php';
|
||||
|
||||
|
||||
require_once(dirname(__FILE__) .'/../xmlbase.php');
|
||||
require_once('cssparser.php');
|
||||
require_once('pathutils.php');
|
||||
|
||||
/**
|
||||
*
|
||||
* Older version better suited for PHP < 5.2
|
||||
* @deprecated
|
||||
* @param unknown_type $url
|
||||
* @param mixed $url
|
||||
* @return boolean
|
||||
*/
|
||||
function is_url_deprecated($url) {
|
||||
@@ -70,66 +68,64 @@ function GetDepFiles($manifestroot, $fname, $folder, &$filenames) {
|
||||
}
|
||||
}
|
||||
|
||||
function GetDepFilesHTML ($manifestroot, $fname, &$filenames, &$dcx, $folder){
|
||||
$dcx->resetXpath();
|
||||
$nlist = $dcx->nodeList("//img/@src | //link/@href | //script/@src | //a[not(starts-with(@href,'#'))]/@href");
|
||||
$css_obj_array=array();
|
||||
foreach ($nlist as $nl) {
|
||||
$item = $folder.$nl->nodeValue;
|
||||
$path_parts = pathinfo($item);
|
||||
$fname = $path_parts['basename'];
|
||||
$ext = array_key_exists('extension',$path_parts) ? $path_parts['extension'] : '';
|
||||
if (!is_url($folder.$nl->nodeValue) && !is_url($nl->nodeValue)) {
|
||||
$path = $folder.$nl->nodeValue;
|
||||
$file = fullPath($path,"/");
|
||||
toNativePath($file);
|
||||
if (file_exists($manifestroot.DIRECTORY_SEPARATOR.$file)) {
|
||||
$filenames[$file]= $file;
|
||||
}
|
||||
}
|
||||
if ($ext == 'css') {
|
||||
$css = new cssparser();
|
||||
$css->Parse($dcx->filePath().$nl->nodeValue);
|
||||
$css_obj_array[$item]=$css;
|
||||
function GetDepFilesHTML($manifestroot, $fname, &$filenames, &$dcx, $folder) {
|
||||
$dcx->resetXpath();
|
||||
$nlist = $dcx->nodeList("//img/@src | //link/@href | //script/@src | //a[not(starts-with(@href,'#'))]/@href");
|
||||
$css_obj_array = array();
|
||||
foreach ($nlist as $nl) {
|
||||
$item = $folder.$nl->nodeValue;
|
||||
$path_parts = pathinfo($item);
|
||||
$fname = $path_parts['basename'];
|
||||
$ext = array_key_exists('extension', $path_parts) ? $path_parts['extension'] : '';
|
||||
if (!is_url($folder.$nl->nodeValue) && !is_url($nl->nodeValue)) {
|
||||
$path = $folder.$nl->nodeValue;
|
||||
$file = fullPath($path, "/");
|
||||
toNativePath($file);
|
||||
if (file_exists($manifestroot.DIRECTORY_SEPARATOR.$file)) {
|
||||
$filenames[$file] = $file;
|
||||
}
|
||||
}
|
||||
$nlist = $dcx->nodeList("//*/@class");
|
||||
foreach ($nlist as $nl) {
|
||||
$item = $folder.$nl->nodeValue;
|
||||
if ($ext == 'css') {
|
||||
$css = new cssparser();
|
||||
$css->Parse($dcx->filePath().$nl->nodeValue);
|
||||
$css_obj_array[$item] = $css;
|
||||
}
|
||||
}
|
||||
$nlist = $dcx->nodeList("//*/@class");
|
||||
foreach ($nlist as $nl) {
|
||||
$item = $folder.$nl->nodeValue;
|
||||
foreach ($css_obj_array as $csskey => $cssobj) {
|
||||
$bimg = $cssobj->Get($item, "background-image");
|
||||
$limg = $cssobj->Get($item, "list-style-image");
|
||||
$npath = pathinfo($csskey);
|
||||
if ((!empty($bimg)) && ($bimg != 'none')) {
|
||||
$value = stripUrl($bimg, $npath['dirname'].'/');
|
||||
$filenames[$value] = $value;
|
||||
} else if ((!empty($limg)) && ($limg != 'none')) {
|
||||
$value = stripUrl($limg, $npath['dirname'].'/');
|
||||
$filenames[$value] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$elems_to_check = array("body", "p", "ul", "h4", "a", "th");
|
||||
$do_we_have_it = array();
|
||||
foreach ($elems_to_check as $elem) {
|
||||
$do_we_have_it[$elem] = ($dcx->nodeList("//".$elem)->length > 0);
|
||||
}
|
||||
foreach ($elems_to_check as $elem) {
|
||||
if ($do_we_have_it[$elem]) {
|
||||
foreach ($css_obj_array as $csskey => $cssobj) {
|
||||
$bimg = $cssobj->Get($item,"background-image");
|
||||
$limg = $cssobj->Get($item,"list-style-image");
|
||||
$sb = $cssobj->Get($elem, "background-image");
|
||||
$sbl = $cssobj->Get($elem, "list-style-image");
|
||||
$npath = pathinfo($csskey);
|
||||
if ((!empty($bimg))&& ($bimg != 'none')) {
|
||||
$value = stripUrl($bimg,$npath['dirname'].'/');
|
||||
if ((!empty($sb)) && ($sb != 'none')) {
|
||||
$value = stripUrl($sb, $npath['dirname'].'/');
|
||||
$filenames[$value] = $value;
|
||||
} else
|
||||
if ((!empty($limg))&& ($limg != 'none')) {
|
||||
$value = stripUrl($limg,$npath['dirname'].'/');
|
||||
} else if ((!empty($sbl)) && ($sbl != 'none')) {
|
||||
$value = stripUrl($sbl, $npath['dirname'].'/');
|
||||
$filenames[$value] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$elems_to_check = array("body","p","ul","h4","a","th");
|
||||
$do_we_have_it = array();
|
||||
foreach ($elems_to_check as $elem) {
|
||||
$do_we_have_it[$elem]=($dcx->nodeList("//".$elem)->length > 0);
|
||||
}
|
||||
foreach ($elems_to_check as $elem) {
|
||||
if ($do_we_have_it[$elem]) {
|
||||
foreach ($css_obj_array as $csskey => $cssobj) {
|
||||
$sb = $cssobj->Get($elem, "background-image");
|
||||
$sbl = $cssobj->Get($elem,"list-style-image");
|
||||
$npath = pathinfo($csskey);
|
||||
if ((!empty($sb)) && ($sb != 'none')) {
|
||||
$value = stripUrl($sb,$npath['dirname'].'/');
|
||||
$filenames[$value] = $value;
|
||||
} else
|
||||
if ((!empty($sbl)) && ($sbl != 'none')) {
|
||||
$value = stripUrl($sbl,$npath['dirname'].'/');
|
||||
$filenames[$value] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,38 +12,35 @@
|
||||
*
|
||||
*/
|
||||
|
||||
require_once 'gral_lib/cssparser.php';
|
||||
require_once('gral_lib/cssparser.php');
|
||||
|
||||
/**
|
||||
* Base XML class
|
||||
*
|
||||
*/
|
||||
class XMLGenericDocument {
|
||||
|
||||
|
||||
private $charset;
|
||||
private $charset;
|
||||
/**
|
||||
*
|
||||
* Document
|
||||
* @var DOMDocument
|
||||
*/
|
||||
public $doc = null;
|
||||
public $doc = null;
|
||||
/**
|
||||
*
|
||||
* Xpath
|
||||
* @var DOMXPath
|
||||
*/
|
||||
protected $dxpath = null;
|
||||
protected $filename;
|
||||
private $filepath;
|
||||
private $isloaded = false;
|
||||
private $arrayPrefixNS = array();
|
||||
private $is_html = false;
|
||||
protected $filename;
|
||||
private $filepath;
|
||||
private $isloaded = false;
|
||||
private $arrayPrefixNS = array();
|
||||
private $is_html = false;
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function safexml($value) {
|
||||
$result = htmlspecialchars(html_entity_decode($value, ENT_QUOTES, 'UTF-8'),
|
||||
ENT_NOQUOTES,
|
||||
@@ -52,51 +49,51 @@ class XMLGenericDocument {
|
||||
return $result;
|
||||
}
|
||||
|
||||
function __construct($ch = 'UTF-8',$validatenow=true){
|
||||
function __construct($ch = 'UTF-8', $validatenow = true) {
|
||||
$this->charset = $ch;
|
||||
$this->documentInit();
|
||||
$this->doc->validateOnParse = $validatenow;
|
||||
}
|
||||
|
||||
function __destruct(){
|
||||
function __destruct() {
|
||||
$this->dxpath = null;
|
||||
$this->doc = null;
|
||||
$this->doc = null;
|
||||
}
|
||||
|
||||
private function documentInit($withonCreate=true) {
|
||||
private function documentInit($withonCreate = true) {
|
||||
$hg = false;
|
||||
if ($this->isloaded){
|
||||
if ($this->isloaded) {
|
||||
$guardstate = $this->doc->validateOnParse;
|
||||
$hg = true;
|
||||
unset($this->dxpath);
|
||||
unset($this->doc);
|
||||
$this->isloaded = false;
|
||||
}
|
||||
$this->doc = new DOMDocument("1.0",$this->charset);
|
||||
$this->doc = new DOMDocument("1.0", $this->charset);
|
||||
$this->doc->strictErrorChecking = true;
|
||||
if ($hg) {
|
||||
$this->doc->validateOnParse = $guardstate;
|
||||
}
|
||||
$this->doc->formatOutput = true;
|
||||
$this->doc->preserveWhiteSpace = true;
|
||||
if($withonCreate) {
|
||||
if ($withonCreate) {
|
||||
$this->on_create();
|
||||
}
|
||||
}
|
||||
|
||||
public function viewXML (){
|
||||
public function viewXML() {
|
||||
return $this->doc->saveXML();
|
||||
}
|
||||
|
||||
public function registerNS($prefix, $nsuri) {
|
||||
$this->arrayPrefixNS[$prefix]=$nsuri;
|
||||
$this->arrayPrefixNS[$prefix] = $nsuri;
|
||||
}
|
||||
|
||||
public function load($fname) {
|
||||
// Sine xml will remain loaded should the repeated load fail we should recreate document to be empty.
|
||||
// Sine xml will remain loaded should the repeated load fail we should recreate document to be empty.
|
||||
$this->documentInit(false);
|
||||
$this->isloaded = $this->doc->load($fname);
|
||||
if ($this->isloaded){
|
||||
if ($this->isloaded) {
|
||||
$this->filename = $fname;
|
||||
$this->processPath();
|
||||
$this->is_html = false;
|
||||
@@ -104,7 +101,7 @@ class XMLGenericDocument {
|
||||
return $this->on_load();
|
||||
}
|
||||
|
||||
public function loadUrl($url){
|
||||
public function loadUrl($url) {
|
||||
$this->documentInit();
|
||||
$this->isloaded = true;
|
||||
$this->doc->loadXML( file_get_contents($url) );
|
||||
@@ -112,7 +109,7 @@ class XMLGenericDocument {
|
||||
return $this->on_load();
|
||||
}
|
||||
|
||||
public function loadHTML ($content){
|
||||
public function loadHTML($content) {
|
||||
$this->documentInit();
|
||||
$this->doc->validateOnParse = false;
|
||||
$this->isloaded = true;
|
||||
@@ -121,7 +118,7 @@ class XMLGenericDocument {
|
||||
return $this->on_load();
|
||||
}
|
||||
|
||||
public function loadXML ($content){
|
||||
public function loadXML($content) {
|
||||
$this->documentInit();
|
||||
$this->doc->validateOnParse = false;
|
||||
$this->isloaded = true;
|
||||
@@ -130,9 +127,9 @@ class XMLGenericDocument {
|
||||
return $this->on_load();
|
||||
}
|
||||
|
||||
public function loadHTMLFile($fname){
|
||||
//Sine xml will remain loaded should the repeated load fail
|
||||
//we shoudl recreate document to be empty
|
||||
public function loadHTMLFile($fname) {
|
||||
// Sine xml will remain loaded should the repeated load fail
|
||||
// we should recreate document to be empty.
|
||||
$this->documentInit();
|
||||
$this->doc->validateOnParse = false;
|
||||
$this->isloaded = $this->doc->loadHTMLFile($fname);
|
||||
@@ -144,29 +141,28 @@ class XMLGenericDocument {
|
||||
return $this->on_load();
|
||||
}
|
||||
|
||||
public function loadXMLFile($fname){
|
||||
//Sine xml will remain loaded should the repeated load fail
|
||||
//we shoudl recreate document to be empty
|
||||
public function loadXMLFile($fname) {
|
||||
// Sine xml will remain loaded should the repeated load fail
|
||||
// we should recreate document to be empty.
|
||||
$this->documentInit();
|
||||
$this->doc->validateOnParse = false;
|
||||
$this->isloaded = $this->doc->load($fname);
|
||||
if ($this->isloaded) {
|
||||
$this->filename = $fname;
|
||||
$this->processPath();
|
||||
$this->is_html=true;
|
||||
$this->is_html = true;
|
||||
}
|
||||
return $this->on_load();
|
||||
}
|
||||
|
||||
|
||||
public function loadString($content){
|
||||
public function loadString($content) {
|
||||
|
||||
$this->doc = new DOMDocument("1.0",$this->charset);
|
||||
$this->doc = new DOMDocument("1.0", $this->charset);
|
||||
$content = '<virtualtag>'.$content.'</virtualtag>';
|
||||
$this->doc->loadXML($content);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function save() {
|
||||
@@ -192,18 +188,16 @@ class XMLGenericDocument {
|
||||
return $this->doc->validate();
|
||||
}
|
||||
|
||||
public function attributeValue($path,$attrname,$node=null) {
|
||||
public function attributeValue($path, $attrname, $node = null) {
|
||||
$this->chkxpath();
|
||||
$result = null;
|
||||
$resultlist = null;
|
||||
if (is_null($node)) {
|
||||
$resultlist = $this->dxpath->query($path);
|
||||
} else {
|
||||
$resultlist = $this->dxpath->query($path,$node);
|
||||
$resultlist = $this->dxpath->query($path, $node);
|
||||
}
|
||||
if ( is_object($resultlist) &&
|
||||
($resultlist->length > 0) &&
|
||||
$resultlist->item(0)->hasAttribute($attrname)){
|
||||
if (is_object($resultlist) && ($resultlist->length > 0) && $resultlist->item(0)->hasAttribute($attrname)) {
|
||||
$result = $resultlist->item(0)->getAttribute($attrname);
|
||||
}
|
||||
return $result;
|
||||
@@ -217,7 +211,7 @@ class XMLGenericDocument {
|
||||
* @param int $count
|
||||
* @return string
|
||||
*/
|
||||
public function nodeValue($path, $node = null, $count = 1){
|
||||
public function nodeValue($path, $node = null, $count = 1) {
|
||||
$nd = $this->node($path, $node, $count);
|
||||
return $this->nodeTextValue($nd);
|
||||
}
|
||||
@@ -228,17 +222,17 @@ class XMLGenericDocument {
|
||||
* @param DOMNode $node
|
||||
* @return string
|
||||
*/
|
||||
public function nodeTextValue($node){
|
||||
public function nodeTextValue($node) {
|
||||
$result = '';
|
||||
if (is_object($node)) {
|
||||
if ($node->hasChildNodes()) {
|
||||
$chnodesList = $node->childNodes;
|
||||
$types = array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE);
|
||||
foreach ($chnodesList as $chnode) {
|
||||
if (in_array($chnode->nodeType, $types)){
|
||||
$result .= $chnode->wholeText;
|
||||
}
|
||||
}
|
||||
if (in_array($chnode->nodeType, $types)) {
|
||||
$result .= $chnode->wholeText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
@@ -255,9 +249,8 @@ class XMLGenericDocument {
|
||||
public function node($path, $nd = null, $count = 1) {
|
||||
$result = null;
|
||||
$resultlist = $this->nodeList($path,$nd);
|
||||
if ( is_object($resultlist) &&
|
||||
($resultlist->length > 0) ){
|
||||
$result = $resultlist->item($count -1);
|
||||
if (is_object($resultlist) && ($resultlist->length > 0)) {
|
||||
$result = $resultlist->item($count - 1);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@@ -269,7 +262,7 @@ class XMLGenericDocument {
|
||||
* @param DOMNode $node
|
||||
* @return DOMNodeList
|
||||
*/
|
||||
public function nodeList($path,$node=null){
|
||||
public function nodeList($path, $node = null) {
|
||||
|
||||
$this->chkxpath();
|
||||
|
||||
@@ -277,7 +270,7 @@ class XMLGenericDocument {
|
||||
if (is_null($node)) {
|
||||
$resultlist = $this->dxpath->query($path);
|
||||
} else {
|
||||
$resultlist = $this->dxpath->query($path,$node);
|
||||
$resultlist = $this->dxpath->query($path, $node);
|
||||
}
|
||||
return $resultlist;
|
||||
}
|
||||
@@ -392,12 +385,25 @@ class XMLGenericDocument {
|
||||
return $node->appendChild($this->create_attribute_ns($namespace, $name, $value));
|
||||
}
|
||||
|
||||
public function fileName() {return $this->filename;}
|
||||
public function filePath() {return $this->filepath;}
|
||||
public function fileName() {
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
protected function on_load() {return $this->isloaded;}
|
||||
protected function on_save() {return true;}
|
||||
protected function on_create() {return true;}
|
||||
public function filePath() {
|
||||
return $this->filepath;
|
||||
}
|
||||
|
||||
protected function on_load() {
|
||||
return $this->isloaded;
|
||||
}
|
||||
|
||||
protected function on_save() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function on_create() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function resetXpath() {
|
||||
$this->dxpath = null;
|
||||
@@ -405,16 +411,16 @@ class XMLGenericDocument {
|
||||
}
|
||||
|
||||
private function chkxpath() {
|
||||
if (!isset($this->dxpath) || is_null($this->dxpath)){
|
||||
if (!isset($this->dxpath) || is_null($this->dxpath)) {
|
||||
$this->dxpath = new DOMXPath($this->doc);
|
||||
foreach ($this->arrayPrefixNS as $nskey => $nsuri) {
|
||||
$this->dxpath->registerNamespace($nskey,$nsuri);
|
||||
$this->dxpath->registerNamespace($nskey, $nsuri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function processPath(){
|
||||
$path_parts = pathinfo($this->filename);
|
||||
$this->filepath = array_key_exists('dirname',$path_parts) ? $path_parts['dirname']."/" : '';
|
||||
protected function processPath() {
|
||||
$path_parts = pathinfo($this->filename);
|
||||
$this->filepath = array_key_exists('dirname', $path_parts) ? $path_parts['dirname']."/" : '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,10 @@ defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
|
||||
|
||||
class entities {
|
||||
/**
|
||||
*
|
||||
* Prepares convert for inclusion into XML
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function safexml($value) {
|
||||
$result = htmlspecialchars(html_entity_decode($value, ENT_QUOTES, 'UTF-8'),
|
||||
@@ -57,7 +58,7 @@ class entities {
|
||||
$result = mb_convert_encoding($content, 'UTF-8', $encoding);
|
||||
}
|
||||
|
||||
// See if we can strip off body tag and anything outside of it
|
||||
// See if we can strip off body tag and anything outside of it.
|
||||
foreach (array('body', 'html') as $tagname) {
|
||||
$regex = str_replace('##', $tagname, "/<##[^>]*>(.+)<\/##>/is");
|
||||
if (preg_match($regex, $result, $matches)) {
|
||||
@@ -68,11 +69,11 @@ class entities {
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function load_xml_resource ($path_to_file) {
|
||||
public function load_xml_resource($path_to_file) {
|
||||
|
||||
$resource = new DOMDocument();
|
||||
|
||||
cc2moodle::log_action('Load the XML resource file: ' . $path_to_file);
|
||||
cc2moodle::log_action('Load the XML resource file: '.$path_to_file);
|
||||
|
||||
if (!$resource->load($path_to_file)) {
|
||||
cc2moodle::log_action('Cannot load the XML resource file: ' . $path_to_file, true);
|
||||
@@ -81,7 +82,7 @@ class entities {
|
||||
return $resource;
|
||||
}
|
||||
|
||||
public function update_sources ($html, $root_path = '') {
|
||||
public function update_sources($html, $root_path = '') {
|
||||
|
||||
$document = $this->load_html($html);
|
||||
|
||||
@@ -111,13 +112,12 @@ class entities {
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function full_path ($path, $dir_sep = DIRECTORY_SEPARATOR) {
|
||||
public function full_path($path, $dir_sep = DIRECTORY_SEPARATOR) {
|
||||
|
||||
$token = '$IMS-CC-FILEBASE$';
|
||||
$path = str_replace($token, '', $path);
|
||||
|
||||
if (is_string($path) && ($path != '')) {
|
||||
$dir_sep;
|
||||
$dot_dir = '.';
|
||||
$up_dir = '..';
|
||||
$length = strlen($path);
|
||||
@@ -152,7 +152,6 @@ class entities {
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public function include_titles ($html) {
|
||||
@@ -184,11 +183,10 @@ class entities {
|
||||
|
||||
public function get_external_xml ($identifier) {
|
||||
|
||||
$response = '';
|
||||
|
||||
$xpath = cc2moodle::newx_path(cc2moodle::$manifest, cc2moodle::$namespaces);
|
||||
|
||||
$files = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $identifier . '"]/imscc:file/@href');
|
||||
$files = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="'.
|
||||
$identifier.'"]/imscc:file/@href');
|
||||
|
||||
if (empty($files)) {
|
||||
$response = '';
|
||||
@@ -199,7 +197,7 @@ class entities {
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function move_files ($files, $destination_folder) {
|
||||
public function move_files($files, $destination_folder) {
|
||||
global $CFG;
|
||||
|
||||
if (!empty($files)) {
|
||||
@@ -242,7 +240,7 @@ class entities {
|
||||
|
||||
if (!empty($files) && ($files->length > 0)) {
|
||||
foreach ($files as $file) {
|
||||
//omit html files
|
||||
// Omit html files.
|
||||
$ext = strtolower(pathinfo($file->nodeValue, PATHINFO_EXTENSION));
|
||||
if (in_array($ext, array('html', 'htm', 'xhtml'))) {
|
||||
continue;
|
||||
@@ -253,7 +251,7 @@ class entities {
|
||||
unset($files);
|
||||
}
|
||||
|
||||
//are there any labels?
|
||||
// Are there any labels?
|
||||
$xquery = "//imscc:item/imscc:item/imscc:item[imscc:title][not(@identifierref)]";
|
||||
$labels = $xpath->query($xquery);
|
||||
if (!empty($labels) && ($labels->length > 0)) {
|
||||
@@ -265,7 +263,7 @@ class entities {
|
||||
if (!file_exists($dpath)) {
|
||||
mkdir($dpath, $CFG->directorypermissions, true);
|
||||
}
|
||||
//copy the folder.gif file
|
||||
// Copy the folder.gif file.
|
||||
$folder_gif = "{$CFG->dirroot}/pix/i/files.gif";
|
||||
copy($folder_gif, $fpath);
|
||||
$all_files[] = $rfpath;
|
||||
@@ -337,7 +335,7 @@ class entities {
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function truncate_text ($text, $max, $remove_html) {
|
||||
public function truncate_text($text, $max, $remove_html) {
|
||||
|
||||
if ($max > 10) {
|
||||
$text = substr($text, 0, ($max - 6)) . ' [...]';
|
||||
|
||||
@@ -88,13 +88,17 @@ class cc_quiz extends entities {
|
||||
|
||||
if (!empty($assessment_file)) {
|
||||
|
||||
$assessment = $this->load_xml_resource(cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $assessment_file);
|
||||
$assessment = $this->load_xml_resource(
|
||||
cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $assessment_file
|
||||
);
|
||||
|
||||
if (!empty($assessment)) {
|
||||
|
||||
$replace_values = array('unlimited' => 0);
|
||||
|
||||
$questions = $this->get_questions($assessment, $last_question_id, $last_answer_id, dirname($assessment_file), $is_question_bank);
|
||||
$questions = $this->get_questions(
|
||||
$assessment, $last_question_id, $last_answer_id, dirname($assessment_file), $is_question_bank
|
||||
);
|
||||
$question_count = count($questions);
|
||||
|
||||
if (!empty($question_count)) {
|
||||
@@ -105,8 +109,10 @@ class cc_quiz extends entities {
|
||||
$instances[$instance['resource_indentifier']]['id'] = $last_instance_id;
|
||||
$instances[$instance['resource_indentifier']]['title'] = $instance['title'];
|
||||
$instances[$instance['resource_indentifier']]['is_question_bank'] = $is_question_bank;
|
||||
$instances[$instance['resource_indentifier']]['options']['timelimit'] = $this->get_global_config($assessment, 'qmd_timelimit', 0);
|
||||
$instances[$instance['resource_indentifier']]['options']['max_attempts'] = $this->get_global_config($assessment, 'cc_maxattempts', 0, $replace_values);
|
||||
$instances[$instance['resource_indentifier']]['options']['timelimit'] =
|
||||
$this->get_global_config($assessment, 'qmd_timelimit', 0);
|
||||
$instances[$instance['resource_indentifier']]['options']['max_attempts'] =
|
||||
$this->get_global_config($assessment, 'cc_maxattempts', 0, $replace_values);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,7 +154,7 @@ class cc_quiz extends entities {
|
||||
$instance['options']['max_attempts'],
|
||||
$instance['options']['timelimit'],
|
||||
$node_course_modules_quiz_question_instances,
|
||||
$node_course_modules_quiz_feedback); //this one has tags
|
||||
$node_course_modules_quiz_feedback); // This one has tags.
|
||||
|
||||
$node_question_mod = str_replace($find_tags, $replace_values, $sheet_question_mod);
|
||||
|
||||
@@ -194,10 +200,14 @@ class cc_quiz extends entities {
|
||||
|
||||
foreach ($instance['questions'] as $question) {
|
||||
$replace_values = array($question['id'] , $question['id']);
|
||||
$node_course_module_mod_quiz_questions_instances .= str_replace($find_tags, $replace_values, $sheet_question_mod_instance);
|
||||
$node_course_module_mod_quiz_questions_instances .= str_replace(
|
||||
$find_tags, $replace_values, $sheet_question_mod_instance
|
||||
);
|
||||
}
|
||||
|
||||
$node_course_module_mod_quiz_questions_instances = str_replace($find_tags, $replace_values, $node_course_module_mod_quiz_questions_instances);
|
||||
$node_course_module_mod_quiz_questions_instances = str_replace(
|
||||
$find_tags, $replace_values, $node_course_module_mod_quiz_questions_instances
|
||||
);
|
||||
}
|
||||
|
||||
return $node_course_module_mod_quiz_questions_instances;
|
||||
@@ -218,7 +228,7 @@ class cc_quiz extends entities {
|
||||
return $questions_string;
|
||||
}
|
||||
|
||||
private function create_node_course_question_categories ($instances) {
|
||||
private function create_node_course_question_categories($instances) {
|
||||
|
||||
$sheet_question_categories = cc2moodle::loadsheet(SHEET_COURSE_QUESTION_CATEGORIES);
|
||||
|
||||
@@ -227,7 +237,8 @@ class cc_quiz extends entities {
|
||||
$node_course_question_categories_question_category = '';
|
||||
|
||||
foreach ($instances as $instance) {
|
||||
$node_course_question_categories_question_category .= $this->create_node_course_question_categories_question_category($instance);
|
||||
$node_course_question_categories_question_category .=
|
||||
$this->create_node_course_question_categories_question_category($instance);
|
||||
}
|
||||
|
||||
$find_tags = array('[#node_course_question_categories_question_category#]');
|
||||
@@ -250,8 +261,10 @@ class cc_quiz extends entities {
|
||||
'[#quiz_stamp#]',
|
||||
'[#node_course_question_categories_question_category_questions#]');
|
||||
|
||||
$node_course_question_categories_questions = $this->create_node_course_question_categories_question_category_question($instance);
|
||||
$node_course_question_categories_questions = empty($node_course_question_categories_questions) ? '' : $node_course_question_categories_questions;
|
||||
$node_course_question_categories_questions =
|
||||
$this->create_node_course_question_categories_question_category_question($instance);
|
||||
$node_course_question_categories_questions =
|
||||
empty($node_course_question_categories_questions) ? '' : $node_course_question_categories_questions;
|
||||
|
||||
$quiz_stamp = 'localhost+' . time() . '+' . $this->generate_random_string(6);
|
||||
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Provides Common Cartridge v1 converter class
|
||||
*
|
||||
* @package core
|
||||
* @subpackage backup-convert
|
||||
* @copyright 2011 Darko Miletic <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
* Provides Common Cartridge v1 converter class
|
||||
*
|
||||
* @package core
|
||||
* @subpackage backup-convert
|
||||
* @copyright 2011 Darko Miletic <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once($CFG->dirroot . '/backup/converter/convertlib.php');
|
||||
require_once($CFG->dirroot . '/backup/cc/includes/constants.php');
|
||||
require_once($CFG->dirroot . '/backup/cc/cc2moodle.php');
|
||||
require_once($CFG->dirroot . '/backup/cc/validator.php');
|
||||
require_once($CFG->dirroot.'/backup/converter/convertlib.php');
|
||||
require_once($CFG->dirroot.'/backup/cc/includes/constants.php');
|
||||
require_once($CFG->dirroot.'/backup/cc/cc2moodle.php');
|
||||
require_once($CFG->dirroot.'/backup/cc/validator.php');
|
||||
|
||||
class imscc1_converter extends base_converter {
|
||||
|
||||
/**
|
||||
* Log a message
|
||||
*
|
||||
* @see parent::log()
|
||||
* @param string $message message text
|
||||
* @param int $level message level {@example backup::LOG_WARNING}
|
||||
* @param null|mixed $a additional information
|
||||
* @param null|int $depth the message depth
|
||||
* @param bool $display whether the message should be sent to the output, too
|
||||
*/
|
||||
* Log a message
|
||||
*
|
||||
* @see parent::log()
|
||||
* @param string $message message text
|
||||
* @param int $level message level {@example backup::LOG_WARNING}
|
||||
* @param null|mixed $a additional information
|
||||
* @param null|int $depth the message depth
|
||||
* @param bool $display whether the message should be sent to the output, too
|
||||
*/
|
||||
public function log($message, $level, $a = null, $depth = null, $display = false) {
|
||||
parent::log('(imscc1) '.$message, $level, $a, $depth, $display);
|
||||
}
|
||||
@@ -42,12 +42,12 @@ class imscc1_converter extends base_converter {
|
||||
$filepath = $CFG->dataroot . '/temp/backup/' . $tempdir;
|
||||
$manifest = cc2moodle::get_manifest($filepath);
|
||||
if (!empty($manifest)) {
|
||||
// looks promising, lets load some information
|
||||
// Looks promising, lets load some information.
|
||||
$handle = fopen($manifest, 'r');
|
||||
$xml_snippet = fread($handle, 1024);
|
||||
fclose($handle);
|
||||
|
||||
// check if it has the required strings
|
||||
// Check if it has the required strings.
|
||||
|
||||
$xml_snippet = strtolower($xml_snippet);
|
||||
$xml_snippet = preg_replace('/\s*/m', '', $xml_snippet);
|
||||
@@ -65,13 +65,13 @@ class imscc1_converter extends base_converter {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the basic information about the converter
|
||||
*
|
||||
* The returned array must contain the following keys:
|
||||
* 'from' - the supported source format, eg. backup::FORMAT_MOODLE1
|
||||
* 'to' - the supported target format, eg. backup::FORMAT_MOODLE
|
||||
* 'cost' - the cost of the conversion, non-negative non-zero integer
|
||||
*/
|
||||
* Returns the basic information about the converter
|
||||
*
|
||||
* The returned array must contain the following keys:
|
||||
* 'from' - the supported source format, eg. backup::FORMAT_MOODLE1
|
||||
* 'to' - the supported target format, eg. backup::FORMAT_MOODLE
|
||||
* 'cost' - the cost of the conversion, non-negative non-zero integer
|
||||
*/
|
||||
public static function description() {
|
||||
|
||||
return array(
|
||||
@@ -102,7 +102,7 @@ class imscc1_converter extends base_converter {
|
||||
throw new imscc1_convert_exception('protected_cc_not_supported');
|
||||
}
|
||||
$status = $cc2moodle->generate_moodle_xml();
|
||||
//Final cleanup
|
||||
// Final cleanup.
|
||||
$xml_error = new libxml_errors_mgr(true);
|
||||
$mdoc = new DOMDocument();
|
||||
$mdoc->preserveWhiteSpace = false;
|
||||
@@ -116,7 +116,7 @@ class imscc1_converter extends base_converter {
|
||||
$this->log('validation error(s): '.PHP_EOL.error_messages::instance(), backup::LOG_DEBUG, null, 2);
|
||||
throw new imscc1_convert_exception(error_messages::instance()->to_string(true));
|
||||
}
|
||||
//Move the files to the workdir
|
||||
// Move the files to the workdir.
|
||||
rename($manifestdir.'/course_files', $this->get_workdir_path().'/course_files');
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ class imscc1_converter extends base_converter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown by this converter
|
||||
*/
|
||||
* Exception thrown by this converter
|
||||
*/
|
||||
class imscc1_convert_exception extends convert_exception {
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Provides Common Cartridge v1.1 converter class
|
||||
*
|
||||
* @package core
|
||||
* @subpackage backup-convert
|
||||
* @copyright 2011 Darko Miletic <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
* Provides Common Cartridge v1.1 converter class
|
||||
*
|
||||
* @package core
|
||||
* @subpackage backup-convert
|
||||
* @copyright 2011 Darko Miletic <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once($CFG->dirroot . '/backup/converter/convertlib.php');
|
||||
require_once($CFG->dirroot . '/backup/cc/includes/constants.php');
|
||||
require_once($CFG->dirroot . '/backup/cc/cc112moodle.php');
|
||||
require_once($CFG->dirroot . '/backup/cc/validator.php');
|
||||
require_once($CFG->dirroot.'/backup/converter/convertlib.php');
|
||||
require_once($CFG->dirroot.'/backup/cc/includes/constants.php');
|
||||
require_once($CFG->dirroot.'/backup/cc/cc112moodle.php');
|
||||
require_once($CFG->dirroot.'/backup/cc/validator.php');
|
||||
|
||||
|
||||
class imscc11_converter extends base_converter {
|
||||
|
||||
/**
|
||||
* Log a message
|
||||
*
|
||||
* @see parent::log()
|
||||
* @param string $message message text
|
||||
* @param int $level message level {@example backup::LOG_WARNING}
|
||||
* @param null|mixed $a additional information
|
||||
* @param null|int $depth the message depth
|
||||
* @param bool $display whether the message should be sent to the output, too
|
||||
*/
|
||||
* Log a message
|
||||
*
|
||||
* @see parent::log()
|
||||
* @param string $message message text
|
||||
* @param int $level message level {@example backup::LOG_WARNING}
|
||||
* @param null|mixed $a additional information
|
||||
* @param null|int $depth the message depth
|
||||
* @param bool $display whether the message should be sent to the output, too
|
||||
*/
|
||||
public function log($message, $level, $a = null, $depth = null, $display = false) {
|
||||
parent::log('(imscc1) '.$message, $level, $a, $depth, $display);
|
||||
}
|
||||
@@ -43,12 +43,12 @@ class imscc11_converter extends base_converter {
|
||||
$filepath = $CFG->dataroot . '/temp/backup/' . $tempdir;
|
||||
$manifest = cc112moodle::get_manifest($filepath);
|
||||
if (file_exists($manifest)) {
|
||||
// looks promising, lets load some information
|
||||
// Looks promising, lets load some information.
|
||||
$handle = fopen($manifest, 'r');
|
||||
$xml_snippet = fread($handle, 1024);
|
||||
fclose($handle);
|
||||
|
||||
// check if it has the required strings
|
||||
// Check if it has the required strings.
|
||||
|
||||
$xml_snippet = strtolower($xml_snippet);
|
||||
$xml_snippet = preg_replace('/\s*/m', '', $xml_snippet);
|
||||
@@ -66,13 +66,13 @@ class imscc11_converter extends base_converter {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the basic information about the converter
|
||||
*
|
||||
* The returned array must contain the following keys:
|
||||
* 'from' - the supported source format, eg. backup::FORMAT_MOODLE1
|
||||
* 'to' - the supported target format, eg. backup::FORMAT_MOODLE
|
||||
* 'cost' - the cost of the conversion, non-negative non-zero integer
|
||||
*/
|
||||
* Returns the basic information about the converter
|
||||
*
|
||||
* The returned array must contain the following keys:
|
||||
* 'from' - the supported source format, eg. backup::FORMAT_MOODLE1
|
||||
* 'to' - the supported target format, eg. backup::FORMAT_MOODLE
|
||||
* 'cost' - the cost of the conversion, non-negative non-zero integer
|
||||
*/
|
||||
public static function description() {
|
||||
|
||||
return array(
|
||||
@@ -102,7 +102,7 @@ class imscc11_converter extends base_converter {
|
||||
throw new imscc11_convert_exception('protected_cc_not_supported');
|
||||
}
|
||||
$status = $cc112moodle->generate_moodle_xml();
|
||||
//Final cleanup
|
||||
// Final cleanup.
|
||||
$xml_error = new libxml_errors_mgr(true);
|
||||
$mdoc = new DOMDocument();
|
||||
$mdoc->preserveWhiteSpace = false;
|
||||
@@ -116,7 +116,7 @@ class imscc11_converter extends base_converter {
|
||||
$this->log('validation error(s): '.PHP_EOL.error_messages::instance(), backup::LOG_DEBUG, null, 2);
|
||||
throw new imscc11_convert_exception(error_messages::instance()->to_string(true));
|
||||
}
|
||||
//Move the files to the workdir
|
||||
// Move the files to the workdir.
|
||||
rename($manifestdir.'/course_files', $this->get_workdir_path().'/course_files');
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ class imscc11_converter extends base_converter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown by this converter
|
||||
*/
|
||||
* Exception thrown by this converter
|
||||
*/
|
||||
class imscc11_convert_exception extends convert_exception {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user