Skip to content

Commit

Permalink
MDL-71679 mod_quiz: Updates for new qbank api
Browse files Browse the repository at this point in the history
This implementation will introduct changes to
the mod_quiz to implement the new qbank api
for view. Major changes are introduced in
the custom view and also all the legacy points
to the old qbank are changed to qbank plugins
where needed. It also deprecated and deletes
classes and scripts which were kept not to
break mod_quiz for the new api implementation.
  • Loading branch information
safatshahin committed Oct 4, 2021
1 parent 1a9bee6 commit f9fc355
Show file tree
Hide file tree
Showing 64 changed files with 286 additions and 5,970 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static function get_edit_url(\stdClass $componentinfo): \moodle_url {
}
// Default to SITEID if courseid is null, i.e. system or category level questions.
$thiscourseid = ($componentinfo->courseid !== null) ? $componentinfo->courseid : SITEID;
return new \moodle_url('/question/question.php', ['courseid' => $thiscourseid, 'id' => $questionid]);
return new \moodle_url('/question/bank/editquestion/question.php', ['courseid' => $thiscourseid, 'id' => $questionid]);
}

/**
Expand Down
17 changes: 0 additions & 17 deletions config-dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,23 +692,6 @@
// $CFG->uninstallclionly = true;
//
//
// Customise question bank display
//
// The display of Moodle's question bank is made up of a number of columns.
// You can customise this display by giving a comma-separated list of column class
// names here. Each class must be a subclass of \core_question\bank\column_base.
// For example you might define a class like
// class \local_qbank_extensions\my_column extends \core_question\bank\column_base
// in a local plugin, then add it to the list here. At the time of writing,
// the default question bank display is equivalent to the following, but you might like
// to check the latest default in question/classes/bank/view.php before setting this.
//
// $CFG->questionbankcolumns = 'checkbox_column,question_type_column,'
// . 'question_name_idnumber_tags_column,edit_menu_column,'
// . 'tags_action_column,edit_action_column,copy_action_column,'
// . 'preview_action_column,delete_action_column,export_xml_action_column,'
// . 'creator_name_column,modifier_name_column';
//
// Forum summary report
//
// In order for the forum summary report to calculate word count and character count data, those details are now stored
Expand Down
6 changes: 3 additions & 3 deletions lib/classes/event/question_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public function get_description() {
public function get_url() {
if ($this->courseid) {
if ($this->contextlevel == CONTEXT_MODULE) {
return new \moodle_url('/question/preview.php', ['cmid' => $this->contextinstanceid, 'id' => $this->objectid]);
return new \moodle_url('/question/bank/previewquestion/preview.php', ['cmid' => $this->contextinstanceid, 'id' => $this->objectid]);
}
return new \moodle_url('/question/preview.php', ['courseid' => $this->courseid, 'id' => $this->objectid]);
return new \moodle_url('/question/bank/previewquestion/preview.php', ['courseid' => $this->courseid, 'id' => $this->objectid]);
}
// Lets try editing from the frontpage for contexts above course.
return new \moodle_url('/question/preview.php', ['courseid' => SITEID, 'id' => $this->objectid]);
return new \moodle_url('/question/bank/previewquestion/preview.php', ['courseid' => SITEID, 'id' => $this->objectid]);
}
}
5 changes: 3 additions & 2 deletions lib/classes/plugininfo/qbank.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace core\plugininfo;

defined('MOODLE_INTERNAL') || die();

/**
* Base class for qbank plugins.
*
Expand All @@ -38,6 +36,9 @@
class qbank extends base {

public function is_uninstall_allowed(): bool {
if (in_array($this->name, \core_plugin_manager::standard_plugins_list('qbank'))) {
return false;
}
return true;
}

Expand Down
38 changes: 36 additions & 2 deletions lib/db/renamedclasses.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,51 @@
// Like other files in the db directory this file uses an array.
// The old class name is the key, the new class name is the value.
// The array must be called $renamedclasses.
$renamedclasses = array(
$renamedclasses = [
// Since Moodle 3.7.
'core\\analytics\\target\\course_dropout' => 'core_course\\analytics\\target\\course_dropout',
'core\\analytics\\target\\course_competencies' => 'core_course\\analytics\\target\\course_competencies',
'core\\analytics\\target\\course_completion' => 'core_course\\analytics\\target\\course_completion',
'core\\analytics\\target\\course_gradetopass' => 'core_course\\analytics\\target\\course_gradetopass',
'core\\analytics\\target\\no_teaching' => 'core_course\\analytics\\target\\no_teaching',
// Since Moodle 4.0.
'format_base' => 'core_courseformat\\base',
'format_topics_renderer' => 'format_topics\\output\\renderer',
'format_section_renderer_base' => 'core_courseformat\\output\\section_renderer',
'format_singleactivity_renderer' => 'format_singleactivity\\output\\renderer',
'format_site_renderer' => 'core_courseformat\\output\\site_renderer',
'format_weeks_renderer' => 'format_weeks\\output\\renderer',
);
'core_question\\bank\\action_column_base' => 'core_question\\local\\bank\\action_column_base',
'core_question\\bank\\checkbox_column' => 'core_question\\local\\bank\\checkbox_column',
'core_question\\bank\\column_base' => 'core_question\\local\\bank\\column_base',
'core_question\\bank\\edit_menu_column' => 'core_question\\local\\bank\\edit_menu_column',
'core_question\\bank\\menu_action_column_base' => 'core_question\\local\\bank\\menu_action_column_base',
'core_question\\bank\\menuable_action' => 'core_question\\local\\bank\\menuable_action',
'core_question\\bank\\random_question_loader' => 'core_question\\local\\bank\\random_question_loader',
'core_question\\bank\\row_base' => 'core_question\\local\\bank\\row_base',
'core_question\\bank\\view' => 'core_question\\local\\bank\\view',
'core_question\\bank\\copy_action_column' => 'qbank_editquestion\\copy_action_column',
'core_question\\bank\\edit_action_column' => 'qbank_editquestion\\edit_action_column',
'core_question\\bank\\creator_name_column' => 'qbank_viewcreator\\creator_name_column',
'core_question\\bank\\modifier_name_column' => 'qbank_viewcreator\\modifier_name_column',
'core_question\\bank\\question_name_column' => 'qbank_viewquestionname\\viewquestionname_column_helper',
'core_question\\bank\\question_name_idnumber_tags_column' => 'qbank_viewquestionname\\question_name_idnumber_tags_column',
'core_question\\bank\\delete_action_column' => 'qbank_deletequestion\\delete_action_column',
'core_question\\bank\\export_xml_action_column' => 'qbank_exporttoxml\\export_xml_action_column',
'core_question\\bank\\preview_action_column' => 'qbank_previewquestion\\preview_action_column',
'core_question\\bank\\question_text_row' => 'qbank_viewquestiontext\\question_text_row',
'core_question\\bank\\question_type_column' => 'qbank_viewquestiontype\\question_type_column',
'core_question\\bank\\tags_action_column' => 'qbank_tagquestion\\tags_action_column',
'core_question\\output\\qbank_chooser' => 'qbank_editquestion\\qbank_chooser',
'core_question\\output\\qbank_chooser_item' => 'qbank_editquestion\\qbank_chooser_item',
'question_move_form' => 'qbank_managecategories\\form\\question_move_form',
'question_import_form' => 'qbank_importquestions\\form\\question_import_form',
'question_category_list' => 'qbank_managecategories\\question_category_list',
'question_category_list_item' => 'qbank_managecategories\\question_category_list_item',
'question_category_object' => 'qbank_managecategories\\question_category_object',
'category_form' => 'qbank_managecategories\\form\\category_form',
'export_form' => 'qbank_exportquestions\\form\\export_form',
'preview_options_form' => 'qbank_previewquestion\\form\\preview_options_form',
'question_preview_options' => 'qbank_previewquestion\\output\\question_preview_options',
'core_question\\form\\tags' => '\qbank_tagquestion\\form\\tags_form'
];
42 changes: 18 additions & 24 deletions lib/questionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -759,14 +759,12 @@ function question_move_category_to_context($categoryid, $oldcontextid, $newconte
* @return moodle_url the URL.
* @deprecated since Moodle 4.0
* @see qbank_previewquestion\helper::question_preview_url()
* @todo MDL-71679 uncomment the debug messages after implementing the changes in mod_quiz.
* @todo Final deprecation on Moodle 4.4 MDL-72438
*/
function question_preview_url($questionid, $preferredbehaviour = null,
$maxmark = null, $displayoptions = null, $variant = null, $context = null) {
// Debugging message will be re-added after implementing the changes in mod_quiz.
// ...debugging('Function question_preview_url() has been deprecated and moved to qbank_previewquestion plugin,
// Please use qbank_previewquestion\helper::question_preview_url() instead.', DEBUG_DEVELOPER);.
debugging('Function question_preview_url() has been deprecated and moved to qbank_previewquestion plugin,
Please use qbank_previewquestion\helper::question_preview_url() instead.', DEBUG_DEVELOPER);

return \qbank_previewquestion\helper::question_preview_url($questionid, $preferredbehaviour = null,
$maxmark = null, $displayoptions = null, $variant = null, $context = null);
Expand All @@ -776,13 +774,11 @@ function question_preview_url($questionid, $preferredbehaviour = null,
* @return array that can be passed as $params to the {@link popup_action} constructor.
* @deprecated since Moodle 4.0
* @see qbank_previewquestion\helper::question_preview_popup_params()
* @todo MDL-71679 uncomment the debug messages after implementing the changes to mod_quiz.
* @todo Final deprecation on Moodle 4.4 MDL-72438
*/
function question_preview_popup_params() {
// Debugging message will be re-added after implementing the changes in mod_quiz.
// ...debugging('Function question_preview_popup_params() has been deprecated and moved to qbank_previewquestion plugin,
// Please use qbank_previewquestion\helper::question_preview_popup_params() instead.', DEBUG_DEVELOPER);.
debugging('Function question_preview_popup_params() has been deprecated and moved to qbank_previewquestion plugin,
Please use qbank_previewquestion\helper::question_preview_popup_params() instead.', DEBUG_DEVELOPER);

return \qbank_previewquestion\helper::question_preview_popup_params();
}
Expand Down Expand Up @@ -1656,18 +1652,9 @@ function question_extend_settings_navigation(navigation_node $navigationnode, $c
'title' => get_string('questions', 'question'),
'url' => new moodle_url($baseurl)
],
'categories' => [
'title' => get_string('categories', 'question'),
'url' => new moodle_url('/question/category.php')
],
'import' => [
'title' => get_string('import', 'question'),
'url' => new moodle_url('/question/import.php')
],
'export' => [
'title' => get_string('export', 'question'),
'url' => new moodle_url('/question/export.php')
]
'categories' => [],
'import' => [],
'export' => []
];

$plugins = \core_component::get_plugin_list_with_class('qbank', 'plugin_feature', 'plugin_feature.php');
Expand All @@ -1692,16 +1679,23 @@ function question_extend_settings_navigation(navigation_node $navigationnode, $c
];
}
}
}

