我想以情绪化的方式在课程中添加addcohort。我已经翻阅了文件,但确实在那里找到了这个。有像chort_add_course() with parameters as course id and chort id
这样的函数吗?
发布于 2014-08-16 19:19:39
我猜你是说在一门课上加入一个队列注册方法?然后,该队列中的用户将自动注册该课程。
代码在/enrol/cohort/ed.php和/enrol/cohort/edit_form.php中,但是这样的代码会自动完成。
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();
}
发布于 2014-08-15 11:22:21
在enrol/cohort/ajax.php中查看并向下滚动到"case‘cohort’:“。没有单一的队列注册功能,但这几行代码应该涵盖您想要的内容。
注意--您还可以使用下面的“注册队列用户”部分--区别是,如果向队列中添加/删除了新用户,则第一个用户将继续更新注册人数;第二个用户将添加当前用户,但将来不会更新。
https://stackoverflow.com/questions/25325314
复制相似问题