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


PHP moveto_module函数代码示例

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


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

示例1: ma_move_execute

function ma_move_execute($modids, $post)
{
    $section_id = -1;
    foreach ($post as $key => $val) {
        if ($key == 'section') {
            $section = decode_array($val);
            $section_id = $section['id'];
        }
    }
    if ($section_id == -1) {
        return;
    }
    $section = get_record("course_sections", "id", $section_id);
    $message = "";
    if ($section) {
        foreach ($modids as $modid) {
            $cm = get_record("course_modules", "id", $modid);
            if (!moveto_module($cm, $section)) {
                $message .= "Could not move module {$modid}, ";
            }
        }
    } else {
        $message = "No sections were selected";
    }
    return $message;
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:26,代码来源:move.php

示例2: foreach

// restored copy of the module
$newcmid = null;
$tasks = $rc->get_plan()->get_tasks();
foreach ($tasks as $task) {
    if (is_subclass_of($task, 'restore_activity_task')) {
        if ($task->get_old_contextid() == $cmcontext->id) {
            $newcmid = $task->get_moduleid();
            break;
        }
    }
}
// if we know the cmid of the new course module, let us move it
// right below the original one. otherwise it will stay at the
// end of the section
if ($newcmid) {
    $newcm = get_coursemodule_from_id('', $newcmid, $course->id, true, MUST_EXIST);
    moveto_module($newcm, $section, $cm);
    moveto_module($cm, $section, $newcm);
}
$rc->destroy();
if (empty($CFG->keeptempdirectoriesonbackup)) {
    fulldelete($backupbasepath);
}
echo $output->header();
if ($newcmid) {
    echo $output->confirm(get_string('duplicatesuccess', 'core', $a), new single_button(new moodle_url('/course/modedit.php', array('update' => $newcmid, 'sr' => $sectionreturn)), get_string('duplicatecontedit'), 'get'), new single_button(course_get_url($course, $cm->sectionnum, array('sr' => $sectionreturn)), get_string('duplicatecontcourse'), 'get'));
} else {
    echo $output->notification(get_string('duplicatesuccess', 'core', $a), 'notifysuccess');
    echo $output->continue_button(course_get_url($course, $cm->sectionnum, array('sr' => $sectionreturn)));
}
echo $output->footer();
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:31,代码来源:modduplicate.php

示例3: mergeup_section

 /**
  * Moves the section content to the parent section and deletes it
  *
  * Moves all activities and subsections to the parent section (section 0
  * can never be deleted)
  *
  * @param section_info $section
  */
 protected function mergeup_section($section)
 {
     global $DB;
     if (!$section->section) {
         // seciton 0 does not have parent
         return;
     }
     // move all modules and activities from this section to parent
     $modinfo = get_fast_modinfo($this->courseid);
     $allsections = $modinfo->get_section_info_all();
     $subsections = $this->get_subsections($section);
     $parent = $modinfo->get_section_info($section->parent);
     if (!empty($modinfo->sections[$section->section])) {
         foreach ($modinfo->sections[$section->section] as $cmid) {
             moveto_module($modinfo->get_cm($cmid), $parent);
         }
     }
     foreach ($subsections as $subsection) {
         $this->update_section_format_options(array('id' => $subsection->id, 'parent' => $parent->section));
     }
     if ($this->get_course()->marker == $section->section) {
         course_set_marker($this->courseid, 0);
     }
     // move the section to be removed to the end (this will re-number other sections)
     $this->move_section($section->section, 0);
     // delete it completely
     $params = array('courseid' => $this->courseid, 'sectionid' => $section->id);
     $transaction = $DB->start_delegated_transaction();
     $DB->delete_records('course_format_options', $params);
     $DB->delete_records('course_sections', array('id' => $section->id));
     $transaction->allow_commit();
     rebuild_course_cache($this->courseid, true);
 }
开发者ID:etarrillo,项目名称:pvflbl,代码行数:41,代码来源:lib.php

示例4: reorder_activities

 /**
  * Make sure that current active activity is in section 0
  *
  * All other activities are moved to section 1 that will be displayed as 'Orphaned'.
  * It may be needed after the course format was changed or activitytype in
  * course settings has been changed.
  *
  * @return null|cm_info current activity
  */
 public function reorder_activities()
 {
     course_create_sections_if_missing($this->courseid, array(0, 1));
     foreach ($this->get_sections() as $sectionnum => $section) {
         if ($sectionnum && $section->visible || !$sectionnum && !$section->visible) {
             // Make sure that 0 section is visible and all others are hidden.
             set_section_visible($this->courseid, $sectionnum, $sectionnum == 0);
         }
     }
     $modinfo = get_fast_modinfo($this->courseid);
     // Find the current activity (first activity with the specified type in all course activities).
     $activitytype = $this->get_activitytype();
     $activity = null;
     if (!empty($activitytype)) {
         foreach ($modinfo->sections as $sectionnum => $cmlist) {
             foreach ($cmlist as $cmid) {
                 if ($modinfo->cms[$cmid]->modname === $activitytype) {
                     $activity = $modinfo->cms[$cmid];
                     break 2;
                 }
             }
         }
     }
     // Make sure the current activity is in the 0-section.
     if ($activity && $activity->sectionnum != 0) {
         moveto_module($activity, $modinfo->get_section_info(0));
         // Cache was reset so get modinfo again.
         $modinfo = get_fast_modinfo($this->courseid);
     }
     // Move all other activities into section 1 (the order must be kept).
     $hasvisibleactivities = false;
     $firstorphanedcm = null;
     foreach ($modinfo->sections as $sectionnum => $cmlist) {
         if ($sectionnum && !empty($cmlist) && $firstorphanedcm === null) {
             $firstorphanedcm = reset($cmlist);
         }
         foreach ($cmlist as $cmid) {
             if ($sectionnum > 1) {
                 moveto_module($modinfo->get_cm($cmid), $modinfo->get_section_info(1));
             } else {
                 if (!$hasvisibleactivities && $sectionnum == 1 && $modinfo->get_cm($cmid)->visible) {
                     $hasvisibleactivities = true;
                 }
             }
         }
     }
     if (!empty($modinfo->sections[0])) {
         foreach ($modinfo->sections[0] as $cmid) {
             if (!$activity || $cmid != $activity->id) {
                 moveto_module($modinfo->get_cm($cmid), $modinfo->get_section_info(1), $firstorphanedcm);
             }
         }
     }
     if ($hasvisibleactivities) {
         set_section_visible($this->courseid, 1, false);
     }
     return $activity;
 }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:67,代码来源:lib.php

示例5: mod_duplicate_activity

/**
 * Duplicate a module on the course.
 *
 * @param object $course The course
 * @param object $cm The course module to duplicate
 * @throws moodle_exception if the plugin doesn't support duplication
 * @return Object containing:
 * - fullcontent: The HTML markup for the created CM
 * - cmid: The CMID of the newly created CM
 * - redirect: Whether to trigger a redirect following this change
 */
function mod_duplicate_activity($course, $cm, $sr = null)
{
    global $CFG, $USER, $PAGE, $DB;
    require_once $CFG->dirroot . '/backup/util/includes/backup_includes.php';
    require_once $CFG->dirroot . '/backup/util/includes/restore_includes.php';
    require_once $CFG->libdir . '/filelib.php';
    $a = new stdClass();
    $a->modtype = get_string('modulename', $cm->modname);
    $a->modname = format_string($cm->name);
    if (!plugin_supports('mod', $cm->modname, FEATURE_BACKUP_MOODLE2)) {
        throw new moodle_exception('duplicatenosupport', 'error');
    }
    // backup the activity
    $bc = new backup_controller(backup::TYPE_1ACTIVITY, $cm->id, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id);
    $backupid = $bc->get_backupid();
    $backupbasepath = $bc->get_plan()->get_basepath();
    $bc->execute_plan();
    $bc->destroy();
    // restore the backup immediately
    $rc = new restore_controller($backupid, $course->id, backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id, backup::TARGET_CURRENT_ADDING);
    $cmcontext = context_module::instance($cm->id);
    if (!$rc->execute_precheck()) {
        $precheckresults = $rc->get_precheck_results();
        if (is_array($precheckresults) && !empty($precheckresults['errors'])) {
            if (empty($CFG->keeptempdirectoriesonbackup)) {
                fulldelete($backupbasepath);
            }
        }
    }
    $rc->execute_plan();
    // now a bit hacky part follows - we try to get the cmid of the newly
    // restored copy of the module
    $newcmid = null;
    $tasks = $rc->get_plan()->get_tasks();
    foreach ($tasks as $task) {
        error_log("Looking at a task");
        if (is_subclass_of($task, 'restore_activity_task')) {
            error_log("Looking at a restore_activity_task task");
            if ($task->get_old_contextid() == $cmcontext->id) {
                error_log("Contexts match");
                $newcmid = $task->get_moduleid();
                break;
            }
        }
    }
    // if we know the cmid of the new course module, let us move it
    // right below the original one. otherwise it will stay at the
    // end of the section
    if ($newcmid) {
        $info = get_fast_modinfo($course);
        $newcm = $info->get_cm($newcmid);
        $section = $DB->get_record('course_sections', array('id' => $cm->section, 'course' => $cm->course));
        moveto_module($newcm, $section, $cm);
        moveto_module($cm, $section, $newcm);
        // Trigger course module created event. We can trigger the event only if we know the newcmid.
        $event = \core\event\course_module_created::create_from_cm($newcm);
        $event->trigger();
    }
    rebuild_course_cache($cm->course);
    $rc->destroy();
    if (empty($CFG->keeptempdirectoriesonbackup)) {
        fulldelete($backupbasepath);
    }
    $resp = new stdClass();
    if ($newcm) {
        $courserenderer = $PAGE->get_renderer('core', 'course');
        $completioninfo = new completion_info($course);
        $modulehtml = $courserenderer->course_section_cm($course, $completioninfo, $newcm, null, array());
        $resp->fullcontent = $courserenderer->course_section_cm_list_item($course, $completioninfo, $newcm, $sr);
        $resp->cmid = $newcm->id;
    } else {
        // Trigger a redirect
        $resp->redirect = true;
    }
    return $resp;
}
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:87,代码来源:lib.php

示例6: test_moveto_module_in_same_section

 /**
  * Tests moving a module around in the same section. moveto_module()
  * is called this way in modduplicate.
  */
 public function test_moveto_module_in_same_section()
 {
     global $DB;
     $this->resetAfterTest(true);
     $course = $this->getDataGenerator()->create_course(array('numsections' => 3), array('createsections' => true));
     $page = $this->getDataGenerator()->create_module('page', array('course' => $course->id));
     $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id));
     // Simulate inconsistent visible/visibleold values (MDL-38713).
     $cm = $DB->get_record('course_modules', array('id' => $page->cmid), '*', MUST_EXIST);
     $cm->visible = 0;
     $cm->visibleold = 1;
     $DB->update_record('course_modules', $cm);
     $modinfo = get_fast_modinfo($course);
     $forumcm = $modinfo->cms[$forum->cmid];
     $pagecm = $modinfo->cms[$page->cmid];
     // Verify that page is hidden.
     $this->assertEquals($pagecm->visible, 0);
     // Verify section 0 is where all mods added.
     $section = $modinfo->get_section_info(0);
     $this->assertEquals($section->id, $forumcm->section);
     $this->assertEquals($section->id, $pagecm->section);
     // Move the page inside the hidden section. Make sure it is hidden.
     $this->assertEquals(0, moveto_module($pagecm, $section, $forumcm));
     // Double check that the the page is still hidden.
     $modinfo = get_fast_modinfo($course);
     $pagecm = $modinfo->cms[$page->cmid];
     $this->assertEquals($pagecm->visible, 0);
 }
