From 435d32798be4aa4d6599c9216d5beef2228028b6 Mon Sep 17 00:00:00 2001 From: M Kassaei Date: Fri, 24 Jan 2014 14:08:19 +0000 Subject: [PATCH] MDL-33839d, Remove the move icon from the question bank --- question/editlib.php | 34 +---------- question/engine/tests/helpers.php | 1 - question/question.php | 84 +++++++++------------------- question/type/edit_question_form.php | 20 +------ question/type/questiontypebase.php | 2 +- 5 files changed, 32 insertions(+), 109 deletions(-) diff --git a/question/editlib.php b/question/editlib.php index b7fc4ebe07e..3de1a6027f6 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -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()); diff --git a/question/engine/tests/helpers.php b/question/engine/tests/helpers.php index 69c02d08f33..37da365d3be 100644 --- a/question/engine/tests/helpers.php +++ b/question/engine/tests/helpers.php @@ -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); diff --git a/question/question.php b/question/question.php index e5fe3178e1e..c0927d52482 100644 --- a/question/question.php +++ b/question/question.php @@ -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); diff --git a/question/type/edit_question_form.php b/question/type/edit_question_form.php index d458e409db8..23dc402d1c4 100644 --- a/question/type/edit_question_form.php +++ b/question/type/edit_question_form.php @@ -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')); } diff --git a/question/type/questiontypebase.php b/question/type/questiontypebase.php index 73fd706e3ef..6a8ac6c64d7 100644 --- a/question/type/questiontypebase.php +++ b/question/type/questiontypebase.php @@ -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 = '