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


PHP course_delete_module函数代码示例

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


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

示例1: execute

 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/course/lib.php';
     $moduleid = intval($this->arguments[0]);
     if ($moduleid <= 0) {
         cli_error("Argument 'moduleid' must be bigger than 0.");
     }
     if (!$DB->get_record('course_modules', array('id' => $this->arguments[0]))) {
         cli_error("There is no such activity to delete.");
     }
     course_delete_module($moduleid);
     echo "Deleted activity {$moduleid}\n";
 }
开发者ID:dariogs,项目名称:moosh,代码行数:14,代码来源:ActivityDelete.php

示例2: start_afresh_steps

 /**
  * Resets (truncates) all dataform tables to remove any records and reset sequences.
  * This set of steps is essential for any standalone scenario that adds entries with content
  * since such a scenario has to refer to input elements by the name field_{fieldid}_{entryid}
  * (or field_{fieldid}_-1 for a new entry) and the ids have to persist between runs.
  *
  * @Given /^a fresh site for dataform scenario$/
  * @return array
  */
 public function start_afresh_steps()
 {
     global $DB;
     // Dataform module id.
     $moduleid = $DB->get_field('modules', 'id', array('name' => 'dataform'));
     // CM ids.
     if ($cmids = $DB->get_records('course_modules', array('module' => $moduleid), '', 'id,id AS cmid')) {
         // Delete properly any existing dataform instances.
         foreach ($cmids as $cmid) {
             course_delete_module($cmid);
         }
     }
     // Clean up tables.
     $tables = array('dataform', 'dataform_contents', 'dataform_entries', 'dataform_fields', 'dataform_filters', 'dataform_views');
     $prefix = $DB->get_prefix();
     foreach ($tables as $table) {
         $DB->execute("TRUNCATE TABLE {$prefix}{$table}");
     }
     // Clean up instance store cache.
     \mod_dataform_instance_store::unregister();
     $steps = array();
     // Add a course.
     $data = array('| fullname | shortname | category  |', '| Course 1 | C1        | 0         |');
     $table = new TableNode(implode("\n", $data));
     $steps[] = new Given('the following "courses" exist:', $table);
     // Add users.
     $data = array('| username     | firstname | lastname  | email                 |', '| teacher1     | Teacher   | 1         | teacher1@asd.com      |', '| assistant1   | Assistant | 1         | assistant1@asd.com    |', '| assistant2   | Assistant | 2         | assistant2@asd.com    |', '| student1     | Student   | 1         | student1@asd.com      |', '| student2     | Student   | 2         | student2@asd.com      |', '| student3     | Student   | 3         | student3@asd.com      |');
     $table = new TableNode(implode("\n", $data));
     $steps[] = new Given('the following "users" exist:', $table);
     // Enrol users in course.
     $teacherrole = \mod_dataform\helper\testing::get_role_shortname('editingteacher');
     $assistantrole = \mod_dataform\helper\testing::get_role_shortname('teacher');
     $studentrole = \mod_dataform\helper\testing::get_role_shortname('student');
     $data = array('| user         | course | role             |', "| teacher1     | C1     | {$teacherrole}     |", "| assistant1   | C1     | {$assistantrole}   |", "| assistant2   | C1     | {$assistantrole}   |", "| student1     | C1     | {$studentrole}     |", "| student2     | C1     | {$studentrole}     |");
     $table = new TableNode(implode("\n", $data));
     $steps[] = new Given('the following "course enrolments" exist:', $table);
     // Add groups.
     $data = array('| name    | description | course  | idnumber |', '| Group 1 | Anything    | C1 | G1   |', '| Group 2 | Anything    | C1 | G2   |');
     $table = new TableNode(implode("\n", $data));
     $steps[] = new Given('the following "groups" exist:', $table);
     // Add group members.
     $data = array('| user     | group  |', '| student1 | G1 |', '| student2 | G2 |');
     $table = new TableNode(implode("\n", $data));
     $steps[] = new Given('the following "group members" exist:', $table);
     return $steps;
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:55,代码来源:behat_mod_dataform.php

示例3: execute

 /**
  * Run the deletion task.
  *
  * @throws \coding_exception if the module could not be removed.
  */
 public function execute()
 {
     global $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     // Set the proper user.
     if ($this->get_custom_data()->userid !== $this->get_custom_data()->realuserid) {
         $realuser = \core_user::get_user($this->get_custom_data()->realuserid, '*', MUST_EXIST);
         cron_setup_user($realuser);
         \core\session\manager::loginas($this->get_custom_data()->userid, \context_system::instance(), false);
     } else {
         $user = \core_user::get_user($this->get_custom_data()->userid, '*', MUST_EXIST);
         cron_setup_user($user);
     }
     $cms = $this->get_custom_data()->cms;
     foreach ($cms as $cm) {
         try {
             course_delete_module($cm->id);
         } catch (\Exception $e) {
             throw new \coding_exception("The course module {$cm->id} could not be deleted. {$e->getTraceAsString()}");
         }
     }
 }
开发者ID:lucaboesch,项目名称:moodle,代码行数:27,代码来源:course_delete_modules.php

示例4: test_event

 /**
  * Tests the event details.
  */
 public function test_event()
 {
     global $CFG;
     require_once "{$CFG->libdir}/gradelib.php";
     $this->resetAfterTest();
     $course = $this->getDataGenerator()->create_course();
     $user = $this->getDataGenerator()->create_user();
     $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id));
     // Create a grade item for the quiz.
     $grade = array();
     $grade['userid'] = $user->id;
     $grade['rawgrade'] = 50;
     grade_update('mod/quiz', $course->id, 'mod', 'quiz', $quiz->id, 0, $grade);
     // Get the grade item and override it.
     $gradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id, 'courseid' => $course->id));
     $gradeitem->update_final_grade($user->id, 10, 'gradebook');
     // Get the grade_grade object.
     $gradegrade = new grade_grade(array('userid' => $user->id, 'itemid' => $gradeitem->id), true);
     $gradegrade->grade_item = $gradeitem;
     // Trigger the event.
     $sink = $this->redirectEvents();
     course_delete_module($quiz->cmid);
     $events = $sink->get_events();
     $event = reset($events);
     $sink->close();
     // Check the event details are correct.
     $grade = $event->get_grade();
     $this->assertInstanceOf('grade_grade', $grade);
     $this->assertInstanceOf('\\core\\event\\grade_deleted', $event);
     $this->assertEquals(context_course::instance($course->id), $event->get_context());
     $this->assertSame($event->objecttable, 'grade_grades');
     $this->assertEquals($event->objectid, $gradegrade->id);
     $this->assertEquals($event->other['itemid'], $gradeitem->id);
     $this->assertTrue($event->other['overridden']);
     $this->assertEquals(10, $event->other['finalgrade']);
     $this->assertEventContextNotUsed($event);
     $this->assertEquals($gradegrade->id, $grade->id);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:41,代码来源:event_grade_deleted_test.php

