You are here

function opigno_quiz_app_preprocess_page in Opigno Quiz App 7

Implements hook_preprocess_page().

File

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

Code

function opigno_quiz_app_preprocess_page(&$vars) {
  $group = og_context('node');
  if (!empty($group['gid'])) {
    $class_context = NULL;
    $node = node_load($group['gid']);

    // Try to get class context
    if ($node->type == "course") {
      global $user;
      if (module_exists("opigno_class_app")) {
        $classes = opigno_class_app_classes_of_course_that_user_is_part_of($node->nid, $user->uid);
        if ($classes) {
          $class = key($classes);
          $node = node_load($class);
        }
        else {

          //Course with no class context
          $vars['group_state']['course'][$node->nid]['quiz'] = opigno_quiz_app_course_lessons_progress_and_time($group['gid']);
          return;
        }
      }
      else {
        $vars['group_state']['course'][$node->nid]['quiz'] = opigno_quiz_app_course_lessons_progress_and_time($group['gid']);
      }
    }
    if ($node->type == "class") {
      if (isset($node->opigno_class_courses[LANGUAGE_NONE])) {
        foreach ($node->opigno_class_courses[LANGUAGE_NONE] as $cindex => $course) {
          $vars['group_state']['course'][$course['target_id']]['quiz'] = opigno_quiz_app_course_lessons_progress_and_time($course['target_id']);
          if (module_exists("opigno_sort_groups")) {
            $vars['group_state']['course'][$course['target_id']]['weight'] = opigno_sort_groups_get_groups_weight($node->nid, $course['target_id']);
          }
        }
      }
    }
  }
  if (isset($vars['node']) && $vars['node']->type == "quiz") {
    if (user_is_logged_in()) {
      $lesson_id = opigno_quiz_app_is_quiz_path(current_path());
      if ($lesson_id) {
        global $user;
        $lesson = node_load($lesson_id);
        $courses_field = field_get_items('node', $lesson, 'og_group_ref');
        if ($courses_field) {
          foreach ($courses_field as $index => $target_id) {

            // When we are at the results page, the $_SESSION results is no loger set so we have to check for that.
            if (isset($_SESSION['quiz_' . $lesson_id]['result_id'])) {
              opigno_quiz_app_course_last_viewed($target_id['target_id'], $lesson_id, $_SESSION['quiz_' . $lesson_id]['result_id'], $user->uid);
            }
          }
        }
      }
    }
  }
}