开发者ID:uniedpa,项目名称:moodle,代码行数:32,代码来源:courselib_test.php

示例7: rebuild_course_cache

         $DB->update_record('course_modules', $cm);
         rebuild_course_cache($cm->course);
     }
     break;
 case 'move':
     require_capability('moodle/course:manageactivities', $modcontext);
     if (!($section = $DB->get_record('course_sections', array('course' => $course->id, 'section' => $sectionid)))) {
         throw new moodle_exception('AJAX commands.php: Bad section ID ' . $sectionid);
     }
     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' => $isvisible));
     break;
 case 'gettitle':
     require_capability('moodle/course:manageactivities', $modcontext);
     $cm = get_coursemodule_from_id('', $id, 0, false, MUST_EXIST);
     $module = new stdClass();
     $module->id = $cm->instance;
     // Don't pass edit strings through multilang filters - we need the entire string
     echo json_encode(array('instancename' => $cm->name));
     break;
 case 'updatetitle':
     require_capability('moodle/course:manageactivities', $modcontext);
     require_once $CFG->libdir . '/gradelib.php';
     $cm = get_coursemodule_from_id('', $id, 0, false, MUST_EXIST);
     $module = new stdClass();
开发者ID:miguelangelUvirtual,项目名称:uEducon,代码行数:31,代码来源:rest.php

