Skip to content

Commit

Permalink
Towards removing reference to quiz module from the question code
Browse files Browse the repository at this point in the history
Renaming tables:
quiz_questions -> question
quiz_states -> question_states

Renaming functions:
quiz_delete_question -> delete_question
quiz_get_question_options -> get_question_options
quiz_get_states -> get_question_states
quiz_restore_state -> restore_question_state
quiz_save_question_session -> save_question_session
quiz_state_is_graded -> question_state_is_graded
quiz_extract_responses -> question_extract_responses
quiz_regrade_question_in_attempt -> regrade_question_in_attempt
quiz_process_responses -> question_process_responses
quiz_isgradingevent -> question_isgradingevent($event)
quiz_search_for_duplicate_responses -> question_search_for_duplicate_responses
quiz_apply_penalty_and_timelimit -> question_apply_penalty_and_timelimit
quiz_print_question_icon -> print_question_icon
quiz_get_image -> get_question_image
quiz_make_name_prefix -> question_make_name_prefix
quiz_get_id_from_name_prefix -> question_get_id_from_name_prefix
quiz_new_attempt_uniqueid -> question_new_attempt_uniqueid
quiz_get_renderoptions -> question_get_renderoptions
quiz_print_quiz_question -> print_question
quiz_get_question_responses -> get_question_responses
quiz_get_question_actual_response -> get_question_actual_response
quiz_get_question_fraction_grade -> get_question_fraction_grade
quiz_get_default_category -> get_default_question_category


Renaming constants:
QUIZ_EVENT.... -> QUESTION_EVENT....
QUIZ_MAX_NUMBER_ANSWERS -> QUESTION_NUMANS
  • Loading branch information
gustav_delius committed Feb 28, 2006
1 parent 77230a8 commit 4f48fb4
Show file tree
Hide file tree
Showing 46 changed files with 473 additions and 532 deletions.
356 changes: 113 additions & 243 deletions lib/questionlib.php

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions mod/quiz/attempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
// there should only be one but we loop just in case
// TODO: the following should become a function in questionlib.php which
// really deletes all records associated to this attempt.
delete_records('quiz_states', 'attempt', $oldattempt->uniqueid);
delete_records('question_states', 'attempt', $oldattempt->uniqueid);
delete_records('question_sessions', 'attemptid', $oldattempt->uniqueid);
}
}
Expand Down Expand Up @@ -263,7 +263,7 @@
}

$sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance".
" FROM {$CFG->prefix}quiz_questions q,".
" FROM {$CFG->prefix}question q,".
" {$CFG->prefix}quiz_question_instances i".
" WHERE i.quiz = '$quiz->id' AND q.id = i.question".
" AND q.id IN ($questionlist)";
Expand All @@ -274,20 +274,20 @@
}

// Load the question type specific information
if (!quiz_get_question_options($questions)) {
if (!get_question_options($questions)) {
error('Could not load question options');
}

// Restore the question sessions to their most recent states
// creating new sessions where required
if (!$states = quiz_get_states($questions, $quiz, $attempt)) {
if (!$states = get_question_states($questions, $quiz, $attempt)) {
error('Could not restore question sessions');
}

// Save all the newly created states
if ($newattempt) {
foreach ($questions as $i => $question) {
quiz_save_question_session($questions[$i], $states[$i]);
save_question_session($questions[$i], $states[$i]);
}
}

Expand All @@ -297,8 +297,8 @@
if ($responses = data_submitted() and empty($_POST['quizpassword'])) {

// set the default event. This can be overruled by individual buttons.
$event = (array_key_exists('markall', $responses)) ? QUIZ_EVENTGRADE :
($finishattempt ? QUIZ_EVENTCLOSE : QUIZ_EVENTSAVE);
$event = (array_key_exists('markall', $responses)) ? QUESTION_EVENTGRADE :
($finishattempt ? QUESTION_EVENTCLOSE : QUESTION_EVENTSAVE);

// Unset any variables we know are not responses
unset($responses->id);
Expand All @@ -314,7 +314,7 @@

// extract responses
// $actions is an array indexed by the questions ids
$actions = quiz_extract_responses($questions, $responses, $event);
$actions = question_extract_responses($questions, $responses, $event);

// Process each question in turn

Expand All @@ -324,8 +324,8 @@
$actions[$i]->responses = array('' => '');
}
$actions[$i]->timestamp = $timestamp;
quiz_process_responses($questions[$i], $states[$i], $actions[$i], $quiz, $attempt);
quiz_save_question_session($questions[$i], $states[$i]);
question_process_responses($questions[$i], $states[$i], $actions[$i], $quiz, $attempt);
save_question_session($questions[$i], $states[$i]);
}

$attempt->timemodified = $timestamp;
Expand All @@ -348,7 +348,7 @@
// load all the questions
$closequestionlist = implode(',', array_keys($closequestions));
$sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance".
" FROM {$CFG->prefix}quiz_questions q,".
" FROM {$CFG->prefix}question q,".
" {$CFG->prefix}quiz_question_instances i".
" WHERE i.quiz = '$quiz->id' AND q.id = i.question".
" AND q.id IN ($closequestionlist)";
Expand All @@ -357,21 +357,21 @@
}

