Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * This file contains the backup task for the lesson module
  20   *
  21   * @package     mod_lesson
  22   * @category    backup
  23   * @copyright   2010 Sam Hemelryk
  24   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  require_once($CFG->dirroot . '/mod/lesson/backup/moodle2/backup_lesson_stepslib.php');
  30  
  31  /**
  32   * Provides the steps to perform one complete backup of the Lesson instance
  33   *
  34   * @copyright  2010 Sam Hemelryk
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class backup_lesson_activity_task extends backup_activity_task {
  38  
  39      /**
  40       * No specific settings for this activity
  41       */
  42      protected function define_my_settings() {
  43      }
  44  
  45      /**
  46       * Defines a backup step to store the instance data in the lesson.xml file
  47       */
  48      protected function define_my_steps() {
  49          $this->add_step(new backup_lesson_activity_structure_step('lesson structure', 'lesson.xml'));
  50      }
  51  
  52      /**
  53       * Encodes URLs to various Lesson scripts
  54       *
  55       * @param string $content some HTML text that eventually contains URLs to the activity instance scripts
  56       * @return string the content with the URLs encoded
  57       */
  58      static public function encode_content_links($content) {
  59          global $CFG;
  60  
  61          $base = preg_quote($CFG->wwwroot.'/mod/lesson','#');
  62  
  63          // Provides the interface for overall authoring of lessons
  64          $pattern = '#'.$base.'/edit\.php\?id=([0-9]+)#';
  65          $replacement = '$@LESSONEDIT*$1@$';
  66          $content = preg_replace($pattern, $replacement, $content);
  67  
  68          // Action for adding a question page.  Prints an HTML form.
  69          $pattern = '#'.$base.'/editpage\.php\?id=([0-9]+)&(amp;)?pageid=([0-9]+)#';
  70          $replacement = '$@LESSONEDITPAGE*$1*$3@$';
  71          $content = preg_replace($pattern, $replacement, $content);
  72  
  73          // Provides the interface for grading essay questions
  74          $pattern = '#'.$base.'/essay\.php\?id=([0-9]+)#';
  75          $replacement = '$@LESSONESSAY*$1@$';
  76          $content = preg_replace($pattern, $replacement, $content);
  77  
  78          // Provides the interface for viewing the report
  79          $pattern = '#'.$base.'/report\.php\?id=([0-9]+)#';
  80          $replacement = '$@LESSONREPORT*$1@$';
  81          $content = preg_replace($pattern, $replacement, $content);
  82  
  83          // This file plays the mediafile set in lesson settings.
  84          $pattern = '#'.$base.'/mediafile\.php\?id=([0-9]+)#';
  85          $replacement = '$@LESSONMEDIAFILE*$1@$';
  86          $content = preg_replace($pattern, $replacement, $content);
  87  
  88          // This page lists all the instances of lesson in a particular course
  89          $pattern = '#'.$base.'/index\.php\?id=([0-9]+)#';
  90          $replacement = '$@LESSONINDEX*$1@$';
  91          $content = preg_replace($pattern, $replacement, $content);
  92  
  93          // This page prints a particular page of lesson
  94          $pattern = '#'.$base.'/view\.php\?id=([0-9]+)&(amp;)?pageid=([0-9]+)#';
  95          $replacement = '$@LESSONVIEWPAGE*$1*$3@$';
  96          $content = preg_replace($pattern, $replacement, $content);
  97  
  98          // Link to one lesson by cmid
  99          $pattern = '#'.$base.'/view\.php\?id=([0-9]+)#';
 100          $replacement = '$@LESSONVIEWBYID*$1@$';
 101          $content = preg_replace($pattern, $replacement, $content);
 102  
 103          // Return the now encoded content
 104          return $content;
 105      }
 106  }