Skip to content

Commit

Permalink
MDL-75125 qbank: Convert qbank plugins to new actions API
Browse files Browse the repository at this point in the history
  • Loading branch information
marxjohnson committed Jun 2, 2023
1 parent be1bc85 commit 359bb7e
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
namespace qbank_deletequestion;

use core_question\local\bank\question_version_status;
use core_question\local\bank\menu_action_column_base;
use core_question\local\bank\question_action_base;

/**
* Action to delete (or hide) a question, or restore a previously hidden question.
Expand All @@ -35,7 +35,7 @@
* @author 2021 Safat Shahin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delete_action_column extends menu_action_column_base {
class delete_action extends question_action_base {

/**
* @var string $strdelete
Expand Down Expand Up @@ -75,10 +75,6 @@ public function init(): void {
}
}

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

protected function get_url_icon_and_label(\stdClass $question): array {
if (!question_has_capability_on($question, 'edit')) {
return [null, null, null];
Expand All @@ -100,9 +96,4 @@ protected function get_url_icon_and_label(\stdClass $question): array {
return [$url, 't/delete', $this->strdelete];
}
}

public function get_required_fields(): array {
$required = parent::get_required_fields();
return $required;
}
}
4 changes: 2 additions & 2 deletions question/bank/deletequestion/classes/plugin_feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
* @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 {
public function get_question_actions($qbank): array {
return [
new delete_action_column($qbank),
new delete_action($qbank),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace qbank_editquestion;

use core_question\local\bank\menu_action_column_base;
use core_question\local\bank\question_action_base;
use moodle_url;

/**
Expand All @@ -34,7 +34,7 @@
* @author 2021 Safat Shahin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class copy_action_column extends menu_action_column_base {
class copy_action extends question_action_base {

/** @var string avoids repeated calls to get_string('duplicate'). */
protected $strcopy;
Expand All @@ -57,10 +57,6 @@ public function init(): void {
}
}

public function get_name() {
return 'copyaction';
}

