当前位置: 首页>>代码示例>>PHP>>正文


PHP delete_mod_from_section函数代码示例

本文整理汇总了PHP中delete_mod_from_section函数的典型用法代码示例。如果您正苦于以下问题:PHP delete_mod_from_section函数的具体用法?PHP delete_mod_from_section怎么用?PHP delete_mod_from_section使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了delete_mod_from_section函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: delete

 private static function delete($modulename, $course, $title, $section)
 {
     global $DB, $CFG;
     $sql = 'SELECT cm.id FROM {course_sections} AS cs JOIN {course_modules} AS cm ON cm.section = cs.id JOIN {modules} AS ms ON ms.id = cm.module JOIN {' . $modulename . '} AS m ON m.id = cm.instance WHERE cs.course = ? AND cs.section = ? AND m.name = ? AND ms.name = ?';
     $instances = $DB->get_records_sql($sql, array($course->id, $section, $title, $modulename));
     foreach ($instances as $instance) {
         $cm = get_coursemodule_from_id('', $instance->id);
         $modlib = "{$CFG->dirroot}/mod/{$cm->modname}/lib.php";
         if (file_exists($modlib)) {
             require_once $modlib;
         } else {
             return false;
         }
         $deleteinstancefunction = $cm->modname . "_delete_instance";
         if (!$deleteinstancefunction($cm->instance)) {
             return false;
         }
         if (!delete_course_module($cm->id)) {
             return false;
         }
         if (!delete_mod_from_section($cm->id, $cm->section)) {
             return false;
         }
         // Trigger a mod_deleted event with information about this module.
         $eventdata = new stdClass();
         $eventdata->modulename = $cm->modname;
         $eventdata->cmid = $cm->id;
         $eventdata->courseid = $course->id;
         $eventdata->userid = 0;
         events_trigger('mod_deleted', $eventdata);
     }
     return true;
 }
开发者ID:OBU-OBIS,项目名称:moodle-block_module_add,代码行数:33,代码来源:course_mod_add.php

示例2: ma_delete_execute

