我可以用什么功能来设置课程老师?我用它来获得课程学生或教师
$context = get_context_instance(CONTEXT_COURSE, course_id);
$students = get_role_users(5, $context);但是,需要的是用一个函数来设置课程老师。
发布于 2014-10-26 12:58:40
在课程中为用户指定教师角色
$coursecontext = context_course::instance($courseid);
$teacherroleid = $DB->get_field('role', 'id', array('shortname' => 'teacher'));
role_assign($teacherroleid, $userid, $coursecontext);更新:手动注册一个课程的用户-这也会分配一个角色,所以你可能不需要上面的代码?
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);
}https://stackoverflow.com/questions/26573136
复制相似问题