Exemplo n.º 1
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());
            }
        }
    }
}
    }
}
wimba_add_log(WIMBA_DEBUG, voicepresentation_LOGS, "manageAction : parameters  \n" . print_r($params, true));
require_login($params["enc_course_id"]);
$session = new WimbaMoodleSession($params);
$redirectionUrl = 'welcome.php?id=' . $params["enc_course_id"] . '&' . voicepresentation_get_url_params($params["enc_course_id"]) . '&time=' . $session->timeOfLoad;
$urlModuleForm = $CFG->wwwroot . '/course/mod.php?section=0&sesskey=' . sesskey() . '&id=' . $session->getCourseId() . '&add=voicepresentation&rid=';
$messageType = "";
if ($session->error === false && $session != NULL) {
    $vtAction = new vtAction($session->getEmail(), $params);
    if ($params['action'] == 'launch') {
        $session->setCurrentVtUSer($params["type"]);
        if ($params["studentView"] == "true") {
            $session->setVtUserRigths($params["type"], "student");
        }
        $resource = voicetools_api_get_resource($params["resource_id"]);
        $result = $vtAction->getVtSession($resource, $session->getVtUser(), $session->getVtUserRigths());
        if ($result != NULL) {
            wimba_add_log(WIMBA_DEBUG, voicepresentation_LOGS, "launch the " . $params["type"] . ", nid =" . $result->getNid());
            if (!empty($params["filter_screen_name"])) {
                redirection($CFG->voicetools_servername . '/' . $params["type"] . '?action=display_popup&nid=' . $result->getNid() . "&filter_screen_name=" . $params["filter_screen_name"]);
            } else {
                redirection($CFG->voicetools_servername . '/' . $params["type"] . '?action=display_popup&nid=' . $result->getNid());
            }
        } else {
            redirection($redirectionUrl . '&error=problem_vt');
        }
    } elseif ($params['action'] == 'create' || $params['action'] == "createDefault") {
        if ($params['type'] == "board") {
            $result = $vtAction->createBoard();
            //create the resource on the vt
} else {
    $vtUserRigths->setProfile('moodle.recorder.student');
    $type = "play";
}
$rid = voiceauthoring_get_resource_rid($course_id);
if ($rid === false) {
    $result = $vtAction->createRecorder("Voice Authoring associated to the course " . $course_id);
    //create the resource on the vt
    if ($result != NULL && $result->error != "error") {
        if (!storeResource($result->getRid(), $course_id, "recorder", $course_id . "_recorder")) {
            $rid = $result->getRid();
            //problem to insert the record in db
        }
    }
}
$resource = voicetools_api_get_resource($rid);
if ($resource) {
    //echo "<script language='javascript'>window.location.replace('error.php?error=problem_vt')</script>";
    //exit();
    $message = new vtMessage(null);
    $message->setMid($block_id);
    $result = $vtAction->getVtSession($resource, $vtUser, $vtUserRigths, $message);
    if ($result === false) {
        $error = "There is a problem to display the voice authoring";
        // echo "<script language='javascript'>window.location.replace('error.php?error=problem_vt')</script>";
        //  exit();
    }
    $recorderInformations = voiceauthoring_get_block_informations($block_id);
}
?>
        $params[$param["value"]] = $value;
    }
}
wimba_add_log(WIMBA_DEBUG, voicepresentation_LOGS, "getXmlListPanel : parameters  \n" . print_r($params, true));
require_login($params["enc_course_id"]);
$uiManager = new WimbaUI($params);
if ($uiManager->getSessionError() === false) {
    /*******************
       GET URL INFORMATIONS
       ********************/
    $action = optional_param('action', "");
    // Course Module ID, or
    $typeProduct = $params['type'];
    if ($action == 'update') {
        //get the information of the resource
        $currentBoard = voicetools_api_get_resource($params["resource_id"]);
        if (!isset($currentBoard) || $currentBoard->error == true) {
            wimba_add_log(WIMBA_ERROR, voicepresentation_LOGS, "getXmlNewPanel : " . get_string('problem_vt', 'voicepresentation'));
            $uiManager->setError(get_string('problem_vt', 'voicepresentation'));
        } else {
            $currentBoardInformations = voicepresentation_get_wimbaVoice_Informations($params["resource_id"]);
            $uiManager->setCurrentProduct($typeProduct, $currentBoard, $currentBoardInformations);
        }
    } else {
        $uiManager->setCurrentProduct($typeProduct);
    }
    $display = $uiManager->getVTSettingsView($action, $createWorkflow);
} else {
    wimba_add_log(WIMBA_ERROR, voicepresentation_LOGS, "getXmlNewPanel : " . get_string('error_session', 'voicepresentation'));
    $uiManager->setError(get_string('error_session', 'voicepresentation'));
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
 function getResource($rid)
 {
     $result = voicetools_api_get_resource($rid);
     return $result;
 }