Merge branch 'master_MDL-75306-lastused-41' of https://github.com/catalyst/moodle-MDL-72752
This commit is contained in:
@@ -134,4 +134,22 @@ class helper {
|
||||
return $sql;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the question last used sql.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_question_last_used_sql(): string {
|
||||
$sql = "SELECT MAX(qa.timemodified) as lastused
|
||||
FROM {quiz} qz
|
||||
JOIN {quiz_attempts} qa ON qa.quiz = qz.id
|
||||
JOIN {question_usages} qu ON qu.id = qa.uniqueid
|
||||
JOIN {question_attempts} qatt ON qatt.questionusageid = qu.id
|
||||
JOIN {question} q ON q.id = qatt.questionid
|
||||
WHERE qa.preview = 0
|
||||
AND q.id = ?";
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
namespace qbank_usage\output;
|
||||
|
||||
/**
|
||||
* Class renderer
|
||||
* Renderer for usage plugin.
|
||||
*
|
||||
* @package qbank_usage
|
||||
* @copyright 2021 Catalyst IT Australia Pty Ltd
|
||||
@@ -36,4 +36,14 @@ class renderer extends \plugin_renderer_base {
|
||||
return $this->render_from_template('qbank_usage/usage_modal', $displaydata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the question usage column.
|
||||
*
|
||||
* @param array $displaydata last used date or never
|
||||
* @return string
|
||||
*/
|
||||
public function render_last_used_column(array $displaydata): string {
|
||||
return $this->render_from_template('qbank_usage/last_used', $displaydata);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
namespace qbank_usage;
|
||||
|
||||
use core_question\local\bank\view;
|
||||
|
||||
/**
|
||||
* Class plugin_feature is the entrypoint for the columns.
|
||||
*
|
||||
@@ -26,9 +28,11 @@ namespace qbank_usage;
|
||||
*/
|
||||
class plugin_feature extends \core_question\local\bank\plugin_features_base {
|
||||
|
||||
public function get_question_columns($qbank): array {
|
||||
public function get_question_columns(view $qbank): array {
|
||||
return [
|
||||
new question_usage_column($qbank)
|
||||
new question_usage_column($qbank),
|
||||
new question_last_used_column($qbank)
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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_usage;
|
||||
|
||||
use core_question\local\bank\column_base;
|
||||
|
||||
/**
|
||||
* Question bank column for the question last used.
|
||||
*
|
||||
* @package qbank_usage
|
||||
* @copyright 2022 Catalyst IT Australia Pty Ltd
|
||||
* @author Safat Shahin <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class question_last_used_column extends column_base {
|
||||
|
||||
public function get_name(): string {
|
||||
return 'questionlastused';
|
||||
}
|
||||
|
||||
public function get_title(): string {
|
||||
return get_string('questionlastused', 'qbank_usage');
|
||||
}
|
||||
|
||||
public function help_icon(): ?\help_icon {
|
||||
return new \help_icon('questionlastused', 'qbank_usage');
|
||||
}
|
||||
|
||||
protected function display_content($question, $rowclasses): void {
|
||||
global $DB, $PAGE;
|
||||
$displaydata = [];
|
||||
$questionusage = $DB->get_record_sql(helper::get_question_last_used_sql(), [$question->id]);
|
||||
$displaydata['lastused'] = get_string('notused', 'qbank_usage');
|
||||
if (!empty($questionusage->lastused)) {
|
||||
$displaydata['lastused'] = userdate($questionusage->lastused);
|
||||
}
|
||||
echo $PAGE->get_renderer('qbank_usage')->render_last_used_column($displaydata);
|
||||
}
|
||||
|
||||
public function get_extra_classes(): array {
|
||||
return ['pr-3'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,9 +24,12 @@
|
||||
*/
|
||||
|
||||
$string['pluginname'] = 'Question usage';
|
||||
$string['notused'] = 'Never';
|
||||
$string['privacy:metadata'] = 'The Question usage question bank plugin does not store any personal data.';
|
||||
$string['questionusage'] = 'Usage';
|
||||
$string['questionusage_help'] = 'The number of quizzes in which the question is used, with a link to open a window listing the quizzes and the number of attempts.';
|
||||
$string['questionlastused'] = 'Last used';
|
||||
$string['questionlastused_help'] = 'When was the question last attempted by a student.';
|
||||
$string['usageheader'] = 'Question usage';
|
||||
|
||||
// Table.
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#categoryquestions td.questionlastused span.date {
|
||||
font-weight: 400;
|
||||
font-size: .8em;
|
||||
}
|
||||
@@ -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_usage/last_used
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"displaydata": [
|
||||
{
|
||||
"lastused": "Never"
|
||||
}
|
||||
]
|
||||
}
|
||||
}}
|
||||
|
||||
<span class="date">
|
||||
{{lastused}}
|
||||
</span>
|
||||
@@ -0,0 +1,31 @@
|
||||
@qbank @qbank_usage @javascript
|
||||
Feature: Use the qbank plugin manager page for question last used
|
||||
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 question last usage 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 "Question usage"
|
||||
When I click on "Disable" "link" in the "Question usage" "table_row"
|
||||
And I am on the "Test quiz" "quiz activity" page
|
||||
And I navigate to "Question bank" in current page administration
|
||||
Then I should not see "Last used"
|
||||
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
|
||||
And I click on "Enable" "link" in the "Question usage" "table_row"
|
||||
And I am on the "Test quiz" "quiz activity" page
|
||||
And I navigate to "Question bank" in current page administration
|
||||
And I should see "Last used"
|
||||
Reference in New Issue
Block a user