mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-71575 qbank_viewquestiontext: Add View question text plugin to core
This implementation will introduce a qbank plugin "viewquestiontext" which will view the question text row in the question bank view by replacing the core class. Having this plugin will give users the flexibility of enabling or disabling the question text row in the question view.
This commit is contained in:
parent
206023c15f
commit
97880f26b9
8 changed files with 245 additions and 1 deletions
|
@ -1943,6 +1943,7 @@ class core_plugin_manager {
|
|||
'editquestion',
|
||||
'exportquestions',
|
||||
'importquestions',
|
||||
'viewquestiontext'
|
||||
],
|
||||
|
||||
'qbehaviour' => array(
|
||||
|
|
36
question/bank/viewquestiontext/classes/plugin_feature.php
Normal file
36
question/bank/viewquestiontext/classes/plugin_feature.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?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_viewquestiontext;
|
||||
|
||||
use core_question\local\bank\plugin_features_base;
|
||||
|
||||
/**
|
||||
* Class columns is the entrypoint for the columns.
|
||||
*
|
||||
* @package qbank_viewquestiontext
|
||||
* @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 plugin_features_base {
|
||||
|
||||
public function get_question_columns($qbank): array {
|
||||
return [
|
||||
new question_text_row($qbank)
|
||||
];
|
||||
}
|
||||
}
|
32
question/bank/viewquestiontext/classes/privacy/provider.php
Normal file
32
question/bank/viewquestiontext/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?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_viewquestiontext\privacy;
|
||||
|
||||
/**
|
||||
* Privacy Subsystem for qbank_viewquestiontext implementing null_provider.
|
||||
*
|
||||
* @package qbank_viewquestiontext
|
||||
* @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';
|
||||
}
|
||||
}
|
82
question/bank/viewquestiontext/classes/question_text_row.php
Normal file
82
question/bank/viewquestiontext/classes/question_text_row.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?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_viewquestiontext;
|
||||
|
||||
use core_question\local\bank\row_base;
|
||||
|
||||
/**
|
||||
* A column type for the name of the question name.
|
||||
*
|
||||
* @package qbank_viewquestiontext
|
||||
* @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 question_text_row extends row_base {
|
||||
|
||||
/**
|
||||
* To initialise subclasses
|
||||
* @var $formatoptions
|
||||
*/
|
||||
protected $formatoptions;
|
||||
|
||||
protected function init(): void {
|
||||
$this->formatoptions = new \stdClass();
|
||||
$this->formatoptions->noclean = true;
|
||||
$this->formatoptions->para = false;
|
||||
}
|
||||
|
||||
public function get_name(): string {
|
||||
return 'questiontext';
|
||||
}
|
||||
|
||||
protected function get_title(): string {
|
||||
return get_string('questiontext', 'question');
|
||||
}
|
||||
|
||||
protected function display_content($question, $rowclasses): void {
|
||||
$text = question_rewrite_question_preview_urls($question->questiontext, $question->id,
|
||||
$question->contextid, 'question', 'questiontext', $question->id,
|
||||
$question->contextid, 'core_question');
|
||||
$text = format_text($text, $question->questiontextformat,
|
||||
$this->formatoptions);
|
||||
if ($text == '') {
|
||||
$text = ' ';
|
||||
}
|
||||
echo $text;
|
||||
}
|
||||
|
||||
public function get_extra_joins(): array {
|
||||
return ['qc' => 'JOIN {question_categories} qc ON qc.id = q.category'];
|
||||
}
|
||||
|
||||
public function get_required_fields(): array {
|
||||
return ['q.id', 'q.questiontext', 'q.questiontextformat', 'qc.contextid'];
|
||||
}
|
||||
|
||||
public function has_preference(): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get_preference_key(): string {
|
||||
return 'qbshowtext';
|
||||
}
|
||||
|
||||
public function get_preference(): bool {
|
||||
return question_get_display_preference($this->get_preference_key(), 0, PARAM_BOOL, new \moodle_url(''));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?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_viewquestiontext, language 'en'
|
||||
*
|
||||
* @package qbank_viewquestiontext
|
||||
* @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'] = 'View question text';
|
||||
$string['privacy:metadata'] = 'View question text question bank plugin does not store any user data.';
|
|
@ -0,0 +1,35 @@
|
|||
@qbank @qbank_viewquestiontext
|
||||
Feature: Use the qbank plugin manager page for viewquestiontext
|
||||
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 |
|
||||
|
||||
@javascript
|
||||
Scenario: Enable/disable viewquestiontext column from the base view
|
||||
Given I log in as "admin"
|
||||
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
|
||||
And I should see "View question text"
|
||||
When I click on "Disable" "link" in the "View question text" "table_row"
|
||||
And I am on the "Test quiz" "quiz activity" page
|
||||
And I navigate to "Question bank > Questions" in current page administration
|
||||
And I should not see "Show question text in the question list"
|
||||
Then "#categoryquestions .questiontext" "css_element" should not be visible
|
||||
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
|
||||
And I click on "Enable" "link" in the "View question text" "table_row"
|
||||
And I am on the "Test quiz" "quiz activity" page
|
||||
And I navigate to "Question bank > Questions" in current page administration
|
||||
And I should see "Show question text in the question list"
|
||||
And I click on "qbshowtext" "checkbox"
|
||||
And I should see "Answer the first question"
|
31
question/bank/viewquestiontext/version.php
Normal file
31
question/bank/viewquestiontext/version.php
Normal 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_viewquestiontext.
|
||||
*
|
||||
* @package qbank_viewquestiontext
|
||||
* @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_viewquestiontext';
|
||||
$plugin->version = 2021070700;
|
||||
$plugin->requires = 2021052500;
|
||||
$plugin->maturity = MATURITY_STABLE;
|
|
@ -273,7 +273,7 @@ class_alias('core_question\local\bank\row_base', 'question_bank_row_base', true)
|
|||
* @deprecated since Moodle 2.7 MDL-40457
|
||||
* @todo MDl-72004 delete the class alias, not done in MDL-71516 for any potential error from other plugins.
|
||||
*/
|
||||
class_alias('core_question\bank\question_text_row', 'question_bank_question_text_row', true);
|
||||
class_alias('qbank_viewquestiontext\question_text_row', 'question_bank_question_text_row', true);
|
||||
|
||||
/**
|
||||
* @copyright 2009 Tim Hunt
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue