| 1 | efrain | 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 | defined('MOODLE_INTERNAL') || die();
 | 
        
           |  |  | 18 |   | 
        
           |  |  | 19 | // Because it exists (must).
 | 
        
           |  |  | 20 | require_once($CFG->dirroot . '/mod/questionnaire/backup/moodle2/backup_questionnaire_stepslib.php');
 | 
        
           |  |  | 21 | // Because it exists (optional).
 | 
        
           |  |  | 22 | require_once($CFG->dirroot . '/mod/questionnaire/backup/moodle2/backup_questionnaire_settingslib.php');
 | 
        
           |  |  | 23 |   | 
        
           |  |  | 24 | /**
 | 
        
           |  |  | 25 |  * Questionnaire backup task that provides all the settings and steps to perform one complete backup of the activity.
 | 
        
           |  |  | 26 |  * @package mod_questionnaire
 | 
        
           |  |  | 27 |  * @copyright  2016 Mike Churchward (mike.churchward@poetgroup.org)
 | 
        
           |  |  | 28 |  * @author     Mike Churchward
 | 
        
           |  |  | 29 |  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 30 |  */
 | 
        
           |  |  | 31 | class backup_questionnaire_activity_task extends backup_activity_task {
 | 
        
           |  |  | 32 |   | 
        
           |  |  | 33 |     /**
 | 
        
           |  |  | 34 |      * Define (add) particular settings this activity can have
 | 
        
           |  |  | 35 |      */
 | 
        
           |  |  | 36 |     protected function define_my_settings() {
 | 
        
           |  |  | 37 |         // No particular settings for this activity.
 | 
        
           |  |  | 38 |     }
 | 
        
           |  |  | 39 |   | 
        
           |  |  | 40 |     /**
 | 
        
           |  |  | 41 |      * Define (add) particular steps this activity can have
 | 
        
           |  |  | 42 |      */
 | 
        
           |  |  | 43 |     protected function define_my_steps() {
 | 
        
           |  |  | 44 |         // Choice only has one structure step.
 | 
        
           |  |  | 45 |         $this->add_step(new backup_questionnaire_activity_structure_step('questionnaire_structure', 'questionnaire.xml'));
 | 
        
           |  |  | 46 |     }
 | 
        
           |  |  | 47 |   | 
        
           |  |  | 48 |     /**
 | 
        
           |  |  | 49 |      * Code the transformations to perform in the activity in
 | 
        
           |  |  | 50 |      * order to get transportable (encoded) links
 | 
        
           |  |  | 51 |      * @param string $content
 | 
        
           |  |  | 52 |      * @return array|string|string[]|null
 | 
        
           |  |  | 53 |      */
 | 
        
           |  |  | 54 |     public static function encode_content_links($content) {
 | 
        
           |  |  | 55 |         global $CFG;
 | 
        
           |  |  | 56 |   | 
        
           |  |  | 57 |         $base = preg_quote($CFG->wwwroot, "/");
 | 
        
           |  |  | 58 |   | 
        
           |  |  | 59 |         // Link to the list of questionnaires.
 | 
        
           |  |  | 60 |         $search = "/(".$base."\/mod\/questionnaire\/index.php\?id\=)([0-9]+)/";
 | 
        
           |  |  | 61 |         $content = preg_replace($search, '$@QUESTIONNAIREINDEX*$2@$', $content);
 | 
        
           |  |  | 62 |   | 
        
           |  |  | 63 |         // Link to questionnaire view by moduleid.
 | 
        
           |  |  | 64 |         $search = "/(".$base."\/mod\/questionnaire\/view.php\?id\=)([0-9]+)/";
 | 
        
           |  |  | 65 |         $content = preg_replace($search, '$@QUESTIONNAIREVIEWBYID*$2@$', $content);
 | 
        
           |  |  | 66 |   | 
        
           |  |  | 67 |         return $content;
 | 
        
           |  |  | 68 |     }
 | 
        
           |  |  | 69 | }
 |