course_certificate.module in Course 7
File
modules/course_certificate/course_certificate.module
View source
<?php
function course_certificate_course_outline_completion_links_alter(&$links, $node, $account) {
$course = course_get_course($node);
if (course_certificate_course_has_certificate($course)) {
$links['certificate'] = array(
t('Download certificate'),
"node/{$node->nid}/certificate",
t('Download a PDF of your certificate.'),
);
}
}
function course_certificate_course_has_certificate($course) {
foreach ($course
->getObjects() as $courseObject) {
if ($courseObject
->getComponent() == 'certificate') {
return TRUE;
}
}
return FALSE;
}
function course_certificate_access_certificate($node, $user) {
if (course_node_is_course($node)) {
$course = course_get_course($node);
$has_certificate = course_certificate_course_has_certificate($course);
return $has_certificate && (bool) db_query("SELECT 1 FROM {course_report} WHERE nid = :nid AND uid = :uid AND complete = :complete", array(
':nid' => $node->nid,
':uid' => $user->uid,
':complete' => 1,
))
->fetchField();
}
}
function course_certificate_course_handlers() {
return array(
'object' => array(
'certificate' => array(
'name' => t('Certificate'),
'description' => t('A certificate course object.'),
'class' => 'CourseObjectCertificate',
),
),
);
}