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


PHP course_add_cm_to_section函数代码示例

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


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

示例1: print_error

         print_error('invalidfunction', '', course_get_url($course, $cw->section));
     } else {
         print_error('cannotaddnewmodule', '', course_get_url($course, $cw->section), $fromform->modulename);
     }
 }
 $fromform->instance = $returnfromfunc;
 $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id' => $fromform->coursemodule));
 // update embedded links and save files
 $modcontext = context_module::instance($fromform->coursemodule);
 if (!empty($introeditor)) {
     $fromform->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id, 'mod_' . $fromform->modulename, 'intro', 0, array('subdirs' => true), $introeditor['text']);
     $DB->set_field($fromform->modulename, 'intro', $fromform->intro, array('id' => $fromform->instance));
 }
 // course_modules and course_sections each contain a reference
 // to each other, so we have to update one of them twice.
 $sectionid = course_add_cm_to_section($course, $fromform->coursemodule, $fromform->section);
 // make sure visibility is set correctly (in particular in calendar)
 // note: allow them to set it even without moodle/course:activityvisibility
 set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
 if (isset($fromform->cmidnumber)) {
     //label
     // set cm idnumber - uniqueness is already verified by form validation
     set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
 }
 // Set up conditions
 if ($CFG->enableavailability) {
     condition_info::update_cm_from_form((object) array('id' => $fromform->coursemodule), $fromform, false);
 }
 $eventname = 'mod_created';
 add_to_log($course->id, "course", "add mod", "../mod/{$fromform->modulename}/view.php?id={$fromform->coursemodule}", "{$fromform->modulename} {$fromform->instance}");
 add_to_log($course->id, $fromform->modulename, "add", "view.php?id={$fromform->coursemodule}", "{$fromform->instance}", $fromform->coursemodule);
开发者ID:vinoth4891,项目名称:clinique,代码行数:31,代码来源:modedit.php

示例2: print_error

                // course_modules and course_sections each contain a reference
                // to each other, so we have to update one of them twice.

                if (! $currmodule = $DB->get_record("modules", array("name"=>'glossary'))) {
                    print_error('modulenotexist', 'debug', '', 'Glossary');
                }
                $mod->module = $currmodule->id;
                $mod->course = $course->id;
                $mod->modulename = 'glossary';
                $mod->section = 0;

                if (! $mod->coursemodule = add_course_module($mod) ) {
                    print_error('cannotaddcoursemodule');
                }

                $sectionid = course_add_cm_to_section($course, $mod->coursemodule, 0);
                //We get the section's visible field status
                $visible = $DB->get_field("course_sections", "visible", array("id"=>$sectionid));

                $DB->set_field("course_modules", "visible", $visible, array("id"=>$mod->coursemodule));

                add_to_log($course->id, "course", "add mod",
                           "../mod/$mod->modulename/view.php?id=$mod->coursemodule",
                           "$mod->modulename $mod->instance");
                add_to_log($course->id, $mod->modulename, "add",
                           "view.php?id=$mod->coursemodule",
                           "$mod->instance", $mod->coursemodule);

                rebuild_course_cache($course->id);

                echo $OUTPUT->box(get_string("newglossarycreated","glossary"),'generalbox boxaligncenter boxwidthnormal');
开发者ID:verbazend,项目名称:AWFA,代码行数:31,代码来源:import.php

