function voiceauthoring_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, "voiceauthoring", $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //add logs
        //Now, build the voiceauthoring record structure
        $resource = get_record("voiceauthoring_resources", "fromrid", $info['MOD']['#']['RID']['0']['#'], "course", $restore->course_id);
        if (empty($resource)) {
            $resourceCopy = voicetools_api_copy_resource($info['MOD']['#']['RID']['0']['#'], null, "0");
            if ($resourceCopy === false) {
                return false;
                //error to copy the resource
            }
            $resourceId = $resourceCopy->getRid();
            voiceauthoring_createResourceFromResource($info['MOD']['#']['RID']['0']['#'], $resourceId, $restore->course_id);
        }
        if ($userdata === false) {
            $mid = $resource->mid + 1;
            $resource->mid = $resource->mid + 1;
            update_record("voiceauthoring_resources", $resource);
            $name = str_replace(backup_todb($info['MOD']['#']['MID']['0']['#']), $mid, backup_todb($info['MOD']['#']['NAME']['0']['#']));
        } else {
            $mid = backup_todb(backup_todb($info['MOD']['#']['MID']['0']['#']));
            $name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        }
        $voiceauthoring->course = backup_todb($restore->course_id);
        $voiceauthoring->rid = backup_todb($resourceId);
        $voiceauthoring->mid = $mid;
        $voiceauthoring->name = str_replace(backup_todb($info['MOD']['#']['RID']['0']['#']), $resourceId, $name);
        $voiceauthoring->activityname = backup_todb($info['MOD']['#']['ACTIVITY_NAME']['0']['#']);
        $voiceauthoring->section = backup_todb($info['MOD']['#']['SECTION']['0']['#']);
        $voiceauthoring->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $voiceauthoring->isfirst = 1;
        //The structure is equal to the db, so insert the voiceauthoring
        $newid = insert_record("voiceauthoring", $voiceauthoring);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "voiceauthoring") . " \"" . format_string(stripslashes(stripslashes($voiceauthoring->name)), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
function voiceemail_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, "voiceemail", $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //add logs
        //Now, build the voiceemail record structure
        if ($userdata === true) {
            $copyOptions = "0";
            //top message
        } else {
            $copyOptions = "2";
            //top message
        }
        $oldResource = get_record("voiceemail_resources", "id", $info['MOD']['#']['RID']['0']['#']);
        $resourceId = $oldResource->rid;
        $resource = voicetools_api_copy_resource($resourceId, null, $copyOptions);
        if ($resource === false) {
            return false;
            //error to copy the resource
        }
        $bdId = voiceemail_createResourceFromResource($resourceId, $resource->getRid(), $restore->course_id);
        $voiceemail->course = backup_todb($restore->course_id);
        $voiceemail->rid = backup_todb($bdId);
        $voiceemail->recipients_email = backup_todb(backup_todb($info['MOD']['#']['RECIPIENTS_EMAIL']['0']['#']));
        $voiceemail->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $voiceemail->section = backup_todb($info['MOD']['#']['SECTION']['0']['#']);
        $voiceemail->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $voiceemail->isfirst = 1;
        //The structure is equal to the db, so insert the voiceemail
        $newid = insert_record("voiceemail", $voiceemail);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "voiceemail") . " \"" . format_string(stripslashes($voiceemail->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Example #3
0
/**
* 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());
            }
        }
    }
}
Example #4
0
/**
 * For moodle version < 1.9
 * 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 voiceauthoring_delete_userdata($data)
{
    global $CFG;
    $componentstr = get_string('modulenameplural', 'voiceauthoring');
    $typesstr = "Delete all message";
    $status = array();
    if (!empty($data->reset_content_voiceauthoring)) {
        $resource = get_record("voiceauthoring_resources", "course", $data->id);
        $rid = $resource->rid;
        $newResource = voicetools_api_copy_resource($rid, "", 2);
        //delete the old one and update the stored record
        //voicetools_api_delete_resource($rid);
        $resource->rid = $newResource->getRid();
        update_record("voiceauthoring_resources", $resource);
        //update all the activities which use this resource
        $activities = get_records("voiceauthoring", "rid", $rid);
        foreach (array_keys($activities) as $activity_id) {
            $new_rid = $newResource->getRid();
            $activities[$activity_id]->name = str_replace($rid, $new_rid, $activities[$activity_id]->name);
            $activities[$activity_id]->rid = $new_rid;
            $activities[$activity_id]->name = addslashes($activities[$activity_id]->name);
            update_record("voiceauthoring", $activities[$activity_id]);
        }
        $status[] = array('component' => $componentstr, 'item' => $typesstr, 'error' => false);
    }
    rebuild_course_cache($data->id);
    return $status;
}
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;
}
Example #6
0
/**
* For moodle version < 1.9
* 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 voiceemail_delete_userdata($data, $showfeedback = true)
{
    global $CFG;
    $componentstr = get_string('modulenameplural', 'voiceemail');
    $typesstr = "Delete history";
    if (!empty($data->reset_content_voiceemail)) {
        $resources = get_records("voiceemail_resources", "course", $data->id);
        foreach (array_keys($resources) as $id) {
            $rid = $resources[$id]->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("voiceemail_resources", $resources[$id]);
        }
        if ($showfeedback) {
            $strreset = get_string('reset');
            notify($strreset . ': ' . $typestr, 'notifysuccess');
        }
    }
}