You are here

quiz_stats.module in Quiz 6.4

Quiz stats

Module creates a report to analyse and compare the results of quiz attendees.

File

includes/quiz_stats/quiz_stats.module
View source
<?php

/**
 * @file
 * Quiz stats
 *
 * Module creates a report to analyse and compare the results of quiz attendees.
 */

/**
 * Implementation of hook_help().
 */
function quiz_stats_help($path, $arg) {
  if ($path == 'admin/help#quiz_stats') {
    return '<p>' . t('Module creates a report to analyse and compare the results of quiz attendees. The reports will be displayed visually using goolge chart API.') . '</p>';
  }
}

/**
 * Implementation of hook_perm()
 */
function quiz_stats_perm() {
  $permission = array(
    'access user stats',
    'access author stats',
  );
  return $permission;
}

/**
 * Implementation of hook_menu()
 */
function quiz_stats_menu() {
  global $user;
  $items = array();
  $items['admin/quiz/reports/stats/creator'] = array(
    'title' => 'Quiz Statistics',
    'description' => 'Generates a report on quiz results for quiz creators.',
    'file' => 'quiz_stats.admin.inc',
    'page callback' => 'quiz_stats_get_basic_stats',
    'access arguments' => array(
      'access author stats',
    ),
    'type' => MENU_NORMAL_ITEM,
  );
  $items['node/%node/statistics'] = array(
    'title' => 'Statistics',
    'description' => 'Generates a report on quiz results for quiz creators.',
    'file' => 'quiz_stats.admin.inc',
    'page callback' => 'quiz_stats_revision_selector_page',
    'page arguments' => array(
      1,
    ),
    'access callback' => 'quiz_type_confirm',
    'access arguments' => array(
      1,
      'access user stats',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 4,
  );
  $items['node/%node/statistics/%'] = array(
    'title' => 'Statistics',
    'description' => 'Generates a report on quiz results for quiz creators.',
    'file' => 'quiz_stats.admin.inc',
    'page callback' => 'quiz_stats_get_adv_stats',
    'page arguments' => array(
      3,
    ),
    'access callback' => 'quiz_stats_validate_vid',
    'access arguments' => array(
      1,
      3,
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 4,
  );
  $items['user/%/stats'] = array(
    'title' => 'Result Statistics',
    'description' => 'Generates a report on quiz results for quiz creators.',
    'file' => 'quiz_stats.admin.inc',
    'page callback' => 'quiz_stats_get_basic_stats',
    'page arguments' => array(
      1,
    ),
    'access arguments' => array(
      'access user stats',
    ),
    'type' => MENU_LOCAL_TASK,
  );
  $items['user/%/stats/%/view'] = array(
    'title' => 'Result Statistics',
    'file' => 'quiz_stats.admin.inc',
    'page callback' => 'quiz_stats_get_adv_stats',
    'page arguments' => array(
      3,
      1,
    ),
    'access arguments' => array(
      'access user stats',
    ),
    'type' => MENU_LOCAL_TASK,
  );
  return $items;
}

/**
 * Implementation of hook_theme().
 */
function quiz_stats_theme() {
  return array(
    'quiz_stats_get_basic_stats' => array(
      'arguments' => array(
        'results' => NULL,
      ),
      'file' => 'quiz_stats.admin.inc',
    ),
    'date_vs_takeup_count' => array(
      'arguments' => array(
        'takeup' => NULL,
      ),
      'file' => 'quiz_stats.admin.inc',
    ),
    'get_quiz_status_chart' => array(
      'arguments' => array(
        'quiz' => NULL,
      ),
      'file' => 'quiz_stats.admin.inc',
    ),
    'quiz_top_scorers' => array(
      'arguments' => array(
        'scorer' => NULL,
      ),
      'file' => 'quiz_stats.admin.inc',
    ),
    'quiz_grade_range' => array(
      'arguments' => array(
        'range' => NULL,
      ),
      'file' => 'quiz_stats.admin.inc',
    ),
    'quiz_stats_revision_selector' => array(
      'arguments' => array(
        'content' => NULL,
      ),
      'path' => drupal_get_path('module', 'quiz_stats') . '/theme',
      'template' => 'quiz_stats_revision_selector',
    ),
    'quiz_stats_charts' => array(
      'arguments' => array(
        'charts' => NULL,
      ),
      'path' => drupal_get_path('module', 'quiz_stats') . '/theme',
      'template' => 'quiz_stats_charts',
    ),
  );
}

/**
 * Validate that a node is of type quiz, and that the user has access to it, and that the vid is a vid of that quiz
 *
 * @param $quiz
 *  The quiz node
 * @param $vid
 *  The version id
 * @return
 *  TRUE if user has access
 */
function quiz_stats_validate_vid($quiz, $vid) {
  if ($quiz->type != 'quiz') {
    return FALSE;
  }
  if (!user_access('access author stats')) {
    return FALSE;
  }
  $sql = db_rewrite_sql('SELECT n.nid
     FROM {node} n
     WHERE n.nid = (
       SELECT nr.nid
       FROM {node_revisions} nr
       WHERE nr.vid = %d
     )');
  $nid = db_result(db_query($sql, $vid));
  return $quiz->nid == $nid;
}

Functions

Namesort descending Description
quiz_stats_help Implementation of hook_help().
quiz_stats_menu Implementation of hook_menu()
quiz_stats_perm Implementation of hook_perm()
quiz_stats_theme Implementation of hook_theme().
quiz_stats_validate_vid Validate that a node is of type quiz, and that the user has access to it, and that the vid is a vid of that quiz