// Mitigate the risk of regression.
foreach ($corenavigations as $node => $corenavigation) {
if (empty($corenavigation)) {
unset($corenavigations[$node]);
}
}

// Community/additional plugins have navigation node.
$pluginnavigations = [];
foreach ($plugins as $componentname => $plugin) {
$pluginentrypoin = new $plugin();
$pluginentrypointobject = $pluginentrypoin->get_navigation_node();
if (!\core\plugininfo\qbank::is_plugin_enabled($componentname)) {
unset($corenavigations[$key]);
$pluginentrypoint = new $plugin();
$pluginentrypointobject = $pluginentrypoint->get_navigation_node();
// Don't need the plugins without navigation node.
if ($pluginentrypointobject === null || !\core\plugininfo\qbank::is_plugin_enabled($componentname)) {
unset($plugins[$componentname]);
continue;
}
$pluginnavigations[$pluginentrypointobject->get_navigation_key()] = [
Expand Down
5 changes: 5 additions & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ information provided here is intended especially for developers.
rendered. The default icon for "select" types has also changed to a dropdown caret ("t/expanded").
* The function message_send() in messagelib.php now returns false if there is an error sending the message to the
message processor (MDL-70046).
* Following methods are now deprecated in questionlib and moved to the new qbank_previewquestion plugin:
- question_preview_url() is moved to qbank_previewquestion\helper::question_preview_url()
- question_preview_popup_params() is moved to \qbank_previewquestion\helper::question_preview_popup_params()
Calling these functions in the question will point to the plugin.
The deprecated codes are removed from the questionlib for those two methods.
* The following functions are deprecated in questionlib.php and moved to the new location.
These are marked for final deprecation on 4.4:
- question_remove_stale_questions_from_category() =>
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/attemptlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,7 @@ public function process_redo_question($slot, $timestamp) {
} else {
$tagids = quiz_retrieve_slot_tag_ids($this->slots[$slot]->id);

$randomloader = new \core_question\bank\random_question_loader($qubaids, array());
$randomloader = new \core_question\local\bank\random_question_loader($qubaids, array());
$newqusetionid = $randomloader->get_next_question_id($questiondata->category,
(bool) $questiondata->questiontext, $tagids);
if ($newqusetionid === null) {
Expand Down
12 changes: 5 additions & 7 deletions mod/quiz/classes/output/edit_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ public function edit_menu_actions(structure $structure, $page,
'addonpage' => $page, 'appendqnumstring' => 'addquestion');

$actions['addaquestion'] = new \action_menu_link_secondary(
new \moodle_url('/question/addquestion.php', $params),
new \moodle_url('/question/bank/editquestion/addquestion.php', $params),
new \pix_icon('t/add', $str->addaquestion, 'moodle', array('class' => 'iconsmall', 'title' => '')),
$str->addaquestion, array('class' => 'cm-edit-action addquestion', 'data-action' => 'addquestion')
);
Expand Down Expand Up @@ -722,7 +722,7 @@ protected function add_question_form(structure $structure, $page, \moodle_url $p

return html_writer::tag('form', html_writer::div($output),
array('class' => 'addnewquestion', 'method' => 'post',
'action' => new \moodle_url('/question/addquestion.php')));
'action' => new \moodle_url('/question/bank/editquestion/addquestion.php')));
}

/**
Expand Down Expand Up @@ -836,7 +836,7 @@ public function question_preview_icon($quiz, $question, $label = null, $variant
$image = $this->pix_icon('t/preview', $strpreviewquestion);

$action = new \popup_action('click', $url, 'questionpreview',
question_preview_popup_params());
\qbank_previewquestion\helper::question_preview_popup_params());

return $this->action_link($url, $image . $strpreviewlabel, $action,
array('title' => $strpreviewquestion, 'class' => 'preview'));
Expand Down Expand Up @@ -946,7 +946,7 @@ public function question_name(structure $structure, $slot, $pageurl) {
$output = '';

$question = $structure->get_question_in_slot($slot);
$editurl = new \moodle_url('/question/question.php', array(
$editurl = new \moodle_url('/question/bank/editquestion/question.php', array(
'returnurl' => $pageurl->out_as_local_url(),
'cmid' => $structure->get_cmid(), 'id' => $question->id));

Expand Down Expand Up @@ -1252,9 +1252,7 @@ protected function add_page_icon_template(structure $structure) {
*/
public function question_bank_contents(\mod_quiz\question\bank\custom_view $questionbank, array $pagevars) {

$qbank = $questionbank->render('editq', $pagevars['qpage'], $pagevars['qperpage'],
$pagevars['cat'], $pagevars['recurse'], $pagevars['showhidden'], $pagevars['qbshowtext'],
$pagevars['qtagids']);
$qbank = $questionbank->render($pagevars, 'editq');
return html_writer::div(html_writer::div($qbank, 'bd'), 'questionbankformforpopup');
}
}
2 changes: 1 addition & 1 deletion mod/quiz/classes/output/question_chooser.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class question_chooser extends \core_question\output\qbank_chooser {
class question_chooser extends \qbank_editquestion\qbank_chooser {
}
19 changes: 6 additions & 13 deletions mod/quiz/classes/question/bank/add_action_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,23 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* A column type for the add this question to the quiz action.
*
* @package mod_quiz
* @category question
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_quiz\question\bank;
defined('MOODLE_INTERNAL') || die();


/**
* A column type for the add this question to the quiz action.
*
* @package mod_quiz
* @category question
* @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 add_action_column extends \core_question\bank\action_column_base {
class add_action_column extends \core_question\local\bank\action_column_base {

/** @var string caches a lang string used repeatedly. */
protected $stradd;

public function init() {
public function init(): void {
parent::init();
$this->stradd = get_string('addtoquiz', 'quiz');
}
Expand Down
Loading

0 comments on commit f9fc355

Please sign in to comment.