You are here

function opigno_quiz_app_course_resume in Opigno Quiz App 7

Page callback for resuming a course.

Redirects to the appropriate lesson.

1 string reference to 'opigno_quiz_app_course_resume'
opigno_quiz_app_menu in ./opigno_quiz_app.module
Implements hook_menu().

File

./opigno_quiz_app.module, line 93
Module file. Defines module hooks.

Code

function opigno_quiz_app_course_resume($node) {
  if ($node->type == 'class') {

    // Get all the courses from the class and check for each if there is a "next lesson".
    // If no courses, return to front page.
    $courses = opigno_class_app_get_class_courses($node);
    if (empty($courses)) {
      drupal_set_message(t('This class does not have any courses.'), 'status', FALSE);
      drupal_goto('node/' . $node->nid);
    }
  }
  else {
    if ($node->type == 'course') {
      $courses = array(
        $node->nid,
      );
    }
    else {
      drupal_goto('<front>');
    }
  }

  // Loop for each course. If one returns a /take, go to this one.
  // Else, keep going in this loop.
  foreach ($courses as $course_nid) {
    $path = opigno_quiz_app_course_resume_get_path($course_nid);
    if ($path != '<front>' && $path != 'node/' . $course_nid && drupal_valid_path($path)) {
      drupal_goto($path);
    }
  }

  // If no courses returned a /take, go to the first lesson of the first course.
  $first_lesson = opigno_quiz_app_get_first_lesson_from_group($node);
  if ($first_lesson != null && drupal_valid_path('node/' . $first_lesson . '/take')) {
    drupal_goto('node/' . $first_lesson . '/take');
  }

  // If no lesson in this course, says that there is no lessons in this group.
  drupal_set_message(t('This @type does not have any lessons.', array(
    '@type' => $node->type,
  )), 'status', FALSE);
  drupal_goto('node/' . $node->nid);
}