first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,94 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Shows a screen where the user can choose a question type, before being redirected to question.php
*
* @package qbank_editquestion
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../../config.php');
require_once(__DIR__ . '/../../editlib.php');
use qbank_editquestion\editquestion_helper;
// Read URL parameters.
$categoryid = required_param('category', PARAM_INT);
$cmid = optional_param('cmid', 0, PARAM_INT);
$courseid = optional_param('courseid', 0, PARAM_INT);
$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
$appendqnumstring = optional_param('appendqnumstring', '', PARAM_ALPHA);
$validationerror = optional_param('validationerror', false, PARAM_BOOL);
\core_question\local\bank\helper::require_plugin_enabled('qbank_editquestion');
// Place to accumulate hidden params for the form we will print.
$hiddenparams = array('category' => $categoryid);
// Validate params.
if (!$category = $DB->get_record('question_categories', array('id' => $categoryid))) {
throw new moodle_exception('categorydoesnotexist', 'question', $returnurl);
}
if ($cmid) {
list($module, $cm) = get_module_from_cmid($cmid);
require_login($cm->course, false, $cm);
$thiscontext = context_module::instance($cmid);
$hiddenparams['cmid'] = $cmid;
} else if ($courseid) {
require_login($courseid, false);
$thiscontext = context_course::instance($courseid);
$module = null;
$cm = null;
$hiddenparams['courseid'] = $courseid;
} else {
throw new moodle_exception('missingcourseorcmid', 'question');
}
// Check permissions.
$categorycontext = context::instance_by_id($category->contextid);
require_capability('moodle/question:add', $categorycontext);
// Ensure other optional params get passed on to question.php.
if (!empty($returnurl)) {
$hiddenparams['returnurl'] = $returnurl;
}
if (!empty($appendqnumstring)) {
$hiddenparams['appendqnumstring'] = $appendqnumstring;
}
$PAGE->set_url('/question/bank/editquestion/addquestion.php', $hiddenparams);
if ($cmid) {
$questionbankurl = new moodle_url('/question/edit.php', array('cmid' => $cmid));
} else {
$questionbankurl = new moodle_url('/question/edit.php', array('courseid' => $courseid));
}
navigation_node::override_active_url($questionbankurl);
$chooseqtype = get_string('chooseqtypetoadd', 'question');
$PAGE->set_heading($COURSE->fullname);
$PAGE->navbar->add($chooseqtype);
$PAGE->set_title($chooseqtype);
// Display a form to choose the question type.
echo $OUTPUT->header();
echo $OUTPUT->notification(get_string('youmustselectaqtype', 'question'));
echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox');
echo editquestion_helper::print_choose_qtype_to_add_form($hiddenparams, null, false);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
@@ -0,0 +1,11 @@
define("qbank_editquestion/question_status",["exports","core/ajax","core/notification"],(function(_exports,_ajax,_notification){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
/**
* Status column selector js.
*
* @module qbank_editquestion/question_status
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_ajax=_interopRequireDefault(_ajax),_notification=_interopRequireDefault(_notification);_exports.init=questionId=>{document.querySelector("#question_status_dropdown-"+questionId).addEventListener("change",(e=>{const questionStatus=e.target.value;((questionId,status)=>_ajax.default.call([{methodname:"qbank_editquestion_set_status",args:{questionid:questionId,status:status}}])[0])(questionId,questionStatus).then((response=>{response.error&&_notification.default.addNotification({type:"error",message:response.error})})).catch()}))}}));
//# sourceMappingURL=question_status.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"question_status.min.js","sources":["../src/question_status.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Status column selector js.\n *\n * @module qbank_editquestion/question_status\n * @copyright 2021 Catalyst IT Australia Pty Ltd\n * @author Safat Shahin <safatshahin@catalyst-au.net>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\nimport Notification from 'core/notification';\n\n/**\n * Set the question status.\n *\n * @param {Number} questionId The question id.\n * @param {String} status The updated question status.\n * @return {Array} The modified question status\n */\nconst setQuestionStatus = (questionId, status) => Ajax.call([{\n methodname: 'qbank_editquestion_set_status',\n args: {\n questionid: questionId,\n status: status\n }\n}])[0];\n\n/**\n * Entrypoint of the js.\n *\n * @method init\n * @param {Number} questionId Question id.\n */\nexport const init = (questionId) => {\n let target = document.querySelector('#question_status_dropdown-' + questionId);\n target.addEventListener('change', (e) => {\n const questionStatus = e.target.value;\n setQuestionStatus(questionId, questionStatus)\n .then((response) => {\n if (response.error) {\n Notification.addNotification({\n type: 'error',\n message: response.error\n });\n }\n return;\n }).catch();\n });\n};\n"],"names":["questionId","document","querySelector","addEventListener","e","questionStatus","target","value","status","Ajax","call","methodname","args","questionid","setQuestionStatus","then","response","error","addNotification","type","message","catch"],"mappings":";;;;;;;;wLAgDqBA,aACJC,SAASC,cAAc,6BAA+BF,YAC5DG,iBAAiB,UAAWC,UACzBC,eAAiBD,EAAEE,OAAOC,MAjBd,EAACP,WAAYQ,SAAWC,cAAKC,KAAK,CAAC,CACzDC,WAAY,gCACZC,KAAM,CACFC,WAAYb,WACZQ,OAAQA,WAEZ,GAYIM,CAAkBd,WAAYK,gBAC7BU,MAAMC,WACCA,SAASC,6BACIC,gBAAgB,CACzBC,KAAM,QACNC,QAASJ,SAASC,WAI3BI"}
@@ -0,0 +1,64 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Status column selector js.
*
* @module qbank_editquestion/question_status
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import Ajax from 'core/ajax';
import Notification from 'core/notification';
/**
* Set the question status.
*
* @param {Number} questionId The question id.
* @param {String} status The updated question status.
* @return {Array} The modified question status
*/
const setQuestionStatus = (questionId, status) => Ajax.call([{
methodname: 'qbank_editquestion_set_status',
args: {
questionid: questionId,
status: status
}
}])[0];
/**
* Entrypoint of the js.
*
* @method init
* @param {Number} questionId Question id.
*/
export const init = (questionId) => {
let target = document.querySelector('#question_status_dropdown-' + questionId);
target.addEventListener('change', (e) => {
const questionStatus = e.target.value;
setQuestionStatus(questionId, questionStatus)
.then((response) => {
if (response.error) {
Notification.addNotification({
type: 'error',
message: response.error
});
}
return;
}).catch();
});
};
@@ -0,0 +1,91 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Question bank column for the duplicate action icon.
*
* @package qbank_editquestion
* @copyright 2013 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qbank_editquestion;
use core_question\local\bank\question_action_base;
use moodle_url;
/**
* Question bank column for the duplicate action icon.
*
* @copyright 2013 The Open University
* @author 2021 Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class copy_action extends question_action_base {
/** @var string avoids repeated calls to get_string('duplicate'). */
protected $strcopy;
/**
* Contains the url of the edit question page.
* @var moodle_url|string
*/
public $duplicatequestionurl;
public function init(): void {
parent::init();
$this->strcopy = get_string('duplicate');
$this->duplicatequestionurl = new \moodle_url('/question/bank/editquestion/question.php',
array('returnurl' => $this->qbank->returnurl));
if ($this->qbank->cm !== null) {
$this->duplicatequestionurl->param('cmid', $this->qbank->cm->id);
} else {
$this->duplicatequestionurl->param('courseid', $this->qbank->course->id);
}
}
public function get_menu_position(): int {
return 250;
}
/**
* Get the URL for duplicating a question as a moodle_url.
*
* @param int $questionid the question id.
* @return \moodle_url the URL.
*/
public function duplicate_question_moodle_url($questionid): moodle_url {
return new \moodle_url($this->duplicatequestionurl, ['id' => $questionid, 'makecopy' => 1]);
}
protected function get_url_icon_and_label(\stdClass $question): array {
if (!\question_bank::is_qtype_installed($question->qtype)) {
// It sometimes happens that people end up with junk questions
// in their question bank of a type that is no longer installed.
// We cannot do most actions on them, because that leads to errors.
return [null, null, null];
}
// To copy a question, you need permission to add a question in the same
// category as the existing question, and ability to access the details of
// the question being copied.
if (question_has_capability_on($question, 'add') &&
(question_has_capability_on($question, 'edit') || question_has_capability_on($question, 'view'))) {
return [$this->duplicate_question_moodle_url($question->id), 't/copy', $this->strcopy];
}
return [null, null, null];
}
}
@@ -0,0 +1,100 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class for question bank edit question column.
*
* @package qbank_editquestion
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qbank_editquestion;
use core_question\local\bank\question_action_base;
use moodle_url;
/**
* Class for question bank edit question column.
*
* @copyright 2009 Tim Hunt
* @author 2021 Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit_action extends question_action_base {
/**
* Contains the string.
* @var string
*/
protected $stredit;
/**
* Contains the string.
* @var string
*/
protected $strview;
/**
* Contains the url of the edit question page.
* @var moodle_url|string
*/
public $editquestionurl;
public function init(): void {
parent::init();
$this->stredit = get_string('editquestion', 'question');
$this->strview = get_string('view');
$this->editquestionurl = new \moodle_url('/question/bank/editquestion/question.php',
array('returnurl' => $this->qbank->returnurl));
if ($this->qbank->cm !== null) {
$this->editquestionurl->param('cmid', $this->qbank->cm->id);
} else {
$this->editquestionurl->param('courseid', $this->qbank->course->id);
}
}
public function get_menu_position(): int {
return 200;
}
/**
* Get the URL for editing a question as a link.
*
* @param int $questionid the question id.
* @return moodle_url the URL, HTML-escaped.
*/
public function edit_question_moodle_url($questionid): moodle_url {
return new moodle_url($this->editquestionurl, ['id' => $questionid]);
}
protected function get_url_icon_and_label(\stdClass $question): array {
if (!\question_bank::is_qtype_installed($question->qtype)) {
// It sometimes happens that people end up with junk questions
// in their question bank of a type that is no longer installed.
// We cannot do most actions on them, because that leads to errors.
return [null, null, null];
}
if (question_has_capability_on($question, 'edit')) {
return [$this->edit_question_moodle_url($question->id), 't/edit', $this->stredit];
} else if (question_has_capability_on($question, 'view')) {
return [$this->edit_question_moodle_url($question->id), 'i/info', $this->strview];
} else {
return [null, null, null];
}
}
}
@@ -0,0 +1,104 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Helper class for adding/editing a question.
*
* This code is based on question/editlib.php by Martin Dougiamas.
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qbank_editquestion;
use core_question\local\bank\question_version_status;
use qbank_editquestion\output\add_new_question;
/**
* Class editquestion_helper for methods related to add/edit/copy
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
*/
class editquestion_helper {
/**
* Print a form to let the user choose which question type to add.
* When the form is submitted, it goes to the question.php script.
*
* @param array|null $hiddenparams hidden parameters to add to the form, in addition to
* the qtype radio buttons.
* @param array|null $allowedqtypes optional list of qtypes that are allowed. If given, only
* those qtypes will be shown. Example value array('description', 'multichoice').
* @param bool $enablejs
* @return bool|string
*/
public static function print_choose_qtype_to_add_form(array $hiddenparams, array $allowedqtypes = null, $enablejs = true) {
global $PAGE;
$chooser = \qbank_editquestion\qbank_chooser::get($PAGE->course, $hiddenparams, $allowedqtypes);
$renderer = $PAGE->get_renderer('qbank_editquestion');
return $renderer->render($chooser);
}
/**
* Print a button for creating a new question. This will open question/addquestion.php,
* which in turn goes to question/question.php before getting back to $params['returnurl']
* (by default the question bank screen).
*
* @param int $categoryid The id of the category that the new question should be added to.
* @param array $params Other paramters to add to the URL. You need either $params['cmid'] or
* $params['courseid'], and you should probably set $params['returnurl']
* @param bool $canadd the text to display on the button.
* @param string $tooltip a tooltip to add to the button (optional).
* @param bool $disabled if true, the button will be disabled.
* @deprecated since Moodle 4.3. Use {@see add_new_question} renderable instead
* @todo Final deprecation in Moodle 4.7
*/
public static function create_new_question_button($categoryid, $params, $canadd, $tooltip = '', $disabled = false) {
global $OUTPUT;
debugging('create_new_question_button() is deprecated. Use the add_new_question renderable instead.');
return $OUTPUT->render(new add_new_question($categoryid, $params, $canadd));
}
/**
* Get the string for the status of the question.
*
* @param string $status
* @return string
*/
public static function get_question_status_string($status): string {
return get_string('questionstatus' . $status, 'qbank_editquestion');
}
/**
* Get the array of status of the questions.
*
* @return array
*/
public static function get_question_status_list(): array {
$statuslist = [];
$statuslist[question_version_status::QUESTION_STATUS_READY] = get_string('questionstatusready', 'qbank_editquestion');
$statuslist[question_version_status::QUESTION_STATUS_DRAFT] = get_string('questionstatusdraft', 'qbank_editquestion');
return $statuslist;
}
}
@@ -0,0 +1,114 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace qbank_editquestion\external;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/question/engine/bank.php');
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use qbank_editquestion\editquestion_helper;
use question_bank;
/**
* Update question status external api.
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class update_question_version_status extends external_api {
/**
* Returns description of method parameters.
*
* @return external_function_parameters.
*/
public static function execute_parameters() {
return new external_function_parameters([
'questionid' => new external_value(PARAM_INT, 'The question id'),
'status' => new external_value(PARAM_TEXT, 'The updated question status')
]);
}
/**
* Handles the status form submission.
*
* @param int $questionid The question id.
* @param string $status The updated question status.
* @return array The created or modified question tag
*/
public static function execute($questionid, $status) {
global $DB;
$result = [
'status' => false,
'statusname' => '',
'error' => ''
];
// Parameter validation.
$params = self::validate_parameters(self::execute_parameters(), [
'questionid' => $questionid,
'status' => $status
]);
$statuslist = editquestion_helper::get_question_status_list();
$statusexists = array_key_exists($status, $statuslist);
if (!$statusexists) {
return [
'status' => false,
'statusname' => '',
'error' => get_string('unrecognizedstatus', 'qbank_editquestion')
];
}
$question = question_bank::load_question($params['questionid']);
$editingcontext = \context::instance_by_id($question->contextid);
self::validate_context($editingcontext);
$canedit = question_has_capability_on($question, 'edit');
if ($canedit) {
$versionrecord = $DB->get_record('question_versions', ['questionid' => $params['questionid']]);
$versionrecord->status = $params['status'];
$DB->update_record('question_versions', $versionrecord);
question_bank::notify_question_edited($question->id);
$result = [
'status' => true,
'statusname' => editquestion_helper::get_question_status_string($versionrecord->status),
'error' => ''
];
$event = \core\event\question_updated::create_from_question_instance($question, $editingcontext);
$event->trigger();
}
return $result;
}
/**
* Returns description of method result value.
*/
public static function execute_returns() {
return new external_single_structure([
'status' => new external_value(PARAM_BOOL, 'status: true if success'),
'statusname' => new external_value(PARAM_RAW, 'statusname: name of the status'),
'error' => new external_value(PARAM_TEXT, 'Error message if error exists')
]);
}
}
@@ -0,0 +1,69 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace qbank_editquestion\output;
use qbank_editquestion\editquestion_helper;
use renderer_base;
/**
* Create new question button
*
* @package qbank_editquestion
* @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net}
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class add_new_question implements \renderable, \templatable {
/** @var int $categoryid The ID of the category the quesiton will be added to. */
protected int $categoryid;
/** @var array $params URL parameters to pass to the add question form. */
protected array $params;
/** @var bool $canadd True if the add question button should be displayed. If false, a placeholder will be shown.*/
protected bool $canadd;
/**
* Store data for building the template context.
*
* @param int $categoryid
* @param array $params
* @param bool $canadd
*/
public function __construct(int $categoryid, array $params, bool $canadd) {
$this->categoryid = $categoryid;
$this->params = $params;
$this->canadd = $canadd;
}
public function export_for_template(renderer_base $output): array {
$addquestiondisplay = [];
$addquestiondisplay['canadd'] = $this->canadd;
if ($this->canadd) {
$this->params['category'] = $this->categoryid;
$url = new \moodle_url('/question/bank/editquestion/addquestion.php', $this->params);
$addquestiondisplay['buttonhtml'] = $output->single_button(
$url,
get_string('createnewquestion', 'question'),
'get',
['disabled' => 'disabled'],
);
$addquestiondisplay['qtypeform'] = editquestion_helper::print_choose_qtype_to_add_form([]);
}
return $addquestiondisplay;
}
}
@@ -0,0 +1,83 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Renderer for adding/editing a question.
*
* This code is based on question/renderer.php by The Open University.
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qbank_editquestion\output;
/**
* Renderer for add/edit/copy
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends \plugin_renderer_base {
/**
* Render a qbank_chooser.
*
* @param \renderable $qbankchooser The chooser.
* @return string
*/
public function render_qbank_chooser(\renderable $qbankchooser) {
return $this->render_from_template('qbank_editquestion/qbank_chooser', $qbankchooser->export_for_template($this));
}
/**
* Render add question button.
*
* @param array $addquestiondata
* @return bool|string
* @deprecated since Moodle 4.3. Use {@see add_new_question} renderable instead
* @todo Final deprecation in Moodle 4.7
*/
public function render_create_new_question_button($addquestiondata) {
debugging('render_create_new_question_button() is deprecated. '
. 'Pass the add_new_question renderable to render() instead.');
return $this->render_from_template('qbank_editquestion/add_new_question', $addquestiondata);
}
/**
* Render question information for edit form.
*
* @param array $questiondata
* @return bool|string
*/
public function render_question_info($questiondata) {
return $this->render_from_template('qbank_editquestion/question_info', $questiondata);
}
/**
* Render status dropdown.
*
* @param array $dropdownoptions
* @return bool|string
*/
public function render_status_dropdown($dropdownoptions) {
return $this->render_from_template('qbank_editquestion/question_status_dropdown', $dropdownoptions);
}
}
@@ -0,0 +1,74 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Plugin entrypoint for columns.
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qbank_editquestion;
use core\context;
use core_question\local\bank\view;
use qbank_editquestion\output\add_new_question;
/**
* Class columns is the entrypoint for the columns.
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class plugin_feature extends \core_question\local\bank\plugin_features_base {
public function get_question_columns($qbank): array {
return [
new question_status_column($qbank),
];
}
public function get_question_actions(view $qbank): array {
return [
new edit_action($qbank),
new copy_action($qbank),
];
}
/**
* Return "Add new question" control.
*
* @param view $qbank The question bank view.
* @param context $context The current context, for permission checks.
* @param int $categoryid The current question category ID.
* @return \renderable[]
*/
public function get_question_bank_controls(view $qbank, context $context, int $categoryid): array {
if (!$qbank->allow_add_questions()) {
return [];
}
$canadd = has_capability('moodle/question:add', $context);
$urlparams = (new edit_action($qbank))->editquestionurl->params();
return [
100 => new add_new_question($categoryid, $urlparams, $canadd),
];
}
}
@@ -0,0 +1,40 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version information for qbank_editquestion.
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qbank_editquestion\privacy;
/**
* Privacy Subsystem for qbank_editquestion implementing null_provider.
*
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
@@ -0,0 +1,105 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The qbank_chooser renderable.
*
* @package qbank_editquestion
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qbank_editquestion;
use context;
use context_course;
use core\output\chooser_section;
use lang_string;
use moodle_url;
use question_bank;
use stdClass;
/**
* The qbank_chooser renderable class.
*
* @package qbank_editquestion
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qbank_chooser extends \core\output\chooser {
/**
* Constructor.
*
* @param array $real The real question types.
* @param array $fake The fake question types.
* @param stdClass $course The course.
* @param array $hiddenparams Hidden parameters.
* @param context $context The relevant context.
*/
public function __construct($real, $fake, $course, $hiddenparams, $context) {
$sections = [];
$sections[] = new chooser_section('questions', new lang_string('questions', 'question'),
array_map(function($qtype) use ($context) {
return new qbank_chooser_item($qtype, $context);
}, $real));
if (!empty($fake)) {
$sections[] = new chooser_section('other', new lang_string('other'),
array_map(function ($qtype) use ($context) {
return new qbank_chooser_item($qtype, $context);
}, $fake));
}
parent::__construct(new moodle_url('/question/bank/editquestion/question.php'),
new lang_string('chooseqtypetoadd', 'question'), $sections, 'qtype');
$this->set_instructions(new lang_string('selectaqtypefordescription', 'question'));
$this->set_method('get');
$this->add_param('courseid', $course->id);
foreach ($hiddenparams as $k => $v) {
$this->add_param($k, $v);
}
}
/**
* Get an instance of the question bank chooser.
*
* @param stdClass $course The course.
* @param array $hiddenparams Hidden parameters.
* @param array|null $allowedqtypes Allowed question types.
* @return qbank_chooser
*/
public static function get($course, $hiddenparams, array $allowedqtypes = null): qbank_chooser {
$realqtypes = array();
$fakeqtypes = array();
foreach (question_bank::get_creatable_qtypes() as $qtypename => $qtype) {
if ($allowedqtypes && !in_array($qtypename, $allowedqtypes)) {
continue;
}
if ($qtype->is_real_question_type()) {
$realqtypes[] = $qtype;
} else {
$fakeqtypes[] = $qtype;
}
}
return new static($realqtypes, $fakeqtypes, $course, $hiddenparams, context_course::instance($course->id));
}
}
@@ -0,0 +1,55 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The qbank_chooser_item renderable.
*
* @package qbank_editquestion
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qbank_editquestion;
use context;
use lang_string;
use pix_icon;
/**
* The qbank_chooser_item renderable class.
*
* @package qbank_editquestion
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qbank_chooser_item extends \core\output\chooser_item {
/**
* Constructor.
*
* @param object $qtype The question type.
* @param context $context The relevant context.
*/
public function __construct($qtype, $context) {
$icon = new pix_icon('icon', $qtype->local_name(), $qtype->plugin_name(), [
'class' => 'icon',
'title' => $qtype->local_name()
]);
$help = new lang_string('pluginnamesummary', $qtype->plugin_name());
parent::__construct($qtype->plugin_name(), $qtype->menu_name(), $qtype->name(), $icon, $help, $context);
}
}
@@ -0,0 +1,64 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace qbank_editquestion;
use core_question\local\bank\column_base;
use core_question\local\bank\question_version_status;
/**
* A column to show the status of the question.
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class question_status_column extends column_base {
public function get_name(): string {
return 'questionstatus';
}
public function get_title(): string {
return get_string('questionstatus', 'qbank_editquestion');
}
protected function display_content($question, $rowclasses): void {
global $PAGE;
$attributes = [];
if (question_has_capability_on($question, 'edit')
&& $question->status !== question_version_status::QUESTION_STATUS_HIDDEN) {
$options = [];
$options['questionid'] = $question->id;
$statuslist = editquestion_helper::get_question_status_list();
foreach ($statuslist as $value => $displaystatus) {
$options['options'][] = [
'name' => $displaystatus,
'value' => $value,
'selected' => ($question->status) === $value ? true : false
];
}
echo $PAGE->get_renderer('qbank_editquestion')->render_status_dropdown($options);
$PAGE->requires->js_call_amd('qbank_editquestion/question_status', 'init', [$question->id]);
}
}
public function get_extra_classes(): array {
return ['pr-3'];
}
}
@@ -0,0 +1,35 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* External services definition for qbank_editquestion.
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$functions = [
'qbank_editquestion_set_status' => [
'classname' => 'qbank_editquestion\external\update_question_version_status',
'description' => 'Update the question status.',
'type' => 'write',
'ajax' => true,
],
];
@@ -0,0 +1,39 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component qbank_editquestion, language 'en'.
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Edit questions';
$string['privacy:metadata'] = 'The Edit questions question bank plugin does not store any personal data.';
// Question status.
$string['questionstatus'] = 'Status';
$string['questionstatusready'] = 'Ready';
$string['questionstatushidden'] = 'Hidden';
$string['questionstatusdraft'] = 'Draft';
$string['questionstatusheader'] = 'Change question status';
$string['unrecognizedstatus'] = 'Unrecognised status';
// Edit form.
$string['versioninfo'] = 'Version';
$string['status'] = 'Question status';
+370
View File
@@ -0,0 +1,370 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Page for editing questions.
*
* @package qbank_editquestion
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../../config.php');
require_once(__DIR__ . '/../../editlib.php');
require_once($CFG->libdir . '/filelib.php');
require_once($CFG->libdir . '/formslib.php');
// Read URL parameters telling us which question to edit.
$id = optional_param('id', 0, PARAM_INT); // Question id.
$makecopy = optional_param('makecopy', 0, PARAM_BOOL);
$qtype = optional_param('qtype', '', PARAM_COMPONENT);
$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);
$originalreturnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
$appendqnumstring = optional_param('appendqnumstring', '', PARAM_ALPHA);
$inpopup = optional_param('inpopup', 0, PARAM_BOOL);
$mdlscrollto = optional_param('mdlscrollto', 0, PARAM_INT);
\core_question\local\bank\helper::require_plugin_enabled('qbank_editquestion');
$url = new moodle_url('/question/bank/editquestion/question.php');
if ($id !== 0) {
$url->param('id', $id);
}
if ($makecopy) {
$url->param('makecopy', $makecopy);
}
if ($qtype !== '') {
$url->param('qtype', $qtype);
}
if ($categoryid !== 0) {
$url->param('category', $categoryid);
}
if ($cmid !== 0) {
$url->param('cmid', $cmid);
}
if ($courseid !== 0) {
$url->param('courseid', $courseid);
}
if ($wizardnow !== '') {
$url->param('wizardnow', $wizardnow);
}
if ($originalreturnurl !== 0) {
$url->param('returnurl', $originalreturnurl);
}
if ($appendqnumstring !== '') {
$url->param('appendqnumstring', $appendqnumstring);
}
if ($inpopup !== 0) {
$url->param('inpopup', $inpopup);
}
if ($mdlscrollto) {
$url->param('mdlscrollto', $mdlscrollto);
}
$PAGE->set_url($url);
if ($cmid) {
$questionbankurl = new moodle_url('/question/edit.php', array('cmid' => $cmid));
} else {
$questionbankurl = new moodle_url('/question/edit.php', array('courseid' => $courseid));
}
navigation_node::override_active_url($questionbankurl);
if ($originalreturnurl) {
if (strpos($originalreturnurl, '/') !== 0) {
throw new coding_exception("returnurl must be a local URL starting with '/'. $originalreturnurl was given.");
}
$returnurl = new moodle_url($originalreturnurl);
} else {
$returnurl = $questionbankurl;
}
if ($mdlscrollto) {
$returnurl->param('mdlscrollto', $mdlscrollto);
}
if ($cmid) {
list($module, $cm) = get_module_from_cmid($cmid);
require_login($cm->course, false, $cm);
$thiscontext = context_module::instance($cmid);
} else if ($courseid) {
require_login($courseid, false);
$thiscontext = context_course::instance($courseid);
$module = null;
$cm = null;
} else {
throw new moodle_exception('missingcourseorcmid', 'question');
}
$contexts = new core_question\local\bank\question_edit_contexts($thiscontext);
$PAGE->set_pagelayout('admin');
if (optional_param('addcancel', false, PARAM_BOOL)) {
redirect($returnurl);
}
if ($id) {
if (!$question = $DB->get_record('question', array('id' => $id))) {
throw new moodle_exception('questiondoesnotexist', 'question', $returnurl);
}
// We can use $COURSE here because it's been initialised as part of the
// require_login above. Passing it as the third parameter tells the function
// to filter the course tags by that course.
get_question_options($question, true, [$COURSE]);
} else if ($categoryid && $qtype) { // Only for creating new questions.
$question = new stdClass();
$question->category = $categoryid;
$question->qtype = $qtype;
$question->createdby = $USER->id;
// Check that users are allowed to create this question type at the moment.
if (!question_bank::qtype_enabled($qtype)) {
throw new moodle_exception('cannotenable', 'question', $returnurl, $qtype);
}
} else if ($categoryid) {
// Category, but no qtype. They probably came from the addquestion.php
// script without choosing a question type. Send them back.
$addurl = new moodle_url('/question/bank/editquestion/addquestion.php', $url->params());
$addurl->param('validationerror', 1);
redirect($addurl);
} else {
throw new moodle_exception('notenoughdatatoeditaquestion', 'question', $returnurl);
}
$qtypeobj = question_bank::get_qtype($question->qtype);
if (isset($question->categoryobject)) {
$category = $question->categoryobject;
} else {
// Validate the question category.
if (!$category = $DB->get_record('question_categories', array('id' => $question->category))) {
throw new moodle_exception('categorydoesnotexist', 'question', $returnurl);
}
}
// Check permissions.
$question->formoptions = new stdClass();
$categorycontext = context::instance_by_id($category->contextid);
$question->contextid = $category->contextid;
$addpermission = has_capability('moodle/question:add', $categorycontext);
if ($id) {
$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');
}
$question->beingcopied = false;
if ($makecopy) {
// If we are duplicating a question, add some indication to the question name.
$question->name = get_string('questionnamecopy', 'question', $question->name);
$question->idnumber = isset($question->idnumber) ?
core_question_find_next_unused_idnumber($question->idnumber, $category->id) : '';
$question->beingcopied = true;
}
} else { // Creating a new question.
$question->formoptions->canedit = question_has_capability_on($question, 'edit');
$question->formoptions->canmove = (question_has_capability_on($question, 'move') && $addpermission);
$question->formoptions->cansaveasnew = false;
$question->formoptions->repeatelements = true;
$formeditable = true;
require_capability('moodle/question:add', $categorycontext);
}
$question->formoptions->mustbeusable = (bool) $appendqnumstring;
// Validate the question type.
$PAGE->set_pagetype('question-type-' . $question->qtype);
// Create the question editing form.
if ($wizardnow !== '') {
$mform = $qtypeobj->next_wizard_form('question.php', $question, $wizardnow, $formeditable);
} else {
$mform = $qtypeobj->create_editing_form('question.php', $question, $category, $contexts, $formeditable);
}
$toform = fullclone($question); // Send the question object and a few more parameters to the form.
$toform->category = "{$category->id},{$category->contextid}";
$toform->mdlscrollto = $mdlscrollto;
if ($formeditable && $id) {
$toform->categorymoveto = $toform->category;
}
$toform->appendqnumstring = $appendqnumstring;
$toform->returnurl = $originalreturnurl;
$toform->makecopy = $makecopy;
$toform->idnumber = null;
if (!empty($question->id)) {
$questionobject = question_bank::load_question($question->id);
$toform->status = $questionobject->status;
$toform->idnumber = $questionobject->idnumber;
} else {
$toform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
}
if ($makecopy) {
$toform->idnumber = core_question_find_next_unused_idnumber($toform->idnumber, $category->id);
}
if ($cm !== null) {
$toform->cmid = $cm->id;
$toform->courseid = $cm->course;
} else {
$toform->courseid = $COURSE->id;
}
$toform->inpopup = $inpopup;
// Prepare custom fields data.
$customfieldhandler = qbank_customfields\customfield\question_handler::create();
$customfieldhandler->instance_form_before_set_data($toform);
$mform->set_data($toform);
if ($mform->is_cancelled()) {
if ($inpopup) {
close_window();
} else {
redirect($returnurl);
}
} else if ($fromform = $mform->get_data()) {
// If we are saving as a copy, break the connection to the old question.
if ($makecopy) {
$question->id = 0;
// Copies should not be hidden.
$question->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
}
// If is will be added directly to a module send the module name to be referenced.
if ($appendqnumstring && $cm) {
$fromform->modulename = 'mod_' . $cm->modname;
}
// Process the combination of usecurrentcat, categorymoveto and category form
// fields, so the save_question method only has to consider $fromform->category.
if (empty($fromform->usecurrentcat) && !empty($fromform->categorymoveto)) {
$fromform->category = $fromform->categorymoveto;
}
// If we are moving a question, check we have permission to move it from
// whence it came (Where we are moving to is validated by the form).
list($newcatid, $newcontextid) = explode(',', $fromform->category);
if (!empty($question->id) && $newcatid != $question->categoryobject->id) {
$contextid = $newcontextid;
question_require_capability_on($question, 'move');
} else {
$contextid = $category->contextid;
}
// Ensure we redirect back to the category the question is being saved into.
$returnurl->param('category', $fromform->category);
// We are actually saving the question.
if (!empty($question->id)) {
question_require_capability_on($question, 'edit');
} else {
require_capability('moodle/question:add', context::instance_by_id($contextid));
if (!empty($fromform->makecopy) && !$question->formoptions->cansaveasnew) {
throw new moodle_exception('nopermissions', '', '', 'edit');
}
}
// If this is a new question, save defaults for user in user_preferences table.
if (empty($question->id)) {
$qtypeobj->save_defaults_for_new_questions($fromform);
}
$question = $qtypeobj->save_question($question, $fromform);
if (isset($fromform->tags)) {
// If we have any question context level tags then set those tags now.
core_tag_tag::set_item_tags('core_question', 'question', $question->id,
context::instance_by_id($contextid), $fromform->tags, 0);
}
if (isset($fromform->coursetags)) {
// If we have and course context level tags then set those now.
core_tag_tag::set_item_tags('core_question', 'question', $question->id,
context_course::instance($fromform->courseid), $fromform->coursetags, 0);
}
// Update custom fields if there are any of them in the form.
$customfieldhandler->instance_form_save($fromform);
// Purge this question from the cache.
question_bank::notify_question_edited($question->id);
// If we are saving and continuing to edit the question.
if (!empty($fromform->updatebutton)) {
$url->param('id', $question->id);
$url->remove_params('makecopy');
redirect($url);
}
if ($qtypeobj->finished_edit_wizard($fromform)) {
if ($inpopup) {
echo $OUTPUT->notification(get_string('changessaved'), '');
close_window(3);
} else {
$returnurl->param('lastchanged', $question->id);
if ($appendqnumstring) {
$returnurl->param($appendqnumstring, $question->id);
$returnurl->param('sesskey', sesskey());
$returnurl->param('cmid', $cmid);
}
redirect($returnurl);
}
} else {
$nexturlparams = [
'returnurl' => $originalreturnurl,
'appendqnumstring' => $appendqnumstring,
'mdlscrollto' => $mdlscrollto,
];
if (isset($fromform->nextpageparam) && is_array($fromform->nextpageparam)) {
// Useful for passing data to the next page which is not saved in the database.
$nexturlparams += $fromform->nextpageparam;
}
$nexturlparams['id'] = $question->id;
$nexturlparams['wizardnow'] = $fromform->wizard;
$nexturl = new moodle_url($url, $nexturlparams);
if ($cmid) {
$nexturl->param('cmid', $cmid);
} else {
$nexturl->param('courseid', $COURSE->id);
}
redirect($nexturl);
}
}
$streditingquestion = $qtypeobj->get_heading();
$PAGE->set_title($streditingquestion);
$PAGE->set_heading($COURSE->fullname);
$PAGE->activityheader->disable();
$PAGE->navbar->add($streditingquestion);
if ($PAGE->course->id == $SITE->id) {
$PAGE->set_primary_active_tab('home');
}
// Display a heading, question editing form and possibly some extra content needed for
// for this question type.
echo $OUTPUT->header();
$qtypeobj->display_question_editing_page($mform, $question, $wizardnow);
echo $OUTPUT->footer();
@@ -0,0 +1,41 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template qbank_editquestion/add_new_question
Example context (json):
{
"addquestiondata": [
{
"canadd": true,
"buttonhtml": "HTML for button",
"qtypeform": "html for qtype"
}
]
}
}}
<div class="createnewquestion mb-1">
{{^canadd}}
{{#str}} nopermissionadd, question{{/str}}
{{/canadd}}
{{#canadd}}
{{{buttonhtml}}}
<div id="qtypechoicecontainer">
{{{qtypeform}}}
</div>
{{/canadd}}
</div>
@@ -0,0 +1,29 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template qbank_editquestion/qbank_chooser
}}
{{> core/chooser }}
{{#js}}
require([
'core/yui'
], function(Y) {
Y.use('moodle-qbank_editquestion-chooser', function() {
M.question.init_chooser();
});
});
{{/js}}
@@ -0,0 +1,32 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template qbank_editquestion/question_info
Example context (json):
{
"elements": [
{"pluginhtml":"<div>Version: 1</div>"},
{"pluginhtml":"<div>Usage: 1</div>"}
]
}
}}
<div class="question-edit-elements">
{{#editelements}}
{{{pluginhtml}}}
{{/editelements}}
</div>
@@ -0,0 +1,36 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template qbank_editquestion/question_status_dropdown
Dropdrown selector for question status in question bank.
Context variables required for this template:
* options - list of options for question status containing name, value, selected.
* questionid - Question id for status selection.
Example context (json):
{
"options" : [ { "name": "Ready", "value": "ready", "selected": true } ],
"questionid" : "12"
}
}}
<select id="question_status_dropdown-{{questionid}}" class="custom-select my-2" name="question_status_dropdown">
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
</select>
@@ -0,0 +1,34 @@
@qbank @qbank_editquestion
Feature: Use the qbank plugin manager page for editquestion
In order to check the plugin behaviour with enable and disable
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "activities" exist:
| activity | name | course | idnumber |
| quiz | Test quiz | C1 | quiz1 |
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | First question | Answer the first question |
| Test questions | truefalse | First question second | Answer the first question |
Scenario: Enable/disable edit question columns from the base view
Given I log in as "admin"
When I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I should see "Edit question"
And I click on "Disable" "link" in the "Edit question" "table_row"
And I am on the "Test quiz" "mod_quiz > question bank" page
Then I should not see "Status"
And the "Edit question" action should not exist for the "First question" question in the question bank
And the "Duplicate" action should not exist for the "First question" question in the question bank
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Edit question" "table_row"
And I am on the "Test quiz" "mod_quiz > question bank" page
Then I should see "Status"
And the "Edit question" action should exist for the "First question" question in the question bank
And the "Duplicate" action should exist for the "First question" question in the question bank
@@ -0,0 +1,35 @@
@qbank @qbank_editquestion
Feature: Use the qbank base view to test the status change using
the pop up
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "activities" exist:
| activity | name | course | idnumber |
| quiz | Test quiz | C1 | quiz1 |
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | First question | Answer the first question |
| Test questions | truefalse | Second question | Answer the first question |
@javascript
Scenario: Question status dropdown should change the status of the question
Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "admin"
And I apply question bank filter "Category" with value "Test questions"
And I should see "Test questions"
And the field "question_status_dropdown" in the "First question" "table_row" matches value "Ready"
And the field "question_status_dropdown" in the "Second question" "table_row" matches value "Ready"
And I set the field "question_status_dropdown" to "Draft"
And I reload the page
And the field "question_status_dropdown" in the "First question" "table_row" matches value "Draft"
And the field "question_status_dropdown" in the "Second question" "table_row" matches value "Ready"
And I set the field "question_status_dropdown" in the "Second question" "table_row" to "Draft"
And I set the field "question_status_dropdown" in the "First question" "table_row" to "Ready"
And I reload the page
And the field "question_status_dropdown" in the "First question" "table_row" matches value "Ready"
And the field "question_status_dropdown" in the "Second question" "table_row" matches value "Draft"
@@ -0,0 +1,118 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace qbank_editquestion;
use core_question\local\bank\question_version_status;
use qbank_editquestion\external\update_question_version_status;
/**
* Submit status external api test.
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @covers \core_question\local\bank\question_version_status
* @coversDefaultClass \qbank_editquestion\external\update_question_version_status
*/
class update_question_version_status_test extends \advanced_testcase {
/** @var \stdClass course record. */
protected $course;
/** @var mixed. */
protected $user;
/**
* Called before every test.
*/
public function setUp(): void {
global $USER;
parent::setUp();
$this->setAdminUser();
$this->course = $this->getDataGenerator()->create_course();
$this->user = $USER;
}
/**
* Test if the submit status webservice changes the status of the question.
*
* @covers ::execute
* @covers \qbank_editquestion\editquestion_helper::get_question_status_string
*/
public function test_submit_status_updates_the_question_status(): void {
global $DB;
$this->resetAfterTest();
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $questiongenerator->create_question_category();
$numq = $questiongenerator->create_question('essay', null,
['category' => $cat->id, 'name' => 'This is the first version']);
$result = update_question_version_status::execute($numq->id, 'draft');
// Test if the version actually changed.
$currentstatus = $DB->get_record('question_versions', ['questionid' => $numq->id]);
$this->assertEquals(editquestion_helper::get_question_status_string($currentstatus->status), $result['statusname']);
}
/**
* Test submit status webservice only takes an existing parameter status.
*
* @covers ::execute
*/
public function test_submit_status_error(): void {
global $DB;
$this->resetAfterTest();
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $questiongenerator->create_question_category();
$numq = $questiongenerator->create_question('essay', null,
['category' => $cat->id, 'name' => 'This is the first version']);
// Passing a wrong status to web service.
$result = update_question_version_status::execute($numq->id, 'frog');
// Tests web service returns error.
$this->assertEquals(false, $result['status']);
$this->assertEquals('', $result['statusname']);
$this->assertEquals(get_string('unrecognizedstatus', 'qbank_editquestion'), $result['error']);
// Test version did not change.
$currentstatus = $DB->get_record('question_versions', ['questionid' => $numq->id]);
$this->assertEquals(question_version_status::QUESTION_STATUS_READY, $currentstatus->status);
}
/**
* Test that updating the status does not create a new version.
*
* @covers ::execute
*/
public function test_submit_status_does_not_create_a_new_version(): void {
global $DB;
$this->resetAfterTest();
// Find out the start count in 'question_versions' table.
$versioncount = $DB->count_records('question_versions');
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $questiongenerator->create_question_category();
$numq = $questiongenerator->create_question('essay', null,
['category' => $cat->id, 'name' => 'This is the first version']);
$countcurrentrecords = $DB->count_records('question_versions');
// New version count should be equal to start + 1.
$this->assertEquals($versioncount + 1, $countcurrentrecords);
$result = update_question_version_status::execute($numq->id, 'draft');
$countafterupdate = $DB->count_records('question_versions');
$this->assertEquals($countcurrentrecords, $countafterupdate);
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version information for qbank_editquestion.
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'qbank_editquestion';
$plugin->version = 2024042200;
$plugin->requires = 2024041600;
$plugin->maturity = MATURITY_STABLE;
@@ -0,0 +1,82 @@
YUI.add('moodle-qbank_editquestion-chooser', function (Y, NAME) {
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* JavaScript required by the add question pop-up.
*
* @module moodle-qbank_editquestion-chooser
*/
var SELECTORS = {
CREATENEWQUESTION: 'div.createnewquestion',
CREATENEWQUESTIONFORM: 'div.createnewquestion form',
CHOOSERDIALOGUE: 'div.chooserdialoguebody',
CHOOSERHEADER: 'div.choosertitle'
};
function Chooser() {
Chooser.superclass.constructor.apply(this, arguments);
}
Y.extend(Chooser, M.core.chooserdialogue, {
initializer: function() {
Y.all(SELECTORS.CREATENEWQUESTIONFORM).each(function(createForm) {
if (createForm.get('id') === 'chooserform') {
// Not the singlebutton form. Ignore.
return;
}
createForm.on('submit', this.displayQuestionChooser, this);
createForm.one('button').set('disabled', false);
}, this);
},
displayQuestionChooser: function(e) {
var dialogue = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERDIALOGUE),
header = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERHEADER);
if (this.container === null) {
// Setup the dialogue, and then prepare the chooser if it's not already been set up.
this.setup_chooser_dialogue(dialogue, header, {});
this.prepare_chooser();
}
// Update all of the hidden fields within the questionbank form.
var originForm = e.target.ancestor('form', true),
targetForm = this.container.one('form'),
hiddenElements = originForm.all('input[type="hidden"]');
targetForm.all('input.customfield').remove();
hiddenElements.each(function(field) {
targetForm.appendChild(field.cloneNode())
.removeAttribute('id')
.addClass('customfield');
});
// Display the chooser dialogue.
this.display_chooser(e);
}
}, {
NAME: 'questionChooser'
});
M.question = M.question || {};
M.question.init_chooser = function(config) {
return new Chooser(config);
};
}, '@VERSION@', {"requires": ["moodle-core-chooserdialogue"]});
@@ -0,0 +1 @@
YUI.add("moodle-qbank_editquestion-chooser",function(n,e){var s="div.createnewquestion",o="div.createnewquestion form",r="div.chooserdialoguebody",u="div.choosertitle";function i(){i.superclass.constructor.apply(this,arguments)}n.extend(i,M.core.chooserdialogue,{initializer:function(){n.all(o).each(function(e){"chooserform"!==e.get("id")&&(e.on("submit",this.displayQuestionChooser,this),e.one("button").set("disabled",!1))},this)},displayQuestionChooser:function(e){var o,i=n.one(s+" "+r),t=n.one(s+" "+u);null===this.container&&(this.setup_chooser_dialogue(i,t,{}),this.prepare_chooser()),i=e.target.ancestor("form",!0),o=this.container.one("form"),t=i.all('input[type="hidden"]'),o.all("input.customfield").remove(),t.each(function(e){o.appendChild(e.cloneNode()).removeAttribute("id").addClass("customfield")}),this.display_chooser(e)}},{NAME:"questionChooser"}),M.question=M.question||{},M.question.init_chooser=function(e){return new i(e)}},"@VERSION@",{requires:["moodle-core-chooserdialogue"]});
@@ -0,0 +1,82 @@
YUI.add('moodle-qbank_editquestion-chooser', function (Y, NAME) {
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* JavaScript required by the add question pop-up.
*
* @module moodle-qbank_editquestion-chooser
*/
var SELECTORS = {
CREATENEWQUESTION: 'div.createnewquestion',
CREATENEWQUESTIONFORM: 'div.createnewquestion form',
CHOOSERDIALOGUE: 'div.chooserdialoguebody',
CHOOSERHEADER: 'div.choosertitle'
};
function Chooser() {
Chooser.superclass.constructor.apply(this, arguments);
}
Y.extend(Chooser, M.core.chooserdialogue, {
initializer: function() {
Y.all(SELECTORS.CREATENEWQUESTIONFORM).each(function(createForm) {
if (createForm.get('id') === 'chooserform') {
// Not the singlebutton form. Ignore.
return;
}
createForm.on('submit', this.displayQuestionChooser, this);
createForm.one('button').set('disabled', false);
}, this);
},
displayQuestionChooser: function(e) {
var dialogue = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERDIALOGUE),
header = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERHEADER);
if (this.container === null) {
// Setup the dialogue, and then prepare the chooser if it's not already been set up.
this.setup_chooser_dialogue(dialogue, header, {});
this.prepare_chooser();
}
// Update all of the hidden fields within the questionbank form.
var originForm = e.target.ancestor('form', true),
targetForm = this.container.one('form'),
hiddenElements = originForm.all('input[type="hidden"]');
targetForm.all('input.customfield').remove();
hiddenElements.each(function(field) {
targetForm.appendChild(field.cloneNode())
.removeAttribute('id')
.addClass('customfield');
});
// Display the chooser dialogue.
this.display_chooser(e);
}
}, {
NAME: 'questionChooser'
});
M.question = M.question || {};
M.question.init_chooser = function(config) {
return new Chooser(config);
};
}, '@VERSION@', {"requires": ["moodle-core-chooserdialogue"]});
@@ -0,0 +1,10 @@
{
"name": "moodle-qbank_editquestion-chooser",
"builds": {
"moodle-qbank_editquestion-chooser": {
"jsfiles": [
"chooser.js"
]
}
}
}
@@ -0,0 +1,77 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* JavaScript required by the add question pop-up.
*
* @module moodle-qbank_editquestion-chooser
*/
var SELECTORS = {
CREATENEWQUESTION: 'div.createnewquestion',
CREATENEWQUESTIONFORM: 'div.createnewquestion form',
CHOOSERDIALOGUE: 'div.chooserdialoguebody',
CHOOSERHEADER: 'div.choosertitle'
};
function Chooser() {
Chooser.superclass.constructor.apply(this, arguments);
}
Y.extend(Chooser, M.core.chooserdialogue, {
initializer: function() {
Y.all(SELECTORS.CREATENEWQUESTIONFORM).each(function(createForm) {
if (createForm.get('id') === 'chooserform') {
// Not the singlebutton form. Ignore.
return;
}
createForm.on('submit', this.displayQuestionChooser, this);
createForm.one('button').set('disabled', false);
}, this);
},
displayQuestionChooser: function(e) {
var dialogue = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERDIALOGUE),
header = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERHEADER);
if (this.container === null) {
// Setup the dialogue, and then prepare the chooser if it's not already been set up.
this.setup_chooser_dialogue(dialogue, header, {});
this.prepare_chooser();
}
// Update all of the hidden fields within the questionbank form.
var originForm = e.target.ancestor('form', true),
targetForm = this.container.one('form'),
hiddenElements = originForm.all('input[type="hidden"]');
targetForm.all('input.customfield').remove();
hiddenElements.each(function(field) {
targetForm.appendChild(field.cloneNode())
.removeAttribute('id')
.addClass('customfield');
});
// Display the chooser dialogue.
this.display_chooser(e);
}
}, {
NAME: 'questionChooser'
});
M.question = M.question || {};
M.question.init_chooser = function(config) {
return new Chooser(config);
};
@@ -0,0 +1,7 @@
{
"moodle-qbank_editquestion-chooser": {
"requires": [
"moodle-core-chooserdialogue"
]
}
}