示例5: array

                        // Attempt to update the grade item if relevant
                        $grademodule = $DB->get_record($cm->modname, array('id' => $cm->instance));
                        $grademodule->cmidnumber = $cm->idnumber;
                        $grademodule->modname = $cm->modname;
                        grade_update_mod_grades($grademodule);
                        // We need to return strings after they've been through filters for multilang
                        $stringoptions = new stdClass();
                        $stringoptions->context = $coursecontext;
                        echo json_encode(array('instancename' => html_entity_decode(format_string($module->name, true, $stringoptions))));
                        break;
                }
                break;
            case 'course':
                switch ($field) {
                    case 'marker':
                        require_capability('moodle/course:setcurrentsection', $coursecontext);
                        course_set_marker($course->id, $value);
                        break;
                }
                break;
        }
        break;
    case 'DELETE':
        switch ($class) {
            case 'resource':
                require_capability('moodle/course:manageactivities', $modcontext);
                course_delete_module($cm->id);
                break;
        }
        break;
}
开发者ID:miguelangelUvirtual,项目名称:uEducon,代码行数:31,代码来源:rest.php

示例6: delete_section_int

 /**
  * Completely removes a section, all subsections and activities they contain
  *
  * @param section_info $section
  */
 protected function delete_section_int($section)
 {
     global $DB;
     if (!$section->section) {
         // section 0 does not have parent
         return;
     }
     $sectionid = $section->id;
     // move the section to be removed to the end (this will re-number other sections)
     $this->move_section($section->section, 0);
     $modinfo = get_fast_modinfo($this->courseid);
     $allsections = $modinfo->get_section_info_all();
     $section = null;
     $sectionstodelete = array();
     $modulestodelete = array();
     foreach ($allsections as $sectioninfo) {
         if ($sectioninfo->id == $sectionid) {
             // This is the section to be deleted. Since we have already
             // moved it to the end we know that we need to delete this section
             // and all the following (which can only be its subsections).
             $section = $sectioninfo;
         }
         if ($section) {
             $sectionstodelete[] = $sectioninfo->id;
             if (!empty($modinfo->sections[$sectioninfo->section])) {
                 $modulestodelete = array_merge($modulestodelete, $modinfo->sections[$sectioninfo->section]);
             }
         }
     }
     foreach ($modulestodelete as $cmid) {
         course_delete_module($cmid);
     }
     list($sectionsql, $params) = $DB->get_in_or_equal($sectionstodelete);
     $DB->execute('DELETE FROM {course_format_options} WHERE sectionid ' . $sectionsql, $params);
     $DB->execute('DELETE FROM {course_sections} WHERE id ' . $sectionsql, $params);
     rebuild_course_cache($this->courseid, true);
 }
