MDL-14676 "In question bank, problem with moodle/question:edit* when do not have moodle/question:move*" Fixed logic for processing submission of question form and also added some validation to check that the user has permissions to move a question.
This commit is contained in:
@@ -130,6 +130,7 @@ $string['movingquestionsnofiles']= 'Are you sure you want to move question(s) {
|
||||
$string['needtochoosecat'] = 'You need to choose a category to move this question to or press \'cancel\'.';
|
||||
$string['nocate'] = 'No such category $a!';
|
||||
$string['nopermissionadd'] = 'You don\'t have permission to add questions here.';
|
||||
$string['nopermissionmove'] = 'You don\'t have permission to move questions from here. You must save the question in this category or save it as a new question.';
|
||||
$string['noprobs'] = 'No problems found in your question database.';
|
||||
$string['notenoughdatatoeditaquestion'] = 'Neither a question id, nor a category id and question type, was specified.';
|
||||
$string['notenoughdatatomovequestions'] = 'You need to provide the question ids of questions you want to move.';
|
||||
|
||||
@@ -219,6 +219,17 @@ class question_edit_form extends moodleform {
|
||||
$mform->hardFreezeAllVisibleExcept(array('categorymoveto', 'buttonar', 'currentgrp'));
|
||||
}
|
||||
}
|
||||
|
||||
function validation($fromform, $files) {
|
||||
$errors= parent::validation($fromform, $files);
|
||||
if (empty($fromform->makecopy) && isset($this->question->id)
|
||||
&& ($this->question->formoptions->canedit || $this->question->formoptions->cansaveasnew)
|
||||
&& empty($fromform->usecurrentcat) && !$this->question->formoptions->canmove){
|
||||
$errors['currentgrp'] = get_string('nopermissionmove', 'question');
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add any question-type specific form fields.
|
||||
|
||||
@@ -306,10 +306,11 @@ class default_questiontype {
|
||||
$question->defaultgrade = $form->defaultgrade;
|
||||
}
|
||||
|
||||
if (!empty($question->id)) { // Question already exists
|
||||
if (isset($form->categorymoveto)){
|
||||
if (!empty($question->id) && !empty($form->categorymoveto)) { // Question already exists
|
||||
list($movetocategory, $movetocontextid) = explode(',', $form->categorymoveto);
|
||||
if ($movetocategory != $question->category){
|
||||
question_require_capability_on($question, 'move');
|
||||
list($question->category, $movetocontextid) = explode(',', $form->categorymoveto);
|
||||
$question->category = $movetocategory;
|
||||
//don't need to test add permission of category we are moving question to.
|
||||
//Only categories that we have permission to add
|
||||
//a question to will get through the form cleaning code for the select box.
|
||||
|
||||
@@ -71,7 +71,11 @@ class question_edit_random_form extends question_edit_form {
|
||||
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
|
||||
$mform->closeHeaderBefore('buttonar');
|
||||
}
|
||||
|
||||
function validation($fromform, $files) {
|
||||
//validation of category
|
||||
//is not relevant for this question type
|
||||
return array();
|
||||
}
|
||||
function qtype() {
|
||||
return 'random';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user