/**
* Get the URL for duplicating a question as a moodle_url.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace qbank_editquestion;

use core_question\local\bank\menu_action_column_base;
use core_question\local\bank\question_action_base;
use moodle_url;

/**
Expand All @@ -34,7 +34,7 @@
* @author 2021 Safat Shahin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit_action_column extends menu_action_column_base {
class edit_action extends question_action_base {

/**
* Contains the string.
Expand Down Expand Up @@ -67,10 +67,6 @@ public function init(): void {
}
}

public function get_name() {
return 'editaction';
}

/**
* Get the URL for editing a question as a link.
*
Expand Down
13 changes: 10 additions & 3 deletions question/bank/editquestion/classes/plugin_feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace qbank_editquestion;

use core_question\local\bank\view;

/**
* Class columns is the entrypoint for the columns.
*
Expand All @@ -37,9 +39,14 @@ class plugin_feature extends \core_question\local\bank\plugin_features_base{

public function get_question_columns($qbank): array {
return [
new edit_action_column($qbank),
new copy_action_column($qbank),
new question_status_column($qbank)
new question_status_column($qbank),
];
}

public function get_question_actions(view $qbank): array {
return [
new edit_action($qbank),
new copy_action($qbank),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace qbank_exporttoxml;

use core_question\local\bank\menu_action_column_base;
use core_question\local\bank\question_action_base;

/**
* Question bank column export the question in Moodle XML format.
Expand All @@ -26,7 +26,7 @@
* @author 2021 Safat Shahin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class export_xml_action_column extends menu_action_column_base {
class export_xml_action extends question_action_base {

/** @var string avoids repeated calls to get_string('duplicate'). */
protected $strexportasxml;
Expand All @@ -36,10 +36,6 @@ public function init(): void {
$this->strexportasxml = get_string('exportasxml', 'question');
}

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

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
Expand Down
4 changes: 2 additions & 2 deletions question/bank/exporttoxml/classes/plugin_feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
*/
class plugin_feature extends plugin_features_base {

public function get_question_columns($qbank): array {
public function get_question_actions($qbank): array {
return [
new export_xml_action_column($qbank)
new export_xml_action($qbank)
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace qbank_history;

use core_question\local\bank\menu_action_column_base;
use core_question\local\bank\question_action_base;

/**
* Question bank column for the history action icon.
Expand All @@ -26,7 +26,7 @@
* @author Safat Shahin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class history_action_column extends menu_action_column_base {
class history_action extends question_action_base {

// Store this lang string for performance.
protected $strpreview;
Expand All @@ -36,14 +36,6 @@ public function init(): void {
$this->strpreview = get_string('history_action', 'qbank_history');
}

public function get_extra_classes(): array {
return ['pr-3'];
}

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
Expand Down
11 changes: 9 additions & 2 deletions question/bank/history/classes/plugin_feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace qbank_history;

use core_question\local\bank\view;

/**
* Class plugin_feature is the entrypoint for the columns.
*
Expand All @@ -28,8 +30,13 @@ 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)
new version_number_column($qbank),
];
}

public function get_question_actions(view $qbank): array {
return [
new history_action($qbank),
];
}

Expand Down
22 changes: 6 additions & 16 deletions question/bank/history/classes/question_history_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ public function __construct(question_edit_contexts $contexts, moodle_url $pageur
$this->basereturnurl = new \moodle_url($returnurl);
}

protected function init_question_actions(): void {
parent::init_question_actions();
unset($this->questionactions['qbank_history\history_action']);
}

protected function wanted_columns(): array {
$this->requiredcolumns = [];
$excludefeatures = [
'question_usage_column',
'history_action_column'
];
$questionbankcolumns = $this->get_question_bank_plugins();
foreach ($questionbankcolumns as $classobject) {
Expand Down Expand Up @@ -128,21 +132,7 @@ protected function default_sort(): array {

protected function build_query(): void {
// Get the required tables and fields.
$joins = [];
$fields = ['qv.status', 'qv.version', 'qv.id as versionid', 'qbe.id as questionbankentryid'];
if (!empty($this->requiredcolumns)) {
foreach ($this->requiredcolumns as $column) {
$extrajoins = $column->get_extra_joins();
foreach ($extrajoins as $prefix => $join) {
if (isset($joins[$prefix]) && $joins[$prefix] != $join) {
throw new \coding_exception('Join ' . $join . ' conflicts with previous join ' . $joins[$prefix]);
}
$joins[$prefix] = $join;
}
$fields = array_merge($fields, $column->get_required_fields());
}
}
$fields = array_unique($fields);
[$fields, $joins] = $this->get_component_requirements(array_merge($this->requiredcolumns, $this->questionactions));

// Build the order by clause.
$sorts = [];
Expand Down
4 changes: 2 additions & 2 deletions question/bank/previewquestion/classes/plugin_feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
*/
class plugin_feature extends \core_question\local\bank\plugin_features_base{

public function get_question_columns($qbank): array {
public function get_question_actions($qbank): array {
return [
new preview_action_column($qbank)
new preview_action($qbank)
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace qbank_previewquestion;

use core_question\local\bank\menu_action_column_base;
use core_question\local\bank\question_action_base;

/**
* Question bank columns for the preview action icon.
Expand All @@ -26,7 +26,7 @@
* @author 2021 Safat Shahin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class preview_action_column extends menu_action_column_base {
class preview_action extends question_action_base {

/**
* @var string store this lang string for performance.
Expand All @@ -38,10 +38,6 @@ public function init(): void {
$this->strpreview = get_string('preview');
}

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

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
Expand Down
4 changes: 2 additions & 2 deletions question/bank/tagquestion/classes/plugin_feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
*/
class plugin_feature extends plugin_features_base{

public function get_question_columns($qbank): array {
public function get_question_actions($qbank): array {
return [
new tags_action_column($qbank),
new tags_action($qbank),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

namespace qbank_tagquestion;

use core_question\local\bank\action_column_base;
use core_question\local\bank\menuable_action;
use core_question\local\bank\question_action_base;

/**
* Action to add and remove tags to questions.
Expand All @@ -27,7 +26,7 @@
* @author 2021 Safat Shahin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tags_action_column extends action_column_base implements menuable_action {
class tags_action extends question_action_base {

/**
* @var string store this lang string for performance.
Expand Down Expand Up @@ -56,10 +55,6 @@ protected function check_tags_status(): void {
}
}

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

protected function display_content($question, $rowclasses): void {
global $OUTPUT;

Expand Down
Loading

0 comments on commit 359bb7e

Please sign in to comment.