First very quick cut at fixes for backup (Eloy!!!)
This commit is contained in:
+53
-54
@@ -9,8 +9,11 @@
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// choice_responses
|
||||
// (UL,pk->id, fk->choice)
|
||||
// choice_options
|
||||
// (UL,pk->id, fk->choiceid)
|
||||
//
|
||||
// choice_answers
|
||||
// (UL,pk->id, fk->choiceid, fk->optionid)
|
||||
//
|
||||
// Meaning: pk->primary key field of the table
|
||||
// fk->foreign key to link with parent
|
||||
@@ -44,13 +47,14 @@
|
||||
fwrite ($bf,full_tag("TIMECLOSE",4,false,$choice->timeclose));
|
||||
fwrite ($bf,full_tag("PUBLISH",4,false,$choice->publish));
|
||||
fwrite ($bf,full_tag("RELEASE",4,false,$choice->release));
|
||||
fwrite ($bf,full_tag("DISPLAY",4,false,$choice->display));
|
||||
fwrite ($bf,full_tag("ALLOWUPDATE",4,false,$choice->allowupdate));
|
||||
fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$choice->timemodified));
|
||||
//if we've selected to backup users info, then execute backup_choice_responses
|
||||
if ($preferences->mods["choice"]->userinfo) {
|
||||
$status = backup_choice_responses($bf,$preferences,$choice->id);
|
||||
$status = backup_choice_answers($bf,$preferences,$choice->id);
|
||||
}
|
||||
backup_choice_answers($bf,$preferences,$choice->id);
|
||||
backup_choice_options($bf,$preferences,$choice->id);
|
||||
//End mod
|
||||
$status =fwrite ($bf,end_tag("MOD",3,true));
|
||||
}
|
||||
@@ -58,56 +62,28 @@
|
||||
return $status;
|
||||
}
|
||||
|
||||
//Backup choice_responses contents (executed from choice_backup_mods)
|
||||
function backup_choice_responses ($bf,$preferences,$choice) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
$choice_responses = get_records("choice_responses","choice",$choice,"id");
|
||||
//If there is submissions
|
||||
if ($choice_responses) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag("RESPONSES",4,true));
|
||||
//Iterate over each answer
|
||||
foreach ($choice_responses as $cho_resp) {
|
||||
//Start answer
|
||||
$status =fwrite ($bf,start_tag("RESPONSE",5,true));
|
||||
//Print submission contents
|
||||
fwrite ($bf,full_tag("ID",6,false,$cho_resp->id));
|
||||
fwrite ($bf,full_tag("USERID",6,false,$cho_resp->userid));
|
||||
fwrite ($bf,full_tag("CHOICE_RESPONSE",6,false,$cho_resp->answer));
|
||||
fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$cho_resp->timemodified));
|
||||
//End answer
|
||||
$status =fwrite ($bf,end_tag("RESPONSE",5,true));
|
||||
}
|
||||
//Write end tag
|
||||
$status =fwrite ($bf,end_tag("RESPONSES",4,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
//backup choice_answers contents (executed from choice_backup_mods)
|
||||
//Backup choice_answers contents (executed from choice_backup_mods)
|
||||
function backup_choice_answers ($bf,$preferences,$choice) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
$choice_answers = get_records("choice_answers","choice",$choice,"choice");
|
||||
|
||||
$choice_answers = get_records("choice_answers","choiceid",$choice,"id");
|
||||
//If there is submissions
|
||||
if ($choice_answers) {
|
||||
if ($choice_answers) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag("ANSWERS",4,true));
|
||||
//Iterate over each answer
|
||||
foreach ($choice_answers as $cho_ans) {
|
||||
foreach ($choice_answers as $cho_resp) {
|
||||
//Start answer
|
||||
$status =fwrite ($bf,start_tag("ANSWER",5,true));
|
||||
//Print submission contents
|
||||
fwrite ($bf,full_tag("ID",6,false,$cho_ans->id));
|
||||
fwrite ($bf,full_tag("CHOICE_ANSWER",6,false,$cho_ans->answer));
|
||||
fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$cho_ans->timemodified));
|
||||
fwrite ($bf,full_tag("ID",6,false,$cho_resp->id));
|
||||
fwrite ($bf,full_tag("CHOICEID",6,false,$cho_resp->choiceid));
|
||||
fwrite ($bf,full_tag("USERID",6,false,$cho_resp->userid));
|
||||
fwrite ($bf,full_tag("OPTIONID",6,false,$cho_resp->optionid));
|
||||
fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$cho_resp->timemodified));
|
||||
//End answer
|
||||
$status =fwrite ($bf,end_tag("ANSWER",5,true));
|
||||
}
|
||||
@@ -115,11 +91,37 @@
|
||||
$status =fwrite ($bf,end_tag("ANSWERS",4,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
//backup choice_options contents (executed from choice_backup_mods)
|
||||
function backup_choice_options ($bf,$preferences,$choice) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
|
||||
|
||||
|
||||
$choice_options = get_records("choice_options","choice",$choice,"choice");
|
||||
//If there is submissions
|
||||
if ($choice_options) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag("OPTIONS",4,true));
|
||||
//Iterate over each answer
|
||||
foreach ($choice_options as $cho_ans) {
|
||||
//Start answer
|
||||
$status =fwrite ($bf,start_tag("OPTION",5,true));
|
||||
//Print submission contents
|
||||
fwrite ($bf,full_tag("ID",6,false,$cho_ans->id));
|
||||
fwrite ($bf,full_tag("CHOICEID",6,false,$cho_ans->choiceid));
|
||||
fwrite ($bf,full_tag("TEXT",6,false,$cho_ans->text));
|
||||
fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$cho_ans->timemodified));
|
||||
//End answer
|
||||
$status =fwrite ($bf,end_tag("OPTION",5,true));
|
||||
}
|
||||
//Write end tag
|
||||
$status =fwrite ($bf,end_tag("OPTIONS",4,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
////Return an array of info (name,value)
|
||||
@@ -135,7 +137,7 @@
|
||||
//Now, if requested, the user_data
|
||||
if ($user_data) {
|
||||
$info[1][0] = get_string("responses","choice");
|
||||
if ($ids = choice_response_ids_by_course ($course)) {
|
||||
if ($ids = choice_answer_ids_by_course ($course)) {
|
||||
$info[1][1] = count($ids);
|
||||
} else {
|
||||
$info[1][1] = 0;
|
||||
@@ -146,9 +148,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE
|
||||
|
||||
//Returns an array of choices id
|
||||
@@ -161,15 +160,15 @@
|
||||
WHERE a.course = '$course'");
|
||||
}
|
||||
|
||||
//Returns an array of choice_responses id
|
||||
function choice_response_ids_by_course ($course) {
|
||||
//Returns an array of choice_answers id
|
||||
function choice_answer_ids_by_course ($course) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
return get_records_sql ("SELECT s.id , s.choice
|
||||
FROM {$CFG->prefix}choice_responses s,
|
||||
return get_records_sql ("SELECT s.id , s.choiceid
|
||||
FROM {$CFG->prefix}choice_answers s,
|
||||
{$CFG->prefix}choice a
|
||||
WHERE a.course = '$course' AND
|
||||
s.choice = a.id");
|
||||
s.choiceid = a.id");
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user