我需要帮助了解 Moodle 中资源(文件)的完成状态存储在哪里。
请参阅附件图片了解更多信息。
我需要生成一个显示文件和完成状态的 SQL 报告。
我已经有了查询的“难点”,我只需要从“table-X”中选择完成状态,wha-la!
谢谢你。
我需要帮助了解 Moodle 中资源(文件)的完成状态存储在哪里。
请参阅附件图片了解更多信息。
我需要生成一个显示文件和完成状态的 SQL 报告。
我已经有了查询的“难点”,我只需要从“table-X”中选择完成状态,wha-la!
谢谢你。
好的,所以我找到了表格和列。
表:mdl_course_modules_completion
栏目:已查看
我将在下面发布我的报告代码,希望这可能对下一个人有所帮助。
注意:我将所有模块类型加入到查询中,并且仅针对 where 语句中的类型测验、课程和资源进行过滤。我这样做是因为我只对这三种类型感兴趣。但是,我没有删除连接,因为其他人可能需要该代码。
SELECT DISTINCT
u.firstname AS 'Firstname'
,u.lastname AS 'Lastname'
,u.institution AS 'Institution'
,u.department AS 'Department'
,u.city AS 'City/Site'
,cc.name AS 'Course'
,c.fullname AS 'Module'
,CASE
WHEN mf.name IS NOT NULL THEN mf.name
WHEN mb.name IS NOT NULL THEN mb.name
WHEN mr.name IS NOT NULL THEN mr.name
WHEN mu.name IS NOT NULL THEN mu.name
WHEN mq.name IS NOT NULL THEN mq.name
WHEN mp.name IS NOT NULL THEN mp.name
WHEN ml.name IS NOT NULL THEN ml.name
ELSE NULL
END AS activityname
,CASE WHEN mdl.name = 'lesson' THEN CASE WHEN mlg.id IS NOT NULL AND mlg.completed IS NOT NULL THEN 'Complete' ELSE 'Incomplete' END
WHEN mdl.name = 'quiz' THEN CASE WHEN mqg.id IS NOT NULL AND mqg.timemodified IS NOT NULL THEN 'Complete' ELSE 'Incomplete' END
WHEN mdl.name = 'resource' THEN CASE WHEN cmc.viewed = 1 THEN 'Complete' ELSE 'Incomplete' END
END AS Status
FROM
mdl_user u
JOIN mdl_user_enrolments ue ON ue.userid = u.id
JOIN mdl_enrol E on E.id = ue.enrolid
JOIN mdl_course c ON c.id = E.courseid
JOIN mdl_course_categories cc ON c.category = cc.id
JOIN mdl_course_modules cm ON cm.course = c.id
JOIN mdl_course_modules_completion cmc ON cmc.coursemoduleid = cm.id
JOIN mdl_context AS ctx ON ctx.contextlevel = 70 AND ctx.instanceid = cm.id
JOIN mdl_modules AS mdl ON cm.module = mdl.id
LEFT JOIN mdl_forum AS mf ON mdl.name = 'forum' AND cm.instance = mf.id
LEFT JOIN mdl_book AS mb ON mdl.name = 'book' AND cm.instance = mb.id
LEFT JOIN mdl_resource AS mr ON mdl.name = 'resource' AND cm.instance = mr.id
LEFT JOIN mdl_url AS mu ON mdl.name = 'url' AND cm.instance = mu.id
LEFT JOIN mdl_quiz AS mq ON mdl.name = 'quiz' AND cm.instance = mq.id
LEFT JOIN mdl_quiz_grades mqg ON mqg.quiz = mq.id
LEFT JOIN mdl_page AS mp ON mdl.name = 'page' AND cm.instance = mp.id
LEFT JOIN mdl_lesson AS ml ON mdl.name = 'lesson' AND cm.instance = ml.id
LEFT JOIN mdl_lesson_grades mlg ON mlg.lessonid = ml.id
LEFT JOIN mdl_files AS f ON f.contextid = ctx.id
LEFT JOIN mdl_files_reference fr ON fr.id = f.referencefileid
WHERE mdl.name in ('quiz','lesson','resource')
ORDER BY firstname,Lastname,cc.name,c.fullname
SELECT r.id, r.name, r.course, cmc.userid, cmc.completionstate, cmc.viewed
FROM mdl_course_modules_completion cmc
JOIN mdl_course_modules cm ON cm.id = cmc.coursemoduleid
JOIN mdl_modules m ON m.id = cm.module AND m.name = 'resource'
JOIN mdl_resource r ON r.id = cm.instance
完成状态和查看的常量在/lib/completionlib.php
例如:
COMPLETION_INCOMPLETE = 0
COMPLETION_COMPLETE = 1
COMPLETION_COMPLETE_PASS = 2
COMPLETION_COMPLETE_FAIL = 3
COMPLETION_COMPLETE_RPL = 4 // This is used in Totara.
COMPLETION_NOT_VIEWED = 0
COMPLETION_VIEWED = 1