Count number of distinct learners and teachers enrolled per category (including all
its sub categories)
SELECT COUNT(DISTINCT lra.userid) AS learners, COUNT(DISTINCT tra.userid) AS
teachers
FROM prefix_course AS c #, mdl_course_categories AS cats
LEFT JOIN prefix_context AS ctx ON c.id = ctx.instanceid
JOIN prefix_role_assignments AS lra ON lra.contextid = ctx.id
JOIN prefix_role_assignments AS tra ON tra.contextid = ctx.id
JOIN prefix_course_categories AS cats ON c.category = cats.id
WHERE c.category = cats.id
AND (
cats.path LIKE '%/CATEGORYID/%' #Replace CATEGORYID WITH the category id you
want TO COUNT (eg: 80)
OR cats.path LIKE '%/CATEGORYID'
)
AND lra.roleid=5
AND tra.roleid=3
Detailed ACTIONs for each ROLE (TEACHER, NON-EDITING TEACHER and STUDENT)
SELECT r.name, l.action, COUNT( l.userid ) AS counter
FROM prefix_log AS l
JOIN prefix_context AS context ON context.instanceid = l.course AND
context.contextlevel = 50
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid AND ra.contextid =
context.id
JOIN prefix_role AS r ON ra.roleid = r.id
WHERE ra.roleid IN ( 3, 4, 5 )
GROUP BY roleid, l.action
Student (user) COUNT in each Course
Including (optional) filter by: year (if included in course fullname).
SELECT
user2.id AS ID,
ul.timeaccess,
user2.firstname AS Firstname,
user2.lastname AS Lastname,
user2.email AS Email,
user2.city AS City,
user2.idnumber AS IDNumber,
user2.phone1 AS Phone,
user2.institution AS Institution,
IF (user2.lastaccess = 0,'never',
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),'%Y-%m-%d')) AS dLastAccess
,(SELECT r.name
FROM prefix_user_enrolments AS uenrol
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid
JOIN prefix_role AS r ON e.id = r.id
WHERE uenrol.userid=user2.id AND e.courseid = c.id) AS RoleName
FROM prefix_user_enrolments AS ue
JOIN prefix_enrol AS e ON e.id = ue.enrolid
JOIN prefix_course AS c ON c.id = e.courseid
JOIN prefix_user AS user2 ON user2 .id = ue.userid
LEFT JOIN prefix_user_lastaccess AS ul ON ul.userid = user2.id
WHERE c.id=16 AND ul.timeaccess IS NULL
%%FILTER_SEARCHTEXT:user2.firstname%%
Role assignments on categories
SELECT
concat('<a target="_new" href="%%WWWROOT%%/course/category.php?
id=',cc.id,'">',cc.id,'</a>') AS id,
concat('<a target="_new" href="%%WWWROOT%%/course/category.php?
id=',cc.id,'">',cc.name,'</a>') AS category,
cc.depth, cc.path, r.name AS ROLE,
concat('<a target="_new" href="%%WWWROOT%%/user/view.php?
id=',usr.id,'">',usr.lastname,'</a>') AS name,
usr.firstname, usr.username, usr.email
FROM prefix_course_categories cc
INNER JOIN prefix_context cx ON cc.id = cx.instanceid
AND cx.contextlevel = '40'
INNER JOIN prefix_role_assignments ra ON cx.id = ra.contextid
INNER JOIN prefix_role r ON ra.roleid = r.id
INNER JOIN prefix_user usr ON ra.userid = usr.id
ORDER BY cc.depth, cc.path, usr.lastname, usr.firstname, r.name, cc.name
Permissions Overides on Categories
(By: S�verin Terrier )
SELECT
concat('<a target="_new" href="%%WWWROOT%%/course/view.php?
id=',c.id,'">',c.id,'</a>') AS id,
concat('<a target="_new" href="%%WWWROOT%%/course/view.php?
id=',c.id,'">',c.shortname,'</a>') AS 'Course',
concat('<a target="_new" href="%%WWWROOT%%/enrol/instances.php?
id=',c.id,'">M�thodes inscription</a>') AS 'Enrollment plugins',
e.sortorder
FROM prefix_enrol AS e, prefix_course AS c
WHERE e.enrol='guest' AND e.status=0 AND e.password='' AND c.id=e.courseid AND
c.visible=1
Lists "loggedin users" from the last 120 days
SELECT id,username,FROM_UNIXTIME(`lastlogin`) AS days
FROM `prefix_user`
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) < 120
and user count for that same population:
SELECT *
FROM prefix_user AS u
JOIN prefix_user_info_data AS uid ON uid.userid = u.id
JOIN prefix_user_info_field AS uif ON (uid.fieldid = uif.id AND uif.shortname =
'class')
WHERE `deleted` = "1" AND `institution`="your school name" AND `department` = "your
department" AND `data` = "class level and number"
User's courses
change "u.id = 2" with a new user id
An issue with systems that do not have their default language set up properly is
the need to do a mass change for all users to a localization. A common case is
changing default English to American English.
This will show you the language setting for all users:
SELECT username, lang FROM prefix_user
NOTE: UPDATE commands require the ability to alter the database directly via tools
like Adminer or PHPMyAdmin or other db tools.
This code will change the setting from 'en' to 'en_us' for all users:
UPDATE prefix_user SET lang = 'en_us' WHERE country = 'US' AND lang = 'en'
List of users with Authentication
Contributed by: Randy Thornton
This will show you the Authentication setting for all users:
This code will change the setting from 'manual' to 'ldap' for all users except for
the first two accounts which are Guest and Admin. (WARNING: it is bad practice to
change your admin account from manual to an external method as failure of that
external method will lock you out of Moodle as admin.)
UPDATE prefix_user SET auth = 'ldap' WHERE auth = 'manual' AND id > 2
Compare role capability and permissions
SELECT DISTINCT mrc.capability
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability =
mrc.capability
AND rc.roleid = '1' AND rc.contextid = '1') AS Manager
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability =
mrc.capability
AND rc.roleid = '2' AND rc.contextid = '1') AS CourseCreator
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability =
mrc.capability
AND rc.roleid = '3' AND rc.contextid = '1') AS Teacher
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability =
mrc.capability
AND rc.roleid = '4' AND rc.contextid = '1') AS AssistantTeacher
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability =
mrc.capability
AND rc.roleid = '5' AND rc.contextid = '1') AS Student
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability =
mrc.capability
AND rc.roleid = '6' AND rc.contextid = '1') AS Guest
SELECT
l.id,
l.timecreated,
DATE_FORMAT(FROM_UNIXTIME(l.timecreated),'%d-%m-%Y') AS dTime,
@prevtime := (SELECT MAX(timecreated) FROM mdl_logstore_standard_log
WHERE userid = %%USERID%% AND id < l.id ORDER BY id ASC LIMIT 1) AS
prev_time,
IF (l.timecreated - @prevtime < 7200, @delta := @delta + (l.timecreated-
@prevtime),0) AS sumtime,
l.timecreated-@prevtime AS delta,
"User" AS TYPE
FROM prefix_logstore_standard_log AS l,
(SELECT @delta := 0) AS s_init
# CHANGE UserID
WHERE l.userid = %%USERID%% AND l.courseid = %%COURSEID%%
%%FILTER_STARTTIME:l.timecreated:>%% %%FILTER_ENDTIME:l.timecreated:<%%
Low-Participation Student Report
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ
This report returns a list of students who are enrolled in courses filtered by a
short-name text marker (in this case "OL-") in the specified category, but have
very low participation in the course during the specified time period (fewer than 2
"Edits" to Activity Modules, indicating few active contributions to the course).
The number of "Edits" is provided for each student for the time period specified.
An "Edit" is defined as course activity other than viewing content. Click the
"Logs" link to review the student activity. The Logs offer the option to review
"View" activity as well as "Edit" activity.
Only "visible" courses are included in this report. The report may be downloaded as
an Excel spreadsheet.
Don't forget to set up Filters: "Start / End date filter" and "Filter categories"
on the Filters tab in Configurable reports.
FROM prefix_user AS u
JOIN prefix_role_assignments AS ra ON u.id = ra.userid
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
JOIN prefix_course AS c ON c.id = ctx.instanceid
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id AND l.action NOT
LIKE "view%" %%FILTER_STARTTIME:l.TIME:>%% %%FILTER_ENDTIME:l.TIME:<%%
WHERE ra.roleid =5
AND ctx.instanceid = c.id
AND c.visible=1
# This prefix FILTER allows the exclusion OF non-online courses at the original
institution. ALTER this TO fit your institution, OR remove it.
AND c.shortname LIKE '%OL-%'
%%FILTER_CATEGORIES:c.category%%
GROUP BY u.idnumber
SELECT
COUNT(DISTINCT l.userid) AS 'DistinctUserLogins',
DATE_FORMAT(FROM_UNIXTIME(l.timecreated), '%M') AS 'Month'
FROM prefix_logstore_standard_log l
WHERE l.action = 'loggedin' AND YEAR(FROM_UNIXTIME(l.timecreated)) = '2017'
GROUP BY MONTH(FROM_UNIXTIME(l.timecreated))
Total activity per course, per unique user on the last 24h
SELECT
COUNT(DISTINCT userid) AS countUsers
, COUNT(l.courseid) AS countVisits
, CONCAT('<a target="_new" href="%%WWWROOT%%/course/view.php?id=',c.id,'">',
c.fullname, '</a>') AS Course
FROM mdl_logstore_standard_log AS l
JOIN mdl_course AS c ON c.id = l.courseid
WHERE l.courseid > 0
AND FROM_UNIXTIME(l.timecreated) >= DATE_SUB(NOW(), INTERVAL 1 DAY)
AND c.fullname LIKE '%????%'
GROUP BY l.courseid
ORDER BY countVisits DESC
Weekly Instructor Online Participation
Contributed by Elizabeth Dalton, Granite State College
Note: This report can take a long time to run. While it can be run in Configurable
Reports on demand, it may be more appropriate to implement it in the Ad Hoc Queries
plugin as a scheduled report.
Note: This version uses legacy (pre-2.7) logs. See below for post-2.7 Standard Logs
version.
SELECT
c.shortname AS CourseID
, cc.name AS Category
, CONCAT(u.firstname ,' ',u.lastname) AS Instructor
, c.startdate AS Course_Start_Date
, c.visible AS Visible
, COUNT(l.id) AS Edits
, SUM(IF(WEEK(FROM_UNIXTIME(l.time)) - WEEK(FROM_UNIXTIME(c.startdate))<0,1,0)) AS
BeforeTerm
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=0,1,0)) AS
Week1
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=1,1,0)) AS
Week2
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=2,1,0)) AS
Week3
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=3,1,0)) AS
Week4
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=4,1,0)) AS
Week5
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=5,1,0)) AS
Week6
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=6,1,0)) AS
Week7
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=7,1,0)) AS
Week8
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=8,1,0)) AS
Week9
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=9,1,0)) AS
Week10
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=10,1,0)) AS
Week11
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=11,1,0)) AS
Week12
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))>=12,1,0)) AS
AfterTerm
FROM prefix_user AS u
JOIN prefix_role_assignments AS ra ON u.id = ra.userid
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
JOIN prefix_course AS c ON c.id = ctx.instanceid
JOIN prefix_course_categories AS cc ON c.category = cc.id
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id AND l.action NOT
LIKE "view%"
WHERE ra.roleid =3
AND ctx.instanceid = c.id
AND c.shortname LIKE :course
AND u.lastname LIKE :last_name
, FROM_UNIXTIME(c.startdate) AS Course_Start_Date
, c.visible AS Visible
FROM prefix_user AS u
LEFT JOIN prefix_role_assignments AS ra ON u.id = ra.userid
LEFT JOIN prefix_context AS ctx ON ra.contextid = ctx.id
LEFT JOIN prefix_course AS c ON c.id = ctx.instanceid
LEFT JOIN prefix_course_categories AS cc ON c.category = cc.id
Logs: complete log entries for the student in the course, organized by date
Activity Outline: the "Outline Report" from the User Activity Reports, summarizing
the student's activity in the course, organized by course content
Consolidated Activity Report: the "Complete Report" from the User Activity Reports,
detailing the student's activity in the course, organized by course content
(includes text of forum posts)
Note: This should be defined as a "Global" report (visible from within all
courses). At our institution, our terms are 12 weeks long. You would want to insert
additional "SUM" lines for longer terms, or remove lines for shorter terms. We pull
advisor names into student user profiles as part of our configuration. These lines
are present in the code below, but are commented out, as they are very specific to
your Moodle configuration.
Note: This version of the report uses legacy (pre-2.7) logs. See below for a post-
2.7 Standard Logs version.
SELECT
u.lastname AS 'Last Name'
, u.firstname AS 'First Name'
, COUNT(l.id) AS 'Edits'
FROM prefix_user AS u
JOIN prefix_role_assignments AS ra ON u.id = ra.userid
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
JOIN prefix_course AS c ON c.id = ctx.instanceid
JOIN prefix_course_categories AS cc ON c.category = cc.id
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id AND l.action NOT
LIKE "view%"
WHERE ra.roleid =5
AND ctx.instanceid = c.id
GROUP BY u.idnumber
SELECT
u.lastname AS 'Last Name'
, u.firstname AS 'First Name'
, COUNT(l.id) AS 'Edits'
# Our institution stores academic advisor names AND emails IN custom profile FIELDS
#, CONCAT('<a href="mailto:',uce.data,'">',uid.data, '</a>') AS 'Academic Advisor'
FROM prefix_user AS u
JOIN prefix_role_assignments AS ra ON u.id = ra.userid
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
JOIN prefix_course AS c ON c.id = ctx.instanceid
JOIN prefix_course_categories AS cc ON c.category = cc.id
# student academic coach - you can include custom profile FIELD DATA WITH these
methods
# LEFT JOIN prefix_user_info_data AS uid ON u.id = uid.userid AND uid.fieldid = '2'
# student academic coach email
# LEFT JOIN prefix_user_info_data AS uce ON u.id = uce.userid AND uce.fieldid = '6'
WHERE ra.roleid =5
AND ctx.instanceid = c.id
GROUP BY u.idnumber
Displays participation of the current user in the current course by week, including
pre-term and post-term submissions/edits. A submission/edit is defined as a change
to the course, such as a discussion post, the submission of an assignment, or the
completion of a quiz, as well as alterations to course content such as database
entries or new course activities or resources (if permitted).
l.component AS 'activity'
, COUNT(l.id) AS 'Total'
FROM prefix_user AS u
JOIN prefix_role_assignments AS ra ON u.id = ra.userid
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
JOIN prefix_course AS c ON c.id = ctx.instanceid
JOIN prefix_course_categories AS cc ON c.category = cc.id
WHERE 1
AND ctx.instanceid = c.id
GROUP BY l.component
ORDER BY l.component
Faculty/Student Interactions
Contributed by Elizabeth Dalton, Granite State College
Note: This version of the report uses legacy (pre-2.7) logs. See below for the
post-2.7 Standard Logs version.
Note: This should be defined as a "Global" report (visible from within all
courses).
SELECT
# Identify student
CONCAT('<a target="_blank" href="%%WWWROOT%%/message/index.php?id=' , allstu.id ,
'">' , allstu.firstname , ' ' , allstu.lastname , '</a>' ) AS 'Student - click to
send message'
# USING link back TO student posts ON replies, GET UNIQUE student IDs responded
, COUNT(DISTINCT IF(fpsr.created > (UNIX_TIMESTAMP() -
(7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created > (UNIX_TIMESTAMP() -
(7*24*60*60)),fpi.id,NULL) ) AS 'Forum Stu Replies - 7 days'
# ALL replies
, COUNT(DISTINCT IF(fpsr.created > (UNIX_TIMESTAMP() -
(7*24*60*60)),fpsr.id,NULL)) AS 'Forum All Replies - 7 days'
# USING link back TO student posts ON replies, GET UNIQUE student IDs responded
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS 'Forum Stu Replies - to date'
# ALL replies
, COUNT(DISTINCT fpsr.id) AS 'Forum All Replies - to date'
## JOINS
# Now we GET the forums AND forum discussions FROM this course ONLY
LEFT JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%
LEFT JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum =
frm.id
# These are forum discussion posts just BY students WITHIN specified TIME
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion =
fd.id
# Now we will CONNECT TO posts BY instructors that are replies TO student posts
# This IS a LEFT JOIN, because we don't want to eliminate any students from the
list
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid =
instr.id AND fpi.parent = fps.id
# To get identities of only those students who were replied to:
# Connect from instr replies back up to parent posts by students again
# This has to be a LEFT JOIN, we know these posts exist but don't eliminate non-
responded students
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent
# We care about messages that involve BOTH the instructor AND students OF this
course
# messages FROM instructor TO students:
# LEFT JOIN prefix_message AS mts ON mts.useridfrom = instr.id AND mts.useridto =
allstu.id
# LEFT JOIN prefix_message AS mfs ON mfs.useridfrom = instr.id AND mfs.useridto =
allstu.id
WHERE
c.id = %%COURSEID%%
ORDER BY allstu.lastname
Note: Post-2.7 Standard Logs version
SELECT
# Identify student
CONCAT('<a target="_blank" href="%%WWWROOT%%/message/index.php?id=' , allstu.id ,
'">' , allstu.firstname , ' ' , allstu.lastname , '</a>' ) AS 'Student - click to
send message'
# USING link back TO student posts ON replies, GET UNIQUE student IDs responded
, COUNT(DISTINCT IF(fpsr.created > (UNIX_TIMESTAMP() -
(7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created > (UNIX_TIMESTAMP() -
(7*24*60*60)),fpi.id,NULL) ) AS 'Forum Stu Replies - 7 days'
# ALL replies
, COUNT(DISTINCT IF(fpsr.created > (UNIX_TIMESTAMP() -
(7*24*60*60)),fpsr.id,NULL)) AS 'Forum All Replies - 7 days'
# USING link back TO student posts ON replies, GET UNIQUE student IDs responded
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS 'Forum Stu Replies - to date'
# ALL replies
, COUNT(DISTINCT fpsr.id) AS 'Forum All Replies - to date'
## JOINS
# START BY getting ALL the students IN the course
FROM prefix_user AS allstu
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5
JOIN prefix_context AS ctx ON ras.contextid = ctx.id
JOIN prefix_course AS c ON c.id = ctx.instanceid
JOIN prefix_course_categories AS cc ON c.category = cc.id
# Now we GET the forums AND forum discussions FROM this course ONLY
JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%
JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum =
frm.id
# These are forum discussion posts just BY students WITHIN specified TIME
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion =
fd.id
# Now we will CONNECT TO posts BY instructors that are replies TO student posts
# This IS a LEFT JOIN, because we don't want to eliminate any students from the
list
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid =
instr.id AND fpi.parent = fps.id
WHERE
c.id = %%COURSEID%%
ORDER BY allstu.lastname
Student Resource Usage
Contributed by Elizabeth Dalton, Granite State College
Displays usage by students of all activities and resources in the current course by
activity. Only activities and sections which are visible in the course are
included. This version requires the new "Standard Logs" from Moodle 2.7+.
Note: This should be defined as a "Global" report (visible from within all
courses).
SELECT
cs.section AS 'Week'
, cs.name AS 'Section Name'
, m.name AS 'item type'
, CONCAT(
COALESCE(a.name, ''),
COALESCE(b.name,''),
COALESCE(cert.name,''),
COALESCE(chat.name,''),
COALESCE(choice.name,''),
COALESCE(DATA.name,''),
COALESCE(feedback.name,''),
COALESCE(folder.name,''),
COALESCE(forum.name,''),
COALESCE(glossary.name,''),
COALESCE(imscp.name,''),
COALESCE(lesson.name,''),
COALESCE(p.name,''),
COALESCE(questionnaire.name,''),
COALESCE(quiz.name,''),
COALESCE(cr.name,''),
COALESCE(scorm.name,''),
COALESCE(survey.name,''),
COALESCE(url.name,''),
COALESCE(wiki.name,''),
COALESCE(workshop.name,''),
COALESCE(kalvidassign.name,''),
COALESCE(attendance.name,''),
COALESCE(checklist.name,''),
COALESCE(flashcard.name,''),
COALESCE(lti.name,''),
COALESCE(oublog.name,''),
COALESCE(ouwiki.name,''),
COALESCE(subpage.name,''),
COALESCE(journal.name,''),
COALESCE(lightboxgallery.name,''),
COALESCE(elluminate.name,''),
COALESCE(adaptivequiz.name,''),
COALESCE(hotpot.name,''),
COALESCE(wiziq.name,''),
COALESCE(turnitintooltwo.name,''),
COALESCE(kvr.name,'')
) AS 'item name'
WHERE ra.roleid =5
AND ctx.instanceid = c.id
AND cs.visible = 1
AND cm.visible = 1
GROUP BY cm.id
ORDER BY cs.section
Module activity (Hits) between dates
SELECT module, COUNT( * )
FROM prefix_log AS l
WHERE (FROM_UNIXTIME( l.`time` ) BETWEEN '2012-10-01 00:00:00' AND '2013-09-31
00:00:00')
GROUP BY module
Module activity (Instances and Hits) for each academic year
SELECT name
,(SELECT COUNT(*)
FROM mdl_log AS l
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN '2010-10-01 00:00:00' AND '2011-09-31
00:00:00')
AND l.module = m.name AND l.action = 'add'
) AS "Added 2010"
,(SELECT COUNT(*)
FROM mdl_log AS l
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN '2010-10-01 00:00:00' AND '2011-09-31
00:00:00')
AND l.module = m.name
) AS "Used 2010"
,(SELECT COUNT(*)
FROM mdl_log AS l
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN '2011-10-01 00:00:00' AND '2012-09-31
00:00:00')
AND l.module = m.name AND l.action = 'add'
) AS "Added 2011"
,(SELECT COUNT(*)
FROM mdl_log AS l
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN '2011-10-01 00:00:00' AND '2012-09-31
00:00:00')
AND l.module = m.name
) AS "Used 2011"
,(SELECT COUNT(*)
FROM mdl_log AS l
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN '2012-10-01 00:00:00' AND '2013-09-31
00:00:00')
AND l.module = m.name AND l.action = 'add'
) AS "Added 2012"
,(SELECT COUNT(*)
FROM mdl_log AS l
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN '2012-10-01 00:00:00' AND '2013-09-31
00:00:00')
AND l.module = m.name
) AS "Used 2012"
FROM mdl_modules AS m
Unique user sessions per day and month + graph
The "graph" column is used when displaying a graph (which needs at least three
columns to pick from)
Counting user's global and unique hits per day + counting individual usage of
specific activities and resources (on that day),
And since I am using phpMyAdmin's "Display Graph" feature (at the bottom of the
query's output page), I have scaled down the "User Hits" by 10 to fit the graph.
that's it.
FROM `mdl_logstore_standard_log`
WHERE 1=1
AND timecreated > UNIX_TIMESTAMP('2015-03-01 00:00:00') # optional START DATE
AND timecreated <= UNIX_TIMESTAMP('2015-05-31 23:59:00') # optional END DATE
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))
System wide, daily unique user hits for the last 7 days
SELECT
DATE_FORMAT(FROM_UNIXTIME(l.timecreated), '%m%d') 'Day'
,COUNT(DISTINCT l.userid) AS 'Distinct Users Hits'
,COUNT( l.userid) AS 'Users Hits'
FROM mdl_logstore_standard_log AS l
WHERE l.courseid > 1
AND FROM_UNIXTIME(l.timecreated) >= DATE_SUB(NOW(), INTERVAL 7 DAY)
GROUP BY DAY(FROM_UNIXTIME(timecreated))
User detailed activity in course modules
Considering only several modules: url, resource, forum, quiz, questionnaire.
,(SELECT s.name
FROM mdl_course_modules AS cm
JOIN mdl_course_sections AS s ON s.course = cm.course AND s.id = cm.section
WHERE cm.id = l.contextinstanceid) AS "Section name"
FROM mdl_logstore_standard_log AS l
JOIN mdl_user AS u ON u.id = l.userid
JOIN mdl_role_assignments AS ra ON ra.userid = l.userid
AND ra.contextid = (SELECT id FROM mdl_context WHERE instanceid = l.courseid AND
contextlevel = 50)
WHERE l.courseid = %%COURSEID%%
AND l.component IN ('mod_url', 'mod_resource', 'mod_forum', 'mod_quiz',
'mod_questionnaire')
%%FILTER_STARTTIME:l.timecreated:>%% %%FILTER_ENDTIME:l.timecreated:<%%
#,course.shortname
,CASE
WHEN course.fullname LIKE '%2012%' THEN '2012'
WHEN course.fullname LIKE '%2013%' THEN '2013'
WHEN course.fullname LIKE '%2014%' THEN '2014'
WHEN course.fullname LIKE '%2015%' THEN '2015'
END AS YEAR
,CASE
WHEN course.fullname LIKE '%semester a%' THEN 'Spring semester'
WHEN course.fullname LIKE '%semester b%' THEN 'Fall semester'
WHEN course.fullname LIKE '%semester s%' THEN 'Summer semester'
END AS Semester
#,(SELECT COUNT(*)
#FROM mdl_logstore_standard_log AS l
#JOIN mdl_role_assignments AS ra ON ra.userid= l.userid AND ra.roleid = 5 AND
ra.contextid = (SELECT id FROM mdl_context WHERE instanceid = l.courseid AND
contextlevel = 50)
#WHERE l.courseid = course.id ) AS "Student HITs"
#,(SELECT COUNT(*)
#FROM mdl_logstore_standard_log AS l
#JOIN mdl_role_assignments AS ra ON ra.userid= l.userid AND ra.roleid = 3 AND
ra.contextid = (SELECT id FROM mdl_context WHERE instanceid = l.courseid AND
contextlevel = 50)
#WHERE l.courseid = course.id ) AS "Teacher HITs"
,(SELECT COUNT(*)
FROM mdl_log AS l
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND
ra.roleid = 5
WHERE l.course = course.id) AS "Students HITs"
,(SELECT COUNT(*)
FROM mdl_log AS l
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND
ra.roleid = 3
WHERE l.course = course.id) AS "Teachers HITs"
,CASE
WHEN c.fullname LIKE '%???' THEN '???'
WHEN c.fullname LIKE '%????' THEN '????'
WHEN c.fullname LIKE '%????' THEN '????'
END AS YEAR
FROM prefix_log l
INNER JOIN prefix_course c ON l.course = c.id
GROUP BY c.id
#The following line restricts the courses returned TO those HAVING more than 2
modules. Adjust based ON your needs.
HAVING Modules > 2
ORDER BY YEAR DESC, hits DESC
Least active or probably empty courses
Contributed by: Randy Thornton
It is difficult to know sometimes when a course is actually empty or was never
really in use. Other than the simple case where the course was created and never
touched again, in which case the course timecreated and timemodified will be the
same, many courses created as shells for teachers or other users may be used once
or a few times and have few or no test users enrollments in them. This query helps
you see the range of such courses, showing you how many days if any it was used
after initial creation, and how many user are enrolled. It denotes a course never
ever modified by "-1" instead of "0" so you can sort those to the top. By default
it limits this to courses used within 60 days of creation, and to courses with 3 or
less enrollments (for example, teacher and assistant and test student account
only.) You can easily adjust these numbers. The query includes a link to the course
as well.
SELECT
c.fullname,
CONCAT('<a target="_blank" href="%%WWWROOT%
%/course/view.php',CHAR(63),'id=',c.id,'">',c.shortname,'</a>') AS 'CourseLink',
DATE_FORMAT(FROM_UNIXTIME(c.timecreated), '%Y-%m-%d %H:%i') AS 'Timecreated',
DATE_FORMAT(FROM_UNIXTIME(c.timemodified), '%Y-%m-%d %H:%i') AS 'Timemodified',
CASE
WHEN c.timecreated = c.timemodified THEN '-1'
ELSE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated))
END AS 'DateDifference',
COUNT(ue.id) AS Enroled
FROM prefix_course AS c
JOIN prefix_enrol AS en ON en.courseid = c.id
LEFT JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id
WHERE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated) ) < 60
GROUP BY c.id
HAVING COUNT(ue.id) <= 3
ORDER BY c.fullname
Count unique teachers with courses that use at least X module (Moodle19)
You can remove the outer "SELECT COUNT(*) FROM (...) AS ActiveTeachers" SQL query
and get the list of the Teachers and Courses.
SELECT COUNT(*)
FROM (SELECT c.id AS CourseID, c.fullname AS Course, ra.roleid AS RoleID,
CONCAT(u.firstname, ' ', u.lastname) AS Teacher
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = c.id) AS Modules
FROM prefix_course AS c
JOIN prefix_context AS ctx ON c.id = ctx.instanceid AND ctx.contextlevel = 50
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id
JOIN prefix_user AS u ON u.id = ra.userid
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE ra.roleid = 3
GROUP BY u.id
HAVING Modules > 5) AS ActiveTeachers
RESOURCE count for each COURSE
SELECT COUNT(l.id) COUNT, l.course, c.fullname coursename
FROM prefix_resource l INNER JOIN prefix_course c ON l.course = c.id
GROUP BY course
ORDER BY COUNT DESC
Common resource types count for each Category (Moodle19)
Including sub-categories in total count.
SELECT mcc.id AS mccid, CONCAT( LPAD( '', mcc.depth, '.' ) , mcc.name ) AS Category
,(SELECT COUNT( * )
FROM prefix_resource AS r
JOIN prefix_course AS c ON c.id = r.course
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE cc.path LIKE CONCAT( '%', mccid, '%' ) AND r.TYPE = 'file' AND r.reference
LIKE 'http://%'
) AS Links
,(SELECT COUNT( * )
FROM prefix_resource AS r
JOIN prefix_course AS c ON c.id = r.course
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE cc.path LIKE CONCAT( '%', mccid, '%' ) AND r.TYPE = 'file' AND r.reference
NOT LIKE 'http://%'
) AS Files
,(SELECT COUNT( * )
FROM prefix_resource AS r
JOIN prefix_course AS c ON c.id = r.course
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE cc.path LIKE CONCAT( '%', mccid, '%' ) AND r.TYPE = 'directory'
) AS Folders
,(SELECT COUNT( * )
FROM prefix_resource AS r
JOIN prefix_course AS c ON c.id = r.course
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE cc.path LIKE CONCAT( '%', mccid, '%' ) AND r.TYPE = 'html'
) AS Pages
,(SELECT COUNT(*)
FROM stats_log_context_role_course
WHERE roleid = 5 AND module = 'resource' AND category = mcc.id
) AS Hits
(SELECT COUNT(*)
FROM prefix_url AS u
JOIN prefix_course AS c ON c.id = u.course
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE cc.path LIKE CONCAT( '%/', mccid, '%' )
) AS URLs,
(SELECT COUNT(*)
FROM prefix_folder AS f
JOIN prefix_course AS c ON c.id = f.course
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE cc.path LIKE CONCAT( '%/', mccid, '%' )
) AS FOLDERs,
(SELECT COUNT(*)
FROM prefix_page AS p
JOIN prefix_course AS c ON c.id = p.course
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE cc.path LIKE CONCAT( '%/', mccid, '%' )
) AS PAGEs,
(SELECT COUNT(*)
FROM prefix_book AS b
JOIN prefix_course AS c ON c.id = b.course
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE cc.path LIKE CONCAT( '%/', mccid, '%' )
) AS BOOKs,
(SELECT COUNT(*)
FROM prefix_label AS l
JOIN prefix_course AS c ON c.id = l.course
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE cc.path LIKE CONCAT( '%/', mccid, '%' )
) AS LABELs,
(SELECT COUNT(*)
FROM prefix_tab AS t
JOIN prefix_course AS c ON c.id = t.course
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE cc.path LIKE CONCAT( '%/', mccid, '%' )
) AS TABs
, (CASE
WHEN c.fullname LIKE '%????%' THEN '2012'
WHEN c.fullname LIKE '%????%' THEN '2011'
END ) AS YEAR
, (CASE
WHEN c.fullname LIKE '%????? ?%' THEN 'Semester A'
WHEN c.fullname LIKE '%????? ?%' THEN 'Semester B'
WHEN c.fullname LIKE '%????? ?%' THEN 'Semester C'
END ) AS Semester
,COUNT(c.id) AS Total
,(SELECT COUNT(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND
cm.module= 20) AS TABs
,(SELECT COUNT(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND
cm.module= 33) AS BOOKs
FROM `prefix_resource` AS r
JOIN `prefix_course` AS c ON c.id = r.course
#WHERE TYPE= 'file' AND reference NOT LIKE 'http://%'
#WHERE 1=1
#%%FILTER_YEARS:c.fullname%%
#AND c.fullname LIKE '%2013%'
GROUP BY course
ORDER BY COUNT(c.id) DESC
Courses that are defined as using GROUPs
SELECT concat('<a target="_new" href="%%WWWROOT%%/group/index.php?
id=',c.id,'">',c.fullname,'</a>') AS Course
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = c.id) Modules
,(SELECT COUNT(*) FROM prefix_groups g WHERE g.courseid = c.id) Groups
FROM `prefix_course` AS c
WHERE groupmode > 0
Courses with Groups
Contributed by: Randy Thornton
List of all courses with Groups in them (groupmode > 0). You can also use
groupmode=1 to list just Separate type groups or groupmode=2 to list Visible type
groups.
SELECT DISTINCT
user2.firstname AS Firstname,
user2.lastname AS Lastname,
user2.email AS Email,
user2.city AS City,
course.fullname AS Course
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) AS ROLE
,(SELECT name FROM prefix_role WHERE id=en.roleid) AS RoleName
There's a group import function, but no export. Use this to give you a report with
the proper column order and headings to export to a csv file you can then import
into another course to replicate the groups. This is a simple version with just the
main fields: groupname, description, enrolment key.
$s should be the id of the top level category you are interested in.
<?php
require_once('./config.php');
$parent_id = $s;
$categories= array();
$categories = get_categories($parent_id);
echo '<ol>';
foreach ($categories as $category)
{
echo '<li><a href="'.$CFG->wwwroot.'/course/category.php?id='.$category-
>id.'">'.$category->name.'</a></li>';
}
echo '</ol>';
?>
Blog activity per Course (not including VIEW)
Filter activity logging to some specific Course Categories! + link course name to
actual course (for quick reference) (you can change %blog% to %wiki% to filter down
all wiki activity or any other module you wish)
FROM prefix_oublog_posts AS op
JOIN prefix_oublog_instances AS oi ON oi.id = op.oubloginstancesid
JOIN prefix_oublog AS b ON b.id = oi.oublogid
JOIN prefix_course AS c ON b.course = c.id
SELECT
concat('<a target="_new" href="%%WWWROOT%%/course/view.php?
id=',c.id,'">',c.fullname,'</a>') AS Course
,c.shortname,r.name
,(SELECT CONCAT(u.firstname,' ', u.lastname) AS Teacher
FROM prefix_role_assignments AS ra
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
JOIN prefix_user AS u ON u.id = ra.userid
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher
FROM prefix_resource AS r
JOIN prefix_course AS c ON r.course = c.id
WHERE ( r.name LIKE '%??????%' OR r.name LIKE '%???????%' OR r.name LIKE '%syllabus
%' OR r.name LIKE '%????? ?????%' )
AND c.category IN (10,18,26,13,28)
Site-wide completed SCORM activities by Course name
This report will list all completed attempts for all SCORM activities. It is
ordered first by Course name, then student's last name, then student's first name,
then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.
SELECT
USER.firstname AS Firstname,
USER.lastname AS Lastname,
USER.idnumber Employee_ID,
course.fullname AS Course
FROM mdl_files AS f
JOIN mdl_context AS context ON context.id = f.contextid
JOIN mdl_course AS c ON c.id = (
SELECT instanceid
FROM mdl_context
WHERE id = SUBSTRING_INDEX( SUBSTRING_INDEX( context.path, '/' , -2 ) , '/',
1 ) )
WHERE filesize >0
GROUP BY c.id
With this report, you will have to define "alias" report property to "coursefiles"
for it to be able to be called from the above report. And also setup (add) a
FILTER_COURSES filter.
SELECT
id ,CONCAT('<a target="_new" href="%%WWWROOT%%/pluginfile.php/', contextid, '/',
component, '/', filearea, '/', itemid, '/', filename, '">', filename,'</a>') AS
"File"
,filesize, mimetype ,author, license, timecreated, component, filearea, filepath
FROM mdl_files AS f
WHERE filesize >0
AND f.contextid
IN ( SELECT id
FROM mdl_context
WHERE path
LIKE ( SELECT CONCAT('%/',id,'/%')
AS contextquery
FROM mdl_context
WHERE 1=1
%%FILTER_COURSES:instanceid%%
AND contextlevel = 50
)
)
Which courses has redundant topics
This report list several "active topics" calculations, per course. which should
give an administrator some indications for which topics/sections/weeks are filled
with resources and activities and which ones are empty and not used (usually, at
the end of the course).
The following, second SQL query, could be used to "trim" down those redundant
course topics/sections/weeks by updating the course format's numsection (Number of
sections) setting. (It's a per course format setting!)
FROM mdl_course AS c
The following SQL REPLACE query is used for "fixing" (updating) the "numsections"
of a specific course format "onetopics" (you can always change it, or discard it to
use this SQL REPLACE on all course formats)
This query identifies courses with student enrollment that are currently hidden
from students. Includes the defined course start date, count of students and
instructors, and a clickable email link of instructor (first found record if more
than one).
now() AS Report_Timestamp
FROM prefix_course AS c
WHERE c.visible = 0 AND (SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS
ra JOIN prefix_context AS ctx ON ra.contextid = ctx.id WHERE ra.roleid = 5 AND
ctx.instanceid = c.id) > 0
ORDER BY StartDate, Instructor_Email, Course_ID
Course Content/Week
Contributed by Elizabeth Dalton, Granite State College
This report assumes that the first 14 sections in a course, not including the "0"
or "Welcome" section, correspond to weeks (with "Subsections" given numbers much
higher in the sequence). Of those sections, each is checked to count the number of:
Forums
Graded Activities (may include Forums)
Resources (not including a Label)
Totals of each of these types of content elements per section are provided.
Note: Only visible resources and activities are counted. Note: this is a "Global"
report.
SELECT
cs.section AS 'Week'
, cs.name AS 'Section Name'
FROM prefix_course AS c
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section <= 14 AND
cs.section > 0
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id
JOIN prefix_modules AS m ON m.id = cm.module
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name
AND gi.iteminstance = cm.instance
WHERE
cs.visible = 1
AND cm.visible = 1
AND c.id = %%COURSEID%%
GROUP BY cs.section
ORDER BY cs.section
Assignments and Weights
Contributed by Elizabeth Dalton, Granite State College
Returns a list of grade book categories for the current course, grade book
weightings, the first type of assignment included in the category, a count of
different assignment types for each category, and a count of assignments for each
category.
SELECT
FROM prefix_course AS c
WHERE
cm.visible = 1
AND c.id = %%COURSEID%%
GROUP BY gc.id
ORDER BY gc.id
Pre-Term Course Review
Contributed by Elizabeth Dalton, Granite State College
Provides an overview of the readiness of ONLINE, HYBRID, and BLENDED courses in the
Staging category and all subcategories. Links to each course are provided. Other
details:
#, IF(SUM(IF(bi.configdata LIKE
'Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%',1,0))
AND (bip.visible !=0),'YES','') AS 'Instructor Details Block visible' # This IS a
hack based ON UUencoded string DATA FROM the title OF HTML "Instructor Details"
block
# Here are SOME other things you could CHECK FOR per course
#,(SELECT COUNT( m.name ) AS COUNT FROM prefix_course_modules AS cm JOIN
prefix_modules AS m ON cm.module = m.id WHERE cm.course = c.id AND m.name LIKE
'%forum%') AS Forums
,(SELECT FROM_UNIXTIME(MAX(prefix_resource.timemodified))
FROM prefix_resource
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id =
prefix_resource.course AND prefix_resource.name LIKE '%syllabus%') AS SyllabusDate
,(SELECT TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(MAX(prefix_resource.timemodified)))
FROM prefix_resource
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id =
prefix_resource.course AND prefix_resource.name LIKE '%syllabus%') AS DaysAgo
FROM prefix_course AS c
LEFT JOIN prefix_course_categories AS cc ON c.category = cc.id
LEFT JOIN prefix_context AS ctxx ON c.id = ctxx.instanceid
GROUP BY c.shortname
Module instances + Module HITs by role teacher and student in course
SELECT
m.name AS "Module name"
, COUNT(*) AS "Module count"
,(SELECT COUNT(*)
FROM prefix_log AS l
WHERE l.course = cm.course AND l.module = m.name ) AS "Hits"
,(SELECT COUNT(*)
FROM prefix_log AS l
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid
AND ra.roleid = 5
WHERE l.course = cm.course AND l.module = m.name) AS "Students HITs"
,(SELECT COUNT(*)
FROM prefix_log AS l
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid
AND ra.roleid = 3
WHERE l.course = cm.course AND l.module = m.name) AS "Teachers HITs"
FROM mdl_course_modules AS cm
JOIN mdl_modules AS m ON m.id = cm.module
WHERE cm.course = '%%COURSEID%%'
GROUP BY cm.module
Course Syllabus
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ
This report requires ELIS. It runs from within a course and constructs a course
syllabus based on content in the course and in the ELIS entries related to the
course (Class Instance, Course Description, and Program). It is a proof-of-concept
of an automated syllabus production tool. Fields such as "Course Policies" and
"Teaching Philosophy" are added to the Class Instance records, and instructors
enter them there. The Instructor Bio is pulled from the User Profile of all users
with the Teacher role in the course.
SELECT
c.fullname AS 'fullname'
, ec.idnumber AS 'elis-id'
, DATE_FORMAT(FROM_UNIXTIME(ec.startdate), '%b %e, %Y') AS 'start'
, DATE_FORMAT(FROM_UNIXTIME(ec.enddate), '%b %e, %Y') AS 'end'
, ecd.name AS 'longname'
, ecd.code AS 'coursecode'
, ecd.credits AS 'coursecredits'
, ecd.syllabus AS 'description'
, (SELECT eft.data
FROM prefix_local_eliscore_fld_data_text AS eft
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname =
'learning-outcomes'
WHERE ctxecd.id = eft.contextid) AS 'outcomes'
, (SELECT efc.data
FROM prefix_local_eliscore_fld_data_char AS efc
JOIN prefix_local_eliscore_field AS ef ON ef.id = efc.fieldid AND ef.shortname =
'term-code'
WHERE ctxci.id = efc.contextid) AS 'termcode'
, (SELECT eft.data
FROM prefix_local_eliscore_fld_data_text AS eft
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname =
'prerequisites'
WHERE ctxecd.id = eft.contextid) AS 'prerequisites'
, (SELECT eft.data
FROM prefix_local_eliscore_fld_data_text AS eft
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname =
'textbooks'
WHERE ctxci.id = eft.contextid) AS 'textbooks'
, (SELECT eft.data
FROM prefix_local_eliscore_fld_data_text AS eft
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname =
'other-class-materials'
WHERE ctxci.id = eft.contextid) AS 'other-class-materials'
, (SELECT eft.data
FROM prefix_local_eliscore_fld_data_text AS eft
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname =
'course-policies'
WHERE ctxci.id = eft.contextid) AS 'course-policies'
, (SELECT eft.data
FROM prefix_local_eliscore_fld_data_text AS eft
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname =
'teaching-philosophy'
WHERE ctxci.id = eft.contextid) AS 'teaching-philosophy'
, (SELECT eft.data
FROM prefix_local_eliscore_fld_data_text AS eft
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname =
'course-methods'
WHERE ctxci.id = eft.contextid) AS 'course-methods'
,(SELECT u2.description
FROM prefix_role_assignments AS ra
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
JOIN prefix_user AS u2 ON u2.id = ra.userid
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS 'Bio'
,(SELECT
GROUP_CONCAT(DISTINCT CONCAT(
) SEPARATOR '</td></tr>')
#get grade categories
FROM prefix_grade_categories AS gc
# back FROM categories TO grade items TO GET aggregations AND weights
LEFT JOIN prefix_grade_items AS gic ON gic.courseid = gc.courseid AND gic.itemtype
= 'category' AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR
(gc.parent IS NULL))
# attach grade items TO activities
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = gc.courseid AND gi.itemtype =
'mod' AND gi.categoryid = gc.id AND gi.hidden != 1
# attach manual grade items TO course-- they don't have modules
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = gc.courseid AND mgi.itemtype
= 'manual' AND mgi.categoryid = gc.id
WHERE gc.courseid = c.id ) AS 'grade categories'
, (SELECT eft.data
FROM prefix_local_eliscore_fld_data_text AS eft
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname =
'activities-schedule'
WHERE ctxci.id = eft.contextid) AS 'activities'
, (SELECT eft.data
FROM prefix_local_eliscore_fld_data_text AS eft
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname =
'schedule'
WHERE ctxci.id = eft.contextid) AS 'schedule'
, (SELECT eft.data
FROM prefix_local_eliscore_fld_data_text AS eft
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname =
'grading-scale'
WHERE ctxepm.id = eft.contextid) AS 'gradescale'
FROM
prefix_course AS c
WHERE
c.id = %%COURSEID%%
Grade and Course Completion Reports
Site-Wide Grade Report with All Items
Shows grades for all course items along with course totals for each student. Works
with ad-hoc reports or Configurable Reports
CASE
WHEN gi.itemtype = 'course'
THEN c.fullname + ' Course Total'
ELSE gi.itemname
END AS 'Item Name',
ROUND(gg.finalgrade,2) AS Grade,
DATEADD(ss,gi.timemodified,'1970-01-01') AS TIME
FROM prefix_course AS c
JOIN prefix_context AS ctx ON c.id = ctx.instanceid
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id
JOIN prefix_user AS u ON u.id = ra.userid
JOIN prefix_grade_grades AS gg ON gg.userid = u.id
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE gi.courseid = c.id
ORDER BY lastname
For MySQL users, you'll need to use the MySQL DATE_ADD function instead of DATEADD.
Replace the line
DATEADD(ss,gi.timemodified,'1970-01-01') AS Time
with
ROUND(gg.finalgrade,2) AS Grade,
DATEADD(ss,gg.timemodified,'1970-01-01') AS TIME
FROM prefix_course AS c
JOIN prefix_context AS ctx ON c.id = ctx.instanceid
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id
JOIN prefix_user AS u ON u.id = ra.userid
JOIN prefix_grade_grades AS gg ON gg.userid = u.id
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid
JOIN prefix_course_categories AS cc ON cc.id = c.category
ORDER BY lastname
For MySQL users:
ROUND(gg.finalgrade,2) AS Grade,
FROM_UNIXTIME(gg.timemodified) AS TIME
FROM prefix_course AS c
JOIN prefix_context AS ctx ON c.id = ctx.instanceid
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id
JOIN prefix_user AS u ON u.id = ra.userid
JOIN prefix_grade_grades AS gg ON gg.userid = u.id
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE gi.courseid = c.id
ORDER BY lastname
Learner report by Learner with grades
Which Learners in which course and what are the grades
FROM prefix_course AS c
JOIN prefix_context AS ctx ON c.id = ctx.instanceid
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id
JOIN prefix_user AS u ON u.id = ra.userid
JOIN prefix_grade_grades AS gg ON gg.userid = u.id
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE gi.courseid = c.id AND gi.itemname != 'Attendance'
ORDER BY `Name` ASC
User Course Completion
Contributed by: Randy Thornton
SELECT
u.username,
c.shortname,
DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),'%Y-%m-%d') AS completed
FROM prefix_course_completions AS p
JOIN prefix_course AS c ON p.course = c.id
JOIN prefix_user AS u ON p.userid = u.id
WHERE c.enablecompletion = 1
ORDER BY u.username
User Course Completion with Criteria
Contributed by: Randy Thornton
List of all courses with completion enabled and their Aggregation setting, Criteria
types, and Criteria details.
FROM prefix_grade_items AS gi
JOIN prefix_course AS c ON c.id = gi.courseid
JOIN prefix_course_modules AS cm ON cm.course = gi.courseid AND cm.instance =
gi.iteminstance
JOIN prefix_scale AS scale ON scale.id = gi.scaleid
WHERE gi.scaleid IS NOT NULL
This query identifies grade items in visible courses with student enrollment that
have "extra credit" in the name of the item but set as extra credit in the grade
settings. Includes the defined course start date, count of students and
instructors, and a clickable email link of instructor (first found record if more
than one).
,now() AS Report_Timestamp
FROM prefix_grade_items AS gi
JOIN prefix_course AS c ON gi.courseid = c.id
%%FILTER_SEARCHTEXT:Course_ID:~%%
Site Wide Number of Courses Completed by User
Contributed by Ken St. John
Simple report that shows the number of completed courses for all users site wide
This report shows the users completion status of activities across all courses. It
is intended to be uses with Configurable Reports filters for user, start and end
times, and also to be able to search the Module names.
Note: The CASE statement with module numbers may differ on different systems,
depending on the number give to the module when the site was created or the module
added to the site. These are common default numbers, but you should check your id
numbers for them in the course_modules table and adjust as required. You can also
add other, third-party plugins too if you wish.
SELECT
u.username AS 'User',
c.shortname AS 'Course',
m.name AS Activitytype,
CASE
WHEN cm.module = 1 THEN (SELECT a1.name FROM prefix_assign a1 WHERE
a1.id = cm.instance)
WHEN cm.module = 2 THEN (SELECT a2.name FROM prefix_assignment a2 WHERE
a2.id = cm.instance)
WHEN cm.module = 3 THEN (SELECT a3.name FROM prefix_book a3 WHERE
a3.id = cm.instance)
WHEN cm.module = 4 THEN (SELECT a4.name FROM prefix_chat a4
WHERE a4.id = cm.instance)
WHEN cm.module = 5 THEN (SELECT a5.name FROM prefix_choice a5 WHERE
a5.id = cm.instance)
WHEN cm.module = 6 THEN (SELECT a6.name FROM prefix_data a6
WHERE a6.id = cm.instance)
WHEN cm.module = 7 THEN (SELECT a7.name FROM prefix_feedback a7 WHERE
a7.id = cm.instance)
WHEN cm.module = 8 THEN (SELECT a8.name FROM prefix_folder a8
WHERE a8.id = cm.instance)
WHEN cm.module = 9 THEN (SELECT a9.name FROM prefix_forum a9 WHERE
a9.id = cm.instance)
WHEN cm.module = 10 THEN (SELECT a10.name FROM prefix_glossary a10
WHERE a10.id = cm.instance)
WHEN cm.module = 11 THEN (SELECT a11.name FROM prefix_imscp a11
WHERE a11.id = cm.instance)
WHEN cm.module = 12 THEN (SELECT a12.name FROM prefix_label a12
WHERE a12.id = cm.instance)
WHEN cm.module = 13 THEN (SELECT a13.name FROM prefix_lesson a13
WHERE a13.id = cm.instance)
WHEN cm.module = 14 THEN (SELECT a14.name FROM prefix_lti a14
WHERE a14.id = cm.instance)
WHEN cm.module = 15 THEN (SELECT a15.name FROM prefix_page a15
WHERE a15.id = cm.instance)
WHEN cm.module = 16 THEN (SELECT a16.name FROM prefix_quiz a16
WHERE a16.id = cm.instance)
WHEN cm.module = 17 THEN (SELECT a17.name FROM prefix_resource a17
WHERE a17.id = cm.instance)
WHEN cm.module = 18 THEN (SELECT a18.name FROM prefix_scorm a18
WHERE a18.id = cm.instance)
WHEN cm.module = 19 THEN (SELECT a19.name FROM prefix_survey a19
WHERE a19.id = cm.instance)
WHEN cm.module = 20 THEN (SELECT a20.name FROM prefix_url a20
WHERE a20.id = cm.instance)
WHEN cm.module = 21 THEN (SELECT a21.name FROM prefix_wiki a21
WHERE a21.id = cm.instance)
WHEN cm.module = 22 THEN (SELECT a22.name FROM prefix_workshop a22
WHERE a22.id = cm.instance)
END AS Actvityname,
# cm.section AS Coursesection,
CASE
WHEN cm.completion = 0 THEN '0 None'
WHEN cm.completion = 1 THEN '1 Self'
WHEN cm.completion = 2 THEN '2 Auto'
END AS Activtycompletiontype,
CASE
WHEN cmc.completionstate = 0 THEN 'In Progress'
WHEN cmc.completionstate = 1 THEN 'Completed'
WHEN cmc.completionstate = 2 THEN 'Completed with Pass'
WHEN cmc.completionstate = 3 THEN 'Completed with Fail'
ELSE 'Unknown'
END AS 'Progress',
DATE_FORMAT(FROM_UNIXTIME(cmc.timemodified), '%Y-%m-%d %H:%i') AS 'When'
FROM prefix_course_modules_completion cmc
JOIN prefix_user u ON cmc.userid = u.id
JOIN prefix_course_modules cm ON cmc.coursemoduleid = cm.id
JOIN prefix_course c ON cm.course = c.id
JOIN prefix_modules m ON cm.module = m.id
# skip the predefined admin AND guest USER
WHERE u.id > 2
# config reports filters
%%FILTER_USERS:u.username%%
%%FILTER_SEARCHTEXT:m.name:~%%
%%FILTER_STARTTIME:cmc.timemodified:>%% %%FILTER_ENDTIME:cmc.timemodified:<%%
ORDER BY u.username
How many SCORM activities are used in each Course
SELECT cm.course,c.fullname ,m.name
,concat('<a target="_new" href="%%WWWROOT%%/mod/scorm/index.php?
id=',c.id,'">',COUNT(cm.id),'</a>') AS Counter
FROM `prefix_course_modules` AS cm
JOIN prefix_modules AS m ON cm.module=m.id
JOIN prefix_course AS c ON cm.course = c.id
WHERE m.name LIKE '%scorm%'
GROUP BY cm.course,cm.module
ORDER BY COUNT(cm.id) DESC
SCORM Usage by Course Start Date
Contributed by Elizabeth Dalton, Granite State College
SELECT
, cc.name AS 'Category'
, scm.name AS 'Sample Activity Name'
, FROM_UNIXTIME(c.startdate) AS 'Course Start Date'
, COUNT(DISTINCT cm.id) AS 'Resources Used'
#, FROM_UNIXTIME(cm.added) AS 'resource added'
FROM prefix_course_modules AS cm
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE 'SCO%'
WHERE
1
%%FILTER_STARTTIME:c.startdate:>%%
%%FILTER_ENDTIME:c.startdate:<%%
, cc.name AS 'Category'
, lti.name AS 'Sample Activity Name'
, FROM_UNIXTIME(c.startdate) AS 'Course Start Date'
, COUNT(DISTINCT cm.id) AS 'Resources Used'
#, FROM_UNIXTIME(cm.added) AS 'resource added'
FROM prefix_course_modules AS cm
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE 'lti'
%%FILTER_STARTTIME:c.startdate:>%%
%%FILTER_ENDTIME:c.startdate:<%%
FROM prefix_course AS c
WHERE c.category IN ( 18)
ORDER BY Wikis DESC,Blogs DESC, Forums DESC
Course wiki usage/activity over the last 6 semesters
SELECT "Courses with Wikis"
,(SELECT COUNT(*) FROM prefix_log AS l WHERE l.course = c.id AND l.module LIKE
'%wiki%') AS 'WikiActivity<br/>ALL'
,(SELECT COUNT(*) FROM prefix_log AS l WHERE l.course = c.id AND l.module LIKE
'%wiki%' AND l.action LIKE '%add%' ) AS 'WikiActivity<br/>ADD'
,(SELECT COUNT(*) FROM prefix_log AS l WHERE l.course = c.id AND l.module LIKE
'%wiki%' AND l.action LIKE '%edit%' ) AS 'WikiActivity<br/>EDIT'
,(SELECT COUNT(*) FROM prefix_log AS l WHERE l.course = c.id AND l.module LIKE
'%wiki%' AND l.action LIKE '%annotate%' ) AS 'WikiActivity<br/>ANNOTATE'
,(SELECT COUNT(*) FROM prefix_log AS l WHERE l.course = c.id AND l.module LIKE
'%wiki%' AND l.action LIKE '%comments%' ) AS 'WikiActivity<br/>Comments'
FROM prefix_course AS c
WHERE c.category IN ( 8,13,15)
HAVING Wikis > 0
ORDER BY 'WikiActivity<br/>ALL' DESC
Aggregated Teacher activity by "WEB2" Modules
(Tested and works fine in Moodle 2.x) The NV column shows activity without VIEW log
activity
SELECT
DATE_FORMAT( FROM_UNIXTIME(prefix_certificate_issues.timecreated), '%Y-%m-%d' ) AS
DATE,
prefix_certificate_issues.classname AS Topic,
prefix_certificate.name AS Certificate,
prefix_certificate_issues.studentname AS Name,
prefix_user_info_data.data AS Units
FROM
prefix_certificate_issues
Basic report of all certificates earned with the Simple Certificate plugin module
in the whole site, sorted by most recent first. (Note: this uses the MySQL
DATE_FORMAT function.)
SELECT
CONCAT (u.firstname, ' ',u.lastname) AS 'User',
c.fullname AS 'Course',
sc.name AS 'Certificate',
DATE_FORMAT( FROM_UNIXTIME(sci.timecreated), '%Y-%m-%d' ) AS 'Date Awarded'
# sci.code 'CertificateId'
FROM prefix_simplecertificate_issues sci
JOIN prefix_user u ON sci.userid = u.id
JOIN prefix_simplecertificate sc ON sci.certificateid = sc.id
JOIN prefix_course AS c ON sc.course = c.id
ORDER BY sci.timecreated DESC
If you want to limit this to the most recent ones, you can add a condition to limit
it to a certain number of days past. For example, adding this WHERE clause (above
the ORDER BY) will show only those earned in the last 30 days:
FROM prefix_elluminate_recordings AS er
JOIN prefix_elluminate AS e ON e.meetingid = er.meetingid
JOIN prefix_course AS c ON c.id = e.course
JOIN prefix_user AS u ON u.id = e.creator
ORDER BY er.recordingsize DESC
Choice
Contributed by: Randy Thornton
Results of the Choice activity. For all courses, shows course shortname, username,
the Choice text, and the answer chosen by the user.
,(SELECT COUNT(*)
FROM prefix_assign_plugin_config AS apc
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment
WHERE iassign.course = c.id AND apc.plugin = 'file' AND apc.subtype =
'assignsubmission' AND apc.name = 'enabled' AND apc.value = '1'
#GROUP BY apc.plugin
) AS "File Assignments"
,(SELECT COUNT(*)
FROM prefix_assign_plugin_config AS apc
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment
WHERE iassign.course = c.id AND apc.plugin = 'onlinetext' AND apc.subtype =
'assignsubmission' AND apc.name = 'enabled' AND apc.value = '1'
) AS "Online Assignments"
,(SELECT COUNT(*)
FROM prefix_assign_plugin_config AS apc
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment
WHERE iassign.course = c.id AND apc.plugin = 'pdf' AND apc.subtype =
'assignsubmission' AND apc.name = 'enabled' AND apc.value = '1'
) AS "PDF Assignments"
,(SELECT COUNT(*)
FROM prefix_assign_plugin_config AS apc
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment
WHERE iassign.course = c.id AND apc.plugin = 'offline' AND apc.subtype =
'assignsubmission' AND apc.name = 'enabled' AND apc.value = '1'
) AS "Offline Assignments"
,(SELECT COUNT(*)
FROM prefix_assign_plugin_config AS apc
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment
WHERE iassign.course = c.id AND apc.plugin = 'comments' AND apc.subtype =
'assignsubmission' AND apc.name = 'enabled' AND apc.value = '1'
) AS "Assignments Comments"
SELECT
u.firstname AS "First",
u.lastname AS "Last",
c.fullname AS "Course",
a.name AS "Assignment"
Returns all the submitted assignments that still need grading, along with a link
that goes directly to the submission to grade it. The links work if you view the
report within Moodle.
SELECT
u.firstname AS "First",
u.lastname AS "Last",
c.fullname AS "Course",
a.name AS "Assignment",
This report requires a YEAR filter to be added (Available when using the latest
block/configurable_reports)
Which you can always remove, to make this query work on earlier versions.
number of quizzes
unFinished Quiz attempts
Finished Quiz attempts
number of students
number of Assignments
number of submitted answers by students
number of unchecked assignments (waiting for the Teacher) in a Course.
SELECT concat('<a target="_new" href="%%WWWROOT%%/course/view.php?
id=',c.id,'">',c.fullname,'</a>') AS Course
,(SELECT COUNT(*)
FROM prefix_course_modules cm
JOIN prefix_modules AS m ON m.id = cm.module
WHERE m.name LIKE 'quiz' AND cm.course = c.id
GROUP BY cm.course
) AS 'nQuizzes'
,(SELECT COUNT(*)
FROM prefix_quiz_attempts AS qa
JOIN prefix_quiz AS q ON q.id = qa.quiz
WHERE q.course = c.id
AND qa.timefinish = 0
GROUP BY q.course) AS 'unFinished Quiz attempts'
,(SELECT COUNT(*)
FROM prefix_quiz_attempts AS qa
JOIN prefix_quiz AS q ON q.id = qa.quiz
WHERE q.course = c.id
AND qa.timefinish > 0
GROUP BY q.course) AS 'finished quiz attempts'
,(
SELECT COUNT(a.id)
FROM prefix_assignment AS a
JOIN prefix_course_modules AS cm ON a.course = cm.course
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id
) nAssignments
,(
SELECT COUNT(*)
FROM prefix_assignment AS a
WHERE a.course = c.id AND FROM_UNIXTIME(a.timedue) > NOW()
GROUP BY a.course
) 'Open <br/>Assignments'
,(
SELECT COUNT(asb.id)
FROM prefix_assignment_submissions AS asb
JOIN prefix_assignment AS a ON a.id = asb.assignment
JOIN prefix_course_modules AS cm ON a.course = cm.course
WHERE asb.grade < 0 AND cm.instance = a.id AND cm.module = 1 AND a.course = c.id
) 'unChecked <br/>Submissions'
,(
SELECT COUNT(asb.id)
FROM prefix_assignment_submissions AS asb
JOIN prefix_assignment AS a ON a.id = asb.assignment
JOIN prefix_course_modules AS cm ON a.course = cm.course
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id
) 'Submitted <br/>Assignments'
FROM prefix_course AS c
LEFT JOIN (
SELECT course, COUNT(*) AS iAssignments
FROM prefix_assignment AS a
GROUP BY a.course
) AS tblAssignmentsCount ON tblAssignmentsCount.course = c.id
LEFT JOIN (
SELECT course, COUNT(*) AS iOpenAssignments
FROM prefix_assignment AS a
WHERE FROM_UNIXTIME(a.timedue) > NOW()
GROUP BY a.course
) AS tblOpenAssignmentsCount ON tblOpenAssignmentsCount.course = c.id
WHERE 1=1
#AND c.fullname LIKE '%????%'
%%FILTER_YEARS:c.fullname%%
## You can enable the SEMESTER FILTER AS well,
## BY uncommenting the following line:
## %%FILTER_SEMESTERS:c.fullname%%
ORDER BY 'Open <br/>Assignments' DESC
Rubrics without zero values in criteria
Contributed by Eric Strom
"For example, when the teacher in the previous example chose both levels with 1
point, the plain sum would be 2 points. But that is actually the lowest possible
score so it maps to the grade 0 in Moodle. TIP: To avoid confusion from this sort
of thing, we recommend including a level with 0 points in every rubric criterion."
This report identifies rubrics having criteria without a zero value level and the
courses they live in. This also refines to only assignments with active rubrics
that are visible to students in the course. Links to the each rubric id is the
direct link to edit the rubric. Fix by adding a zero level for each criteria that
is missing it. In general, the grading changes that result will be in the students'
favor.
GROUP BY Rubric
ORDER BY Course_ID, Rubric
%%FILTER_SEARCHTEXT:c.idnumber:~%%
Who is using "Single File Upload" assignment
SELECT
concat('<a target="_new" href="%%WWWROOT%%/course/view.php?
id=',c.id,'">',c.fullname,'</a>') AS Course
FROM
prefix_assignment AS ass
JOIN
prefix_course AS c ON c.id = ass.course
FROM prefix_feedback AS f
INNER JOIN prefix_course AS crs ON crs.id=f.course %%FILTER_COURSES:f.course%%
INNER JOIN prefix_feedback_item AS i ON f.id=i.feedback
INNER JOIN prefix_feedback_completed AS c ON f.id=c.feedback %
%FILTER_COURSEUSER:c.userid%%
LEFT JOIN prefix_feedback_value AS v ON v.completed=c.id AND v.item=i.id
INNER JOIN prefix_user AS u ON c.userid=u.id
Shows all Feedbacks in all Courses with all multi-choice questions and answers of
all users including showing the username of anonymous users. Also shows tryly
anonymous users on the front page as 'Not-logged-in' users. This is a rough report,
not a pretty report, and is limited to multiple-choice type questions, but is shows
the answer number and the list of possible answers in raw form. I post it here as a
basis for further reports, and also as away to get the identities of anonymous
users if needed.
SELECT
c.shortname AS Course,
f.name AS Feedback,
# i.id AS Itemid,
i.name AS Itemname,
i.label AS Itemlabel,
CASE
WHEN f.anonymous = 1 AND u.id != 0 THEN CONCAT(u.username, ' :ANON')
WHEN fc.userid = 0 THEN 'Not-logged-in'
ELSE u.username
END AS 'User',
DATE_FORMAT(FROM_UNIXTIME(fc.timemodified),'%Y-%m-%d %H:%i') AS "Completed",
v.value AS "Choice",
CASE
WHEN i.typ = 'multichoice' THEN
IF ( SUBSTRING(i.presentation,1,6)='d>>>>>',
SUBSTRING(i.presentation,7),
i.presentation)
ELSE i.presentation
END AS "Answers",
i.typ,
i.dependitem,
i.dependvalue
FROM prefix_feedback f
JOIN prefix_course c ON c.id=f.course
JOIN prefix_feedback_item AS i ON f.id=i.feedback
JOIN prefix_feedback_completed fc ON f.id=fc.feedback
LEFT JOIN prefix_feedback_value v ON v.completed=fc.id AND v.item=i.id
LEFT JOIN prefix_user AS u ON fc.userid=u.id
WHERE i.typ != 'pagebreak'
Resource Module Reports
List "Recently uploaded files"
see what users are uploading
SELECT
concat('<a target="_new" href="%%WWWROOT%%/course/view.php?
id=',c.id,'">',c.fullname,'</a>') AS Course
,c.shortname,r.name
,(SELECT CONCAT(u.firstname,' ', u.lastname) AS Teacher
FROM prefix_role_assignments AS ra
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
JOIN prefix_user AS u ON u.id = ra.userid
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher
,concat('<a target="_new" href="%%WWWROOT%%/mod/resource/view.php?
id=',r.id,'">',r.name,'</a>') AS Resource
FROM prefix_resource AS r
JOIN prefix_course AS c ON r.course = c.id
WHERE r.reference LIKE 'http://info.oranim.ac.il/home%'
"Compose Web Page" RESOURCE count
SELECT course,prefix_course.fullname, COUNT(*) AS Total
FROM `prefix_resource`
JOIN `prefix_course` ON prefix_course.id = prefix_resource.course
WHERE TYPE='html'
GROUP BY course
Resource count in courses
+ (First)Teacher name + Where course is inside some specific Categories
SELECT
COUNT(*) AS COUNT
,r.course
,c.shortname shortname
,c.fullname coursename
,( SELECT DISTINCT CONCAT(u.firstname,' ',u.lastname)
FROM prefix_role_assignments AS ra
JOIN prefix_user AS u ON ra.userid = u.id
JOIN prefix_context AS ctx ON ctx.id = ra.contextid
WHERE ra.roleid = 3 AND ctx.instanceid = r.course AND ctx.contextlevel = 50 LIMIT
1) AS Teacher
FROM prefix_resource r
JOIN prefix_course c ON r.course = c.id
WHERE c.category IN (10,13,28,18,26)
GROUP BY r.course
ORDER BY COUNT(*) DESC
Delete all the automated backup files
Prepare bash cli script to delete all the automated backup files on the file
system. (clean up some disk space)
SELECT
concat('<a target="_new" href="%%WWWROOT%%/mod/forum/user.php?
course=',c.id,'&id=',u.id,'&mode=posts">',CONCAT(u.firstname,' ',
u.lastname),'</a>') AS Fullname
,concat('<a target="_new" href="%%WWWROOT%%/mod/forum/view.php?
f=',fd.forum,'">',f.name,'</a>') AS Forum
,COUNT(*) AS Posts
,(SELECT COUNT(*) FROM prefix_forum_discussions AS ifd JOIN prefix_forum AS iforum
ON iforum.id = ifd.forum WHERE ifd.userid = fp.userid AND iforum.id = f.id) AS
cAllDiscussion
FROM prefix_forum_posts AS fp
JOIN prefix_user AS u ON u.id = fp.userid
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id
JOIN prefix_forum AS f ON f.id = fd.forum
JOIN prefix_course AS c ON c.id = fd.course
WHERE fd.course = %%COURSEID%%
GROUP BY f.id,u.id
ORDER BY u.id
FORUM use Count per COURSE -- not including NEWS Forum!
SELECT prefix_course.fullname, prefix_forum.course, COUNT(*) AS total FROM
prefix_forum
INNER JOIN prefix_course
ON prefix_course.id = prefix_forum.course
WHERE NOT(prefix_forum.type = 'news')
GROUP BY prefix_forum.course
ORDER BY total DESC
FORUM use Count per COURSE by type -- not including NEWS Forum!
SELECT prefix_course.fullname, prefix_forum.course, prefix_forum.type, COUNT(*) AS
total FROM prefix_forum
INNER JOIN prefix_course
ON prefix_course.id = prefix_forum.course
WHERE NOT(prefix_forum.type = 'news')
GROUP BY prefix_forum.course,prefix_forum.type
ORDER BY total DESC
Forum activity - system wide
SELECT concat('<a target="_new" href="%%WWWROOT%%/course/view.php?
id=',c.id,'">',c.id,'</a>') AS CourseID
,( SELECT DISTINCT CONCAT(u.firstname,' ',u.lastname)
FROM prefix_role_assignments AS ra
JOIN prefix_user AS u ON ra.userid = u.id
JOIN prefix_context AS ctx ON ctx.id = ra.contextid
WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1)
AS Teacher
,c.fullname AS Course
,f.type
,(SELECT COUNT( ra.userid ) AS Users FROM prefix_role_assignments AS ra
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students
, fd.forum, f.name,COUNT(*) AS cPostAndDisc
,(SELECT COUNT(*) FROM prefix_forum_discussions AS ifd WHERE ifd.forum = f.id) AS
cDiscussion
FROM prefix_forum_posts AS fp
JOIN prefix_forum_discussions AS fd ON fd.id = fp.discussion
JOIN prefix_forum AS f ON f.id = fd.forum
JOIN prefix_course AS c ON c.id = f.course
WHERE f.type != 'news' AND c.fullname LIKE '%2013%'
## WHERE 1=1
## %%FILTER_YEARS:c.fullname%%
## You can enable the SEMESTER FILTER AS well,
## BY uncommenting the following line:
## %%FILTER_SEMESTERS:c.fullname%%
GROUP BY fd.forum
ORDER BY COUNT( * ) DESC
Activity In Forums
Trying to figure out how much real activity we have in Forums by aggregating: Users
in Course, Number of Posts, Number of Discussions, Unique student post, Unique
student discussions, Number of Teachers , Number of Students, ratio between unique
Student posts and the number of students in the Course...
SELECT c.fullname,f.name,f.type
,(SELECT COUNT(id) FROM prefix_forum_discussions AS fd WHERE f.id = fd.forum) AS
Discussions
,(SELECT COUNT(DISTINCT fd.userid) FROM prefix_forum_discussions AS fd WHERE
fd.forum = f.id) AS UniqueUsersDiscussions
,(SELECT COUNT(fp.id) FROM prefix_forum_discussions fd JOIN prefix_forum_posts AS
fp ON fd.id = fp.discussion WHERE f.id = fd.forum) AS Posts
,(SELECT COUNT(DISTINCT fp.userid) FROM prefix_forum_discussions fd JOIN
prefix_forum_posts AS fp ON fd.id = fp.discussion WHERE f.id = fd.forum) AS
UniqueUsersPosts
,(SELECT COUNT( ra.userid ) AS Students
FROM prefix_role_assignments AS ra
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
WHERE ra.roleid =5
AND ctx.instanceid = c.id
) AS StudentsCount
,(SELECT COUNT( ra.userid ) AS Teachers
FROM prefix_role_assignments AS ra
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
WHERE ra.roleid =3
AND ctx.instanceid = c.id
) AS 'Teacher<br/>Count'
,(SELECT COUNT( ra.userid ) AS Users
FROM prefix_role_assignments AS ra
JOIN prefix_context AS ctx ON ra.contextid = ctx.id
WHERE ra.roleid IN (3,5)
AND ctx.instanceid = c.id
) AS UserCount
, (SELECT (UniqueUsersDiscussions / StudentsCount )) AS StudentDissUsage
, (SELECT (UniqueUsersPosts /StudentsCount)) AS StudentPostUsage
FROM prefix_forum AS f
JOIN prefix_course AS c ON f.course = c.id
WHERE `type` != 'news'
ORDER BY StudentPostUsage DESC
All Forum type:NEWS
SELECT f.id, f.name
FROM prefix_course_modules AS cm
JOIN prefix_modules AS m ON cm.module = m.id
JOIN prefix_forum AS f ON cm.instance = f.id
WHERE m.name = 'forum'
AND f.type = 'news'
All new forum NEWS items (discussions) from all my Courses
change "userid = 26" and "id = 26" to a new user id
Queriamos saber cuales son las acciones del profesor dentro de los foros de cada
curso, por ello se hizo este informe.
(We wanted to know what the teacher's actions are in the forums of each course, so
this report was made. /Google translator)
SELECT
concat('<a target="_new" href="%%WWWROOT%%/course/view.php?
id=',c.id,'">',c.shortname,'</a>') AS curso,
CONCAT(u.firstname ,' ',u.lastname) AS Facilitador,
COUNT(*) AS Posts
FROM prefix_forum_posts AS fp
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id
JOIN prefix_forum AS f ON f.id = fd.forum
JOIN prefix_course AS c ON c.id = fd.course
JOIN prefix_user AS u ON u.id = fp.userid
WHERE fp.userid =
(
SELECT DISTINCT prefix_user.id
FROM prefix_user
JOIN prefix_role_assignments AS ra ON ra.userid = prefix_user.id
WHERE ra.roleid = 3
AND userid = fp.userid
LIMIT 1
)
List all the Posts in all the Forums that got high rating
We setup a scale that let teachers and students Rate forum post with "Important,
interesting, valuable, not rated" scale And then add a link to the following report
at the begining of the course "Link to all interesting posts"
SELECT
CONCAT('<a target="_new" href="%%WWWROOT%%/mod/forum/view.php?
f=',f.id,'">',f.name,'</a>') AS 'Forum name,
CONCAT('<a target="_new" href="%%WWWROOT%%/mod/forum/discuss.php?
d=',fd.id,'#p',fp.id,'">',fp.subject,'</a>') AS 'Post link',
SUM(r.rating) AS 'Rating'
FROM mdl_rating AS r
JOIN mdl_forum_posts AS fp ON fp.id = r.itemid
JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion
JOIN mdl_forum AS f ON f.id = fd.forum
WHERE r.component = 'mod_forum' AND r.ratingarea = 'post' AND f.course = %%COURSEID
%%
GROUP BY r.itemid
ORDER BY SUM(r.rating) DESC
List all the Posts in all Discussions of a single Forum
This report is used to help export all the student's posts and discussions of a
single forum, by passing the context module id as a parameter to the report using
"&filter_var=cmid"
SELECT
CONCAT('<a target="_new" href="%%WWWROOT%%/mod/forum/view.php?f=', f.id, '">',
f.name, '</a>') AS 'Forum name',
fd.name AS 'Discussion',
CONCAT('<a target="_new" href="%%WWWROOT%%/mod/forum/discuss.php?d=', fd.id, '#p',
fp.id, '">', fp.subject, '</a>') AS 'Post (link)',
fp.message
FROM mdl_forum_posts AS fp
JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion
JOIN mdl_forum AS f ON f.id = fd.forum
JOIN mdl_course_modules AS cm ON cm.module = 9 AND cm.instance = f.id
WHERE cm.id = %%FILTER_VAR%%
ORDER BY f.id, fd.id
Quiz Module Reports
Generate a list of instructors and their email addresses for those courses that has
"essay questions" in their quizzes
SELECT qu.id AS quiz_id, qu.course AS course_id, qu.questions,
co.fullname AS course_fullname, co.shortname AS course_shortname,
qu.name AS quiz_name, FROM_UNIXTIME(qu.timeopen) AS quiz_timeopen,
FROM_UNIXTIME(qu.timeclose) AS quiz_timeclose,
u.firstname, u.lastname, u.email,
FROM prefix_quiz qu, prefix_course co, prefix_role re, prefix_context ct,
prefix_role_assignments ra, prefix_user u
WHERE FROM_UNIXTIME(timeopen) > '2008-05-14' AND
qu.course = co.id AND
co.id = ct.instanceid AND
ra.roleid = re.id AND
re.name = 'Teacher' AND
ra.contextid = ct.id AND
ra.userid = u.id
FROM prefix_course_modules cm
JOIN prefix_course c ON c.id = cm.course
JOIN prefix_modules AS m ON m.id = cm.module
WHERE m.name LIKE 'quiz'
GROUP BY c.id
List all MultiAnswer (Cloze) Questions
SELECT concat('<a target="_new" href="%%WWWROOT%%/mod/quiz/attempt.php?q=',
quiz.id, '">', quiz.name, '</a>') AS Quiz
,question.id question_id, question.questiontext
FROM prefix_question question
JOIN prefix_quiz_question_instances qqi ON question.id = qqi.question
JOIN prefix_quiz quiz ON qqi.quiz = quiz.id
WHERE `qtype` LIKE 'multianswer'
List courses with MANUAL grades
Which is basically and indication to teachers using Moodle to hold offline grades
inside Moodle's Gradebook, So grades could be uploaded into an administrative SIS.
Use with Configurable Reports.
SELECT COUNT( * )
,concat('<a target="_new" href="%%WWWROOT%%/grade/edit/tree/index.php?
showadvanced=1&id=',c.id,'">',c.fullname,'</a>') AS Course
FROM prefix_grade_items AS gi
JOIN prefix_course AS c ON c.id = gi.courseid
WHERE `itemtype` = 'manual'
GROUP BY courseid
List the users that did not took the Quiz
Do not forget to change "c.id = 14" and q.name LIKE '%quiz name goes here%'
SELECT
user2.id AS ID,
ul.timeaccess,
user2.firstname AS Firstname,
user2.lastname AS Lastname,
user2.email AS Email,
user2.username AS IDNumber,
user2.institution AS Institution,
IF (user2.lastaccess = 0,'never',
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),'%Y-%m-%d')) AS dLastAccess
,(SELECT r.name
FROM prefix_user_enrolments AS uenrol
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid
JOIN prefix_role AS r ON e.id = r.id
WHERE uenrol.userid=user2.id AND e.courseid = c.id) AS RoleName
FROM prefix_user_enrolments AS ue
JOIN prefix_enrol AS e ON e.id = ue.enrolid
JOIN prefix_course AS c ON c.id = e.courseid
JOIN prefix_user AS user2 ON user2 .id = ue.userid
LEFT JOIN prefix_user_lastaccess AS ul ON ul.userid = user2.id
WHERE c.id=14 AND ue.userid NOT IN (SELECT qa.userid FROM prefix_quiz_attempts AS
qa
JOIN prefix_quiz AS q ON qa.quiz = q.id
JOIN prefix_course AS c ON q.course = c.id
WHERE c.id = 14 AND q.name LIKE '%quiz name goes here%')
SELECT
cm.course "course_id", cm.id "moduel_id", q.id "quiz_id", q.name "quiz_name",
CASE q.grademethod
WHEN 1 THEN "GRADEHIGHEST"
WHEN 2 THEN "GRADEAVERAGE"
WHEN 3 THEN "ATTEMPTFIRST"
WHEN 4 THEN "ATTEMPTLAST"
END "grade method"
FROM mdl_quiz AS q
JOIN mdl_course_modules AS cm ON cm.instance = q.id AND cm.module = 14
JOIN mdl_quiz_attempts qa ON q.id = qa.quiz
LEFT JOIN mdl_quiz_grades AS qg ON qg.quiz = q.id AND qg.userid = qa.userid
JOIN mdl_user AS u ON u.id = qa.userid
JOIN mdl_question_usages AS qu ON qu.id = qa.uniqueid
JOIN mdl_question_attempts AS qatt ON qatt.questionusageid = qu.id
JOIN mdl_question AS question ON question.id = qatt.questionid
JOIN mdl_question_attempt_steps AS qas ON qas.questionattemptid = qatt.id
LEFT JOIN mdl_question_hints AS qh ON qh.questionid = q.id
#WHERE q.id = "SOME QUIZ ID"
WHERE cm.course = "SOME COURSE ID"
Quiz Usage in Courses by Date
Contributed by Elizabeth Dalton, Granite State College
This report lists the courses containing quizzes with the course start date between
the two values, and provides a summary of the types of questions in the quizzes in
each course and whether question randomization and answer randomization functions
were used.
"Other" questions include fixed numerical, calculated, essay, and various drag and
drop types.
"Min Quiz Age" and "Max Quiz Age" provide data about the last modified date for the
quizzes in the course, compared to the course start date. The values are expressed
in units of days. A negative value indicates that a quiz was edited after the start
of the course. A value greater than 90 days indicates that the quiz may have been
used in an earlier term (cohort) without modification.
Note: In Configurable Reports, the Date Filter is not applied until the "Apply"
button is clicked.
SELECT
c.shortname AS 'Course'
#, u.lastname AS 'Instructor'
, COUNT(DISTINCT q.id) AS 'Quizzes'
, COUNT(DISTINCT qu.id) AS 'Questions'
, SUM(IF (qu.qtype = 'multichoice', 1, 0 )) + SUM(IF (qu.qtype = 'truefalse', 1,
0 )) + SUM(IF (qu.qtype = 'match', 1, 0 )) AS 'multichoice'
#, DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(MIN(q.timemodified))) AS 'Quiz
age'
, MIN(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS 'Min
Quiz Age'
, MAX(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS 'Max
Quiz Age'
FROM prefix_quiz AS q
JOIN prefix_course AS c ON c.id = q.course
JOIN prefix_quiz_question_instances AS qqi ON qqi.quiz = q.id
LEFT JOIN prefix_question AS qu ON qu.id = qqi.question
WHERE
1
%%FILTER_STARTTIME:c.startdate:>%% %%FILTER_ENDTIME:c.startdate:<%%
GROUP BY c.id
ORDER BY c.shortname
Student responses (answers) to quiz questions
(Contributed by Juan F with help from Tim hunt and fellow Moodlers on the forums) A
report that targets a specific quiz for all of our Biology courses, a summary of
all questions and how many students get them right/wrong.
SELECT
concat( u.firstname, " ", u.lastname ) AS "Student Name",
u.id,
quiza.userid,
q.course,
q.name,
quiza.attempt,
qa.slot,
que.questiontext AS 'Question',
qa.rightanswer AS 'Correct Answer',
qa.responsesummary AS 'Student Answer'
SELECT
u.firstname AS FIRST,
u.lastname AS LAST,
u.idnumber AS Employee_ID,
u.city AS City,
uid.data AS State,
u.country AS Country,
g.name AS Group_name,
c.fullname AS Course,
st.attempt AS Attempt,
st.value AS STATUS,
FROM_UNIXTIME(st.timemodified,"%m-%d-%Y") AS DATE
FROM prefix_scorm_scoes_track AS st
JOIN prefix_user AS u ON st.userid=u.id
JOIN prefix_user_info_data AS uid ON uid.userid = u.id
JOIN prefix_scorm AS sc ON sc.id=st.scormid
JOIN prefix_course AS c ON c.id=sc.course
JOIN prefix_groups AS g ON g.courseid = c.id
JOIN prefix_groups_members AS m ON g.id = m.groupid
UNION
SELECT
user2.firstname AS FIRST,
user2.lastname AS LAST,
user2. idnumber AS Employee_ID,
user2.city AS City,
uid.data AS State,
user2.country AS Country,
g.name AS Group_name,
c.fullname AS Course,
"-" AS Attempt,
"not_started" AS STATUS,
"-" AS DATE
FROM prefix_user_enrolments AS ue
JOIN prefix_enrol AS e ON e.id = ue.enrolid
JOIN prefix_course AS c ON c.id = e.courseid
JOIN prefix_user AS user2 ON user2 .id = ue.userid
JOIN prefix_user_info_data AS uid ON uid.userid = user2.id
JOIN prefix_groups AS g ON g.courseid = c.id
JOIN prefix_groups_members AS m ON g.id = m.groupid
JOIN prefix_scorm AS sc ON sc.course=c.id
LEFT JOIN prefix_scorm_scoes_track AS st ON st.scormid=sc.id AND st.userid=user2.id
This report will show you all the badges on a site that have been issued, both site
and all courses, by the username of each user issued a badge. Includes the type of
criteria passed (activity, course completion, manual), date issued, date expires,
and a direct link to that issued badge page so you can see all the other details
for that badge.
Report of all badges in the system, with badge name and description, context,
course shortname if a course badge, whether it is active and available, and a count
of how many users have been issued that badge.
A simple list of usernames and how many badges they have earned overall.
The Administrative report Config changes is very useful but it would be nice to
have it in a format that could be easily exported in one listing. Here is code to
do that.
SELECT
DATE_FORMAT( FROM_UNIXTIME( g.timemodified ) , '%Y-%m-%d' ) AS DATE,
u.username AS USER,
g.name AS setting,
CASE
WHEN g.plugin IS NULL THEN "core"
ELSE g.plugin
END AS plugin,
g.value AS new_value,
g.oldvalue AS original_value
FROM prefix_config_log AS g
JOIN prefix_user AS u ON g.userid = u.id
ORDER BY DATE DESC
Cohorts by user
Contributed by: Randy Thornton
How to get a list of all users and which cohorts they belong to.
List of all cohorts with name, id, visibility, and which courses they are enrolled
in.
SELECT
# h.id,
# e.customint1,
h.name AS Cohort,
h.idnumber AS Cohortid,
CASE
WHEN h.visible = 1 THEN 'Yes'
ELSE '-'
END AS Cohortvisible,
CONCAT('<a target="_new" href="%%WWWROOT%%/course/view.php',
CHAR(63),'id=',c.id,'">',c.fullname,'</a>') AS Course
FROM prefix_cohort h
JOIN prefix_enrol e ON h.id = e.customint1
JOIN prefix_course c ON c.id = e.courseid %%FILTER_COURSES:e.courseid%%
WHERE e.enrol = 'cohort' AND e.roleid = 5
Courses created And Active courses by Year
Active courses is counting course that have at least one Hit, And
"Active_MoreThan100Hits" counts courses that have at least 100 Hits
SELECT
FROM `prefix_course`
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) )
Users created And Active users by Year
Active users is counting users that have at least one Hit, And
"Active_MoreThan500Hits" counts users that have at least 500 Hits
SELECT
FROM `prefix_user`
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) )
Course Aggregation Report
Contributed by Elizabeth Dalton, Granite State College
If you are considering upgrading from Moodle 2.6 to 2.8 or later, your grades may
be changed. This report can help quantify and identify the courses at risk of
changes.
In particular, be on the lookout for any courses with the following combinations of
parameters, which are known to cause changes in calculations:
SELECT
# IF you want TO display ALL the courses FOR each aggregation TYPE, uncomment the
NEXT line AND CHANGE GROUP BY settings
#, c.shortname AS 'course name'
# IF you need TO display grade categories FOR each aggregation TYPE, uncomment the
NEXT line AND CHANGE GROUP BY settings
#, gc.fullname AS 'grade category name'
# Note that gc.aggregatesubcats column is eliminated in 2.8 and later per MDL-
47503, so comment that line on updated systems or you'll GET an error
, gc.keephigh AS 'keep high'
, gc.droplow AS 'dr0p low'
, gc.aggregateonlygraded AS 'Aggregate only graded'
, gc.aggregateoutcomes AS 'aggregate outcomes'
, gc.aggregatesubcats AS 'aggregate subcategories'
# IF you are displaying DATA about individual courses, you may want TO know how OLD
they are
#, FROM_UNIXTIME(c.startdate) AS 'course start date'
# IF you are trying TO USE this report TO CHECK TO see IF final grades have changed
after an upgrade, you might want these DATA items, but calculations can still
CHANGE later WHEN the courses are actually viewed. Also, you'll need to uncomment
the necessary JOINs below
#, gi.itemname AS 'grade item'
#, gg.finalgrade AS 'final grade'
FROM
prefix_course AS c
JOIN prefix_grade_categories AS gc ON gc.courseid = c.id
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE
1
#AND gc.aggregation = 13 #only the dreaded Sum of Grades aggregations
#AND gc.depth = 1 # if for some reason you only want course aggregations, not
subcategories
This shows the list of courses with Meta course link enrollments in them ('Parent
course'), and the courses which are connected to them to provide enrollments
('Child courses').
SELECT
c.fullname AS 'Parent course name',
c.shortname AS 'Parent course shortname',
en.courseid AS 'Parent course id',
(SELECT fullname FROM prefix_course WHERE prefix_course.id = en.customint1) AS
'Child course name',
(SELECT shortname FROM prefix_course WHERE prefix_course.id = en.customint1) AS
'Child course shortname',
en.customint1 AS 'Child course id'
FROM prefix_enrol en
JOIN prefix_course c ON c.id = en.courseid
WHERE en.enrol = 'meta'
ORDER BY c.fullname
Useful sub queries
IN this section please put any short one purpose sub queries that show how common
procedures often useful as part of larger queries.
This snippet of code shows how to connect a user with their custom profile field
data. This will list all users with all custom profile fields and data. Custom
profile fields have two tables, one for the definition of the profile field
(user_info_field) and its settings, and a separate table to hold the data entered
by users (user_info_data).
If you want to do this with two or more custom profile fields, you will need to
have a JOIN and table alias for each with a restriction for each profile field
shortname. Example:
Instead you should use an alternate method which uses Subselects for each of the
profile fields. Details and sample code are in this forum discussion:
https://moodle.org/mod/forum/discuss.php?d=355502#p1434854. A sample of the style
is:
SELECT u.username
FROM prefix_user u
How to use Configurable Reports Date Time Filters
Contributed by: Randy Thornton
In the Configurable Reports block, you can set the Time and Date filter to allow
you to pick your report Start date/time and End date/time interactively. This will
work on any column in a table that is a timestamp.
SELECT u.username,
DATE_FORMAT(FROM_UNIXTIME(u.firstaccess),'%Y-%m-%d %H:%i') AS 'FirstAccess',
DATE_FORMAT(FROM_UNIXTIME(u.lastaccess),'%Y-%m-%d %H:%i') AS 'LastAccess'
FROM prefix_user u
WHERE 1=1
%%FILTER_STARTTIME:u.firstaccess:>%%
%%FILTER_ENDTIME:u.lastaccess:<%%
1) You will need to replace name of the table and column for the filter to use the
time and date column you need for your query. In the example above, it filters on
the firstaccess and lastaccess columns in the user table. If you were doing a
report on course completion, you might put the timecompleted column, and so forth.
2) You MUST then add the Start / End date filter on the Filters tab of the Report.
If you don't, the report will still run, probably, but the filter will be ignored.
Note: the WHERE 1=1 statement is a peculiarity of the filters in Config reports: if
you don't have a WHERE statement in your query already, then you must add this
dummy WHERE to keep the statement valid. If you already have a WHERE statement in
your code, simply add the %%FILTER%% placeholders after it (and before any GROUP or
ORDER BY statements.)