You are here

function course_get_course_object_by_id in Course 6

Same name and namespace in other branches
  1. 8.3 course.module \course_get_course_object_by_id()
  2. 8.2 course.module \course_get_course_object_by_id()
  3. 7.2 course.module \course_get_course_object_by_id()
  4. 7 course.module \course_get_course_object_by_id()
  5. 3.x course.module \course_get_course_object_by_id()

Get a course object by its identifier.

Parameters

int $coid: The numeric ID of the course object.

stdClass $account: If specified the CourseObject will be loaded with this user (for access and fulfillment tracking).

Return value

CourseObject|FALSE A loaded CourseObject or FALSE if no object found.

12 calls to course_get_course_object_by_id()
CourseObjectBookTestCase::testBookCourseObject in modules/course_book/course_book.test
CourseObjectQuizTestCase::testQuizCourseObject in modules/course_quiz/course_quiz.test
CourseObjectTestCase::testCourseObjectBasicCrud in tests/CourseObjectTestCase.test
Test basic save/load of CourseObjects.
CourseObjectTestCase::testCourseObjectConfigurations in tests/CourseObjectTestCase.test
Test CourseObject configurations.
CourseObjectWebformTestCase::testWebformCourseObject in modules/course_webform/course_webform.test

... See full list

File

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

Code

function course_get_course_object_by_id($coid, $account = NULL, $course = NULL) {
  if (!$account) {
    global $user;
    $account = $user;
  }
  $available = course_get_handlers('object');
  if (!is_numeric($coid)) {
    return _course_get_course_object_by_uniqid($coid, $account, $course);
  }
  $result = db_query('SELECT * FROM {course_outline} WHERE coid = %d', $coid);
  if ($row = db_fetch_object($result)) {
    $ret = $available[$row->module][$row->object_type];
    if (!class_exists($ret['class'])) {
      drupal_set_message(t("Could not find class for %m-%c!", array(
        '%m' => $row->module,
        '%c' => $row->object_type,
      )), 'error');
      return FALSE;
    }
    else {
      if (!$course) {
        $course = new Course(node_load($row->nid), $account);
      }
      return new $ret['class']($row, $account, $course);
    }
  }
  else {
    return FALSE;
  }
}