首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何以编程方式将队列添加到课程中?

如何以编程方式将队列添加到课程中?
EN

Stack Overflow用户
提问于 2014-08-15 11:02:41
回答 2查看 3K关注 0票数 1

我想以情绪化的方式在课程中添加addcohort。我已经翻阅了文件,但确实在那里找到了这个。有像chort_add_course() with parameters as course id and chort id这样的函数吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-08-16 19:19:39

我猜你是说在一门课上加入一个队列注册方法?然后,该队列中的用户将自动注册该课程。

代码在/enrol/cohort/ed.php和/enrol/cohort/edit_form.php中,但是这样的代码会自动完成。

代码语言:javascript
运行
复制
require_once($CFG->dirroot . '/enrol/cohort/locallib.php');

function cohort_add_course($courseid, $cohortid) {
    global $DB;

    if (!enrol_is_enabled('cohort')) {
        // Not enabled.
        return false;
    }

    if ($DB->record_exists('enrol', array('courseid' => $courseid, 'enrol' => 'cohort'))) {
        // The course already has a cohort enrol method.
        return false;
    }

    // Get the cohort enrol plugin
    $enrol = enrol_get_plugin('cohort');

    // Get the course record.
    $course = $DB->get_record('course', array('id' => $courseid));

    // Add a cohort instance to the course.
    $instance = array();
    $instance['name'] = 'custom instance name - can be blank';
    $instance['status'] = ENROL_INSTANCE_ENABLED; // Enable it.
    $instance['customint1'] = $cohortid; // Used to store the cohort id.
    $instance['roleid'] = $enrol->get_config('roleid'); // Default role for cohort enrol which is usually student.
    $instance['customint2'] = 0; // Optional group id.
    $enrol->add_instance($course, $instance);

    // Sync the existing cohort members.
    $trace = new null_progress_trace();
    enrol_cohort_sync($trace, $course->id);
    $trace->finished();
}
票数 3
EN

Stack Overflow用户

发布于 2014-08-15 11:22:21

在enrol/cohort/ajax.php中查看并向下滚动到"case‘cohort’:“。没有单一的队列注册功能,但这几行代码应该涵盖您想要的内容。

注意--您还可以使用下面的“注册队列用户”部分--区别是,如果向队列中添加/删除了新用户,则第一个用户将继续更新注册人数;第二个用户将添加当前用户,但将来不会更新。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25325314

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档