// Load the question type specific information
if (!quiz_get_question_options($closequestions)) {
if (!get_question_options($closequestions)) {
error('Could not load question options');
}

// Restore the question sessions
if (!$closestates = quiz_get_states($closequestions, $quiz, $attempt)) {
if (!$closestates = get_question_states($closequestions, $quiz, $attempt)) {
error('Could not restore question sessions');
}

foreach($closequestions as $key => $question) {
$action->event = QUIZ_EVENTCLOSE;
$action->event = QUESTION_EVENTCLOSE;
$action->responses = $closestates[$key]->responses;
$action->timestamp = $closestates[$key]->timestamp;
quiz_process_responses($question, $closestates[$key], $action, $quiz, $attempt);
quiz_save_question_session($question, $closestates[$key]);
question_process_responses($question, $closestates[$key], $action, $quiz, $attempt);
save_question_session($question, $closestates[$key]);
}
}
add_to_log($course->id, 'quiz', 'close attempt',
Expand Down Expand Up @@ -469,8 +469,8 @@ function navigate(page) {
if ($i > 0) {
echo "<br />\n";
}
quiz_print_quiz_question($questions[$i], $states[$i], $number, $quiz, $options);
quiz_save_question_session($questions[$i], $states[$i]);
print_question($questions[$i], $states[$i], $number, $quiz, $options);
save_question_session($questions[$i], $states[$i]);
$number += $questions[$i]->length;
}

Expand Down
34 changes: 17 additions & 17 deletions mod/quiz/backuplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// |---------(UL,pk->id,fk->attempt,question)-----| . | | | .
// | . | . | | quiz_dataset_definitions
// | . | . | | (CL,pk->id,fk->category)
// | quiz_states | quiz_questions |
// | question_states | question |
// ----------(UL,pk->id,fk->attempt,question)--------------------------(CL,pk->id,fk->category,files) |
// | | quiz_dataset_items
// | | (CL,pk->id,fk->definition)
Expand Down Expand Up @@ -69,7 +69,7 @@
//This module is special, because we make the backup in two steps:
// 1.-We backup every category and their questions (complete structure). It includes this tables:
// - quiz_categories
// - quiz_questions
// - question
// - quiz_rqp
// - quiz_truefalse
// - quiz_shortanswer
Expand All @@ -95,7 +95,7 @@
// - quiz_question_instances
// - quiz_attempts
// - quiz_grades
// - quiz_states
// - question_states
// - question_sessions
// This step is the standard mod backup. (course dependent).

Expand Down Expand Up @@ -123,7 +123,7 @@ function insert_category_ids ($course,$backup_unique_code,$instances=null) {
$status = execute_sql("INSERT INTO {$CFG->prefix}backup_ids
(backup_code, table_name, old_id)
SELECT DISTINCT $backup_unique_code,'quiz_categories',t.category
FROM {$CFG->prefix}quiz_questions t,
FROM {$CFG->prefix}question t,
{$CFG->prefix}quiz_question_instances g
$from
WHERE $where g.question = t.id",false);
Expand Down Expand Up @@ -162,7 +162,7 @@ function insert_category_ids ($course,$backup_unique_code,$instances=null) {
// because we will have to add these subcategories
$sql = "SELECT t.id, t.category
FROM {$CFG->prefix}quiz_question_instances AS g,
{$CFG->prefix}quiz_questions AS t
{$CFG->prefix}question AS t
$from
WHERE $where t.id = g.question
AND t.qtype = '".RANDOM."'
Expand Down Expand Up @@ -199,7 +199,7 @@ function fix_orphaned_questions ($course) {
global $CFG;

$categories = get_records_sql("SELECT DISTINCT t.category, t.category
FROM {$CFG->prefix}quiz_questions t,
FROM {$CFG->prefix}question t,
{$CFG->prefix}quiz_question_instances g,
{$CFG->prefix}quiz q
WHERE q.course = '$course' AND
Expand All @@ -221,7 +221,7 @@ function fix_orphaned_questions ($course) {
unset ($db_cat);
if ($catid) {
//Reasign orphaned questions to their new category
set_field ('quiz_questions','category',$catid,'category',$key);
set_field ('question','category',$catid,'category',$key);
}
}
}
Expand Down Expand Up @@ -287,7 +287,7 @@ function quiz_backup_question($bf,$preferences,$category) {
// We'll fetch the questions sorted by parent so that questions with no parents
// (these are the ones which could be parents themselves) are backed up first. This
// is important for the recoding of the parent field during the restore process
$questions = get_records("quiz_questions","category",$category,"parent ASC, id");
$questions = get_records("question","category",$category,"parent ASC, id");
//If there are questions
if ($questions) {
//Write start tag
Expand Down Expand Up @@ -946,7 +946,7 @@ function backup_quiz_attempts ($bf,$preferences,$quiz) {
fwrite ($bf,full_tag("LAYOUT",6,false,$attempt->layout));
fwrite ($bf,full_tag("PREVIEW",6,false,$attempt->preview));
//Now write to xml the states (in this attempt)
$status = backup_quiz_states ($bf,$preferences,$attempt->uniqueid);
$status = backup_question_states ($bf,$preferences,$attempt->uniqueid);
//Now write to xml the sessions (in this attempt)
$status = backup_question_sessions ($bf,$preferences,$attempt->uniqueid);
//End attempt
Expand All @@ -958,20 +958,20 @@ function backup_quiz_attempts ($bf,$preferences,$quiz) {
return $status;
}

//Backup quiz_states contents (executed from backup_quiz_attempts)
function backup_quiz_states ($bf,$preferences,$attempt) {
//Backup question_states contents (executed from backup_quiz_attempts)
function backup_question_states ($bf,$preferences,$attempt) {

global $CFG;

$status = true;

$quiz_states = get_records("quiz_states","attempt",$attempt,"id");
$question_states = get_records("question_states","attempt",$attempt,"id");
//If there are states
if ($quiz_states) {
if ($question_states) {
//Write start tag
$status = fwrite ($bf,start_tag("STATES",6,true));
//Iterate over each state
foreach ($quiz_states as $state) {
foreach ($question_states as $state) {
//Start state
$status = fwrite ($bf,start_tag("STATE",7,true));
//Print state contents
Expand Down Expand Up @@ -1059,7 +1059,7 @@ function quiz_check_backup_mods_instances($instance,$backup_unique_code) {
return $info;
}

//Backup quiz_rqp_state contents (executed from backup_quiz_states)
//Backup quiz_rqp_state contents (executed from backup_question_states)
function backup_quiz_rqp_state ($bf,$preferences,$state) {

global $CFG;
Expand All @@ -1081,7 +1081,7 @@ function backup_quiz_rqp_state ($bf,$preferences,$state) {
return $status;
}

//Backup quiz_essay_state contents (executed from backup_quiz_states)
//Backup quiz_essay_state contents (executed from backup_question_states)
function backup_quiz_essay_state ($bf,$preferences,$state) {

global $CFG;
Expand Down Expand Up @@ -1202,7 +1202,7 @@ function quiz_question_ids_by_backup ($backup_unique_code) {

return get_records_sql ("SELECT q.id, q.category
FROM {$CFG->prefix}backup_ids a,
{$CFG->prefix}quiz_questions q
{$CFG->prefix}question q
WHERE a.backup_code = '$backup_unique_code' AND
q.category = a.old_id AND
a.table_name = 'quiz_categories'");
Expand Down
26 changes: 13 additions & 13 deletions mod/quiz/db/migrate2utf8.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?
function migrate2utf8_quiz_questions_name($recordid){
function migrate2utf8_question_name($recordid){
global $CFG, $globallang;

/// Some trivial checks
Expand All @@ -10,7 +10,7 @@ function migrate2utf8_quiz_questions_name($recordid){

$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq
{$CFG->prefix}question qq
WHERE qc.id = qq.category
AND qq.id = $recordid";

Expand All @@ -19,7 +19,7 @@ function migrate2utf8_quiz_questions_name($recordid){
return false;
}

if (!$quizquestions = get_record('quiz_questions','id',$recordid)) {
if (!$quizquestions = get_record('question','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
Expand All @@ -42,13 +42,13 @@ function migrate2utf8_quiz_questions_name($recordid){
$newquizquestion = new object;
$newquizquestion->id = $recordid;
$newquizquestion->name = $result;
update_record('quiz_questions',$newquizquestion);
update_record('question',$newquizquestion);
}
/// And finally, just return the converted field
return $result;
}

function migrate2utf8_quiz_questions_questiontext($recordid){
function migrate2utf8_question_questiontext($recordid){
global $CFG, $globallang;

/// Some trivial checks
Expand All @@ -59,7 +59,7 @@ function migrate2utf8_quiz_questions_questiontext($recordid){

$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq
{$CFG->prefix}question qq
WHERE qc.id = qq.category
AND qq.id = $recordid";

Expand All @@ -68,7 +68,7 @@ function migrate2utf8_quiz_questions_questiontext($recordid){
return false;
}

if (!$quizquestions = get_record('quiz_questions','id',$recordid)) {
if (!$quizquestions = get_record('question','id',$recordid)) {
log_the_problem_somewhere();
return false;
}
Expand All @@ -92,7 +92,7 @@ function migrate2utf8_quiz_questions_questiontext($recordid){
$newquizquestion = new object;
$newquizquestion->id = $recordid;
$newquizquestion->questiontext = $result;
update_record('quiz_questions',$newquizquestion);
update_record('question',$newquizquestion);
}
/// And finally, just return the converted field
return $result;
Expand All @@ -110,7 +110,7 @@ function migrate2utf8_quiz_numerical_units_unit($recordid){

$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}question qq,
{$CFG->prefix}quiz_numerical_units qnu
WHERE qc.id = qq.category
AND qq.id = qnu.question
Expand Down Expand Up @@ -162,7 +162,7 @@ function migrate2utf8_quiz_match_sub_questiontext($recordid){

$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}question qq,
{$CFG->prefix}quiz_match_sub qms
WHERE qc.id = qq.category
AND qq.id = qms.question
Expand Down Expand Up @@ -214,7 +214,7 @@ function migrate2utf8_quiz_match_sub_answertext($recordid){

$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}question qq,
{$CFG->prefix}quiz_match_sub qms
WHERE qc.id = qq.category
AND qq.id = qms.question
Expand Down Expand Up @@ -266,7 +266,7 @@ function migrate2utf8_quiz_answers_answer($recordid){

$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}question qq,
{$CFG->prefix}quiz_answers qa
WHERE qc.id = qq.category
AND qq.id = qa.question
Expand Down Expand Up @@ -318,7 +318,7 @@ function migrate2utf8_quiz_answers_feedback($recordid){

$SQL = "SELECT qc.course
FROM {$CFG->prefix}quiz_categories qc,
{$CFG->prefix}quiz_questions qq,
{$CFG->prefix}question qq,
{$CFG->prefix}quiz_answers qa
WHERE qc.id = qq.category
AND qq.id = qa.question
Expand Down
Loading

0 comments on commit 4f48fb4

Please sign in to comment.