Skip to content

Commit

Permalink
Initial commit of meta_module.xml support
Browse files Browse the repository at this point in the history
  • Loading branch information
csev committed Jan 15, 2024
1 parent e997f2f commit e8a8deb
Show file tree
Hide file tree
Showing 5 changed files with 795 additions and 14 deletions.
83 changes: 70 additions & 13 deletions src/Util/CC.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class CC extends \Tsugi\Util\TsugiDOM {
public $last_identifier = false;
public $last_identifierref = false;

public $canvas_module_meta = null;
public $canvas_modules = null;
public $canvas_items = null;

function __construct() {
parent::__construct('<?xml version="1.0" encoding="UTF-8"?>
<manifest identifier="cctd0015" xmlns="http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1" xmlns:lom="http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource" xmlns:lomimscc="http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imslticc_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticc_v1p0.xsd http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0p1.xsd">
Expand Down Expand Up @@ -92,6 +96,11 @@ function __construct() {
$this->delete_children_ns(self::CC_1_1_CP, $items);
$lom = $xpath->query(self::lom_general_xpath)->item(0);
$this->delete_children_ns(self::LOMIMSCC_NS, $lom);

// Optionally create a DOM that can be used for the
// course_settings/module_meta.xml
// Canvas extension to CC
$this->canvas_module_meta = new CanvasModuleMeta();
}

/*
Expand Down Expand Up @@ -134,21 +143,27 @@ public function set_description($desc) {
public function add_module($title) {
$this->resource_count++;
$resource_str = str_pad($this->resource_count.'',6,'0',STR_PAD_LEFT);
$identifier = 'T_'.$resource_str;
$this->last_identifier = 'T_'.$resource_str;

$xpath = new \DOMXpath($this);

$items = $xpath->query(CC::item_xpath)->item(0);
$module = $this->add_child_ns(CC::CC_1_1_CP, $items, 'item', null, array('identifier' => $identifier));
$module = $this->add_child_ns(CC::CC_1_1_CP, $items, 'item', null, array('identifier' => $this->last_identifier));
$new_title = $this->add_child_ns(CC::CC_1_1_CP, $module, 'title', $title);

if ( $this->canvas_module_meta ) {
$this->canvas_modules = $this->canvas_module_meta->add_module($title, $this->last_identifier);
$this->canvas_items = $this->canvas_module_meta->add_items($this->canvas_modules);
}

return $module;
}

/**
* Adds a sub module to a module
*
* As a note, while some LMS's are happpy with deeply nested
* sub-module trees, other LMS's prefre a strict two-layer
* sub-module trees, other LMS's prefer a strict two-layer
* module / submodule structure.
*
* @param $sub_module DOMNode The module where we are adding the submodule
Expand All @@ -159,9 +174,9 @@ public function add_module($title) {
public function add_sub_module($module, $title) {
$this->resource_count++;
$resource_str = str_pad($this->resource_count.'',6,'0',STR_PAD_LEFT);
$identifier = 'T_'.$resource_str;
$this->last_identifier = 'T_'.$resource_str;

$sub_module = $this->add_child_ns(CC::CC_1_1_CP, $module, 'item', null, array('identifier' => $identifier));
$sub_module = $this->add_child_ns(CC::CC_1_1_CP, $module, 'item', null, array('identifier' => $this->last_identifier));
$new_title = $this->add_child_ns(CC::CC_1_1_CP, $sub_module, 'title',$title);
return $sub_module;
}
Expand All @@ -182,9 +197,9 @@ public function add_web_link($module, $title=null) {
$this->resource_count++;
$resource_str = str_pad($this->resource_count.'',6,'0',STR_PAD_LEFT);
$file = 'xml/WL_'.$resource_str.'.xml';
$identifier = 'T_'.$resource_str;
$this->last_identifier = 'T_'.$resource_str;
$type = 'imswl_xmlv1p1';
$this-> add_resource_item($module, $title, $type, $identifier, $file);
$this-> add_resource_item($module, $title, $type, $this->last_identifier, $file);
return $file;
}

Expand All @@ -204,9 +219,9 @@ public function add_topic($module, $title=null) {
$this->resource_count++;
$resource_str = str_pad($this->resource_count.'',6,'0',STR_PAD_LEFT);
$file = 'xml/TO_'.$resource_str.'.xml';
$identifier = 'T_'.$resource_str;
$this->last_identifier = 'T_'.$resource_str;
$type = 'imsdt_v1p1';
$this-> add_resource_item($module, $title, $type, $identifier, $file);
$this-> add_resource_item($module, $title, $type, $this->last_identifier, $file);
return $file;
}

Expand All @@ -226,9 +241,9 @@ public function add_lti_link($module, $title=null) {
$this->resource_count++;
$resource_str = str_pad($this->resource_count.'',6,'0',STR_PAD_LEFT);
$file = 'xml/LT_'.$resource_str.'.xml';
$identifier = 'T_'.$resource_str;
$this->last_identifier = 'T_'.$resource_str;
$type = 'imsbasiclti_xmlv1p0';
$this-> add_resource_item($module, $title, $type, $identifier, $file);
$this-> add_resource_item($module, $title, $type, $this->last_identifier, $file);
return $file;
}

Expand All @@ -243,14 +258,17 @@ public function add_resource_item($module, $title, $type, $identifier, $file) {

$xpath = new \DOMXpath($this);

$new_item = $this->add_child_ns(CC::CC_1_1_CP, $module, 'item', null, array('identifier' => $this->last_identifier, "identifierref" => $this->last_identifierref));
$new_item = $this->add_child_ns(CC::CC_1_1_CP, $module, 'item', null,
array('identifier' => $this->last_identifier, "identifierref" => $this->last_identifierref));
if ( $title != null ) {
$new_title = $this->add_child_ns(CC::CC_1_1_CP, $new_item, 'title', $title);
}

$resources = $xpath->query(CC::resource_xpath)->item(0);
$new_resource = $this->add_child_ns(CC::CC_1_1_CP, $resources, 'resource', null, array('identifier' => $this->last_identifierref, "type" => $type));
$new_resource = $this->add_child_ns(CC::CC_1_1_CP, $resources, 'resource', null,
array('identifier' => $this->last_identifierref, "type" => $type));
$new_file = $this->add_child_ns(CC::CC_1_1_CP, $new_resource, 'file', null, array("href" => $file));

return $file;
}

Expand All @@ -270,6 +288,16 @@ function zip_add_url_to_module($zip, $module, $title, $url) {
$web_dom->set_title($title);
$web_dom->set_url($url, array("target" => "_iframe"));
$zip->addFromString($file,$web_dom->saveXML());

// Add to the ever-growing canvas_module_meta
if ( $this->canvas_items ) {
$w = $this->canvas_module_meta->child_tags(CanvasModuleMeta::content_type_ExternalUrl);
$w[CanvasModuleMeta::title] = $title;
$w[CanvasModuleMeta::url] = $url;
$w[CanvasModuleMeta::identifierref] = $this->last_identifierref;
$w[CanvasModuleMeta::new_tab] = CanvasModuleMeta::new_tab_true;
$item = $this->canvas_module_meta->add_item($this->canvas_items, $this->last_identifier, $w);
}
}

/*
Expand Down Expand Up @@ -297,6 +325,16 @@ function zip_add_lti_to_module($zip, $module, $title, $url, $custom=null, $exten
$lti_dom->set_extension($key,$value);
}
$zip->addFromString($file,$lti_dom->saveXML());

// Add to the ever-growing canvas_module_meta
if ( $this->canvas_items ) {
$w = $this->canvas_module_meta->child_tags(CanvasModuleMeta::content_type_ContextExternalTool);
$w[CanvasModuleMeta::title] = $title;
$w[CanvasModuleMeta::url] = $url;
$w[CanvasModuleMeta::identifierref] = $this->last_identifierref;
$w[CanvasModuleMeta::new_tab] = CanvasModuleMeta::new_tab_true;
$item = $this->canvas_module_meta->add_item($this->canvas_items, $this->last_identifier, $w);
}
}

/*
Expand Down Expand Up @@ -324,6 +362,16 @@ function zip_add_lti_outcome_to_module($zip, $module, $title, $url, $custom=null
$lti_dom->set_extension($key,$value);
}
$zip->addFromString($file,$lti_dom->saveXML());

// Add to the ever-growing canvas_module_meta
if ( $this->canvas_items ) {
$w = $this->canvas_module_meta->child_tags(CanvasModuleMeta::content_type_Assignment);
$w[CanvasModuleMeta::title] = $title;
$w[CanvasModuleMeta::url] = $url;
$w[CanvasModuleMeta::identifierref] = $this->last_identifierref;
$w[CanvasModuleMeta::new_tab] = CanvasModuleMeta::new_tab_true;
$item = $this->canvas_module_meta->add_item($this->canvas_items, $this->last_identifier, $w);
}
}

/*
Expand All @@ -342,6 +390,15 @@ function zip_add_topic_to_module($zip, $module, $title, $text) {
$web_dom->set_title($title);
$web_dom->set_text($text);
$zip->addFromString($file,$web_dom->saveXML());

// Add to the ever-growing canvas_module_meta
if ( $this->canvas_items ) {
$w = $this->canvas_module_meta->child_tags(CanvasModuleMeta::content_type_DiscussionTopic);
$w[CanvasModuleMeta::title] = $title;
$w[CanvasModuleMeta::identifierref] = $this->last_identifierref;
$w[CanvasModuleMeta::new_tab] = CanvasModuleMeta::new_tab_false;
$item = $this->canvas_module_meta->add_item($this->canvas_items, $this->last_identifier, $w);
}
}


Expand Down

0 comments on commit e8a8deb

Please sign in to comment.