示例3: create_migration_assignment

 /**
  * Create a migrated turnitin assignment in Moodle
  *
  * @global type $DB
  * @global type $CFG
  * @param array $partids the ids of turnitin assignment to create as parts of new assignment
  * @param int $courseid
  * @param string $assignmentname
  * @return boolean false if failed
  */
 public static function create_migration_assignment($partids, $courseid, $assignmentname)
 {
     global $DB, $CFG, $OUTPUT;
     $config = turnitintooltwo_admin_config();
     $partids = (array) $partids;
     $tempassignment = new turnitintooltwo_assignment(0, '', 'M');
     $newassignment = $tempassignment->update_assignment_from_tii($partids);
     $newassignment["turnitintooltwo"]->course = $courseid;
     $newassignment["turnitintooltwo"]->name = $assignmentname;
     $newassignment["turnitintooltwo"]->numparts = count($partids);
     $newassignment["turnitintooltwo"]->gradedisplay = 1;
     $newassignment["turnitintooltwo"]->shownonsubmission = 1;
     $newassignment["turnitintooltwo"]->usegrademark = $config->usegrademark;
     // Get maximum grade.
     $newassignment["turnitintooltwo"]->grade = 0;
     foreach ($newassignment["parts"] as $part) {
         if ($newassignment["turnitintooltwo"]->grade < $part->maxmarks) {
             $newassignment["turnitintooltwo"]->grade = $part->maxmarks;
         }
     }
     $turnitintooltwoassignment = new turnitintooltwo_assignment(0, $newassignment["turnitintooltwo"]);
     if (!($toolid = $DB->insert_record("turnitintooltwo", $turnitintooltwoassignment->turnitintooltwo))) {
         turnitintooltwo_activitylog(get_string('migrationassignmentcreationerror', 'turnitintooltwo', $courseid), "REQUEST");
         return false;
     } else {
         turnitintooltwo_activitylog(get_string('migrationassignmentcreated', 'turnitintooltwo', $toolid), "REQUEST");
     }
     $module = $DB->get_record("modules", array("name" => "turnitintooltwo"));
     $coursemodule = new stdClass();
     $coursemodule->course = $courseid;
     $coursemodule->module = $module->id;
     $coursemodule->added = time();
     $coursemodule->instance = $toolid;
     $coursemodule->section = 0;
     include_once $CFG->dirroot . "/course/lib.php";
     // Add Course module and get course section.
     if (!($coursemodule->coursemodule = add_course_module($coursemodule))) {
         echo $OUTPUT->notification(get_string('migrationassignmenterror1', 'turnitintooltwo', $courseid));
         turnitintooltwo_activitylog(get_string('migrationassignmenterror1', 'turnitintooltwo', $courseid), "REQUEST");
         return false;
     }
     if (is_callable('course_add_cm_to_section')) {
         if (!($sectionid = course_add_cm_to_section($coursemodule->course, $coursemodule->coursemodule, $coursemodule->section))) {
             echo $OUTPUT->notification(get_string('migrationassignmenterror2', 'turnitintooltwo', $courseid));
             turnitintooltwo_activitylog(get_string('migrationassignmenterror2', 'turnitintooltwo', $courseid), "REQUEST");
             return false;
         }
     } else {
         if (!($sectionid = add_mod_to_section($coursemodule))) {
             echo $OUTPUT->notification(get_string('migrationassignmenterror2', 'turnitintooltwo', $courseid));
             turnitintooltwo_activitylog(get_string('migrationassignmenterror2', 'turnitintooltwo', $courseid), "REQUEST");
             return false;
         }
     }
     $DB->set_field("course_modules", "section", $sectionid, array("id" => $coursemodule->coursemodule));
     rebuild_course_cache($courseid);
     foreach ($newassignment["parts"] as $part) {
         $part->turnitintooltwoid = $toolid;
         $part->deleted = 0;
         $part->migrated = -1;
         if ($part->id = $DB->insert_record("turnitintooltwo_parts", $part)) {
             turnitintooltwo_activitylog(get_string('migrationassignmentpartcreated', 'turnitintooltwo', $part->id), "REQUEST");
         }
         if ($turnitintooltwoassignment->create_event($toolid, $part->partname, $part->dtdue)) {
             $part->migrated = 1;
             $DB->update_record("turnitintooltwo_parts", $part);
         } else {
             echo $OUTPUT->notification(get_string('migrationassignmenterror3', 'turnitintooltwo', $courseid));
             turnitintooltwo_activitylog(get_string('migrationassignmenterror3', 'turnitintooltwo', $courseid), "REQUEST");
         }
     }
 }
开发者ID:sk-unikent,项目名称:moodle-mod_turnitintooltwo-1,代码行数:82,代码来源:turnitintooltwo_assignment.class.php

示例4: test_course_add_cm_to_section

 public function test_course_add_cm_to_section()
 {
     global $DB;
     $this->resetAfterTest(true);
     // Create course with 1 section.
     $course = $this->getDataGenerator()->create_course(array('shortname' => 'GrowingCourse', 'fullname' => 'Growing Course', 'numsections' => 1), array('createsections' => true));
     // Trash modinfo.
     rebuild_course_cache($course->id, true);
     // Create some cms for testing.
     $cmids = array();
     for ($i = 0; $i < 4; $i++) {
         $cmids[$i] = $DB->insert_record('course_modules', array('course' => $course->id));
     }
     // Add it to section that exists.
     course_add_cm_to_section($course, $cmids[0], 1);
     // Check it got added to sequence.
     $sequence = $DB->get_field('course_sections', 'sequence', array('course' => $course->id, 'section' => 1));
     $this->assertEquals($cmids[0], $sequence);
     // Add a second, this time using courseid variant of parameters.
     $coursecacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     course_add_cm_to_section($course->id, $cmids[1], 1);
     $sequence = $DB->get_field('course_sections', 'sequence', array('course' => $course->id, 'section' => 1));
     $this->assertEquals($cmids[0] . ',' . $cmids[1], $sequence);
     // Check that modinfo cache was reset but not rebuilt (important for performance if calling repeatedly).
     $this->assertGreaterThan($coursecacherev, $DB->get_field('course', 'cacherev', array('id' => $course->id)));
     $this->assertEmpty(cache::make('core', 'coursemodinfo')->get($course->id));
     // Add one to section that doesn't exist (this might rebuild modinfo).
     course_add_cm_to_section($course, $cmids[2], 2);
     $this->assertEquals(3, $DB->count_records('course_sections', array('course' => $course->id)));
     $sequence = $DB->get_field('course_sections', 'sequence', array('course' => $course->id, 'section' => 2));
     $this->assertEquals($cmids[2], $sequence);
     // Add using the 'before' option.
     course_add_cm_to_section($course, $cmids[3], 2, $cmids[2]);
     $this->assertEquals(3, $DB->count_records('course_sections', array('course' => $course->id)));
     $sequence = $DB->get_field('course_sections', 'sequence', array('course' => $course->id, 'section' => 2));
     $this->assertEquals($cmids[3] . ',' . $cmids[2], $sequence);
 }
