quiz_stats.module in Quiz 8.4
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 = array(
'access user stats' => array(
'title' => t('access user stats'),
),
'access author stats' => array(
'title' => t('access author stats'),
),
);
return $permission;
}
/**
* Implements hook_menu().
*/
function quiz_stats_menu() {
$items['admin/quiz/reports/stats/creator'] = array(
'title' => 'Quiz Statistics',
'description' => 'Generates a report on quiz results for quiz creators.',
'route_name' => 'quiz_stats.quiz_statistics',
'type' => MENU_NORMAL_ITEM,
);
$items['node/%node/statistics'] = array(
'title' => 'Statistics',
'description' => 'Generates a report on quiz results for quiz creators.',
'route_name' => 'quiz_stats.quiz_statistics_report',
'type' => MENU_LOCAL_TASK,
'weight' => 4,
);
$items['node/%node/statistics/%'] = array(
'title' => 'Statistics',
'description' => 'Generates a report on quiz results for quiz creators.',
'route_name' => 'quiz_stats.quiz_statistics_page',
'type' => MENU_CALLBACK,
'weight' => 4,
);
$items['user/%/stats'] = array(
'title' => 'Result Statistics',
'description' => 'Generates a report on quiz results for quiz creators.',
'route_name' => 'quiz_stats.quiz_user_statistics',
'type' => MENU_LOCAL_TASK,
);
$items['user/%/stats/%/view'] = array(
'title' => 'Result Statistics',
'route_name' => 'quiz_stats.quiz_user_statistics_view',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_theme().
*/
function quiz_stats_theme() {
return array(
'quiz_stats_get_basic_stats' => array(
'variables' => array(
'results' => NULL,
),
'file' => 'quiz_stats.admin.inc',
),
'date_vs_takeup_count' => array(
'variables' => array(
'takeup' => NULL,
),
'file' => 'quiz_stats.admin.inc',
),
'get_quiz_status_chart' => array(
'variables' => array(
'quiz' => NULL,
),
'file' => 'quiz_stats.admin.inc',
),
'quiz_top_scorers' => array(
'variables' => array(
'scorer' => NULL,
),
'file' => 'quiz_stats.admin.inc',
),
'quiz_grade_range' => array(
'variables' => array(
'range' => NULL,
),
'file' => 'quiz_stats.admin.inc',
),
'quiz_stats_revision_selector' => array(
'variables' => array(
'content' => NULL,
),
'file' => 'quiz_stats.admin.inc',
),
'quiz_stats_charts' => array(
'variables' => array(
'charts' => NULL,
),
'file' => 'quiz_stats.admin.inc',
),
);
}
/**
* 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
->getType() != 'quiz') {
return FALSE;
}
if (!\Drupal::currentUser()
->hasPermission('access author stats')) {
return FALSE;
}
return $quiz
->id() == db_query('SELECT n.nid FROM {node} n INNER JOIN {node_revision} nr ON (n.nid = nr.nid) WHERE nr.vid = :vid', array(
':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 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 |