function quiz_views_tables in Quiz 5.2
Implementation of hook_views_tables().
File
- ./
quiz_views.module, line 11 - This include file implements views 5.x-1.x functionality on behalf of quiz.module
Code
function quiz_views_tables() {
$tables['quiz_node_results'] = array(
'name' => 'quiz_node_results',
'provider' => 'internal',
// won't show up in external list.
// attach quiz results to node
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid',
),
'right' => array(
'field' => 'nid',
),
'type' => 'inner',
),
'fields' => array(
'result_id' => array(
'name' => t('Quiz Result: Result ID'),
'sortable' => TRUE,
'help' => t('Display the Result ID of the Quiz Result. Optionally you can show the result id with or without a link.'),
'handler' => 'quiz_views_handler_field_result_id',
'option' => array(
'#type' => 'select',
'#options' => array(
'link' => 'As link',
'nolink' => 'Without link',
),
),
),
'quiz_result_actions' => array(
'field' => 'result_id',
'name' => t('Quiz Result: Actions'),
'sortable' => TRUE,
'help' => t('Show a link to results, or admin actions (both view and delete) or admin view and delete separately.'),
'handler' => 'quiz_views_handler_field_result_id',
'option' => array(
'#type' => 'select',
'#options' => array(
'onlylink' => 'view result link',
'actions' => 'As admin actions',
'adminview' => 'As admin view link',
'admindelete' => 'As admin delete link',
),
),
),
'time_start' => array(
'name' => t('Quiz Result: Start Time'),
'sortable' => TRUE,
'handler' => views_handler_field_dates(),
'help' => t('Display the start time of a quiz result.'),
),
'time_end' => array(
'name' => t('Quiz Result: End Time'),
'sortable' => TRUE,
'handler' => views_handler_field_dates(),
'help' => t('Display the end time of a quiz result.'),
),
'score' => array(
'name' => t('Quiz Result: Score'),
'sortable' => TRUE,
'handler' => 'quiz_views_handler_field_score',
'addlfields' => array(
'result_id',
),
'help' => t('Display the final score of a quiz result.'),
),
'avg_score' => array(
'name' => t('Quiz Result: AVG Score'),
'sortable' => TRUE,
'help' => t('A user\'s average score across all quizzes they have taken. This field will group results by quiz taker UID.'),
'notafield' => TRUE,
'handler' => 'quiz_views_handler_field_avg_score',
'query_handler' => 'quiz_views_handler_query_avg_score',
),
),
'sorts' => array(
'result_id' => array(
'name' => t('Quiz Result: Result ID'),
'help' => t('This allows you to sort by the Result ID.'),
),
'score' => array(
'name' => t('Quiz Result: Score'),
'help' => t('This allows you to sort by the percentage needed to pass the quiz.'),
),
'time_start' => array(
'name' => t('Quiz Result: Start Time'),
'handler' => 'views_handler_sort_date',
'option' => views_handler_sort_date_options(),
'help' => t('This allows you to sort by the start time of the quiz result.'),
),
'time_end' => array(
'name' => t('Quiz Result: End Time'),
'handler' => 'views_handler_sort_date',
'option' => views_handler_sort_date_options(),
'help' => t('This allows you to sort by the end time of the quiz result.'),
),
'avg_score' => array(
'name' => t('Quiz Result: AVG Score'),
'help' => t('Sort by overall score (the average across all completed quizzes by a user)'),
'handler' => 'quiz_views_handler_sort_avg_score',
),
),
'filters' => array(
'quiz_user_current' => array(
'field' => 'uid',
'name' => t('Quiz Results: Quiz Taker Current User'),
'operator' => 'views_handler_operator_eqneq',
'list' => 'views_handler_filter_usercurrent',
'list-type' => 'select',
'help' => t('This allows you to filter by whether or not the quiz result was created by the logged in user of the view.'),
),
'quiz_taker' => array(
'field' => 'uid',
'name' => t('Quiz Result: Quiz Taker'),
'operator' => 'views_handler_operator_or',
'list' => 'views_handler_filter_username',
'value-type' => 'array',
'help' => t('This allows you to filter quiz results by a particular user. You might not find this useful if you have a lot of users.'),
),
'score' => array(
'name' => t('Quiz Result: Score'),
'operator' => 'views_handler_operator_gtlt',
'option' => 'integer',
'help' => t('This allows you to filter by the quiz result score.'),
),
'time_start' => array(
'name' => t('Quiz Result: Start Time'),
'operator' => 'views_handler_operator_gtlt',
'value' => views_handler_filter_date_value_form(),
'handler' => 'views_handler_filter_timestamp',
'option' => 'string',
'help' => t('This allows you to sort by the start time of the quiz result.'),
),
'time_end' => array(
'name' => t('Quiz Result: End Time'),
'operator' => 'views_handler_operator_gtlt',
'value' => views_handler_filter_date_value_form(),
'handler' => 'views_handler_filter_timestamp',
'option' => 'string',
'help' => t('This allows you to sort by the end time of the quiz result.'),
),
),
);
$tables['quiz_user'] = array(
'name' => 'users',
'provider' => 'internal',
// won't show up in external list.
// attach quiz user to results
'join' => array(
'type' => 'inner',
'left' => array(
'table' => 'quiz_node_results',
'field' => 'uid',
),
'right' => array(
'field' => 'uid',
),
),
'fields' => array(
'name' => array(
'name' => t('Quiz Result: Quiz Taker'),
'sortable' => TRUE,
//'option' => 'string',
'handler' => array(
'quiz_views_handler_field_username_text' => t('normal text'),
'quiz_views_handler_field_username_link' => t('themed userlink'),
),
'uid' => 'uid',
'addlfields' => array(
'uid',
),
'help' => t('Displays the user who created this quiz result.'),
),
),
/**
* While this would be really great functionality, I can't for the life of me
* figure out how to fix sorting by username
*/
'sort' => array(
'name' => array(
'name' => t('Quiz Result: Quiz Taker'),
'help' => t('Sort by the user who created the quiz result.'),
),
),
);
$tables['quiz_node_properties'] = array(
'name' => 'quiz_node_properties',
'provider' => 'internal',
// won't show up in external list.
// attach quiz table to node
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid',
),
'right' => array(
'field' => 'nid',
),
),
'fields' => array(
'pass_rate' => array(
'name' => t('Quiz: Passing Percentage Rate'),
'sortable' => TRUE,
'handler' => 'quiz_views_handler_percentage',
'help' => t('Display the percentage needed to pass the quiz.'),
),
'takes' => array(
'name' => t('Quiz: Number of Takes Allowed'),
'sortable' => TRUE,
'handler' => 'views_handler_field_takes',
'help' => t('Display the number of takes allowed on a quiz.'),
),
/*
* The database has replaced this field with the number of random questions
*
* TODO add to database total number of questions per quiz,
* otherwise it takes too many queries if there are a lot of quizzes on a page
* and is a performance issue.
*/
/*'number_of_questions' => array(
'name' => t('Quiz: Number of Questions'),
'sortable' => TRUE,
'handler' => 'views_handler_field_int',
'help' => t('Display the number of quiz questions.'),
),*/
'quiz_open' => array(
'name' => t('Quiz: Start Time'),
'sortable' => TRUE,
'handler' => views_handler_field_dates(),
'help' => t('Display the start date of a quiz.'),
),
'quiz_close' => array(
'name' => t('Quiz: End Time'),
'sortable' => TRUE,
'handler' => views_handler_field_dates(),
'help' => t('Display the end date of a quiz.'),
),
'quiz_always' => array(
'name' => t('Quiz: Always Available'),
'sortable' => TRUE,
'handler' => views_handler_yes_no,
'help' => t('Display the end date of a quiz.'),
),
),
'sorts' => array(
'pass_rate' => array(
'name' => t('Quiz: Passing Rate'),
'help' => t('This allows you to sort by the percentage needed to pass the quiz.'),
),
'takes' => array(
'name' => t('Quiz: Number of Takes Allowed'),
'help' => t('This allows you to sort by the number of takes allowed of the quiz.'),
),
// changed to number of random questions
/*'number_of_questions' => array(
'name' => t('Quiz: Number of Questions'),
'help' => t('This allows you to sort by the number of questions in the quiz.'),
),*/
'quiz_open' => array(
'name' => t('Quiz: Start Time'),
'handler' => 'views_handler_sort_date',
'option' => views_handler_sort_date_options(),
'help' => t('This allows you to sort by the Start Date of the quiz.'),
),
'quiz_closed' => array(
'name' => t('Quiz: End Time'),
'handler' => 'views_handler_sort_date',
'option' => views_handler_sort_date_options(),
'help' => t('This allows you to sort by the end date of the quiz.'),
),
),
'filters' => array(
'pass_rate' => array(
'name' => t('Quiz: Passing Rate'),
'operator' => 'views_handler_operator_gtlt',
'option' => 'integer',
'help' => t('This allows you to filter by the percentage needed to pass the quiz.'),
),
// changed to number of random questions
/*'number_of_questions' => array(
'name' => t('Quiz: Number of Questions'),
'operator' => 'views_handler_operator_gtlt',
'option' => 'integer',
'help' => t('This allows you to filter by the number of questions in the quiz.'),
),*/
'takes' => array(
'name' => t('Quiz: Number of Takes Allowed'),
'operator' => 'views_handler_operator_gtlt',
'option' => 'integer',
'help' => t('This allows you to filter by the number of takes allowed of the quiz. Enter 0 for unlimited'),
),
'quiz_open' => array(
'name' => t('Quiz: Start Time'),
'operator' => 'views_handler_operator_gtlt',
'value' => views_handler_filter_date_value_form(),
'handler' => 'views_handler_filter_timestamp',
'option' => 'string',
'help' => t('This allows you to sort by the Start Date of the quiz.'),
),
'quiz_closed' => array(
'name' => t('Quiz: End Time'),
'operator' => 'views_handler_operator_yesno()',
'value' => views_handler_filter_date_value_form(),
'handler' => 'views_handler_filter_timestamp',
'option' => 'string',
'help' => t('This allows you to sort by the end date of the quiz.'),
),
'quiz_always' => array(
'name' => t('Quiz: Always Available'),
'operator' => 'views_handler_operator_yesno',
'value' => integer,
'handler' => 'views_handler_yes_no',
'option' => 'string',
'help' => t('This allows you to sort by the end date of the quiz.'),
),
),
);
return $tables;
}