开发者ID:uniedpa,项目名称:moodle,代码行数:37,代码来源:courselib_test.php

示例5: 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.
         delete_course_module($this->cm->id);
         throw new moodle_exception('errorcreatingactivity', 'moodle', '', $this->module->name);
     }
     $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);
     $this->course->modinfo = null;
     // Otherwise we will just get the old version back again.
     $sectionid = course_add_cm_to_section($this->course, $this->cm->id, $this->section);
     set_coursemodule_visible($this->cm->id, true);
     // 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.
         delete_course_module($this->cm->id);
         throw new moodle_exception('errorcreatingactivity', 'moodle', '', $this->module->name);
     }
     $mod = $info->cms[$this->cm->id];
     $mod->groupmodelink = $this->cm->groupmodelink;
     $mod->groupmode = $this->cm->groupmode;
     // Trigger mod_created event with information about this module.
     $eventdata = new stdClass();
     $eventdata->modulename = $mod->modname;
     $eventdata->name = $mod->name;
     $eventdata->cmid = $mod->id;
     $eventdata->courseid = $this->course->id;
     $eventdata->userid = $USER->id;
     events_trigger('mod_created', $eventdata);
     add_to_log($this->course->id, "course", "add mod", "../mod/{$mod->modname}/view.php?id={$mod->id}", "{$mod->modname} {$instanceid}");
     add_to_log($this->course->id, $mod->modname, "add", "view.php?id={$mod->id}", "{$instanceid}", $mod->id);
     $this->send_response($mod);
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:43,代码来源:dnduploadlib.php

示例6: add_moduleinfo


//.........这里部分代码省略.........
    $moduleinfo = set_moduleinfo_defaults($moduleinfo);
    if (!empty($course->groupmodeforce) or !isset($moduleinfo->groupmode)) {
        $moduleinfo->groupmode = 0;
        // Do not set groupmode.
    }
    // First add course_module record because we need the context.
    $newcm = new stdClass();
    $newcm->course = $course->id;
    $newcm->module = $moduleinfo->module;
    $newcm->instance = 0;
    // Not known yet, will be updated later (this is similar to restore code).
    $newcm->visible = $moduleinfo->visible;
    $newcm->visibleold = $moduleinfo->visible;
    if (isset($moduleinfo->cmidnumber)) {
        $newcm->idnumber = $moduleinfo->cmidnumber;
    }
    $newcm->groupmode = $moduleinfo->groupmode;
    $newcm->groupingid = $moduleinfo->groupingid;
    $completion = new completion_info($course);
    if ($completion->is_enabled()) {
        $newcm->completion = $moduleinfo->completion;
        $newcm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber;
        $newcm->completionview = $moduleinfo->completionview;
        $newcm->completionexpected = $moduleinfo->completionexpected;
    }
    if (!empty($CFG->enableavailability)) {
        // This code is used both when submitting the form, which uses a long
        // name to avoid clashes, and by unit test code which uses the real
        // name in the table.
        $newcm->availability = null;
        if (property_exists($moduleinfo, 'availabilityconditionsjson')) {
            if ($moduleinfo->availabilityconditionsjson !== '') {
                $newcm->availability = $moduleinfo->availabilityconditionsjson;
            }
        } else {
            if (property_exists($moduleinfo, 'availability')) {
                $newcm->availability = $moduleinfo->availability;
            }
        }
    }
    if (isset($moduleinfo->showdescription)) {
        $newcm->showdescription = $moduleinfo->showdescription;
    } else {
        $newcm->showdescription = 0;
    }
    // From this point we make database changes, so start transaction.
    $transaction = $DB->start_delegated_transaction();
    if (!($moduleinfo->coursemodule = add_course_module($newcm))) {
        print_error('cannotaddcoursemodule');
    }
    if (plugin_supports('mod', $moduleinfo->modulename, FEATURE_MOD_INTRO, true) && isset($moduleinfo->introeditor)) {
        $introeditor = $moduleinfo->introeditor;
        unset($moduleinfo->introeditor);
        $moduleinfo->intro = $introeditor['text'];
        $moduleinfo->introformat = $introeditor['format'];
    }
    $addinstancefunction = $moduleinfo->modulename . "_add_instance";
    try {
        $returnfromfunc = $addinstancefunction($moduleinfo, $mform);
    } catch (moodle_exception $e) {
        $returnfromfunc = $e;
    }
    if (!$returnfromfunc or !is_number($returnfromfunc)) {
        // Undo everything we can. This is not necessary for databases which
        // support transactions, but improves consistency for other databases.
        $modcontext = context_module::instance($moduleinfo->coursemodule);
        context_helper::delete_instance(CONTEXT_MODULE, $moduleinfo->coursemodule);
        $DB->delete_records('course_modules', array('id' => $moduleinfo->coursemodule));
        if ($e instanceof moodle_exception) {
            throw $e;
        } else {
            if (!is_number($returnfromfunc)) {
                print_error('invalidfunction', '', course_get_url($course, $moduleinfo->section));
            } else {
                print_error('cannotaddnewmodule', '', course_get_url($course, $moduleinfo->section), $moduleinfo->modulename);
            }
        }
    }
    $moduleinfo->instance = $returnfromfunc;
    $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id' => $moduleinfo->coursemodule));
    // Update embedded links and save files.
    $modcontext = context_module::instance($moduleinfo->coursemodule);
    if (!empty($introeditor)) {
        $moduleinfo->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id, 'mod_' . $moduleinfo->modulename, 'intro', 0, array('subdirs' => true), $introeditor['text']);
        $DB->set_field($moduleinfo->modulename, 'intro', $moduleinfo->intro, array('id' => $moduleinfo->instance));
    }
    // Course_modules and course_sections each contain a reference to each other.
    // So we have to update one of them twice.
    $sectionid = course_add_cm_to_section($course, $moduleinfo->coursemodule, $moduleinfo->section);
    // Trigger event based on the action we did.
    // Api create_from_cm expects modname and id property, and we don't want to modify $moduleinfo since we are returning it.
    $eventdata = clone $moduleinfo;
    $eventdata->modname = $eventdata->modulename;
    $eventdata->id = $eventdata->coursemodule;
    $event = \core\event\course_module_created::create_from_cm($eventdata, $modcontext);
    $event->trigger();
    $moduleinfo = edit_module_post_actions($moduleinfo, $course);
    $transaction->allow_commit();
    return $moduleinfo;
}
开发者ID:abhilash1994,项目名称:moodle,代码行数:101,代码来源:modlib.php

