I'm trying to draw a list of courses and the badges awarded for completing the course. My badges criteria is set to be awarded when a (one) course is completed.
In /lib/badgelib.php there's a routine badges_get_user_badges($userid, $courseid = 0, $page = 0, $perpage = 0, $search = '', $onlypublic = false) which at first appearance is what I thought I was looking for. But when I pass in the user and course it doesn't return.
It turns out there are two wants to issue the badges for a course. One, you can go through admin and create the new badge and then specify the criteria for it such as "completing one or more courses". This is what I did, and the record in mdl_badge doesn't have a courseid set - it is null. If I first open the course, then edit in a new badge that way, the mdl_badge.courseid value does get set, and the badges_get_user_badges() is populated.
Seems like I've created badges for a courseset rather than a course. After a bit of thought I feel like if a single instance of a course is part of a criteria that includes one or more courses and the badge is awarded, then it should show the badge. badges_get_user_badges() doesn't go that far in determining the the course id passed is part of a set whose criteria complete the badge.
Is there a method somewhere that lets me figure out all the nastywork of joining criterias together back to a course, then cross-comparing that with an issue to filter against a user? Or is there a reason why I shouldn't be doing this?