Moodle 如何以编程方式将队列添加到课程中?
我想在moodle中以编程方式向课程中添加AddQuestion。我查阅了文件,但确实在那里发现了这一点。是否有类似于Moodle 如何以编程方式将队列添加到课程中?,moodle,Moodle,我想在moodle中以编程方式向课程中添加AddQuestion。我查阅了文件,但确实在那里发现了这一点。是否有类似于chort\u add\u course()的函数,参数为course id和chort id?查看enrol/court/ajax.php并向下滚动到“case'enrolcourt':”。没有一个单一的队列注册函数,但其中的几行代码应该涵盖您想要的内容 注意-您也可以使用下面的“enrolcohortusers”部分-区别在于,如果队列中添加/删除了新用户,第一个将继续更新注
chort\u add\u course()的函数,参数为course id和chort id
?查看enrol/court/ajax.php并向下滚动到“case'enrolcourt':”。没有一个单一的队列注册函数,但其中的几行代码应该涵盖您想要的内容
注意-您也可以使用下面的“enrolcohortusers”部分-区别在于,如果队列中添加/删除了新用户,第一个将继续更新注册,第二个将添加当前用户,但将来不会更新。查看enrol/court/ajax.php并向下滚动到“case‘EnrolCourt’:”。没有一个单一的队列注册函数,但其中的几行代码应该涵盖您想要的内容
注意-您也可以使用下面的“enrolcohortusers”部分-区别在于,如果队列中添加/删除了新用户,第一个将继续更新注册,第二个将添加当前用户,但不会在将来更新。我猜您的意思是在课程中添加队列注册方法?然后,该群组中的用户将自动注册到课程中 代码位于/enrol/court/edit.php和/enrol/court/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();
}
我猜你的意思是在课程中增加一个队列注册方法?然后,该群组中的用户将自动注册到课程中 代码位于/enrol/court/edit.php和/enrol/court/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();
}