You are here

function quiz_stats_revision_selector_page in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 modules/quiz_stats/quiz_stats.admin.inc \quiz_stats_revision_selector_page()
  2. 8.4 modules/quiz_stats/quiz_stats.admin.inc \quiz_stats_revision_selector_page()
  3. 8.5 modules/quiz_stats/quiz_stats.admin.inc \quiz_stats_revision_selector_page()
  4. 6.4 includes/quiz_stats/quiz_stats.admin.inc \quiz_stats_revision_selector_page()
  5. 7.6 modules/quiz_stats/quiz_stats.admin.inc \quiz_stats_revision_selector_page()
  6. 7 includes/quiz_stats/quiz_stats.admin.inc \quiz_stats_revision_selector_page()
  7. 7.4 includes/quiz_stats/quiz_stats.admin.inc \quiz_stats_revision_selector_page()
  8. 7.5 modules/quiz_stats/quiz_stats.admin.inc \quiz_stats_revision_selector_page()

Page for selecting between several quiz revisions.

Parameters

$nid Quiz node id.:

Return value

Themed html.

1 string reference to 'quiz_stats_revision_selector_page'
quiz_stats_menu in modules/quiz_stats/quiz_stats.module
Implements hook_menu().

File

modules/quiz_stats/quiz_stats.admin.inc, line 15
Administration file for Quiz stats Module.

Code

function quiz_stats_revision_selector_page($quiz) {

  // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
  // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
  $res = \Drupal::database()
    ->query('SELECT vid FROM {node_revision} WHERE nid = :nid ORDER BY vid', [
    ':nid' => $quiz->nid,
  ]);

  // Uses this variable to slightly increase performance.
  $count = 0;
  $vids = [];
  while ($res_o = $res
    ->fetch()) {
    $vids[] = $res_o->vid;
    $count++;
  }
  if ($count < 1) {
    return t('Something went wrong. Please try again');
  }
  elseif ($count == 1) {

    // If there is only one revision we jump directly to that revision.
    drupal_goto("quiz/{$quiz->nid}/quiz/statistics/{$vids[0]}");
  }
  else {
    $content = [];
    $content['explanation'] = t('There are !num revisions of this quiz that have been taken.
    Different revisions may have different scoring, difficulity and other differences affecting its statistics.
    Because of this you have to choose the revision you want to see statistics from.', [
      '!num' => $count,
    ]);
    $content['links'] = [];
    foreach ($vids as $key => $value) {
      $content['links'][] = 'quiz/' . $quiz->nid . '/quiz/statistics/' . $value;
    }
    return theme('quiz_stats_revision_selector', [
      'content' => $content,
    ]);
  }
}