【问题标题】:Create Moodle activities programmatically以编程方式创建 Moodle 活动
【发布时间】:2015-09-21 13:17:01
【问题描述】:

有谁知道是否可以以编程方式将活动添加到 Moodle 中的课程中?

我在想也许可以使用自定义插件的 lib.php 中的 module_add_instance() 类...

例如

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 变量是什么?它包含什么以及如何构建它?

有人知道这方面的知识吗?或者有什么建议?

【问题讨论】:

    标签: php moodle


    【解决方案1】:

    add_moduleinfo() 会更好。以下是我用于面对面交流的内容。

    首先,编辑/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);
    

    【讨论】:

    • 太好了,我不知道 add_moduleinfo() 存在。 Moodle 有这么多功能却没有文档!我会尝试报告解决方案。谢谢
    • 我是moodle的新手,我正在努力解决这个问题。我想使用api进行测验,我尝试了很多方法,我已经阅读了所有的moodle文档,但仍然没有解决。请你帮助我好吗。或解释你为这个问题做了什么。谢谢@Christos312
    • 我是moodle的新手,我正在努力解决这个问题。我想使用api进行测验,我尝试了很多方法,我已经阅读了所有的moodle文档,但仍然没有解决。请你帮助我好吗。或解释你为这个问题做了什么。谢谢@Russell England
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-23
    • 2012-07-17
    相关资源
    最近更新 更多