You are here

function course_enrolment_save in Course 6

Create or update an enrolment.

5 calls to course_enrolment_save()
CourseAccessTestCase::testDurationExpiration in tests/CourseAccessTestCase.test
Test the enrollment duration. This does not test the enrollment end date being set correctly.
course_edit_enrollment_action in ./course.module
Edit enrolment action
course_enrol in ./course.module
Enrols a user in a course.
course_take_course in ./course.module
Take a course.
course_user_type_form_submit in ./course.module
Save the user's type in the course.

File

./course.module, line 1459
course.module Core functionality for Courses.

Code

function course_enrolment_save($enrolment) {
  if ($enrolment->nid && $enrolment->uid) {
    if (db_result(db_query('SELECT 1 FROM {course_enrolment} WHERE nid = %d AND uid = %d', $enrolment->nid, $enrolment->uid))) {
      drupal_write_record('course_enrolment', $enrolment, array(
        'nid',
        'uid',
      ));
    }
    else {
      if (!isset($enrolment->created) || $enrolment->created == 0) {
        $enrolment->created = time();
      }
      drupal_write_record('course_enrolment', $enrolment);
    }
  }
  else {
    return FALSE;
  }
}