3

我正在尝试编写查询以获取 Moodle 中课程文件的名称和路径,但似乎我永远无法做到。这是我到目前为止所做的,对此的任何帮助都非常感谢:)

SELECT SOURCE file,
              course,
              contenthash path
FROM mdl_files
INNER JOIN mdl_context ON mdl_files.contextid = mdl_context.id
JOIN mdl_resource ON instanceid = mdl_resource.id
WHERE course=
    (SELECT id
     FROM mdl_course
     WHERE fullname="XXXX")
4

2 回答 2

6

在任何这些 Moodle 表中都没有名为“文件”的列。您实际上是指“mdl_files.filename”列吗?

如果是这样,请尝试以下查询:

SELECT
    mdl_files.source,
    mdl_files.filename,
    mdl_files.contenthash,
    mdl_context.path,
    mdl_resource.course,
    mdl_resource.name,
    mdl_course.fullname, 
    mdl_course.shortname
FROM
    mdl_files
INNER JOIN mdl_context ON mdl_files.contextid = mdl_context.id
INNER JOIN mdl_resource ON mdl_context.instanceid = mdl_resource.id
INNER JOIN mdl_course ON mdl_resource.course = mdl_course.id
WHERE (mdl_course.fullname = 'XXXX')

那是你要的吗?

于 2013-04-16T07:36:11.557 回答
4

试试这个....只需将下面的“ 58 ”替换为适当的课程 ID 号

SELECT cm.id, cm.course, cm.module, mdl.name AS type,
       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 mf.name IS NOT NULL THEN CONCAT('/mod/forum/view.php?id=', cm.id)
            WHEN mb.name IS NOT NULL THEN CONCAT('/mod/book/view.php?id=', cm.id)
            WHEN mr.name IS NOT NULL THEN CONCAT('/mod/resource/view.php?id=', cm.id)
            WHEN mu.name IS NOT NULL THEN CONCAT('/mod/url/view.php?id=', cm.id)
            WHEN mq.name IS NOT NULL THEN CONCAT('/mod/quiz/view.php?id=', cm.id)
            WHEN mp.name IS NOT NULL THEN CONCAT('/mod/page/view.php?id=', cm.id)
            WHEN ml.name IS NOT NULL THEN CONCAT('/mod/lesson/view.php?id=', cm.id)
            ELSE NULL
       END AS linkurl, f.id AS fileid, f.filepath, f.filename, CONCAT('/filedir/', SUBSTRING(f.contenthash, 1, 2), '/', SUBSTRING(f.contenthash, 3, 2), '/', f.contenthash) AS filesystempath, f.userid AS fileuserid, f.filesize, f.mimetype, f.author AS fileauthor, f.timecreated, f.timemodified
FROM mdl_course_modules AS cm
INNER JOIN mdl_context AS ctx ON ctx.contextlevel = 70 AND ctx.instanceid = cm.id
INNER 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_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_files AS f ON f.contextid = ctx.id
WHERE cm.course = 58
AND mdl.name = 'resource'
AND ((f.mimetype = 'application/pdf') OR (f.id IS NULL))

注意:最初受到 Darko Miletić 解决方案的启发:https ://moodle.org/mod/forum/discuss.php?d=153059#p1166404

于 2014-10-18T04:30:34.167 回答