示例7: add_mod_to_section

/**
 * Given a full mod object with section and course already defined, adds this module to that section.
 *
 * This function is deprecated, please use {@link course_add_cm_to_section()}
 * Note that course_add_cm_to_section() also updates field course_modules.section and
 * calls rebuild_course_cache()
 *
 * @deprecated since 2.4
 *
 * @param object $mod
 * @param int $beforemod An existing ID which we will insert the new module before
 * @return int The course_sections ID where the mod is inserted
 */
function add_mod_to_section($mod, $beforemod = null)
{
    debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER);
    global $DB;
    return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod);
}
开发者ID:Hirenvaghasiya,项目名称:moodle,代码行数:19,代码来源:deprecatedlib.php

示例8: pearsondirect_create_lti

function pearsondirect_create_lti($ltilink, $courseid)
{
    global $DB, $CFG;
    require_once $CFG->dirroot . '/course/lib.php';
    $lti = new stdClass();
    $lti->course = $courseid;
    $lti->name = $ltilink->title;
    $lti->timecreated = time();
    $lti->timemodified = $lti->timecreated;
    $lti->typeid = 0;
    $lti->toolurl = $ltilink->launchUrl;
    $lti->instructorchoicesendname = 1;
    $lti->instructorchoicesendemailaddr = 1;
    $strCustomParams = '';
    $cps = $ltilink->customParameters;
    foreach ($cps as $cp) {
        $n = $cp->name;
        // @todo fix
        if ($n == 'target_function') {
            $n = 'targetId';
        }
        $v = $cp->value;
        if ($strCustomParams == NULL) {
            $strCustomParams = '';
        }
        $strCustomParams .= $n . '=' . $v . "\n";
    }
    if ($strCustomParams != null) {
        $lti->instructorcustomparameters = $strCustomParams;
    }
    $lti->launchcontainer = 4;
    $lti->resourcekey = $CFG->pearson_key;
    $lti->password = $CFG->pearson_secret;
    $lti->debuglaunch = 0;
    $lti->showtitlelaunch = 0;
    $lti->showdescriptionlaunch = 0;
    $use_icons = $CFG->pearson_use_icons;
    if ($use_icons) {
        $lti->icon = $CFG->wwwroot . '/blocks/pearson/pix/icon.png';
    }
    $lti->id = $DB->insert_record('lti', $lti);
    $cm = new stdClass();
    $cm->course = $courseid;
    $cm->module = pearsondirect_get_lti_module();
    $cm->instance = $lti->id;
    $cm->section = 0;
    $cm->idnumber = pearsondirect_construct_id_for_lti($ltilink->id, $courseid, $lti->id, 't');
    $cm->added = time();
    $cm->score = 0;
    $cm->indent = 0;
    $instructoronly = pearsondirect_is_instructor_link($ltilink);
    if ($instructoronly) {
        $cm->visible = 0;
        $cm->visibleold = 0;
    } else {
        $cm->visible = 1;
        $cm->visibleold = 1;
    }
    $cm->groupmode = 0;
    $cm->groupingid = 0;
    $cm->groupmembersonly = 0;
    $cm->completion = 0;
    $cm->completionview = 0;
    $cm->completionexpected = 0;
    $cm->showavailability = 0;
    $cm->showdescription = 0;
    $cm->coursemodule = add_course_module($cm);
    $sectionid = course_add_cm_to_section($cm->course, $cm->coursemodule, $cm->section, null);
    $DB->set_field("course_modules", "section", $sectionid, array("id" => $cm->coursemodule));
    return $lti->id;
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:71,代码来源:locallib.php

示例9: mimeinfo

        $eq->intro = $equrl;
        $eq->introformat = FORMAT_HTML;
        $eq->url = $equrl;
        $eq->course = $courseid;
        $eq->modulename = 'equella';
        $eq->module = $module->id;
        $eq->attachmentuuid = $attachmentuuid;
        $eq->mimetype = mimeinfo('type', $equrl);
        try {
            $moduleid = equella_add_instance($eq);
        } catch (Exception $ex) {
            throw new equella_exception('Failed to create EQUELLA resource.');
        }
        $eq->instance = $moduleid;
        if (!($eq->coursemodule = add_course_module($eq))) {
            print_error('cannotaddcoursemodule');
        }
        if (!($addedsectionid = course_add_cm_to_section($eq->course, $eq->coursemodule, 0))) {
            print_error('cannotaddcoursemoduletosection');
        }
        if (!$DB->set_field('course_modules', 'section', $addedsectionid, array('id' => $eq->coursemodule))) {
            print_error('Could not update the course module with the correct section');
        }
        set_coursemodule_visible($eq->coursemodule, true);
    }
    $courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
    redirect($courseurl);
}
echo $OUTPUT->header();
$form->display();
echo $OUTPUT->footer();
开发者ID:CTANZ,项目名称:moodle-mod_equella,代码行数:31,代码来源:generator.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: pearson_add_instance


