我正在尝试在moodle中创建一个可以在外部调用的Web服务。 Web服务在数据库表 mdl_quiz 中创建一个条目。但测验没有出现在前端。
这是我的externallib文件的代码:
global $CFG, $DB;
$params = self::validate_parameters(
self::create_quiz_parameters(),
['quiz' => $quiz]
);
foreach ($params['quiz'] as $quiz) {
$courseid = $quiz['courseid'];
$quizname = $quiz['quizname'];
$intro = $quiz['intro'];
$attempts = $quiz['attempts'];
$timeopen = $quiz['timeopen'];
$timeclose = $quiz['timeclose'];
$quiz = new stdClass();
$quiz->course = $courseid;
$quiz->name = $quizname;
$quiz->timeopen = $timeopen;
$quiz->timeclose = $timeclose;
$quiz->attempts = $attempts;
$quiz->intro = $intro;
$rqa = $DB->insert_record('quiz', $quiz);
if (isset($rqa)) {
$moduleid = $DB->get_field('modules', 'id', ['name' => 'quiz'], MUST_EXIST);
$instanceid = 50;
$sectionid = 1;
$newcm = new stdClass();
$newcm->course = $courseid;
$newcm->module = $moduleid;
$newcm->section = $sectionid;
$newcm->added = time();
$newcm->instance = $instanceid;
$newcm->visible = 1;
$newcm->groupmode = 0;
$newcm->groupingid = 0;
$newcm->groupmembersonly = 0;
$newcm->showdescription = 0;
$cmid = $DB->insert_record('course_modules', $newcm);
}
}
答案 0 :(得分:0)
您应该使用add_moduleinfo()
而不是手动插入记录。这将为您完成大部分工作。