示例8: test_filter_users

 /**
  * Tests the filter_users() function.
  */
 public function test_filter_users()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/course/lib.php';
     $this->resetAfterTest();
     $CFG->enableavailability = true;
     // Create a course with 2 sections and 2 pages and 3 users.
     // Availability is set up initially on the 'page/section 2' items.
     $generator = $this->getDataGenerator();
     $course = $generator->create_course(array('numsections' => 2), array('createsections' => true));
     $u1 = $generator->create_user();
     $u2 = $generator->create_user();
     $u3 = $generator->create_user();
     $studentroleid = $DB->get_field('role', 'id', array('shortname' => 'student'), MUST_EXIST);
     $allusers = array($u1->id => $u1, $u2->id => $u2, $u3->id => $u3);
     $generator->enrol_user($u1->id, $course->id, $studentroleid);
     $generator->enrol_user($u2->id, $course->id, $studentroleid);
     $generator->enrol_user($u3->id, $course->id, $studentroleid);
     // Page 2 allows access to users 2 and 3, while section 2 allows access
     // to users 1 and 2.
     $pagegen = $generator->get_plugin_generator('mod_page');
     $page = $pagegen->create_instance(array('course' => $course));
     $page2 = $pagegen->create_instance(array('course' => $course, 'availability' => '{"op":"|","show":true,"c":[{"type":"mock","filter":[' . $u2->id . ',' . $u3->id . ']}]}'));
     $modinfo = get_fast_modinfo($course);
     $section = $modinfo->get_section_info(1);
     $section2 = $modinfo->get_section_info(2);
     $DB->set_field('course_sections', 'availability', '{"op":"|","show":true,"c":[{"type":"mock","filter":[' . $u1->id . ',' . $u2->id . ']}]}', array('id' => $section2->id));
     moveto_module($modinfo->get_cm($page2->cmid), $section2);
     // With no restrictions, returns full list.
     $info = new info_module($modinfo->get_cm($page->cmid));
     $this->assertEquals(array($u1->id, $u2->id, $u3->id), array_keys($info->filter_user_list($allusers)));
     // Set an availability restriction in database for section 1.
     // For the section we set it so it doesn't support filters; for the
     // module we have a filter.
     $DB->set_field('course_sections', 'availability', '{"op":"|","show":true,"c":[{"type":"mock","a":false}]}', array('id' => $section->id));
     $DB->set_field('course_modules', 'availability', '{"op":"|","show":true,"c":[{"type":"mock","filter":[' . $u3->id . ']}]}', array('id' => $page->cmid));
     rebuild_course_cache($course->id, true);
     $modinfo = get_fast_modinfo($course);
     // Now it should work (for the module).
     $info = new info_module($modinfo->get_cm($page->cmid));
     $this->assertEquals(array($u3->id), array_keys($info->filter_user_list($allusers)));
     $info = new info_section($modinfo->get_section_info(1));
     $this->assertEquals(array($u1->id, $u2->id, $u3->id), array_keys($info->filter_user_list($allusers)));
     // With availability disabled, module returns full list too.
     $CFG->enableavailability = false;
     $info = new info_module($modinfo->get_cm($page->cmid));
     $this->assertEquals(array($u1->id, $u2->id, $u3->id), array_keys($info->filter_user_list($allusers)));
     // Check the other section...
     $CFG->enableavailability = true;
     $info = new info_section($modinfo->get_section_info(2));
     $this->assertEquals(array($u1->id, $u2->id), array_keys($info->filter_user_list($allusers)));
     // And the module in that section - which has combined the section and
     // module restrictions.
     $info = new info_module($modinfo->get_cm($page2->cmid));
     $this->assertEquals(array($u2->id), array_keys($info->filter_user_list($allusers)));
     // If the students have viewhiddenactivities, they get past the module
     // restriction.
     role_change_permission($studentroleid, context_module::instance($page2->cmid), 'moodle/course:viewhiddenactivities', CAP_ALLOW);
     $expected = array($u1->id, $u2->id);
     $this->assertEquals($expected, array_keys($info->filter_user_list($allusers)));
     // If they have viewhiddensections, they also get past the section
     // restriction.
     role_change_permission($studentroleid, context_course::instance($course->id), 'moodle/course:viewhiddensections', CAP_ALLOW);
     $expected = array($u1->id, $u2->id, $u3->id);
     $this->assertEquals($expected, array_keys($info->filter_user_list($allusers)));
 }
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:69,代码来源:info_test.php