//.........这里部分代码省略.........
    require_once $CFG->dirroot . '/course/lib.php';
    require_once $CFG->dirroot . '/blocks/pearson/locallib.php';
    require_once $CFG->dirroot . '/lib/modinfolib.php';
    $pd_c = clean_param($pd->pdcourseid, PARAM_INT);
    $pd_s = clean_param($pd->pdsection, PARAM_INT);
    $launchpresentation = 4;
    if (isset($pd->inframe)) {
        $launchpresentation = 2;
    }
    $templatelink = $DB->get_record('lti_types', array('id' => $pd->selectedlink), '*', MUST_EXIST);
    $ltilink = new stdClass();
    $ltilink->course = $templatelink->course;
    $linkname = '';
    if (isset($pd->mediaurltitle) && trim($pd->mediaurltitle) !== '') {
        $linkname = clean_param($pd->mediaurltitle, PARAM_TEXT);
    } else {
        if (isset($pd->linktitle) && trim($pd->linktitle) !== '') {
            $linkname = clean_param($pd->linktitle, PARAM_TEXT);
        } else {
            $linkname = $templatelink->name;
        }
    }
    $ltilink->name = format_string($linkname);
    $ltilink->timecreated = time();
    $ltilink->timemodified = $ltilink->timecreated;
    $ltilink->typeid = 0;
    $ltilink->toolurl = $templatelink->baseurl;
    $ltilink->instructorchoicesendname = 1;
    $ltilink->instructorchoicesendemailaddr = 1;
    $strCustomParams = $DB->get_field('lti_types_config', 'value', array('typeid' => $templatelink->id, 'name' => 'customparameters'), IGNORE_MISSING);
    if ($strCustomParams == null) {
        $strCustomParams = '';
    }
    $pd_customparams = clean_param($pd->customparams, PARAM_TEXT);
    if (isset($pd_customparams) && trim($pd_customparams) !== '') {
        if (strpos($pd_customparams, ',') !== false) {
            $cp_array = explode(',', $pd_customparams);
            foreach ($cp_array as $cpa) {
                $kv_array = explode('=', $cpa);
                $key = $kv_array[0];
                $length = strlen('custom_');
                if (substr($key, 0, $length) === 'custom_') {
                    $key = substr($key, $length, strlen($key));
                }
                $strCustomParams .= $key . '=' . $kv_array[1] . "\n";
            }
        } else {
            $kv_array = explode('=', $pd_customparams);
            $key = $kv_array[0];
            $length = strlen('custom_');
            if (substr($key, 0, $length) === 'custom_') {
                $key = substr($key, $length, strlen($key));
            }
            $strCustomParams .= $key . '=' . $kv_array[1] . "\n";
        }
    }
    $pd_mediaurl = clean_param($pd->mediaurl, PARAM_URL);
    if (isset($pd_mediaurl) && trim($pd_mediaurl) !== '') {
        $strCustomParams .= 'genericmediaurl=' . $pd_mediaurl . "\n";
    }
    if ($strCustomParams != null) {
        $ltilink->instructorcustomparameters = $strCustomParams;
    }
    $ltilink->launchcontainer = $launchpresentation;
    $ltilink->resourcekey = $CFG->pearson_key;
    $ltilink->password = $CFG->pearson_secret;
    $ltilink->debuglaunch = 0;
    $ltilink->showtitlelaunch = 0;
    $ltilink->showdescriptionlaunch = 0;
    $use_icons = $CFG->pearson_use_icons;
    if ($use_icons) {
        $ltilink->icon = $CFG->wwwroot . '/blocks/pearson/pix/icon.png';
    }
    $ltilink->id = $DB->insert_record('lti', $ltilink);
    $cm = new stdClass();
    $cm->course = $pd_c;
    $cm->module = pearsondirect_get_lti_module();
    $cm->instance = $ltilink->id;
    $cm->section = $pd_s;
    $cm->idnumber = $templatelink->tooldomain . ':' . $ltilink->id . ':c';
    $cm->added = time();
    $cm->score = 0;
    $cm->indent = 0;
    $cm->visible = 1;
    $cm->visibleold = 1;
    $cm->groupmode = 0;
    $cm->groupingid = 0;
    $cm->groupmembersonly = 0;
    $cm->completion = 0;
    $cm->completionview = 0;
    $cm->completionexpected = 0;
    $cm->showavailability = 0;
    $cm->showdescription = 0;
    $cm->coursemodule = add_course_module($cm);
    $sectionid = course_add_cm_to_section($cm->course, $cm->coursemodule, $cm->section, null);
    $DB->set_field("course_modules", "section", $sectionid, array("id" => $cm->coursemodule));
    rebuild_course_cache($pd_c);
    redirect("{$CFG->wwwroot}/course/view.php?id={$pd_c}#section-" . $pd_s);
    return $ltilink->id;
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:101,代码来源:lib.php

