Tim, I'm using question_category_options to get a list of question categories from which I generate options for mform select. I can get context instances for system/courses/modules so as to retrieve the respective categories as they appear in the qbank. But the qbank also allows categories in course category contexts. How do I retrieve these categories?
General developer forum
I am using question_edit_contexts with a course context to populate a mform questioncategory element.
my $contexts variable returns count 1 but returns nothing in a foreach statement. The SQL to build the dropdown returns an error as the array is empty.
The end purpose is to have a nicely formatted drop down to use as a question category filter in a sql customizable_report.
I guess what I'm asking is why I only get one context and why that one context is not displayed in the drop down.
This was previously working when I populated the list direct from SQL with all question categories.
I suggest you look at the code in the quistion bank that successfully dose what you want. E.g. question/category_form.php
Thank you. Pretty much what I had been doing. Got my answer.
I passed '$contexts->having_add_and_use()' to the questioncategory form element, instead of simply '$contexts'. The same code also allowed me to do a foreach loop which I was using for debugging.