示例9: print_error

            $newsection = $dest->add_section();
            $id = $newsection['sectionid'];
        } else {
            $id = $info[1];
        }
        // ensure that the destination section does exists
        if (!($section = $DB->get_record('course_sections', array('id' => (int) $id)))) {
            print_error('sectionnotcreatedorexisting', 'mod_subpage', "{$CFG->wwwroot}/mod/subpage/view.php?id={$cmid}");
        }
        foreach ($cmids as $id) {
            if (!($cm = get_coursemodule_from_id('', $id))) {
                print_error('modulenotfound', 'mod_subpage', "{$CFG->wwwroot}/mod/subpage/view.php?id={$cmid}");
            }
            // no reason to move if in the same section
            if ($cm->section !== $section->id) {
                moveto_module($cm, $section);
            }
        }
        rebuild_course_cache($course->id, true);
    }
    // return to original subpage view
    if (!$dest) {
        redirect("{$CFG->wwwroot}/course/view.php?id=" . $subpage->get_course()->id . "#section-{$section->section}");
    } else {
        redirect("{$CFG->wwwroot}/mod/subpage/view.php?id=" . $dest->get_course_module()->id . "#section-{$section->section}");
    }
    exit;
}
echo $OUTPUT->header();
// Course wrapper start.
echo html_writer::start_tag('div', array('class' => 'course-content'));
开发者ID:nadavkav,项目名称:moodle-mod_subpage,代码行数:31,代码来源:move.php

