General developer forum

Getting question categories from course category contexts

 
 
Picture of Itamar Tzadok
Getting question categories from course category contexts
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

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? smile

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Getting question categories from course category contexts
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

Get the context instance for that course category.

 
Average of ratings: -
Picture of Itamar Tzadok
Re: Getting question categories from course category contexts
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

Of coursecat. smile

 
Average of ratings: -
Picture of Andrew Sadler
Re: Getting question categories from course category contexts
 

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.

 

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Getting question categories from course category contexts
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

I suggest you look at the code in the quistion bank that successfully dose what you want. E.g. question/category_form.php

 
Average of ratings: -
Picture of Andrew Sadler
Re: Getting question categories from course category contexts
 

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.

 
Average of ratings: -
Picture of jasi jasi
Re: Getting question categories from course category contexts
 

Hi Mr.Andrew Sadler....


i'm using moodle 2.6

in my custom form, i have to implement that question categories dropdown. i make that via query but i need as on source code i tried a week but still cant understand the procedure of moodle. can u help me if u know? plz

 
Average of ratings: -