You are here

function opigno_class_app_class_results in Opigno Class App 7

Page callback: display class results.

1 string reference to 'opigno_class_app_class_results'
opigno_class_app_menu in ./opigno_class_app.module
Implements hook_menu().

File

./opigno_class_app.module, line 187
Module hooks.

Code

function opigno_class_app_class_results() {
  global $user;
  $html = '';

  // Failsafe.
  if (!module_exists('opigno_quiz_app')) {
    return t("This page requires the Opigno Quiz App to be enabled.");
  }

  // Cache accounts, as we will potentially use them many times.
  $accounts = array();
  $state = isset($_SESSION['opigno_quiz_app']['state_filter'][request_path()]) ? $_SESSION['opigno_quiz_app']['state_filter'][request_path()] : OG_STATE_ACTIVE;
  foreach (og_get_groups_by_user($user, 'node') as $gid => $nid) {
    $node = node_load($nid);
    if ($node->type == 'class' && og_user_access('node', $nid, 'access class results')) {
      $rows = array();
      $scores = array();
      foreach ($node->opigno_class_courses as $lang => $items) {
        foreach ($items as $item) {
          foreach (opigno_get_users_in_group($item['target_id'], $state) as $uid => $account) {
            if (og_is_member('node', $nid, 'user', $account)) {
              if ($data = opigno_quiz_app_get_course_data_result($uid, $item['target_id'])) {
                $course = node_load($item['target_id']);
                $scores[$uid][$course->title] = $data;
                $scores[$uid][$course->title]['node'] = $course;
                $accounts[$uid] = $account;
              }
            }
          }
        }
      }
      foreach ($scores as $uid => $course_results) {
        $passed = OPIGNO_QUIZ_APP_PASSED;
        foreach ($course_results as $results) {
          if (!empty($results['passed']) && $results['passed'] != OPIGNO_QUIZ_APP_PASSED) {
            $passed = $results['passed'];
            break;
          }
        }
        $rows[] = array(
          theme('table', array(
            'header' => array(
              t("@name (!status)", array(
                '@name' => $accounts[$uid]->name,
                '!status' => $passed == OPIGNO_QUIZ_APP_PASSED ? t("Passed") : ($passed == OPIGNO_QUIZ_APP_FAILED ? t("Failed") : t("Pending")),
              )),
            ),
            'rows' => array(
              array(
                theme('opigno_quiz_app_user_results', array(
                  'user' => $accounts[$uid],
                  'results' => $course_results,
                )),
              ),
            ),
            'attributes' => array(
              'class' => array(
                'opigno-quiz-app-results-table',
                'opigno-quiz-app-results-collapsible-table',
                'opigno-quiz-app-course-class-user-results-table',
              ),
            ),
          )),
        );
      }
      $header = array(
        check_plain($node->title),
      );
      $html .= theme('table', array(
        'header' => $header,
        'rows' => $rows,
        'attributes' => array(
          'class' => array(
            'opigno-quiz-app-results-table',
            'opigno-quiz-app-results-collapsible-table',
            'opigno-quiz-app-course-class-results-table',
          ),
        ),
      ));
    }
  }
  module_load_include('inc', 'opigno_quiz_app', 'includes/opigno_quiz_app.pages');
  $path = drupal_get_path('module', 'opigno_quiz_app');
  drupal_add_js($path . '/js/opigno_quiz_app.js');
  drupal_add_css($path . '/css/opigno_quiz_app.css');
  $form = drupal_get_form('opigno_quiz_app_filter_by_status_form');
  return render($form) . $html;
}