示例10: MAX

        } else {
            $newlocation = '';
        }
        if (empty($newlocation)) {
            $newlocation = $DB->get_field_sql("SELECT MAX(pageorder) FROM {subpage_sections} WHERE subpageid = ?", array($subpage->get_subpage()->id));
        }
        $subpage->move_section($thissection->id, $newlocation);
    }
} else {
    if ($action == 'moveactivity') {
        // Now cleanup and check vars.
        if (strpos($thisid, 'module-') === 0) {
            $thisid = str_replace('module-', '', $thisid);
            $thisid = get_coursemodule_from_id(false, $thisid, $subpage->get_course()->id, false, MUST_EXIST);
        } else {
            $thisid = '';
        }
        if (strpos($nextid, 'module-') === 0) {
            $nextid = str_replace('module-', '', $nextid);
            $nextid = get_coursemodule_from_id(false, $nextid, $subpage->get_course()->id, false, MUST_EXIST);
        } else {
            $nextid = '';
        }
        if (strpos($section, 'section-') === 0) {
            // Section must be provided - if not then can't move.
            $section = str_replace('section-', '', $section);
            $section = $DB->get_record('course_sections', array('course' => $subpage->get_course()->id, 'section' => $section), '*', MUST_EXIST);
            moveto_module($thisid, $section, $nextid);
        }
    }
}
开发者ID:ninelanterns,项目名称:moodle-mod_subpage,代码行数:31,代码来源:ajaxhandler.php

示例11: duplicate_module

/**
 * Api to duplicate a module.
 *
 * @param object $course course object.
 * @param object $cm course module object to be duplicated.
 * @since Moodle 2.8
 *
 * @throws Exception
 * @throws coding_exception
 * @throws moodle_exception
 * @throws restore_controller_exception
 *
 * @return cm_info|null cminfo object if we sucessfully duplicated the mod and found the new cm.
 */
