Skip to content

Commit

Permalink
MDL-72448 qbank_history: Add history plugin to core
Browse files Browse the repository at this point in the history
This implementation will introduce history plugin to
show the versions of a question. This plugin uses the
actual qbank api to implement the feature.
  • Loading branch information
safatshahin committed Mar 1, 2022
1 parent 9cd77c4 commit 6c923f4
Show file tree
Hide file tree
Showing 17 changed files with 918 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/classes/plugin_manager.php
Expand Up @@ -1957,6 +1957,7 @@ public static function standard_plugins_list($type) {
'editquestion',
'exporttoxml',
'exportquestions',
'history',
'importquestions',
'managecategories',
'previewquestion',
Expand Down
47 changes: 47 additions & 0 deletions question/bank/history/classes/helper.php
@@ -0,0 +1,47 @@
<?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_history;

/**
* Helper class for question history.
*
* @package qbank_history
* @copyright 2022 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 helper {

/**
* Get the question history url.
*
* @param int $entryid id of the question entry
* @param string $returnrul url of the page to return to
* @param int $courseid id of the course
* @return \moodle_url
*/
public static function question_history_url(int $entryid, string $returnrul, int $courseid): \moodle_url {
$params = [
'entryid' => $entryid,
'returnurl' => $returnrul,
'courseid' => $courseid
];

return new \moodle_url('/question/bank/history/history.php', $params);
}

}
60 changes: 60 additions & 0 deletions question/bank/history/classes/history_action_column.php
@@ -0,0 +1,60 @@
<?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_history;

use core_question\local\bank\menu_action_column_base;

/**
* Question bank column for the history action icon.
*
* @package qbank_history
* @copyright 2022 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 history_action_column extends menu_action_column_base {

// Store this lang string for performance.
protected $strpreview;

public function init(): void {
parent::init();
$this->strpreview = get_string('history_action', 'qbank_history');
}

public function get_name(): string {
return 'historyaction';
}

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, 'use')) {
$url = helper::question_history_url($question->questionbankentryid, $this->qbank->returnurl,
$this->qbank->course->id);
return [$url, 't/log', $this->strpreview];
}

return [null, null, null];
}

}
39 changes: 39 additions & 0 deletions question/bank/history/classes/output/renderer.php
@@ -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/>.

namespace qbank_history\output;

/**
* Class renderer for rendering question history.
*
* @package qbank_history
* @copyright 2022 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 the history header.
*
* @param array $historydata data to be passed in the mustache
* @return string
*/
public function render_history_header(array $historydata): string {
return $this->render_from_template('qbank_history/history_header', $historydata);
}

}
36 changes: 36 additions & 0 deletions question/bank/history/classes/plugin_feature.php
@@ -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_history;

/**
* Class plugin_feature is the entrypoint for the columns.
*
* @package qbank_history
* @copyright 2022 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 history_action_column($qbank),
new version_number_column($qbank)
];
}

}
33 changes: 33 additions & 0 deletions question/bank/history/classes/privacy/provider.php
@@ -0,0 +1,33 @@
<?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_history\privacy;

/**
* Privacy Subsystem for qbank_history implementing null_provider.
*
* @package qbank_history
* @copyright 2022 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 comments on commit 6c923f4

Please sign in to comment.