以编程方式创建Moodle活动 [英] Create Moodle activities programmatically
问题描述
有人知道是否可以通过编程将活动添加到Moodle的课程中吗?
Does anyone know if it’s possible to add an activity programmatically to a course in Moodle?
我正在考虑也许使用自定义插件的lib.php中的类module_add_instance()
...
I was thinking to maybe use the class module_add_instance()
from the lib.php of my custom plugin...
例如
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
变量?它包含什么以及如何构造?
But then again: What is the $mod
variable? What does it contain and how to construct it?
有人对此主题有知识吗?还是有什么建议?
Does anyone has knowledge on the subject? Or something to advise?
推荐答案
add_moduleinfo()
会更好.下面是我用于面对面的东西.
add_moduleinfo()
would be better. Below is something I use for facetoface.
要开始使用,请编辑/course/modedit.php
,然后临时添加以下内容,然后通过前端添加所需的活动-这将为您提供所需的大多数属性的列表:
To get started, edit /course/modedit.php
then temporarily add the following, then add the required activity via the front end - this will give you a list of most of the properties required:
var_dump($fromform);
die();
$fromform = add_moduleinfo($fromform, $course, $mform);
创建面对面实例的代码
$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);
这篇关于以编程方式创建Moodle活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!