function chat_delete_instance($id) { /// Given an ID of an instance of this module, /// this function will permanently delete the instance /// and any data that depends on it. if (!($chat = get_record('chat', 'id', $id))) { return false; } $result = true; # Delete any dependent records here # if (!delete_records('chat', 'id', $chat->id)) { $result = false; } if (!delete_records('chat_messages', 'chatid', $chat->id)) { $result = false; } if (!delete_records('chat_users', 'chatid', $chat->id)) { $result = false; } $pagetypes = page_import_types('mod/chat/'); foreach ($pagetypes as $pagetype) { if (!delete_records('block_instance', 'pageid', $chat->id, 'pagetype', $pagetype)) { $result = false; } } if (!delete_records('event', 'modulename', 'chat', 'instance', $chat->id)) { $result = false; } return $result; }
function bigbluebutton_delete_instance($id) { if (!($bigbluebutton = get_record('bigbluebutton', 'id', $id))) { return false; } $result = true; # Delete any dependent records here # if (!delete_records('bigbluebutton', 'id', $bigbluebutton->id)) { $result = false; } $pagetypes = page_import_types('mod/bigbluebutton/'); foreach ($pagetypes as $pagetype) { if (!delete_records('block_instance', 'pageid', $bigbluebutton->id, 'pagetype', $pagetype)) { $result = false; } } if (!delete_records('event', 'modulename', 'bigbluebutton', 'instance', $bigbluebutton->id)) { $result = false; } return $result; }
function backup_course_blocks($bf, $preferences) { global $CFG; $status = true; // Read all of the block table $blocks = blocks_get_record(); $pages = array(); $pages[] = page_create_object(PAGE_COURSE_VIEW, $preferences->backup_course); if (!empty($CFG->showblocksonmodpages)) { // get course structure $course = get_record('course', 'id', $preferences->backup_course); $modinfo =& get_fast_modinfo($course); foreach ($preferences->mods as $module) { if (!$module->backup) { continue; } if (empty($modinfo->instances[$module->name])) { continue; } $pagetypes = page_import_types('mod/' . $module->name . '/'); if (empty($pagetypes)) { continue; } foreach ($pagetypes as $pagetype) { foreach ($modinfo->instances[$module->name] as $cm) { if (!empty($module->instances[$cm->instance]->backup)) { $pages[] = page_create_object($pagetype, $cm->instance); } } } } } //Blocks open tag fwrite($bf, start_tag('BLOCKS', 2, true)); foreach ($pages as $page) { if ($instances = blocks_get_by_page($page)) { //Iterate over every block foreach ($instances as $position) { foreach ($position as $instance) { //If we somehow have a block with an invalid id, skip it if (empty($blocks[$instance->blockid]->name)) { continue; } $blockname = $blocks[$instance->blockid]->name; if (!($blockobj = block_instance($blockname, $instance))) { // Invalid block continue; } // encode absolute links in block config $instance->configdata = $blockobj->get_backup_encoded_config(); //Begin Block fwrite($bf, start_tag('BLOCK', 3, true)); fwrite($bf, full_tag('ID', 4, false, $instance->id)); fwrite($bf, full_tag('NAME', 4, false, $blockname)); fwrite($bf, full_tag('PAGEID', 4, false, $instance->pageid)); fwrite($bf, full_tag('PAGETYPE', 4, false, $instance->pagetype)); fwrite($bf, full_tag('POSITION', 4, false, $instance->position)); fwrite($bf, full_tag('WEIGHT', 4, false, $instance->weight)); fwrite($bf, full_tag('VISIBLE', 4, false, $instance->visible)); fwrite($bf, full_tag('CONFIGDATA', 4, false, $instance->configdata)); // Write instance data if needed if ($blockobj->backuprestore_instancedata_used()) { fwrite($bf, start_tag('INSTANCEDATA', 4, true)); $status = $blockobj->instance_backup($bf, $preferences); fwrite($bf, end_tag('INSTANCEDATA', 4, true)); } $context = get_context_instance(CONTEXT_BLOCK, $instance->id); write_role_overrides_xml($bf, $context, 4); /// write role_assign code here write_role_assignments_xml($bf, $preferences, $context, 4); //End Block fwrite($bf, end_tag('BLOCK', 3, true)); } } } } //Blocks close tag $status = fwrite($bf, end_tag('BLOCKS', 2, true)); return $status; }
function lesson_delete_instance($id) { /// Given an ID of an instance of this module, /// this function will permanently delete the instance /// and any data that depends on it. if (!($lesson = get_record("lesson", "id", "{$id}"))) { return false; } $result = true; if (!delete_records("lesson", "id", "{$lesson->id}")) { $result = false; } if (!delete_records("lesson_pages", "lessonid", "{$lesson->id}")) { $result = false; } if (!delete_records("lesson_answers", "lessonid", "{$lesson->id}")) { $result = false; } if (!delete_records("lesson_attempts", "lessonid", "{$lesson->id}")) { $result = false; } if (!delete_records("lesson_grades", "lessonid", "{$lesson->id}")) { $result = false; } if (!delete_records("lesson_timer", "lessonid", "{$lesson->id}")) { $result = false; } if (!delete_records("lesson_branch", "lessonid", "{$lesson->id}")) { $result = false; } if (!delete_records("lesson_high_scores", "lessonid", "{$lesson->id}")) { $result = false; } if ($events = get_records_select('event', "modulename = 'lesson' and instance = '{$lesson->id}'")) { foreach ($events as $event) { delete_event($event->id); } } $pagetypes = page_import_types('mod/lesson/'); foreach ($pagetypes as $pagetype) { if (!delete_records('block_instance', 'pageid', $lesson->id, 'pagetype', $pagetype)) { $result = false; } } lesson_grade_item_delete($lesson); return $result; }
function quiz_delete_instance($id) { /// Given an ID of an instance of this module, /// this function will permanently delete the instance /// and any data that depends on it. if (!($quiz = get_record("quiz", "id", "{$id}"))) { return false; } $result = true; if ($attempts = get_records("quiz_attempts", "quiz", "{$quiz->id}")) { // TODO: this should use the delete_attempt($attempt->uniqueid) function in questionlib.php // require_once($CFG->libdir.'/questionlib.php'); foreach ($attempts as $attempt) { if (!delete_records("question_states", "attempt", "{$attempt->uniqueid}")) { $result = false; } if (!delete_records("question_sessions", "attemptid", "{$attempt->uniqueid}")) { $result = false; } } } $tables_to_purge = array('quiz_attempts' => 'quiz', 'quiz_grades' => 'quiz', 'quiz_question_instances' => 'quiz', 'quiz_grades' => 'quiz', 'quiz_feedback' => 'quizid', 'quiz' => 'id'); foreach ($tables_to_purge as $table => $keyfield) { if (!delete_records($table, $keyfield, $quiz->id)) { $result = false; } } $pagetypes = page_import_types('mod/quiz/'); foreach ($pagetypes as $pagetype) { if (!delete_records('block_instance', 'pageid', $quiz->id, 'pagetype', $pagetype)) { $result = false; } } if ($events = get_records_select('event', "modulename = 'quiz' and instance = '{$quiz->id}'")) { foreach ($events as $event) { delete_event($event->id); } } quiz_grade_item_delete($quiz); return $result; }
function backup_course_blocks($bf, $preferences) { global $CFG; $status = true; // Read all of the block table $blocks = blocks_get_record(); $pages = array(); $pages[] = page_create_object(PAGE_COURSE_VIEW, $preferences->backup_course); // Let's see if we have to backup blocks from modules $modulerecords = get_records_sql('SELECT name, id FROM ' . $CFG->prefix . 'modules'); foreach ($preferences->mods as $module) { if (!$module->backup) { continue; } $cmods = get_records_select('course_modules', 'course = ' . $preferences->backup_course . ' AND module = ' . $modulerecords[$module->name]->id); if (empty($cmods)) { continue; } $pagetypes = page_import_types('mod/' . $module->name . '/'); if (empty($pagetypes)) { continue; } foreach ($pagetypes as $pagetype) { foreach ($cmods as $cmod) { $pages[] = page_create_object($pagetype, $cmod->instance); } } } //Blocks open tag fwrite($bf, start_tag('BLOCKS', 2, true)); while ($page = array_pop($pages)) { if ($instances = blocks_get_by_page($page)) { //Iterate over every block foreach ($instances as $position) { foreach ($position as $instance) { //If we somehow have a block with an invalid id, skip it if (empty($blocks[$instance->blockid]->name)) { continue; } //Begin Block fwrite($bf, start_tag('BLOCK', 3, true)); fwrite($bf, full_tag('ID', 4, false, $instance->id)); fwrite($bf, full_tag('NAME', 4, false, $blocks[$instance->blockid]->name)); fwrite($bf, full_tag('PAGEID', 4, false, $instance->pageid)); fwrite($bf, full_tag('PAGETYPE', 4, false, $instance->pagetype)); fwrite($bf, full_tag('POSITION', 4, false, $instance->position)); fwrite($bf, full_tag('WEIGHT', 4, false, $instance->weight)); fwrite($bf, full_tag('VISIBLE', 4, false, $instance->visible)); fwrite($bf, full_tag('CONFIGDATA', 4, false, $instance->configdata)); $context = get_context_instance(CONTEXT_BLOCK, $instance->id); write_role_overrides_xml($bf, $context, 4); /// write role_assign code here write_role_assignments_xml($bf, $preferences, $context, 4); //End Block fwrite($bf, end_tag('BLOCK', 3, true)); } } } } //Blocks close tag $status = fwrite($bf, end_tag('BLOCKS', 2, true)); return $status; }
if (!($page = page_get($pageid))) { error('Invalid page ID'); } } // Ensure this page is with this course if ($page->courseid != $course->id) { error(get_string('invalidpageid', 'format_page', $pageid)); } } else { // We don't have a page ID to work with if (has_capability('format/page:editpages', $context)) { $action = 'editpage'; $page = new stdClass(); $page->id = 0; } else { // Nothing this person can do about it, error out error(get_string('nopageswithcontent', 'format_page')); } } /// There are a couple processes that need some help via the session... take care of those. $action = page_handle_session_hacks($course->id, $action); /// Check if page wants to redirect if (!empty($page->redirect) && empty($action)) { redirect($page->redirect, '', 0); } /// Override PAGE_COURSE_VIEW class mapping page_import_types('course/format/page'); $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id); $PAGE->set_formatpage($page); /// Handle format actions page_format_execute_url_action($action);
} } else { // We don't have a page ID to work with if (has_capability('format/page:editpages', $context)) { $action = 'editpage'; $page = new stdClass(); $page->id = 0; } else { // Nothing this person can do about it, error out error(get_string('nopageswithcontent', 'format_page')); } } // TODO: put in equivalent of 'session hacks' used in page/format.php // Override PAGE_COURSE_VIEW class mapping // we need to reset various things that have been previously set by moodle core page_import_types('course/format/learning'); // note hat this includes /course/format/page/pagelib.php $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id); $PAGE->set_formatpage($page); $editing = $PAGE->user_is_editing(); $pageblocks = page_blocks_setup(); /// Handle format actions page_format_execute_url_action($action, $course); // ** Only get to his part if page_format_execute_url_action returns ** // /// Make sure the individual page is 'published' if (!($page->display & DISP_PUBLISH) and !(has_capability('format/page:editpages', $context) and $editing)) { error(get_string('thispageisnotpublished', 'format_page')); } /// Finally, we can print the page if ($editing) { $PAGE->print_tabs('layout');