MDL-68252 question bank: for 'missingtype' questions, hide actions
This commit is contained in:
@@ -53,6 +53,8 @@ abstract class action_column_base extends column_base {
|
||||
|
||||
public function get_required_fields() {
|
||||
// Createdby is required for permission checks.
|
||||
return array('q.id', 'q.createdby', 'qc.contextid');
|
||||
// Qtype so we can easily avoid applying actions to question types that
|
||||
// are no longer installed.
|
||||
return ['q.id', 'q.qtype', 'q.createdby', 'qc.contextid'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,13 @@ class copy_action_column extends menu_action_column_base {
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
// To copy a question, you need permission to add a question in the same
|
||||
// category as the existing question, and ability to access the details of
|
||||
// the question being copied.
|
||||
|
||||
@@ -47,6 +47,13 @@ class edit_action_column extends menu_action_column_base {
|
||||
}
|
||||
|
||||
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, 'edit')) {
|
||||
return [$this->qbank->edit_question_moodle_url($question->id), 't/edit', $this->stredit];
|
||||
} else if (question_has_capability_on($question, 'view')) {
|
||||
|
||||
@@ -46,6 +46,13 @@ class export_xml_action_column extends menu_action_column_base {
|
||||
}
|
||||
|
||||
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, 'view')) {
|
||||
return [null, null, null];
|
||||
}
|
||||
|
||||
@@ -49,6 +49,14 @@ class preview_action_column extends action_column_base implements menuable_actio
|
||||
|
||||
protected function display_content($question, $rowclasses) {
|
||||
global $PAGE;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (question_has_capability_on($question, 'use')) {
|
||||
echo $PAGE->get_renderer('core_question')->question_preview_link(
|
||||
$question->id, $this->qbank->get_most_specific_context(), false);
|
||||
@@ -56,6 +64,13 @@ class preview_action_column extends action_column_base implements menuable_actio
|
||||
}
|
||||
|
||||
public function get_action_menu_link(\stdClass $question): ?\action_menu_link {
|
||||
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;
|
||||
}
|
||||
|
||||
if (!question_has_capability_on($question, 'use')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user