开发者ID:etarrillo,项目名称:pvflbl,代码行数:42,代码来源:lib.php

示例7: get_coursemodule_from_id

                        }
                        if ($beforeid > 0) {
                            $beforemod = get_coursemodule_from_id('', $beforeid, $course->id);
                            $beforemod = $DB->get_record('course_modules', array('id' => $beforeid));
                        } else {
                            $beforemod = NULL;
                        }
                        $isvisible = moveto_module($cm, $section, $beforemod);
                        echo json_encode(array('visible' => (bool) $isvisible));
                        break;
                }
                break;
            case 'course':
                switch ($field) {
                    case 'marker':
                        require_capability('moodle/course:setcurrentsection', $coursecontext);
                        course_set_marker($course->id, $value);
                        break;
                }
                break;
        }
        break;
    case 'DELETE':
        switch ($class) {
            case 'resource':
                require_capability('moodle/course:manageactivities', $modcontext);
                course_delete_module($cm->id, true);
                break;
        }
        break;
}
开发者ID:lucaboesch,项目名称:moodle,代码行数:31,代码来源:rest.php

示例8: test_upgrade_offline_assignment

    public function test_upgrade_offline_assignment() {
        global $DB;

        $this->setUser($this->editingteachers[0]);
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
        $params = array('course'=>$this->course->id,
                        'assignmenttype'=>'offline');
        $record = $generator->create_instance($params);

        $assignment = new assignment_base($record->cmid);

        $this->setAdminUser();
        $log = '';
        $upgrader = new assign_upgrade_manager();

        $this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log));
        $record = $DB->get_record('assign', array('course'=>$this->course->id));

        $cm = get_coursemodule_from_instance('assign', $record->id);
        $context = context_module::instance($cm->id);

        $assign = new assign($context, $cm, $this->course);

        $plugin = $assign->get_submission_plugin_by_type('onlinetext');
        $this->assertEmpty($plugin->is_enabled());
        $plugin = $assign->get_submission_plugin_by_type('comments');
        $this->assertEmpty($plugin->is_enabled());
        $plugin = $assign->get_submission_plugin_by_type('file');
        $this->assertEmpty($plugin->is_enabled());
        $plugin = $assign->get_feedback_plugin_by_type('comments');
        $this->assertNotEmpty($plugin->is_enabled());
        $plugin = $assign->get_feedback_plugin_by_type('file');
        $this->assertEmpty($plugin->is_enabled());
        $plugin = $assign->get_feedback_plugin_by_type('offline');
        $this->assertEmpty($plugin->is_enabled());

        course_delete_module($cm->id);
    }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:38,代码来源:upgradelib_test.php

