#82 Do not assume $COURSE represents the course for the certificate
This commit is contained in:
parent
90109a881e
commit
b067d398dd
6 changed files with 157 additions and 20 deletions
|
@ -352,4 +352,29 @@ class element_helper {
|
|||
|
||||
return $sequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that returns the course id for this element.
|
||||
*
|
||||
* @param int $elementid The element id
|
||||
* @return int The course id
|
||||
*/
|
||||
public static function get_courseid($elementid) {
|
||||
global $DB, $SITE;
|
||||
|
||||
$sql = "SELECT course
|
||||
FROM {customcert} c
|
||||
INNER JOIN {customcert_pages} cp
|
||||
ON c.templateid = cp.templateid
|
||||
INNER JOIN {customcert_elements} ce
|
||||
ON cp.id = ce.pageid
|
||||
WHERE ce.id = :elementid";
|
||||
|
||||
// Check if there is a course associated with this element.
|
||||
if ($course = $DB->get_record_sql($sql, array('elementid' => $elementid))) {
|
||||
return $course->course;
|
||||
} else { // Must be in a site template.
|
||||
return $SITE->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue