首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置课程老师的情绪

设置课程老师的情绪
EN

Stack Overflow用户
提问于 2014-10-26 12:49:38
回答 1查看 532关注 0票数 0

我可以用什么功能来设置课程老师?我用它来获得课程学生或教师

代码语言:javascript
复制
$context = get_context_instance(CONTEXT_COURSE, course_id);
$students = get_role_users(5, $context);

但是,需要的是用一个函数来设置课程老师。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-26 12:58:40

在课程中为用户指定教师角色

代码语言:javascript
复制
$coursecontext = context_course::instance($courseid);
$teacherroleid = $DB->get_field('role', 'id', array('shortname' => 'teacher'));
role_assign($teacherroleid, $userid, $coursecontext);

更新:手动注册一个课程的用户-这也会分配一个角色,所以你可能不需要上面的代码?

代码语言:javascript
复制
if (enrol_is_enabled('manual')) {
    // Ensure the manual enrolment plugin is enabled.
    $enrolplugin = enrol_get_plugin('manual');

    // Lookup the manual enrolment instance for this course.
    $instances = enrol_get_instances($this->course->id, true);
    foreach ($instances as $instance) {
        if ($instance->enrol === 'manual') {
            break;
        }
    }
    if ($instance->enrol !== 'manual') {
        throw new coding_exception('No manual enrol plugin in course');
    }

    // Enrol the user with the required role
    $enrolplugin->enrol_user($instance, $userid, $roleid);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26573136

复制
相关文章

相似问题

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