function ma_delete_execute($modids)
{
    global $CFG;
    $in_list = "(" . join(", ", $modids) . ")";
    $sql = "SELECT cm.id as coursemodule, cm.section, cm.course, mo.name as modulename, instance\n        FROM {$CFG->prefix}course_modules cm\n        LEFT JOIN {$CFG->prefix}modules mo on mo.id=cm.module\n        WHERE cm.id IN {$in_list}";
    $records = get_records_sql($sql);
    $courses = array();
    $message = '';
    if ($records) {
        foreach ($records as $id => $record) {
            $modlib = "{$CFG->dirroot}/mod/{$record->modulename}/lib.php";
            $courses[] = $record->course;
            if (file_exists($modlib)) {
                include_once $modlib;
            } else {
                $message .= "This module is missing important code! ({$modlib})  ";
                continue;
            }
            $deleteinstancefunction = $record->modulename . "_delete_instance";
            if (!$deleteinstancefunction($record->instance)) {
                $message .= "Could not delete the {$record->modulename} (instance)  ";
                continue;
            }
            if (!delete_course_module($record->coursemodule)) {
                $message .= "Could not delete the {$record->modulename} (coursemodule)  ";
                continue;
            }
            if (!delete_mod_from_section($record->coursemodule, "{$record->section}")) {
                $message .= "Could not delete the {$record->modulename} from that section  ";
                continue;
            }
        }
    }
    return $message;
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:35,代码来源:delete.php

示例3: voiceauthoring_update_instance

function voiceauthoring_update_instance($voicetool)
{
    /// Given an object containing all the necessary data,
    /// (defined by the form in mod.html) this function
    global $USER;
    global $CFG;
    //get the course_module instance linked to the liveclassroom instance
    if (!($cm = get_coursemodule_from_instance("voiceauthoring", $voicetool->instance, $voicetool->course))) {
        wimba_add_log(WIMBA_ERROR, voiceauthoring_LOGS, "Problem to update the instance : " . $voicetool->instance);
        error("Course Module ID was incorrect");
    }
    if ($voicetool->section != $cm->section) {
        //Find the right section in the course_section
        if (!($section = get_record("course_sections", "id", $cm->section))) {
            return false;
        }
        //delete in the course section
        if (!delete_mod_from_section($cm->id, $cm->section)) {
            return false;
        }
        //update the course module section
        if (!($sectionid = add_mod_to_section($voicetool))) {
            wimba_add_log(WIMBA_ERROR, voiceauthoring_LOGS, "Problem to update the instance : " . $voicetool->instance);
            error("Could not add the new course module to that section");
        }
        //update the course modules
        if (!set_field("course_modules", "section", $sectionid, "id", $cm->id)) {
            wimba_add_log(WIMBA_ERROR, voiceauthoring_LOGS, "Problem to update the instance : " . $voicetool->instance);
            error("Could not update the course module with the correct section");
        }
    }
    $voicetool->timemodified = time();
    $objectPath = $CFG->wwwroot . "/mod/voiceauthoring/enableVA.php";
    $imgPath = $CFG->wwwroot . "/mod/voiceauthoring/lib/web/pictures/items/speaker-18.gif";
    $iFramePath = $CFG->wwwroot . "/mod/voiceauthoring/displayPlayer.php?rid=" . $voicetool->rid . "&mid=" . $voicetool->mid;
    $iFramePath1 = $CFG->wwwroot . "/mod/voiceauthoring/displayActivityName.php?rid=" . $voicetool->rid . "&mid=" . $voicetool->mid . "&title=" . urlencode($voicetool->name);
    $voicetool->activityname = htmlspecialchars($voicetool->name, ENT_QUOTES);
    $voicetool->name = "<iframe id=\\'" . $voicetool->rid . "_" . $voicetool->mid . "\\'  width=\\'0px\\' height=\\'0px\\' style=\\'float:left;display:none;position:absolute;overflow-x:hidden;overflow-y:hidden\\' frameborder=\\'0\\' scrolling=\\'no\\' allowTransparency=\\'true\\' >\n       </iframe><span id=\\'" . $voicetool->rid . "_" . $voicetool->mid . "_span\\'>" . $voicetool->name . "</span><iframe id=\\'" . $voicetool->rid . "_" . $voicetool->mid . "_name\\' src=\\'" . $iFramePath1 . "\\' frameborder=\\'0\\' scrolling=\\'no\\'  style=\\'overflow-x:hidden;overflow-y:hidden;\\' width=\\'20px\\' height=\\'20px\\' allowTransparency=\\'true\\'></iframe>";
    $voicetool->id = $voicetool->instance;
    $voicetool->isfirst = 0;
    if (!($voicetool->id = update_record('voiceauthoring', $voicetool))) {
        return false;
    }
    if (isset($voicetool->calendar_event) && $voicetool->calendar_event) {
        //no problem
        voiceauthoring_addCalendarEvent($voicetool, $voicetool->instance);
    } else {
        voiceauthoring_deleteCalendarEvent($voicetool->instance);
    }
    set_config("allowobjectembed", 1);
    set_config("formatstringstriptags", 0);
    wimba_add_log(WIMBA_INFO, voiceauthoring_LOGS, "Update of the instance : " . $voicetool->id);
    return $voicetool->id;
}
开发者ID:nagyistoce,项目名称:moodle-Teach-Pilot,代码行数:54,代码来源:lib.php

示例4: uninstall_cleanup

 /**
  * Pre-uninstall hook.
  *
  * This is intended for disabling of plugin, some DB table purging, etc.
  *
  * NOTE: to be called from uninstall_plugin() only.
  * @private
  */
 public function uninstall_cleanup()
 {
     global $DB, $CFG;
     if (!($module = $DB->get_record('modules', array('name' => $this->name)))) {
         parent::uninstall_cleanup();
         return;
     }
     // Delete all the relevant instances from all course sections.
     if ($coursemods = $DB->get_records('course_modules', array('module' => $module->id))) {
         foreach ($coursemods as $coursemod) {
             // Do not verify results, there is not much we can do anyway.
             delete_mod_from_section($coursemod->id, $coursemod->section);
         }
     }
     // Increment course.cacherev for courses that used this module.
     // This will force cache rebuilding on the next request.
     increment_revision_number('course', 'cacherev', "id IN (SELECT DISTINCT course\n                      FROM {course_modules}\n                     WHERE module=?)", array($module->id));
     // Delete all the course module records.
     $DB->delete_records('course_modules', array('module' => $module->id));
     // Delete module contexts.
     if ($coursemods) {
         foreach ($coursemods as $coursemod) {
             \context_helper::delete_instance(CONTEXT_MODULE, $coursemod->id);
         }
     }
     // Delete the module entry itself.
     $DB->delete_records('modules', array('name' => $module->name));
     // Cleanup the gradebook.
     require_once $CFG->libdir . '/gradelib.php';
     grade_uninstalled_module($module->name);
     // Do not look for legacy $module->name . '_uninstall any more,
     // they should have migrated to db/uninstall.php by now.
     parent::uninstall_cleanup();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:42,代码来源:mod.php

示例5: uninstall_plugin

/**
 * Automatically clean-up all plugin data and remove the plugin DB tables
 *
 * @param string $type The plugin type, eg. 'mod', 'qtype', 'workshopgrading' etc.
 * @param string $name The plugin name, eg. 'forum', 'multichoice', 'accumulative' etc.
 * @uses global $OUTPUT to produce notices and other messages
 * @return void
 */
function uninstall_plugin($type, $name)
{
    global $CFG, $DB, $OUTPUT;
    // recursively uninstall all module subplugins first
    if ($type === 'mod') {
        if (file_exists("{$CFG->dirroot}/mod/{$name}/db/subplugins.php")) {
            $subplugins = array();
            include "{$CFG->dirroot}/mod/{$name}/db/subplugins.php";
            foreach ($subplugins as $subplugintype => $dir) {
                $instances = get_plugin_list($subplugintype);
                foreach ($instances as $subpluginname => $notusedpluginpath) {
                    uninstall_plugin($subplugintype, $subpluginname);
                }
            }
        }
    }
    $component = $type . '_' . $name;
    // eg. 'qtype_multichoice' or 'workshopgrading_accumulative' or 'mod_forum'
    if ($type === 'mod') {
        $pluginname = $name;
        // eg. 'forum'
        if (get_string_manager()->string_exists('modulename', $component)) {
            $strpluginname = get_string('modulename', $component);
        } else {
            $strpluginname = $component;
        }
    } else {
        $pluginname = $component;
        if (get_string_manager()->string_exists('pluginname', $component)) {
            $strpluginname = get_string('pluginname', $component);
        } else {
            $strpluginname = $component;
        }
    }
    echo $OUTPUT->heading($pluginname);
    $plugindirectory = get_plugin_directory($type, $name);
    $uninstalllib = $plugindirectory . '/db/uninstall.php';
    if (file_exists($uninstalllib)) {
        require_once $uninstalllib;
        $uninstallfunction = 'xmldb_' . $pluginname . '_uninstall';
        // eg. 'xmldb_workshop_uninstall()'
        if (function_exists($uninstallfunction)) {
            if (!$uninstallfunction()) {
                echo $OUTPUT->notification('Encountered a problem running uninstall function for ' . $pluginname);
            }
        }
    }
    if ($type === 'mod') {
        // perform cleanup tasks specific for activity modules
        if (!($module = $DB->get_record('modules', array('name' => $name)))) {
            print_error('moduledoesnotexist', 'error');
        }
        // delete all the relevant instances from all course sections
        if ($coursemods = $DB->get_records('course_modules', array('module' => $module->id))) {
            foreach ($coursemods as $coursemod) {
                if (!delete_mod_from_section($coursemod->id, $coursemod->section)) {
                    echo $OUTPUT->notification("Could not delete the {$strpluginname} with id = {$coursemod->id} from section {$coursemod->section}");
                }
            }
        }
        // clear course.modinfo for courses that used this module
        $sql = "UPDATE {course}\n                   SET modinfo=''\n                 WHERE id IN (SELECT DISTINCT course\n                                FROM {course_modules}\n                               WHERE module=?)";
        $DB->execute($sql, array($module->id));
        // delete all the course module records
        $DB->delete_records('course_modules', array('module' => $module->id));
        // delete module contexts
        if ($coursemods) {
            foreach ($coursemods as $coursemod) {
                if (!delete_context(CONTEXT_MODULE, $coursemod->id)) {
                    echo $OUTPUT->notification("Could not delete the context for {$strpluginname} with id = {$coursemod->id}");
                }
            }
        }
        // delete the module entry itself
        $DB->delete_records('modules', array('name' => $module->name));
        // cleanup the gradebook
        require_once $CFG->libdir . '/gradelib.php';
        grade_uninstalled_module($module->name);
        // Perform any custom uninstall tasks
        if (file_exists($CFG->dirroot . '/mod/' . $module->name . '/lib.php')) {
            require_once $CFG->dirroot . '/mod/' . $module->name . '/lib.php';
            $uninstallfunction = $module->name . '_uninstall';
            if (function_exists($uninstallfunction)) {
                debugging("{$uninstallfunction}() has been deprecated. Use the plugin's db/uninstall.php instead", DEBUG_DEVELOPER);
                if (!$uninstallfunction()) {
                    echo $OUTPUT->notification('Encountered a problem running uninstall function for ' . $module->name . '!');
                }
            }
        }
    } else {
        if ($type === 'enrol') {
            // NOTE: this is a bit brute force way - it will not trigger events and hooks properly
//.........这里部分代码省略.........
开发者ID:raymondAntonio,项目名称:moodle,代码行数:101,代码来源:adminlib.php

示例6: update_file

 public function update_file($cmid, $updatefilepath)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->dirroot . '/mod/resource/lib.php';
     require_once $CFG->dirroot . '/mod/resource/locallib.php';
     // course module should contain section (id)
     $coursemodule = $DB->get_record('course_modules', array('id' => $cmid), '*', MUST_EXIST);
     $course = $DB->get_record('course', array('id' => $coursemodule->course), '*', MUST_EXIST);
     $resource = $DB->get_record('resource', array('id' => $coursemodule->instance), '*', MUST_EXIST);
     self::require_access($course->id);
     // should be able to get record including context id and instance - file id
     $contextid = $DB->get_field('context', 'id', array('instanceid' => $coursemodule->id, 'contextlevel' => CONTEXT_MODULE));
     $fs = get_file_storage();
     $files = $fs->get_area_files($contextid, 'mod_resource', 'content', 0, 'sortorder, itemid, filepath, filename', false);
     foreach ($files as $file) {
         // delete the file
         $file->delete();
         // delete from database tables course_module, resource, context (via
         // delete course module), section sequence (via delete mod from
         // section), etext_usage
         $DB->delete_records('resource', array('id' => $resource->id));
         delete_mod_from_section($coursemodule, $coursemodule->section);
         delete_course_module($cmid);
         $DB->delete_records('coursereport_etexts_usage', array('cmid' => $cmid));
     }
     $this->add_file($coursemodule->section, $resource->name, $updatefilepath, $resource->display);
 }
开发者ID:nadavkav,项目名称:moodle-mod_subpage,代码行数:28,代码来源:externallib.php

示例7: move_item

 public static function move_item($user, $itemid, $courseid, $locationid)
 {
     global $DB, $USER;
     $params = self::validate_parameters(self::move_item_parameters(), array('user' => $user, 'itemid' => $itemid, 'courseid' => $courseid, 'locationid' => $locationid));
     $item = $DB->get_record('equella', array('id' => $params['itemid']), '*', MUST_EXIST);
     self::check_modify_permissions($params['user'], $item->course);
     $cm = get_coursemodule_from_instance('equella', $item->id, $item->course, false, MUST_EXIST);
     $oldCourse = $cm->course;
     $newCourse = $params['courseid'];
     $newSection = $DB->get_record('course_sections', array('course' => $newCourse, 'section' => $params['locationid']), '*', MUST_EXIST);
     delete_mod_from_section($cm->id, $cm->section);
     $cm->section = $newSection->id;
     $cm->course = $newCourse;
     $item->course = $newCourse;
     $item->section = $newSection->section;
     $item->instance = $cm->instance;
     $item->cm = $cm->id;
     $success = $DB->update_record("course_modules", $cm);
     if ($success) {
         $success = equella_update_instance($item);
         if (!($sectionid = course_add_cm_to_section($newCourse, $cm->id, $newSection->section))) {
             print_error('cannotaddcoursemoduletosection');
             return null;
         }
         if (class_exists('core\\event\\course_module_updated')) {
             $event = \core\event\course_module_updated::create_from_cm($cm);
             $event->trigger();
         } else {
             $eventdata = new stdClass();
             $eventdata->modulename = 'equella';
             $eventdata->name = $item->name;
             $eventdata->cmid = $cm->id;
             $eventdata->courseid = $item->course;
             $eventdata->userid = $USER->id;
             events_trigger('mod_updated', $eventdata);
             add_to_log($item->course, "course", "update mod", "../mod/equella/view.php?id={$cm->id}", "equella {$item->instance}");
             add_to_log($item->course, "equella", "update equella resource", "view.php?id={$cm->id}", "{$item->instance}", $cm->id);
         }
         rebuild_course_cache($oldCourse);
         rebuild_course_cache($newCourse);
     }
     return array('success' => $success);
 }
开发者ID:CTANZ,项目名称:moodle-mod_equella,代码行数:43,代码来源:externallib.php

示例8: voicepresentation_delete_all_instance_of_resource

function voicepresentation_delete_all_instance_of_resource($id)
{
    /// Given an ID of an instance of this module,
    /// this function will permanently delete the instance
    /// and any data that depends on it.
    //delete the resource of the vt list
    $result = true;
    wimba_add_log(WIMBA_INFO, voicepresentation_LOGS, "Delete the resouce " . $id);
    if ($voicepresentation = get_records("voicepresentation", "rid", $id)) {
        # Delete any dependent records here #
        foreach ($voicepresentation as $voicetool) {
            //get the course_module instance linked to the liveclassroom instance
            $cm = get_coursemodule_from_instance("voicepresentation", $voicetool->id, $voicetool->course);
            if (!empty($cm)) {
                if (!delete_course_module($cm->id)) {
                    wimba_add_log(WIMBA_ERROR, voicepresentation_LOGS, "Problem to delete the course module : " . $cm->id);
                    $result = false;
                    //Delete a course module and any associated data at the course level (events)
                }
                //delete the instance
                if (!delete_records("voicepresentation", "id", $voicetool->id)) {
                    wimba_add_log(WIMBA_ERROR, voicepresentation_LOGS, "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, voicepresentation_LOGS, "Could not delete the " . $cm->id . " from that section : " . $cm->section);
                    $result = false;
                }
                voicepresentation_deleteCalendarEvent($voicetool->id);
            }
        }
    }
    voicepresentation_delete_resource($id);
    return $result;
}
开发者ID:nagyistoce,项目名称:moodle-Teach-Pilot,代码行数:36,代码来源:lib.php

示例9: print_error

 if (!$confirm) {
     echo $OUTPUT->confirm(get_string("moduledeleteconfirm", "", $strmodulename), "modules.php?delete={$delete}&confirm=1", "modules.php");
     echo $OUTPUT->footer();
     exit;
 } else {
     // Delete everything!!
     if ($delete == "forum") {
         print_error("cannotdeleteforummodule", 'forum');
     }
     if (!($module = $DB->get_record("modules", array("name" => $delete)))) {
         print_error('moduledoesnotexist', 'error');
     }
     // OK, first delete all the relevant instances from all course sections
     if ($coursemods = $DB->get_records("course_modules", array("module" => $module->id))) {
         foreach ($coursemods as $coursemod) {
             if (!delete_mod_from_section($coursemod->id, $coursemod->section)) {
                 echo $OUTPUT->notification("Could not delete the {$strmodulename} with id = {$coursemod->id} from section {$coursemod->section}");
             }
         }
     }
     // delete calendar events
     if (!$DB->delete_records("event", array("modulename" => $delete))) {
         echo $OUTPUT->notification("Error occurred while deleting all {$strmodulename} records in calendar event table");
     }
     // clear course.modinfo for courses
     // that used this module...
     $sql = "UPDATE {course}\n                       SET modinfo=''\n                     WHERE id IN (SELECT DISTINCT course\n                                    FROM {course_modules}\n                                   WHERE module=?)";
     $DB->execute($sql, array($module->id));
     // Now delete all the course module records
     if (!$DB->delete_records("course_modules", array("module" => $module->id))) {
         echo $OUTPUT->notification("Error occurred while deleting all {$strmodulename} records in course_modules table");
开发者ID:ajv,项目名称:Offline-Caching,代码行数:31,代码来源:modules.php

示例10: moveto_module

/**
 * Move the module object $mod to the specified $section
 * If $beforemod exists then that is the module
 * before which $modid should be inserted
 * All parameters are objects
 */
function moveto_module($mod, $section, $beforemod = NULL)
{
    global $OUTPUT;
    /// Remove original module from original section
    if (!delete_mod_from_section($mod->id, $mod->section)) {
        echo $OUTPUT->notification("Could not delete module from existing section");
    }
    // if moving to a hidden section then hide module
    if (!$section->visible && $mod->visible) {
        set_coursemodule_visible($mod->id, 0);
    }
    /// Add the module into the new section
    course_add_cm_to_section($section->course, $mod->id, $section->section, $beforemod);
    return true;
}
开发者ID:vinoth4891,项目名称:clinique,代码行数:21,代码来源:lib.php

示例11: delete_module

 /**
  * function used to delete a module - copied from course/mod.php, it would
  * be nice for this to be a core function.
  * @param stdclass $cm full course modules record
  */
 public function delete_module($cm)
 {
     global $CFG, $OUTPUT, $USER, $DB;
     $cm->modname = $DB->get_field("modules", "name", array("id" => $cm->module));
     $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
     $modlib = "{$CFG->dirroot}/mod/{$cm->modname}/lib.php";
     if (file_exists($modlib)) {
         require_once $modlib;
     } else {
         print_error('modulemissingcode', '', '', $modlib);
     }
     $deleteinstancefunction = $cm->modname . "_delete_instance";
     if (!$deleteinstancefunction($cm->instance)) {
         echo $OUTPUT->notification("Could not delete the {$cm->modname} (instance)");
     }
     // Remove all module files in case modules forget to do that.
     $fs = get_file_storage();
     $fs->delete_area_files($modcontext->id);
     if (!delete_course_module($cm->id)) {
         echo $OUTPUT->notification("Could not delete the {$cm->modname} (coursemodule)");
     }
     if (!delete_mod_from_section($cm->id, $cm->section)) {
         echo $OUTPUT->notification("Could not delete the {$cm->modname} from that section");
     }
     // Trigger a mod_deleted event with information about this module.
     $eventdata = new stdClass();
     $eventdata->modulename = $cm->modname;
     $eventdata->cmid = $cm->id;
     $eventdata->courseid = $cm->course;
     $eventdata->userid = $USER->id;
     events_trigger('mod_deleted', $eventdata);
     add_to_log($cm->course, 'course', "delete mod", "view.php?id={$cm->course}", "{$cm->modname} {$cm->instance}", $cm->id);
     rebuild_course_cache($cm->course);
 }
开发者ID:nadavkav,项目名称:moodle-mod_subpage,代码行数:39,代码来源:locallib.php

示例12: wipe_forumng

function wipe_forumng($cm)
{
    forum_utils::start_transaction();
    // Tell forum to delete itself
    if (!forumng_delete_instance($cm->instance)) {
        throw new Exception("Could not delete forum instance {$cm->instance}");
    }
    // Delete course_module entry
    if (!delete_records('course_modules', 'id', $cm->id)) {
        throw new Exception("Could not delete course module {$cm->id}");
    }
    // Update section
    if (!delete_mod_from_section($cm->id, $cm->section)) {
        throw new Exception("Could not delete module {$cm->id} from section {$cm->section}");
    }
    forum_utils::finish_transaction();
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:17,代码来源:makebig.php

示例13: perform_deletion

/**
 * perform the actual deletion of the selected course modules
 * @param array $modules
 */
function perform_deletion($modules)
{
    global $CFG, $OUTPUT, $DB, $USER;
    require_once $CFG->dirroot . '/course/lib.php';
    foreach ($modules as $cm_record) {
        if (!($cm = get_coursemodule_from_id('', $cm_record->id, 0, true))) {
            print_error('invalidcoursemodule');
        }
        if (!($course = $DB->get_record('course', array('id' => $cm->course)))) {
            print_error('invalidcourseid');
        }
        $context = context_course::instance($course->id);
        $modcontext = context_module::instance($cm->id);
        require_capability('moodle/course:manageactivities', $context);
        $modlib = $CFG->dirroot . '/mod/' . $cm->modname . '/lib.php';
        if (file_exists($modlib)) {
            require_once $modlib;
        } else {
            print_error('modulemissingcode', '', '', $modlib);
        }
        if (function_exists('course_delete_module')) {
            // available from Moodle 2.5
            course_delete_module($cm->id);
        } else {
            // pre Moodle 2.5
            $deleteinstancefunction = $cm->modname . "_delete_instance";
            if (!$deleteinstancefunction($cm->instance)) {
                echo $OUTPUT->notification("Could not delete the {$cm->modname} (instance)");
            }
            // remove all module files in case modules forget to do that
            $fs = get_file_storage();
            $fs->delete_area_files($modcontext->id);
            if (!delete_course_module($cm->id)) {
                echo $OUTPUT->notification("Could not delete the {$cm->modname} (coursemodule)");
            }
            if (!delete_mod_from_section($cm->id, $cm->section)) {
                echo $OUTPUT->notification("Could not delete the {$cm->modname} from that section");
            }
            // Trigger a mod_deleted event with information about this module.
            $eventdata = new stdClass();
            $eventdata->modulename = $cm->modname;
            $eventdata->cmid = $cm->id;
            $eventdata->courseid = $course->id;
            $eventdata->userid = $USER->id;
            events_trigger('mod_deleted', $eventdata);
            add_to_log($course->id, 'course', "delete mod", "view.php?id={$cm->course}", "{$cm->modname} {$cm->instance}", $cm->id);
        }
    }
}
开发者ID:ULCC-QMUL,项目名称:moodle-block_massaction,代码行数:53,代码来源:action.php

示例14: wipe_forumng

function wipe_forumng($cm)
{
    global $DB;
    $transaction = $DB->start_delegated_transaction();
    // Tell forum to delete itself
    if (!forumng_delete_instance($cm->instance)) {
        throw new Exception("Could not delete forum instance {$cm->instance}");
    }
    // Delete course_module entry
    $DB->delete_records('course_modules', array('id' => $cm->id));
    // Update section
    if (!delete_mod_from_section($cm->id, $cm->section)) {
        throw new Exception("Could not delete module {$cm->id} from section {$cm->section}");
    }
    $transaction->allow_commit();
}
开发者ID:ULCC-QMUL,项目名称:moodle-mod_forumng,代码行数:16,代码来源:makebig.php

示例15: voiceemail_update_instance

function voiceemail_update_instance($voicetool)
{
    /// Given an object containing all the necessary data,
    /// (defined by the form in mod.html) this function
    /// will update an existing instance with new data.
    global $USER;
    //get the course_module instance linked to the liveclassroom instance
    if (!($cm = get_coursemodule_from_instance("voiceemail", $voicetool->instance, $voicetool->course))) {
        wimba_add_log(WIMBA_ERROR, voiceemail_LOGS, "Problem to update the instance : " . $voicetool->instance);
        error("Course Module ID was incorrect");
    }
    if ($voicetool->section != $cm->section) {
        //Find the right section in the course_section
        if (!($section = get_record("course_sections", "id", $cm->section))) {
            return false;
        }
        //delete in the course section
        if (!delete_mod_from_section($cm->id, $cm->section)) {
            return false;
        }
        //update the course module section
        if (!($sectionid = add_mod_to_section($voicetool))) {
            wimba_add_log(WIMBA_ERROR, voiceemail_LOGS, "Problem to update the instance : " . $voicetool->instance);
            error("Could not add the new course module to that section");
        }
        //update the course modules
        if (!set_field("course_modules", "section", $sectionid, "id", $cm->id)) {
            wimba_add_log(WIMBA_ERROR, voiceemail_LOGS, "Problem to update the instance : " . $voicetool->instance);
            error("Could not update the course module with the correct section");
        }
    }
    $voicetool->timemodified = time();
    //Create the Voice E-mail linked to this actvity
    $paramVMail = array();
    $paramVMail["name"] = $voicetool->name;
    $paramVMail["audio_format"] = $voicetool->audio_format;
    $paramVMail["max_length"] = $voicetool->max_length;
    $paramVMail["reply_link"] = $voicetool->reply_link;
    $paramVMail["subject"] = $voicetool->subject;
    $paramVMail["recipients"] = voiceemail_getEnrolledUsers($voicetool->course, $voicetool->recipients_email);
    $vtAction = new VtAction($USER->email, $paramVMail);
    $vt = $vtAction->updateVMmail($voicetool->rid, $voicetool->name);
    if ($vt->error == "error") {
        return false;
    }
    $resource_id = updateVmailResource($vt->getRid(), $voicetool->course);
    //default availability
    if (empty($resource_id)) {
        return false;
    }
    $voicetool->rid = $resource_id;
    $voicetool->id = $voicetool->instance;
    if (!($voicetool->id = update_record('voiceemail', $voicetool))) {
        return false;
    }
    if (isset($voicetool->calendar_event) && $voicetool->calendar_event) {
        //no problem
        voiceemail_addCalendarEvent($voicetool, $voicetool->instance);
    } else {
        voiceemail_deleteCalendarEvent($voicetool->instance);
    }
    wimba_add_log(WIMBA_INFO, voiceemail_LOGS, "Update of the instance : " . $voicetool->id);
    return $voicetool->id;
}
开发者ID:nagyistoce,项目名称:moodle-Teach-Pilot,代码行数:64,代码来源:lib.php


注:本文中的delete_mod_from_section函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。