示例9: delete_item

 public static function delete_item($user, $itemid)
 {
     global $DB, $USER;
     $params = self::validate_parameters(self::delete_item_parameters(), array('user' => $user, 'itemid' => $itemid));
     $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);
     $success = true;
     try {
         course_delete_module($cm->id);
     } catch (Exception $ex) {
         $success = false;
         throw $ex;
     }
     return array('success' => $success);
 }
开发者ID:CTANZ,项目名称:moodle-mod_equella,代码行数:16,代码来源:externallib.php

示例10: finish_setup_course_module

 /**
  * Called after the mod has set itself up, to finish off any course module settings
  * (set instance id, add to correct section, set visibility, etc.) and send the response
  *
  * @param int $instanceid id returned by the mod when it was created
  */
 protected function finish_setup_course_module($instanceid)
 {
     global $DB, $USER;
     if (!$instanceid) {
         // Something has gone wrong - undo everything we can.
         course_delete_module($this->cm->id);
         throw new moodle_exception('errorcreatingactivity', 'moodle', '', $this->module->name);
     }
     // Note the section visibility
     $visible = get_fast_modinfo($this->course)->get_section_info($this->section)->visible;
     $DB->set_field('course_modules', 'instance', $instanceid, array('id' => $this->cm->id));
     // Rebuild the course cache after update action
     rebuild_course_cache($this->course->id, true);
     $sectionid = course_add_cm_to_section($this->course, $this->cm->id, $this->section);
     set_coursemodule_visible($this->cm->id, $visible);
     if (!$visible) {
         $DB->set_field('course_modules', 'visibleold', 1, array('id' => $this->cm->id));
     }
     // retrieve the final info about this module.
     $info = get_fast_modinfo($this->course);
     if (!isset($info->cms[$this->cm->id])) {
         // The course module has not been properly created in the course - undo everything.
         course_delete_module($this->cm->id);
         throw new moodle_exception('errorcreatingactivity', 'moodle', '', $this->module->name);
     }
     $mod = $info->get_cm($this->cm->id);
     // Trigger course module created event.
     $event = \core\event\course_module_created::create(array('courseid' => $this->course->id, 'context' => context_module::instance($mod->id), 'objectid' => $mod->id, 'other' => array('modulename' => $mod->modname, 'name' => $mod->name, 'instanceid' => $instanceid)));
     $event->trigger();
     add_to_log($this->course->id, $mod->modname, "add", "view.php?id={$mod->id}", "{$instanceid}", $mod->id);
     $this->send_response($mod);
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:38,代码来源:dnduploadlib.php

示例11: forumng_delete_instance

function forumng_delete_instance($id)
{
    global $DB;
    require_once dirname(__FILE__) . '/mod_forumng.php';
    $cm = get_coursemodule_from_instance('forumng', $id);
    $forum = mod_forumng::get_from_id($id, mod_forumng::CLONE_DIRECT, true, $cm);
    $forum->delete_all_data();
    if (mod_forumng::search_installed()) {
        $cm = $forum->get_course_module();
        local_ousearch_document::delete_module_instance_data($cm);
    }
    if ($forum->is_shared()) {
        // Find all the clone instances.
        $clones = $forum->get_clone_details();
        $transaction = $DB->start_delegated_transaction();
        foreach ($clones as $clone) {
            try {
                course_delete_module($clone->context->instanceid);
            } catch (moodle_exception $e) {
                notify("Could not delete the Clone\n                        forumng (coursemoduleid) {$clone->context}->instanceid ");
                return false;
            }
            rebuild_course_cache($clone->courseid, true);
        }
        $transaction->allow_commit();
    }
    return $DB->delete_records('forumng', array('id' => $id));
}
开发者ID:unikent,项目名称:moodle-mod_forumng,代码行数:28,代码来源:lib.php

示例12: 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));
     $modlib = "{$CFG->dirroot}/mod/{$cm->modname}/lib.php";
     if (file_exists($modlib)) {
         require_once $modlib;
     } else {
         print_error('modulemissingcode', '', '', $modlib);
     }
     try {
         course_delete_module($cm->id);
     } catch (moodle_exception $e) {
         echo $OUTPUT->notification("Could not delete the {$cm->modname} (coursemodule)");
     }
     rebuild_course_cache($cm->course);
 }
