Get files' list of a course

Get files' list of a course

by fares kaya -
Number of replies: 1

I need a querry to find all files of a course

I find here this query:

select filename file, instanceid course, filesize
from mdl_files join mdl_context on mdl_files.contextid = mdl_context.id
where instanceid = XXXX and contextlevel=50 union all
select filename file, course, filesize
from mdl_files inner join mdl_context on mdl_files.contextid = mdl_context.id
join mdl_resource on instanceid = mdl_resource.id
where course=XXXX and contextlevel = 70

XXX=idcourse

but it didn't work.

I don't find the relation between instanceid and idcourse?

i use moodle 2.4

Average of ratings: -
In reply to fares kaya

Re: Get files' list of a course

by Miguel Santos -

Hi Fares,

   This query should get you all the files in a course; including: the course files, files tied to blocks in the course, and files associated with resources in the course.  I have it excluding automated backups, manual backups, user private files, and user draft files.

 

-- gets course union course modules union course blocks
SELECT course.id AS CourseID, course.fullname AS CourseFullName, course.shortname AS CourseShortName, course.filename, course.filesize AS CourseSizeBytes
FROM (

SELECT c.id, c.fullname, c.shortname, cx.contextlevel,f.component, f.filearea, f.filename, f.filesize
FROM mdl_context cx
JOIN mdl_course c ON cx.instanceid=c.id
JOIN mdl_files f ON cx.id=f.contextid
WHERE f.filename <> '.'
AND f.component NOT IN ("private", "automated", "backup","draft")

UNION

SELECT cm.course, c.fullname, c.shortname, cx.contextlevel,f.component, f.filearea, f.filename, f.filesize
FROM mdl_files f
JOIN mdl_context cx ON f.contextid = cx.id
JOIN mdl_course_modules cm ON cx.instanceid=cm.id
JOIN mdl_course c ON cm.course=c.id
WHERE filename <> '.'

UNION

SELECT c.id, c.shortname, c.fullname, cx.contextlevel, f.component, f.filearea, f.filename, f.filesize
from mdl_block_instances bi
join mdl_context cx on (cx.contextlevel=80 and bi.id = cx.instanceid)
join mdl_files f on (cx.id = f.contextid)
join mdl_context pcx on (bi.parentcontextid = pcx.id)
join mdl_course c on (pcx.instanceid = c.id)
where filename <> '.'

) AS course;

Average of ratings: Useful (3)