-
Notifications
You must be signed in to change notification settings - Fork 325
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for moodledevdocs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
There was a problem hiding this 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.
Ah! but I see taht the automated checks need to be appeased. |
4d0a913
to
ce8e3fb
Compare
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.
ce8e3fb
to
606e80b
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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:
```php | |
```php title="question/bank/myplugin/classes/myfilter_condition.php" |
```php | ||
public function get_name(): string { | ||
return get_string('myfilter_name', 'myplugin'); | ||
} |
There was a problem hiding this comment.
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.
```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
```php | |
public function get_name(): string { | |
return get_string('myfilter_name', 'myplugin'); | |
} | |
```php | |
public function get_name(): string { | |
return get_string('myfilter_name', 'myplugin'); | |
} |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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:
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) |
There was a problem hiding this comment.
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?
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.