Skip to content

Instantly share code, notes, and snippets.

@mackensen
Last active August 14, 2017 13:49
Show Gist options
  • Save mackensen/aa63cd831e031b635ea1eaaa1d9c6e43 to your computer and use it in GitHub Desktop.
Save mackensen/aa63cd831e031b635ea1eaaa1d9c6e43 to your computer and use it in GitHub Desktop.
All active Moodle courses in a given term
SELECT c.fullname,
c.shortname,
c.idnumber
FROM prefix_course c
WHERE EXISTS
(SELECT cc.id
FROM prefix_course_categories cc
WHERE cc.id=c.category
AND cc.parent=:term
LIMIT 1)
AND (EXISTS
(SELECT id
FROM prefix_logstore_standard_log lsl
WHERE lsl.courseid=c.id
AND (lsl.crud='c'
OR lsl.crud='u')
AND lsl.userid <> 0
AND lsl.userid <> 2
LIMIT 1)
AND NOT EXISTS
(SELECT id
FROM prefix_enrol e
WHERE e.enrol='meta'
AND (e.courseid=c.id
OR e.customint1=c.id)
LIMIT 1)
OR EXISTS
(SELECT id
FROM prefix_enrol e
WHERE e.enrol='meta'
AND e.customint1=c.id
LIMIT 1))
AND NOT EXISTS
(SELECT id
FROM prefix_enrol e
WHERE e.enrol='meta'
AND e.courseid=c.id)
AND c.shortname NOT LIKE 'EXCL%'
AND c.fullname NOT LIKE '%Independent%'
AND c.fullname NOT LIKE '%Thesis%'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment