有谁知道是否可以通过编程方式将活动添加到Moodle的课程中?
我在考虑使用自定义插件的lib.php中的类module_add_instance()
...
e.g。
function feedback_add_instance(stdClass $mod) {
global $DB;
$newmodule->timecreated = time();
// You may have to add extra stuff in here.
$newmodule->id = $DB->insert_record('exams', $newmodule);
unicexams_grade_item_update($newmodule);
return $newmodule->id;
}
但话又说回来:$mod
变量是什么?它包含什么以及如何构建它?
有没有人对这个问题有所了解?或建议的事情?
答案 0 :(得分:4)
add_moduleinfo()
会更好。以下是我用于facetoface的内容。
要开始使用,请修改/course/modedit.php
,然后暂时添加以下内容,然后通过前端添加所需的活动 - 这将为您提供所需的大多数属性的列表:
var_dump($fromform);
die();
$fromform = add_moduleinfo($fromform, $course, $mform);
创建facetoface实例的代码
$newfacetoface = new stdClass();
$newfacetoface->name = $facetoface->facetofacename;
$newfacetoface->intro = '';
$newfacetoface->thirdparty = '';
$newfacetoface->display = 6;
$newfacetoface->approvalreqd = 0;
$newfacetoface->selfapprovaltandc = $strmgr->get_string('selfapprovaltandccontents', 'facetoface', $facetoface->langcode);
$newfacetoface->allowcancellationsdefault = 1;
$newfacetoface->cancellationscutoffdefault = 0;
$newfacetoface->multiplesessions = 1; // Allow multiple sessions.
$newfacetoface->managerreserve = '0';
$newfacetoface->maxmanagerreserves = '1';
$newfacetoface->reservecancel = '1';
$newfacetoface->reservecanceldays = '1';
$newfacetoface->reservedays = '2';
$newfacetoface->showoncalendar = '1';
$newfacetoface->usercalentry = '1';
$newfacetoface->shortname = '';
$newfacetoface->published = $facetoface->visible;
$newfacetoface->branches = $facetoface->branches;
$newfacetoface->visible = $facetoface->visible;
$newfacetoface->cmidnumber = $facetoface->facetofaceid;
$newfacetoface->idnumber = $facetoface->facetofaceid;
$newfacetoface->groupmode = '0';
$newfacetoface->availabilityconditionsjson = '{"op":"&","c":[],"showc":[]}';
$newfacetoface->completionunlocked = 1;
$newfacetoface->completionunlockednoreset = 0;
$newfacetoface->completion = COMPLETION_TRACKING_AUTOMATIC;
$newfacetoface->completionstatusrequired = '{"100":1}';
$newfacetoface->completionexpected = 0;
$newfacetoface->course = $course->id;
$newfacetoface->coursemodule = 0;
$newfacetoface->section = 1;
$newfacetoface->module = $moduleid;
$newfacetoface->modulename = 'facetoface';
$newfacetoface->instance = 0;
$newfacetoface->add = 'facetoface';
$newfacetoface->update = 0;
$newfacetoface->return = 0;
$newfacetoface->sr = 0;
$moduleinfo = add_moduleinfo($newfacetoface, $course);