示例12: add

 static function add($modulename, $courseid, $atstart = 0, $ifexists = 0, $moduleparams = null, $section = 0, $visible = 0, $permissionsoverrides = array())
 {
     global $DB, $CFG;
     // Check module type exists
     if (!($module = $DB->get_record('modules', array('name' => $modulename), '*'))) {
         return array(false, 'Module type not found');
     }
     // Check course exists
     if (!($course = $DB->get_record('course', array('id' => $courseid), '*'))) {
         return array(false, 'Course not found');
     }
     // Check course is correct format
     if ($course->format == 'site' || $course->format == 'social' || $course->format == 'scorm') {
         return array(false, 'Course is not a weekly or topic type, skipping');
     }
     // Check user has required permissions to add course module
     $requiredcapabilities = array('moodle/course:manageactivities', 'moodle/course:activityvisibility', 'moodle/role:override');
     if (!has_all_capabilities($requiredcapabilities, context_course::instance($courseid))) {
         return array(false, 'Insufficient permissions to add course module');
     }
     // Set course module initial data
     $newcm = new stdClass();
     $newcm->course = $course->id;
     $newcm->module = $module->id;
     $newcm->modulename = $module->name;
     $newcm->section = 0;
     $newcm->instance = 0;
     $newcm->visible = $visible;
     $newcm->groupmode = 0;
     // No groups
     $newcm->groupingid = 0;
     $newcm->groupmembersonly = 0;
     $newcm->showdescription = 0;
     $newcm->cmidnumber = '';
     // Check whether module plugin class exists for selected module otherwise use generic module plugin
     $modulepluginclass = 'module_plugin_' . $modulename;
     $modulepluginfilename = 'moduleplugins/' . $modulepluginclass . '.php';
     if (file_exists($modulepluginfilename)) {
         include_once $modulepluginfilename;
         $moduleplugin = new $modulepluginclass($moduleparams, $newcm);
     } else {
         include_once 'moduleplugins/module_plugin_generic.php';
         $moduleplugin = new module_plugin_generic($moduleparams, $newcm, $modulename);
         $modulepluginclass = 'module_plugin_generic';
     }
     // Check that module params XML is valid
     if (!$modulepluginclass::check_params_xml($moduleparams)) {
         return array(false, 'Module parameters not valid');
     }
     $newcm->name = (string) $moduleparams->title;
     $newcm->intro = (string) $moduleparams->description;
     $newcm->introformat = 1;
     // Check whether module instance with title already exists
     $sql = 'SELECT COUNT(*) AS count 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 {' . $module->name . '} AS m ON m.id = cm.instance WHERE cs.course = ? AND cs.section = ? AND m.name = ? AND ms.name = ?';
     $instances = $DB->get_record_sql($sql, array($course->id, $section, $newcm->name, $module->name));
     if ($instances->count > 0) {
         if ($ifexists == 0) {
             return array(false, 'Already exists, skipping');
         } else {
             if ($ifexists == 2) {
                 if (!self::delete($modulename, $course, $newcm->name, $section)) {
                     return array(false, 'Error removing existing module instance(s), could not replace');
                 }
             }
         }
     }
     // Create course module
     if (!($newcm->coursemodule = add_course_module($newcm))) {
         return array(false, 'Could not create course module');
     }
     // Create module instance
     $ret = $moduleplugin->create_instance();
     if (!$ret[0]) {
         return $ret;
     }
     // Update course_modules DB row to reference new module instance
     $DB->set_field('course_modules', 'instance', $newcm->instance, array('id' => $newcm->coursemodule));
     // course_modules and course_sections each contain a reference
     // to each other, so we have to update one of them twice.
     if ($atstart) {
         if (!($section = $DB->get_record('course_sections', array('course' => $newcm->course, 'section' => $newcm->section)))) {
             // Section doesn't already exist so create it in normal manner
             // $sectionid = add_mod_to_section($newcm); JAC change 20160809
             // requires course_add_cm_to_section($courseorid, $cmid, $sectionnum, $beforemod = null)
             $sectionid = course_add_cm_to_section($newcm->course, $newcm->coursemodule, $newcm->section);
         } else {
             // Moodle's add_mod_to_section add before functionality is broken so we have to do this here
             $section->sequence = trim($section->sequence);
             if (empty($section->sequence)) {
                 $newsequence = "{$newcm->coursemodule}";
             } else {
                 $newsequence = "{$newcm->coursemodule},{$section->sequence}";
             }
             $DB->set_field("course_sections", "sequence", $newsequence, array("id" => $section->id));
             $sectionid = $section->id;
         }
     } else {
         // $sectionid = add_mod_to_section($newcm); JAC change 20160809
         $sectionid = course_add_cm_to_section($newcm->course, $newcm->coursemodule, $newcm->section);
     }
//.........这里部分代码省略.........
开发者ID:OBU-OBIS,项目名称:moodle-block_module_add,代码行数:101,代码来源:course_mod_add.php

示例13: add_file

 public function add_file($section, $name, $path, $display = 0)
 {
     global $DB, $CFG, $USER;
     $section = (int) $section;
     $display = (int) $display;
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->dirroot . '/mod/resource/lib.php';
     require_once $CFG->dirroot . '/mod/resource/locallib.php';
     $params = self::validate_parameters(self::add_file_parameters(), array('section' => $section, 'name' => $name, 'path' => $path, 'display' => $display));
     $section = $DB->get_record('course_sections', array('id' => $section), '*', MUST_EXIST);
     $course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
     self::require_access($course->id);
     // Finally create the file item.
     // First add course_module record because we need the context.
     $newcm = new stdClass();
     $newcm->course = $course->id;
     $newcm->module = $DB->get_field('modules', 'id', array('name' => 'resource'));
     // Not known yet, will be updated later (this is similar to restore code).
     $newcm->instance = 0;
     $newcm->section = $params['section'];
     $newcm->visible = 1;
     $newcm->groupmode = 0;
     $newcm->groupingid = 0;
     $newcm->groupmembersonly = 0;
     if (!($coursemodule = add_course_module($newcm))) {
         throw new invalid_parameter_exception('Error creating course module');
     }
     $config = get_config('resource');
     $module = new stdClass();
     $module->course = $course->id;
     $module->name = format_string($params['name']);
     $module->intro = '<p></p>';
     $module->introformat = 1;
     $module->coursemodule = $coursemodule;
     if (!$display) {
         $module->display = $config->display;
     } else {
         $module->display = $display;
     }
     $module->popupwidth = $config->popupwidth;
     $module->popupheight = $config->popupheight;
     $module->printintro = $config->printintro;
     // 'Show size' support only from Moodle 2.3 / OU moodle April 2012.
     if (isset($config->showsize)) {
         $module->showsize = $config->showsize;
         $module->showtype = $config->showtype;
     }
     $module->filterfiles = $config->filterfiles;
     $module->section = $section->section;
     // Check $params['path'] and create files based on that and attach to $module->files
     // now check $path and obtain $filename and $filepath.
     $contextuser = context_user::instance($USER->id);
     $fs = get_file_storage();
     $module->files = 0;
     file_prepare_draft_area($module->files, null, null, null, null);
     $fileinfo = array('contextid' => $contextuser->id, 'component' => 'user', 'filearea' => 'draft', 'itemid' => $module->files, 'filepath' => '/', 'filename' => basename($params['path']), 'timecreated' => time(), 'timemodified' => time(), 'mimetype' => mimeinfo('type', $path), 'userid' => $USER->id);
     if (strpos($params['path'], '://') === false) {
         // This is a path.
         if (!file_exists($params['path'])) {
             throw new invalid_parameter_exception('Error accessing filepath - file may not exist.');
         }
         $fs->create_file_from_pathname($fileinfo, $params['path']);
     } else {
         // This is a URL - download the file first.
         $content = download_file_content($params['path']);
         if ($content === false) {
             throw new invalid_parameter_exception('Error accessing file - url may not exist.');
         }
         $fs->create_file_from_string($fileinfo, $content);
     }
     $module->instance = resource_add_instance($module, array());
     $DB->set_field('course_modules', 'instance', $module->instance, array('id' => $coursemodule));
     course_add_cm_to_section($module->course, $coursemodule, $section->section);
     rebuild_course_cache($course->id, true);
     return array('id' => $coursemodule);
 }
开发者ID:ninelanterns,项目名称:moodle-mod_subpage,代码行数:76,代码来源:externallib.php

示例14: make_forumng

function make_forumng($courseid, $starttime, $discussions, $posts, $readpercent, $readusers, &$userids, $subscribepercent, $ratingpercent)
{
    global $DB;
    $section = $DB->get_record('course_sections', array('course' => $courseid, 'section' => 0), '*', MUST_EXIST);
    $transaction = $DB->start_delegated_transaction();
    // Create course modules record
    $mod = new stdClass();
    $mod->course = $courseid;
    $mod->module = $DB->get_field('modules', 'id', array('name' => 'forumng'));
    $mod->section = $section->section;
    // was $section->id; logical but incorrect!
    $mod->added = $starttime;
    $mod->visible = 1;
    // course_modules and course_sections each contain a reference
    // to each other, so we have to update one of them twice.
    // Note: This is unbelievable!!! $mod->section MUST BE section number (not id)
    //       Adds course_module with section number, add_mod_to_section uses
    //       section number (& course id) to get section id, which is returned
    //       course module record then updated to replace section number by id!!!
    if (!($mod->coursemodule = add_course_module($mod))) {
        throw new Exception("Could not add a new course module");
    }
    if (!($sectionid = course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section))) {
        throw new Exception("Could not add the new course module to that section");
    }
    // Create forum object
    $forumng = new stdClass();
    static $index = 0;
    $index++;
    $forumng->name = 'Perf test ' . date('Ymd H:j', $starttime) . ' ' . $index;
    $forumng->course = $courseid;
    $forumng->section = $section;
    $forumng->cmidnumber = $mod->coursemodule;
    if (!($forumng->id = forumng_add_instance($forumng))) {
        throw new dml_exception('Failed to add forum');
    }
    // Mark cm object as owning it
    $updatemod = new stdClass();
    $updatemod->id = $mod->coursemodule;
    $updatemod->instance = $forumng->id;
    $updatemod->section = $sectionid;
    $DB->update_record('course_modules', $updatemod);
    // Make it be random users included in the forum
    shuffle($userids);
    // OK, forum is created. Let's make discussions
    $forum = mod_forumng::get_from_id($forumng->id, mod_forumng::CLONE_DIRECT);
    $count = my_random($discussions);
    for ($i = 0; $i < $count; $i++) {
        make_discussion($forum, $posts, my_random_percentage($readpercent) ? $readusers : 0, $userids, $ratingpercent);
    }
    // Add subscribe users
    set_time_limit(200);
    for ($i = 0; $i < $readusers; $i++) {
        if (my_random_percentage($subscribepercent)) {
            $forum->subscribe($userids[$i]);
        }
    }
    $transaction->allow_commit();
}
开发者ID:ULCC-QMUL,项目名称:moodle-mod_forumng,代码行数:59,代码来源:makebig.php

