~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to question/type/randomsamatch/backup/moodle2/restore_qtype_randomsamatch_plugin.class.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
        $paths = array();
43
43
 
44
 
        // Add own qtype stuff
 
44
        // Add own qtype stuff.
45
45
        $elename = 'randomsamatch';
46
46
        $elepath = $this->get_pathfor('/randomsamatch');
47
47
        $paths[] = new restore_path_element($elename, $elepath);
64
64
        $questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false;
65
65
 
66
66
        // If the question has been created by restore, we need to create its
67
 
        // question_randomsamatch too.
 
67
        // qtype_randomsamatch_options too.
68
68
        if ($questioncreated) {
 
69
            // Fill in some field that were added in 2.1, and so which may be missing
 
70
            // from backups made in older versions of Moodle.
 
71
            if (!isset($data->subcats)) {
 
72
                $data->subcats = 1;
 
73
            }
 
74
            if (!isset($data->correctfeedback)) {
 
75
                $data->correctfeedback = '';
 
76
                $data->correctfeedbackformat = FORMAT_HTML;
 
77
            }
 
78
            if (!isset($data->partiallycorrectfeedback)) {
 
79
                $data->partiallycorrectfeedback = '';
 
80
                $data->partiallycorrectfeedbackformat = FORMAT_HTML;
 
81
            }
 
82
            if (!isset($data->incorrectfeedback)) {
 
83
                $data->incorrectfeedback = '';
 
84
                $data->incorrectfeedbackformat = FORMAT_HTML;
 
85
            }
 
86
            if (!isset($data->shownumcorrect)) {
 
87
                $data->shownumcorrect = 0;
 
88
            }
69
89
            // Adjust some columns.
70
 
            $data->question = $newquestionid;
 
90
            $data->questionid = $newquestionid;
71
91
            // Insert record.
72
 
            $newitemid = $DB->insert_record('question_randomsamatch', $data);
 
92
            $newitemid = $DB->insert_record('qtype_randomsamatch_options', $data);
73
93
            // Create mapping.
74
 
            $this->set_mapping('question_randomsamatch', $oldid, $newitemid);
 
94
            $this->set_mapping('qtype_randomsamatch_options', $oldid, $newitemid);
75
95
        }
76
96
    }
77
97
 
82
102
     * answer is one comma separated list of hypen separated pairs
83
103
     * containing question->id and question_answers->id
84
104
     */
85
 
    public function recode_state_answer($state) {
 
105
    public function recode_legacy_state_answer($state) {
86
106
        $answer = $state->answer;
87
107
        $resultarr = array();
88
108
        foreach (explode(',', $answer) as $pair) {
95
115
        }
96
116
        return implode(',', $resultarr);
97
117
    }
 
118
 
 
119
    /**
 
120
     * Return the contents of this qtype to be processed by the links decoder.
 
121
     */
 
122
    public static function define_decode_contents() {
 
123
 
 
124
        $contents = array();
 
125
 
 
126
        $fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback');
 
127
        $contents[] = new restore_decode_content('qtype_randomsamatch_options', $fields, 'qtype_randomsamatch_options');
 
128
 
 
129
        return $contents;
 
130
    }
98
131
}