$status = true;
- $dialogue_conversations = get_records("dialogue_conversations","dialogue",$dialogue,"id");
- //If there is conversationss
+ $dialogue_conversations = get_records("dialogue_conversations","dialogueid",$dialogue,"id");
+ //If there is conversations
if ($dialogue_conversations) {
//Write start tag
$status =fwrite ($bf,start_tag("CONVERSATIONS",4,true));
$status = true;
- $dialogue_entries = get_records("dialogue_entries","conversationid",$conservationid,"id");
+ $dialogue_entries = get_records("dialogue_entries","conversationid",$conversationid,"id");
//If there is entries
if ($dialogue_entries) {
//Write start tag
//Print dialogue_entries contents
fwrite ($bf,full_tag("ID",6,false,$entry->id));
fwrite ($bf,full_tag("USERID",6,false,$entry->userid));
- fwrite ($bf,full_tag("TIMECREATED",6,false,$entry->modified));
- fwrite ($bf,full_tag("MAILED",6,false,$entry->text));
- fwrite ($bf,full_tag("TEXT",6,false,$entry->format));
+ fwrite ($bf,full_tag("TIMECREATED",6,false,$entry->timecreated));
+ fwrite ($bf,full_tag("MAILED",6,false,$entry->mailed));
+ fwrite ($bf,full_tag("TEXT",6,false,$entry->text));
//End entry
$status =fwrite ($bf,end_tag("ENTRY",5,true));
}
}
}
+ // have a look for open conversations
+ $opencontent = false;
+ if ($logs = dialogue_get_open_conversations($course)) {
+ // got some, see if any belong to a visible module
+ foreach ($logs as $log) {
+ // Create a temp valid module structure (only need courseid, moduleid)
+ $tempmod->course = $course->id;
+ $tempmod->id = $log->dialogueid;
+ //Obtain the visible property from the instance
+ if (instance_is_visible("dialogue",$tempmod)) {
+ $opencontent = true;
+ break;
+ }
+ }
+ // if we got some "live" ones then output them
+ if ($opencontent) {
+ $strftimerecent = get_string("strftimerecent");
+ print_headline(get_string("opendialogueentries", "dialogue").":");
+ foreach ($logs as $log) {
+ //Create a temp valid module structure (only need courseid, moduleid)
+ $tempmod->course = $course->id;
+ $tempmod->id = $log->dialogueid;
+ //Obtain the visible property from the instance
+ if (instance_is_visible("dialogue",$tempmod)) {
+ $date = userdate($log->time, $strftimerecent);
+ echo "<p><font size=1>$date - $log->firstname $log->lastname<br />";
+ echo "\"<a href=\"$CFG->wwwroot/mod/dialogue/$log->url\">";
+ echo "$log->name";
+ echo "</a>\"</font></p>";
+ }
+ }
+ }
+ }
+
// have a look for closed conversations
$closedcontent = false;
if ($logs = dialogue_get_closed_logs($course, $timestart)) {
}
+//////////////////////////////////////////////////////////////////////////////////////
+function dialogue_get_open_conversations($course) {
+ // get the conversations which are waiting for a response for this user.
+ // Add the first and last names of the other participant
+ global $CFG, $USER;
+ if ($conversations = get_records_sql("SELECT d.name dialoguename, c.id, c.dialogueid, c.timemodified, c.lastid
+ FROM {$CFG->prefix}dialogue d, {$CFG->prefix}dialogue_conversations c
+ WHERE d.course = $course->id
+ AND c.dialogueid = d.id
+ AND (c.userid = $USER->id OR c.recipientid = $USER->id)
+ AND c.lastid != $USER->id
+ AND c.closed =0")) {
+
+ foreach ($conversations as $conversation) {
+ if (!$user = get_record("user", "id", $conversation->lastid)) {
+ error("Get open conversations: user record not found");
+ }
+ if (!$cm = get_coursemodule_from_instance("dialogue", $conversation->dialogueid, $course->id)) {
+ error("Course Module ID was incorrect");
+ }
+ $entry[$conversation->id]->dialogueid = $conversation->dialogueid;
+ $entry[$conversation->id]->time = $conversation->timemodified;
+ $entry[$conversation->id]->url = "view.php?id=$cm->id";
+ $entry[$conversation->id]->firstname = $user->firstname;
+ $entry[$conversation->id]->lastname = $user->lastname;
+ $entry[$conversation->id]->name = $conversation->dialoguename;
+ }
+ return $entry;
+ }
+ return;
+}
+
+
//////////////////////////////////////////////////////////////////////////////////////
function dialogue_get_closed_logs($course, $timestart) {
// get the "closed" entries and add the first and last names, we are not interested in the entries
// list the conversations of the current user awaiting response from the other person
global $THEME, $USER;
- if (! $course = get_record("course", "id", $dialogue->course)) {
+ if (!$course = get_record("course", "id", $dialogue->course)) {
error("Course is misconfigured");
}
- if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) {
+ if (!$cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) {
error("Course Module ID was incorrect");
}
$dialogue->maildefault = backup_todb($info['MOD']['#']['MAILDEFAULT']['0']['#']);
$dialogue->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
- //We have to recode the assessed field if it is <0 (scale)
- if ($dialogue->assessed < 0) {
- $scale = backup_getid($restore->backup_unique_code,"scale",abs($dialogue->assessed));
- if ($scale) {
- $dialogue->assessed = -($scale->new_id);
- }
- }
-
//The structure is equal to the db, so insert the dialogue
$newid = insert_record ("dialogue",$dialogue);
//Now check if want to restore user data and do it.
if ($restore->mods['dialogue']->userinfo) {
//Restore dialogue_conversations
- $status = dialogue_conversations_restore_mods ($mod->id, $newid,$info,$restore);
+ $status = dialogue_conversations_restore($mod->id, $newid,$info,$restore);
}
} else {
$status = false;
//This function restores the dialogue_conversations
- function dialogue_conversations_restore_mods($old_dialogue_id, $new_dialogue_id,$info,$restore) {
+ function dialogue_conversations_restore($old_dialogue_id, $new_dialogue_id,$info,$restore) {
global $CFG;
//Get the entries array
$conversations = $info['MOD']['#']['CONVERSATIONS']['0']['#']['CONVERSATION'];
- //Iterate over conversations
- for($i = 0; $i < sizeof($converstions); $i++) {
- $conversation_info = $conversations[$i];
- //traverse_xmlize($conversation_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //We'll need this later!!
- $oldid = backup_todb($sub_info['#']['ID']['0']['#']);
- $olduserid = backup_todb($sub_info['#']['USERID']['0']['#']);
-
- //Now, build the dialogue_ENTRIES record structure
- $conversation->dialogue = $new_dialogue_id;
- $conversation->userid = backup_todb($conversation_info['#']['USERID']['0']['#']);
- $conversation->recipientid = backup_todb($conversation_info['#']['RECIPIENTID']['0']['#']);
- $conversation->lastid = backup_todb($conversation_info['#']['LASTID']['0']['#']);
- $conversation->timemodified = backup_todb($conversation_info['#']['TIMEMODIFIED']['0']['#']);
- $conversation->closed = backup_todb($conversation_info['#']['CLOSED']['0']['#']);
- $conversation->seenon = backup_todb($conversation_info['#']['SEENON']['0']['#']);
- $conversation->ctype = backup_todb($conversation_info['#']['CTYPE']['0']['#']);
- $conversation->format = backup_todb($conversation_info['#']['FORMAT']['0']['#']);
- $conversation->subject = backup_todb($conversation_info['#']['SUBJECT']['0']['#']);
- //We have to recode the userid and recipientid fields
- $user = backup_getid($restore->backup_unique_code,"user",$conversation->userid);
- if ($user) {
- $conversation->userid = $user->new_id;
- }
- $user = backup_getid($restore->backup_unique_code,"user",$conversation->recipientid);
- if ($user) {
- $conversation->recipientid = $user->new_id;
- }
+ if ($conversations) {
+ //Iterate over conversations
+ for($i = 0; $i < sizeof($conversations); $i++) {
+ $conversation_info = $conversations[$i];
+ //traverse_xmlize($conversation_info); //Debug
+ //print_object ($GLOBALS['traverse_array']); //Debug
+ //$GLOBALS['traverse_array']=""; //Debug
+
+ //We'll need this later!!
+ $oldid = backup_todb($conversation_info['#']['ID']['0']['#']);
+ $olduserid = backup_todb($conversation_info['#']['USERID']['0']['#']);
+
+ //Now, build the dialogue_ENTRIES record structure
+ $conversation->dialogueid = $new_dialogue_id;
+ $conversation->userid = backup_todb($conversation_info['#']['USERID']['0']['#']);
+ $conversation->recipientid = backup_todb($conversation_info['#']['RECIPIENTID']['0']['#']);
+ $conversation->lastid = backup_todb($conversation_info['#']['LASTID']['0']['#']);
+ $conversation->timemodified = backup_todb($conversation_info['#']['TIMEMODIFIED']['0']['#']);
+ $conversation->closed = backup_todb($conversation_info['#']['CLOSED']['0']['#']);
+ $conversation->seenon = backup_todb($conversation_info['#']['SEENON']['0']['#']);
+ $conversation->ctype = backup_todb($conversation_info['#']['CTYPE']['0']['#']);
+ $conversation->format = backup_todb($conversation_info['#']['FORMAT']['0']['#']);
+ $conversation->subject = backup_todb($conversation_info['#']['SUBJECT']['0']['#']);
+ //We have to recode the userid and recipientid fields
+ $user = backup_getid($restore->backup_unique_code,"user",$conversation->userid);
+ if ($user) {
+ $conversation->userid = $user->new_id;
+ }
+ $user = backup_getid($restore->backup_unique_code,"user",$conversation->recipientid);
+ if ($user) {
+ $conversation->recipientid = $user->new_id;
+ }
- //The structure is equal to the db, so insert the dialogue_conversation
- $newid = insert_record ("dialogue_conversations",$conversation);
+ //The structure is equal to the db, so insert the dialogue_conversation
+ $newid = insert_record ("dialogue_conversations",$conversation);
- //Do some output
- if (($i+1) % 50 == 0) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br>";
+ //Do some output
+ if (($i+1) % 50 == 0) {
+ echo ".";
+ if (($i+1) % 1000 == 0) {
+ echo "<br>";
+ }
+ backup_flush(300);
}
- backup_flush(300);
- }
- if ($newid) {
- //We have the newid, update backup_ids
- backup_putid($restore->backup_unique_code, "dialogue_conversations",
- $oldid, $newid);
- //Now check if want to restore user data and do it.
- if ($status) {
- //Restore dialogue_entries
- $status = dialogue_entries_restore_mods ($new_dialogue_id, $newid,$conversation,$restore);
+ if ($newid) {
+ //We have the newid, update backup_ids
+ backup_putid($restore->backup_unique_code, "dialogue_conversations",
+ $oldid, $newid);
+ //Now check if want to restore user data and do it.
+ if ($status) {
+ //Restore dialogue_entries
+ $status = dialogue_entries_restore($new_dialogue_id, $newid,$conversation_info,
+ $restore);
+ }
+ } else {
+ $status = false;
}
- } else {
- $status = false;
}
}
}
//This function restores the dialogue_entries
- function dialogue_entries_restore_mods($old_dialogue_id, $new_dialogue_id,$conversation,$restore) {
+ function dialogue_entries_restore($new_dialogue_id, $new_conversation_id,$info,$restore) {
global $CFG;
$status = true;
//Get the entries array
- $entries = $info['MOD']['#']['ENTRIES']['0']['#']['ENTRY'];
-
- //Iterate over entries
- for($i = 0; $i < sizeof($entries); $i++) {
- $entry_info = $entries[$i];
- //traverse_xmlize($entry_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //We'll need this later!!
- $oldid = backup_todb($sub_info['#']['ID']['0']['#']);
- $olduserid = backup_todb($sub_info['#']['USERID']['0']['#']);
-
- //Now, build the dialogue_ENTRIES record structure
- $entry->dialogue = $new_dialogue_id;
- $entry->conversationid = $conversation->id;
- $entry->userid = backup_todb($entry_info['#']['USERID']['0']['#']);
- $entry->timecreated = backup_todb($entry_info['#']['TIMECREATED']['0']['#']);
- $entry->mailed = backup_todb($entry_info['#']['MAILED']['0']['#']);
- $entry->text = backup_todb($entry_info['#']['TEXT']['0']['#']);
-
- //We have to recode the userid field
- $user = backup_getid($restore->backup_unique_code,"user",$entry->userid);
- if ($user) {
- $entry->userid = $user->new_id;
- }
+ if (isset($info['#']['ENTRIES']['0']['#']['ENTRY'])) {
+ $entries = $info['#']['ENTRIES']['0']['#']['ENTRY'];
+
+ //Iterate over entries
+ for($i = 0; $i < sizeof($entries); $i++) {
+ $entry_info = $entries[$i];
+ //traverse_xmlize($entry_info); //Debug
+ //print_object ($GLOBALS['traverse_array']); //Debug
+ //$GLOBALS['traverse_array']=""; //Debug
+
+ //We'll need this later!!
+ $oldid = backup_todb($entry_info['#']['ID']['0']['#']);
+ $olduserid = backup_todb($entry_info['#']['USERID']['0']['#']);
+
+ //Now, build the dialogue_ENTRIES record structure
+ $entry->dialogue = $new_dialogue_id;
+ $entry->conversationid = $new_conversation_id;
+ $entry->userid = backup_todb($entry_info['#']['USERID']['0']['#']);
+ $entry->timecreated = backup_todb($entry_info['#']['TIMECREATED']['0']['#']);
+ $entry->mailed = backup_todb($entry_info['#']['MAILED']['0']['#']);
+ $entry->text = backup_todb($entry_info['#']['TEXT']['0']['#']);
+
+ //We have to recode the userid field
+ $user = backup_getid($restore->backup_unique_code,"user",$entry->userid);
+ if ($user) {
+ $entry->userid = $user->new_id;
+ }
- //The structure is equal to the db, so insert the dialogue_entry
- $newid = insert_record ("dialogue_entries",$entry);
+ //The structure is equal to the db, so insert the dialogue_entry
+ $newid = insert_record ("dialogue_entries",$entry);
- //Do some output
- if (($i+1) % 50 == 0) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br>";
+ //Do some output
+ if (($i+1) % 50 == 0) {
+ echo ".";
+ if (($i+1) % 1000 == 0) {
+ echo "<br>";
+ }
+ backup_flush(300);
}
- backup_flush(300);
- }
- if ($newid) {
- //We have the newid, update backup_ids
- backup_putid($restore->backup_unique_code,"dialogue_entry",$oldid,
- $newid);
- } else {
- $status = false;
+ if ($newid) {
+ //We have the newid, update backup_ids
+ backup_putid($restore->backup_unique_code,"dialogue_entry",$oldid,
+ $newid);
+ } else {
+ $status = false;
+ }
}
}