Exemplo n.º 1
0
function liveclassroom_delete_all_instance_of_room($roomid)
{
    global $CFG;
    // / Given an ID of an instance of this module,
    // / this function will permanently delete the instance
    // / and any data that depends on it.
    $api = new LCApi($CFG->liveclassroom_servername, $CFG->liveclassroom_adminusername, $CFG->liveclassroom_adminpassword);
    $result = true;
    if ($liveclassrooms = get_records("liveclassroom", "type", $roomid)) {
        $roomname = $api->lcapi_get_room_name($liveclassroom->type);
        // Delete any dependent records here #
        foreach ($liveclassrooms as $liveclassroom) {
            // get the course_module instance linked to the liveclassroom instance
            if (!($cm = get_coursemodule_from_instance("liveclassroom", $liveclassroom->id, $liveclassroom->course))) {
                error("Course Module ID was incorrect");
            }
            if (!delete_course_module($cm->id)) {
                wimba_add_log(WIMBA_ERROR, WC, "Problem to delete the course module : " . $cm->id);
                $result = false;
                // Delete a course module and any associated data at the course level (events)
                // notify("Could not delete the $cm->id (coursemodule)");
            }
            if (!delete_records("liveclassroom", "id", "{$liveclassroom->id}")) {
                wimba_add_log(WIMBA_ERROR, WC, "Problem to delete all the activities associated to the voice tools");
                $result = false;
            }
            // delete in the course section too
            if (!delete_mod_from_section($cm->id, "{$cm->section}")) {
                wimba_add_log(WIMBA_ERROR, WC, "Could not delete the " . $cm->id . " from that section : " . $cm->section);
                $result = false;
                // notify("Could not delete the $mod->modulename from that section");
            }
        }
    }
    return $result;
}