Skip to content
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

Add question bank filter API guide #1199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

marxjohnson
Copy link
Contributor

This functionality was added in MDL-72321. MDL-78220 will add several new filters, so this guide may expand as the children of that tracker are developed.

Copy link

netlify bot commented Dec 3, 2024

Deploy Preview for moodledevdocs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 606e80b
🔍 Latest deploy log https://app.netlify.com/sites/moodledevdocs/deploys/674f1f1aaaab320009a892b3
😎 Deploy Preview https://deploy-preview-1199--moodledevdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Dec 3, 2024

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🔴 39 🟢 95 🟢 100 🟢 90 🟢 100 Report
/docs/5.0/apis/commonfiles 🔴 47 🟢 93 🟢 100 🟢 100 🟢 100 Report
/general/development/gettingstarted 🟠 61 🟢 95 🟢 100 🟢 90 🟢 100 Report
/general/releases 🟠 54 🟢 95 🟢 100 🟢 100 🟢 100 Report

Copy link
Collaborator

@timhunt timhunt left a comment

Choose a reason for hiding this comment

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

Thanks Mark. This looks like a good start to documenting this.

@timhunt
Copy link
Collaborator

timhunt commented Dec 3, 2024

Ah! but I see taht the automated checks need to be appeased.

@marxjohnson marxjohnson force-pushed the question-bank-filters branch from 4d0a913 to ce8e3fb Compare December 3, 2024 15:03
This functionality was added in MDL-72321. MDL-78220 will add several
new filters, so this guide may expand as the children of that tracker
are developed.
@marxjohnson marxjohnson force-pushed the question-bank-filters branch from ce8e3fb to 606e80b Compare December 3, 2024 15:09
Copy link
Member

@andrewnicols andrewnicols left a comment

Choose a reason for hiding this comment

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

These docs look generally great. I've left a few comments -- see what you think.

Since these are docs for a 4.3 feature we should backport to 4.3 and 4.4 using the versioned_docs folders. If you need help with this I can do this on the PR -- just let me know.

Thanks


Create a `condition` class within your plugin's namespace. For a plugin called `qbank_myplugin` this would look something like:

```php
Copy link
Member

Choose a reason for hiding this comment

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

I find it's really handy to specify the location of the class in the title, for example:

Suggested change
```php
```php title="question/bank/myplugin/classes/myfilter_condition.php"

Comment on lines +51 to +54
```php
public function get_name(): string {
return get_string('myfilter_name', 'myplugin');
}
Copy link
Member

Choose a reason for hiding this comment

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

Since this example is in isolation, you could either:

  • add the class wrapper to make it clearer; or
  • remove the indent to make it look cleaner in the built code.
Suggested change
```php
public function get_name(): string {
return get_string('myfilter_name', 'myplugin');
}
```php
class myfilter_condition extends condition {
public function get_name(): string {
return get_string('myfilter_name', 'myplugin');
}
}

Or

Suggested change
```php
public function get_name(): string {
return get_string('myfilter_name', 'myplugin');
}
```php
public function get_name(): string {
return get_string('myfilter_name', 'myplugin');
}

Copy link
Member

Choose a reason for hiding this comment

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

You may also want to use the title attribute here, but that's up to you. If you do I wouldn't set it to the filename, but a short sumarry of what you're doing, for example:

title="Define the filter name"

}
```

Define the `get_name` method, which returns the label displayed in the filter UI.
Copy link
Member

Choose a reason for hiding this comment

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

You may also want to consider adding parens to method names:

Suggested change
Define the `get_name` method, which returns the label displayed in the filter UI.
Define the `get_name()` method, which returns the label displayed in the filter UI.

Your call but if you do please do so for all of them.

In your condition class, define `get_filteroptions()` which returns an object containing the current filter options. You will
probably want to add some code to the constructor to read in the current filter options, and some code the `build_query_from_filter`
to use the option. See
[`qbank_managecategories\category_condition`](https://github.com/moodle/moodle/blob/main/question/bank/managecategories/classes/category_condition.php#L331)
Copy link
Member

Choose a reason for hiding this comment

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

Consider making this link point to a specific commit hash, or to just the file as a whole?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants