Writing Quizzes in other programming languages

Re: Writing Quizzes in other programming languages

by Charlie Daly -
Number of replies: 2
I discovered the answer and am documenting it here in case someone else needs it. It seems that the category id is stored in the category field. You can get the category using:


        $cat_id = $this->category;

        $query = $DB->get_record_sql('select name from mdl_question_categories where id="' . $cat_id . '"');

        print($query->name);


In reply to Charlie Daly

Re: Writing Quizzes in other programming languages

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Thanks for posting Charlie, that should work but you should consider something like

$DB->get_record('question_categories',['id'=>$cat_id)  

Then it will work if someone has a prefix other than mdl.

See 

https://docs.moodle.org/dev/Data_manipulation_API#Main_info

I suspect most people most of the time leave the default mdl_ but  it is nice to cover unusual situations.




In reply to Marcus Green

Re: Writing Quizzes in other programming languages

by Charlie Daly -

Thanks Marcus,

It's good to see an elegant approach.

Average of ratings: Useful (1)