You are here

function opigno_quiz_app_courses_results in Opigno Quiz App 7

Page callback: view all user results for all courses (where allowed).

Return value

string

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

File

includes/opigno_quiz_app.pages.inc, line 101
Defines all page callbacks.

Code

function opigno_quiz_app_courses_results() {
  global $user;
  $html = '';
  $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 == OPIGNO_COURSE_BUNDLE) {
      $scores = array();
      foreach (opigno_get_users_in_group($node->nid, $state) as $uid => $account) {

        // Only display results for roles that don't have the 'skip display of results' permission.
        if (!og_user_access('node', $nid, 'skip display of results', $account, FALSE, TRUE) && ($data = opigno_quiz_app_get_course_data_result($uid, $node->nid, TRUE))) {
          $scores[$uid] = $data;
          $scores[$uid]['user'] = $account;
        }
      }

      // Are there any results to show ?
      if (!empty($scores)) {
        $header = array(
          'data' => check_plain($node->title),
        );
        $rows = array(
          array(
            theme('opigno_quiz_app_course_results', array(
              'course' => $node,
              'results' => $scores,
            )),
          ),
        );
        $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-all-courses-user-results-table',
            ),
          ),
        ));
      }
    }
  }
  $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 = render(drupal_get_form('opigno_quiz_app_filter_by_status_form'));
  return $form . $html;
}