mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-71576 qbank_viewquestionname: Add View question name to core
This implementation will introduce a qbank plugin "viewquestionname" which will view the question name column in the question bank view by replacing the core classes. Having this plugin will give users the flexibility of enabling or disabling the question name column.
- Loading branch information
1 parent
206023c
commit 354b98c
Showing
10 changed files
with
318 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_viewquestionname; | ||
|
||
use core_question\local\bank\plugin_features_base; | ||
|
||
/** | ||
* Plugin entrypoint for columns. | ||
* | ||
* @package qbank_viewquestionname | ||
* @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_name_idnumber_tags_column($qbank) | ||
]; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
question/bank/viewquestionname/classes/privacy/provider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_viewquestionname\privacy; | ||
|
||
/** | ||
* Privacy Subsystem for qbank_viewquestionname implementing null_provider. | ||
* | ||
* @package qbank_viewquestionname | ||
* @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'; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
question/bank/viewquestionname/classes/question_name_idnumber_tags_column.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/>. | ||
|
||
namespace qbank_viewquestionname; | ||
|
||
/** | ||
* A question bank column showing the question name with idnumber and tags. | ||
* | ||
* @package qbank_viewquestionname | ||
* @copyright 2019 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 question_name_idnumber_tags_column extends viewquestionname_column_helper { | ||
|
||
public function get_name(): string { | ||
return 'qnameidnumbertags'; | ||
} | ||
|
||
protected function display_content($question, $rowclasses): void { | ||
global $OUTPUT; | ||
|
||
$layoutclasses = 'd-inline-flex flex-nowrap overflow-hidden w-100'; | ||
$labelfor = $this->label_for($question); | ||
if ($labelfor) { | ||
echo \html_writer::start_tag('label', ['for' => $labelfor, 'class' => $layoutclasses]); | ||
$closetag = \html_writer::end_tag('label'); | ||
} else { | ||
echo \html_writer::start_tag('span', ['class' => $layoutclasses]); | ||
echo \html_writer::end_tag('span'); | ||
} | ||
|
||
// Question name. | ||
echo \html_writer::span(format_string($question->name), 'questionname flex-grow-1 flex-shrink-1 text-truncate'); | ||
|
||
// Question idnumber. | ||
if ($question->idnumber !== null && $question->idnumber !== '') { | ||
echo ' ' . \html_writer::span( | ||
\html_writer::span(get_string('idnumber', 'question'), 'accesshide') | ||
. ' ' . \html_writer::span(s($question->idnumber), 'badge badge-primary'), 'ml-1'); | ||
} | ||
|
||
// Question tags. | ||
if (!empty($question->tags)) { | ||
$tags = \core_tag_tag::get_item_tags('core_question', 'question', $question->id); | ||
echo $OUTPUT->tag_list($tags, null, 'd-inline flex-shrink-1 text-truncate ml-1', 0, null, true); | ||
} | ||
|
||
echo $closetag; // Computed above to ensure it matches. | ||
} | ||
|
||
public function get_required_fields(): array { | ||
$fields = parent::get_required_fields(); | ||
$fields[] = 'q.idnumber'; | ||
return $fields; | ||
} | ||
|
||
public function is_sortable(): array { | ||
return [ | ||
'name' => ['field' => 'q.name', 'title' => get_string('questionname', 'question')], | ||
'idnumber' => ['field' => 'q.idnumber', 'title' => get_string('idnumber', 'question')], | ||
]; | ||
} | ||
|
||
public function load_additional_data(array $questions): void { | ||
parent::load_additional_data($questions); | ||
parent::load_question_tags($questions); | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
question/bank/viewquestionname/classes/viewquestionname_column_helper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?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_viewquestionname; | ||
|
||
use core_question\local\bank\column_base; | ||
|
||
|
||
/** | ||
* A column type for the name of the question name. | ||
* | ||
* @package qbank_viewquestionname | ||
* @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 viewquestionname_column_helper extends column_base { | ||
|
||
/** | ||
* @var null $checkboxespresent | ||
*/ | ||
protected $checkboxespresent = null; | ||
|
||
public function get_name(): string { | ||
return 'questionname'; | ||
} | ||
|
||
protected function get_title(): string { | ||
return get_string('question'); | ||
} | ||
|
||
protected function label_for($question): string { | ||
if (is_null($this->checkboxespresent)) { | ||
$this->checkboxespresent = $this->qbank->has_column('core_question\local\bank\checkbox_column'); | ||
} | ||
if ($this->checkboxespresent) { | ||
return 'checkq' . $question->id; | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
protected function display_content($question, $rowclasses): void { | ||
$labelfor = $this->label_for($question); | ||
if ($labelfor) { | ||
echo \html_writer::start_tag('label', array('for' => $labelfor)); | ||
} | ||
echo format_string($question->name); | ||
if ($labelfor) { | ||
echo \html_writer::end_tag('label'); | ||
} | ||
} | ||
|
||
public function get_required_fields(): array { | ||
return ['q.id', 'q.name']; | ||
} | ||
|
||
public function is_sortable() { | ||
return 'q.name'; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
question/bank/viewquestionname/lang/en/qbank_viewquestionname.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_viewquestionname, language 'en' | ||
* | ||
* @package qbank_viewquestionname | ||
* @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 name'; | ||
$string['privacy:metadata'] = 'View question name question bank plugin does not store any user data.'; |
31 changes: 31 additions & 0 deletions
31
question/bank/viewquestionname/tests/behat/view_question_name_column.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@qbank @qbank_viewquestionname | ||
Feature: Use the qbank plugin manager page for viewquestionname | ||
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 | | ||
|
||
Scenario: Enable/disable viewquestionname 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 name" | ||
When I click on "Disable" "link" in the "View question name" "table_row" | ||
And I am on the "Test quiz" "quiz activity" page | ||
And I navigate to "Question bank > Questions" in current page administration | ||
Then I should not see "First question" | ||
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 name" "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 "First question" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_viewquestionname. | ||
* | ||
* @package qbank_viewquestionname | ||
* @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_viewquestionname'; | ||
$plugin->version = 2021070700; | ||
$plugin->requires = 2021052500; | ||
$plugin->maturity = MATURITY_STABLE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters