You are here

function course_enrollment_save in Course 7

Same name and namespace in other branches
  1. 7.2 course.module \course_enrollment_save()

Create or update an enrollment.

4 calls to course_enrollment_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 enrollment action
course_take_course in ./course.module
Take a course.
course_uc_enroll_user_in_ordered_courses in modules/course_uc/course_uc.module
Loops through items in an Ubercart order and enrolls the user in courses purchased.

File

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

Code

function course_enrollment_save($enrollment) {
  if ($enrollment->nid && $enrollment->uid) {
    if ($eid = db_query('SELECT eid FROM {course_enrollment} WHERE nid = :nid AND uid = :uid', array(
      ':nid' => $enrollment->nid,
      ':uid' => $enrollment->uid,
    ))
      ->fetchField()) {
      $enrollment->eid = $eid;
      unset($enrollment->is_new);
    }
    if (!isset($enrollment->type)) {
      $node = node_load($enrollment->nid);
      $enrollment->type = $node->course['enrollment_type'];
    }
    entity_save('course_enrollment', $enrollment);
  }
  else {
    return FALSE;
  }
}