Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 29... Línea 29...
29
// Read URL parameters telling us which question to edit.
29
// Read URL parameters telling us which question to edit.
30
$id = optional_param('id', 0, PARAM_INT); // Question id.
30
$id = optional_param('id', 0, PARAM_INT); // Question id.
31
$makecopy = optional_param('makecopy', 0, PARAM_BOOL);
31
$makecopy = optional_param('makecopy', 0, PARAM_BOOL);
32
$qtype = optional_param('qtype', '', PARAM_COMPONENT);
32
$qtype = optional_param('qtype', '', PARAM_COMPONENT);
33
$categoryid = optional_param('category', 0, PARAM_INT);
33
$categoryid = optional_param('category', 0, PARAM_INT);
34
$cmid = optional_param('cmid', 0, PARAM_INT);
34
$cmid = required_param('cmid', PARAM_INT);
35
$courseid = optional_param('courseid', 0, PARAM_INT);
-
 
36
$wizardnow = optional_param('wizardnow', '', PARAM_ALPHA);
35
$wizardnow = optional_param('wizardnow', '', PARAM_ALPHA);
37
$originalreturnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
36
$originalreturnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
38
$appendqnumstring = optional_param('appendqnumstring', '', PARAM_ALPHA);
37
$appendqnumstring = optional_param('appendqnumstring', '', PARAM_ALPHA);
39
$inpopup = optional_param('inpopup', 0, PARAM_BOOL);
38
$inpopup = optional_param('inpopup', 0, PARAM_BOOL);
40
$mdlscrollto = optional_param('mdlscrollto', 0, PARAM_INT);
39
$mdlscrollto = optional_param('mdlscrollto', 0, PARAM_INT);
Línea 55... Línea 54...
55
    $url->param('category', $categoryid);
54
    $url->param('category', $categoryid);
56
}
55
}
57
if ($cmid !== 0) {
56
if ($cmid !== 0) {
58
    $url->param('cmid', $cmid);
57
    $url->param('cmid', $cmid);
59
}
58
}
60
if ($courseid !== 0) {
-
 
61
    $url->param('courseid', $courseid);
-
 
62
}
-
 
63
if ($wizardnow !== '') {
59
if ($wizardnow !== '') {
64
    $url->param('wizardnow', $wizardnow);
60
    $url->param('wizardnow', $wizardnow);
65
}
61
}
66
if ($originalreturnurl !== 0) {
62
if ($originalreturnurl !== 0) {
67
    $url->param('returnurl', $originalreturnurl);
63
    $url->param('returnurl', $originalreturnurl);
Línea 75... Línea 71...
75
if ($mdlscrollto) {
71
if ($mdlscrollto) {
76
    $url->param('mdlscrollto', $mdlscrollto);
72
    $url->param('mdlscrollto', $mdlscrollto);
77
}
73
}
78
$PAGE->set_url($url);
74
$PAGE->set_url($url);
Línea 79... Línea -...
79
 
-
 
80
if ($cmid) {
75
 
81
    $questionbankurl = new moodle_url('/question/edit.php', array('cmid' => $cmid));
-
 
82
} else {
-
 
83
    $questionbankurl = new moodle_url('/question/edit.php', array('courseid' => $courseid));
76
$questionbankurl = new moodle_url('/question/edit.php', ['cmid' => $cmid]);
84
}
77
 
Línea 85... Línea 78...
85
navigation_node::override_active_url($questionbankurl);
78
navigation_node::override_active_url($questionbankurl);
86
 
79
 
87
if ($originalreturnurl) {
80
if ($originalreturnurl) {
Línea 94... Línea 87...
94
}
87
}
95
if ($mdlscrollto) {
88
if ($mdlscrollto) {
96
    $returnurl->param('mdlscrollto', $mdlscrollto);
89
    $returnurl->param('mdlscrollto', $mdlscrollto);
97
}
90
}
Línea 98... Línea -...
98
 
-
 
99
if ($cmid) {
91
 
100
    list($module, $cm) = get_module_from_cmid($cmid);
92
list($module, $cm) = get_module_from_cmid($cmid);
101
    require_login($cm->course, false, $cm);
93
require_login($cm->course, false, $cm);
102
    $thiscontext = context_module::instance($cmid);
-
 
103
} else if ($courseid) {
-
 
104
    require_login($courseid, false);
-
 
105
    $thiscontext = context_course::instance($courseid);
-
 
106
    $module = null;
-
 
107
    $cm = null;
-
 
108
} else {
-
 
109
    throw new moodle_exception('missingcourseorcmid', 'question');
94
$thiscontext = context_module::instance($cmid);
110
}
95
 
111
$contexts = new core_question\local\bank\question_edit_contexts($thiscontext);
96
$contexts = new core_question\local\bank\question_edit_contexts($thiscontext);
Línea 112... Línea 97...
112
$PAGE->set_pagelayout('admin');
97
$PAGE->set_pagelayout('admin');
113
 
98
 
Línea 117... Línea 102...
117
 
102
 
118
if ($id) {
103
if ($id) {
119
    if (!$question = $DB->get_record('question', array('id' => $id))) {
104
    if (!$question = $DB->get_record('question', array('id' => $id))) {
120
        throw new moodle_exception('questiondoesnotexist', 'question', $returnurl);
105
        throw new moodle_exception('questiondoesnotexist', 'question', $returnurl);
121
    }
-
 
122
    // We can use $COURSE here because it's been initialised as part of the
-
 
123
    // require_login above. Passing it as the third parameter tells the function
-
 
124
    // to filter the course tags by that course.
106
    }
Línea 125... Línea 107...
125
    get_question_options($question, true, [$COURSE]);
107
    get_question_options($question, true);
126
 
108
 
127
} else if ($categoryid && $qtype) { // Only for creating new questions.
109
} else if ($categoryid && $qtype) { // Only for creating new questions.
128
    $question = new stdClass();
110
    $question = new stdClass();
Línea 144... Línea 126...
144
 
126
 
145
} else {
127
} else {
146
    throw new moodle_exception('notenoughdatatoeditaquestion', 'question', $returnurl);
128
    throw new moodle_exception('notenoughdatatoeditaquestion', 'question', $returnurl);
Línea -... Línea 129...
-
 
129
}
-
 
130
 
-
 
131
// If we get to the editing page from somewhere outside the question bank (such as the quiz) while migration is still
-
 
132
// pending, redirect back with a warning.
-
 
133
if (!\core_question\local\bank\question_bank_helper::has_bank_migration_task_completed_successfully()) {
-
 
134
    $defaultactivityname = \core_question\local\bank\question_bank_helper::get_default_question_bank_activity_name();
-
 
135
    redirect(
-
 
136
        $returnurl,
-
 
137
        get_string('transfernotfinished', 'mod_' . $defaultactivityname),
-
 
138
        messagetype: \core\output\notification::NOTIFY_WARNING,
-
 
139
    );
147
}
140
}
Línea 148... Línea 141...
148
 
141
 
149
$qtypeobj = question_bank::get_qtype($question->qtype);
142
$qtypeobj = question_bank::get_qtype($question->qtype);
150
 
143
 
Línea 285... Línea 278...
285
        if (!empty($fromform->makecopy) && !$question->formoptions->cansaveasnew) {
278
        if (!empty($fromform->makecopy) && !$question->formoptions->cansaveasnew) {
286
            throw new moodle_exception('nopermissions', '', '', 'edit');
279
            throw new moodle_exception('nopermissions', '', '', 'edit');
287
        }
280
        }
288
    }
281
    }
