Merge branch 'MDL-33839c' of git://github.com/mkassaei/moodle

This commit is contained in:
Sam Hemelryk 2014-01-27 15:28:47 +13:00
commit 049422651c
5 changed files with 32 additions and 109 deletions

View File

@ -759,32 +759,6 @@ class question_bank_preview_action_column extends question_bank_action_column_ba
}
/**
* Question bank columns for the move action icon.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class question_bank_move_action_column extends question_bank_action_column_base {
protected $strmove;
public function init() {
parent::init();
$this->strmove = get_string('move');
}
public function get_name() {
return 'moveaction';
}
protected function display_content($question, $rowclasses) {
if (question_has_capability_on($question, 'move')) {
$this->print_icon('t/move', $this->strmove, $this->qbank->move_question_url($question->id));
}
}
}
/**
* action to delete (or hide) a question, or restore a previously hidden question.
*
@ -987,8 +961,7 @@ class question_bank_view {
protected function wanted_columns() {
$columns = array('checkbox', 'qtype', 'questionname', 'editaction', 'copyaction',
'previewaction', 'moveaction', 'deleteaction', 'creatorname',
'modifiername');
'previewaction', 'deleteaction', 'creatorname', 'modifiername');
if (question_get_display_preference('qbshowtext', 0, PARAM_BOOL, new moodle_url(''))) {
$columns[] = 'questiontext';
}
@ -1014,7 +987,6 @@ class question_bank_view {
new question_bank_edit_action_column($this),
new question_bank_copy_action_column($this),
new question_bank_preview_action_column($this),
new question_bank_move_action_column($this),
new question_bank_delete_action_column($this),
new question_bank_question_text_row($this),
);
@ -1292,10 +1264,6 @@ class question_bank_view {
return $this->editquestionurl->out(true, array('id' => $questionid, 'makecopy' => 1));
}
public function move_question_url($questionid) {
return $this->editquestionurl->out(true, array('id' => $questionid, 'movecontext' => 1));
}
public function preview_question_url($question) {
return question_preview_url($question->id, null, null, null, null,
$this->contexts->lowest());

View File

@ -116,7 +116,6 @@ abstract class question_test_helper {
$dataforformconstructor->formoptions = new stdClass();
$dataforformconstructor->formoptions->canmove = true;
$dataforformconstructor->formoptions->cansaveasnew = true;
$dataforformconstructor->formoptions->movecontext = false;
$dataforformconstructor->formoptions->canedit = true;
$dataforformconstructor->formoptions->repeatelements = true;
$qtype = question_bank::get_qtype($questiondata->qtype);

View File

@ -37,8 +37,6 @@ $categoryid = optional_param('category', 0, PARAM_INT);
$cmid = optional_param('cmid', 0, PARAM_INT);
$courseid = optional_param('courseid', 0, PARAM_INT);
$wizardnow = optional_param('wizardnow', '', PARAM_ALPHA);
$movecontext = optional_param('movecontext', 0, PARAM_BOOL); // Switch to make
// question uneditable - form is displayed to edit category only
$originalreturnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
$appendqnumstring = optional_param('appendqnumstring', '', PARAM_ALPHA);
$inpopup = optional_param('inpopup', 0, PARAM_BOOL);
@ -66,9 +64,6 @@ if ($courseid !== 0) {
if ($wizardnow !== '') {
$url->param('wizardnow', $wizardnow);
}
if ($movecontext !== 0) {
$url->param('movecontext', $movecontext);
}
if ($originalreturnurl !== 0) {
$url->param('returnurl', $originalreturnurl);
}
@ -97,10 +92,6 @@ if ($scrollpos) {
$returnurl->param('scrollpos', $scrollpos);
}
if ($movecontext && !$id){
print_error('questiondoesnotexist', 'question', $returnurl);
}
if ($cmid){
list($module, $cm) = get_module_from_cmid($cmid);
require_login($cm->course, false, $cm);
@ -162,29 +153,18 @@ $categorycontext = context::instance_by_id($category->contextid);
$addpermission = has_capability('moodle/question:add', $categorycontext);
if ($id) {
if ($movecontext){
$question->formoptions->canedit = false;
$question->formoptions->canmove = (question_has_capability_on($question, 'move') && $contexts->have_cap('moodle/question:add'));
$question->formoptions->cansaveasnew = false;
$question->formoptions->repeatelements = false;
$question->formoptions->movecontext = true;
$formeditable = true;
question_require_capability_on($question, 'move');
} else {
$question->formoptions->canedit = question_has_capability_on($question, 'edit');
$question->formoptions->canmove = $addpermission && question_has_capability_on($question, 'move');
$question->formoptions->cansaveasnew = $addpermission &&
(question_has_capability_on($question, 'view') || $question->formoptions->canedit);
$question->formoptions->repeatelements = $question->formoptions->canedit || $question->formoptions->cansaveasnew;
$formeditable = $question->formoptions->canedit || $question->formoptions->cansaveasnew || $question->formoptions->canmove;
$question->formoptions->movecontext = false;
if (!$formeditable) {
question_require_capability_on($question, 'view');
}
if ($makecopy) {
// If we are duplicating a question, add some indication to the question name.
$question->name = get_string('questionnamecopy', 'question', $question->name);
}
$question->formoptions->canedit = question_has_capability_on($question, 'edit');
$question->formoptions->canmove = $addpermission && question_has_capability_on($question, 'move');
$question->formoptions->cansaveasnew = $addpermission &&
(question_has_capability_on($question, 'view') || $question->formoptions->canedit);
$question->formoptions->repeatelements = $question->formoptions->canedit || $question->formoptions->cansaveasnew;
$formeditable = $question->formoptions->canedit || $question->formoptions->cansaveasnew || $question->formoptions->canmove;
if (!$formeditable) {
question_require_capability_on($question, 'view');
}
if ($makecopy) {
// If we are duplicating a question, add some indication to the question name.
$question->name = get_string('questionnamecopy', 'question', $question->name);
}
} else { // creating a new question
@ -192,7 +172,6 @@ if ($id) {
$question->formoptions->canmove = (question_has_capability_on($question, 'move') && $addpermission);
$question->formoptions->cansaveasnew = false;
$question->formoptions->repeatelements = true;
$question->formoptions->movecontext = false;
$formeditable = true;
require_capability('moodle/question:add', $categorycontext);
}
@ -202,7 +181,7 @@ $question->formoptions->mustbeusable = (bool) $appendqnumstring;
$PAGE->set_pagetype('question-type-' . $question->qtype);
// Create the question editing form.
if ($wizardnow !== '' && !$movecontext){
if ($wizardnow !== '') {
$mform = $qtypeobj->next_wizard_form('question.php', $question, $wizardnow, $formeditable);
} else {
$mform = $qtypeobj->create_editing_form('question.php', $question, $category, $contexts, $formeditable);
@ -216,7 +195,6 @@ if ($formeditable && $id){
$toform->appendqnumstring = $appendqnumstring;
$toform->returnurl = $originalreturnurl;
$toform->movecontext = $movecontext;
$toform->makecopy = $makecopy;
if ($cm !== null){
$toform->cmid = $cm->id;
@ -265,35 +243,27 @@ if ($mform->is_cancelled()) {
// Ensure we redirect back to the category the question is being saved into.
$returnurl->param('category', $fromform->category);
if ($movecontext) {
// We are just moving the question to a different context.
list($tocatid, $tocontextid) = explode(',', $fromform->categorymoveto);
require_capability('moodle/question:add', context::instance_by_id($tocontextid));
question_move_questions_to_category(array($question->id), $tocatid);
// We are acutally saving the question.
if (!empty($question->id)) {
question_require_capability_on($question, 'edit');
} else {
// We are acutally saving the question.
if (!empty($question->id)) {
question_require_capability_on($question, 'edit');
} else {
require_capability('moodle/question:add', context::instance_by_id($newcontextid));
if (!empty($fromform->makecopy) && !$question->formoptions->cansaveasnew) {
print_error('nopermissions', '', '', 'edit');
}
}
$question = $qtypeobj->save_question($question, $fromform);
if (!empty($CFG->usetags) && isset($fromform->tags)) {
// A wizardpage from multipe pages questiontype like calculated may not
// allow editing the question tags, hence the isset($fromform->tags) test.
require_once($CFG->dirroot.'/tag/lib.php');
tag_set('question', $question->id, $fromform->tags);
require_capability('moodle/question:add', context::instance_by_id($newcontextid));
if (!empty($fromform->makecopy) && !$question->formoptions->cansaveasnew) {
print_error('nopermissions', '', '', 'edit');
}
}
$question = $qtypeobj->save_question($question, $fromform);
if (!empty($CFG->usetags) && isset($fromform->tags)) {
// A wizardpage from multipe pages questiontype like calculated may not
// allow editing the question tags, hence the isset($fromform->tags) test.
require_once($CFG->dirroot.'/tag/lib.php');
tag_set('question', $question->id, $fromform->tags);
}
// Purge this question from the cache.
question_bank::notify_question_edited($question->id);
if (($qtypeobj->finished_edit_wizard($fromform)) || $movecontext) {
if ($qtypeobj->finished_edit_wizard($fromform)) {
if ($inpopup) {
echo $OUTPUT->notification(get_string('changessaved'), '');
close_window(3);

View File

@ -146,12 +146,6 @@ abstract class question_edit_form extends question_wizard_form {
// Editing question with no permission to move from category.
$mform->addElement('questioncategory', 'category', get_string('category', 'question'),
array('contexts' => array($this->categorycontext)));
} else if ($this->question->formoptions->movecontext) {
// Moving question to another context.
$mform->addElement('questioncategory', 'categorymoveto',
get_string('category', 'question'),
array('contexts' => $this->contexts->having_cap('moodle/question:add')));
} else {
// Editing question with permission to move from category or save as new q.
$currentgrp = array();
@ -235,9 +229,6 @@ abstract class question_edit_form extends question_wizard_form {
$this->add_hidden_fields();
$mform->addElement('hidden', 'movecontext');
$mform->setType('movecontext', PARAM_BOOL);
$mform->addElement('hidden', 'qtype');
$mform->setType('qtype', PARAM_ALPHA);
@ -246,11 +237,8 @@ abstract class question_edit_form extends question_wizard_form {
$buttonarray = array();
if (!empty($this->question->id)) {
// Editing / moving question.
if ($this->question->formoptions->movecontext) {
$buttonarray[] = $mform->createElement('submit', 'submitbutton',
get_string('moveq', 'question'));
} else if ($this->question->formoptions->canedit) {
// Editing question.
if ($this->question->formoptions->canedit) {
$buttonarray[] = $mform->createElement('submit', 'submitbutton',
get_string('savechanges'));
}
@ -264,9 +252,7 @@ abstract class question_edit_form extends question_wizard_form {
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->closeHeaderBefore('buttonar');
if ($this->question->formoptions->movecontext) {
$mform->hardFreezeAllVisibleExcept(array('categorymoveto', 'buttonar'));
} else if ((!empty($this->question->id)) && (!($this->question->formoptions->canedit ||
if ((!empty($this->question->id)) && (!($this->question->formoptions->canedit ||
$this->question->formoptions->cansaveasnew))) {
$mform->hardFreezeAllVisibleExcept(array('categorymoveto', 'buttonar', 'currentgrp'));
}

View File

@ -259,7 +259,7 @@ class question_type {
$permissionstrs[] = get_string('permissionsaveasnew', 'question');
}
}
if (!$question->formoptions->movecontext && count($permissionstrs)) {
if (count($permissionstrs)) {
echo $OUTPUT->heading(get_string('permissionto', 'question'), 3);
$html = '<ul>';
foreach ($permissionstrs as $permissionstr) {