function duplicate_module($course, $cm)
{
    global $CFG, $DB, $USER;
    require_once $CFG->dirroot . '/backup/util/includes/backup_includes.php';
    require_once $CFG->dirroot . '/backup/util/includes/restore_includes.php';
    require_once $CFG->libdir . '/filelib.php';
    $a = new stdClass();
    $a->modtype = get_string('modulename', $cm->modname);
    $a->modname = format_string($cm->name);
    if (!plugin_supports('mod', $cm->modname, FEATURE_BACKUP_MOODLE2)) {
        throw new moodle_exception('duplicatenosupport', 'error', '', $a);
    }
    // Backup the activity.
    $bc = new backup_controller(backup::TYPE_1ACTIVITY, $cm->id, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id);
    $backupid = $bc->get_backupid();
    $backupbasepath = $bc->get_plan()->get_basepath();
    $bc->execute_plan();
    $bc->destroy();
    // Restore the backup immediately.
    $rc = new restore_controller($backupid, $course->id, backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id, backup::TARGET_CURRENT_ADDING);
    $cmcontext = context_module::instance($cm->id);
    if (!$rc->execute_precheck()) {
        $precheckresults = $rc->get_precheck_results();
        if (is_array($precheckresults) && !empty($precheckresults['errors'])) {
            if (empty($CFG->keeptempdirectoriesonbackup)) {
                fulldelete($backupbasepath);
            }
        }
    }
    $rc->execute_plan();
    // Now a bit hacky part follows - we try to get the cmid of the newly
    // restored copy of the module.
    $newcmid = null;
    $tasks = $rc->get_plan()->get_tasks();
    foreach ($tasks as $task) {
        if (is_subclass_of($task, 'restore_activity_task')) {
            if ($task->get_old_contextid() == $cmcontext->id) {
                $newcmid = $task->get_moduleid();
                break;
            }
        }
    }
    // If we know the cmid of the new course module, let us move it
    // right below the original one. otherwise it will stay at the
    // end of the section.
    if ($newcmid) {
        $info = get_fast_modinfo($course);
        $newcm = $info->get_cm($newcmid);
        $section = $DB->get_record('course_sections', array('id' => $cm->section, 'course' => $cm->course));
        moveto_module($newcm, $section, $cm);
        moveto_module($cm, $section, $newcm);
        // Update calendar events with the duplicated module.
        $refresheventsfunction = $newcm->modname . '_refresh_events';
        if (function_exists($refresheventsfunction)) {
            call_user_func($refresheventsfunction, $newcm->course);
        }
        // Trigger course module created event. We can trigger the event only if we know the newcmid.
        $event = \core\event\course_module_created::create_from_cm($newcm);
        $event->trigger();
    }
    rebuild_course_cache($cm->course);
    $rc->destroy();
    if (empty($CFG->keeptempdirectoriesonbackup)) {
        fulldelete($backupbasepath);
    }
    return isset($newcm) ? $newcm : null;
}
开发者ID:janeklb,项目名称:moodle,代码行数:81,代码来源:lib.php

