Пример #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 liveclassroom_reset_userdata($data, $showfeedback = true)
{
    global $CFG, $COURSE;
    $componentstr = get_string('modulenameplural', 'liveclassroom');
    $status = array();
    if (!empty($data->reset_content_liveclassroom_all)) {
        $api = new LCAction(null, $CFG->liveclassroom_servername, $CFG->liveclassroom_adminusername, $CFG->liveclassroom_adminpassword, $CFG->dataroot);
        $rooms = $api->getRooms($data->id . "_T");
        foreach ($rooms as $room) {
            if ($room->isArchive() == 0) {
                $isAdmin = $api->isStudentAdmin($room->getRoomId(), $data->id . "_S");
                $api->cloneRoom($data->id, $room->getRoomId(), "0", $isAdmin, $room->isPreview());
                if ($isAdmin == "true") {
                    $api->removeRole($room->getRoomId(), $data->id . "_S", "Student");
                    $api->removeRole($room->getRoomId(), $data->id . "_T", "ClassAdmin");
                } else {
                    $api->removeRole($room->getRoomId(), $data->id . "_S", "Instructor");
                    $api->removeRole($room->getRoomId(), $data->id . "_T", "ClassAdmin");
                }
            } else {
                $api->deleteRoom($room->getRoomId());
            }
            $activities = get_records("liveclassroom", "id", $room->getRoomId());
            foreach (array_keys($activities) as $id) {
                $activities[$id]->rid = new_rid;
                update_record("liveclassroom", $activities[$id]);
            }
        }
        $typesstr = "Delete all the archives and content";
        $status[] = array('component' => $componentstr, 'item' => $typesstr, 'error' => false);
    } else {
        if (!empty($data->reset_content_liveclassroom_archives)) {
            $api = new LCAction(null, $CFG->liveclassroom_servername, $CFG->liveclassroom_adminusername, $CFG->liveclassroom_adminpassword, $CFG->dataroot);
            $rooms = $api->getRooms($data->id . "_T");
            foreach ($rooms as $room) {
                if ($room->isArchive() == 1) {
                    $api->deleteRoom($room->getRoomId());
                }
            }
            $typesstr = "Delete only the archives";
            $status[] = array('component' => $componentstr, 'item' => $typesstr, 'error' => false);
        }
    }
    return $status;
}
Пример #2
0
function liveclassroom_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, "liveclassroom", $mod->id);
    $lcAction = new LCAction(null, $CFG->liveclassroom_servername, $CFG->liveclassroom_adminusername, $CFG->liveclassroom_adminpassword, $CFG->dataroot, $restore->course_id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //add logs
        //Now, build the liveclassroom record structure
        $copy_content = 0;
        if ($userdata) {
            $copy_content = 1;
        }
        $sameResource = get_record("liveclassroom", "fromid", $info['MOD']['#']['TYPE']['0']['#'], "course", $restore->course_id, "copy_content", $copy_content);
        $resource = get_record("liveclassroom", "fromid", $info['MOD']['#']['TYPE']['0']['#'], "course", $restore->course_id, "copy_content", $copy_content == 1 ? 0 : 1);
        if (empty($sameResource)) {
            if (!($new_lc_id = $lcAction->cloneRoom($restore->course_id, $info['MOD']['#']['TYPE']['0']['#'], $userdata, $info['MOD']['#']['ISSTUDENTADMIN']['0']['#'], $info['MOD']['#']['PREVIEW']['0']['#']))) {
                return false;
                //there is a problem during the copy of the room
            }
            if (!empty($resource)) {
                if ($userdata) {
                    $room = $lcAction->getRoom($new_lc_id);
                    $room->setLongname($room->getLongname() . " with user data");
                    $lcAction->api->lcapi_modify_room($new_lc_id, $room->getAttributes());
                } else {
                    $room = $lcAction->getRoom($resource->type);
                    $room->setLongname($room->getLongname() . " with user data");
                    $lcAction->api->lcapi_modify_room($resource->type, $room->getAttributes());
                }
            }
        } else {
            $new_lc_id = $resource->type;
        }
        $liveclassroom->course = backup_todb($restore->course_id);
        $liveclassroom->type = backup_todb($new_lc_id);
        $liveclassroom->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $liveclassroom->section = backup_todb($info['MOD']['#']['SECTION']['0']['#']);
        $liveclassroom->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $liveclassroom->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $liveclassroom->fromid = $info['MOD']['#']['TYPE']['0']['#'];
        $liveclassroom->copy_content = $copy_content;
        $liveclassroom->isfirst = 1;
        //The structure is equal to the db, so insert the liveclassroom
        $newid = insert_record("liveclassroom", $liveclassroom);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "liveclassroom") . " \"" . format_string(stripslashes($liveclassroom->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;
}