quiz_stats.module in Quiz 6.x
Quiz stats.
Module creates a report to analyse and compare the results of quiz attendees.
File
modules/quiz_stats/quiz_stats.moduleView source
<?php
/**
* @file
* Quiz stats.
*
* Module creates a report to analyse and compare the results of quiz attendees.
*/
/**
* Implements 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>';
}
}
/**
* Implements hook_permission().
*/
function quiz_stats_permission() {
$permission = [
'access user stats' => [
'title' => t('access user stats'),
],
'access author stats' => [
'title' => t('access author stats'),
],
];
return $permission;
}
/**
* Implements hook_menu().
*/
function quiz_stats_menu() {
$items['admin/quiz/reports/stats/creator'] = [
'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' => [
'access author stats',
],
'type' => MENU_NORMAL_ITEM,
];
$items['quiz/%quiz/quiz/statistics'] = [
'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' => [
1,
],
'access callback' => 'quiz_type_confirm',
'access arguments' => [
1,
'access user stats',
],
'type' => MENU_LOCAL_TASK,
'weight' => 4,
];
$items['quiz/%quiz/quiz/statistics/%'] = [
'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' => [
4,
],
'access callback' => 'quiz_stats_validate_vid',
'access arguments' => [
1,
4,
],
'type' => MENU_CALLBACK,
'weight' => 4,
];
$items['user/%/stats'] = [
'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' => [
1,
],
'access arguments' => [
'access user stats',
],
'type' => MENU_LOCAL_TASK,
];
$items['user/%/stats/%/view'] = [
'title' => 'Result Statistics',
'file' => 'quiz_stats.admin.inc',
'page callback' => 'quiz_stats_get_adv_stats',
'page arguments' => [
3,
1,
],
'access arguments' => [
'access user stats',
],
'type' => MENU_CALLBACK,
];
return $items;
}
/**
* Implements hook_theme().
*/
function quiz_stats_theme() {
$path = drupal_get_path('module', 'quiz_stats') . '/theme';
return [
'quiz_stats_get_basic_stats' => [
'variables' => [
'results' => NULL,
],
'file' => 'quiz_stats.admin.inc',
],
'date_vs_takeup_count' => [
'variables' => [
'takeup' => NULL,
],
'file' => 'quiz_stats.admin.inc',
],
'get_quiz_status_chart' => [
'variables' => [
'quiz' => NULL,
],
'file' => 'quiz_stats.admin.inc',
],
'quiz_top_scorers' => [
'variables' => [
'scorer' => NULL,
],
'file' => 'quiz_stats.admin.inc',
],
'quiz_grade_range' => [
'variables' => [
'range' => NULL,
],
'file' => 'quiz_stats.admin.inc',
],
'quiz_stats_revision_selector' => [
'variables' => [
'content' => NULL,
],
'path' => $path,
'template' => 'quiz_stats_revision_selector',
],
'quiz_stats_charts' => [
'variables' => [
'charts' => NULL,
],
'path' => $path,
'template' => 'quiz_stats_charts',
],
];
}
/**
* Validate the node.
*
* Check if its 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;
}
// 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.
return $quiz->nid == \Drupal::database()
->query('SELECT n.nid FROM {node} n INNER JOIN {node_revision} nr ON (n.nid = nr.nid) WHERE nr.vid = :vid', [
':vid' => $vid,
])
->fetchField();
}
Functions
Name | Description |
---|---|
quiz_stats_help | Implements hook_help(). |
quiz_stats_menu | Implements hook_menu(). |
quiz_stats_permission | Implements hook_permission(). |
quiz_stats_theme | Implements hook_theme(). |
quiz_stats_validate_vid | Validate the node. |