Skip to content

[MDL-80945] Update quizaccess page #1410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/main/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"qbank": "public/question/bank",
"qbehaviour": "public/question/behaviour",
"qformat": "public/question/format",
"quizaccess": "public/mod/quiz/access",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this - it is wrong.

The new component is a subplugin of mod_quiz and not a global plugin type.
The content of this file is automatically pulled in.

"plagiarism": "public/plagiarism",
"tool": "public/admin/tool",
"cachestore": "public/cache/stores",
Expand Down
4 changes: 4 additions & 0 deletions docs/apis/plugintypes/quizaccess/_examples/override_rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- markdownlint-disable first-line-heading -->
Most quiz settings can be overridden on a per user and/or group level and you can extend this ability to your rule as well. To make your rule overridable, you must create the `override_rule` class extending `mod_quiz\local\access_override_rule_base`.

Please refer to the inline phpdocs of the [mod_quiz::access_override_rule_base class](https://github.com/moodle/moodle/blob/main/mod/quiz/classes/local/access_override_rule_base.php) for detailed descriptions of the functions and meaning.
48 changes: 48 additions & 0 deletions docs/apis/plugintypes/quizaccess/_examples/override_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use mod_quiz\local\access_override_rule_base;
use MoodleQuickForm;
use context_module;
use context;

class override_rule extends access_override_rule_base {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pass this file through the code style checker and fix it.

It's worth noting tha twe also tend to further reduce line length limits to around 80 characters in docs because the way that code scrolls left-to-right makes it hard to view things in context.

/**
* All of the below access_override_rule_base functions to be implemented.
*/

public static function add_form_fields(context_module $context, int $overrideid, object $quiz, MoodleQuickForm $mform): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of exagerated line length limit:

Suggested change
public static function add_form_fields(context_module $context, int $overrideid, object $quiz, MoodleQuickForm $mform): void {
public static function add_form_fields(
context_module $context,
int $overrideid,
object $quiz,
MoodleQuickForm $mform,
): void {

// Do nothing.
}

public static function validate_form_fields(array $errors,
array $data, array $files, context_module $context): array {
Comment on lines +16 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This coding style is not accepted in Moodle core code any more.

return [];
}

public static function save_settings(array $override): void {
// Do nothing.
}

public static function delete_settings(int $quizid, array $overrides): void {
// Do nothing.
}

public static function get_settings(): array {
return [];
}

public static function get_required_settings(): array {
return [];
}

public static function get_settings_sql(string $overridetablename): array {
return [];
}

public static function add_table_fields(object $override, array $fields, array $values, context $context): array {
return [];
}

public static function clean_form_data(array $formdata): array {
return $formdata;
}
}
1 change: 0 additions & 1 deletion docs/apis/plugintypes/quizaccess/_examples/rule.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use mod_quiz\form\edit_override_form;
use mod_quiz\form\preflight_check_form;
use mod_quiz\quiz_settings;
use mod_quiz\local\access_rule_base;
Expand Down

This file was deleted.

100 changes: 0 additions & 100 deletions docs/apis/plugintypes/quizaccess/_examples/rule_overridable.php

This file was deleted.

20 changes: 11 additions & 9 deletions docs/apis/plugintypes/quizaccess/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Quiz access rule sub-plugins
title: Quiz access rules
tags:
- Quiz
- Access
Expand All @@ -11,7 +11,7 @@ tags:

import { ComponentFileSummary } from '../../../_utils';

Quiz access rule sub-plugins extend the ability to add conditions a user must meet to attempt a given quiz.
Quiz access rules give the ability to add conditions a user must meet to attempt a given quiz.

The following rules are readily available as part of Moodle core:

Expand Down Expand Up @@ -67,20 +67,22 @@ import RuleDescription from './_examples/rule.md';
description={RuleDescription}
/>

import RuleOverridableFile from '!!raw-loader!./_examples/rule_overridable.php';
import RuleOverridableDescription from './_examples/rule_overridable.md';
### classes/override_rule.php

import OverrideRuleFile from '!!raw-loader!./_examples/override_rule.php';
import OverrideRuleDescription from './_examples/override_rule.md';

<ComponentFileSummary
filepath="/rule.php"
summary="Rule definition class with override"
filepath="/classes/override_rule.php"
summary="Override rule definition class"
plugintype="quizaccessrule"
pluginname="pluginname"
example={RuleOverridableFile}
description={RuleOverridableDescription}
example={OverrideRuleFile}
description={OverrideRuleDescription}
/>

:::info

Implementing `rule_overridable` is not required but can enhance the usability of the rule.
Implementing `override_rule` is not required but can enhance the usability of the access rule.

:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- markdownlint-disable first-line-heading -->
Most quiz settings can be overridden on a per user and/or group level and you can extend this ability to your rule as well. To make your rule overridable, you must create the `override_rule` class extending `mod_quiz\local\access_override_rule_base`.

Please refer to the inline phpdocs of the [mod_quiz::access_override_rule_base class](https://github.com/moodle/moodle/blob/main/mod/quiz/classes/local/access_override_rule_base.php) for detailed descriptions of the functions and meaning.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use mod_quiz\form\edit_override_form;
use mod_quiz\local\access_override_rule_base;
use MoodleQuickForm;
use context_module;
use context;

class override_rule extends access_override_rule_base {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto the other exampels


/**
* All of the below access_override_rule_base be implemented below.
*/

public static function add_form_fields(context_module $context, int $overrideid, object $quiz, MoodleQuickForm $mform): void {
// Do nothing.
}

public static function validate_form_fields(array $errors,
array $data, array $files, edit_override_form $quizform): array {
return [];
}

public static function save_settings(array $override): void {
// Do nothing.
}

public static function delete_settings(int $quizid, array $overrides): void {
// Do nothing.
}

public static function get_settings(): array {
return [];
}

public static function get_required_settings(): array {
return [];
}

public static function get_settings_sql(string $overridetablename): array {
return [];
}

public static function add_table_fields(object $override, array $fields, array $values, context $context): array {
return [];
}

public static function clean_form_data(array $formdata): array {
return $formdata;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use mod_quiz\form\edit_override_form;
use mod_quiz\form\preflight_check_form;
use mod_quiz\quiz_settings;
use mod_quiz\local\access_rule_base;
Expand Down

This file was deleted.

This file was deleted.

Loading