示例15: precreate_course_module

 /**
  * Create course module and link it to course
  *
  * Since 2.6 it is recommended to use function add_moduleinfo() to create a module.
  *
  * @deprecated since 2.6
  * @see testing_module_generator::create_instance()
  *
  * @param integer $courseid
  * @param array $options section, visible
  * @return integer $cm instance id
  */
 protected function precreate_course_module($courseid, array $options)
 {
     global $DB, $CFG;
     require_once "{$CFG->dirroot}/course/lib.php";
     $modulename = $this->get_modulename();
     $sectionnum = isset($options['section']) ? $options['section'] : 0;
     unset($options['section']);
     // Prevent confusion, it would be overridden later in course_add_cm_to_section() anyway.
     $cm = new stdClass();
     $cm->course = $courseid;
     $cm->module = $DB->get_field('modules', 'id', array('name' => $modulename));
     $cm->instance = 0;
     $cm->section = 0;
     $cm->idnumber = isset($options['idnumber']) ? $options['idnumber'] : 0;
     $cm->added = time();
     $columns = $DB->get_columns('course_modules');
     foreach ($options as $key => $value) {
         if ($key === 'id' or !isset($columns[$key])) {
             continue;
         }
         if (property_exists($cm, $key)) {
             continue;
         }
         $cm->{$key} = $value;
     }
     $cm->id = $DB->insert_record('course_modules', $cm);
     course_add_cm_to_section($courseid, $cm->id, $sectionnum);
     return $cm->id;
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:41,代码来源:module_generator.php


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