开发者ID:ninelanterns,项目名称:moodle-mod_subpage,代码行数:22,代码来源:locallib.php

示例13: array

 }
 $params = array("module" => "{$cm->module}", "refid" => "{$val}");
 $sql = "SELECT * FROM {course_modules} WHERE module = :module AND instance=:refid ";
 $courses_modules = $DB->get_records_sql($sql, $params);
 if ($courses_modules) {
     foreach ($courses_modules as $course_module) {
         if (!empty($course_module)) {
             if ($course_record = $DB->get_record("course", array("id" => "{$course_module->course}"))) {
                 require_login($course_module->course);
                 // needed to setup proper $COURSE
                 $context_course = context_course::instance($course_module->course);
                 require_capability('moodle/course:manageactivities', $context_course);
                 if ($that_instance = $DB->get_record("referentiel", array("id" => "{$course_module->instance}"))) {
                     if (function_exists('course_delete_module')) {
                         // Moodle v 2.5 et suivantes
                         if (course_delete_module($course_module->id)) {
                             if (delete_mod_from_section($course_module->id, "{$course_module->section}")) {
                                 rebuild_course_cache($course_record->id);
                                 $msg .= get_string('instance_deleted', 'referentiel') . ' ' . $that_instance->name;
                             }
                         }
                     } else {
                         // Moodle v 2.x
                         if (delete_course_module($course_module->id)) {
                             if (delete_mod_from_section($course_module->id, "{$course_module->section}")) {
                                 rebuild_course_cache($course_record->id);
                                 $msg .= get_string('instance_deleted', 'referentiel') . ' ' . $that_instance->name;
                             }
                         }
                     }
                     // Supprimer l'instance
开发者ID:jfruitet,项目名称:moodle_referentiel,代码行数:31,代码来源:delete.php

示例14: test_course_bin_item_restored

 /**
  * Test the course bin item restored event.
  */
 public function test_course_bin_item_restored()
 {
     // Create a course.
     $course = $this->getDataGenerator()->create_course();
     // Create the assignment.
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
     $instance = $generator->create_instance(array('course' => $course->id));
     course_delete_module($instance->cmid);
     // Get the item from the recycle bin.
     $rb = new \tool_recyclebin\course_bin($course->id);
     $items = $rb->get_items();
     $item = reset($items);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $rb->restore_item($item);
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event contains the expected values.
     $this->assertInstanceOf('\\tooL_recyclebin\\event\\course_bin_item_restored', $event);
     $this->assertEquals(context_course::instance($course->id), $event->get_context());
     $this->assertEquals($item->id, $event->objectid);
     $this->assertEventContextNotUsed($event);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:26,代码来源:events_test.php

示例15: pearsondirect_handle_code_change

function pearsondirect_handle_code_change($courseconfig, $newcode, $newparams)
{
    global $DB, $CFG;
    require_once $CFG->dirroot . '/mod/lti/locallib.php';
    require_once $CFG->dirroot . '/course/lib.php';
    $types = $DB->get_records('lti_types', array('course' => $courseconfig->course));
    if ($types) {
        foreach ($types as $type) {
            if (!strncmp($type->tooldomain, 'pearson:', strlen('pearson:'))) {
                lti_delete_type($type->id);
            }
        }
    }
    $coursemodules = $DB->get_records('course_modules', array('course' => $courseconfig->course, 'module' => pearsondirect_get_lti_module()));
    if ($coursemodules) {
        foreach ($coursemodules as $cm) {
            if (!strncmp($cm->idnumber, 'pearson:', strlen('pearson:'))) {
                course_delete_module($cm->id);
            }
        }
    }
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:22,代码来源:locallib.php


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