Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * @package    backup-convert
  19   * @subpackage cc-library
  20   * @copyright  2011 Darko Miletic <dmiletic@moodlerooms.com>
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  require_once ('cc_version1.php');
  25  
  26  /**
  27   * Version 1.1 class of Common Cartridge
  28   *
  29   */
  30  class cc_version11 extends cc_version1 {
  31      const webcontent         = 'webcontent';
  32      const questionbank       = 'imsqti_xmlv1p2/imscc_xmlv1p1/question-bank';
  33      const assessment         = 'imsqti_xmlv1p2/imscc_xmlv1p1/assessment';
  34      const associatedcontent  = 'associatedcontent/imscc_xmlv1p1/learning-application-resource';
  35      const discussiontopic    = 'imsdt_xmlv1p1';
  36      const weblink            = 'imswl_xmlv1p1';
  37      const basiclti           = 'imsbasiclti_xmlv1p0';
  38  
  39      public static $checker = array(self::webcontent,
  40                                     self::assessment,
  41                                     self::associatedcontent,
  42                                     self::discussiontopic,
  43                                     self::questionbank,
  44                                     self::weblink,
  45                                     self::basiclti);
  46  
  47      /**
  48       * Validate if the type are valid or not
  49       *
  50       * @param string $type
  51       * @return bool
  52       */
  53      public function valid($type) {
  54          return in_array($type, self::$checker);
  55      }
  56  
  57      public function __construct() {
  58          $this->ccnamespaces = array('imscc'    => 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1',
  59                                      'lomimscc' => 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest'  ,
  60                                      'lom'      => 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource'  ,
  61                                      'xsi'      => 'http://www.w3.org/2001/XMLSchema-instance'
  62                                     );
  63  
  64          $this->ccnsnames    = array('imscc'    => 'http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd'     ,
  65                                      'lomimscc' => 'http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd',
  66                                      'lom'      => 'http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd'
  67                                     );
  68  
  69          $this->ccversion    = '1.1.0';
  70          $this->camversion   = '1.1.0';
  71          $this->_generator   = 'Moodle 2 Common Cartridge generator';
  72      }
  73  
  74      protected function update_items($items, DOMDocument &$doc, DOMElement &$xmlnode) {
  75          foreach ($items as $key => $item) {
  76              $itemnode = $doc->createElementNS($this->ccnamespaces['imscc'], 'item');
  77              $this->update_attribute($doc, 'identifier'   , $key                , $itemnode);
  78              $this->update_attribute($doc, 'identifierref', $item->identifierref, $itemnode);
  79              if (!is_null($item->title)) {
  80                  $titlenode = $doc->createElementNS($this->ccnamespaces['imscc'], 'title');
  81                  $titlenode->appendChild(new DOMText($item->title));
  82                  $itemnode->appendChild($titlenode);
  83              }
  84              if ($item->has_child_items()) {
  85                  $this->update_items($item->childitems, $doc, $itemnode);
  86              }
  87              $xmlnode->appendChild($itemnode);
  88          }
  89      }
  90  
  91      /**
  92       * Create Education Metadata (How To)
  93       *
  94       * @param object $met
  95       * @param DOMDocument $doc
  96       * @param object $xmlnode
  97       * @return DOMNode
  98       */
  99      public function create_metadata_educational($met, DOMDocument  &$doc, $xmlnode) {
 100          $metadata = $doc->createElementNS($this->ccnamespaces['imscc'], 'metadata');
 101          $xmlnode->insertBefore($metadata, $xmlnode->firstChild);
 102          $lom = $doc->createElementNS($this->ccnamespaces['lom'], 'lom');
 103          $metadata->appendChild($lom);
 104          $educational = $doc->createElementNS($this->ccnamespaces['lom'], 'educational');
 105          $lom->appendChild($educational);
 106  
 107          foreach ($met->arrayeducational as $value) {
 108              !is_array($value) ? $value = array($value) : null;
 109              foreach ($value as $v) {
 110                  $userrole = $doc->createElementNS($this->ccnamespaces['lom'], 'intendedEndUserRole');
 111                  $educational->appendChild($userrole);
 112                  $nd4 = $doc->createElementNS($this->ccnamespaces['lom'], 'source', 'IMSGLC_CC_Rolesv1p1');
 113                  $nd5 = $doc->createElementNS($this->ccnamespaces['lom'], 'value', $v[0]);
 114                  $userrole->appendChild($nd4);
 115                  $userrole->appendChild($nd5);
 116              }
 117          }
 118          return $metadata;
 119      }
 120  }