function voicepodcaster_restore_mods($mod, $restore) { global $CFG; $status = true; //Get record from backup_ids $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id); $userdata = restore_userdata_selected($restore, "voicepodcaster", $mod->id); if ($data) { //Now get completed xmlized object $info = $data->info; $old_rid = $info['MOD']['#']['RID']['0']['#']; //add logs //Now, build the voicepodcaster record structure if ("voicepodcaster" == "voiceboard") { $typeCopy = "0"; //we copy all the content } else { $typeCopy = "1"; //we copy top messages } if ($userdata === true) { $copyOptions = $typeCopy; $resourceDbMatched = get_record("voicepodcaster_resources", "fromrid", $old_rid, "course", $restore->course_id, "copyoptions", $typeCopy); //resource which match the current copy options $resourceDbOther = get_record("voicepodcaster_resources", "fromrid", $old_rid, "course", $restore->course_id, "copyoptions", "2"); } else { $copyOptions = "2"; //delete all $resourceDbMatched = get_record("voicepodcaster_resources", "fromrid", $old_rid, "course", $restore->course_id, "copyoptions", "2"); $resourceDbOther = get_record("voicepodcaster_resources", "fromrid", $old_rid, "course", $restore->course_id, "copyoptions", $typeCopy); } if (empty($resourceDbMatched)) { // the resource of the type needed was not created before $newResource = voicetools_api_copy_resource($old_rid, null, $copyOptions); if ($newResource === false) { return false; //error during the copy } $newResource = voicetools_api_get_resource($newResource->getRid()); // get all the informations if ($newResource === false) { return false; //error to get the resouce } $newResourceOptions = $newResource->getOptions(); $isGradable = $newResourceOptions->getGrade(); $resourceId = $newResource->getRid(); if (!empty($resourceDbOther)) { //the other type was created, need to update one name if ($copyOptions == $typeCopy) { //we have to update the name of the new one $newResource->setTitle($newResource->getTitle() . " with user data"); if (voicetools_api_modify_resource($newResource->getResource()) === false) { return false; //error to get the resouce } //save some parameters that we will used to manage the grade column $title = $newResource->getTitle(); $ridForGrade = $newResource->getRid(); $pointsPossible = $newResourceOptions->getPointsPossible(); $actionGradebook = "create"; //we will only need to create the grade column with grades for the second resource. } else { //we have to update the other which was the one with user data $otherResource = voicetools_api_get_resource($resourceDbOther->rid); if ($otherResource === false) { return false; //error to get the resouce } $otherResource->setTitle($otherResource->getTitle() . " with user data"); if (voicetools_api_modify_resource($otherResource->getResource()) === false) { return false; //error to get the resouce } $title = $otherResource->getTitle(); $ridForGrade = $otherResource->getRid(); $otherResourceOptions = $otherResource->getOptions(); $pointsPossible = $otherResourceOptions->getPointsPossible(); $actionGradebook = "update"; //we will only have to update the name of the grade column and create a new one } //we store the new resource in the database; } //update the moodle database voicepodcaster_createResourceFromResource($old_rid, $resourceId, $restore->course_id, $copyOptions); } else { //the resource already exist $resourceId = $resourceDbMatched->rid; $isGradable = false; } $voicefeature->course = backup_todb($restore->course_id); $voicefeature->rid = backup_todb($resourceId); $voicefeature->name = str_replace(backup_todb($old_rid), $resourceId, backup_todb($info['MOD']['#']['NAME']['0']['#'])); $voicefeature->section = backup_todb($info['MOD']['#']['SECTION']['0']['#']); $voicefeature->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); $voicefeature->isfirst = 1; //The structure is equal to the db, so insert the voicepodcaster $newActivityId = insert_record("voicepodcaster", $voicefeature); if ($isGradable == 'true') { //the old vb was gradable //the activity linked has changed due to the copy, we need to update it to be able to match the good grade column $vb = get_record("voicepodcaster_resources", "rid", $resourceId); $vb->gradeid = $newActivityId; update_record("voicepodcaster_resources", $vb); $oldResourceDb = get_record("voicepodcaster_resources", "rid", $old_rid); $students = getStudentsEnrolled($oldResourceDb->course); $users_key = array_keys($students); //get the grade of the initial resource $gradesfromInitialResource = grade_get_grades($oldResourceDb->course, "mod", "voicepodcaster", $oldResourceDb->gradeid, $users_key); $grades = null; if (isset($gradesfromInitialResource->items[0])) { $grades = voicepodcaster_build_gradeObject_From_ArrayOfGradeInfoObjects($gradesfromInitialResource->items[0]->grades); } if (isset($actionGradebook) && $actionGradebook == "update") { //we update the name of the column (add "with user data") voicepodcaster_delete_grade_column($ridForGrade, $restore->course_id, $newActivityId); //delete the one automatically created by moodle voicepodcaster_add_grade_column($ridForGrade, $restore->course_id, $title, $pointsPossible, $grades); //we need to create the grade column with contains no grade( user data was unchecked); voicepodcaster_add_grade_column($newResource->getRid(), $restore->course_id, $newResource->getTitle(), $newResourceCopyOptions->getPointsPossible()); } else { if (isset($actionGradebook) && $actionGradebook == "create") { voicepodcaster_add_grade_column($ridForGrade, $restore->course_id, $title, $pointsPossible, $grades); } } } //Do some output if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("modulename", "voicepodcaster") . " \"" . format_string(stripslashes($voicefeature->name), true) . "\"</li>"; } backup_flush(300); if ($newActivityId) { //We have the newid, update backup_ids backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newActivityId); } else { $status = false; } } else { $status = false; } return $status; }
/** * Actual implementation of the rest coures functionality, delete all the * chat messages for course $data->courseid. * @param $data the data submitted from the reset course. * @return array status array */ function voicepresentation_delete_userdata($data, $showfeedback = true) { global $CFG; $componentstr = get_string('modulenameplural', 'voicepresentation'); if (!empty($data->reset_content_voicepresentation_replies)) { $resources = get_records("voicepresentation_resources", "course", $data->id); foreach (array_keys($resources) as $id) { $rid = $resources[$id]->rid; $activities = get_records("voicepresentation", "rid", $rid); $newResource = voicetools_api_copy_resource($rid, "", 1); //delete the old one and update the stored record //voicetools_api_delete_resource($rid); $resources[$id]->rid = $newResource->getRid(); update_record("voicepresentation_resources", $resources[$id]); //need to update the rid linked to the activity foreach (array_keys($activities) as $activity_id) { $activities[$activity_id]->rid = $newResource->getRid(); update_record("voicepresentation", $activities[$activity_id]); } } $typestr = get_string("voicepresentation_reset_only_replies", 'voicepresentation'); if ($showfeedback) { $strreset = get_string('reset'); notify($strreset . ': ' . $typestr, 'notifysuccess'); } } if (!empty($data->reset_content_voicepresentation)) { $resources = get_records("voicepresentation_resources", "course", $data->id); foreach (array_keys($resources) as $id) { $rid = $resources[$id]->rid; $activities = get_records("voicepresentation", "rid", $rid); $newResource = voicetools_api_copy_resource($rid, "", 2); //delete the old one and update the stored record //voicetools_api_delete_resource($rid); $resources[$id]->rid = $newResource->getRid(); update_record("voicepresentation_resources", $resources[$id]); foreach (array_keys($activities) as $activity_id) { $activities[$activity_id]->rid = $newResource->getRid(); update_record("voicepresentation", $activities[$activity_id]); } } $typestr = get_string("voicepresentation_reset_all", 'voicepresentation'); if ($showfeedback) { $strreset = get_string('reset'); notify($strreset . ': ' . $typestr, 'notifysuccess'); } } //the gradebook is completely reset, we have to manage that on our side. The grade setting of the resource has to be updated if (!empty($data->reset_gradebook_items)) { $resources = get_records("voicepresentation_resources", "course", $data->id); foreach (array_keys($resources) as $id) { if ($resources[$id]->gradeid != "-1") { $resources[$id]->gradeid = "-1"; update_record("voicepresentation_resources", $resources[$id]); $resource = voicetools_api_get_resource($resources[$id]->rid); $options = $resource->getOptions(); $options->setPointsPossible(""); $options->setGrade(false); $resource->setOptions($options); voicetools_api_modify_resource($resource->getResource()); } } } }
function updateVMmail($id, $title) { $resource = new vtResource(NULL); $audio = new vtAudioFormat(NULL); $options = new VtOptions(NULL); // Info $resource->setType("vmail"); $resource->setMail($this->creator); if (isset($this->params["name"])) { $resource->setTitle(stripslashes($this->params["name"])); } //Media $audio->setName($this->params["audio_format"]); $options->setMaxLength($this->params["max_length"]); $options->setReplyLink($this->params["reply_link"]); if (isset($this->params["subject"])) { $options->setSubject($this->params["subject"]); } else { $options->setSubject(""); } $options->setTo($this->params["recipients"]); $options->setAudioFormat($audio); $resource->setOptions($options); //create the resource on the vt server $resource->setRid($id); //create the resource on the vt server $result = voicetools_api_modify_resource($resource->getResource()); return $result; }