示例12: stdClass

            $data_progress = new stdClass();
            $data_progress->current = 0;
            $data_progress->size = $progress_bar_elements;
            $k = 0;
            $pbar->update_full(40, get_string('progress_counter', 'format_onetopic', $data_progress));
            foreach ($section_mods as $modnumber) {
                $k++;
                $mod = $modinfo->cms[$modnumber];
                $cm = get_coursemodule_from_id('', $mod->id, 0, true, MUST_EXIST);
                $modcontext = context_module::instance($cm->id);
                if (has_capability('moodle/course:manageactivities', $modcontext)) {
                    // Duplicate the module.
                    $newcm = duplicate_module($course, $cm);
                    //Move new module to new section
                    if ($newcm && is_object($newcm)) {
                        moveto_module($newcm, $new_sectioninfo);
                    }
                }
                $data_progress->current = $k;
                $percent = 40 + $k / $progress_bar_elements * 60;
                $pbar->update_full($percent, get_string('progress_counter', 'format_onetopic', $data_progress));
            }
        }
    } else {
        $pbar->update_full(100, get_string('progress_full', 'format_onetopic'));
    }
    $section_togo = $num_newsection;
} else {
    $section_togo = $section;
    echo get_string('error_nosectioninfo', 'format_onetopic');
    echo $OUTPUT->continue_button(course_get_url($course, $section));
开发者ID:dibarbado,项目名称:moodle,代码行数:31,代码来源:duplicate.php

示例13: test_move_module_in_course

 public function test_move_module_in_course()
 {
     global $DB;
     $this->resetAfterTest(true);
     // Setup fixture
     $course = $this->getDataGenerator()->create_course(array('numsections' => 5), array('createsections' => true));
     $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id));
     $cms = get_fast_modinfo($course)->get_cms();
     $cm = reset($cms);
     $newsection = get_fast_modinfo($course)->get_section_info(3);
     $oldsectionid = $cm->section;
     // Perform the move
     moveto_module($cm, $newsection);
     // reset of get_fast_modinfo is usually called the code calling moveto_module so call it here
     get_fast_modinfo(0, 0, true);
     $cms = get_fast_modinfo($course)->get_cms();
     $cm = reset($cms);
     // Check that the cached modinfo contains the correct section info
     $modinfo = get_fast_modinfo($course);
     $this->assertTrue(empty($modinfo->sections[0]));
     $this->assertFalse(empty($modinfo->sections[3]));
     // Check that the old section's sequence no longer contains this ID
     $oldsection = $DB->get_record('course_sections', array('id' => $oldsectionid));
     $oldsequences = explode(',', $newsection->sequence);
     $this->assertFalse(in_array($cm->id, $oldsequences));
     // Check that the new section's sequence now contains this ID
     $newsection = $DB->get_record('course_sections', array('id' => $newsection->id));
     $newsequences = explode(',', $newsection->sequence);
     $this->assertTrue(in_array($cm->id, $newsequences));
     // Check that the section number has been changed in the cm
     $this->assertEquals($newsection->id, $cm->section);
     // Perform a second move as some issues were only seen on the second move
     $newsection = get_fast_modinfo($course)->get_section_info(2);
     $oldsectionid = $cm->section;
     $result = moveto_module($cm, $newsection);
     $this->assertTrue($result);
     // reset of get_fast_modinfo is usually called the code calling moveto_module so call it here
     get_fast_modinfo(0, 0, true);
     $cms = get_fast_modinfo($course)->get_cms();
     $cm = reset($cms);
     // Check that the cached modinfo contains the correct section info
     $modinfo = get_fast_modinfo($course);
     $this->assertTrue(empty($modinfo->sections[0]));
     $this->assertFalse(empty($modinfo->sections[2]));
     // Check that the old section's sequence no longer contains this ID
     $oldsection = $DB->get_record('course_sections', array('id' => $oldsectionid));
     $oldsequences = explode(',', $newsection->sequence);
     $this->assertFalse(in_array($cm->id, $oldsequences));
     // Check that the new section's sequence now contains this ID
     $newsection = $DB->get_record('course_sections', array('id' => $newsection->id));
     $newsequences = explode(',', $newsection->sequence);
     $this->assertTrue(in_array($cm->id, $newsequences));
 }
开发者ID:Burick,项目名称:moodle,代码行数:53,代码来源:courselib_test.php

示例14: perform_moveto

/**
 * perform the actual deletion of the selected course modules
 * @param array $modules
 * @param int $target ID of the section to move to
 */
function perform_moveto($modules, $target)
{
    global $CFG, $DB;
    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');
        }
        // verify target
        if (!($section = $DB->get_record('course_sections', array('course' => $cm->course, 'section' => $target)))) {
            print_error('sectionnotexist', 'block_massaction');
        }
        $context = context_course::instance($section->course);
        require_capability('moodle/course:manageactivities', $context);
        moveto_module($cm_record, $section);
    }
}
开发者ID:ULCC-QMUL,项目名称:moodle-block_massaction,代码行数:22,代码来源:action.php

示例15: error

        // normal moveto
        if (!($beforecm = get_record("course_modules", "id", $moveto))) {
            error("The destination course module doesn't exist");
        }
        if (!($section = get_record("course_sections", "id", $beforecm->section))) {
            error("This section doesn't exist");
        }
    }
    require_login($section->course);
    // needed to setup proper $COURSE
    $context = get_context_instance(CONTEXT_COURSE, $section->course);
    require_capability('moodle/course:manageactivities', $context);
    if (!ismoving($section->course)) {
        error("You need to copy something first!");
    }
    moveto_module($cm, $section, $beforecm);
    unset($USER->activitycopy);
    unset($USER->activitycopycourse);
    unset($USER->activitycopyname);
    rebuild_course_cache($section->course);
    if (SITEID == $section->course) {
        redirect($CFG->wwwroot);
    } else {
        redirect("view.php?id={$section->course}#section-{$sectionreturn}");
    }
} else {
    if (!empty($indent) and confirm_sesskey()) {
        $id = required_param('id', PARAM_INT);
        if (!($cm = get_record("course_modules", "id", $id))) {
            error("This course module doesn't exist");
        }
开发者ID:veritech,项目名称:pare-project,代码行数:31,代码来源:mod.php


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