Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
/**
18
 * Defines backup_quiz_activity_task class
19
 *
20
 * @package     mod_quiz
21
 * @category    backup
22
 * @copyright   2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
23
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
defined('MOODLE_INTERNAL') || die();
27
 
28
require_once($CFG->dirroot . '/mod/quiz/backup/moodle2/backup_quiz_stepslib.php');
29
 
30
/**
31
 * Provides the steps to perform one complete backup of the Quiz instance
32
 *
33
 * @copyright  2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class backup_quiz_activity_task extends backup_activity_task {
37
 
38
    /**
39
     * No specific settings for this activity
40
     */
41
    protected function define_my_settings() {
42
    }
43
 
44
    /**
45
     * Defines backup steps to store the instance data and required questions
46
     */
47
    protected function define_my_steps() {
48
        // Generate the quiz.xml file containing all the quiz information
49
        // and annotating used questions.
50
        $this->add_step(new backup_quiz_activity_structure_step('quiz_structure', 'quiz.xml'));
51
 
52
        // Note: Following  steps must be present
53
        // in all the activities using question banks (only quiz for now)
54
        // TODO: Specialise these step to a new subclass of backup_activity_task.
55
 
56
        // Process all the annotated questions to calculate the question
57
        // categories needing to be included in backup for this activity
58
        // plus the categories belonging to the activity context itself.
59
        $this->add_step(new backup_calculate_question_categories('activity_question_categories'));
60
 
61
        // Clean backup_temp_ids table from questions. We already
62
        // have used them to detect question_categories and aren't
63
        // needed anymore.
64
        $this->add_step(new backup_delete_temp_questions('clean_temp_questions'));
65
    }
66
 
67
    /**
68
     * Encodes URLs to the index.php and view.php scripts
69
     *
70
     * @param string $content some HTML text that eventually contains URLs to the activity instance scripts
71
     * @return string the content with the URLs encoded
72
     */
73
    public static function encode_content_links($content) {
74
        global $CFG;
75
 
76
        $base = preg_quote($CFG->wwwroot, '/');
77
 
78
        // Link to the list of quizzes.
79
        $search="/(".$base."\/mod\/quiz\/index.php\?id\=)([0-9]+)/";
80
        $content= preg_replace($search, '$@QUIZINDEX*$2@$', $content);
81
 
82
        // Link to quiz view by moduleid.
83
        $search="/(".$base."\/mod\/quiz\/view.php\?id\=)([0-9]+)/";
84
        $content= preg_replace($search, '$@QUIZVIEWBYID*$2@$', $content);
85
 
86
        // Link to quiz view by quizid.
87
        $search="/(".$base."\/mod\/quiz\/view.php\?q\=)([0-9]+)/";
88
        $content= preg_replace($search, '$@QUIZVIEWBYQ*$2@$', $content);
89
 
90
        return $content;
91
    }
92
}