Moodle资源/文件完成

时间:2016-02-11 15:55:25

标签: mysql moodle moodle-api

我需要帮助理解存储Moodle中资源(文件)的完成状态。

有关详细信息,请参阅附件图片。

  1. 用户查看后,文件旁边的标记将标记为已完成 View of resource/file
  2. 这是在此文件/资源​​的完成设置中设置的。
  3. Completion setup

    我需要生成一个显示文件和完成状态的SQL报告。

    我已经有了'#34;困难的部分"对于查询,我只需要从" table-X"中选择完成状态。和哇拉!

    谢谢。

2 个答案:

答案 0 :(得分:1)

好的,我找到了桌子和柱子。

表: mdl_course_modules_completion

专栏:已查看

我将在下面发布我的报告代码,希望这可能有助于下一个人。

注意:我将所有模块类型加入到查询中,并仅过滤where语句中的类型测验,课程和资源。我这样做是因为我只对这3种类型感兴趣。但是我没有删除连接,因为其他人可能需要代码。

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

答案 1 :(得分:1)

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