function course_take_course in Course 6
Same name and namespace in other branches
- 7.2 course.module \course_take_course()
- 7 course.module \course_take_course()
Take a course.
- Enroll the user, if allowed.
- Block the user if not allowed.
- Fire the outline handler.
2 calls to course_take_course()
- CourseEnrollmentTestCase::testCourseDuration in tests/
CourseEnrollmentTestCase.test - Test for course duration being set properly on enrollment.
- CourseEnrollmentTestCase::testCourseEnrollment in tests/
CourseEnrollmentTestCase.test - Test for enrollment access and timestamping.
1 string reference to 'course_take_course'
- course_menu in ./
course.module - Implements hook_menu().
File
- ./
course.module, line 1397 - course.module Core functionality for Courses.
Code
function course_take_course($node) {
global $user;
drupal_set_title($node->title);
$result = course_enrol_access($node);
$enrolment = course_enrolment_load($node, $user);
// Check enroll access or if user is already enrolled.
if ($result['success'] || $enrolment->status) {
$result = course_take_course_access($node);
}
if ($result['success'] === TRUE) {
if (empty($enrolment->eid)) {
// User has access to take this course, but they haven't been enrolled. So
// enroll them now.
$enrolment = course_enrol($node, $user);
}
if (empty($enrolment->timestamp)) {
// If user hasn't started course, mark start of enrolment.
$enrolment->timestamp = time();
course_enrolment_save($enrolment);
drupal_set_message(t('Your enrollment in this course has been recorded.'));
}
// Display the configured outline handler output.
$key = isset($node->course['outline']) ? $node->course['outline'] : 'course';
$handlers = course_get_handlers('outline');
foreach ($handlers as $module => $outline_handlers) {
if ($outline_handlers) {
foreach ($outline_handlers as $key2 => $outline_handler) {
if ($key == $key2) {
$callback = $outline_handler['callback'];
}
}
}
}
if (function_exists($callback)) {
$outline = $callback($node, $user);
}
else {
$outline = t('Outline not provided.');
}
if (!$outline) {
$outline = t('No learning objects are available this time.');
}
return $outline;
}
else {
drupal_set_header('HTTP/1.1 403 Forbidden');
drupal_set_title(t('Access denied'));
if (empty($result['message'])) {
return t('Sorry, you do not have access to take this course. (No message provided by module).');
}
return "<h2>" . $result['header'] . "</h2>" . $result['message'];
}
}