Línea 289... Línea 282...
289
 
282
 
290
    // If this is a new question, save defaults for user in user_preferences table.
283
    // If this is a new question and question defaults save is enabled, save defaults for user in user_preferences table.
291
    if (empty($question->id)) {
284
    if (empty($question->id) && !empty($CFG->questiondefaultssave)) {
292
        $qtypeobj->save_defaults_for_new_questions($fromform);
285
        $qtypeobj->save_defaults_for_new_questions($fromform);
293
    }
286
    }
294
    $question = $qtypeobj->save_question($question, $fromform);
287
    $question = $qtypeobj->save_question($question, $fromform);
295
    if (isset($fromform->tags)) {
288
    if (isset($fromform->tags)) {
Línea 326... Línea 319...
326
            if ($appendqnumstring) {
319
            if ($appendqnumstring) {
327
                $returnurl->param($appendqnumstring, $question->id);
320
                $returnurl->param($appendqnumstring, $question->id);
328
                $returnurl->param('sesskey', sesskey());
321
                $returnurl->param('sesskey', sesskey());
329
                $returnurl->param('cmid', $cmid);
322
                $returnurl->param('cmid', $cmid);
330
            }
323
            }
-
 
324
            // Update the filter param to the updated category if the return have any.
-
 
325
            if (!empty($returnurl->param('filter'))) {
-
 
326
                $filter = json_decode($returnurl->param('filter'), true);
-
 
327
                if (isset($filter['category']['values'])) {
-
 
328
                    $filter['category']['values'][0] = $question->category;
-
 
329
                    $returnurl->param('filter', json_encode($filter));
-
 
330
                }
-
 
331
            }
331
            redirect($returnurl);
332
            redirect($returnurl);
332
        }
333
        }
Línea 333... Línea 334...
333
 
334
 
334
    } else {
335
    } else {
Línea 347... Línea 348...
347
        if ($cmid) {
348
        if ($cmid) {
348
            $nexturl->param('cmid', $cmid);
349
            $nexturl->param('cmid', $cmid);
349
        } else {
350
        } else {
350
            $nexturl->param('courseid', $COURSE->id);
351
            $nexturl->param('courseid', $COURSE->id);
351
        }
352
        }
-
 
353
        // Update the filter param to the updated category if the return url have any.
-
 
354
        if (!empty($nexturl->param('filter'))) {
-
 
355
            $filter = json_decode($nexturl->param('filter'), true);
-
 
356
            if (isset($filter['category']['values'])) {
-
 
357
                $filter['category']['values'][0] = $question->category;
-
 
358
                $nexturl->param('filter', json_encode($filter));
-
 
359
            }
-
 
360
        }
352
        redirect($nexturl);
361
        redirect($nexturl);
353
    }
362
    }
Línea 354... Línea 363...
354
 
363