<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/310/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Nadavkav</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/310/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Nadavkav"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/Special:Contributions/Nadavkav"/>
	<updated>2026-04-16T13:33:15Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Quiz_statistics_report&amp;diff=140676</id>
		<title>Quiz statistics report</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Quiz_statistics_report&amp;diff=140676"/>
		<updated>2022-02-13T11:58:34Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Quiz structure analysis */ explain questions with red background and Discrimination index&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Quiz reports}}&lt;br /&gt;
The &#039;&#039;&#039;quiz statistics report&#039;&#039;&#039; may be viewed by clicking on the quiz and accessing Statistics from the gear menu, or if using a non-Boost based theme, accessing &#039;&#039;Administration &amp;gt; Quiz administration&amp;gt; Results &amp;gt; Statistics&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This report gives a statistical (psychometric) analysis of the quiz, and the questions within it. The top section of this report gives a summary of the whole quiz. The next section gives an analysis showing all questions in a table format. There are links in this section to edit individual questions or drill down into a detailed analysis of a particular question. The last section of this report is a bar graph of the percentage of correct answers (Facility index) and the Discriminative efficiency index.&lt;br /&gt;
&lt;br /&gt;
The full report (overview, and detailed analysis of all questions) can be downloaded in a variety of formats, as can the quiz structure analysis table.&lt;br /&gt;
==Reasons to look at the statistics report==&lt;br /&gt;
There are lots of highly technical in the Quiz statistics, which is great if you are a data scientist or mathematician, but even if you are not, there is very useful information to help you learn about how well your quiz is helping your students, even if you don&#039;t understand all the technicalities.&lt;br /&gt;
===Finding &#039;broken&#039; questions===&lt;br /&gt;
If everything is working well, then what normally happens is that students who got a high mark on the whole quiz are more likely to get each question right. If you make a mistake when you create a question, for example if you accidentally set the wrong response to be marked correct, what happens then is that the better students who get a higher overall mark are more likely to select the right answer, and get marked wrong. This shows up in the &#039;Discrimination index&#039; column. If the number there is small, you may have a problem. A broken question is not the only thing that might cause this, so you need to go an investigate, but it is a worrying sign. Because of that, Moodle will highlight any low values in this column so they stand out.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip: look down the &#039;Discrimination index&#039; column. If any numbers there are small, then investigate that question.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you find a &#039;broken&#039; question, there are various options. You may be able to edit the question and then regrade the quiz to fix the problem (but be very careful editing questions after they were attempted.) Or, you could to go to the Edit quiz page, and set the mark for that question to 0 (zero-weight it).&lt;br /&gt;
===Ensuring that random variants are fair===&lt;br /&gt;
There are lots of different ways that [https://en.wikipedia.org/wiki/Randomization randomization] can be used when building a quiz. Sometimes you will have something like a topic review quiz that draws a selection of 10 question from a set of 100, but the case we want to consider here is when for each &#039;question&#039; in the quiz, you have a few different but similar versions of the &#039;same&#039; question. For [https://en.wikipedia.org/wiki/Formative_assessment formative quizzes] that is good, because it gives students more chance to practise. For [https://en.wikipedia.org/wiki/Summative_assessment summative quizzes], it is good because it reduces the changes for copying. You can build this either using random selection from different categories like &#039;Variants of question 1&#039;, or you can do it with question types like [[Calculated question type|Calculated]] or [https://moodle.org/plugins/qtype_stack STACK] that have internal random variants, or both. ([[Effective quiz practices#Robust testing with random variants|For more details, see here]].) &lt;br /&gt;
&lt;br /&gt;
If you are doing this, particularly if doing this for-credit, you probably want to ensure that it is &#039;fair&#039;. You don&#039;t want one variant to be much harder than the others. To see this, look at the subsidiary rows that show all the different questions that appeared in once particular place in the quiz. Look in particular at the &#039;Facility index&#039;, which is basically how many people got that question right. If those numbers are very different for different variants, that is a sign the quiz may be unfair.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip: if using variants, look down the &#039;Facility index&#039; column to make sure that all the different variants of a particular question have similar facility index.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If there is big variation in one questions, then you could zero-weight it. Also, if you are re-using the quiz in future, consider removing that variant, and adding a new one.&lt;br /&gt;
&lt;br /&gt;
Of course, when you have variants like this, you should check that Discrimination index for all the different variants, to ensure that none of the variants are broken in that way either.&lt;br /&gt;
===Understanding how students are responding to a particular question===&lt;br /&gt;
When you set a particular question in a quiz, you normally do so intending to test a particular skill or bit of knowledge. However, can you be sure that is what you are really measuring?&lt;br /&gt;
&lt;br /&gt;
As an example from this, there was an Open University &#039;Maths for Scientists&#039; course, where they had a question which was supposed to test that the student could substitute some numbers in an equation, and computer the answer with their calculator. As is standard practice for OU science tests, students had to give the answer to the right number of decimal places (which had already been taught and assessed). However, when they look at the answers students had given, they found that many students had clearly computed the right thing in their calculator, but were then being marked wrong because they input too many decimal places. (http://oro.open.ac.uk/39669/ Jordan, 2014)&lt;br /&gt;
&lt;br /&gt;
The statistics report makes this kind of analysis quite easy. As described below, if you click through to the details about a particular question, then at the bottom of that page it shows all the different responses that were given, whether they were marked right or wrong, and how many students gave each results.&lt;br /&gt;
&lt;br /&gt;
This can be a good place to start looking if some of the checks above highlight a potential problem.&lt;br /&gt;
&lt;br /&gt;
Another way you can use this information is, if you are using more open-ended question types, like Short answer or Numerical, then you may notice several students have made the same mistake. You might then go back end edit the question, to add specific feedback for students who have given that answer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip: particularly if using open-ended questions, look at the Analysis of responses to see what answers sudents are actually giving.&#039;&#039;&#039;&lt;br /&gt;
==Overall quiz statistics==&lt;br /&gt;
Here are the details concerning information in this report.&lt;br /&gt;
===Quiz information===&lt;br /&gt;
This section gives some basic information about the test as a whole. You will see:&lt;br /&gt;
* Quiz name&lt;br /&gt;
* Course name&lt;br /&gt;
* Open and close dates (if applicable)&lt;br /&gt;
* Total number of first/graded attempts&lt;br /&gt;
* Average grade for first/all attempts&lt;br /&gt;
* Median grade&lt;br /&gt;
* Standard deviation of grades &lt;br /&gt;
* [http://en.wikipedia.org/wiki/Skewness Skewness] and [http://en.wikipedia.org/wiki/Kurtosis Kurtosis] of the grade distribution&lt;br /&gt;
* Coefficient of internal consistency (sometimes called [http://en.wikipedia.org/wiki/Cronbach%27s_alpha Cronbach Alpha]) - This is a measure of whether all the items in the quiz are testing basically the same thing. Thus it measures the consistency of the text, which is a lower bound for the validity. Higher numbers here are better.&lt;br /&gt;
* Error ratio - the variation in the grades comes from two sources. First some students are better than others at what is being tested, and second there is some random variation. We hope that the quiz grades will largely be determined by the student&#039;s ability, and that random variation will be minimised. The error ratio estimates how much of the variation is random, and so lower is better.&lt;br /&gt;
* Standard error - this is derived from the error ratio, and is a measure of how much random variation there is in each test grade. So, if the Standard error is 10%, and a student scored 60%, then their real ability probably lies somewhere between 50% and 70%.&lt;br /&gt;
[[File:Quiz_results_statistics_information.png|thumb|center|Example of quiz information section]]&lt;br /&gt;
===Quiz structure analysis===&lt;br /&gt;
This section lists all the questions in the quiz with various statistics in a table format.&lt;br /&gt;
* &#039;&#039;&#039;Q#&#039;&#039;&#039; - shows the question number (position), question type icon, and preview and edit icons&lt;br /&gt;
* &#039;&#039;&#039;Question name&#039;&#039;&#039; - the name is also a link to the detailed analysis of this question (See Quiz Question Statistics below).&lt;br /&gt;
* &#039;&#039;&#039;Attempts&#039;&#039;&#039; - how many students attempted this question.&lt;br /&gt;
* &#039;&#039;&#039;Facility Index&#039;&#039;&#039; - the percentage of students that answered the question correctly.&lt;br /&gt;
* &#039;&#039;&#039;[http://en.wikipedia.org/wiki/Standard_deviation Standard Deviation]&#039;&#039;&#039; - how much variation there was in the scores for this question.&lt;br /&gt;
* &#039;&#039;&#039;Random guess score&#039;&#039;&#039; - the score the student would get by guessing randomly&lt;br /&gt;
* &#039;&#039;&#039;Intended/Effective weight&#039;&#039;&#039; - Intended weight is simply what you set up when editing the quiz. If question 1 is worth 3 marks out of a total of 10 for the quiz, the intended weight is 30%. The effective weight is an attempt to estimate, from the results, how much of the actual variation was due to this question. So, ideally the effective weights should be close to the intended weights.&lt;br /&gt;
* &#039;&#039;&#039;Discrimination index&#039;&#039;&#039; - this is the correlation between the score for this question and the score for the whole quiz. That is, for a good question, you hope that the students who score highly on this question are the same students who score highly on the whole quiz. Higher numbers are better.&lt;br /&gt;
* &#039;&#039;&#039;Discriminative efficiency&#039;&#039;&#039; - another measure that is similar to Discrimination index.&lt;br /&gt;
:Where random questions are used, there is one row in the table for the random question, followed by further rows, one for each real question that was selected in place of this random question.&lt;br /&gt;
:When quiz questions are randomized for each quiz, the quiz module determines a default position.&lt;br /&gt;
:[[:dev:Quiz statistics calculations|Quiz statistics calculations]] gives further details on all these quantities.&lt;br /&gt;
[[File:Quiz_results_statistics_structure_analysis.png|thumb|center|Example of statistics structural analysis section|449x449px]]Red background under question names indicate that the questions have low &#039;&#039;&#039;Discrimination index&#039;&#039;&#039;. That is a bad sign. It means that many students who score a high overall grade got a bad score for this question, and vice versa. It suggests you should check that question, to make sure it does not contain an error.&lt;br /&gt;
&lt;br /&gt;
it is based on the following formula: discriminative efficiency &amp;lt; 15%&lt;br /&gt;
&lt;br /&gt;
===Quiz statistics chart===&lt;br /&gt;
[[File:Quiz_results_statistics_chart.png|thumb|center|Chart example]]&lt;br /&gt;
==Quiz question statistics==&lt;br /&gt;
Navigation &amp;gt; quiz&#039;s name &amp;gt; Results &amp;gt; Statistics (click on any question title)&lt;br /&gt;
It is possible to see the statistics for one question on a single page. This view will also tell you what percentage of quiz takers selected each answer (Analysis of responses) and give you basic information about the question.&lt;br /&gt;
*Question information- The basic information about the question, the name of the quiz, the question, the question type, the position in the quiz and the question itself. There are preview and edit icons in this page.&lt;br /&gt;
*Question statistics - This repeats the information from the table row from the Quiz structure analysis that relates to this question.&lt;br /&gt;
*Report options - You can choose whether to run the report on all attempts, or just the first attempt by each student. Some of the calculations used in the report are based on assumptions that may not apply to quizzes that allow more than one attempt.&lt;br /&gt;
&#039;&#039;:Tip:&#039;&#039; Computing the statistics takes some time, the report will store the computed values and re-use them for up to 15 minutes. Therefore, there is a display of how recently the statistics were calculated, with a button to recalculate them immediate&lt;br /&gt;
&amp;lt;gallery&amp;gt;&lt;br /&gt;
File:Quiz_results_statistics_individual_question_preferences.png|Individual question page preferences&lt;br /&gt;
File:Quiz_results_statistics_individual_question_information.png|Individual question&#039;s information&lt;br /&gt;
File:Quiz_results_statistics_individual_question_statistics.png|Individual question&#039;s statistic information&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
===Analysis of individual question responses===&lt;br /&gt;
This gives a frequency analysis of the different responses that were given to each part of the question. The details of the analysis depends on the question type, and not all question types support this. For example, essay question responses cannot be analysed.&lt;br /&gt;
[[File:Quiz_results_statistics_individual_question_analysis_responses.png|thumb|center|Individual question&#039;s responses statistic information]]&lt;br /&gt;
== See also ==&lt;br /&gt;
* https://docs.moodle.org/dev/Quiz_statistics_calculations&lt;br /&gt;
* [https://docs.moodle.org/dev/Quiz_report_statistics https://docs.moodle.org/dev/Quiz_report_statistics] on the Developers documentation&lt;br /&gt;
* [https://wiki.umontreal.ca/download/attachments/92832287/Brief_Guide_to_iCMA_reports.pdf?version=1&amp;amp;modificationDate=1399917582000&amp;amp;api=v2 A brief guide to what the statistics mean, from the Open University]&lt;br /&gt;
[[de:Test-Statistik]]&lt;br /&gt;
[[es:Quiz statistics report]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=139623</id>
		<title>ad-hoc contributed reports</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=139623"/>
		<updated>2021-02-08T14:02:04Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Course format used on my system */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Sitewide reports}}&lt;br /&gt;
==User and Role Report==&lt;br /&gt;
&lt;br /&gt;
===Count number of distinct learners and teachers enrolled per category (including all its sub categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;SELECT COUNT(DISTINCT lra.userid) AS learners, COUNT(DISTINCT tra.userid) as teachers&lt;br /&gt;
FROM prefix_course AS c #, mdl_course_categories AS cats&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments  AS lra ON lra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role_assignments  AS tra ON tra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category = cats.id&lt;br /&gt;
AND (&lt;br /&gt;
	cats.path LIKE &#039;%/CATEGORYID/%&#039; #Replace CATEGORYID with the category id you want to count (eg: 80)&lt;br /&gt;
	OR cats.path LIKE &#039;%/CATEGORYID&#039;&lt;br /&gt;
	)&lt;br /&gt;
AND lra.roleid=5&lt;br /&gt;
AND tra.roleid=3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each ROLE (TEACHER, NON-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT r.name, l.action, COUNT( l.userid ) AS counter&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_role AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE ra.roleid IN ( 3, 4, 5 ) &lt;br /&gt;
GROUP BY roleid, l.action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student (user) COUNT in each Course===&lt;br /&gt;
Including (optional) filter by: year (if included in course fullname).&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/index.php?contextid=&#039;,context.id,&#039;&amp;quot;&amp;gt;Show users&amp;lt;/a&amp;gt;&#039;) AS Users&lt;br /&gt;
, COUNT(course.id) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS asg&lt;br /&gt;
JOIN prefix_context AS context ON asg.contextid = context.id AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_user AS user ON user.id = asg.userid&lt;br /&gt;
JOIN prefix_course AS course ON context.instanceid = course.id&lt;br /&gt;
WHERE asg.roleid = 5 &lt;br /&gt;
# AND course.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
GROUP BY course.id&lt;br /&gt;
ORDER BY COUNT(course.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enrolment count in each Course ===&lt;br /&gt;
&lt;br /&gt;
Shows the total number of enroled users of all roles in each course. Sorted by course name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname, COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LIST of all site USERS by COURSE enrollment (Moodle 2.x)===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) as Role&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) as RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course as course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enrolled users,which did not login into the Course, even once (Moodle 2)===&lt;br /&gt;
Designed forMoodle 2 table structure and uses special plugin filter : %%FILTER_SEARCHTEXT:table.field%%&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id as ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
user2.idnumber AS IDNumber,&lt;br /&gt;
user2.phone1 AS Phone,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
&lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id and courseid=c.id) as CourseLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id and e.courseid = c.id) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments as ue&lt;br /&gt;
JOIN prefix_enrol as e on e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user as user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess as ul on ul.userid = user2.id&lt;br /&gt;
WHERE c.id=16 AND ul.timeaccess IS NULL&lt;br /&gt;
%%FILTER_SEARCHTEXT:user2.firstname%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enrolled users who have never accessed a given course (simpler version)===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, firstname, lastname, idnumber&lt;br /&gt;
FROM prefix_user_enrolments ue&lt;br /&gt;
JOIN prefix_enrol en ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user uu ON uu.id = ue.userid &lt;br /&gt;
WHERE en.courseid = 123456&lt;br /&gt;
AND NOT EXISTS (&lt;br /&gt;
    SELECT * FROM prefix_user_lastaccess la&lt;br /&gt;
    WHERE la.userid = ue.userid&lt;br /&gt;
    AND la.courseid = en.courseid&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Replace 123456 near the middle with your courseid)&lt;br /&gt;
&lt;br /&gt;
===Role assignments on categories===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS category,&lt;br /&gt;
cc.depth, cc.path, r.name AS role,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php?id=&#039;,usr.id,&#039;&amp;quot;&amp;gt;&#039;,usr.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS name,&lt;br /&gt;
usr.firstname, usr.username, usr.email&lt;br /&gt;
FROM prefix_course_categories cc&lt;br /&gt;
INNER JOIN prefix_context cx ON cc.id = cx.instanceid&lt;br /&gt;
AND cx.contextlevel = &#039;40&#039;&lt;br /&gt;
INNER JOIN prefix_role_assignments ra ON cx.id = ra.contextid&lt;br /&gt;
INNER JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
INNER JOIN prefix_user usr ON ra.userid = usr.id&lt;br /&gt;
ORDER BY cc.depth, cc.path, usr.lastname, usr.firstname, r.name, cc.name&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Permissions Overides on Categories===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712834 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT rc.id, ct.instanceid, ccat.name, rc.roleid, rc.capability, rc.permission, &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( rc.timemodified ) , &#039;%Y-%m-%d&#039; ) AS timemodified, rc.modifierid, ct.instanceid, ct.path, ct.depth&lt;br /&gt;
FROM `prefix_role_capabilities` AS rc&lt;br /&gt;
INNER JOIN `prefix_context` AS ct ON rc.contextid = ct.id&lt;br /&gt;
INNER JOIN `prefix_course_categories` AS ccat ON ccat.id = ct.instanceid&lt;br /&gt;
AND `contextlevel` =40&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;Totally Opened Courses&amp;quot; (visible, opened to guests, with no password)===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712837 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Course&#039;,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/enrol/instances.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Méthodes inscription&amp;lt;/a&amp;gt;&#039;) AS &#039;Enrollment plugins&#039;,&lt;br /&gt;
e.sortorder&lt;br /&gt;
FROM prefix_enrol AS e, prefix_course AS c&lt;br /&gt;
WHERE e.enrol=&#039;guest&#039; AND e.status=0 AND e.password=&#039;&#039; AND c.id=e.courseid AND c.visible=1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;loggedin users&amp;quot; from the last 120 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id,username,FROM_UNIXTIME(`lastlogin`) as days &lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;and user count for that same population:&#039;&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(id) as Users  FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Users loggedin within the last 7 days ====&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    l.* FROM mdl_logstore_standard_log l&lt;br /&gt;
WHERE&lt;br /&gt;
   l.eventname = &#039;\\core\\event\\user_loggedin&#039;&lt;br /&gt;
   AND FROM_UNIXTIME(l.timecreated, &#039;%Y-%m-%d&#039;) &amp;gt;= DATE_SUB(NOW(), INTERVAL 7 DAY)&lt;br /&gt;
&lt;br /&gt;
SELECT l.eventname FROM mdl_logstore_standard_log l&lt;br /&gt;
GROUP BY l.eventname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists the users who have only logged into the site once===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, username, firstname, lastname, idnumber&lt;br /&gt;
FROM prefix_user&lt;br /&gt;
WHERE prefix_user.deleted = 0&lt;br /&gt;
AND prefix_user.lastlogin = 0 &lt;br /&gt;
AND prefix_user.lastaccess &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Students in all courses of some institute===&lt;br /&gt;
What is the status (deleted or not) of all Students (roleid = 5) in all courses of some Institute&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname, u.firstname, u.lastname, u.deleted&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND u.institution = &#039;please enter school name here&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Full User info (for deleted users)===&lt;br /&gt;
Including extra custom profile fields (from prefix_user_info_data)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT * &lt;br /&gt;
FROM prefix_user as u &lt;br /&gt;
JOIN prefix_user_info_data as uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_user_info_field as uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;class&#039;)&lt;br /&gt;
WHERE `deleted` = &amp;quot;1&amp;quot; and `institution`=&amp;quot;your school name&amp;quot; and `department` = &amp;quot;your department&amp;quot; and `data` = &amp;quot;class level and number&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User&#039;s courses===&lt;br /&gt;
change &amp;quot;u.id = 2&amp;quot; with a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, c.id, c.fullname&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE u.id = 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Users with extra info (email) in current course===&lt;br /&gt;
blocks/configurable_reports replaces %%COURSEID%% with course id.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, u.email&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Students with enrollment and completion dates in current course===&lt;br /&gt;
This is meant to be a &amp;quot;global&amp;quot; report in Configurable Reports containing the following:&lt;br /&gt;
firstname, lastname, idnumber, institution, department, email, student enrolment date, student completion date&lt;br /&gt;
Note: for PGSQL, use to_timestamp() instead of FROM_UNIXTIME()&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.firstname&lt;br /&gt;
, u.lastname&lt;br /&gt;
, u.idnumber&lt;br /&gt;
, u.institution&lt;br /&gt;
, u.department&lt;br /&gt;
, u.email&lt;br /&gt;
, FROM_UNIXTIME(cc.timeenrolled)&lt;br /&gt;
, FROM_UNIXTIME(cc.timecompleted)&lt;br /&gt;
&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_completions AS cc ON cc.course = c.id AND cc.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Special Roles===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.roleid,r.name&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,ra.userid,&#039;&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Username&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON (ctx.id = ra.contextid AND ctx.contextlevel = 50)&lt;br /&gt;
JOIN prefix_course AS c ON ctx.instanceid = c.id&lt;br /&gt;
WHERE ra.roleid &amp;gt; 6&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses without Teachers===&lt;br /&gt;
Actually, shows the number of Teachers in a course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Teachers&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
ORDER BY Teachers ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of users who have been enrolled for more than 4 weeks===&lt;br /&gt;
For Moodle 2.2 , by  Isuru Madushanka Weerarathna &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT uenr.userid As User, IF(enr.courseid=uenr.courseid ,&#039;Y&#039;,&#039;N&#039;) As Enrolled, &lt;br /&gt;
IF(DATEDIFF(NOW(), FROM_UNIXTIME(uenr.timecreated))&amp;gt;=28,&#039;Y&#039;,&#039;N&#039;) As EnrolledMoreThan4Weeks&lt;br /&gt;
FROM prefix_enrol As enr, prefix_user_enrolments AS uenr&lt;br /&gt;
WHERE enr.id = uenr.enrolid AND enr.status = uenr.status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with language===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 (in the U.S., Canada and the Americas) is changing the default English to United States English. &lt;br /&gt;
&lt;br /&gt;
This will show you the language setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, lang from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools.&lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;en&#039; to &#039;en_us&#039; for all users:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To do this for only users who have a particular country set, use this as an example:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE country = &#039;US&#039; AND lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with Authentication ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Sometimes you need to do mass changes of authentication methods. A common case is changing default manual to LDAP. &lt;br /&gt;
&lt;br /&gt;
This will show you the Authentication setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, auth from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools. &lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;manual&#039; to &#039;ldap&#039; 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.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET auth = &#039;ldap&#039; WHERE auth = &#039;manual&#039; AND id &amp;gt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compare role capability and permissions ===&lt;br /&gt;
Compatibility: MySQL and PostgreSQL&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT mrc.capability &lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;1&#039; AND rc.contextid = &#039;1&#039;) AS Manager&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;2&#039; AND rc.contextid = &#039;1&#039;) AS Course_Creator&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;3&#039; AND rc.contextid = &#039;1&#039;) AS Teacher&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;4&#039; AND rc.contextid = &#039;1&#039;) AS Assistant_Teacher&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;5&#039; AND rc.contextid = &#039;1&#039;) AS Student&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;6&#039; AND rc.contextid = &#039;1&#039;) AS Guest&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;7&#039; AND rc.contextid = &#039;1&#039;) AS Authenticated&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;8&#039; AND rc.contextid = &#039;1&#039;) AS Auth_front&lt;br /&gt;
FROM prefix_role_capabilities AS mrc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User&#039;s accumulative time spent in course ===&lt;br /&gt;
A sum up of the time delta between logstore_standard_log user&#039;s records, considering the a 2 hour session limit.&lt;br /&gt;
&lt;br /&gt;
Uses: current user&#039;s id %%USERID%% and current course&#039;s id %%COURSEID%%  &lt;br /&gt;
&lt;br /&gt;
And also using a date filter (which can be ignored)  &lt;br /&gt;
&lt;br /&gt;
The extra &amp;quot;User&amp;quot; field is used as a dummy field for the Line chart Series field, in which I use X=id, Series=Type, Y=delta.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
l.id, &lt;br /&gt;
l.timecreated, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(l.timecreated),&#039;%d-%m-%Y&#039;) AS dTime,&lt;br /&gt;
@prevtime := (SELECT max(timecreated) FROM mdl_logstore_standard_log &lt;br /&gt;
		WHERE userid = %%USERID%% and id &amp;lt; l.id ORDER BY id ASC LIMIT 1) AS prev_time,&lt;br /&gt;
IF (l.timecreated - @prevtime &amp;lt; 7200, @delta := @delta + (l.timecreated-@prevtime),0) AS sumtime,&lt;br /&gt;
l.timecreated-@prevtime AS delta,&lt;br /&gt;
&amp;quot;User&amp;quot; as type&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log as l, &lt;br /&gt;
(SELECT @delta := 0) AS s_init &lt;br /&gt;
# Change UserID&lt;br /&gt;
WHERE l.userid = %%USERID%% AND l.courseid = %%COURSEID%%&lt;br /&gt;
%%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Low-Participation Student Report ===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
This report returns a list of students who are enrolled in courses filtered by a short-name text marker (in this case &amp;quot;OL-&amp;quot;) in the specified category, but have very low participation in the course during the specified time period (fewer than 2 &amp;quot;Edits&amp;quot; to Activity Modules, indicating few active contributions to the course). The number of &amp;quot;Edits&amp;quot; is provided for each student for the time period specified.&lt;br /&gt;
&lt;br /&gt;
An &amp;quot;Edit&amp;quot; is defined as course activity other than viewing content. Click the &amp;quot;Logs&amp;quot; link to review the student activity. The Logs offer the option to review &amp;quot;View&amp;quot; activity as well as &amp;quot;Edit&amp;quot; activity.&lt;br /&gt;
&lt;br /&gt;
Only &amp;quot;visible&amp;quot; courses are included in this report. The report may be downloaded as an Excel spreadsheet.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t forget to set up Filters: &amp;quot;Start / End date filter&amp;quot; and &amp;quot;Filter categories&amp;quot; on the Filters tab in Configurable reports.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname AS Last, u.firstname AS First, u.idnumber AS IDnumber, u.email AS email, c.shortname AS CourseID,  count(l.id) AS Edits, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;https://learn.granite.edu/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=-view&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id AND l.action NOT LIKE &amp;quot;view%&amp;quot; %%FILTER_STARTTIME:l.TIME:&amp;gt;%% %%FILTER_ENDTIME:l.TIME:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.visible=1&lt;br /&gt;
# This prefix filter allows the exclusion of non-online courses at the original institution. Alter this to fit your institution, or remove it.&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
%%FILTER_CATEGORIES:c.category%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
HAVING Edits &amp;lt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Messages of All Users in a Specific Course ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
NOTE: I have deleted this query since it has not worked since 3.5 due to the changes in the structure of the Messages database in that version. If you really need this query for Moodle 3.4 or earlier (please upgrade!), then take a look at the earlier versions of this page for your particular version of Moodle. - RT&lt;br /&gt;
&lt;br /&gt;
===List of attendees/students that were marked present across courses===&lt;br /&gt;
This report will pull all Present students across a specific category.  &lt;br /&gt;
Contributed by: Emma Richardson&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &amp;quot;First Name&amp;quot;, u.lastname AS &amp;quot;Last Name&amp;quot;, u.Institution AS &amp;quot;District&amp;quot;,c.fullname AS &amp;quot;Training&amp;quot;, DATE_FORMAT(FROM_UNIXTIME(att.sessdate),&#039;%d %M %Y&#039;)AS Date&lt;br /&gt;
&lt;br /&gt;
FROM prefix_attendance_sessions AS att&lt;br /&gt;
JOIN prefix_attendance_log AS attlog ON att.id = attlog.sessionid&lt;br /&gt;
JOIN prefix_attendance_statuses AS attst ON attlog.statusid = attst.id&lt;br /&gt;
JOIN prefix_attendance AS a ON att.attendanceid = a.id&lt;br /&gt;
JOIN prefix_course AS c ON a.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON attlog.studentid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE attst.acronym = &amp;quot;P&amp;quot;&lt;br /&gt;
AND c.category = INSERT YOUR CATEGORY ID HERE&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Log Activity Reports==&lt;br /&gt;
===Count all Active Users by ROLE in a course category (including all of its sub-categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT l.userid) as active&lt;br /&gt;
FROM mdl_course as c&lt;br /&gt;
JOIN mdl_context AS ctx ON  ctx.instanceid=c.id&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN mdl_user_lastaccess as l ON ra.userid = l.userid&lt;br /&gt;
JOIN mdl_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category=cats.id AND (&lt;br /&gt;
	cats.path LIKE &#039;%/80/%&#039;&lt;br /&gt;
	OR cats.path LIKE &#039;%/80&#039;&lt;br /&gt;
) &lt;br /&gt;
AND ra.roleid=3  AND ctx.contextlevel=50  #ra.roleid= TEACHER 3, NON-EDITING TEACHER 4, STUDENT 5&lt;br /&gt;
AND  l.timeaccess &amp;gt; (unix_timestamp() - ((60*60*24)*NO_OF_DAYS)) #NO_OF_DAYS change to number&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Detailed &amp;quot;VIEW&amp;quot; ACTION for each ROLE (TEACHER,NONE-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT l.action, count( l.userid ) as counter , r.name&lt;br /&gt;
FROM `prefix_log` as l&lt;br /&gt;
JOIN `prefix_role_assignments` AS ra on l.userid = ra.userid&lt;br /&gt;
JOIN `prefix_role` AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE (ra.roleid IN (3,4,5)) AND (l.action LIKE &#039;%view%&#039; )&lt;br /&gt;
GROUP BY roleid,l.action&lt;br /&gt;
order by r.name,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total Activity of Roles:&amp;quot;Teacher&amp;quot; and &amp;quot;None-Editing Teacher&amp;quot; by Dates and by Hours===&lt;br /&gt;
The output columns of this report table can be used as base for a Pivot-Table&lt;br /&gt;
which will show the amount of &#039;&#039;&#039;activity&#039;&#039;&#039; per &#039;&#039;&#039;hour&#039;&#039;&#039; per &#039;&#039;&#039;days&#039;&#039;&#039; in 3D graph view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%Y-%m-%d&#039; ) AS grptimed ,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%k&#039; ) AS grptimeh  , count( l.userid ) AS counter &lt;br /&gt;
FROM `prefix_log` AS l&lt;br /&gt;
JOIN prefix_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
WHERE ra.roleid IN (3,4)&lt;br /&gt;
GROUP BY grptimed,grptimeh&lt;br /&gt;
ORDER BY grptimed,grptimeh&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many LOGINs per user and user&#039;s Activity===&lt;br /&gt;
+ link username to a user activity graph report&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,u.id,&#039;&amp;amp;mode=alllogs&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) as Username&lt;br /&gt;
,count(*) as logins&lt;br /&gt;
,(SELECT count(*) FROM prefix_log WHERE userid = l.userid GROUP BY userid) as Activity &lt;br /&gt;
FROM prefix_log as l JOIN prefix_user as u ON l.userid = u.id &lt;br /&gt;
WHERE `action` LIKE &#039;%login%&#039; group by userid&lt;br /&gt;
ORDER BY Activity DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Distinct user logins per month===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
The following will show you the months of the current calendar year with the total number of distinct, unique user logins per month. Change the year in the WHERE clause to the year you need.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
 COUNT(DISTINCT l.userid) AS &#039;DistinctUserLogins&#039;, &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%M&#039;) AS &#039;Month&#039;&lt;br /&gt;
FROM prefix_logstore_standard_log l&lt;br /&gt;
WHERE l.action = &#039;loggedin&#039; AND YEAR(FROM_UNIXTIME(l.timecreated)) = &#039;2017&#039; &lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(l.timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total activity per course, per unique user on the last 24h===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    COUNT(DISTINCT userid) AS countUsers&lt;br /&gt;
  , COUNT(l.courseid) AS countVisits&lt;br /&gt;
  , CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
  JOIN mdl_course AS c ON c.id = l.courseid&lt;br /&gt;
WHERE l.courseid &amp;gt; 0&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 1 DAY)&lt;br /&gt;
      AND c.fullname LIKE &#039;%תשעו%&#039;&lt;br /&gt;
GROUP BY l.courseid&lt;br /&gt;
ORDER BY countVisits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Instructor Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of instructors in all courses per week of a term, including pre-term and post-term edits. An edit is defined as a change to the course, such as a discussion post, the grading of an assignment, or the uploading of file attachments, as well as alterations to course content.&lt;br /&gt;
&lt;br /&gt;
* To specify a subject and/or course number, use % as a wildcard, e.g. ARTS% or ARTS501%&lt;br /&gt;
* To match part of a last name, use %, e.g. Smi% will match &amp;quot;Smith&amp;quot;, &amp;quot;Smile&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
At our institution, we include filters on the course name or category to constrain by terms. These are very specific to how course names and categories are constructed at our institution, so I&#039;ve removed those elements from this code. Also, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; lines for longer terms, or remove lines for shorter terms.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version uses legacy (pre-2.7) logs. See below for post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, c.startdate AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time)) - WEEK(FROM_UNIXTIME(c.startdate))&amp;lt;0,1,0)) AS BeforeTerm&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=0,1,0)) AS Week1&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=1,1,0)) AS Week2&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=2,1,0)) AS Week3&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=3,1,0)) AS Week4&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=4,1,0)) AS Week5&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=5,1,0)) AS Week6&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=6,1,0)) AS Week7&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=7,1,0)) AS Week8&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=8,1,0)) AS Week9&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=9,1,0)) AS Week10&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=10,1,0)) AS Week11&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=11,1,0)) AS Week12&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))&amp;gt;=12,1,0)) AS AfterTerm&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE :course&lt;br /&gt;
AND u.lastname LIKE :last_name&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 log version:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(DISTINCT l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
AND cc.idnumber LIKE &#039;%current%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
#HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY RIGHT(c.shortname,2), c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Student Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of students in the current course by week, including pre-term and post-term edits. An 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 (if permitted).&lt;br /&gt;
&lt;br /&gt;
Links to three other reports are also provided:&lt;br /&gt;
&lt;br /&gt;
* Logs: complete log entries for the student in the course, organized by date&lt;br /&gt;
* Activity Outline: the &amp;quot;Outline Report&amp;quot; from the User Activity Reports, summarizing the student&#039;s activity in the course, organized by course content&lt;br /&gt;
* Consolidated Activity Report: the &amp;quot;Complete Report&amp;quot; from the User Activity Reports, detailing the student&#039;s activity in the course, organized by course content (includes text of forum posts)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). At our institution, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for a post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF((l.time-c.startdate)/7&amp;lt;0,1,0)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=0,1,0)) AS &#039;Week 1&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=1,1,0)) AS &#039;Week 2&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=2,1,0)) AS &#039;Week 3&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=3,1,0)) AS &#039;Week 4&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=4,1,0)) AS &#039;Week 5&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=5,1,0)) AS &#039;Week 6&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=6,1,0)) AS &#039;Week 7&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=7,1,0)) AS &#039;Week 8&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=8,1,0)) AS &#039;Week 9&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=9,1,0)) AS &#039;Week 10&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=10,1,0)) AS &#039;Week 11&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=11,1,0)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))&amp;gt;=15,1,0)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 (Standard Logs) version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
# Our institution stores academic advisor names and emails in custom profile fields&lt;br /&gt;
#, CONCAT(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,uce.data,&#039;&amp;quot;&amp;gt;&#039;,uid.data, &#039;&amp;lt;/a&amp;gt;&#039;)  AS &#039;Academic Advisor&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,&#039;Posts&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Posts&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# student academic coach - you can include custom profile field data with these methods&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uid ON u.id = uid.userid AND uid.fieldid = &#039;2&#039;&lt;br /&gt;
# student academic coach email&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uce on u.id = uce.userid AND uce.fieldid = &#039;6&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===My Weekly Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of the &#039;&#039;&#039;current user&#039;&#039;&#039; in the &#039;&#039;&#039;current course&#039;&#039;&#039; 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).&lt;br /&gt;
&lt;br /&gt;
This report uses Standard Logs (post 2.7).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
l.component AS &#039;activity&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS &#039;Total&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE 1&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
AND u.id = %%USERID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY l.component&lt;br /&gt;
&lt;br /&gt;
ORDER BY l.component&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Faculty/Student Interactions===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Returns a count of instructor and other-student responses to student activity for the specified time period. This report can help indicate whether students&#039; comments are being responded to, as well as summarizing post activity by students during the specified time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for the post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This report can take a long time to run. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
LEFT JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
# We care about messages that involve both the instructor and students of this course&lt;br /&gt;
# messages from instructor to students:&lt;br /&gt;
# LEFT JOIN prefix_message AS mts ON mts.useridfrom = instr.id AND mts.useridto = allstu.id&lt;br /&gt;
# LEFT JOIN prefix_message AS mfs ON mfs.useridfrom = instr.id AND mfs.useridto = allstu.id&lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 Standard Logs version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
 JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student Resource Usage===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Standard Logs&amp;quot; from Moodle 2.7+.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
, m.name AS &#039;item type&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&lt;br /&gt;
COALESCE(a.name, &#039;&#039;), &lt;br /&gt;
COALESCE(b.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cert.name,&#039;&#039;), &lt;br /&gt;
COALESCE(chat.name,&#039;&#039;), &lt;br /&gt;
COALESCE(choice.name,&#039;&#039;), &lt;br /&gt;
COALESCE(data.name,&#039;&#039;), &lt;br /&gt;
COALESCE(feedback.name,&#039;&#039;), &lt;br /&gt;
COALESCE(folder.name,&#039;&#039;), &lt;br /&gt;
COALESCE(forum.name,&#039;&#039;), &lt;br /&gt;
COALESCE(glossary.name,&#039;&#039;), &lt;br /&gt;
COALESCE(imscp.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lesson.name,&#039;&#039;), &lt;br /&gt;
COALESCE(p.name,&#039;&#039;),&lt;br /&gt;
COALESCE(questionnaire.name,&#039;&#039;), &lt;br /&gt;
COALESCE(quiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cr.name,&#039;&#039;), &lt;br /&gt;
COALESCE(scorm.name,&#039;&#039;), &lt;br /&gt;
COALESCE(survey.name,&#039;&#039;), &lt;br /&gt;
COALESCE(url.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(workshop.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kalvidassign.name,&#039;&#039;), &lt;br /&gt;
COALESCE(attendance.name,&#039;&#039;), &lt;br /&gt;
COALESCE(checklist.name,&#039;&#039;), &lt;br /&gt;
COALESCE(flashcard.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lti.name,&#039;&#039;), &lt;br /&gt;
COALESCE(oublog.name,&#039;&#039;), &lt;br /&gt;
COALESCE(ouwiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(subpage.name,&#039;&#039;), &lt;br /&gt;
COALESCE(journal.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lightboxgallery.name,&#039;&#039;), &lt;br /&gt;
COALESCE(elluminate.name,&#039;&#039;), &lt;br /&gt;
COALESCE(adaptivequiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(hotpot.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiziq.name,&#039;&#039;), &lt;br /&gt;
COALESCE(turnitintooltwo.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kvr.name,&#039;&#039;)&lt;br /&gt;
) AS &#039;item name&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;r&#039;),1,0)) AS &#039;total views&#039;&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),1,0)) AS &#039;total submissions&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;r&#039;),u.id,NULL)) AS &#039;count of students who viewed&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),u.id,NULL)) AS &#039;count of students who submitted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 #AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module AND m.name NOT LIKE &#039;label&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON a.id = cm.instance AND m.name = &#039;assign&#039;&lt;br /&gt;
LEFT JOIN prefix_book AS b ON b.id = cm.instance AND m.name = &#039;book&#039;&lt;br /&gt;
LEFT JOIN prefix_certificate AS cert ON cert.id = cm.instance AND m.name = &#039;certificate&#039;&lt;br /&gt;
LEFT JOIN prefix_chat AS chat ON chat.id = cm.instance AND m.name = &#039;chat&#039;&lt;br /&gt;
LEFT JOIN prefix_choice AS choice ON choice.id = cm.instance AND m.name = &#039;choice&#039;&lt;br /&gt;
LEFT JOIN prefix_data AS data ON data.id = cm.instance AND m.name = &#039;data&#039;&lt;br /&gt;
LEFT JOIN prefix_feedback AS feedback ON feedback.id = cm.instance AND m.name = &#039;feedback&#039;&lt;br /&gt;
LEFT JOIN prefix_folder AS folder ON folder.id = cm.instance AND m.name = &#039;folder&#039;&lt;br /&gt;
LEFT JOIN prefix_forum AS forum ON forum.id = cm.instance AND m.name = &#039;forum&#039;&lt;br /&gt;
LEFT JOIN prefix_glossary AS glossary ON glossary.id = cm.instance AND m.name = &#039;glossary&#039;&lt;br /&gt;
LEFT JOIN prefix_imscp AS imscp ON imscp.id = cm.instance AND m.name = &#039;imscp&#039;&lt;br /&gt;
LEFT JOIN prefix_lesson AS lesson ON lesson.id = cm.instance AND m.name = &#039;lesson&#039;&lt;br /&gt;
LEFT JOIN prefix_page AS p ON p.id = cm.instance AND m.name = &#039;page&#039;&lt;br /&gt;
LEFT JOIN prefix_questionnaire AS questionnaire ON questionnaire.id = cm.instance AND m.name = &#039;questionnaire&#039;&lt;br /&gt;
LEFT JOIN prefix_quiz AS quiz ON quiz.id = cm.instance AND m.name = &#039;quiz&#039;&lt;br /&gt;
LEFT JOIN prefix_resource AS cr ON cr.id = cm.instance AND m.name = &#039;resource&#039;&lt;br /&gt;
LEFT JOIN prefix_scorm AS scorm ON scorm.id = cm.instance AND m.name = &#039;scorm&#039;&lt;br /&gt;
LEFT JOIN prefix_survey AS survey ON survey.id = cm.instance AND m.name = &#039;survey&#039;&lt;br /&gt;
LEFT JOIN prefix_url AS url ON url.id = cm.instance AND m.name = &#039;url&#039;&lt;br /&gt;
LEFT JOIN prefix_wiki AS wiki ON wiki.id = cm.instance AND m.name = &#039;wiki&#039;&lt;br /&gt;
LEFT JOIN prefix_workshop AS workshop ON workshop.id = cm.instance AND m.name = &#039;workshop&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidassign AS kalvidassign ON kalvidassign.id = cm.instance AND m.name = &#039;kalvidassign&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidres AS kvr ON kvr.id = cm.instance AND m.name = &#039;kalvidres&#039;&lt;br /&gt;
LEFT JOIN prefix_attendance AS attendance ON attendance.id = cm.instance AND m.name = &#039;attendance&#039;&lt;br /&gt;
LEFT JOIN prefix_checklist AS checklist ON checklist.id = cm.instance AND m.name = &#039;checklist&#039;&lt;br /&gt;
LEFT JOIN prefix_flashcard AS flashcard ON flashcard.id = cm.instance AND m.name = &#039;flashcard&#039;&lt;br /&gt;
LEFT JOIN prefix_lti AS lti ON lti.id = cm.instance AND m.name = &#039;lti&#039;&lt;br /&gt;
LEFT JOIN prefix_oublog AS oublog ON oublog.id = cm.instance AND m.name = &#039;oublog&#039;&lt;br /&gt;
LEFT JOIN prefix_ouwiki AS ouwiki ON ouwiki.id = cm.instance AND m.name = &#039;ouwiki&#039;&lt;br /&gt;
LEFT JOIN prefix_subpage AS subpage ON subpage.id = cm.instance AND m.name = &#039;subpage&#039;&lt;br /&gt;
LEFT JOIN prefix_journal AS journal ON journal.id = cm.instance AND m.name = &#039;journal&#039;&lt;br /&gt;
LEFT JOIN prefix_lightboxgallery AS lightboxgallery ON lightboxgallery.id = cm.instance AND m.name = &#039;lightboxgallery&#039;&lt;br /&gt;
LEFT JOIN prefix_elluminate AS elluminate ON elluminate.id = cm.instance AND m.name = &#039;elluminate&#039;&lt;br /&gt;
LEFT JOIN prefix_adaptivequiz AS adaptivequiz ON adaptivequiz.id = cm.instance AND m.name = &#039;adaptivequiz&#039;&lt;br /&gt;
LEFT JOIN prefix_hotpot AS hotpot ON hotpot.id = cm.instance AND m.name = &#039;hotpot&#039;&lt;br /&gt;
LEFT JOIN prefix_wiziq AS wiziq ON wiziq.id = cm.instance AND m.name = &#039;wiziq&#039;&lt;br /&gt;
LEFT JOIN prefix_turnitintooltwo AS turnitintooltwo ON turnitintooltwo.id = cm.instance AND m.name = &#039;turnitintooltwo&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cm.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Hits) between dates===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module, COUNT( * ) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME( l.`timecreated` ) BETWEEN  &#039;2018-10-01 00:00:00&#039; AND  &#039;2019-09-31 00:00:00&#039;)&lt;br /&gt;
GROUP BY module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Instances and Hits) for each academic year===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2017-10-01 00:00:00&#039; AND &#039;2018-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2017&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2017-10-01 00:00:00&#039; AND &#039;2018-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2017&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2018-10-01 00:00:00&#039; AND &#039;2019-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2018&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2018-10-01 00:00:00&#039; AND &#039;2019-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2018&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2019-10-01 00:00:00&#039; AND &#039;2020-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2019&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2019-10-01 00:00:00&#039; AND &#039;2020-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2019&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_modules AS m&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Unique user sessions per day and month + graph===&lt;br /&gt;
The &amp;quot;graph&amp;quot; column is used when displaying a graph (which needs at least three columns to pick from)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT userid) AS &amp;quot;Unique User Logins&amp;quot;&lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y /%m / %d&amp;quot;) AS &amp;quot;Year / Month / Day&amp;quot;, &amp;quot;Graph&amp;quot; &lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE action LIKE &#039;loggedin&#039;&lt;br /&gt;
#AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) # optional start date&lt;br /&gt;
#AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:00&#039;) # optional end date&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And...&lt;br /&gt;
&lt;br /&gt;
Counting user&#039;s global and unique hits per day + counting individual usage of specific activities and resources (on that day),&lt;br /&gt;
&lt;br /&gt;
And since I am using phpMyAdmin&#039;s &amp;quot;Display Graph&amp;quot; feature (at the bottom of the query&#039;s output page), I have scaled down the &amp;quot;User Hits&amp;quot; by 10 to fit the graph. that&#039;s it.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y-%m-%d&amp;quot;) AS &amp;quot;Datez&amp;quot;&lt;br /&gt;
,COUNT(DISTINCT userid) AS &amp;quot;Unique Users&amp;quot;&lt;br /&gt;
,ROUND(COUNT(*)/10) &amp;quot;User Hits (K)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_quiz&#039;,1,0)) &amp;quot;Quizzes&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_forum&#039; or component=&#039;mod_forumng&#039;,1,0)) &amp;quot;Forums&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_assign&#039;,1,0)) &amp;quot;Assignments&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_oublog&#039;,1,0)) &amp;quot;Blogs&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_resource&#039;,1,0)) &amp;quot;Files (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_url&#039;,1,0)) &amp;quot;Links (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_page&#039;,1,0)) &amp;quot;Pages (Resource)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE 1=1&lt;br /&gt;
AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-03-01 00:00:00&#039;) # optional START DATE&lt;br /&gt;
AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-05-31 23:59:00&#039;) # optional END DATE&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide, daily unique user hits for the last 7 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
  DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%m%d&#039;) &#039;Day&#039;&lt;br /&gt;
  ,COUNT(DISTINCT l.userid) AS &#039;Distinct Users Hits&#039;&lt;br /&gt;
  ,COUNT( l.userid) AS &#039;Users Hits&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE l.courseid &amp;gt; 1&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 7 DAY)&lt;br /&gt;
GROUP BY DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User detailed activity in course modules===&lt;br /&gt;
Considering only several modules: url, resource, forum, quiz, questionnaire.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.id, ra.roleid,&lt;br /&gt;
CONCAT(u.lastname, &#039; &#039;, u.firstname) AS &#039;Student&#039;&lt;br /&gt;
,COUNT(l.id) AS &#039;Actions&#039;&lt;br /&gt;
,l.component &amp;quot;Module type&amp;quot;&lt;br /&gt;
,l.objectid &amp;quot;Module ID&amp;quot;&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN l.component = &#039;mod_url&#039; THEN (SELECT u.name FROM prefix_url AS u WHERE u.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_resource&#039; THEN (SELECT r.name FROM prefix_resource AS r WHERE r.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_forum&#039; THEN (SELECT f.name FROM prefix_forum AS f WHERE f.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_quiz&#039; THEN (SELECT q.name FROM prefix_quiz AS q WHERE q.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_questionnaire&#039; THEN (SELECT q.name FROM prefix_questionnaire AS q WHERE q.id = l.objectid )&lt;br /&gt;
END AS &#039;Module name&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM prefix_groups AS g&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid WHERE g.courseid = l.courseid AND m.userid = u.id) &amp;quot;user_groups&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT s.name &lt;br /&gt;
  FROM prefix_course_modules AS cm &lt;br /&gt;
  JOIN prefix_course_sections AS s ON s.course = cm.course AND s.id = cm.section &lt;br /&gt;
  WHERE cm.id = l.contextinstanceid) AS &amp;quot;Section name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log AS l  &lt;br /&gt;
JOIN prefix_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = l.userid &lt;br /&gt;
  AND ra.contextid = (SELECT id FROM prefix_context WHERE instanceid = l.courseid AND contextlevel = 50) &lt;br /&gt;
WHERE l.courseid = %%COURSEID%%&lt;br /&gt;
  AND l.component IN (&#039;mod_url&#039;, &#039;mod_resource&#039;, &#039;mod_forum&#039;, &#039;mod_quiz&#039;, &#039;mod_questionnaire&#039;) &lt;br /&gt;
  %%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%%&lt;br /&gt;
 &lt;br /&gt;
GROUP BY u.id, l.component&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What teachers and courses considered active?===&lt;br /&gt;
This report display several calculations and parameters that help the Online academic training team find teachers that might need more support getting their courses more supporting of online learning pedagogical methodologies.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,&lt;br /&gt;
			  course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
#,course.shortname&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2012%&#039; THEN &#039;2012&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2013%&#039; THEN &#039;2013&#039; &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2014%&#039; THEN &#039;2014&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2015%&#039; THEN &#039;2015&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester a%&#039; THEN &#039;Spring semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester b%&#039; THEN &#039;Fall semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester s%&#039; THEN &#039;Summer semester&#039;&lt;br /&gt;
END AS Semester&lt;br /&gt;
&lt;br /&gt;
,IF(course.startdate&amp;gt;0, DATE_FORMAT(FROM_UNIXTIME(startdate), &#039;%d-%m-%Y&#039;), &#039;no date&#039;) AS &amp;quot;Course Start Date&amp;quot; &lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 4 AND ctx.instanceid = course.id&lt;br /&gt;
) AS &amp;quot;Assistant teacher&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
&lt;br /&gt;
# Uncomment to use the new Moodle 2.8+ logstore&lt;br /&gt;
#,(SELECT COUNT(*) FROM mdl_logstore_standard_log AS l WHERE l.courseid = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Student HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Teacher HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_log AS l WHERE l.course = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course c&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = c.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND c.id = course.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
  &lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = course.id) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(DISTINCT cm.module) FROM prefix_course_modules cm &lt;br /&gt;
  WHERE cm.course = course.id) UniqueModules&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(DISTINCT m.name) &lt;br /&gt;
  FROM prefix_course_modules cm &lt;br /&gt;
  JOIN mdl_modules as m ON m.id = cm.module&lt;br /&gt;
  WHERE cm.course = course.id) UniqueModuleNames&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;ouwiki&#039;, &#039;wiki&#039;) ) &amp;quot;Num Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;oublog&#039;) ) &amp;quot;Num Blogs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;forum&#039;, &#039;forumng&#039;) ) &amp;quot;Num Forums&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;resource&#039;, &#039;folder&#039;, &#039;url&#039;, &#039;tab&#039;, &#039;file&#039;, &#039;book&#039;, &#039;page&#039;) ) Resources&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;forum&#039;, &#039;forumng&#039;, &#039;oublog&#039;, &#039;page&#039;, &#039;file&#039;, &#039;url&#039;, &#039;wiki&#039; , &#039;ouwiki&#039;) ) &amp;quot;Basic Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;advmindmap&#039;, &#039;assign&#039;, &#039;attendance&#039;, &#039;book&#039;, &#039;choice&#039;, &#039;folder&#039;, &#039;tab&#039;, &#039;glossary&#039;, &#039;questionnaire&#039;, &#039;quiz&#039;, &#039;label&#039; ) ) &amp;quot;Avarage Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;elluminate&#039;, &#039;game&#039;, &#039;workshop&#039;) ) &amp;quot;Advanced Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course&lt;br /&gt;
&lt;br /&gt;
#WHERE course.shortname LIKE &#039;%2015%&#039;&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_SEARCHTEXT:course.shortname:~%%&lt;br /&gt;
&lt;br /&gt;
WHERE course.fullname LIKE &#039;%2015%&#039; &lt;br /&gt;
&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY UniqueModules DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly attendance report===&lt;br /&gt;
This report display weekly report in format HH:M:SS This MySQL query works together with AttendaceRegister module, and gather Log information from Attendanceregister_log table. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, SEC_TO_TIME (SUM(arsess.duration)) AS weekly_online_attendance,  FROM_UNIXTIME (arsess.logout) AS Last_Logout&lt;br /&gt;
FROM prefix_attendanceregister_session AS arsess&lt;br /&gt;
JOIN prefix_user AS u ON arsess.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE (((arsess.logout) BETWEEN UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 7 DAY)) AND UNIX_TIMESTAMP(CURDATE())))&lt;br /&gt;
&lt;br /&gt;
GROUP BY arsess.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many distinct users connected to Moodle using the app by month===&lt;br /&gt;
https://moodle.org/mod/forum/discuss.php?d=336086#p1354194 by &lt;br /&gt;
Iñigo Zendegi Urzelai&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;) as year, &lt;br /&gt;
  to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;) as month, &lt;br /&gt;
  count(distinct userid) as distinct_users&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log l&lt;br /&gt;
WHERE l.origin=&#039;ws&#039;&lt;br /&gt;
GROUP BY to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;), to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;) &lt;br /&gt;
ORDER BY to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;), to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Course Reports==&lt;br /&gt;
===Most Active courses===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(l.userid) AS Views&lt;br /&gt;
FROM `mdl_logstore_standard_log` l, `mdl_user` u, `mdl_role_assignments` r&lt;br /&gt;
WHERE l.courseid=35&lt;br /&gt;
AND l.userid = u.id&lt;br /&gt;
AND (l.timecreated &amp;gt; UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) AND l.timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:59&#039;))AND r.contextid= (&lt;br /&gt;
	 SELECT id&lt;br /&gt;
	 FROM mdl_context&lt;br /&gt;
	 WHERE contextlevel=50 AND instanceid=l.courseid&lt;br /&gt;
 )&lt;br /&gt;
AND r.roleid=5&lt;br /&gt;
AND r.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active courses, advanced===&lt;br /&gt;
Including: Teacher&#039;s name, link to the course, All types of log activities, special YEAR generated field, Activities and Resource count, enrolled Student count&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשע&#039; THEN &#039;תשע&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעא&#039; THEN &#039;תשעא&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעב&#039; THEN &#039;תשעב&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = l.course) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_log l &lt;br /&gt;
INNER JOIN prefix_course c ON l.course = c.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
#The following line restricts the courses returned to those having more than 2 modules.  Adjust based on your needs.&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY Year DESC, hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Least active or probably empty courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;-1&amp;quot; instead of &amp;quot;0&amp;quot; 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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
c.fullname,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;CourseLink&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timecreated&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timemodified&#039;,&lt;br /&gt;
CASE&lt;br /&gt;
 WHEN c.timecreated = c.timemodified THEN &#039;-1&#039;&lt;br /&gt;
 ELSE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated))&lt;br /&gt;
END AS &#039;DateDifference&#039;,&lt;br /&gt;
COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
LEFT JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
WHERE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated) ) &amp;lt; 60&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
HAVING COUNT(ue.id) &amp;lt;= 3&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Count unique teachers with courses that use at least X module (Moodle19)===&lt;br /&gt;
You can remove the outer &amp;quot;SELECT COUNT(*) FROM (...) AS ActiveTeachers&amp;quot; SQL query and get the list of the Teachers and Courses.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(*)&lt;br /&gt;
FROM (SELECT c.id AS CourseID, c.fullname AS Course, ra.roleid AS RoleID, CONCAT(u.firstname, &#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = c.id) AS Modules&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid AND ctx.contextlevel = 50 &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE  ra.roleid = 3 &lt;br /&gt;
GROUP BY u.id&lt;br /&gt;
HAVING Modules &amp;gt; 5) AS ActiveTeachers&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RESOURCE count for each COURSE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) count, l.course, c.fullname coursename&lt;br /&gt;
FROM prefix_resource l INNER JOIN prefix_course c on l.course = c.id&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY count DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Common resource types count for each Category (Moodle19)===&lt;br /&gt;
Including sub-categories in total count.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category&lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Links&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference NOT LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Files&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;directory&#039; &lt;br /&gt;
) AS Folders&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;html&#039; &lt;br /&gt;
) AS Pages&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM stats_log_context_role_course &lt;br /&gt;
WHERE roleid = 5 AND module = &#039;resource&#039; AND category = mcc.id&lt;br /&gt;
) AS Hits&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Where &amp;quot;stats_log_context_role_course&amp;quot; (in the above SQL query) is a VIEW generated by:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
CREATE VIEW stats_log_context_role_course AS&lt;br /&gt;
SELECT l.course, c.category, cc.path, l.module, l.action, ra.userid, ra.roleid&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = l.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Same query but for Moodle2+&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category,&lt;br /&gt;
mcc.path,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_url AS u&lt;br /&gt;
JOIN prefix_course AS c ON c.id = u.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS URLs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_folder AS f&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS FOLDERs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_page AS p&lt;br /&gt;
JOIN prefix_course AS c ON c.id = p.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS PAGEs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_book AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS BOOKs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_label AS l&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS LABELs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_tab AS t&lt;br /&gt;
JOIN prefix_course AS c ON c.id = t.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS TABs&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed Resource COUNT by Teacher in each course===&lt;br /&gt;
&lt;br /&gt;
Including (optional) filter by: year, semester and course id.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
, c.id&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעב%&#039; THEN &#039;2012&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעא%&#039; THEN &#039;2011&#039;&lt;br /&gt;
END ) as Year&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר א%&#039; THEN &#039;Semester A&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ב%&#039; THEN &#039;Semester B&#039;&lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ק%&#039; THEN &#039;Semester C&#039;&lt;br /&gt;
END ) as Semester&lt;br /&gt;
,COUNT(c.id) AS Total&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 20) AS TABs&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 33) AS BOOKs&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_resource` as r &lt;br /&gt;
JOIN `prefix_course` AS c on c.id = r.course&lt;br /&gt;
#WHERE type= &#039;file&#039; and reference NOT LIKE &#039;http://%&#039; &lt;br /&gt;
&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
#AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY COUNT(c.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses that are defined as using GROUPs===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/group/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = c.id) Modules&lt;br /&gt;
,(SELECT count(*) FROM prefix_groups g WHERE g.courseid = c.id) Groups&lt;br /&gt;
 FROM `prefix_course` AS c&lt;br /&gt;
WHERE groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Groups===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with Groups in them (groupmode &amp;gt; 0). You can also use groupmode=1 to list just Separate type groups or groupmode=2 to list Visible type groups.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name, c.groupmode&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON c.id = g.courseid&lt;br /&gt;
WHERE c.groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users enrolled in a course with groups but not assigned a group ===&lt;br /&gt;
&lt;br /&gt;
Displays by course all enrolled users that have not been assigned a group in courses that have groups. NOTE: This needs to be optimized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) AS ROLE&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = course.id&lt;br /&gt;
&lt;br /&gt;
WHERE ue.enrolid NOT IN (select userid from prefix_groups_members WHERE g.id=groupid)&lt;br /&gt;
&lt;br /&gt;
ORDER BY Course, Lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Groups in course with member list===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List the groups in a course (replace the # by the course id number) with the members of each group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name AS Groupname, u.username&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_user AS u ON m.userid = u.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Group Export===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
There&#039;s a [[Import_groups|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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT g.name AS groupname, g.description, g.enrolmentkey&lt;br /&gt;
FROM prefix_groups AS g &lt;br /&gt;
JOIN prefix_course as c ON g.courseid = c.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Courses in and below a certain category===&lt;br /&gt;
Use this SQL code to retrieve all courses that exist in or under a set category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the category you want to know about...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course. * , prefix_course_categories. *&lt;br /&gt;
FROM prefix_course, prefix_course_categories&lt;br /&gt;
WHERE prefix_course.category = prefix_course_categories.id&lt;br /&gt;
AND (&lt;br /&gt;
prefix_course_categories.path LIKE &#039;%/$s/%&#039;&lt;br /&gt;
OR prefix_course_categories.path LIKE &#039;%/$s&#039;&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Categories in one level below a certain category===&lt;br /&gt;
Use this PHP code to retrieve a list of all categories below a certain category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the top level category you are interested in.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
require_once(&#039;./config.php&#039;);&lt;br /&gt;
&lt;br /&gt;
$parent_id = $s;&lt;br /&gt;
&lt;br /&gt;
$categories= array();&lt;br /&gt;
&lt;br /&gt;
$categories = get_categories($parent_id);&lt;br /&gt;
&lt;br /&gt;
echo &#039;&amp;lt;ol&amp;gt;&#039;;&lt;br /&gt;
foreach ($categories as $category)&lt;br /&gt;
        {&lt;br /&gt;
        echo &#039;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&#039;.$CFG-&amp;gt;wwwroot.&#039;/course/category.php?id=&#039;.$category-&amp;gt;id.&#039;&amp;quot;&amp;gt;&#039;.$category-&amp;gt;name.&#039;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
        }&lt;br /&gt;
echo &#039;&amp;lt;/ol&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Blog activity per Course (not including VIEW)===&lt;br /&gt;
Filter activity logging to some specific Course Categories!&lt;br /&gt;
+ link course name to actual course (for quick reference)&lt;br /&gt;
(you can change %blog% to %wiki% to filter down all wiki activity or any other module you wish)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID&lt;br /&gt;
,m.name ,count(cm.id) as counter &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS Students&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE `module` LIKE &#039;%blog%&#039; AND course = c.id AND action NOT LIKE &#039;%view%&#039; ) as BlogActivity&lt;br /&gt;
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 &lt;br /&gt;
WHERE m.name LIKE &#039;%blog%&#039; AND c.category IN ( 8,13,15)&lt;br /&gt;
GROUP BY cm.course,cm.module order by counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student&#039;s posts content in all course blogs (oublog)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
b.name &lt;br /&gt;
,op.title&lt;br /&gt;
,op.message&lt;br /&gt;
,( SELECT CONCAT(u.firstname, &#039; &#039;,u.lastname) FROM prefix_user AS u WHERE u.id = oi.userid) AS &amp;quot;Username&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_oublog_posts AS op&lt;br /&gt;
JOIN prefix_oublog_instances AS oi ON oi.id = op.oubloginstancesid &lt;br /&gt;
JOIN prefix_oublog as b ON b.id = oi.oublogid&lt;br /&gt;
JOIN prefix_course AS c ON b.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Courses which uploaded a Syllabus file===&lt;br /&gt;
+ under specific Category&lt;br /&gt;
+ show first Teacher in that course&lt;br /&gt;
+ link Course&#039;s fullname to actual course&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) as Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user as u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) as Teacher&lt;br /&gt;
FROM prefix_resource as r &lt;br /&gt;
JOIN prefix_course as c ON r.course = c.id&lt;br /&gt;
WHERE ( r.name LIKE &#039;%סילבוס%&#039; OR r.name LIKE &#039;%סילאבוס%&#039; OR r.name LIKE &#039;%syllabus%&#039; OR r.name LIKE &#039;%תכנית הקורס%&#039; ) &lt;br /&gt;
AND c.category IN (10,18,26,13,28)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
===Site-wide completed SCORM activities by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===All users enrolled in a course without a role===&lt;br /&gt;
Identifies All users that are enrolled in a course but are not assigned a role.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user.firstname AS Firstname,&lt;br /&gt;
user.lastname AS Lastname,&lt;br /&gt;
user.idnumber Employee_ID,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user as user ON user.id = ue.userid&lt;br /&gt;
&lt;br /&gt;
WHERE user.id NOT IN (&lt;br /&gt;
SELECT u.id&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE c.id=course.id&lt;br /&gt;
)&lt;br /&gt;
ORDER BY Course, Lastname, Firstname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List course resources accumulative file size and count===&lt;br /&gt;
This is the main (first) report, which has a link (alias) to a second report (the following on this page) which list each file in the course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id &amp;quot;CourseID&amp;quot;, context.id &amp;quot;ContextID&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;, c.id, &#039;&amp;quot;&amp;gt;&#039;, c.fullname ,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Course Name&amp;quot;&lt;br /&gt;
, COUNT(*) &amp;quot;Course Files&amp;quot; , ROUND( SUM( f.filesize ) /1048576 ) AS file_size_MB&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/blocks/configurable_reports/viewreport.php?alias=coursefiles&amp;amp;courseid=1&amp;amp;filter_courses=&#039;, c.id, &#039;&amp;quot;&amp;gt;List files&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List Files&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
JOIN mdl_context AS context ON context.id = f.contextid&lt;br /&gt;
JOIN mdl_course AS c ON c.id = (&lt;br /&gt;
  SELECT instanceid&lt;br /&gt;
  FROM mdl_context&lt;br /&gt;
  WHERE id = SUBSTRING_INDEX( SUBSTRING_INDEX( context.path, &#039;/&#039; , -2 ) , &#039;/&#039;, 1 ) )&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this report, you will have to define &amp;quot;alias&amp;quot; report property to &amp;quot;coursefiles&amp;quot; for it to be able to be called from the above report.&lt;br /&gt;
And also setup (add) a FILTER_COURSES filter. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id ,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/pluginfile.php/&#039;, contextid, &#039;/&#039;, component, &#039;/&#039;, filearea, &#039;/&#039;, itemid, &#039;/&#039;, filename, &#039;&amp;quot;&amp;gt;&#039;, filename,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;File&amp;quot;&lt;br /&gt;
,filesize, mimetype ,author, license, timecreated, component, filearea, filepath&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
            AND f.contextid&lt;br /&gt;
            IN (   SELECT id&lt;br /&gt;
                     FROM mdl_context&lt;br /&gt;
                    WHERE path &lt;br /&gt;
                     LIKE (   SELECT CONCAT(&#039;%/&#039;,id,&#039;/%&#039;)&lt;br /&gt;
                                  AS contextquery&lt;br /&gt;
                                FROM mdl_context&lt;br /&gt;
                               WHERE 1=1&lt;br /&gt;
			        %%FILTER_COURSES:instanceid%%&lt;br /&gt;
                                 AND contextlevel = 50&lt;br /&gt;
                           )&lt;br /&gt;
                )&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Which courses has redundant topics===&lt;br /&gt;
This report list several &amp;quot;active topics&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
The following, second SQL query, could be used to &amp;quot;trim&amp;quot; down those redundant course topics/sections/weeks by updating the course format&#039;s numsection (Number of sections) setting. (It&#039;s a per course format setting!)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, format,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT value  FROM  `mdl_course_format_options` WHERE  `courseid` = c.id AND `format` = c.format AND `name` = &#039;numsections&#039; ) AS &amp;quot;numsections&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND `sequence` !=  &#039;&#039; ) AS &amp;quot;Non empty sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id ) AS &amp;quot;Total section count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND sequence IS NOT NULL) AS &amp;quot;Non NULL sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND name != &#039;&#039;) AS &amp;quot;Non empty section Name count&amp;quot;&lt;br /&gt;
 ,(SELECT COUNT(*) FROM mdl_course_modules cm WHERE cm.course = c.id) &amp;quot;Modules count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course AS c&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following SQL REPLACE query is used for &amp;quot;fixing&amp;quot; (updating) the &amp;quot;numsections&amp;quot; of a specific course format &amp;quot;onetopics&amp;quot; (you can always change it, or discard it to use this SQL REPLACE on all course formats) &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
REPLACE INTO `mdl_course_format_options` (`id`, `courseid`, `format`, `sectionid`, `name`, `value`) &lt;br /&gt;
SELECT NULL, c.id, &#039;onetopic&#039;, &#039;0&#039;, &#039;numsections&#039;, (SELECT COUNT(*) FROM `mdl_course_sections` WHERE `course` = c.id AND name != &#039;&#039;)&lt;br /&gt;
FROM `mdl_course` c where format = &#039;onetopic&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hidden Courses with Students Enrolled===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.visible AS Visible, &lt;br /&gt;
DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors,&lt;br /&gt;
&lt;br /&gt;
(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;, &lt;br /&gt;
&lt;br /&gt;
now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
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) &amp;gt; 0&lt;br /&gt;
ORDER BY StartDate, Instructor_Email, Course_ID&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Course formats used on my system ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(*) &#039;Count&#039;, c.format &#039;Format&#039;&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
GROUP BY c.format&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Course Design Reports==&lt;br /&gt;
&lt;br /&gt;
These are reports which summarize course design aspects, such as activity and resource modules per section, types of activities used, etc.&lt;br /&gt;
&lt;br /&gt;
===Course Content/Week===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report assumes that the first 14 sections in a course, not including the &amp;quot;0&amp;quot; or &amp;quot;Welcome&amp;quot; section, correspond to weeks (with &amp;quot;Subsections&amp;quot; given numbers much higher in the sequence). Of those sections, each is checked to count the number of:&lt;br /&gt;
&lt;br /&gt;
    Forums&lt;br /&gt;
    Graded Activities (may include Forums)&lt;br /&gt;
    Resources (not including a Label)&lt;br /&gt;
&lt;br /&gt;
Totals of each of these types of content elements per section are provided.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Only visible resources and activities are counted.&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: this is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
 &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT LIKE &#039;label&#039;),cm.id,NULL)) AS &#039;Ungraded Resources&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Graded Activities&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cs.section&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments and Weights===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Categories with weights of 0 are not included in this report.&lt;br /&gt;
&lt;br /&gt;
Only visible activities are included in this report.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This is designed to be a &amp;quot;Global&amp;quot; report in Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;) AS &#039;Grade Book Category&#039;&lt;br /&gt;
, IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND(SUM(DISTINCT gi.aggregationcoef), 2)+ROUND(SUM(DISTINCT mgi.aggregationcoef), 2)) AS &#039;Category weight&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT_WS(&#039;, &#039;,GROUP_CONCAT(DISTINCT gi.itemmodule SEPARATOR &#039;, &#039;), IF(mgi.id, &#039;manual&#039;,NULL)) AS &#039;Activity Types&#039;&lt;br /&gt;
, COUNT(DISTINCT gi.itemmodule) + IF(mgi.id,1,0) AS &#039;Different Activity Types&#039;&lt;br /&gt;
, CONCAT_WS(&#039;&amp;lt;br&amp;gt;&#039;, GROUP_CONCAT(DISTINCT gi.itemname ORDER BY gi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;), GROUP_CONCAT(DISTINCT mgi.itemname ORDER BY mgi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;)) AS &#039;Activity Names&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) + COUNT(DISTINCT mgi.id) AS &#039;Activity Count&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
&lt;br /&gt;
#get grade categories&lt;br /&gt;
LEFT JOIN prefix_grade_categories AS gc ON gc.courseid = c.id &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
JOIN prefix_grade_items AS gic ON gic.courseid = c.id AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
&lt;br /&gt;
# attach activities to course&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = c.id &lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.iteminstance = cm.instance AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.id&lt;br /&gt;
ORDER BY gc.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pre-Term Course Review===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
#   &amp;quot;Required blocks&amp;quot; include Instructor Block (mooprofile), Activities, and the Research block.&lt;br /&gt;
#    &amp;quot;Instructor Details&amp;quot; block is not the &amp;quot;Instructor&amp;quot; block (mooprofile) automatically provided by the system. It is an optional block that can be edited by the instructor. If not edited to remove boilerplate text, it should be hidden.&lt;br /&gt;
#    All courses should be in the &amp;quot;Collapsed Topics&amp;quot; format with the &amp;quot;Weeks&amp;quot; structure.&lt;br /&gt;
#    &amp;quot;Weeks defined in course settings&amp;quot; is taken from our SIS when the course shells are created, but can be edited by faculty. &amp;quot;# of weeks named and visible&amp;quot; should usually match or exceed this value.&lt;br /&gt;
#    We recommend that each week contain at least one forum, at least one graded activity, and at least one ungraded resource.&lt;br /&gt;
#    &amp;quot;Syllabus updated&amp;quot; date is for the first attached file found with the text &amp;quot;syllabus&amp;quot; in the name. The &amp;quot;Days ago&amp;quot; calculation is included for convenience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: At our institution, we construct categories each term, and insert a text string &amp;quot;staging&amp;quot; in the Category ID for pre-term courses during the preparation or &amp;quot;staging&amp;quot; phase of course development. We remove this text string (and change it to &amp;quot;production&amp;quot;) when courses go live at the start of the new term.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
#,RIGHT(c.idnumber,2) AS Type # Specific to GSC &amp;quot;Instructional Method&amp;quot; storage&lt;br /&gt;
&lt;br /&gt;
#, substring_index(substr(c.shortname FROM locate(&#039;.&#039;,c.shortname)+1),&#039;-&#039;,1) AS Section # Specific to GSC&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.lastname,&#039;, &#039;, u.firstname,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
,(SELECT IF((u2.description IS NULL) OR (u2.description LIKE &#039;&#039;),&#039;NO&#039;, &#039;YES&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT IF(u3.picture &amp;gt; 0,&#039;YES&#039;,&#039;NO&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u3 ON u3.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Picture&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(((bpi.visible IS NULL) OR (bpi.visible !=0)) AND ((bpm.visible IS NULL) OR (bpm.visible !=0)) AND ((bpa.visible IS NULL) OR (bpa.visible !=0)) AND ((bpr.visible IS NULL) OR (bpr.visible !=0)),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Required blocks visible&#039;&lt;br /&gt;
#, IF((bpm.visible IS NULL) OR (bpm.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Messages block visible&#039;&lt;br /&gt;
#, IF((bpa.visible IS NULL) OR (bpa.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;activities block visible&#039;&lt;br /&gt;
#, IF((bpr.visible IS NULL) OR (bpr.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;research block visible&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)) AND (bip.visible !=0),&#039;YES&#039;,&#039;&#039;) AS &#039;Instructor Details Block visible&#039; # This is a hack based on UUencoded string data from the title of HTML &amp;quot;Instructor Details&amp;quot; block&lt;br /&gt;
&lt;br /&gt;
#, IF(bi.configdata LIKE &#039;%ZGl0IHRoaXMgYmxvY2s%&#039;,&#039;NO&#039;,&#039;&#039;) AS &#039;Instructor Details Block Updated&#039; # HTML block has string &#039;dit this block&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(COUNT(bi.id) -  SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)),&#039;YES&#039;,&#039;&#039;) AS &#039;possible extra instructor blocks&#039; #looking for any HTML block with &amp;quot;instructor&amp;quot; in the title&lt;br /&gt;
&lt;br /&gt;
, IF(c.format=&#039;topcoll&#039;,&#039;YES&#039;, c.format) AS &#039;Collapsed Topics course format&#039; # change this if you want to test for a different format&lt;br /&gt;
, IF(cfo.value = 2, &#039;YES&#039;,&#039;NO&#039;) AS &#039;weeks structure&#039;&lt;br /&gt;
&lt;br /&gt;
, cfw.value AS &#039;weeks defined in course settings&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(((cs.name IS NOT NULL) AND (cs.visible = 1) AND (cs.section != &#039;0&#039;) AND (cs.sequence IS NOT NULL)),cs.id,NULL)) AS &#039;# of weeks named &amp;amp; visible (includes orphans)&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039; ,cs.id , NULL)) AS &#039;Weeks with Forum&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cs.id, NULL)) AS &#039;Weeks with Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT mgi.id) AS &#039;Manual Grade Items&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)),cm.id,NULL)) AS &#039;Resources&#039;&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)), cs.id, NULL)) AS &#039;Weeks with Resources&#039;&lt;br /&gt;
&lt;br /&gt;
# Here are some other things you could check for per course&lt;br /&gt;
#,(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 &#039;%forum%&#039;) AS Forums&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%quiz%&#039;) AS Quizzes&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%assign%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_resource.id) FROM prefix_resource JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course) AS Files&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_url.id) FROM prefix_url JOIN prefix_course ON prefix_course.id = prefix_url.course WHERE c.id = prefix_url.course) AS Links&lt;br /&gt;
&lt;br /&gt;
,(SELECT FROM_UNIXTIME(MAX(prefix_resource.timemodified))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS SyllabusDate&lt;br /&gt;
&lt;br /&gt;
,(SELECT TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(MAX(prefix_resource.timemodified)))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS DaysAgo&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, f.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement Forum Visible&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, fd.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement posted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
LEFT JOIN prefix_context AS ctxx ON c.id = ctxx.instanceid &lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpi ON bpi.contextid = ctxx.id AND bpi.blockinstanceid = &#039;43692&#039; # mooprofile&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpm ON bpm.contextid = ctxx.id AND bpm.blockinstanceid = &#039;43962&#039; # messages&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpa ON bpa.contextid = ctxx.id AND bpa.blockinstanceid = &#039;43963&#039; # activities&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpr ON bpr.contextid = ctxx.id AND bpr.blockinstanceid = &#039;38368&#039; # html research help&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.visible = 1 AND cs.sequence IS NOT NULL&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
LEFT JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_forum AS f ON f.course = c.id AND cm.instance = f.id AND cm.visible = 1&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.forum = f.id&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfo ON cfo.courseid = c.id AND cfo.name = &#039;layoutstructure&#039;&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfw ON cfw.courseid = c.id AND cfw.name = &#039;numsections&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_instances AS bi ON bi.parentcontextid = ctxx.id AND bi.blockname = &#039;html&#039; AND (bi.configdata LIKE &#039;%SW5zdHJ1Y3Rvc%&#039; or bi.configdata LIKE &#039;%bnN0cnVjdG9y%&#039;)&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bip ON bip.blockinstanceid = bi.id&lt;br /&gt;
&lt;br /&gt;
WHERE RIGHT(c.idnumber,2) IN (&#039;OL&#039;, &#039;BL&#039;, &#039;HY&#039;) &lt;br /&gt;
# AND substring(cc.path,2,2) IN (&#039;26&#039;) # Staging&lt;br /&gt;
#AND substring(cc.path,2,3) IN (&#039;158&#039;) # UG&lt;br /&gt;
AND cc.idnumber LIKE &#039;%staging%&#039;&lt;br /&gt;
AND ctxx.contextlevel = 50&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module instances + Module HITs by role teacher and student in course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
m.name AS &amp;quot;Module name&amp;quot;&lt;br /&gt;
, COUNT(*) AS &amp;quot;Module count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name ) AS &amp;quot;Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course_modules AS cm&lt;br /&gt;
JOIN mdl_modules AS m on m.id = cm.module&lt;br /&gt;
WHERE cm.course = &#039;%%COURSEID%%&#039;&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Syllabus===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Course Policies&amp;quot; and &amp;quot;Teaching Philosophy&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.fullname AS &#039;fullname&#039;&lt;br /&gt;
, ec.idnumber AS &#039;elis-id&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.startdate), &#039;%b %e, %Y&#039;) AS &#039;start&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.enddate), &#039;%b %e, %Y&#039;) AS &#039;end&#039;&lt;br /&gt;
, ecd.name AS &#039;longname&#039;&lt;br /&gt;
, ecd.code AS &#039;coursecode&#039;&lt;br /&gt;
, ecd.credits AS &#039;coursecredits&#039;&lt;br /&gt;
, ecd.syllabus AS &#039;description&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;learning-outcomes&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;outcomes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.firstname,&#039; &#039;, u.lastname,&#039;&amp;lt;/a&amp;gt; &#039;, u.email)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
, (SELECT  efc.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_char AS efc&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = efc.fieldid AND ef.shortname = &#039;term-code&#039;&lt;br /&gt;
WHERE ctxci.id = efc.contextid) AS &#039;termcode&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;prerequisites&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;prerequisites&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;textbooks&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;textbooks&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;other-class-materials&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;other-class-materials&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-policies&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-policies&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;teaching-philosophy&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;teaching-philosophy&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-methods&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-methods&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT u2.description&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT&lt;br /&gt;
&lt;br /&gt;
GROUP_CONCAT(DISTINCT CONCAT(&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;tr&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt;&#039;,IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;)&lt;br /&gt;
, &#039; &amp;lt;/td&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt; &#039;&lt;br /&gt;
,IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND( gi.aggregationcoef, 2)+ROUND(mgi.aggregationcoef, 2))&lt;br /&gt;
&lt;br /&gt;
) SEPARATOR &#039;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&#039;)&lt;br /&gt;
#get grade categories&lt;br /&gt;
FROM prefix_grade_categories AS gc &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gic ON gic.courseid = gc.courseid AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = gc.courseid  AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = gc.courseid and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
WHERE gc.courseid = c.id  ) AS &#039;grade categories&#039;&lt;br /&gt;
&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;50%&amp;quot; &amp;gt;&#039; AS &#039;table start&#039;&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;100%&amp;quot; &amp;gt;&#039; AS &#039;table start 2&#039;&lt;br /&gt;
, &#039;&amp;lt;/table&amp;gt;&#039; AS &#039;table end&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;activities-schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;schedule&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;grading-scale&#039;&lt;br /&gt;
WHERE ctxepm.id = eft.contextid) AS &#039;gradescale&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
# connect moodle course to ELIS class instance&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls_mdl AS ecm ON ecm.moodlecourseid = c.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls AS ec ON ec.id = ecm.classid&lt;br /&gt;
# class instance context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxci ON ctxci.instanceid = ec.id AND ctxci.contextlevel = &#039;14&#039;&lt;br /&gt;
&lt;br /&gt;
# connect ELIS class instance to ELIS course description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_crs AS ecd ON ecd.id = ec.courseid&lt;br /&gt;
# course description context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxecd ON ctxecd.instanceid = ecd.id AND ctxecd.contextlevel = &#039;13&#039;&lt;br /&gt;
&lt;br /&gt;
#connect ELIS program to ELIS Course Description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm_crs AS epc ON epc.courseid = ecd.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm AS epm ON epm.id = epc.curriculumid&lt;br /&gt;
# course program context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxepm ON ctxepm.instanceid = epm.id AND ctxepm.contextlevel = &#039;11&#039;&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Activities Helper===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report provides a list of the graded activities in a course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: Only graded activities are displayed.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This report assumes that course sections each last one week.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
# 303 Course Activities Helper&lt;br /&gt;
&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
gi.itemmodule AS &#039;activity type&#039;&lt;br /&gt;
# cs.section AS &#039;section number&#039;&lt;br /&gt;
&lt;br /&gt;
# Calculation assumes each section lasts one week&lt;br /&gt;
, CONCAT(DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section-1))), &#039;%b %e, %Y&#039;),&#039; - &amp;lt;br&amp;gt;&#039;,DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section))), &#039;%b %e, %Y&#039;)) AS &#039;Date&#039;&lt;br /&gt;
&lt;br /&gt;
, gi.itemname AS &#039;activity name&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = cm.instance) AS &#039;intro&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT f.intro FROM prefix_forum AS f WHERE f.id = cm.instance) AS &#039;f intro&#039;&lt;br /&gt;
&lt;br /&gt;
, CASE gi.itemmodule &lt;br /&gt;
WHEN &#039;assign&#039; THEN (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;forum&#039; THEN (SELECT f.intro FROM prefix_forum AS f WHERE f.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;quiz&#039; THEN (SELECT q.intro FROM prefix_quiz AS q WHERE q.id = gi.iteminstance) &lt;br /&gt;
END AS &#039;test case&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT GROUP_CONCAT(CONCAT(&#039; - &#039;,gi.itemname) SEPARATOR &#039;&amp;lt;BR&amp;gt;&#039;) FROM  prefix_grade_items AS gi  JOIN prefix_course_modules AS cm ON  gi.iteminstance = cm.instance WHERE gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id ) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
#get grade sections&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id  AND cs.section &amp;gt; 0 AND cs.section &amp;lt;=14&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_assign AS asg ON asg.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_grade_items AS gi  ON  gi.iteminstance = cm.instance AND gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
&lt;br /&gt;
ORDER BY gi.itemmodule, cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Grade and Course Completion Reports==&lt;br /&gt;
===Site-Wide Grade Report with All Items===&lt;br /&gt;
Shows grades for all course items along with course totals for each student. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, &lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
For MySQL users, you&#039;ll need to use the MySQL DATE_ADD function instead of DATEADD. Replace the line:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
And:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
CONCAT(u.firstname,&#039; &#039;,u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site-Wide Grade Report with Just Course Totals===&lt;br /&gt;
A second site-wide grade report for all students that just shows course totals. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id AND gi.itemtype = &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For MySQL users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN CONCAT(c.fullname, &#039; - Total&#039;)&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS TIME&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
 &lt;br /&gt;
WHERE  gi.courseid = c.id AND gi.itemtype = &#039;course&#039;&lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Learner report by Learner with grades===&lt;br /&gt;
Which Learners in which course and what are the grades&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;Name&#039; , u.lastname AS &#039;Surname&#039;, c.fullname AS &#039;Course&#039;, cc.name AS &#039;Category&#039;, &lt;br /&gt;
CASE WHEN gi.itemtype = &#039;Course&#039;    &lt;br /&gt;
THEN c.fullname + &#039; Course Total&#039;  &lt;br /&gt;
ELSE gi.itemname &lt;br /&gt;
END AS &#039;Item Name&#039;, ROUND(gg.finalgrade,2) AS Score,ROUND(gg.rawgrademax,2) AS Max, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) as Percentage,&lt;br /&gt;
&lt;br /&gt;
if (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) &amp;gt; 79,&#039;Yes&#039; , &#039;No&#039;) as Pass&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id &lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid &lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category &lt;br /&gt;
WHERE  gi.courseid = c.id and gi.itemname != &#039;Attendance&#039;&lt;br /&gt;
ORDER BY `Name` ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A very simple report with a list of course completion status by username. Completions are noted by date, blank otherwise. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  u.username, &lt;br /&gt;
  c.shortname,  &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%Y-%m-%d&#039;) AS completed&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion with Criteria===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A report with course completions by username, with Aggregation method, Criteria types, and Criteria detail where available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username AS user, &lt;br /&gt;
c.shortname AS course,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(t.timecompleted),&#039;%Y-%m-%d&#039;) AS completed,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = c.id AND a.criteriatype IS NULL) = 1) THEN &amp;quot;Any&amp;quot;&lt;br /&gt;
ELSE &amp;quot;All&amp;quot;&lt;br /&gt;
END AS aggregation,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;Self&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN &amp;quot;By Date&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 3 THEN &amp;quot;Unenrol Status&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &amp;quot;Activity&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 5 THEN &amp;quot;Duration&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 6 THEN &amp;quot;Course Grade&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 7 THEN &amp;quot;Approve by Role&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 8 THEN &amp;quot;Previous Course&amp;quot;&lt;br /&gt;
END AS criteriatype,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;*&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(p.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN p.criteriatype = 3 THEN t.unenroled&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,p.module,&#039;/view.php?id=&#039;,p.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,p.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN p.criteriatype = 5 THEN p.enrolperiod&lt;br /&gt;
WHEN p.criteriatype = 6 THEN CONCAT(&#039;Needed: &#039;,ROUND(p.gradepass,2),&#039; Achieved: &#039;,ROUND(t.gradefinal,2)) &lt;br /&gt;
WHEN p.criteriatype = 7 THEN p.role&lt;br /&gt;
WHEN p.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = p.courseinstance)&lt;br /&gt;
END AS criteriadetail &lt;br /&gt;
FROM prefix_course_completion_crit_compl AS t&lt;br /&gt;
JOIN prefix_user AS u ON t.userid = u.id&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
JOIN prefix_course_completion_criteria AS p ON t.criteriaid = p.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Completion Enabled and their settings===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with completion enabled and their Aggregation setting, Criteria types, and Criteria details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT c.shortname AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = t.course AND a.criteriatype IS NULL)) = 2 THEN &amp;quot;All&amp;quot;&lt;br /&gt;
ELSE &amp;quot;Any&amp;quot;&lt;br /&gt;
END AS Course_Aggregation,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;Self completion&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN &amp;quot;Date done by&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;Unenrolement&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 4 THEN &amp;quot;Activity completion&amp;quot;   &lt;br /&gt;
WHEN t.criteriatype = 5 THEN &amp;quot;Duration in days&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 6 THEN &amp;quot;Final grade&amp;quot;     &lt;br /&gt;
WHEN t.criteriatype = 7 THEN &amp;quot;Approve by role&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 8 THEN &amp;quot;Previous course&amp;quot;&lt;br /&gt;
END AS Criteria_type,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(t.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 4 THEN&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,t.module,&#039;/view.php?id=&#039;,t.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,t.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN t.criteriatype = 5 THEN ROUND(t.enrolperiod/86400)&lt;br /&gt;
WHEN t.criteriatype = 6 THEN ROUND(t.gradepass,2)&lt;br /&gt;
WHEN t.criteriatype = 7 THEN (SELECT r.shortname FROM prefix_role AS r WHERE r.id = t.role)&lt;br /&gt;
WHEN t.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = t.courseinstance)&lt;br /&gt;
END AS Criteria_detail&lt;br /&gt;
FROM prefix_course_completion_criteria as t&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Completion Report with custom dates===&lt;br /&gt;
&lt;br /&gt;
List of users who completed multiple or single course/s from a start date to end date chosen by the user. The output gives username, name, course name, completion date and score&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT u.username AS &#039;User Name&#039;,&lt;br /&gt;
CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Name&#039;,&lt;br /&gt;
c.shortname AS &#039;Course Name&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%W %e %M, %Y&#039;) AS &#039;Completed Date&#039;,&lt;br /&gt;
ROUND(c4.gradefinal,2) AS &#039;Score&#039;&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
JOIN prefix_course_completion_crit_compl AS c4 ON u.id = c4.userid&lt;br /&gt;
WHERE c.enablecompletion = 1  AND (p.timecompleted IS NOT NULL OR p.timecompleted !=&#039;&#039;) &lt;br /&gt;
AND (p.timecompleted&amp;gt;= :start_date AND p.timecompleted&amp;lt;=:end_date)&lt;br /&gt;
GROUP BY u.username&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scales used in activities===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT scale.name&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,gi.itemmodule,&#039;/view.php?id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module View&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/modedit.php?up&#039;,&#039;date=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module Settings&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON c.id = gi.courseid&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = gi.courseid AND cm.instance = gi.iteminstance&lt;br /&gt;
JOIN prefix_scale AS scale ON scale.id = gi.scaleid&lt;br /&gt;
WHERE gi.scaleid IS NOT NULL&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Extra Credit Items by Name Only===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
This query identifies grade items in visible courses with student enrollment that have &amp;quot;extra credit&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, gi.itemname AS Item_Name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors&lt;br /&gt;
&lt;br /&gt;
,(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;&lt;br /&gt;
&lt;br /&gt;
,now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON gi.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE gi.itemname LIKE &#039;%extra credit%&#039; &lt;br /&gt;
	AND gi.gradetype = &#039;1&#039; &lt;br /&gt;
	AND gi.hidden = &#039;0&#039; &lt;br /&gt;
	AND gi.aggregationcoef = &#039;0&#039; &lt;br /&gt;
	AND c.visible = 1&lt;br /&gt;
	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) &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
GROUP BY Course_ID, gi.id&lt;br /&gt;
ORDER BY StartDate, Course_ID&lt;br /&gt;
 &lt;br /&gt;
%%FILTER_SEARCHTEXT:Course_ID:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site Wide Number of Courses Completed by User===&lt;br /&gt;
Contributed by Ken St. John&lt;br /&gt;
&lt;br /&gt;
Simple report that shows the number of completed courses for all users site wide&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname, u.firstname,&lt;br /&gt;
COUNT(p.timecompleted) AS TotalCompletions&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
GROUP BY p.userid&lt;br /&gt;
ORDER BY u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Activity Module Reports==&lt;br /&gt;
&lt;br /&gt;
=== User activity completions with dates===&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. It includes the new core H5P module in 3.10. Add any third party activity modules you may have in your site as you need. Also, thanks to Tim Hunt for improvements to this query. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.username As &#039;User&#039;,&lt;br /&gt;
c.shortname AS &#039;Course&#039;,&lt;br /&gt;
m.name AS Activitytype, &lt;br /&gt;
CASE &lt;br /&gt;
    WHEN m.name = &#039;assign&#039;  THEN (SELECT name FROM prefix_assign WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;assignment&#039;  THEN (SELECT name FROM prefix_assignment WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;book&#039;  THEN (SELECT name FROM prefix_book WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;chat&#039;  THEN (SELECT name FROM prefix_chat WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;choice&#039;  THEN (SELECT name FROM prefix_choice WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;data&#039;  THEN (SELECT name FROM prefix_data WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;feedback&#039;  THEN (SELECT name FROM prefix_feedback WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;folder&#039;  THEN (SELECT name FROM prefix_folder WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;forum&#039; THEN (SELECT name FROM prefix_forum WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;glossary&#039; THEN (SELECT name FROM prefix_glossary WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;h5pactivity&#039; THEN (SELECT name FROM prefix_h5pactivity WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;imscp&#039; THEN (SELECT name FROM prefix_imscp WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;label&#039;  THEN (SELECT name FROM prefix_label WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;lesson&#039;  THEN (SELECT name FROM prefix_lesson WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;lti&#039;  THEN (SELECT name FROM prefix_lti  WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;page&#039;  THEN (SELECT name FROM prefix_page WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;quiz&#039;  THEN (SELECT name FROM prefix_quiz WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;resource&#039;  THEN (SELECT name FROM prefix_resource WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;scorm&#039;  THEN (SELECT name FROM prefix_scorm WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;survey&#039;  THEN (SELECT name FROM prefix_survey WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;url&#039;  THEN (SELECT name FROM prefix_url  WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;wiki&#039; THEN (SELECT name FROM prefix_wiki  WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;workshop&#039; THEN (SELECT name FROM prefix_workshop  WHERE id = cm.instance)&lt;br /&gt;
   ELSE &amp;quot;Other activity&amp;quot;&lt;br /&gt;
END AS Actvityname,&lt;br /&gt;
# cm.section AS Coursesection,&lt;br /&gt;
CASE&lt;br /&gt;
    WHEN cm.completion = 0 THEN &#039;0 None&#039;&lt;br /&gt;
    WHEN cm.completion = 1 THEN &#039;1 Self&#039;&lt;br /&gt;
    WHEN cm.completion = 2 THEN &#039;2 Auto&#039;&lt;br /&gt;
END AS Activtycompletiontype, &lt;br /&gt;
CASE&lt;br /&gt;
   WHEN cmc.completionstate = 0 THEN &#039;In Progress&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 1 THEN &#039;Completed&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 2 THEN &#039;Completed with Pass&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 3 THEN &#039;Completed with Fail&#039;&lt;br /&gt;
   ELSE &#039;Unknown&#039;&lt;br /&gt;
END AS &#039;Progress&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(cmc.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;&lt;br /&gt;
FROM prefix_course_modules_completion cmc &lt;br /&gt;
JOIN prefix_user u ON cmc.userid = u.id&lt;br /&gt;
JOIN prefix_course_modules cm ON cmc.coursemoduleid = cm.id&lt;br /&gt;
JOIN prefix_course c ON cm.course = c.id&lt;br /&gt;
JOIN prefix_modules m ON cm.module = m.id&lt;br /&gt;
# skip the predefined admin and guest user&lt;br /&gt;
WHERE u.id &amp;gt; 2&lt;br /&gt;
# config reports filters&lt;br /&gt;
%%FILTER_USERS:u.username%%&lt;br /&gt;
%%FILTER_SEARCHTEXT:m.name:~%%&lt;br /&gt;
%%FILTER_STARTTIME:cmc.timemodified:&amp;gt;%% %%FILTER_ENDTIME:cmc.timemodified:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many SCORM activities are used in each Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cm.course,c.fullname ,m.name &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/scorm/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,count(cm.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS Counter&lt;br /&gt;
 &lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
  JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
  JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%scorm%&#039; &lt;br /&gt;
GROUP BY cm.course,cm.module &lt;br /&gt;
ORDER BY count(cm.id) desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===SCORM Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of SCORM activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, scm.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;SCO%&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_scorm AS scm ON scm.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LTI (External Tool) Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of  LTI (External Tool) Usage activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, lti.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;lti&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_lti AS lti ON lti.id = cm.instance&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each MODULE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module,action,count(id) as counter&lt;br /&gt;
FROM prefix_log&lt;br /&gt;
GROUP BY module,action&lt;br /&gt;
ORDER BY module,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Most popular ACTIVITY===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, module&lt;br /&gt;
FROM prefix_log l&lt;br /&gt;
WHERE module != &#039;login&#039; AND module != &#039;course&#039; AND module != &#039;role&#039;&lt;br /&gt;
GROUP BY module&lt;br /&gt;
ORDER BY hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide use of ACTIVITIES and RESOURCES===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count( cm.id ) AS counter, m.name&lt;br /&gt;
FROM `prefix_course_modules` AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
ORDER BY counter DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LOG file ACTIONS per MODULE per COURSE (IDs)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select course,module,action,count(action) as summa from prefix_log&lt;br /&gt;
where action &amp;lt;&amp;gt; &#039;new&#039;&lt;br /&gt;
group by course,action,module&lt;br /&gt;
order by course,module,action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System Wide usage count of various course Activities===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
Like: Forum, Wiki, Blog, Assignment, Database,&lt;br /&gt;
#Within specific category&lt;br /&gt;
#Teacher name in course&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS Forums&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%data%&#039;) AS Databses&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%assignment%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 18)&lt;br /&gt;
ORDER BY Wikis DESC,Blogs DESC, Forums DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course wiki usage/activity over the last 6 semesters===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &amp;quot;Courses with Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester A%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester A&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester B%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester B&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed WIKI activity (per wiki per course)===&lt;br /&gt;
Including Number of Students in course (for reference)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID  &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id ) AS Students&lt;br /&gt;
,m.name&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%updat%&#039; ) as &#039;UPDAT E&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%annotate%&#039; ) as ANNOTATE&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%comment%&#039; ) as COMMENT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%add%&#039; ) as &#039;A DD&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%edit%&#039; ) as EDIT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action NOT LIKE &#039;%view%&#039; ) as &#039;All (NO View)&#039;&lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
GROUP BY cm.course,cm.module&lt;br /&gt;
ORDER BY &#039;All (NO View)&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wiki usage, system wide===&lt;br /&gt;
(you can filter the output by selecting some specific course categories : &amp;quot;WHERE c.category IN ( 8,13,15)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039;) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%add%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ADD&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%edit%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;EDIT&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%annotate%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ANNOTATE&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%comments%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;Comments&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_ouwiki_pages as ouwp&lt;br /&gt;
JOIN prefix_ouwiki as ouw ON ouw.id = ouwp.subwikiid&lt;br /&gt;
WHERE ouw.course = c.id GROUP BY ouw.course  ) as OUWikiPages&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( DISTINCT nwp.pagename ) FROM prefix_wiki_pages AS nwp&lt;br /&gt;
JOIN prefix_wiki AS nw ON nw.id = nwp.dfwiki WHERE nw.course = c.id ) As NWikiPages&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Wikis &amp;gt; 0&lt;br /&gt;
ORDER BY &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Aggregated Teacher activity by &amp;quot;WEB2&amp;quot; Modules===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
The NV column shows activity without VIEW log activity&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.userid, u.firstname,u.lastname&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039;) AS Wiki&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Wiki_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039;) AS Forum&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Forum_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039;) AS Blog&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Blog_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039;) AS Assignment&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Assignment_NV&lt;br /&gt;
FROM prefix_role_assignments AS ra &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
WHERE ra.roleid = 3 &lt;br /&gt;
GROUP BY ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the certificates issued, sort by variables in the custom profile fields===&lt;br /&gt;
Note: The SQL queries look intimidating at first, but isn&#039;t really that difficult to learn. I&#039;ve seen in the forums that users wanted to do &#039;site-wide&#039; groups in 1.9x. This is sort of the idea. It pulls all the certificates issued to all users sorted by the custom profile fields, which in my case is the Units or Depts (i.e. my site wide groups). Why certificates? I&#039;ve explored with both grades and quizzes, the course admins are not really interested in the actual grades but whether the learner received a certificate (i.e. passed the course with x, y, z activities). It also saves me from creating groups and assigning them into the right groups. Even assigning in bulk is not efficient, since I have upward of 25 groups per course and constantly new learners enrolling in courses. The limitation is something to do with the server? as it only pull 5000 rows of data. If anyone figured out how to change this, please let me know. In the meantime, the work around is to pull only a few units/depts at a time to limit the number of rows. This is fine at the moment, since each course admin are only responsible for certain units/depts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(prefix_certificate_issues.timecreated), &#039;%Y-%m-%d&#039; ) AS Date,&lt;br /&gt;
prefix_certificate_issues.classname AS Topic,&lt;br /&gt;
prefix_certificate.name AS Certificate,&lt;br /&gt;
prefix_certificate_issues.studentname as Name,&lt;br /&gt;
prefix_user_info_data.data AS Units&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_certificate_issues&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_user_info_data&lt;br /&gt;
on prefix_certificate_issues.userid = prefix_user_info_data.userid&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_certificate&lt;br /&gt;
on prefix_certificate_issues.certificateid = prefix_certificate.id&lt;br /&gt;
&lt;br /&gt;
WHERE prefix_user_info_data.data=&#039;Unit 1&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 2&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 3&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY Units, Name, Topic ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== All Simple Certificates Earned in the Site===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 [http://www.mysqltutorial.org/mysql-date_format/ DATE_FORMAT] function.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
CONCAT (u.firstname, &#039; &#039;,u.lastname) As &#039;User&#039;,&lt;br /&gt;
c.fullname AS &#039;Course&#039;,&lt;br /&gt;
sc.name AS &#039;Certificate&#039;,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(sci.timecreated), &#039;%Y-%m-%d&#039; ) As &#039;Date Awarded&#039;&lt;br /&gt;
# sci.code &#039;CertificateId&#039;&lt;br /&gt;
FROM prefix_simplecertificate_issues sci&lt;br /&gt;
JOIN prefix_user u ON sci.userid = u.id&lt;br /&gt;
JOIN prefix_simplecertificate sc ON sci.certificateid = sc.id&lt;br /&gt;
JOIN prefix_course AS c ON sc.course = c.id&lt;br /&gt;
ORDER BY sci.timecreated DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE DATEDIFF(NOW(),FROM_UNIXTIME(sci.timecreated) ) &amp;lt; 30&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Counter Blog usage in Courses,system wide===&lt;br /&gt;
What teachers in what courses, uses blogs and how many + student count in that course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT ( @counter := @counter+1) as counter, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c, (SELECT @counter := 0) as s_init&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Blogs &amp;gt; 0&lt;br /&gt;
ORDER BY Blogs DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Elluminate (Blackboard Collaborate) - system wide usage===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT e.name As Session ,er.recordingsize&lt;br /&gt;
,c.fullname As Course&lt;br /&gt;
,u.firstname,u.lastname &lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(e.timestart),&#039;%d-%m-%Y&#039;) AS dTimeStart&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/moodle/mod/elluminate/loadrecording.php?id=&#039;,er.id,&#039;&amp;quot;&amp;gt;Show&amp;lt;/a&amp;gt;&#039;) AS RecordedSession&lt;br /&gt;
&lt;br /&gt;
FROM prefix_elluminate_recordings AS er&lt;br /&gt;
JOIN prefix_elluminate AS e ON e.meetingid = er.meetingid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = e.creator &lt;br /&gt;
ORDER BY er.recordingsize DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choice ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Results of the Choice activity. For all courses, shows course shortname, username, the Choice text, and the answer chosen by the user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname AS course, u.username, h.name as question, o.text AS answer&lt;br /&gt;
FROM prefix_choice AS h&lt;br /&gt;
JOIN prefix_course AS c ON h.course = c.id&lt;br /&gt;
JOIN prefix_choice_answers AS a ON h.id = a.choiceid&lt;br /&gt;
JOIN prefix_user AS u ON a.userid = u.id&lt;br /&gt;
JOIN prefix_choice_options AS o ON a.optionid = o.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment type usage in courses ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assign/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_assign WHERE c.id = course) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;file&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
#GROUP BY apc.plugin&lt;br /&gt;
) AS &amp;quot;File Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;onlinetext&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Online Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;pdf&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;PDF Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;offline&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Offline Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;comments&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Assignments Comments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_assign AS assign&lt;br /&gt;
JOIN prefix_course AS c ON c.id = assign.course&lt;br /&gt;
GROUP BY c.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Assignment Module Reports==&lt;br /&gt;
===All Ungraded Assignments===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
Returns all the submitted assignments that still need grading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id&lt;br /&gt;
and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Ungraded Assignments w/ Link===&lt;br /&gt;
Returns all assignments submitted by those with the student role that have the status of &#039;submitted&#039;, along with a link that goes directly to the submission to grade it. The links work if you view the report within Moodle.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This query is updated for use with Moodle 2.2 or later.  Contributed by Carly J. Born, Carleton College&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;,&lt;br /&gt;
 &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assign/view.php?id=&#039;, &lt;br /&gt;
cm.id, &lt;br /&gt;
&#039;&amp;amp;rownum=0&amp;amp;action=grader&amp;amp;userid=&#039;, &lt;br /&gt;
u.id,&lt;br /&gt;
&#039;&amp;quot;&amp;gt;Grade&amp;lt;/a&amp;gt;&#039;) &lt;br /&gt;
AS &amp;quot;Assignment link&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_assign_submission sub&lt;br /&gt;
JOIN prefix_assign a ON a.id = sub.assignment&lt;br /&gt;
JOIN prefix_user u ON u.id = sub.userid&lt;br /&gt;
JOIN prefix_course c ON c.id = a.course AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_course_modules cm ON c.id = cm.course &lt;br /&gt;
JOIN prefix_context cxt ON c.id=cxt.instanceid AND cxt.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments ra ON cxt.id = ra.contextid AND ra.roleid=5 AND ra.userid=u.id&lt;br /&gt;
 &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 22 AND sub.status=&#039;submitted&#039;&lt;br /&gt;
 &lt;br /&gt;
ORDER BY c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;a href=&amp;quot;http://education.varonis.com/mod/assignment/submissions.php&#039; + char(63) +&lt;br /&gt;
+ &#039;id=&#039; + cast(cm.id as varchar) + &#039;&amp;amp;userid=&#039; + cast(u.id as varchar) &lt;br /&gt;
+ &#039;&amp;amp;mode=single&amp;amp;filter=0&amp;amp;offset=2&amp;quot;&amp;gt;&#039; + a.name + &#039;&amp;lt;/a&amp;gt;&#039;&lt;br /&gt;
AS &amp;quot;Assignmentlink&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments (and Quizzes) waiting to be graded===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This report requires a YEAR filter to be added (Available when using the latest block/configurable_reports)&lt;br /&gt;
&lt;br /&gt;
Which you can always remove, to make this query work on earlier versions.&lt;br /&gt;
&lt;br /&gt;
The report includes: &lt;br /&gt;
*number of quizzes&lt;br /&gt;
*unFinished Quiz attempts&lt;br /&gt;
*Finished Quiz attempts&lt;br /&gt;
*number of students&lt;br /&gt;
*number of Assignments&lt;br /&gt;
*number of submitted answers by students &lt;br /&gt;
*number of unchecked assignments (waiting for the Teacher) in a Course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
 &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assignment/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;מטלות&amp;lt;/a&amp;gt;&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;בחנים&amp;lt;/a&amp;gt;&#039;) AS &#039;Quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_course_modules cm &lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module &lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039; AND cm.course = c.id &lt;br /&gt;
GROUP BY cm.course &lt;br /&gt;
) AS &#039;nQuizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish = 0&lt;br /&gt;
GROUP BY q.course) AS &#039;unFinished Quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish &amp;gt; 0&lt;br /&gt;
GROUP BY q.course) AS &#039;finished quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS nStudents&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(a.id)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) nAssignments&lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE a.course = c.id AND FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course&lt;br /&gt;
) &#039;Open &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(ROUND( (100 / iAssignments ) * iOpenAssignments ) ,&#039;%&#039;) &#039;unFinished &amp;lt;br/&amp;gt;Assignments &amp;lt;br/&amp;gt;(percent)&#039;&lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE asb.grade &amp;lt; 0 AND cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;unChecked  &amp;lt;br/&amp;gt;Submissions&#039; &lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;Submitted  &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblAssignmentsCount ON tblAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iOpenAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblOpenAssignmentsCount ON tblOpenAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1  &lt;br /&gt;
#AND c.fullname LIKE &#039;%תשעג%&#039;&lt;br /&gt;
%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
ORDER BY &#039;Open &amp;lt;br/&amp;gt;Assignments&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rubrics without zero values in criteria===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
Rubric calculations in Moodle can fail to align with instructors expectations if they lack a zero value for each criterion used in the assessment. From documentation at https://docs.moodle.org/32/en/Rubrics#Grade_calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;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.&lt;br /&gt;
TIP: To avoid confusion from this sort of thing, we recommend including a level with 0 points in every rubric criterion.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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&#039; favor.&lt;br /&gt;
&lt;br /&gt;
Includes search filter of course idnumber.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cat.name AS Department, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, &lt;br /&gt;
c.fullname AS Course_Name, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/grading/form/rubric/edit.php&#039;,CHAR(63),&#039;areaid=&#039;,gd.areaid,&#039;&amp;quot;&amp;gt;&#039;,gd.areaid,&#039;&amp;lt;/a&amp;gt;&#039;) AS Rubric&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_categories AS cat &lt;br /&gt;
ON cat.id = c.category&lt;br /&gt;
JOIN prefix_course_modules AS cm &lt;br /&gt;
ON c.id=cm.course&lt;br /&gt;
JOIN prefix_context AS ctx &lt;br /&gt;
ON cm.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_grading_areas AS garea &lt;br /&gt;
ON ctx.id = garea.contextid&lt;br /&gt;
JOIN prefix_grading_definitions AS gd &lt;br /&gt;
ON garea.id = gd.areaid&lt;br /&gt;
JOIN prefix_gradingform_rubric_criteria AS crit &lt;br /&gt;
ON gd.id = crit.definitionid&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id&lt;br /&gt;
WHERE cm.visible=&#039;1&#039; AND garea.activemethod = &#039;rubric&#039; AND (crit.id NOT IN&lt;br /&gt;
(SELECT crit.id&lt;br /&gt;
FROM prefix_gradingform_rubric_criteria AS crit&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id WHERE levels.score = &#039;0&#039;))&lt;br /&gt;
&lt;br /&gt;
GROUP BY Rubric&lt;br /&gt;
ORDER BY Course_ID, Rubric&lt;br /&gt;
&lt;br /&gt;
%%FILTER_SEARCHTEXT:c.idnumber:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Who is using &amp;quot;Single File Upload&amp;quot; assignment===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,ass.name as &amp;quot;Assignment Name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM &lt;br /&gt;
prefix_assignment as ass&lt;br /&gt;
&lt;br /&gt;
JOIN &lt;br /&gt;
prefix_course as c ON c.id = ass.course&lt;br /&gt;
&lt;br /&gt;
WHERE `assignmenttype` LIKE &#039;uploadsingle&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Feedback Module Reports==&lt;br /&gt;
===List the answers to all the Feedback activities within the current course, submitted by the current user===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT /* crs.fullname as &amp;quot;Course name&amp;quot;, f.name AS &amp;quot;Journal name&amp;quot;, CONCAT(u.firstname,&#039; &#039;,UPPER(u.lastname)) as &amp;quot;Participant&amp;quot;, */ /* include these fields if you want to check the composition of the recordset */&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified),&#039;%W %e %M, %Y&#039;) as &amp;quot;Answer Date&amp;quot;,&lt;br /&gt;
CASE i.typ WHEN &#039;label&#039; THEN i.presentation ELSE i.name END as &amp;quot;Topic&amp;quot;,  /* usually labels are used as section titles, so you&#039;d want them present in the recordset */&lt;br /&gt;
v.value as &amp;quot;My Answer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback AS f&lt;br /&gt;
INNER JOIN prefix_course as crs on crs.id=f.course %%FILTER_COURSES:f.course%% &lt;br /&gt;
INNER JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
INNER JOIN prefix_feedback_completed AS c on f.id=c.feedback %%FILTER_COURSEUSER:c.userid%% &lt;br /&gt;
LEFT JOIN prefix_feedback_value AS v on v.completed=c.id AND v.item=i.id&lt;br /&gt;
INNER JOIN prefix_user AS u on c.userid=u.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%% AND u.id = %%USERID%%  AND c.anonymous_response = 1  /* This clause limits the recordset to the current course and the current user and includes/ excludes the anonymous responses as needed */&lt;br /&gt;
&lt;br /&gt;
ORDER BY f.id, c.timemodified, i.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show all Feedbacks from all courses for all users including showing names of anonymous users===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 truly anonymous users on the front page as &#039;Not-logged-in&#039; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS Course, &lt;br /&gt;
f.name AS Feedback,&lt;br /&gt;
# i.id AS Itemid,&lt;br /&gt;
i.name AS Itemname,&lt;br /&gt;
i.label AS Itemlabel,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN f.anonymous = 1 AND u.id != 0 THEN CONCAT(u.username, &#039; :ANON&#039;)&lt;br /&gt;
 WHEN fc.userid = 0 THEN &#039;Not-logged-in&#039;&lt;br /&gt;
 ELSE u.username&lt;br /&gt;
END AS &#039;User&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(fc.timemodified),&#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;Completed&amp;quot;,&lt;br /&gt;
v.value AS &amp;quot;Choice&amp;quot;,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN i.typ = &#039;multichoice&#039; THEN&lt;br /&gt;
     IF (  SUBSTRING(i.presentation,1,6)=&#039;d&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&#039;,&lt;br /&gt;
	       SUBSTRING(i.presentation,7),&lt;br /&gt;
		   i.presentation)&lt;br /&gt;
 ELSE i.presentation&lt;br /&gt;
END AS &amp;quot;Answers&amp;quot;,&lt;br /&gt;
i.typ,&lt;br /&gt;
i.dependitem,&lt;br /&gt;
i.dependvalue&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback f&lt;br /&gt;
JOIN prefix_course c ON c.id=f.course &lt;br /&gt;
JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
JOIN prefix_feedback_completed fc ON f.id=fc.feedback&lt;br /&gt;
LEFT JOIN prefix_feedback_value v ON v.completed=fc.id AND v.item=i.id&lt;br /&gt;
LEFT JOIN prefix_user AS u ON fc.userid=u.id&lt;br /&gt;
WHERE i.typ != &#039;pagebreak&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Show all Feedbacks from all courses for all users with their answers===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Shows all Feedbacks in all Courses with all multi-choice questions and answers of all users for multi-choice questions. It shows the possible answers, the number of the chosen answer and the text of the chosen answer by the user. As always, I disavow any prettiness here and you should update the fields as you need.&lt;br /&gt;
&lt;br /&gt;
Known to work in Moodle 3.5 to 3.10.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.fullname as &amp;quot;Course&amp;quot;, &lt;br /&gt;
f.name AS &amp;quot;Feedback&amp;quot;, &lt;br /&gt;
CONCAT(u.firstname,&#039;  &#039;,u.lastname) as &amp;quot;User&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(fc.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;When&amp;quot;,&lt;br /&gt;
IF(i.typ = &#039;label&#039;, i.presentation, i.name) AS &amp;quot;Question&amp;quot;, &lt;br /&gt;
# answers presentation string starts with these 6 characters:  r&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;br /&gt;
CASE WHEN i.typ = &#039;multichoice&#039; THEN SUBSTRING(i.presentation,7) END AS &amp;quot;Possible Answers&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
CASE i.typ WHEN &#039;multichoice&#039; THEN v.value ELSE &#039;-&#039; END AS &amp;quot;Chosen Answer Num&amp;quot;,&lt;br /&gt;
CASE v.value&lt;br /&gt;
  WHEN 1 THEN SUBSTRING(i.presentation, 7, POSITION(&#039;|&#039; IN i.presentation) - 7) &lt;br /&gt;
  WHEN 2 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,2), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 3 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,3), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 4 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,4), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 5 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,5), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 6 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,6), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 7 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,7), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 8 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,8), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 9 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,9), &#039;|&#039;,-1) &lt;br /&gt;
  ELSE CONCAT(&amp;quot;More:&amp;quot;, v.value)&lt;br /&gt;
END AS &amp;quot;Chosen Answer Text&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_feedback AS f&lt;br /&gt;
JOIN prefix_course AS c ON c.id=f.course&lt;br /&gt;
JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
JOIN prefix_feedback_completed AS fc ON f.id=fc.feedback &lt;br /&gt;
LEFT JOIN prefix_feedback_value AS v ON v.completed=fc.id AND v.item=i.id&lt;br /&gt;
JOIN prefix_user AS u ON fc.userid=u.id&lt;br /&gt;
&lt;br /&gt;
WHERE i.typ IN (&#039;label&#039;, &#039;multichoice&#039;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Resource Module Reports==&lt;br /&gt;
===List &amp;quot;Recently uploaded files&amp;quot;===&lt;br /&gt;
see what users are uploading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT FROM_UNIXTIME(time,&#039;%Y %M %D %h:%i:%s&#039;) as time ,ip,userid,url,info  &lt;br /&gt;
FROM `prefix_log` &lt;br /&gt;
WHERE `action` LIKE &#039;upload&#039; &lt;br /&gt;
ORDER BY `prefix_log`.`time`  DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Courses that loaded a specific file: &amp;quot;X&amp;quot;===&lt;br /&gt;
Did the Teacher (probably) uploaded course&#039;s Syllabus ?&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname  FROM `prefix_log` as l &lt;br /&gt;
JOIN prefix_course as c ON c.id = l.course &lt;br /&gt;
WHERE `action` LIKE &#039;%upload%&#039; AND ( info LIKE &#039;%Syllabus%&#039; OR info LIKE &#039;%Sylabus%&#039; ) GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All resources that link to some specific external website===&lt;br /&gt;
+ link to course&lt;br /&gt;
+ who&#039;s the teacher&lt;br /&gt;
+ link to external resource&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/resource/view.php?id=&#039;,r.id,&#039;&amp;quot;&amp;gt;&#039;,r.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Resource&lt;br /&gt;
FROM prefix_resource AS r &lt;br /&gt;
JOIN prefix_course AS c ON r.course = c.id&lt;br /&gt;
WHERE r.reference LIKE &#039;http://info.oranim.ac.il/home%&#039; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;quot;Compose Web Page&amp;quot; RESOURCE count===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT course,prefix_course.fullname, COUNT(*) AS Total&lt;br /&gt;
FROM `prefix_resource`&lt;br /&gt;
JOIN `prefix_course` ON prefix_course.id = prefix_resource.course&lt;br /&gt;
WHERE type=&#039;html&#039;&lt;br /&gt;
GROUP BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resource count in courses===&lt;br /&gt;
+ (First)Teacher name&lt;br /&gt;
+ Where course is inside some specific Categories&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
COUNT(*) AS count&lt;br /&gt;
,r.course &lt;br /&gt;
,c.shortname shortname&lt;br /&gt;
,c.fullname coursename&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user as u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = r.course AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
FROM prefix_resource r &lt;br /&gt;
JOIN prefix_course c ON r.course = c.id&lt;br /&gt;
WHERE c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY r.course&lt;br /&gt;
ORDER BY COUNT(*) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Delete all the automated backup files===&lt;br /&gt;
Prepare bash cli script to delete all the automated backup files on the file system. (clean up some disk space)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT( &#039;rm -f /var/moodledatanew/filedir/&#039;, SUBSTRING( contenthash, 1, 2 ) , &#039;/&#039;, SUBSTRING( contenthash, 3, 2 ) , &#039;/&#039;, contenthash ) &lt;br /&gt;
FROM `mdl_files` &lt;br /&gt;
WHERE `filename` LIKE &#039;%mbz%&#039;&lt;br /&gt;
AND filearea = &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find out how much disk space is used by all automated backup files:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT SUM(filesize)/(1024*1024*1024) FROM `mdl_files` WHERE  `filename` LIKE &#039;%mbz%&#039; AND filearea =  &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Forum Module Reports==&lt;br /&gt;
===print all User&#039;s post in course Forums===&lt;br /&gt;
%%COURSEID%% is a variable the is replace by the current CourseID you are running the sql report from. if you are using the latest block/configurable_reports ! (You can always change it to a fixed course or remove it to display all courses.)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php?course=&#039;,c.id,&#039;&amp;amp;id=&#039;,u.id,&#039;&amp;amp;mode=posts&amp;quot;&amp;gt;&#039;,CONCAT(u.firstname,&#039; &#039;, u.lastname),&#039;&amp;lt;/a&amp;gt;&#039;) As Fullname&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Forum&lt;br /&gt;
,count(*) as Posts&lt;br /&gt;
,(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&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_user as u ON u.id = fp.userid &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = fd.course &lt;br /&gt;
WHERE fd.course = %%COURSEID%% &lt;br /&gt;
GROUP BY f.id,u.id&lt;br /&gt;
ORDER BY u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE by type -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, prefix_forum.type, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course,prefix_forum.type&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Forum activity - system wide===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,c.fullname as Course&lt;br /&gt;
,f.type&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
, fd.forum, f.name,count(*) AS cPostAndDisc&lt;br /&gt;
,(SELECT count(*) FROM prefix_forum_discussions AS ifd WHERE ifd.forum = f.id) AS cDiscussion&lt;br /&gt;
FROM prefix_forum_posts AS fp&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type != &#039;news&#039; AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
## WHERE 1=1 &lt;br /&gt;
## %%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count( * ) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Activity In Forums===&lt;br /&gt;
Trying to figure out how much real activity we have in Forums by aggregating:&lt;br /&gt;
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...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname,f.name,f.type &lt;br /&gt;
,(SELECT count(id) FROM prefix_forum_discussions as fd WHERE f.id = fd.forum) as Discussions&lt;br /&gt;
,(SELECT count(distinct fd.userid) FROM prefix_forum_discussions as fd WHERE fd.forum = f.id) as UniqueUsersDiscussions&lt;br /&gt;
,(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&lt;br /&gt;
,(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&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS StudentsCount&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Teachers&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS &#039;Teacher&amp;lt;br/&amp;gt;Count&#039;&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid IN (3,5)&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS UserCount&lt;br /&gt;
, (SELECT (UniqueUsersDiscussions / StudentsCount )) as StudentDissUsage&lt;br /&gt;
, (SELECT (UniqueUsersPosts /StudentsCount)) as StudentPostUsage&lt;br /&gt;
FROM prefix_forum as f &lt;br /&gt;
JOIN prefix_course as c ON f.course = c.id&lt;br /&gt;
WHERE `type` != &#039;news&#039;&lt;br /&gt;
ORDER BY StudentPostUsage DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Forum type:NEWS===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT f.id, f.name&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
WHERE m.name = &#039;forum&#039;&lt;br /&gt;
AND f.type = &#039;news&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All new forum NEWS items (discussions) from all my Courses===&lt;br /&gt;
change &amp;quot;userid = 26&amp;quot; and &amp;quot;id = 26&amp;quot; to a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname,f.name,fd.name,FROM_UNIXTIME(fd.timemodified ,&amp;quot;%d %M %Y &amp;quot;) as Date&lt;br /&gt;
FROM prefix_forum_discussions as fd &lt;br /&gt;
JOIN prefix_forum as f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = f.course &lt;br /&gt;
JOIN prefix_user_lastaccess as ul ON (c.id = ul.courseid AND ul.userid = 26)&lt;br /&gt;
WHERE fd.timemodified &amp;gt; ul.timeaccess  &lt;br /&gt;
 AND fd.forum IN (SELECT f.id&lt;br /&gt;
 FROM prefix_course_modules AS cm&lt;br /&gt;
 JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
 JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
 WHERE m.name = &#039;forum&#039;&lt;br /&gt;
 AND f.type = &#039;news&#039;)&lt;br /&gt;
  AND c.id IN (SELECT c.id&lt;br /&gt;
   FROM prefix_course AS c&lt;br /&gt;
   JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
   JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
   JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
   WHERE u.id = 26) ORDER BY `fd`.`timemodified` DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===News Forum - Discussions COUNT===&lt;br /&gt;
Which is actually... How much instructions students get from their teachers&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname ,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,count(fd.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS DiscussionsSum&lt;br /&gt;
FROM prefix_forum_discussions AS fd&lt;br /&gt;
INNER JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
INNER JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type = &#039;news&#039; AND c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count(fd.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cantidad de foros que han sido posteados por profesor===&lt;br /&gt;
&lt;br /&gt;
(Number of forums that have been posted by teacher/Google translator)&lt;br /&gt;
&lt;br /&gt;
Queriamos saber cuales son las acciones del profesor dentro de los foros de cada curso, por ello se hizo este informe.&lt;br /&gt;
&lt;br /&gt;
(We wanted to know what the teacher&#039;s actions are in the forums of each course, so this report was made. /Google translator)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS curso,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Facilitador,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( m.name ) AS COUNT FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS foros,&lt;br /&gt;
&lt;br /&gt;
COUNT(*) AS Posts&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course AS c ON c.id = fd.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = fp.userid &lt;br /&gt;
&lt;br /&gt;
WHERE fp.userid =&lt;br /&gt;
(&lt;br /&gt;
select distinct prefix_user.id&lt;br /&gt;
from prefix_user &lt;br /&gt;
join prefix_role_assignments as ra on ra.userid = prefix_user.id &lt;br /&gt;
where ra.roleid = 3 &lt;br /&gt;
and userid = fp.userid&lt;br /&gt;
limit 1&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
and c.shortname like &#039;%2014-2-1%&#039;&lt;br /&gt;
GROUP BY c.id, u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all the Forums that got high rating===&lt;br /&gt;
We setup a scale that let teachers and students Rate forum post with &amp;quot;Important, interesting, valuable, not rated&amp;quot; scale&lt;br /&gt;
And then add a link to the following report at the begining of the course &amp;quot;Link to all interesting posts&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,f.id,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;,fd.id,&#039;#p&#039;,fp.id,&#039;&amp;quot;&amp;gt;&#039;,fp.subject,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post link&#039;,&lt;br /&gt;
SUM(r.rating) AS &#039;Rating&#039;&lt;br /&gt;
FROM mdl_rating AS r&lt;br /&gt;
  JOIN mdl_forum_posts AS fp ON fp.id = r.itemid&lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
WHERE r.component = &#039;mod_forum&#039; AND r.ratingarea = &#039;post&#039; AND f.course = %%COURSEID%%&lt;br /&gt;
GROUP BY r.itemid&lt;br /&gt;
ORDER BY SUM(r.rating) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all Discussions of a single Forum===&lt;br /&gt;
This report is used to help export all the student&#039;s posts and discussions of a single forum, by passing the context module id as a parameter to the report using &amp;quot;&amp;amp;filter_var=cmid&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;, f.id, &#039;&amp;quot;&amp;gt;&#039;, f.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name&#039;,&lt;br /&gt;
fd.name AS &#039;Discussion&#039;, &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;, fd.id, &#039;#p&#039;, fp.id, &#039;&amp;quot;&amp;gt;&#039;, fp.subject, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post (link)&#039;,&lt;br /&gt;
fp.message&lt;br /&gt;
&lt;br /&gt;
FROM mdl_forum_posts AS fp &lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
  JOIN mdl_course_modules AS cm ON cm.module = 9 AND cm.instance = f.id&lt;br /&gt;
WHERE cm.id = %%FILTER_VAR%%&lt;br /&gt;
ORDER BY f.id, fd.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Quiz Module Reports==&lt;br /&gt;
===Generate a list of instructors and their email addresses for those courses that has &amp;quot;essay questions&amp;quot; in their quizzes===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT qu.id AS quiz_id, qu.course AS course_id, qu.questions,&lt;br /&gt;
                co.fullname AS course_fullname, co.shortname AS course_shortname,&lt;br /&gt;
                qu.name AS quiz_name, FROM_UNIXTIME(qu.timeopen) AS quiz_timeopen, FROM_UNIXTIME(qu.timeclose) AS quiz_timeclose,&lt;br /&gt;
                u.firstname, u.lastname, u.email,&lt;br /&gt;
FROM prefix_quiz qu, prefix_course co, prefix_role re, prefix_context ct, prefix_role_assignments ra, prefix_user u&lt;br /&gt;
WHERE FROM_UNIXTIME(timeopen) &amp;gt; &#039;2008-05-14&#039; AND&lt;br /&gt;
                qu.course = co.id AND&lt;br /&gt;
                co.id = ct.instanceid AND&lt;br /&gt;
                ra.roleid = re.id AND&lt;br /&gt;
                re.name = &#039;Teacher&#039; AND&lt;br /&gt;
                ra.contextid = ct.id AND&lt;br /&gt;
                ra.userid = u.id&lt;br /&gt;
 &lt;br /&gt;
SELECT Count(&#039;x&#039;) As NumOfStudents&lt;br /&gt;
                                FROM prefix_role_assignments a&lt;br /&gt;
                                JOIN prefix_user u ON userid = u.id&lt;br /&gt;
                                WHERE roleid = 5 AND contextid = (SELECT id FROM prefix_context WHERE instanceid = 668 AND contextlevel = 50)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Number of Quizes per Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Link&amp;lt;/a&amp;gt;&#039;) AS Quizes&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules cm&lt;br /&gt;
JOIN prefix_course c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module&lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039;&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all MultiAnswer (Cloze) Questions===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/attempt.php?q=&#039;, quiz.id, &#039;&amp;quot;&amp;gt;&#039;, quiz.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS Quiz&lt;br /&gt;
,question.id question_id, question.questiontext &lt;br /&gt;
FROM  prefix_question question&lt;br /&gt;
JOIN prefix_quiz_question_instances qqi ON question.id = qqi.question&lt;br /&gt;
JOIN prefix_quiz quiz ON qqi.quiz = quiz.id&lt;br /&gt;
WHERE  `qtype` LIKE  &#039;multianswer&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List courses with MANUAL grades===&lt;br /&gt;
Which is basically and indication to teachers using Moodle to hold offline grades inside Moodle&#039;s Gradebook,&lt;br /&gt;
So grades could be uploaded into an administrative SIS. Use with Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT( * )&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php?showadvanced=1&amp;amp;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM  prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course as c ON c.id = gi.courseid&lt;br /&gt;
WHERE  `itemtype` =  &#039;manual&#039;&lt;br /&gt;
GROUP BY courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===List the users that did not take the Quiz===&lt;br /&gt;
Do not forget to change &amp;quot;c.id = 14&amp;quot; and q.name LIKE &#039;%quiz name goes here%&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id AS ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.username AS IDNumber,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
 &lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id AND courseid=c.id) AS CourseLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id AND e.courseid = c.id) AS RoleName&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess AS ul ON ul.userid = user2.id&lt;br /&gt;
WHERE c.id=14 and ue.userid NOT IN (SELECT qa.userid FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON qa.quiz = q.id&lt;br /&gt;
JOIN prefix_course AS c ON q.course = c.id&lt;br /&gt;
WHERE c.id = 14 AND q.name LIKE &#039;%quiz name goes here%&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Questions in each Quiz===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT quiz.id,quiz.name, q.id, q.name&lt;br /&gt;
FROM mdl_quiz AS quiz&lt;br /&gt;
JOIN mdl_question AS q ON FIND_IN_SET(q.id, quiz.questions)&lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
ORDER BY quiz.id ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this query does not work in Moodle 2.8+. There is no mdl_quiz.questions field. It will need to be rewritten to use the usage/contextid organization.&lt;br /&gt;
&lt;br /&gt;
Here is a version for Moodle 3.x&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cm.id &#039;cmid&#039;, quiz.id &#039;quiz id&#039;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/edit.php?cmid=&#039;, &lt;br /&gt;
	   cm.id, &#039;&amp;quot;&amp;gt;&#039;, quiz.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;edit quiz&#039;&lt;br /&gt;
,q.id &#039;qid&#039;, q.name &#039;question name&#039;&lt;br /&gt;
FROM mdl_quiz AS quiz&lt;br /&gt;
JOIN mdl_course_modules cm ON cm.instance = quiz.id AND cm.module = 33 # 33=quiz mdl_modules&lt;br /&gt;
JOIN mdl_quiz_slots qs ON qs.quizid = quiz.id &lt;br /&gt;
JOIN mdl_question AS q ON q.id = qs.questionid&lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
ORDER BY quiz.id ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quiz activity research===&lt;br /&gt;
This report was made to extract student full activity in quizzes for an academic research about adapting instructional design teaching methods in online learning. The students do not use the Quiz module as a standard quiz but more as Study booklets or mini courses with embedded questions and hints to assist students evaluate their progress (Similar to what you expect to find in a SCORM activity)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cm.course &amp;quot;course_id&amp;quot;, cm.id &amp;quot;moduel_id&amp;quot;, q.id &amp;quot;quiz_id&amp;quot;, q.name &amp;quot;quiz_name&amp;quot;,&lt;br /&gt;
 &lt;br /&gt;
CASE q.grademethod&lt;br /&gt;
      WHEN 1 THEN &amp;quot;GRADEHIGHEST&amp;quot;&lt;br /&gt;
      WHEN 2 THEN &amp;quot;GRADEAVERAGE&amp;quot;&lt;br /&gt;
      WHEN 3 THEN &amp;quot;ATTEMPTFIRST&amp;quot;&lt;br /&gt;
      WHEN 4 THEN &amp;quot;ATTEMPTLAST&amp;quot;&lt;br /&gt;
END &amp;quot;grade method&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
, q.attempts &amp;quot;quiz_attempts_allowed&amp;quot;, cm.groupmode &amp;quot;group_mode&amp;quot;&lt;br /&gt;
, qa.id &amp;quot;attempt_id&amp;quot;, qa.state &amp;quot;attempt_state&amp;quot;, qa.sumgrades &amp;quot;attempt_grade&amp;quot;, qg.grade &amp;quot;user_final_grade&amp;quot;, q.grade &amp;quot;quiz_max_grade&amp;quot;&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = q.course AND m.userid = u.id) &amp;quot;user_groups&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timestart), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_start&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timefinish), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_finish&amp;quot;,&lt;br /&gt;
u.id &amp;quot;user_id&amp;quot;, u.firstname, u.lastname,&lt;br /&gt;
question.id &amp;quot;question_id&amp;quot;, question.name &amp;quot;question_name&amp;quot;,&lt;br /&gt;
qas.state &amp;quot;question_step_state&amp;quot;,qas.fraction &amp;quot;question_grade&amp;quot;, qh.hint, question.qtype &amp;quot;question_type&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz as q&lt;br /&gt;
JOIN mdl_course_modules as cm ON cm.instance = q.id and cm.module = 14 &lt;br /&gt;
JOIN mdl_quiz_attempts qa ON q.id = qa.quiz&lt;br /&gt;
LEFT JOIN mdl_quiz_grades as qg ON qg.quiz = q.id and qg.userid = qa.userid&lt;br /&gt;
JOIN mdl_user as u ON u.id = qa.userid&lt;br /&gt;
JOIN mdl_question_usages as qu ON qu.id = qa.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts as qatt ON qatt.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question as question ON question.id = qatt.questionid&lt;br /&gt;
JOIN mdl_question_attempt_steps as qas ON qas.questionattemptid = qatt.id&lt;br /&gt;
LEFT JOIN mdl_question_hints as qh ON qh.questionid = q.id&lt;br /&gt;
#WHERE q.id = &amp;quot;SOME QUIZ ID&amp;quot;&lt;br /&gt;
WHERE cm.course = &amp;quot;SOME COURSE ID&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quiz Usage in Courses by Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Multiple Choice&amp;quot; questions include true/false and matching question types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Short Answer&amp;quot; are questions that accept a single phrase.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Other&amp;quot; questions include fixed numerical, calculated, essay, and various drag and drop types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Min Quiz Age&amp;quot; and &amp;quot;Max Quiz Age&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: In Configurable Reports, the Date Filter is not applied until the &amp;quot;Apply&amp;quot; button is clicked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.shortname AS &#039;Course&#039;&lt;br /&gt;
#, u.lastname AS &#039;Instructor&#039;&lt;br /&gt;
, COUNT(DISTINCT q.id) AS &#039;Quizzes&#039;&lt;br /&gt;
, COUNT(DISTINCT qu.id) AS &#039;Questions&#039;&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 ))  AS &#039;multichoice&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT( qu.id) - SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;Other&#039;&lt;br /&gt;
&lt;br /&gt;
, (SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )))/COUNT( qu.id) AS &#039;Percent MC&#039;&lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;numerical&#039;, 1, 0 )) AS &#039;numerical&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype LIKE &#039;calc%&#039;, 1, 0 )) AS &#039;calculated&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;random&#039;, 1, 0 )) AS &#039;random&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;essay&#039;, 1, 0 )) AS &#039;essay&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, IF(q.shufflequestions &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Questions&#039;&lt;br /&gt;
, IF(q.shuffleanswers &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Answers&#039;&lt;br /&gt;
 &lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
#, FROM_UNIXTIME(MIN(q.timemodified)) AS &#039;Last Modified&#039;&lt;br /&gt;
&lt;br /&gt;
#, DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(MIN(q.timemodified))) AS &#039;Quiz age&#039;&lt;br /&gt;
&lt;br /&gt;
, MIN(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Min Quiz Age&#039; &lt;br /&gt;
, MAX(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Max Quiz Age&#039; &lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified)) &amp;lt; 90, 1,0)) AS &#039;new quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_quiz AS q&lt;br /&gt;
JOIN prefix_course AS c on c.id = q.course&lt;br /&gt;
JOIN prefix_quiz_question_instances AS qqi ON qqi.quiz = q.id&lt;br /&gt;
LEFT JOIN prefix_question AS qu ON qu.id = qqi.question&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%% %%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student responses (answers) to quiz questions===&lt;br /&gt;
(Contributed by Juan F with help from Tim hunt and fellow Moodlers on the forums)&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    concat( u.firstname, &amp;quot; &amp;quot;, u.lastname ) AS &amp;quot;Student Name&amp;quot;,&lt;br /&gt;
    u.id,&lt;br /&gt;
    quiza.userid,&lt;br /&gt;
    q.course,&lt;br /&gt;
    q.name,&lt;br /&gt;
    quiza.attempt,&lt;br /&gt;
    qa.slot,&lt;br /&gt;
    que.questiontext AS &#039;Question&#039;,&lt;br /&gt;
    qa.rightanswer AS &#039;Correct Answer&#039;,&lt;br /&gt;
    qa.responsesummary AS &#039;Student Answer&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz_attempts quiza&lt;br /&gt;
JOIN mdl_quiz q ON q.id=quiza.quiz&lt;br /&gt;
JOIN mdl_question_usages qu ON qu.id = quiza.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts qa ON qa.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question que ON que.id = qa.questionid&lt;br /&gt;
JOIN mdl_user u ON u.id = quiza.userid&lt;br /&gt;
&lt;br /&gt;
WHERE q.name = &amp;quot;BIO 208 Post Test Assessment&amp;quot;&lt;br /&gt;
AND q.course = &amp;quot;17926&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ORDER BY quiza.userid, quiza.attempt, qa.slot&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Questions which are tagged within a course/quiz===&lt;br /&gt;
Calculates subgrades for tags in the each of the quizzes in a course. &lt;br /&gt;
Contributed by Daniel Thies in https://moodle.org/mod/forum/discuss.php?d=324314#p1346542&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
    quiz.name AS quiz,&lt;br /&gt;
    t.rawname AS tag,&lt;br /&gt;
    CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/review.php?attempt=&#039;,&lt;br /&gt;
            MAX(quiza.id),&#039;&amp;quot;&amp;gt;&#039;,u.firstname,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS student,&lt;br /&gt;
    CAST(SUM(qas.fraction) as decimal(12,1)) AS correct,&lt;br /&gt;
    CAST(SUM(qa.maxmark) as decimal(12,1)) AS maximum,&lt;br /&gt;
    CAST(SUM(qas.fraction)/SUM(qa.maxmark)*100 as decimal(4,2)) AS score&lt;br /&gt;
FROM prefix_quiz_attempts quiza&lt;br /&gt;
JOIN prefix_user u ON quiza.userid = u.id&lt;br /&gt;
JOIN prefix_question_usages qu ON qu.id = quiza.uniqueid&lt;br /&gt;
JOIN prefix_question_attempts qa ON qa.questionusageid = qu.id&lt;br /&gt;
JOIN prefix_quiz quiz ON quiz.id = quiza.quiz&lt;br /&gt;
JOIN prefix_tag_instance ti ON qa.questionid = ti.itemid&lt;br /&gt;
JOIN prefix_tag t ON t.id = ti.tagid&lt;br /&gt;
JOIN (SELECT MAX(fraction) AS fraction, questionattemptid&lt;br /&gt;
        FROM prefix_question_attempt_steps&lt;br /&gt;
        GROUP BY questionattemptid) qas ON qas.questionattemptid = qa.id &lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
GROUP BY quiza.userid,&lt;br /&gt;
    quiza.quiz,&lt;br /&gt;
    quiz.name,&lt;br /&gt;
    u.firstname,&lt;br /&gt;
    u.lastname,&lt;br /&gt;
    ti.tagid,&lt;br /&gt;
    t.rawname&lt;br /&gt;
ORDER BY quiza.quiz, t.rawname, u.lastname, u.firstname, score&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==SCORM Activity Reports==&lt;br /&gt;
&lt;br /&gt;
===Lists All completed SCORM activites by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists SCORM status for all enrolled users by Course name===&lt;br /&gt;
This report will list the SCORM status for all users enrolled in the course. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. This can be limited to individual courses by adding to the where clause the course id to report on.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.firstname AS First,&lt;br /&gt;
u.lastname AS Last, &lt;br /&gt;
u.idnumber AS Employee_ID,  &lt;br /&gt;
u.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
u.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course, &lt;br /&gt;
st.attempt AS Attempt,&lt;br /&gt;
st.value AS Status,&lt;br /&gt;
FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) AS Date &lt;br /&gt;
&lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
&lt;br /&gt;
WHERE st.element=&#039;cmi.core.lesson_status&#039; AND m.userid=u.id&lt;br /&gt;
&lt;br /&gt;
UNION&lt;br /&gt;
&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS First,&lt;br /&gt;
user2.lastname AS Last,&lt;br /&gt;
user2. idnumber AS Employee_ID,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
user2.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Attempt,&lt;br /&gt;
&amp;quot;not_started&amp;quot; AS Status,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Date&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = user2.id &lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.course=c.id&lt;br /&gt;
Left Join prefix_scorm_scoes_track AS st on st.scormid=sc.id AND st.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
WHERE  st.timemodified IS NULL AND m.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY  Course, Last, First, Attempt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Badges==&lt;br /&gt;
&lt;br /&gt;
=== All badges issued, by User ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, b.name AS badgename, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN&lt;br /&gt;
(SELECT c.shortname&lt;br /&gt;
    FROM prefix_course AS c&lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Context,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 1 THEN &amp;quot;Activity Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 2 THEN &amp;quot;Activity Completion (Any)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 2 AND t.method = 2 THEN &amp;quot;Manual Award&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 1 THEN &amp;quot;Course Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 2 THEN &amp;quot;Course Completion (Any)&amp;quot;&lt;br /&gt;
  ELSE CONCAT (&#039;Other: &#039;, t.criteriatype)&lt;br /&gt;
END AS Criteriatype,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateissued ) , &#039;%Y-%m-%d&#039; ) AS dateissued,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateexpire ), &#039;%Y-%m-%d&#039; ) AS dateexpires,&lt;br /&gt;
CONCAT (&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/badge.php?hash=&#039;,d.uniquehash,&#039;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&#039;) AS Details&lt;br /&gt;
FROM prefix_badge_issued AS d &lt;br /&gt;
JOIN prefix_badge AS b ON d.badgeid = b.id&lt;br /&gt;
JOIN prefix_user AS u ON d.userid = u.id&lt;br /&gt;
JOIN prefix_badge_criteria AS t on b.id = t.badgeid &lt;br /&gt;
WHERE t.criteriatype &amp;lt;&amp;gt; 0&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&lt;br /&gt;
=== All badges available in the system, with Earned count ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.type = 1 THEN &amp;quot;System&amp;quot;&lt;br /&gt;
WHEN b.type = 2 THEN &amp;quot;Course&amp;quot;&lt;br /&gt;
END AS Context, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN &lt;br /&gt;
(SELECT c.shortname &lt;br /&gt;
    FROM prefix_course AS c &lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 2 THEN &amp;quot;No&amp;quot;&lt;br /&gt;
WHEN b.status = 1 OR b.status = 3 THEN &amp;quot;Yes&amp;quot;&lt;br /&gt;
WHEN b.status = 4 THEN &amp;quot;x&amp;quot;&lt;br /&gt;
END AS Available,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 1 THEN &amp;quot;0&amp;quot;&lt;br /&gt;
WHEN b.status = 2 OR b.status = 3 OR b.status = 4 THEN &lt;br /&gt;
 (SELECT COUNT(*) &lt;br /&gt;
   FROM prefix_badge_issued AS d&lt;br /&gt;
   WHERE d.badgeid = b.id&lt;br /&gt;
 )&lt;br /&gt;
END AS Earned&lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Badges Leaderboard ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A simple list of usernames and how many badges they have earned overall.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, (SELECT COUNT(*) FROM prefix_badge_issued AS d WHERE d.userid = u.id) AS earned&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
ORDER BY earned DESC, u.username ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Manage badges (System &amp;amp; Course) ===&lt;br /&gt;
&lt;br /&gt;
List system wide badges, course and system level badges + a link to relevant &amp;quot;manage badges&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description &lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN b.type = 1 THEN &#039;System&#039;&lt;br /&gt;
  WHEN b.type = 2 THEN &#039;Course&#039;&lt;br /&gt;
END AS Level&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/index.php?type=&#039;, b.type, &#039;&amp;amp;id=&#039;,&lt;br /&gt;
			  c.id, &#039;&amp;quot;&amp;gt;Manage badges in: &#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Manage &lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Administrator Reports==&lt;br /&gt;
&lt;br /&gt;
===Config changes in Export friendly form===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( g.timemodified ) , &#039;%Y-%m-%d&#039; ) AS date, &lt;br /&gt;
u.username AS user, &lt;br /&gt;
g.name AS setting, &lt;br /&gt;
CASE &lt;br /&gt;
 WHEN g.plugin IS NULL THEN &amp;quot;core&amp;quot;&lt;br /&gt;
 ELSE g.plugin&lt;br /&gt;
END AS plugin, &lt;br /&gt;
g.value AS new_value, &lt;br /&gt;
g.oldvalue AS original_value&lt;br /&gt;
FROM prefix_config_log  AS g&lt;br /&gt;
JOIN prefix_user AS u ON g.userid = u.id&lt;br /&gt;
ORDER BY date DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts by user===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
How to get a list of all users and which cohorts they belong to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, h.idnumber, h.name&lt;br /&gt;
FROM prefix_cohort AS h&lt;br /&gt;
JOIN prefix_cohort_members AS hm ON h.id = hm.cohortid&lt;br /&gt;
JOIN prefix_user AS u ON hm.userid = u.id&lt;br /&gt;
ORDER BY u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts with Courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all cohorts with name, id, visibility, and which courses they are enrolled in.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
# h.id,&lt;br /&gt;
# e.customint1,&lt;br /&gt;
h.name AS Cohort,&lt;br /&gt;
h.idnumber AS Cohortid,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN h.visible = 1 THEN &#039;Yes&#039;&lt;br /&gt;
 ELSE &#039;-&#039;&lt;br /&gt;
END AS Cohortvisible,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;, CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_cohort h&lt;br /&gt;
JOIN prefix_enrol e ON h.id = e.customint1&lt;br /&gt;
JOIN prefix_course c ON c.id = e.courseid %%FILTER_COURSES:e.courseid%% &lt;br /&gt;
WHERE e.enrol = &#039;cohort&#039; AND e.roleid = 5&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses created And Active courses by Year===&lt;br /&gt;
Active courses is counting course that have at least one Hit, And &amp;quot;Active_MoreThan100Hits&amp;quot; counts courses that have at least 100 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `timecreated` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT course ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY course &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 100) AS courses_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( courses_log.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan100Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_course` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users created And Active users by Year===&lt;br /&gt;
Active users is counting users that have at least one Hit, And &amp;quot;Active_MoreThan500Hits&amp;quot; counts users that have at least 500 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `firstaccess` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT userid ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY userid &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 500) AS users_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( users_log.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan500Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Aggregation Report===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In particular, be on the lookout for any courses with the following combinations of parameters, which are known to cause changes in calculations:&lt;br /&gt;
&lt;br /&gt;
# mean of grades set with aggregate with subcategory.&lt;br /&gt;
# Simple weighted mean of grades with aggregate with sub category and drop the lowest&lt;br /&gt;
# Sum of grades drop the lowest&lt;br /&gt;
&lt;br /&gt;
Also review:&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48618&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48634&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-49257&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50089&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50062&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
COUNT(c.shortname) AS &#039;Count of Courses&#039;&lt;br /&gt;
&lt;br /&gt;
# If you want to display all the courses for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, c.shortname AS &#039;course name&#039;&lt;br /&gt;
&lt;br /&gt;
# If you need to display grade categories for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, gc.fullname AS &#039;grade category name&#039;&lt;br /&gt;
&lt;br /&gt;
, gc.aggregation AS &#039;aggregation method&#039;&lt;br /&gt;
&lt;br /&gt;
#These aggregation text strings appear to be hard-coded. I couldn&#039;t find a table for them. If you have aggregation types I haven&#039;t included here, they&#039;ll be blank in your report results.&lt;br /&gt;
, CASE gc.aggregation&lt;br /&gt;
  WHEN 0 THEN &#039;Mean of Grades&#039;&lt;br /&gt;
  WHEN 2 THEN &#039;Median of Grades&#039;&lt;br /&gt;
  WHEN 6 THEN &#039;Highest Grade&#039;&lt;br /&gt;
  WHEN 8 THEN &#039;Mode of Grades&#039;&lt;br /&gt;
  WHEN 10 THEN &#039;Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 11 THEN &#039;Simple Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 12 THEN &#039;Mean of Grades (with extra credits)&#039;&lt;br /&gt;
  WHEN 13 THEN &#039;Sum of Grades&#039;&lt;br /&gt;
END AS &#039;aggregation name&#039;&lt;br /&gt;
&lt;br /&gt;
# Note that gc.aggregatesubcats column is eliminated in 2.8 and later per MDL-47503, so comment that line on updated systems or you&#039;ll get an error&lt;br /&gt;
, gc.keephigh AS &#039;keep high&#039;&lt;br /&gt;
, gc.droplow AS &#039;dr0p low&#039;&lt;br /&gt;
, gc.aggregateonlygraded AS &#039;Aggregate only graded&#039;&lt;br /&gt;
, gc.aggregateoutcomes AS &#039;aggregate outcomes&#039;&lt;br /&gt;
, gc.aggregatesubcats AS &#039;aggregate subcategories&#039;&lt;br /&gt;
&lt;br /&gt;
# If you are displaying data about individual courses, you may want to know how old they are&lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;course start date&#039;&lt;br /&gt;
&lt;br /&gt;
# 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&#039;ll need to uncomment the necessary JOINs below&lt;br /&gt;
#, gi.itemname AS &#039;grade item&#039;&lt;br /&gt;
#, gg.finalgrade AS &#039;final grade&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
&lt;br /&gt;
prefix_course AS c&lt;br /&gt;
JOIN prefix_grade_categories AS gc ON gc.courseid = c.id&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id #AND gi.categoryid=gc.id&lt;br /&gt;
#LEFT JOIN prefix_grade_grades AS gg ON gg.itemid = gi.id AND gg.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
#AND gc.aggregation = 13 #only the dreaded Sum of Grades aggregations&lt;br /&gt;
#AND gc.depth = 1 # if for some reason you only want course aggregations, not subcategories&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.aggregation, gc.keephigh, gc.droplow, gc.aggregateonlygraded, gc.aggregateoutcomes, gc.aggregatesubcats&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running Cron jobs (task_scheduled) ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT classname&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(lastruntime), &#039;%H:%i [%d]&#039;) AS &#039;last&#039;&lt;br /&gt;
  ,DATE_FORMAT(now(), &#039;%H:%i&#039;) AS &#039;now&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(nextruntime), &#039;%H:%i [%d]&#039;) AS &#039;next&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP()-nextruntime), &#039;%i&#039;) AS &#039;next in min&#039;&lt;br /&gt;
FROM mdl_task_scheduled&lt;br /&gt;
WHERE now() &amp;gt; FROM_UNIXTIME(nextruntime)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Flat file enrollments waiting for processing ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
This lists all enrolments uploaded by the [[Flat_file|Flat file enrolment method]] that are currently waiting to be processed. When the optional enrolment start date is set for a user in the file, and this start date is in the future, the enrolment information is held in the database until the time for the actual enrolment to start at which time the user is actually enroled. This report allows you to see any and all such enrolments that are waiting to be done. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.username,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
ef.action,&lt;br /&gt;
r.shortname AS &amp;quot;Role&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(ef.timestart),&#039;%Y-%m-%d %H:%i&#039;)  AS &amp;quot;Enrolment Start&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(ef.timeend),&#039;%Y-%m-%d %H:%i&#039;)  AS &amp;quot;Enrolment End&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(ef.timemodified),&#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;Uploaded Date&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_enrol_flatfile ef&lt;br /&gt;
JOIN prefix_user u ON u.id = ef.userid&lt;br /&gt;
JOIN prefix_course c ON c.id = ef.courseid&lt;br /&gt;
JOIN prefix_role r ON r.id = ef.roleid&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== All Meta courses with Parent and Child course relationships ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
This shows the list of courses with Meta course link enrollments in them (&#039;Parent course&#039;), and the courses which are connected to them to provide enrollments (&#039;Child courses&#039;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.fullname AS &#039;Parent course name&#039;,&lt;br /&gt;
c.shortname AS &#039;Parent course shortname&#039;,&lt;br /&gt;
en.courseid AS &#039;Parent course id&#039;,&lt;br /&gt;
(SELECT fullname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course name&#039;,&lt;br /&gt;
(SELECT shortname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course shortname&#039;,&lt;br /&gt;
en.customint1 AS &#039;Child course id&#039;&lt;br /&gt;
FROM prefix_enrol en&lt;br /&gt;
JOIN prefix_course c ON c.id = en.courseid&lt;br /&gt;
WHERE en.enrol = &#039;meta&#039;&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== All Private Files by User ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Lists all files by all users in the Private Files repository, with the file path location and name in the moodledata/filedir directory structure, and time created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.username, &lt;br /&gt;
f.filename, &lt;br /&gt;
CONCAT(&#039;/&#039;, LEFT(f.contenthash,2), &#039;/&#039;, MID(f.contenthash,3,2), &#039;/&#039;, f.contenthash) AS &amp;quot;Filedir_Location&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(f.timecreated),&#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;Created&amp;quot;&lt;br /&gt;
FROM prefix_files f &lt;br /&gt;
JOIN prefix_user u ON u.id = f.userid&lt;br /&gt;
WHERE f.component = &#039;user&#039; &lt;br /&gt;
AND f.filearea = &#039;private&#039; &lt;br /&gt;
AND f.filesize &amp;gt; 0 &lt;br /&gt;
ORDER BY u.username, f.filename&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== All Tags in use in Courses and Activities ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Shows all tags that are in use in Courses and in Activities. Shows the tag name, which course it is used in, whether it is a course level tag or an activity level tag, along with handy links to the course and activity. If it is an tag in an activity, it shows the activity type and its name. Also shows you if the tag is a Standard tag or not in the system, and if not, which user created the tag. &lt;br /&gt;
&lt;br /&gt;
Note: this version includes the new H5P core activity in its list of modules.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
t.name AS &amp;quot;Tag&amp;quot;,&lt;br /&gt;
CASE ti.itemtype&lt;br /&gt;
  WHEN &#039;course&#039; THEN &#039;Course&#039;&lt;br /&gt;
  ELSE &amp;quot;Activity&amp;quot;&lt;br /&gt;
END AS &amp;quot;Tag_Type&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
# get the course name&lt;br /&gt;
CASE ti.itemtype&lt;br /&gt;
  WHEN &#039;course&#039; THEN &lt;br /&gt;
   (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,id,&#039;&amp;quot;&amp;gt;&#039;,shortname,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_course WHERE id = ti.itemid)&lt;br /&gt;
  ELSE &lt;br /&gt;
   (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,id,&#039;&amp;quot;&amp;gt;&#039;,shortname,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_course WHERE id = cm.course)&lt;br /&gt;
END AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
# get the activity type&lt;br /&gt;
CASE ti.itemtype&lt;br /&gt;
  WHEN &#039;course&#039; THEN &#039;-&#039;&lt;br /&gt;
  ELSE &lt;br /&gt;
     # (SELECT CONCAT(name, &#039; (&#039;,cm.module,&#039;)&#039;) FROM prefix_modules WHERE id = cm.module)&lt;br /&gt;
	 m.name&lt;br /&gt;
END AS &amp;quot;Activity_Type&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
# get the activity name&lt;br /&gt;
CASE ti.itemtype&lt;br /&gt;
  WHEN &#039;course&#039; THEN &#039;-&#039;&lt;br /&gt;
  ELSE &lt;br /&gt;
    CASE&lt;br /&gt;
    WHEN m.name = &#039;assign&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_assign WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;assignment&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_assignment WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;book&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_book WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;chat&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_chat WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;choice&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_choice WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;data&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_data WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;feedback&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_feedback WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;folder&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_folder WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;forum&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_forum  WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;glossary&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_glossary WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;h5pactivity&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_h5pactivity WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;imscp&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_imscp WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;label&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_label WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;lesson&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_lesson WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;lti&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_lti WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;page&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_page WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;quiz&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_quiz WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;resource&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_resource WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;scorm&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_scorm WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;survey&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_survey WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;url&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_url WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;wiki&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_wiki WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;workshop&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_workshop WHERE id = cm.instance)&lt;br /&gt;
     # add any others you have installed here with their id number&lt;br /&gt;
     ELSE CONCAT(&amp;quot;Unknown_mod_id: &amp;quot;, cm.module)&lt;br /&gt;
     END&lt;br /&gt;
END AS &amp;quot;Activity_name&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
# get tag standard &lt;br /&gt;
CASE t.isstandard&lt;br /&gt;
  WHEN 1 THEN &#039;Yes&#039;&lt;br /&gt;
  ELSE CONCAT(&#039;No (&#039;, (SELECT username FROM prefix_user WHERE id = t.userid),&#039;)&#039;)&lt;br /&gt;
END AS &amp;quot;Standard&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_tag_instance ti&lt;br /&gt;
JOIN prefix_tag t ON t.id = ti.tagid&lt;br /&gt;
JOIN prefix_tag_coll tc ON tc.id = t.tagcollid&lt;br /&gt;
JOIN prefix_course_modules cm ON cm.id = ti.itemid&lt;br /&gt;
JOIN prefix_modules m ON m.id = cm.module&lt;br /&gt;
&lt;br /&gt;
WHERE ti.component = &#039;core&#039; &lt;br /&gt;
AND (ti.itemtype = &#039;course&#039; OR ti.itemtype = &#039;course_modules&#039;) &lt;br /&gt;
&lt;br /&gt;
ORDER BY 1,2,3,4,5&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Learning Analytics Reports ==&lt;br /&gt;
(Moodle v. 3.4 and later)&lt;br /&gt;
&lt;br /&gt;
=== Learning Analytics Model Summary ===&lt;br /&gt;
This report provides a list of the learning analytics models on your site, whether enabled or not, and several details about them.&lt;br /&gt;
&lt;br /&gt;
(Note: this report was created on a system using PostgreSQL. Some changes may be needed for other forms of SQL.)&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
am.id AS &amp;quot;model id&amp;quot;,	 &lt;br /&gt;
split_part(am.target,&#039;\&#039;,5) AS &amp;quot;target&amp;quot;,&lt;br /&gt;
CASE WHEN am.enabled=1 THEN &#039;YES&#039; ELSE &#039;NO&#039; END AS &amp;quot;enabled&amp;quot;,	 &lt;br /&gt;
CASE WHEN am.trained=1 THEN &#039;YES&#039; ELSE &#039;NO&#039; END AS &amp;quot;trained&amp;quot;,&lt;br /&gt;
am.name,	 &lt;br /&gt;
/* indicators,*/&lt;br /&gt;
char_length(am.indicators) - char_length(REPLACE(am.indicators,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;indicator count&amp;quot;,&lt;br /&gt;
split_part(am.timesplitting,&#039;\&#039;,5) AS &amp;quot;interval&amp;quot;,&lt;br /&gt;
/*&lt;br /&gt;
to_timestamp(am.version) AS &amp;quot;version&amp;quot;,	 &lt;br /&gt;
to_timestamp(am.timecreated) AS &amp;quot;time created&amp;quot;,	 &lt;br /&gt;
to_timestamp(am.timemodified) AS &amp;quot;time modified&amp;quot;,	&lt;br /&gt;
*/&lt;br /&gt;
COUNT(DISTINCT ap.contextid) AS &amp;quot;contexts&amp;quot;,&lt;br /&gt;
COUNT(ap.sampleid) AS &amp;quot;samples&amp;quot;,&lt;br /&gt;
/* AVG(ap.prediction) AS &amp;quot;avg prediction&amp;quot;, */&lt;br /&gt;
ROUND(ap.prediction,1) AS &amp;quot;prediction&amp;quot;,		   &lt;br /&gt;
ROUND(AVG(aml.score),3) AS &amp;quot;model accuracy (avg)&amp;quot;,&lt;br /&gt;
apa.actionname AS &amp;quot;action&amp;quot;,&lt;br /&gt;
COUNT(apa.id) AS &amp;quot;number actions taken&amp;quot;&lt;br /&gt;
		   &lt;br /&gt;
FROM prefix_analytics_models AS am&lt;br /&gt;
JOIN prefix_analytics_predictions AS ap ON am.id = ap.modelid&lt;br /&gt;
LEFT JOIN prefix_analytics_models_log AS aml ON aml.modelid = am.id&lt;br /&gt;
LEFT JOIN prefix_analytics_prediction_actions AS apa ON apa.predictionid = ap.id&lt;br /&gt;
GROUP BY am.id, ap.prediction, apa.actionname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Indicator Calculations ===&lt;br /&gt;
Pulls calculations from the &amp;quot;analytics_indicator_calc&amp;quot; table consisting of all calculations made for each indicator for each sample within each context for every model. In most cases you will want to limit this per context or sample, or at least group by context and sample.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id,	 &lt;br /&gt;
to_timestamp(starttime) AS &amp;quot;start time&amp;quot;,	 &lt;br /&gt;
to_timestamp(endtime) AS &amp;quot;end time&amp;quot;,	 &lt;br /&gt;
contextid,	 &lt;br /&gt;
sampleorigin,	 &lt;br /&gt;
sampleid,	 &lt;br /&gt;
/*indicator, */&lt;br /&gt;
split_part(indicator,&#039;\&#039;,2) AS &amp;quot;module&amp;quot;,&lt;br /&gt;
split_part(indicator,&#039;\&#039;,5) AS &amp;quot;indicator type&amp;quot;,&lt;br /&gt;
value,	 &lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_indicator_calc&lt;br /&gt;
WHERE id = 1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Analytics Models ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_models&amp;quot; table consisting of one row per model. See the &amp;quot;Learning Analytics Model Summary&amp;quot; report, above, for an expanded report that JOINs model data from different tables to provide a more comprehensive view.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
id,	 &lt;br /&gt;
enabled,	 &lt;br /&gt;
trained, &lt;br /&gt;
name,	 &lt;br /&gt;
split_part(target,&#039;\&#039;,5) AS &amp;quot;target&amp;quot;,&lt;br /&gt;
/* indicators,*/&lt;br /&gt;
char_length(indicators) - char_length(REPLACE(indicators,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;indicator count&amp;quot;,&lt;br /&gt;
split_part(timesplitting,&#039;\&#039;,5) AS &amp;quot;interval&amp;quot;,&lt;br /&gt;
predictionsprocessor, &lt;br /&gt;
to_timestamp(version) AS &amp;quot;version&amp;quot;,	 &lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;,	 &lt;br /&gt;
to_timestamp(timemodified) AS &amp;quot;time modified&amp;quot;,	 &lt;br /&gt;
usermodified&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_models&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Analytics Models Log ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_models_log&amp;quot; table consisting of evaluation calculations per model. If model evaluations have not been manually executed on the system from the command line, there will be no contents in this table.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
id,	 &lt;br /&gt;
modelid,	 &lt;br /&gt;
to_timestamp(version) AS &amp;quot;version&amp;quot;,	 &lt;br /&gt;
evaluationmode,	 &lt;br /&gt;
split_part(target,&#039;\&#039;,5) AS &amp;quot;target&amp;quot;,	 &lt;br /&gt;
/* indicators,*/&lt;br /&gt;
char_length(indicators) - char_length(REPLACE(indicators,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;indicator count&amp;quot;,&lt;br /&gt;
split_part(timesplitting,&#039;\&#039;,5) AS &amp;quot;interval&amp;quot;,	 &lt;br /&gt;
score,	 &lt;br /&gt;
info,	 &lt;br /&gt;
dir,	 &lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;,	 &lt;br /&gt;
usermodified&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_models_log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Predictions ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_predictions&amp;quot; table consisting of one row per prediction per model. Counts the number of indicators calculated for each prediction, but does not list them. If a model has not yet been trained, the system cannot make predictions and this table will not include rows for that model ID. See the &amp;quot;Learning Analytics Model Summary&amp;quot; report, above, for an expanded report that JOINs model data from different tables to provide a more comprehensive view.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id,	 &lt;br /&gt;
modelid,	 &lt;br /&gt;
contextid,	 &lt;br /&gt;
sampleid,	 &lt;br /&gt;
rangeindex,	 &lt;br /&gt;
prediction,	 &lt;br /&gt;
predictionscore,	 &lt;br /&gt;
char_length(calculations) - char_length(REPLACE(calculations,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;indicators calculated&amp;quot;,&lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;,	 &lt;br /&gt;
to_timestamp(timestart) AS &amp;quot;time start&amp;quot;,	 &lt;br /&gt;
to_timestamp(timeend) AS &amp;quot;time end&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from prefix_analytics_predictions&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Prediction Actions ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_prediction_actions&amp;quot; table consisting of one row per action taken per prediction (e.g. a teacher viewing the outline report for a student at risk). If the model has not yet made predictions, there can be no prediction actions. See the &amp;quot;Learning Analytics Model Summary&amp;quot; report, above, for an expanded report that JOINs model data from different tables to provide a more comprehensive view.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
id,	 &lt;br /&gt;
predictionid,	 &lt;br /&gt;
userid,	 &lt;br /&gt;
actionname,	 &lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_prediction_actions&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Analytics Predictions with All Indicators ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_predictions&amp;quot; table consisting of one row per prediction per model. Lists the indicators calculated for each prediction. If a model has not yet been trained, the system cannot make predictions and this table will not include rows for that model ID.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id AS &amp;quot;Prediction ID&amp;quot;,	 &lt;br /&gt;
modelid AS &amp;quot;Model ID&amp;quot;,	 &lt;br /&gt;
contextid AS &amp;quot;Context ID&amp;quot;,	 &lt;br /&gt;
sampleid AS &amp;quot;Sample ID&amp;quot;,	 &lt;br /&gt;
rangeindex AS &amp;quot;Analysis Interval&amp;quot;,	 &lt;br /&gt;
prediction AS &amp;quot;Prediction value&amp;quot;,	 &lt;br /&gt;
predictionscore,	 &lt;br /&gt;
calculations,&lt;br /&gt;
char_length(calculations) - char_length(REPLACE(calculations,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;indicators calculated&amp;quot;,&lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;,	 &lt;br /&gt;
to_timestamp(timestart) AS &amp;quot;time start&amp;quot;,	 &lt;br /&gt;
to_timestamp(timeend) AS &amp;quot;time end&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from prefix_analytics_predictions&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Predict Samples ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_predict_samples&amp;quot; table consisting of one row per analysis interval per model, with a count of the samples used for each prediction. Sample details are not included here, but the report can be modified to list samples by IDs if needed by parsing the contents of the sampleids field. For example, this counts the number of student enrolments for which the system has generated predictions for a given model and analysis interval.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id,	 &lt;br /&gt;
modelid,	 &lt;br /&gt;
analysableid,	 &lt;br /&gt;
split_part(timesplitting,&#039;\&#039;,5) AS &amp;quot;interval&amp;quot;,	 &lt;br /&gt;
rangeindex,	 &lt;br /&gt;
/* sampleids, */	 &lt;br /&gt;
char_length(sampleids) - char_length(REPLACE(sampleids,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;samples used&amp;quot;,&lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;,	 &lt;br /&gt;
to_timestamp(timemodified) AS &amp;quot;time modified&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_predict_samples&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Train Samples ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_train_samples&amp;quot; table consisting of one row per analysis interval per model, with a count of the samples used for each training calculation. &lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id,	 &lt;br /&gt;
modelid,	 &lt;br /&gt;
analysableid,	 &lt;br /&gt;
split_part(timesplitting,&#039;\&#039;,5) AS &amp;quot;interval&amp;quot;,&lt;br /&gt;
/* sampleids,	*/&lt;br /&gt;
char_length(sampleids) - char_length(REPLACE(sampleids,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;samples used&amp;quot;,&lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_train_samples&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Used Analysables ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_used_analysables&amp;quot; table consisting of one row per context per model, noting whether the analysable was used to train the model or to make a prediction. This data is used to control the training and prediction processes.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id,	 &lt;br /&gt;
modelid,	 &lt;br /&gt;
action,	 &lt;br /&gt;
analysableid,	 &lt;br /&gt;
to_timestamp(firstanalysis) AS &amp;quot;first analysis&amp;quot;,	 &lt;br /&gt;
to_timestamp(timeanalysed) AS &amp;quot;time analysed&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_used_analysables&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Used Files ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_used_files&amp;quot; table consisting of one row per file per model, noting whether the file was used to train the model or to make a prediction. This data is used to control the training and prediction processes.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
id,	 &lt;br /&gt;
modelid,	 &lt;br /&gt;
fileid,	 &lt;br /&gt;
action,	 &lt;br /&gt;
TO_TIMESTAMP(time) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_used_files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Average Cognitive Depth and Social Breadth===&lt;br /&gt;
&lt;br /&gt;
Here is a simple SQL snippet to calculate average cognitive depth and social breadth indicators for all students in the system. This one ignores  indicator values of 0, as they are nulls as defined in this model.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
i.contextid,&lt;br /&gt;
i.sampleid,&lt;br /&gt;
&lt;br /&gt;
TRUNC(AVG(CASE&lt;br /&gt;
WHEN i.indicator LIKE &#039;%cognitive%&#039; THEN i.value &lt;br /&gt;
ELSE &#039;0&#039;&lt;br /&gt;
END),2) AS &amp;quot;Average Cognitive Depth&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
TRUNC(AVG(CASE&lt;br /&gt;
WHEN i.indicator LIKE &#039;%social%&#039; THEN i.value &lt;br /&gt;
ELSE &#039;0&#039;&lt;br /&gt;
END),2) AS &amp;quot;Average Social Breadth&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_indicator_calc as i&lt;br /&gt;
WHERE&lt;br /&gt;
i.value != 0&lt;br /&gt;
GROUP BY i.contextid, i.sampleid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Competencies==&lt;br /&gt;
&lt;br /&gt;
===List of competencies from a framework and the courses including them===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
f.shortname AS &#039;Framework&#039;,&lt;br /&gt;
comp.shortname AS &#039;Competency&#039;, &lt;br /&gt;
cccomp.courseid AS &#039;Course id&#039;, &lt;br /&gt;
c.fullname AS &#039;Course name&#039;,&lt;br /&gt;
c.shortname AS &#039;Course code&#039;&lt;br /&gt;
FROM &lt;br /&gt;
prefix_competency_coursecomp AS cccomp &lt;br /&gt;
INNER JOIN prefix_competency AS comp ON cccomp.competencyid = comp.id&lt;br /&gt;
INNER JOIN prefix_course AS c ON cccomp.courseid = c.id&lt;br /&gt;
INNER JOIN prefix_competency_framework AS f ON comp.competencyframeworkid = f.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Count the courses using each competency from frameworks===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is not a filter by competency framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
f.shortname AS framework,&lt;br /&gt;
comp.shortname AS &#039;Competency&#039;,&lt;br /&gt;
COUNT(cccomp.competencyid) AS &#039;nb course&#039;&lt;br /&gt;
FROM prefix_competency AS comp&lt;br /&gt;
INNER JOIN prefix_competency_framework AS f ON comp.competencyframeworkid = f.id&lt;br /&gt;
LEFT JOIN prefix_competency_coursecomp AS cccomp ON cccomp.competencyid = comp.id&lt;br /&gt;
GROUP BY comp.id, comp.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Scale details with ids ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Competency import and export files include scales with id numbers. However, the management page in Grades &amp;gt; Scales does not have the scale id, nor other useful details that scales store about themselves, like who made them and when, and what context they pertain to. This simple query shows you that information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
s.id AS Scaleid,&lt;br /&gt;
s.name AS Scale_Name,&lt;br /&gt;
s.scale AS Scale,&lt;br /&gt;
CASE  &lt;br /&gt;
  WHEN s.courseid = 0 THEN &#039;System&#039;&lt;br /&gt;
  ELSE (SELECT shortname FROM prefix_course WHERE id = s.courseid)&lt;br /&gt;
END AS Context,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN s.userid = 0 THEN &#039;System&#039;&lt;br /&gt;
  ELSE (SELECT username FROM prefix_user WHERE id = s.userid)&lt;br /&gt;
END AS User,&lt;br /&gt;
s.description,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(s.timemodified), &#039;%Y-%m-%d %H:%i&#039; ) AS &#039;Modified&#039;&lt;br /&gt;
FROM prefix_scale s&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syllabus==&lt;br /&gt;
&lt;br /&gt;
Our school simply asks teachers to drop a file (resource) on their course page&lt;br /&gt;
and rename this resource (not the file) starting with &amp;quot;syllabus&amp;quot; (case insensitive)&lt;br /&gt;
&lt;br /&gt;
===Count the number of resources whose name starts by &amp;quot;Syllabus&amp;quot;===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
Select &lt;br /&gt;
r.name As &#039;Resource name&#039;,&lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a href=&amp;quot;%%WWWROOT%%/pluginfile.php/&#039;, ct.id, &#039;/mod_resource/content/1/&#039;, f.filename, &#039;&amp;quot;&amp;gt;&#039;,f.filename,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Clickable filename&#039;,&lt;br /&gt;
&lt;br /&gt;
c.fullname AS &#039;Course name&#039;,&lt;br /&gt;
c.shortname AS &#039;Course shortname&#039;,&lt;br /&gt;
&lt;br /&gt;
# the date filters are connected to this &amp;quot;last modif&amp;quot; field&lt;br /&gt;
# userful to check if the syllabus has been updated this year&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(f.timemodified), &#039;%e %b %Y&#039;) AS &#039;last modif&#039;, &lt;br /&gt;
&lt;br /&gt;
# tell if the file is visible by the students or hidden&lt;br /&gt;
IF(cm.visible=0,&amp;quot;masqué&amp;quot;,&amp;quot;visible&amp;quot;) AS &#039;Visibility&#039;,&lt;br /&gt;
&lt;br /&gt;
# next line tries to give the real path (local path) if you want to create a zip file using an external script)&lt;br /&gt;
# notice that the path is in the column &amp;quot;contenthash&amp;quot; and NOT in the column pathhash&lt;br /&gt;
# if the contenthash starts with 9af3... then the file is stored in moodledata/filedir/9a/f3/contenthash&lt;br /&gt;
# I try to get the path to moodledata from the value of the geoip variable in the mdl_config table... maybe a bad idea&lt;br /&gt;
CONCAT(&#039;&amp;quot;&#039;,(Select left(value, length(value)-25) from prefix_config where name =&amp;quot;geoip2file&amp;quot;),&#039;/filedir/&#039;, left(f.contenthash,2), &amp;quot;/&amp;quot;,substring(f.contenthash,3,2),&#039;/&#039;, f.contenthash, &#039;&amp;quot;&#039;) AS &#039;link&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
INNER JOIN prefix_course_modules AS cm ON cm.instance = r.id&lt;br /&gt;
INNER JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
INNER JOIN prefix_context AS ct ON ct.instanceid = cm.id&lt;br /&gt;
JOIN prefix_course_categories cc ON c.category = cc.id&lt;br /&gt;
INNER JOIN prefix_files AS f ON f.contextid = ct.id AND f.mimetype IS NOT NULL AND f.component = &#039;mod_resource&#039;&lt;br /&gt;
WHERE LOWER( r.name) LIKE &#039;syllabus%&#039;&lt;br /&gt;
%%FILTER_STARTTIME:f.timemodified:&amp;gt;%% %%FILTER_ENDTIME:f.timemodified:&amp;lt;%%&lt;br /&gt;
%%FILTER_SUBCATEGORIES:cc.path%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List files which have been tagged &amp;quot;Syllabus&amp;quot;===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
Select &lt;br /&gt;
t.rawname AS &#039;rawtag&#039;,&lt;br /&gt;
c.shortname AS &#039;Cours shortname&#039;,&lt;br /&gt;
c.fullname AS &#039;Course name&#039;,&lt;br /&gt;
r.name As &#039;Resource name&#039;,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a href=&amp;quot;%%WWWROOT%%/pluginfile.php/&#039;, ti.contextid, &#039;/mod_resource/content/1/&#039;, f.filename, &#039;&amp;quot;&amp;gt;cliquez ici&amp;lt;/a&amp;gt;&#039;) AS &#039;link&#039;,&lt;br /&gt;
ti.contextid AS &#039;Instance for link&#039;,&lt;br /&gt;
f.id AS &#039;file id&#039; &lt;br /&gt;
FROM prefix_tag_instance AS ti&lt;br /&gt;
INNER JOIN prefix_tag AS t ON ti.tagid = t.id&lt;br /&gt;
INNER JOIN prefix_course_modules AS cm ON ti.itemid = cm.id&lt;br /&gt;
INNER JOIN prefix_course AS c ON cm.course = c.id&lt;br /&gt;
INNER JOIN prefix_resource AS r ON r.id = cm.instance&lt;br /&gt;
INNER JOIN prefix_files AS f ON f.contextid = ti.contextid AND f.mimetype IS NOT NULL&lt;br /&gt;
WHERE t.rawname = &#039;Syllabus&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of courses WITHOUT a resource with a name starting by &amp;quot;syllabus&amp;quot;===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select c.id, c.shortname,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;, c.id, &#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Course link&#039;&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
  Select r.course &lt;br /&gt;
  from prefix_resource AS r&lt;br /&gt;
  WHERE LOWER( r.name) LIKE &#039;syllabus%&#039;&lt;br /&gt;
  GROUP BY r.course) AS r ON r.course = c.id&lt;br /&gt;
INNER JOIN prefix_course_categories cc ON c.category = cc.id&lt;br /&gt;
WHERE r.course IS NULL &lt;br /&gt;
%%FILTER_SUBCATEGORIES:cc.path%%&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%% %%FILTER_ENDTIME:c.enddate:&amp;lt;%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of courses have MULTIPLE resource with a name like &amp;quot;Syllabus%&amp;quot;===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
r.course,&lt;br /&gt;
c.shortname,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;, r.id, &#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Course link&#039;&lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
INNER JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories cc ON c.category = cc.id&lt;br /&gt;
WHERE LOWER( r.name) LIKE &#039;syllabus%&#039;&lt;br /&gt;
GROUP BY r.course HAVING count(r.course)&amp;gt;1&lt;br /&gt;
%%FILTER_SUBCATEGORIES:cc.path%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Chat==&lt;br /&gt;
&lt;br /&gt;
===List the chats===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
This report gives the list of all chats with the name of the course and various ids needed for further queries.&lt;br /&gt;
&lt;br /&gt;
The column &amp;quot;participants&amp;quot; is intended to work with an (optional) secondary report. If you don&#039;t need it , you can erase it.&lt;br /&gt;
It produces a direct link to another (optional) report which will give you the current participants list to this chat.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
c.shortname,&lt;br /&gt;
c.fullname,&lt;br /&gt;
ch.course, &lt;br /&gt;
ch.id,&lt;br /&gt;
# if you intend to use a secondary report to see the participants of a specific chat&lt;br /&gt;
# create the secondary report, check the id of the report in the url, and change the 21 in next line to your participant report&#039;s id&lt;br /&gt;
CONCAT(&#039;&amp;lt;a href=&amp;quot;%%WWWROOT%%/blocks/configurable_reports/viewreport.php?id=21&amp;amp;filter_courses=&#039;, ch.id,&#039;&amp;quot;&amp;gt;Chat participants&amp;lt;/a&amp;gt;&#039;) AS &#039;Course link&#039;,&lt;br /&gt;
ch.chattime&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_chat ch&lt;br /&gt;
INNER JOIN prefix_course c ON c.id = ch.course&lt;br /&gt;
&lt;br /&gt;
ORDER BY ch.chattime, c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Participants to a chat (optional secondary report)===&lt;br /&gt;
This version of the participant list is intended to work with a link given in the previous report.&lt;br /&gt;
* User opens the report listing all the chats on the platform&lt;br /&gt;
* user clicks on the link from the column &amp;quot;chat participant&amp;quot; &lt;br /&gt;
* which open this report with a filter on the chatid&lt;br /&gt;
&#039;&#039;(careful, we are tweaking the coursefilter to carry instead the chatid: the displayed &amp;quot;course filter&amp;quot; will not work! but we need it)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT&lt;br /&gt;
c.id AS courseid,&lt;br /&gt;
chu.chatid,&lt;br /&gt;
chu.userid AS &#039;chat user userid&#039;,&lt;br /&gt;
c.fullname,&lt;br /&gt;
u.username,&lt;br /&gt;
u.firstname,&lt;br /&gt;
u.lastname,&lt;br /&gt;
u.email&lt;br /&gt;
                                &lt;br /&gt;
FROM&lt;br /&gt;
prefix_user u &lt;br /&gt;
LEFT JOIN prefix_chat_users chu ON chu.userid = u.id&lt;br /&gt;
INNER JOIN prefix_course c ON c.id = chu.course&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1&lt;br /&gt;
%%FILTER_COURSES:chu.chatid%%&lt;br /&gt;
# you can also filter by course&lt;br /&gt;
# but don&#039;t put comment line between where and filter&lt;br /&gt;
# %%FILTER_COURSES:chu.course%%&lt;br /&gt;
&lt;br /&gt;
                                &lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List current participants to chat===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
c.id AS courseid,&lt;br /&gt;
chu.chatid,&lt;br /&gt;
chu.userid AS &#039;chat user userid&#039;,&lt;br /&gt;
c.fullname,&lt;br /&gt;
u.username,&lt;br /&gt;
u.firstname,&lt;br /&gt;
u.lastname,&lt;br /&gt;
u.email&lt;br /&gt;
                                &lt;br /&gt;
FROM&lt;br /&gt;
prefix_user u &lt;br /&gt;
LEFT JOIN prefix_chat_users chu ON chu.userid = u.id&lt;br /&gt;
INNER JOIN prefix_course c ON c.id = chu.course&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1&lt;br /&gt;
%%FILTER_COURSES:chu.course%%&lt;br /&gt;
                                &lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Useful sub queries ==&lt;br /&gt;
&lt;br /&gt;
IN this section please put any short one purpose sub queries that show how common procedures often useful as part of larger queries.&lt;br /&gt;
&lt;br /&gt;
=== All teachers in the course ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This snippet shows how to get teachers from a course. The contextevel for course objects is 50. And the default Teacher role is role id 3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course ic&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = ic.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND ic.id = c.id&lt;br /&gt;
GROUP BY ic.id&lt;br /&gt;
) AS TeacherNames&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Get custom User profile fields for a user ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON uid.fieldid = uif.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to limit it to one of those fields, you can restrict it by shortname of the custom profile field, so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;shortname1&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will show you only the data from the custom profile field with the shortname &#039;shortname1&#039;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, d1.data AS &#039;Profile One&#039;, d2.data As &#039;Profile Two&#039;&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
JOIN prefix_user_info_data d1 ON d1.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
JOIN prefix_user_info_data d2 ON d2.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f2 ON d2.fieldid = f2.id AND f2.shortname = &#039;shortname2&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== NOTE: Alternate Method ====&lt;br /&gt;
&lt;br /&gt;
If you have more than a couple of fields you need to use, then this query may time out or not return data due to too many joins. The limit seems to be around 10 custom profile fields. &lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thefirstfield&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname2&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thesecondfield&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== How to use Configurable Reports Date Time Filters===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Here is a simple example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.firstaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;FirstAccess&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.lastaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;LastAccess&#039;   &lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1&lt;br /&gt;
%%FILTER_STARTTIME:u.firstaccess:&amp;gt;%% &lt;br /&gt;
%%FILTER_ENDTIME:u.lastaccess:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2) You MUST then add the Start / End date filter on the Filters tab of the Report. If you don&#039;t, the report will still run, probably, but the filter will be ignored.&lt;br /&gt;
&lt;br /&gt;
Note: the WHERE 1=1 statement is a peculiarity of the filters in Config reports: if you don&#039;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.)&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://github.com/jleyva/moodle-configurable_reports_repository Configurable Reports Repository on GitHub]&lt;br /&gt;
* [https://moodleschema.zoola.io/index.html Moodle DB schema explorer] - searching and filtering tables, fields and external key connections between tables.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;br /&gt;
&lt;br /&gt;
[[es:Reportes específicos hechos por usuarios]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=139622</id>
		<title>ad-hoc contributed reports</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=139622"/>
		<updated>2021-02-08T14:01:24Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Hidden Courses with Students Enrolled */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Sitewide reports}}&lt;br /&gt;
==User and Role Report==&lt;br /&gt;
&lt;br /&gt;
===Count number of distinct learners and teachers enrolled per category (including all its sub categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;SELECT COUNT(DISTINCT lra.userid) AS learners, COUNT(DISTINCT tra.userid) as teachers&lt;br /&gt;
FROM prefix_course AS c #, mdl_course_categories AS cats&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments  AS lra ON lra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role_assignments  AS tra ON tra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category = cats.id&lt;br /&gt;
AND (&lt;br /&gt;
	cats.path LIKE &#039;%/CATEGORYID/%&#039; #Replace CATEGORYID with the category id you want to count (eg: 80)&lt;br /&gt;
	OR cats.path LIKE &#039;%/CATEGORYID&#039;&lt;br /&gt;
	)&lt;br /&gt;
AND lra.roleid=5&lt;br /&gt;
AND tra.roleid=3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each ROLE (TEACHER, NON-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT r.name, l.action, COUNT( l.userid ) AS counter&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_role AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE ra.roleid IN ( 3, 4, 5 ) &lt;br /&gt;
GROUP BY roleid, l.action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student (user) COUNT in each Course===&lt;br /&gt;
Including (optional) filter by: year (if included in course fullname).&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/index.php?contextid=&#039;,context.id,&#039;&amp;quot;&amp;gt;Show users&amp;lt;/a&amp;gt;&#039;) AS Users&lt;br /&gt;
, COUNT(course.id) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS asg&lt;br /&gt;
JOIN prefix_context AS context ON asg.contextid = context.id AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_user AS user ON user.id = asg.userid&lt;br /&gt;
JOIN prefix_course AS course ON context.instanceid = course.id&lt;br /&gt;
WHERE asg.roleid = 5 &lt;br /&gt;
# AND course.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
GROUP BY course.id&lt;br /&gt;
ORDER BY COUNT(course.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enrolment count in each Course ===&lt;br /&gt;
&lt;br /&gt;
Shows the total number of enroled users of all roles in each course. Sorted by course name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname, COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LIST of all site USERS by COURSE enrollment (Moodle 2.x)===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) as Role&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) as RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course as course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enrolled users,which did not login into the Course, even once (Moodle 2)===&lt;br /&gt;
Designed forMoodle 2 table structure and uses special plugin filter : %%FILTER_SEARCHTEXT:table.field%%&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id as ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
user2.idnumber AS IDNumber,&lt;br /&gt;
user2.phone1 AS Phone,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
&lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id and courseid=c.id) as CourseLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id and e.courseid = c.id) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments as ue&lt;br /&gt;
JOIN prefix_enrol as e on e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user as user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess as ul on ul.userid = user2.id&lt;br /&gt;
WHERE c.id=16 AND ul.timeaccess IS NULL&lt;br /&gt;
%%FILTER_SEARCHTEXT:user2.firstname%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enrolled users who have never accessed a given course (simpler version)===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, firstname, lastname, idnumber&lt;br /&gt;
FROM prefix_user_enrolments ue&lt;br /&gt;
JOIN prefix_enrol en ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user uu ON uu.id = ue.userid &lt;br /&gt;
WHERE en.courseid = 123456&lt;br /&gt;
AND NOT EXISTS (&lt;br /&gt;
    SELECT * FROM prefix_user_lastaccess la&lt;br /&gt;
    WHERE la.userid = ue.userid&lt;br /&gt;
    AND la.courseid = en.courseid&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Replace 123456 near the middle with your courseid)&lt;br /&gt;
&lt;br /&gt;
===Role assignments on categories===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS category,&lt;br /&gt;
cc.depth, cc.path, r.name AS role,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php?id=&#039;,usr.id,&#039;&amp;quot;&amp;gt;&#039;,usr.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS name,&lt;br /&gt;
usr.firstname, usr.username, usr.email&lt;br /&gt;
FROM prefix_course_categories cc&lt;br /&gt;
INNER JOIN prefix_context cx ON cc.id = cx.instanceid&lt;br /&gt;
AND cx.contextlevel = &#039;40&#039;&lt;br /&gt;
INNER JOIN prefix_role_assignments ra ON cx.id = ra.contextid&lt;br /&gt;
INNER JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
INNER JOIN prefix_user usr ON ra.userid = usr.id&lt;br /&gt;
ORDER BY cc.depth, cc.path, usr.lastname, usr.firstname, r.name, cc.name&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Permissions Overides on Categories===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712834 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT rc.id, ct.instanceid, ccat.name, rc.roleid, rc.capability, rc.permission, &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( rc.timemodified ) , &#039;%Y-%m-%d&#039; ) AS timemodified, rc.modifierid, ct.instanceid, ct.path, ct.depth&lt;br /&gt;
FROM `prefix_role_capabilities` AS rc&lt;br /&gt;
INNER JOIN `prefix_context` AS ct ON rc.contextid = ct.id&lt;br /&gt;
INNER JOIN `prefix_course_categories` AS ccat ON ccat.id = ct.instanceid&lt;br /&gt;
AND `contextlevel` =40&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;Totally Opened Courses&amp;quot; (visible, opened to guests, with no password)===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712837 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Course&#039;,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/enrol/instances.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Méthodes inscription&amp;lt;/a&amp;gt;&#039;) AS &#039;Enrollment plugins&#039;,&lt;br /&gt;
e.sortorder&lt;br /&gt;
FROM prefix_enrol AS e, prefix_course AS c&lt;br /&gt;
WHERE e.enrol=&#039;guest&#039; AND e.status=0 AND e.password=&#039;&#039; AND c.id=e.courseid AND c.visible=1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;loggedin users&amp;quot; from the last 120 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id,username,FROM_UNIXTIME(`lastlogin`) as days &lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;and user count for that same population:&#039;&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(id) as Users  FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Users loggedin within the last 7 days ====&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    l.* FROM mdl_logstore_standard_log l&lt;br /&gt;
WHERE&lt;br /&gt;
   l.eventname = &#039;\\core\\event\\user_loggedin&#039;&lt;br /&gt;
   AND FROM_UNIXTIME(l.timecreated, &#039;%Y-%m-%d&#039;) &amp;gt;= DATE_SUB(NOW(), INTERVAL 7 DAY)&lt;br /&gt;
&lt;br /&gt;
SELECT l.eventname FROM mdl_logstore_standard_log l&lt;br /&gt;
GROUP BY l.eventname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists the users who have only logged into the site once===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, username, firstname, lastname, idnumber&lt;br /&gt;
FROM prefix_user&lt;br /&gt;
WHERE prefix_user.deleted = 0&lt;br /&gt;
AND prefix_user.lastlogin = 0 &lt;br /&gt;
AND prefix_user.lastaccess &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Students in all courses of some institute===&lt;br /&gt;
What is the status (deleted or not) of all Students (roleid = 5) in all courses of some Institute&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname, u.firstname, u.lastname, u.deleted&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND u.institution = &#039;please enter school name here&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Full User info (for deleted users)===&lt;br /&gt;
Including extra custom profile fields (from prefix_user_info_data)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT * &lt;br /&gt;
FROM prefix_user as u &lt;br /&gt;
JOIN prefix_user_info_data as uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_user_info_field as uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;class&#039;)&lt;br /&gt;
WHERE `deleted` = &amp;quot;1&amp;quot; and `institution`=&amp;quot;your school name&amp;quot; and `department` = &amp;quot;your department&amp;quot; and `data` = &amp;quot;class level and number&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User&#039;s courses===&lt;br /&gt;
change &amp;quot;u.id = 2&amp;quot; with a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, c.id, c.fullname&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE u.id = 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Users with extra info (email) in current course===&lt;br /&gt;
blocks/configurable_reports replaces %%COURSEID%% with course id.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, u.email&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Students with enrollment and completion dates in current course===&lt;br /&gt;
This is meant to be a &amp;quot;global&amp;quot; report in Configurable Reports containing the following:&lt;br /&gt;
firstname, lastname, idnumber, institution, department, email, student enrolment date, student completion date&lt;br /&gt;
Note: for PGSQL, use to_timestamp() instead of FROM_UNIXTIME()&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.firstname&lt;br /&gt;
, u.lastname&lt;br /&gt;
, u.idnumber&lt;br /&gt;
, u.institution&lt;br /&gt;
, u.department&lt;br /&gt;
, u.email&lt;br /&gt;
, FROM_UNIXTIME(cc.timeenrolled)&lt;br /&gt;
, FROM_UNIXTIME(cc.timecompleted)&lt;br /&gt;
&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_completions AS cc ON cc.course = c.id AND cc.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Special Roles===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.roleid,r.name&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,ra.userid,&#039;&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Username&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON (ctx.id = ra.contextid AND ctx.contextlevel = 50)&lt;br /&gt;
JOIN prefix_course AS c ON ctx.instanceid = c.id&lt;br /&gt;
WHERE ra.roleid &amp;gt; 6&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses without Teachers===&lt;br /&gt;
Actually, shows the number of Teachers in a course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Teachers&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
ORDER BY Teachers ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of users who have been enrolled for more than 4 weeks===&lt;br /&gt;
For Moodle 2.2 , by  Isuru Madushanka Weerarathna &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT uenr.userid As User, IF(enr.courseid=uenr.courseid ,&#039;Y&#039;,&#039;N&#039;) As Enrolled, &lt;br /&gt;
IF(DATEDIFF(NOW(), FROM_UNIXTIME(uenr.timecreated))&amp;gt;=28,&#039;Y&#039;,&#039;N&#039;) As EnrolledMoreThan4Weeks&lt;br /&gt;
FROM prefix_enrol As enr, prefix_user_enrolments AS uenr&lt;br /&gt;
WHERE enr.id = uenr.enrolid AND enr.status = uenr.status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with language===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 (in the U.S., Canada and the Americas) is changing the default English to United States English. &lt;br /&gt;
&lt;br /&gt;
This will show you the language setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, lang from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools.&lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;en&#039; to &#039;en_us&#039; for all users:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To do this for only users who have a particular country set, use this as an example:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE country = &#039;US&#039; AND lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with Authentication ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Sometimes you need to do mass changes of authentication methods. A common case is changing default manual to LDAP. &lt;br /&gt;
&lt;br /&gt;
This will show you the Authentication setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, auth from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools. &lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;manual&#039; to &#039;ldap&#039; 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.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET auth = &#039;ldap&#039; WHERE auth = &#039;manual&#039; AND id &amp;gt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compare role capability and permissions ===&lt;br /&gt;
Compatibility: MySQL and PostgreSQL&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT mrc.capability &lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;1&#039; AND rc.contextid = &#039;1&#039;) AS Manager&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;2&#039; AND rc.contextid = &#039;1&#039;) AS Course_Creator&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;3&#039; AND rc.contextid = &#039;1&#039;) AS Teacher&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;4&#039; AND rc.contextid = &#039;1&#039;) AS Assistant_Teacher&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;5&#039; AND rc.contextid = &#039;1&#039;) AS Student&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;6&#039; AND rc.contextid = &#039;1&#039;) AS Guest&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;7&#039; AND rc.contextid = &#039;1&#039;) AS Authenticated&lt;br /&gt;
,(SELECT &#039;X&#039; FROM prefix_role_capabilities AS rc WHERE rc.capability = mrc.capability AND rc.roleid = &#039;8&#039; AND rc.contextid = &#039;1&#039;) AS Auth_front&lt;br /&gt;
FROM prefix_role_capabilities AS mrc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User&#039;s accumulative time spent in course ===&lt;br /&gt;
A sum up of the time delta between logstore_standard_log user&#039;s records, considering the a 2 hour session limit.&lt;br /&gt;
&lt;br /&gt;
Uses: current user&#039;s id %%USERID%% and current course&#039;s id %%COURSEID%%  &lt;br /&gt;
&lt;br /&gt;
And also using a date filter (which can be ignored)  &lt;br /&gt;
&lt;br /&gt;
The extra &amp;quot;User&amp;quot; field is used as a dummy field for the Line chart Series field, in which I use X=id, Series=Type, Y=delta.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
l.id, &lt;br /&gt;
l.timecreated, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(l.timecreated),&#039;%d-%m-%Y&#039;) AS dTime,&lt;br /&gt;
@prevtime := (SELECT max(timecreated) FROM mdl_logstore_standard_log &lt;br /&gt;
		WHERE userid = %%USERID%% and id &amp;lt; l.id ORDER BY id ASC LIMIT 1) AS prev_time,&lt;br /&gt;
IF (l.timecreated - @prevtime &amp;lt; 7200, @delta := @delta + (l.timecreated-@prevtime),0) AS sumtime,&lt;br /&gt;
l.timecreated-@prevtime AS delta,&lt;br /&gt;
&amp;quot;User&amp;quot; as type&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log as l, &lt;br /&gt;
(SELECT @delta := 0) AS s_init &lt;br /&gt;
# Change UserID&lt;br /&gt;
WHERE l.userid = %%USERID%% AND l.courseid = %%COURSEID%%&lt;br /&gt;
%%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Low-Participation Student Report ===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
This report returns a list of students who are enrolled in courses filtered by a short-name text marker (in this case &amp;quot;OL-&amp;quot;) in the specified category, but have very low participation in the course during the specified time period (fewer than 2 &amp;quot;Edits&amp;quot; to Activity Modules, indicating few active contributions to the course). The number of &amp;quot;Edits&amp;quot; is provided for each student for the time period specified.&lt;br /&gt;
&lt;br /&gt;
An &amp;quot;Edit&amp;quot; is defined as course activity other than viewing content. Click the &amp;quot;Logs&amp;quot; link to review the student activity. The Logs offer the option to review &amp;quot;View&amp;quot; activity as well as &amp;quot;Edit&amp;quot; activity.&lt;br /&gt;
&lt;br /&gt;
Only &amp;quot;visible&amp;quot; courses are included in this report. The report may be downloaded as an Excel spreadsheet.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t forget to set up Filters: &amp;quot;Start / End date filter&amp;quot; and &amp;quot;Filter categories&amp;quot; on the Filters tab in Configurable reports.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname AS Last, u.firstname AS First, u.idnumber AS IDnumber, u.email AS email, c.shortname AS CourseID,  count(l.id) AS Edits, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;https://learn.granite.edu/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=-view&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id AND l.action NOT LIKE &amp;quot;view%&amp;quot; %%FILTER_STARTTIME:l.TIME:&amp;gt;%% %%FILTER_ENDTIME:l.TIME:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.visible=1&lt;br /&gt;
# This prefix filter allows the exclusion of non-online courses at the original institution. Alter this to fit your institution, or remove it.&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
%%FILTER_CATEGORIES:c.category%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
HAVING Edits &amp;lt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Messages of All Users in a Specific Course ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
NOTE: I have deleted this query since it has not worked since 3.5 due to the changes in the structure of the Messages database in that version. If you really need this query for Moodle 3.4 or earlier (please upgrade!), then take a look at the earlier versions of this page for your particular version of Moodle. - RT&lt;br /&gt;
&lt;br /&gt;
===List of attendees/students that were marked present across courses===&lt;br /&gt;
This report will pull all Present students across a specific category.  &lt;br /&gt;
Contributed by: Emma Richardson&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &amp;quot;First Name&amp;quot;, u.lastname AS &amp;quot;Last Name&amp;quot;, u.Institution AS &amp;quot;District&amp;quot;,c.fullname AS &amp;quot;Training&amp;quot;, DATE_FORMAT(FROM_UNIXTIME(att.sessdate),&#039;%d %M %Y&#039;)AS Date&lt;br /&gt;
&lt;br /&gt;
FROM prefix_attendance_sessions AS att&lt;br /&gt;
JOIN prefix_attendance_log AS attlog ON att.id = attlog.sessionid&lt;br /&gt;
JOIN prefix_attendance_statuses AS attst ON attlog.statusid = attst.id&lt;br /&gt;
JOIN prefix_attendance AS a ON att.attendanceid = a.id&lt;br /&gt;
JOIN prefix_course AS c ON a.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON attlog.studentid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE attst.acronym = &amp;quot;P&amp;quot;&lt;br /&gt;
AND c.category = INSERT YOUR CATEGORY ID HERE&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Log Activity Reports==&lt;br /&gt;
===Count all Active Users by ROLE in a course category (including all of its sub-categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT l.userid) as active&lt;br /&gt;
FROM mdl_course as c&lt;br /&gt;
JOIN mdl_context AS ctx ON  ctx.instanceid=c.id&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN mdl_user_lastaccess as l ON ra.userid = l.userid&lt;br /&gt;
JOIN mdl_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category=cats.id AND (&lt;br /&gt;
	cats.path LIKE &#039;%/80/%&#039;&lt;br /&gt;
	OR cats.path LIKE &#039;%/80&#039;&lt;br /&gt;
) &lt;br /&gt;
AND ra.roleid=3  AND ctx.contextlevel=50  #ra.roleid= TEACHER 3, NON-EDITING TEACHER 4, STUDENT 5&lt;br /&gt;
AND  l.timeaccess &amp;gt; (unix_timestamp() - ((60*60*24)*NO_OF_DAYS)) #NO_OF_DAYS change to number&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Detailed &amp;quot;VIEW&amp;quot; ACTION for each ROLE (TEACHER,NONE-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT l.action, count( l.userid ) as counter , r.name&lt;br /&gt;
FROM `prefix_log` as l&lt;br /&gt;
JOIN `prefix_role_assignments` AS ra on l.userid = ra.userid&lt;br /&gt;
JOIN `prefix_role` AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE (ra.roleid IN (3,4,5)) AND (l.action LIKE &#039;%view%&#039; )&lt;br /&gt;
GROUP BY roleid,l.action&lt;br /&gt;
order by r.name,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total Activity of Roles:&amp;quot;Teacher&amp;quot; and &amp;quot;None-Editing Teacher&amp;quot; by Dates and by Hours===&lt;br /&gt;
The output columns of this report table can be used as base for a Pivot-Table&lt;br /&gt;
which will show the amount of &#039;&#039;&#039;activity&#039;&#039;&#039; per &#039;&#039;&#039;hour&#039;&#039;&#039; per &#039;&#039;&#039;days&#039;&#039;&#039; in 3D graph view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%Y-%m-%d&#039; ) AS grptimed ,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%k&#039; ) AS grptimeh  , count( l.userid ) AS counter &lt;br /&gt;
FROM `prefix_log` AS l&lt;br /&gt;
JOIN prefix_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
WHERE ra.roleid IN (3,4)&lt;br /&gt;
GROUP BY grptimed,grptimeh&lt;br /&gt;
ORDER BY grptimed,grptimeh&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many LOGINs per user and user&#039;s Activity===&lt;br /&gt;
+ link username to a user activity graph report&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,u.id,&#039;&amp;amp;mode=alllogs&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) as Username&lt;br /&gt;
,count(*) as logins&lt;br /&gt;
,(SELECT count(*) FROM prefix_log WHERE userid = l.userid GROUP BY userid) as Activity &lt;br /&gt;
FROM prefix_log as l JOIN prefix_user as u ON l.userid = u.id &lt;br /&gt;
WHERE `action` LIKE &#039;%login%&#039; group by userid&lt;br /&gt;
ORDER BY Activity DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Distinct user logins per month===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
The following will show you the months of the current calendar year with the total number of distinct, unique user logins per month. Change the year in the WHERE clause to the year you need.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
 COUNT(DISTINCT l.userid) AS &#039;DistinctUserLogins&#039;, &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%M&#039;) AS &#039;Month&#039;&lt;br /&gt;
FROM prefix_logstore_standard_log l&lt;br /&gt;
WHERE l.action = &#039;loggedin&#039; AND YEAR(FROM_UNIXTIME(l.timecreated)) = &#039;2017&#039; &lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(l.timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total activity per course, per unique user on the last 24h===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    COUNT(DISTINCT userid) AS countUsers&lt;br /&gt;
  , COUNT(l.courseid) AS countVisits&lt;br /&gt;
  , CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
  JOIN mdl_course AS c ON c.id = l.courseid&lt;br /&gt;
WHERE l.courseid &amp;gt; 0&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 1 DAY)&lt;br /&gt;
      AND c.fullname LIKE &#039;%תשעו%&#039;&lt;br /&gt;
GROUP BY l.courseid&lt;br /&gt;
ORDER BY countVisits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Instructor Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of instructors in all courses per week of a term, including pre-term and post-term edits. An edit is defined as a change to the course, such as a discussion post, the grading of an assignment, or the uploading of file attachments, as well as alterations to course content.&lt;br /&gt;
&lt;br /&gt;
* To specify a subject and/or course number, use % as a wildcard, e.g. ARTS% or ARTS501%&lt;br /&gt;
* To match part of a last name, use %, e.g. Smi% will match &amp;quot;Smith&amp;quot;, &amp;quot;Smile&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
At our institution, we include filters on the course name or category to constrain by terms. These are very specific to how course names and categories are constructed at our institution, so I&#039;ve removed those elements from this code. Also, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; lines for longer terms, or remove lines for shorter terms.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version uses legacy (pre-2.7) logs. See below for post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, c.startdate AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time)) - WEEK(FROM_UNIXTIME(c.startdate))&amp;lt;0,1,0)) AS BeforeTerm&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=0,1,0)) AS Week1&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=1,1,0)) AS Week2&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=2,1,0)) AS Week3&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=3,1,0)) AS Week4&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=4,1,0)) AS Week5&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=5,1,0)) AS Week6&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=6,1,0)) AS Week7&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=7,1,0)) AS Week8&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=8,1,0)) AS Week9&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=9,1,0)) AS Week10&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=10,1,0)) AS Week11&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=11,1,0)) AS Week12&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))&amp;gt;=12,1,0)) AS AfterTerm&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE :course&lt;br /&gt;
AND u.lastname LIKE :last_name&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 log version:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(DISTINCT l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
AND cc.idnumber LIKE &#039;%current%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
#HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY RIGHT(c.shortname,2), c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Student Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of students in the current course by week, including pre-term and post-term edits. An 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 (if permitted).&lt;br /&gt;
&lt;br /&gt;
Links to three other reports are also provided:&lt;br /&gt;
&lt;br /&gt;
* Logs: complete log entries for the student in the course, organized by date&lt;br /&gt;
* Activity Outline: the &amp;quot;Outline Report&amp;quot; from the User Activity Reports, summarizing the student&#039;s activity in the course, organized by course content&lt;br /&gt;
* Consolidated Activity Report: the &amp;quot;Complete Report&amp;quot; from the User Activity Reports, detailing the student&#039;s activity in the course, organized by course content (includes text of forum posts)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). At our institution, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for a post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF((l.time-c.startdate)/7&amp;lt;0,1,0)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=0,1,0)) AS &#039;Week 1&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=1,1,0)) AS &#039;Week 2&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=2,1,0)) AS &#039;Week 3&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=3,1,0)) AS &#039;Week 4&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=4,1,0)) AS &#039;Week 5&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=5,1,0)) AS &#039;Week 6&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=6,1,0)) AS &#039;Week 7&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=7,1,0)) AS &#039;Week 8&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=8,1,0)) AS &#039;Week 9&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=9,1,0)) AS &#039;Week 10&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=10,1,0)) AS &#039;Week 11&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=11,1,0)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))&amp;gt;=15,1,0)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 (Standard Logs) version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
# Our institution stores academic advisor names and emails in custom profile fields&lt;br /&gt;
#, CONCAT(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,uce.data,&#039;&amp;quot;&amp;gt;&#039;,uid.data, &#039;&amp;lt;/a&amp;gt;&#039;)  AS &#039;Academic Advisor&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,&#039;Posts&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Posts&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# student academic coach - you can include custom profile field data with these methods&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uid ON u.id = uid.userid AND uid.fieldid = &#039;2&#039;&lt;br /&gt;
# student academic coach email&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uce on u.id = uce.userid AND uce.fieldid = &#039;6&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===My Weekly Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of the &#039;&#039;&#039;current user&#039;&#039;&#039; in the &#039;&#039;&#039;current course&#039;&#039;&#039; 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).&lt;br /&gt;
&lt;br /&gt;
This report uses Standard Logs (post 2.7).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
l.component AS &#039;activity&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS &#039;Total&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE 1&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
AND u.id = %%USERID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY l.component&lt;br /&gt;
&lt;br /&gt;
ORDER BY l.component&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Faculty/Student Interactions===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Returns a count of instructor and other-student responses to student activity for the specified time period. This report can help indicate whether students&#039; comments are being responded to, as well as summarizing post activity by students during the specified time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for the post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This report can take a long time to run. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
LEFT JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
# We care about messages that involve both the instructor and students of this course&lt;br /&gt;
# messages from instructor to students:&lt;br /&gt;
# LEFT JOIN prefix_message AS mts ON mts.useridfrom = instr.id AND mts.useridto = allstu.id&lt;br /&gt;
# LEFT JOIN prefix_message AS mfs ON mfs.useridfrom = instr.id AND mfs.useridto = allstu.id&lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 Standard Logs version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
 JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student Resource Usage===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Standard Logs&amp;quot; from Moodle 2.7+.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
, m.name AS &#039;item type&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&lt;br /&gt;
COALESCE(a.name, &#039;&#039;), &lt;br /&gt;
COALESCE(b.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cert.name,&#039;&#039;), &lt;br /&gt;
COALESCE(chat.name,&#039;&#039;), &lt;br /&gt;
COALESCE(choice.name,&#039;&#039;), &lt;br /&gt;
COALESCE(data.name,&#039;&#039;), &lt;br /&gt;
COALESCE(feedback.name,&#039;&#039;), &lt;br /&gt;
COALESCE(folder.name,&#039;&#039;), &lt;br /&gt;
COALESCE(forum.name,&#039;&#039;), &lt;br /&gt;
COALESCE(glossary.name,&#039;&#039;), &lt;br /&gt;
COALESCE(imscp.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lesson.name,&#039;&#039;), &lt;br /&gt;
COALESCE(p.name,&#039;&#039;),&lt;br /&gt;
COALESCE(questionnaire.name,&#039;&#039;), &lt;br /&gt;
COALESCE(quiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cr.name,&#039;&#039;), &lt;br /&gt;
COALESCE(scorm.name,&#039;&#039;), &lt;br /&gt;
COALESCE(survey.name,&#039;&#039;), &lt;br /&gt;
COALESCE(url.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(workshop.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kalvidassign.name,&#039;&#039;), &lt;br /&gt;
COALESCE(attendance.name,&#039;&#039;), &lt;br /&gt;
COALESCE(checklist.name,&#039;&#039;), &lt;br /&gt;
COALESCE(flashcard.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lti.name,&#039;&#039;), &lt;br /&gt;
COALESCE(oublog.name,&#039;&#039;), &lt;br /&gt;
COALESCE(ouwiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(subpage.name,&#039;&#039;), &lt;br /&gt;
COALESCE(journal.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lightboxgallery.name,&#039;&#039;), &lt;br /&gt;
COALESCE(elluminate.name,&#039;&#039;), &lt;br /&gt;
COALESCE(adaptivequiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(hotpot.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiziq.name,&#039;&#039;), &lt;br /&gt;
COALESCE(turnitintooltwo.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kvr.name,&#039;&#039;)&lt;br /&gt;
) AS &#039;item name&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;r&#039;),1,0)) AS &#039;total views&#039;&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),1,0)) AS &#039;total submissions&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;r&#039;),u.id,NULL)) AS &#039;count of students who viewed&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),u.id,NULL)) AS &#039;count of students who submitted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 #AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module AND m.name NOT LIKE &#039;label&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON a.id = cm.instance AND m.name = &#039;assign&#039;&lt;br /&gt;
LEFT JOIN prefix_book AS b ON b.id = cm.instance AND m.name = &#039;book&#039;&lt;br /&gt;
LEFT JOIN prefix_certificate AS cert ON cert.id = cm.instance AND m.name = &#039;certificate&#039;&lt;br /&gt;
LEFT JOIN prefix_chat AS chat ON chat.id = cm.instance AND m.name = &#039;chat&#039;&lt;br /&gt;
LEFT JOIN prefix_choice AS choice ON choice.id = cm.instance AND m.name = &#039;choice&#039;&lt;br /&gt;
LEFT JOIN prefix_data AS data ON data.id = cm.instance AND m.name = &#039;data&#039;&lt;br /&gt;
LEFT JOIN prefix_feedback AS feedback ON feedback.id = cm.instance AND m.name = &#039;feedback&#039;&lt;br /&gt;
LEFT JOIN prefix_folder AS folder ON folder.id = cm.instance AND m.name = &#039;folder&#039;&lt;br /&gt;
LEFT JOIN prefix_forum AS forum ON forum.id = cm.instance AND m.name = &#039;forum&#039;&lt;br /&gt;
LEFT JOIN prefix_glossary AS glossary ON glossary.id = cm.instance AND m.name = &#039;glossary&#039;&lt;br /&gt;
LEFT JOIN prefix_imscp AS imscp ON imscp.id = cm.instance AND m.name = &#039;imscp&#039;&lt;br /&gt;
LEFT JOIN prefix_lesson AS lesson ON lesson.id = cm.instance AND m.name = &#039;lesson&#039;&lt;br /&gt;
LEFT JOIN prefix_page AS p ON p.id = cm.instance AND m.name = &#039;page&#039;&lt;br /&gt;
LEFT JOIN prefix_questionnaire AS questionnaire ON questionnaire.id = cm.instance AND m.name = &#039;questionnaire&#039;&lt;br /&gt;
LEFT JOIN prefix_quiz AS quiz ON quiz.id = cm.instance AND m.name = &#039;quiz&#039;&lt;br /&gt;
LEFT JOIN prefix_resource AS cr ON cr.id = cm.instance AND m.name = &#039;resource&#039;&lt;br /&gt;
LEFT JOIN prefix_scorm AS scorm ON scorm.id = cm.instance AND m.name = &#039;scorm&#039;&lt;br /&gt;
LEFT JOIN prefix_survey AS survey ON survey.id = cm.instance AND m.name = &#039;survey&#039;&lt;br /&gt;
LEFT JOIN prefix_url AS url ON url.id = cm.instance AND m.name = &#039;url&#039;&lt;br /&gt;
LEFT JOIN prefix_wiki AS wiki ON wiki.id = cm.instance AND m.name = &#039;wiki&#039;&lt;br /&gt;
LEFT JOIN prefix_workshop AS workshop ON workshop.id = cm.instance AND m.name = &#039;workshop&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidassign AS kalvidassign ON kalvidassign.id = cm.instance AND m.name = &#039;kalvidassign&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidres AS kvr ON kvr.id = cm.instance AND m.name = &#039;kalvidres&#039;&lt;br /&gt;
LEFT JOIN prefix_attendance AS attendance ON attendance.id = cm.instance AND m.name = &#039;attendance&#039;&lt;br /&gt;
LEFT JOIN prefix_checklist AS checklist ON checklist.id = cm.instance AND m.name = &#039;checklist&#039;&lt;br /&gt;
LEFT JOIN prefix_flashcard AS flashcard ON flashcard.id = cm.instance AND m.name = &#039;flashcard&#039;&lt;br /&gt;
LEFT JOIN prefix_lti AS lti ON lti.id = cm.instance AND m.name = &#039;lti&#039;&lt;br /&gt;
LEFT JOIN prefix_oublog AS oublog ON oublog.id = cm.instance AND m.name = &#039;oublog&#039;&lt;br /&gt;
LEFT JOIN prefix_ouwiki AS ouwiki ON ouwiki.id = cm.instance AND m.name = &#039;ouwiki&#039;&lt;br /&gt;
LEFT JOIN prefix_subpage AS subpage ON subpage.id = cm.instance AND m.name = &#039;subpage&#039;&lt;br /&gt;
LEFT JOIN prefix_journal AS journal ON journal.id = cm.instance AND m.name = &#039;journal&#039;&lt;br /&gt;
LEFT JOIN prefix_lightboxgallery AS lightboxgallery ON lightboxgallery.id = cm.instance AND m.name = &#039;lightboxgallery&#039;&lt;br /&gt;
LEFT JOIN prefix_elluminate AS elluminate ON elluminate.id = cm.instance AND m.name = &#039;elluminate&#039;&lt;br /&gt;
LEFT JOIN prefix_adaptivequiz AS adaptivequiz ON adaptivequiz.id = cm.instance AND m.name = &#039;adaptivequiz&#039;&lt;br /&gt;
LEFT JOIN prefix_hotpot AS hotpot ON hotpot.id = cm.instance AND m.name = &#039;hotpot&#039;&lt;br /&gt;
LEFT JOIN prefix_wiziq AS wiziq ON wiziq.id = cm.instance AND m.name = &#039;wiziq&#039;&lt;br /&gt;
LEFT JOIN prefix_turnitintooltwo AS turnitintooltwo ON turnitintooltwo.id = cm.instance AND m.name = &#039;turnitintooltwo&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cm.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Hits) between dates===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module, COUNT( * ) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME( l.`timecreated` ) BETWEEN  &#039;2018-10-01 00:00:00&#039; AND  &#039;2019-09-31 00:00:00&#039;)&lt;br /&gt;
GROUP BY module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Instances and Hits) for each academic year===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2017-10-01 00:00:00&#039; AND &#039;2018-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2017&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2017-10-01 00:00:00&#039; AND &#039;2018-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2017&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2018-10-01 00:00:00&#039; AND &#039;2019-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2018&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2018-10-01 00:00:00&#039; AND &#039;2019-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2018&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2019-10-01 00:00:00&#039; AND &#039;2020-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2019&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2019-10-01 00:00:00&#039; AND &#039;2020-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2019&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_modules AS m&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Unique user sessions per day and month + graph===&lt;br /&gt;
The &amp;quot;graph&amp;quot; column is used when displaying a graph (which needs at least three columns to pick from)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT userid) AS &amp;quot;Unique User Logins&amp;quot;&lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y /%m / %d&amp;quot;) AS &amp;quot;Year / Month / Day&amp;quot;, &amp;quot;Graph&amp;quot; &lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE action LIKE &#039;loggedin&#039;&lt;br /&gt;
#AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) # optional start date&lt;br /&gt;
#AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:00&#039;) # optional end date&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And...&lt;br /&gt;
&lt;br /&gt;
Counting user&#039;s global and unique hits per day + counting individual usage of specific activities and resources (on that day),&lt;br /&gt;
&lt;br /&gt;
And since I am using phpMyAdmin&#039;s &amp;quot;Display Graph&amp;quot; feature (at the bottom of the query&#039;s output page), I have scaled down the &amp;quot;User Hits&amp;quot; by 10 to fit the graph. that&#039;s it.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y-%m-%d&amp;quot;) AS &amp;quot;Datez&amp;quot;&lt;br /&gt;
,COUNT(DISTINCT userid) AS &amp;quot;Unique Users&amp;quot;&lt;br /&gt;
,ROUND(COUNT(*)/10) &amp;quot;User Hits (K)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_quiz&#039;,1,0)) &amp;quot;Quizzes&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_forum&#039; or component=&#039;mod_forumng&#039;,1,0)) &amp;quot;Forums&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_assign&#039;,1,0)) &amp;quot;Assignments&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_oublog&#039;,1,0)) &amp;quot;Blogs&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_resource&#039;,1,0)) &amp;quot;Files (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_url&#039;,1,0)) &amp;quot;Links (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_page&#039;,1,0)) &amp;quot;Pages (Resource)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE 1=1&lt;br /&gt;
AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-03-01 00:00:00&#039;) # optional START DATE&lt;br /&gt;
AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-05-31 23:59:00&#039;) # optional END DATE&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide, daily unique user hits for the last 7 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
  DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%m%d&#039;) &#039;Day&#039;&lt;br /&gt;
  ,COUNT(DISTINCT l.userid) AS &#039;Distinct Users Hits&#039;&lt;br /&gt;
  ,COUNT( l.userid) AS &#039;Users Hits&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE l.courseid &amp;gt; 1&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 7 DAY)&lt;br /&gt;
GROUP BY DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User detailed activity in course modules===&lt;br /&gt;
Considering only several modules: url, resource, forum, quiz, questionnaire.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.id, ra.roleid,&lt;br /&gt;
CONCAT(u.lastname, &#039; &#039;, u.firstname) AS &#039;Student&#039;&lt;br /&gt;
,COUNT(l.id) AS &#039;Actions&#039;&lt;br /&gt;
,l.component &amp;quot;Module type&amp;quot;&lt;br /&gt;
,l.objectid &amp;quot;Module ID&amp;quot;&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN l.component = &#039;mod_url&#039; THEN (SELECT u.name FROM prefix_url AS u WHERE u.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_resource&#039; THEN (SELECT r.name FROM prefix_resource AS r WHERE r.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_forum&#039; THEN (SELECT f.name FROM prefix_forum AS f WHERE f.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_quiz&#039; THEN (SELECT q.name FROM prefix_quiz AS q WHERE q.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_questionnaire&#039; THEN (SELECT q.name FROM prefix_questionnaire AS q WHERE q.id = l.objectid )&lt;br /&gt;
END AS &#039;Module name&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM prefix_groups AS g&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid WHERE g.courseid = l.courseid AND m.userid = u.id) &amp;quot;user_groups&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT s.name &lt;br /&gt;
  FROM prefix_course_modules AS cm &lt;br /&gt;
  JOIN prefix_course_sections AS s ON s.course = cm.course AND s.id = cm.section &lt;br /&gt;
  WHERE cm.id = l.contextinstanceid) AS &amp;quot;Section name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log AS l  &lt;br /&gt;
JOIN prefix_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = l.userid &lt;br /&gt;
  AND ra.contextid = (SELECT id FROM prefix_context WHERE instanceid = l.courseid AND contextlevel = 50) &lt;br /&gt;
WHERE l.courseid = %%COURSEID%%&lt;br /&gt;
  AND l.component IN (&#039;mod_url&#039;, &#039;mod_resource&#039;, &#039;mod_forum&#039;, &#039;mod_quiz&#039;, &#039;mod_questionnaire&#039;) &lt;br /&gt;
  %%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%%&lt;br /&gt;
 &lt;br /&gt;
GROUP BY u.id, l.component&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What teachers and courses considered active?===&lt;br /&gt;
This report display several calculations and parameters that help the Online academic training team find teachers that might need more support getting their courses more supporting of online learning pedagogical methodologies.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,&lt;br /&gt;
			  course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
#,course.shortname&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2012%&#039; THEN &#039;2012&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2013%&#039; THEN &#039;2013&#039; &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2014%&#039; THEN &#039;2014&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2015%&#039; THEN &#039;2015&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester a%&#039; THEN &#039;Spring semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester b%&#039; THEN &#039;Fall semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester s%&#039; THEN &#039;Summer semester&#039;&lt;br /&gt;
END AS Semester&lt;br /&gt;
&lt;br /&gt;
,IF(course.startdate&amp;gt;0, DATE_FORMAT(FROM_UNIXTIME(startdate), &#039;%d-%m-%Y&#039;), &#039;no date&#039;) AS &amp;quot;Course Start Date&amp;quot; &lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 4 AND ctx.instanceid = course.id&lt;br /&gt;
) AS &amp;quot;Assistant teacher&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
&lt;br /&gt;
# Uncomment to use the new Moodle 2.8+ logstore&lt;br /&gt;
#,(SELECT COUNT(*) FROM mdl_logstore_standard_log AS l WHERE l.courseid = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Student HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Teacher HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_log AS l WHERE l.course = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course c&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = c.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND c.id = course.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
  &lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = course.id) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(DISTINCT cm.module) FROM prefix_course_modules cm &lt;br /&gt;
  WHERE cm.course = course.id) UniqueModules&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(DISTINCT m.name) &lt;br /&gt;
  FROM prefix_course_modules cm &lt;br /&gt;
  JOIN mdl_modules as m ON m.id = cm.module&lt;br /&gt;
  WHERE cm.course = course.id) UniqueModuleNames&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;ouwiki&#039;, &#039;wiki&#039;) ) &amp;quot;Num Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;oublog&#039;) ) &amp;quot;Num Blogs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;forum&#039;, &#039;forumng&#039;) ) &amp;quot;Num Forums&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;resource&#039;, &#039;folder&#039;, &#039;url&#039;, &#039;tab&#039;, &#039;file&#039;, &#039;book&#039;, &#039;page&#039;) ) Resources&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;forum&#039;, &#039;forumng&#039;, &#039;oublog&#039;, &#039;page&#039;, &#039;file&#039;, &#039;url&#039;, &#039;wiki&#039; , &#039;ouwiki&#039;) ) &amp;quot;Basic Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;advmindmap&#039;, &#039;assign&#039;, &#039;attendance&#039;, &#039;book&#039;, &#039;choice&#039;, &#039;folder&#039;, &#039;tab&#039;, &#039;glossary&#039;, &#039;questionnaire&#039;, &#039;quiz&#039;, &#039;label&#039; ) ) &amp;quot;Avarage Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;elluminate&#039;, &#039;game&#039;, &#039;workshop&#039;) ) &amp;quot;Advanced Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course&lt;br /&gt;
&lt;br /&gt;
#WHERE course.shortname LIKE &#039;%2015%&#039;&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_SEARCHTEXT:course.shortname:~%%&lt;br /&gt;
&lt;br /&gt;
WHERE course.fullname LIKE &#039;%2015%&#039; &lt;br /&gt;
&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY UniqueModules DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly attendance report===&lt;br /&gt;
This report display weekly report in format HH:M:SS This MySQL query works together with AttendaceRegister module, and gather Log information from Attendanceregister_log table. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, SEC_TO_TIME (SUM(arsess.duration)) AS weekly_online_attendance,  FROM_UNIXTIME (arsess.logout) AS Last_Logout&lt;br /&gt;
FROM prefix_attendanceregister_session AS arsess&lt;br /&gt;
JOIN prefix_user AS u ON arsess.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE (((arsess.logout) BETWEEN UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 7 DAY)) AND UNIX_TIMESTAMP(CURDATE())))&lt;br /&gt;
&lt;br /&gt;
GROUP BY arsess.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many distinct users connected to Moodle using the app by month===&lt;br /&gt;
https://moodle.org/mod/forum/discuss.php?d=336086#p1354194 by &lt;br /&gt;
Iñigo Zendegi Urzelai&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;) as year, &lt;br /&gt;
  to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;) as month, &lt;br /&gt;
  count(distinct userid) as distinct_users&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log l&lt;br /&gt;
WHERE l.origin=&#039;ws&#039;&lt;br /&gt;
GROUP BY to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;), to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;) &lt;br /&gt;
ORDER BY to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;), to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Course Reports==&lt;br /&gt;
===Most Active courses===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(l.userid) AS Views&lt;br /&gt;
FROM `mdl_logstore_standard_log` l, `mdl_user` u, `mdl_role_assignments` r&lt;br /&gt;
WHERE l.courseid=35&lt;br /&gt;
AND l.userid = u.id&lt;br /&gt;
AND (l.timecreated &amp;gt; UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) AND l.timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:59&#039;))AND r.contextid= (&lt;br /&gt;
	 SELECT id&lt;br /&gt;
	 FROM mdl_context&lt;br /&gt;
	 WHERE contextlevel=50 AND instanceid=l.courseid&lt;br /&gt;
 )&lt;br /&gt;
AND r.roleid=5&lt;br /&gt;
AND r.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active courses, advanced===&lt;br /&gt;
Including: Teacher&#039;s name, link to the course, All types of log activities, special YEAR generated field, Activities and Resource count, enrolled Student count&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשע&#039; THEN &#039;תשע&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעא&#039; THEN &#039;תשעא&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעב&#039; THEN &#039;תשעב&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = l.course) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_log l &lt;br /&gt;
INNER JOIN prefix_course c ON l.course = c.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
#The following line restricts the courses returned to those having more than 2 modules.  Adjust based on your needs.&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY Year DESC, hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Least active or probably empty courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;-1&amp;quot; instead of &amp;quot;0&amp;quot; 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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
c.fullname,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;CourseLink&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timecreated&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timemodified&#039;,&lt;br /&gt;
CASE&lt;br /&gt;
 WHEN c.timecreated = c.timemodified THEN &#039;-1&#039;&lt;br /&gt;
 ELSE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated))&lt;br /&gt;
END AS &#039;DateDifference&#039;,&lt;br /&gt;
COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
LEFT JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
WHERE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated) ) &amp;lt; 60&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
HAVING COUNT(ue.id) &amp;lt;= 3&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Count unique teachers with courses that use at least X module (Moodle19)===&lt;br /&gt;
You can remove the outer &amp;quot;SELECT COUNT(*) FROM (...) AS ActiveTeachers&amp;quot; SQL query and get the list of the Teachers and Courses.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(*)&lt;br /&gt;
FROM (SELECT c.id AS CourseID, c.fullname AS Course, ra.roleid AS RoleID, CONCAT(u.firstname, &#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = c.id) AS Modules&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid AND ctx.contextlevel = 50 &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE  ra.roleid = 3 &lt;br /&gt;
GROUP BY u.id&lt;br /&gt;
HAVING Modules &amp;gt; 5) AS ActiveTeachers&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RESOURCE count for each COURSE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) count, l.course, c.fullname coursename&lt;br /&gt;
FROM prefix_resource l INNER JOIN prefix_course c on l.course = c.id&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY count DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Common resource types count for each Category (Moodle19)===&lt;br /&gt;
Including sub-categories in total count.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category&lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Links&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference NOT LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Files&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;directory&#039; &lt;br /&gt;
) AS Folders&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;html&#039; &lt;br /&gt;
) AS Pages&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM stats_log_context_role_course &lt;br /&gt;
WHERE roleid = 5 AND module = &#039;resource&#039; AND category = mcc.id&lt;br /&gt;
) AS Hits&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Where &amp;quot;stats_log_context_role_course&amp;quot; (in the above SQL query) is a VIEW generated by:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
CREATE VIEW stats_log_context_role_course AS&lt;br /&gt;
SELECT l.course, c.category, cc.path, l.module, l.action, ra.userid, ra.roleid&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = l.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Same query but for Moodle2+&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category,&lt;br /&gt;
mcc.path,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_url AS u&lt;br /&gt;
JOIN prefix_course AS c ON c.id = u.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS URLs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_folder AS f&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS FOLDERs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_page AS p&lt;br /&gt;
JOIN prefix_course AS c ON c.id = p.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS PAGEs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_book AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS BOOKs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_label AS l&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS LABELs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_tab AS t&lt;br /&gt;
JOIN prefix_course AS c ON c.id = t.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS TABs&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed Resource COUNT by Teacher in each course===&lt;br /&gt;
&lt;br /&gt;
Including (optional) filter by: year, semester and course id.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
, c.id&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעב%&#039; THEN &#039;2012&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעא%&#039; THEN &#039;2011&#039;&lt;br /&gt;
END ) as Year&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר א%&#039; THEN &#039;Semester A&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ב%&#039; THEN &#039;Semester B&#039;&lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ק%&#039; THEN &#039;Semester C&#039;&lt;br /&gt;
END ) as Semester&lt;br /&gt;
,COUNT(c.id) AS Total&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 20) AS TABs&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 33) AS BOOKs&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_resource` as r &lt;br /&gt;
JOIN `prefix_course` AS c on c.id = r.course&lt;br /&gt;
#WHERE type= &#039;file&#039; and reference NOT LIKE &#039;http://%&#039; &lt;br /&gt;
&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
#AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY COUNT(c.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses that are defined as using GROUPs===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/group/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = c.id) Modules&lt;br /&gt;
,(SELECT count(*) FROM prefix_groups g WHERE g.courseid = c.id) Groups&lt;br /&gt;
 FROM `prefix_course` AS c&lt;br /&gt;
WHERE groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Groups===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with Groups in them (groupmode &amp;gt; 0). You can also use groupmode=1 to list just Separate type groups or groupmode=2 to list Visible type groups.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name, c.groupmode&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON c.id = g.courseid&lt;br /&gt;
WHERE c.groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users enrolled in a course with groups but not assigned a group ===&lt;br /&gt;
&lt;br /&gt;
Displays by course all enrolled users that have not been assigned a group in courses that have groups. NOTE: This needs to be optimized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) AS ROLE&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = course.id&lt;br /&gt;
&lt;br /&gt;
WHERE ue.enrolid NOT IN (select userid from prefix_groups_members WHERE g.id=groupid)&lt;br /&gt;
&lt;br /&gt;
ORDER BY Course, Lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Groups in course with member list===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List the groups in a course (replace the # by the course id number) with the members of each group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name AS Groupname, u.username&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_user AS u ON m.userid = u.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Group Export===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
There&#039;s a [[Import_groups|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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT g.name AS groupname, g.description, g.enrolmentkey&lt;br /&gt;
FROM prefix_groups AS g &lt;br /&gt;
JOIN prefix_course as c ON g.courseid = c.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Courses in and below a certain category===&lt;br /&gt;
Use this SQL code to retrieve all courses that exist in or under a set category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the category you want to know about...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course. * , prefix_course_categories. *&lt;br /&gt;
FROM prefix_course, prefix_course_categories&lt;br /&gt;
WHERE prefix_course.category = prefix_course_categories.id&lt;br /&gt;
AND (&lt;br /&gt;
prefix_course_categories.path LIKE &#039;%/$s/%&#039;&lt;br /&gt;
OR prefix_course_categories.path LIKE &#039;%/$s&#039;&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Categories in one level below a certain category===&lt;br /&gt;
Use this PHP code to retrieve a list of all categories below a certain category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the top level category you are interested in.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
require_once(&#039;./config.php&#039;);&lt;br /&gt;
&lt;br /&gt;
$parent_id = $s;&lt;br /&gt;
&lt;br /&gt;
$categories= array();&lt;br /&gt;
&lt;br /&gt;
$categories = get_categories($parent_id);&lt;br /&gt;
&lt;br /&gt;
echo &#039;&amp;lt;ol&amp;gt;&#039;;&lt;br /&gt;
foreach ($categories as $category)&lt;br /&gt;
        {&lt;br /&gt;
        echo &#039;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&#039;.$CFG-&amp;gt;wwwroot.&#039;/course/category.php?id=&#039;.$category-&amp;gt;id.&#039;&amp;quot;&amp;gt;&#039;.$category-&amp;gt;name.&#039;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
        }&lt;br /&gt;
echo &#039;&amp;lt;/ol&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Blog activity per Course (not including VIEW)===&lt;br /&gt;
Filter activity logging to some specific Course Categories!&lt;br /&gt;
+ link course name to actual course (for quick reference)&lt;br /&gt;
(you can change %blog% to %wiki% to filter down all wiki activity or any other module you wish)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID&lt;br /&gt;
,m.name ,count(cm.id) as counter &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS Students&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE `module` LIKE &#039;%blog%&#039; AND course = c.id AND action NOT LIKE &#039;%view%&#039; ) as BlogActivity&lt;br /&gt;
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 &lt;br /&gt;
WHERE m.name LIKE &#039;%blog%&#039; AND c.category IN ( 8,13,15)&lt;br /&gt;
GROUP BY cm.course,cm.module order by counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student&#039;s posts content in all course blogs (oublog)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
b.name &lt;br /&gt;
,op.title&lt;br /&gt;
,op.message&lt;br /&gt;
,( SELECT CONCAT(u.firstname, &#039; &#039;,u.lastname) FROM prefix_user AS u WHERE u.id = oi.userid) AS &amp;quot;Username&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_oublog_posts AS op&lt;br /&gt;
JOIN prefix_oublog_instances AS oi ON oi.id = op.oubloginstancesid &lt;br /&gt;
JOIN prefix_oublog as b ON b.id = oi.oublogid&lt;br /&gt;
JOIN prefix_course AS c ON b.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Courses which uploaded a Syllabus file===&lt;br /&gt;
+ under specific Category&lt;br /&gt;
+ show first Teacher in that course&lt;br /&gt;
+ link Course&#039;s fullname to actual course&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) as Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user as u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) as Teacher&lt;br /&gt;
FROM prefix_resource as r &lt;br /&gt;
JOIN prefix_course as c ON r.course = c.id&lt;br /&gt;
WHERE ( r.name LIKE &#039;%סילבוס%&#039; OR r.name LIKE &#039;%סילאבוס%&#039; OR r.name LIKE &#039;%syllabus%&#039; OR r.name LIKE &#039;%תכנית הקורס%&#039; ) &lt;br /&gt;
AND c.category IN (10,18,26,13,28)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
===Site-wide completed SCORM activities by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===All users enrolled in a course without a role===&lt;br /&gt;
Identifies All users that are enrolled in a course but are not assigned a role.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user.firstname AS Firstname,&lt;br /&gt;
user.lastname AS Lastname,&lt;br /&gt;
user.idnumber Employee_ID,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user as user ON user.id = ue.userid&lt;br /&gt;
&lt;br /&gt;
WHERE user.id NOT IN (&lt;br /&gt;
SELECT u.id&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE c.id=course.id&lt;br /&gt;
)&lt;br /&gt;
ORDER BY Course, Lastname, Firstname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List course resources accumulative file size and count===&lt;br /&gt;
This is the main (first) report, which has a link (alias) to a second report (the following on this page) which list each file in the course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id &amp;quot;CourseID&amp;quot;, context.id &amp;quot;ContextID&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;, c.id, &#039;&amp;quot;&amp;gt;&#039;, c.fullname ,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Course Name&amp;quot;&lt;br /&gt;
, COUNT(*) &amp;quot;Course Files&amp;quot; , ROUND( SUM( f.filesize ) /1048576 ) AS file_size_MB&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/blocks/configurable_reports/viewreport.php?alias=coursefiles&amp;amp;courseid=1&amp;amp;filter_courses=&#039;, c.id, &#039;&amp;quot;&amp;gt;List files&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List Files&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
JOIN mdl_context AS context ON context.id = f.contextid&lt;br /&gt;
JOIN mdl_course AS c ON c.id = (&lt;br /&gt;
  SELECT instanceid&lt;br /&gt;
  FROM mdl_context&lt;br /&gt;
  WHERE id = SUBSTRING_INDEX( SUBSTRING_INDEX( context.path, &#039;/&#039; , -2 ) , &#039;/&#039;, 1 ) )&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this report, you will have to define &amp;quot;alias&amp;quot; report property to &amp;quot;coursefiles&amp;quot; for it to be able to be called from the above report.&lt;br /&gt;
And also setup (add) a FILTER_COURSES filter. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id ,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/pluginfile.php/&#039;, contextid, &#039;/&#039;, component, &#039;/&#039;, filearea, &#039;/&#039;, itemid, &#039;/&#039;, filename, &#039;&amp;quot;&amp;gt;&#039;, filename,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;File&amp;quot;&lt;br /&gt;
,filesize, mimetype ,author, license, timecreated, component, filearea, filepath&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
            AND f.contextid&lt;br /&gt;
            IN (   SELECT id&lt;br /&gt;
                     FROM mdl_context&lt;br /&gt;
                    WHERE path &lt;br /&gt;
                     LIKE (   SELECT CONCAT(&#039;%/&#039;,id,&#039;/%&#039;)&lt;br /&gt;
                                  AS contextquery&lt;br /&gt;
                                FROM mdl_context&lt;br /&gt;
                               WHERE 1=1&lt;br /&gt;
			        %%FILTER_COURSES:instanceid%%&lt;br /&gt;
                                 AND contextlevel = 50&lt;br /&gt;
                           )&lt;br /&gt;
                )&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Which courses has redundant topics===&lt;br /&gt;
This report list several &amp;quot;active topics&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
The following, second SQL query, could be used to &amp;quot;trim&amp;quot; down those redundant course topics/sections/weeks by updating the course format&#039;s numsection (Number of sections) setting. (It&#039;s a per course format setting!)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, format,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT value  FROM  `mdl_course_format_options` WHERE  `courseid` = c.id AND `format` = c.format AND `name` = &#039;numsections&#039; ) AS &amp;quot;numsections&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND `sequence` !=  &#039;&#039; ) AS &amp;quot;Non empty sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id ) AS &amp;quot;Total section count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND sequence IS NOT NULL) AS &amp;quot;Non NULL sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND name != &#039;&#039;) AS &amp;quot;Non empty section Name count&amp;quot;&lt;br /&gt;
 ,(SELECT COUNT(*) FROM mdl_course_modules cm WHERE cm.course = c.id) &amp;quot;Modules count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course AS c&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following SQL REPLACE query is used for &amp;quot;fixing&amp;quot; (updating) the &amp;quot;numsections&amp;quot; of a specific course format &amp;quot;onetopics&amp;quot; (you can always change it, or discard it to use this SQL REPLACE on all course formats) &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
REPLACE INTO `mdl_course_format_options` (`id`, `courseid`, `format`, `sectionid`, `name`, `value`) &lt;br /&gt;
SELECT NULL, c.id, &#039;onetopic&#039;, &#039;0&#039;, &#039;numsections&#039;, (SELECT COUNT(*) FROM `mdl_course_sections` WHERE `course` = c.id AND name != &#039;&#039;)&lt;br /&gt;
FROM `mdl_course` c where format = &#039;onetopic&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hidden Courses with Students Enrolled===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.visible AS Visible, &lt;br /&gt;
DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors,&lt;br /&gt;
&lt;br /&gt;
(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;, &lt;br /&gt;
&lt;br /&gt;
now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
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) &amp;gt; 0&lt;br /&gt;
ORDER BY StartDate, Instructor_Email, Course_ID&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Course format used on my system ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(*) &#039;Count&#039;, c.format &#039;Format&#039;&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
GROUP BY c.format&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Course Design Reports==&lt;br /&gt;
&lt;br /&gt;
These are reports which summarize course design aspects, such as activity and resource modules per section, types of activities used, etc.&lt;br /&gt;
&lt;br /&gt;
===Course Content/Week===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report assumes that the first 14 sections in a course, not including the &amp;quot;0&amp;quot; or &amp;quot;Welcome&amp;quot; section, correspond to weeks (with &amp;quot;Subsections&amp;quot; given numbers much higher in the sequence). Of those sections, each is checked to count the number of:&lt;br /&gt;
&lt;br /&gt;
    Forums&lt;br /&gt;
    Graded Activities (may include Forums)&lt;br /&gt;
    Resources (not including a Label)&lt;br /&gt;
&lt;br /&gt;
Totals of each of these types of content elements per section are provided.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Only visible resources and activities are counted.&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: this is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
 &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT LIKE &#039;label&#039;),cm.id,NULL)) AS &#039;Ungraded Resources&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Graded Activities&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cs.section&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments and Weights===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Categories with weights of 0 are not included in this report.&lt;br /&gt;
&lt;br /&gt;
Only visible activities are included in this report.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This is designed to be a &amp;quot;Global&amp;quot; report in Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;) AS &#039;Grade Book Category&#039;&lt;br /&gt;
, IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND(SUM(DISTINCT gi.aggregationcoef), 2)+ROUND(SUM(DISTINCT mgi.aggregationcoef), 2)) AS &#039;Category weight&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT_WS(&#039;, &#039;,GROUP_CONCAT(DISTINCT gi.itemmodule SEPARATOR &#039;, &#039;), IF(mgi.id, &#039;manual&#039;,NULL)) AS &#039;Activity Types&#039;&lt;br /&gt;
, COUNT(DISTINCT gi.itemmodule) + IF(mgi.id,1,0) AS &#039;Different Activity Types&#039;&lt;br /&gt;
, CONCAT_WS(&#039;&amp;lt;br&amp;gt;&#039;, GROUP_CONCAT(DISTINCT gi.itemname ORDER BY gi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;), GROUP_CONCAT(DISTINCT mgi.itemname ORDER BY mgi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;)) AS &#039;Activity Names&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) + COUNT(DISTINCT mgi.id) AS &#039;Activity Count&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
&lt;br /&gt;
#get grade categories&lt;br /&gt;
LEFT JOIN prefix_grade_categories AS gc ON gc.courseid = c.id &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
JOIN prefix_grade_items AS gic ON gic.courseid = c.id AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
&lt;br /&gt;
# attach activities to course&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = c.id &lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.iteminstance = cm.instance AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.id&lt;br /&gt;
ORDER BY gc.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pre-Term Course Review===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
#   &amp;quot;Required blocks&amp;quot; include Instructor Block (mooprofile), Activities, and the Research block.&lt;br /&gt;
#    &amp;quot;Instructor Details&amp;quot; block is not the &amp;quot;Instructor&amp;quot; block (mooprofile) automatically provided by the system. It is an optional block that can be edited by the instructor. If not edited to remove boilerplate text, it should be hidden.&lt;br /&gt;
#    All courses should be in the &amp;quot;Collapsed Topics&amp;quot; format with the &amp;quot;Weeks&amp;quot; structure.&lt;br /&gt;
#    &amp;quot;Weeks defined in course settings&amp;quot; is taken from our SIS when the course shells are created, but can be edited by faculty. &amp;quot;# of weeks named and visible&amp;quot; should usually match or exceed this value.&lt;br /&gt;
#    We recommend that each week contain at least one forum, at least one graded activity, and at least one ungraded resource.&lt;br /&gt;
#    &amp;quot;Syllabus updated&amp;quot; date is for the first attached file found with the text &amp;quot;syllabus&amp;quot; in the name. The &amp;quot;Days ago&amp;quot; calculation is included for convenience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: At our institution, we construct categories each term, and insert a text string &amp;quot;staging&amp;quot; in the Category ID for pre-term courses during the preparation or &amp;quot;staging&amp;quot; phase of course development. We remove this text string (and change it to &amp;quot;production&amp;quot;) when courses go live at the start of the new term.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
#,RIGHT(c.idnumber,2) AS Type # Specific to GSC &amp;quot;Instructional Method&amp;quot; storage&lt;br /&gt;
&lt;br /&gt;
#, substring_index(substr(c.shortname FROM locate(&#039;.&#039;,c.shortname)+1),&#039;-&#039;,1) AS Section # Specific to GSC&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.lastname,&#039;, &#039;, u.firstname,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
,(SELECT IF((u2.description IS NULL) OR (u2.description LIKE &#039;&#039;),&#039;NO&#039;, &#039;YES&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT IF(u3.picture &amp;gt; 0,&#039;YES&#039;,&#039;NO&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u3 ON u3.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Picture&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(((bpi.visible IS NULL) OR (bpi.visible !=0)) AND ((bpm.visible IS NULL) OR (bpm.visible !=0)) AND ((bpa.visible IS NULL) OR (bpa.visible !=0)) AND ((bpr.visible IS NULL) OR (bpr.visible !=0)),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Required blocks visible&#039;&lt;br /&gt;
#, IF((bpm.visible IS NULL) OR (bpm.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Messages block visible&#039;&lt;br /&gt;
#, IF((bpa.visible IS NULL) OR (bpa.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;activities block visible&#039;&lt;br /&gt;
#, IF((bpr.visible IS NULL) OR (bpr.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;research block visible&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)) AND (bip.visible !=0),&#039;YES&#039;,&#039;&#039;) AS &#039;Instructor Details Block visible&#039; # This is a hack based on UUencoded string data from the title of HTML &amp;quot;Instructor Details&amp;quot; block&lt;br /&gt;
&lt;br /&gt;
#, IF(bi.configdata LIKE &#039;%ZGl0IHRoaXMgYmxvY2s%&#039;,&#039;NO&#039;,&#039;&#039;) AS &#039;Instructor Details Block Updated&#039; # HTML block has string &#039;dit this block&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(COUNT(bi.id) -  SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)),&#039;YES&#039;,&#039;&#039;) AS &#039;possible extra instructor blocks&#039; #looking for any HTML block with &amp;quot;instructor&amp;quot; in the title&lt;br /&gt;
&lt;br /&gt;
, IF(c.format=&#039;topcoll&#039;,&#039;YES&#039;, c.format) AS &#039;Collapsed Topics course format&#039; # change this if you want to test for a different format&lt;br /&gt;
, IF(cfo.value = 2, &#039;YES&#039;,&#039;NO&#039;) AS &#039;weeks structure&#039;&lt;br /&gt;
&lt;br /&gt;
, cfw.value AS &#039;weeks defined in course settings&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(((cs.name IS NOT NULL) AND (cs.visible = 1) AND (cs.section != &#039;0&#039;) AND (cs.sequence IS NOT NULL)),cs.id,NULL)) AS &#039;# of weeks named &amp;amp; visible (includes orphans)&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039; ,cs.id , NULL)) AS &#039;Weeks with Forum&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cs.id, NULL)) AS &#039;Weeks with Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT mgi.id) AS &#039;Manual Grade Items&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)),cm.id,NULL)) AS &#039;Resources&#039;&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)), cs.id, NULL)) AS &#039;Weeks with Resources&#039;&lt;br /&gt;
&lt;br /&gt;
# Here are some other things you could check for per course&lt;br /&gt;
#,(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 &#039;%forum%&#039;) AS Forums&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%quiz%&#039;) AS Quizzes&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%assign%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_resource.id) FROM prefix_resource JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course) AS Files&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_url.id) FROM prefix_url JOIN prefix_course ON prefix_course.id = prefix_url.course WHERE c.id = prefix_url.course) AS Links&lt;br /&gt;
&lt;br /&gt;
,(SELECT FROM_UNIXTIME(MAX(prefix_resource.timemodified))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS SyllabusDate&lt;br /&gt;
&lt;br /&gt;
,(SELECT TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(MAX(prefix_resource.timemodified)))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS DaysAgo&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, f.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement Forum Visible&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, fd.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement posted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
LEFT JOIN prefix_context AS ctxx ON c.id = ctxx.instanceid &lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpi ON bpi.contextid = ctxx.id AND bpi.blockinstanceid = &#039;43692&#039; # mooprofile&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpm ON bpm.contextid = ctxx.id AND bpm.blockinstanceid = &#039;43962&#039; # messages&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpa ON bpa.contextid = ctxx.id AND bpa.blockinstanceid = &#039;43963&#039; # activities&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpr ON bpr.contextid = ctxx.id AND bpr.blockinstanceid = &#039;38368&#039; # html research help&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.visible = 1 AND cs.sequence IS NOT NULL&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
LEFT JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_forum AS f ON f.course = c.id AND cm.instance = f.id AND cm.visible = 1&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.forum = f.id&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfo ON cfo.courseid = c.id AND cfo.name = &#039;layoutstructure&#039;&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfw ON cfw.courseid = c.id AND cfw.name = &#039;numsections&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_instances AS bi ON bi.parentcontextid = ctxx.id AND bi.blockname = &#039;html&#039; AND (bi.configdata LIKE &#039;%SW5zdHJ1Y3Rvc%&#039; or bi.configdata LIKE &#039;%bnN0cnVjdG9y%&#039;)&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bip ON bip.blockinstanceid = bi.id&lt;br /&gt;
&lt;br /&gt;
WHERE RIGHT(c.idnumber,2) IN (&#039;OL&#039;, &#039;BL&#039;, &#039;HY&#039;) &lt;br /&gt;
# AND substring(cc.path,2,2) IN (&#039;26&#039;) # Staging&lt;br /&gt;
#AND substring(cc.path,2,3) IN (&#039;158&#039;) # UG&lt;br /&gt;
AND cc.idnumber LIKE &#039;%staging%&#039;&lt;br /&gt;
AND ctxx.contextlevel = 50&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module instances + Module HITs by role teacher and student in course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
m.name AS &amp;quot;Module name&amp;quot;&lt;br /&gt;
, COUNT(*) AS &amp;quot;Module count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name ) AS &amp;quot;Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course_modules AS cm&lt;br /&gt;
JOIN mdl_modules AS m on m.id = cm.module&lt;br /&gt;
WHERE cm.course = &#039;%%COURSEID%%&#039;&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Syllabus===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Course Policies&amp;quot; and &amp;quot;Teaching Philosophy&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.fullname AS &#039;fullname&#039;&lt;br /&gt;
, ec.idnumber AS &#039;elis-id&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.startdate), &#039;%b %e, %Y&#039;) AS &#039;start&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.enddate), &#039;%b %e, %Y&#039;) AS &#039;end&#039;&lt;br /&gt;
, ecd.name AS &#039;longname&#039;&lt;br /&gt;
, ecd.code AS &#039;coursecode&#039;&lt;br /&gt;
, ecd.credits AS &#039;coursecredits&#039;&lt;br /&gt;
, ecd.syllabus AS &#039;description&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;learning-outcomes&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;outcomes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.firstname,&#039; &#039;, u.lastname,&#039;&amp;lt;/a&amp;gt; &#039;, u.email)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
, (SELECT  efc.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_char AS efc&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = efc.fieldid AND ef.shortname = &#039;term-code&#039;&lt;br /&gt;
WHERE ctxci.id = efc.contextid) AS &#039;termcode&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;prerequisites&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;prerequisites&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;textbooks&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;textbooks&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;other-class-materials&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;other-class-materials&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-policies&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-policies&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;teaching-philosophy&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;teaching-philosophy&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-methods&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-methods&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT u2.description&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT&lt;br /&gt;
&lt;br /&gt;
GROUP_CONCAT(DISTINCT CONCAT(&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;tr&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt;&#039;,IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;)&lt;br /&gt;
, &#039; &amp;lt;/td&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt; &#039;&lt;br /&gt;
,IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND( gi.aggregationcoef, 2)+ROUND(mgi.aggregationcoef, 2))&lt;br /&gt;
&lt;br /&gt;
) SEPARATOR &#039;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&#039;)&lt;br /&gt;
#get grade categories&lt;br /&gt;
FROM prefix_grade_categories AS gc &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gic ON gic.courseid = gc.courseid AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = gc.courseid  AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = gc.courseid and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
WHERE gc.courseid = c.id  ) AS &#039;grade categories&#039;&lt;br /&gt;
&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;50%&amp;quot; &amp;gt;&#039; AS &#039;table start&#039;&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;100%&amp;quot; &amp;gt;&#039; AS &#039;table start 2&#039;&lt;br /&gt;
, &#039;&amp;lt;/table&amp;gt;&#039; AS &#039;table end&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;activities-schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;schedule&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;grading-scale&#039;&lt;br /&gt;
WHERE ctxepm.id = eft.contextid) AS &#039;gradescale&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
# connect moodle course to ELIS class instance&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls_mdl AS ecm ON ecm.moodlecourseid = c.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls AS ec ON ec.id = ecm.classid&lt;br /&gt;
# class instance context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxci ON ctxci.instanceid = ec.id AND ctxci.contextlevel = &#039;14&#039;&lt;br /&gt;
&lt;br /&gt;
# connect ELIS class instance to ELIS course description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_crs AS ecd ON ecd.id = ec.courseid&lt;br /&gt;
# course description context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxecd ON ctxecd.instanceid = ecd.id AND ctxecd.contextlevel = &#039;13&#039;&lt;br /&gt;
&lt;br /&gt;
#connect ELIS program to ELIS Course Description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm_crs AS epc ON epc.courseid = ecd.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm AS epm ON epm.id = epc.curriculumid&lt;br /&gt;
# course program context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxepm ON ctxepm.instanceid = epm.id AND ctxepm.contextlevel = &#039;11&#039;&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Activities Helper===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report provides a list of the graded activities in a course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: Only graded activities are displayed.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This report assumes that course sections each last one week.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
# 303 Course Activities Helper&lt;br /&gt;
&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
gi.itemmodule AS &#039;activity type&#039;&lt;br /&gt;
# cs.section AS &#039;section number&#039;&lt;br /&gt;
&lt;br /&gt;
# Calculation assumes each section lasts one week&lt;br /&gt;
, CONCAT(DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section-1))), &#039;%b %e, %Y&#039;),&#039; - &amp;lt;br&amp;gt;&#039;,DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section))), &#039;%b %e, %Y&#039;)) AS &#039;Date&#039;&lt;br /&gt;
&lt;br /&gt;
, gi.itemname AS &#039;activity name&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = cm.instance) AS &#039;intro&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT f.intro FROM prefix_forum AS f WHERE f.id = cm.instance) AS &#039;f intro&#039;&lt;br /&gt;
&lt;br /&gt;
, CASE gi.itemmodule &lt;br /&gt;
WHEN &#039;assign&#039; THEN (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;forum&#039; THEN (SELECT f.intro FROM prefix_forum AS f WHERE f.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;quiz&#039; THEN (SELECT q.intro FROM prefix_quiz AS q WHERE q.id = gi.iteminstance) &lt;br /&gt;
END AS &#039;test case&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT GROUP_CONCAT(CONCAT(&#039; - &#039;,gi.itemname) SEPARATOR &#039;&amp;lt;BR&amp;gt;&#039;) FROM  prefix_grade_items AS gi  JOIN prefix_course_modules AS cm ON  gi.iteminstance = cm.instance WHERE gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id ) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
#get grade sections&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id  AND cs.section &amp;gt; 0 AND cs.section &amp;lt;=14&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_assign AS asg ON asg.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_grade_items AS gi  ON  gi.iteminstance = cm.instance AND gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
&lt;br /&gt;
ORDER BY gi.itemmodule, cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Grade and Course Completion Reports==&lt;br /&gt;
===Site-Wide Grade Report with All Items===&lt;br /&gt;
Shows grades for all course items along with course totals for each student. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, &lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
For MySQL users, you&#039;ll need to use the MySQL DATE_ADD function instead of DATEADD. Replace the line:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
And:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
CONCAT(u.firstname,&#039; &#039;,u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site-Wide Grade Report with Just Course Totals===&lt;br /&gt;
A second site-wide grade report for all students that just shows course totals. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id AND gi.itemtype = &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For MySQL users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN CONCAT(c.fullname, &#039; - Total&#039;)&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS TIME&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
 &lt;br /&gt;
WHERE  gi.courseid = c.id AND gi.itemtype = &#039;course&#039;&lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Learner report by Learner with grades===&lt;br /&gt;
Which Learners in which course and what are the grades&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;Name&#039; , u.lastname AS &#039;Surname&#039;, c.fullname AS &#039;Course&#039;, cc.name AS &#039;Category&#039;, &lt;br /&gt;
CASE WHEN gi.itemtype = &#039;Course&#039;    &lt;br /&gt;
THEN c.fullname + &#039; Course Total&#039;  &lt;br /&gt;
ELSE gi.itemname &lt;br /&gt;
END AS &#039;Item Name&#039;, ROUND(gg.finalgrade,2) AS Score,ROUND(gg.rawgrademax,2) AS Max, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) as Percentage,&lt;br /&gt;
&lt;br /&gt;
if (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) &amp;gt; 79,&#039;Yes&#039; , &#039;No&#039;) as Pass&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id &lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid &lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category &lt;br /&gt;
WHERE  gi.courseid = c.id and gi.itemname != &#039;Attendance&#039;&lt;br /&gt;
ORDER BY `Name` ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A very simple report with a list of course completion status by username. Completions are noted by date, blank otherwise. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  u.username, &lt;br /&gt;
  c.shortname,  &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%Y-%m-%d&#039;) AS completed&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion with Criteria===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A report with course completions by username, with Aggregation method, Criteria types, and Criteria detail where available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username AS user, &lt;br /&gt;
c.shortname AS course,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(t.timecompleted),&#039;%Y-%m-%d&#039;) AS completed,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = c.id AND a.criteriatype IS NULL) = 1) THEN &amp;quot;Any&amp;quot;&lt;br /&gt;
ELSE &amp;quot;All&amp;quot;&lt;br /&gt;
END AS aggregation,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;Self&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN &amp;quot;By Date&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 3 THEN &amp;quot;Unenrol Status&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &amp;quot;Activity&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 5 THEN &amp;quot;Duration&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 6 THEN &amp;quot;Course Grade&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 7 THEN &amp;quot;Approve by Role&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 8 THEN &amp;quot;Previous Course&amp;quot;&lt;br /&gt;
END AS criteriatype,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;*&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(p.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN p.criteriatype = 3 THEN t.unenroled&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,p.module,&#039;/view.php?id=&#039;,p.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,p.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN p.criteriatype = 5 THEN p.enrolperiod&lt;br /&gt;
WHEN p.criteriatype = 6 THEN CONCAT(&#039;Needed: &#039;,ROUND(p.gradepass,2),&#039; Achieved: &#039;,ROUND(t.gradefinal,2)) &lt;br /&gt;
WHEN p.criteriatype = 7 THEN p.role&lt;br /&gt;
WHEN p.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = p.courseinstance)&lt;br /&gt;
END AS criteriadetail &lt;br /&gt;
FROM prefix_course_completion_crit_compl AS t&lt;br /&gt;
JOIN prefix_user AS u ON t.userid = u.id&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
JOIN prefix_course_completion_criteria AS p ON t.criteriaid = p.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Completion Enabled and their settings===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with completion enabled and their Aggregation setting, Criteria types, and Criteria details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT c.shortname AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = t.course AND a.criteriatype IS NULL)) = 2 THEN &amp;quot;All&amp;quot;&lt;br /&gt;
ELSE &amp;quot;Any&amp;quot;&lt;br /&gt;
END AS Course_Aggregation,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;Self completion&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN &amp;quot;Date done by&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;Unenrolement&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 4 THEN &amp;quot;Activity completion&amp;quot;   &lt;br /&gt;
WHEN t.criteriatype = 5 THEN &amp;quot;Duration in days&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 6 THEN &amp;quot;Final grade&amp;quot;     &lt;br /&gt;
WHEN t.criteriatype = 7 THEN &amp;quot;Approve by role&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 8 THEN &amp;quot;Previous course&amp;quot;&lt;br /&gt;
END AS Criteria_type,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(t.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 4 THEN&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,t.module,&#039;/view.php?id=&#039;,t.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,t.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN t.criteriatype = 5 THEN ROUND(t.enrolperiod/86400)&lt;br /&gt;
WHEN t.criteriatype = 6 THEN ROUND(t.gradepass,2)&lt;br /&gt;
WHEN t.criteriatype = 7 THEN (SELECT r.shortname FROM prefix_role AS r WHERE r.id = t.role)&lt;br /&gt;
WHEN t.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = t.courseinstance)&lt;br /&gt;
END AS Criteria_detail&lt;br /&gt;
FROM prefix_course_completion_criteria as t&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Completion Report with custom dates===&lt;br /&gt;
&lt;br /&gt;
List of users who completed multiple or single course/s from a start date to end date chosen by the user. The output gives username, name, course name, completion date and score&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT u.username AS &#039;User Name&#039;,&lt;br /&gt;
CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Name&#039;,&lt;br /&gt;
c.shortname AS &#039;Course Name&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%W %e %M, %Y&#039;) AS &#039;Completed Date&#039;,&lt;br /&gt;
ROUND(c4.gradefinal,2) AS &#039;Score&#039;&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
JOIN prefix_course_completion_crit_compl AS c4 ON u.id = c4.userid&lt;br /&gt;
WHERE c.enablecompletion = 1  AND (p.timecompleted IS NOT NULL OR p.timecompleted !=&#039;&#039;) &lt;br /&gt;
AND (p.timecompleted&amp;gt;= :start_date AND p.timecompleted&amp;lt;=:end_date)&lt;br /&gt;
GROUP BY u.username&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scales used in activities===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT scale.name&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,gi.itemmodule,&#039;/view.php?id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module View&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/modedit.php?up&#039;,&#039;date=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module Settings&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON c.id = gi.courseid&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = gi.courseid AND cm.instance = gi.iteminstance&lt;br /&gt;
JOIN prefix_scale AS scale ON scale.id = gi.scaleid&lt;br /&gt;
WHERE gi.scaleid IS NOT NULL&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Extra Credit Items by Name Only===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
This query identifies grade items in visible courses with student enrollment that have &amp;quot;extra credit&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, gi.itemname AS Item_Name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors&lt;br /&gt;
&lt;br /&gt;
,(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;&lt;br /&gt;
&lt;br /&gt;
,now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON gi.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE gi.itemname LIKE &#039;%extra credit%&#039; &lt;br /&gt;
	AND gi.gradetype = &#039;1&#039; &lt;br /&gt;
	AND gi.hidden = &#039;0&#039; &lt;br /&gt;
	AND gi.aggregationcoef = &#039;0&#039; &lt;br /&gt;
	AND c.visible = 1&lt;br /&gt;
	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) &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
GROUP BY Course_ID, gi.id&lt;br /&gt;
ORDER BY StartDate, Course_ID&lt;br /&gt;
 &lt;br /&gt;
%%FILTER_SEARCHTEXT:Course_ID:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site Wide Number of Courses Completed by User===&lt;br /&gt;
Contributed by Ken St. John&lt;br /&gt;
&lt;br /&gt;
Simple report that shows the number of completed courses for all users site wide&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname, u.firstname,&lt;br /&gt;
COUNT(p.timecompleted) AS TotalCompletions&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
GROUP BY p.userid&lt;br /&gt;
ORDER BY u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Activity Module Reports==&lt;br /&gt;
&lt;br /&gt;
=== User activity completions with dates===&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. It includes the new core H5P module in 3.10. Add any third party activity modules you may have in your site as you need. Also, thanks to Tim Hunt for improvements to this query. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.username As &#039;User&#039;,&lt;br /&gt;
c.shortname AS &#039;Course&#039;,&lt;br /&gt;
m.name AS Activitytype, &lt;br /&gt;
CASE &lt;br /&gt;
    WHEN m.name = &#039;assign&#039;  THEN (SELECT name FROM prefix_assign WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;assignment&#039;  THEN (SELECT name FROM prefix_assignment WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;book&#039;  THEN (SELECT name FROM prefix_book WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;chat&#039;  THEN (SELECT name FROM prefix_chat WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;choice&#039;  THEN (SELECT name FROM prefix_choice WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;data&#039;  THEN (SELECT name FROM prefix_data WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;feedback&#039;  THEN (SELECT name FROM prefix_feedback WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;folder&#039;  THEN (SELECT name FROM prefix_folder WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;forum&#039; THEN (SELECT name FROM prefix_forum WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;glossary&#039; THEN (SELECT name FROM prefix_glossary WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;h5pactivity&#039; THEN (SELECT name FROM prefix_h5pactivity WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;imscp&#039; THEN (SELECT name FROM prefix_imscp WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;label&#039;  THEN (SELECT name FROM prefix_label WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;lesson&#039;  THEN (SELECT name FROM prefix_lesson WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;lti&#039;  THEN (SELECT name FROM prefix_lti  WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;page&#039;  THEN (SELECT name FROM prefix_page WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;quiz&#039;  THEN (SELECT name FROM prefix_quiz WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;resource&#039;  THEN (SELECT name FROM prefix_resource WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;scorm&#039;  THEN (SELECT name FROM prefix_scorm WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;survey&#039;  THEN (SELECT name FROM prefix_survey WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;url&#039;  THEN (SELECT name FROM prefix_url  WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;wiki&#039; THEN (SELECT name FROM prefix_wiki  WHERE id = cm.instance)&lt;br /&gt;
    WHEN m.name = &#039;workshop&#039; THEN (SELECT name FROM prefix_workshop  WHERE id = cm.instance)&lt;br /&gt;
   ELSE &amp;quot;Other activity&amp;quot;&lt;br /&gt;
END AS Actvityname,&lt;br /&gt;
# cm.section AS Coursesection,&lt;br /&gt;
CASE&lt;br /&gt;
    WHEN cm.completion = 0 THEN &#039;0 None&#039;&lt;br /&gt;
    WHEN cm.completion = 1 THEN &#039;1 Self&#039;&lt;br /&gt;
    WHEN cm.completion = 2 THEN &#039;2 Auto&#039;&lt;br /&gt;
END AS Activtycompletiontype, &lt;br /&gt;
CASE&lt;br /&gt;
   WHEN cmc.completionstate = 0 THEN &#039;In Progress&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 1 THEN &#039;Completed&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 2 THEN &#039;Completed with Pass&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 3 THEN &#039;Completed with Fail&#039;&lt;br /&gt;
   ELSE &#039;Unknown&#039;&lt;br /&gt;
END AS &#039;Progress&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(cmc.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;&lt;br /&gt;
FROM prefix_course_modules_completion cmc &lt;br /&gt;
JOIN prefix_user u ON cmc.userid = u.id&lt;br /&gt;
JOIN prefix_course_modules cm ON cmc.coursemoduleid = cm.id&lt;br /&gt;
JOIN prefix_course c ON cm.course = c.id&lt;br /&gt;
JOIN prefix_modules m ON cm.module = m.id&lt;br /&gt;
# skip the predefined admin and guest user&lt;br /&gt;
WHERE u.id &amp;gt; 2&lt;br /&gt;
# config reports filters&lt;br /&gt;
%%FILTER_USERS:u.username%%&lt;br /&gt;
%%FILTER_SEARCHTEXT:m.name:~%%&lt;br /&gt;
%%FILTER_STARTTIME:cmc.timemodified:&amp;gt;%% %%FILTER_ENDTIME:cmc.timemodified:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many SCORM activities are used in each Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cm.course,c.fullname ,m.name &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/scorm/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,count(cm.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS Counter&lt;br /&gt;
 &lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
  JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
  JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%scorm%&#039; &lt;br /&gt;
GROUP BY cm.course,cm.module &lt;br /&gt;
ORDER BY count(cm.id) desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===SCORM Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of SCORM activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, scm.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;SCO%&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_scorm AS scm ON scm.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LTI (External Tool) Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of  LTI (External Tool) Usage activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, lti.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;lti&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_lti AS lti ON lti.id = cm.instance&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each MODULE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module,action,count(id) as counter&lt;br /&gt;
FROM prefix_log&lt;br /&gt;
GROUP BY module,action&lt;br /&gt;
ORDER BY module,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Most popular ACTIVITY===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, module&lt;br /&gt;
FROM prefix_log l&lt;br /&gt;
WHERE module != &#039;login&#039; AND module != &#039;course&#039; AND module != &#039;role&#039;&lt;br /&gt;
GROUP BY module&lt;br /&gt;
ORDER BY hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide use of ACTIVITIES and RESOURCES===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count( cm.id ) AS counter, m.name&lt;br /&gt;
FROM `prefix_course_modules` AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
ORDER BY counter DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LOG file ACTIONS per MODULE per COURSE (IDs)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select course,module,action,count(action) as summa from prefix_log&lt;br /&gt;
where action &amp;lt;&amp;gt; &#039;new&#039;&lt;br /&gt;
group by course,action,module&lt;br /&gt;
order by course,module,action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System Wide usage count of various course Activities===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
Like: Forum, Wiki, Blog, Assignment, Database,&lt;br /&gt;
#Within specific category&lt;br /&gt;
#Teacher name in course&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS Forums&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%data%&#039;) AS Databses&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%assignment%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 18)&lt;br /&gt;
ORDER BY Wikis DESC,Blogs DESC, Forums DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course wiki usage/activity over the last 6 semesters===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &amp;quot;Courses with Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester A%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester A&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester B%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester B&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed WIKI activity (per wiki per course)===&lt;br /&gt;
Including Number of Students in course (for reference)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID  &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id ) AS Students&lt;br /&gt;
,m.name&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%updat%&#039; ) as &#039;UPDAT E&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%annotate%&#039; ) as ANNOTATE&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%comment%&#039; ) as COMMENT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%add%&#039; ) as &#039;A DD&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%edit%&#039; ) as EDIT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action NOT LIKE &#039;%view%&#039; ) as &#039;All (NO View)&#039;&lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
GROUP BY cm.course,cm.module&lt;br /&gt;
ORDER BY &#039;All (NO View)&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wiki usage, system wide===&lt;br /&gt;
(you can filter the output by selecting some specific course categories : &amp;quot;WHERE c.category IN ( 8,13,15)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039;) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%add%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ADD&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%edit%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;EDIT&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%annotate%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ANNOTATE&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%comments%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;Comments&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_ouwiki_pages as ouwp&lt;br /&gt;
JOIN prefix_ouwiki as ouw ON ouw.id = ouwp.subwikiid&lt;br /&gt;
WHERE ouw.course = c.id GROUP BY ouw.course  ) as OUWikiPages&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( DISTINCT nwp.pagename ) FROM prefix_wiki_pages AS nwp&lt;br /&gt;
JOIN prefix_wiki AS nw ON nw.id = nwp.dfwiki WHERE nw.course = c.id ) As NWikiPages&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Wikis &amp;gt; 0&lt;br /&gt;
ORDER BY &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Aggregated Teacher activity by &amp;quot;WEB2&amp;quot; Modules===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
The NV column shows activity without VIEW log activity&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.userid, u.firstname,u.lastname&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039;) AS Wiki&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Wiki_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039;) AS Forum&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Forum_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039;) AS Blog&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Blog_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039;) AS Assignment&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Assignment_NV&lt;br /&gt;
FROM prefix_role_assignments AS ra &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
WHERE ra.roleid = 3 &lt;br /&gt;
GROUP BY ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the certificates issued, sort by variables in the custom profile fields===&lt;br /&gt;
Note: The SQL queries look intimidating at first, but isn&#039;t really that difficult to learn. I&#039;ve seen in the forums that users wanted to do &#039;site-wide&#039; groups in 1.9x. This is sort of the idea. It pulls all the certificates issued to all users sorted by the custom profile fields, which in my case is the Units or Depts (i.e. my site wide groups). Why certificates? I&#039;ve explored with both grades and quizzes, the course admins are not really interested in the actual grades but whether the learner received a certificate (i.e. passed the course with x, y, z activities). It also saves me from creating groups and assigning them into the right groups. Even assigning in bulk is not efficient, since I have upward of 25 groups per course and constantly new learners enrolling in courses. The limitation is something to do with the server? as it only pull 5000 rows of data. If anyone figured out how to change this, please let me know. In the meantime, the work around is to pull only a few units/depts at a time to limit the number of rows. This is fine at the moment, since each course admin are only responsible for certain units/depts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(prefix_certificate_issues.timecreated), &#039;%Y-%m-%d&#039; ) AS Date,&lt;br /&gt;
prefix_certificate_issues.classname AS Topic,&lt;br /&gt;
prefix_certificate.name AS Certificate,&lt;br /&gt;
prefix_certificate_issues.studentname as Name,&lt;br /&gt;
prefix_user_info_data.data AS Units&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_certificate_issues&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_user_info_data&lt;br /&gt;
on prefix_certificate_issues.userid = prefix_user_info_data.userid&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_certificate&lt;br /&gt;
on prefix_certificate_issues.certificateid = prefix_certificate.id&lt;br /&gt;
&lt;br /&gt;
WHERE prefix_user_info_data.data=&#039;Unit 1&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 2&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 3&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY Units, Name, Topic ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== All Simple Certificates Earned in the Site===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 [http://www.mysqltutorial.org/mysql-date_format/ DATE_FORMAT] function.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
CONCAT (u.firstname, &#039; &#039;,u.lastname) As &#039;User&#039;,&lt;br /&gt;
c.fullname AS &#039;Course&#039;,&lt;br /&gt;
sc.name AS &#039;Certificate&#039;,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(sci.timecreated), &#039;%Y-%m-%d&#039; ) As &#039;Date Awarded&#039;&lt;br /&gt;
# sci.code &#039;CertificateId&#039;&lt;br /&gt;
FROM prefix_simplecertificate_issues sci&lt;br /&gt;
JOIN prefix_user u ON sci.userid = u.id&lt;br /&gt;
JOIN prefix_simplecertificate sc ON sci.certificateid = sc.id&lt;br /&gt;
JOIN prefix_course AS c ON sc.course = c.id&lt;br /&gt;
ORDER BY sci.timecreated DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE DATEDIFF(NOW(),FROM_UNIXTIME(sci.timecreated) ) &amp;lt; 30&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Counter Blog usage in Courses,system wide===&lt;br /&gt;
What teachers in what courses, uses blogs and how many + student count in that course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT ( @counter := @counter+1) as counter, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c, (SELECT @counter := 0) as s_init&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Blogs &amp;gt; 0&lt;br /&gt;
ORDER BY Blogs DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Elluminate (Blackboard Collaborate) - system wide usage===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT e.name As Session ,er.recordingsize&lt;br /&gt;
,c.fullname As Course&lt;br /&gt;
,u.firstname,u.lastname &lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(e.timestart),&#039;%d-%m-%Y&#039;) AS dTimeStart&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/moodle/mod/elluminate/loadrecording.php?id=&#039;,er.id,&#039;&amp;quot;&amp;gt;Show&amp;lt;/a&amp;gt;&#039;) AS RecordedSession&lt;br /&gt;
&lt;br /&gt;
FROM prefix_elluminate_recordings AS er&lt;br /&gt;
JOIN prefix_elluminate AS e ON e.meetingid = er.meetingid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = e.creator &lt;br /&gt;
ORDER BY er.recordingsize DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choice ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Results of the Choice activity. For all courses, shows course shortname, username, the Choice text, and the answer chosen by the user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname AS course, u.username, h.name as question, o.text AS answer&lt;br /&gt;
FROM prefix_choice AS h&lt;br /&gt;
JOIN prefix_course AS c ON h.course = c.id&lt;br /&gt;
JOIN prefix_choice_answers AS a ON h.id = a.choiceid&lt;br /&gt;
JOIN prefix_user AS u ON a.userid = u.id&lt;br /&gt;
JOIN prefix_choice_options AS o ON a.optionid = o.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment type usage in courses ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assign/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_assign WHERE c.id = course) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;file&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
#GROUP BY apc.plugin&lt;br /&gt;
) AS &amp;quot;File Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;onlinetext&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Online Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;pdf&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;PDF Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;offline&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Offline Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;comments&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Assignments Comments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_assign AS assign&lt;br /&gt;
JOIN prefix_course AS c ON c.id = assign.course&lt;br /&gt;
GROUP BY c.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Assignment Module Reports==&lt;br /&gt;
===All Ungraded Assignments===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
Returns all the submitted assignments that still need grading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id&lt;br /&gt;
and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Ungraded Assignments w/ Link===&lt;br /&gt;
Returns all assignments submitted by those with the student role that have the status of &#039;submitted&#039;, along with a link that goes directly to the submission to grade it. The links work if you view the report within Moodle.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This query is updated for use with Moodle 2.2 or later.  Contributed by Carly J. Born, Carleton College&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;,&lt;br /&gt;
 &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assign/view.php?id=&#039;, &lt;br /&gt;
cm.id, &lt;br /&gt;
&#039;&amp;amp;rownum=0&amp;amp;action=grader&amp;amp;userid=&#039;, &lt;br /&gt;
u.id,&lt;br /&gt;
&#039;&amp;quot;&amp;gt;Grade&amp;lt;/a&amp;gt;&#039;) &lt;br /&gt;
AS &amp;quot;Assignment link&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_assign_submission sub&lt;br /&gt;
JOIN prefix_assign a ON a.id = sub.assignment&lt;br /&gt;
JOIN prefix_user u ON u.id = sub.userid&lt;br /&gt;
JOIN prefix_course c ON c.id = a.course AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_course_modules cm ON c.id = cm.course &lt;br /&gt;
JOIN prefix_context cxt ON c.id=cxt.instanceid AND cxt.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments ra ON cxt.id = ra.contextid AND ra.roleid=5 AND ra.userid=u.id&lt;br /&gt;
 &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 22 AND sub.status=&#039;submitted&#039;&lt;br /&gt;
 &lt;br /&gt;
ORDER BY c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;a href=&amp;quot;http://education.varonis.com/mod/assignment/submissions.php&#039; + char(63) +&lt;br /&gt;
+ &#039;id=&#039; + cast(cm.id as varchar) + &#039;&amp;amp;userid=&#039; + cast(u.id as varchar) &lt;br /&gt;
+ &#039;&amp;amp;mode=single&amp;amp;filter=0&amp;amp;offset=2&amp;quot;&amp;gt;&#039; + a.name + &#039;&amp;lt;/a&amp;gt;&#039;&lt;br /&gt;
AS &amp;quot;Assignmentlink&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments (and Quizzes) waiting to be graded===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This report requires a YEAR filter to be added (Available when using the latest block/configurable_reports)&lt;br /&gt;
&lt;br /&gt;
Which you can always remove, to make this query work on earlier versions.&lt;br /&gt;
&lt;br /&gt;
The report includes: &lt;br /&gt;
*number of quizzes&lt;br /&gt;
*unFinished Quiz attempts&lt;br /&gt;
*Finished Quiz attempts&lt;br /&gt;
*number of students&lt;br /&gt;
*number of Assignments&lt;br /&gt;
*number of submitted answers by students &lt;br /&gt;
*number of unchecked assignments (waiting for the Teacher) in a Course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
 &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assignment/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;מטלות&amp;lt;/a&amp;gt;&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;בחנים&amp;lt;/a&amp;gt;&#039;) AS &#039;Quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_course_modules cm &lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module &lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039; AND cm.course = c.id &lt;br /&gt;
GROUP BY cm.course &lt;br /&gt;
) AS &#039;nQuizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish = 0&lt;br /&gt;
GROUP BY q.course) AS &#039;unFinished Quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish &amp;gt; 0&lt;br /&gt;
GROUP BY q.course) AS &#039;finished quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS nStudents&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(a.id)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) nAssignments&lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE a.course = c.id AND FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course&lt;br /&gt;
) &#039;Open &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(ROUND( (100 / iAssignments ) * iOpenAssignments ) ,&#039;%&#039;) &#039;unFinished &amp;lt;br/&amp;gt;Assignments &amp;lt;br/&amp;gt;(percent)&#039;&lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE asb.grade &amp;lt; 0 AND cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;unChecked  &amp;lt;br/&amp;gt;Submissions&#039; &lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;Submitted  &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblAssignmentsCount ON tblAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iOpenAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblOpenAssignmentsCount ON tblOpenAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1  &lt;br /&gt;
#AND c.fullname LIKE &#039;%תשעג%&#039;&lt;br /&gt;
%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
ORDER BY &#039;Open &amp;lt;br/&amp;gt;Assignments&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rubrics without zero values in criteria===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
Rubric calculations in Moodle can fail to align with instructors expectations if they lack a zero value for each criterion used in the assessment. From documentation at https://docs.moodle.org/32/en/Rubrics#Grade_calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;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.&lt;br /&gt;
TIP: To avoid confusion from this sort of thing, we recommend including a level with 0 points in every rubric criterion.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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&#039; favor.&lt;br /&gt;
&lt;br /&gt;
Includes search filter of course idnumber.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cat.name AS Department, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, &lt;br /&gt;
c.fullname AS Course_Name, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/grading/form/rubric/edit.php&#039;,CHAR(63),&#039;areaid=&#039;,gd.areaid,&#039;&amp;quot;&amp;gt;&#039;,gd.areaid,&#039;&amp;lt;/a&amp;gt;&#039;) AS Rubric&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_categories AS cat &lt;br /&gt;
ON cat.id = c.category&lt;br /&gt;
JOIN prefix_course_modules AS cm &lt;br /&gt;
ON c.id=cm.course&lt;br /&gt;
JOIN prefix_context AS ctx &lt;br /&gt;
ON cm.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_grading_areas AS garea &lt;br /&gt;
ON ctx.id = garea.contextid&lt;br /&gt;
JOIN prefix_grading_definitions AS gd &lt;br /&gt;
ON garea.id = gd.areaid&lt;br /&gt;
JOIN prefix_gradingform_rubric_criteria AS crit &lt;br /&gt;
ON gd.id = crit.definitionid&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id&lt;br /&gt;
WHERE cm.visible=&#039;1&#039; AND garea.activemethod = &#039;rubric&#039; AND (crit.id NOT IN&lt;br /&gt;
(SELECT crit.id&lt;br /&gt;
FROM prefix_gradingform_rubric_criteria AS crit&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id WHERE levels.score = &#039;0&#039;))&lt;br /&gt;
&lt;br /&gt;
GROUP BY Rubric&lt;br /&gt;
ORDER BY Course_ID, Rubric&lt;br /&gt;
&lt;br /&gt;
%%FILTER_SEARCHTEXT:c.idnumber:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Who is using &amp;quot;Single File Upload&amp;quot; assignment===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,ass.name as &amp;quot;Assignment Name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM &lt;br /&gt;
prefix_assignment as ass&lt;br /&gt;
&lt;br /&gt;
JOIN &lt;br /&gt;
prefix_course as c ON c.id = ass.course&lt;br /&gt;
&lt;br /&gt;
WHERE `assignmenttype` LIKE &#039;uploadsingle&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Feedback Module Reports==&lt;br /&gt;
===List the answers to all the Feedback activities within the current course, submitted by the current user===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT /* crs.fullname as &amp;quot;Course name&amp;quot;, f.name AS &amp;quot;Journal name&amp;quot;, CONCAT(u.firstname,&#039; &#039;,UPPER(u.lastname)) as &amp;quot;Participant&amp;quot;, */ /* include these fields if you want to check the composition of the recordset */&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified),&#039;%W %e %M, %Y&#039;) as &amp;quot;Answer Date&amp;quot;,&lt;br /&gt;
CASE i.typ WHEN &#039;label&#039; THEN i.presentation ELSE i.name END as &amp;quot;Topic&amp;quot;,  /* usually labels are used as section titles, so you&#039;d want them present in the recordset */&lt;br /&gt;
v.value as &amp;quot;My Answer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback AS f&lt;br /&gt;
INNER JOIN prefix_course as crs on crs.id=f.course %%FILTER_COURSES:f.course%% &lt;br /&gt;
INNER JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
INNER JOIN prefix_feedback_completed AS c on f.id=c.feedback %%FILTER_COURSEUSER:c.userid%% &lt;br /&gt;
LEFT JOIN prefix_feedback_value AS v on v.completed=c.id AND v.item=i.id&lt;br /&gt;
INNER JOIN prefix_user AS u on c.userid=u.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%% AND u.id = %%USERID%%  AND c.anonymous_response = 1  /* This clause limits the recordset to the current course and the current user and includes/ excludes the anonymous responses as needed */&lt;br /&gt;
&lt;br /&gt;
ORDER BY f.id, c.timemodified, i.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show all Feedbacks from all courses for all users including showing names of anonymous users===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 truly anonymous users on the front page as &#039;Not-logged-in&#039; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS Course, &lt;br /&gt;
f.name AS Feedback,&lt;br /&gt;
# i.id AS Itemid,&lt;br /&gt;
i.name AS Itemname,&lt;br /&gt;
i.label AS Itemlabel,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN f.anonymous = 1 AND u.id != 0 THEN CONCAT(u.username, &#039; :ANON&#039;)&lt;br /&gt;
 WHEN fc.userid = 0 THEN &#039;Not-logged-in&#039;&lt;br /&gt;
 ELSE u.username&lt;br /&gt;
END AS &#039;User&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(fc.timemodified),&#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;Completed&amp;quot;,&lt;br /&gt;
v.value AS &amp;quot;Choice&amp;quot;,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN i.typ = &#039;multichoice&#039; THEN&lt;br /&gt;
     IF (  SUBSTRING(i.presentation,1,6)=&#039;d&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&#039;,&lt;br /&gt;
	       SUBSTRING(i.presentation,7),&lt;br /&gt;
		   i.presentation)&lt;br /&gt;
 ELSE i.presentation&lt;br /&gt;
END AS &amp;quot;Answers&amp;quot;,&lt;br /&gt;
i.typ,&lt;br /&gt;
i.dependitem,&lt;br /&gt;
i.dependvalue&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback f&lt;br /&gt;
JOIN prefix_course c ON c.id=f.course &lt;br /&gt;
JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
JOIN prefix_feedback_completed fc ON f.id=fc.feedback&lt;br /&gt;
LEFT JOIN prefix_feedback_value v ON v.completed=fc.id AND v.item=i.id&lt;br /&gt;
LEFT JOIN prefix_user AS u ON fc.userid=u.id&lt;br /&gt;
WHERE i.typ != &#039;pagebreak&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Show all Feedbacks from all courses for all users with their answers===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Shows all Feedbacks in all Courses with all multi-choice questions and answers of all users for multi-choice questions. It shows the possible answers, the number of the chosen answer and the text of the chosen answer by the user. As always, I disavow any prettiness here and you should update the fields as you need.&lt;br /&gt;
&lt;br /&gt;
Known to work in Moodle 3.5 to 3.10.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.fullname as &amp;quot;Course&amp;quot;, &lt;br /&gt;
f.name AS &amp;quot;Feedback&amp;quot;, &lt;br /&gt;
CONCAT(u.firstname,&#039;  &#039;,u.lastname) as &amp;quot;User&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(fc.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;When&amp;quot;,&lt;br /&gt;
IF(i.typ = &#039;label&#039;, i.presentation, i.name) AS &amp;quot;Question&amp;quot;, &lt;br /&gt;
# answers presentation string starts with these 6 characters:  r&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;br /&gt;
CASE WHEN i.typ = &#039;multichoice&#039; THEN SUBSTRING(i.presentation,7) END AS &amp;quot;Possible Answers&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
CASE i.typ WHEN &#039;multichoice&#039; THEN v.value ELSE &#039;-&#039; END AS &amp;quot;Chosen Answer Num&amp;quot;,&lt;br /&gt;
CASE v.value&lt;br /&gt;
  WHEN 1 THEN SUBSTRING(i.presentation, 7, POSITION(&#039;|&#039; IN i.presentation) - 7) &lt;br /&gt;
  WHEN 2 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,2), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 3 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,3), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 4 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,4), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 5 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,5), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 6 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,6), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 7 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,7), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 8 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,8), &#039;|&#039;,-1)&lt;br /&gt;
  WHEN 9 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(i.presentation, &#039;|&#039;,9), &#039;|&#039;,-1) &lt;br /&gt;
  ELSE CONCAT(&amp;quot;More:&amp;quot;, v.value)&lt;br /&gt;
END AS &amp;quot;Chosen Answer Text&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_feedback AS f&lt;br /&gt;
JOIN prefix_course AS c ON c.id=f.course&lt;br /&gt;
JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
JOIN prefix_feedback_completed AS fc ON f.id=fc.feedback &lt;br /&gt;
LEFT JOIN prefix_feedback_value AS v ON v.completed=fc.id AND v.item=i.id&lt;br /&gt;
JOIN prefix_user AS u ON fc.userid=u.id&lt;br /&gt;
&lt;br /&gt;
WHERE i.typ IN (&#039;label&#039;, &#039;multichoice&#039;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Resource Module Reports==&lt;br /&gt;
===List &amp;quot;Recently uploaded files&amp;quot;===&lt;br /&gt;
see what users are uploading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT FROM_UNIXTIME(time,&#039;%Y %M %D %h:%i:%s&#039;) as time ,ip,userid,url,info  &lt;br /&gt;
FROM `prefix_log` &lt;br /&gt;
WHERE `action` LIKE &#039;upload&#039; &lt;br /&gt;
ORDER BY `prefix_log`.`time`  DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Courses that loaded a specific file: &amp;quot;X&amp;quot;===&lt;br /&gt;
Did the Teacher (probably) uploaded course&#039;s Syllabus ?&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname  FROM `prefix_log` as l &lt;br /&gt;
JOIN prefix_course as c ON c.id = l.course &lt;br /&gt;
WHERE `action` LIKE &#039;%upload%&#039; AND ( info LIKE &#039;%Syllabus%&#039; OR info LIKE &#039;%Sylabus%&#039; ) GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All resources that link to some specific external website===&lt;br /&gt;
+ link to course&lt;br /&gt;
+ who&#039;s the teacher&lt;br /&gt;
+ link to external resource&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/resource/view.php?id=&#039;,r.id,&#039;&amp;quot;&amp;gt;&#039;,r.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Resource&lt;br /&gt;
FROM prefix_resource AS r &lt;br /&gt;
JOIN prefix_course AS c ON r.course = c.id&lt;br /&gt;
WHERE r.reference LIKE &#039;http://info.oranim.ac.il/home%&#039; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;quot;Compose Web Page&amp;quot; RESOURCE count===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT course,prefix_course.fullname, COUNT(*) AS Total&lt;br /&gt;
FROM `prefix_resource`&lt;br /&gt;
JOIN `prefix_course` ON prefix_course.id = prefix_resource.course&lt;br /&gt;
WHERE type=&#039;html&#039;&lt;br /&gt;
GROUP BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resource count in courses===&lt;br /&gt;
+ (First)Teacher name&lt;br /&gt;
+ Where course is inside some specific Categories&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
COUNT(*) AS count&lt;br /&gt;
,r.course &lt;br /&gt;
,c.shortname shortname&lt;br /&gt;
,c.fullname coursename&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user as u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = r.course AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
FROM prefix_resource r &lt;br /&gt;
JOIN prefix_course c ON r.course = c.id&lt;br /&gt;
WHERE c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY r.course&lt;br /&gt;
ORDER BY COUNT(*) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Delete all the automated backup files===&lt;br /&gt;
Prepare bash cli script to delete all the automated backup files on the file system. (clean up some disk space)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT( &#039;rm -f /var/moodledatanew/filedir/&#039;, SUBSTRING( contenthash, 1, 2 ) , &#039;/&#039;, SUBSTRING( contenthash, 3, 2 ) , &#039;/&#039;, contenthash ) &lt;br /&gt;
FROM `mdl_files` &lt;br /&gt;
WHERE `filename` LIKE &#039;%mbz%&#039;&lt;br /&gt;
AND filearea = &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find out how much disk space is used by all automated backup files:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT SUM(filesize)/(1024*1024*1024) FROM `mdl_files` WHERE  `filename` LIKE &#039;%mbz%&#039; AND filearea =  &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Forum Module Reports==&lt;br /&gt;
===print all User&#039;s post in course Forums===&lt;br /&gt;
%%COURSEID%% is a variable the is replace by the current CourseID you are running the sql report from. if you are using the latest block/configurable_reports ! (You can always change it to a fixed course or remove it to display all courses.)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php?course=&#039;,c.id,&#039;&amp;amp;id=&#039;,u.id,&#039;&amp;amp;mode=posts&amp;quot;&amp;gt;&#039;,CONCAT(u.firstname,&#039; &#039;, u.lastname),&#039;&amp;lt;/a&amp;gt;&#039;) As Fullname&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Forum&lt;br /&gt;
,count(*) as Posts&lt;br /&gt;
,(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&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_user as u ON u.id = fp.userid &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = fd.course &lt;br /&gt;
WHERE fd.course = %%COURSEID%% &lt;br /&gt;
GROUP BY f.id,u.id&lt;br /&gt;
ORDER BY u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE by type -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, prefix_forum.type, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course,prefix_forum.type&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Forum activity - system wide===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,c.fullname as Course&lt;br /&gt;
,f.type&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
, fd.forum, f.name,count(*) AS cPostAndDisc&lt;br /&gt;
,(SELECT count(*) FROM prefix_forum_discussions AS ifd WHERE ifd.forum = f.id) AS cDiscussion&lt;br /&gt;
FROM prefix_forum_posts AS fp&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type != &#039;news&#039; AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
## WHERE 1=1 &lt;br /&gt;
## %%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count( * ) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Activity In Forums===&lt;br /&gt;
Trying to figure out how much real activity we have in Forums by aggregating:&lt;br /&gt;
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...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname,f.name,f.type &lt;br /&gt;
,(SELECT count(id) FROM prefix_forum_discussions as fd WHERE f.id = fd.forum) as Discussions&lt;br /&gt;
,(SELECT count(distinct fd.userid) FROM prefix_forum_discussions as fd WHERE fd.forum = f.id) as UniqueUsersDiscussions&lt;br /&gt;
,(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&lt;br /&gt;
,(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&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS StudentsCount&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Teachers&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS &#039;Teacher&amp;lt;br/&amp;gt;Count&#039;&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid IN (3,5)&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS UserCount&lt;br /&gt;
, (SELECT (UniqueUsersDiscussions / StudentsCount )) as StudentDissUsage&lt;br /&gt;
, (SELECT (UniqueUsersPosts /StudentsCount)) as StudentPostUsage&lt;br /&gt;
FROM prefix_forum as f &lt;br /&gt;
JOIN prefix_course as c ON f.course = c.id&lt;br /&gt;
WHERE `type` != &#039;news&#039;&lt;br /&gt;
ORDER BY StudentPostUsage DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Forum type:NEWS===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT f.id, f.name&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
WHERE m.name = &#039;forum&#039;&lt;br /&gt;
AND f.type = &#039;news&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All new forum NEWS items (discussions) from all my Courses===&lt;br /&gt;
change &amp;quot;userid = 26&amp;quot; and &amp;quot;id = 26&amp;quot; to a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname,f.name,fd.name,FROM_UNIXTIME(fd.timemodified ,&amp;quot;%d %M %Y &amp;quot;) as Date&lt;br /&gt;
FROM prefix_forum_discussions as fd &lt;br /&gt;
JOIN prefix_forum as f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = f.course &lt;br /&gt;
JOIN prefix_user_lastaccess as ul ON (c.id = ul.courseid AND ul.userid = 26)&lt;br /&gt;
WHERE fd.timemodified &amp;gt; ul.timeaccess  &lt;br /&gt;
 AND fd.forum IN (SELECT f.id&lt;br /&gt;
 FROM prefix_course_modules AS cm&lt;br /&gt;
 JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
 JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
 WHERE m.name = &#039;forum&#039;&lt;br /&gt;
 AND f.type = &#039;news&#039;)&lt;br /&gt;
  AND c.id IN (SELECT c.id&lt;br /&gt;
   FROM prefix_course AS c&lt;br /&gt;
   JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
   JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
   JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
   WHERE u.id = 26) ORDER BY `fd`.`timemodified` DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===News Forum - Discussions COUNT===&lt;br /&gt;
Which is actually... How much instructions students get from their teachers&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname ,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,count(fd.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS DiscussionsSum&lt;br /&gt;
FROM prefix_forum_discussions AS fd&lt;br /&gt;
INNER JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
INNER JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type = &#039;news&#039; AND c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count(fd.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cantidad de foros que han sido posteados por profesor===&lt;br /&gt;
&lt;br /&gt;
(Number of forums that have been posted by teacher/Google translator)&lt;br /&gt;
&lt;br /&gt;
Queriamos saber cuales son las acciones del profesor dentro de los foros de cada curso, por ello se hizo este informe.&lt;br /&gt;
&lt;br /&gt;
(We wanted to know what the teacher&#039;s actions are in the forums of each course, so this report was made. /Google translator)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS curso,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Facilitador,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( m.name ) AS COUNT FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS foros,&lt;br /&gt;
&lt;br /&gt;
COUNT(*) AS Posts&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course AS c ON c.id = fd.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = fp.userid &lt;br /&gt;
&lt;br /&gt;
WHERE fp.userid =&lt;br /&gt;
(&lt;br /&gt;
select distinct prefix_user.id&lt;br /&gt;
from prefix_user &lt;br /&gt;
join prefix_role_assignments as ra on ra.userid = prefix_user.id &lt;br /&gt;
where ra.roleid = 3 &lt;br /&gt;
and userid = fp.userid&lt;br /&gt;
limit 1&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
and c.shortname like &#039;%2014-2-1%&#039;&lt;br /&gt;
GROUP BY c.id, u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all the Forums that got high rating===&lt;br /&gt;
We setup a scale that let teachers and students Rate forum post with &amp;quot;Important, interesting, valuable, not rated&amp;quot; scale&lt;br /&gt;
And then add a link to the following report at the begining of the course &amp;quot;Link to all interesting posts&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,f.id,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;,fd.id,&#039;#p&#039;,fp.id,&#039;&amp;quot;&amp;gt;&#039;,fp.subject,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post link&#039;,&lt;br /&gt;
SUM(r.rating) AS &#039;Rating&#039;&lt;br /&gt;
FROM mdl_rating AS r&lt;br /&gt;
  JOIN mdl_forum_posts AS fp ON fp.id = r.itemid&lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
WHERE r.component = &#039;mod_forum&#039; AND r.ratingarea = &#039;post&#039; AND f.course = %%COURSEID%%&lt;br /&gt;
GROUP BY r.itemid&lt;br /&gt;
ORDER BY SUM(r.rating) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all Discussions of a single Forum===&lt;br /&gt;
This report is used to help export all the student&#039;s posts and discussions of a single forum, by passing the context module id as a parameter to the report using &amp;quot;&amp;amp;filter_var=cmid&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;, f.id, &#039;&amp;quot;&amp;gt;&#039;, f.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name&#039;,&lt;br /&gt;
fd.name AS &#039;Discussion&#039;, &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;, fd.id, &#039;#p&#039;, fp.id, &#039;&amp;quot;&amp;gt;&#039;, fp.subject, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post (link)&#039;,&lt;br /&gt;
fp.message&lt;br /&gt;
&lt;br /&gt;
FROM mdl_forum_posts AS fp &lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
  JOIN mdl_course_modules AS cm ON cm.module = 9 AND cm.instance = f.id&lt;br /&gt;
WHERE cm.id = %%FILTER_VAR%%&lt;br /&gt;
ORDER BY f.id, fd.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Quiz Module Reports==&lt;br /&gt;
===Generate a list of instructors and their email addresses for those courses that has &amp;quot;essay questions&amp;quot; in their quizzes===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT qu.id AS quiz_id, qu.course AS course_id, qu.questions,&lt;br /&gt;
                co.fullname AS course_fullname, co.shortname AS course_shortname,&lt;br /&gt;
                qu.name AS quiz_name, FROM_UNIXTIME(qu.timeopen) AS quiz_timeopen, FROM_UNIXTIME(qu.timeclose) AS quiz_timeclose,&lt;br /&gt;
                u.firstname, u.lastname, u.email,&lt;br /&gt;
FROM prefix_quiz qu, prefix_course co, prefix_role re, prefix_context ct, prefix_role_assignments ra, prefix_user u&lt;br /&gt;
WHERE FROM_UNIXTIME(timeopen) &amp;gt; &#039;2008-05-14&#039; AND&lt;br /&gt;
                qu.course = co.id AND&lt;br /&gt;
                co.id = ct.instanceid AND&lt;br /&gt;
                ra.roleid = re.id AND&lt;br /&gt;
                re.name = &#039;Teacher&#039; AND&lt;br /&gt;
                ra.contextid = ct.id AND&lt;br /&gt;
                ra.userid = u.id&lt;br /&gt;
 &lt;br /&gt;
SELECT Count(&#039;x&#039;) As NumOfStudents&lt;br /&gt;
                                FROM prefix_role_assignments a&lt;br /&gt;
                                JOIN prefix_user u ON userid = u.id&lt;br /&gt;
                                WHERE roleid = 5 AND contextid = (SELECT id FROM prefix_context WHERE instanceid = 668 AND contextlevel = 50)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Number of Quizes per Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Link&amp;lt;/a&amp;gt;&#039;) AS Quizes&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules cm&lt;br /&gt;
JOIN prefix_course c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module&lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039;&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all MultiAnswer (Cloze) Questions===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/attempt.php?q=&#039;, quiz.id, &#039;&amp;quot;&amp;gt;&#039;, quiz.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS Quiz&lt;br /&gt;
,question.id question_id, question.questiontext &lt;br /&gt;
FROM  prefix_question question&lt;br /&gt;
JOIN prefix_quiz_question_instances qqi ON question.id = qqi.question&lt;br /&gt;
JOIN prefix_quiz quiz ON qqi.quiz = quiz.id&lt;br /&gt;
WHERE  `qtype` LIKE  &#039;multianswer&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List courses with MANUAL grades===&lt;br /&gt;
Which is basically and indication to teachers using Moodle to hold offline grades inside Moodle&#039;s Gradebook,&lt;br /&gt;
So grades could be uploaded into an administrative SIS. Use with Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT( * )&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php?showadvanced=1&amp;amp;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM  prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course as c ON c.id = gi.courseid&lt;br /&gt;
WHERE  `itemtype` =  &#039;manual&#039;&lt;br /&gt;
GROUP BY courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===List the users that did not take the Quiz===&lt;br /&gt;
Do not forget to change &amp;quot;c.id = 14&amp;quot; and q.name LIKE &#039;%quiz name goes here%&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id AS ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.username AS IDNumber,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
 &lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id AND courseid=c.id) AS CourseLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id AND e.courseid = c.id) AS RoleName&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess AS ul ON ul.userid = user2.id&lt;br /&gt;
WHERE c.id=14 and ue.userid NOT IN (SELECT qa.userid FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON qa.quiz = q.id&lt;br /&gt;
JOIN prefix_course AS c ON q.course = c.id&lt;br /&gt;
WHERE c.id = 14 AND q.name LIKE &#039;%quiz name goes here%&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Questions in each Quiz===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT quiz.id,quiz.name, q.id, q.name&lt;br /&gt;
FROM mdl_quiz AS quiz&lt;br /&gt;
JOIN mdl_question AS q ON FIND_IN_SET(q.id, quiz.questions)&lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
ORDER BY quiz.id ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this query does not work in Moodle 2.8+. There is no mdl_quiz.questions field. It will need to be rewritten to use the usage/contextid organization.&lt;br /&gt;
&lt;br /&gt;
Here is a version for Moodle 3.x&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cm.id &#039;cmid&#039;, quiz.id &#039;quiz id&#039;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/edit.php?cmid=&#039;, &lt;br /&gt;
	   cm.id, &#039;&amp;quot;&amp;gt;&#039;, quiz.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;edit quiz&#039;&lt;br /&gt;
,q.id &#039;qid&#039;, q.name &#039;question name&#039;&lt;br /&gt;
FROM mdl_quiz AS quiz&lt;br /&gt;
JOIN mdl_course_modules cm ON cm.instance = quiz.id AND cm.module = 33 # 33=quiz mdl_modules&lt;br /&gt;
JOIN mdl_quiz_slots qs ON qs.quizid = quiz.id &lt;br /&gt;
JOIN mdl_question AS q ON q.id = qs.questionid&lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
ORDER BY quiz.id ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quiz activity research===&lt;br /&gt;
This report was made to extract student full activity in quizzes for an academic research about adapting instructional design teaching methods in online learning. The students do not use the Quiz module as a standard quiz but more as Study booklets or mini courses with embedded questions and hints to assist students evaluate their progress (Similar to what you expect to find in a SCORM activity)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cm.course &amp;quot;course_id&amp;quot;, cm.id &amp;quot;moduel_id&amp;quot;, q.id &amp;quot;quiz_id&amp;quot;, q.name &amp;quot;quiz_name&amp;quot;,&lt;br /&gt;
 &lt;br /&gt;
CASE q.grademethod&lt;br /&gt;
      WHEN 1 THEN &amp;quot;GRADEHIGHEST&amp;quot;&lt;br /&gt;
      WHEN 2 THEN &amp;quot;GRADEAVERAGE&amp;quot;&lt;br /&gt;
      WHEN 3 THEN &amp;quot;ATTEMPTFIRST&amp;quot;&lt;br /&gt;
      WHEN 4 THEN &amp;quot;ATTEMPTLAST&amp;quot;&lt;br /&gt;
END &amp;quot;grade method&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
, q.attempts &amp;quot;quiz_attempts_allowed&amp;quot;, cm.groupmode &amp;quot;group_mode&amp;quot;&lt;br /&gt;
, qa.id &amp;quot;attempt_id&amp;quot;, qa.state &amp;quot;attempt_state&amp;quot;, qa.sumgrades &amp;quot;attempt_grade&amp;quot;, qg.grade &amp;quot;user_final_grade&amp;quot;, q.grade &amp;quot;quiz_max_grade&amp;quot;&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = q.course AND m.userid = u.id) &amp;quot;user_groups&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timestart), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_start&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timefinish), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_finish&amp;quot;,&lt;br /&gt;
u.id &amp;quot;user_id&amp;quot;, u.firstname, u.lastname,&lt;br /&gt;
question.id &amp;quot;question_id&amp;quot;, question.name &amp;quot;question_name&amp;quot;,&lt;br /&gt;
qas.state &amp;quot;question_step_state&amp;quot;,qas.fraction &amp;quot;question_grade&amp;quot;, qh.hint, question.qtype &amp;quot;question_type&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz as q&lt;br /&gt;
JOIN mdl_course_modules as cm ON cm.instance = q.id and cm.module = 14 &lt;br /&gt;
JOIN mdl_quiz_attempts qa ON q.id = qa.quiz&lt;br /&gt;
LEFT JOIN mdl_quiz_grades as qg ON qg.quiz = q.id and qg.userid = qa.userid&lt;br /&gt;
JOIN mdl_user as u ON u.id = qa.userid&lt;br /&gt;
JOIN mdl_question_usages as qu ON qu.id = qa.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts as qatt ON qatt.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question as question ON question.id = qatt.questionid&lt;br /&gt;
JOIN mdl_question_attempt_steps as qas ON qas.questionattemptid = qatt.id&lt;br /&gt;
LEFT JOIN mdl_question_hints as qh ON qh.questionid = q.id&lt;br /&gt;
#WHERE q.id = &amp;quot;SOME QUIZ ID&amp;quot;&lt;br /&gt;
WHERE cm.course = &amp;quot;SOME COURSE ID&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quiz Usage in Courses by Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Multiple Choice&amp;quot; questions include true/false and matching question types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Short Answer&amp;quot; are questions that accept a single phrase.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Other&amp;quot; questions include fixed numerical, calculated, essay, and various drag and drop types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Min Quiz Age&amp;quot; and &amp;quot;Max Quiz Age&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: In Configurable Reports, the Date Filter is not applied until the &amp;quot;Apply&amp;quot; button is clicked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.shortname AS &#039;Course&#039;&lt;br /&gt;
#, u.lastname AS &#039;Instructor&#039;&lt;br /&gt;
, COUNT(DISTINCT q.id) AS &#039;Quizzes&#039;&lt;br /&gt;
, COUNT(DISTINCT qu.id) AS &#039;Questions&#039;&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 ))  AS &#039;multichoice&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT( qu.id) - SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;Other&#039;&lt;br /&gt;
&lt;br /&gt;
, (SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )))/COUNT( qu.id) AS &#039;Percent MC&#039;&lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;numerical&#039;, 1, 0 )) AS &#039;numerical&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype LIKE &#039;calc%&#039;, 1, 0 )) AS &#039;calculated&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;random&#039;, 1, 0 )) AS &#039;random&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;essay&#039;, 1, 0 )) AS &#039;essay&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, IF(q.shufflequestions &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Questions&#039;&lt;br /&gt;
, IF(q.shuffleanswers &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Answers&#039;&lt;br /&gt;
 &lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
#, FROM_UNIXTIME(MIN(q.timemodified)) AS &#039;Last Modified&#039;&lt;br /&gt;
&lt;br /&gt;
#, DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(MIN(q.timemodified))) AS &#039;Quiz age&#039;&lt;br /&gt;
&lt;br /&gt;
, MIN(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Min Quiz Age&#039; &lt;br /&gt;
, MAX(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Max Quiz Age&#039; &lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified)) &amp;lt; 90, 1,0)) AS &#039;new quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_quiz AS q&lt;br /&gt;
JOIN prefix_course AS c on c.id = q.course&lt;br /&gt;
JOIN prefix_quiz_question_instances AS qqi ON qqi.quiz = q.id&lt;br /&gt;
LEFT JOIN prefix_question AS qu ON qu.id = qqi.question&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%% %%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student responses (answers) to quiz questions===&lt;br /&gt;
(Contributed by Juan F with help from Tim hunt and fellow Moodlers on the forums)&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    concat( u.firstname, &amp;quot; &amp;quot;, u.lastname ) AS &amp;quot;Student Name&amp;quot;,&lt;br /&gt;
    u.id,&lt;br /&gt;
    quiza.userid,&lt;br /&gt;
    q.course,&lt;br /&gt;
    q.name,&lt;br /&gt;
    quiza.attempt,&lt;br /&gt;
    qa.slot,&lt;br /&gt;
    que.questiontext AS &#039;Question&#039;,&lt;br /&gt;
    qa.rightanswer AS &#039;Correct Answer&#039;,&lt;br /&gt;
    qa.responsesummary AS &#039;Student Answer&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz_attempts quiza&lt;br /&gt;
JOIN mdl_quiz q ON q.id=quiza.quiz&lt;br /&gt;
JOIN mdl_question_usages qu ON qu.id = quiza.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts qa ON qa.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question que ON que.id = qa.questionid&lt;br /&gt;
JOIN mdl_user u ON u.id = quiza.userid&lt;br /&gt;
&lt;br /&gt;
WHERE q.name = &amp;quot;BIO 208 Post Test Assessment&amp;quot;&lt;br /&gt;
AND q.course = &amp;quot;17926&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ORDER BY quiza.userid, quiza.attempt, qa.slot&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Questions which are tagged within a course/quiz===&lt;br /&gt;
Calculates subgrades for tags in the each of the quizzes in a course. &lt;br /&gt;
Contributed by Daniel Thies in https://moodle.org/mod/forum/discuss.php?d=324314#p1346542&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
    quiz.name AS quiz,&lt;br /&gt;
    t.rawname AS tag,&lt;br /&gt;
    CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/review.php?attempt=&#039;,&lt;br /&gt;
            MAX(quiza.id),&#039;&amp;quot;&amp;gt;&#039;,u.firstname,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS student,&lt;br /&gt;
    CAST(SUM(qas.fraction) as decimal(12,1)) AS correct,&lt;br /&gt;
    CAST(SUM(qa.maxmark) as decimal(12,1)) AS maximum,&lt;br /&gt;
    CAST(SUM(qas.fraction)/SUM(qa.maxmark)*100 as decimal(4,2)) AS score&lt;br /&gt;
FROM prefix_quiz_attempts quiza&lt;br /&gt;
JOIN prefix_user u ON quiza.userid = u.id&lt;br /&gt;
JOIN prefix_question_usages qu ON qu.id = quiza.uniqueid&lt;br /&gt;
JOIN prefix_question_attempts qa ON qa.questionusageid = qu.id&lt;br /&gt;
JOIN prefix_quiz quiz ON quiz.id = quiza.quiz&lt;br /&gt;
JOIN prefix_tag_instance ti ON qa.questionid = ti.itemid&lt;br /&gt;
JOIN prefix_tag t ON t.id = ti.tagid&lt;br /&gt;
JOIN (SELECT MAX(fraction) AS fraction, questionattemptid&lt;br /&gt;
        FROM prefix_question_attempt_steps&lt;br /&gt;
        GROUP BY questionattemptid) qas ON qas.questionattemptid = qa.id &lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
GROUP BY quiza.userid,&lt;br /&gt;
    quiza.quiz,&lt;br /&gt;
    quiz.name,&lt;br /&gt;
    u.firstname,&lt;br /&gt;
    u.lastname,&lt;br /&gt;
    ti.tagid,&lt;br /&gt;
    t.rawname&lt;br /&gt;
ORDER BY quiza.quiz, t.rawname, u.lastname, u.firstname, score&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==SCORM Activity Reports==&lt;br /&gt;
&lt;br /&gt;
===Lists All completed SCORM activites by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists SCORM status for all enrolled users by Course name===&lt;br /&gt;
This report will list the SCORM status for all users enrolled in the course. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. This can be limited to individual courses by adding to the where clause the course id to report on.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.firstname AS First,&lt;br /&gt;
u.lastname AS Last, &lt;br /&gt;
u.idnumber AS Employee_ID,  &lt;br /&gt;
u.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
u.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course, &lt;br /&gt;
st.attempt AS Attempt,&lt;br /&gt;
st.value AS Status,&lt;br /&gt;
FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) AS Date &lt;br /&gt;
&lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
&lt;br /&gt;
WHERE st.element=&#039;cmi.core.lesson_status&#039; AND m.userid=u.id&lt;br /&gt;
&lt;br /&gt;
UNION&lt;br /&gt;
&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS First,&lt;br /&gt;
user2.lastname AS Last,&lt;br /&gt;
user2. idnumber AS Employee_ID,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
user2.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Attempt,&lt;br /&gt;
&amp;quot;not_started&amp;quot; AS Status,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Date&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = user2.id &lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.course=c.id&lt;br /&gt;
Left Join prefix_scorm_scoes_track AS st on st.scormid=sc.id AND st.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
WHERE  st.timemodified IS NULL AND m.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY  Course, Last, First, Attempt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Badges==&lt;br /&gt;
&lt;br /&gt;
=== All badges issued, by User ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, b.name AS badgename, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN&lt;br /&gt;
(SELECT c.shortname&lt;br /&gt;
    FROM prefix_course AS c&lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Context,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 1 THEN &amp;quot;Activity Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 2 THEN &amp;quot;Activity Completion (Any)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 2 AND t.method = 2 THEN &amp;quot;Manual Award&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 1 THEN &amp;quot;Course Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 2 THEN &amp;quot;Course Completion (Any)&amp;quot;&lt;br /&gt;
  ELSE CONCAT (&#039;Other: &#039;, t.criteriatype)&lt;br /&gt;
END AS Criteriatype,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateissued ) , &#039;%Y-%m-%d&#039; ) AS dateissued,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateexpire ), &#039;%Y-%m-%d&#039; ) AS dateexpires,&lt;br /&gt;
CONCAT (&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/badge.php?hash=&#039;,d.uniquehash,&#039;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&#039;) AS Details&lt;br /&gt;
FROM prefix_badge_issued AS d &lt;br /&gt;
JOIN prefix_badge AS b ON d.badgeid = b.id&lt;br /&gt;
JOIN prefix_user AS u ON d.userid = u.id&lt;br /&gt;
JOIN prefix_badge_criteria AS t on b.id = t.badgeid &lt;br /&gt;
WHERE t.criteriatype &amp;lt;&amp;gt; 0&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&lt;br /&gt;
=== All badges available in the system, with Earned count ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.type = 1 THEN &amp;quot;System&amp;quot;&lt;br /&gt;
WHEN b.type = 2 THEN &amp;quot;Course&amp;quot;&lt;br /&gt;
END AS Context, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN &lt;br /&gt;
(SELECT c.shortname &lt;br /&gt;
    FROM prefix_course AS c &lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 2 THEN &amp;quot;No&amp;quot;&lt;br /&gt;
WHEN b.status = 1 OR b.status = 3 THEN &amp;quot;Yes&amp;quot;&lt;br /&gt;
WHEN b.status = 4 THEN &amp;quot;x&amp;quot;&lt;br /&gt;
END AS Available,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 1 THEN &amp;quot;0&amp;quot;&lt;br /&gt;
WHEN b.status = 2 OR b.status = 3 OR b.status = 4 THEN &lt;br /&gt;
 (SELECT COUNT(*) &lt;br /&gt;
   FROM prefix_badge_issued AS d&lt;br /&gt;
   WHERE d.badgeid = b.id&lt;br /&gt;
 )&lt;br /&gt;
END AS Earned&lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Badges Leaderboard ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A simple list of usernames and how many badges they have earned overall.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, (SELECT COUNT(*) FROM prefix_badge_issued AS d WHERE d.userid = u.id) AS earned&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
ORDER BY earned DESC, u.username ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Manage badges (System &amp;amp; Course) ===&lt;br /&gt;
&lt;br /&gt;
List system wide badges, course and system level badges + a link to relevant &amp;quot;manage badges&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description &lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN b.type = 1 THEN &#039;System&#039;&lt;br /&gt;
  WHEN b.type = 2 THEN &#039;Course&#039;&lt;br /&gt;
END AS Level&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/index.php?type=&#039;, b.type, &#039;&amp;amp;id=&#039;,&lt;br /&gt;
			  c.id, &#039;&amp;quot;&amp;gt;Manage badges in: &#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Manage &lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Administrator Reports==&lt;br /&gt;
&lt;br /&gt;
===Config changes in Export friendly form===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( g.timemodified ) , &#039;%Y-%m-%d&#039; ) AS date, &lt;br /&gt;
u.username AS user, &lt;br /&gt;
g.name AS setting, &lt;br /&gt;
CASE &lt;br /&gt;
 WHEN g.plugin IS NULL THEN &amp;quot;core&amp;quot;&lt;br /&gt;
 ELSE g.plugin&lt;br /&gt;
END AS plugin, &lt;br /&gt;
g.value AS new_value, &lt;br /&gt;
g.oldvalue AS original_value&lt;br /&gt;
FROM prefix_config_log  AS g&lt;br /&gt;
JOIN prefix_user AS u ON g.userid = u.id&lt;br /&gt;
ORDER BY date DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts by user===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
How to get a list of all users and which cohorts they belong to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, h.idnumber, h.name&lt;br /&gt;
FROM prefix_cohort AS h&lt;br /&gt;
JOIN prefix_cohort_members AS hm ON h.id = hm.cohortid&lt;br /&gt;
JOIN prefix_user AS u ON hm.userid = u.id&lt;br /&gt;
ORDER BY u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts with Courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all cohorts with name, id, visibility, and which courses they are enrolled in.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
# h.id,&lt;br /&gt;
# e.customint1,&lt;br /&gt;
h.name AS Cohort,&lt;br /&gt;
h.idnumber AS Cohortid,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN h.visible = 1 THEN &#039;Yes&#039;&lt;br /&gt;
 ELSE &#039;-&#039;&lt;br /&gt;
END AS Cohortvisible,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;, CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_cohort h&lt;br /&gt;
JOIN prefix_enrol e ON h.id = e.customint1&lt;br /&gt;
JOIN prefix_course c ON c.id = e.courseid %%FILTER_COURSES:e.courseid%% &lt;br /&gt;
WHERE e.enrol = &#039;cohort&#039; AND e.roleid = 5&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses created And Active courses by Year===&lt;br /&gt;
Active courses is counting course that have at least one Hit, And &amp;quot;Active_MoreThan100Hits&amp;quot; counts courses that have at least 100 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `timecreated` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT course ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY course &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 100) AS courses_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( courses_log.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan100Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_course` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users created And Active users by Year===&lt;br /&gt;
Active users is counting users that have at least one Hit, And &amp;quot;Active_MoreThan500Hits&amp;quot; counts users that have at least 500 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `firstaccess` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT userid ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY userid &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 500) AS users_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( users_log.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan500Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Aggregation Report===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In particular, be on the lookout for any courses with the following combinations of parameters, which are known to cause changes in calculations:&lt;br /&gt;
&lt;br /&gt;
# mean of grades set with aggregate with subcategory.&lt;br /&gt;
# Simple weighted mean of grades with aggregate with sub category and drop the lowest&lt;br /&gt;
# Sum of grades drop the lowest&lt;br /&gt;
&lt;br /&gt;
Also review:&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48618&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48634&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-49257&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50089&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50062&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
COUNT(c.shortname) AS &#039;Count of Courses&#039;&lt;br /&gt;
&lt;br /&gt;
# If you want to display all the courses for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, c.shortname AS &#039;course name&#039;&lt;br /&gt;
&lt;br /&gt;
# If you need to display grade categories for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, gc.fullname AS &#039;grade category name&#039;&lt;br /&gt;
&lt;br /&gt;
, gc.aggregation AS &#039;aggregation method&#039;&lt;br /&gt;
&lt;br /&gt;
#These aggregation text strings appear to be hard-coded. I couldn&#039;t find a table for them. If you have aggregation types I haven&#039;t included here, they&#039;ll be blank in your report results.&lt;br /&gt;
, CASE gc.aggregation&lt;br /&gt;
  WHEN 0 THEN &#039;Mean of Grades&#039;&lt;br /&gt;
  WHEN 2 THEN &#039;Median of Grades&#039;&lt;br /&gt;
  WHEN 6 THEN &#039;Highest Grade&#039;&lt;br /&gt;
  WHEN 8 THEN &#039;Mode of Grades&#039;&lt;br /&gt;
  WHEN 10 THEN &#039;Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 11 THEN &#039;Simple Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 12 THEN &#039;Mean of Grades (with extra credits)&#039;&lt;br /&gt;
  WHEN 13 THEN &#039;Sum of Grades&#039;&lt;br /&gt;
END AS &#039;aggregation name&#039;&lt;br /&gt;
&lt;br /&gt;
# Note that gc.aggregatesubcats column is eliminated in 2.8 and later per MDL-47503, so comment that line on updated systems or you&#039;ll get an error&lt;br /&gt;
, gc.keephigh AS &#039;keep high&#039;&lt;br /&gt;
, gc.droplow AS &#039;dr0p low&#039;&lt;br /&gt;
, gc.aggregateonlygraded AS &#039;Aggregate only graded&#039;&lt;br /&gt;
, gc.aggregateoutcomes AS &#039;aggregate outcomes&#039;&lt;br /&gt;
, gc.aggregatesubcats AS &#039;aggregate subcategories&#039;&lt;br /&gt;
&lt;br /&gt;
# If you are displaying data about individual courses, you may want to know how old they are&lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;course start date&#039;&lt;br /&gt;
&lt;br /&gt;
# 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&#039;ll need to uncomment the necessary JOINs below&lt;br /&gt;
#, gi.itemname AS &#039;grade item&#039;&lt;br /&gt;
#, gg.finalgrade AS &#039;final grade&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
&lt;br /&gt;
prefix_course AS c&lt;br /&gt;
JOIN prefix_grade_categories AS gc ON gc.courseid = c.id&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id #AND gi.categoryid=gc.id&lt;br /&gt;
#LEFT JOIN prefix_grade_grades AS gg ON gg.itemid = gi.id AND gg.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
#AND gc.aggregation = 13 #only the dreaded Sum of Grades aggregations&lt;br /&gt;
#AND gc.depth = 1 # if for some reason you only want course aggregations, not subcategories&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.aggregation, gc.keephigh, gc.droplow, gc.aggregateonlygraded, gc.aggregateoutcomes, gc.aggregatesubcats&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running Cron jobs (task_scheduled) ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT classname&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(lastruntime), &#039;%H:%i [%d]&#039;) AS &#039;last&#039;&lt;br /&gt;
  ,DATE_FORMAT(now(), &#039;%H:%i&#039;) AS &#039;now&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(nextruntime), &#039;%H:%i [%d]&#039;) AS &#039;next&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP()-nextruntime), &#039;%i&#039;) AS &#039;next in min&#039;&lt;br /&gt;
FROM mdl_task_scheduled&lt;br /&gt;
WHERE now() &amp;gt; FROM_UNIXTIME(nextruntime)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Flat file enrollments waiting for processing ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
This lists all enrolments uploaded by the [[Flat_file|Flat file enrolment method]] that are currently waiting to be processed. When the optional enrolment start date is set for a user in the file, and this start date is in the future, the enrolment information is held in the database until the time for the actual enrolment to start at which time the user is actually enroled. This report allows you to see any and all such enrolments that are waiting to be done. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.username,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
ef.action,&lt;br /&gt;
r.shortname AS &amp;quot;Role&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(ef.timestart),&#039;%Y-%m-%d %H:%i&#039;)  AS &amp;quot;Enrolment Start&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(ef.timeend),&#039;%Y-%m-%d %H:%i&#039;)  AS &amp;quot;Enrolment End&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(ef.timemodified),&#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;Uploaded Date&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_enrol_flatfile ef&lt;br /&gt;
JOIN prefix_user u ON u.id = ef.userid&lt;br /&gt;
JOIN prefix_course c ON c.id = ef.courseid&lt;br /&gt;
JOIN prefix_role r ON r.id = ef.roleid&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== All Meta courses with Parent and Child course relationships ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
This shows the list of courses with Meta course link enrollments in them (&#039;Parent course&#039;), and the courses which are connected to them to provide enrollments (&#039;Child courses&#039;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.fullname AS &#039;Parent course name&#039;,&lt;br /&gt;
c.shortname AS &#039;Parent course shortname&#039;,&lt;br /&gt;
en.courseid AS &#039;Parent course id&#039;,&lt;br /&gt;
(SELECT fullname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course name&#039;,&lt;br /&gt;
(SELECT shortname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course shortname&#039;,&lt;br /&gt;
en.customint1 AS &#039;Child course id&#039;&lt;br /&gt;
FROM prefix_enrol en&lt;br /&gt;
JOIN prefix_course c ON c.id = en.courseid&lt;br /&gt;
WHERE en.enrol = &#039;meta&#039;&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== All Private Files by User ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Lists all files by all users in the Private Files repository, with the file path location and name in the moodledata/filedir directory structure, and time created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.username, &lt;br /&gt;
f.filename, &lt;br /&gt;
CONCAT(&#039;/&#039;, LEFT(f.contenthash,2), &#039;/&#039;, MID(f.contenthash,3,2), &#039;/&#039;, f.contenthash) AS &amp;quot;Filedir_Location&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(f.timecreated),&#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;Created&amp;quot;&lt;br /&gt;
FROM prefix_files f &lt;br /&gt;
JOIN prefix_user u ON u.id = f.userid&lt;br /&gt;
WHERE f.component = &#039;user&#039; &lt;br /&gt;
AND f.filearea = &#039;private&#039; &lt;br /&gt;
AND f.filesize &amp;gt; 0 &lt;br /&gt;
ORDER BY u.username, f.filename&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== All Tags in use in Courses and Activities ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Shows all tags that are in use in Courses and in Activities. Shows the tag name, which course it is used in, whether it is a course level tag or an activity level tag, along with handy links to the course and activity. If it is an tag in an activity, it shows the activity type and its name. Also shows you if the tag is a Standard tag or not in the system, and if not, which user created the tag. &lt;br /&gt;
&lt;br /&gt;
Note: this version includes the new H5P core activity in its list of modules.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
t.name AS &amp;quot;Tag&amp;quot;,&lt;br /&gt;
CASE ti.itemtype&lt;br /&gt;
  WHEN &#039;course&#039; THEN &#039;Course&#039;&lt;br /&gt;
  ELSE &amp;quot;Activity&amp;quot;&lt;br /&gt;
END AS &amp;quot;Tag_Type&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
# get the course name&lt;br /&gt;
CASE ti.itemtype&lt;br /&gt;
  WHEN &#039;course&#039; THEN &lt;br /&gt;
   (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,id,&#039;&amp;quot;&amp;gt;&#039;,shortname,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_course WHERE id = ti.itemid)&lt;br /&gt;
  ELSE &lt;br /&gt;
   (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,id,&#039;&amp;quot;&amp;gt;&#039;,shortname,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_course WHERE id = cm.course)&lt;br /&gt;
END AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
# get the activity type&lt;br /&gt;
CASE ti.itemtype&lt;br /&gt;
  WHEN &#039;course&#039; THEN &#039;-&#039;&lt;br /&gt;
  ELSE &lt;br /&gt;
     # (SELECT CONCAT(name, &#039; (&#039;,cm.module,&#039;)&#039;) FROM prefix_modules WHERE id = cm.module)&lt;br /&gt;
	 m.name&lt;br /&gt;
END AS &amp;quot;Activity_Type&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
# get the activity name&lt;br /&gt;
CASE ti.itemtype&lt;br /&gt;
  WHEN &#039;course&#039; THEN &#039;-&#039;&lt;br /&gt;
  ELSE &lt;br /&gt;
    CASE&lt;br /&gt;
    WHEN m.name = &#039;assign&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_assign WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;assignment&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_assignment WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;book&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_book WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;chat&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_chat WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;choice&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_choice WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;data&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_data WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;feedback&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_feedback WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;folder&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_folder WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;forum&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_forum  WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;glossary&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_glossary WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;h5pactivity&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_h5pactivity WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;imscp&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_imscp WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;label&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_label WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;lesson&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_lesson WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;lti&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_lti WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;page&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_page WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;quiz&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_quiz WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;resource&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_resource WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;scorm&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_scorm WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;survey&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_survey WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;url&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_url WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;wiki&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_wiki WHERE id = cm.instance)&lt;br /&gt;
     WHEN m.name = &#039;workshop&#039; THEN (SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%//mod/&#039;,m.name,&#039;/view.php&#039;,CHAR(63),&#039;id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,name,&#039;&amp;lt;/a&amp;gt;&#039;) FROM prefix_workshop WHERE id = cm.instance)&lt;br /&gt;
     # add any others you have installed here with their id number&lt;br /&gt;
     ELSE CONCAT(&amp;quot;Unknown_mod_id: &amp;quot;, cm.module)&lt;br /&gt;
     END&lt;br /&gt;
END AS &amp;quot;Activity_name&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
# get tag standard &lt;br /&gt;
CASE t.isstandard&lt;br /&gt;
  WHEN 1 THEN &#039;Yes&#039;&lt;br /&gt;
  ELSE CONCAT(&#039;No (&#039;, (SELECT username FROM prefix_user WHERE id = t.userid),&#039;)&#039;)&lt;br /&gt;
END AS &amp;quot;Standard&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_tag_instance ti&lt;br /&gt;
JOIN prefix_tag t ON t.id = ti.tagid&lt;br /&gt;
JOIN prefix_tag_coll tc ON tc.id = t.tagcollid&lt;br /&gt;
JOIN prefix_course_modules cm ON cm.id = ti.itemid&lt;br /&gt;
JOIN prefix_modules m ON m.id = cm.module&lt;br /&gt;
&lt;br /&gt;
WHERE ti.component = &#039;core&#039; &lt;br /&gt;
AND (ti.itemtype = &#039;course&#039; OR ti.itemtype = &#039;course_modules&#039;) &lt;br /&gt;
&lt;br /&gt;
ORDER BY 1,2,3,4,5&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Learning Analytics Reports ==&lt;br /&gt;
(Moodle v. 3.4 and later)&lt;br /&gt;
&lt;br /&gt;
=== Learning Analytics Model Summary ===&lt;br /&gt;
This report provides a list of the learning analytics models on your site, whether enabled or not, and several details about them.&lt;br /&gt;
&lt;br /&gt;
(Note: this report was created on a system using PostgreSQL. Some changes may be needed for other forms of SQL.)&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
am.id AS &amp;quot;model id&amp;quot;,	 &lt;br /&gt;
split_part(am.target,&#039;\&#039;,5) AS &amp;quot;target&amp;quot;,&lt;br /&gt;
CASE WHEN am.enabled=1 THEN &#039;YES&#039; ELSE &#039;NO&#039; END AS &amp;quot;enabled&amp;quot;,	 &lt;br /&gt;
CASE WHEN am.trained=1 THEN &#039;YES&#039; ELSE &#039;NO&#039; END AS &amp;quot;trained&amp;quot;,&lt;br /&gt;
am.name,	 &lt;br /&gt;
/* indicators,*/&lt;br /&gt;
char_length(am.indicators) - char_length(REPLACE(am.indicators,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;indicator count&amp;quot;,&lt;br /&gt;
split_part(am.timesplitting,&#039;\&#039;,5) AS &amp;quot;interval&amp;quot;,&lt;br /&gt;
/*&lt;br /&gt;
to_timestamp(am.version) AS &amp;quot;version&amp;quot;,	 &lt;br /&gt;
to_timestamp(am.timecreated) AS &amp;quot;time created&amp;quot;,	 &lt;br /&gt;
to_timestamp(am.timemodified) AS &amp;quot;time modified&amp;quot;,	&lt;br /&gt;
*/&lt;br /&gt;
COUNT(DISTINCT ap.contextid) AS &amp;quot;contexts&amp;quot;,&lt;br /&gt;
COUNT(ap.sampleid) AS &amp;quot;samples&amp;quot;,&lt;br /&gt;
/* AVG(ap.prediction) AS &amp;quot;avg prediction&amp;quot;, */&lt;br /&gt;
ROUND(ap.prediction,1) AS &amp;quot;prediction&amp;quot;,		   &lt;br /&gt;
ROUND(AVG(aml.score),3) AS &amp;quot;model accuracy (avg)&amp;quot;,&lt;br /&gt;
apa.actionname AS &amp;quot;action&amp;quot;,&lt;br /&gt;
COUNT(apa.id) AS &amp;quot;number actions taken&amp;quot;&lt;br /&gt;
		   &lt;br /&gt;
FROM prefix_analytics_models AS am&lt;br /&gt;
JOIN prefix_analytics_predictions AS ap ON am.id = ap.modelid&lt;br /&gt;
LEFT JOIN prefix_analytics_models_log AS aml ON aml.modelid = am.id&lt;br /&gt;
LEFT JOIN prefix_analytics_prediction_actions AS apa ON apa.predictionid = ap.id&lt;br /&gt;
GROUP BY am.id, ap.prediction, apa.actionname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Indicator Calculations ===&lt;br /&gt;
Pulls calculations from the &amp;quot;analytics_indicator_calc&amp;quot; table consisting of all calculations made for each indicator for each sample within each context for every model. In most cases you will want to limit this per context or sample, or at least group by context and sample.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id,	 &lt;br /&gt;
to_timestamp(starttime) AS &amp;quot;start time&amp;quot;,	 &lt;br /&gt;
to_timestamp(endtime) AS &amp;quot;end time&amp;quot;,	 &lt;br /&gt;
contextid,	 &lt;br /&gt;
sampleorigin,	 &lt;br /&gt;
sampleid,	 &lt;br /&gt;
/*indicator, */&lt;br /&gt;
split_part(indicator,&#039;\&#039;,2) AS &amp;quot;module&amp;quot;,&lt;br /&gt;
split_part(indicator,&#039;\&#039;,5) AS &amp;quot;indicator type&amp;quot;,&lt;br /&gt;
value,	 &lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_indicator_calc&lt;br /&gt;
WHERE id = 1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Analytics Models ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_models&amp;quot; table consisting of one row per model. See the &amp;quot;Learning Analytics Model Summary&amp;quot; report, above, for an expanded report that JOINs model data from different tables to provide a more comprehensive view.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
id,	 &lt;br /&gt;
enabled,	 &lt;br /&gt;
trained, &lt;br /&gt;
name,	 &lt;br /&gt;
split_part(target,&#039;\&#039;,5) AS &amp;quot;target&amp;quot;,&lt;br /&gt;
/* indicators,*/&lt;br /&gt;
char_length(indicators) - char_length(REPLACE(indicators,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;indicator count&amp;quot;,&lt;br /&gt;
split_part(timesplitting,&#039;\&#039;,5) AS &amp;quot;interval&amp;quot;,&lt;br /&gt;
predictionsprocessor, &lt;br /&gt;
to_timestamp(version) AS &amp;quot;version&amp;quot;,	 &lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;,	 &lt;br /&gt;
to_timestamp(timemodified) AS &amp;quot;time modified&amp;quot;,	 &lt;br /&gt;
usermodified&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_models&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Analytics Models Log ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_models_log&amp;quot; table consisting of evaluation calculations per model. If model evaluations have not been manually executed on the system from the command line, there will be no contents in this table.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
id,	 &lt;br /&gt;
modelid,	 &lt;br /&gt;
to_timestamp(version) AS &amp;quot;version&amp;quot;,	 &lt;br /&gt;
evaluationmode,	 &lt;br /&gt;
split_part(target,&#039;\&#039;,5) AS &amp;quot;target&amp;quot;,	 &lt;br /&gt;
/* indicators,*/&lt;br /&gt;
char_length(indicators) - char_length(REPLACE(indicators,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;indicator count&amp;quot;,&lt;br /&gt;
split_part(timesplitting,&#039;\&#039;,5) AS &amp;quot;interval&amp;quot;,	 &lt;br /&gt;
score,	 &lt;br /&gt;
info,	 &lt;br /&gt;
dir,	 &lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;,	 &lt;br /&gt;
usermodified&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_models_log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Predictions ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_predictions&amp;quot; table consisting of one row per prediction per model. Counts the number of indicators calculated for each prediction, but does not list them. If a model has not yet been trained, the system cannot make predictions and this table will not include rows for that model ID. See the &amp;quot;Learning Analytics Model Summary&amp;quot; report, above, for an expanded report that JOINs model data from different tables to provide a more comprehensive view.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id,	 &lt;br /&gt;
modelid,	 &lt;br /&gt;
contextid,	 &lt;br /&gt;
sampleid,	 &lt;br /&gt;
rangeindex,	 &lt;br /&gt;
prediction,	 &lt;br /&gt;
predictionscore,	 &lt;br /&gt;
char_length(calculations) - char_length(REPLACE(calculations,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;indicators calculated&amp;quot;,&lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;,	 &lt;br /&gt;
to_timestamp(timestart) AS &amp;quot;time start&amp;quot;,	 &lt;br /&gt;
to_timestamp(timeend) AS &amp;quot;time end&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from prefix_analytics_predictions&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Prediction Actions ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_prediction_actions&amp;quot; table consisting of one row per action taken per prediction (e.g. a teacher viewing the outline report for a student at risk). If the model has not yet made predictions, there can be no prediction actions. See the &amp;quot;Learning Analytics Model Summary&amp;quot; report, above, for an expanded report that JOINs model data from different tables to provide a more comprehensive view.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
id,	 &lt;br /&gt;
predictionid,	 &lt;br /&gt;
userid,	 &lt;br /&gt;
actionname,	 &lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_prediction_actions&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Analytics Predictions with All Indicators ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_predictions&amp;quot; table consisting of one row per prediction per model. Lists the indicators calculated for each prediction. If a model has not yet been trained, the system cannot make predictions and this table will not include rows for that model ID.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id AS &amp;quot;Prediction ID&amp;quot;,	 &lt;br /&gt;
modelid AS &amp;quot;Model ID&amp;quot;,	 &lt;br /&gt;
contextid AS &amp;quot;Context ID&amp;quot;,	 &lt;br /&gt;
sampleid AS &amp;quot;Sample ID&amp;quot;,	 &lt;br /&gt;
rangeindex AS &amp;quot;Analysis Interval&amp;quot;,	 &lt;br /&gt;
prediction AS &amp;quot;Prediction value&amp;quot;,	 &lt;br /&gt;
predictionscore,	 &lt;br /&gt;
calculations,&lt;br /&gt;
char_length(calculations) - char_length(REPLACE(calculations,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;indicators calculated&amp;quot;,&lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;,	 &lt;br /&gt;
to_timestamp(timestart) AS &amp;quot;time start&amp;quot;,	 &lt;br /&gt;
to_timestamp(timeend) AS &amp;quot;time end&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from prefix_analytics_predictions&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Predict Samples ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_predict_samples&amp;quot; table consisting of one row per analysis interval per model, with a count of the samples used for each prediction. Sample details are not included here, but the report can be modified to list samples by IDs if needed by parsing the contents of the sampleids field. For example, this counts the number of student enrolments for which the system has generated predictions for a given model and analysis interval.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id,	 &lt;br /&gt;
modelid,	 &lt;br /&gt;
analysableid,	 &lt;br /&gt;
split_part(timesplitting,&#039;\&#039;,5) AS &amp;quot;interval&amp;quot;,	 &lt;br /&gt;
rangeindex,	 &lt;br /&gt;
/* sampleids, */	 &lt;br /&gt;
char_length(sampleids) - char_length(REPLACE(sampleids,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;samples used&amp;quot;,&lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;,	 &lt;br /&gt;
to_timestamp(timemodified) AS &amp;quot;time modified&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_predict_samples&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Train Samples ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_train_samples&amp;quot; table consisting of one row per analysis interval per model, with a count of the samples used for each training calculation. &lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id,	 &lt;br /&gt;
modelid,	 &lt;br /&gt;
analysableid,	 &lt;br /&gt;
split_part(timesplitting,&#039;\&#039;,5) AS &amp;quot;interval&amp;quot;,&lt;br /&gt;
/* sampleids,	*/&lt;br /&gt;
char_length(sampleids) - char_length(REPLACE(sampleids,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;samples used&amp;quot;,&lt;br /&gt;
to_timestamp(timecreated) AS &amp;quot;time created&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_train_samples&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Used Analysables ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_used_analysables&amp;quot; table consisting of one row per context per model, noting whether the analysable was used to train the model or to make a prediction. This data is used to control the training and prediction processes.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id,	 &lt;br /&gt;
modelid,	 &lt;br /&gt;
action,	 &lt;br /&gt;
analysableid,	 &lt;br /&gt;
to_timestamp(firstanalysis) AS &amp;quot;first analysis&amp;quot;,	 &lt;br /&gt;
to_timestamp(timeanalysed) AS &amp;quot;time analysed&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_used_analysables&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analytics Used Files ===&lt;br /&gt;
Pulls data from the &amp;quot;analytics_used_files&amp;quot; table consisting of one row per file per model, noting whether the file was used to train the model or to make a prediction. This data is used to control the training and prediction processes.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
id,	 &lt;br /&gt;
modelid,	 &lt;br /&gt;
fileid,	 &lt;br /&gt;
action,	 &lt;br /&gt;
TO_TIMESTAMP(time) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_used_files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Average Cognitive Depth and Social Breadth===&lt;br /&gt;
&lt;br /&gt;
Here is a simple SQL snippet to calculate average cognitive depth and social breadth indicators for all students in the system. This one ignores  indicator values of 0, as they are nulls as defined in this model.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
i.contextid,&lt;br /&gt;
i.sampleid,&lt;br /&gt;
&lt;br /&gt;
TRUNC(AVG(CASE&lt;br /&gt;
WHEN i.indicator LIKE &#039;%cognitive%&#039; THEN i.value &lt;br /&gt;
ELSE &#039;0&#039;&lt;br /&gt;
END),2) AS &amp;quot;Average Cognitive Depth&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
TRUNC(AVG(CASE&lt;br /&gt;
WHEN i.indicator LIKE &#039;%social%&#039; THEN i.value &lt;br /&gt;
ELSE &#039;0&#039;&lt;br /&gt;
END),2) AS &amp;quot;Average Social Breadth&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_indicator_calc as i&lt;br /&gt;
WHERE&lt;br /&gt;
i.value != 0&lt;br /&gt;
GROUP BY i.contextid, i.sampleid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Competencies==&lt;br /&gt;
&lt;br /&gt;
===List of competencies from a framework and the courses including them===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
f.shortname AS &#039;Framework&#039;,&lt;br /&gt;
comp.shortname AS &#039;Competency&#039;, &lt;br /&gt;
cccomp.courseid AS &#039;Course id&#039;, &lt;br /&gt;
c.fullname AS &#039;Course name&#039;,&lt;br /&gt;
c.shortname AS &#039;Course code&#039;&lt;br /&gt;
FROM &lt;br /&gt;
prefix_competency_coursecomp AS cccomp &lt;br /&gt;
INNER JOIN prefix_competency AS comp ON cccomp.competencyid = comp.id&lt;br /&gt;
INNER JOIN prefix_course AS c ON cccomp.courseid = c.id&lt;br /&gt;
INNER JOIN prefix_competency_framework AS f ON comp.competencyframeworkid = f.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Count the courses using each competency from frameworks===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is not a filter by competency framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
f.shortname AS framework,&lt;br /&gt;
comp.shortname AS &#039;Competency&#039;,&lt;br /&gt;
COUNT(cccomp.competencyid) AS &#039;nb course&#039;&lt;br /&gt;
FROM prefix_competency AS comp&lt;br /&gt;
INNER JOIN prefix_competency_framework AS f ON comp.competencyframeworkid = f.id&lt;br /&gt;
LEFT JOIN prefix_competency_coursecomp AS cccomp ON cccomp.competencyid = comp.id&lt;br /&gt;
GROUP BY comp.id, comp.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Scale details with ids ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Competency import and export files include scales with id numbers. However, the management page in Grades &amp;gt; Scales does not have the scale id, nor other useful details that scales store about themselves, like who made them and when, and what context they pertain to. This simple query shows you that information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
s.id AS Scaleid,&lt;br /&gt;
s.name AS Scale_Name,&lt;br /&gt;
s.scale AS Scale,&lt;br /&gt;
CASE  &lt;br /&gt;
  WHEN s.courseid = 0 THEN &#039;System&#039;&lt;br /&gt;
  ELSE (SELECT shortname FROM prefix_course WHERE id = s.courseid)&lt;br /&gt;
END AS Context,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN s.userid = 0 THEN &#039;System&#039;&lt;br /&gt;
  ELSE (SELECT username FROM prefix_user WHERE id = s.userid)&lt;br /&gt;
END AS User,&lt;br /&gt;
s.description,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(s.timemodified), &#039;%Y-%m-%d %H:%i&#039; ) AS &#039;Modified&#039;&lt;br /&gt;
FROM prefix_scale s&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syllabus==&lt;br /&gt;
&lt;br /&gt;
Our school simply asks teachers to drop a file (resource) on their course page&lt;br /&gt;
and rename this resource (not the file) starting with &amp;quot;syllabus&amp;quot; (case insensitive)&lt;br /&gt;
&lt;br /&gt;
===Count the number of resources whose name starts by &amp;quot;Syllabus&amp;quot;===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
Select &lt;br /&gt;
r.name As &#039;Resource name&#039;,&lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a href=&amp;quot;%%WWWROOT%%/pluginfile.php/&#039;, ct.id, &#039;/mod_resource/content/1/&#039;, f.filename, &#039;&amp;quot;&amp;gt;&#039;,f.filename,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Clickable filename&#039;,&lt;br /&gt;
&lt;br /&gt;
c.fullname AS &#039;Course name&#039;,&lt;br /&gt;
c.shortname AS &#039;Course shortname&#039;,&lt;br /&gt;
&lt;br /&gt;
# the date filters are connected to this &amp;quot;last modif&amp;quot; field&lt;br /&gt;
# userful to check if the syllabus has been updated this year&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(f.timemodified), &#039;%e %b %Y&#039;) AS &#039;last modif&#039;, &lt;br /&gt;
&lt;br /&gt;
# tell if the file is visible by the students or hidden&lt;br /&gt;
IF(cm.visible=0,&amp;quot;masqué&amp;quot;,&amp;quot;visible&amp;quot;) AS &#039;Visibility&#039;,&lt;br /&gt;
&lt;br /&gt;
# next line tries to give the real path (local path) if you want to create a zip file using an external script)&lt;br /&gt;
# notice that the path is in the column &amp;quot;contenthash&amp;quot; and NOT in the column pathhash&lt;br /&gt;
# if the contenthash starts with 9af3... then the file is stored in moodledata/filedir/9a/f3/contenthash&lt;br /&gt;
# I try to get the path to moodledata from the value of the geoip variable in the mdl_config table... maybe a bad idea&lt;br /&gt;
CONCAT(&#039;&amp;quot;&#039;,(Select left(value, length(value)-25) from prefix_config where name =&amp;quot;geoip2file&amp;quot;),&#039;/filedir/&#039;, left(f.contenthash,2), &amp;quot;/&amp;quot;,substring(f.contenthash,3,2),&#039;/&#039;, f.contenthash, &#039;&amp;quot;&#039;) AS &#039;link&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
INNER JOIN prefix_course_modules AS cm ON cm.instance = r.id&lt;br /&gt;
INNER JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
INNER JOIN prefix_context AS ct ON ct.instanceid = cm.id&lt;br /&gt;
JOIN prefix_course_categories cc ON c.category = cc.id&lt;br /&gt;
INNER JOIN prefix_files AS f ON f.contextid = ct.id AND f.mimetype IS NOT NULL AND f.component = &#039;mod_resource&#039;&lt;br /&gt;
WHERE LOWER( r.name) LIKE &#039;syllabus%&#039;&lt;br /&gt;
%%FILTER_STARTTIME:f.timemodified:&amp;gt;%% %%FILTER_ENDTIME:f.timemodified:&amp;lt;%%&lt;br /&gt;
%%FILTER_SUBCATEGORIES:cc.path%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List files which have been tagged &amp;quot;Syllabus&amp;quot;===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
Select &lt;br /&gt;
t.rawname AS &#039;rawtag&#039;,&lt;br /&gt;
c.shortname AS &#039;Cours shortname&#039;,&lt;br /&gt;
c.fullname AS &#039;Course name&#039;,&lt;br /&gt;
r.name As &#039;Resource name&#039;,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a href=&amp;quot;%%WWWROOT%%/pluginfile.php/&#039;, ti.contextid, &#039;/mod_resource/content/1/&#039;, f.filename, &#039;&amp;quot;&amp;gt;cliquez ici&amp;lt;/a&amp;gt;&#039;) AS &#039;link&#039;,&lt;br /&gt;
ti.contextid AS &#039;Instance for link&#039;,&lt;br /&gt;
f.id AS &#039;file id&#039; &lt;br /&gt;
FROM prefix_tag_instance AS ti&lt;br /&gt;
INNER JOIN prefix_tag AS t ON ti.tagid = t.id&lt;br /&gt;
INNER JOIN prefix_course_modules AS cm ON ti.itemid = cm.id&lt;br /&gt;
INNER JOIN prefix_course AS c ON cm.course = c.id&lt;br /&gt;
INNER JOIN prefix_resource AS r ON r.id = cm.instance&lt;br /&gt;
INNER JOIN prefix_files AS f ON f.contextid = ti.contextid AND f.mimetype IS NOT NULL&lt;br /&gt;
WHERE t.rawname = &#039;Syllabus&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of courses WITHOUT a resource with a name starting by &amp;quot;syllabus&amp;quot;===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select c.id, c.shortname,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;, c.id, &#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Course link&#039;&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
  Select r.course &lt;br /&gt;
  from prefix_resource AS r&lt;br /&gt;
  WHERE LOWER( r.name) LIKE &#039;syllabus%&#039;&lt;br /&gt;
  GROUP BY r.course) AS r ON r.course = c.id&lt;br /&gt;
INNER JOIN prefix_course_categories cc ON c.category = cc.id&lt;br /&gt;
WHERE r.course IS NULL &lt;br /&gt;
%%FILTER_SUBCATEGORIES:cc.path%%&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%% %%FILTER_ENDTIME:c.enddate:&amp;lt;%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of courses have MULTIPLE resource with a name like &amp;quot;Syllabus%&amp;quot;===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
r.course,&lt;br /&gt;
c.shortname,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;, r.id, &#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Course link&#039;&lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
INNER JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories cc ON c.category = cc.id&lt;br /&gt;
WHERE LOWER( r.name) LIKE &#039;syllabus%&#039;&lt;br /&gt;
GROUP BY r.course HAVING count(r.course)&amp;gt;1&lt;br /&gt;
%%FILTER_SUBCATEGORIES:cc.path%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Chat==&lt;br /&gt;
&lt;br /&gt;
===List the chats===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
This report gives the list of all chats with the name of the course and various ids needed for further queries.&lt;br /&gt;
&lt;br /&gt;
The column &amp;quot;participants&amp;quot; is intended to work with an (optional) secondary report. If you don&#039;t need it , you can erase it.&lt;br /&gt;
It produces a direct link to another (optional) report which will give you the current participants list to this chat.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
c.shortname,&lt;br /&gt;
c.fullname,&lt;br /&gt;
ch.course, &lt;br /&gt;
ch.id,&lt;br /&gt;
# if you intend to use a secondary report to see the participants of a specific chat&lt;br /&gt;
# create the secondary report, check the id of the report in the url, and change the 21 in next line to your participant report&#039;s id&lt;br /&gt;
CONCAT(&#039;&amp;lt;a href=&amp;quot;%%WWWROOT%%/blocks/configurable_reports/viewreport.php?id=21&amp;amp;filter_courses=&#039;, ch.id,&#039;&amp;quot;&amp;gt;Chat participants&amp;lt;/a&amp;gt;&#039;) AS &#039;Course link&#039;,&lt;br /&gt;
ch.chattime&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_chat ch&lt;br /&gt;
INNER JOIN prefix_course c ON c.id = ch.course&lt;br /&gt;
&lt;br /&gt;
ORDER BY ch.chattime, c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Participants to a chat (optional secondary report)===&lt;br /&gt;
This version of the participant list is intended to work with a link given in the previous report.&lt;br /&gt;
* User opens the report listing all the chats on the platform&lt;br /&gt;
* user clicks on the link from the column &amp;quot;chat participant&amp;quot; &lt;br /&gt;
* which open this report with a filter on the chatid&lt;br /&gt;
&#039;&#039;(careful, we are tweaking the coursefilter to carry instead the chatid: the displayed &amp;quot;course filter&amp;quot; will not work! but we need it)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT&lt;br /&gt;
c.id AS courseid,&lt;br /&gt;
chu.chatid,&lt;br /&gt;
chu.userid AS &#039;chat user userid&#039;,&lt;br /&gt;
c.fullname,&lt;br /&gt;
u.username,&lt;br /&gt;
u.firstname,&lt;br /&gt;
u.lastname,&lt;br /&gt;
u.email&lt;br /&gt;
                                &lt;br /&gt;
FROM&lt;br /&gt;
prefix_user u &lt;br /&gt;
LEFT JOIN prefix_chat_users chu ON chu.userid = u.id&lt;br /&gt;
INNER JOIN prefix_course c ON c.id = chu.course&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1&lt;br /&gt;
%%FILTER_COURSES:chu.chatid%%&lt;br /&gt;
# you can also filter by course&lt;br /&gt;
# but don&#039;t put comment line between where and filter&lt;br /&gt;
# %%FILTER_COURSES:chu.course%%&lt;br /&gt;
&lt;br /&gt;
                                &lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List current participants to chat===&lt;br /&gt;
Contributed by [https://moodle.org/user/profile.php?id=2049965 François Parlant]&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
c.id AS courseid,&lt;br /&gt;
chu.chatid,&lt;br /&gt;
chu.userid AS &#039;chat user userid&#039;,&lt;br /&gt;
c.fullname,&lt;br /&gt;
u.username,&lt;br /&gt;
u.firstname,&lt;br /&gt;
u.lastname,&lt;br /&gt;
u.email&lt;br /&gt;
                                &lt;br /&gt;
FROM&lt;br /&gt;
prefix_user u &lt;br /&gt;
LEFT JOIN prefix_chat_users chu ON chu.userid = u.id&lt;br /&gt;
INNER JOIN prefix_course c ON c.id = chu.course&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1&lt;br /&gt;
%%FILTER_COURSES:chu.course%%&lt;br /&gt;
                                &lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Useful sub queries ==&lt;br /&gt;
&lt;br /&gt;
IN this section please put any short one purpose sub queries that show how common procedures often useful as part of larger queries.&lt;br /&gt;
&lt;br /&gt;
=== All teachers in the course ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This snippet shows how to get teachers from a course. The contextevel for course objects is 50. And the default Teacher role is role id 3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course ic&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = ic.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND ic.id = c.id&lt;br /&gt;
GROUP BY ic.id&lt;br /&gt;
) AS TeacherNames&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Get custom User profile fields for a user ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON uid.fieldid = uif.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to limit it to one of those fields, you can restrict it by shortname of the custom profile field, so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;shortname1&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will show you only the data from the custom profile field with the shortname &#039;shortname1&#039;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, d1.data AS &#039;Profile One&#039;, d2.data As &#039;Profile Two&#039;&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
JOIN prefix_user_info_data d1 ON d1.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
JOIN prefix_user_info_data d2 ON d2.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f2 ON d2.fieldid = f2.id AND f2.shortname = &#039;shortname2&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== NOTE: Alternate Method ====&lt;br /&gt;
&lt;br /&gt;
If you have more than a couple of fields you need to use, then this query may time out or not return data due to too many joins. The limit seems to be around 10 custom profile fields. &lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thefirstfield&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname2&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thesecondfield&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== How to use Configurable Reports Date Time Filters===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Here is a simple example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.firstaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;FirstAccess&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.lastaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;LastAccess&#039;   &lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1&lt;br /&gt;
%%FILTER_STARTTIME:u.firstaccess:&amp;gt;%% &lt;br /&gt;
%%FILTER_ENDTIME:u.lastaccess:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2) You MUST then add the Start / End date filter on the Filters tab of the Report. If you don&#039;t, the report will still run, probably, but the filter will be ignored.&lt;br /&gt;
&lt;br /&gt;
Note: the WHERE 1=1 statement is a peculiarity of the filters in Config reports: if you don&#039;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.)&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://github.com/jleyva/moodle-configurable_reports_repository Configurable Reports Repository on GitHub]&lt;br /&gt;
* [https://moodleschema.zoola.io/index.html Moodle DB schema explorer] - searching and filtering tables, fields and external key connections between tables.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;br /&gt;
&lt;br /&gt;
[[es:Reportes específicos hechos por usuarios]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Mail_configuration&amp;diff=139214</id>
		<title>Mail configuration</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Mail_configuration&amp;diff=139214"/>
		<updated>2021-01-03T12:22:16Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Outgoing mail configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
==Outgoing mail configuration==&lt;br /&gt;
&lt;br /&gt;
Settings related to mail sent by Moodle can be found in &#039;Outgoing mail configuration&#039; in Site administration -&amp;gt; Server -&amp;gt; Email.&lt;br /&gt;
&lt;br /&gt;
The setting &#039;Allowed email domains&#039; (allowedemaildomains) allows you to enter domains allowed by your mail server so that forum post notification emails can be sent from users&#039; real addresses. It accepts a wildcard for conveniently adding a lot of domains (*.example.com - tim@first.example.com), or a strict match (example.com - tim@example.com). &lt;br /&gt;
&lt;br /&gt;
If allowed domains are set then the user&#039;s email address will be used in the &amp;quot;From&amp;quot; and &amp;quot;Reply to&amp;quot; field only in the following situations:&lt;br /&gt;
&lt;br /&gt;
* The email matches the allowed domains, and the user&#039;s setting is to display their email address to everyone.&lt;br /&gt;
* The email matches the allowed domains, and the user&#039;s setting is to display their email only to course members, and the email is to be delivered to a course member.&lt;br /&gt;
&lt;br /&gt;
All other situations use the no-reply address.&lt;br /&gt;
&lt;br /&gt;
The setting &#039;Email via information&#039; (emailfromvia) adds via information in the From section of outgoing email to inform the recipient where the email came from:&lt;br /&gt;
 Name (via shortname) &amp;lt;noreplyaddress&amp;gt;&lt;br /&gt;
&#039;shortname&#039; is the short name for the site as set in the front page settings.&lt;br /&gt;
&lt;br /&gt;
 NOTE: You can also use [[Email_setup_gmail|Google gMail]] servers or AMAZON [https://docs.bitnami.com/aws/how-to/use-ses/ AWS SES]] Simple Email Services to setup SMTP relay for your outbound emails. &lt;br /&gt;
&lt;br /&gt;
===Test outgoing mail configuration===&lt;br /&gt;
&lt;br /&gt;
A link is available to send yourself a test email to check everything is working correctly.&lt;br /&gt;
&lt;br /&gt;
==Incoming mail configuration==&lt;br /&gt;
If incoming mail processing is enabled in &#039;Incoming mail configuration&#039; in Site administration, then users are able to reply to forum posts via email and send files to their private files as email attachments.&lt;br /&gt;
&lt;br /&gt;
===Mailbox configuration===&lt;br /&gt;
It is important to have a dedicated email address here. Don&#039;t use one you normally use for your personal emails. You do not need to add the @ sign. If you have set up the email mountorangeschool @ besteveremail.com then it would be entered as in the following screenshot:&lt;br /&gt;
[[File:emailexampleincoming.png|thumb|center|400px]]&lt;br /&gt;
&lt;br /&gt;
===Incoming mail server settings===&lt;br /&gt;
As an example, if you are using gmail you would use &#039;&#039;&#039;IMAP.gmail.com&#039;&#039;&#039; in the Incoming mail server (messageinbound_host) field. (If using gmail you also need to make sure that you&#039;ve enabled IMAP for yor gmail account - see https://support.google.com/mail/troubleshooter/1668960?hl=en )&lt;br /&gt;
&lt;br /&gt;
Note1: The SMTP server hosting the mailbox you&#039;ve configured above must support &#039;&#039;plus addressing&#039;&#039; i.e. any email sent to mountorangeschool+blahblahblah@besteveremail.com is still delivered to mountorangeschool@besteveremail.com.&lt;br /&gt;
&lt;br /&gt;
Note2 : The username and password  here must relate to the settings you entered earlier in Mailbox configuration. So if your address was mountorangeschool @ besteveremail.com and your username is &#039;&#039;mountorangeschool&#039;&#039;, then enter your username in this section along with the password you use to get into this email account.&lt;br /&gt;
&lt;br /&gt;
Note 3: You may also need to make sure that your host does not block outbound connections to the IMAP ports (some do by default).&lt;br /&gt;
&lt;br /&gt;
Note 4: If using gmail, you may find that IMAP does not work with Google&#039;s higher security setting.  If IMAP is not working with gmail, check out https://support.google.com/accounts/answer/6010255?hl=en-GB&lt;br /&gt;
&lt;br /&gt;
==Message handlers==&lt;br /&gt;
&lt;br /&gt;
===Email to Private files===&lt;br /&gt;
*If you enable this, then users will be able to send attachments via email directly to their private files. See [[Private files]] for details of how the feature works.&lt;br /&gt;
*Each user will be provided with  an address in their Private files to which they send the email and attached files. You can set the default expiry period for this address here.&lt;br /&gt;
*Checking the &#039;Validate sender address&#039; box will mean that if an email is sent to a user&#039;s private files from a different account from that registered with  user in Moodle, then Moodle will check first before allowing the file to be stored in the user&#039;s Private files.&lt;br /&gt;
&lt;br /&gt;
===Invalid recipient handler===&lt;br /&gt;
If a valid message is received but the sender cannot be authenticated, the message is stored on the email server and the user is contacted using the email address in their user profile. The user is given the chance to reply to confirm the authenticity of the original message.This handler processes those replies.&lt;br /&gt;
&lt;br /&gt;
It is not possible to disable sender verification of this handler because the user may reply from an incorrect email address if their email client configuration is incorrect.&lt;br /&gt;
&lt;br /&gt;
===Reply to forum posts===&lt;br /&gt;
*If you enable this, then users will be able to reply to forum posts directly from their email inbox. See the section on &#039;Reply to posts via email&#039; in [[Using Forum]] for details of how the feature works.&lt;br /&gt;
*You must leave empty the &#039;&#039;Site administration &amp;gt; Server &amp;gt; Email &amp;gt; Outgoing mail configuration &amp;gt; Allowed email domains&#039;&#039; setting; otherwise users will see the email of the forum poster instead.&lt;br /&gt;
*Each user will be provided with  reply-to address when they click to reply to a forum post via  email. You can set the default expiry period for this address here.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=277594 Need help configuring forum&#039;s &amp;quot;Reply to post&amp;quot; feature] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[es:Configuración del correo]]&lt;br /&gt;
[[de:Einstellungen für E-Mails]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Forum]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Installing_Moodle&amp;diff=139213</id>
		<title>Installing Moodle</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Installing_Moodle&amp;diff=139213"/>
		<updated>2021-01-03T12:17:01Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Settings within Moodle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Installing Moodle}}&lt;br /&gt;
&#039;&#039;This page explains how to install Moodle. If you are an expert and/or in a hurry try [[Installation Quickstart]].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you just want to try Moodle on a standalone machine there are &#039;one-click&#039; installers for Windows (see [[Complete install packages for Windows]]) and for OSX (see [[Complete Install Packages for Mac OS X]]) or [[ install on OS X]]. These are unsuitable for production servers.&lt;br /&gt;
&lt;br /&gt;
If you want to avoid installing Moodle yourself completely, consider https://moodle.com/moodlecloud/&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Moodle is primarily developed in Linux using [[Apache]], [[PostgreSQL]]/[[MySQL]]/[[MariaDB]] and [[PHP]] (sometimes known as the LAMP platform). Typically this is also how Moodle is run, although there are other options as long as the software requirements of the  [{{Release notes}} release] are met.&lt;br /&gt;
&lt;br /&gt;
If you are installing Moodle in a Windows server, note that from php5.5 onwards, you will also need to have  the Visual C++ Redistributable for Visual Studio 2012 installed from:&lt;br /&gt;
http://www.microsoft.com/en-us/download/details.aspx?id=30679 Visual C++] ( x86 or x64)  &lt;br /&gt;
&lt;br /&gt;
The basic requirements for Moodle are as follows:&lt;br /&gt;
&lt;br /&gt;
=== Hardware === &lt;br /&gt;
* Disk space: 200MB for the Moodle code, plus as much as you need to store content. 5GB is probably a realistic minimum. &lt;br /&gt;
* Processor: 1GHz (min), 2GHz dual core or more recommended.&lt;br /&gt;
* Memory: 512MB (min), 1GB or more is recommended. 8GB plus is likely on a large production server&lt;br /&gt;
* Consider separate servers for the web &amp;quot;front ends&amp;quot; and the database. It is much easier to &amp;quot;tune&amp;quot;&lt;br /&gt;
&lt;br /&gt;
All the above requirements will vary depending on specific hardware and software combinations as well as the type of use and load; busy sites may well require additional resources. Further guidance can be found under [[Performance_recommendations|performance recommendations]]. Moodle scales easily by increasing hardware.&lt;br /&gt;
&lt;br /&gt;
For very large sites, you are much better starting with a small pilot and gaining some experience and insight. A &amp;quot;what hardware do I need for 50,000 user?&amp;quot; style post in the forums is highly unlikely to get a useful answer.&lt;br /&gt;
&lt;br /&gt;
=== Software ===&lt;br /&gt;
&lt;br /&gt;
See the [{{Release notes}} release notes] in the dev docs for software requirements.&lt;br /&gt;
&lt;br /&gt;
== Set up your server ==&lt;br /&gt;
&lt;br /&gt;
Depending on the use case a Moodle server may be anything from a Desktop PC (e.g. for testing and evaluating) to a rackmounted or  [[Server cluster|clustered]] solution to cloud VMs or other hosted solutions. As mentioned above there are lots of possibilities for installing the basic server software, some links and pointers are at [[Installing AMP]], [[Internet_Information_Services|IIS]], [[Nginx]]. &lt;br /&gt;
&lt;br /&gt;
It will help hugely, regardless of your deployment choices, if time is taken to understand how to configure the different parts of your software stack (HTTP daemon, database,  PHP etc). Do not expect the standard server configuration to be optimal for Moodle. For example, the web server and database servers will almost certainly require tuning to get the best out of Moodle.&lt;br /&gt;
&lt;br /&gt;
If a hosting provider is being used  ensure that all Moodle [{{Release notes}}#Server_requirements requirements] (such as PHP version) are met by the hosting platform before attempting the installation. It will help to become familiar with changing settings within the hosting provider&#039;s platform (e.g. PHP file upload maximums) as the options and tools provided vary.&lt;br /&gt;
&lt;br /&gt;
== Download and copy files into place ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT: While there are now a number of places you can get the Moodle code (including host provided Moodle installers), you are strongly advised to only obtain Moodle from moodle.org. If you run into problems it will be a great deal easier to support you.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You have two options:&lt;br /&gt;
* Download your required version from http://moodle.org/downloads and unzip/unpack...&lt;br /&gt;
* &#039;&#039;&#039;OR&#039;&#039;&#039; Pull the code from the Git repository (recommended for developers and also makes upgrading very simple):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git clone -b MOODLE_{{Version3}}_STABLE git://git.moodle.org/moodle.git  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a fuller discussion see [[Git for Administrators]]. &lt;br /&gt;
&lt;br /&gt;
Either of the above should result in a directory called &#039;&#039;&#039;moodle&#039;&#039;&#039;, containing a number of files and folders. &lt;br /&gt;
&lt;br /&gt;
You can typically place the whole folder in your web server documents directory, in which case the site will be located at &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://yourwebserver.com/moodle&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;, or you can copy all the contents straight into the main web server documents directory, in which case the site will be simply &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://yourwebserver.com&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;. See the documentation for your system and/or web server if you are unsure. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;Tip:&#039;&#039; If you are downloading Moodle to your local computer and then uploading it to your hosted web site, it is usually better to upload the compressed Moodle file and then decompress on your hosted web site.  If you decompress Moodle on your local computer, because Moodle is comprised of over 25,000 files, trying to upload over 25,000 files using an FTP client or your host&#039;s &amp;quot;file manager&amp;quot; can sometimes miss a file and cause errors. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Secure the Moodle files:&#039;&#039;&#039; It is vital that the files are not writeable by the web server user. For example, on Unix/Linux (as root):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chown -R root /path/to/moodle&lt;br /&gt;
chmod -R 0755 /path/to/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(files are owned by the administrator/superuser and are only writeable by them - readable by everyone else)&lt;br /&gt;
&lt;br /&gt;
On test/dev sites you &#039;&#039;may&#039;&#039; want to make the files writeable in order to use the built-in plugin installer. This is discouraged for live sites (at least, revert to more secure settings if you do).&lt;br /&gt;
&lt;br /&gt;
== Create an empty database ==&lt;br /&gt;
&lt;br /&gt;
Next create a new, empty database for your installation. You need to find and make a note of following information for use during the final installation stage:&lt;br /&gt;
* &#039;&#039;&#039;dbhost&#039;&#039;&#039; - the database server hostname. Probably &#039;&#039;localhost&#039;&#039; if the database and web server are the same machine, otherwise the name of the database server&lt;br /&gt;
* &#039;&#039;&#039;dbname&#039;&#039;&#039; - the database name. Whatever you called it, e.g. &#039;&#039;moodle&#039;&#039; &lt;br /&gt;
* &#039;&#039;&#039;dbuser&#039;&#039;&#039; - the username for the database. Whatever you assigned, e.g. &#039;&#039;moodleuser&#039;&#039; - do not use the root/superuser account. Create a proper account with the minimum permissions needed.&lt;br /&gt;
* &#039;&#039;&#039;dbpass&#039;&#039;&#039; - the password for the above user&lt;br /&gt;
&lt;br /&gt;
If your site is hosted you should find a web-based administration page for databases as part of the control panel (or ask your administrator). For everyone else or for detailed instructions, see the page for your chosen database server:&lt;br /&gt;
* [[PostgreSQL]]&lt;br /&gt;
* [[MariaDB]]&lt;br /&gt;
* [[MySQL]]&lt;br /&gt;
* [[MSSQL]]&lt;br /&gt;
* [[Oracle]] (not recommended)&lt;br /&gt;
&lt;br /&gt;
== Create the (&#039;&#039;moodledata&#039;&#039;) data directory  ==&lt;br /&gt;
&lt;br /&gt;
Moodle requires a directory to store all of its files (all your site&#039;s uploaded files, temporary data, cache, session data etc.). The web server needs to be able to write to this directory. On larger systems consider how much free space you are going to use when allocating this directory. &lt;br /&gt;
&lt;br /&gt;
Due to the default way Moodle caches data you may have serious performance issues if you use relatively slow storage (e.g. NFS) for this directory. Read the [[Performance_recommendations]] carefully and consider using (e.g.) redis or memcached for [[Caching]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This directory must &#039;&#039;&#039;NOT&#039;&#039;&#039; be accessible directly via the web. This would be a serious security hole. Do not try to place it inside your web root or inside your Moodle program files directory. Moodle will not install. It can go anywhere else convenient. &lt;br /&gt;
&lt;br /&gt;
Here is an example (Unix/Linux) of creating the directory and setting the permissions for &#039;&#039;&#039;anyone&#039;&#039;&#039; on the server to write here. This is only appropriate for Moodle servers that are not shared. Discuss this with your server administrator for better permissions that just allow the web server user to access these files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# mkdir /path/to/moodledata&lt;br /&gt;
# chmod 0777 /path/to/moodledata&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Securing moodledata in a web directory ====&lt;br /&gt;
&lt;br /&gt;
If you are using a hosted site and you have no option but to place &#039;moodledata&#039; in a web accessible directory. You may be able to secure it by creating an .htaccess file in the &#039;moodledata&#039; directory. This does not work on all systems - see your host/administrator. Create a file called .htaccess containing only the following lines:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
order deny,allow&lt;br /&gt;
deny from all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Start Moodle install ==&lt;br /&gt;
It&#039;s now time to run the installer to create the database tables and configure your new site. The recommended method is to use the command line installer. If you cannot do this for any reason (e.g. on a Windows server) the web-based installer is still available.&lt;br /&gt;
&lt;br /&gt;
=== Command line installer ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s best to run the command line as your system&#039;s web user. You need to know what that is - see your system&#039;s documentation (e.g. Ubuntu/Debian is &#039;www-data&#039;, Centos is &#039;apache&#039;)&lt;br /&gt;
&lt;br /&gt;
* Example of using the command-line  (as root - substitute &#039;www-data&#039; for your web user):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chown www-data /path/to/moodle&lt;br /&gt;
# cd /path/to/moodle/admin/cli&lt;br /&gt;
# sudo -u www-data /usr/bin/php install.php&lt;br /&gt;
# chown -R root /path/to/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The chowns allow the script to write a new config.php file. More information about the options can be found using &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# php install.php --help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be asked for other settings that have not been discussed on this page - if unsure just accept the defaults. For a full discussion see [[Administration via command line]]&lt;br /&gt;
&lt;br /&gt;
=== Web based installer ===&lt;br /&gt;
&lt;br /&gt;
For ease of use you can install Moodle via the web. We recommend configuring your web server so that the page is not publicly accessible until the installation is complete.&lt;br /&gt;
&lt;br /&gt;
To run the web installer script, just go to your Moodle&#039;s main URL using a web browser.&lt;br /&gt;
&lt;br /&gt;
The installation process will take you through a number of pages. You should be asked to confirm the copyright, see the database tables being created, supply administrator account details and supply the site details. The database creation can take some time - please be patient. You should eventually end up at the Moodle front page with an invitation to create a new course. &lt;br /&gt;
&lt;br /&gt;
It is very likely that you will be asked to download the new config.php file and upload it to your Moodle installation - just follow the on-screen instructions.&lt;br /&gt;
&lt;br /&gt;
==Final configuration==&lt;br /&gt;
&lt;br /&gt;
=== Settings within Moodle ===&lt;br /&gt;
There are a number of options within the Moodle Site Administration screens (accessible from the &#039;Site administration&#039; tab in the &#039;Administration&#039; block (Classic theme) or the Site administration button in the navigation bar (Boost). Here are a few of the more important ones that you will probably want to check:&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; Email &amp;gt; [[Mail_configuration#Outgoing_mail_configuration|Outgoing mail configuration]]&#039;&#039;: Set your smtp server and authentication if required (so your Moodle site can send emails). You can also set a norepy email on this page.&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; Server &amp;gt; Support contact&#039;&#039;. Set your support contact email. &lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; System paths&#039;&#039;: Set the paths to du, dot and aspell binaries.&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; HTTP&#039;&#039;: If you are behind a firewall you may need to set your proxy credentials in the &#039;Web proxy&#039; section.&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Location &amp;gt; Update timezones&#039;&#039;: Run this to make sure your timezone information is up to date. (more info [[Location]])&lt;br /&gt;
** [http://php.net/manual/en/timezones.php Set server&#039;s local timezone] inside &amp;lt;tt&amp;gt;php.ini&amp;lt;/tt&amp;gt; (should probably be inside &amp;lt;tt&amp;gt;/etc/php.ini&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;/etc/php.d/date.ini&amp;lt;/tt&amp;gt;, depending on the underlying OS):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
[Date] &lt;br /&gt;
; Defines the default timezone used by the date functions &lt;br /&gt;
date.timezone = &amp;quot;YOUR LOCAL TIMEZONE&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remaining tasks ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configure Cron&#039;&#039;&#039;: Moodle&#039;s background tasks (e.g. sending out forum emails and performing course backups) are performed by a script which you can set to execute at specific times of the day. This is known as a cron script. Please refer to the [[Cron|Cron instructions]].&lt;br /&gt;
* &#039;&#039;&#039;Set up backups&#039;&#039;&#039;: See [[Site backup]] and [[Automated course backup]].&lt;br /&gt;
* &#039;&#039;&#039;Secure your Moodle site&#039;&#039;&#039;: Read the [[Security recommendations]].&lt;br /&gt;
*&#039;&#039;&#039;Increasing the maximum upload size&#039;&#039;&#039;  See [[Installation FAQ]] Maximum upload file size - how to change it?&lt;br /&gt;
* &#039;&#039;&#039;Check mail works&#039;&#039;&#039; : From Site administration &amp;gt; Server &amp;gt; Test outgoing mail configuration, use the  link to send yourself a test email. Don&#039;t be tempted to skip this step.&lt;br /&gt;
&lt;br /&gt;
=== Installation is complete :) ===&lt;br /&gt;
&lt;br /&gt;
* Create a new course: You can now access Moodle through your web browser (using the same URL as you set during the install process), log in as your admin user and creatse a new course. See  [[Adding a new course|create a new course]].&lt;br /&gt;
&lt;br /&gt;
=== If something goes wrong... ===&lt;br /&gt;
&lt;br /&gt;
Here are some things you should try...&lt;br /&gt;
&lt;br /&gt;
* Check the [[Installation FAQ]]&lt;br /&gt;
* Check your file permissions carefully. Can your web server read (but not write) the Moodle program files? Can your web server read and write your Moodle data directory? If you don&#039;t fully understand how file ownership and permissions work on your operating system it would be time very well spent to find out.&lt;br /&gt;
* Check your database permissions. Have you set up your database user with the correct rights and permissions for your configuration (especially if the web server and database server are different machines)?&lt;br /&gt;
* Create your [[Configuration file]] (config.php) by hand. Copy config-dist.php (in the root of the Moodle program directory) to config.php, edit it and set your database/site options there. Installation will continue from the right place. &lt;br /&gt;
* Once you have a config.php (see previous tip) you can edit it to turn on debugging (in section 8). This may give you extra information to help track down a problem. If you have access, check your web server error log(s).&lt;br /&gt;
* Re-check your php.ini / .htaccess settings. Are they appropriate (e.g. memory_limit), did you edit the correct php.ini / .htaccess file and (if required) did you re-start the web server after making changes?&lt;br /&gt;
* Did you include any non-core (optional) plugins, themes or other code before starting the installation script? If so, remove it and try again (it may be broken or incompatible).&lt;br /&gt;
* Explain your problem in the [http://moodle.org/mod/forum/view.php?id=28 Installation problems forum]. &#039;&#039;&#039;PLEASE&#039;&#039;&#039; list your software versions; explain what you did, what happened and what error messages you saw (if any); explain what you tried. There is no such thing as &#039;nothing&#039;, even a blank page is something!&lt;br /&gt;
&lt;br /&gt;
== Platform specific instructions ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Much of this information is provided by the community. It may not have been checked and may be out of date. Please read in conjunction with the above installation instructions.&lt;br /&gt;
&lt;br /&gt;
* [[Windows installation]]&lt;br /&gt;
** [[Installing Moodle on SmarterASP.NET]]&lt;br /&gt;
* [[Unix or Linux Installation]]&lt;br /&gt;
* [[Mac Installation]]&lt;br /&gt;
* [[Amazon EC2 Cloud Services Installation]]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [http://www.slideshare.net/gb2048/my-own-moodle Slideshare presentation by Gareth Barnard on installing a local installation of Moodle] and accompanying [https://drive.google.com/folderview?id=0B17B0rYH2zERU21sQnVweUZCUFk&amp;amp;usp=sharing  help guides]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=182086 New Video Tutorial- How to Install Moodle on Shared Hosting via cPanel (Not Fantastico)]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=401983 Another one for cPanel using videos]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=199542 Video Tutorial - Install Moodle on a Virtual Box from scratch] &lt;br /&gt;
&lt;br /&gt;
[[es:Instalaci%C3%B3n_de_moodle]]&lt;br /&gt;
[[de:Installation von Moodle]]&lt;br /&gt;
[[fr:Installation de Moodle]]&lt;br /&gt;
[[ja:Moodleのインストール]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Large_installations&amp;diff=139024</id>
		<title>Large installations</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Large_installations&amp;diff=139024"/>
		<updated>2020-11-17T17:56:39Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Main page}}&lt;br /&gt;
&lt;br /&gt;
== Architecture ==&lt;br /&gt;
Large scale Moodle infrastructures can be set up on different types of machines, from bare metal to compartmentalized virtual containers (or Kubernetes Pods).&amp;lt;br /&amp;gt;&lt;br /&gt;
In this section, we will try to share and put together some case study examples of such technological concepts of running very large scale Moodle systems.&lt;br /&gt;
&lt;br /&gt;
=== On premise ===&lt;br /&gt;
* Bare metal or Virtualization for Moodle [[Server_cluster]] setup.&lt;br /&gt;
&lt;br /&gt;
=== Public clouds ===&lt;br /&gt;
* [https://github.com/aws-samples/aws-refarch-moodle Amazon (AWS) EC2 (VMs)] with auto scaling groups and managed services (Storage, Caching, Database, CI/CD).&lt;br /&gt;
** [https://developerck.com/moodle-horizontal-scalable-aws/ Moodle Horizontal Scalable Deployment on AWS stack]&lt;br /&gt;
** [https://mxmartempresarial.com/caso-de-estudio-univa.html Hosting high availability Moodle on AWS] (Spanish)&lt;br /&gt;
** [https://www.erichartzog.com/blog/horz-scale-moodle Auto-Scaling Moodle Architecture on AWS 2015]&lt;br /&gt;
** [https://github.com/Tulkis/aws-ebs-moodle Moodle with AWS Elastic Beanstalk]&lt;br /&gt;
** [https://moodle.com/wp-content/events/mootglobal19/Cloudinfrastructureforhighconcurrency.pdf Cloud infrastructure for high concurrency] 2019 Moodle MOOT Global presentation.&lt;br /&gt;
* [https://ktree.com/blog/moodle-ha-setup-using-docker-over-aws.html Amazon (AWS) Docker containers] with auto scaling groups and managed services (Storage, Caching, Database, CI/CD).&lt;br /&gt;
* Google (GPC) Kubernetes including automated managed micro services (Storage, Caching, Database, CI/CD, document conversions) &lt;br /&gt;
* Microsoft (Azure) - [https://github.com/Azure/Moodle/ Deploy and Manage a Scalable Moodle Cluster on Azure]&lt;br /&gt;
&lt;br /&gt;
== Custom setup and Tips ==&lt;br /&gt;
* A list of [[Performance_recommendations]] tuning tweaks you should consider applying to your system.&lt;br /&gt;
* Bare metal vs Virtualization, consideration relevant to the specific way Moodle is built.&lt;br /&gt;
* [https://aws.amazon.com/efs/features/infrequent-access/ Save some budget with AWS infrequent access EFS]&lt;br /&gt;
* [https://techcommunity.microsoft.com/t5/azure-database-for-mysql/deploying-moodle-on-azure-things-you-should-know/ba-p/814054 Deploying Moodle on Azure – things you should know]&lt;br /&gt;
&lt;br /&gt;
== Community support ==&lt;br /&gt;
* Moodle [https://moodle.org/mod/forum/view.php?id=596 Hardware and performance] forum.&lt;br /&gt;
* [https://t.me/large_scale_moodle Large scale Moodle IT support] Telegram group (click to join)&lt;br /&gt;
&lt;br /&gt;
== List of Moodle systems by user count ==&lt;br /&gt;
This page was started in December 2005. Inclusion on these pages is by self selection and completely voluntary.  There are more sites which meet these criterion that are not listed.&lt;br /&gt;
&lt;br /&gt;
*[[Installations 1000 plus]] users&lt;br /&gt;
*[[Installations 5000 plus]] users&lt;br /&gt;
*[[Installations 10000 plus]] users&lt;br /&gt;
*[[Installations 30000 plus]] users&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
*[http://moodle.org/mod/choice/view.php?id=3934 How big is your Moodle site?] choice activity (Sorry, this activity is currently hidden)&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=36216 Chart of schools (by size) that are using Moodle] forum discussion&lt;br /&gt;
*[http://www.frappr.com/moodle World map of Moodle users]&lt;br /&gt;
*[http://moodle.org/stats/ Moodle statistics]&lt;br /&gt;
*[[Institutions that have Migrated to Moodle]]&lt;br /&gt;
&lt;br /&gt;
[[ja:Moodleの大規模インストール]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Administration_via_command_line&amp;diff=135626</id>
		<title>Administration via command line</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Administration_via_command_line&amp;diff=135626"/>
		<updated>2019-10-01T07:01:58Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Build theme CSS cache */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
==Running CLI scripts==&lt;br /&gt;
If you have shell access to your web server, you may find various CLI (command line interface) scripts useful during Moodle administration. Core admin CLI tools are located in the &amp;lt;code&amp;gt;admin/cli/*&amp;lt;/code&amp;gt; folder. Other plugins provide their CLI functionality via scripts in their own cli folder. For example, the enrol_db sync script is located in &amp;lt;code&amp;gt;enrol/db/cli/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To avoid problems with access control, you should run them as the owner of the web server process. It is especially important for CLI installation and upgrade as they create new files in moodledata directory and the web server has to have write access to them. In Linux distributions, the user that runs the web server is usually apache or wwrun or httpd or something similar. As a root, you will probably want to execute Moodle CLI scripts like this:&lt;br /&gt;
&lt;br /&gt;
    $ cd /path/to/your/moodle/dir&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/somescript.php --params&lt;br /&gt;
&lt;br /&gt;
Most of the scripts accept common --help (or -h) parameter to display the full usage information, for example:&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/install.php --help&lt;br /&gt;
&lt;br /&gt;
{{Note|These scripts are supposed to be run under the identity of the web server user. Examples on this page use the &amp;lt;tt&amp;gt;apache&amp;lt;/tt&amp;gt; user for illustration. The particular value depends on your OS distribution and local set-up. Typical values may be &amp;lt;tt&amp;gt;apache&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;www-data&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;httpd&amp;lt;/tt&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
== Upgrading ==&lt;br /&gt;
&lt;br /&gt;
Moodle can be upgraded from the command line. As with the installation script, there is either interactive or non-interactive mode of the upgrade. The script itself does not put the site into the maintenance mode, you have to do it on your own. Also, the script does not backup any data (if you read this page, you probably have some own scripts to backup your moodledata and the database, right?)&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/upgrade.php&lt;br /&gt;
&lt;br /&gt;
Upgrading via command line is a very comfortable way of Moodle upgrade if you use Git checkout of the Moodle source code (see [[Git for Administrators]]). See the following procedure how to upgrade your site within several seconds to the most recent version while preserving your eventual local customizations tracked in git repository:&lt;br /&gt;
&lt;br /&gt;
    $ cd /var/www/sites/moodle/htdocs/&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable&lt;br /&gt;
    $ git pull&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/upgrade.php&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
There are two modes of installing Moodle from the command line. In interactive mode, the install script asks you for all data needed to properly set up new Moodle site. In non-interactive mode, you must provide all required data as the script parameters and then the new site is installed silently. The parameters can be passed in the interactive mode, too. The provided values are then used as the default values during the interactive session.&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/install.php --lang=cs&lt;br /&gt;
&lt;br /&gt;
If required, the database install may be skipped, with just config.php populated.&lt;br /&gt;
&lt;br /&gt;
   $ sudo -u apache /usr/bin/php admin/cli/install.php --skip-database&lt;br /&gt;
&lt;br /&gt;
== Maintenance mode ==&lt;br /&gt;
&lt;br /&gt;
To switch your site into the maintenance mode via CLI, you can use&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable&lt;br /&gt;
&lt;br /&gt;
To turn maintenance mode off, execute the same script with the --disable parameter:&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to enable maintenance mode immediately, but show a countdown to your users, execute the same script with the --enablelater parameter and the number of minutes which the countdown should run:&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enablelater=10&lt;br /&gt;
&lt;br /&gt;
This script will also create and remove the climaintenance.html file for &amp;quot;Offline&amp;quot; mode.&lt;br /&gt;
&lt;br /&gt;
== Offline mode ==&lt;br /&gt;
&lt;br /&gt;
In some situations, you may want to switch your Moodle site into offline mode so that it is not accessible via the web but you can not stop the web server completely (typically because there are other web pages and applications running there). If a file called &amp;lt;code&amp;gt;climaintenance.html&amp;lt;/code&amp;gt; exists in the root folder of moodledata directory, Moodle will automatically display the contents of that file instead of any other page.&lt;br /&gt;
&lt;br /&gt;
    $ cd /var/www/sites/moodle/moodledata/&lt;br /&gt;
    $ echo &#039;&amp;amp;lt;h1&amp;amp;gt;Sorry, maintenance in progress&amp;amp;lt;/h1&amp;amp;gt;&#039; &amp;amp;gt; climaintenance.html&lt;br /&gt;
&lt;br /&gt;
You can prepare a nice formatted HTML page to inform your users about the server being down and keep in the moodledata directory under a name like &amp;lt;code&amp;gt;climaintenance.off&amp;lt;/code&amp;gt; and rename it to the &amp;lt;code&amp;gt;climaintenance.html&amp;lt;/code&amp;gt; if needed.&lt;br /&gt;
&lt;br /&gt;
== Custom site defaults ==&lt;br /&gt;
&lt;br /&gt;
During the install and upgrade via CLI, Moodle sets the administration variables to the default values. You can use different defaults. See MDL-17850 for details. Shortly, all you need to do is to add a file &amp;lt;code&amp;gt;local/defaults.php&amp;lt;/code&amp;gt; into your Moodle installation. The format of the file is like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$defaults[&#039;pluginname&#039;][&#039;settingname&#039;] = &#039;settingvalue&#039;; // for plugins&lt;br /&gt;
$defaults[&#039;moodle&#039;][&#039;settingname&#039;] = &#039;settingvalue&#039;;     // for core settings&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These defaults are used during install, upgrade and are also displayed as defaults on Site administration pages.&lt;br /&gt;
&lt;br /&gt;
== Reset user password ==&lt;br /&gt;
&lt;br /&gt;
If you happen to forget your admin password (or you want to set a password for any other user on the site), you can use reset_password.php script. The script sets the correctly salted password for the given user.&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/reset_password.php&lt;br /&gt;
&lt;br /&gt;
== MySQL storage engine conversion ==&lt;br /&gt;
&lt;br /&gt;
If you run your Moodle site with MySQL database backend and use the default MyISAM as the storage engine for your tables, you may want to convert them to use some more reliable engine like InnoDB (actually, you should want to switch to PostgreSQL ;-) anyway).&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/mysql_engine.php --engine=InnoDB&lt;br /&gt;
&lt;br /&gt;
==Converting InnoDB tables to Barracuda==&lt;br /&gt;
&lt;br /&gt;
Sites using MySQL with database tables using Antelope as the file format are recommended to convert the tables to the Barracuda file format.&lt;br /&gt;
&lt;br /&gt;
This is because tables using Antelope as the file format cannot handle more than 10 text columns. This file formats only supports &#039;&#039;compact&#039;&#039; and &#039;&#039;redundant&#039;&#039; row formats for backward compatibility reasons. This may cause a problem on larger sites when restoring a course, in which case the following error will be displayed: &lt;br /&gt;
&lt;br /&gt;
 Row size too large (&amp;gt;8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help.&lt;br /&gt;
&lt;br /&gt;
Barracuda is the newest innoDB file format. In addition to supporting &#039;&#039;compact&#039;&#039; and &#039;&#039;redundant&#039;&#039; row formats, Barracuda also supports &#039;&#039;compressed&#039;&#039; and &#039;&#039;dynamic&#039;&#039; row formats. &lt;br /&gt;
&lt;br /&gt;
However, converting tables to Barracuda is only recommended, and not required, since not all MySQL users are affected. (It may only be a problem for larger sites.)&lt;br /&gt;
&lt;br /&gt;
===Tool for converting tables===&lt;br /&gt;
&lt;br /&gt;
A command line tool is included in Moodle for converting tables to Barracuda.&lt;br /&gt;
&lt;br /&gt;
To view tables requiring conversion, use the list option:&lt;br /&gt;
&lt;br /&gt;
 $ php admin/cli/mysql_compressed_rows.php --list&lt;br /&gt;
&lt;br /&gt;
Here is an example output:&lt;br /&gt;
&lt;br /&gt;
 mdl_data                            Compact     (needs fixing) &lt;br /&gt;
 mdl_data_fields                     Compact     (needs fixing)&lt;br /&gt;
 mdl_enrol_paypal                    Compact     (needs fixing)&lt;br /&gt;
&lt;br /&gt;
To proceed with the conversion, run the command using the fix option:&lt;br /&gt;
&lt;br /&gt;
 $ php admin/cli/mysql_compressed_rows.php --fix&lt;br /&gt;
&lt;br /&gt;
Successful table conversion will be reported in the output, for example:&lt;br /&gt;
&lt;br /&gt;
 mdl_data                   ... Compressed&lt;br /&gt;
 mdl_data_fields            ... Compressed&lt;br /&gt;
 mdl_enrol_paypal           ... Compressed&lt;br /&gt;
&lt;br /&gt;
Please note that the commands must be executed on your moodle directory. Once tables are fixed, the warning message will no longer be displayed.&lt;br /&gt;
 &lt;br /&gt;
For further information on InnoDB file formats see the [http://dev.mysql.com/doc/innodb/1.1/en/glossary.html#glos_antelope MySQL InnoDB glossary - Antelope] and the [http://dev.mysql.com/doc/innodb/1.1/en/glossary.html#glos_barracuda MySQL InnoDB glossary - Barracuda].&lt;br /&gt;
&lt;br /&gt;
If you get errors due to having insufficient privileges to run these commands (this is quite likely) then the easiest solution is to generate the required SQL commands using,&lt;br /&gt;
&lt;br /&gt;
 $ php admin/cli/mysql_compressed_rows.php --showsql&lt;br /&gt;
&lt;br /&gt;
You can then copy the generated SQL into your mysql client running as the &#039;root&#039; user.&lt;br /&gt;
&lt;br /&gt;
==Converting to the new character set and collation==&lt;br /&gt;
&lt;br /&gt;
 $ php admin/cli/mysql_collation.php --collation=utf8mb4_unicode_ci&lt;br /&gt;
&lt;br /&gt;
== Running cron via command line ==&lt;br /&gt;
&lt;br /&gt;
In versions 1.x, you could execute admin/cron.php either from command line or via the web. Since Moodle 2.0, only admin/cli/cron.php script can be run via command line.&lt;br /&gt;
&lt;br /&gt;
== Scheduled tasks ==&lt;br /&gt;
&lt;br /&gt;
Scheduled tasks are automatically run by the cron script, but the specific tasks which run on each cron iteration are determined by the scheduled tasks configuration. It is possible to override the scheduled tasks configuration and run a single scheduled task immediately using the admin/tool/task/cli/schedule_task.php script. &lt;br /&gt;
&lt;br /&gt;
This script accepts the following arguments:&lt;br /&gt;
&lt;br /&gt;
 --list - list all the known scheduled tasks. The tasks are listed by the class name used to run the task. This class name is required as the argument to the next option in order to run a specific task immediately.&lt;br /&gt;
&lt;br /&gt;
 --execute=&amp;lt;task&amp;gt; - Runs a single scheduled task immediately - regardless of scheduling settings. This will even run disabled tasks. Tasks will still use locking to prevent concurrent execution of the same task - even on clusters. The format of the &amp;lt;task&amp;gt; argument must be the same as returned by the --list option above.&lt;br /&gt;
&lt;br /&gt;
 --showsql - Shows sql queries before they are execute&lt;br /&gt;
&lt;br /&gt;
 --showdebugging - Shows developer debugging info&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; You must escape the &amp;quot;\&amp;quot; with an extra \ when using the --execute command. Take the following for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php schedule_task.php --list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== List of scheduled tasks (http://yourserver.com/moodle) ==&lt;br /&gt;
\enrol_imsenterprise\task\cron_task                10 * * * * *      ASAP&lt;br /&gt;
\logstore_legacy\task\cleanup_task                 * 5 * * * *       ASAP&lt;br /&gt;
\logstore_standard\task\cleanup_task               * 4 * * * *       Wednesday, November 12, 2014, 4:35 AM&lt;br /&gt;
\mod_forum\task\cron_task                          * * * * * *       ASAP&lt;br /&gt;
\core\task\automated_backup_task                   50 * * * * *      ASAP&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the first task in that list, you would execute&lt;br /&gt;
&lt;br /&gt;
 php schedule_task.php --execute=&#039;\enrol_imsenterprise\task\cron_task&#039;&lt;br /&gt;
&lt;br /&gt;
Be aware of the single quotes. Without them, you would need to use double backlashes to avoid escaping by the shell.&lt;br /&gt;
&lt;br /&gt;
==Database transfer==&lt;br /&gt;
&lt;br /&gt;
A command line script for [[Database transfer]] may be found in &#039;&#039;admin/tool/dbtransfer/cli/migrate.php&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Purge caches==&lt;br /&gt;
&lt;br /&gt;
You can purge caches using this script:&lt;br /&gt;
&lt;br /&gt;
  php admin/cli/purge_caches.php&lt;br /&gt;
&lt;br /&gt;
==Kill all sessions==&lt;br /&gt;
If needed for administrative reasons, you can kill all user sessions using this script:&lt;br /&gt;
&lt;br /&gt;
 php admin/cli/kill_all_sessions.php&lt;br /&gt;
&lt;br /&gt;
As a result, all users will be logged out from Moodle.&lt;br /&gt;
&lt;br /&gt;
==Fix course / module sequences==&lt;br /&gt;
&lt;br /&gt;
In rare cases (such as after upgrading from a very old version of Moodle), the course / section / module sequence data can be out of sync. This can cause various problems for affected courses, such as sections not appearing, backups failing, pages not displaying etc. There is a specific check to check for errors caused by this problem, and to fix the data in the database if they are found. To run this script please use the command below:&lt;br /&gt;
&lt;br /&gt;
  php admin/cli/fix_course_sequence.php -c=* --fix&lt;br /&gt;
&lt;br /&gt;
This will check every course in Moodle and report which ones had errors and were fixed.&lt;br /&gt;
&lt;br /&gt;
==Fix orphaned question categories==&lt;br /&gt;
&lt;br /&gt;
When a quiz is created, a new question category for the quiz is automatically created. In versions of Moodle prior to 2.9.1, if the quiz is deleted, the question category and any questions in the category remain in database. These orphaned question categories may be fixed by running the admin/cli/fix_orphaned_question_categories.php script with the --fix option.&lt;br /&gt;
&lt;br /&gt;
==Search and replace text==&lt;br /&gt;
&lt;br /&gt;
This script can be used to search and replace text throughout the whole database. Use carefully and backup first always. More info in [[Search and replace tool]].&lt;br /&gt;
&lt;br /&gt;
  php admin/tool/replace/cli/replace.php --search=//oldsitehost --replace=//newsitehost&lt;br /&gt;
&lt;br /&gt;
==Build theme CSS cache==&lt;br /&gt;
&lt;br /&gt;
If Moodle is not running in theme designer mode it will keep a copy of the compiled CSS on local disk and serve that to the browser when it requests a page. If there isn&#039;t a copy on local disk then a copy will be built the first time a page within Moodle is requested. &lt;br /&gt;
&lt;br /&gt;
With this script you can pre-compile the cached CSS files for themes within Moodle to avoid having a user wait for the theme to compile during the first page request.&lt;br /&gt;
&lt;br /&gt;
  php admin/cli/build_theme_css.php --themes=boost&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* MDL-35736 - Manage plugins via command line&lt;br /&gt;
* MDL-36237 - Resort course list via CLI&lt;br /&gt;
* [http://moosh-online.com/ MOOSH] - MOOdle SHell. It is a commandline tool that will allow you to perform most common Moodle tasks.&lt;br /&gt;
&lt;br /&gt;
[[fr:Administration en ligne de commande]]&lt;br /&gt;
[[de:Administration über Kommandozeile]]&lt;br /&gt;
[[es:Administración por línea de comando]]&lt;br /&gt;
[[it:Amministrazione via linea di comando]]&lt;br /&gt;
[[ja:コマンドライン経由の管理]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Administration_via_command_line&amp;diff=135625</id>
		<title>Administration via command line</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Administration_via_command_line&amp;diff=135625"/>
		<updated>2019-10-01T06:59:55Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Build theme CSS cache */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
==Running CLI scripts==&lt;br /&gt;
If you have shell access to your web server, you may find various CLI (command line interface) scripts useful during Moodle administration. Core admin CLI tools are located in the &amp;lt;code&amp;gt;admin/cli/*&amp;lt;/code&amp;gt; folder. Other plugins provide their CLI functionality via scripts in their own cli folder. For example, the enrol_db sync script is located in &amp;lt;code&amp;gt;enrol/db/cli/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To avoid problems with access control, you should run them as the owner of the web server process. It is especially important for CLI installation and upgrade as they create new files in moodledata directory and the web server has to have write access to them. In Linux distributions, the user that runs the web server is usually apache or wwrun or httpd or something similar. As a root, you will probably want to execute Moodle CLI scripts like this:&lt;br /&gt;
&lt;br /&gt;
    $ cd /path/to/your/moodle/dir&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/somescript.php --params&lt;br /&gt;
&lt;br /&gt;
Most of the scripts accept common --help (or -h) parameter to display the full usage information, for example:&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/install.php --help&lt;br /&gt;
&lt;br /&gt;
{{Note|These scripts are supposed to be run under the identity of the web server user. Examples on this page use the &amp;lt;tt&amp;gt;apache&amp;lt;/tt&amp;gt; user for illustration. The particular value depends on your OS distribution and local set-up. Typical values may be &amp;lt;tt&amp;gt;apache&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;www-data&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;httpd&amp;lt;/tt&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
== Upgrading ==&lt;br /&gt;
&lt;br /&gt;
Moodle can be upgraded from the command line. As with the installation script, there is either interactive or non-interactive mode of the upgrade. The script itself does not put the site into the maintenance mode, you have to do it on your own. Also, the script does not backup any data (if you read this page, you probably have some own scripts to backup your moodledata and the database, right?)&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/upgrade.php&lt;br /&gt;
&lt;br /&gt;
Upgrading via command line is a very comfortable way of Moodle upgrade if you use Git checkout of the Moodle source code (see [[Git for Administrators]]). See the following procedure how to upgrade your site within several seconds to the most recent version while preserving your eventual local customizations tracked in git repository:&lt;br /&gt;
&lt;br /&gt;
    $ cd /var/www/sites/moodle/htdocs/&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable&lt;br /&gt;
    $ git pull&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/upgrade.php&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
There are two modes of installing Moodle from the command line. In interactive mode, the install script asks you for all data needed to properly set up new Moodle site. In non-interactive mode, you must provide all required data as the script parameters and then the new site is installed silently. The parameters can be passed in the interactive mode, too. The provided values are then used as the default values during the interactive session.&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/install.php --lang=cs&lt;br /&gt;
&lt;br /&gt;
If required, the database install may be skipped, with just config.php populated.&lt;br /&gt;
&lt;br /&gt;
   $ sudo -u apache /usr/bin/php admin/cli/install.php --skip-database&lt;br /&gt;
&lt;br /&gt;
== Maintenance mode ==&lt;br /&gt;
&lt;br /&gt;
To switch your site into the maintenance mode via CLI, you can use&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable&lt;br /&gt;
&lt;br /&gt;
To turn maintenance mode off, execute the same script with the --disable parameter:&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to enable maintenance mode immediately, but show a countdown to your users, execute the same script with the --enablelater parameter and the number of minutes which the countdown should run:&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enablelater=10&lt;br /&gt;
&lt;br /&gt;
This script will also create and remove the climaintenance.html file for &amp;quot;Offline&amp;quot; mode.&lt;br /&gt;
&lt;br /&gt;
== Offline mode ==&lt;br /&gt;
&lt;br /&gt;
In some situations, you may want to switch your Moodle site into offline mode so that it is not accessible via the web but you can not stop the web server completely (typically because there are other web pages and applications running there). If a file called &amp;lt;code&amp;gt;climaintenance.html&amp;lt;/code&amp;gt; exists in the root folder of moodledata directory, Moodle will automatically display the contents of that file instead of any other page.&lt;br /&gt;
&lt;br /&gt;
    $ cd /var/www/sites/moodle/moodledata/&lt;br /&gt;
    $ echo &#039;&amp;amp;lt;h1&amp;amp;gt;Sorry, maintenance in progress&amp;amp;lt;/h1&amp;amp;gt;&#039; &amp;amp;gt; climaintenance.html&lt;br /&gt;
&lt;br /&gt;
You can prepare a nice formatted HTML page to inform your users about the server being down and keep in the moodledata directory under a name like &amp;lt;code&amp;gt;climaintenance.off&amp;lt;/code&amp;gt; and rename it to the &amp;lt;code&amp;gt;climaintenance.html&amp;lt;/code&amp;gt; if needed.&lt;br /&gt;
&lt;br /&gt;
== Custom site defaults ==&lt;br /&gt;
&lt;br /&gt;
During the install and upgrade via CLI, Moodle sets the administration variables to the default values. You can use different defaults. See MDL-17850 for details. Shortly, all you need to do is to add a file &amp;lt;code&amp;gt;local/defaults.php&amp;lt;/code&amp;gt; into your Moodle installation. The format of the file is like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$defaults[&#039;pluginname&#039;][&#039;settingname&#039;] = &#039;settingvalue&#039;; // for plugins&lt;br /&gt;
$defaults[&#039;moodle&#039;][&#039;settingname&#039;] = &#039;settingvalue&#039;;     // for core settings&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These defaults are used during install, upgrade and are also displayed as defaults on Site administration pages.&lt;br /&gt;
&lt;br /&gt;
== Reset user password ==&lt;br /&gt;
&lt;br /&gt;
If you happen to forget your admin password (or you want to set a password for any other user on the site), you can use reset_password.php script. The script sets the correctly salted password for the given user.&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/reset_password.php&lt;br /&gt;
&lt;br /&gt;
== MySQL storage engine conversion ==&lt;br /&gt;
&lt;br /&gt;
If you run your Moodle site with MySQL database backend and use the default MyISAM as the storage engine for your tables, you may want to convert them to use some more reliable engine like InnoDB (actually, you should want to switch to PostgreSQL ;-) anyway).&lt;br /&gt;
&lt;br /&gt;
    $ sudo -u apache /usr/bin/php admin/cli/mysql_engine.php --engine=InnoDB&lt;br /&gt;
&lt;br /&gt;
==Converting InnoDB tables to Barracuda==&lt;br /&gt;
&lt;br /&gt;
Sites using MySQL with database tables using Antelope as the file format are recommended to convert the tables to the Barracuda file format.&lt;br /&gt;
&lt;br /&gt;
This is because tables using Antelope as the file format cannot handle more than 10 text columns. This file formats only supports &#039;&#039;compact&#039;&#039; and &#039;&#039;redundant&#039;&#039; row formats for backward compatibility reasons. This may cause a problem on larger sites when restoring a course, in which case the following error will be displayed: &lt;br /&gt;
&lt;br /&gt;
 Row size too large (&amp;gt;8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help.&lt;br /&gt;
&lt;br /&gt;
Barracuda is the newest innoDB file format. In addition to supporting &#039;&#039;compact&#039;&#039; and &#039;&#039;redundant&#039;&#039; row formats, Barracuda also supports &#039;&#039;compressed&#039;&#039; and &#039;&#039;dynamic&#039;&#039; row formats. &lt;br /&gt;
&lt;br /&gt;
However, converting tables to Barracuda is only recommended, and not required, since not all MySQL users are affected. (It may only be a problem for larger sites.)&lt;br /&gt;
&lt;br /&gt;
===Tool for converting tables===&lt;br /&gt;
&lt;br /&gt;
A command line tool is included in Moodle for converting tables to Barracuda.&lt;br /&gt;
&lt;br /&gt;
To view tables requiring conversion, use the list option:&lt;br /&gt;
&lt;br /&gt;
 $ php admin/cli/mysql_compressed_rows.php --list&lt;br /&gt;
&lt;br /&gt;
Here is an example output:&lt;br /&gt;
&lt;br /&gt;
 mdl_data                            Compact     (needs fixing) &lt;br /&gt;
 mdl_data_fields                     Compact     (needs fixing)&lt;br /&gt;
 mdl_enrol_paypal                    Compact     (needs fixing)&lt;br /&gt;
&lt;br /&gt;
To proceed with the conversion, run the command using the fix option:&lt;br /&gt;
&lt;br /&gt;
 $ php admin/cli/mysql_compressed_rows.php --fix&lt;br /&gt;
&lt;br /&gt;
Successful table conversion will be reported in the output, for example:&lt;br /&gt;
&lt;br /&gt;
 mdl_data                   ... Compressed&lt;br /&gt;
 mdl_data_fields            ... Compressed&lt;br /&gt;
 mdl_enrol_paypal           ... Compressed&lt;br /&gt;
&lt;br /&gt;
Please note that the commands must be executed on your moodle directory. Once tables are fixed, the warning message will no longer be displayed.&lt;br /&gt;
 &lt;br /&gt;
For further information on InnoDB file formats see the [http://dev.mysql.com/doc/innodb/1.1/en/glossary.html#glos_antelope MySQL InnoDB glossary - Antelope] and the [http://dev.mysql.com/doc/innodb/1.1/en/glossary.html#glos_barracuda MySQL InnoDB glossary - Barracuda].&lt;br /&gt;
&lt;br /&gt;
If you get errors due to having insufficient privileges to run these commands (this is quite likely) then the easiest solution is to generate the required SQL commands using,&lt;br /&gt;
&lt;br /&gt;
 $ php admin/cli/mysql_compressed_rows.php --showsql&lt;br /&gt;
&lt;br /&gt;
You can then copy the generated SQL into your mysql client running as the &#039;root&#039; user.&lt;br /&gt;
&lt;br /&gt;
==Converting to the new character set and collation==&lt;br /&gt;
&lt;br /&gt;
 $ php admin/cli/mysql_collation.php --collation=utf8mb4_unicode_ci&lt;br /&gt;
&lt;br /&gt;
== Running cron via command line ==&lt;br /&gt;
&lt;br /&gt;
In versions 1.x, you could execute admin/cron.php either from command line or via the web. Since Moodle 2.0, only admin/cli/cron.php script can be run via command line.&lt;br /&gt;
&lt;br /&gt;
== Scheduled tasks ==&lt;br /&gt;
&lt;br /&gt;
Scheduled tasks are automatically run by the cron script, but the specific tasks which run on each cron iteration are determined by the scheduled tasks configuration. It is possible to override the scheduled tasks configuration and run a single scheduled task immediately using the admin/tool/task/cli/schedule_task.php script. &lt;br /&gt;
&lt;br /&gt;
This script accepts the following arguments:&lt;br /&gt;
&lt;br /&gt;
 --list - list all the known scheduled tasks. The tasks are listed by the class name used to run the task. This class name is required as the argument to the next option in order to run a specific task immediately.&lt;br /&gt;
&lt;br /&gt;
 --execute=&amp;lt;task&amp;gt; - Runs a single scheduled task immediately - regardless of scheduling settings. This will even run disabled tasks. Tasks will still use locking to prevent concurrent execution of the same task - even on clusters. The format of the &amp;lt;task&amp;gt; argument must be the same as returned by the --list option above.&lt;br /&gt;
&lt;br /&gt;
 --showsql - Shows sql queries before they are execute&lt;br /&gt;
&lt;br /&gt;
 --showdebugging - Shows developer debugging info&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; You must escape the &amp;quot;\&amp;quot; with an extra \ when using the --execute command. Take the following for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php schedule_task.php --list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will return something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== List of scheduled tasks (http://yourserver.com/moodle) ==&lt;br /&gt;
\enrol_imsenterprise\task\cron_task                10 * * * * *      ASAP&lt;br /&gt;
\logstore_legacy\task\cleanup_task                 * 5 * * * *       ASAP&lt;br /&gt;
\logstore_standard\task\cleanup_task               * 4 * * * *       Wednesday, November 12, 2014, 4:35 AM&lt;br /&gt;
\mod_forum\task\cron_task                          * * * * * *       ASAP&lt;br /&gt;
\core\task\automated_backup_task                   50 * * * * *      ASAP&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the first task in that list, you would execute&lt;br /&gt;
&lt;br /&gt;
 php schedule_task.php --execute=&#039;\enrol_imsenterprise\task\cron_task&#039;&lt;br /&gt;
&lt;br /&gt;
Be aware of the single quotes. Without them, you would need to use double backlashes to avoid escaping by the shell.&lt;br /&gt;
&lt;br /&gt;
==Database transfer==&lt;br /&gt;
&lt;br /&gt;
A command line script for [[Database transfer]] may be found in &#039;&#039;admin/tool/dbtransfer/cli/migrate.php&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Purge caches==&lt;br /&gt;
&lt;br /&gt;
You can purge caches using this script:&lt;br /&gt;
&lt;br /&gt;
  php admin/cli/purge_caches.php&lt;br /&gt;
&lt;br /&gt;
==Kill all sessions==&lt;br /&gt;
If needed for administrative reasons, you can kill all user sessions using this script:&lt;br /&gt;
&lt;br /&gt;
 php admin/cli/kill_all_sessions.php&lt;br /&gt;
&lt;br /&gt;
As a result, all users will be logged out from Moodle.&lt;br /&gt;
&lt;br /&gt;
==Fix course / module sequences==&lt;br /&gt;
&lt;br /&gt;
In rare cases (such as after upgrading from a very old version of Moodle), the course / section / module sequence data can be out of sync. This can cause various problems for affected courses, such as sections not appearing, backups failing, pages not displaying etc. There is a specific check to check for errors caused by this problem, and to fix the data in the database if they are found. To run this script please use the command below:&lt;br /&gt;
&lt;br /&gt;
  php admin/cli/fix_course_sequence.php -c=* --fix&lt;br /&gt;
&lt;br /&gt;
This will check every course in Moodle and report which ones had errors and were fixed.&lt;br /&gt;
&lt;br /&gt;
==Fix orphaned question categories==&lt;br /&gt;
&lt;br /&gt;
When a quiz is created, a new question category for the quiz is automatically created. In versions of Moodle prior to 2.9.1, if the quiz is deleted, the question category and any questions in the category remain in database. These orphaned question categories may be fixed by running the admin/cli/fix_orphaned_question_categories.php script with the --fix option.&lt;br /&gt;
&lt;br /&gt;
==Search and replace text==&lt;br /&gt;
&lt;br /&gt;
This script can be used to search and replace text throughout the whole database. Use carefully and backup first always. More info in [[Search and replace tool]].&lt;br /&gt;
&lt;br /&gt;
  php admin/tool/replace/cli/replace.php --search=//oldsitehost --replace=//newsitehost&lt;br /&gt;
&lt;br /&gt;
==Build theme CSS cache==&lt;br /&gt;
&lt;br /&gt;
If Moodle is not running in theme designer mode it will keep a copy of the compiled CSS on local disk and serve that to the browser when it requests a page. If there isn&#039;t a copy on local disk then a copy will be built the first time a page within Moodle is requested. &lt;br /&gt;
&lt;br /&gt;
With this script you can pre-compile the cached CSS files for themes within Moodle to avoid having a user wait for the theme to compile during the first page request.&lt;br /&gt;
&lt;br /&gt;
  php admin/cli/build_theme_css.php --themes boost&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* MDL-35736 - Manage plugins via command line&lt;br /&gt;
* MDL-36237 - Resort course list via CLI&lt;br /&gt;
* [http://moosh-online.com/ MOOSH] - MOOdle SHell. It is a commandline tool that will allow you to perform most common Moodle tasks.&lt;br /&gt;
&lt;br /&gt;
[[fr:Administration en ligne de commande]]&lt;br /&gt;
[[de:Administration über Kommandozeile]]&lt;br /&gt;
[[es:Administración por línea de comando]]&lt;br /&gt;
[[it:Amministrazione via linea di comando]]&lt;br /&gt;
[[ja:コマンドライン経由の管理]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Server_cluster&amp;diff=135177</id>
		<title>Server cluster</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Server_cluster&amp;diff=135177"/>
		<updated>2019-08-31T11:49:14Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is going to describe some basic information related to server clustering...&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
* database server - ACID compliant, for example PostgreSQL and MariaDB&lt;br /&gt;
* main server that is able to share dataroot - locking support recommended, for example NFS&lt;br /&gt;
* load balancer - for example Nginx&lt;br /&gt;
* cluster nodes - web servers&lt;br /&gt;
* Redis (or Memcached) server for shared MUC caches&lt;br /&gt;
&lt;br /&gt;
Note: this guide is not intended for Windows OS or any other Microsoft technologies.&lt;br /&gt;
&lt;br /&gt;
==Initial installation==&lt;br /&gt;
&lt;br /&gt;
# Perform standard CLI installation on the main server using shared database and dataroot directory.&lt;br /&gt;
# Setup web servers on cluster nodes - use local dirroot and shared database and dataroot.&lt;br /&gt;
# Configure load balancing.&lt;br /&gt;
&lt;br /&gt;
==Related config.php settings==&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;wwwroot===&lt;br /&gt;
It must be the same on all nodes, it must be the public facing URL. It cannot be dynamic.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;sslproxy===&lt;br /&gt;
Enable if you have https:// wwwroot but the SSL is done by load-balancer instead of web server.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
Enable &#039;&#039;Secure cookies only&#039;&#039; to make your site really secure, without it cookie stealing is still trivial.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;reverseproxy===&lt;br /&gt;
Enable if your nodes are accessed via different URL.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dirroot===&lt;br /&gt;
It is strongly recommended that $CFG-&amp;gt;dirroot (which is automatically set via realpath(config.php)) contains the same path on all nodes. It does not need to point to the same shared directory though. The reason is that some some low level code may use the dirroot value for cache invalidation.&lt;br /&gt;
&lt;br /&gt;
The simplest solution is to have the same directory structure on each cluster node and synchronise these during each upgrade.&lt;br /&gt;
&lt;br /&gt;
The dirroot should be always read only for apache process because otherwise built in plugin installation and uninstallation would get the nodes out of sync.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dataroot===&lt;br /&gt;
&lt;br /&gt;
This &#039;&#039;&#039;MUST&#039;&#039;&#039; be a shared directory where each cluster node is accessing the files directly. It must be very reliable, administrators cannot manipulate files directly.&lt;br /&gt;
&lt;br /&gt;
Locking support is not required, if any code tries to use file locks in dataroot outside of cachedir or muc directory it is a bug.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;tempdir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;cachedir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localcachedir===&lt;br /&gt;
&lt;br /&gt;
The difference from $CFG-&amp;gt;cachedir is that the directory does not have to be shared by all cluster nodes, the file contents do not change. Use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
==Performance recommendations==&lt;br /&gt;
&lt;br /&gt;
#Use OPcache extension on all cluster nodes.&lt;br /&gt;
#Set $CFG-&amp;gt;localcachedir to fast local filesystem on each node.&lt;br /&gt;
#Use one big central memcached server for all shared caches that support it.&lt;br /&gt;
#Use local memcached instances on cluster nodes for local caches that support it.&lt;br /&gt;
#Store user sessions in one shared memcached server. (See [[Session_handling]] for details)&lt;br /&gt;
#Use fast local directory for dirroot on each cluster node.&lt;br /&gt;
#Use dynamic cluster node management.&lt;br /&gt;
#Use transparent proxy servers.&lt;br /&gt;
&lt;br /&gt;
==Upgrade procedure==&lt;br /&gt;
&lt;br /&gt;
#Disable load balancer.&lt;br /&gt;
#Upgrade dirroot files on master server.&lt;br /&gt;
#Perform CLI upgrade.&lt;br /&gt;
#Manually reset all caches in cluster nodes - restart web server, delete localcachedir and temp directories, restart memcached, etc. Or delete all cluster nodes and create nodes from a new template.&lt;br /&gt;
#Enable load balancer.&lt;br /&gt;
&lt;br /&gt;
==Step by step guide for server clustering in Moodle 2.6==&lt;br /&gt;
From hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547 https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
&lt;br /&gt;
* 1 Determine your specific need for caches. This involves the concepts of shared cache or local cache, disk based cache or server based cache or protocol specific cache like Memcached or MongoDB. &lt;br /&gt;
** 1.1 If you have a slow shared disk, you might benefit from a local disk cache.&lt;br /&gt;
** 1.2 If you have only a few users on your Moodle site, you might not want to set up a Memcached service, even if the acceleration that Memcached provides, is very significant for the user experience.&lt;br /&gt;
** 1.3 If you want to do anything in your power for accelerating the site, you might consider MongoDB.&lt;br /&gt;
* 2 Configure the caches, test them and verify them. There is room for improvement in the examples for cache configuration. This is probably the most difficult step.&lt;br /&gt;
* 3 Install the cache support on server level. This may involve installing php modules or config for php modules.&lt;br /&gt;
* 4 Create a cache instance in MUC here: example.com/cache/admin.php?action=addstore&amp;amp;plugin=memcached&lt;br /&gt;
** 4.1 Give the cache instance some arbitrary name.&lt;br /&gt;
** 4.2 All other fields have a question mark that can be clicked on for excellent help that tells you what to fill in, and the syntax (very important).&lt;br /&gt;
** 4.3 The result should be a Configured Store Instance, with the name of your choice.&lt;br /&gt;
* 5 The final step is to deploy the created cache instances by Editing Mappings for e.g. Language string cache in the list of Known cache definitions.&lt;br /&gt;
** 5.1  While experimenting with this, I have found it a life saver to open a separate browser window, where the default setting is selected, so I just need to click on the Save button to revert the setting, just in case I lose contact with the site.&lt;br /&gt;
** 5.2 Select the name of your configured store instance from the dropdown list and click on the Save button. &lt;br /&gt;
** 5.3 Test the new cache setting. If you lose contact with the site or it behaves weirdly, try using the trick in step 1. In case of emergency you might remove the cache config file (muc/config.php) in the folder pointed to by $CFG-&amp;gt;dataroot .  It seems that Moodle writes a new default config file if it is missing.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Performance recommendations]]&lt;br /&gt;
*[[Caching]]&lt;br /&gt;
*[[:dev:Server clustering improvements proposal]]&lt;br /&gt;
*Hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
*How to Cluster Moodle on Multiple Servers for High Availability and Scalability [http://www.severalnines.com/blog/clustering-moodle-multiple-servers-high-availability-scalability]&lt;br /&gt;
* PHP session cache in a cluster &lt;br /&gt;
** https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04&lt;br /&gt;
** https://inchoo.net/magento/programming-magento/session-storage-php&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Server_cluster&amp;diff=135176</id>
		<title>Server cluster</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Server_cluster&amp;diff=135176"/>
		<updated>2019-08-31T11:34:42Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is going to describe some basic information related to server clustering...&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
* database server - ACID compliant, for example PostgreSQL and MariaDB&lt;br /&gt;
* main server that is able to share dataroot - locking support recommended, for example NFS&lt;br /&gt;
* load balancer - for example Nginx&lt;br /&gt;
* cluster nodes - web servers&lt;br /&gt;
* Redis (or Memcached) server for shared MUC caches&lt;br /&gt;
&lt;br /&gt;
Note: this guide is not intended for Windows OS or any other Microsoft technologies.&lt;br /&gt;
&lt;br /&gt;
==Initial installation==&lt;br /&gt;
&lt;br /&gt;
# Perform standard CLI installation on the main server using shared database and dataroot directory.&lt;br /&gt;
# Setup web servers on cluster nodes - use local dirroot and shared database and dataroot.&lt;br /&gt;
# Configure load balancing.&lt;br /&gt;
&lt;br /&gt;
==Related config.php settings==&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;wwwroot===&lt;br /&gt;
It must be the same on all nodes, it must be the public facing URL. It cannot be dynamic.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;sslproxy===&lt;br /&gt;
Enable if you have https:// wwwroot but the SSL is done by load-balancer instead of web server.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
Enable &#039;&#039;Secure cookies only&#039;&#039; to make your site really secure, without it cookie stealing is still trivial.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;reverseproxy===&lt;br /&gt;
Enable if your nodes are accessed via different URL.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dirroot===&lt;br /&gt;
It is strongly recommended that $CFG-&amp;gt;dirroot (which is automatically set via realpath(config.php)) contains the same path on all nodes. It does not need to point to the same shared directory though. The reason is that some some low level code may use the dirroot value for cache invalidation.&lt;br /&gt;
&lt;br /&gt;
The simplest solution is to have the same directory structure on each cluster node and synchronise these during each upgrade.&lt;br /&gt;
&lt;br /&gt;
The dirroot should be always read only for apache process because otherwise built in plugin installation and uninstallation would get the nodes out of sync.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dataroot===&lt;br /&gt;
&lt;br /&gt;
This &#039;&#039;&#039;MUST&#039;&#039;&#039; be a shared directory where each cluster node is accessing the files directly. It must be very reliable, administrators cannot manipulate files directly.&lt;br /&gt;
&lt;br /&gt;
Locking support is not required, if any code tries to use file locks in dataroot outside of cachedir or muc directory it is a bug.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;tempdir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;cachedir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localcachedir===&lt;br /&gt;
&lt;br /&gt;
The difference from $CFG-&amp;gt;cachedir is that the directory does not have to be shared by all cluster nodes, the file contents do not change. Use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
==Performance recommendations==&lt;br /&gt;
&lt;br /&gt;
#Use OPcache extension on all cluster nodes.&lt;br /&gt;
#Set $CFG-&amp;gt;localcachedir to fast local filesystem on each node.&lt;br /&gt;
#Use one big central memcached server for all shared caches that support it.&lt;br /&gt;
#Use local memcached instances on cluster nodes for local caches that support it.&lt;br /&gt;
#Store user sessions in one shared memcached server. (See [[Session_handling]] for details)&lt;br /&gt;
#Use fast local directory for dirroot on each cluster node.&lt;br /&gt;
#Use dynamic cluster node management.&lt;br /&gt;
#Use transparent proxy servers.&lt;br /&gt;
&lt;br /&gt;
==Upgrade procedure==&lt;br /&gt;
&lt;br /&gt;
#Disable load balancer.&lt;br /&gt;
#Upgrade dirroot files on master server.&lt;br /&gt;
#Perform CLI upgrade.&lt;br /&gt;
#Manually reset all caches in cluster nodes - restart web server, delete localcachedir and temp directories, restart memcached, etc. Or delete all cluster nodes and create nodes from a new template.&lt;br /&gt;
#Enable load balancer.&lt;br /&gt;
&lt;br /&gt;
==Step by step guide for server clustering in Moodle 2.6==&lt;br /&gt;
From hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547 https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
&lt;br /&gt;
* 1 Determine your specific need for caches. This involves the concepts of shared cache or local cache, disk based cache or server based cache or protocol specific cache like Memcached or MongoDB. &lt;br /&gt;
** 1.1 If you have a slow shared disk, you might benefit from a local disk cache.&lt;br /&gt;
** 1.2 If you have only a few users on your Moodle site, you might not want to set up a Memcached service, even if the acceleration that Memcached provides, is very significant for the user experience.&lt;br /&gt;
** 1.3 If you want to do anything in your power for accelerating the site, you might consider MongoDB.&lt;br /&gt;
* 2 Configure the caches, test them and verify them. There is room for improvement in the examples for cache configuration. This is probably the most difficult step.&lt;br /&gt;
* 3 Install the cache support on server level. This may involve installing php modules or config for php modules.&lt;br /&gt;
* 4 Create a cache instance in MUC here: example.com/cache/admin.php?action=addstore&amp;amp;plugin=memcached&lt;br /&gt;
** 4.1 Give the cache instance some arbitrary name.&lt;br /&gt;
** 4.2 All other fields have a question mark that can be clicked on for excellent help that tells you what to fill in, and the syntax (very important).&lt;br /&gt;
** 4.3 The result should be a Configured Store Instance, with the name of your choice.&lt;br /&gt;
* 5 The final step is to deploy the created cache instances by Editing Mappings for e.g. Language string cache in the list of Known cache definitions.&lt;br /&gt;
** 5.1  While experimenting with this, I have found it a life saver to open a separate browser window, where the default setting is selected, so I just need to click on the Save button to revert the setting, just in case I lose contact with the site.&lt;br /&gt;
** 5.2 Select the name of your configured store instance from the dropdown list and click on the Save button. &lt;br /&gt;
** 5.3 Test the new cache setting. If you lose contact with the site or it behaves weirdly, try using the trick in step 1. In case of emergency you might remove the cache config file (muc/config.php) in the folder pointed to by $CFG-&amp;gt;dataroot .  It seems that Moodle writes a new default config file if it is missing.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Performance recommendations]]&lt;br /&gt;
*[[Caching]]&lt;br /&gt;
*[[:dev:Server clustering improvements proposal]]&lt;br /&gt;
*Hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
*How to Cluster Moodle on Multiple Servers for High Availability and Scalability [http://www.severalnines.com/blog/clustering-moodle-multiple-servers-high-availability-scalability]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=APC_user_cache_(APCu)&amp;diff=135172</id>
		<title>APC user cache (APCu)</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=APC_user_cache_(APCu)&amp;diff=135172"/>
		<updated>2019-08-30T08:14:39Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Installation of APC */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
==About using APCu in Moodle==&lt;br /&gt;
&lt;br /&gt;
APC provides a shared application cache that is usually very limited in size but provides excellent performance. It doesn&#039;t provide the ability to configure multiple instances of itself and as such within Moodle you are only able to create a single APC cache store instance. Because of its incredible performance but very limited size it is strongly suggested that you map only small, crucial caches to the APC store.&lt;br /&gt;
&lt;br /&gt;
Another important thing to understand about the APC store is that it provides no garbage cleaning, or storage reclamation facilities. As such cache data will persist there until APC is restarted or the store is purged. On top of that once the store is full requests to store information within the cache fail until there is once more sufficient space. Because of this it is recommended that you regularly purge or restart APC. Also recommended is to map a secondary application cache instance to any definition with the APC mapped. This ensures that if it does indeed full up that an alternative cache is available.&lt;br /&gt;
&lt;br /&gt;
==Installation of APC==&lt;br /&gt;
&lt;br /&gt;
It is recommended that you read through the APC documentation http://www.php.net/manual/en/book.apc.php before beginning with this plugin. The above documentation recommends installing the PECL APC extension that can be found at http://pecl.php.net/package/apc. http://www.php.net/manual/en/install.pecl.php contains information on installing PECL extensions.&lt;br /&gt;
&lt;br /&gt;
Its also worth noting for this those using Linux that there is usually a &amp;quot;php7[X]u-pecl-apcu&amp;quot; [[https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/repoview/php71u-pecl-apcu.html PHP 7.1 package]] that can be installed very easily. If you have installed PHP under Linux through a package manager then this will be by far the easiest way to proceed.&lt;br /&gt;
&lt;br /&gt;
Once installed ensure you restart your web server before proceeding.&lt;br /&gt;
&lt;br /&gt;
==Making use of APC within Moodle==&lt;br /&gt;
&lt;br /&gt;
The first thing you will need to do is create an APC cache store instance. This is done through the Cache configuration interface.&lt;br /&gt;
&lt;br /&gt;
# Log in as an administrator and go to &#039;Caching &amp;gt; Configuration&#039; in the Site administration.&lt;br /&gt;
# Locate the APC row within the Installed cache stores table. You should see an &amp;quot;Add instance&amp;quot; link within that row. If not then the APC extension has not being installed correctly.&lt;br /&gt;
# Click &amp;quot;Add instance&amp;quot;.&lt;br /&gt;
# Give the new instance a name and click &amp;quot;Save changes&amp;quot;. You should be directed back to the configuration page.&lt;br /&gt;
# Locate the Configured cache store instances table and ensure there is now a row for you APC instance and that it has a green tick in the ready column.&lt;br /&gt;
&lt;br /&gt;
Once done you have an APC instance that is ready to be used. The next step is to map definitions to make use of the APC instance.&lt;br /&gt;
&lt;br /&gt;
# Locate the known cache definitions table. This table lists the caches being used within Moodle at the moment. For each cache you should be able to Edit mappings.&lt;br /&gt;
# Find a cache that you would like to map to the APC instance and click Edit mappings.&lt;br /&gt;
# One the next screen proceed to select your APC instance as the primary cache and save changes.&lt;br /&gt;
# Back in the known cache definitions table you should now see your APC instance listed under the store mappings for the cache you had selected. You can proceed to map as many or as few cache definitions to the APC instance as you see fit.&lt;br /&gt;
&lt;br /&gt;
That is it! you are now using APC within Moodle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* MDL-39117&lt;br /&gt;
&lt;br /&gt;
[[de:APC User Cache]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Redis_cache_store&amp;diff=135023</id>
		<title>Redis cache store</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Redis_cache_store&amp;diff=135023"/>
		<updated>2019-08-10T08:55:13Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Installing Redis server */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
The Redis cache store is one of the best options to handle session and application cache as it supports: data guarantee, locking, key awareness. (and also can be used for [[Session_handling#Redis_session_driver|user&#039;s sessions caching]] in the config.php file)&lt;br /&gt;
&lt;br /&gt;
Before Redis is available as a cache store, you will need to install [[Redis]] service (daemon) on your Moodle server, locally in case of a single Moodle app node architecture or externally if you are using a cluster of Moodle nodes. only then, you can configure Redis as an application or session level cache store.&lt;br /&gt;
&lt;br /&gt;
If you are configuring a cluster of Moodle servers/nodes, the [[Redis]] service (daemon) should be installed on an external server and all Moodle nodes (servers/instances) should point to that external Redis. so all user&#039;s data is available when the user is using (connected to) any of the Moodle nodes, in case the user&#039;s connection is not persistent (sticky) to a specific node for the entire Moodle session. An external Redis (NoSQL) service can be installed on the main SQL server alongside the MySQL/MariaDB service, just make sure you have enough memory allocated on that server for both services. &lt;br /&gt;
&lt;br /&gt;
A good practice is to give the [[Redis]] cache store prefix a proper short name and not leave it empty, as later on, it might conflict with user&#039;s session Redis cache you might choose to use, or other Moodle instances that will be installed on the same server. for example &amp;quot;my-school-name_cs_&amp;quot;, where you replace &amp;quot;my-school-name&amp;quot; with your short school name. (and if you are also using a user&#039;s session store on the config.php file, you might like to prefix it with &amp;quot;my-school-name_us_&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
When using a cluster setup with several Moodle instances on each node that belong to different Schools/Institutes/clients, make sure that you use the same Prefix for all Moodle instances that are on different nodes and are of the same School/Institute/Client.&lt;br /&gt;
&lt;br /&gt;
==Installing Redis server==&lt;br /&gt;
* [https://www.linode.com/docs/databases/redis/install-and-configure-redis-on-centos-7 install and configure redis on centos 7]&lt;br /&gt;
* [https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-18-04 install and configure redis on Ubuntu 18.04]&lt;br /&gt;
* [[Session_handling#Redis_session_driver]] and [https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04 How to Set Up a Redis Server as a Session Handler for PHP]&lt;br /&gt;
* Install [https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/repoview/redis5.html Redis 5] via IUS CentOS 7 repository.&lt;br /&gt;
&lt;br /&gt;
==Installing Redis php driver==&lt;br /&gt;
* For CentOS, you can use either [https://rpms.remirepo.net/ Remi] or [https://ius.io/ IUS] repositories, and install the [https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/repoview/php71u-pecl-redis.html php71u-pecl-redis] driver.&lt;br /&gt;
* [https://gist.github.com/hollodotme/418e9b7c6ebc358e7fda Redis php-fpm 7 driver on Ubuntu 14.04]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://gist.github.com/kabel/10023961 Monitor Redis stats (a php one page app)]&lt;br /&gt;
* MDL-48468 : Add a Redis cache store to Moodle core&lt;br /&gt;
&lt;br /&gt;
[[de:Redis Cache]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Redis_cache_store&amp;diff=135022</id>
		<title>Redis cache store</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Redis_cache_store&amp;diff=135022"/>
		<updated>2019-08-10T08:54:44Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Installing Redis server */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
The Redis cache store is one of the best options to handle session and application cache as it supports: data guarantee, locking, key awareness. (and also can be used for [[Session_handling#Redis_session_driver|user&#039;s sessions caching]] in the config.php file)&lt;br /&gt;
&lt;br /&gt;
Before Redis is available as a cache store, you will need to install [[Redis]] service (daemon) on your Moodle server, locally in case of a single Moodle app node architecture or externally if you are using a cluster of Moodle nodes. only then, you can configure Redis as an application or session level cache store.&lt;br /&gt;
&lt;br /&gt;
If you are configuring a cluster of Moodle servers/nodes, the [[Redis]] service (daemon) should be installed on an external server and all Moodle nodes (servers/instances) should point to that external Redis. so all user&#039;s data is available when the user is using (connected to) any of the Moodle nodes, in case the user&#039;s connection is not persistent (sticky) to a specific node for the entire Moodle session. An external Redis (NoSQL) service can be installed on the main SQL server alongside the MySQL/MariaDB service, just make sure you have enough memory allocated on that server for both services. &lt;br /&gt;
&lt;br /&gt;
A good practice is to give the [[Redis]] cache store prefix a proper short name and not leave it empty, as later on, it might conflict with user&#039;s session Redis cache you might choose to use, or other Moodle instances that will be installed on the same server. for example &amp;quot;my-school-name_cs_&amp;quot;, where you replace &amp;quot;my-school-name&amp;quot; with your short school name. (and if you are also using a user&#039;s session store on the config.php file, you might like to prefix it with &amp;quot;my-school-name_us_&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
When using a cluster setup with several Moodle instances on each node that belong to different Schools/Institutes/clients, make sure that you use the same Prefix for all Moodle instances that are on different nodes and are of the same School/Institute/Client.&lt;br /&gt;
&lt;br /&gt;
==Installing Redis server==&lt;br /&gt;
* [https://www.linode.com/docs/databases/redis/install-and-configure-redis-on-centos-7 install and configure redis on centos 7]&lt;br /&gt;
* [https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-18-04 install and configure redis on Ubuntu 18.04]&lt;br /&gt;
* [[Session_handling#Redis_session_driver]] and [https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04 How to Set Up a Redis Server as a Session Handler for PHP]&lt;br /&gt;
* [https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/repoview/redis5.html Redis 5] from IUS CentOS 7 repository.&lt;br /&gt;
&lt;br /&gt;
==Installing Redis php driver==&lt;br /&gt;
* For CentOS, you can use either [https://rpms.remirepo.net/ Remi] or [https://ius.io/ IUS] repositories, and install the [https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/repoview/php71u-pecl-redis.html php71u-pecl-redis] driver.&lt;br /&gt;
* [https://gist.github.com/hollodotme/418e9b7c6ebc358e7fda Redis php-fpm 7 driver on Ubuntu 14.04]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://gist.github.com/kabel/10023961 Monitor Redis stats (a php one page app)]&lt;br /&gt;
* MDL-48468 : Add a Redis cache store to Moodle core&lt;br /&gt;
&lt;br /&gt;
[[de:Redis Cache]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Performance_recommendations&amp;diff=135021</id>
		<title>Performance recommendations</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Performance_recommendations&amp;diff=135021"/>
		<updated>2019-08-10T08:28:42Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* MemCached */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
Moodle can be made to perform very well, at small usage levels or scaling up to many thousands of users. The factors involved in performance are basically the same as for any PHP-based database-driven system. When trying to optimize your server, try to focus on the factor which will make the most difference to the user. For example, if you have relatively more users browsing than accessing the database, look to improve the webserver performance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Obtain a baseline benchmark==&lt;br /&gt;
&lt;br /&gt;
Before attempting any optimization, you should obtain a baseline benchmark of the component of the system you are trying to improve. For Linux try [http://lbs.sourceforge.net/ LBS] and for Windows use the Performance Monitor. Once you have quantitative data about how your system is performing currently, you&#039;ll be able to determine if the change you have made has had any real impact.&lt;br /&gt;
&lt;br /&gt;
The overall aim of adjustments to improve performance is to use RAM (cacheing) and to reduce disk-based activity. It is especially important to try to eliminate swap file usage as much as you can. If your system starts swapping, this is a sign that you need more RAM. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;optimization order preference&#039;&#039;&#039; is usually: primary storage (more RAM), secondary storage (faster hard disks/improved hard disk configuration), processor (more and faster).&lt;br /&gt;
&lt;br /&gt;
It can be interesting to install and use the [https://moodle.org/plugins/report_benchmark Benchmark plugin] in order to find the bottlenecks of your system that specifically affect Moodle.&lt;br /&gt;
&lt;br /&gt;
==Scalability==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s design (with clear separation of application layers) allows for strongly scalable setups. (Please check the list of [[Large installations|large Moodle installations]].)&lt;br /&gt;
&lt;br /&gt;
Large sites usually separate the web server and database onto separate servers, although for smaller installations this is typically not necessary.&lt;br /&gt;
&lt;br /&gt;
It is possible to load-balance a Moodle installation, for example by using more than one webserver. The separate webservers should query the same database and refer to the same filestore and cache areas (see [[Caching]]), but otherwise the separation of the application layers is complete enough to make this kind of clustering feasible. Similarly, the database could be a cluster of servers (e.g. a MySQL cluster), but this is not an easy task and you should seek expert support, e.g. from a Moodle Partner.&lt;br /&gt;
&lt;br /&gt;
===Server cluster===&lt;br /&gt;
&lt;br /&gt;
Using Moodle forum discussions:&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=57202 Moodle clustering]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=44470 Software load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=49986 TCP load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=88214 Installation for 3000 simultaneous users]&lt;br /&gt;
&lt;br /&gt;
==Hardware configuration==&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: The fastest and most effective change that you can make to improve performance is to &#039;&#039;&#039;increase the amount of RAM on your web server&#039;&#039;&#039; - get as much as possible (e.g. 4GB or more). Increasing primary memory will reduce the need for processes to swap to disk and will enable your server to handle more users.&lt;br /&gt;
* Better performance is gained by obtaining the best &#039;&#039;&#039;processor capability&#039;&#039;&#039; you can, i.e. dual or dual core processors. A modern BIOS should allow you to enable hyperthreading, but check if this makes a difference to the overall performance of the processors by using a [http://en.wikipedia.org/wiki/Super_PI CPU benchmarking tool].&lt;br /&gt;
* If you can afford them, use &#039;&#039;&#039;SCSI hard disks&#039;&#039;&#039; instead of SATA drives. SATA drives will increase your system&#039;s CPU utilization, whereas SCSI drives have their own integrated processors and come into their own when you have multiple drives. If you must have SATA drives, check that your motherboard and the drives themselves support NCQ (Native Command Queuing).&lt;br /&gt;
* Purchase hard disks with a &#039;&#039;&#039;low seek time&#039;&#039;&#039;. This will improve the overall speed of your system, especially when accessing Moodle&#039;s reports.&lt;br /&gt;
* Size your &#039;&#039;&#039;swap file&#039;&#039;&#039; correctly. The general advice is to set it to 4 x physical RAM.&lt;br /&gt;
* Use a &#039;&#039;&#039;RAID disk system&#039;&#039;&#039;. Although there are many different RAID configurations you can create, the following generally works best:&lt;br /&gt;
** install a hardware RAID controller (if you can)&lt;br /&gt;
** the operating system and swap drive on one set of disks configured as RAID-1.&lt;br /&gt;
** Moodle, Web server and Database server on another set of disks configured as RAID-5.&lt;br /&gt;
* If your &#039;moodledata&#039; area is going to be on relatively slow storage (e.g. NFS mount on to a NAS device) you will probably have performance issues with the default cache configuration (which writes to this storage). See the page on [[Caching]] and consider an alternative. Using [https://en.wikipedia.org/wiki/GlusterFS GlusterFS] / [https://en.wikipedia.org/wiki/OCFS2 OCFS2] / [https://en.wikipedia.org/wiki/GFS2 GFS2] on a [https://en.wikipedia.org/wiki/Storage_Area_Network SAN] device and [https://en.wikipedia.org/wiki/Fibre_Channel Fiber Channel] could improve performance (See more info on the Moodle [https://moodle.org/mod/forum/discuss.php?d=214680#p1123124 forum thread], [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 NFS performance tuing] )&lt;br /&gt;
* Use &#039;&#039;&#039;gigabit ethernet&#039;&#039;&#039; for improved latency and throughput. This is especially important when you have your webserver and database server separated out on different hosts.&lt;br /&gt;
* Check the settings on your &#039;&#039;&#039;network card&#039;&#039;&#039;. You may get an improvement in performance by increasing the use of buffers and transmit/receive descriptors (balance this with processor and memory overheads) and off-loading TCP checksum calculation onto the card instead of the OS.&lt;br /&gt;
*  Read this [http://moodle.org/mod/forum/discuss.php?d=68579 Case Study] on a server stress test with 300 users.  &lt;br /&gt;
* See this [http://elearning.sgu.ac.jp/doc/PT/ accompanying report] on network traffic and server loads.&lt;br /&gt;
* Also see this SFSU presentation at Educause (using VMWare): [http://www.educause.edu/Resources/AnOpenSourceLMSforaMissionCrit/162843]&lt;br /&gt;
&lt;br /&gt;
==Operating System==&lt;br /&gt;
* You can use [http://en.wikipedia.org/wiki/Linux Linux](recommended), Unix-based, Windows or Mac OS X for the server &#039;&#039;&#039;operating system&#039;&#039;&#039;. *nix operating systems generally require less memory than Mac OS X or Windows servers for doing the same task as the server is configured with just a shell interface. Additionally Linux does not have licensing fees attached, but can have a big learning curve if you&#039;re used to another operating system. If you have a large number of processors running SMP, you may also want to consider using a highly tuned OS such as [http://en.wikipedia.org/wiki/Solaris_Operating_Environment Solaris].&lt;br /&gt;
* Check your own OS and &#039;&#039;&#039;vendor specific instructions&#039;&#039;&#039; for optimization steps.&lt;br /&gt;
** For Linux look at the [http://linuxperf.sourceforge.net/ Linux Performance Team] site. &lt;br /&gt;
** For Linux investigate the hdparm command, e.g. hdparm -m16 -d1 can be used to enable read/write on multiple sectors and DMA. Mount disks with the [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 &amp;quot;async&amp;quot; and &amp;quot;noatime&amp;quot;] options.&lt;br /&gt;
** For Windows set the sever to be optimized for network applications (Control Panel, Network Connections, LAN connection, Properties, File &amp;amp; Printer Sharing for Microsoft Networks, Properties, Optimization). You can also search the [http://technet.microsoft.com/ Microsoft TechNet site] for optimization documents.&lt;br /&gt;
&lt;br /&gt;
==Web server performance==&lt;br /&gt;
&lt;br /&gt;
Installing [http://www.mozilla.com/en-US/ Firefox] and the [https://addons.mozilla.org/en-US/firefox/addon/1843 firebug] extension will allow you to watch the time it takes for each page component to load. Also, the [https://addons.mozilla.org/en-US/firefox/addon/5369 Yslow] extension will evaluate your page against Yahoo&#039;s [http://www.skrenta.com/2007/05/14_rules_for_fast_web_pages_by_1.html 14 rules], full text [http://developer.yahoo.com/performance/rules.html Best Practices for Speeding Up Your Web Site], &amp;lt;strike&amp;gt;([http://video.yahoo.com/video/play?vid=1040890 video])&amp;lt;/strike&amp;gt; for fast loading websites.&lt;br /&gt;
&lt;br /&gt;
===PHP performance===&lt;br /&gt;
* You are strongly recommended to use a &#039;&#039;&#039;PHP accelerator&#039;&#039;&#039; to ease CPU load, such as [http://pecl.php.net/apc APC], [http://www.php-accelerator.co.uk/ PHPA], [http://trac.lighttpd.net/xcache/ Xcache], [http://sourceforge.net/projects/wincache WinCache] or [http://eaccelerator.net/ eAccelerator]. (Take care to choose a PHP accelerator that is known to work well with your version of PHP and note that Turck MMCache is [http://turckmmcache.exeprod.com/TheManifestoEnglish no longer maintained] and can cause failures with PHP 5). PHP 5.5 (and newer) includes OpCache and is fully supported and recommended by Moodle&lt;br /&gt;
* Improvements in read/write performance can be improved by putting the cached PHP pages on a [[TMPFS]] filesystem - but remember that you&#039;ll lose the cache contents when there is a power failure or the server is rebooted.&lt;br /&gt;
* Performance of PHP is better when installed as an &#039;&#039;&#039;Apache/IIS6 ISAPI module&#039;&#039;&#039; (rather than a CGI). IIS 7.0/7.5 (Windows Server 2008/R2) users should choose a FastCGI installation for best performance.&lt;br /&gt;
* Also check the &#039;&#039;&#039;memory_limit&#039;&#039;&#039; in php.ini, reduce it to 16M for Moodle version earlier than 1.7 ([http://moodle.org/mod/forum/discuss.php?d=39656 See this forum discussion]). For Moodle 1.7 or later, it is recommended that the value of memory_limit should be 40M. As of [http://www.php.net/ChangeLog-5.php PHP 5.2.1] the default value for the memory_limit directive is 128M.&lt;br /&gt;
* Also see [[PHP_settings_by_Moodle_version]]&lt;br /&gt;
* Use [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html PHP-FPM] (with apache).&lt;br /&gt;
&lt;br /&gt;
===Install HowTo===&lt;br /&gt;
==== APC ====&lt;br /&gt;
* [http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html APC on CentOS 5.x (linux)]&lt;br /&gt;
* [http://fplanque.com/dev/linux/install-apc-php-cache-debian-lenny APC on Debian (linux)]&lt;br /&gt;
==== eAccelerator ====&lt;br /&gt;
* [http://noveckg.blogspot.com/2010/02/installing-eaccelerator-cache-for-php.html Installing eAccelerator on CentOS 5.x (linux)]&lt;br /&gt;
* [https://docs.moodle.org/en/Installing_eAccelerator_In_Ubuntu_Server/ Installing eAccelerator on Ubuntu Server (linux)]&lt;br /&gt;
==== MemCached ====&lt;br /&gt;
Memcached server (daemon)&lt;br /&gt;
* [https://www.tecmint.com/install-memcached-on-centos-7/ Installing Memcached on CentOS 7.x (linux)] (as of php 7.x, only memcached is available)&lt;br /&gt;
* [https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-memcached-on-centos-7 How To Install and Secure Memcached on CentOS 7]&lt;br /&gt;
* [https://wiki.zimbra.com/wiki/Blocking_Memcached_Attack#Iptables_rules_for_Redhat_based_servers Iptables rules for Redhat based servers]&lt;br /&gt;
Memcached PHP 7.1 extension &lt;br /&gt;
* [https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/repoview/php71u-pecl-memcached.html php71u-pecl-memcached] from IUS CentOS 7.x repository.&lt;br /&gt;
&lt;br /&gt;
===Apache performance===&lt;br /&gt;
* If you are using Apache on a Windows server, use the build from [http://www.apachelounge.com Apache Lounge] which is reported to have [http://moodle.org/mod/forum/discuss.php?d=93358 performance and stability improvements] compared to the official Apache download. Note that this is an unofficial build, so may not keep up with official releases.&lt;br /&gt;
* Set the &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; directive correctly (&#039;&#039;&#039;MaxClients&#039;&#039;&#039; before Apache 2.4). Use this formula to help (which uses 80% of available memory to leave room for spare):&lt;br /&gt;
 MaxRequestWorkers = Total available memory * 80% / Max memory usage of apache process&lt;br /&gt;
:Memory usage of apache process is usually 10MB but Moodle can easily use up to 100MB per process, so a general rule of thumb is to divide your available memory in megabytes by 100 to get a conservative setting for MaxClients. You are quite likely to find yourself lowering the MaxRequestWorkers from its default of 150 on a Moodle server. To get a more accurate estimate read the value from the shell command:&lt;br /&gt;
 #ps -ylC httpd --sort:rss&lt;br /&gt;
&lt;br /&gt;
:If you need to increase the value of &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; beyond 256, you will also need to set the &#039;&#039;&#039;ServerLimit&#039;&#039;&#039; directive. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: Do not be tempted to set the value of MaxRequestWorkers higher than your available memory as your server will consume more RAM than available and start to swap to disk. &lt;br /&gt;
* Consider reducing the &#039;&#039;&#039;number of modules&#039;&#039;&#039; that Apache loads in the httpd.conf file to the minumum necessary to reduce the memory needed. &lt;br /&gt;
* Use the &#039;&#039;&#039;latest version of Apache&#039;&#039;&#039; - Apache 2 has an improved memory model which reduces memory usage further.&lt;br /&gt;
* For Unix/Linux systems, consider lowering &#039;&#039;&#039;MaxConnectionsPerChild&#039;&#039;&#039; (&#039;&#039;&#039;MaxRequestsPerChild&#039;&#039;&#039; before Apache 2.4) in httpd.conf to as low as 20-30 (if you set it any lower the overhead of forking begins to outweigh the benefits). &lt;br /&gt;
* For a heavily loaded server, consider setting &#039;&#039;&#039;KeepAlive Off&#039;&#039;&#039; (do this only if your Moodle pages do not contain links to resources or uploaded images) or lowering the &#039;&#039;&#039;KeepAliveTimeout&#039;&#039;&#039; to between 2 and 5. The default is 15 (seconds) - the higher the value the more server processes will be kept waiting for possibly idle connections. A more accurate value for KeepAliveTimeout is obtained by observing how long it takes your users to download a page. After altering any of the KeepAlive variables, monitor your CPU utilization as there may be an additional overhead in initiating more worker processes/threads.&lt;br /&gt;
* As an alternative to using KeepAlive Off, consider setting-up a &#039;&#039;&#039;Reverse Proxy server&#039;&#039;&#039; infront of the Moodle server to cache HTML files with images. You can then return Apache to using keep-alives on the Moodle server.&lt;br /&gt;
* If you do not use a .htaccess file, set the &#039;&#039;&#039;AllowOverride&#039;&#039;&#039; variable to AllowOverride None to prevent .htaccess lookups.&lt;br /&gt;
* Set &#039;&#039;&#039;DirectoryIndex&#039;&#039;&#039; correctly so as to avoid content-negotiation. Here&#039;s an example from a production server:&lt;br /&gt;
 DirectoryIndex index.php index.html index.htm&lt;br /&gt;
* Unless you are doing development work on the server, set &#039;&#039;&#039;ExtendedStatus Off&#039;&#039;&#039; and disable mod_info as well as mod_status.&lt;br /&gt;
* Leave &#039;&#039;&#039;HostnameLookups Off&#039;&#039;&#039; (as default) to reduce DNS latency.&lt;br /&gt;
* Consider reducing the value of &#039;&#039;&#039;TimeOut&#039;&#039;&#039; to between 30 to 60 (seconds). &lt;br /&gt;
* For the &#039;&#039;&#039;Options directive&#039;&#039;&#039;, avoid Options Multiviews as this performs a directory scan. To reduce disk I/O further use&lt;br /&gt;
 Options -Indexes FollowSymLinks&lt;br /&gt;
&lt;br /&gt;
* Compression reduces response times by reducing the size of the HTTP response&lt;br /&gt;
# Install and enable mod_deflate - refer to documentation or man pages&lt;br /&gt;
# Add this code to the virtual server config file within the &amp;lt;directory&amp;gt; section for the root directory (or within the .htaccess file if AllowOverrides is On):&lt;br /&gt;
 &amp;lt;ifModule mod_deflate.c&amp;gt;&lt;br /&gt;
   AddOutputFilterByType DEFLATE text/html text/plain text/xml text/x-js text/javascript text/css application/javascript&lt;br /&gt;
 &amp;lt;/ifmodule&amp;gt;&lt;br /&gt;
* Use Apache [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html event] [http://httpd.apache.org/docs/current/mpm.html MPM] (and not the default Prefork or Worker)&lt;br /&gt;
&lt;br /&gt;
===IIS performance===&lt;br /&gt;
All alter this location in the registry:&lt;br /&gt;
 HKLM\SYSTEM\CurrentControlSet\Services\Inetinfo\Parameters\&lt;br /&gt;
* The equivalent to KeepAliveTimeout is &#039;&#039;&#039;ListenBackLog&#039;&#039;&#039; (IIS - registry location is HKLM\ SYSTEM\ CurrentControlSet\ Services\ Inetinfo\ Parameters). Set this to between 2 to 5.&lt;br /&gt;
*Change the &#039;&#039;&#039;MemCacheSize&#039;&#039;&#039; value to adjust the amount of memory (Mb) that IIS will use for its file cache (50% of available memory by default).&lt;br /&gt;
*Change the &#039;&#039;&#039;MaxCachedFileSize&#039;&#039;&#039; to adjust the maximum size of a file cached in the file cache in bytes. Default is 262,144 (256K).&lt;br /&gt;
*Create a new DWORD called &#039;&#039;&#039;ObjectCacheTTL&#039;&#039;&#039; to change the length of time (in milliseconds) that objects in the cache are held in memory. Default is 30,000 milliseconds (30 seconds).&lt;br /&gt;
&lt;br /&gt;
===Lighttpd, NginX and Cherokee performance===&lt;br /&gt;
You can increase server performance by using a &#039;&#039;&#039;light-weight&#039;&#039;&#039; webserver like [http://www.lighttpd.net/ lighttpd],  [http://nginx.net/ nginx] or [http://www.cherokee-project.com/ cherokee] in combination with PHP in FastCGI-mode. Lighttpd was originally created as a proof-of-concept[http://www.lighttpd.net/story] to address the [http://www.kegel.com/c10k.html C10k problem] and while primarily recommended for memory-limited servers, its design origins and asynchronous-IO model make it a suitable and proven[http://blog.lighttpd.net/articles/2006/12/28/lighttpd-powers-5-alexa-top-250-sites] alternative HTTP server for high-load websites and web apps, including Moodle. See the [[lighttpd | MoodleDocs Lighttpd page]] for additional information, configuration example and links.&lt;br /&gt;
&lt;br /&gt;
Alternatively, both [http://www.lighttpd.net/ lighttpd] and [http://nginx.net/ nginx] are capable of performing as a load-balancer and/or reverse-proxy to alleviate load on back-end servers[http://www.linuxjournal.com/article/10108], providing benefit without requiring an actual software change on existing servers.&lt;br /&gt;
&lt;br /&gt;
Do note that these are likely to be the least tested server environments of all particularly if you are using advanced features such as web services and/or Moodle Networking. They are probably best considered for heavily used Moodle sites with relatively simple configurations.&lt;br /&gt;
&lt;br /&gt;
===X-Sendfile===&lt;br /&gt;
&lt;br /&gt;
X-Sendfile modules improve performance when sending large files from Moodle. It is recommended to configure your web server and Moodle to use this feature of available.&lt;br /&gt;
&lt;br /&gt;
Configure web server:&lt;br /&gt;
* Apache - https://tn123.org/mod_xsendfile/&lt;br /&gt;
* Lighttpd - http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file&lt;br /&gt;
* Nginx - http://wiki.nginx.org/XSendfile&lt;br /&gt;
&lt;br /&gt;
Enable support in config.php (see config-dist.php):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Sendfile&#039;;           // Apache {@see https://tn123.org/mod_xsendfile/}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-LIGHTTPD-send-file&#039;; // Lighttpd {@see http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Accel-Redirect&#039;;     // Nginx {@see http://wiki.nginx.org/XSendfile}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure file location prefixes if your server implementation requires it:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfilealiases = array(&lt;br /&gt;
//         &#039;/dataroot/&#039; =&amp;gt; $CFG-&amp;gt;dataroot,&lt;br /&gt;
//         &#039;/cachedir/&#039; =&amp;gt; &#039;/var/www/moodle/cache&#039;,    // for custom $CFG-&amp;gt;cachedir locations&lt;br /&gt;
//         &#039;/localcachedir/&#039; =&amp;gt; &#039;/var/local/cache&#039;,    // for custom $CFG-&amp;gt;localcachedir locations&lt;br /&gt;
//         &#039;/tempdir/&#039;  =&amp;gt; &#039;/var/www/moodle/temp&#039;,     // for custom $CFG-&amp;gt;tempdir locations&lt;br /&gt;
//         &#039;/filedir&#039;   =&amp;gt; &#039;/var/www/moodle/filedir&#039;,  // for custom $CFG-&amp;gt;filedir locations&lt;br /&gt;
//     );&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Database performance==&lt;br /&gt;
&lt;br /&gt;
===MySQL performance===&lt;br /&gt;
&lt;br /&gt;
The following are MySQL specific settings which can be adjusted for better performance in your my.cnf (my.ini in Windows). The file contains a list of settings and their values. To see the current values use these commands&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
 SHOW VARIABLES; &lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: You must make backups of your database before attempting to change any MySQL server configuration. After any change to the my.cnf, restart mysqld.&lt;br /&gt;
&lt;br /&gt;
If you are able, the [http://mysqltuner.com/ MySQLTuner] tool can be run against your MySQL server and will calculate appropriate configuration values for most of the following settings based on your current load, status and variables automatically.&lt;br /&gt;
&lt;br /&gt;
* Enable the &#039;&#039;&#039;query cache&#039;&#039;&#039; with &lt;br /&gt;
 query_cache_type = 1. &lt;br /&gt;
For most Moodle installs, set the following:&lt;br /&gt;
 query_cache_size = 36M &lt;br /&gt;
 query_cache_min_res_unit = 2K. &lt;br /&gt;
The query cache will improve performance if you are doing few updates on the database. &lt;br /&gt;
* Set the &#039;&#039;&#039;table cache&#039;&#039;&#039; correctly. For Moodle 1.6 set &lt;br /&gt;
 table_cache = 256 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min), and for Moodle 1.7 set &lt;br /&gt;
 table_cache = 512 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min). The table cache is used by all threads (connections), so monitor the value of opened_tables to further adjust - if opened_tables &amp;gt; 3 * table_cache(table_open_cache in MySQL &amp;gt; 5.1.2) then increase table_cache upto your OS limit. Note also that the figure for table_cache will also change depending on the number of modules and plugins you have installed. Find the number for your server by executing the mysql statement below. Look at the number returned and set table_cache to this value.&lt;br /&gt;
 mysql&amp;gt;SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema=&#039;yourmoodledbname&#039;;&lt;br /&gt;
* Set the &#039;&#039;&#039;thread cache&#039;&#039;&#039; correctly. Adjust the value so that your thread cache utilization is as close to 100% as possible by this formula:&lt;br /&gt;
 thread cache utilization (%) = (threads_created / connections) * 100&lt;br /&gt;
* The &#039;&#039;&#039;key buffer&#039;&#039;&#039; can improve the access speed to Moodle&#039;s SELECT queries. The correct size depends on the size of the index files (.myi) and in Moodle 1.6 or later (without any additional modules and plugins), the recommendation for this value is key_buffer_size = 32M. Ideally you want the database to be reading once from the disk for every 100 requests so monitor that the value is suitable for your install by adjusting the value of key_buffer_size so that the following formulas are true:&lt;br /&gt;
 key_read / key_read_requests &amp;lt; 0.01&lt;br /&gt;
 key_write / key_write_requests &amp;lt;= 1.0&lt;br /&gt;
* Set the &#039;&#039;&#039;maximum number of connections&#039;&#039;&#039; so that your users will not see a &amp;quot;Too many connections&amp;quot; message. Be careful that this may have an impact on the total memory used. MySQL connections usually last for milliseconds, so it is unusual even for a heavily loaded server for this value to be over 200.&lt;br /&gt;
* Manage &#039;&#039;&#039;high burst activity&#039;&#039;&#039;. If your Moodle install uses a lot of quizzes and you are experiencing performance problems (check by monitoring the value of threads_connected - it should not be rising) consider increasing the value of back_log.&lt;br /&gt;
* &#039;&#039;&#039;Optimize your tables weekly and after upgrading Moodle&#039;&#039;&#039;. It is good practice to also optimize your tables after performing a large data deletion exercise, e.g. at the end of your semester or academic year. This will ensure that index files are up to date. Backup your database first and then use:&lt;br /&gt;
 mysql&amp;gt;CHECK TABLE mdl_tablename;&lt;br /&gt;
 mysql&amp;gt;OPTIMIZE TABLE mdl_tablename;&lt;br /&gt;
:The common tables in Moodle to check are mdl_course_sections, mdl_forum_posts, mdl_log and mdl_sessions (if using dbsessions). Any errors need to be corrected using REPAIR TABLE (see the [http://dev.mysql.com/doc/refman/5.0/en/repair-table.html MySQL manual] and this [http://moodle.org/mod/forum/discuss.php?d=58208#p279638 forum script]).&lt;br /&gt;
* &#039;&#039;&#039;Maintain the key distribution&#039;&#039;&#039;. Every month or so it is a good idea to stop the mysql server and run these myisamchk commands.&lt;br /&gt;
 #myisamchk -a -S /pathtomysql/data/moodledir/*.MYI&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: You must stop the mysql database process (mysqld) before running any myisamchk command. If you do not, you risk data loss.&lt;br /&gt;
* Reduce the number of &#039;&#039;&#039;temporary tables saved to disk&#039;&#039;&#039;. Check this with the created_tmp_disk_tables value. If this is relatively large (&amp;gt;5%) increase tmp_table_size until you see a reduction. Note that this will have an impact on RAM usage.&lt;br /&gt;
&lt;br /&gt;
===PostgreSQL performance===&lt;br /&gt;
&lt;br /&gt;
There are some good papers around on tuning PostgreSQL (like [http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server this one]), and Moodle&#039;s case does not seem to be different to the general case.&lt;br /&gt;
&lt;br /&gt;
The first thing to recognise is that if you really need to worry about tuning you should be using a separate machine for the database server. If you are not using a separate machine then the answers to many performance questions are substantially muddied by the memory requirements of the rest of the application.&lt;br /&gt;
&lt;br /&gt;
You should probably &#039;&#039;&#039;enable autovacuum&#039;&#039;&#039;, unless you know what you are doing. Many e-learning sites have predictable periods of low use, so disabling autovacuum and running a specific vacuum at those times can be a good option. Or perhaps leave autovacuum running but do a full vacuum weekly in a quiet period.&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;&#039;shared_buffers&#039;&#039;&#039; to something reasonable. For versions up to 8.1 my testing has shown that peak performance is almost always obtained with buffers &amp;lt; 10000, so if you are using such a version, and have more than 512M of RAM just set shared_buffers to 10,000 (8MB).&lt;br /&gt;
&lt;br /&gt;
The buffer management had a big overhaul in 8.2 and &amp;quot;reasonable&amp;quot; is now a much larger number. I have not conducted performance tests with 8.2, but the recommendations from others are generally that you should now scale shared_buffers much more with memory and may continue to reap benefits even up to values like 100,000 (80MB). Consider using 1-2% of system RAM.&lt;br /&gt;
&lt;br /&gt;
PostgreSQL will also assume that the operating system is caching its files, so setting &#039;&#039;&#039;effective_cache_size&#039;&#039;&#039; to a reasonable value is also a good idea. A reasonable value will usually be (total RAM - RAM in use by programs). If you are running Linux and leave the system running for a day or two you can look at &#039;free&#039; and under the &#039;cached&#039; column you will see what it currently is. Consider taking that number (which is kB) and dividing it by 10 (i.e. allow 20% for other programs cache needs and then divide by 8 to get pages). If you are not using a dedicated database server you will need to decrease that value to account for usage by other programs.&lt;br /&gt;
&lt;br /&gt;
Some other useful parameters that can have positive effects, and the values I would typically set them to on a machine with 4G RAM, are:&lt;br /&gt;
&lt;br /&gt;
 work_mem = 10240&lt;br /&gt;
&lt;br /&gt;
That&#039;s 10M of RAM to use instead of on-disk sorting and so forth. That can give a big speed increase, but it is per connection and 200 connections * 10M is 2G, so it can theoretically chew up a lot of RAM.&lt;br /&gt;
&lt;br /&gt;
 maintenance_work_mem = 163840&lt;br /&gt;
&lt;br /&gt;
That&#039;s 160M of RAM which will be used by (e.g.) VACUUM, index rebuild, cluster and so forth. This should only be used periodically and should be freed when those processes exit, so I believe it is well worth while.&lt;br /&gt;
&lt;br /&gt;
 wal_buffers = 64&lt;br /&gt;
&lt;br /&gt;
These buffers are used for the write-ahead log, and there have been a number of reports on the PostgreSQL mailing lists of improvement from this level of increase.&lt;br /&gt;
&lt;br /&gt;
This is a little out of date now (version 8.0) but still worth a read: http://www.powerpostgresql.com/Docs&lt;br /&gt;
&lt;br /&gt;
And there is lots of good stuff here as well: http://www.varlena.com/GeneralBits/Tidbits/index.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Based on Andrew McMillan&#039;s post at [http://moodle.org/mod/forum/discuss.php?d=68558 Tuning PostgreSQL] forum thread.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Splitting &#039;&#039;&#039;mdl_log&#039;&#039;&#039; to several tables and using a VIEW with UNION to read them as one. (See Tim Hunt [https://moodle.org/mod/forum/discuss.php?d=243531#p1104165 explanation] on the Moodle forums)&lt;br /&gt;
&lt;br /&gt;
===Other database performance links===&lt;br /&gt;
* Consider using a &#039;&#039;&#039;distributed cacheing system&#039;&#039;&#039; like [http://en.wikipedia.org/wiki/Memcached memcached] but note that memcached does not have any security features so it should be used behind a firewall.&lt;br /&gt;
* Consider using PostgreSQL. See [[Arguments in favour of PostgreSQL]] and [http://moodle.org/mod/forum/discuss.php?d=49195 how to migrate from MySQL to PostgreSQL] (forum discussion).&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.0/en/server-parameters.html General advice on tuning MySQL parameters] (advice from the MySQL manual)&lt;br /&gt;
* [http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/ InnoDB performance optimization] taken from the [http://www.mysqlperformanceblog.com/ MySQL performance blog] site.&lt;br /&gt;
&lt;br /&gt;
==Performance of different Moodle modules==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s activity modules, filters, and other plugins can be activated/deactivated. If necessary, you may wish to deactivate some features (such as chat) if not required - but this isn&#039;t necessary. Some notes on the performance of certain modules:&lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;Chat&#039;&#039;&#039; module is [http://moodle.org/mod/forum/discuss.php?d=37979&amp;amp;parent=175079 said] to be a hog in terms of frequent HTTP requests to the main server. This can be reduced by setting the module to use &#039;&#039;Streamed&#039;&#039; updates, or, if you&#039;re using a Unix-based webserver, by running the chat in daemon mode. When using the Chat module use the configuration settings to tune for your expected load. Pay particular attention to the &#039;&#039;chat_old_ping&#039;&#039; and &#039;&#039;chat_refresh&#039;&#039; parameters as these can have greatest impact on server load.&lt;br /&gt;
* The Moodle &#039;&#039;&#039;Cron&#039;&#039;&#039; task is triggered by calling the script &#039;&#039;cron.php&#039;&#039;. If this is called over HTTP (e.g. using wget or curl) it can take a large amount of memory on large installations. If it is called by directly invoking the php command (e.g. &#039;&#039;php -f /path/to/moodle/directory/admin/cli/cron.php&#039;&#039;) efficiency can be much improved.&lt;br /&gt;
* The &#039;&#039;&#039;Recent activities&#039;&#039;&#039; block is consuming too many resources if you have huge number of records &amp;lt;code&amp;gt;mdl_log&amp;lt;/code&amp;gt;. This is being tested to optimize the SQL query.&lt;br /&gt;
* The &#039;&#039;&#039;Quiz&#039;&#039;&#039; module is known to stretch database performance. However, it has been getting better in recent versions, and we don&#039;t know of any good, up-to-date performance measurements. (Here is a [http://moodle.org/mod/forum/discuss.php?d=68579 case study from 2007 with 300 quiz users].). The following suggestions were described by [https://moodle.org/user/view.php?id=94615&amp;amp;course=5 Al Rachels] in [https://moodle.org/mod/forum/discuss.php?d=347126 this forum thread]:&lt;br /&gt;
** make sure both Moodle, and the operating system, are installed on a [https://en.wikipedia.org/wiki/Solid-state_drive solid state drive]&lt;br /&gt;
** upgrade to and use [https://docs.moodle.org/dev/Moodle_and_PHP7 PHP 7]&lt;br /&gt;
** run MySQLTuner and implement its recommendations&lt;br /&gt;
&lt;br /&gt;
See [[Performance settings]] for more information on performance-related Moodle settings.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle: [http://moodle.org/mod/forum/view.php?f=94 Hardware and Performance] forum&lt;br /&gt;
*[http://opensourceelearning.blogspot.be/2012/10/why-your-moodle-site-is-slow-five.html Why Your Moodle Site is Slow: Five Simple Settings] blog post from Jonathan Moore &lt;br /&gt;
*I teach with Moodle perfomance testing: http://www.iteachwithmoodle.com/2012/11/17/moodle-2-4-beta-performance-test-comparison-with-moodle-2-3/&lt;br /&gt;
*[http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs 2.5.2 performance and MUC APC cahe store]&lt;br /&gt;
*[http://jfilip.ca/2013/09/25/moodle-performance-testing-2-4-6-vs-2-5-2-vs-2-6dev/ Moodle performance testing 2.4.6 vs 2.5.2 vs 2.6dev]&lt;br /&gt;
*[http://jfilip.ca/2013/09/24/moodle-performance-analysis-revisted-now-with-mariadb/ Moodle performance analysis revisited (now with MariaDB)]&lt;br /&gt;
*[http://tjhunt.blogspot.ca/2013/05/performance-testing-moodle.html Tim Hunt&#039;s blog (May 2, 2013) on performance testing Moodle]&lt;br /&gt;
*[http://newrelic.com/ New Relic, Application Performance Monitoring]&lt;br /&gt;
*[http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html Performance enhacements for Apache and PHP (Apache Event MPM and PHP-FPM)]&lt;br /&gt;
*[https://scholarlms.net/performance-recommendations/ Performance recommendations]&lt;br /&gt;
&lt;br /&gt;
There have been a lot of discussions on moodle.org about performance, here are some of the more interesting and (potentially) useful ones:&lt;br /&gt;
&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=83057 Performance woes!]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=57028 Performance perspectives - a little script]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=88927 Comments on planned server hardware]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=102978#p461624 Moodle performance in a pil by Martin Langhoff]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=240391#unread Advice on optimising php/db code in moodle2+]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=243531 Moodle 2.5 performance testing at the OU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=273602 100 active users limit with 4vCPU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=336603#p1356423 Performance Tip ... shared...]&lt;br /&gt;
&lt;br /&gt;
[[es:Recomendaciones sobre desempeño]]&lt;br /&gt;
[[fr:Performance]]&lt;br /&gt;
[[ja:パフォーマンス]]&lt;br /&gt;
[[de:Geschwindigkeitsempfehlungen]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Caching&amp;diff=135020</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Caching&amp;diff=135020"/>
		<updated>2019-08-10T08:16:01Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Memcached */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
Moodle 2.4 saw the implementation of MUC, the Moodle Universal Cache. This new system allows certain functions of Moodle (eg string fetching) take advantage of different installed cache services (eg files, ram, memcached).&lt;br /&gt;
&lt;br /&gt;
In future versions of Moodle we will continue expanding the number of Moodle functions that use MUC, which will continue improving performance, but you can already start using it to improve your site.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
Since Moodle 2.4, Moodle has provided a caching plugin framework to give administrators the ability to control where Moodle stores cached data. For most Moodle sites the default configuration should be sufficient and it is not necessary to change the configuration. For larger Moodle sites with multiple servers, administrators may wish to use memcached, mongodb or other systems to store cache data. The cache plugin screen provides administrators with the ability to configure what cache data is stored where.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to as MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Let&#039;s start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar with, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than an area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
If you have a system with multiple front-end web servers, the application cache must be shared between the servers. In other words, you cannot use fast local storage for the application cache, but must use shared storage or some other form of shared cache such as a shared memcached.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcached server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above. The standard Moodle has the three defaults mentioned above as well as Memcached, MongoDB, [[APC user cache (APCu)|APC user cache (APCu)]] and [[Redis cache store|Redis]].&lt;br /&gt;
&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&lt;br /&gt;
&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcached servers, for instance, you can create a cache store instance for each. Moodle by default contains three cache store instances that get used when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored in your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Let&#039;s keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcached, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that, you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecture again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it. A cache by nature is volatile and any information that is absolutely mission critical should be a more permanent data store likely the database.&lt;br /&gt;
&lt;br /&gt;
Nonetheless there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However, in some situations, it&#039;s beneficial to allow multiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course, not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID: This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version: All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key: For this, you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone: The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on a server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share in many situations, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is important to consider with the language cache that by sharing it between sites any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:cacheadmin29.png|thumb|500px|The cache configuration screen]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in  &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:ist29.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any PHP requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores, it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:csi29.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039;: The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039;: The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready &#039;&#039;&#039;: A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039;: The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039;: The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039;: The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking &#039;&#039;&#039;: Locking is a mechanism that restricts access to cached data to one process at a time to prevent the data from being overwritten. The locking method determines how the lock is acquired and checked.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039;: Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really it&#039;s like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039;: The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component &#039;&#039;&#039;: The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039;: The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039;: The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039;: How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039;: Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during an upgrade, and if a new cache definition is encountered. However, should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. It is useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default, just a single locking mechanism is available, file locking.&lt;br /&gt;
At present, there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are no specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
To simplify that, this shows the default cache stores for each type.&lt;br /&gt;
&lt;br /&gt;
At the bottom, you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however, you may be able to improve the performance of your sites by making use of various caching backends and techniques. The first thing you are going to want to do is to add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes your intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039;: Allows you to specify a directory to use when storing cache data on the file system. Of course the user the web server is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039;: If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039;: By default, the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely to hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039;: One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default, the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you have an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many Linux installations these days, for example, use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is a different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course, you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
Whatever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
You must first have a [https://docs.moodle.org/310/en/Performance_recommendations#MemCached Memcached server] you can access and have the [https://docs.moodle.org/310/en/Performance_recommendations#MemCached Memcached PHP extension] installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
There are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039;: It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039;: The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039;: Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039;: Allows you to select which serialiser gets used when communicating with the Memcached server. By default the Memcached extension and PHP only provide one serialised, however, there is a couple of others available for installation if you go looking for them. One, for example, is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039;: Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039;: The hash method provided by the Memcached extension is used by default here. However, you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes &#039;&#039;&#039;: Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interactions are taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcached extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this, it is important to note that when you purge a Memcached store within Moodle it deletes ALL entries in the Memcached server. Not just those relating to Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
For that reason, it is highly recommended to use dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use the same servers. Doing so may lead to performance depreciation and adverse effects.&lt;br /&gt;
* Likewise if you want to use Memcached for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise, a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mongodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039;: Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server &#039;&#039;&#039;: This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database &#039;&#039;&#039;: The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039;: The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password &#039;&#039;&#039;: The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set &#039;&#039;&#039;: The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039;: If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039;: You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039;: If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add a small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and, most importantly, optimise the performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column select the link for &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
You are presented with several drop-downs that allow you to map one or more cached. All mapped caches get interacted with. The &amp;quot;Primary&amp;quot; store is the store that will be used first when interacting with the cache.&lt;br /&gt;
The &amp;quot;Final&amp;quot; mapped store will be the last cache store interacted with.&amp;lt;br /&amp;gt;&lt;br /&gt;
How this interaction occurs is documented below.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039;: Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it, it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it, then fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039;: Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039;: Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continues until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039;: Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage of assigning multiple stores is that you can introduce cache redundancy. Of course, this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Scenario:&lt;br /&gt;
You have a web server that has a Moodle site as well as other sites.&lt;br /&gt;
You also have a Memcached server that is used by several sites including Moodle.&lt;br /&gt;
&lt;br /&gt;
Memcached has a limited size cache, that when full and requested to store more information frees space by dropping the least used cache entries.&lt;br /&gt;
&lt;br /&gt;
You want to use Memcached for your Moodle site because it is fast, however, you are aware that it may introduce more cache misses because it is a heavily used Memcached server.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcached.&lt;br /&gt;
You make Memcached the primary store, and you make the default file store the final cache store.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
By doing this you&#039;ve created redundancy; when something is requested, Moodle first tries to get it from Memcached (the fastest store) and if it is not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately, there is no step-by-step guide to this.&lt;br /&gt;
&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered are some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&lt;br /&gt;
&lt;br /&gt;
If you are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before telling Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcached installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcached server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcached for instance drops least used data when full to make room for new entries. APC, on the other hand, stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
===More on performance testing===&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
===Performance advice for load-balanced web servers===&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
&lt;br /&gt;
Have you encountered a problem, or found yourself in a conundrum? Perhaps the answer is in this section. If not when you find an answer, how about you share it here.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=378416#p1526130 Why using a not-completely-shared application cache will fail]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[MUC FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;br /&gt;
[[fr:Mettre en cache]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Performance_recommendations&amp;diff=135019</id>
		<title>Performance recommendations</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Performance_recommendations&amp;diff=135019"/>
		<updated>2019-08-10T08:14:24Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Install HowTo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
Moodle can be made to perform very well, at small usage levels or scaling up to many thousands of users. The factors involved in performance are basically the same as for any PHP-based database-driven system. When trying to optimize your server, try to focus on the factor which will make the most difference to the user. For example, if you have relatively more users browsing than accessing the database, look to improve the webserver performance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Obtain a baseline benchmark==&lt;br /&gt;
&lt;br /&gt;
Before attempting any optimization, you should obtain a baseline benchmark of the component of the system you are trying to improve. For Linux try [http://lbs.sourceforge.net/ LBS] and for Windows use the Performance Monitor. Once you have quantitative data about how your system is performing currently, you&#039;ll be able to determine if the change you have made has had any real impact.&lt;br /&gt;
&lt;br /&gt;
The overall aim of adjustments to improve performance is to use RAM (cacheing) and to reduce disk-based activity. It is especially important to try to eliminate swap file usage as much as you can. If your system starts swapping, this is a sign that you need more RAM. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;optimization order preference&#039;&#039;&#039; is usually: primary storage (more RAM), secondary storage (faster hard disks/improved hard disk configuration), processor (more and faster).&lt;br /&gt;
&lt;br /&gt;
It can be interesting to install and use the [https://moodle.org/plugins/report_benchmark Benchmark plugin] in order to find the bottlenecks of your system that specifically affect Moodle.&lt;br /&gt;
&lt;br /&gt;
==Scalability==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s design (with clear separation of application layers) allows for strongly scalable setups. (Please check the list of [[Large installations|large Moodle installations]].)&lt;br /&gt;
&lt;br /&gt;
Large sites usually separate the web server and database onto separate servers, although for smaller installations this is typically not necessary.&lt;br /&gt;
&lt;br /&gt;
It is possible to load-balance a Moodle installation, for example by using more than one webserver. The separate webservers should query the same database and refer to the same filestore and cache areas (see [[Caching]]), but otherwise the separation of the application layers is complete enough to make this kind of clustering feasible. Similarly, the database could be a cluster of servers (e.g. a MySQL cluster), but this is not an easy task and you should seek expert support, e.g. from a Moodle Partner.&lt;br /&gt;
&lt;br /&gt;
===Server cluster===&lt;br /&gt;
&lt;br /&gt;
Using Moodle forum discussions:&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=57202 Moodle clustering]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=44470 Software load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=49986 TCP load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=88214 Installation for 3000 simultaneous users]&lt;br /&gt;
&lt;br /&gt;
==Hardware configuration==&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: The fastest and most effective change that you can make to improve performance is to &#039;&#039;&#039;increase the amount of RAM on your web server&#039;&#039;&#039; - get as much as possible (e.g. 4GB or more). Increasing primary memory will reduce the need for processes to swap to disk and will enable your server to handle more users.&lt;br /&gt;
* Better performance is gained by obtaining the best &#039;&#039;&#039;processor capability&#039;&#039;&#039; you can, i.e. dual or dual core processors. A modern BIOS should allow you to enable hyperthreading, but check if this makes a difference to the overall performance of the processors by using a [http://en.wikipedia.org/wiki/Super_PI CPU benchmarking tool].&lt;br /&gt;
* If you can afford them, use &#039;&#039;&#039;SCSI hard disks&#039;&#039;&#039; instead of SATA drives. SATA drives will increase your system&#039;s CPU utilization, whereas SCSI drives have their own integrated processors and come into their own when you have multiple drives. If you must have SATA drives, check that your motherboard and the drives themselves support NCQ (Native Command Queuing).&lt;br /&gt;
* Purchase hard disks with a &#039;&#039;&#039;low seek time&#039;&#039;&#039;. This will improve the overall speed of your system, especially when accessing Moodle&#039;s reports.&lt;br /&gt;
* Size your &#039;&#039;&#039;swap file&#039;&#039;&#039; correctly. The general advice is to set it to 4 x physical RAM.&lt;br /&gt;
* Use a &#039;&#039;&#039;RAID disk system&#039;&#039;&#039;. Although there are many different RAID configurations you can create, the following generally works best:&lt;br /&gt;
** install a hardware RAID controller (if you can)&lt;br /&gt;
** the operating system and swap drive on one set of disks configured as RAID-1.&lt;br /&gt;
** Moodle, Web server and Database server on another set of disks configured as RAID-5.&lt;br /&gt;
* If your &#039;moodledata&#039; area is going to be on relatively slow storage (e.g. NFS mount on to a NAS device) you will probably have performance issues with the default cache configuration (which writes to this storage). See the page on [[Caching]] and consider an alternative. Using [https://en.wikipedia.org/wiki/GlusterFS GlusterFS] / [https://en.wikipedia.org/wiki/OCFS2 OCFS2] / [https://en.wikipedia.org/wiki/GFS2 GFS2] on a [https://en.wikipedia.org/wiki/Storage_Area_Network SAN] device and [https://en.wikipedia.org/wiki/Fibre_Channel Fiber Channel] could improve performance (See more info on the Moodle [https://moodle.org/mod/forum/discuss.php?d=214680#p1123124 forum thread], [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 NFS performance tuing] )&lt;br /&gt;
* Use &#039;&#039;&#039;gigabit ethernet&#039;&#039;&#039; for improved latency and throughput. This is especially important when you have your webserver and database server separated out on different hosts.&lt;br /&gt;
* Check the settings on your &#039;&#039;&#039;network card&#039;&#039;&#039;. You may get an improvement in performance by increasing the use of buffers and transmit/receive descriptors (balance this with processor and memory overheads) and off-loading TCP checksum calculation onto the card instead of the OS.&lt;br /&gt;
*  Read this [http://moodle.org/mod/forum/discuss.php?d=68579 Case Study] on a server stress test with 300 users.  &lt;br /&gt;
* See this [http://elearning.sgu.ac.jp/doc/PT/ accompanying report] on network traffic and server loads.&lt;br /&gt;
* Also see this SFSU presentation at Educause (using VMWare): [http://www.educause.edu/Resources/AnOpenSourceLMSforaMissionCrit/162843]&lt;br /&gt;
&lt;br /&gt;
==Operating System==&lt;br /&gt;
* You can use [http://en.wikipedia.org/wiki/Linux Linux](recommended), Unix-based, Windows or Mac OS X for the server &#039;&#039;&#039;operating system&#039;&#039;&#039;. *nix operating systems generally require less memory than Mac OS X or Windows servers for doing the same task as the server is configured with just a shell interface. Additionally Linux does not have licensing fees attached, but can have a big learning curve if you&#039;re used to another operating system. If you have a large number of processors running SMP, you may also want to consider using a highly tuned OS such as [http://en.wikipedia.org/wiki/Solaris_Operating_Environment Solaris].&lt;br /&gt;
* Check your own OS and &#039;&#039;&#039;vendor specific instructions&#039;&#039;&#039; for optimization steps.&lt;br /&gt;
** For Linux look at the [http://linuxperf.sourceforge.net/ Linux Performance Team] site. &lt;br /&gt;
** For Linux investigate the hdparm command, e.g. hdparm -m16 -d1 can be used to enable read/write on multiple sectors and DMA. Mount disks with the [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 &amp;quot;async&amp;quot; and &amp;quot;noatime&amp;quot;] options.&lt;br /&gt;
** For Windows set the sever to be optimized for network applications (Control Panel, Network Connections, LAN connection, Properties, File &amp;amp; Printer Sharing for Microsoft Networks, Properties, Optimization). You can also search the [http://technet.microsoft.com/ Microsoft TechNet site] for optimization documents.&lt;br /&gt;
&lt;br /&gt;
==Web server performance==&lt;br /&gt;
&lt;br /&gt;
Installing [http://www.mozilla.com/en-US/ Firefox] and the [https://addons.mozilla.org/en-US/firefox/addon/1843 firebug] extension will allow you to watch the time it takes for each page component to load. Also, the [https://addons.mozilla.org/en-US/firefox/addon/5369 Yslow] extension will evaluate your page against Yahoo&#039;s [http://www.skrenta.com/2007/05/14_rules_for_fast_web_pages_by_1.html 14 rules], full text [http://developer.yahoo.com/performance/rules.html Best Practices for Speeding Up Your Web Site], &amp;lt;strike&amp;gt;([http://video.yahoo.com/video/play?vid=1040890 video])&amp;lt;/strike&amp;gt; for fast loading websites.&lt;br /&gt;
&lt;br /&gt;
===PHP performance===&lt;br /&gt;
* You are strongly recommended to use a &#039;&#039;&#039;PHP accelerator&#039;&#039;&#039; to ease CPU load, such as [http://pecl.php.net/apc APC], [http://www.php-accelerator.co.uk/ PHPA], [http://trac.lighttpd.net/xcache/ Xcache], [http://sourceforge.net/projects/wincache WinCache] or [http://eaccelerator.net/ eAccelerator]. (Take care to choose a PHP accelerator that is known to work well with your version of PHP and note that Turck MMCache is [http://turckmmcache.exeprod.com/TheManifestoEnglish no longer maintained] and can cause failures with PHP 5). PHP 5.5 (and newer) includes OpCache and is fully supported and recommended by Moodle&lt;br /&gt;
* Improvements in read/write performance can be improved by putting the cached PHP pages on a [[TMPFS]] filesystem - but remember that you&#039;ll lose the cache contents when there is a power failure or the server is rebooted.&lt;br /&gt;
* Performance of PHP is better when installed as an &#039;&#039;&#039;Apache/IIS6 ISAPI module&#039;&#039;&#039; (rather than a CGI). IIS 7.0/7.5 (Windows Server 2008/R2) users should choose a FastCGI installation for best performance.&lt;br /&gt;
* Also check the &#039;&#039;&#039;memory_limit&#039;&#039;&#039; in php.ini, reduce it to 16M for Moodle version earlier than 1.7 ([http://moodle.org/mod/forum/discuss.php?d=39656 See this forum discussion]). For Moodle 1.7 or later, it is recommended that the value of memory_limit should be 40M. As of [http://www.php.net/ChangeLog-5.php PHP 5.2.1] the default value for the memory_limit directive is 128M.&lt;br /&gt;
* Also see [[PHP_settings_by_Moodle_version]]&lt;br /&gt;
* Use [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html PHP-FPM] (with apache).&lt;br /&gt;
&lt;br /&gt;
===Install HowTo===&lt;br /&gt;
==== APC ====&lt;br /&gt;
* [http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html APC on CentOS 5.x (linux)]&lt;br /&gt;
* [http://fplanque.com/dev/linux/install-apc-php-cache-debian-lenny APC on Debian (linux)]&lt;br /&gt;
==== eAccelerator ====&lt;br /&gt;
* [http://noveckg.blogspot.com/2010/02/installing-eaccelerator-cache-for-php.html Installing eAccelerator on CentOS 5.x (linux)]&lt;br /&gt;
* [https://docs.moodle.org/en/Installing_eAccelerator_In_Ubuntu_Server/ Installing eAccelerator on Ubuntu Server (linux)]&lt;br /&gt;
==== MemCached ====&lt;br /&gt;
Memcached server (daemon)&lt;br /&gt;
* [https://www.tecmint.com/install-memcached-on-centos-7/ Installing Memcached on CentOS 7.x (linux)] (as of php 7.x, only memcached is available)&lt;br /&gt;
* [https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-memcached-on-centos-7 How To Install and Secure Memcached on CentOS 7]&lt;br /&gt;
Memcached PHP 7.1 extension &lt;br /&gt;
* [https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/repoview/php71u-pecl-memcached.html php71u-pecl-memcached] from IUS CentOS 7.x repository.&lt;br /&gt;
&lt;br /&gt;
===Apache performance===&lt;br /&gt;
* If you are using Apache on a Windows server, use the build from [http://www.apachelounge.com Apache Lounge] which is reported to have [http://moodle.org/mod/forum/discuss.php?d=93358 performance and stability improvements] compared to the official Apache download. Note that this is an unofficial build, so may not keep up with official releases.&lt;br /&gt;
* Set the &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; directive correctly (&#039;&#039;&#039;MaxClients&#039;&#039;&#039; before Apache 2.4). Use this formula to help (which uses 80% of available memory to leave room for spare):&lt;br /&gt;
 MaxRequestWorkers = Total available memory * 80% / Max memory usage of apache process&lt;br /&gt;
:Memory usage of apache process is usually 10MB but Moodle can easily use up to 100MB per process, so a general rule of thumb is to divide your available memory in megabytes by 100 to get a conservative setting for MaxClients. You are quite likely to find yourself lowering the MaxRequestWorkers from its default of 150 on a Moodle server. To get a more accurate estimate read the value from the shell command:&lt;br /&gt;
 #ps -ylC httpd --sort:rss&lt;br /&gt;
&lt;br /&gt;
:If you need to increase the value of &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; beyond 256, you will also need to set the &#039;&#039;&#039;ServerLimit&#039;&#039;&#039; directive. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: Do not be tempted to set the value of MaxRequestWorkers higher than your available memory as your server will consume more RAM than available and start to swap to disk. &lt;br /&gt;
* Consider reducing the &#039;&#039;&#039;number of modules&#039;&#039;&#039; that Apache loads in the httpd.conf file to the minumum necessary to reduce the memory needed. &lt;br /&gt;
* Use the &#039;&#039;&#039;latest version of Apache&#039;&#039;&#039; - Apache 2 has an improved memory model which reduces memory usage further.&lt;br /&gt;
* For Unix/Linux systems, consider lowering &#039;&#039;&#039;MaxConnectionsPerChild&#039;&#039;&#039; (&#039;&#039;&#039;MaxRequestsPerChild&#039;&#039;&#039; before Apache 2.4) in httpd.conf to as low as 20-30 (if you set it any lower the overhead of forking begins to outweigh the benefits). &lt;br /&gt;
* For a heavily loaded server, consider setting &#039;&#039;&#039;KeepAlive Off&#039;&#039;&#039; (do this only if your Moodle pages do not contain links to resources or uploaded images) or lowering the &#039;&#039;&#039;KeepAliveTimeout&#039;&#039;&#039; to between 2 and 5. The default is 15 (seconds) - the higher the value the more server processes will be kept waiting for possibly idle connections. A more accurate value for KeepAliveTimeout is obtained by observing how long it takes your users to download a page. After altering any of the KeepAlive variables, monitor your CPU utilization as there may be an additional overhead in initiating more worker processes/threads.&lt;br /&gt;
* As an alternative to using KeepAlive Off, consider setting-up a &#039;&#039;&#039;Reverse Proxy server&#039;&#039;&#039; infront of the Moodle server to cache HTML files with images. You can then return Apache to using keep-alives on the Moodle server.&lt;br /&gt;
* If you do not use a .htaccess file, set the &#039;&#039;&#039;AllowOverride&#039;&#039;&#039; variable to AllowOverride None to prevent .htaccess lookups.&lt;br /&gt;
* Set &#039;&#039;&#039;DirectoryIndex&#039;&#039;&#039; correctly so as to avoid content-negotiation. Here&#039;s an example from a production server:&lt;br /&gt;
 DirectoryIndex index.php index.html index.htm&lt;br /&gt;
* Unless you are doing development work on the server, set &#039;&#039;&#039;ExtendedStatus Off&#039;&#039;&#039; and disable mod_info as well as mod_status.&lt;br /&gt;
* Leave &#039;&#039;&#039;HostnameLookups Off&#039;&#039;&#039; (as default) to reduce DNS latency.&lt;br /&gt;
* Consider reducing the value of &#039;&#039;&#039;TimeOut&#039;&#039;&#039; to between 30 to 60 (seconds). &lt;br /&gt;
* For the &#039;&#039;&#039;Options directive&#039;&#039;&#039;, avoid Options Multiviews as this performs a directory scan. To reduce disk I/O further use&lt;br /&gt;
 Options -Indexes FollowSymLinks&lt;br /&gt;
&lt;br /&gt;
* Compression reduces response times by reducing the size of the HTTP response&lt;br /&gt;
# Install and enable mod_deflate - refer to documentation or man pages&lt;br /&gt;
# Add this code to the virtual server config file within the &amp;lt;directory&amp;gt; section for the root directory (or within the .htaccess file if AllowOverrides is On):&lt;br /&gt;
 &amp;lt;ifModule mod_deflate.c&amp;gt;&lt;br /&gt;
   AddOutputFilterByType DEFLATE text/html text/plain text/xml text/x-js text/javascript text/css application/javascript&lt;br /&gt;
 &amp;lt;/ifmodule&amp;gt;&lt;br /&gt;
* Use Apache [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html event] [http://httpd.apache.org/docs/current/mpm.html MPM] (and not the default Prefork or Worker)&lt;br /&gt;
&lt;br /&gt;
===IIS performance===&lt;br /&gt;
All alter this location in the registry:&lt;br /&gt;
 HKLM\SYSTEM\CurrentControlSet\Services\Inetinfo\Parameters\&lt;br /&gt;
* The equivalent to KeepAliveTimeout is &#039;&#039;&#039;ListenBackLog&#039;&#039;&#039; (IIS - registry location is HKLM\ SYSTEM\ CurrentControlSet\ Services\ Inetinfo\ Parameters). Set this to between 2 to 5.&lt;br /&gt;
*Change the &#039;&#039;&#039;MemCacheSize&#039;&#039;&#039; value to adjust the amount of memory (Mb) that IIS will use for its file cache (50% of available memory by default).&lt;br /&gt;
*Change the &#039;&#039;&#039;MaxCachedFileSize&#039;&#039;&#039; to adjust the maximum size of a file cached in the file cache in bytes. Default is 262,144 (256K).&lt;br /&gt;
*Create a new DWORD called &#039;&#039;&#039;ObjectCacheTTL&#039;&#039;&#039; to change the length of time (in milliseconds) that objects in the cache are held in memory. Default is 30,000 milliseconds (30 seconds).&lt;br /&gt;
&lt;br /&gt;
===Lighttpd, NginX and Cherokee performance===&lt;br /&gt;
You can increase server performance by using a &#039;&#039;&#039;light-weight&#039;&#039;&#039; webserver like [http://www.lighttpd.net/ lighttpd],  [http://nginx.net/ nginx] or [http://www.cherokee-project.com/ cherokee] in combination with PHP in FastCGI-mode. Lighttpd was originally created as a proof-of-concept[http://www.lighttpd.net/story] to address the [http://www.kegel.com/c10k.html C10k problem] and while primarily recommended for memory-limited servers, its design origins and asynchronous-IO model make it a suitable and proven[http://blog.lighttpd.net/articles/2006/12/28/lighttpd-powers-5-alexa-top-250-sites] alternative HTTP server for high-load websites and web apps, including Moodle. See the [[lighttpd | MoodleDocs Lighttpd page]] for additional information, configuration example and links.&lt;br /&gt;
&lt;br /&gt;
Alternatively, both [http://www.lighttpd.net/ lighttpd] and [http://nginx.net/ nginx] are capable of performing as a load-balancer and/or reverse-proxy to alleviate load on back-end servers[http://www.linuxjournal.com/article/10108], providing benefit without requiring an actual software change on existing servers.&lt;br /&gt;
&lt;br /&gt;
Do note that these are likely to be the least tested server environments of all particularly if you are using advanced features such as web services and/or Moodle Networking. They are probably best considered for heavily used Moodle sites with relatively simple configurations.&lt;br /&gt;
&lt;br /&gt;
===X-Sendfile===&lt;br /&gt;
&lt;br /&gt;
X-Sendfile modules improve performance when sending large files from Moodle. It is recommended to configure your web server and Moodle to use this feature of available.&lt;br /&gt;
&lt;br /&gt;
Configure web server:&lt;br /&gt;
* Apache - https://tn123.org/mod_xsendfile/&lt;br /&gt;
* Lighttpd - http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file&lt;br /&gt;
* Nginx - http://wiki.nginx.org/XSendfile&lt;br /&gt;
&lt;br /&gt;
Enable support in config.php (see config-dist.php):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Sendfile&#039;;           // Apache {@see https://tn123.org/mod_xsendfile/}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-LIGHTTPD-send-file&#039;; // Lighttpd {@see http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Accel-Redirect&#039;;     // Nginx {@see http://wiki.nginx.org/XSendfile}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure file location prefixes if your server implementation requires it:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfilealiases = array(&lt;br /&gt;
//         &#039;/dataroot/&#039; =&amp;gt; $CFG-&amp;gt;dataroot,&lt;br /&gt;
//         &#039;/cachedir/&#039; =&amp;gt; &#039;/var/www/moodle/cache&#039;,    // for custom $CFG-&amp;gt;cachedir locations&lt;br /&gt;
//         &#039;/localcachedir/&#039; =&amp;gt; &#039;/var/local/cache&#039;,    // for custom $CFG-&amp;gt;localcachedir locations&lt;br /&gt;
//         &#039;/tempdir/&#039;  =&amp;gt; &#039;/var/www/moodle/temp&#039;,     // for custom $CFG-&amp;gt;tempdir locations&lt;br /&gt;
//         &#039;/filedir&#039;   =&amp;gt; &#039;/var/www/moodle/filedir&#039;,  // for custom $CFG-&amp;gt;filedir locations&lt;br /&gt;
//     );&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Database performance==&lt;br /&gt;
&lt;br /&gt;
===MySQL performance===&lt;br /&gt;
&lt;br /&gt;
The following are MySQL specific settings which can be adjusted for better performance in your my.cnf (my.ini in Windows). The file contains a list of settings and their values. To see the current values use these commands&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
 SHOW VARIABLES; &lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: You must make backups of your database before attempting to change any MySQL server configuration. After any change to the my.cnf, restart mysqld.&lt;br /&gt;
&lt;br /&gt;
If you are able, the [http://mysqltuner.com/ MySQLTuner] tool can be run against your MySQL server and will calculate appropriate configuration values for most of the following settings based on your current load, status and variables automatically.&lt;br /&gt;
&lt;br /&gt;
* Enable the &#039;&#039;&#039;query cache&#039;&#039;&#039; with &lt;br /&gt;
 query_cache_type = 1. &lt;br /&gt;
For most Moodle installs, set the following:&lt;br /&gt;
 query_cache_size = 36M &lt;br /&gt;
 query_cache_min_res_unit = 2K. &lt;br /&gt;
The query cache will improve performance if you are doing few updates on the database. &lt;br /&gt;
* Set the &#039;&#039;&#039;table cache&#039;&#039;&#039; correctly. For Moodle 1.6 set &lt;br /&gt;
 table_cache = 256 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min), and for Moodle 1.7 set &lt;br /&gt;
 table_cache = 512 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min). The table cache is used by all threads (connections), so monitor the value of opened_tables to further adjust - if opened_tables &amp;gt; 3 * table_cache(table_open_cache in MySQL &amp;gt; 5.1.2) then increase table_cache upto your OS limit. Note also that the figure for table_cache will also change depending on the number of modules and plugins you have installed. Find the number for your server by executing the mysql statement below. Look at the number returned and set table_cache to this value.&lt;br /&gt;
 mysql&amp;gt;SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema=&#039;yourmoodledbname&#039;;&lt;br /&gt;
* Set the &#039;&#039;&#039;thread cache&#039;&#039;&#039; correctly. Adjust the value so that your thread cache utilization is as close to 100% as possible by this formula:&lt;br /&gt;
 thread cache utilization (%) = (threads_created / connections) * 100&lt;br /&gt;
* The &#039;&#039;&#039;key buffer&#039;&#039;&#039; can improve the access speed to Moodle&#039;s SELECT queries. The correct size depends on the size of the index files (.myi) and in Moodle 1.6 or later (without any additional modules and plugins), the recommendation for this value is key_buffer_size = 32M. Ideally you want the database to be reading once from the disk for every 100 requests so monitor that the value is suitable for your install by adjusting the value of key_buffer_size so that the following formulas are true:&lt;br /&gt;
 key_read / key_read_requests &amp;lt; 0.01&lt;br /&gt;
 key_write / key_write_requests &amp;lt;= 1.0&lt;br /&gt;
* Set the &#039;&#039;&#039;maximum number of connections&#039;&#039;&#039; so that your users will not see a &amp;quot;Too many connections&amp;quot; message. Be careful that this may have an impact on the total memory used. MySQL connections usually last for milliseconds, so it is unusual even for a heavily loaded server for this value to be over 200.&lt;br /&gt;
* Manage &#039;&#039;&#039;high burst activity&#039;&#039;&#039;. If your Moodle install uses a lot of quizzes and you are experiencing performance problems (check by monitoring the value of threads_connected - it should not be rising) consider increasing the value of back_log.&lt;br /&gt;
* &#039;&#039;&#039;Optimize your tables weekly and after upgrading Moodle&#039;&#039;&#039;. It is good practice to also optimize your tables after performing a large data deletion exercise, e.g. at the end of your semester or academic year. This will ensure that index files are up to date. Backup your database first and then use:&lt;br /&gt;
 mysql&amp;gt;CHECK TABLE mdl_tablename;&lt;br /&gt;
 mysql&amp;gt;OPTIMIZE TABLE mdl_tablename;&lt;br /&gt;
:The common tables in Moodle to check are mdl_course_sections, mdl_forum_posts, mdl_log and mdl_sessions (if using dbsessions). Any errors need to be corrected using REPAIR TABLE (see the [http://dev.mysql.com/doc/refman/5.0/en/repair-table.html MySQL manual] and this [http://moodle.org/mod/forum/discuss.php?d=58208#p279638 forum script]).&lt;br /&gt;
* &#039;&#039;&#039;Maintain the key distribution&#039;&#039;&#039;. Every month or so it is a good idea to stop the mysql server and run these myisamchk commands.&lt;br /&gt;
 #myisamchk -a -S /pathtomysql/data/moodledir/*.MYI&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: You must stop the mysql database process (mysqld) before running any myisamchk command. If you do not, you risk data loss.&lt;br /&gt;
* Reduce the number of &#039;&#039;&#039;temporary tables saved to disk&#039;&#039;&#039;. Check this with the created_tmp_disk_tables value. If this is relatively large (&amp;gt;5%) increase tmp_table_size until you see a reduction. Note that this will have an impact on RAM usage.&lt;br /&gt;
&lt;br /&gt;
===PostgreSQL performance===&lt;br /&gt;
&lt;br /&gt;
There are some good papers around on tuning PostgreSQL (like [http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server this one]), and Moodle&#039;s case does not seem to be different to the general case.&lt;br /&gt;
&lt;br /&gt;
The first thing to recognise is that if you really need to worry about tuning you should be using a separate machine for the database server. If you are not using a separate machine then the answers to many performance questions are substantially muddied by the memory requirements of the rest of the application.&lt;br /&gt;
&lt;br /&gt;
You should probably &#039;&#039;&#039;enable autovacuum&#039;&#039;&#039;, unless you know what you are doing. Many e-learning sites have predictable periods of low use, so disabling autovacuum and running a specific vacuum at those times can be a good option. Or perhaps leave autovacuum running but do a full vacuum weekly in a quiet period.&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;&#039;shared_buffers&#039;&#039;&#039; to something reasonable. For versions up to 8.1 my testing has shown that peak performance is almost always obtained with buffers &amp;lt; 10000, so if you are using such a version, and have more than 512M of RAM just set shared_buffers to 10,000 (8MB).&lt;br /&gt;
&lt;br /&gt;
The buffer management had a big overhaul in 8.2 and &amp;quot;reasonable&amp;quot; is now a much larger number. I have not conducted performance tests with 8.2, but the recommendations from others are generally that you should now scale shared_buffers much more with memory and may continue to reap benefits even up to values like 100,000 (80MB). Consider using 1-2% of system RAM.&lt;br /&gt;
&lt;br /&gt;
PostgreSQL will also assume that the operating system is caching its files, so setting &#039;&#039;&#039;effective_cache_size&#039;&#039;&#039; to a reasonable value is also a good idea. A reasonable value will usually be (total RAM - RAM in use by programs). If you are running Linux and leave the system running for a day or two you can look at &#039;free&#039; and under the &#039;cached&#039; column you will see what it currently is. Consider taking that number (which is kB) and dividing it by 10 (i.e. allow 20% for other programs cache needs and then divide by 8 to get pages). If you are not using a dedicated database server you will need to decrease that value to account for usage by other programs.&lt;br /&gt;
&lt;br /&gt;
Some other useful parameters that can have positive effects, and the values I would typically set them to on a machine with 4G RAM, are:&lt;br /&gt;
&lt;br /&gt;
 work_mem = 10240&lt;br /&gt;
&lt;br /&gt;
That&#039;s 10M of RAM to use instead of on-disk sorting and so forth. That can give a big speed increase, but it is per connection and 200 connections * 10M is 2G, so it can theoretically chew up a lot of RAM.&lt;br /&gt;
&lt;br /&gt;
 maintenance_work_mem = 163840&lt;br /&gt;
&lt;br /&gt;
That&#039;s 160M of RAM which will be used by (e.g.) VACUUM, index rebuild, cluster and so forth. This should only be used periodically and should be freed when those processes exit, so I believe it is well worth while.&lt;br /&gt;
&lt;br /&gt;
 wal_buffers = 64&lt;br /&gt;
&lt;br /&gt;
These buffers are used for the write-ahead log, and there have been a number of reports on the PostgreSQL mailing lists of improvement from this level of increase.&lt;br /&gt;
&lt;br /&gt;
This is a little out of date now (version 8.0) but still worth a read: http://www.powerpostgresql.com/Docs&lt;br /&gt;
&lt;br /&gt;
And there is lots of good stuff here as well: http://www.varlena.com/GeneralBits/Tidbits/index.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Based on Andrew McMillan&#039;s post at [http://moodle.org/mod/forum/discuss.php?d=68558 Tuning PostgreSQL] forum thread.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Splitting &#039;&#039;&#039;mdl_log&#039;&#039;&#039; to several tables and using a VIEW with UNION to read them as one. (See Tim Hunt [https://moodle.org/mod/forum/discuss.php?d=243531#p1104165 explanation] on the Moodle forums)&lt;br /&gt;
&lt;br /&gt;
===Other database performance links===&lt;br /&gt;
* Consider using a &#039;&#039;&#039;distributed cacheing system&#039;&#039;&#039; like [http://en.wikipedia.org/wiki/Memcached memcached] but note that memcached does not have any security features so it should be used behind a firewall.&lt;br /&gt;
* Consider using PostgreSQL. See [[Arguments in favour of PostgreSQL]] and [http://moodle.org/mod/forum/discuss.php?d=49195 how to migrate from MySQL to PostgreSQL] (forum discussion).&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.0/en/server-parameters.html General advice on tuning MySQL parameters] (advice from the MySQL manual)&lt;br /&gt;
* [http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/ InnoDB performance optimization] taken from the [http://www.mysqlperformanceblog.com/ MySQL performance blog] site.&lt;br /&gt;
&lt;br /&gt;
==Performance of different Moodle modules==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s activity modules, filters, and other plugins can be activated/deactivated. If necessary, you may wish to deactivate some features (such as chat) if not required - but this isn&#039;t necessary. Some notes on the performance of certain modules:&lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;Chat&#039;&#039;&#039; module is [http://moodle.org/mod/forum/discuss.php?d=37979&amp;amp;parent=175079 said] to be a hog in terms of frequent HTTP requests to the main server. This can be reduced by setting the module to use &#039;&#039;Streamed&#039;&#039; updates, or, if you&#039;re using a Unix-based webserver, by running the chat in daemon mode. When using the Chat module use the configuration settings to tune for your expected load. Pay particular attention to the &#039;&#039;chat_old_ping&#039;&#039; and &#039;&#039;chat_refresh&#039;&#039; parameters as these can have greatest impact on server load.&lt;br /&gt;
* The Moodle &#039;&#039;&#039;Cron&#039;&#039;&#039; task is triggered by calling the script &#039;&#039;cron.php&#039;&#039;. If this is called over HTTP (e.g. using wget or curl) it can take a large amount of memory on large installations. If it is called by directly invoking the php command (e.g. &#039;&#039;php -f /path/to/moodle/directory/admin/cli/cron.php&#039;&#039;) efficiency can be much improved.&lt;br /&gt;
* The &#039;&#039;&#039;Recent activities&#039;&#039;&#039; block is consuming too many resources if you have huge number of records &amp;lt;code&amp;gt;mdl_log&amp;lt;/code&amp;gt;. This is being tested to optimize the SQL query.&lt;br /&gt;
* The &#039;&#039;&#039;Quiz&#039;&#039;&#039; module is known to stretch database performance. However, it has been getting better in recent versions, and we don&#039;t know of any good, up-to-date performance measurements. (Here is a [http://moodle.org/mod/forum/discuss.php?d=68579 case study from 2007 with 300 quiz users].). The following suggestions were described by [https://moodle.org/user/view.php?id=94615&amp;amp;course=5 Al Rachels] in [https://moodle.org/mod/forum/discuss.php?d=347126 this forum thread]:&lt;br /&gt;
** make sure both Moodle, and the operating system, are installed on a [https://en.wikipedia.org/wiki/Solid-state_drive solid state drive]&lt;br /&gt;
** upgrade to and use [https://docs.moodle.org/dev/Moodle_and_PHP7 PHP 7]&lt;br /&gt;
** run MySQLTuner and implement its recommendations&lt;br /&gt;
&lt;br /&gt;
See [[Performance settings]] for more information on performance-related Moodle settings.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle: [http://moodle.org/mod/forum/view.php?f=94 Hardware and Performance] forum&lt;br /&gt;
*[http://opensourceelearning.blogspot.be/2012/10/why-your-moodle-site-is-slow-five.html Why Your Moodle Site is Slow: Five Simple Settings] blog post from Jonathan Moore &lt;br /&gt;
*I teach with Moodle perfomance testing: http://www.iteachwithmoodle.com/2012/11/17/moodle-2-4-beta-performance-test-comparison-with-moodle-2-3/&lt;br /&gt;
*[http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs 2.5.2 performance and MUC APC cahe store]&lt;br /&gt;
*[http://jfilip.ca/2013/09/25/moodle-performance-testing-2-4-6-vs-2-5-2-vs-2-6dev/ Moodle performance testing 2.4.6 vs 2.5.2 vs 2.6dev]&lt;br /&gt;
*[http://jfilip.ca/2013/09/24/moodle-performance-analysis-revisted-now-with-mariadb/ Moodle performance analysis revisited (now with MariaDB)]&lt;br /&gt;
*[http://tjhunt.blogspot.ca/2013/05/performance-testing-moodle.html Tim Hunt&#039;s blog (May 2, 2013) on performance testing Moodle]&lt;br /&gt;
*[http://newrelic.com/ New Relic, Application Performance Monitoring]&lt;br /&gt;
*[http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html Performance enhacements for Apache and PHP (Apache Event MPM and PHP-FPM)]&lt;br /&gt;
*[https://scholarlms.net/performance-recommendations/ Performance recommendations]&lt;br /&gt;
&lt;br /&gt;
There have been a lot of discussions on moodle.org about performance, here are some of the more interesting and (potentially) useful ones:&lt;br /&gt;
&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=83057 Performance woes!]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=57028 Performance perspectives - a little script]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=88927 Comments on planned server hardware]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=102978#p461624 Moodle performance in a pil by Martin Langhoff]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=240391#unread Advice on optimising php/db code in moodle2+]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=243531 Moodle 2.5 performance testing at the OU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=273602 100 active users limit with 4vCPU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=336603#p1356423 Performance Tip ... shared...]&lt;br /&gt;
&lt;br /&gt;
[[es:Recomendaciones sobre desempeño]]&lt;br /&gt;
[[fr:Performance]]&lt;br /&gt;
[[ja:パフォーマンス]]&lt;br /&gt;
[[de:Geschwindigkeitsempfehlungen]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Performance_recommendations&amp;diff=135018</id>
		<title>Performance recommendations</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Performance_recommendations&amp;diff=135018"/>
		<updated>2019-08-10T07:54:54Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Install HowTo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
Moodle can be made to perform very well, at small usage levels or scaling up to many thousands of users. The factors involved in performance are basically the same as for any PHP-based database-driven system. When trying to optimize your server, try to focus on the factor which will make the most difference to the user. For example, if you have relatively more users browsing than accessing the database, look to improve the webserver performance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Obtain a baseline benchmark==&lt;br /&gt;
&lt;br /&gt;
Before attempting any optimization, you should obtain a baseline benchmark of the component of the system you are trying to improve. For Linux try [http://lbs.sourceforge.net/ LBS] and for Windows use the Performance Monitor. Once you have quantitative data about how your system is performing currently, you&#039;ll be able to determine if the change you have made has had any real impact.&lt;br /&gt;
&lt;br /&gt;
The overall aim of adjustments to improve performance is to use RAM (cacheing) and to reduce disk-based activity. It is especially important to try to eliminate swap file usage as much as you can. If your system starts swapping, this is a sign that you need more RAM. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;optimization order preference&#039;&#039;&#039; is usually: primary storage (more RAM), secondary storage (faster hard disks/improved hard disk configuration), processor (more and faster).&lt;br /&gt;
&lt;br /&gt;
It can be interesting to install and use the [https://moodle.org/plugins/report_benchmark Benchmark plugin] in order to find the bottlenecks of your system that specifically affect Moodle.&lt;br /&gt;
&lt;br /&gt;
==Scalability==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s design (with clear separation of application layers) allows for strongly scalable setups. (Please check the list of [[Large installations|large Moodle installations]].)&lt;br /&gt;
&lt;br /&gt;
Large sites usually separate the web server and database onto separate servers, although for smaller installations this is typically not necessary.&lt;br /&gt;
&lt;br /&gt;
It is possible to load-balance a Moodle installation, for example by using more than one webserver. The separate webservers should query the same database and refer to the same filestore and cache areas (see [[Caching]]), but otherwise the separation of the application layers is complete enough to make this kind of clustering feasible. Similarly, the database could be a cluster of servers (e.g. a MySQL cluster), but this is not an easy task and you should seek expert support, e.g. from a Moodle Partner.&lt;br /&gt;
&lt;br /&gt;
===Server cluster===&lt;br /&gt;
&lt;br /&gt;
Using Moodle forum discussions:&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=57202 Moodle clustering]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=44470 Software load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=49986 TCP load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=88214 Installation for 3000 simultaneous users]&lt;br /&gt;
&lt;br /&gt;
==Hardware configuration==&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: The fastest and most effective change that you can make to improve performance is to &#039;&#039;&#039;increase the amount of RAM on your web server&#039;&#039;&#039; - get as much as possible (e.g. 4GB or more). Increasing primary memory will reduce the need for processes to swap to disk and will enable your server to handle more users.&lt;br /&gt;
* Better performance is gained by obtaining the best &#039;&#039;&#039;processor capability&#039;&#039;&#039; you can, i.e. dual or dual core processors. A modern BIOS should allow you to enable hyperthreading, but check if this makes a difference to the overall performance of the processors by using a [http://en.wikipedia.org/wiki/Super_PI CPU benchmarking tool].&lt;br /&gt;
* If you can afford them, use &#039;&#039;&#039;SCSI hard disks&#039;&#039;&#039; instead of SATA drives. SATA drives will increase your system&#039;s CPU utilization, whereas SCSI drives have their own integrated processors and come into their own when you have multiple drives. If you must have SATA drives, check that your motherboard and the drives themselves support NCQ (Native Command Queuing).&lt;br /&gt;
* Purchase hard disks with a &#039;&#039;&#039;low seek time&#039;&#039;&#039;. This will improve the overall speed of your system, especially when accessing Moodle&#039;s reports.&lt;br /&gt;
* Size your &#039;&#039;&#039;swap file&#039;&#039;&#039; correctly. The general advice is to set it to 4 x physical RAM.&lt;br /&gt;
* Use a &#039;&#039;&#039;RAID disk system&#039;&#039;&#039;. Although there are many different RAID configurations you can create, the following generally works best:&lt;br /&gt;
** install a hardware RAID controller (if you can)&lt;br /&gt;
** the operating system and swap drive on one set of disks configured as RAID-1.&lt;br /&gt;
** Moodle, Web server and Database server on another set of disks configured as RAID-5.&lt;br /&gt;
* If your &#039;moodledata&#039; area is going to be on relatively slow storage (e.g. NFS mount on to a NAS device) you will probably have performance issues with the default cache configuration (which writes to this storage). See the page on [[Caching]] and consider an alternative. Using [https://en.wikipedia.org/wiki/GlusterFS GlusterFS] / [https://en.wikipedia.org/wiki/OCFS2 OCFS2] / [https://en.wikipedia.org/wiki/GFS2 GFS2] on a [https://en.wikipedia.org/wiki/Storage_Area_Network SAN] device and [https://en.wikipedia.org/wiki/Fibre_Channel Fiber Channel] could improve performance (See more info on the Moodle [https://moodle.org/mod/forum/discuss.php?d=214680#p1123124 forum thread], [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 NFS performance tuing] )&lt;br /&gt;
* Use &#039;&#039;&#039;gigabit ethernet&#039;&#039;&#039; for improved latency and throughput. This is especially important when you have your webserver and database server separated out on different hosts.&lt;br /&gt;
* Check the settings on your &#039;&#039;&#039;network card&#039;&#039;&#039;. You may get an improvement in performance by increasing the use of buffers and transmit/receive descriptors (balance this with processor and memory overheads) and off-loading TCP checksum calculation onto the card instead of the OS.&lt;br /&gt;
*  Read this [http://moodle.org/mod/forum/discuss.php?d=68579 Case Study] on a server stress test with 300 users.  &lt;br /&gt;
* See this [http://elearning.sgu.ac.jp/doc/PT/ accompanying report] on network traffic and server loads.&lt;br /&gt;
* Also see this SFSU presentation at Educause (using VMWare): [http://www.educause.edu/Resources/AnOpenSourceLMSforaMissionCrit/162843]&lt;br /&gt;
&lt;br /&gt;
==Operating System==&lt;br /&gt;
* You can use [http://en.wikipedia.org/wiki/Linux Linux](recommended), Unix-based, Windows or Mac OS X for the server &#039;&#039;&#039;operating system&#039;&#039;&#039;. *nix operating systems generally require less memory than Mac OS X or Windows servers for doing the same task as the server is configured with just a shell interface. Additionally Linux does not have licensing fees attached, but can have a big learning curve if you&#039;re used to another operating system. If you have a large number of processors running SMP, you may also want to consider using a highly tuned OS such as [http://en.wikipedia.org/wiki/Solaris_Operating_Environment Solaris].&lt;br /&gt;
* Check your own OS and &#039;&#039;&#039;vendor specific instructions&#039;&#039;&#039; for optimization steps.&lt;br /&gt;
** For Linux look at the [http://linuxperf.sourceforge.net/ Linux Performance Team] site. &lt;br /&gt;
** For Linux investigate the hdparm command, e.g. hdparm -m16 -d1 can be used to enable read/write on multiple sectors and DMA. Mount disks with the [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 &amp;quot;async&amp;quot; and &amp;quot;noatime&amp;quot;] options.&lt;br /&gt;
** For Windows set the sever to be optimized for network applications (Control Panel, Network Connections, LAN connection, Properties, File &amp;amp; Printer Sharing for Microsoft Networks, Properties, Optimization). You can also search the [http://technet.microsoft.com/ Microsoft TechNet site] for optimization documents.&lt;br /&gt;
&lt;br /&gt;
==Web server performance==&lt;br /&gt;
&lt;br /&gt;
Installing [http://www.mozilla.com/en-US/ Firefox] and the [https://addons.mozilla.org/en-US/firefox/addon/1843 firebug] extension will allow you to watch the time it takes for each page component to load. Also, the [https://addons.mozilla.org/en-US/firefox/addon/5369 Yslow] extension will evaluate your page against Yahoo&#039;s [http://www.skrenta.com/2007/05/14_rules_for_fast_web_pages_by_1.html 14 rules], full text [http://developer.yahoo.com/performance/rules.html Best Practices for Speeding Up Your Web Site], &amp;lt;strike&amp;gt;([http://video.yahoo.com/video/play?vid=1040890 video])&amp;lt;/strike&amp;gt; for fast loading websites.&lt;br /&gt;
&lt;br /&gt;
===PHP performance===&lt;br /&gt;
* You are strongly recommended to use a &#039;&#039;&#039;PHP accelerator&#039;&#039;&#039; to ease CPU load, such as [http://pecl.php.net/apc APC], [http://www.php-accelerator.co.uk/ PHPA], [http://trac.lighttpd.net/xcache/ Xcache], [http://sourceforge.net/projects/wincache WinCache] or [http://eaccelerator.net/ eAccelerator]. (Take care to choose a PHP accelerator that is known to work well with your version of PHP and note that Turck MMCache is [http://turckmmcache.exeprod.com/TheManifestoEnglish no longer maintained] and can cause failures with PHP 5). PHP 5.5 (and newer) includes OpCache and is fully supported and recommended by Moodle&lt;br /&gt;
* Improvements in read/write performance can be improved by putting the cached PHP pages on a [[TMPFS]] filesystem - but remember that you&#039;ll lose the cache contents when there is a power failure or the server is rebooted.&lt;br /&gt;
* Performance of PHP is better when installed as an &#039;&#039;&#039;Apache/IIS6 ISAPI module&#039;&#039;&#039; (rather than a CGI). IIS 7.0/7.5 (Windows Server 2008/R2) users should choose a FastCGI installation for best performance.&lt;br /&gt;
* Also check the &#039;&#039;&#039;memory_limit&#039;&#039;&#039; in php.ini, reduce it to 16M for Moodle version earlier than 1.7 ([http://moodle.org/mod/forum/discuss.php?d=39656 See this forum discussion]). For Moodle 1.7 or later, it is recommended that the value of memory_limit should be 40M. As of [http://www.php.net/ChangeLog-5.php PHP 5.2.1] the default value for the memory_limit directive is 128M.&lt;br /&gt;
* Also see [[PHP_settings_by_Moodle_version]]&lt;br /&gt;
* Use [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html PHP-FPM] (with apache).&lt;br /&gt;
&lt;br /&gt;
===Install HowTo===&lt;br /&gt;
* [http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html APC on CentOS 5.x (linux)]&lt;br /&gt;
* [http://fplanque.com/dev/linux/install-apc-php-cache-debian-lenny APC on Debian (linux)]&lt;br /&gt;
* [http://www.linuxtuts.net/211-installing-memcached-php5-memcache-module-debian-apache2.html MemCache module on Debian (Apache2 and PHP5) ]&lt;br /&gt;
* [https://www.tecmint.com/install-memcached-on-centos-7/ Installing Memcached on CentOS 7.x (linux)] (as of php 7.x, only memcached is available)&lt;br /&gt;
* [https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-memcached-on-centos-7 How To Install and Secure Memcached on CentOS 7]&lt;br /&gt;
* [http://noveckg.blogspot.com/2010/02/installing-eaccelerator-cache-for-php.html Installing eAccelerator on CentOS 5.x (linux)]&lt;br /&gt;
* [https://docs.moodle.org/en/Installing_eAccelerator_In_Ubuntu_Server/ Installing eAccelerator on Ubuntu Server (linux)]&lt;br /&gt;
&lt;br /&gt;
===Apache performance===&lt;br /&gt;
* If you are using Apache on a Windows server, use the build from [http://www.apachelounge.com Apache Lounge] which is reported to have [http://moodle.org/mod/forum/discuss.php?d=93358 performance and stability improvements] compared to the official Apache download. Note that this is an unofficial build, so may not keep up with official releases.&lt;br /&gt;
* Set the &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; directive correctly (&#039;&#039;&#039;MaxClients&#039;&#039;&#039; before Apache 2.4). Use this formula to help (which uses 80% of available memory to leave room for spare):&lt;br /&gt;
 MaxRequestWorkers = Total available memory * 80% / Max memory usage of apache process&lt;br /&gt;
:Memory usage of apache process is usually 10MB but Moodle can easily use up to 100MB per process, so a general rule of thumb is to divide your available memory in megabytes by 100 to get a conservative setting for MaxClients. You are quite likely to find yourself lowering the MaxRequestWorkers from its default of 150 on a Moodle server. To get a more accurate estimate read the value from the shell command:&lt;br /&gt;
 #ps -ylC httpd --sort:rss&lt;br /&gt;
&lt;br /&gt;
:If you need to increase the value of &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; beyond 256, you will also need to set the &#039;&#039;&#039;ServerLimit&#039;&#039;&#039; directive. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: Do not be tempted to set the value of MaxRequestWorkers higher than your available memory as your server will consume more RAM than available and start to swap to disk. &lt;br /&gt;
* Consider reducing the &#039;&#039;&#039;number of modules&#039;&#039;&#039; that Apache loads in the httpd.conf file to the minumum necessary to reduce the memory needed. &lt;br /&gt;
* Use the &#039;&#039;&#039;latest version of Apache&#039;&#039;&#039; - Apache 2 has an improved memory model which reduces memory usage further.&lt;br /&gt;
* For Unix/Linux systems, consider lowering &#039;&#039;&#039;MaxConnectionsPerChild&#039;&#039;&#039; (&#039;&#039;&#039;MaxRequestsPerChild&#039;&#039;&#039; before Apache 2.4) in httpd.conf to as low as 20-30 (if you set it any lower the overhead of forking begins to outweigh the benefits). &lt;br /&gt;
* For a heavily loaded server, consider setting &#039;&#039;&#039;KeepAlive Off&#039;&#039;&#039; (do this only if your Moodle pages do not contain links to resources or uploaded images) or lowering the &#039;&#039;&#039;KeepAliveTimeout&#039;&#039;&#039; to between 2 and 5. The default is 15 (seconds) - the higher the value the more server processes will be kept waiting for possibly idle connections. A more accurate value for KeepAliveTimeout is obtained by observing how long it takes your users to download a page. After altering any of the KeepAlive variables, monitor your CPU utilization as there may be an additional overhead in initiating more worker processes/threads.&lt;br /&gt;
* As an alternative to using KeepAlive Off, consider setting-up a &#039;&#039;&#039;Reverse Proxy server&#039;&#039;&#039; infront of the Moodle server to cache HTML files with images. You can then return Apache to using keep-alives on the Moodle server.&lt;br /&gt;
* If you do not use a .htaccess file, set the &#039;&#039;&#039;AllowOverride&#039;&#039;&#039; variable to AllowOverride None to prevent .htaccess lookups.&lt;br /&gt;
* Set &#039;&#039;&#039;DirectoryIndex&#039;&#039;&#039; correctly so as to avoid content-negotiation. Here&#039;s an example from a production server:&lt;br /&gt;
 DirectoryIndex index.php index.html index.htm&lt;br /&gt;
* Unless you are doing development work on the server, set &#039;&#039;&#039;ExtendedStatus Off&#039;&#039;&#039; and disable mod_info as well as mod_status.&lt;br /&gt;
* Leave &#039;&#039;&#039;HostnameLookups Off&#039;&#039;&#039; (as default) to reduce DNS latency.&lt;br /&gt;
* Consider reducing the value of &#039;&#039;&#039;TimeOut&#039;&#039;&#039; to between 30 to 60 (seconds). &lt;br /&gt;
* For the &#039;&#039;&#039;Options directive&#039;&#039;&#039;, avoid Options Multiviews as this performs a directory scan. To reduce disk I/O further use&lt;br /&gt;
 Options -Indexes FollowSymLinks&lt;br /&gt;
&lt;br /&gt;
* Compression reduces response times by reducing the size of the HTTP response&lt;br /&gt;
# Install and enable mod_deflate - refer to documentation or man pages&lt;br /&gt;
# Add this code to the virtual server config file within the &amp;lt;directory&amp;gt; section for the root directory (or within the .htaccess file if AllowOverrides is On):&lt;br /&gt;
 &amp;lt;ifModule mod_deflate.c&amp;gt;&lt;br /&gt;
   AddOutputFilterByType DEFLATE text/html text/plain text/xml text/x-js text/javascript text/css application/javascript&lt;br /&gt;
 &amp;lt;/ifmodule&amp;gt;&lt;br /&gt;
* Use Apache [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html event] [http://httpd.apache.org/docs/current/mpm.html MPM] (and not the default Prefork or Worker)&lt;br /&gt;
&lt;br /&gt;
===IIS performance===&lt;br /&gt;
All alter this location in the registry:&lt;br /&gt;
 HKLM\SYSTEM\CurrentControlSet\Services\Inetinfo\Parameters\&lt;br /&gt;
* The equivalent to KeepAliveTimeout is &#039;&#039;&#039;ListenBackLog&#039;&#039;&#039; (IIS - registry location is HKLM\ SYSTEM\ CurrentControlSet\ Services\ Inetinfo\ Parameters). Set this to between 2 to 5.&lt;br /&gt;
*Change the &#039;&#039;&#039;MemCacheSize&#039;&#039;&#039; value to adjust the amount of memory (Mb) that IIS will use for its file cache (50% of available memory by default).&lt;br /&gt;
*Change the &#039;&#039;&#039;MaxCachedFileSize&#039;&#039;&#039; to adjust the maximum size of a file cached in the file cache in bytes. Default is 262,144 (256K).&lt;br /&gt;
*Create a new DWORD called &#039;&#039;&#039;ObjectCacheTTL&#039;&#039;&#039; to change the length of time (in milliseconds) that objects in the cache are held in memory. Default is 30,000 milliseconds (30 seconds).&lt;br /&gt;
&lt;br /&gt;
===Lighttpd, NginX and Cherokee performance===&lt;br /&gt;
You can increase server performance by using a &#039;&#039;&#039;light-weight&#039;&#039;&#039; webserver like [http://www.lighttpd.net/ lighttpd],  [http://nginx.net/ nginx] or [http://www.cherokee-project.com/ cherokee] in combination with PHP in FastCGI-mode. Lighttpd was originally created as a proof-of-concept[http://www.lighttpd.net/story] to address the [http://www.kegel.com/c10k.html C10k problem] and while primarily recommended for memory-limited servers, its design origins and asynchronous-IO model make it a suitable and proven[http://blog.lighttpd.net/articles/2006/12/28/lighttpd-powers-5-alexa-top-250-sites] alternative HTTP server for high-load websites and web apps, including Moodle. See the [[lighttpd | MoodleDocs Lighttpd page]] for additional information, configuration example and links.&lt;br /&gt;
&lt;br /&gt;
Alternatively, both [http://www.lighttpd.net/ lighttpd] and [http://nginx.net/ nginx] are capable of performing as a load-balancer and/or reverse-proxy to alleviate load on back-end servers[http://www.linuxjournal.com/article/10108], providing benefit without requiring an actual software change on existing servers.&lt;br /&gt;
&lt;br /&gt;
Do note that these are likely to be the least tested server environments of all particularly if you are using advanced features such as web services and/or Moodle Networking. They are probably best considered for heavily used Moodle sites with relatively simple configurations.&lt;br /&gt;
&lt;br /&gt;
===X-Sendfile===&lt;br /&gt;
&lt;br /&gt;
X-Sendfile modules improve performance when sending large files from Moodle. It is recommended to configure your web server and Moodle to use this feature of available.&lt;br /&gt;
&lt;br /&gt;
Configure web server:&lt;br /&gt;
* Apache - https://tn123.org/mod_xsendfile/&lt;br /&gt;
* Lighttpd - http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file&lt;br /&gt;
* Nginx - http://wiki.nginx.org/XSendfile&lt;br /&gt;
&lt;br /&gt;
Enable support in config.php (see config-dist.php):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Sendfile&#039;;           // Apache {@see https://tn123.org/mod_xsendfile/}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-LIGHTTPD-send-file&#039;; // Lighttpd {@see http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Accel-Redirect&#039;;     // Nginx {@see http://wiki.nginx.org/XSendfile}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure file location prefixes if your server implementation requires it:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfilealiases = array(&lt;br /&gt;
//         &#039;/dataroot/&#039; =&amp;gt; $CFG-&amp;gt;dataroot,&lt;br /&gt;
//         &#039;/cachedir/&#039; =&amp;gt; &#039;/var/www/moodle/cache&#039;,    // for custom $CFG-&amp;gt;cachedir locations&lt;br /&gt;
//         &#039;/localcachedir/&#039; =&amp;gt; &#039;/var/local/cache&#039;,    // for custom $CFG-&amp;gt;localcachedir locations&lt;br /&gt;
//         &#039;/tempdir/&#039;  =&amp;gt; &#039;/var/www/moodle/temp&#039;,     // for custom $CFG-&amp;gt;tempdir locations&lt;br /&gt;
//         &#039;/filedir&#039;   =&amp;gt; &#039;/var/www/moodle/filedir&#039;,  // for custom $CFG-&amp;gt;filedir locations&lt;br /&gt;
//     );&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Database performance==&lt;br /&gt;
&lt;br /&gt;
===MySQL performance===&lt;br /&gt;
&lt;br /&gt;
The following are MySQL specific settings which can be adjusted for better performance in your my.cnf (my.ini in Windows). The file contains a list of settings and their values. To see the current values use these commands&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
 SHOW VARIABLES; &lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: You must make backups of your database before attempting to change any MySQL server configuration. After any change to the my.cnf, restart mysqld.&lt;br /&gt;
&lt;br /&gt;
If you are able, the [http://mysqltuner.com/ MySQLTuner] tool can be run against your MySQL server and will calculate appropriate configuration values for most of the following settings based on your current load, status and variables automatically.&lt;br /&gt;
&lt;br /&gt;
* Enable the &#039;&#039;&#039;query cache&#039;&#039;&#039; with &lt;br /&gt;
 query_cache_type = 1. &lt;br /&gt;
For most Moodle installs, set the following:&lt;br /&gt;
 query_cache_size = 36M &lt;br /&gt;
 query_cache_min_res_unit = 2K. &lt;br /&gt;
The query cache will improve performance if you are doing few updates on the database. &lt;br /&gt;
* Set the &#039;&#039;&#039;table cache&#039;&#039;&#039; correctly. For Moodle 1.6 set &lt;br /&gt;
 table_cache = 256 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min), and for Moodle 1.7 set &lt;br /&gt;
 table_cache = 512 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min). The table cache is used by all threads (connections), so monitor the value of opened_tables to further adjust - if opened_tables &amp;gt; 3 * table_cache(table_open_cache in MySQL &amp;gt; 5.1.2) then increase table_cache upto your OS limit. Note also that the figure for table_cache will also change depending on the number of modules and plugins you have installed. Find the number for your server by executing the mysql statement below. Look at the number returned and set table_cache to this value.&lt;br /&gt;
 mysql&amp;gt;SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema=&#039;yourmoodledbname&#039;;&lt;br /&gt;
* Set the &#039;&#039;&#039;thread cache&#039;&#039;&#039; correctly. Adjust the value so that your thread cache utilization is as close to 100% as possible by this formula:&lt;br /&gt;
 thread cache utilization (%) = (threads_created / connections) * 100&lt;br /&gt;
* The &#039;&#039;&#039;key buffer&#039;&#039;&#039; can improve the access speed to Moodle&#039;s SELECT queries. The correct size depends on the size of the index files (.myi) and in Moodle 1.6 or later (without any additional modules and plugins), the recommendation for this value is key_buffer_size = 32M. Ideally you want the database to be reading once from the disk for every 100 requests so monitor that the value is suitable for your install by adjusting the value of key_buffer_size so that the following formulas are true:&lt;br /&gt;
 key_read / key_read_requests &amp;lt; 0.01&lt;br /&gt;
 key_write / key_write_requests &amp;lt;= 1.0&lt;br /&gt;
* Set the &#039;&#039;&#039;maximum number of connections&#039;&#039;&#039; so that your users will not see a &amp;quot;Too many connections&amp;quot; message. Be careful that this may have an impact on the total memory used. MySQL connections usually last for milliseconds, so it is unusual even for a heavily loaded server for this value to be over 200.&lt;br /&gt;
* Manage &#039;&#039;&#039;high burst activity&#039;&#039;&#039;. If your Moodle install uses a lot of quizzes and you are experiencing performance problems (check by monitoring the value of threads_connected - it should not be rising) consider increasing the value of back_log.&lt;br /&gt;
* &#039;&#039;&#039;Optimize your tables weekly and after upgrading Moodle&#039;&#039;&#039;. It is good practice to also optimize your tables after performing a large data deletion exercise, e.g. at the end of your semester or academic year. This will ensure that index files are up to date. Backup your database first and then use:&lt;br /&gt;
 mysql&amp;gt;CHECK TABLE mdl_tablename;&lt;br /&gt;
 mysql&amp;gt;OPTIMIZE TABLE mdl_tablename;&lt;br /&gt;
:The common tables in Moodle to check are mdl_course_sections, mdl_forum_posts, mdl_log and mdl_sessions (if using dbsessions). Any errors need to be corrected using REPAIR TABLE (see the [http://dev.mysql.com/doc/refman/5.0/en/repair-table.html MySQL manual] and this [http://moodle.org/mod/forum/discuss.php?d=58208#p279638 forum script]).&lt;br /&gt;
* &#039;&#039;&#039;Maintain the key distribution&#039;&#039;&#039;. Every month or so it is a good idea to stop the mysql server and run these myisamchk commands.&lt;br /&gt;
 #myisamchk -a -S /pathtomysql/data/moodledir/*.MYI&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: You must stop the mysql database process (mysqld) before running any myisamchk command. If you do not, you risk data loss.&lt;br /&gt;
* Reduce the number of &#039;&#039;&#039;temporary tables saved to disk&#039;&#039;&#039;. Check this with the created_tmp_disk_tables value. If this is relatively large (&amp;gt;5%) increase tmp_table_size until you see a reduction. Note that this will have an impact on RAM usage.&lt;br /&gt;
&lt;br /&gt;
===PostgreSQL performance===&lt;br /&gt;
&lt;br /&gt;
There are some good papers around on tuning PostgreSQL (like [http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server this one]), and Moodle&#039;s case does not seem to be different to the general case.&lt;br /&gt;
&lt;br /&gt;
The first thing to recognise is that if you really need to worry about tuning you should be using a separate machine for the database server. If you are not using a separate machine then the answers to many performance questions are substantially muddied by the memory requirements of the rest of the application.&lt;br /&gt;
&lt;br /&gt;
You should probably &#039;&#039;&#039;enable autovacuum&#039;&#039;&#039;, unless you know what you are doing. Many e-learning sites have predictable periods of low use, so disabling autovacuum and running a specific vacuum at those times can be a good option. Or perhaps leave autovacuum running but do a full vacuum weekly in a quiet period.&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;&#039;shared_buffers&#039;&#039;&#039; to something reasonable. For versions up to 8.1 my testing has shown that peak performance is almost always obtained with buffers &amp;lt; 10000, so if you are using such a version, and have more than 512M of RAM just set shared_buffers to 10,000 (8MB).&lt;br /&gt;
&lt;br /&gt;
The buffer management had a big overhaul in 8.2 and &amp;quot;reasonable&amp;quot; is now a much larger number. I have not conducted performance tests with 8.2, but the recommendations from others are generally that you should now scale shared_buffers much more with memory and may continue to reap benefits even up to values like 100,000 (80MB). Consider using 1-2% of system RAM.&lt;br /&gt;
&lt;br /&gt;
PostgreSQL will also assume that the operating system is caching its files, so setting &#039;&#039;&#039;effective_cache_size&#039;&#039;&#039; to a reasonable value is also a good idea. A reasonable value will usually be (total RAM - RAM in use by programs). If you are running Linux and leave the system running for a day or two you can look at &#039;free&#039; and under the &#039;cached&#039; column you will see what it currently is. Consider taking that number (which is kB) and dividing it by 10 (i.e. allow 20% for other programs cache needs and then divide by 8 to get pages). If you are not using a dedicated database server you will need to decrease that value to account for usage by other programs.&lt;br /&gt;
&lt;br /&gt;
Some other useful parameters that can have positive effects, and the values I would typically set them to on a machine with 4G RAM, are:&lt;br /&gt;
&lt;br /&gt;
 work_mem = 10240&lt;br /&gt;
&lt;br /&gt;
That&#039;s 10M of RAM to use instead of on-disk sorting and so forth. That can give a big speed increase, but it is per connection and 200 connections * 10M is 2G, so it can theoretically chew up a lot of RAM.&lt;br /&gt;
&lt;br /&gt;
 maintenance_work_mem = 163840&lt;br /&gt;
&lt;br /&gt;
That&#039;s 160M of RAM which will be used by (e.g.) VACUUM, index rebuild, cluster and so forth. This should only be used periodically and should be freed when those processes exit, so I believe it is well worth while.&lt;br /&gt;
&lt;br /&gt;
 wal_buffers = 64&lt;br /&gt;
&lt;br /&gt;
These buffers are used for the write-ahead log, and there have been a number of reports on the PostgreSQL mailing lists of improvement from this level of increase.&lt;br /&gt;
&lt;br /&gt;
This is a little out of date now (version 8.0) but still worth a read: http://www.powerpostgresql.com/Docs&lt;br /&gt;
&lt;br /&gt;
And there is lots of good stuff here as well: http://www.varlena.com/GeneralBits/Tidbits/index.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Based on Andrew McMillan&#039;s post at [http://moodle.org/mod/forum/discuss.php?d=68558 Tuning PostgreSQL] forum thread.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Splitting &#039;&#039;&#039;mdl_log&#039;&#039;&#039; to several tables and using a VIEW with UNION to read them as one. (See Tim Hunt [https://moodle.org/mod/forum/discuss.php?d=243531#p1104165 explanation] on the Moodle forums)&lt;br /&gt;
&lt;br /&gt;
===Other database performance links===&lt;br /&gt;
* Consider using a &#039;&#039;&#039;distributed cacheing system&#039;&#039;&#039; like [http://en.wikipedia.org/wiki/Memcached memcached] but note that memcached does not have any security features so it should be used behind a firewall.&lt;br /&gt;
* Consider using PostgreSQL. See [[Arguments in favour of PostgreSQL]] and [http://moodle.org/mod/forum/discuss.php?d=49195 how to migrate from MySQL to PostgreSQL] (forum discussion).&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.0/en/server-parameters.html General advice on tuning MySQL parameters] (advice from the MySQL manual)&lt;br /&gt;
* [http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/ InnoDB performance optimization] taken from the [http://www.mysqlperformanceblog.com/ MySQL performance blog] site.&lt;br /&gt;
&lt;br /&gt;
==Performance of different Moodle modules==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s activity modules, filters, and other plugins can be activated/deactivated. If necessary, you may wish to deactivate some features (such as chat) if not required - but this isn&#039;t necessary. Some notes on the performance of certain modules:&lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;Chat&#039;&#039;&#039; module is [http://moodle.org/mod/forum/discuss.php?d=37979&amp;amp;parent=175079 said] to be a hog in terms of frequent HTTP requests to the main server. This can be reduced by setting the module to use &#039;&#039;Streamed&#039;&#039; updates, or, if you&#039;re using a Unix-based webserver, by running the chat in daemon mode. When using the Chat module use the configuration settings to tune for your expected load. Pay particular attention to the &#039;&#039;chat_old_ping&#039;&#039; and &#039;&#039;chat_refresh&#039;&#039; parameters as these can have greatest impact on server load.&lt;br /&gt;
* The Moodle &#039;&#039;&#039;Cron&#039;&#039;&#039; task is triggered by calling the script &#039;&#039;cron.php&#039;&#039;. If this is called over HTTP (e.g. using wget or curl) it can take a large amount of memory on large installations. If it is called by directly invoking the php command (e.g. &#039;&#039;php -f /path/to/moodle/directory/admin/cli/cron.php&#039;&#039;) efficiency can be much improved.&lt;br /&gt;
* The &#039;&#039;&#039;Recent activities&#039;&#039;&#039; block is consuming too many resources if you have huge number of records &amp;lt;code&amp;gt;mdl_log&amp;lt;/code&amp;gt;. This is being tested to optimize the SQL query.&lt;br /&gt;
* The &#039;&#039;&#039;Quiz&#039;&#039;&#039; module is known to stretch database performance. However, it has been getting better in recent versions, and we don&#039;t know of any good, up-to-date performance measurements. (Here is a [http://moodle.org/mod/forum/discuss.php?d=68579 case study from 2007 with 300 quiz users].). The following suggestions were described by [https://moodle.org/user/view.php?id=94615&amp;amp;course=5 Al Rachels] in [https://moodle.org/mod/forum/discuss.php?d=347126 this forum thread]:&lt;br /&gt;
** make sure both Moodle, and the operating system, are installed on a [https://en.wikipedia.org/wiki/Solid-state_drive solid state drive]&lt;br /&gt;
** upgrade to and use [https://docs.moodle.org/dev/Moodle_and_PHP7 PHP 7]&lt;br /&gt;
** run MySQLTuner and implement its recommendations&lt;br /&gt;
&lt;br /&gt;
See [[Performance settings]] for more information on performance-related Moodle settings.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle: [http://moodle.org/mod/forum/view.php?f=94 Hardware and Performance] forum&lt;br /&gt;
*[http://opensourceelearning.blogspot.be/2012/10/why-your-moodle-site-is-slow-five.html Why Your Moodle Site is Slow: Five Simple Settings] blog post from Jonathan Moore &lt;br /&gt;
*I teach with Moodle perfomance testing: http://www.iteachwithmoodle.com/2012/11/17/moodle-2-4-beta-performance-test-comparison-with-moodle-2-3/&lt;br /&gt;
*[http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs 2.5.2 performance and MUC APC cahe store]&lt;br /&gt;
*[http://jfilip.ca/2013/09/25/moodle-performance-testing-2-4-6-vs-2-5-2-vs-2-6dev/ Moodle performance testing 2.4.6 vs 2.5.2 vs 2.6dev]&lt;br /&gt;
*[http://jfilip.ca/2013/09/24/moodle-performance-analysis-revisted-now-with-mariadb/ Moodle performance analysis revisited (now with MariaDB)]&lt;br /&gt;
*[http://tjhunt.blogspot.ca/2013/05/performance-testing-moodle.html Tim Hunt&#039;s blog (May 2, 2013) on performance testing Moodle]&lt;br /&gt;
*[http://newrelic.com/ New Relic, Application Performance Monitoring]&lt;br /&gt;
*[http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html Performance enhacements for Apache and PHP (Apache Event MPM and PHP-FPM)]&lt;br /&gt;
*[https://scholarlms.net/performance-recommendations/ Performance recommendations]&lt;br /&gt;
&lt;br /&gt;
There have been a lot of discussions on moodle.org about performance, here are some of the more interesting and (potentially) useful ones:&lt;br /&gt;
&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=83057 Performance woes!]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=57028 Performance perspectives - a little script]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=88927 Comments on planned server hardware]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=102978#p461624 Moodle performance in a pil by Martin Langhoff]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=240391#unread Advice on optimising php/db code in moodle2+]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=243531 Moodle 2.5 performance testing at the OU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=273602 100 active users limit with 4vCPU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=336603#p1356423 Performance Tip ... shared...]&lt;br /&gt;
&lt;br /&gt;
[[es:Recomendaciones sobre desempeño]]&lt;br /&gt;
[[fr:Performance]]&lt;br /&gt;
[[ja:パフォーマンス]]&lt;br /&gt;
[[de:Geschwindigkeitsempfehlungen]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Caching&amp;diff=135017</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Caching&amp;diff=135017"/>
		<updated>2019-08-10T07:51:21Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Memcached */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
Moodle 2.4 saw the implementation of MUC, the Moodle Universal Cache. This new system allows certain functions of Moodle (eg string fetching) take advantage of different installed cache services (eg files, ram, memcached).&lt;br /&gt;
&lt;br /&gt;
In future versions of Moodle we will continue expanding the number of Moodle functions that use MUC, which will continue improving performance, but you can already start using it to improve your site.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
Since Moodle 2.4, Moodle has provided a caching plugin framework to give administrators the ability to control where Moodle stores cached data. For most Moodle sites the default configuration should be sufficient and it is not necessary to change the configuration. For larger Moodle sites with multiple servers, administrators may wish to use memcached, mongodb or other systems to store cache data. The cache plugin screen provides administrators with the ability to configure what cache data is stored where.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to as MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Let&#039;s start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar with, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than an area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
If you have a system with multiple front-end web servers, the application cache must be shared between the servers. In other words, you cannot use fast local storage for the application cache, but must use shared storage or some other form of shared cache such as a shared memcached.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcached server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above. The standard Moodle has the three defaults mentioned above as well as Memcached, MongoDB, [[APC user cache (APCu)|APC user cache (APCu)]] and [[Redis cache store|Redis]].&lt;br /&gt;
&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&lt;br /&gt;
&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcached servers, for instance, you can create a cache store instance for each. Moodle by default contains three cache store instances that get used when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored in your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Let&#039;s keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcached, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that, you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecture again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it. A cache by nature is volatile and any information that is absolutely mission critical should be a more permanent data store likely the database.&lt;br /&gt;
&lt;br /&gt;
Nonetheless there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However, in some situations, it&#039;s beneficial to allow multiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course, not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID: This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version: All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key: For this, you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone: The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on a server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share in many situations, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is important to consider with the language cache that by sharing it between sites any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:cacheadmin29.png|thumb|500px|The cache configuration screen]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in  &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:ist29.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any PHP requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores, it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:csi29.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039;: The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039;: The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready &#039;&#039;&#039;: A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039;: The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039;: The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039;: The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking &#039;&#039;&#039;: Locking is a mechanism that restricts access to cached data to one process at a time to prevent the data from being overwritten. The locking method determines how the lock is acquired and checked.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039;: Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really it&#039;s like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039;: The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component &#039;&#039;&#039;: The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039;: The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039;: The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039;: How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039;: Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during an upgrade, and if a new cache definition is encountered. However, should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. It is useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default, just a single locking mechanism is available, file locking.&lt;br /&gt;
At present, there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are no specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
To simplify that, this shows the default cache stores for each type.&lt;br /&gt;
&lt;br /&gt;
At the bottom, you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however, you may be able to improve the performance of your sites by making use of various caching backends and techniques. The first thing you are going to want to do is to add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes your intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039;: Allows you to specify a directory to use when storing cache data on the file system. Of course the user the web server is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039;: If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039;: By default, the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely to hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039;: One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default, the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you have an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many Linux installations these days, for example, use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is a different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course, you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
Whatever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
You must first have a [https://docs.moodle.org/310/en/Performance_recommendations#Install_HowTo Memcached server] you can access and have the [https://docs.moodle.org/310/en/Performance_recommendations#Install_HowTo Memcached PHP extension] installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
There are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039;: It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039;: The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039;: Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039;: Allows you to select which serialiser gets used when communicating with the Memcached server. By default the Memcached extension and PHP only provide one serialised, however, there is a couple of others available for installation if you go looking for them. One, for example, is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039;: Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039;: The hash method provided by the Memcached extension is used by default here. However, you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes &#039;&#039;&#039;: Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interactions are taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcached extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this, it is important to note that when you purge a Memcached store within Moodle it deletes ALL entries in the Memcached server. Not just those relating to Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
For that reason, it is highly recommended to use dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use the same servers. Doing so may lead to performance depreciation and adverse effects.&lt;br /&gt;
* Likewise if you want to use Memcached for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise, a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mongodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039;: Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server &#039;&#039;&#039;: This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database &#039;&#039;&#039;: The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039;: The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password &#039;&#039;&#039;: The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set &#039;&#039;&#039;: The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039;: If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039;: You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039;: If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add a small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and, most importantly, optimise the performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column select the link for &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
You are presented with several drop-downs that allow you to map one or more cached. All mapped caches get interacted with. The &amp;quot;Primary&amp;quot; store is the store that will be used first when interacting with the cache.&lt;br /&gt;
The &amp;quot;Final&amp;quot; mapped store will be the last cache store interacted with.&amp;lt;br /&amp;gt;&lt;br /&gt;
How this interaction occurs is documented below.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039;: Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it, it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it, then fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039;: Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039;: Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continues until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039;: Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage of assigning multiple stores is that you can introduce cache redundancy. Of course, this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Scenario:&lt;br /&gt;
You have a web server that has a Moodle site as well as other sites.&lt;br /&gt;
You also have a Memcached server that is used by several sites including Moodle.&lt;br /&gt;
&lt;br /&gt;
Memcached has a limited size cache, that when full and requested to store more information frees space by dropping the least used cache entries.&lt;br /&gt;
&lt;br /&gt;
You want to use Memcached for your Moodle site because it is fast, however, you are aware that it may introduce more cache misses because it is a heavily used Memcached server.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcached.&lt;br /&gt;
You make Memcached the primary store, and you make the default file store the final cache store.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
By doing this you&#039;ve created redundancy; when something is requested, Moodle first tries to get it from Memcached (the fastest store) and if it is not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately, there is no step-by-step guide to this.&lt;br /&gt;
&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered are some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&lt;br /&gt;
&lt;br /&gt;
If you are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before telling Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcached installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcached server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcached for instance drops least used data when full to make room for new entries. APC, on the other hand, stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
===More on performance testing===&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
===Performance advice for load-balanced web servers===&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
&lt;br /&gt;
Have you encountered a problem, or found yourself in a conundrum? Perhaps the answer is in this section. If not when you find an answer, how about you share it here.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=378416#p1526130 Why using a not-completely-shared application cache will fail]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[MUC FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;br /&gt;
[[fr:Mettre en cache]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Performance_recommendations&amp;diff=135016</id>
		<title>Performance recommendations</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Performance_recommendations&amp;diff=135016"/>
		<updated>2019-08-10T07:47:19Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Install HowTo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
Moodle can be made to perform very well, at small usage levels or scaling up to many thousands of users. The factors involved in performance are basically the same as for any PHP-based database-driven system. When trying to optimize your server, try to focus on the factor which will make the most difference to the user. For example, if you have relatively more users browsing than accessing the database, look to improve the webserver performance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Obtain a baseline benchmark==&lt;br /&gt;
&lt;br /&gt;
Before attempting any optimization, you should obtain a baseline benchmark of the component of the system you are trying to improve. For Linux try [http://lbs.sourceforge.net/ LBS] and for Windows use the Performance Monitor. Once you have quantitative data about how your system is performing currently, you&#039;ll be able to determine if the change you have made has had any real impact.&lt;br /&gt;
&lt;br /&gt;
The overall aim of adjustments to improve performance is to use RAM (cacheing) and to reduce disk-based activity. It is especially important to try to eliminate swap file usage as much as you can. If your system starts swapping, this is a sign that you need more RAM. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;optimization order preference&#039;&#039;&#039; is usually: primary storage (more RAM), secondary storage (faster hard disks/improved hard disk configuration), processor (more and faster).&lt;br /&gt;
&lt;br /&gt;
It can be interesting to install and use the [https://moodle.org/plugins/report_benchmark Benchmark plugin] in order to find the bottlenecks of your system that specifically affect Moodle.&lt;br /&gt;
&lt;br /&gt;
==Scalability==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s design (with clear separation of application layers) allows for strongly scalable setups. (Please check the list of [[Large installations|large Moodle installations]].)&lt;br /&gt;
&lt;br /&gt;
Large sites usually separate the web server and database onto separate servers, although for smaller installations this is typically not necessary.&lt;br /&gt;
&lt;br /&gt;
It is possible to load-balance a Moodle installation, for example by using more than one webserver. The separate webservers should query the same database and refer to the same filestore and cache areas (see [[Caching]]), but otherwise the separation of the application layers is complete enough to make this kind of clustering feasible. Similarly, the database could be a cluster of servers (e.g. a MySQL cluster), but this is not an easy task and you should seek expert support, e.g. from a Moodle Partner.&lt;br /&gt;
&lt;br /&gt;
===Server cluster===&lt;br /&gt;
&lt;br /&gt;
Using Moodle forum discussions:&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=57202 Moodle clustering]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=44470 Software load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=49986 TCP load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=88214 Installation for 3000 simultaneous users]&lt;br /&gt;
&lt;br /&gt;
==Hardware configuration==&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: The fastest and most effective change that you can make to improve performance is to &#039;&#039;&#039;increase the amount of RAM on your web server&#039;&#039;&#039; - get as much as possible (e.g. 4GB or more). Increasing primary memory will reduce the need for processes to swap to disk and will enable your server to handle more users.&lt;br /&gt;
* Better performance is gained by obtaining the best &#039;&#039;&#039;processor capability&#039;&#039;&#039; you can, i.e. dual or dual core processors. A modern BIOS should allow you to enable hyperthreading, but check if this makes a difference to the overall performance of the processors by using a [http://en.wikipedia.org/wiki/Super_PI CPU benchmarking tool].&lt;br /&gt;
* If you can afford them, use &#039;&#039;&#039;SCSI hard disks&#039;&#039;&#039; instead of SATA drives. SATA drives will increase your system&#039;s CPU utilization, whereas SCSI drives have their own integrated processors and come into their own when you have multiple drives. If you must have SATA drives, check that your motherboard and the drives themselves support NCQ (Native Command Queuing).&lt;br /&gt;
* Purchase hard disks with a &#039;&#039;&#039;low seek time&#039;&#039;&#039;. This will improve the overall speed of your system, especially when accessing Moodle&#039;s reports.&lt;br /&gt;
* Size your &#039;&#039;&#039;swap file&#039;&#039;&#039; correctly. The general advice is to set it to 4 x physical RAM.&lt;br /&gt;
* Use a &#039;&#039;&#039;RAID disk system&#039;&#039;&#039;. Although there are many different RAID configurations you can create, the following generally works best:&lt;br /&gt;
** install a hardware RAID controller (if you can)&lt;br /&gt;
** the operating system and swap drive on one set of disks configured as RAID-1.&lt;br /&gt;
** Moodle, Web server and Database server on another set of disks configured as RAID-5.&lt;br /&gt;
* If your &#039;moodledata&#039; area is going to be on relatively slow storage (e.g. NFS mount on to a NAS device) you will probably have performance issues with the default cache configuration (which writes to this storage). See the page on [[Caching]] and consider an alternative. Using [https://en.wikipedia.org/wiki/GlusterFS GlusterFS] / [https://en.wikipedia.org/wiki/OCFS2 OCFS2] / [https://en.wikipedia.org/wiki/GFS2 GFS2] on a [https://en.wikipedia.org/wiki/Storage_Area_Network SAN] device and [https://en.wikipedia.org/wiki/Fibre_Channel Fiber Channel] could improve performance (See more info on the Moodle [https://moodle.org/mod/forum/discuss.php?d=214680#p1123124 forum thread], [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 NFS performance tuing] )&lt;br /&gt;
* Use &#039;&#039;&#039;gigabit ethernet&#039;&#039;&#039; for improved latency and throughput. This is especially important when you have your webserver and database server separated out on different hosts.&lt;br /&gt;
* Check the settings on your &#039;&#039;&#039;network card&#039;&#039;&#039;. You may get an improvement in performance by increasing the use of buffers and transmit/receive descriptors (balance this with processor and memory overheads) and off-loading TCP checksum calculation onto the card instead of the OS.&lt;br /&gt;
*  Read this [http://moodle.org/mod/forum/discuss.php?d=68579 Case Study] on a server stress test with 300 users.  &lt;br /&gt;
* See this [http://elearning.sgu.ac.jp/doc/PT/ accompanying report] on network traffic and server loads.&lt;br /&gt;
* Also see this SFSU presentation at Educause (using VMWare): [http://www.educause.edu/Resources/AnOpenSourceLMSforaMissionCrit/162843]&lt;br /&gt;
&lt;br /&gt;
==Operating System==&lt;br /&gt;
* You can use [http://en.wikipedia.org/wiki/Linux Linux](recommended), Unix-based, Windows or Mac OS X for the server &#039;&#039;&#039;operating system&#039;&#039;&#039;. *nix operating systems generally require less memory than Mac OS X or Windows servers for doing the same task as the server is configured with just a shell interface. Additionally Linux does not have licensing fees attached, but can have a big learning curve if you&#039;re used to another operating system. If you have a large number of processors running SMP, you may also want to consider using a highly tuned OS such as [http://en.wikipedia.org/wiki/Solaris_Operating_Environment Solaris].&lt;br /&gt;
* Check your own OS and &#039;&#039;&#039;vendor specific instructions&#039;&#039;&#039; for optimization steps.&lt;br /&gt;
** For Linux look at the [http://linuxperf.sourceforge.net/ Linux Performance Team] site. &lt;br /&gt;
** For Linux investigate the hdparm command, e.g. hdparm -m16 -d1 can be used to enable read/write on multiple sectors and DMA. Mount disks with the [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 &amp;quot;async&amp;quot; and &amp;quot;noatime&amp;quot;] options.&lt;br /&gt;
** For Windows set the sever to be optimized for network applications (Control Panel, Network Connections, LAN connection, Properties, File &amp;amp; Printer Sharing for Microsoft Networks, Properties, Optimization). You can also search the [http://technet.microsoft.com/ Microsoft TechNet site] for optimization documents.&lt;br /&gt;
&lt;br /&gt;
==Web server performance==&lt;br /&gt;
&lt;br /&gt;
Installing [http://www.mozilla.com/en-US/ Firefox] and the [https://addons.mozilla.org/en-US/firefox/addon/1843 firebug] extension will allow you to watch the time it takes for each page component to load. Also, the [https://addons.mozilla.org/en-US/firefox/addon/5369 Yslow] extension will evaluate your page against Yahoo&#039;s [http://www.skrenta.com/2007/05/14_rules_for_fast_web_pages_by_1.html 14 rules], full text [http://developer.yahoo.com/performance/rules.html Best Practices for Speeding Up Your Web Site], &amp;lt;strike&amp;gt;([http://video.yahoo.com/video/play?vid=1040890 video])&amp;lt;/strike&amp;gt; for fast loading websites.&lt;br /&gt;
&lt;br /&gt;
===PHP performance===&lt;br /&gt;
* You are strongly recommended to use a &#039;&#039;&#039;PHP accelerator&#039;&#039;&#039; to ease CPU load, such as [http://pecl.php.net/apc APC], [http://www.php-accelerator.co.uk/ PHPA], [http://trac.lighttpd.net/xcache/ Xcache], [http://sourceforge.net/projects/wincache WinCache] or [http://eaccelerator.net/ eAccelerator]. (Take care to choose a PHP accelerator that is known to work well with your version of PHP and note that Turck MMCache is [http://turckmmcache.exeprod.com/TheManifestoEnglish no longer maintained] and can cause failures with PHP 5). PHP 5.5 (and newer) includes OpCache and is fully supported and recommended by Moodle&lt;br /&gt;
* Improvements in read/write performance can be improved by putting the cached PHP pages on a [[TMPFS]] filesystem - but remember that you&#039;ll lose the cache contents when there is a power failure or the server is rebooted.&lt;br /&gt;
* Performance of PHP is better when installed as an &#039;&#039;&#039;Apache/IIS6 ISAPI module&#039;&#039;&#039; (rather than a CGI). IIS 7.0/7.5 (Windows Server 2008/R2) users should choose a FastCGI installation for best performance.&lt;br /&gt;
* Also check the &#039;&#039;&#039;memory_limit&#039;&#039;&#039; in php.ini, reduce it to 16M for Moodle version earlier than 1.7 ([http://moodle.org/mod/forum/discuss.php?d=39656 See this forum discussion]). For Moodle 1.7 or later, it is recommended that the value of memory_limit should be 40M. As of [http://www.php.net/ChangeLog-5.php PHP 5.2.1] the default value for the memory_limit directive is 128M.&lt;br /&gt;
* Also see [[PHP_settings_by_Moodle_version]]&lt;br /&gt;
* Use [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html PHP-FPM] (with apache).&lt;br /&gt;
&lt;br /&gt;
===Install HowTo===&lt;br /&gt;
* [http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html APC on CentOS 5.x (linux)]&lt;br /&gt;
* [http://fplanque.com/dev/linux/install-apc-php-cache-debian-lenny APC on Debian (linux)]&lt;br /&gt;
* [http://www.linuxtuts.net/211-installing-memcached-php5-memcache-module-debian-apache2.html MemCache module on Debian (Apache2 and PHP5) ]&lt;br /&gt;
* [https://www.tecmint.com/install-memcached-on-centos-7/ Installing Memcached on CentOS 7.x (linux)] (as of php 7.x, only memcached is available)&lt;br /&gt;
* [http://noveckg.blogspot.com/2010/02/installing-eaccelerator-cache-for-php.html Installing eAccelerator on CentOS 5.x (linux)]&lt;br /&gt;
* [https://docs.moodle.org/en/Installing_eAccelerator_In_Ubuntu_Server/ Installing eAccelerator on Ubuntu Server (linux)]&lt;br /&gt;
&lt;br /&gt;
===Apache performance===&lt;br /&gt;
* If you are using Apache on a Windows server, use the build from [http://www.apachelounge.com Apache Lounge] which is reported to have [http://moodle.org/mod/forum/discuss.php?d=93358 performance and stability improvements] compared to the official Apache download. Note that this is an unofficial build, so may not keep up with official releases.&lt;br /&gt;
* Set the &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; directive correctly (&#039;&#039;&#039;MaxClients&#039;&#039;&#039; before Apache 2.4). Use this formula to help (which uses 80% of available memory to leave room for spare):&lt;br /&gt;
 MaxRequestWorkers = Total available memory * 80% / Max memory usage of apache process&lt;br /&gt;
:Memory usage of apache process is usually 10MB but Moodle can easily use up to 100MB per process, so a general rule of thumb is to divide your available memory in megabytes by 100 to get a conservative setting for MaxClients. You are quite likely to find yourself lowering the MaxRequestWorkers from its default of 150 on a Moodle server. To get a more accurate estimate read the value from the shell command:&lt;br /&gt;
 #ps -ylC httpd --sort:rss&lt;br /&gt;
&lt;br /&gt;
:If you need to increase the value of &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; beyond 256, you will also need to set the &#039;&#039;&#039;ServerLimit&#039;&#039;&#039; directive. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: Do not be tempted to set the value of MaxRequestWorkers higher than your available memory as your server will consume more RAM than available and start to swap to disk. &lt;br /&gt;
* Consider reducing the &#039;&#039;&#039;number of modules&#039;&#039;&#039; that Apache loads in the httpd.conf file to the minumum necessary to reduce the memory needed. &lt;br /&gt;
* Use the &#039;&#039;&#039;latest version of Apache&#039;&#039;&#039; - Apache 2 has an improved memory model which reduces memory usage further.&lt;br /&gt;
* For Unix/Linux systems, consider lowering &#039;&#039;&#039;MaxConnectionsPerChild&#039;&#039;&#039; (&#039;&#039;&#039;MaxRequestsPerChild&#039;&#039;&#039; before Apache 2.4) in httpd.conf to as low as 20-30 (if you set it any lower the overhead of forking begins to outweigh the benefits). &lt;br /&gt;
* For a heavily loaded server, consider setting &#039;&#039;&#039;KeepAlive Off&#039;&#039;&#039; (do this only if your Moodle pages do not contain links to resources or uploaded images) or lowering the &#039;&#039;&#039;KeepAliveTimeout&#039;&#039;&#039; to between 2 and 5. The default is 15 (seconds) - the higher the value the more server processes will be kept waiting for possibly idle connections. A more accurate value for KeepAliveTimeout is obtained by observing how long it takes your users to download a page. After altering any of the KeepAlive variables, monitor your CPU utilization as there may be an additional overhead in initiating more worker processes/threads.&lt;br /&gt;
* As an alternative to using KeepAlive Off, consider setting-up a &#039;&#039;&#039;Reverse Proxy server&#039;&#039;&#039; infront of the Moodle server to cache HTML files with images. You can then return Apache to using keep-alives on the Moodle server.&lt;br /&gt;
* If you do not use a .htaccess file, set the &#039;&#039;&#039;AllowOverride&#039;&#039;&#039; variable to AllowOverride None to prevent .htaccess lookups.&lt;br /&gt;
* Set &#039;&#039;&#039;DirectoryIndex&#039;&#039;&#039; correctly so as to avoid content-negotiation. Here&#039;s an example from a production server:&lt;br /&gt;
 DirectoryIndex index.php index.html index.htm&lt;br /&gt;
* Unless you are doing development work on the server, set &#039;&#039;&#039;ExtendedStatus Off&#039;&#039;&#039; and disable mod_info as well as mod_status.&lt;br /&gt;
* Leave &#039;&#039;&#039;HostnameLookups Off&#039;&#039;&#039; (as default) to reduce DNS latency.&lt;br /&gt;
* Consider reducing the value of &#039;&#039;&#039;TimeOut&#039;&#039;&#039; to between 30 to 60 (seconds). &lt;br /&gt;
* For the &#039;&#039;&#039;Options directive&#039;&#039;&#039;, avoid Options Multiviews as this performs a directory scan. To reduce disk I/O further use&lt;br /&gt;
 Options -Indexes FollowSymLinks&lt;br /&gt;
&lt;br /&gt;
* Compression reduces response times by reducing the size of the HTTP response&lt;br /&gt;
# Install and enable mod_deflate - refer to documentation or man pages&lt;br /&gt;
# Add this code to the virtual server config file within the &amp;lt;directory&amp;gt; section for the root directory (or within the .htaccess file if AllowOverrides is On):&lt;br /&gt;
 &amp;lt;ifModule mod_deflate.c&amp;gt;&lt;br /&gt;
   AddOutputFilterByType DEFLATE text/html text/plain text/xml text/x-js text/javascript text/css application/javascript&lt;br /&gt;
 &amp;lt;/ifmodule&amp;gt;&lt;br /&gt;
* Use Apache [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html event] [http://httpd.apache.org/docs/current/mpm.html MPM] (and not the default Prefork or Worker)&lt;br /&gt;
&lt;br /&gt;
===IIS performance===&lt;br /&gt;
All alter this location in the registry:&lt;br /&gt;
 HKLM\SYSTEM\CurrentControlSet\Services\Inetinfo\Parameters\&lt;br /&gt;
* The equivalent to KeepAliveTimeout is &#039;&#039;&#039;ListenBackLog&#039;&#039;&#039; (IIS - registry location is HKLM\ SYSTEM\ CurrentControlSet\ Services\ Inetinfo\ Parameters). Set this to between 2 to 5.&lt;br /&gt;
*Change the &#039;&#039;&#039;MemCacheSize&#039;&#039;&#039; value to adjust the amount of memory (Mb) that IIS will use for its file cache (50% of available memory by default).&lt;br /&gt;
*Change the &#039;&#039;&#039;MaxCachedFileSize&#039;&#039;&#039; to adjust the maximum size of a file cached in the file cache in bytes. Default is 262,144 (256K).&lt;br /&gt;
*Create a new DWORD called &#039;&#039;&#039;ObjectCacheTTL&#039;&#039;&#039; to change the length of time (in milliseconds) that objects in the cache are held in memory. Default is 30,000 milliseconds (30 seconds).&lt;br /&gt;
&lt;br /&gt;
===Lighttpd, NginX and Cherokee performance===&lt;br /&gt;
You can increase server performance by using a &#039;&#039;&#039;light-weight&#039;&#039;&#039; webserver like [http://www.lighttpd.net/ lighttpd],  [http://nginx.net/ nginx] or [http://www.cherokee-project.com/ cherokee] in combination with PHP in FastCGI-mode. Lighttpd was originally created as a proof-of-concept[http://www.lighttpd.net/story] to address the [http://www.kegel.com/c10k.html C10k problem] and while primarily recommended for memory-limited servers, its design origins and asynchronous-IO model make it a suitable and proven[http://blog.lighttpd.net/articles/2006/12/28/lighttpd-powers-5-alexa-top-250-sites] alternative HTTP server for high-load websites and web apps, including Moodle. See the [[lighttpd | MoodleDocs Lighttpd page]] for additional information, configuration example and links.&lt;br /&gt;
&lt;br /&gt;
Alternatively, both [http://www.lighttpd.net/ lighttpd] and [http://nginx.net/ nginx] are capable of performing as a load-balancer and/or reverse-proxy to alleviate load on back-end servers[http://www.linuxjournal.com/article/10108], providing benefit without requiring an actual software change on existing servers.&lt;br /&gt;
&lt;br /&gt;
Do note that these are likely to be the least tested server environments of all particularly if you are using advanced features such as web services and/or Moodle Networking. They are probably best considered for heavily used Moodle sites with relatively simple configurations.&lt;br /&gt;
&lt;br /&gt;
===X-Sendfile===&lt;br /&gt;
&lt;br /&gt;
X-Sendfile modules improve performance when sending large files from Moodle. It is recommended to configure your web server and Moodle to use this feature of available.&lt;br /&gt;
&lt;br /&gt;
Configure web server:&lt;br /&gt;
* Apache - https://tn123.org/mod_xsendfile/&lt;br /&gt;
* Lighttpd - http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file&lt;br /&gt;
* Nginx - http://wiki.nginx.org/XSendfile&lt;br /&gt;
&lt;br /&gt;
Enable support in config.php (see config-dist.php):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Sendfile&#039;;           // Apache {@see https://tn123.org/mod_xsendfile/}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-LIGHTTPD-send-file&#039;; // Lighttpd {@see http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Accel-Redirect&#039;;     // Nginx {@see http://wiki.nginx.org/XSendfile}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure file location prefixes if your server implementation requires it:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfilealiases = array(&lt;br /&gt;
//         &#039;/dataroot/&#039; =&amp;gt; $CFG-&amp;gt;dataroot,&lt;br /&gt;
//         &#039;/cachedir/&#039; =&amp;gt; &#039;/var/www/moodle/cache&#039;,    // for custom $CFG-&amp;gt;cachedir locations&lt;br /&gt;
//         &#039;/localcachedir/&#039; =&amp;gt; &#039;/var/local/cache&#039;,    // for custom $CFG-&amp;gt;localcachedir locations&lt;br /&gt;
//         &#039;/tempdir/&#039;  =&amp;gt; &#039;/var/www/moodle/temp&#039;,     // for custom $CFG-&amp;gt;tempdir locations&lt;br /&gt;
//         &#039;/filedir&#039;   =&amp;gt; &#039;/var/www/moodle/filedir&#039;,  // for custom $CFG-&amp;gt;filedir locations&lt;br /&gt;
//     );&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Database performance==&lt;br /&gt;
&lt;br /&gt;
===MySQL performance===&lt;br /&gt;
&lt;br /&gt;
The following are MySQL specific settings which can be adjusted for better performance in your my.cnf (my.ini in Windows). The file contains a list of settings and their values. To see the current values use these commands&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
 SHOW VARIABLES; &lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: You must make backups of your database before attempting to change any MySQL server configuration. After any change to the my.cnf, restart mysqld.&lt;br /&gt;
&lt;br /&gt;
If you are able, the [http://mysqltuner.com/ MySQLTuner] tool can be run against your MySQL server and will calculate appropriate configuration values for most of the following settings based on your current load, status and variables automatically.&lt;br /&gt;
&lt;br /&gt;
* Enable the &#039;&#039;&#039;query cache&#039;&#039;&#039; with &lt;br /&gt;
 query_cache_type = 1. &lt;br /&gt;
For most Moodle installs, set the following:&lt;br /&gt;
 query_cache_size = 36M &lt;br /&gt;
 query_cache_min_res_unit = 2K. &lt;br /&gt;
The query cache will improve performance if you are doing few updates on the database. &lt;br /&gt;
* Set the &#039;&#039;&#039;table cache&#039;&#039;&#039; correctly. For Moodle 1.6 set &lt;br /&gt;
 table_cache = 256 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min), and for Moodle 1.7 set &lt;br /&gt;
 table_cache = 512 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min). The table cache is used by all threads (connections), so monitor the value of opened_tables to further adjust - if opened_tables &amp;gt; 3 * table_cache(table_open_cache in MySQL &amp;gt; 5.1.2) then increase table_cache upto your OS limit. Note also that the figure for table_cache will also change depending on the number of modules and plugins you have installed. Find the number for your server by executing the mysql statement below. Look at the number returned and set table_cache to this value.&lt;br /&gt;
 mysql&amp;gt;SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema=&#039;yourmoodledbname&#039;;&lt;br /&gt;
* Set the &#039;&#039;&#039;thread cache&#039;&#039;&#039; correctly. Adjust the value so that your thread cache utilization is as close to 100% as possible by this formula:&lt;br /&gt;
 thread cache utilization (%) = (threads_created / connections) * 100&lt;br /&gt;
* The &#039;&#039;&#039;key buffer&#039;&#039;&#039; can improve the access speed to Moodle&#039;s SELECT queries. The correct size depends on the size of the index files (.myi) and in Moodle 1.6 or later (without any additional modules and plugins), the recommendation for this value is key_buffer_size = 32M. Ideally you want the database to be reading once from the disk for every 100 requests so monitor that the value is suitable for your install by adjusting the value of key_buffer_size so that the following formulas are true:&lt;br /&gt;
 key_read / key_read_requests &amp;lt; 0.01&lt;br /&gt;
 key_write / key_write_requests &amp;lt;= 1.0&lt;br /&gt;
* Set the &#039;&#039;&#039;maximum number of connections&#039;&#039;&#039; so that your users will not see a &amp;quot;Too many connections&amp;quot; message. Be careful that this may have an impact on the total memory used. MySQL connections usually last for milliseconds, so it is unusual even for a heavily loaded server for this value to be over 200.&lt;br /&gt;
* Manage &#039;&#039;&#039;high burst activity&#039;&#039;&#039;. If your Moodle install uses a lot of quizzes and you are experiencing performance problems (check by monitoring the value of threads_connected - it should not be rising) consider increasing the value of back_log.&lt;br /&gt;
* &#039;&#039;&#039;Optimize your tables weekly and after upgrading Moodle&#039;&#039;&#039;. It is good practice to also optimize your tables after performing a large data deletion exercise, e.g. at the end of your semester or academic year. This will ensure that index files are up to date. Backup your database first and then use:&lt;br /&gt;
 mysql&amp;gt;CHECK TABLE mdl_tablename;&lt;br /&gt;
 mysql&amp;gt;OPTIMIZE TABLE mdl_tablename;&lt;br /&gt;
:The common tables in Moodle to check are mdl_course_sections, mdl_forum_posts, mdl_log and mdl_sessions (if using dbsessions). Any errors need to be corrected using REPAIR TABLE (see the [http://dev.mysql.com/doc/refman/5.0/en/repair-table.html MySQL manual] and this [http://moodle.org/mod/forum/discuss.php?d=58208#p279638 forum script]).&lt;br /&gt;
* &#039;&#039;&#039;Maintain the key distribution&#039;&#039;&#039;. Every month or so it is a good idea to stop the mysql server and run these myisamchk commands.&lt;br /&gt;
 #myisamchk -a -S /pathtomysql/data/moodledir/*.MYI&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: You must stop the mysql database process (mysqld) before running any myisamchk command. If you do not, you risk data loss.&lt;br /&gt;
* Reduce the number of &#039;&#039;&#039;temporary tables saved to disk&#039;&#039;&#039;. Check this with the created_tmp_disk_tables value. If this is relatively large (&amp;gt;5%) increase tmp_table_size until you see a reduction. Note that this will have an impact on RAM usage.&lt;br /&gt;
&lt;br /&gt;
===PostgreSQL performance===&lt;br /&gt;
&lt;br /&gt;
There are some good papers around on tuning PostgreSQL (like [http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server this one]), and Moodle&#039;s case does not seem to be different to the general case.&lt;br /&gt;
&lt;br /&gt;
The first thing to recognise is that if you really need to worry about tuning you should be using a separate machine for the database server. If you are not using a separate machine then the answers to many performance questions are substantially muddied by the memory requirements of the rest of the application.&lt;br /&gt;
&lt;br /&gt;
You should probably &#039;&#039;&#039;enable autovacuum&#039;&#039;&#039;, unless you know what you are doing. Many e-learning sites have predictable periods of low use, so disabling autovacuum and running a specific vacuum at those times can be a good option. Or perhaps leave autovacuum running but do a full vacuum weekly in a quiet period.&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;&#039;shared_buffers&#039;&#039;&#039; to something reasonable. For versions up to 8.1 my testing has shown that peak performance is almost always obtained with buffers &amp;lt; 10000, so if you are using such a version, and have more than 512M of RAM just set shared_buffers to 10,000 (8MB).&lt;br /&gt;
&lt;br /&gt;
The buffer management had a big overhaul in 8.2 and &amp;quot;reasonable&amp;quot; is now a much larger number. I have not conducted performance tests with 8.2, but the recommendations from others are generally that you should now scale shared_buffers much more with memory and may continue to reap benefits even up to values like 100,000 (80MB). Consider using 1-2% of system RAM.&lt;br /&gt;
&lt;br /&gt;
PostgreSQL will also assume that the operating system is caching its files, so setting &#039;&#039;&#039;effective_cache_size&#039;&#039;&#039; to a reasonable value is also a good idea. A reasonable value will usually be (total RAM - RAM in use by programs). If you are running Linux and leave the system running for a day or two you can look at &#039;free&#039; and under the &#039;cached&#039; column you will see what it currently is. Consider taking that number (which is kB) and dividing it by 10 (i.e. allow 20% for other programs cache needs and then divide by 8 to get pages). If you are not using a dedicated database server you will need to decrease that value to account for usage by other programs.&lt;br /&gt;
&lt;br /&gt;
Some other useful parameters that can have positive effects, and the values I would typically set them to on a machine with 4G RAM, are:&lt;br /&gt;
&lt;br /&gt;
 work_mem = 10240&lt;br /&gt;
&lt;br /&gt;
That&#039;s 10M of RAM to use instead of on-disk sorting and so forth. That can give a big speed increase, but it is per connection and 200 connections * 10M is 2G, so it can theoretically chew up a lot of RAM.&lt;br /&gt;
&lt;br /&gt;
 maintenance_work_mem = 163840&lt;br /&gt;
&lt;br /&gt;
That&#039;s 160M of RAM which will be used by (e.g.) VACUUM, index rebuild, cluster and so forth. This should only be used periodically and should be freed when those processes exit, so I believe it is well worth while.&lt;br /&gt;
&lt;br /&gt;
 wal_buffers = 64&lt;br /&gt;
&lt;br /&gt;
These buffers are used for the write-ahead log, and there have been a number of reports on the PostgreSQL mailing lists of improvement from this level of increase.&lt;br /&gt;
&lt;br /&gt;
This is a little out of date now (version 8.0) but still worth a read: http://www.powerpostgresql.com/Docs&lt;br /&gt;
&lt;br /&gt;
And there is lots of good stuff here as well: http://www.varlena.com/GeneralBits/Tidbits/index.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Based on Andrew McMillan&#039;s post at [http://moodle.org/mod/forum/discuss.php?d=68558 Tuning PostgreSQL] forum thread.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Splitting &#039;&#039;&#039;mdl_log&#039;&#039;&#039; to several tables and using a VIEW with UNION to read them as one. (See Tim Hunt [https://moodle.org/mod/forum/discuss.php?d=243531#p1104165 explanation] on the Moodle forums)&lt;br /&gt;
&lt;br /&gt;
===Other database performance links===&lt;br /&gt;
* Consider using a &#039;&#039;&#039;distributed cacheing system&#039;&#039;&#039; like [http://en.wikipedia.org/wiki/Memcached memcached] but note that memcached does not have any security features so it should be used behind a firewall.&lt;br /&gt;
* Consider using PostgreSQL. See [[Arguments in favour of PostgreSQL]] and [http://moodle.org/mod/forum/discuss.php?d=49195 how to migrate from MySQL to PostgreSQL] (forum discussion).&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.0/en/server-parameters.html General advice on tuning MySQL parameters] (advice from the MySQL manual)&lt;br /&gt;
* [http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/ InnoDB performance optimization] taken from the [http://www.mysqlperformanceblog.com/ MySQL performance blog] site.&lt;br /&gt;
&lt;br /&gt;
==Performance of different Moodle modules==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s activity modules, filters, and other plugins can be activated/deactivated. If necessary, you may wish to deactivate some features (such as chat) if not required - but this isn&#039;t necessary. Some notes on the performance of certain modules:&lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;Chat&#039;&#039;&#039; module is [http://moodle.org/mod/forum/discuss.php?d=37979&amp;amp;parent=175079 said] to be a hog in terms of frequent HTTP requests to the main server. This can be reduced by setting the module to use &#039;&#039;Streamed&#039;&#039; updates, or, if you&#039;re using a Unix-based webserver, by running the chat in daemon mode. When using the Chat module use the configuration settings to tune for your expected load. Pay particular attention to the &#039;&#039;chat_old_ping&#039;&#039; and &#039;&#039;chat_refresh&#039;&#039; parameters as these can have greatest impact on server load.&lt;br /&gt;
* The Moodle &#039;&#039;&#039;Cron&#039;&#039;&#039; task is triggered by calling the script &#039;&#039;cron.php&#039;&#039;. If this is called over HTTP (e.g. using wget or curl) it can take a large amount of memory on large installations. If it is called by directly invoking the php command (e.g. &#039;&#039;php -f /path/to/moodle/directory/admin/cli/cron.php&#039;&#039;) efficiency can be much improved.&lt;br /&gt;
* The &#039;&#039;&#039;Recent activities&#039;&#039;&#039; block is consuming too many resources if you have huge number of records &amp;lt;code&amp;gt;mdl_log&amp;lt;/code&amp;gt;. This is being tested to optimize the SQL query.&lt;br /&gt;
* The &#039;&#039;&#039;Quiz&#039;&#039;&#039; module is known to stretch database performance. However, it has been getting better in recent versions, and we don&#039;t know of any good, up-to-date performance measurements. (Here is a [http://moodle.org/mod/forum/discuss.php?d=68579 case study from 2007 with 300 quiz users].). The following suggestions were described by [https://moodle.org/user/view.php?id=94615&amp;amp;course=5 Al Rachels] in [https://moodle.org/mod/forum/discuss.php?d=347126 this forum thread]:&lt;br /&gt;
** make sure both Moodle, and the operating system, are installed on a [https://en.wikipedia.org/wiki/Solid-state_drive solid state drive]&lt;br /&gt;
** upgrade to and use [https://docs.moodle.org/dev/Moodle_and_PHP7 PHP 7]&lt;br /&gt;
** run MySQLTuner and implement its recommendations&lt;br /&gt;
&lt;br /&gt;
See [[Performance settings]] for more information on performance-related Moodle settings.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle: [http://moodle.org/mod/forum/view.php?f=94 Hardware and Performance] forum&lt;br /&gt;
*[http://opensourceelearning.blogspot.be/2012/10/why-your-moodle-site-is-slow-five.html Why Your Moodle Site is Slow: Five Simple Settings] blog post from Jonathan Moore &lt;br /&gt;
*I teach with Moodle perfomance testing: http://www.iteachwithmoodle.com/2012/11/17/moodle-2-4-beta-performance-test-comparison-with-moodle-2-3/&lt;br /&gt;
*[http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs 2.5.2 performance and MUC APC cahe store]&lt;br /&gt;
*[http://jfilip.ca/2013/09/25/moodle-performance-testing-2-4-6-vs-2-5-2-vs-2-6dev/ Moodle performance testing 2.4.6 vs 2.5.2 vs 2.6dev]&lt;br /&gt;
*[http://jfilip.ca/2013/09/24/moodle-performance-analysis-revisted-now-with-mariadb/ Moodle performance analysis revisited (now with MariaDB)]&lt;br /&gt;
*[http://tjhunt.blogspot.ca/2013/05/performance-testing-moodle.html Tim Hunt&#039;s blog (May 2, 2013) on performance testing Moodle]&lt;br /&gt;
*[http://newrelic.com/ New Relic, Application Performance Monitoring]&lt;br /&gt;
*[http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html Performance enhacements for Apache and PHP (Apache Event MPM and PHP-FPM)]&lt;br /&gt;
*[https://scholarlms.net/performance-recommendations/ Performance recommendations]&lt;br /&gt;
&lt;br /&gt;
There have been a lot of discussions on moodle.org about performance, here are some of the more interesting and (potentially) useful ones:&lt;br /&gt;
&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=83057 Performance woes!]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=57028 Performance perspectives - a little script]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=88927 Comments on planned server hardware]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=102978#p461624 Moodle performance in a pil by Martin Langhoff]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=240391#unread Advice on optimising php/db code in moodle2+]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=243531 Moodle 2.5 performance testing at the OU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=273602 100 active users limit with 4vCPU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=336603#p1356423 Performance Tip ... shared...]&lt;br /&gt;
&lt;br /&gt;
[[es:Recomendaciones sobre desempeño]]&lt;br /&gt;
[[fr:Performance]]&lt;br /&gt;
[[ja:パフォーマンス]]&lt;br /&gt;
[[de:Geschwindigkeitsempfehlungen]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Performance_recommendations&amp;diff=135015</id>
		<title>Performance recommendations</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Performance_recommendations&amp;diff=135015"/>
		<updated>2019-08-10T07:22:35Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Install HowTo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
Moodle can be made to perform very well, at small usage levels or scaling up to many thousands of users. The factors involved in performance are basically the same as for any PHP-based database-driven system. When trying to optimize your server, try to focus on the factor which will make the most difference to the user. For example, if you have relatively more users browsing than accessing the database, look to improve the webserver performance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Obtain a baseline benchmark==&lt;br /&gt;
&lt;br /&gt;
Before attempting any optimization, you should obtain a baseline benchmark of the component of the system you are trying to improve. For Linux try [http://lbs.sourceforge.net/ LBS] and for Windows use the Performance Monitor. Once you have quantitative data about how your system is performing currently, you&#039;ll be able to determine if the change you have made has had any real impact.&lt;br /&gt;
&lt;br /&gt;
The overall aim of adjustments to improve performance is to use RAM (cacheing) and to reduce disk-based activity. It is especially important to try to eliminate swap file usage as much as you can. If your system starts swapping, this is a sign that you need more RAM. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;optimization order preference&#039;&#039;&#039; is usually: primary storage (more RAM), secondary storage (faster hard disks/improved hard disk configuration), processor (more and faster).&lt;br /&gt;
&lt;br /&gt;
It can be interesting to install and use the [https://moodle.org/plugins/report_benchmark Benchmark plugin] in order to find the bottlenecks of your system that specifically affect Moodle.&lt;br /&gt;
&lt;br /&gt;
==Scalability==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s design (with clear separation of application layers) allows for strongly scalable setups. (Please check the list of [[Large installations|large Moodle installations]].)&lt;br /&gt;
&lt;br /&gt;
Large sites usually separate the web server and database onto separate servers, although for smaller installations this is typically not necessary.&lt;br /&gt;
&lt;br /&gt;
It is possible to load-balance a Moodle installation, for example by using more than one webserver. The separate webservers should query the same database and refer to the same filestore and cache areas (see [[Caching]]), but otherwise the separation of the application layers is complete enough to make this kind of clustering feasible. Similarly, the database could be a cluster of servers (e.g. a MySQL cluster), but this is not an easy task and you should seek expert support, e.g. from a Moodle Partner.&lt;br /&gt;
&lt;br /&gt;
===Server cluster===&lt;br /&gt;
&lt;br /&gt;
Using Moodle forum discussions:&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=57202 Moodle clustering]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=44470 Software load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=49986 TCP load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=88214 Installation for 3000 simultaneous users]&lt;br /&gt;
&lt;br /&gt;
==Hardware configuration==&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: The fastest and most effective change that you can make to improve performance is to &#039;&#039;&#039;increase the amount of RAM on your web server&#039;&#039;&#039; - get as much as possible (e.g. 4GB or more). Increasing primary memory will reduce the need for processes to swap to disk and will enable your server to handle more users.&lt;br /&gt;
* Better performance is gained by obtaining the best &#039;&#039;&#039;processor capability&#039;&#039;&#039; you can, i.e. dual or dual core processors. A modern BIOS should allow you to enable hyperthreading, but check if this makes a difference to the overall performance of the processors by using a [http://en.wikipedia.org/wiki/Super_PI CPU benchmarking tool].&lt;br /&gt;
* If you can afford them, use &#039;&#039;&#039;SCSI hard disks&#039;&#039;&#039; instead of SATA drives. SATA drives will increase your system&#039;s CPU utilization, whereas SCSI drives have their own integrated processors and come into their own when you have multiple drives. If you must have SATA drives, check that your motherboard and the drives themselves support NCQ (Native Command Queuing).&lt;br /&gt;
* Purchase hard disks with a &#039;&#039;&#039;low seek time&#039;&#039;&#039;. This will improve the overall speed of your system, especially when accessing Moodle&#039;s reports.&lt;br /&gt;
* Size your &#039;&#039;&#039;swap file&#039;&#039;&#039; correctly. The general advice is to set it to 4 x physical RAM.&lt;br /&gt;
* Use a &#039;&#039;&#039;RAID disk system&#039;&#039;&#039;. Although there are many different RAID configurations you can create, the following generally works best:&lt;br /&gt;
** install a hardware RAID controller (if you can)&lt;br /&gt;
** the operating system and swap drive on one set of disks configured as RAID-1.&lt;br /&gt;
** Moodle, Web server and Database server on another set of disks configured as RAID-5.&lt;br /&gt;
* If your &#039;moodledata&#039; area is going to be on relatively slow storage (e.g. NFS mount on to a NAS device) you will probably have performance issues with the default cache configuration (which writes to this storage). See the page on [[Caching]] and consider an alternative. Using [https://en.wikipedia.org/wiki/GlusterFS GlusterFS] / [https://en.wikipedia.org/wiki/OCFS2 OCFS2] / [https://en.wikipedia.org/wiki/GFS2 GFS2] on a [https://en.wikipedia.org/wiki/Storage_Area_Network SAN] device and [https://en.wikipedia.org/wiki/Fibre_Channel Fiber Channel] could improve performance (See more info on the Moodle [https://moodle.org/mod/forum/discuss.php?d=214680#p1123124 forum thread], [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 NFS performance tuing] )&lt;br /&gt;
* Use &#039;&#039;&#039;gigabit ethernet&#039;&#039;&#039; for improved latency and throughput. This is especially important when you have your webserver and database server separated out on different hosts.&lt;br /&gt;
* Check the settings on your &#039;&#039;&#039;network card&#039;&#039;&#039;. You may get an improvement in performance by increasing the use of buffers and transmit/receive descriptors (balance this with processor and memory overheads) and off-loading TCP checksum calculation onto the card instead of the OS.&lt;br /&gt;
*  Read this [http://moodle.org/mod/forum/discuss.php?d=68579 Case Study] on a server stress test with 300 users.  &lt;br /&gt;
* See this [http://elearning.sgu.ac.jp/doc/PT/ accompanying report] on network traffic and server loads.&lt;br /&gt;
* Also see this SFSU presentation at Educause (using VMWare): [http://www.educause.edu/Resources/AnOpenSourceLMSforaMissionCrit/162843]&lt;br /&gt;
&lt;br /&gt;
==Operating System==&lt;br /&gt;
* You can use [http://en.wikipedia.org/wiki/Linux Linux](recommended), Unix-based, Windows or Mac OS X for the server &#039;&#039;&#039;operating system&#039;&#039;&#039;. *nix operating systems generally require less memory than Mac OS X or Windows servers for doing the same task as the server is configured with just a shell interface. Additionally Linux does not have licensing fees attached, but can have a big learning curve if you&#039;re used to another operating system. If you have a large number of processors running SMP, you may also want to consider using a highly tuned OS such as [http://en.wikipedia.org/wiki/Solaris_Operating_Environment Solaris].&lt;br /&gt;
* Check your own OS and &#039;&#039;&#039;vendor specific instructions&#039;&#039;&#039; for optimization steps.&lt;br /&gt;
** For Linux look at the [http://linuxperf.sourceforge.net/ Linux Performance Team] site. &lt;br /&gt;
** For Linux investigate the hdparm command, e.g. hdparm -m16 -d1 can be used to enable read/write on multiple sectors and DMA. Mount disks with the [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 &amp;quot;async&amp;quot; and &amp;quot;noatime&amp;quot;] options.&lt;br /&gt;
** For Windows set the sever to be optimized for network applications (Control Panel, Network Connections, LAN connection, Properties, File &amp;amp; Printer Sharing for Microsoft Networks, Properties, Optimization). You can also search the [http://technet.microsoft.com/ Microsoft TechNet site] for optimization documents.&lt;br /&gt;
&lt;br /&gt;
==Web server performance==&lt;br /&gt;
&lt;br /&gt;
Installing [http://www.mozilla.com/en-US/ Firefox] and the [https://addons.mozilla.org/en-US/firefox/addon/1843 firebug] extension will allow you to watch the time it takes for each page component to load. Also, the [https://addons.mozilla.org/en-US/firefox/addon/5369 Yslow] extension will evaluate your page against Yahoo&#039;s [http://www.skrenta.com/2007/05/14_rules_for_fast_web_pages_by_1.html 14 rules], full text [http://developer.yahoo.com/performance/rules.html Best Practices for Speeding Up Your Web Site], &amp;lt;strike&amp;gt;([http://video.yahoo.com/video/play?vid=1040890 video])&amp;lt;/strike&amp;gt; for fast loading websites.&lt;br /&gt;
&lt;br /&gt;
===PHP performance===&lt;br /&gt;
* You are strongly recommended to use a &#039;&#039;&#039;PHP accelerator&#039;&#039;&#039; to ease CPU load, such as [http://pecl.php.net/apc APC], [http://www.php-accelerator.co.uk/ PHPA], [http://trac.lighttpd.net/xcache/ Xcache], [http://sourceforge.net/projects/wincache WinCache] or [http://eaccelerator.net/ eAccelerator]. (Take care to choose a PHP accelerator that is known to work well with your version of PHP and note that Turck MMCache is [http://turckmmcache.exeprod.com/TheManifestoEnglish no longer maintained] and can cause failures with PHP 5). PHP 5.5 (and newer) includes OpCache and is fully supported and recommended by Moodle&lt;br /&gt;
* Improvements in read/write performance can be improved by putting the cached PHP pages on a [[TMPFS]] filesystem - but remember that you&#039;ll lose the cache contents when there is a power failure or the server is rebooted.&lt;br /&gt;
* Performance of PHP is better when installed as an &#039;&#039;&#039;Apache/IIS6 ISAPI module&#039;&#039;&#039; (rather than a CGI). IIS 7.0/7.5 (Windows Server 2008/R2) users should choose a FastCGI installation for best performance.&lt;br /&gt;
* Also check the &#039;&#039;&#039;memory_limit&#039;&#039;&#039; in php.ini, reduce it to 16M for Moodle version earlier than 1.7 ([http://moodle.org/mod/forum/discuss.php?d=39656 See this forum discussion]). For Moodle 1.7 or later, it is recommended that the value of memory_limit should be 40M. As of [http://www.php.net/ChangeLog-5.php PHP 5.2.1] the default value for the memory_limit directive is 128M.&lt;br /&gt;
* Also see [[PHP_settings_by_Moodle_version]]&lt;br /&gt;
* Use [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html PHP-FPM] (with apache).&lt;br /&gt;
&lt;br /&gt;
===Install HowTo===&lt;br /&gt;
* [http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html APC on CentOS 5.x (linux)]&lt;br /&gt;
* [http://fplanque.com/dev/linux/install-apc-php-cache-debian-lenny APC on Debian (linux)]&lt;br /&gt;
* [http://www.linuxtuts.net/211-installing-memcached-php5-memcache-module-debian-apache2.html MemCache module on Debian (Apache2 and PHP5) ]&lt;br /&gt;
* [https://www.tecmint.com/install-memcached-on-centos-7/ Installing Memcache on CentOS 7.x (linux)]&lt;br /&gt;
* [http://noveckg.blogspot.com/2010/02/installing-eaccelerator-cache-for-php.html Installing eAccelerator on CentOS 5.x (linux)]&lt;br /&gt;
* [https://docs.moodle.org/en/Installing_eAccelerator_In_Ubuntu_Server/ Installing eAccelerator on Ubuntu Server (linux)]&lt;br /&gt;
&lt;br /&gt;
===Apache performance===&lt;br /&gt;
* If you are using Apache on a Windows server, use the build from [http://www.apachelounge.com Apache Lounge] which is reported to have [http://moodle.org/mod/forum/discuss.php?d=93358 performance and stability improvements] compared to the official Apache download. Note that this is an unofficial build, so may not keep up with official releases.&lt;br /&gt;
* Set the &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; directive correctly (&#039;&#039;&#039;MaxClients&#039;&#039;&#039; before Apache 2.4). Use this formula to help (which uses 80% of available memory to leave room for spare):&lt;br /&gt;
 MaxRequestWorkers = Total available memory * 80% / Max memory usage of apache process&lt;br /&gt;
:Memory usage of apache process is usually 10MB but Moodle can easily use up to 100MB per process, so a general rule of thumb is to divide your available memory in megabytes by 100 to get a conservative setting for MaxClients. You are quite likely to find yourself lowering the MaxRequestWorkers from its default of 150 on a Moodle server. To get a more accurate estimate read the value from the shell command:&lt;br /&gt;
 #ps -ylC httpd --sort:rss&lt;br /&gt;
&lt;br /&gt;
:If you need to increase the value of &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; beyond 256, you will also need to set the &#039;&#039;&#039;ServerLimit&#039;&#039;&#039; directive. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: Do not be tempted to set the value of MaxRequestWorkers higher than your available memory as your server will consume more RAM than available and start to swap to disk. &lt;br /&gt;
* Consider reducing the &#039;&#039;&#039;number of modules&#039;&#039;&#039; that Apache loads in the httpd.conf file to the minumum necessary to reduce the memory needed. &lt;br /&gt;
* Use the &#039;&#039;&#039;latest version of Apache&#039;&#039;&#039; - Apache 2 has an improved memory model which reduces memory usage further.&lt;br /&gt;
* For Unix/Linux systems, consider lowering &#039;&#039;&#039;MaxConnectionsPerChild&#039;&#039;&#039; (&#039;&#039;&#039;MaxRequestsPerChild&#039;&#039;&#039; before Apache 2.4) in httpd.conf to as low as 20-30 (if you set it any lower the overhead of forking begins to outweigh the benefits). &lt;br /&gt;
* For a heavily loaded server, consider setting &#039;&#039;&#039;KeepAlive Off&#039;&#039;&#039; (do this only if your Moodle pages do not contain links to resources or uploaded images) or lowering the &#039;&#039;&#039;KeepAliveTimeout&#039;&#039;&#039; to between 2 and 5. The default is 15 (seconds) - the higher the value the more server processes will be kept waiting for possibly idle connections. A more accurate value for KeepAliveTimeout is obtained by observing how long it takes your users to download a page. After altering any of the KeepAlive variables, monitor your CPU utilization as there may be an additional overhead in initiating more worker processes/threads.&lt;br /&gt;
* As an alternative to using KeepAlive Off, consider setting-up a &#039;&#039;&#039;Reverse Proxy server&#039;&#039;&#039; infront of the Moodle server to cache HTML files with images. You can then return Apache to using keep-alives on the Moodle server.&lt;br /&gt;
* If you do not use a .htaccess file, set the &#039;&#039;&#039;AllowOverride&#039;&#039;&#039; variable to AllowOverride None to prevent .htaccess lookups.&lt;br /&gt;
* Set &#039;&#039;&#039;DirectoryIndex&#039;&#039;&#039; correctly so as to avoid content-negotiation. Here&#039;s an example from a production server:&lt;br /&gt;
 DirectoryIndex index.php index.html index.htm&lt;br /&gt;
* Unless you are doing development work on the server, set &#039;&#039;&#039;ExtendedStatus Off&#039;&#039;&#039; and disable mod_info as well as mod_status.&lt;br /&gt;
* Leave &#039;&#039;&#039;HostnameLookups Off&#039;&#039;&#039; (as default) to reduce DNS latency.&lt;br /&gt;
* Consider reducing the value of &#039;&#039;&#039;TimeOut&#039;&#039;&#039; to between 30 to 60 (seconds). &lt;br /&gt;
* For the &#039;&#039;&#039;Options directive&#039;&#039;&#039;, avoid Options Multiviews as this performs a directory scan. To reduce disk I/O further use&lt;br /&gt;
 Options -Indexes FollowSymLinks&lt;br /&gt;
&lt;br /&gt;
* Compression reduces response times by reducing the size of the HTTP response&lt;br /&gt;
# Install and enable mod_deflate - refer to documentation or man pages&lt;br /&gt;
# Add this code to the virtual server config file within the &amp;lt;directory&amp;gt; section for the root directory (or within the .htaccess file if AllowOverrides is On):&lt;br /&gt;
 &amp;lt;ifModule mod_deflate.c&amp;gt;&lt;br /&gt;
   AddOutputFilterByType DEFLATE text/html text/plain text/xml text/x-js text/javascript text/css application/javascript&lt;br /&gt;
 &amp;lt;/ifmodule&amp;gt;&lt;br /&gt;
* Use Apache [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html event] [http://httpd.apache.org/docs/current/mpm.html MPM] (and not the default Prefork or Worker)&lt;br /&gt;
&lt;br /&gt;
===IIS performance===&lt;br /&gt;
All alter this location in the registry:&lt;br /&gt;
 HKLM\SYSTEM\CurrentControlSet\Services\Inetinfo\Parameters\&lt;br /&gt;
* The equivalent to KeepAliveTimeout is &#039;&#039;&#039;ListenBackLog&#039;&#039;&#039; (IIS - registry location is HKLM\ SYSTEM\ CurrentControlSet\ Services\ Inetinfo\ Parameters). Set this to between 2 to 5.&lt;br /&gt;
*Change the &#039;&#039;&#039;MemCacheSize&#039;&#039;&#039; value to adjust the amount of memory (Mb) that IIS will use for its file cache (50% of available memory by default).&lt;br /&gt;
*Change the &#039;&#039;&#039;MaxCachedFileSize&#039;&#039;&#039; to adjust the maximum size of a file cached in the file cache in bytes. Default is 262,144 (256K).&lt;br /&gt;
*Create a new DWORD called &#039;&#039;&#039;ObjectCacheTTL&#039;&#039;&#039; to change the length of time (in milliseconds) that objects in the cache are held in memory. Default is 30,000 milliseconds (30 seconds).&lt;br /&gt;
&lt;br /&gt;
===Lighttpd, NginX and Cherokee performance===&lt;br /&gt;
You can increase server performance by using a &#039;&#039;&#039;light-weight&#039;&#039;&#039; webserver like [http://www.lighttpd.net/ lighttpd],  [http://nginx.net/ nginx] or [http://www.cherokee-project.com/ cherokee] in combination with PHP in FastCGI-mode. Lighttpd was originally created as a proof-of-concept[http://www.lighttpd.net/story] to address the [http://www.kegel.com/c10k.html C10k problem] and while primarily recommended for memory-limited servers, its design origins and asynchronous-IO model make it a suitable and proven[http://blog.lighttpd.net/articles/2006/12/28/lighttpd-powers-5-alexa-top-250-sites] alternative HTTP server for high-load websites and web apps, including Moodle. See the [[lighttpd | MoodleDocs Lighttpd page]] for additional information, configuration example and links.&lt;br /&gt;
&lt;br /&gt;
Alternatively, both [http://www.lighttpd.net/ lighttpd] and [http://nginx.net/ nginx] are capable of performing as a load-balancer and/or reverse-proxy to alleviate load on back-end servers[http://www.linuxjournal.com/article/10108], providing benefit without requiring an actual software change on existing servers.&lt;br /&gt;
&lt;br /&gt;
Do note that these are likely to be the least tested server environments of all particularly if you are using advanced features such as web services and/or Moodle Networking. They are probably best considered for heavily used Moodle sites with relatively simple configurations.&lt;br /&gt;
&lt;br /&gt;
===X-Sendfile===&lt;br /&gt;
&lt;br /&gt;
X-Sendfile modules improve performance when sending large files from Moodle. It is recommended to configure your web server and Moodle to use this feature of available.&lt;br /&gt;
&lt;br /&gt;
Configure web server:&lt;br /&gt;
* Apache - https://tn123.org/mod_xsendfile/&lt;br /&gt;
* Lighttpd - http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file&lt;br /&gt;
* Nginx - http://wiki.nginx.org/XSendfile&lt;br /&gt;
&lt;br /&gt;
Enable support in config.php (see config-dist.php):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Sendfile&#039;;           // Apache {@see https://tn123.org/mod_xsendfile/}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-LIGHTTPD-send-file&#039;; // Lighttpd {@see http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Accel-Redirect&#039;;     // Nginx {@see http://wiki.nginx.org/XSendfile}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure file location prefixes if your server implementation requires it:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfilealiases = array(&lt;br /&gt;
//         &#039;/dataroot/&#039; =&amp;gt; $CFG-&amp;gt;dataroot,&lt;br /&gt;
//         &#039;/cachedir/&#039; =&amp;gt; &#039;/var/www/moodle/cache&#039;,    // for custom $CFG-&amp;gt;cachedir locations&lt;br /&gt;
//         &#039;/localcachedir/&#039; =&amp;gt; &#039;/var/local/cache&#039;,    // for custom $CFG-&amp;gt;localcachedir locations&lt;br /&gt;
//         &#039;/tempdir/&#039;  =&amp;gt; &#039;/var/www/moodle/temp&#039;,     // for custom $CFG-&amp;gt;tempdir locations&lt;br /&gt;
//         &#039;/filedir&#039;   =&amp;gt; &#039;/var/www/moodle/filedir&#039;,  // for custom $CFG-&amp;gt;filedir locations&lt;br /&gt;
//     );&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Database performance==&lt;br /&gt;
&lt;br /&gt;
===MySQL performance===&lt;br /&gt;
&lt;br /&gt;
The following are MySQL specific settings which can be adjusted for better performance in your my.cnf (my.ini in Windows). The file contains a list of settings and their values. To see the current values use these commands&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
 SHOW VARIABLES; &lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: You must make backups of your database before attempting to change any MySQL server configuration. After any change to the my.cnf, restart mysqld.&lt;br /&gt;
&lt;br /&gt;
If you are able, the [http://mysqltuner.com/ MySQLTuner] tool can be run against your MySQL server and will calculate appropriate configuration values for most of the following settings based on your current load, status and variables automatically.&lt;br /&gt;
&lt;br /&gt;
* Enable the &#039;&#039;&#039;query cache&#039;&#039;&#039; with &lt;br /&gt;
 query_cache_type = 1. &lt;br /&gt;
For most Moodle installs, set the following:&lt;br /&gt;
 query_cache_size = 36M &lt;br /&gt;
 query_cache_min_res_unit = 2K. &lt;br /&gt;
The query cache will improve performance if you are doing few updates on the database. &lt;br /&gt;
* Set the &#039;&#039;&#039;table cache&#039;&#039;&#039; correctly. For Moodle 1.6 set &lt;br /&gt;
 table_cache = 256 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min), and for Moodle 1.7 set &lt;br /&gt;
 table_cache = 512 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min). The table cache is used by all threads (connections), so monitor the value of opened_tables to further adjust - if opened_tables &amp;gt; 3 * table_cache(table_open_cache in MySQL &amp;gt; 5.1.2) then increase table_cache upto your OS limit. Note also that the figure for table_cache will also change depending on the number of modules and plugins you have installed. Find the number for your server by executing the mysql statement below. Look at the number returned and set table_cache to this value.&lt;br /&gt;
 mysql&amp;gt;SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema=&#039;yourmoodledbname&#039;;&lt;br /&gt;
* Set the &#039;&#039;&#039;thread cache&#039;&#039;&#039; correctly. Adjust the value so that your thread cache utilization is as close to 100% as possible by this formula:&lt;br /&gt;
 thread cache utilization (%) = (threads_created / connections) * 100&lt;br /&gt;
* The &#039;&#039;&#039;key buffer&#039;&#039;&#039; can improve the access speed to Moodle&#039;s SELECT queries. The correct size depends on the size of the index files (.myi) and in Moodle 1.6 or later (without any additional modules and plugins), the recommendation for this value is key_buffer_size = 32M. Ideally you want the database to be reading once from the disk for every 100 requests so monitor that the value is suitable for your install by adjusting the value of key_buffer_size so that the following formulas are true:&lt;br /&gt;
 key_read / key_read_requests &amp;lt; 0.01&lt;br /&gt;
 key_write / key_write_requests &amp;lt;= 1.0&lt;br /&gt;
* Set the &#039;&#039;&#039;maximum number of connections&#039;&#039;&#039; so that your users will not see a &amp;quot;Too many connections&amp;quot; message. Be careful that this may have an impact on the total memory used. MySQL connections usually last for milliseconds, so it is unusual even for a heavily loaded server for this value to be over 200.&lt;br /&gt;
* Manage &#039;&#039;&#039;high burst activity&#039;&#039;&#039;. If your Moodle install uses a lot of quizzes and you are experiencing performance problems (check by monitoring the value of threads_connected - it should not be rising) consider increasing the value of back_log.&lt;br /&gt;
* &#039;&#039;&#039;Optimize your tables weekly and after upgrading Moodle&#039;&#039;&#039;. It is good practice to also optimize your tables after performing a large data deletion exercise, e.g. at the end of your semester or academic year. This will ensure that index files are up to date. Backup your database first and then use:&lt;br /&gt;
 mysql&amp;gt;CHECK TABLE mdl_tablename;&lt;br /&gt;
 mysql&amp;gt;OPTIMIZE TABLE mdl_tablename;&lt;br /&gt;
:The common tables in Moodle to check are mdl_course_sections, mdl_forum_posts, mdl_log and mdl_sessions (if using dbsessions). Any errors need to be corrected using REPAIR TABLE (see the [http://dev.mysql.com/doc/refman/5.0/en/repair-table.html MySQL manual] and this [http://moodle.org/mod/forum/discuss.php?d=58208#p279638 forum script]).&lt;br /&gt;
* &#039;&#039;&#039;Maintain the key distribution&#039;&#039;&#039;. Every month or so it is a good idea to stop the mysql server and run these myisamchk commands.&lt;br /&gt;
 #myisamchk -a -S /pathtomysql/data/moodledir/*.MYI&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: You must stop the mysql database process (mysqld) before running any myisamchk command. If you do not, you risk data loss.&lt;br /&gt;
* Reduce the number of &#039;&#039;&#039;temporary tables saved to disk&#039;&#039;&#039;. Check this with the created_tmp_disk_tables value. If this is relatively large (&amp;gt;5%) increase tmp_table_size until you see a reduction. Note that this will have an impact on RAM usage.&lt;br /&gt;
&lt;br /&gt;
===PostgreSQL performance===&lt;br /&gt;
&lt;br /&gt;
There are some good papers around on tuning PostgreSQL (like [http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server this one]), and Moodle&#039;s case does not seem to be different to the general case.&lt;br /&gt;
&lt;br /&gt;
The first thing to recognise is that if you really need to worry about tuning you should be using a separate machine for the database server. If you are not using a separate machine then the answers to many performance questions are substantially muddied by the memory requirements of the rest of the application.&lt;br /&gt;
&lt;br /&gt;
You should probably &#039;&#039;&#039;enable autovacuum&#039;&#039;&#039;, unless you know what you are doing. Many e-learning sites have predictable periods of low use, so disabling autovacuum and running a specific vacuum at those times can be a good option. Or perhaps leave autovacuum running but do a full vacuum weekly in a quiet period.&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;&#039;shared_buffers&#039;&#039;&#039; to something reasonable. For versions up to 8.1 my testing has shown that peak performance is almost always obtained with buffers &amp;lt; 10000, so if you are using such a version, and have more than 512M of RAM just set shared_buffers to 10,000 (8MB).&lt;br /&gt;
&lt;br /&gt;
The buffer management had a big overhaul in 8.2 and &amp;quot;reasonable&amp;quot; is now a much larger number. I have not conducted performance tests with 8.2, but the recommendations from others are generally that you should now scale shared_buffers much more with memory and may continue to reap benefits even up to values like 100,000 (80MB). Consider using 1-2% of system RAM.&lt;br /&gt;
&lt;br /&gt;
PostgreSQL will also assume that the operating system is caching its files, so setting &#039;&#039;&#039;effective_cache_size&#039;&#039;&#039; to a reasonable value is also a good idea. A reasonable value will usually be (total RAM - RAM in use by programs). If you are running Linux and leave the system running for a day or two you can look at &#039;free&#039; and under the &#039;cached&#039; column you will see what it currently is. Consider taking that number (which is kB) and dividing it by 10 (i.e. allow 20% for other programs cache needs and then divide by 8 to get pages). If you are not using a dedicated database server you will need to decrease that value to account for usage by other programs.&lt;br /&gt;
&lt;br /&gt;
Some other useful parameters that can have positive effects, and the values I would typically set them to on a machine with 4G RAM, are:&lt;br /&gt;
&lt;br /&gt;
 work_mem = 10240&lt;br /&gt;
&lt;br /&gt;
That&#039;s 10M of RAM to use instead of on-disk sorting and so forth. That can give a big speed increase, but it is per connection and 200 connections * 10M is 2G, so it can theoretically chew up a lot of RAM.&lt;br /&gt;
&lt;br /&gt;
 maintenance_work_mem = 163840&lt;br /&gt;
&lt;br /&gt;
That&#039;s 160M of RAM which will be used by (e.g.) VACUUM, index rebuild, cluster and so forth. This should only be used periodically and should be freed when those processes exit, so I believe it is well worth while.&lt;br /&gt;
&lt;br /&gt;
 wal_buffers = 64&lt;br /&gt;
&lt;br /&gt;
These buffers are used for the write-ahead log, and there have been a number of reports on the PostgreSQL mailing lists of improvement from this level of increase.&lt;br /&gt;
&lt;br /&gt;
This is a little out of date now (version 8.0) but still worth a read: http://www.powerpostgresql.com/Docs&lt;br /&gt;
&lt;br /&gt;
And there is lots of good stuff here as well: http://www.varlena.com/GeneralBits/Tidbits/index.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Based on Andrew McMillan&#039;s post at [http://moodle.org/mod/forum/discuss.php?d=68558 Tuning PostgreSQL] forum thread.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Splitting &#039;&#039;&#039;mdl_log&#039;&#039;&#039; to several tables and using a VIEW with UNION to read them as one. (See Tim Hunt [https://moodle.org/mod/forum/discuss.php?d=243531#p1104165 explanation] on the Moodle forums)&lt;br /&gt;
&lt;br /&gt;
===Other database performance links===&lt;br /&gt;
* Consider using a &#039;&#039;&#039;distributed cacheing system&#039;&#039;&#039; like [http://en.wikipedia.org/wiki/Memcached memcached] but note that memcached does not have any security features so it should be used behind a firewall.&lt;br /&gt;
* Consider using PostgreSQL. See [[Arguments in favour of PostgreSQL]] and [http://moodle.org/mod/forum/discuss.php?d=49195 how to migrate from MySQL to PostgreSQL] (forum discussion).&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.0/en/server-parameters.html General advice on tuning MySQL parameters] (advice from the MySQL manual)&lt;br /&gt;
* [http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/ InnoDB performance optimization] taken from the [http://www.mysqlperformanceblog.com/ MySQL performance blog] site.&lt;br /&gt;
&lt;br /&gt;
==Performance of different Moodle modules==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s activity modules, filters, and other plugins can be activated/deactivated. If necessary, you may wish to deactivate some features (such as chat) if not required - but this isn&#039;t necessary. Some notes on the performance of certain modules:&lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;Chat&#039;&#039;&#039; module is [http://moodle.org/mod/forum/discuss.php?d=37979&amp;amp;parent=175079 said] to be a hog in terms of frequent HTTP requests to the main server. This can be reduced by setting the module to use &#039;&#039;Streamed&#039;&#039; updates, or, if you&#039;re using a Unix-based webserver, by running the chat in daemon mode. When using the Chat module use the configuration settings to tune for your expected load. Pay particular attention to the &#039;&#039;chat_old_ping&#039;&#039; and &#039;&#039;chat_refresh&#039;&#039; parameters as these can have greatest impact on server load.&lt;br /&gt;
* The Moodle &#039;&#039;&#039;Cron&#039;&#039;&#039; task is triggered by calling the script &#039;&#039;cron.php&#039;&#039;. If this is called over HTTP (e.g. using wget or curl) it can take a large amount of memory on large installations. If it is called by directly invoking the php command (e.g. &#039;&#039;php -f /path/to/moodle/directory/admin/cli/cron.php&#039;&#039;) efficiency can be much improved.&lt;br /&gt;
* The &#039;&#039;&#039;Recent activities&#039;&#039;&#039; block is consuming too many resources if you have huge number of records &amp;lt;code&amp;gt;mdl_log&amp;lt;/code&amp;gt;. This is being tested to optimize the SQL query.&lt;br /&gt;
* The &#039;&#039;&#039;Quiz&#039;&#039;&#039; module is known to stretch database performance. However, it has been getting better in recent versions, and we don&#039;t know of any good, up-to-date performance measurements. (Here is a [http://moodle.org/mod/forum/discuss.php?d=68579 case study from 2007 with 300 quiz users].). The following suggestions were described by [https://moodle.org/user/view.php?id=94615&amp;amp;course=5 Al Rachels] in [https://moodle.org/mod/forum/discuss.php?d=347126 this forum thread]:&lt;br /&gt;
** make sure both Moodle, and the operating system, are installed on a [https://en.wikipedia.org/wiki/Solid-state_drive solid state drive]&lt;br /&gt;
** upgrade to and use [https://docs.moodle.org/dev/Moodle_and_PHP7 PHP 7]&lt;br /&gt;
** run MySQLTuner and implement its recommendations&lt;br /&gt;
&lt;br /&gt;
See [[Performance settings]] for more information on performance-related Moodle settings.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle: [http://moodle.org/mod/forum/view.php?f=94 Hardware and Performance] forum&lt;br /&gt;
*[http://opensourceelearning.blogspot.be/2012/10/why-your-moodle-site-is-slow-five.html Why Your Moodle Site is Slow: Five Simple Settings] blog post from Jonathan Moore &lt;br /&gt;
*I teach with Moodle perfomance testing: http://www.iteachwithmoodle.com/2012/11/17/moodle-2-4-beta-performance-test-comparison-with-moodle-2-3/&lt;br /&gt;
*[http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs 2.5.2 performance and MUC APC cahe store]&lt;br /&gt;
*[http://jfilip.ca/2013/09/25/moodle-performance-testing-2-4-6-vs-2-5-2-vs-2-6dev/ Moodle performance testing 2.4.6 vs 2.5.2 vs 2.6dev]&lt;br /&gt;
*[http://jfilip.ca/2013/09/24/moodle-performance-analysis-revisted-now-with-mariadb/ Moodle performance analysis revisited (now with MariaDB)]&lt;br /&gt;
*[http://tjhunt.blogspot.ca/2013/05/performance-testing-moodle.html Tim Hunt&#039;s blog (May 2, 2013) on performance testing Moodle]&lt;br /&gt;
*[http://newrelic.com/ New Relic, Application Performance Monitoring]&lt;br /&gt;
*[http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html Performance enhacements for Apache and PHP (Apache Event MPM and PHP-FPM)]&lt;br /&gt;
*[https://scholarlms.net/performance-recommendations/ Performance recommendations]&lt;br /&gt;
&lt;br /&gt;
There have been a lot of discussions on moodle.org about performance, here are some of the more interesting and (potentially) useful ones:&lt;br /&gt;
&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=83057 Performance woes!]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=57028 Performance perspectives - a little script]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=88927 Comments on planned server hardware]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=102978#p461624 Moodle performance in a pil by Martin Langhoff]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=240391#unread Advice on optimising php/db code in moodle2+]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=243531 Moodle 2.5 performance testing at the OU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=273602 100 active users limit with 4vCPU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=336603#p1356423 Performance Tip ... shared...]&lt;br /&gt;
&lt;br /&gt;
[[es:Recomendaciones sobre desempeño]]&lt;br /&gt;
[[fr:Performance]]&lt;br /&gt;
[[ja:パフォーマンス]]&lt;br /&gt;
[[de:Geschwindigkeitsempfehlungen]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=134996</id>
		<title>ad-hoc contributed reports</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=134996"/>
		<updated>2019-08-06T09:01:42Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* List Questions in each Quiz */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Sitewide reports}}&lt;br /&gt;
==User and Role Report==&lt;br /&gt;
&lt;br /&gt;
===Count number of distinct learners and teachers enrolled per category (including all its sub categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;SELECT COUNT(DISTINCT lra.userid) AS learners, COUNT(DISTINCT tra.userid) as teachers&lt;br /&gt;
FROM prefix_course AS c #, mdl_course_categories AS cats&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments  AS lra ON lra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role_assignments  AS tra ON tra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category = cats.id&lt;br /&gt;
AND (&lt;br /&gt;
	cats.path LIKE &#039;%/CATEGORYID/%&#039; #Replace CATEGORYID with the category id you want to count (eg: 80)&lt;br /&gt;
	OR cats.path LIKE &#039;%/CATEGORYID&#039;&lt;br /&gt;
	)&lt;br /&gt;
AND lra.roleid=5&lt;br /&gt;
AND tra.roleid=3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each ROLE (TEACHER, NON-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT r.name, l.action, COUNT( l.userid ) AS counter&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_role AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE ra.roleid IN ( 3, 4, 5 ) &lt;br /&gt;
GROUP BY roleid, l.action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student (user) COUNT in each Course===&lt;br /&gt;
Including (optional) filter by: year (if included in course fullname).&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/index.php?contextid=&#039;,context.id,&#039;&amp;quot;&amp;gt;Show users&amp;lt;/a&amp;gt;&#039;) AS Users&lt;br /&gt;
, COUNT(course.id) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS asg&lt;br /&gt;
JOIN prefix_context AS context ON asg.contextid = context.id AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_user AS user ON user.id = asg.userid&lt;br /&gt;
JOIN prefix_course AS course ON context.instanceid = course.id&lt;br /&gt;
WHERE asg.roleid = 5 &lt;br /&gt;
# AND course.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
GROUP BY course.id&lt;br /&gt;
ORDER BY COUNT(course.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enrolment count in each Course ===&lt;br /&gt;
&lt;br /&gt;
Shows the total number of enroled users of all roles in each course. Sorted by course name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname, COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LIST of all site USERS by COURSE enrollment (Moodle 2.x)===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) as Role&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) as RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course as course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enrolled users,which did not login into the Course, even once (Moodle 2)===&lt;br /&gt;
Designed forMoodle 2 table structure and uses special plugin filter : %%FILTER_SEARCHTEXT:table.field%%&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id as ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
user2.idnumber AS IDNumber,&lt;br /&gt;
user2.phone1 AS Phone,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
&lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id and courseid=c.id) as CourseLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id and e.courseid = c.id) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments as ue&lt;br /&gt;
JOIN prefix_enrol as e on e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user as user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess as ul on ul.userid = user2.id&lt;br /&gt;
WHERE c.id=16 AND ul.timeaccess IS NULL&lt;br /&gt;
%%FILTER_SEARCHTEXT:user2.firstname%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Role assignments on categories===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS category,&lt;br /&gt;
cc.depth, cc.path, r.name AS role,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php?id=&#039;,usr.id,&#039;&amp;quot;&amp;gt;&#039;,usr.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS name,&lt;br /&gt;
usr.firstname, usr.username, usr.email&lt;br /&gt;
FROM prefix_course_categories cc&lt;br /&gt;
INNER JOIN prefix_context cx ON cc.id = cx.instanceid&lt;br /&gt;
AND cx.contextlevel = &#039;40&#039;&lt;br /&gt;
INNER JOIN prefix_role_assignments ra ON cx.id = ra.contextid&lt;br /&gt;
INNER JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
INNER JOIN prefix_user usr ON ra.userid = usr.id&lt;br /&gt;
ORDER BY cc.depth, cc.path, usr.lastname, usr.firstname, r.name, cc.name&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Permissions Overides on Categories===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712834 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT rc.id, ct.instanceid, ccat.name, rc.roleid, rc.capability, rc.permission, &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( rc.timemodified ) , &#039;%Y-%m-%d&#039; ) AS timemodified, rc.modifierid, ct.instanceid, ct.path, ct.depth&lt;br /&gt;
FROM `prefix_role_capabilities` AS rc&lt;br /&gt;
INNER JOIN `prefix_context` AS ct ON rc.contextid = ct.id&lt;br /&gt;
INNER JOIN `prefix_course_categories` AS ccat ON ccat.id = ct.instanceid&lt;br /&gt;
AND `contextlevel` =40&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;Totally Opened Courses&amp;quot; (visible, opened to guests, with no password)===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712837 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Course&#039;,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/enrol/instances.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Méthodes inscription&amp;lt;/a&amp;gt;&#039;) AS &#039;Enrollment plugins&#039;,&lt;br /&gt;
e.sortorder&lt;br /&gt;
FROM prefix_enrol AS e, prefix_course AS c&lt;br /&gt;
WHERE e.enrol=&#039;guest&#039; AND e.status=0 AND e.password=&#039;&#039; AND c.id=e.courseid AND c.visible=1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;loggedin users&amp;quot; from the last 120 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id,username,FROM_UNIXTIME(`lastlogin`) as days &lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;and user count for that same population:&#039;&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(id) as Users  FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Users loggedin within the last 7 days ====&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    l.* FROM mdl_logstore_standard_log l&lt;br /&gt;
WHERE&lt;br /&gt;
   l.eventname = &#039;\\core\\event\\user_loggedin&#039;&lt;br /&gt;
   AND FROM_UNIXTIME(l.timecreated, &#039;%Y-%m-%d&#039;) &amp;gt;= DATE_SUB(NOW(), INTERVAL 7 DAY)&lt;br /&gt;
&lt;br /&gt;
SELECT l.eventname FROM mdl_logstore_standard_log l&lt;br /&gt;
GROUP BY l.eventname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists the users who have only logged into the site once===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, username, firstname, lastname, idnumber&lt;br /&gt;
FROM prefix_user&lt;br /&gt;
WHERE prefix_user.deleted = 0&lt;br /&gt;
AND prefix_user.lastlogin = 0 &lt;br /&gt;
AND prefix_user.lastaccess &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Students in all courses of some institute===&lt;br /&gt;
What is the status (deleted or not) of all Students (roleid = 5) in all courses of some Institute&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname, u.firstname, u.lastname, u.deleted&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND u.institution = &#039;please enter school name here&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Full User info (for deleted users)===&lt;br /&gt;
Including extra custom profile fields (from prefix_user_info_data)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT * &lt;br /&gt;
FROM prefix_user as u &lt;br /&gt;
JOIN prefix_user_info_data as uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_user_info_field as uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;class&#039;)&lt;br /&gt;
WHERE `deleted` = &amp;quot;1&amp;quot; and `institution`=&amp;quot;your school name&amp;quot; and `department` = &amp;quot;your department&amp;quot; and `data` = &amp;quot;class level and number&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User&#039;s courses===&lt;br /&gt;
change &amp;quot;u.id = 2&amp;quot; with a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, c.id, c.fullname&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE u.id = 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Users with extra info (email) in current course===&lt;br /&gt;
blocks/configurable_reports replaces %%COURSEID%% with course id.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, u.email&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Students with enrollment and completion dates in current course===&lt;br /&gt;
This is meant to be a &amp;quot;global&amp;quot; report in Configurable Reports containing the following:&lt;br /&gt;
firstname, lastname, idnumber, institution, department, email, student enrolment date, student completion date&lt;br /&gt;
Note: for PGSQL, use to_timestamp() instead of FROM_UNIXTIME()&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.firstname&lt;br /&gt;
, u.lastname&lt;br /&gt;
, u.idnumber&lt;br /&gt;
, u.institution&lt;br /&gt;
, u.department&lt;br /&gt;
, u.email&lt;br /&gt;
, FROM_UNIXTIME(cc.timeenrolled)&lt;br /&gt;
, FROM_UNIXTIME(cc.timecompleted)&lt;br /&gt;
&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_completions AS cc ON cc.course = c.id AND cc.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Special Roles===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.roleid,r.name&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,ra.userid,&#039;&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Username&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON (ctx.id = ra.contextid AND ctx.contextlevel = 50)&lt;br /&gt;
JOIN prefix_course AS c ON ctx.instanceid = c.id&lt;br /&gt;
WHERE ra.roleid &amp;gt; 6&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses without Teachers===&lt;br /&gt;
Actually, shows the number of Teachers in a course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Teachers&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
ORDER BY Teachers ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of users who have been enrolled for more than 4 weeks===&lt;br /&gt;
For Moodle 2.2 , by  Isuru Madushanka Weerarathna &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT uenr.userid As User, IF(enr.courseid=uenr.courseid ,&#039;Y&#039;,&#039;N&#039;) As Enrolled, &lt;br /&gt;
IF(DATEDIFF(NOW(), FROM_UNIXTIME(uenr.timecreated))&amp;gt;=28,&#039;Y&#039;,&#039;N&#039;) As EnrolledMoreThan4Weeks&lt;br /&gt;
FROM prefix_enrol As enr, prefix_user_enrolments AS uenr&lt;br /&gt;
WHERE enr.id = uenr.enrolid AND enr.status = uenr.status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with language===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 (in the U.S., Canada and the Americas) is changing the default English to United States English. &lt;br /&gt;
&lt;br /&gt;
This will show you the language setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, lang from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools.&lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;en&#039; to &#039;en_us&#039; for all users:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To do this for only users who have a particular country set, use this as an example:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE country = &#039;US&#039; AND lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with Authentication ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Sometimes you need to do mass changes of authentication methods. A common case is changing default manual to LDAP. &lt;br /&gt;
&lt;br /&gt;
This will show you the Authentication setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, auth from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools. &lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;manual&#039; to &#039;ldap&#039; 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.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET auth = &#039;ldap&#039; WHERE auth = &#039;manual&#039; AND id &amp;gt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compare role capability and permissions ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT mrc.capability &lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;1&#039; AND rc.contextid = &#039;1&#039;) AS Manager&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;2&#039; AND rc.contextid = &#039;1&#039;) AS CourseCreator&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;3&#039; AND rc.contextid = &#039;1&#039;) AS Teacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;4&#039; AND rc.contextid = &#039;1&#039;) AS AssistantTeacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;5&#039; AND rc.contextid = &#039;1&#039;) AS Student&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;6&#039; AND rc.contextid = &#039;1&#039;) AS Guest&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_role_capabilities` AS mrc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User&#039;s accumulative time spent in course ===&lt;br /&gt;
A sum up of the time delta between logstore_standard_log user&#039;s records, considering the a 2 hour session limit.&lt;br /&gt;
&lt;br /&gt;
Uses: current user&#039;s id %%USERID%% and current course&#039;s id %%COURSEID%%  &lt;br /&gt;
&lt;br /&gt;
And also using a date filter (which can be ignored)  &lt;br /&gt;
&lt;br /&gt;
The extra &amp;quot;User&amp;quot; field is used as a dummy field for the Line chart Series field, in which I use X=id, Series=Type, Y=delta.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
l.id, &lt;br /&gt;
l.timecreated, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(l.timecreated),&#039;%d-%m-%Y&#039;) AS dTime,&lt;br /&gt;
@prevtime := (SELECT max(timecreated) FROM mdl_logstore_standard_log &lt;br /&gt;
		WHERE userid = %%USERID%% and id &amp;lt; l.id ORDER BY id ASC LIMIT 1) AS prev_time,&lt;br /&gt;
IF (l.timecreated - @prevtime &amp;lt; 7200, @delta := @delta + (l.timecreated-@prevtime),0) AS sumtime,&lt;br /&gt;
l.timecreated-@prevtime AS delta,&lt;br /&gt;
&amp;quot;User&amp;quot; as type&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log as l, &lt;br /&gt;
(SELECT @delta := 0) AS s_init &lt;br /&gt;
# Change UserID&lt;br /&gt;
WHERE l.userid = %%USERID%% AND l.courseid = %%COURSEID%%&lt;br /&gt;
%%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Low-Participation Student Report ===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
This report returns a list of students who are enrolled in courses filtered by a short-name text marker (in this case &amp;quot;OL-&amp;quot;) in the specified category, but have very low participation in the course during the specified time period (fewer than 2 &amp;quot;Edits&amp;quot; to Activity Modules, indicating few active contributions to the course). The number of &amp;quot;Edits&amp;quot; is provided for each student for the time period specified.&lt;br /&gt;
&lt;br /&gt;
An &amp;quot;Edit&amp;quot; is defined as course activity other than viewing content. Click the &amp;quot;Logs&amp;quot; link to review the student activity. The Logs offer the option to review &amp;quot;View&amp;quot; activity as well as &amp;quot;Edit&amp;quot; activity.&lt;br /&gt;
&lt;br /&gt;
Only &amp;quot;visible&amp;quot; courses are included in this report. The report may be downloaded as an Excel spreadsheet.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t forget to set up Filters: &amp;quot;Start / End date filter&amp;quot; and &amp;quot;Filter categories&amp;quot; on the Filters tab in Configurable reports.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname AS Last, u.firstname AS First, u.idnumber AS IDnumber, u.email AS email, c.shortname AS CourseID,  count(l.id) AS Edits, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;https://learn.granite.edu/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=-view&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id AND l.action NOT LIKE &amp;quot;view%&amp;quot; %%FILTER_STARTTIME:l.TIME:&amp;gt;%% %%FILTER_ENDTIME:l.TIME:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.visible=1&lt;br /&gt;
# This prefix filter allows the exclusion of non-online courses at the original institution. Alter this to fit your institution, or remove it.&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
%%FILTER_CATEGORIES:c.category%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
HAVING Edits &amp;lt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Messages of All Users in a Specific Course ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
NOTE: This query will probably not work at all in 3.5 now due to the changes in the structure of the Messages database. - RT&lt;br /&gt;
&lt;br /&gt;
This query shows the personal messages between users in a specific course, given the course id number. Properly speaking, personal messages pertain only to users and are not part of courses, but by filtering enrollments for roles in a course, you can show this. &lt;br /&gt;
&lt;br /&gt;
This report as is shows only the messages between Teachers and Students, as the WHERE statement contains and AND ((...))) section that restrict this report to ONLY messages between Teachers (role id = 3) and Students (role id =5). Remove that part of the statement if you wish to see _all_ messages between all users, e.g. teachers to teachers, student to student. &lt;br /&gt;
&lt;br /&gt;
Also, if you have created custom roles, you can replace the default id numbers with custom ones to further enhance the report.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.username AS &#039;From&#039;,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS &#039;From Name&#039;,&lt;br /&gt;
u2.username AS &#039;To&#039;,&lt;br /&gt;
CONCAT(u2.firstname ,&#039; &#039;,u2.lastname) AS &#039;To Name&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(me.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;,&lt;br /&gt;
me.subject AS &#039;Subject&#039;, &lt;br /&gt;
me.smallmessage AS &#039;Message&#039;&lt;br /&gt;
FROM prefix_message me&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = me.useridfrom AND ra.roleid IN (3,4,5)  &lt;br /&gt;
JOIN prefix_role_assignments AS ra2 ON ra2.userid = me.useridto AND ra2.roleid IN (3,4,5)  &lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id AND ra2.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_user u ON u.id = me.useridfrom&lt;br /&gt;
JOIN prefix_user u2 ON u2.id = me.useridto&lt;br /&gt;
WHERE c.id=## &lt;br /&gt;
AND ((ra.roleid = 3 AND ra2.roleid = 5) OR (ra.roleid = 5 AND ra2.roleid = 3)) &lt;br /&gt;
ORDER BY me.useridfrom, me.useridto, me.timecreated&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Log Activity Reports==&lt;br /&gt;
===Count all Active Users by ROLE in a course category (including all of its sub-categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT l.userid) as active&lt;br /&gt;
FROM mdl_course as c&lt;br /&gt;
JOIN mdl_context AS ctx ON  ctx.instanceid=c.id&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN mdl_user_lastaccess as l ON ra.userid = l.userid&lt;br /&gt;
JOIN mdl_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category=cats.id AND (&lt;br /&gt;
	cats.path LIKE &#039;%/80/%&#039;&lt;br /&gt;
	OR cats.path LIKE &#039;%/80&#039;&lt;br /&gt;
) &lt;br /&gt;
AND ra.roleid=3  AND ctx.contextlevel=50  #ra.roleid= TEACHER 3, NON-EDITING TEACHER 4, STUDENT 5&lt;br /&gt;
AND  l.timeaccess &amp;gt; (unix_timestamp() - ((60*60*24)*NO_OF_DAYS)) #NO_OF_DAYS change to number&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Detailed &amp;quot;VIEW&amp;quot; ACTION for each ROLE (TEACHER,NONE-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT l.action, count( l.userid ) as counter , r.name&lt;br /&gt;
FROM `prefix_log` as l&lt;br /&gt;
JOIN `prefix_role_assignments` AS ra on l.userid = ra.userid&lt;br /&gt;
JOIN `prefix_role` AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE (ra.roleid IN (3,4,5)) AND (l.action LIKE &#039;%view%&#039; )&lt;br /&gt;
GROUP BY roleid,l.action&lt;br /&gt;
order by r.name,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total Activity of Roles:&amp;quot;Teacher&amp;quot; and &amp;quot;None-Editing Teacher&amp;quot; by Dates and by Hours===&lt;br /&gt;
The output columns of this report table can be used as base for a Pivot-Table&lt;br /&gt;
which will show the amount of &#039;&#039;&#039;activity&#039;&#039;&#039; per &#039;&#039;&#039;hour&#039;&#039;&#039; per &#039;&#039;&#039;days&#039;&#039;&#039; in 3D graph view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%Y-%m-%d&#039; ) AS grptimed ,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%k&#039; ) AS grptimeh  , count( l.userid ) AS counter &lt;br /&gt;
FROM `prefix_log` AS l&lt;br /&gt;
JOIN prefix_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
WHERE ra.roleid IN (3,4)&lt;br /&gt;
GROUP BY grptimed,grptimeh&lt;br /&gt;
ORDER BY grptimed,grptimeh&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many LOGINs per user and user&#039;s Activity===&lt;br /&gt;
+ link username to a user activity graph report&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,u.id,&#039;&amp;amp;mode=alllogs&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) as Username&lt;br /&gt;
,count(*) as logins&lt;br /&gt;
,(SELECT count(*) FROM prefix_log WHERE userid = l.userid GROUP BY userid) as Activity &lt;br /&gt;
FROM prefix_log as l JOIN prefix_user as u ON l.userid = u.id &lt;br /&gt;
WHERE `action` LIKE &#039;%login%&#039; group by userid&lt;br /&gt;
ORDER BY Activity DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Distinct user logins per month===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
The following will show you the months of the current calendar year with the total number of distinct, unique user logins per month. Change the year in the WHERE clause to the year you need.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
 COUNT(DISTINCT l.userid) AS &#039;DistinctUserLogins&#039;, &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%M&#039;) AS &#039;Month&#039;&lt;br /&gt;
FROM prefix_logstore_standard_log l&lt;br /&gt;
WHERE l.action = &#039;loggedin&#039; AND YEAR(FROM_UNIXTIME(l.timecreated)) = &#039;2017&#039; &lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(l.timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total activity per course, per unique user on the last 24h===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    COUNT(DISTINCT userid) AS countUsers&lt;br /&gt;
  , COUNT(l.courseid) AS countVisits&lt;br /&gt;
  , CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
  JOIN mdl_course AS c ON c.id = l.courseid&lt;br /&gt;
WHERE l.courseid &amp;gt; 0&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 1 DAY)&lt;br /&gt;
      AND c.fullname LIKE &#039;%תשעו%&#039;&lt;br /&gt;
GROUP BY l.courseid&lt;br /&gt;
ORDER BY countVisits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Instructor Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of instructors in all courses per week of a term, including pre-term and post-term edits. An edit is defined as a change to the course, such as a discussion post, the grading of an assignment, or the uploading of file attachments, as well as alterations to course content.&lt;br /&gt;
&lt;br /&gt;
* To specify a subject and/or course number, use % as a wildcard, e.g. ARTS% or ARTS501%&lt;br /&gt;
* To match part of a last name, use %, e.g. Smi% will match &amp;quot;Smith&amp;quot;, &amp;quot;Smile&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
At our institution, we include filters on the course name or category to constrain by terms. These are very specific to how course names and categories are constructed at our institution, so I&#039;ve removed those elements from this code. Also, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; lines for longer terms, or remove lines for shorter terms.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version uses legacy (pre-2.7) logs. See below for post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, c.startdate AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time)) - WEEK(FROM_UNIXTIME(c.startdate))&amp;lt;0,1,0)) AS BeforeTerm&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=0,1,0)) AS Week1&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=1,1,0)) AS Week2&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=2,1,0)) AS Week3&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=3,1,0)) AS Week4&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=4,1,0)) AS Week5&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=5,1,0)) AS Week6&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=6,1,0)) AS Week7&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=7,1,0)) AS Week8&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=8,1,0)) AS Week9&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=9,1,0)) AS Week10&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=10,1,0)) AS Week11&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=11,1,0)) AS Week12&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))&amp;gt;=12,1,0)) AS AfterTerm&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE :course&lt;br /&gt;
AND u.lastname LIKE :last_name&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 log version:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(DISTINCT l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
AND cc.idnumber LIKE &#039;%current%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
#HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY RIGHT(c.shortname,2), c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Student Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of students in the current course by week, including pre-term and post-term edits. An 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 (if permitted).&lt;br /&gt;
&lt;br /&gt;
Links to three other reports are also provided:&lt;br /&gt;
&lt;br /&gt;
* Logs: complete log entries for the student in the course, organized by date&lt;br /&gt;
* Activity Outline: the &amp;quot;Outline Report&amp;quot; from the User Activity Reports, summarizing the student&#039;s activity in the course, organized by course content&lt;br /&gt;
* Consolidated Activity Report: the &amp;quot;Complete Report&amp;quot; from the User Activity Reports, detailing the student&#039;s activity in the course, organized by course content (includes text of forum posts)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). At our institution, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for a post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF((l.time-c.startdate)/7&amp;lt;0,1,0)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=0,1,0)) AS &#039;Week 1&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=1,1,0)) AS &#039;Week 2&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=2,1,0)) AS &#039;Week 3&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=3,1,0)) AS &#039;Week 4&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=4,1,0)) AS &#039;Week 5&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=5,1,0)) AS &#039;Week 6&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=6,1,0)) AS &#039;Week 7&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=7,1,0)) AS &#039;Week 8&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=8,1,0)) AS &#039;Week 9&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=9,1,0)) AS &#039;Week 10&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=10,1,0)) AS &#039;Week 11&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=11,1,0)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))&amp;gt;=15,1,0)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 (Standard Logs) version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
# Our institution stores academic advisor names and emails in custom profile fields&lt;br /&gt;
#, CONCAT(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,uce.data,&#039;&amp;quot;&amp;gt;&#039;,uid.data, &#039;&amp;lt;/a&amp;gt;&#039;)  AS &#039;Academic Advisor&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,&#039;Posts&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Posts&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# student academic coach - you can include custom profile field data with these methods&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uid ON u.id = uid.userid AND uid.fieldid = &#039;2&#039;&lt;br /&gt;
# student academic coach email&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uce on u.id = uce.userid AND uce.fieldid = &#039;6&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===My Weekly Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of the &#039;&#039;&#039;current user&#039;&#039;&#039; in the &#039;&#039;&#039;current course&#039;&#039;&#039; 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).&lt;br /&gt;
&lt;br /&gt;
This report uses Standard Logs (post 2.7).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
l.component AS &#039;activity&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS &#039;Total&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE 1&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
AND u.id = %%USERID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY l.component&lt;br /&gt;
&lt;br /&gt;
ORDER BY l.component&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Faculty/Student Interactions===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Returns a count of instructor and other-student responses to student activity for the specified time period. This report can help indicate whether students&#039; comments are being responded to, as well as summarizing post activity by students during the specified time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for the post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This report can take a long time to run. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
LEFT JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
# We care about messages that involve both the instructor and students of this course&lt;br /&gt;
# messages from instructor to students:&lt;br /&gt;
# LEFT JOIN prefix_message AS mts ON mts.useridfrom = instr.id AND mts.useridto = allstu.id&lt;br /&gt;
# LEFT JOIN prefix_message AS mfs ON mfs.useridfrom = instr.id AND mfs.useridto = allstu.id&lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 Standard Logs version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
 JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student Resource Usage===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Standard Logs&amp;quot; from Moodle 2.7+.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
, m.name AS &#039;item type&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&lt;br /&gt;
COALESCE(a.name, &#039;&#039;), &lt;br /&gt;
COALESCE(b.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cert.name,&#039;&#039;), &lt;br /&gt;
COALESCE(chat.name,&#039;&#039;), &lt;br /&gt;
COALESCE(choice.name,&#039;&#039;), &lt;br /&gt;
COALESCE(data.name,&#039;&#039;), &lt;br /&gt;
COALESCE(feedback.name,&#039;&#039;), &lt;br /&gt;
COALESCE(folder.name,&#039;&#039;), &lt;br /&gt;
COALESCE(forum.name,&#039;&#039;), &lt;br /&gt;
COALESCE(glossary.name,&#039;&#039;), &lt;br /&gt;
COALESCE(imscp.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lesson.name,&#039;&#039;), &lt;br /&gt;
COALESCE(p.name,&#039;&#039;),&lt;br /&gt;
COALESCE(questionnaire.name,&#039;&#039;), &lt;br /&gt;
COALESCE(quiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cr.name,&#039;&#039;), &lt;br /&gt;
COALESCE(scorm.name,&#039;&#039;), &lt;br /&gt;
COALESCE(survey.name,&#039;&#039;), &lt;br /&gt;
COALESCE(url.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(workshop.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kalvidassign.name,&#039;&#039;), &lt;br /&gt;
COALESCE(attendance.name,&#039;&#039;), &lt;br /&gt;
COALESCE(checklist.name,&#039;&#039;), &lt;br /&gt;
COALESCE(flashcard.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lti.name,&#039;&#039;), &lt;br /&gt;
COALESCE(oublog.name,&#039;&#039;), &lt;br /&gt;
COALESCE(ouwiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(subpage.name,&#039;&#039;), &lt;br /&gt;
COALESCE(journal.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lightboxgallery.name,&#039;&#039;), &lt;br /&gt;
COALESCE(elluminate.name,&#039;&#039;), &lt;br /&gt;
COALESCE(adaptivequiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(hotpot.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiziq.name,&#039;&#039;), &lt;br /&gt;
COALESCE(turnitintooltwo.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kvr.name,&#039;&#039;)&lt;br /&gt;
) AS &#039;item name&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;r&#039;),1,0)) AS &#039;total views&#039;&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),1,0)) AS &#039;total submissions&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;r&#039;),u.id,NULL)) AS &#039;count of students who viewed&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),u.id,NULL)) AS &#039;count of students who submitted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 #AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module AND m.name NOT LIKE &#039;label&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON a.id = cm.instance AND m.name = &#039;assign&#039;&lt;br /&gt;
LEFT JOIN prefix_book AS b ON b.id = cm.instance AND m.name = &#039;book&#039;&lt;br /&gt;
LEFT JOIN prefix_certificate AS cert ON cert.id = cm.instance AND m.name = &#039;certificate&#039;&lt;br /&gt;
LEFT JOIN prefix_chat AS chat ON chat.id = cm.instance AND m.name = &#039;chat&#039;&lt;br /&gt;
LEFT JOIN prefix_choice AS choice ON choice.id = cm.instance AND m.name = &#039;choice&#039;&lt;br /&gt;
LEFT JOIN prefix_data AS data ON data.id = cm.instance AND m.name = &#039;data&#039;&lt;br /&gt;
LEFT JOIN prefix_feedback AS feedback ON feedback.id = cm.instance AND m.name = &#039;feedback&#039;&lt;br /&gt;
LEFT JOIN prefix_folder AS folder ON folder.id = cm.instance AND m.name = &#039;folder&#039;&lt;br /&gt;
LEFT JOIN prefix_forum AS forum ON forum.id = cm.instance AND m.name = &#039;forum&#039;&lt;br /&gt;
LEFT JOIN prefix_glossary AS glossary ON glossary.id = cm.instance AND m.name = &#039;glossary&#039;&lt;br /&gt;
LEFT JOIN prefix_imscp AS imscp ON imscp.id = cm.instance AND m.name = &#039;imscp&#039;&lt;br /&gt;
LEFT JOIN prefix_lesson AS lesson ON lesson.id = cm.instance AND m.name = &#039;lesson&#039;&lt;br /&gt;
LEFT JOIN prefix_page AS p ON p.id = cm.instance AND m.name = &#039;page&#039;&lt;br /&gt;
LEFT JOIN prefix_questionnaire AS questionnaire ON questionnaire.id = cm.instance AND m.name = &#039;questionnaire&#039;&lt;br /&gt;
LEFT JOIN prefix_quiz AS quiz ON quiz.id = cm.instance AND m.name = &#039;quiz&#039;&lt;br /&gt;
LEFT JOIN prefix_resource AS cr ON cr.id = cm.instance AND m.name = &#039;resource&#039;&lt;br /&gt;
LEFT JOIN prefix_scorm AS scorm ON scorm.id = cm.instance AND m.name = &#039;scorm&#039;&lt;br /&gt;
LEFT JOIN prefix_survey AS survey ON survey.id = cm.instance AND m.name = &#039;survey&#039;&lt;br /&gt;
LEFT JOIN prefix_url AS url ON url.id = cm.instance AND m.name = &#039;url&#039;&lt;br /&gt;
LEFT JOIN prefix_wiki AS wiki ON wiki.id = cm.instance AND m.name = &#039;wiki&#039;&lt;br /&gt;
LEFT JOIN prefix_workshop AS workshop ON workshop.id = cm.instance AND m.name = &#039;workshop&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidassign AS kalvidassign ON kalvidassign.id = cm.instance AND m.name = &#039;kalvidassign&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidres AS kvr ON kvr.id = cm.instance AND m.name = &#039;kalvidres&#039;&lt;br /&gt;
LEFT JOIN prefix_attendance AS attendance ON attendance.id = cm.instance AND m.name = &#039;attendance&#039;&lt;br /&gt;
LEFT JOIN prefix_checklist AS checklist ON checklist.id = cm.instance AND m.name = &#039;checklist&#039;&lt;br /&gt;
LEFT JOIN prefix_flashcard AS flashcard ON flashcard.id = cm.instance AND m.name = &#039;flashcard&#039;&lt;br /&gt;
LEFT JOIN prefix_lti AS lti ON lti.id = cm.instance AND m.name = &#039;lti&#039;&lt;br /&gt;
LEFT JOIN prefix_oublog AS oublog ON oublog.id = cm.instance AND m.name = &#039;oublog&#039;&lt;br /&gt;
LEFT JOIN prefix_ouwiki AS ouwiki ON ouwiki.id = cm.instance AND m.name = &#039;ouwiki&#039;&lt;br /&gt;
LEFT JOIN prefix_subpage AS subpage ON subpage.id = cm.instance AND m.name = &#039;subpage&#039;&lt;br /&gt;
LEFT JOIN prefix_journal AS journal ON journal.id = cm.instance AND m.name = &#039;journal&#039;&lt;br /&gt;
LEFT JOIN prefix_lightboxgallery AS lightboxgallery ON lightboxgallery.id = cm.instance AND m.name = &#039;lightboxgallery&#039;&lt;br /&gt;
LEFT JOIN prefix_elluminate AS elluminate ON elluminate.id = cm.instance AND m.name = &#039;elluminate&#039;&lt;br /&gt;
LEFT JOIN prefix_adaptivequiz AS adaptivequiz ON adaptivequiz.id = cm.instance AND m.name = &#039;adaptivequiz&#039;&lt;br /&gt;
LEFT JOIN prefix_hotpot AS hotpot ON hotpot.id = cm.instance AND m.name = &#039;hotpot&#039;&lt;br /&gt;
LEFT JOIN prefix_wiziq AS wiziq ON wiziq.id = cm.instance AND m.name = &#039;wiziq&#039;&lt;br /&gt;
LEFT JOIN prefix_turnitintooltwo AS turnitintooltwo ON turnitintooltwo.id = cm.instance AND m.name = &#039;turnitintooltwo&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cm.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Hits) between dates===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module, COUNT( * ) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME( l.`timecreated` ) BETWEEN  &#039;2018-10-01 00:00:00&#039; AND  &#039;2019-09-31 00:00:00&#039;)&lt;br /&gt;
GROUP BY module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Instances and Hits) for each academic year===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2017-10-01 00:00:00&#039; AND &#039;2018-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2017&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2017-10-01 00:00:00&#039; AND &#039;2018-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2017&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2018-10-01 00:00:00&#039; AND &#039;2019-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2018&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2018-10-01 00:00:00&#039; AND &#039;2019-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2018&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2019-10-01 00:00:00&#039; AND &#039;2020-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2019&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`timecreated`) BETWEEN &#039;2019-10-01 00:00:00&#039; AND &#039;2020-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2019&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_modules AS m&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Unique user sessions per day and month + graph===&lt;br /&gt;
The &amp;quot;graph&amp;quot; column is used when displaying a graph (which needs at least three columns to pick from)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT userid) AS &amp;quot;Unique User Logins&amp;quot;&lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y /%m / %d&amp;quot;) AS &amp;quot;Year / Month / Day&amp;quot;, &amp;quot;Graph&amp;quot; &lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE action LIKE &#039;loggedin&#039;&lt;br /&gt;
#AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) # optional start date&lt;br /&gt;
#AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:00&#039;) # optional end date&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And...&lt;br /&gt;
&lt;br /&gt;
Counting user&#039;s global and unique hits per day + counting individual usage of specific activities and resources (on that day),&lt;br /&gt;
&lt;br /&gt;
And since I am using phpMyAdmin&#039;s &amp;quot;Display Graph&amp;quot; feature (at the bottom of the query&#039;s output page), I have scaled down the &amp;quot;User Hits&amp;quot; by 10 to fit the graph. that&#039;s it.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y-%m-%d&amp;quot;) AS &amp;quot;Datez&amp;quot;&lt;br /&gt;
,COUNT(DISTINCT userid) AS &amp;quot;Unique Users&amp;quot;&lt;br /&gt;
,ROUND(COUNT(*)/10) &amp;quot;User Hits (K)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_quiz&#039;,1,0)) &amp;quot;Quizzes&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_forum&#039; or component=&#039;mod_forumng&#039;,1,0)) &amp;quot;Forums&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_assign&#039;,1,0)) &amp;quot;Assignments&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_oublog&#039;,1,0)) &amp;quot;Blogs&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_resource&#039;,1,0)) &amp;quot;Files (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_url&#039;,1,0)) &amp;quot;Links (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_page&#039;,1,0)) &amp;quot;Pages (Resource)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE 1=1&lt;br /&gt;
AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-03-01 00:00:00&#039;) # optional START DATE&lt;br /&gt;
AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-05-31 23:59:00&#039;) # optional END DATE&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide, daily unique user hits for the last 7 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
  DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%m%d&#039;) &#039;Day&#039;&lt;br /&gt;
  ,COUNT(DISTINCT l.userid) AS &#039;Distinct Users Hits&#039;&lt;br /&gt;
  ,COUNT( l.userid) AS &#039;Users Hits&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log AS l&lt;br /&gt;
WHERE l.courseid &amp;gt; 1&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 7 DAY)&lt;br /&gt;
GROUP BY DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User detailed activity in course modules===&lt;br /&gt;
Considering only several modules: url, resource, forum, quiz, questionnaire.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.id, ra.roleid,&lt;br /&gt;
CONCAT(u.lastname, &#039; &#039;, u.firstname) AS &#039;Student&#039;&lt;br /&gt;
,COUNT(l.id) AS &#039;Actions&#039;&lt;br /&gt;
,l.component &amp;quot;Module type&amp;quot;&lt;br /&gt;
,l.objectid &amp;quot;Module ID&amp;quot;&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN l.component = &#039;mod_url&#039; THEN (SELECT u.name FROM prefix_url AS u WHERE u.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_resource&#039; THEN (SELECT r.name FROM prefix_resource AS r WHERE r.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_forum&#039; THEN (SELECT f.name FROM prefix_forum AS f WHERE f.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_quiz&#039; THEN (SELECT q.name FROM prefix_quiz AS q WHERE q.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_questionnaire&#039; THEN (SELECT q.name FROM prefix_questionnaire AS q WHERE q.id = l.objectid )&lt;br /&gt;
END AS &#039;Module name&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM prefix_groups AS g&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid WHERE g.courseid = l.courseid AND m.userid = u.id) &amp;quot;user_groups&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT s.name &lt;br /&gt;
  FROM prefix_course_modules AS cm &lt;br /&gt;
  JOIN prefix_course_sections AS s ON s.course = cm.course AND s.id = cm.section &lt;br /&gt;
  WHERE cm.id = l.contextinstanceid) AS &amp;quot;Section name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log AS l  &lt;br /&gt;
JOIN prefix_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = l.userid &lt;br /&gt;
  AND ra.contextid = (SELECT id FROM prefix_context WHERE instanceid = l.courseid AND contextlevel = 50) &lt;br /&gt;
WHERE l.courseid = %%COURSEID%%&lt;br /&gt;
  AND l.component IN (&#039;mod_url&#039;, &#039;mod_resource&#039;, &#039;mod_forum&#039;, &#039;mod_quiz&#039;, &#039;mod_questionnaire&#039;) &lt;br /&gt;
  %%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%%&lt;br /&gt;
 &lt;br /&gt;
GROUP BY u.id, l.component&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What teachers and courses considered active?===&lt;br /&gt;
This report display several calculations and parameters that help the Online academic training team find teachers that might need more support getting their courses more supporting of online learning pedagogical methodologies.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,&lt;br /&gt;
			  course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
#,course.shortname&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2012%&#039; THEN &#039;2012&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2013%&#039; THEN &#039;2013&#039; &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2014%&#039; THEN &#039;2014&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2015%&#039; THEN &#039;2015&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester a%&#039; THEN &#039;Spring semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester b%&#039; THEN &#039;Fall semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester s%&#039; THEN &#039;Summer semester&#039;&lt;br /&gt;
END AS Semester&lt;br /&gt;
&lt;br /&gt;
,IF(course.startdate&amp;gt;0, DATE_FORMAT(FROM_UNIXTIME(startdate), &#039;%d-%m-%Y&#039;), &#039;no date&#039;) AS &amp;quot;Course Start Date&amp;quot; &lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 4 AND ctx.instanceid = course.id&lt;br /&gt;
) AS &amp;quot;Assistant teacher&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
&lt;br /&gt;
# Uncomment to use the new Moodle 2.8+ logstore&lt;br /&gt;
#,(SELECT COUNT(*) FROM mdl_logstore_standard_log AS l WHERE l.courseid = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Student HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Teacher HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_log AS l WHERE l.course = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course c&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = c.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND c.id = course.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
  &lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = course.id) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(DISTINCT cm.module) FROM prefix_course_modules cm &lt;br /&gt;
  WHERE cm.course = course.id) UniqueModules&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(DISTINCT m.name) &lt;br /&gt;
  FROM prefix_course_modules cm &lt;br /&gt;
  JOIN mdl_modules as m ON m.id = cm.module&lt;br /&gt;
  WHERE cm.course = course.id) UniqueModuleNames&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;ouwiki&#039;, &#039;wiki&#039;) ) &amp;quot;Num Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;oublog&#039;) ) &amp;quot;Num Blogs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;forum&#039;, &#039;forumng&#039;) ) &amp;quot;Num Forums&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;resource&#039;, &#039;folder&#039;, &#039;url&#039;, &#039;tab&#039;, &#039;file&#039;, &#039;book&#039;, &#039;page&#039;) ) Resources&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;forum&#039;, &#039;forumng&#039;, &#039;oublog&#039;, &#039;page&#039;, &#039;file&#039;, &#039;url&#039;, &#039;wiki&#039; , &#039;ouwiki&#039;) ) &amp;quot;Basic Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;advmindmap&#039;, &#039;assign&#039;, &#039;attendance&#039;, &#039;book&#039;, &#039;choice&#039;, &#039;folder&#039;, &#039;tab&#039;, &#039;glossary&#039;, &#039;questionnaire&#039;, &#039;quiz&#039;, &#039;label&#039; ) ) &amp;quot;Avarage Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;elluminate&#039;, &#039;game&#039;, &#039;workshop&#039;) ) &amp;quot;Advanced Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course&lt;br /&gt;
&lt;br /&gt;
#WHERE course.shortname LIKE &#039;%2015%&#039;&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_SEARCHTEXT:course.shortname:~%%&lt;br /&gt;
&lt;br /&gt;
WHERE course.fullname LIKE &#039;%2015%&#039; &lt;br /&gt;
&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY UniqueModules DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly attendance report===&lt;br /&gt;
This report display weekly report in format HH:M:SS This MySQL query works together with AttendaceRegister module, and gather Log information from Attendanceregister_log table. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, SEC_TO_TIME (SUM(arsess.duration)) AS weekly_online_attendance,  FROM_UNIXTIME (arsess.logout) AS Last_Logout&lt;br /&gt;
FROM prefix_attendanceregister_session AS arsess&lt;br /&gt;
JOIN prefix_user AS u ON arsess.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE (((arsess.logout) BETWEEN UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 7 DAY)) AND UNIX_TIMESTAMP(CURDATE())))&lt;br /&gt;
&lt;br /&gt;
GROUP BY arsess.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many distinct users connected to Moodle using the app by month===&lt;br /&gt;
https://moodle.org/mod/forum/discuss.php?d=336086#p1354194 by &lt;br /&gt;
Iñigo Zendegi Urzelai&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;) as year, &lt;br /&gt;
  to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;) as month, &lt;br /&gt;
  count(distinct userid) as distinct_users&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log l&lt;br /&gt;
WHERE l.origin=&#039;ws&#039;&lt;br /&gt;
GROUP BY to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;), to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;) &lt;br /&gt;
ORDER BY to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;), to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Course Reports==&lt;br /&gt;
===Most Active courses===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(l.userid) AS Views&lt;br /&gt;
FROM `mdl_logstore_standard_log` l, `mdl_user` u, `mdl_role_assignments` r&lt;br /&gt;
WHERE l.courseid=35&lt;br /&gt;
AND l.userid = u.id&lt;br /&gt;
AND (l.timecreated &amp;gt; UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) AND l.timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:59&#039;))AND r.contextid= (&lt;br /&gt;
	 SELECT id&lt;br /&gt;
	 FROM mdl_context&lt;br /&gt;
	 WHERE contextlevel=50 AND instanceid=l.courseid&lt;br /&gt;
 )&lt;br /&gt;
AND r.roleid=5&lt;br /&gt;
AND r.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active courses, advanced===&lt;br /&gt;
Including: Teacher&#039;s name, link to the course, All types of log activities, special YEAR generated field, Activities and Resource count, enrolled Student count&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשע&#039; THEN &#039;תשע&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעא&#039; THEN &#039;תשעא&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעב&#039; THEN &#039;תשעב&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = l.course) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_log l &lt;br /&gt;
INNER JOIN prefix_course c ON l.course = c.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
#The following line restricts the courses returned to those having more than 2 modules.  Adjust based on your needs.&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY Year DESC, hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Least active or probably empty courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;-1&amp;quot; instead of &amp;quot;0&amp;quot; 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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
c.fullname,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;CourseLink&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timecreated&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timemodified&#039;,&lt;br /&gt;
CASE&lt;br /&gt;
 WHEN c.timecreated = c.timemodified THEN &#039;-1&#039;&lt;br /&gt;
 ELSE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated))&lt;br /&gt;
END AS &#039;DateDifference&#039;,&lt;br /&gt;
COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
LEFT JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
WHERE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated) ) &amp;lt; 60&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
HAVING COUNT(ue.id) &amp;lt;= 3&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Count unique teachers with courses that use at least X module (Moodle19)===&lt;br /&gt;
You can remove the outer &amp;quot;SELECT COUNT(*) FROM (...) AS ActiveTeachers&amp;quot; SQL query and get the list of the Teachers and Courses.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(*)&lt;br /&gt;
FROM (SELECT c.id AS CourseID, c.fullname AS Course, ra.roleid AS RoleID, CONCAT(u.firstname, &#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = c.id) AS Modules&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid AND ctx.contextlevel = 50 &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE  ra.roleid = 3 &lt;br /&gt;
GROUP BY u.id&lt;br /&gt;
HAVING Modules &amp;gt; 5) AS ActiveTeachers&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RESOURCE count for each COURSE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) count, l.course, c.fullname coursename&lt;br /&gt;
FROM prefix_resource l INNER JOIN prefix_course c on l.course = c.id&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY count DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Common resource types count for each Category (Moodle19)===&lt;br /&gt;
Including sub-categories in total count.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category&lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Links&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference NOT LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Files&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;directory&#039; &lt;br /&gt;
) AS Folders&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;html&#039; &lt;br /&gt;
) AS Pages&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM stats_log_context_role_course &lt;br /&gt;
WHERE roleid = 5 AND module = &#039;resource&#039; AND category = mcc.id&lt;br /&gt;
) AS Hits&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Where &amp;quot;stats_log_context_role_course&amp;quot; (in the above SQL query) is a VIEW generated by:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
CREATE VIEW stats_log_context_role_course AS&lt;br /&gt;
SELECT l.course, c.category, cc.path, l.module, l.action, ra.userid, ra.roleid&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = l.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Same query but for Moodle2+&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category,&lt;br /&gt;
mcc.path,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_url AS u&lt;br /&gt;
JOIN prefix_course AS c ON c.id = u.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS URLs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_folder AS f&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS FOLDERs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_page AS p&lt;br /&gt;
JOIN prefix_course AS c ON c.id = p.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS PAGEs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_book AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS BOOKs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_label AS l&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS LABELs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_tab AS t&lt;br /&gt;
JOIN prefix_course AS c ON c.id = t.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS TABs&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed Resource COUNT by Teacher in each course===&lt;br /&gt;
&lt;br /&gt;
Including (optional) filter by: year, semester and course id.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
, c.id&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעב%&#039; THEN &#039;2012&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעא%&#039; THEN &#039;2011&#039;&lt;br /&gt;
END ) as Year&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר א%&#039; THEN &#039;Semester A&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ב%&#039; THEN &#039;Semester B&#039;&lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ק%&#039; THEN &#039;Semester C&#039;&lt;br /&gt;
END ) as Semester&lt;br /&gt;
,COUNT(c.id) AS Total&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 20) AS TABs&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 33) AS BOOKs&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_resource` as r &lt;br /&gt;
JOIN `prefix_course` AS c on c.id = r.course&lt;br /&gt;
#WHERE type= &#039;file&#039; and reference NOT LIKE &#039;http://%&#039; &lt;br /&gt;
&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
#AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY COUNT(c.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses that are defined as using GROUPs===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/group/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = c.id) Modules&lt;br /&gt;
,(SELECT count(*) FROM prefix_groups g WHERE g.courseid = c.id) Groups&lt;br /&gt;
 FROM `prefix_course` AS c&lt;br /&gt;
WHERE groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Groups===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with Groups in them (groupmode &amp;gt; 0). You can also use groupmode=1 to list just Separate type groups or groupmode=2 to list Visible type groups.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name, c.groupmode&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON c.id = g.courseid&lt;br /&gt;
WHERE c.groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users enrolled in a course with groups but not assigned a group ===&lt;br /&gt;
&lt;br /&gt;
Displays by course all enrolled users that have not been assigned a group in courses that have groups. NOTE: This needs to be optimized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) AS ROLE&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = course.id&lt;br /&gt;
&lt;br /&gt;
WHERE ue.enrolid NOT IN (select userid from prefix_groups_members WHERE g.id=groupid)&lt;br /&gt;
&lt;br /&gt;
ORDER BY Course, Lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Groups in course with member list===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List the groups in a course (replace the # by the course id number) with the members of each group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name AS Groupname, u.username&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_user AS u ON m.userid = u.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Group Export===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
There&#039;s a [[Import_groups|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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT g.name AS groupname, g.description, g.enrolmentkey&lt;br /&gt;
FROM prefix_groups AS g &lt;br /&gt;
JOIN prefix_course as c ON g.courseid = c.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Courses in and below a certain category===&lt;br /&gt;
Use this SQL code to retrieve all courses that exist in or under a set category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the category you want to know about...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course. * , prefix_course_categories. *&lt;br /&gt;
FROM prefix_course, prefix_course_categories&lt;br /&gt;
WHERE prefix_course.category = prefix_course_categories.id&lt;br /&gt;
AND (&lt;br /&gt;
prefix_course_categories.path LIKE &#039;%/$s/%&#039;&lt;br /&gt;
OR prefix_course_categories.path LIKE &#039;%/$s&#039;&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Categories in one level below a certain category===&lt;br /&gt;
Use this PHP code to retrieve a list of all categories below a certain category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the top level category you are interested in.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
require_once(&#039;./config.php&#039;);&lt;br /&gt;
&lt;br /&gt;
$parent_id = $s;&lt;br /&gt;
&lt;br /&gt;
$categories= array();&lt;br /&gt;
&lt;br /&gt;
$categories = get_categories($parent_id);&lt;br /&gt;
&lt;br /&gt;
echo &#039;&amp;lt;ol&amp;gt;&#039;;&lt;br /&gt;
foreach ($categories as $category)&lt;br /&gt;
        {&lt;br /&gt;
        echo &#039;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&#039;.$CFG-&amp;gt;wwwroot.&#039;/course/category.php?id=&#039;.$category-&amp;gt;id.&#039;&amp;quot;&amp;gt;&#039;.$category-&amp;gt;name.&#039;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
        }&lt;br /&gt;
echo &#039;&amp;lt;/ol&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Blog activity per Course (not including VIEW)===&lt;br /&gt;
Filter activity logging to some specific Course Categories!&lt;br /&gt;
+ link course name to actual course (for quick reference)&lt;br /&gt;
(you can change %blog% to %wiki% to filter down all wiki activity or any other module you wish)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID&lt;br /&gt;
,m.name ,count(cm.id) as counter &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS Students&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE `module` LIKE &#039;%blog%&#039; AND course = c.id AND action NOT LIKE &#039;%view%&#039; ) as BlogActivity&lt;br /&gt;
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 &lt;br /&gt;
WHERE m.name LIKE &#039;%blog%&#039; AND c.category IN ( 8,13,15)&lt;br /&gt;
GROUP BY cm.course,cm.module order by counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student&#039;s posts content in all course blogs (oublog)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
b.name &lt;br /&gt;
,op.title&lt;br /&gt;
,op.message&lt;br /&gt;
,( SELECT CONCAT(u.firstname, &#039; &#039;,u.lastname) FROM prefix_user AS u WHERE u.id = oi.userid) AS &amp;quot;Username&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_oublog_posts AS op&lt;br /&gt;
JOIN prefix_oublog_instances AS oi ON oi.id = op.oubloginstancesid &lt;br /&gt;
JOIN prefix_oublog as b ON b.id = oi.oublogid&lt;br /&gt;
JOIN prefix_course AS c ON b.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Courses which uploaded a Syllabus file===&lt;br /&gt;
+ under specific Category&lt;br /&gt;
+ show first Teacher in that course&lt;br /&gt;
+ link Course&#039;s fullname to actual course&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) as Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user as u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) as Teacher&lt;br /&gt;
FROM prefix_resource as r &lt;br /&gt;
JOIN prefix_course as c ON r.course = c.id&lt;br /&gt;
WHERE ( r.name LIKE &#039;%סילבוס%&#039; OR r.name LIKE &#039;%סילאבוס%&#039; OR r.name LIKE &#039;%syllabus%&#039; OR r.name LIKE &#039;%תכנית הקורס%&#039; ) &lt;br /&gt;
AND c.category IN (10,18,26,13,28)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
===Site-wide completed SCORM activities by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===All users enrolled in a course without a role===&lt;br /&gt;
Identifies All users that are enrolled in a course but are not assigned a role.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user.firstname AS Firstname,&lt;br /&gt;
user.lastname AS Lastname,&lt;br /&gt;
user.idnumber Employee_ID,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user as user ON user.id = ue.userid&lt;br /&gt;
&lt;br /&gt;
WHERE user.id NOT IN (&lt;br /&gt;
SELECT u.id&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE c.id=course.id&lt;br /&gt;
)&lt;br /&gt;
ORDER BY Course, Lastname, Firstname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List course resources accumulative file size and count===&lt;br /&gt;
This is the main (first) report, which has a link (alias) to a second report (the following on this page) which list each file in the course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id &amp;quot;CourseID&amp;quot;, context.id &amp;quot;ContextID&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;, c.id, &#039;&amp;quot;&amp;gt;&#039;, c.fullname ,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Course Name&amp;quot;&lt;br /&gt;
, COUNT(*) &amp;quot;Course Files&amp;quot; , ROUND( SUM( f.filesize ) /1048576 ) AS file_size_MB&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/blocks/configurable_reports/viewreport.php?alias=coursefiles&amp;amp;courseid=1&amp;amp;filter_courses=&#039;, c.id, &#039;&amp;quot;&amp;gt;List files&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List Files&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
JOIN mdl_context AS context ON context.id = f.contextid&lt;br /&gt;
JOIN mdl_course AS c ON c.id = (&lt;br /&gt;
  SELECT instanceid&lt;br /&gt;
  FROM mdl_context&lt;br /&gt;
  WHERE id = SUBSTRING_INDEX( SUBSTRING_INDEX( context.path, &#039;/&#039; , -2 ) , &#039;/&#039;, 1 ) )&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this report, you will have to define &amp;quot;alias&amp;quot; report property to &amp;quot;coursefiles&amp;quot; for it to be able to be called from the above report.&lt;br /&gt;
And also setup (add) a FILTER_COURSES filter. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id ,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/pluginfile.php/&#039;, contextid, &#039;/&#039;, component, &#039;/&#039;, filearea, &#039;/&#039;, itemid, &#039;/&#039;, filename, &#039;&amp;quot;&amp;gt;&#039;, filename,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;File&amp;quot;&lt;br /&gt;
,filesize, mimetype ,author, license, timecreated, component, filearea, filepath&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
            AND f.contextid&lt;br /&gt;
            IN (   SELECT id&lt;br /&gt;
                     FROM mdl_context&lt;br /&gt;
                    WHERE path &lt;br /&gt;
                     LIKE (   SELECT CONCAT(&#039;%/&#039;,id,&#039;/%&#039;)&lt;br /&gt;
                                  AS contextquery&lt;br /&gt;
                                FROM mdl_context&lt;br /&gt;
                               WHERE 1=1&lt;br /&gt;
			        %%FILTER_COURSES:instanceid%%&lt;br /&gt;
                                 AND contextlevel = 50&lt;br /&gt;
                           )&lt;br /&gt;
                )&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Which courses has redundant topics===&lt;br /&gt;
This report list several &amp;quot;active topics&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
The following, second SQL query, could be used to &amp;quot;trim&amp;quot; down those redundant course topics/sections/weeks by updating the course format&#039;s numsection (Number of sections) setting. (It&#039;s a per course format setting!)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, format,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT value  FROM  `mdl_course_format_options` WHERE  `courseid` = c.id AND `format` = c.format AND `name` = &#039;numsections&#039; ) AS &amp;quot;numsections&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND `sequence` !=  &#039;&#039; ) AS &amp;quot;Non empty sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id ) AS &amp;quot;Total section count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND sequence IS NOT NULL) AS &amp;quot;Non NULL sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND name != &#039;&#039;) AS &amp;quot;Non empty section Name count&amp;quot;&lt;br /&gt;
 ,(SELECT COUNT(*) FROM mdl_course_modules cm WHERE cm.course = c.id) &amp;quot;Modules count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course AS c&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following SQL REPLACE query is used for &amp;quot;fixing&amp;quot; (updating) the &amp;quot;numsections&amp;quot; of a specific course format &amp;quot;onetopics&amp;quot; (you can always change it, or discard it to use this SQL REPLACE on all course formats) &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
REPLACE INTO `mdl_course_format_options` (`id`, `courseid`, `format`, `sectionid`, `name`, `value`) &lt;br /&gt;
SELECT NULL, c.id, &#039;onetopic&#039;, &#039;0&#039;, &#039;numsections&#039;, (SELECT COUNT(*) FROM `mdl_course_sections` WHERE `course` = c.id AND name != &#039;&#039;)&lt;br /&gt;
FROM `mdl_course` c where format = &#039;onetopic&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hidden Courses with Students Enrolled===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.visible AS Visible, &lt;br /&gt;
DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors,&lt;br /&gt;
&lt;br /&gt;
(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;, &lt;br /&gt;
&lt;br /&gt;
now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
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) &amp;gt; 0&lt;br /&gt;
ORDER BY StartDate, Instructor_Email, Course_ID&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Course Design Reports==&lt;br /&gt;
&lt;br /&gt;
These are reports which summarize course design aspects, such as activity and resource modules per section, types of activities used, etc.&lt;br /&gt;
&lt;br /&gt;
===Course Content/Week===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report assumes that the first 14 sections in a course, not including the &amp;quot;0&amp;quot; or &amp;quot;Welcome&amp;quot; section, correspond to weeks (with &amp;quot;Subsections&amp;quot; given numbers much higher in the sequence). Of those sections, each is checked to count the number of:&lt;br /&gt;
&lt;br /&gt;
    Forums&lt;br /&gt;
    Graded Activities (may include Forums)&lt;br /&gt;
    Resources (not including a Label)&lt;br /&gt;
&lt;br /&gt;
Totals of each of these types of content elements per section are provided.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Only visible resources and activities are counted.&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: this is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
 &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT LIKE &#039;label&#039;),cm.id,NULL)) AS &#039;Ungraded Resources&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Graded Activities&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cs.section&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments and Weights===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Categories with weights of 0 are not included in this report.&lt;br /&gt;
&lt;br /&gt;
Only visible activities are included in this report.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This is designed to be a &amp;quot;Global&amp;quot; report in Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;) AS &#039;Grade Book Category&#039;&lt;br /&gt;
, IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND(SUM(DISTINCT gi.aggregationcoef), 2)+ROUND(SUM(DISTINCT mgi.aggregationcoef), 2)) AS &#039;Category weight&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT_WS(&#039;, &#039;,GROUP_CONCAT(DISTINCT gi.itemmodule SEPARATOR &#039;, &#039;), IF(mgi.id, &#039;manual&#039;,NULL)) AS &#039;Activity Types&#039;&lt;br /&gt;
, COUNT(DISTINCT gi.itemmodule) + IF(mgi.id,1,0) AS &#039;Different Activity Types&#039;&lt;br /&gt;
, CONCAT_WS(&#039;&amp;lt;br&amp;gt;&#039;, GROUP_CONCAT(DISTINCT gi.itemname ORDER BY gi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;), GROUP_CONCAT(DISTINCT mgi.itemname ORDER BY mgi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;)) AS &#039;Activity Names&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) + COUNT(DISTINCT mgi.id) AS &#039;Activity Count&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
&lt;br /&gt;
#get grade categories&lt;br /&gt;
LEFT JOIN prefix_grade_categories AS gc ON gc.courseid = c.id &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
JOIN prefix_grade_items AS gic ON gic.courseid = c.id AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
&lt;br /&gt;
# attach activities to course&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = c.id &lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.iteminstance = cm.instance AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.id&lt;br /&gt;
ORDER BY gc.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pre-Term Course Review===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
#   &amp;quot;Required blocks&amp;quot; include Instructor Block (mooprofile), Activities, and the Research block.&lt;br /&gt;
#    &amp;quot;Instructor Details&amp;quot; block is not the &amp;quot;Instructor&amp;quot; block (mooprofile) automatically provided by the system. It is an optional block that can be edited by the instructor. If not edited to remove boilerplate text, it should be hidden.&lt;br /&gt;
#    All courses should be in the &amp;quot;Collapsed Topics&amp;quot; format with the &amp;quot;Weeks&amp;quot; structure.&lt;br /&gt;
#    &amp;quot;Weeks defined in course settings&amp;quot; is taken from our SIS when the course shells are created, but can be edited by faculty. &amp;quot;# of weeks named and visible&amp;quot; should usually match or exceed this value.&lt;br /&gt;
#    We recommend that each week contain at least one forum, at least one graded activity, and at least one ungraded resource.&lt;br /&gt;
#    &amp;quot;Syllabus updated&amp;quot; date is for the first attached file found with the text &amp;quot;syllabus&amp;quot; in the name. The &amp;quot;Days ago&amp;quot; calculation is included for convenience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: At our institution, we construct categories each term, and insert a text string &amp;quot;staging&amp;quot; in the Category ID for pre-term courses during the preparation or &amp;quot;staging&amp;quot; phase of course development. We remove this text string (and change it to &amp;quot;production&amp;quot;) when courses go live at the start of the new term.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
#,RIGHT(c.idnumber,2) AS Type # Specific to GSC &amp;quot;Instructional Method&amp;quot; storage&lt;br /&gt;
&lt;br /&gt;
#, substring_index(substr(c.shortname FROM locate(&#039;.&#039;,c.shortname)+1),&#039;-&#039;,1) AS Section # Specific to GSC&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.lastname,&#039;, &#039;, u.firstname,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
,(SELECT IF((u2.description IS NULL) OR (u2.description LIKE &#039;&#039;),&#039;NO&#039;, &#039;YES&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT IF(u3.picture &amp;gt; 0,&#039;YES&#039;,&#039;NO&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u3 ON u3.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Picture&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(((bpi.visible IS NULL) OR (bpi.visible !=0)) AND ((bpm.visible IS NULL) OR (bpm.visible !=0)) AND ((bpa.visible IS NULL) OR (bpa.visible !=0)) AND ((bpr.visible IS NULL) OR (bpr.visible !=0)),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Required blocks visible&#039;&lt;br /&gt;
#, IF((bpm.visible IS NULL) OR (bpm.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Messages block visible&#039;&lt;br /&gt;
#, IF((bpa.visible IS NULL) OR (bpa.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;activities block visible&#039;&lt;br /&gt;
#, IF((bpr.visible IS NULL) OR (bpr.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;research block visible&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)) AND (bip.visible !=0),&#039;YES&#039;,&#039;&#039;) AS &#039;Instructor Details Block visible&#039; # This is a hack based on UUencoded string data from the title of HTML &amp;quot;Instructor Details&amp;quot; block&lt;br /&gt;
&lt;br /&gt;
#, IF(bi.configdata LIKE &#039;%ZGl0IHRoaXMgYmxvY2s%&#039;,&#039;NO&#039;,&#039;&#039;) AS &#039;Instructor Details Block Updated&#039; # HTML block has string &#039;dit this block&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(COUNT(bi.id) -  SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)),&#039;YES&#039;,&#039;&#039;) AS &#039;possible extra instructor blocks&#039; #looking for any HTML block with &amp;quot;instructor&amp;quot; in the title&lt;br /&gt;
&lt;br /&gt;
, IF(c.format=&#039;topcoll&#039;,&#039;YES&#039;, c.format) AS &#039;Collapsed Topics course format&#039; # change this if you want to test for a different format&lt;br /&gt;
, IF(cfo.value = 2, &#039;YES&#039;,&#039;NO&#039;) AS &#039;weeks structure&#039;&lt;br /&gt;
&lt;br /&gt;
, cfw.value AS &#039;weeks defined in course settings&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(((cs.name IS NOT NULL) AND (cs.visible = 1) AND (cs.section != &#039;0&#039;) AND (cs.sequence IS NOT NULL)),cs.id,NULL)) AS &#039;# of weeks named &amp;amp; visible (includes orphans)&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039; ,cs.id , NULL)) AS &#039;Weeks with Forum&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cs.id, NULL)) AS &#039;Weeks with Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT mgi.id) AS &#039;Manual Grade Items&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)),cm.id,NULL)) AS &#039;Resources&#039;&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)), cs.id, NULL)) AS &#039;Weeks with Resources&#039;&lt;br /&gt;
&lt;br /&gt;
# Here are some other things you could check for per course&lt;br /&gt;
#,(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 &#039;%forum%&#039;) AS Forums&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%quiz%&#039;) AS Quizzes&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%assign%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_resource.id) FROM prefix_resource JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course) AS Files&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_url.id) FROM prefix_url JOIN prefix_course ON prefix_course.id = prefix_url.course WHERE c.id = prefix_url.course) AS Links&lt;br /&gt;
&lt;br /&gt;
,(SELECT FROM_UNIXTIME(MAX(prefix_resource.timemodified))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS SyllabusDate&lt;br /&gt;
&lt;br /&gt;
,(SELECT TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(MAX(prefix_resource.timemodified)))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS DaysAgo&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, f.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement Forum Visible&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, fd.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement posted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
LEFT JOIN prefix_context AS ctxx ON c.id = ctxx.instanceid &lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpi ON bpi.contextid = ctxx.id AND bpi.blockinstanceid = &#039;43692&#039; # mooprofile&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpm ON bpm.contextid = ctxx.id AND bpm.blockinstanceid = &#039;43962&#039; # messages&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpa ON bpa.contextid = ctxx.id AND bpa.blockinstanceid = &#039;43963&#039; # activities&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpr ON bpr.contextid = ctxx.id AND bpr.blockinstanceid = &#039;38368&#039; # html research help&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.visible = 1 AND cs.sequence IS NOT NULL&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
LEFT JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_forum AS f ON f.course = c.id AND cm.instance = f.id AND cm.visible = 1&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.forum = f.id&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfo ON cfo.courseid = c.id AND cfo.name = &#039;layoutstructure&#039;&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfw ON cfw.courseid = c.id AND cfw.name = &#039;numsections&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_instances AS bi ON bi.parentcontextid = ctxx.id AND bi.blockname = &#039;html&#039; AND (bi.configdata LIKE &#039;%SW5zdHJ1Y3Rvc%&#039; or bi.configdata LIKE &#039;%bnN0cnVjdG9y%&#039;)&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bip ON bip.blockinstanceid = bi.id&lt;br /&gt;
&lt;br /&gt;
WHERE RIGHT(c.idnumber,2) IN (&#039;OL&#039;, &#039;BL&#039;, &#039;HY&#039;) &lt;br /&gt;
# AND substring(cc.path,2,2) IN (&#039;26&#039;) # Staging&lt;br /&gt;
#AND substring(cc.path,2,3) IN (&#039;158&#039;) # UG&lt;br /&gt;
AND cc.idnumber LIKE &#039;%staging%&#039;&lt;br /&gt;
AND ctxx.contextlevel = 50&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module instances + Module HITs by role teacher and student in course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
m.name AS &amp;quot;Module name&amp;quot;&lt;br /&gt;
, COUNT(*) AS &amp;quot;Module count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name ) AS &amp;quot;Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course_modules AS cm&lt;br /&gt;
JOIN mdl_modules AS m on m.id = cm.module&lt;br /&gt;
WHERE cm.course = &#039;%%COURSEID%%&#039;&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Syllabus===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Course Policies&amp;quot; and &amp;quot;Teaching Philosophy&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.fullname AS &#039;fullname&#039;&lt;br /&gt;
, ec.idnumber AS &#039;elis-id&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.startdate), &#039;%b %e, %Y&#039;) AS &#039;start&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.enddate), &#039;%b %e, %Y&#039;) AS &#039;end&#039;&lt;br /&gt;
, ecd.name AS &#039;longname&#039;&lt;br /&gt;
, ecd.code AS &#039;coursecode&#039;&lt;br /&gt;
, ecd.credits AS &#039;coursecredits&#039;&lt;br /&gt;
, ecd.syllabus AS &#039;description&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;learning-outcomes&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;outcomes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.firstname,&#039; &#039;, u.lastname,&#039;&amp;lt;/a&amp;gt; &#039;, u.email)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
, (SELECT  efc.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_char AS efc&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = efc.fieldid AND ef.shortname = &#039;term-code&#039;&lt;br /&gt;
WHERE ctxci.id = efc.contextid) AS &#039;termcode&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;prerequisites&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;prerequisites&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;textbooks&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;textbooks&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;other-class-materials&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;other-class-materials&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-policies&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-policies&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;teaching-philosophy&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;teaching-philosophy&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-methods&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-methods&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT u2.description&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT&lt;br /&gt;
&lt;br /&gt;
GROUP_CONCAT(DISTINCT CONCAT(&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;tr&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt;&#039;,IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;)&lt;br /&gt;
, &#039; &amp;lt;/td&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt; &#039;&lt;br /&gt;
,IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND( gi.aggregationcoef, 2)+ROUND(mgi.aggregationcoef, 2))&lt;br /&gt;
&lt;br /&gt;
) SEPARATOR &#039;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&#039;)&lt;br /&gt;
#get grade categories&lt;br /&gt;
FROM prefix_grade_categories AS gc &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gic ON gic.courseid = gc.courseid AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = gc.courseid  AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = gc.courseid and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
WHERE gc.courseid = c.id  ) AS &#039;grade categories&#039;&lt;br /&gt;
&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;50%&amp;quot; &amp;gt;&#039; AS &#039;table start&#039;&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;100%&amp;quot; &amp;gt;&#039; AS &#039;table start 2&#039;&lt;br /&gt;
, &#039;&amp;lt;/table&amp;gt;&#039; AS &#039;table end&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;activities-schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;schedule&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;grading-scale&#039;&lt;br /&gt;
WHERE ctxepm.id = eft.contextid) AS &#039;gradescale&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
# connect moodle course to ELIS class instance&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls_mdl AS ecm ON ecm.moodlecourseid = c.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls AS ec ON ec.id = ecm.classid&lt;br /&gt;
# class instance context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxci ON ctxci.instanceid = ec.id AND ctxci.contextlevel = &#039;14&#039;&lt;br /&gt;
&lt;br /&gt;
# connect ELIS class instance to ELIS course description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_crs AS ecd ON ecd.id = ec.courseid&lt;br /&gt;
# course description context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxecd ON ctxecd.instanceid = ecd.id AND ctxecd.contextlevel = &#039;13&#039;&lt;br /&gt;
&lt;br /&gt;
#connect ELIS program to ELIS Course Description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm_crs AS epc ON epc.courseid = ecd.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm AS epm ON epm.id = epc.curriculumid&lt;br /&gt;
# course program context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxepm ON ctxepm.instanceid = epm.id AND ctxepm.contextlevel = &#039;11&#039;&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Activities Helper===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report provides a list of the graded activities in a course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: Only graded activities are displayed.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This report assumes that course sections each last one week.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
# 303 Course Activities Helper&lt;br /&gt;
&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
gi.itemmodule AS &#039;activity type&#039;&lt;br /&gt;
# cs.section AS &#039;section number&#039;&lt;br /&gt;
&lt;br /&gt;
# Calculation assumes each section lasts one week&lt;br /&gt;
, CONCAT(DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section-1))), &#039;%b %e, %Y&#039;),&#039; - &amp;lt;br&amp;gt;&#039;,DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section))), &#039;%b %e, %Y&#039;)) AS &#039;Date&#039;&lt;br /&gt;
&lt;br /&gt;
, gi.itemname AS &#039;activity name&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = cm.instance) AS &#039;intro&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT f.intro FROM prefix_forum AS f WHERE f.id = cm.instance) AS &#039;f intro&#039;&lt;br /&gt;
&lt;br /&gt;
, CASE gi.itemmodule &lt;br /&gt;
WHEN &#039;assign&#039; THEN (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;forum&#039; THEN (SELECT f.intro FROM prefix_forum AS f WHERE f.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;quiz&#039; THEN (SELECT q.intro FROM prefix_quiz AS q WHERE q.id = gi.iteminstance) &lt;br /&gt;
END AS &#039;test case&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT GROUP_CONCAT(CONCAT(&#039; - &#039;,gi.itemname) SEPARATOR &#039;&amp;lt;BR&amp;gt;&#039;) FROM  prefix_grade_items AS gi  JOIN prefix_course_modules AS cm ON  gi.iteminstance = cm.instance WHERE gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id ) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
#get grade sections&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id  AND cs.section &amp;gt; 0 AND cs.section &amp;lt;=14&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_assign AS asg ON asg.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_grade_items AS gi  ON  gi.iteminstance = cm.instance AND gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
&lt;br /&gt;
ORDER BY gi.itemmodule, cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Grade and Course Completion Reports==&lt;br /&gt;
===Site-Wide Grade Report with All Items===&lt;br /&gt;
Shows grades for all course items along with course totals for each student. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, &lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
For MySQL users, you&#039;ll need to use the MySQL DATE_ADD function instead of DATEADD. Replace the line:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
And:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
CONCAT(u.firstname,&#039; &#039;,u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site-Wide Grade Report with Just Course Totals===&lt;br /&gt;
A second site-wide grade report for all students that just shows course totals. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id AND gi.itemtype = &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For MySQL users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN CONCAT(c.fullname, &#039; - Total&#039;)&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS TIME&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
 &lt;br /&gt;
WHERE  gi.courseid = c.id AND gi.itemtype = &#039;course&#039;&lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Learner report by Learner with grades===&lt;br /&gt;
Which Learners in which course and what are the grades&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;Name&#039; , u.lastname AS &#039;Surname&#039;, c.fullname AS &#039;Course&#039;, cc.name AS &#039;Category&#039;, &lt;br /&gt;
CASE WHEN gi.itemtype = &#039;Course&#039;    &lt;br /&gt;
THEN c.fullname + &#039; Course Total&#039;  &lt;br /&gt;
ELSE gi.itemname &lt;br /&gt;
END AS &#039;Item Name&#039;, ROUND(gg.finalgrade,2) AS Score,ROUND(gg.rawgrademax,2) AS Max, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) as Percentage,&lt;br /&gt;
&lt;br /&gt;
if (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) &amp;gt; 79,&#039;Yes&#039; , &#039;No&#039;) as Pass&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id &lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid &lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category &lt;br /&gt;
WHERE  gi.courseid = c.id and gi.itemname != &#039;Attendance&#039;&lt;br /&gt;
ORDER BY `Name` ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A very simple report with a list of course completion status by username. Completions are noted by date, blank otherwise. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  u.username, &lt;br /&gt;
  c.shortname,  &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%Y-%m-%d&#039;) AS completed&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion with Criteria===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A report with course completions by username, with Aggregation method, Criteria types, and Criteria detail where available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username AS user, &lt;br /&gt;
c.shortname AS course,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(t.timecompleted),&#039;%Y-%m-%d&#039;) AS completed,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = c.id AND a.criteriatype IS NULL) = 1) THEN &amp;quot;Any&amp;quot;&lt;br /&gt;
ELSE &amp;quot;All&amp;quot;&lt;br /&gt;
END AS aggregation,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;Self&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN &amp;quot;By Date&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 3 THEN &amp;quot;Unenrol Status&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &amp;quot;Activity&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 5 THEN &amp;quot;Duration&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 6 THEN &amp;quot;Course Grade&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 7 THEN &amp;quot;Approve by Role&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 8 THEN &amp;quot;Previous Course&amp;quot;&lt;br /&gt;
END AS criteriatype,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;*&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(p.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN p.criteriatype = 3 THEN t.unenroled&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,p.module,&#039;/view.php?id=&#039;,p.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,p.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN p.criteriatype = 5 THEN p.enrolperiod&lt;br /&gt;
WHEN p.criteriatype = 6 THEN CONCAT(&#039;Needed: &#039;,ROUND(p.gradepass,2),&#039; Achieved: &#039;,ROUND(t.gradefinal,2)) &lt;br /&gt;
WHEN p.criteriatype = 7 THEN p.role&lt;br /&gt;
WHEN p.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = p.courseinstance)&lt;br /&gt;
END AS criteriadetail &lt;br /&gt;
FROM prefix_course_completion_crit_compl AS t&lt;br /&gt;
JOIN prefix_user AS u ON t.userid = u.id&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
JOIN prefix_course_completion_criteria AS p ON t.criteriaid = p.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Completion Enabled and their settings===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with completion enabled and their Aggregation setting, Criteria types, and Criteria details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT c.shortname AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = t.course AND a.criteriatype IS NULL)) = 2 THEN &amp;quot;All&amp;quot;&lt;br /&gt;
ELSE &amp;quot;Any&amp;quot;&lt;br /&gt;
END AS Course_Aggregation,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;Self completion&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN &amp;quot;Date done by&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;Unenrolement&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 4 THEN &amp;quot;Activity completion&amp;quot;   &lt;br /&gt;
WHEN t.criteriatype = 5 THEN &amp;quot;Duration in days&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 6 THEN &amp;quot;Final grade&amp;quot;     &lt;br /&gt;
WHEN t.criteriatype = 7 THEN &amp;quot;Approve by role&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 8 THEN &amp;quot;Previous course&amp;quot;&lt;br /&gt;
END AS Criteria_type,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(t.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 4 THEN&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,t.module,&#039;/view.php?id=&#039;,t.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,t.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN t.criteriatype = 5 THEN ROUND(t.enrolperiod/86400)&lt;br /&gt;
WHEN t.criteriatype = 6 THEN ROUND(t.gradepass,2)&lt;br /&gt;
WHEN t.criteriatype = 7 THEN (SELECT r.shortname FROM prefix_role AS r WHERE r.id = t.role)&lt;br /&gt;
WHEN t.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = t.courseinstance)&lt;br /&gt;
END AS Criteria_detail&lt;br /&gt;
FROM prefix_course_completion_criteria as t&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Completion Report with custom dates===&lt;br /&gt;
&lt;br /&gt;
List of users who completed multiple or single course/s from a start date to end date chosen by the user. The output gives username, name, course name, completion date and score&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT u.username AS &#039;User Name&#039;,&lt;br /&gt;
CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Name&#039;,&lt;br /&gt;
c.shortname AS &#039;Course Name&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%W %e %M, %Y&#039;) AS &#039;Completed Date&#039;,&lt;br /&gt;
ROUND(c4.gradefinal,2) AS &#039;Score&#039;&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
JOIN prefix_course_completion_crit_compl AS c4 ON u.id = c4.userid&lt;br /&gt;
WHERE c.enablecompletion = 1  AND (p.timecompleted IS NOT NULL OR p.timecompleted !=&#039;&#039;) &lt;br /&gt;
AND (p.timecompleted&amp;gt;= :start_date AND p.timecompleted&amp;lt;=:end_date)&lt;br /&gt;
GROUP BY u.username&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scales used in activities===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT scale.name&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,gi.itemmodule,&#039;/view.php?id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module View&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/modedit.php?up&#039;,&#039;date=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module Settings&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON c.id = gi.courseid&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = gi.courseid AND cm.instance = gi.iteminstance&lt;br /&gt;
JOIN prefix_scale AS scale ON scale.id = gi.scaleid&lt;br /&gt;
WHERE gi.scaleid IS NOT NULL&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Extra Credit Items by Name Only===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
This query identifies grade items in visible courses with student enrollment that have &amp;quot;extra credit&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, gi.itemname AS Item_Name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors&lt;br /&gt;
&lt;br /&gt;
,(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;&lt;br /&gt;
&lt;br /&gt;
,now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON gi.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE gi.itemname LIKE &#039;%extra credit%&#039; &lt;br /&gt;
	AND gi.gradetype = &#039;1&#039; &lt;br /&gt;
	AND gi.hidden = &#039;0&#039; &lt;br /&gt;
	AND gi.aggregationcoef = &#039;0&#039; &lt;br /&gt;
	AND c.visible = 1&lt;br /&gt;
	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) &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
GROUP BY Course_ID, gi.id&lt;br /&gt;
ORDER BY StartDate, Course_ID&lt;br /&gt;
 &lt;br /&gt;
%%FILTER_SEARCHTEXT:Course_ID:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site Wide Number of Courses Completed by User===&lt;br /&gt;
Contributed by Ken St. John&lt;br /&gt;
&lt;br /&gt;
Simple report that shows the number of completed courses for all users site wide&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname, u.firstname,&lt;br /&gt;
COUNT(p.timecompleted) AS TotalCompletions&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
GROUP BY p.userid&lt;br /&gt;
ORDER BY u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Activity Module Reports==&lt;br /&gt;
&lt;br /&gt;
=== User activity completions with dates===&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.username As &#039;User&#039;,&lt;br /&gt;
c.shortname AS &#039;Course&#039;,&lt;br /&gt;
m.name AS Activitytype, &lt;br /&gt;
CASE &lt;br /&gt;
    WHEN cm.module = 1 THEN (SELECT a1.name FROM prefix_assign a1            WHERE a1.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 2 THEN (SELECT a2.name FROM prefix_assignment a2    WHERE a2.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 3 THEN (SELECT a3.name FROM prefix_book a3               WHERE a3.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 4 THEN (SELECT a4.name FROM prefix_chat a4                WHERE a4.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 5 THEN (SELECT a5.name FROM prefix_choice a5            WHERE a5.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 6 THEN (SELECT a6.name FROM prefix_data a6                WHERE a6.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 7 THEN (SELECT a7.name FROM prefix_feedback a7        WHERE a7.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 8 THEN (SELECT a8.name FROM prefix_folder a8              WHERE a8.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 9 THEN (SELECT a9.name FROM prefix_forum a9              WHERE a9.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 10 THEN (SELECT a10.name FROM prefix_glossary a10         WHERE a10.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 11 THEN (SELECT a11.name FROM prefix_imscp  a11           WHERE a11.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 12 THEN (SELECT a12.name FROM prefix_label a12              WHERE a12.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 13 THEN (SELECT a13.name FROM prefix_lesson a13            WHERE a13.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 14 THEN (SELECT a14.name FROM prefix_lti a14                    WHERE a14.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 15 THEN (SELECT a15.name FROM prefix_page a15               WHERE a15.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 16 THEN (SELECT a16.name FROM prefix_quiz  a16               WHERE a16.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 17 THEN (SELECT a17.name FROM prefix_resource a17         WHERE a17.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 18 THEN (SELECT a18.name FROM prefix_scorm a18             WHERE a18.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 19 THEN (SELECT a19.name FROM prefix_survey a19             WHERE a19.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 20 THEN (SELECT a20.name FROM prefix_url a20                      WHERE a20.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 21 THEN (SELECT a21.name FROM prefix_wiki a21                    WHERE a21.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 22 THEN (SELECT a22.name FROM prefix_workshop a22           WHERE a22.id = cm.instance)&lt;br /&gt;
END AS Actvityname,&lt;br /&gt;
# cm.section AS Coursesection,&lt;br /&gt;
CASE&lt;br /&gt;
    WHEN cm.completion = 0 THEN &#039;0 None&#039;&lt;br /&gt;
    WHEN cm.completion = 1 THEN &#039;1 Self&#039;&lt;br /&gt;
    WHEN cm.completion = 2 THEN &#039;2 Auto&#039;&lt;br /&gt;
END AS Activtycompletiontype, &lt;br /&gt;
CASE&lt;br /&gt;
   WHEN cmc.completionstate = 0 THEN &#039;In Progress&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 1 THEN &#039;Completed&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 2 THEN &#039;Completed with Pass&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 3 THEN &#039;Completed with Fail&#039;&lt;br /&gt;
   ELSE &#039;Unknown&#039;&lt;br /&gt;
END AS &#039;Progress&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(cmc.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;&lt;br /&gt;
FROM prefix_course_modules_completion cmc &lt;br /&gt;
JOIN prefix_user u ON cmc.userid = u.id&lt;br /&gt;
JOIN prefix_course_modules cm ON cmc.coursemoduleid = cm.id&lt;br /&gt;
JOIN prefix_course c ON cm.course = c.id&lt;br /&gt;
JOIN prefix_modules m ON cm.module = m.id&lt;br /&gt;
# skip the predefined admin and guest user&lt;br /&gt;
WHERE u.id &amp;gt; 2&lt;br /&gt;
# config reports filters&lt;br /&gt;
%%FILTER_USERS:u.username%%&lt;br /&gt;
%%FILTER_SEARCHTEXT:m.name:~%%&lt;br /&gt;
%%FILTER_STARTTIME:cmc.timemodified:&amp;gt;%% %%FILTER_ENDTIME:cmc.timemodified:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many SCORM activities are used in each Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cm.course,c.fullname ,m.name &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/scorm/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,count(cm.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS Counter&lt;br /&gt;
 &lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
  JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
  JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%scorm%&#039; &lt;br /&gt;
GROUP BY cm.course,cm.module &lt;br /&gt;
ORDER BY count(cm.id) desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===SCORM Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of SCORM activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, scm.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;SCO%&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_scorm AS scm ON scm.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LTI (External Tool) Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of  LTI (External Tool) Usage activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, lti.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;lti&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_lti AS lti ON lti.id = cm.instance&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each MODULE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module,action,count(id) as counter&lt;br /&gt;
FROM prefix_log&lt;br /&gt;
GROUP BY module,action&lt;br /&gt;
ORDER BY module,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Most popular ACTIVITY===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, module&lt;br /&gt;
FROM prefix_log l&lt;br /&gt;
WHERE module != &#039;login&#039; AND module != &#039;course&#039; AND module != &#039;role&#039;&lt;br /&gt;
GROUP BY module&lt;br /&gt;
ORDER BY hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide use of ACTIVITIES and RESOURCES===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count( cm.id ) AS counter, m.name&lt;br /&gt;
FROM `prefix_course_modules` AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
ORDER BY counter DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LOG file ACTIONS per MODULE per COURSE (IDs)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select course,module,action,count(action) as summa from prefix_log&lt;br /&gt;
where action &amp;lt;&amp;gt; &#039;new&#039;&lt;br /&gt;
group by course,action,module&lt;br /&gt;
order by course,module,action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System Wide usage count of various course Activities===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
Like: Forum, Wiki, Blog, Assignment, Database,&lt;br /&gt;
#Within specific category&lt;br /&gt;
#Teacher name in course&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS Forums&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%data%&#039;) AS Databses&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%assignment%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 18)&lt;br /&gt;
ORDER BY Wikis DESC,Blogs DESC, Forums DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course wiki usage/activity over the last 6 semesters===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &amp;quot;Courses with Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester A%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester A&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester B%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester B&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed WIKI activity (per wiki per course)===&lt;br /&gt;
Including Number of Students in course (for reference)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID  &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id ) AS Students&lt;br /&gt;
,m.name&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%updat%&#039; ) as &#039;UPDAT E&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%annotate%&#039; ) as ANNOTATE&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%comment%&#039; ) as COMMENT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%add%&#039; ) as &#039;A DD&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%edit%&#039; ) as EDIT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action NOT LIKE &#039;%view%&#039; ) as &#039;All (NO View)&#039;&lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
GROUP BY cm.course,cm.module&lt;br /&gt;
ORDER BY &#039;All (NO View)&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wiki usage, system wide===&lt;br /&gt;
(you can filter the output by selecting some specific course categories : &amp;quot;WHERE c.category IN ( 8,13,15)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039;) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%add%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ADD&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%edit%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;EDIT&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%annotate%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ANNOTATE&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%comments%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;Comments&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_ouwiki_pages as ouwp&lt;br /&gt;
JOIN prefix_ouwiki as ouw ON ouw.id = ouwp.subwikiid&lt;br /&gt;
WHERE ouw.course = c.id GROUP BY ouw.course  ) as OUWikiPages&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( DISTINCT nwp.pagename ) FROM prefix_wiki_pages AS nwp&lt;br /&gt;
JOIN prefix_wiki AS nw ON nw.id = nwp.dfwiki WHERE nw.course = c.id ) As NWikiPages&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Wikis &amp;gt; 0&lt;br /&gt;
ORDER BY &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Aggregated Teacher activity by &amp;quot;WEB2&amp;quot; Modules===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
The NV column shows activity without VIEW log activity&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.userid, u.firstname,u.lastname&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039;) AS Wiki&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Wiki_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039;) AS Forum&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Forum_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039;) AS Blog&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Blog_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039;) AS Assignment&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Assignment_NV&lt;br /&gt;
FROM prefix_role_assignments AS ra &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
WHERE ra.roleid = 3 &lt;br /&gt;
GROUP BY ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the certificates issued, sort by variables in the custom profile fields===&lt;br /&gt;
Note: The SQL queries look intimidating at first, but isn&#039;t really that difficult to learn. I&#039;ve seen in the forums that users wanted to do &#039;site-wide&#039; groups in 1.9x. This is sort of the idea. It pulls all the certificates issued to all users sorted by the custom profile fields, which in my case is the Units or Depts (i.e. my site wide groups). Why certificates? I&#039;ve explored with both grades and quizzes, the course admins are not really interested in the actual grades but whether the learner received a certificate (i.e. passed the course with x, y, z activities). It also saves me from creating groups and assigning them into the right groups. Even assigning in bulk is not efficient, since I have upward of 25 groups per course and constantly new learners enrolling in courses. The limitation is something to do with the server? as it only pull 5000 rows of data. If anyone figured out how to change this, please let me know. In the meantime, the work around is to pull only a few units/depts at a time to limit the number of rows. This is fine at the moment, since each course admin are only responsible for certain units/depts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(prefix_certificate_issues.timecreated), &#039;%Y-%m-%d&#039; ) AS Date,&lt;br /&gt;
prefix_certificate_issues.classname AS Topic,&lt;br /&gt;
prefix_certificate.name AS Certificate,&lt;br /&gt;
prefix_certificate_issues.studentname as Name,&lt;br /&gt;
prefix_user_info_data.data AS Units&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_certificate_issues&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_user_info_data&lt;br /&gt;
on prefix_certificate_issues.userid = prefix_user_info_data.userid&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_certificate&lt;br /&gt;
on prefix_certificate_issues.certificateid = prefix_certificate.id&lt;br /&gt;
&lt;br /&gt;
WHERE prefix_user_info_data.data=&#039;Unit 1&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 2&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 3&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY Units, Name, Topic ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== All Simple Certificates Earned in the Site===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 [http://www.mysqltutorial.org/mysql-date_format/ DATE_FORMAT] function.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
CONCAT (u.firstname, &#039; &#039;,u.lastname) As &#039;User&#039;,&lt;br /&gt;
c.fullname AS &#039;Course&#039;,&lt;br /&gt;
sc.name AS &#039;Certificate&#039;,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(sci.timecreated), &#039;%Y-%m-%d&#039; ) As &#039;Date Awarded&#039;&lt;br /&gt;
# sci.code &#039;CertificateId&#039;&lt;br /&gt;
FROM prefix_simplecertificate_issues sci&lt;br /&gt;
JOIN prefix_user u ON sci.userid = u.id&lt;br /&gt;
JOIN prefix_simplecertificate sc ON sci.certificateid = sc.id&lt;br /&gt;
JOIN prefix_course AS c ON sc.course = c.id&lt;br /&gt;
ORDER BY sci.timecreated DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE DATEDIFF(NOW(),FROM_UNIXTIME(sci.timecreated) ) &amp;lt; 30&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Counter Blog usage in Courses,system wide===&lt;br /&gt;
What teachers in what courses, uses blogs and how many + student count in that course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT ( @counter := @counter+1) as counter, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c, (SELECT @counter := 0) as s_init&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Blogs &amp;gt; 0&lt;br /&gt;
ORDER BY Blogs DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Elluminate (Blackboard Collaborate) - system wide usage===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT e.name As Session ,er.recordingsize&lt;br /&gt;
,c.fullname As Course&lt;br /&gt;
,u.firstname,u.lastname &lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(e.timestart),&#039;%d-%m-%Y&#039;) AS dTimeStart&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/moodle/mod/elluminate/loadrecording.php?id=&#039;,er.id,&#039;&amp;quot;&amp;gt;Show&amp;lt;/a&amp;gt;&#039;) AS RecordedSession&lt;br /&gt;
&lt;br /&gt;
FROM prefix_elluminate_recordings AS er&lt;br /&gt;
JOIN prefix_elluminate AS e ON e.meetingid = er.meetingid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = e.creator &lt;br /&gt;
ORDER BY er.recordingsize DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choice ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Results of the Choice activity. For all courses, shows course shortname, username, the Choice text, and the answer chosen by the user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname AS course, u.username, h.name as question, o.text AS answer&lt;br /&gt;
FROM prefix_choice AS h&lt;br /&gt;
JOIN prefix_course AS c ON h.course = c.id&lt;br /&gt;
JOIN prefix_choice_answers AS a ON h.id = a.choiceid&lt;br /&gt;
JOIN prefix_user AS u ON a.userid = u.id&lt;br /&gt;
JOIN prefix_choice_options AS o ON a.optionid = o.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment type usage in courses ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assign/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_assign WHERE c.id = course) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;file&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
#GROUP BY apc.plugin&lt;br /&gt;
) AS &amp;quot;File Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;onlinetext&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Online Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;pdf&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;PDF Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;offline&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Offline Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;comments&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Assignments Comments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_assign AS assign&lt;br /&gt;
JOIN prefix_course AS c ON c.id = assign.course&lt;br /&gt;
GROUP BY c.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moodle Learning Analytics Reports==&lt;br /&gt;
&lt;br /&gt;
===Average Cognitive Depth and Social Breadth===&lt;br /&gt;
&lt;br /&gt;
Here is a simple SQL snippet to calculate average cognitive depth and social breadth indicators for all students in the system. This one ignores  indicator values of 0, as they are nulls as defined in this model.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
i.contextid,&lt;br /&gt;
i.sampleid,&lt;br /&gt;
&lt;br /&gt;
TRUNC(AVG(CASE&lt;br /&gt;
WHEN i.indicator LIKE &#039;%cognitive%&#039; THEN i.value &lt;br /&gt;
ELSE &#039;0&#039;&lt;br /&gt;
END),2) AS &amp;quot;Average Cognitive Depth&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
TRUNC(AVG(CASE&lt;br /&gt;
WHEN i.indicator LIKE &#039;%social%&#039; THEN i.value &lt;br /&gt;
ELSE &#039;0&#039;&lt;br /&gt;
END),2) AS &amp;quot;Average Social Breadth&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_indicator_calc as i&lt;br /&gt;
WHERE&lt;br /&gt;
i.value != 0&lt;br /&gt;
GROUP BY i.contextid, i.sampleid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Assignment Module Reports==&lt;br /&gt;
===All Ungraded Assignments===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
Returns all the submitted assignments that still need grading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id&lt;br /&gt;
and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Ungraded Assignments w/ Link===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;a href=&amp;quot;http://education.varonis.com/mod/assignment/submissions.php&#039; + char(63) +&lt;br /&gt;
+ &#039;id=&#039; + cast(cm.id as varchar) + &#039;&amp;amp;userid=&#039; + cast(u.id as varchar) &lt;br /&gt;
+ &#039;&amp;amp;mode=single&amp;amp;filter=0&amp;amp;offset=2&amp;quot;&amp;gt;&#039; + a.name + &#039;&amp;lt;/a&amp;gt;&#039;&lt;br /&gt;
AS &amp;quot;Assignmentlink&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments (and Quizzes) waiting to be graded===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This report requires a YEAR filter to be added (Available when using the latest block/configurable_reports)&lt;br /&gt;
&lt;br /&gt;
Which you can always remove, to make this query work on earlier versions.&lt;br /&gt;
&lt;br /&gt;
The report includes: &lt;br /&gt;
*number of quizzes&lt;br /&gt;
*unFinished Quiz attempts&lt;br /&gt;
*Finished Quiz attempts&lt;br /&gt;
*number of students&lt;br /&gt;
*number of Assignments&lt;br /&gt;
*number of submitted answers by students &lt;br /&gt;
*number of unchecked assignments (waiting for the Teacher) in a Course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
 &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assignment/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;מטלות&amp;lt;/a&amp;gt;&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;בחנים&amp;lt;/a&amp;gt;&#039;) AS &#039;Quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_course_modules cm &lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module &lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039; AND cm.course = c.id &lt;br /&gt;
GROUP BY cm.course &lt;br /&gt;
) AS &#039;nQuizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish = 0&lt;br /&gt;
GROUP BY q.course) AS &#039;unFinished Quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish &amp;gt; 0&lt;br /&gt;
GROUP BY q.course) AS &#039;finished quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS nStudents&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(a.id)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) nAssignments&lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE a.course = c.id AND FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course&lt;br /&gt;
) &#039;Open &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(ROUND( (100 / iAssignments ) * iOpenAssignments ) ,&#039;%&#039;) &#039;unFinished &amp;lt;br/&amp;gt;Assignments &amp;lt;br/&amp;gt;(percent)&#039;&lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE asb.grade &amp;lt; 0 AND cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;unChecked  &amp;lt;br/&amp;gt;Submissions&#039; &lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;Submitted  &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblAssignmentsCount ON tblAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iOpenAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblOpenAssignmentsCount ON tblOpenAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1  &lt;br /&gt;
#AND c.fullname LIKE &#039;%תשעג%&#039;&lt;br /&gt;
%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
ORDER BY &#039;Open &amp;lt;br/&amp;gt;Assignments&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rubrics without zero values in criteria===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
Rubric calculations in Moodle can fail to align with instructors expectations if they lack a zero value for each criterion used in the assessment. From documentation at https://docs.moodle.org/32/en/Rubrics#Grade_calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;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.&lt;br /&gt;
TIP: To avoid confusion from this sort of thing, we recommend including a level with 0 points in every rubric criterion.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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&#039; favor.&lt;br /&gt;
&lt;br /&gt;
Includes search filter of course idnumber.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cat.name AS Department, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, &lt;br /&gt;
c.fullname AS Course_Name, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/grading/form/rubric/edit.php&#039;,CHAR(63),&#039;areaid=&#039;,gd.areaid,&#039;&amp;quot;&amp;gt;&#039;,gd.areaid,&#039;&amp;lt;/a&amp;gt;&#039;) AS Rubric&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_categories AS cat &lt;br /&gt;
ON cat.id = c.category&lt;br /&gt;
JOIN prefix_course_modules AS cm &lt;br /&gt;
ON c.id=cm.course&lt;br /&gt;
JOIN prefix_context AS ctx &lt;br /&gt;
ON cm.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_grading_areas AS garea &lt;br /&gt;
ON ctx.id = garea.contextid&lt;br /&gt;
JOIN prefix_grading_definitions AS gd &lt;br /&gt;
ON garea.id = gd.areaid&lt;br /&gt;
JOIN prefix_gradingform_rubric_criteria AS crit &lt;br /&gt;
ON gd.id = crit.definitionid&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id&lt;br /&gt;
WHERE cm.visible=&#039;1&#039; AND garea.activemethod = &#039;rubric&#039; AND (crit.id NOT IN&lt;br /&gt;
(SELECT crit.id&lt;br /&gt;
FROM prefix_gradingform_rubric_criteria AS crit&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id WHERE levels.score = &#039;0&#039;))&lt;br /&gt;
&lt;br /&gt;
GROUP BY Rubric&lt;br /&gt;
ORDER BY Course_ID, Rubric&lt;br /&gt;
&lt;br /&gt;
%%FILTER_SEARCHTEXT:c.idnumber:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Who is using &amp;quot;Single File Upload&amp;quot; assignment===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,ass.name as &amp;quot;Assignment Name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM &lt;br /&gt;
prefix_assignment as ass&lt;br /&gt;
&lt;br /&gt;
JOIN &lt;br /&gt;
prefix_course as c ON c.id = ass.course&lt;br /&gt;
&lt;br /&gt;
WHERE `assignmenttype` LIKE &#039;uploadsingle&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Feedback Module Reports==&lt;br /&gt;
===List the answers to all the Feedback activities within the current course, submitted by the current user===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT /* crs.fullname as &amp;quot;Course name&amp;quot;, f.name AS &amp;quot;Journal name&amp;quot;, CONCAT(u.firstname,&#039; &#039;,UPPER(u.lastname)) as &amp;quot;Participant&amp;quot;, */ /* include these fields if you want to check the composition of the recordset */&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified),&#039;%W %e %M, %Y&#039;) as &amp;quot;Answer Date&amp;quot;,&lt;br /&gt;
CASE i.typ WHEN &#039;label&#039; THEN i.presentation ELSE i.name END as &amp;quot;Topic&amp;quot;,  /* usually labels are used as section titles, so you&#039;d want them present in the recordset */&lt;br /&gt;
v.value as &amp;quot;My Answer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback AS f&lt;br /&gt;
INNER JOIN prefix_course as crs on crs.id=f.course %%FILTER_COURSES:f.course%% &lt;br /&gt;
INNER JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
INNER JOIN prefix_feedback_completed AS c on f.id=c.feedback %%FILTER_COURSEUSER:c.userid%% &lt;br /&gt;
LEFT JOIN prefix_feedback_value AS v on v.completed=c.id AND v.item=i.id&lt;br /&gt;
INNER JOIN prefix_user AS u on c.userid=u.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%% AND u.id = %%USERID%%  AND c.anonymous_response = 1  /* This clause limits the recordset to the current course and the current user and includes/ excludes the anonymous responses as needed */&lt;br /&gt;
&lt;br /&gt;
ORDER BY f.id, c.timemodified, i.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show all Feedbacks from all courses for all users including showing names of anonymous users===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &#039;Not-logged-in&#039; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS Course, &lt;br /&gt;
f.name AS Feedback,&lt;br /&gt;
# i.id AS Itemid,&lt;br /&gt;
i.name AS Itemname,&lt;br /&gt;
i.label AS Itemlabel,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN f.anonymous = 1 AND u.id != 0 THEN CONCAT(u.username, &#039; :ANON&#039;)&lt;br /&gt;
 WHEN fc.userid = 0 THEN &#039;Not-logged-in&#039;&lt;br /&gt;
 ELSE u.username&lt;br /&gt;
END AS &#039;User&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(fc.timemodified),&#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;Completed&amp;quot;,&lt;br /&gt;
v.value AS &amp;quot;Choice&amp;quot;,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN i.typ = &#039;multichoice&#039; THEN&lt;br /&gt;
     IF (  SUBSTRING(i.presentation,1,6)=&#039;d&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&#039;,&lt;br /&gt;
	       SUBSTRING(i.presentation,7),&lt;br /&gt;
		   i.presentation)&lt;br /&gt;
 ELSE i.presentation&lt;br /&gt;
END AS &amp;quot;Answers&amp;quot;,&lt;br /&gt;
i.typ,&lt;br /&gt;
i.dependitem,&lt;br /&gt;
i.dependvalue&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback f&lt;br /&gt;
JOIN prefix_course c ON c.id=f.course &lt;br /&gt;
JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
JOIN prefix_feedback_completed fc ON f.id=fc.feedback&lt;br /&gt;
LEFT JOIN prefix_feedback_value v ON v.completed=fc.id AND v.item=i.id&lt;br /&gt;
LEFT JOIN prefix_user AS u ON fc.userid=u.id&lt;br /&gt;
WHERE i.typ != &#039;pagebreak&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Resource Module Reports==&lt;br /&gt;
===List &amp;quot;Recently uploaded files&amp;quot;===&lt;br /&gt;
see what users are uploading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT FROM_UNIXTIME(time,&#039;%Y %M %D %h:%i:%s&#039;) as time ,ip,userid,url,info  &lt;br /&gt;
FROM `prefix_log` &lt;br /&gt;
WHERE `action` LIKE &#039;upload&#039; &lt;br /&gt;
ORDER BY `prefix_log`.`time`  DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Courses that loaded a specific file: &amp;quot;X&amp;quot;===&lt;br /&gt;
Did the Teacher (probably) uploaded course&#039;s Syllabus ?&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname  FROM `prefix_log` as l &lt;br /&gt;
JOIN prefix_course as c ON c.id = l.course &lt;br /&gt;
WHERE `action` LIKE &#039;%upload%&#039; AND ( info LIKE &#039;%Syllabus%&#039; OR info LIKE &#039;%Sylabus%&#039; ) GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All resources that link to some specific external website===&lt;br /&gt;
+ link to course&lt;br /&gt;
+ who&#039;s the teacher&lt;br /&gt;
+ link to external resource&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/resource/view.php?id=&#039;,r.id,&#039;&amp;quot;&amp;gt;&#039;,r.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Resource&lt;br /&gt;
FROM prefix_resource AS r &lt;br /&gt;
JOIN prefix_course AS c ON r.course = c.id&lt;br /&gt;
WHERE r.reference LIKE &#039;http://info.oranim.ac.il/home%&#039; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;quot;Compose Web Page&amp;quot; RESOURCE count===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT course,prefix_course.fullname, COUNT(*) AS Total&lt;br /&gt;
FROM `prefix_resource`&lt;br /&gt;
JOIN `prefix_course` ON prefix_course.id = prefix_resource.course&lt;br /&gt;
WHERE type=&#039;html&#039;&lt;br /&gt;
GROUP BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resource count in courses===&lt;br /&gt;
+ (First)Teacher name&lt;br /&gt;
+ Where course is inside some specific Categories&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
COUNT(*) AS count&lt;br /&gt;
,r.course &lt;br /&gt;
,c.shortname shortname&lt;br /&gt;
,c.fullname coursename&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user as u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = r.course AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
FROM prefix_resource r &lt;br /&gt;
JOIN prefix_course c ON r.course = c.id&lt;br /&gt;
WHERE c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY r.course&lt;br /&gt;
ORDER BY COUNT(*) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Delete all the automated backup files===&lt;br /&gt;
Prepare bash cli script to delete all the automated backup files on the file system. (clean up some disk space)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT( &#039;rm -f /var/moodledatanew/filedir/&#039;, SUBSTRING( contenthash, 1, 2 ) , &#039;/&#039;, SUBSTRING( contenthash, 3, 2 ) , &#039;/&#039;, contenthash ) &lt;br /&gt;
FROM `mdl_files` &lt;br /&gt;
WHERE `filename` LIKE &#039;%mbz%&#039;&lt;br /&gt;
AND filearea = &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find out how much disk space is used by all automated backup files:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT SUM(filesize)/(1024*1024*1024) FROM `mdl_files` WHERE  `filename` LIKE &#039;%mbz%&#039; AND filearea =  &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Forum Module Reports==&lt;br /&gt;
===print all User&#039;s post in course Forums===&lt;br /&gt;
%%COURSEID%% is a variable the is replace by the current CourseID you are running the sql report from. if you are using the latest block/configurable_reports ! (You can always change it to a fixed course or remove it to display all courses.)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php?course=&#039;,c.id,&#039;&amp;amp;id=&#039;,u.id,&#039;&amp;amp;mode=posts&amp;quot;&amp;gt;&#039;,CONCAT(u.firstname,&#039; &#039;, u.lastname),&#039;&amp;lt;/a&amp;gt;&#039;) As Fullname&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Forum&lt;br /&gt;
,count(*) as Posts&lt;br /&gt;
,(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&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_user as u ON u.id = fp.userid &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = fd.course &lt;br /&gt;
WHERE fd.course = %%COURSEID%% &lt;br /&gt;
GROUP BY f.id,u.id&lt;br /&gt;
ORDER BY u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE by type -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, prefix_forum.type, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course,prefix_forum.type&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Forum activity - system wide===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,c.fullname as Course&lt;br /&gt;
,f.type&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
, fd.forum, f.name,count(*) AS cPostAndDisc&lt;br /&gt;
,(SELECT count(*) FROM prefix_forum_discussions AS ifd WHERE ifd.forum = f.id) AS cDiscussion&lt;br /&gt;
FROM prefix_forum_posts AS fp&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type != &#039;news&#039; AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
## WHERE 1=1 &lt;br /&gt;
## %%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count( * ) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Activity In Forums===&lt;br /&gt;
Trying to figure out how much real activity we have in Forums by aggregating:&lt;br /&gt;
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...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname,f.name,f.type &lt;br /&gt;
,(SELECT count(id) FROM prefix_forum_discussions as fd WHERE f.id = fd.forum) as Discussions&lt;br /&gt;
,(SELECT count(distinct fd.userid) FROM prefix_forum_discussions as fd WHERE fd.forum = f.id) as UniqueUsersDiscussions&lt;br /&gt;
,(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&lt;br /&gt;
,(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&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS StudentsCount&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Teachers&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS &#039;Teacher&amp;lt;br/&amp;gt;Count&#039;&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid IN (3,5)&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS UserCount&lt;br /&gt;
, (SELECT (UniqueUsersDiscussions / StudentsCount )) as StudentDissUsage&lt;br /&gt;
, (SELECT (UniqueUsersPosts /StudentsCount)) as StudentPostUsage&lt;br /&gt;
FROM prefix_forum as f &lt;br /&gt;
JOIN prefix_course as c ON f.course = c.id&lt;br /&gt;
WHERE `type` != &#039;news&#039;&lt;br /&gt;
ORDER BY StudentPostUsage DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Forum type:NEWS===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT f.id, f.name&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
WHERE m.name = &#039;forum&#039;&lt;br /&gt;
AND f.type = &#039;news&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All new forum NEWS items (discussions) from all my Courses===&lt;br /&gt;
change &amp;quot;userid = 26&amp;quot; and &amp;quot;id = 26&amp;quot; to a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname,f.name,fd.name,FROM_UNIXTIME(fd.timemodified ,&amp;quot;%d %M %Y &amp;quot;) as Date&lt;br /&gt;
FROM prefix_forum_discussions as fd &lt;br /&gt;
JOIN prefix_forum as f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = f.course &lt;br /&gt;
JOIN prefix_user_lastaccess as ul ON (c.id = ul.courseid AND ul.userid = 26)&lt;br /&gt;
WHERE fd.timemodified &amp;gt; ul.timeaccess  &lt;br /&gt;
 AND fd.forum IN (SELECT f.id&lt;br /&gt;
 FROM prefix_course_modules AS cm&lt;br /&gt;
 JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
 JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
 WHERE m.name = &#039;forum&#039;&lt;br /&gt;
 AND f.type = &#039;news&#039;)&lt;br /&gt;
  AND c.id IN (SELECT c.id&lt;br /&gt;
   FROM prefix_course AS c&lt;br /&gt;
   JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
   JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
   JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
   WHERE u.id = 26) ORDER BY `fd`.`timemodified` DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===News Forum - Discussions COUNT===&lt;br /&gt;
Which is actually... How much instructions students get from their teachers&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname ,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,count(fd.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS DiscussionsSum&lt;br /&gt;
FROM prefix_forum_discussions AS fd&lt;br /&gt;
INNER JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
INNER JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type = &#039;news&#039; AND c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count(fd.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cantidad de foros que han sido posteados por profesor===&lt;br /&gt;
&lt;br /&gt;
(Number of forums that have been posted by teacher/Google translator)&lt;br /&gt;
&lt;br /&gt;
Queriamos saber cuales son las acciones del profesor dentro de los foros de cada curso, por ello se hizo este informe.&lt;br /&gt;
&lt;br /&gt;
(We wanted to know what the teacher&#039;s actions are in the forums of each course, so this report was made. /Google translator)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS curso,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Facilitador,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( m.name ) AS COUNT FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS foros,&lt;br /&gt;
&lt;br /&gt;
COUNT(*) AS Posts&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course AS c ON c.id = fd.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = fp.userid &lt;br /&gt;
&lt;br /&gt;
WHERE fp.userid =&lt;br /&gt;
(&lt;br /&gt;
select distinct prefix_user.id&lt;br /&gt;
from prefix_user &lt;br /&gt;
join prefix_role_assignments as ra on ra.userid = prefix_user.id &lt;br /&gt;
where ra.roleid = 3 &lt;br /&gt;
and userid = fp.userid&lt;br /&gt;
limit 1&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
and c.shortname like &#039;%2014-2-1%&#039;&lt;br /&gt;
GROUP BY c.id, u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all the Forums that got high rating===&lt;br /&gt;
We setup a scale that let teachers and students Rate forum post with &amp;quot;Important, interesting, valuable, not rated&amp;quot; scale&lt;br /&gt;
And then add a link to the following report at the begining of the course &amp;quot;Link to all interesting posts&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,f.id,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;,fd.id,&#039;#p&#039;,fp.id,&#039;&amp;quot;&amp;gt;&#039;,fp.subject,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post link&#039;,&lt;br /&gt;
SUM(r.rating) AS &#039;Rating&#039;&lt;br /&gt;
FROM mdl_rating AS r&lt;br /&gt;
  JOIN mdl_forum_posts AS fp ON fp.id = r.itemid&lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
WHERE r.component = &#039;mod_forum&#039; AND r.ratingarea = &#039;post&#039; AND f.course = %%COURSEID%%&lt;br /&gt;
GROUP BY r.itemid&lt;br /&gt;
ORDER BY SUM(r.rating) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all Discussions of a single Forum===&lt;br /&gt;
This report is used to help export all the student&#039;s posts and discussions of a single forum, by passing the context module id as a parameter to the report using &amp;quot;&amp;amp;filter_var=cmid&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;, f.id, &#039;&amp;quot;&amp;gt;&#039;, f.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name&#039;,&lt;br /&gt;
fd.name AS &#039;Discussion&#039;, &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;, fd.id, &#039;#p&#039;, fp.id, &#039;&amp;quot;&amp;gt;&#039;, fp.subject, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post (link)&#039;,&lt;br /&gt;
fp.message&lt;br /&gt;
&lt;br /&gt;
FROM mdl_forum_posts AS fp &lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
  JOIN mdl_course_modules AS cm ON cm.module = 9 AND cm.instance = f.id&lt;br /&gt;
WHERE cm.id = %%FILTER_VAR%%&lt;br /&gt;
ORDER BY f.id, fd.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Quiz Module Reports==&lt;br /&gt;
===Generate a list of instructors and their email addresses for those courses that has &amp;quot;essay questions&amp;quot; in their quizzes===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT qu.id AS quiz_id, qu.course AS course_id, qu.questions,&lt;br /&gt;
                co.fullname AS course_fullname, co.shortname AS course_shortname,&lt;br /&gt;
                qu.name AS quiz_name, FROM_UNIXTIME(qu.timeopen) AS quiz_timeopen, FROM_UNIXTIME(qu.timeclose) AS quiz_timeclose,&lt;br /&gt;
                u.firstname, u.lastname, u.email,&lt;br /&gt;
FROM prefix_quiz qu, prefix_course co, prefix_role re, prefix_context ct, prefix_role_assignments ra, prefix_user u&lt;br /&gt;
WHERE FROM_UNIXTIME(timeopen) &amp;gt; &#039;2008-05-14&#039; AND&lt;br /&gt;
                qu.course = co.id AND&lt;br /&gt;
                co.id = ct.instanceid AND&lt;br /&gt;
                ra.roleid = re.id AND&lt;br /&gt;
                re.name = &#039;Teacher&#039; AND&lt;br /&gt;
                ra.contextid = ct.id AND&lt;br /&gt;
                ra.userid = u.id&lt;br /&gt;
 &lt;br /&gt;
SELECT Count(&#039;x&#039;) As NumOfStudents&lt;br /&gt;
                                FROM prefix_role_assignments a&lt;br /&gt;
                                JOIN prefix_user u ON userid = u.id&lt;br /&gt;
                                WHERE roleid = 5 AND contextid = (SELECT id FROM prefix_context WHERE instanceid = 668 AND contextlevel = 50)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Number of Quizes per Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Link&amp;lt;/a&amp;gt;&#039;) AS Quizes&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules cm&lt;br /&gt;
JOIN prefix_course c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module&lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039;&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all MultiAnswer (Cloze) Questions===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/attempt.php?q=&#039;, quiz.id, &#039;&amp;quot;&amp;gt;&#039;, quiz.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS Quiz&lt;br /&gt;
,question.id question_id, question.questiontext &lt;br /&gt;
FROM  prefix_question question&lt;br /&gt;
JOIN prefix_quiz_question_instances qqi ON question.id = qqi.question&lt;br /&gt;
JOIN prefix_quiz quiz ON qqi.quiz = quiz.id&lt;br /&gt;
WHERE  `qtype` LIKE  &#039;multianswer&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List courses with MANUAL grades===&lt;br /&gt;
Which is basically and indication to teachers using Moodle to hold offline grades inside Moodle&#039;s Gradebook,&lt;br /&gt;
So grades could be uploaded into an administrative SIS. Use with Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT( * )&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php?showadvanced=1&amp;amp;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM  prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course as c ON c.id = gi.courseid&lt;br /&gt;
WHERE  `itemtype` =  &#039;manual&#039;&lt;br /&gt;
GROUP BY courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===List the users that did not took the Quiz===&lt;br /&gt;
Do not forget to change &amp;quot;c.id = 14&amp;quot; and q.name LIKE &#039;%quiz name goes here%&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id AS ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.username AS IDNumber,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
 &lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id AND courseid=c.id) AS CourseLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id AND e.courseid = c.id) AS RoleName&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess AS ul ON ul.userid = user2.id&lt;br /&gt;
WHERE c.id=14 and ue.userid NOT IN (SELECT qa.userid FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON qa.quiz = q.id&lt;br /&gt;
JOIN prefix_course AS c ON q.course = c.id&lt;br /&gt;
WHERE c.id = 14 AND q.name LIKE &#039;%quiz name goes here%&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List Questions in each Quiz===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT quiz.id,quiz.name, q.id, q.name&lt;br /&gt;
FROM mdl_quiz AS quiz&lt;br /&gt;
JOIN mdl_question AS q ON FIND_IN_SET(q.id, quiz.questions)&lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
ORDER BY quiz.id ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this query does not work in Moodle 2.8+. There is no mdl_quiz.questions field. It will need to be rewritten to use the usage/contextid organization.&lt;br /&gt;
&lt;br /&gt;
Here is a version for Moodle 3.x&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cm.id &#039;cmid&#039;, quiz.id &#039;quiz id&#039;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/edit.php?cmid=&#039;, &lt;br /&gt;
	   cm.id, &#039;&amp;quot;&amp;gt;&#039;, quiz.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;edit quiz&#039;&lt;br /&gt;
,q.id &#039;qid&#039;, q.name &#039;question name&#039;&lt;br /&gt;
FROM mdl_quiz AS quiz&lt;br /&gt;
JOIN mdl_course_modules cm ON cm.instance = quiz.id AND cm.module = 33 # 33=quiz mdl_modules&lt;br /&gt;
JOIN mdl_quiz_slots qs ON qs.quizid = quiz.id &lt;br /&gt;
JOIN mdl_question AS q ON q.id = qs.questionid&lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
ORDER BY quiz.id ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quiz activity research===&lt;br /&gt;
This report was made to extract student full activity in quizzes for an academic research about adapting instructional design teaching methods in online learning. The students do not use the Quiz module as a standard quiz but more as Study booklets or mini courses with embedded questions and hints to assist students evaluate their progress (Similar to what you expect to find in a SCORM activity)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cm.course &amp;quot;course_id&amp;quot;, cm.id &amp;quot;moduel_id&amp;quot;, q.id &amp;quot;quiz_id&amp;quot;, q.name &amp;quot;quiz_name&amp;quot;,&lt;br /&gt;
 &lt;br /&gt;
CASE q.grademethod&lt;br /&gt;
      WHEN 1 THEN &amp;quot;GRADEHIGHEST&amp;quot;&lt;br /&gt;
      WHEN 2 THEN &amp;quot;GRADEAVERAGE&amp;quot;&lt;br /&gt;
      WHEN 3 THEN &amp;quot;ATTEMPTFIRST&amp;quot;&lt;br /&gt;
      WHEN 4 THEN &amp;quot;ATTEMPTLAST&amp;quot;&lt;br /&gt;
END &amp;quot;grade method&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
, q.attempts &amp;quot;quiz_attempts_allowed&amp;quot;, cm.groupmode &amp;quot;group_mode&amp;quot;&lt;br /&gt;
, qa.id &amp;quot;attempt_id&amp;quot;, qa.state &amp;quot;attempt_state&amp;quot;, qa.sumgrades &amp;quot;attempt_grade&amp;quot;, qg.grade &amp;quot;user_final_grade&amp;quot;, q.grade &amp;quot;quiz_max_grade&amp;quot;&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = q.course AND m.userid = u.id) &amp;quot;user_groups&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timestart), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_start&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timefinish), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_finish&amp;quot;,&lt;br /&gt;
u.id &amp;quot;user_id&amp;quot;, u.firstname, u.lastname,&lt;br /&gt;
question.id &amp;quot;question_id&amp;quot;, question.name &amp;quot;question_name&amp;quot;,&lt;br /&gt;
qas.state &amp;quot;question_step_state&amp;quot;,qas.fraction &amp;quot;question_grade&amp;quot;, qh.hint, question.qtype &amp;quot;question_type&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz as q&lt;br /&gt;
JOIN mdl_course_modules as cm ON cm.instance = q.id and cm.module = 14 &lt;br /&gt;
JOIN mdl_quiz_attempts qa ON q.id = qa.quiz&lt;br /&gt;
LEFT JOIN mdl_quiz_grades as qg ON qg.quiz = q.id and qg.userid = qa.userid&lt;br /&gt;
JOIN mdl_user as u ON u.id = qa.userid&lt;br /&gt;
JOIN mdl_question_usages as qu ON qu.id = qa.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts as qatt ON qatt.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question as question ON question.id = qatt.questionid&lt;br /&gt;
JOIN mdl_question_attempt_steps as qas ON qas.questionattemptid = qatt.id&lt;br /&gt;
LEFT JOIN mdl_question_hints as qh ON qh.questionid = q.id&lt;br /&gt;
#WHERE q.id = &amp;quot;SOME QUIZ ID&amp;quot;&lt;br /&gt;
WHERE cm.course = &amp;quot;SOME COURSE ID&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quiz Usage in Courses by Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Multiple Choice&amp;quot; questions include true/false and matching question types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Short Answer&amp;quot; are questions that accept a single phrase.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Other&amp;quot; questions include fixed numerical, calculated, essay, and various drag and drop types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Min Quiz Age&amp;quot; and &amp;quot;Max Quiz Age&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: In Configurable Reports, the Date Filter is not applied until the &amp;quot;Apply&amp;quot; button is clicked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.shortname AS &#039;Course&#039;&lt;br /&gt;
#, u.lastname AS &#039;Instructor&#039;&lt;br /&gt;
, COUNT(DISTINCT q.id) AS &#039;Quizzes&#039;&lt;br /&gt;
, COUNT(DISTINCT qu.id) AS &#039;Questions&#039;&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 ))  AS &#039;multichoice&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT( qu.id) - SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;Other&#039;&lt;br /&gt;
&lt;br /&gt;
, (SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )))/COUNT( qu.id) AS &#039;Percent MC&#039;&lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;numerical&#039;, 1, 0 )) AS &#039;numerical&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype LIKE &#039;calc%&#039;, 1, 0 )) AS &#039;calculated&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;random&#039;, 1, 0 )) AS &#039;random&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;essay&#039;, 1, 0 )) AS &#039;essay&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, IF(q.shufflequestions &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Questions&#039;&lt;br /&gt;
, IF(q.shuffleanswers &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Answers&#039;&lt;br /&gt;
 &lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
#, FROM_UNIXTIME(MIN(q.timemodified)) AS &#039;Last Modified&#039;&lt;br /&gt;
&lt;br /&gt;
#, DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(MIN(q.timemodified))) AS &#039;Quiz age&#039;&lt;br /&gt;
&lt;br /&gt;
, MIN(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Min Quiz Age&#039; &lt;br /&gt;
, MAX(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Max Quiz Age&#039; &lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified)) &amp;lt; 90, 1,0)) AS &#039;new quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_quiz AS q&lt;br /&gt;
JOIN prefix_course AS c on c.id = q.course&lt;br /&gt;
JOIN prefix_quiz_question_instances AS qqi ON qqi.quiz = q.id&lt;br /&gt;
LEFT JOIN prefix_question AS qu ON qu.id = qqi.question&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%% %%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student responses (answers) to quiz questions===&lt;br /&gt;
(Contributed by Juan F with help from Tim hunt and fellow Moodlers on the forums)&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    concat( u.firstname, &amp;quot; &amp;quot;, u.lastname ) AS &amp;quot;Student Name&amp;quot;,&lt;br /&gt;
    u.id,&lt;br /&gt;
    quiza.userid,&lt;br /&gt;
    q.course,&lt;br /&gt;
    q.name,&lt;br /&gt;
    quiza.attempt,&lt;br /&gt;
    qa.slot,&lt;br /&gt;
    que.questiontext AS &#039;Question&#039;,&lt;br /&gt;
    qa.rightanswer AS &#039;Correct Answer&#039;,&lt;br /&gt;
    qa.responsesummary AS &#039;Student Answer&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz_attempts quiza&lt;br /&gt;
JOIN mdl_quiz q ON q.id=quiza.quiz&lt;br /&gt;
JOIN mdl_question_usages qu ON qu.id = quiza.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts qa ON qa.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question que ON que.id = qa.questionid&lt;br /&gt;
JOIN mdl_user u ON u.id = quiza.userid&lt;br /&gt;
&lt;br /&gt;
WHERE q.name = &amp;quot;BIO 208 Post Test Assessment&amp;quot;&lt;br /&gt;
AND q.course = &amp;quot;17926&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ORDER BY quiza.userid, quiza.attempt, qa.slot&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==SCORM Activity Reports==&lt;br /&gt;
&lt;br /&gt;
===Lists All completed SCORM activites by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists SCORM status for all enrolled users by Course name===&lt;br /&gt;
This report will list the SCORM status for all users enrolled in the course. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. This can be limited to individual courses by adding to the where clause the course id to report on.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.firstname AS First,&lt;br /&gt;
u.lastname AS Last, &lt;br /&gt;
u.idnumber AS Employee_ID,  &lt;br /&gt;
u.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
u.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course, &lt;br /&gt;
st.attempt AS Attempt,&lt;br /&gt;
st.value AS Status,&lt;br /&gt;
FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) AS Date &lt;br /&gt;
&lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
&lt;br /&gt;
WHERE st.element=&#039;cmi.core.lesson_status&#039; AND m.userid=u.id&lt;br /&gt;
&lt;br /&gt;
UNION&lt;br /&gt;
&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS First,&lt;br /&gt;
user2.lastname AS Last,&lt;br /&gt;
user2. idnumber AS Employee_ID,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
user2.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Attempt,&lt;br /&gt;
&amp;quot;not_started&amp;quot; AS Status,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Date&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = user2.id &lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.course=c.id&lt;br /&gt;
Left Join prefix_scorm_scoes_track AS st on st.scormid=sc.id AND st.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
WHERE  st.timemodified IS NULL AND m.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY  Course, Last, First, Attempt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Badges==&lt;br /&gt;
&lt;br /&gt;
=== All badges issued, by User ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, b.name AS badgename, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN&lt;br /&gt;
(SELECT c.shortname&lt;br /&gt;
    FROM prefix_course AS c&lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Context,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 1 THEN &amp;quot;Activity Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 2 THEN &amp;quot;Activity Completion (Any)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 2 AND t.method = 2 THEN &amp;quot;Manual Award&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 1 THEN &amp;quot;Course Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 2 THEN &amp;quot;Course Completion (Any)&amp;quot;&lt;br /&gt;
  ELSE CONCAT (&#039;Other: &#039;, t.criteriatype)&lt;br /&gt;
END AS Criteriatype,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateissued ) , &#039;%Y-%m-%d&#039; ) AS dateissued,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateexpire ), &#039;%Y-%m-%d&#039; ) AS dateexpires,&lt;br /&gt;
CONCAT (&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/badge.php?hash=&#039;,d.uniquehash,&#039;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&#039;) AS Details&lt;br /&gt;
FROM prefix_badge_issued AS d &lt;br /&gt;
JOIN prefix_badge AS b ON d.badgeid = b.id&lt;br /&gt;
JOIN prefix_user AS u ON d.userid = u.id&lt;br /&gt;
JOIN prefix_badge_criteria AS t on b.id = t.badgeid &lt;br /&gt;
WHERE t.criteriatype &amp;lt;&amp;gt; 0&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&lt;br /&gt;
=== All badges available in the system, with Earned count ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.type = 1 THEN &amp;quot;System&amp;quot;&lt;br /&gt;
WHEN b.type = 2 THEN &amp;quot;Course&amp;quot;&lt;br /&gt;
END AS Context, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN &lt;br /&gt;
(SELECT c.shortname &lt;br /&gt;
    FROM prefix_course AS c &lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 2 THEN &amp;quot;No&amp;quot;&lt;br /&gt;
WHEN b.status = 1 OR b.status = 3 THEN &amp;quot;Yes&amp;quot;&lt;br /&gt;
WHEN b.status = 4 THEN &amp;quot;x&amp;quot;&lt;br /&gt;
END AS Available,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 1 THEN &amp;quot;0&amp;quot;&lt;br /&gt;
WHEN b.status = 2 OR b.status = 3 OR b.status = 4 THEN &lt;br /&gt;
 (SELECT COUNT(*) &lt;br /&gt;
   FROM prefix_badge_issued AS d&lt;br /&gt;
   WHERE d.badgeid = b.id&lt;br /&gt;
 )&lt;br /&gt;
END AS Earned&lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Badges Leaderboard ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A simple list of usernames and how many badges they have earned overall.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, (SELECT COUNT(*) FROM prefix_badge_issued AS d WHERE d.userid = u.id) AS earned&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
ORDER BY earned DESC, u.username ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Manage badges (System &amp;amp; Course) ===&lt;br /&gt;
&lt;br /&gt;
List system wide badges, course and system level badges + a link to relevant &amp;quot;manage badges&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description &lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN b.type = 1 THEN &#039;System&#039;&lt;br /&gt;
  WHEN b.type = 2 THEN &#039;Course&#039;&lt;br /&gt;
END AS Level&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/index.php?type=&#039;, b.type, &#039;&amp;amp;id=&#039;,&lt;br /&gt;
			  c.id, &#039;&amp;quot;&amp;gt;Manage badges in: &#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Manage &lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Administrator Reports==&lt;br /&gt;
&lt;br /&gt;
===Config changes in Export friendly form===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( g.timemodified ) , &#039;%Y-%m-%d&#039; ) AS date, &lt;br /&gt;
u.username AS user, &lt;br /&gt;
g.name AS setting, &lt;br /&gt;
CASE &lt;br /&gt;
 WHEN g.plugin IS NULL THEN &amp;quot;core&amp;quot;&lt;br /&gt;
 ELSE g.plugin&lt;br /&gt;
END AS plugin, &lt;br /&gt;
g.value AS new_value, &lt;br /&gt;
g.oldvalue AS original_value&lt;br /&gt;
FROM prefix_config_log  AS g&lt;br /&gt;
JOIN prefix_user AS u ON g.userid = u.id&lt;br /&gt;
ORDER BY date DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts by user===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
How to get a list of all users and which cohorts they belong to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, h.idnumber, h.name&lt;br /&gt;
FROM prefix_cohort AS h&lt;br /&gt;
JOIN prefix_cohort_members AS hm ON h.id = hm.cohortid&lt;br /&gt;
JOIN prefix_user AS u ON hm.userid = u.id&lt;br /&gt;
ORDER BY u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts with Courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all cohorts with name, id, visibility, and which courses they are enrolled in.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
# h.id,&lt;br /&gt;
# e.customint1,&lt;br /&gt;
h.name AS Cohort,&lt;br /&gt;
h.idnumber AS Cohortid,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN h.visible = 1 THEN &#039;Yes&#039;&lt;br /&gt;
 ELSE &#039;-&#039;&lt;br /&gt;
END AS Cohortvisible,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;, CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_cohort h&lt;br /&gt;
JOIN prefix_enrol e ON h.id = e.customint1&lt;br /&gt;
JOIN prefix_course c ON c.id = e.courseid %%FILTER_COURSES:e.courseid%% &lt;br /&gt;
WHERE e.enrol = &#039;cohort&#039; AND e.roleid = 5&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses created And Active courses by Year===&lt;br /&gt;
Active courses is counting course that have at least one Hit, And &amp;quot;Active_MoreThan100Hits&amp;quot; counts courses that have at least 100 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `timecreated` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT course ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY course &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 100) AS courses_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( courses_log.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan100Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_course` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users created And Active users by Year===&lt;br /&gt;
Active users is counting users that have at least one Hit, And &amp;quot;Active_MoreThan500Hits&amp;quot; counts users that have at least 500 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `firstaccess` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT userid ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY userid &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 500) AS users_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( users_log.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan500Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Aggregation Report===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In particular, be on the lookout for any courses with the following combinations of parameters, which are known to cause changes in calculations:&lt;br /&gt;
&lt;br /&gt;
# mean of grades set with aggregate with subcategory.&lt;br /&gt;
# Simple weighted mean of grades with aggregate with sub category and drop the lowest&lt;br /&gt;
# Sum of grades drop the lowest&lt;br /&gt;
&lt;br /&gt;
Also review:&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48618&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48634&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-49257&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50089&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50062&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
COUNT(c.shortname) AS &#039;Count of Courses&#039;&lt;br /&gt;
&lt;br /&gt;
# If you want to display all the courses for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, c.shortname AS &#039;course name&#039;&lt;br /&gt;
&lt;br /&gt;
# If you need to display grade categories for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, gc.fullname AS &#039;grade category name&#039;&lt;br /&gt;
&lt;br /&gt;
, gc.aggregation AS &#039;aggregation method&#039;&lt;br /&gt;
&lt;br /&gt;
#These aggregation text strings appear to be hard-coded. I couldn&#039;t find a table for them. If you have aggregation types I haven&#039;t included here, they&#039;ll be blank in your report results.&lt;br /&gt;
, CASE gc.aggregation&lt;br /&gt;
  WHEN 0 THEN &#039;Mean of Grades&#039;&lt;br /&gt;
  WHEN 2 THEN &#039;Median of Grades&#039;&lt;br /&gt;
  WHEN 6 THEN &#039;Highest Grade&#039;&lt;br /&gt;
  WHEN 8 THEN &#039;Mode of Grades&#039;&lt;br /&gt;
  WHEN 10 THEN &#039;Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 11 THEN &#039;Simple Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 12 THEN &#039;Mean of Grades (with extra credits)&#039;&lt;br /&gt;
  WHEN 13 THEN &#039;Sum of Grades&#039;&lt;br /&gt;
END AS &#039;aggregation name&#039;&lt;br /&gt;
&lt;br /&gt;
# Note that gc.aggregatesubcats column is eliminated in 2.8 and later per MDL-47503, so comment that line on updated systems or you&#039;ll get an error&lt;br /&gt;
, gc.keephigh AS &#039;keep high&#039;&lt;br /&gt;
, gc.droplow AS &#039;dr0p low&#039;&lt;br /&gt;
, gc.aggregateonlygraded AS &#039;Aggregate only graded&#039;&lt;br /&gt;
, gc.aggregateoutcomes AS &#039;aggregate outcomes&#039;&lt;br /&gt;
, gc.aggregatesubcats AS &#039;aggregate subcategories&#039;&lt;br /&gt;
&lt;br /&gt;
# If you are displaying data about individual courses, you may want to know how old they are&lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;course start date&#039;&lt;br /&gt;
&lt;br /&gt;
# 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&#039;ll need to uncomment the necessary JOINs below&lt;br /&gt;
#, gi.itemname AS &#039;grade item&#039;&lt;br /&gt;
#, gg.finalgrade AS &#039;final grade&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
&lt;br /&gt;
prefix_course AS c&lt;br /&gt;
JOIN prefix_grade_categories AS gc ON gc.courseid = c.id&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id #AND gi.categoryid=gc.id&lt;br /&gt;
#LEFT JOIN prefix_grade_grades AS gg ON gg.itemid = gi.id AND gg.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
#AND gc.aggregation = 13 #only the dreaded Sum of Grades aggregations&lt;br /&gt;
#AND gc.depth = 1 # if for some reason you only want course aggregations, not subcategories&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.aggregation, gc.keephigh, gc.droplow, gc.aggregateonlygraded, gc.aggregateoutcomes, gc.aggregatesubcats&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running Cron jobs (task_scheduled) ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT classname&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(lastruntime), &#039;%H:%i [%d]&#039;) AS &#039;last&#039;&lt;br /&gt;
  ,DATE_FORMAT(now(), &#039;%H:%i&#039;) AS &#039;now&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(nextruntime), &#039;%H:%i [%d]&#039;) AS &#039;next&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP()-nextruntime), &#039;%i&#039;) AS &#039;next in min&#039;&lt;br /&gt;
FROM mdl_task_scheduled&lt;br /&gt;
WHERE now() &amp;gt; FROM_UNIXTIME(nextruntime)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== All Meta courses with Parent and Child course relationships ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
This shows the list of courses with Meta course link enrollments in them (&#039;Parent course&#039;), and the courses which are connected to them to provide enrollments (&#039;Child courses&#039;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.fullname AS &#039;Parent course name&#039;,&lt;br /&gt;
c.shortname AS &#039;Parent course shortname&#039;,&lt;br /&gt;
en.courseid AS &#039;Parent course id&#039;,&lt;br /&gt;
(SELECT fullname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course name&#039;,&lt;br /&gt;
(SELECT shortname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course shortname&#039;,&lt;br /&gt;
en.customint1 AS &#039;Child course id&#039;&lt;br /&gt;
FROM prefix_enrol en&lt;br /&gt;
JOIN prefix_course c ON c.id = en.courseid&lt;br /&gt;
WHERE en.enrol = &#039;meta&#039;&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Learning Analytics Reports ==&lt;br /&gt;
(Moodle v. 3.4 and later)&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
This report provides a list of the learning analytics models on your site, whether enabled or not, and several details about them.&lt;br /&gt;
&lt;br /&gt;
(Note: this report was created on a system using PostgreSQL. Some changes may be needed for other forms of SQL.)&lt;br /&gt;
&lt;br /&gt;
=== Learning Analytics Model Summary ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
am.id AS &amp;quot;model id&amp;quot;,	 &lt;br /&gt;
split_part(am.target,&#039;\&#039;,5) AS &amp;quot;target&amp;quot;,&lt;br /&gt;
CASE WHEN am.enabled=1 THEN &#039;YES&#039; ELSE &#039;NO&#039; END AS &amp;quot;enabled&amp;quot;,	 &lt;br /&gt;
CASE WHEN am.trained=1 THEN &#039;YES&#039; ELSE &#039;NO&#039; END AS &amp;quot;trained&amp;quot;,&lt;br /&gt;
am.name,	 &lt;br /&gt;
/* indicators,*/&lt;br /&gt;
char_length(am.indicators) - char_length(REPLACE(am.indicators,&#039;,&#039;,&#039;&#039;))+1 AS &amp;quot;indicator count&amp;quot;,&lt;br /&gt;
split_part(am.timesplitting,&#039;\&#039;,5) AS &amp;quot;interval&amp;quot;,&lt;br /&gt;
/*&lt;br /&gt;
to_timestamp(am.version) AS &amp;quot;version&amp;quot;,	 &lt;br /&gt;
to_timestamp(am.timecreated) AS &amp;quot;time created&amp;quot;,	 &lt;br /&gt;
to_timestamp(am.timemodified) AS &amp;quot;time modified&amp;quot;,	&lt;br /&gt;
*/&lt;br /&gt;
COUNT(DISTINCT ap.contextid) AS &amp;quot;contexts&amp;quot;,&lt;br /&gt;
COUNT(ap.sampleid) AS &amp;quot;samples&amp;quot;,&lt;br /&gt;
/* AVG(ap.prediction) AS &amp;quot;avg prediction&amp;quot;, */&lt;br /&gt;
ROUND(ap.prediction,1) AS &amp;quot;prediction&amp;quot;,		   &lt;br /&gt;
ROUND(AVG(aml.score),3) AS &amp;quot;model accuracy (avg)&amp;quot;,&lt;br /&gt;
apa.actionname AS &amp;quot;action&amp;quot;,&lt;br /&gt;
COUNT(apa.id) AS &amp;quot;number actions taken&amp;quot;&lt;br /&gt;
		   &lt;br /&gt;
FROM prefix_analytics_models AS am&lt;br /&gt;
JOIN prefix_analytics_predictions AS ap ON am.id = ap.modelid&lt;br /&gt;
LEFT JOIN prefix_analytics_models_log AS aml ON aml.modelid = am.id&lt;br /&gt;
LEFT JOIN prefix_analytics_prediction_actions AS apa ON apa.predictionid = ap.id&lt;br /&gt;
GROUP BY am.id, ap.prediction, apa.actionname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Useful sub queries ==&lt;br /&gt;
&lt;br /&gt;
IN this section please put any short one purpose sub queries that show how common procedures often useful as part of larger queries.&lt;br /&gt;
&lt;br /&gt;
=== All teachers in the course ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This snippet shows how to get teachers from a course. The contextevel for course objects is 50. And the default Teacher role is role id 3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course ic&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = ic.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND ic.id = c.id&lt;br /&gt;
GROUP BY ic.id&lt;br /&gt;
) AS TeacherNames&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Get custom User profile fields for a user ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON uid.fieldid = uif.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to limit it to one of those fields, you can restrict it by shortname of the custom profile field, so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;shortname1&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will show you only the data from the custom profile field with the shortname &#039;shortname1&#039;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, d1.data AS &#039;Profile One&#039;, d2.data As &#039;Profile Two&#039;&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
JOIN prefix_user_info_data d1 ON d1.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
JOIN prefix_user_info_data d2 ON d2.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f2 ON d2.fieldid = f2.id AND f2.shortname = &#039;shortname2&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== NOTE: Alternate Method ====&lt;br /&gt;
&lt;br /&gt;
If you have more than a couple of fields you need to use, then this query may time out or not return data due to too many joins. The limit seems to be around 10 custom profile fields. &lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thefirstfield&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname2&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thesecondfield&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== How to use Configurable Reports Date Time Filters===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Here is a simple example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.firstaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;FirstAccess&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.lastaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;LastAccess&#039;   &lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1&lt;br /&gt;
%%FILTER_STARTTIME:u.firstaccess:&amp;gt;%% &lt;br /&gt;
%%FILTER_ENDTIME:u.lastaccess:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2) You MUST then add the Start / End date filter on the Filters tab of the Report. If you don&#039;t, the report will still run, probably, but the filter will be ignored.&lt;br /&gt;
&lt;br /&gt;
Note: the WHERE 1=1 statement is a peculiarity of the filters in Config reports: if you don&#039;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.)&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://github.com/jleyva/moodle-configurable_reports_repository Configurable Reports Repository on GitHub]&lt;br /&gt;
* [https://moodleschema.zoola.io/index.html Moodle DB schema explorer] - searching and filtering tables, fields and external key connections between tables.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;br /&gt;
&lt;br /&gt;
[[es:Reportes específicos hechos por usuarios]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Performance_recommendations&amp;diff=134823</id>
		<title>Performance recommendations</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Performance_recommendations&amp;diff=134823"/>
		<updated>2019-07-21T14:19:52Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
Moodle can be made to perform very well, at small usage levels or scaling up to many thousands of users. The factors involved in performance are basically the same as for any PHP-based database-driven system. When trying to optimize your server, try to focus on the factor which will make the most difference to the user. For example, if you have relatively more users browsing than accessing the database, look to improve the webserver performance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Obtain a baseline benchmark==&lt;br /&gt;
&lt;br /&gt;
Before attempting any optimization, you should obtain a baseline benchmark of the component of the system you are trying to improve. For Linux try [http://lbs.sourceforge.net/ LBS] and for Windows use the Performance Monitor. Once you have quantitative data about how your system is performing currently, you&#039;ll be able to determine if the change you have made has had any real impact.&lt;br /&gt;
&lt;br /&gt;
The overall aim of adjustments to improve performance is to use RAM (cacheing) and to reduce disk-based activity. It is especially important to try to eliminate swap file usage as much as you can. If your system starts swapping, this is a sign that you need more RAM. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;optimization order preference&#039;&#039;&#039; is usually: primary storage (more RAM), secondary storage (faster hard disks/improved hard disk configuration), processor (more and faster).&lt;br /&gt;
&lt;br /&gt;
It can be interesting to install and use the [https://moodle.org/plugins/report_benchmark Benchmark plugin] in order to find the bottlenecks of your system that specifically affect Moodle.&lt;br /&gt;
&lt;br /&gt;
==Scalability==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s design (with clear separation of application layers) allows for strongly scalable setups. (Please check the list of [[Large installations|large Moodle installations]].)&lt;br /&gt;
&lt;br /&gt;
Large sites usually separate the web server and database onto separate servers, although for smaller installations this is typically not necessary.&lt;br /&gt;
&lt;br /&gt;
It is possible to load-balance a Moodle installation, for example by using more than one webserver. The separate webservers should query the same database and refer to the same filestore and cache areas (see [[Caching]]), but otherwise the separation of the application layers is complete enough to make this kind of clustering feasible. Similarly, the database could be a cluster of servers (e.g. a MySQL cluster), but this is not an easy task and you should seek expert support, e.g. from a Moodle Partner.&lt;br /&gt;
&lt;br /&gt;
===Server cluster===&lt;br /&gt;
&lt;br /&gt;
Using Moodle forum discussions:&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=57202 Moodle clustering]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=44470 Software load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=49986 TCP load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=88214 Installation for 3000 simultaneous users]&lt;br /&gt;
&lt;br /&gt;
==Hardware configuration==&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: The fastest and most effective change that you can make to improve performance is to &#039;&#039;&#039;increase the amount of RAM on your web server&#039;&#039;&#039; - get as much as possible (e.g. 4GB or more). Increasing primary memory will reduce the need for processes to swap to disk and will enable your server to handle more users.&lt;br /&gt;
* Better performance is gained by obtaining the best &#039;&#039;&#039;processor capability&#039;&#039;&#039; you can, i.e. dual or dual core processors. A modern BIOS should allow you to enable hyperthreading, but check if this makes a difference to the overall performance of the processors by using a [http://en.wikipedia.org/wiki/Super_PI CPU benchmarking tool].&lt;br /&gt;
* If you can afford them, use &#039;&#039;&#039;SCSI hard disks&#039;&#039;&#039; instead of SATA drives. SATA drives will increase your system&#039;s CPU utilization, whereas SCSI drives have their own integrated processors and come into their own when you have multiple drives. If you must have SATA drives, check that your motherboard and the drives themselves support NCQ (Native Command Queuing).&lt;br /&gt;
* Purchase hard disks with a &#039;&#039;&#039;low seek time&#039;&#039;&#039;. This will improve the overall speed of your system, especially when accessing Moodle&#039;s reports.&lt;br /&gt;
* Size your &#039;&#039;&#039;swap file&#039;&#039;&#039; correctly. The general advice is to set it to 4 x physical RAM.&lt;br /&gt;
* Use a &#039;&#039;&#039;RAID disk system&#039;&#039;&#039;. Although there are many different RAID configurations you can create, the following generally works best:&lt;br /&gt;
** install a hardware RAID controller (if you can)&lt;br /&gt;
** the operating system and swap drive on one set of disks configured as RAID-1.&lt;br /&gt;
** Moodle, Web server and Database server on another set of disks configured as RAID-5.&lt;br /&gt;
* If your &#039;moodledata&#039; area is going to be on relatively slow storage (e.g. NFS mount on to a NAS device) you will probably have performance issues with the default cache configuration (which writes to this storage). See the page on [[Caching]] and consider an alternative. Using [https://en.wikipedia.org/wiki/GlusterFS GlusterFS] / [https://en.wikipedia.org/wiki/OCFS2 OCFS2] / [https://en.wikipedia.org/wiki/GFS2 GFS2] on a [https://en.wikipedia.org/wiki/Storage_Area_Network SAN] device and [https://en.wikipedia.org/wiki/Fibre_Channel Fiber Channel] could improve performance (See more info on the Moodle [https://moodle.org/mod/forum/discuss.php?d=214680#p1123124 forum thread], [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 NFS performance tuing] )&lt;br /&gt;
* Use &#039;&#039;&#039;gigabit ethernet&#039;&#039;&#039; for improved latency and throughput. This is especially important when you have your webserver and database server separated out on different hosts.&lt;br /&gt;
* Check the settings on your &#039;&#039;&#039;network card&#039;&#039;&#039;. You may get an improvement in performance by increasing the use of buffers and transmit/receive descriptors (balance this with processor and memory overheads) and off-loading TCP checksum calculation onto the card instead of the OS.&lt;br /&gt;
*  Read this [http://moodle.org/mod/forum/discuss.php?d=68579 Case Study] on a server stress test with 300 users.  &lt;br /&gt;
* See this [http://elearning.sgu.ac.jp/doc/PT/ accompanying report] on network traffic and server loads.&lt;br /&gt;
* Also see this SFSU presentation at Educause (using VMWare): [http://www.educause.edu/Resources/AnOpenSourceLMSforaMissionCrit/162843]&lt;br /&gt;
&lt;br /&gt;
==Operating System==&lt;br /&gt;
* You can use [http://en.wikipedia.org/wiki/Linux Linux](recommended), Unix-based, Windows or Mac OS X for the server &#039;&#039;&#039;operating system&#039;&#039;&#039;. *nix operating systems generally require less memory than Mac OS X or Windows servers for doing the same task as the server is configured with just a shell interface. Additionally Linux does not have licensing fees attached, but can have a big learning curve if you&#039;re used to another operating system. If you have a large number of processors running SMP, you may also want to consider using a highly tuned OS such as [http://en.wikipedia.org/wiki/Solaris_Operating_Environment Solaris].&lt;br /&gt;
* Check your own OS and &#039;&#039;&#039;vendor specific instructions&#039;&#039;&#039; for optimization steps.&lt;br /&gt;
** For Linux look at the [http://linuxperf.sourceforge.net/ Linux Performance Team] site. &lt;br /&gt;
** For Linux investigate the hdparm command, e.g. hdparm -m16 -d1 can be used to enable read/write on multiple sectors and DMA. Mount disks with the [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 &amp;quot;async&amp;quot; and &amp;quot;noatime&amp;quot;] options.&lt;br /&gt;
** For Windows set the sever to be optimized for network applications (Control Panel, Network Connections, LAN connection, Properties, File &amp;amp; Printer Sharing for Microsoft Networks, Properties, Optimization). You can also search the [http://technet.microsoft.com/ Microsoft TechNet site] for optimization documents.&lt;br /&gt;
&lt;br /&gt;
==Web server performance==&lt;br /&gt;
&lt;br /&gt;
Installing [http://www.mozilla.com/en-US/ Firefox] and the [https://addons.mozilla.org/en-US/firefox/addon/1843 firebug] extension will allow you to watch the time it takes for each page component to load. Also, the [https://addons.mozilla.org/en-US/firefox/addon/5369 Yslow] extension will evaluate your page against Yahoo&#039;s [http://www.skrenta.com/2007/05/14_rules_for_fast_web_pages_by_1.html 14 rules], full text [http://developer.yahoo.com/performance/rules.html Best Practices for Speeding Up Your Web Site], &amp;lt;strike&amp;gt;([http://video.yahoo.com/video/play?vid=1040890 video])&amp;lt;/strike&amp;gt; for fast loading websites.&lt;br /&gt;
&lt;br /&gt;
===PHP performance===&lt;br /&gt;
* You are strongly recommended to use a &#039;&#039;&#039;PHP accelerator&#039;&#039;&#039; to ease CPU load, such as [http://pecl.php.net/apc APC], [http://www.php-accelerator.co.uk/ PHPA], [http://trac.lighttpd.net/xcache/ Xcache], [http://sourceforge.net/projects/wincache WinCache] or [http://eaccelerator.net/ eAccelerator]. (Take care to choose a PHP accelerator that is known to work well with your version of PHP and note that Turck MMCache is [http://turckmmcache.exeprod.com/TheManifestoEnglish no longer maintained] and can cause failures with PHP 5). PHP 5.5 (and newer) includes OpCache and is fully supported and recommended by Moodle&lt;br /&gt;
* Improvements in read/write performance can be improved by putting the cached PHP pages on a [[TMPFS]] filesystem - but remember that you&#039;ll lose the cache contents when there is a power failure or the server is rebooted.&lt;br /&gt;
* Performance of PHP is better when installed as an &#039;&#039;&#039;Apache/IIS6 ISAPI module&#039;&#039;&#039; (rather than a CGI). IIS 7.0/7.5 (Windows Server 2008/R2) users should choose a FastCGI installation for best performance.&lt;br /&gt;
* Also check the &#039;&#039;&#039;memory_limit&#039;&#039;&#039; in php.ini, reduce it to 16M for Moodle version earlier than 1.7 ([http://moodle.org/mod/forum/discuss.php?d=39656 See this forum discussion]). For Moodle 1.7 or later, it is recommended that the value of memory_limit should be 40M. As of [http://www.php.net/ChangeLog-5.php PHP 5.2.1] the default value for the memory_limit directive is 128M.&lt;br /&gt;
* Also see [[PHP_settings_by_Moodle_version]]&lt;br /&gt;
* Use [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html PHP-FPM] (with apache).&lt;br /&gt;
&lt;br /&gt;
===Install HowTo===&lt;br /&gt;
* [http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html APC on CentOS 5.x (linux)]&lt;br /&gt;
* [http://fplanque.com/dev/linux/install-apc-php-cache-debian-lenny APC on Debian (linux)]&lt;br /&gt;
* [http://www.linuxtuts.net/211-installing-memcached-php5-memcache-module-debian-apache2.html MemCache module on Debian (Apache2 and PHP5) ]&lt;br /&gt;
* [http://noveckg.blogspot.com/2010/03/installing-memcached-on-centos-5x.html Installing Memcache on CentOS 5.x (linux)]&lt;br /&gt;
* [http://noveckg.blogspot.com/2010/02/installing-eaccelerator-cache-for-php.html Installing eAccelerator on CentOS 5.x (linux)]&lt;br /&gt;
* [https://docs.moodle.org/en/Installing_eAccelerator_In_Ubuntu_Server/ Installing eAccelerator on Ubuntu Server (linux)]&lt;br /&gt;
&lt;br /&gt;
===Apache performance===&lt;br /&gt;
* If you are using Apache on a Windows server, use the build from [http://www.apachelounge.com Apache Lounge] which is reported to have [http://moodle.org/mod/forum/discuss.php?d=93358 performance and stability improvements] compared to the official Apache download. Note that this is an unofficial build, so may not keep up with official releases.&lt;br /&gt;
* Set the &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; directive correctly (&#039;&#039;&#039;MaxClients&#039;&#039;&#039; before Apache 2.4). Use this formula to help (which uses 80% of available memory to leave room for spare):&lt;br /&gt;
 MaxRequestWorkers = Total available memory * 80% / Max memory usage of apache process&lt;br /&gt;
:Memory usage of apache process is usually 10MB but Moodle can easily use up to 100MB per process, so a general rule of thumb is to divide your available memory in megabytes by 100 to get a conservative setting for MaxClients. You are quite likely to find yourself lowering the MaxRequestWorkers from its default of 150 on a Moodle server. To get a more accurate estimate read the value from the shell command:&lt;br /&gt;
 #ps -ylC httpd --sort:rss&lt;br /&gt;
&lt;br /&gt;
:If you need to increase the value of &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; beyond 256, you will also need to set the &#039;&#039;&#039;ServerLimit&#039;&#039;&#039; directive. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: Do not be tempted to set the value of MaxRequestWorkers higher than your available memory as your server will consume more RAM than available and start to swap to disk. &lt;br /&gt;
* Consider reducing the &#039;&#039;&#039;number of modules&#039;&#039;&#039; that Apache loads in the httpd.conf file to the minumum necessary to reduce the memory needed. &lt;br /&gt;
* Use the &#039;&#039;&#039;latest version of Apache&#039;&#039;&#039; - Apache 2 has an improved memory model which reduces memory usage further.&lt;br /&gt;
* For Unix/Linux systems, consider lowering &#039;&#039;&#039;MaxConnectionsPerChild&#039;&#039;&#039; (&#039;&#039;&#039;MaxRequestsPerChild&#039;&#039;&#039; before Apache 2.4) in httpd.conf to as low as 20-30 (if you set it any lower the overhead of forking begins to outweigh the benefits). &lt;br /&gt;
* For a heavily loaded server, consider setting &#039;&#039;&#039;KeepAlive Off&#039;&#039;&#039; (do this only if your Moodle pages do not contain links to resources or uploaded images) or lowering the &#039;&#039;&#039;KeepAliveTimeout&#039;&#039;&#039; to between 2 and 5. The default is 15 (seconds) - the higher the value the more server processes will be kept waiting for possibly idle connections. A more accurate value for KeepAliveTimeout is obtained by observing how long it takes your users to download a page. After altering any of the KeepAlive variables, monitor your CPU utilization as there may be an additional overhead in initiating more worker processes/threads.&lt;br /&gt;
* As an alternative to using KeepAlive Off, consider setting-up a &#039;&#039;&#039;Reverse Proxy server&#039;&#039;&#039; infront of the Moodle server to cache HTML files with images. You can then return Apache to using keep-alives on the Moodle server.&lt;br /&gt;
* If you do not use a .htaccess file, set the &#039;&#039;&#039;AllowOverride&#039;&#039;&#039; variable to AllowOverride None to prevent .htaccess lookups.&lt;br /&gt;
* Set &#039;&#039;&#039;DirectoryIndex&#039;&#039;&#039; correctly so as to avoid content-negotiation. Here&#039;s an example from a production server:&lt;br /&gt;
 DirectoryIndex index.php index.html index.htm&lt;br /&gt;
* Unless you are doing development work on the server, set &#039;&#039;&#039;ExtendedStatus Off&#039;&#039;&#039; and disable mod_info as well as mod_status.&lt;br /&gt;
* Leave &#039;&#039;&#039;HostnameLookups Off&#039;&#039;&#039; (as default) to reduce DNS latency.&lt;br /&gt;
* Consider reducing the value of &#039;&#039;&#039;TimeOut&#039;&#039;&#039; to between 30 to 60 (seconds). &lt;br /&gt;
* For the &#039;&#039;&#039;Options directive&#039;&#039;&#039;, avoid Options Multiviews as this performs a directory scan. To reduce disk I/O further use&lt;br /&gt;
 Options -Indexes FollowSymLinks&lt;br /&gt;
&lt;br /&gt;
* Compression reduces response times by reducing the size of the HTTP response&lt;br /&gt;
# Install and enable mod_deflate - refer to documentation or man pages&lt;br /&gt;
# Add this code to the virtual server config file within the &amp;lt;directory&amp;gt; section for the root directory (or within the .htaccess file if AllowOverrides is On):&lt;br /&gt;
 &amp;lt;ifModule mod_deflate.c&amp;gt;&lt;br /&gt;
   AddOutputFilterByType DEFLATE text/html text/plain text/xml text/x-js text/javascript text/css application/javascript&lt;br /&gt;
 &amp;lt;/ifmodule&amp;gt;&lt;br /&gt;
* Use Apache [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html event] [http://httpd.apache.org/docs/current/mpm.html MPM] (and not the default Prefork or Worker)&lt;br /&gt;
&lt;br /&gt;
===IIS performance===&lt;br /&gt;
All alter this location in the registry:&lt;br /&gt;
 HKLM\SYSTEM\CurrentControlSet\Services\Inetinfo\Parameters\&lt;br /&gt;
* The equivalent to KeepAliveTimeout is &#039;&#039;&#039;ListenBackLog&#039;&#039;&#039; (IIS - registry location is HKLM\ SYSTEM\ CurrentControlSet\ Services\ Inetinfo\ Parameters). Set this to between 2 to 5.&lt;br /&gt;
*Change the &#039;&#039;&#039;MemCacheSize&#039;&#039;&#039; value to adjust the amount of memory (Mb) that IIS will use for its file cache (50% of available memory by default).&lt;br /&gt;
*Change the &#039;&#039;&#039;MaxCachedFileSize&#039;&#039;&#039; to adjust the maximum size of a file cached in the file cache in bytes. Default is 262,144 (256K).&lt;br /&gt;
*Create a new DWORD called &#039;&#039;&#039;ObjectCacheTTL&#039;&#039;&#039; to change the length of time (in milliseconds) that objects in the cache are held in memory. Default is 30,000 milliseconds (30 seconds).&lt;br /&gt;
&lt;br /&gt;
===Lighttpd, NginX and Cherokee performance===&lt;br /&gt;
You can increase server performance by using a &#039;&#039;&#039;light-weight&#039;&#039;&#039; webserver like [http://www.lighttpd.net/ lighttpd],  [http://nginx.net/ nginx] or [http://www.cherokee-project.com/ cherokee] in combination with PHP in FastCGI-mode. Lighttpd was originally created as a proof-of-concept[http://www.lighttpd.net/story] to address the [http://www.kegel.com/c10k.html C10k problem] and while primarily recommended for memory-limited servers, its design origins and asynchronous-IO model make it a suitable and proven[http://blog.lighttpd.net/articles/2006/12/28/lighttpd-powers-5-alexa-top-250-sites] alternative HTTP server for high-load websites and web apps, including Moodle. See the [[lighttpd | MoodleDocs Lighttpd page]] for additional information, configuration example and links.&lt;br /&gt;
&lt;br /&gt;
Alternatively, both [http://www.lighttpd.net/ lighttpd] and [http://nginx.net/ nginx] are capable of performing as a load-balancer and/or reverse-proxy to alleviate load on back-end servers[http://www.linuxjournal.com/article/10108], providing benefit without requiring an actual software change on existing servers.&lt;br /&gt;
&lt;br /&gt;
Do note that these are likely to be the least tested server environments of all particularly if you are using advanced features such as web services and/or Moodle Networking. They are probably best considered for heavily used Moodle sites with relatively simple configurations.&lt;br /&gt;
&lt;br /&gt;
===X-Sendfile===&lt;br /&gt;
&lt;br /&gt;
X-Sendfile modules improve performance when sending large files from Moodle. It is recommended to configure your web server and Moodle to use this feature of available.&lt;br /&gt;
&lt;br /&gt;
Configure web server:&lt;br /&gt;
* Apache - https://tn123.org/mod_xsendfile/&lt;br /&gt;
* Lighttpd - http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file&lt;br /&gt;
* Nginx - http://wiki.nginx.org/XSendfile&lt;br /&gt;
&lt;br /&gt;
Enable support in config.php (see config-dist.php):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Sendfile&#039;;           // Apache {@see https://tn123.org/mod_xsendfile/}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-LIGHTTPD-send-file&#039;; // Lighttpd {@see http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Accel-Redirect&#039;;     // Nginx {@see http://wiki.nginx.org/XSendfile}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure file location prefixes if your server implementation requires it:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfilealiases = array(&lt;br /&gt;
//         &#039;/dataroot/&#039; =&amp;gt; $CFG-&amp;gt;dataroot,&lt;br /&gt;
//         &#039;/cachedir/&#039; =&amp;gt; &#039;/var/www/moodle/cache&#039;,    // for custom $CFG-&amp;gt;cachedir locations&lt;br /&gt;
//         &#039;/localcachedir/&#039; =&amp;gt; &#039;/var/local/cache&#039;,    // for custom $CFG-&amp;gt;localcachedir locations&lt;br /&gt;
//         &#039;/tempdir/&#039;  =&amp;gt; &#039;/var/www/moodle/temp&#039;,     // for custom $CFG-&amp;gt;tempdir locations&lt;br /&gt;
//         &#039;/filedir&#039;   =&amp;gt; &#039;/var/www/moodle/filedir&#039;,  // for custom $CFG-&amp;gt;filedir locations&lt;br /&gt;
//     );&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Database performance==&lt;br /&gt;
&lt;br /&gt;
===MySQL performance===&lt;br /&gt;
&lt;br /&gt;
The following are MySQL specific settings which can be adjusted for better performance in your my.cnf (my.ini in Windows). The file contains a list of settings and their values. To see the current values use these commands&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
 SHOW VARIABLES; &lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: You must make backups of your database before attempting to change any MySQL server configuration. After any change to the my.cnf, restart mysqld.&lt;br /&gt;
&lt;br /&gt;
If you are able, the [http://mysqltuner.com/ MySQLTuner] tool can be run against your MySQL server and will calculate appropriate configuration values for most of the following settings based on your current load, status and variables automatically.&lt;br /&gt;
&lt;br /&gt;
* Enable the &#039;&#039;&#039;query cache&#039;&#039;&#039; with &lt;br /&gt;
 query_cache_type = 1. &lt;br /&gt;
For most Moodle installs, set the following:&lt;br /&gt;
 query_cache_size = 36M &lt;br /&gt;
 query_cache_min_res_unit = 2K. &lt;br /&gt;
The query cache will improve performance if you are doing few updates on the database. &lt;br /&gt;
* Set the &#039;&#039;&#039;table cache&#039;&#039;&#039; correctly. For Moodle 1.6 set &lt;br /&gt;
 table_cache = 256 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min), and for Moodle 1.7 set &lt;br /&gt;
 table_cache = 512 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min). The table cache is used by all threads (connections), so monitor the value of opened_tables to further adjust - if opened_tables &amp;gt; 3 * table_cache(table_open_cache in MySQL &amp;gt; 5.1.2) then increase table_cache upto your OS limit. Note also that the figure for table_cache will also change depending on the number of modules and plugins you have installed. Find the number for your server by executing the mysql statement below. Look at the number returned and set table_cache to this value.&lt;br /&gt;
 mysql&amp;gt;SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema=&#039;yourmoodledbname&#039;;&lt;br /&gt;
* Set the &#039;&#039;&#039;thread cache&#039;&#039;&#039; correctly. Adjust the value so that your thread cache utilization is as close to 100% as possible by this formula:&lt;br /&gt;
 thread cache utilization (%) = (threads_created / connections) * 100&lt;br /&gt;
* The &#039;&#039;&#039;key buffer&#039;&#039;&#039; can improve the access speed to Moodle&#039;s SELECT queries. The correct size depends on the size of the index files (.myi) and in Moodle 1.6 or later (without any additional modules and plugins), the recommendation for this value is key_buffer_size = 32M. Ideally you want the database to be reading once from the disk for every 100 requests so monitor that the value is suitable for your install by adjusting the value of key_buffer_size so that the following formulas are true:&lt;br /&gt;
 key_read / key_read_requests &amp;lt; 0.01&lt;br /&gt;
 key_write / key_write_requests &amp;lt;= 1.0&lt;br /&gt;
* Set the &#039;&#039;&#039;maximum number of connections&#039;&#039;&#039; so that your users will not see a &amp;quot;Too many connections&amp;quot; message. Be careful that this may have an impact on the total memory used. MySQL connections usually last for milliseconds, so it is unusual even for a heavily loaded server for this value to be over 200.&lt;br /&gt;
* Manage &#039;&#039;&#039;high burst activity&#039;&#039;&#039;. If your Moodle install uses a lot of quizzes and you are experiencing performance problems (check by monitoring the value of threads_connected - it should not be rising) consider increasing the value of back_log.&lt;br /&gt;
* &#039;&#039;&#039;Optimize your tables weekly and after upgrading Moodle&#039;&#039;&#039;. It is good practice to also optimize your tables after performing a large data deletion exercise, e.g. at the end of your semester or academic year. This will ensure that index files are up to date. Backup your database first and then use:&lt;br /&gt;
 mysql&amp;gt;CHECK TABLE mdl_tablename;&lt;br /&gt;
 mysql&amp;gt;OPTIMIZE TABLE mdl_tablename;&lt;br /&gt;
:The common tables in Moodle to check are mdl_course_sections, mdl_forum_posts, mdl_log and mdl_sessions (if using dbsessions). Any errors need to be corrected using REPAIR TABLE (see the [http://dev.mysql.com/doc/refman/5.0/en/repair-table.html MySQL manual] and this [http://moodle.org/mod/forum/discuss.php?d=58208#p279638 forum script]).&lt;br /&gt;
* &#039;&#039;&#039;Maintain the key distribution&#039;&#039;&#039;. Every month or so it is a good idea to stop the mysql server and run these myisamchk commands.&lt;br /&gt;
 #myisamchk -a -S /pathtomysql/data/moodledir/*.MYI&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: You must stop the mysql database process (mysqld) before running any myisamchk command. If you do not, you risk data loss.&lt;br /&gt;
* Reduce the number of &#039;&#039;&#039;temporary tables saved to disk&#039;&#039;&#039;. Check this with the created_tmp_disk_tables value. If this is relatively large (&amp;gt;5%) increase tmp_table_size until you see a reduction. Note that this will have an impact on RAM usage.&lt;br /&gt;
&lt;br /&gt;
===PostgreSQL performance===&lt;br /&gt;
&lt;br /&gt;
There are some good papers around on tuning PostgreSQL (like [http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server this one]), and Moodle&#039;s case does not seem to be different to the general case.&lt;br /&gt;
&lt;br /&gt;
The first thing to recognise is that if you really need to worry about tuning you should be using a separate machine for the database server. If you are not using a separate machine then the answers to many performance questions are substantially muddied by the memory requirements of the rest of the application.&lt;br /&gt;
&lt;br /&gt;
You should probably &#039;&#039;&#039;enable autovacuum&#039;&#039;&#039;, unless you know what you are doing. Many e-learning sites have predictable periods of low use, so disabling autovacuum and running a specific vacuum at those times can be a good option. Or perhaps leave autovacuum running but do a full vacuum weekly in a quiet period.&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;&#039;shared_buffers&#039;&#039;&#039; to something reasonable. For versions up to 8.1 my testing has shown that peak performance is almost always obtained with buffers &amp;lt; 10000, so if you are using such a version, and have more than 512M of RAM just set shared_buffers to 10,000 (8MB).&lt;br /&gt;
&lt;br /&gt;
The buffer management had a big overhaul in 8.2 and &amp;quot;reasonable&amp;quot; is now a much larger number. I have not conducted performance tests with 8.2, but the recommendations from others are generally that you should now scale shared_buffers much more with memory and may continue to reap benefits even up to values like 100,000 (80MB). Consider using 1-2% of system RAM.&lt;br /&gt;
&lt;br /&gt;
PostgreSQL will also assume that the operating system is caching its files, so setting &#039;&#039;&#039;effective_cache_size&#039;&#039;&#039; to a reasonable value is also a good idea. A reasonable value will usually be (total RAM - RAM in use by programs). If you are running Linux and leave the system running for a day or two you can look at &#039;free&#039; and under the &#039;cached&#039; column you will see what it currently is. Consider taking that number (which is kB) and dividing it by 10 (i.e. allow 20% for other programs cache needs and then divide by 8 to get pages). If you are not using a dedicated database server you will need to decrease that value to account for usage by other programs.&lt;br /&gt;
&lt;br /&gt;
Some other useful parameters that can have positive effects, and the values I would typically set them to on a machine with 4G RAM, are:&lt;br /&gt;
&lt;br /&gt;
 work_mem = 10240&lt;br /&gt;
&lt;br /&gt;
That&#039;s 10M of RAM to use instead of on-disk sorting and so forth. That can give a big speed increase, but it is per connection and 200 connections * 10M is 2G, so it can theoretically chew up a lot of RAM.&lt;br /&gt;
&lt;br /&gt;
 maintenance_work_mem = 163840&lt;br /&gt;
&lt;br /&gt;
That&#039;s 160M of RAM which will be used by (e.g.) VACUUM, index rebuild, cluster and so forth. This should only be used periodically and should be freed when those processes exit, so I believe it is well worth while.&lt;br /&gt;
&lt;br /&gt;
 wal_buffers = 64&lt;br /&gt;
&lt;br /&gt;
These buffers are used for the write-ahead log, and there have been a number of reports on the PostgreSQL mailing lists of improvement from this level of increase.&lt;br /&gt;
&lt;br /&gt;
This is a little out of date now (version 8.0) but still worth a read: http://www.powerpostgresql.com/Docs&lt;br /&gt;
&lt;br /&gt;
And there is lots of good stuff here as well: http://www.varlena.com/GeneralBits/Tidbits/index.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Based on Andrew McMillan&#039;s post at [http://moodle.org/mod/forum/discuss.php?d=68558 Tuning PostgreSQL] forum thread.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Splitting &#039;&#039;&#039;mdl_log&#039;&#039;&#039; to several tables and using a VIEW with UNION to read them as one. (See Tim Hunt [https://moodle.org/mod/forum/discuss.php?d=243531#p1104165 explanation] on the Moodle forums)&lt;br /&gt;
&lt;br /&gt;
===Other database performance links===&lt;br /&gt;
* Consider using a &#039;&#039;&#039;distributed cacheing system&#039;&#039;&#039; like [http://en.wikipedia.org/wiki/Memcached memcached] but note that memcached does not have any security features so it should be used behind a firewall.&lt;br /&gt;
* Consider using PostgreSQL. See [[Arguments in favour of PostgreSQL]] and [http://moodle.org/mod/forum/discuss.php?d=49195 how to migrate from MySQL to PostgreSQL] (forum discussion).&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.0/en/server-parameters.html General advice on tuning MySQL parameters] (advice from the MySQL manual)&lt;br /&gt;
* [http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/ InnoDB performance optimization] taken from the [http://www.mysqlperformanceblog.com/ MySQL performance blog] site.&lt;br /&gt;
&lt;br /&gt;
==Performance of different Moodle modules==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s activity modules, filters, and other plugins can be activated/deactivated. If necessary, you may wish to deactivate some features (such as chat) if not required - but this isn&#039;t necessary. Some notes on the performance of certain modules:&lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;Chat&#039;&#039;&#039; module is [http://moodle.org/mod/forum/discuss.php?d=37979&amp;amp;parent=175079 said] to be a hog in terms of frequent HTTP requests to the main server. This can be reduced by setting the module to use &#039;&#039;Streamed&#039;&#039; updates, or, if you&#039;re using a Unix-based webserver, by running the chat in daemon mode. When using the Chat module use the configuration settings to tune for your expected load. Pay particular attention to the &#039;&#039;chat_old_ping&#039;&#039; and &#039;&#039;chat_refresh&#039;&#039; parameters as these can have greatest impact on server load.&lt;br /&gt;
* The Moodle &#039;&#039;&#039;Cron&#039;&#039;&#039; task is triggered by calling the script &#039;&#039;cron.php&#039;&#039;. If this is called over HTTP (e.g. using wget or curl) it can take a large amount of memory on large installations. If it is called by directly invoking the php command (e.g. &#039;&#039;php -f /path/to/moodle/directory/admin/cli/cron.php&#039;&#039;) efficiency can be much improved.&lt;br /&gt;
* The &#039;&#039;&#039;Recent activities&#039;&#039;&#039; block is consuming too many resources if you have huge number of records &amp;lt;code&amp;gt;mdl_log&amp;lt;/code&amp;gt;. This is being tested to optimize the SQL query.&lt;br /&gt;
* The &#039;&#039;&#039;Quiz&#039;&#039;&#039; module is known to stretch database performance. However, it has been getting better in recent versions, and we don&#039;t know of any good, up-to-date performance measurements. (Here is a [http://moodle.org/mod/forum/discuss.php?d=68579 case study from 2007 with 300 quiz users].). The following suggestions were described by [https://moodle.org/user/view.php?id=94615&amp;amp;course=5 Al Rachels] in [https://moodle.org/mod/forum/discuss.php?d=347126 this forum thread]:&lt;br /&gt;
** make sure both Moodle, and the operating system, are installed on a [https://en.wikipedia.org/wiki/Solid-state_drive solid state drive]&lt;br /&gt;
** upgrade to and use [https://docs.moodle.org/dev/Moodle_and_PHP7 PHP 7]&lt;br /&gt;
** run MySQLTuner and implement its recommendations&lt;br /&gt;
&lt;br /&gt;
See [[Performance settings]] for more information on performance-related Moodle settings.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle: [http://moodle.org/mod/forum/view.php?f=94 Hardware and Performance] forum&lt;br /&gt;
*[http://opensourceelearning.blogspot.be/2012/10/why-your-moodle-site-is-slow-five.html Why Your Moodle Site is Slow: Five Simple Settings] blog post from Jonathan Moore &lt;br /&gt;
*I teach with Moodle perfomance testing: http://www.iteachwithmoodle.com/2012/11/17/moodle-2-4-beta-performance-test-comparison-with-moodle-2-3/&lt;br /&gt;
*[http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs 2.5.2 performance and MUC APC cahe store]&lt;br /&gt;
*[http://jfilip.ca/2013/09/25/moodle-performance-testing-2-4-6-vs-2-5-2-vs-2-6dev/ Moodle performance testing 2.4.6 vs 2.5.2 vs 2.6dev]&lt;br /&gt;
*[http://jfilip.ca/2013/09/24/moodle-performance-analysis-revisted-now-with-mariadb/ Moodle performance analysis revisited (now with MariaDB)]&lt;br /&gt;
*[http://tjhunt.blogspot.ca/2013/05/performance-testing-moodle.html Tim Hunt&#039;s blog (May 2, 2013) on performance testing Moodle]&lt;br /&gt;
*[http://newrelic.com/ New Relic, Application Performance Monitoring]&lt;br /&gt;
*[http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html Performance enhacements for Apache and PHP (Apache Event MPM and PHP-FPM)]&lt;br /&gt;
*[https://scholarlms.net/performance-recommendations/ Performance recommendations]&lt;br /&gt;
&lt;br /&gt;
There have been a lot of discussions on moodle.org about performance, here are some of the more interesting and (potentially) useful ones:&lt;br /&gt;
&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=83057 Performance woes!]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=57028 Performance perspectives - a little script]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=88927 Comments on planned server hardware]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=102978#p461624 Moodle performance in a pil by Martin Langhoff]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=240391#unread Advice on optimising php/db code in moodle2+]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=243531 Moodle 2.5 performance testing at the OU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=273602 100 active users limit with 4vCPU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=336603#p1356423 Performance Tip ... shared...]&lt;br /&gt;
&lt;br /&gt;
[[es:Recomendaciones sobre desempeño]]&lt;br /&gt;
[[fr:Performance]]&lt;br /&gt;
[[ja:パフォーマンス]]&lt;br /&gt;
[[de:Geschwindigkeitsempfehlungen]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=PHP&amp;diff=134779</id>
		<title>PHP</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=PHP&amp;diff=134779"/>
		<updated>2019-07-15T21:46:06Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* PHP Settings */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
PHP is the scripting language in which Moodle is developed. It is integrated with your web server. The web server detects php pages (by their extension) and sends them to PHP for execution. PHP must be installed and configured properly for Moodle to work effectively (or at all).&lt;br /&gt;
&lt;br /&gt;
==PHP Versions==&lt;br /&gt;
* Moodle 3.0.1 and later support PHP 7, however&lt;br /&gt;
** Moodle 3.1 and earlier does not support PHP 7.1 or later (this means that there is currently no combination of releases of Moodle and PHP that are still supported before Moodle 3.4);&lt;br /&gt;
* Moodle 3.4 and Moodle 3.5 &#039;&#039;&#039;require&#039;&#039;&#039; PHP 7.0 or PHP 7.1 or PHP 7.2&lt;br /&gt;
* Moodle 3.6 &#039;&#039;&#039;requires&#039;&#039;&#039; PHP 7.0 or later&lt;br /&gt;
* Moodle 3.7 and later &#039;&#039;&#039;require&#039;&#039;&#039; PHP 7.1 or later&lt;br /&gt;
&lt;br /&gt;
==PHP Settings==&lt;br /&gt;
Check these settings in your php.ini or .htaccess file (if you&#039;re using Apache). For settings which use ON/OFF as their values, you can substitute 1 for ON and 0 for OFF if you prefer. If you change php.ini, don&#039;t forget to restart the server. &lt;br /&gt;
* &#039;&#039;memory_limit&#039;&#039; needs to be at least 96M (although some functions may not work if this low).  Moodle will refuse to install if lower. 128M is recommended. Large systems may need an even higher setting.&lt;br /&gt;
* &#039;&#039;session.save_handler&#039;&#039; needs to be set to FILES.&lt;br /&gt;
* &#039;&#039;magic_quotes_runtime&#039;&#039; needs to be OFF. (DEPRECATED in PHP 5.3.0, and REMOVED as of PHP 7.0.0.)&lt;br /&gt;
* &#039;&#039;file_uploads&#039;&#039; needs to be ON.&lt;br /&gt;
* &#039;&#039;session.auto_start&#039;&#039; needs to be OFF.&lt;br /&gt;
* The temp folder must be defined and writeable by your webserver user&lt;br /&gt;
* Check the error display/logging section. Make sure the settings are appropriate for your server use.&lt;br /&gt;
* &#039;&#039;post_max_size&#039;&#039; and &#039;&#039;upload_max_filesize&#039;&#039; restrict the maximum file size that can be uploaded.&lt;br /&gt;
* Check the &#039;&#039;[mail function]&#039;&#039; and database section (for your chosen database) to make sure they match your server configuration.&lt;br /&gt;
&lt;br /&gt;
==HTTP_RAW_POST_DATA errors==&lt;br /&gt;
Some users are experiencing $HTTP_RAW_POST_DATA related errors, when establishing connection between MNET servers or making AJAX web services requests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Request for server name returned empty response&lt;br /&gt;
 &lt;br /&gt;
    line 134 of /mnet/lib.php: call to debugging()&lt;br /&gt;
    line 115 of /admin/mnet/peers.php: call to mnet_get_public_key()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These errors are affecting installations running moodle on PHP 5.6 version and it&#039;s a PHP bug on the &#039;&#039;&#039;always_populate_raw_post_data&#039;&#039;&#039; setting the default value to 0.&lt;br /&gt;
&lt;br /&gt;
To avoid the error messages above, please change the value following setting on your php.ini file:&lt;br /&gt;
* &#039;&#039;&#039;always_populate_raw_post_data&#039;&#039;&#039; should be changed to &#039;&#039;&#039;-1&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For more information about this bug, see: https://bugs.php.net/bug.php?id=66763&lt;br /&gt;
&lt;br /&gt;
==Finding the correct php.ini==&lt;br /&gt;
Sometimes it is not obvious where the php.ini file is located or you may even find more than one. To be certain run &#039;phpinfo&#039; - see below. The path of the php.ini file is a few lines down in the top section. &lt;br /&gt;
&lt;br /&gt;
Note that if you are using command-line (CLI) PHP for running cron (or anything else) it may be configured with a &#039;&#039;different&#039;&#039; php.ini file.  To check, run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
php -i | grep php.ini&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==PHP Extensions and libraries==&lt;br /&gt;
The following PHP extensions are required or recommended (some, e.g. iconv, ctype and tokenizer are now included in PHP by default). Others will need to be installed or selected.&lt;br /&gt;
* The &#039;&#039;&#039;iconv&#039;&#039;&#039; extension is required.&lt;br /&gt;
* The &#039;&#039;&#039;mbstring&#039;&#039;&#039; extension is recommended.&lt;br /&gt;
* The &#039;&#039;&#039;curl&#039;&#039;&#039; extension is required (required for networking and web services).&lt;br /&gt;
* The &#039;&#039;&#039;openssl&#039;&#039;&#039; extension is recommended (required for networking and web services).&lt;br /&gt;
* The &#039;&#039;&#039;tokenizer&#039;&#039;&#039; extension is recommended.&lt;br /&gt;
* The &#039;&#039;&#039;xmlrpc&#039;&#039;&#039; extension is recommended (required for networking and web services).&lt;br /&gt;
* The &#039;&#039;&#039;soap&#039;&#039;&#039; extension is recommended (required for web services).&lt;br /&gt;
* The &#039;&#039;&#039;ctype&#039;&#039;&#039; extension is required.&lt;br /&gt;
* The &#039;&#039;&#039;zip&#039;&#039;&#039; extension is required.&lt;br /&gt;
* The &#039;&#039;&#039;gd&#039;&#039;&#039; extension is recommended (required for manipulating images).&lt;br /&gt;
* The &#039;&#039;&#039;simplexml&#039;&#039;&#039; extension is required.&lt;br /&gt;
* The &#039;&#039;&#039;spl&#039;&#039;&#039; extension is required.&lt;br /&gt;
* The &#039;&#039;&#039;pcre&#039;&#039;&#039; extension is required.&lt;br /&gt;
* The &#039;&#039;&#039;dom&#039;&#039;&#039; extension is required.&lt;br /&gt;
* The &#039;&#039;&#039;xml&#039;&#039;&#039; extension is required.&lt;br /&gt;
* The &#039;&#039;&#039;intl&#039;&#039;&#039; extension is recommended.&lt;br /&gt;
* The &#039;&#039;&#039;json&#039;&#039;&#039; extension is required.&lt;br /&gt;
* &#039;&#039;&#039;The appropriate extension for your chosen database is also required.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Other PHP extensions may be required to support optional Moodle functionality, especially external authentication and/or enrolment (e.g. LDAP extension for LDAP authentication and the sockets extension for Chat server).&lt;br /&gt;
&lt;br /&gt;
==Installing (missing) extensions==&lt;br /&gt;
&lt;br /&gt;
This depends on how PHP was installed on your machine and what access you have. Here are some possibilities:&lt;br /&gt;
* If this is a hosted server you are likely to have to ask the administrator or hosting company. &lt;br /&gt;
* If PHP was compiled from source you will need to recompile, changing the &#039;configure&#039; settings - see [[Compiling PHP from source]].&lt;br /&gt;
* If it was installed using packages (typically Linux) you can install the required package (see your Linux distribution&#039;s documentation)&lt;br /&gt;
* If you are using Windows you just need to uncomment the appropriate DLL files in php.ini&lt;br /&gt;
&lt;br /&gt;
After making any changes or additions, don&#039;t forget to re-start your web server.&lt;br /&gt;
&lt;br /&gt;
== .htaccess files ==&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have access to the php.ini file or there are conflicting requirements with other PHP applications on the same server you may be able to change PHP settings in an .htaccess file. This should be placed in the &#039;root&#039; of your Moodle installation (i.e. the same place as the config.php file). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The file isn&#039;t always called .htaccess and may not work at all. Contact your server administrator to be sure&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Settings are made by adding lines in one of two formats:&lt;br /&gt;
* php_value &#039;&#039;name value&#039;&#039;&lt;br /&gt;
* php_flag &#039;&#039;name on/off&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
* &#039;&#039;&#039;php_value memory_limit 128M&#039;&#039;&#039;&lt;br /&gt;
* &#039;&#039;&#039;php_flag register_globals off&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==PHP info==&lt;br /&gt;
&lt;br /&gt;
The phpinfo display contains information about the configuration of your PHP installation. This is useful for checking:&lt;br /&gt;
* that your PHP installation meets Moodle&#039;s system requirements.&lt;br /&gt;
* the values that are currently applied to your server&#039;s PHP install, e.g. File upload limits&lt;br /&gt;
* that you have installed the required modules needed for Moodle to work, e.g. the LDAP module for LDAP authentication.&lt;br /&gt;
&lt;br /&gt;
=== Displaying phpinfo in Moodle===&lt;br /&gt;
&lt;br /&gt;
An administrator can find PHP info in &#039;&#039;Settings &amp;gt; Site administration &amp;gt; Server &amp;gt; PHP info&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Displaying phpinfo outside of Moodle ===&lt;br /&gt;
&lt;br /&gt;
To view the phpinfo information:&lt;br /&gt;
* Create a file called info.php using your text editor, containing this single line:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;&lt;br /&gt;
 &amp;lt;?php phpinfo(); ?&amp;gt;&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Save this file as info.php&lt;br /&gt;
* Upload this file into the root web accessible folder on your server.&lt;br /&gt;
* Now open this file in your browser. For example &amp;lt;nowiki&amp;gt;http://&amp;lt;server-name&amp;gt;/info.php&amp;lt;/nowiki&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[[Compiling PHP from source]]&lt;br /&gt;
* [https://docs.moodle.org/dev/Moodle_and_PHP7 Moodle and PHP7] in the developers documentation&lt;br /&gt;
*http://www.php.net/ - the PHP web site&lt;br /&gt;
*http://php.iis.net/ - Microsoft PHP Installer for IIS&lt;br /&gt;
* [[MoodleDocs:Style_guide#PHP_syntax_highlighting]] to highlight PHP syntax&lt;br /&gt;
* [[Code syntax highlighting]] that uses the GeSHi (Generic Syntax Highlighter) filter. &lt;br /&gt;
&lt;br /&gt;
[[de:PHP]]&lt;br /&gt;
[[es:PHP]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Experimental_settings&amp;diff=133123</id>
		<title>Experimental settings</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Experimental_settings&amp;diff=133123"/>
		<updated>2019-02-09T06:50:49Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Developer tools}}&lt;br /&gt;
An administrator can enable certain experimental features from the  Experimental settings page of Site administration.&lt;br /&gt;
&lt;br /&gt;
An experimental feature is defined as a feature which require additional testing and bug-fixing.&lt;br /&gt;
&lt;br /&gt;
{{New features}}&lt;br /&gt;
&lt;br /&gt;
*Context freezing - this allows an administrator or user with the capability moodle/site:managecontextlocks to make categories, blocks, courses or course content &#039;read only&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[[Safe exam browser]]&lt;br /&gt;
*Path to SassC - this setting allows an admin to specify the path to a binary file that will be used to compile SASS. When this field is set (and valid) - the provided compiler will compile SASS code instead of Moodle&#039;s built in PHP compiler. This makes the process of compiling SASS significantly faster. (see MDL-61394 for further details)&lt;br /&gt;
&lt;br /&gt;
*Drag and drop upload of text/links (see MDL-22504 for further details)&lt;br /&gt;
&lt;br /&gt;
[[es:Configuraciones experimentales]]&lt;br /&gt;
[[eu:Esperimentala]]&lt;br /&gt;
[[fr:Expérimental]]&lt;br /&gt;
[[ja:実験用]]&lt;br /&gt;
[[de:Experimentelle Einstellungen]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Mathematics&amp;diff=133087</id>
		<title>Mathematics</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Mathematics&amp;diff=133087"/>
		<updated>2019-02-02T13:08:19Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Equation Construction and Display */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Main page}}&lt;br /&gt;
{{Update}}&lt;br /&gt;
==Equation Construction and Display==&lt;br /&gt;
&lt;br /&gt;
===Tools===&lt;br /&gt;
There are a variety of tools that are available for the purpose of constructing equations, providing text expressions that can be converted to equations, and displaying equations. &lt;br /&gt;
&lt;br /&gt;
The most common text expression syntax is LaTeX or a derivative with probably the most common form of display being a conversion of the equation to an image file. However, is demonstrated with ASCIIMathML simple text expressions can now be be converted to MathML on the fly.&lt;br /&gt;
&lt;br /&gt;
Some tools for creating and displaying equations on-line that may be of interest to those teaching mathematics are:&lt;br /&gt;
* Moodle offers in core a basic TeX filter and an Algebra filter. These are simple but not simplistic. An overview of using these tools can be found at the [[Using TeX Notation]] pages. Be aware that these packages are subsets of complete TeX packages and the conventions used are designed more for ease of use within Moodle rather than as complete TeX packages. &lt;br /&gt;
* [[ASCIIMathML]],  which both converts equations into MathML on the fly and provides a text expression syntax more easily mastered than Tex, though the filter will convert TeX expressions as well. [http://sourceforge.net/project/showfiles.php?group_id=106148 The ASCIIMathML 2.0.2 zip] provides all the files necessary for setting ASCIIMathML up as  a Moodle filter as well creating run-time graphs with ASCIIsvg. An on-line calculator is also included. Just recently an  ASCIIMathML export format for DragMath was added to version 0.7.2, [https://docs.moodle.org/en/DragMath_equation_editor available here],  so that you have access to both a GUI and text expression syntax for creating and displaying equations. Quick and GIFless. [http://math.chapman.edu/~jipsen/asciencepad/asciencepad.html  ASciencePad is also available] and consists of htmlarea enhanced with the ASCIIMathML functionality. &lt;br /&gt;
* [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=916 Tim Hunt&#039;s Moodle MathTran Module] converts Tex into images on the fly. You can also use  [http://www.mathtran.org/wiki/index.php/TeX_image mathtran_img.js] on a page by page basis.&lt;br /&gt;
* The [[jsMath]] filter, which does a similar job but using [[Javascript]] on the user&#039;s computer&lt;br /&gt;
* [[MathJax_filter]], a next generation for jsMath from David Cervone et al that now includes MathML and web font features: [http://MathJax.org] A discussion regarding deploying the beta release can be found here: [http://moodle.org/mod/forum/discuss.php?d=142785]&lt;br /&gt;
* [[Calculated question type]]&lt;br /&gt;
* [[DragMath equation editor]], a WYSIWYG equation editor that integrates easily with the Moodle HTML editor.&lt;br /&gt;
* [[WIRIS]], is a suite of math and science tools. [http://www.wiris.com/moodle/ www.wiris.com/moodle/]&lt;br /&gt;
** MathType, an equation editor that allows you to type or handwritte math expressions. Based on MathML and a Javascript interface.&lt;br /&gt;
** Wiris Quizzes, a set of question types for math and science topics&lt;br /&gt;
* MathML polyfill support (for Chrome) implementation using custom elements [https://github.com/pshihn/math-ml] (can be added to Moodle via theme custom HTML)&lt;br /&gt;
&lt;br /&gt;
Mathematics teachers may also be interested to follow the work of [http://maths.york.ac.uk York University Maths department], who are working on [http://maths.york.ac.uk/serving_maths/ some projects] to augment Moodle, particularly its [[Quiz module]] for online assessment, for example by integrating a system which is able to mark algebraic and trigonometric answers to open-ended questions.&lt;br /&gt;
&lt;br /&gt;
===Accessibility Display Matrix===&lt;br /&gt;
&lt;br /&gt;
{{Expand-section|date=August 2008}}&lt;br /&gt;
&lt;br /&gt;
■ Feature Key appears below the matrix.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
!width=&amp;quot;12%&amp;quot;|Notation&lt;br /&gt;
!width=&amp;quot;22%&amp;quot;|Tex/LaTex&lt;br /&gt;
!width=&amp;quot;22%&amp;quot;|ASCIIMath&lt;br /&gt;
!width=&amp;quot;22%&amp;quot;|MathML&lt;br /&gt;
!width=&amp;quot;22%&amp;quot;|WIRIS&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|Ease of Use&lt;br /&gt;
|Plain text system. Knowledge of LaTeX notation required. Being a plain text system, LaTeX notation is straightforward to create and edit. &lt;br /&gt;
|Plain text system. Easy to learn. Notation simple. Being a plain text system, ASCIIMath is very easy to create and edit.&lt;br /&gt;
|XML-based. Not easy to create and edit: an editor is required.&lt;br /&gt;
|Visual interface for MathML.&amp;lt;br&amp;gt;Toolbar navigation is accessible.&amp;lt;br&amp;gt;LateX plain text notation is also available.&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|Conversion to Braille&lt;br /&gt;
|Output directly to Braille display via screen reader (fn 2)&lt;br /&gt;
|ASCIIMath notation is converted to MathML or LaTeX. Please refer to those formats for details.&lt;br /&gt;
|Converted to suitable textual format and Brailled using screen reader (fn 3)&lt;br /&gt;
|Image alternative text outputs directly to Braille display via screen reader (fn4)&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|Transmission via TTS&lt;br /&gt;
|Notation spoken &amp;quot;as-is&amp;quot; via screen reader (fn 2)&lt;br /&gt;
|ASCIIMath notation is converted to MathML or LaTeX. Please refer to those formats for details.&lt;br /&gt;
|Converted to suitable textual format and spoken using screen reader. Note that MathPlayer add-on for IE has TTS functionality built-in (fn 3).&lt;br /&gt;
|Image alternative text spoken via screen reader (fn 4)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;fn1&amp;quot;&amp;gt;&#039;&#039;&#039;fn1.&#039;&#039;&#039;&amp;lt;/span&amp;gt;&lt;br /&gt;
MathPlayer claims to do math-to-speech by parsing the MathML, not by parsing TeX. See http://www.dessci.com/en/products/mathplayer/tech/accessibility.htm where it is stated:&lt;br /&gt;
&lt;br /&gt;
All of these examples were written in Microsoft Word and MathType and exported to MathML using MathType’s “MathPage” technology. MathPage technology was added to MathType in version 5.0. No special work is needed to author the expressions to make them accessible. Any product that exports MathML will produce pages that MathPlayer can speak.&lt;br /&gt;
&lt;br /&gt;
For a larger real life example, see this page. Also, MSN Encarta uses MathML on many of their web pages that contain math, so much of their Math should be accessible using MathPlayer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;fn2&amp;quot;&amp;gt;&#039;&#039;&#039;fn2. &#039;&#039;&#039;&amp;lt;/span&amp;gt;&lt;br /&gt;
The alt attribute of the rendered graphic is spoken and/or Braillled. As LaTeX is a plain text notation, the notation can be spoken and Brailled by the screen reader directly. This does, of course, assume an understanding of LaTeX notation on the part of the screen reader user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;fn3&amp;quot;&amp;gt;&#039;&#039;&#039;fn3. &#039;&#039;&#039;&amp;lt;/span&amp;gt;&lt;br /&gt;
In the case of Internet Explorer, screen readers require the MathPlayer plugin to be installed before MathML is rendered (IE does not include native MathML support). By using MSAA, the screen reader can obtain a textual version of the math notation from MathPlayer, which it can then TTS and Braille. Note that MathPlayer also contains built-in TTS functionality (employing MS SAPI) which can be used to speak the math notation without having to employ a screen reader. See [http://www.dessci.com/en/products/mathplayer/tech/accessibility.htm] for further details. At time of writing, screen reader support for Firefox is via MSAA and a special custom, Firefox-specific IAccessible2 interface (to reveal text attributes and character positions). Math notation is spoken via a screen reader which interrogates these interfaces.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;fn1&amp;quot;&amp;gt;&#039;&#039;&#039;fn4.&#039;&#039;&#039;&amp;lt;/span&amp;gt;&lt;br /&gt;
The alt attribute of the rendered image is filled with a textual version of the math notation. Screen readers can read the alternative text without additional plugins.&lt;br /&gt;
&lt;br /&gt;
==Using Java for Curriculum==&lt;br /&gt;
===Java Tools for Building Applets for Interactive Demonstration===&lt;br /&gt;
These tools can be integrated in or used with Moodle Resources&lt;br /&gt;
&lt;br /&gt;
==== Java Sketchpad ====&lt;br /&gt;
http://www.dynamicgeometry.com/JavaSketchpad/About_JavaSketchpad.html, is an applet developed by Key Curriculum Press. The applet has been the focus of quite a bit of discussion and demonstrations and discussions are widely available.  An introductory article from the Journal of Online Mathematics can be found here: http://mathdl.maa.org/mathDL/4/?nodeId=508&amp;amp;pa=content&amp;amp;sa=viewDocument. Usage focuses largely on Geometry&lt;br /&gt;
&lt;br /&gt;
==== CabriJava ====&lt;br /&gt;
http://www-cabri.imag.fr/cabrijava/, an applet offered by the University of Cabri,  also focuses on interactive geometry. Quite a number of examples employing CabriJava can be found here: http://www.mathsnet.net/cabri/index.html.&lt;br /&gt;
&lt;br /&gt;
==== Descartes ==== &lt;br /&gt;
http://descartes.cnice.mec.es/, is an applet developed under the auspices of the Spanish Ministerio de Educacion Politica Social y Diporte.  An English introduction can be found here at http://descartes.cnice.mec.es/ingles/index.html.  The Ministery has produced an extensive Mathematics curriculum using Descartes,  which is available in English and can be freely downloaded and used. Much of what is available is still only in Spanish so anyone interested in doing translation work please post to the Moodle Math Tools forum.&lt;br /&gt;
&lt;br /&gt;
==== Sympl ==== &lt;br /&gt;
http://www.sympl.org/, an open source Java application/applet for creating interactive graphs.&lt;br /&gt;
&lt;br /&gt;
===Additional Curricular Use of Applets===&lt;br /&gt;
*Euclid&#039;s Elements -  http://aleph0.clarku.edu/~djoyce/java/elements/elements.html&lt;br /&gt;
*Tutorials employing applets (applets can be downloaded and used in Moodle) http://www.analyzemath.com/&lt;br /&gt;
*Ultrastudio.org - Applet-capable wiki with over 100 educational applets and explaining articles next to them, best covering mathematics (especially complex plane) but also physics and many other topics. CC-BY-SA texts, most of applets open source - http://ultrastudio.org/#Mathematics.&lt;br /&gt;
&lt;br /&gt;
===Applet Tools===&lt;br /&gt;
*Graphing - http://www.langara.bc.ca/mathstats/resource/GraphExplorer/&lt;br /&gt;
*Geometry Construction - http://www.cs.rice.edu/~jwarren/grace/&lt;br /&gt;
*GeoGebra - http://www.geogebra.org/&lt;br /&gt;
*Physics Applets for Drawing (PAD) - http://www.wku.edu/pads/ These can make interactive activities that can both check for correctness and give guiding feedback. Includes modules for graphs (2D functions), vectors (even in/out and other lines and arrows and bar-graphs), motion analysis, equation recognition and more. Uses don&#039;t have to be just for Physics. Math, of course. VectorPAD can be used for placing markers (as points, lines, small pictures, [http://www.wku.edu/pads/exercise.php?id=mgaazqzoakmqgfrkkmqgaaayo arrows) on a picture], that could be used in almost any subject. They can be incorporating in SCORM packages which can interact with Moodle. There is no Moodle module now (july 2009) for using them directly, but that would add a lot more power (compared to SCORM), like being able to save states, turn on/off feedback, etc.&lt;br /&gt;
*GraphApplet 1.05: both calculator and graphapplet - http://www.lundin.info/graphapplet.aspx&lt;br /&gt;
*Physlets: large suite of applets about physics but includes [http://webphysics.davidson.edu/physletprob/ch16_datagraph/default.html advanced graphing] too. [http://www.tupo.biz/kurser/javaapplets/Fysik/java/Physlets/CFL/3dimDiag.htm A time dependent 3D example (Swedish!)]&lt;br /&gt;
&lt;br /&gt;
===Java Applet Collections===&lt;br /&gt;
* http://cs.jsu.edu/mcis/faculty/leathrum/Mathlets/&lt;br /&gt;
* http://www.walter-fendt.de/m14e/&lt;br /&gt;
&lt;br /&gt;
* Probability and Statistics&lt;br /&gt;
**http://www.mste.uiuc.edu/pavel/java/dilemma/&lt;br /&gt;
**http://lstat.kuleuven.be/java/&lt;br /&gt;
**http://www.math.csusb.edu/faculty/stanton/m262/&lt;br /&gt;
&lt;br /&gt;
*http://www.mste.uiuc.edu/murphy/JavaOverview/default.html&lt;br /&gt;
*Math and Physics - http://www.falstad.com/mathphysics.html&lt;br /&gt;
*Curves - http://www-groups.dcs.st-and.ac.uk/~history/Java/index.html&lt;br /&gt;
*Chaos and Fractals - http://math.bu.edu/DYSYS/applets/index.html&lt;br /&gt;
*For sale, but extensive - http://www.cut-the-knot.org/Curriculum/index.shtml&lt;br /&gt;
&lt;br /&gt;
==Mathematics Assessment==&lt;br /&gt;
&lt;br /&gt;
Assessment is a key driver for mathematics.  There are a number of ways of getting students to answer mathematical questions through Moodle.&lt;br /&gt;
* WebWork, see http://webwork.maa.org/wiki/Main_Page  http://webwork.math.rochester.edu/docs/docs/, and http://webwork.maa.org/moodle/ is an independent web application for assessing student Math progress, and there is a Moodle Module for interfacing WebWork to Moodle that can be found here: http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=332, though the resources on the WeBWork wiki are probably more current as the code  in the Moodle CVS has not been updated for some time.&lt;br /&gt;
* STACK provides very mathematical questions for the Moodle quiz module.  These are supported by the CAS Maxima.  The home page for STACK can be found on http://stack.bham.ac.uk/&lt;br /&gt;
* WIRIS quizzes [http://www.wiris.com/quizzes wiris.com/quizzes]&lt;br /&gt;
**Random variables and graphics&lt;br /&gt;
**Automatic evaluation of open answers&lt;br /&gt;
**Syntax checking of answers&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Mathematics tools FAQ]]&lt;br /&gt;
Using Moodle forum discussions:&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=46009 Best practices for teaching Math(s) in Moodle]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=61993 How do you deal with the challenge of writing equations?]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=62002 How do you deal with the challenge of drawing graphs and diagrams?]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=62014 How do you deal with the challenge of interactive exercises and simulations?]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=95950 How can I have a student enter a fraction as an answer?]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=127867 What are the components of an exemplary high school Moodle course?]&lt;br /&gt;
&lt;br /&gt;
[[Category:Mathematics]]&lt;br /&gt;
[[Category:Teacher]]&lt;br /&gt;
&lt;br /&gt;
[[es:Matemáticas]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Embedded_Answers_(Cloze)_question_type&amp;diff=132993</id>
		<title>Embedded Answers (Cloze) question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Embedded_Answers_(Cloze)_question_type&amp;diff=132993"/>
		<updated>2019-01-18T09:00:24Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
&#039;&#039;&#039;Embedded answers (Cloze)&#039;&#039;&#039; questions consist of a passage of text (in Moodle format) that has various answers embedded within it, including multiple choice, short answers and numerical answers.&lt;br /&gt;
&lt;br /&gt;
Until mid2013, there was no graphical interface to create these questions within your Moodle site - you needed to specify the question format using the text box or by importing them from external files.&lt;br /&gt;
&lt;br /&gt;
You can link to an external web site that does create these questions from a graphical interface, see the &#039;&#039;[http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php Online Cloze Question quiz generator]&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
There is an Excel-based [http://hbwubecc.wixsite.com/jordan/tools Cloze and GIFT Generator] that was presented at the 2017 Moodle Moot Japan.&lt;br /&gt;
&lt;br /&gt;
There is a [[Cloze editor for TinyMCE]] that will let you create these questions from a graphical interface within your Moodle site, but it will overwrite your current HTML editor and only works with the [[TinyMCE editor]] but not with [[Atto]]. In 2016 a [[Cloze editor for Atto]] additional plugin was created.&lt;br /&gt;
&lt;br /&gt;
Lots of people suggested that [[Hot Potatoes]] software is the easiest way to create Embedded answer (Cloze) questions.  Once you have created your questions on your PC, you can then import them into Moodle&#039;s quiz module.&lt;br /&gt;
&lt;br /&gt;
However, the flexibility of the Cloze question type is hard to equal and despite the minor coding that you need to create the questions, it has great worth in the Moodle Quiz.&lt;br /&gt;
&lt;br /&gt;
==Question set-up==&lt;br /&gt;
&lt;br /&gt;
#Select the question category&lt;br /&gt;
#Give the question a descriptive name - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter the passage of text (in Moodle format - see [[Embedded_Answers_%28Cloze%29_question_type#Format|Format]] below) into the &#039;question text&#039; field.&lt;br /&gt;
#Select an image to display if you want to add a picture to the question. For the student, it appears immediately above the question text.&lt;br /&gt;
#Set the &#039;default question grade&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;Penalty factor&#039; (see [[Embedded_Answers_%28Cloze%29_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#The editor has been modified and allows you to test if your syntax is good. The different questions elements decoded will be displayed and syntax errors pinpoint. However, it cannot check if the question decoded is two questions in one because of an error syntax.&lt;br /&gt;
#Click Save changes to add the question to the category.&lt;br /&gt;
&lt;br /&gt;
=== Penalty factor ===&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; only applies when the question is used in a quiz using adaptive mode - i.e. where the student is allowed multiple attempts at a question even within the same attempt at the quiz. If the penalty factor is more than 0, then the student will lose that proportion of the &#039;&#039;&#039;maximum&#039;&#039;&#039; grade upon each successive attempt. For example, if the default question grade is 10, and the penalty factor is 0.2, then each successive attempt after the first one will incur a penalty of 0.2 x 10 = 2 points.  The grading for the cloze question applies the penalty to each subpart of the question as a whole.  For example, if you have three fill in the blanks each worth 1 point each, then the penalty will only be incurred on the incorrect parts, not the questions as a whole.&lt;br /&gt;
&lt;br /&gt;
==Question rendering==&lt;br /&gt;
&lt;br /&gt;
The question answer entry space or INPUT HTML ELEMENT (for Short Answer and Numerical question types) and the dropdown list or SELECT HTML ELEMENT (for multichoice) are normally displayed in-line with the text.&lt;br /&gt;
&lt;br /&gt;
The size of the entry space or INPUT HTML ELEMENT ( Short and Numerical) will be adjustable to the length of the longest answer (good or bad) + a random number (0 to 15% total length).([[User:Pierre Pichet|Pierre Pichet]] 15:37, 26 January 2008 (CST))&lt;br /&gt;
&lt;br /&gt;
The size will adjust to the length of the student response when displayed in the grading and feedback process.&lt;br /&gt;
&lt;br /&gt;
The size of the dropdown list or SELECT HTML ELEMENT (multichoice) adjusts itself automatically to the longest answer.&lt;br /&gt;
&lt;br /&gt;
==Format==&lt;br /&gt;
&lt;br /&gt;
Questions consist of a passage of text (in Moodle format) that has various sub-questions embedded within it, including&lt;br /&gt;
&lt;br /&gt;
* short answers (SHORTANSWER or SA or MW), case is unimportant,&lt;br /&gt;
* short answers (SHORTANSWER_C or SAC or MWC), case must match,&lt;br /&gt;
* numerical answers (NUMERICAL or NM),&lt;br /&gt;
* multiple choice (MULTICHOICE or MC), represented as a dropdown menu in-line in the text,&lt;br /&gt;
* multiple choice (MULTICHOICE_V or MCV), represented as a vertical column of radio buttons, or&lt;br /&gt;
* multiple choice (MULTICHOICE_H or MCH), represented as a horizontal row of radio-buttons,&lt;br /&gt;
* multiple choice (MULTIRESPONSE or MR), represented as a vertical row of checkboxes&lt;br /&gt;
* multiple choice (MULTIRESPONSE_H or MRH), represented as a horizontal row of checkboxes&lt;br /&gt;
===Shuffle sub questions===&lt;br /&gt;
When the quiz question behavior shuffle option is set to &#039;&#039;&#039;YES&#039;&#039;&#039;, the following special multiple choice sub-questions elements will be shuffled:&lt;br /&gt;
* multiple choice (MULTICHOICE_S or MCS), represented as a dropdown menu in-line in the text,&lt;br /&gt;
* multiple choice (MULTICHOICE_VS or MCVS), represented as a vertical column of radio buttons, or&lt;br /&gt;
* multiple choice (MULTICHOICE_HS or MCHS), represented as a horizontal row of radio-buttons.&lt;br /&gt;
* multiple choice (MULTIRESPONSE_S or MRS), represented as a vertical row of checkboxes&lt;br /&gt;
* multiple choice (MULTIRESPONSE_HS or MRHS), represented as a horizontal row of checkboxes&lt;br /&gt;
&lt;br /&gt;
{{Note|MCS, MCVS, MCHS are new (Moodle 3.0) Cloze subquestion types with shuffling of answers. See MDL-38214.}}&lt;br /&gt;
&lt;br /&gt;
The structure of  each cloze sub-question is identical:&lt;br /&gt;
:&#039;&#039;&#039;{&#039;&#039;&#039;  start the cloze sub-question with a bracket (AltGr+7)&lt;br /&gt;
:&#039;&#039;&#039;1&#039;&#039;&#039; define a grade for each cloze by  a number (optional). This used for calculation of question grading.&lt;br /&gt;
:&#039;&#039;&#039;:SHORTANSWER:&#039;&#039;&#039; define the type of cloze sub-question. Definition is bounded by &#039;:&#039;. &lt;br /&gt;
:&#039;&#039;&#039;~&#039;&#039;&#039; is a seperator between answer options&lt;br /&gt;
:&#039;&#039;&#039;=&#039;&#039;&#039; marks a correct answer&lt;br /&gt;
:&#039;&#039;&#039;#&#039;&#039;&#039; marks the beginning of an (optional) feedback message&lt;br /&gt;
:&#039;&#039;&#039;}&#039;&#039;&#039;  close the cloze sub-question at the end with a bracket (AltGr+0)&lt;br /&gt;
&lt;br /&gt;
Now a very simple example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{1:SHORTANSWER:=Berlin} is the capital of Germany.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For full details of the format for embedded-answers questions, see the [[Embedded_Answers_%28Cloze%29_question_type#Detailed_syntax_explanations|detailed syntax explanation]] below.&lt;br /&gt;
&lt;br /&gt;
NB: Be careful when copying a cloze type question into the WYSIWYG HTML editor, as line breaks tend to get added, which destroys the question.&lt;br /&gt;
&lt;br /&gt;
If the correct answer contains } # ~ / &amp;quot; or \ you will have to escape them by putting a \ in front of each such character. But [[https://moodle.org/mod/forum/discuss.php?d=275299 this is tricky]]. The { shouldn&#039;t be escaped, this can be vital in getting TeX expressions to work. In the feedback ~ and } must be escaped otherwise it will be interpreted as &#039;&#039;the next answer&#039;&#039; or &#039;&#039;end of the short answer section&#039;&#039; respectively. Quotation signs: &amp;quot; can lead to trouble anyhow in both places. Use the HTML entity: &amp;amp; quot; (without the space between &#039;&#039;&amp;amp;&#039;&#039; and &#039;&#039;quot;&#039;&#039;). If you want to have Mathematical symbols there can be problems with the \ used in TeX expressions. One alternative can be to use [[unicode]] characters. &lt;br /&gt;
&lt;br /&gt;
See the notes further down about numerical embedded question!&lt;br /&gt;
&lt;br /&gt;
===Examples===&lt;br /&gt;
&lt;br /&gt;
====Example 1====&lt;br /&gt;
The following text creates a simple embedded-answers question:&lt;br /&gt;
&lt;br /&gt;
 Match the following cities with the correct state:&lt;br /&gt;
 * San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
 * Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}&lt;br /&gt;
 * Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
 * Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}&lt;br /&gt;
 The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!&lt;br /&gt;
 ~%50%Marseille#No, that is the second largest city in France (after&lt;br /&gt;
 Paris).~*#Wrong answer. The capital of France is Paris, of course.}.&lt;br /&gt;
&lt;br /&gt;
And the result will be:&lt;br /&gt;
 &lt;br /&gt;
[[Image:Cloze.gif|Cloze question type]] &lt;br /&gt;
&lt;br /&gt;
====Example 2====&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding: 1em;border: 1px dashed #FFB53A;color: black;background-color: #f9f9f9;font-family: monospace;font-size:1.2em;&amp;quot;&amp;gt;&lt;br /&gt;
This question consists of some text with an answer embedded right here {1:MULTICHOICE:Wrong answer#Feedback for this wrong answer~Another wrong answer#Feedback for the other wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer}&lt;br /&gt;
&lt;br /&gt;
and right after that you will have to deal with this short answer {1:SHORTANSWER:Wrong answer#Feedback for this wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer}&lt;br /&gt;
&lt;br /&gt;
and finally we have a floating point number {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8~%50%23.8:2#Feedback for half credit answer in the nearby region of the correct answer}.&lt;br /&gt;
&lt;br /&gt;
The  multichoice question can also be shown in the vertical display of the standard moodle multiple choice.&lt;br /&gt;
{2:MCV:1. Wrong answer#Feedback for this wrong answer~2. Another wrong answer#Feedback for the other wrong answer~=3. Correct answer#Feedback for correct answer~%50%4. Answer that gives half the credit#Feedback for half credit answer}&lt;br /&gt;
&lt;br /&gt;
Or in an horizontal display that is included here in a table&lt;br /&gt;
{2:MCH:a. Wrong answer#Feedback for this wrong answer~b. Another wrong answer#Feedback for the other wrong answer~=c. Correct answer#Feedback for correct answer~%50%d. Answer that gives half the credit#Feedback for half credit answer}&lt;br /&gt;
&lt;br /&gt;
A shortanswer question where case must match. Write moodle in upper case letters {1:SHORTANSWER_C:moodle#Feedback for moodle in lower case ~=MOODLE#Feedback for MOODLE in upper case ~%50%Moodle#Feedback for only first letter in upper case}&lt;br /&gt;
&lt;br /&gt;
Note that addresses like www.moodle.org and smileys :-) all work as normal:&lt;br /&gt;
&lt;br /&gt;
a) How good is this? {:MULTICHOICE:=Yes#Correct~No#We have a different opinion}&lt;br /&gt;
&lt;br /&gt;
b) What grade would you give it? {3:NUMERICAL:=3:2}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
[[Image:Cloze example.png]]&lt;br /&gt;
&lt;br /&gt;
Some things to note:&lt;br /&gt;
* The individual embedded answers are represented by the code in braces {}.&lt;br /&gt;
* The number at the start is the &#039;weight&#039;, so in this case each answer contributes an equal share of the overall grade.&lt;br /&gt;
* The correct option in each case is preceded either by an = sign or by %100%. &lt;br /&gt;
* The text appearing after the # that follows each option is the feedback that the student will see if they choose that option.&lt;br /&gt;
* If the student enters &#039;Marseille&#039; in the final example, they score 50% of the total grade.&lt;br /&gt;
* The asterisk * preceding the &amp;quot;Wrong answer&amp;quot; feedback in the final example means that the student will see this feedback if they enter anything other than &amp;quot;Paris&amp;quot; or &amp;quot;Marseille&amp;quot;.&lt;br /&gt;
* For multiple choice vertical or horizontal rendering there is no automatic numbering, though can added at each answer.&lt;br /&gt;
&lt;br /&gt;
==Detailed syntax explanations==&lt;br /&gt;
# all question items within a cloze-type question are coded inside curled braces { }&lt;br /&gt;
# the number which appears between the opening brace and the colon {1: is the weighting of that item; if it is set at 1 for all the items, it needs not be specified, so you can have {:&lt;br /&gt;
# after the colon we have the item question type: MULTICHOICE, SHORTANSWER, NUMERICAL&lt;br /&gt;
# &#039;&#039;&#039;NOTE&#039;&#039;&#039;.- If you have installed the [https://moodle.org/plugins/qtype_regexp REGEXP question type plugin] you can also use the REGEXP question type; see [https://docs.moodle.org/310/en/Regular_Expression_Short-Answer_question_type#Inserting_RegExp_sub-questions_in_Cloze_type_questions instructions here].&lt;br /&gt;
# the syntax for MULTICHOICE and SHORTANSWER is the same; the only difference is in the displaying of the item to the student&lt;br /&gt;
# the order of the various answers is indifferent (except if you want a catch-all for wrong answers, see #13 below)&lt;br /&gt;
# a correct answer is preceded with the equal sign = or a percentage (usually %100%) - &#039;&#039;&#039;Note&#039;&#039;&#039;: [[Talk:Embedded_Answers_(Cloze)_question_type| The equal sign (=) doesn&#039;t seem to work with SHORTANSWER.]]&lt;br /&gt;
# a wrong answer is preceded with nothing or a percentage (usually %0%)but you can even use negative points by preceding with ~%-25% [not before Moodle 2.0])&lt;br /&gt;
# you can allocate some points between 0 and 100 to some answers, if you put the appropriate percentage&lt;br /&gt;
# all answers except the first one are separated from one another by the tilde ~ sign&lt;br /&gt;
# answers can be followed by an optional feedback message, preceded with the # sign; if there is no feedback message, the # sign can be present or absent, it does not matter&lt;br /&gt;
# note that the feedback message and the correct answer are displayed in a small popup window (if and when the correct and or feedback have been declared accessible to the students in the Quiz settings) upon mouse hovering. The popup window has a title &amp;quot;feedback&amp;quot; and you can use HTML tags to format your feedback. In some browsers (For example IE5.5) the form fields can cover part of the feedback windows. It can help to not have the formfields for the answers too close to each other.&lt;br /&gt;
# in the SHORTANSWER type you may want to put a catch-all (wrong) answer in order to send a &amp;quot;wrong, try again&amp;quot; feedback; you can do this by inserting an asterisk &#039;&#039;&#039;*&#039;&#039;&#039; as &#039;&#039;&#039;the very last expected answer&#039;&#039;&#039; in your formula&lt;br /&gt;
&lt;br /&gt;
==Numerical Cloze questions==	 &lt;br /&gt;
		 &lt;br /&gt;
From the student perspective, a numerical Cloze question looks just like a short-answer question or &#039;&#039;fill in the blanks&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The difference is that numerical answers are allowed to have an accepted error. This allows a continuous range of answers to be set. You can also express your answer in some different numerical formats. 23.4 23,4 (some countries use , as a decimal separator) and 2.34E+1 (meaning 2.34*10^1) would be interpreted as the same.&lt;br /&gt;
&lt;br /&gt;
=== False positives ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; the following examples of false positives do &#039;&#039;&#039;not&#039;&#039;&#039; apply to Moodle 1.8+, where you cannot use percentages or fractions as the answers in a numerical Cloze test; Moodle will generate an error if you try to save such a question. However the following may be relevant for earlier versions of Moodle.&lt;br /&gt;
&lt;br /&gt;
 More examples:	 &lt;br /&gt;
 0.5 accepts .5 0.5 ,5 0,5 0.500 5e-1 5E-1 but not 1/2 50% 	 &lt;br /&gt;
 50% accepts 50% 50.0% 5E1% 50/100 even &#039;&#039;&#039;50/1000 50&#039;&#039;&#039; but not 500/1000 0.5	 &lt;br /&gt;
 1/2 accepts 1/2 &#039;&#039;&#039;1/3 1twenty&#039;&#039;&#039; but not 2/4 0.5 0,5 3/6 50% ½	 &lt;br /&gt;
 ½ accepts ½	 &lt;br /&gt;
 HALF doesn&#039;t even accept HALF (maybe &#039;&#039;&#039;0&#039;&#039;&#039;?)	 &lt;br /&gt;
&lt;br /&gt;
If you want to accept several variants you can have them in the same {} but &#039;&#039;&#039;be careful, notice the &amp;quot;false positives&amp;quot; in bold&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
===Syntax for numerical Cloze questions===&lt;br /&gt;
&lt;br /&gt;
The format of a NUMERICAL Cloze question is similar to that of the other Cloze types and they can be mixed in the same question. As with other Cloze tests, you write your question or incomplete text, and add the Cloze code at the point where the student is supposed to enter their numerical answer.&lt;br /&gt;
&lt;br /&gt;
An example of the syntax used is shown below:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: &#039;&#039;&#039; It is preferable to write the code in &#039;source code&#039; mode. The WSIWYG editor can insert linebreaks that make the question not function. The linebreak in the example box below is for readability only! A problem with these questions is the readability of the code! :(	&lt;br /&gt;
		 &lt;br /&gt;
 {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8	 &lt;br /&gt;
 ~%50%23.8:2#Feedback for ½credit near correct answer}. 	 &lt;br /&gt;
	 &lt;br /&gt;
In this example:&lt;br /&gt;
* 2: is the question point weight, which means that this question has twice the weight in the final point(s) for this question as other partial answers with weight 1 (or no declared weight - you can start with {: for the default weight 1) in the same question.&lt;br /&gt;
* NUMERICAL: says what kind of question it is. It must be in CAPS. &lt;br /&gt;
* =23.8:0.1 = or %100% means correct if the answer is 23.8 with an accepted error of 0.1, then any number between 23.7 and 23.9 will be accepted as correct. (In the GIFT numerical question one can express an interval like this 13..15 or 14:1 but in Cloze only 14:1 works.)	 &lt;br /&gt;
* #Feedback for correct answer 23.8 is preceded by #&lt;br /&gt;
* ~%50%23.8:2 ~ is the separator for answer alternatives %50% means this answer would get 50% of the score that the more precise answer had gotten. Because the tolerance here is 2, 21.8 to 25.8 would get this point and feedback.&lt;br /&gt;
&lt;br /&gt;
The feedback (which is seen within a popup window when the user hovers over the answer space) is formattable with HTML tags. For example, if you want an exponent, surround it with superscript tags: &amp;amp;lt;sup&amp;amp;gt; &amp;amp;lt;/sup&amp;amp;gt;. You can even include pictures in the feedback popup, but you must clean out all &amp;quot; characters and save while still in source code mode (not WYSIWYG). So, this works in feedback popup:&lt;br /&gt;
 #See this picture:&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;img src=Something.gif /&amp;gt;}	 &lt;br /&gt;
but not this:&lt;br /&gt;
 #See this picture:&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;img src=&amp;quot;Something.gif&amp;quot; /&amp;gt;}	 &lt;br /&gt;
&lt;br /&gt;
(ALGEBRA and TEX filters don&#039;t work in the feedback popups, but they can be very useful in the question writing for math/science expressions). But you can use [[Unicode]] characters.	 &lt;br /&gt;
&lt;br /&gt;
If you want to give feedback for any answer that didn&#039;t fit the intervals you already have specified feedback for, add some BIG general intervals, like for positive answers (if they aren&#039;t bigger than 20000 you could add:	 &lt;br /&gt;
 ~%0%10000.0001:10000#Feedback for unspecified not_right answers}	 &lt;br /&gt;
This would give feedback for anything from 0.0001 to 20000.0001 (that hadn&#039;t already gotten feedback). I didn&#039;t want to include 0 since that special case as well as negative ought to have specific reactions.	 &lt;br /&gt;
 ~%0%0#Hey! It can&#039;t be zero	 &lt;br /&gt;
 ~%0%-10000.0001:10000#We just want the size here,	 &lt;br /&gt;
 so a negative value is not what we want}			 &lt;br /&gt;
&lt;br /&gt;
Numerical questions could, before version 1.7, also have case-insensitive non-numerical answers. This is useful whenever the answer for a numerical question is something like +inf, -inf, NaN etc.&lt;br /&gt;
==Importing CLOZE questions==&lt;br /&gt;
If you try importing directly as CLOZE this text:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Single line per question! Match the following cities with the correct state:&lt;br /&gt;
* San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
* Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}&lt;br /&gt;
* Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
* Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}&lt;br /&gt;
&lt;br /&gt;
The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!~%50%Marseille#No, that is the second largest city in France (after Paris).~*#Wrong answer. The capital of France is Paris, of course.}.&lt;br /&gt;
&lt;br /&gt;
23+ 0.8 = {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8 ~%50%23.8:2#Feedback for ½credit near correct answer}. 	 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would get all three questions as different parts of &#039;&#039;&#039;ONE question&#039;&#039;&#039;. (NOTE see that there are no linebreaks between the { } !)&lt;br /&gt;
&lt;br /&gt;
Multiple CLOZE questions can be imported using the XML format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;quiz&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- question: 1  --&amp;gt;&lt;br /&gt;
&amp;lt;question type=&amp;quot;cloze&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;&amp;lt;text&amp;gt;Book Test #1&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;questiontext&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;![CDATA[..............]]&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/questiontext&amp;gt;&lt;br /&gt;
&amp;lt;generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;shuffleanswers&amp;gt;0&amp;lt;/shuffleanswers&amp;gt;&lt;br /&gt;
&amp;lt;/question&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- question: 2 --&amp;gt;&lt;br /&gt;
&amp;lt;question type=&amp;quot;cloze&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;&amp;lt;text&amp;gt;Book Test #2&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;questiontext&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;![CDATA[............]]&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/questiontext&amp;gt;&lt;br /&gt;
&amp;lt;generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;shuffleanswers&amp;gt;0&amp;lt;/shuffleanswers&amp;gt;&lt;br /&gt;
&amp;lt;/question&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You would put the question text including CLOZE code in the  .......  spaces.&lt;br /&gt;
&lt;br /&gt;
==Online Cloze Question generator==&lt;br /&gt;
* There is a website to generate CLOZE quizzes for Moodle (1.9 and 2.x and 3.x versions) and/or to try out the CLOZE editor integration for Moodle.&lt;br /&gt;
* This editor was built at the Chair of Applied English Linguistics at Universitaet Tuebingen, Germany, by Andreas Glombitza (andiglombitza(at)googlemail.com) and Achim Skuta (achim.skuta(at)googlemail.com).&lt;br /&gt;
* The authors are currently maintaining this software and webservice as a private project.&lt;br /&gt;
&lt;br /&gt;
Website: [http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php]&lt;br /&gt;
 &lt;br /&gt;
==Cloze editor plugin for TinyMCE==&lt;br /&gt;
* You can download a [https://moodle.org/plugins/view.php?plugin=other_cloze Moodle plugin from the Moodle plugins database] that will let you create these questions from a graphical interface within your Moodle site. There are versions available for Moodle 1.9, 2.x and 3.x.&lt;br /&gt;
&lt;br /&gt;
==Cloze editor plugin for Atto==&lt;br /&gt;
This [[Cloze editor for Atto|new plugin for Moodle 3.1+]] was developed by Daniel Thies and is available for download and install from the Moodle plugins database..&lt;br /&gt;
&lt;br /&gt;
==Question with 1 media (e.g. audio) and several subquestions==&lt;br /&gt;
As described in [https://moodle.org/mod/forum/discuss.php?d=376874 this forum post], you can easily make a question where the student inspect a media (e.g. an audio file) and then has to answer several small multiple choice questions. The example below is from a Moodle 3.5.2+ site using the new Record audio tool in the Atto editor. The Record video tool will also let you add video as part of the question, if you want to.&lt;br /&gt;
&lt;br /&gt;
[[File:CLOZE question with 1 audio and 3 sub-questions.png|400px]]&lt;br /&gt;
&lt;br /&gt;
== Questions with student notes and feedback for teacher==&lt;br /&gt;
You can easily make one/many/all question(s) with an optional field for student notes and/or feedback for the teacher, as requested in [https://moodle.org/mod/forum/discuss.php?d=353587 this forum thread]. Note that only the first MULTICHOICE question is marked, and the two optional fields do not score positive nor negative points:&lt;br /&gt;
&lt;br /&gt;
[[File:CLOZE question with student comment and teacher feedback.png]]&lt;br /&gt;
&lt;br /&gt;
The full question for the above example is:&lt;br /&gt;
&lt;br /&gt;
 Which of the following options is the right answer ?&lt;br /&gt;
 {1:MULTICHOICE_VS:~A wrong answer~Another wrong answer~Yet another wrong answer~%100%This is the only right answer}&lt;br /&gt;
 Optionally:Write a personal note: {0:SHORTANSWER:~%0%I want to have a longer input box for the note.~%100%*}&lt;br /&gt;
 Optionally:Send feedback to teacher:{0:SHORTANSWER:~%0%I want to have a longer input box for the feedback.~%100%*}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* See the [http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php online Cloze question generator].&lt;br /&gt;
* Download the newest version of the [[Cloze editor for TinyMCE]] for Moodle 1.9 and for Moodle 2.0 to 3.3 from [https://moodle.org/plugins/view.php?plugin=tinymce_clozeeditor the Moodle plugins database]&lt;br /&gt;
* Easily edit embedded answer questions with the additional plugin [[Cloze editor for Atto]] for Moodle 2.7+&lt;br /&gt;
&lt;br /&gt;
This information was drawn from:&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=36521 Is there a guide to using the cloze format?] forum discussion&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=36430&amp;amp;parent=170308 Cloze-type question syntax] forum post&lt;br /&gt;
&lt;br /&gt;
[[Category:Language teaching]]&lt;br /&gt;
&lt;br /&gt;
[[de:Fragetyp Lückentext (Cloze)]]&lt;br /&gt;
[[es:Tipo de Pregunta con respuestas incrustadas (Cloze)]]&lt;br /&gt;
[[fr:Question Cloze à réponses intégrées]]&lt;br /&gt;
[[ja: 穴埋め問題 ( Cloze ) タイプ]]&lt;br /&gt;
[[zh:填空題(克漏字)]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Embedded_Answers_(Cloze)_question_type&amp;diff=132992</id>
		<title>Embedded Answers (Cloze) question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Embedded_Answers_(Cloze)_question_type&amp;diff=132992"/>
		<updated>2019-01-18T08:58:32Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
&#039;&#039;&#039;Embedded answers (Cloze)&#039;&#039;&#039; questions consist of a passage of text (in Moodle format) that has various answers embedded within it, including multiple choice, short answers and numerical answers.&lt;br /&gt;
&lt;br /&gt;
Until mid2013, there was no graphical interface to create these questions within your Moodle site - you needed to specify the question format using the text box or by importing them from external files.&lt;br /&gt;
&lt;br /&gt;
You can link to an external web site that does create these questions from a graphical interface, see the &#039;&#039;[http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php Online Cloze Question quiz generator]&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
There is an Excel-based [http://hbwubecc.wixsite.com/jordan/tools Cloze and GIFT Generator] that was presented at the 2017 Moodle Moot Japan.&lt;br /&gt;
&lt;br /&gt;
There is a [[Cloze editor for TinyMCE]] that will let you create these questions from a graphical interface within your Moodle site, but it will overwrite your current HTML editor and only works with the [[TinyMCE editor]] but not with [[Atto]]. In 2016 a [[Cloze editor for Atto]] additional plugin was created.&lt;br /&gt;
&lt;br /&gt;
Lots of people suggested that [[Hot Potatoes]] software is the easiest way to create Embedded answer (Cloze) questions.  Once you have created your questions on your PC, you can then import them into Moodle&#039;s quiz module.&lt;br /&gt;
&lt;br /&gt;
However, the flexibility of the Cloze question type is hard to equal and despite the minor coding that you need to create the questions, it has great worth in the Moodle Quiz.&lt;br /&gt;
&lt;br /&gt;
==Question set-up==&lt;br /&gt;
&lt;br /&gt;
#Select the question category&lt;br /&gt;
#Give the question a descriptive name - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter the passage of text (in Moodle format - see [[Embedded_Answers_%28Cloze%29_question_type#Format|Format]] below) into the &#039;question text&#039; field.&lt;br /&gt;
#Select an image to display if you want to add a picture to the question. For the student, it appears immediately above the question text.&lt;br /&gt;
#Set the &#039;default question grade&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;Penalty factor&#039; (see [[Embedded_Answers_%28Cloze%29_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#The editor has been modified and allows you to test if your syntax is good. The different questions elements decoded will be displayed and syntax errors pinpoint. However, it cannot check if the question decoded is two questions in one because of an error syntax.&lt;br /&gt;
#Click Save changes to add the question to the category.&lt;br /&gt;
&lt;br /&gt;
=== Penalty factor ===&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; only applies when the question is used in a quiz using adaptive mode - i.e. where the student is allowed multiple attempts at a question even within the same attempt at the quiz. If the penalty factor is more than 0, then the student will lose that proportion of the &#039;&#039;&#039;maximum&#039;&#039;&#039; grade upon each successive attempt. For example, if the default question grade is 10, and the penalty factor is 0.2, then each successive attempt after the first one will incur a penalty of 0.2 x 10 = 2 points.  The grading for the cloze question applies the penalty to each subpart of the question as a whole.  For example, if you have three fill in the blanks each worth 1 point each, then the penalty will only be incurred on the incorrect parts, not the questions as a whole.&lt;br /&gt;
&lt;br /&gt;
==Question rendering==&lt;br /&gt;
&lt;br /&gt;
The question answer entry space or INPUT HTML ELEMENT (for Short Answer and Numerical question types) and the dropdown list or SELECT HTML ELEMENT (for multichoice) are normally displayed in-line with the text.&lt;br /&gt;
&lt;br /&gt;
The size of the entry space or INPUT HTML ELEMENT ( Short and Numerical) will be adjustable to the length of the longest answer (good or bad) + a random number (0 to 15% total length).([[User:Pierre Pichet|Pierre Pichet]] 15:37, 26 January 2008 (CST))&lt;br /&gt;
&lt;br /&gt;
The size will adjust to the length of the student response when displayed in the grading and feedback process.&lt;br /&gt;
&lt;br /&gt;
The size of the dropdown list or SELECT HTML ELEMENT (multichoice) adjusts itself automatically to the longest answer.&lt;br /&gt;
&lt;br /&gt;
==Format==&lt;br /&gt;
&lt;br /&gt;
Questions consist of a passage of text (in Moodle format) that has various sub-questions embedded within it, including&lt;br /&gt;
&lt;br /&gt;
* short answers (SHORTANSWER or SA or MW), case is unimportant,&lt;br /&gt;
* short answers (SHORTANSWER_C or SAC or MWC), case must match,&lt;br /&gt;
* numerical answers (NUMERICAL or NM),&lt;br /&gt;
* multiple choice (MULTICHOICE or MC), represented as a dropdown menu in-line in the text,&lt;br /&gt;
* multiple choice (MULTICHOICE_V or MCV), represented as a vertical column of radio buttons, or&lt;br /&gt;
* multiple choice (MULTICHOICE_H or MCH), represented as a horizontal row of radio-buttons,&lt;br /&gt;
* multiple choice (MULTIRESPONSE or MR), represented as a vertical row of checkboxes&lt;br /&gt;
* multiple choice (MULTIRESPONSE_H or MRH), represented as a horizontal row of checkboxes&lt;br /&gt;
* When the quiz question behavior shuffle option is set to &#039;&#039;&#039;YES&#039;&#039;&#039;, the following special multiple choice sub-questions elements will be shuffled:&lt;br /&gt;
** multiple choice (MULTICHOICE_S or MCS), represented as a dropdown menu in-line in the text,&lt;br /&gt;
** multiple choice (MULTICHOICE_VS or MCVS), represented as a vertical column of radio buttons, or&lt;br /&gt;
** multiple choice (MULTICHOICE_HS or MCHS), represented as a horizontal row of radio-buttons.&lt;br /&gt;
** multiple choice (MULTIRESPONSE_S or MRS), represented as a vertical row of checkboxes&lt;br /&gt;
** multiple choice (MULTIRESPONSE_HS or MRHS), represented as a horizontal row of checkboxes&lt;br /&gt;
&lt;br /&gt;
{{Note|MCS, MCVS, MCHS are new (Moodle 3.0) Cloze subquestion types with shuffling of answers. See MDL-38214.}}&lt;br /&gt;
&lt;br /&gt;
The structure of  each cloze sub-question is identical:&lt;br /&gt;
:&#039;&#039;&#039;{&#039;&#039;&#039;  start the cloze sub-question with a bracket (AltGr+7)&lt;br /&gt;
:&#039;&#039;&#039;1&#039;&#039;&#039; define a grade for each cloze by  a number (optional). This used for calculation of question grading.&lt;br /&gt;
:&#039;&#039;&#039;:SHORTANSWER:&#039;&#039;&#039; define the type of cloze sub-question. Definition is bounded by &#039;:&#039;. &lt;br /&gt;
:&#039;&#039;&#039;~&#039;&#039;&#039; is a seperator between answer options&lt;br /&gt;
:&#039;&#039;&#039;=&#039;&#039;&#039; marks a correct answer&lt;br /&gt;
:&#039;&#039;&#039;#&#039;&#039;&#039; marks the beginning of an (optional) feedback message&lt;br /&gt;
:&#039;&#039;&#039;}&#039;&#039;&#039;  close the cloze sub-question at the end with a bracket (AltGr+0)&lt;br /&gt;
&lt;br /&gt;
Now a very simple example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{1:SHORTANSWER:=Berlin} is the capital of Germany.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For full details of the format for embedded-answers questions, see the [[Embedded_Answers_%28Cloze%29_question_type#Detailed_syntax_explanations|detailed syntax explanation]] below.&lt;br /&gt;
&lt;br /&gt;
NB: Be careful when copying a cloze type question into the WYSIWYG HTML editor, as line breaks tend to get added, which destroys the question.&lt;br /&gt;
&lt;br /&gt;
If the correct answer contains } # ~ / &amp;quot; or \ you will have to escape them by putting a \ in front of each such character. But [[https://moodle.org/mod/forum/discuss.php?d=275299 this is tricky]]. The { shouldn&#039;t be escaped, this can be vital in getting TeX expressions to work. In the feedback ~ and } must be escaped otherwise it will be interpreted as &#039;&#039;the next answer&#039;&#039; or &#039;&#039;end of the short answer section&#039;&#039; respectively. Quotation signs: &amp;quot; can lead to trouble anyhow in both places. Use the HTML entity: &amp;amp; quot; (without the space between &#039;&#039;&amp;amp;&#039;&#039; and &#039;&#039;quot;&#039;&#039;). If you want to have Mathematical symbols there can be problems with the \ used in TeX expressions. One alternative can be to use [[unicode]] characters. &lt;br /&gt;
&lt;br /&gt;
See the notes further down about numerical embedded question!&lt;br /&gt;
&lt;br /&gt;
===Examples===&lt;br /&gt;
&lt;br /&gt;
====Example 1====&lt;br /&gt;
The following text creates a simple embedded-answers question:&lt;br /&gt;
&lt;br /&gt;
 Match the following cities with the correct state:&lt;br /&gt;
 * San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
 * Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}&lt;br /&gt;
 * Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
 * Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}&lt;br /&gt;
 The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!&lt;br /&gt;
 ~%50%Marseille#No, that is the second largest city in France (after&lt;br /&gt;
 Paris).~*#Wrong answer. The capital of France is Paris, of course.}.&lt;br /&gt;
&lt;br /&gt;
And the result will be:&lt;br /&gt;
 &lt;br /&gt;
[[Image:Cloze.gif|Cloze question type]] &lt;br /&gt;
&lt;br /&gt;
====Example 2====&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding: 1em;border: 1px dashed #FFB53A;color: black;background-color: #f9f9f9;font-family: monospace;font-size:1.2em;&amp;quot;&amp;gt;&lt;br /&gt;
This question consists of some text with an answer embedded right here {1:MULTICHOICE:Wrong answer#Feedback for this wrong answer~Another wrong answer#Feedback for the other wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer}&lt;br /&gt;
&lt;br /&gt;
and right after that you will have to deal with this short answer {1:SHORTANSWER:Wrong answer#Feedback for this wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer}&lt;br /&gt;
&lt;br /&gt;
and finally we have a floating point number {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8~%50%23.8:2#Feedback for half credit answer in the nearby region of the correct answer}.&lt;br /&gt;
&lt;br /&gt;
The  multichoice question can also be shown in the vertical display of the standard moodle multiple choice.&lt;br /&gt;
{2:MCV:1. Wrong answer#Feedback for this wrong answer~2. Another wrong answer#Feedback for the other wrong answer~=3. Correct answer#Feedback for correct answer~%50%4. Answer that gives half the credit#Feedback for half credit answer}&lt;br /&gt;
&lt;br /&gt;
Or in an horizontal display that is included here in a table&lt;br /&gt;
{2:MCH:a. Wrong answer#Feedback for this wrong answer~b. Another wrong answer#Feedback for the other wrong answer~=c. Correct answer#Feedback for correct answer~%50%d. Answer that gives half the credit#Feedback for half credit answer}&lt;br /&gt;
&lt;br /&gt;
A shortanswer question where case must match. Write moodle in upper case letters {1:SHORTANSWER_C:moodle#Feedback for moodle in lower case ~=MOODLE#Feedback for MOODLE in upper case ~%50%Moodle#Feedback for only first letter in upper case}&lt;br /&gt;
&lt;br /&gt;
Note that addresses like www.moodle.org and smileys :-) all work as normal:&lt;br /&gt;
&lt;br /&gt;
a) How good is this? {:MULTICHOICE:=Yes#Correct~No#We have a different opinion}&lt;br /&gt;
&lt;br /&gt;
b) What grade would you give it? {3:NUMERICAL:=3:2}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
[[Image:Cloze example.png]]&lt;br /&gt;
&lt;br /&gt;
Some things to note:&lt;br /&gt;
* The individual embedded answers are represented by the code in braces {}.&lt;br /&gt;
* The number at the start is the &#039;weight&#039;, so in this case each answer contributes an equal share of the overall grade.&lt;br /&gt;
* The correct option in each case is preceded either by an = sign or by %100%. &lt;br /&gt;
* The text appearing after the # that follows each option is the feedback that the student will see if they choose that option.&lt;br /&gt;
* If the student enters &#039;Marseille&#039; in the final example, they score 50% of the total grade.&lt;br /&gt;
* The asterisk * preceding the &amp;quot;Wrong answer&amp;quot; feedback in the final example means that the student will see this feedback if they enter anything other than &amp;quot;Paris&amp;quot; or &amp;quot;Marseille&amp;quot;.&lt;br /&gt;
* For multiple choice vertical or horizontal rendering there is no automatic numbering, though can added at each answer.&lt;br /&gt;
&lt;br /&gt;
==Detailed syntax explanations==&lt;br /&gt;
# all question items within a cloze-type question are coded inside curled braces { }&lt;br /&gt;
# the number which appears between the opening brace and the colon {1: is the weighting of that item; if it is set at 1 for all the items, it needs not be specified, so you can have {:&lt;br /&gt;
# after the colon we have the item question type: MULTICHOICE, SHORTANSWER, NUMERICAL&lt;br /&gt;
# &#039;&#039;&#039;NOTE&#039;&#039;&#039;.- If you have installed the [https://moodle.org/plugins/qtype_regexp REGEXP question type plugin] you can also use the REGEXP question type; see [https://docs.moodle.org/310/en/Regular_Expression_Short-Answer_question_type#Inserting_RegExp_sub-questions_in_Cloze_type_questions instructions here].&lt;br /&gt;
# the syntax for MULTICHOICE and SHORTANSWER is the same; the only difference is in the displaying of the item to the student&lt;br /&gt;
# the order of the various answers is indifferent (except if you want a catch-all for wrong answers, see #13 below)&lt;br /&gt;
# a correct answer is preceded with the equal sign = or a percentage (usually %100%) - &#039;&#039;&#039;Note&#039;&#039;&#039;: [[Talk:Embedded_Answers_(Cloze)_question_type| The equal sign (=) doesn&#039;t seem to work with SHORTANSWER.]]&lt;br /&gt;
# a wrong answer is preceded with nothing or a percentage (usually %0%)but you can even use negative points by preceding with ~%-25% [not before Moodle 2.0])&lt;br /&gt;
# you can allocate some points between 0 and 100 to some answers, if you put the appropriate percentage&lt;br /&gt;
# all answers except the first one are separated from one another by the tilde ~ sign&lt;br /&gt;
# answers can be followed by an optional feedback message, preceded with the # sign; if there is no feedback message, the # sign can be present or absent, it does not matter&lt;br /&gt;
# note that the feedback message and the correct answer are displayed in a small popup window (if and when the correct and or feedback have been declared accessible to the students in the Quiz settings) upon mouse hovering. The popup window has a title &amp;quot;feedback&amp;quot; and you can use HTML tags to format your feedback. In some browsers (For example IE5.5) the form fields can cover part of the feedback windows. It can help to not have the formfields for the answers too close to each other.&lt;br /&gt;
# in the SHORTANSWER type you may want to put a catch-all (wrong) answer in order to send a &amp;quot;wrong, try again&amp;quot; feedback; you can do this by inserting an asterisk &#039;&#039;&#039;*&#039;&#039;&#039; as &#039;&#039;&#039;the very last expected answer&#039;&#039;&#039; in your formula&lt;br /&gt;
&lt;br /&gt;
==Numerical Cloze questions==	 &lt;br /&gt;
		 &lt;br /&gt;
From the student perspective, a numerical Cloze question looks just like a short-answer question or &#039;&#039;fill in the blanks&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The difference is that numerical answers are allowed to have an accepted error. This allows a continuous range of answers to be set. You can also express your answer in some different numerical formats. 23.4 23,4 (some countries use , as a decimal separator) and 2.34E+1 (meaning 2.34*10^1) would be interpreted as the same.&lt;br /&gt;
&lt;br /&gt;
=== False positives ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; the following examples of false positives do &#039;&#039;&#039;not&#039;&#039;&#039; apply to Moodle 1.8+, where you cannot use percentages or fractions as the answers in a numerical Cloze test; Moodle will generate an error if you try to save such a question. However the following may be relevant for earlier versions of Moodle.&lt;br /&gt;
&lt;br /&gt;
 More examples:	 &lt;br /&gt;
 0.5 accepts .5 0.5 ,5 0,5 0.500 5e-1 5E-1 but not 1/2 50% 	 &lt;br /&gt;
 50% accepts 50% 50.0% 5E1% 50/100 even &#039;&#039;&#039;50/1000 50&#039;&#039;&#039; but not 500/1000 0.5	 &lt;br /&gt;
 1/2 accepts 1/2 &#039;&#039;&#039;1/3 1twenty&#039;&#039;&#039; but not 2/4 0.5 0,5 3/6 50% ½	 &lt;br /&gt;
 ½ accepts ½	 &lt;br /&gt;
 HALF doesn&#039;t even accept HALF (maybe &#039;&#039;&#039;0&#039;&#039;&#039;?)	 &lt;br /&gt;
&lt;br /&gt;
If you want to accept several variants you can have them in the same {} but &#039;&#039;&#039;be careful, notice the &amp;quot;false positives&amp;quot; in bold&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
===Syntax for numerical Cloze questions===&lt;br /&gt;
&lt;br /&gt;
The format of a NUMERICAL Cloze question is similar to that of the other Cloze types and they can be mixed in the same question. As with other Cloze tests, you write your question or incomplete text, and add the Cloze code at the point where the student is supposed to enter their numerical answer.&lt;br /&gt;
&lt;br /&gt;
An example of the syntax used is shown below:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: &#039;&#039;&#039; It is preferable to write the code in &#039;source code&#039; mode. The WSIWYG editor can insert linebreaks that make the question not function. The linebreak in the example box below is for readability only! A problem with these questions is the readability of the code! :(	&lt;br /&gt;
		 &lt;br /&gt;
 {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8	 &lt;br /&gt;
 ~%50%23.8:2#Feedback for ½credit near correct answer}. 	 &lt;br /&gt;
	 &lt;br /&gt;
In this example:&lt;br /&gt;
* 2: is the question point weight, which means that this question has twice the weight in the final point(s) for this question as other partial answers with weight 1 (or no declared weight - you can start with {: for the default weight 1) in the same question.&lt;br /&gt;
* NUMERICAL: says what kind of question it is. It must be in CAPS. &lt;br /&gt;
* =23.8:0.1 = or %100% means correct if the answer is 23.8 with an accepted error of 0.1, then any number between 23.7 and 23.9 will be accepted as correct. (In the GIFT numerical question one can express an interval like this 13..15 or 14:1 but in Cloze only 14:1 works.)	 &lt;br /&gt;
* #Feedback for correct answer 23.8 is preceded by #&lt;br /&gt;
* ~%50%23.8:2 ~ is the separator for answer alternatives %50% means this answer would get 50% of the score that the more precise answer had gotten. Because the tolerance here is 2, 21.8 to 25.8 would get this point and feedback.&lt;br /&gt;
&lt;br /&gt;
The feedback (which is seen within a popup window when the user hovers over the answer space) is formattable with HTML tags. For example, if you want an exponent, surround it with superscript tags: &amp;amp;lt;sup&amp;amp;gt; &amp;amp;lt;/sup&amp;amp;gt;. You can even include pictures in the feedback popup, but you must clean out all &amp;quot; characters and save while still in source code mode (not WYSIWYG). So, this works in feedback popup:&lt;br /&gt;
 #See this picture:&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;img src=Something.gif /&amp;gt;}	 &lt;br /&gt;
but not this:&lt;br /&gt;
 #See this picture:&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;img src=&amp;quot;Something.gif&amp;quot; /&amp;gt;}	 &lt;br /&gt;
&lt;br /&gt;
(ALGEBRA and TEX filters don&#039;t work in the feedback popups, but they can be very useful in the question writing for math/science expressions). But you can use [[Unicode]] characters.	 &lt;br /&gt;
&lt;br /&gt;
If you want to give feedback for any answer that didn&#039;t fit the intervals you already have specified feedback for, add some BIG general intervals, like for positive answers (if they aren&#039;t bigger than 20000 you could add:	 &lt;br /&gt;
 ~%0%10000.0001:10000#Feedback for unspecified not_right answers}	 &lt;br /&gt;
This would give feedback for anything from 0.0001 to 20000.0001 (that hadn&#039;t already gotten feedback). I didn&#039;t want to include 0 since that special case as well as negative ought to have specific reactions.	 &lt;br /&gt;
 ~%0%0#Hey! It can&#039;t be zero	 &lt;br /&gt;
 ~%0%-10000.0001:10000#We just want the size here,	 &lt;br /&gt;
 so a negative value is not what we want}			 &lt;br /&gt;
&lt;br /&gt;
Numerical questions could, before version 1.7, also have case-insensitive non-numerical answers. This is useful whenever the answer for a numerical question is something like +inf, -inf, NaN etc.&lt;br /&gt;
==Importing CLOZE questions==&lt;br /&gt;
If you try importing directly as CLOZE this text:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Single line per question! Match the following cities with the correct state:&lt;br /&gt;
* San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
* Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}&lt;br /&gt;
* Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
* Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}&lt;br /&gt;
&lt;br /&gt;
The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!~%50%Marseille#No, that is the second largest city in France (after Paris).~*#Wrong answer. The capital of France is Paris, of course.}.&lt;br /&gt;
&lt;br /&gt;
23+ 0.8 = {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8 ~%50%23.8:2#Feedback for ½credit near correct answer}. 	 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would get all three questions as different parts of &#039;&#039;&#039;ONE question&#039;&#039;&#039;. (NOTE see that there are no linebreaks between the { } !)&lt;br /&gt;
&lt;br /&gt;
Multiple CLOZE questions can be imported using the XML format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;quiz&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- question: 1  --&amp;gt;&lt;br /&gt;
&amp;lt;question type=&amp;quot;cloze&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;&amp;lt;text&amp;gt;Book Test #1&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;questiontext&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;![CDATA[..............]]&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/questiontext&amp;gt;&lt;br /&gt;
&amp;lt;generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;shuffleanswers&amp;gt;0&amp;lt;/shuffleanswers&amp;gt;&lt;br /&gt;
&amp;lt;/question&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- question: 2 --&amp;gt;&lt;br /&gt;
&amp;lt;question type=&amp;quot;cloze&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;&amp;lt;text&amp;gt;Book Test #2&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;questiontext&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;![CDATA[............]]&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/questiontext&amp;gt;&lt;br /&gt;
&amp;lt;generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;shuffleanswers&amp;gt;0&amp;lt;/shuffleanswers&amp;gt;&lt;br /&gt;
&amp;lt;/question&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You would put the question text including CLOZE code in the  .......  spaces.&lt;br /&gt;
&lt;br /&gt;
==Online Cloze Question generator==&lt;br /&gt;
* There is a website to generate CLOZE quizzes for Moodle (1.9 and 2.x and 3.x versions) and/or to try out the CLOZE editor integration for Moodle.&lt;br /&gt;
* This editor was built at the Chair of Applied English Linguistics at Universitaet Tuebingen, Germany, by Andreas Glombitza (andiglombitza(at)googlemail.com) and Achim Skuta (achim.skuta(at)googlemail.com).&lt;br /&gt;
* The authors are currently maintaining this software and webservice as a private project.&lt;br /&gt;
&lt;br /&gt;
Website: [http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php]&lt;br /&gt;
 &lt;br /&gt;
==Cloze editor plugin for TinyMCE==&lt;br /&gt;
* You can download a [https://moodle.org/plugins/view.php?plugin=other_cloze Moodle plugin from the Moodle plugins database] that will let you create these questions from a graphical interface within your Moodle site. There are versions available for Moodle 1.9, 2.x and 3.x.&lt;br /&gt;
&lt;br /&gt;
==Cloze editor plugin for Atto==&lt;br /&gt;
This [[Cloze editor for Atto|new plugin for Moodle 3.1+]] was developed by Daniel Thies and is available for download and install from the Moodle plugins database..&lt;br /&gt;
&lt;br /&gt;
==Question with 1 media (e.g. audio) and several subquestions==&lt;br /&gt;
As described in [https://moodle.org/mod/forum/discuss.php?d=376874 this forum post], you can easily make a question where the student inspect a media (e.g. an audio file) and then has to answer several small multiple choice questions. The example below is from a Moodle 3.5.2+ site using the new Record audio tool in the Atto editor. The Record video tool will also let you add video as part of the question, if you want to.&lt;br /&gt;
&lt;br /&gt;
[[File:CLOZE question with 1 audio and 3 sub-questions.png|400px]]&lt;br /&gt;
&lt;br /&gt;
== Questions with student notes and feedback for teacher==&lt;br /&gt;
You can easily make one/many/all question(s) with an optional field for student notes and/or feedback for the teacher, as requested in [https://moodle.org/mod/forum/discuss.php?d=353587 this forum thread]. Note that only the first MULTICHOICE question is marked, and the two optional fields do not score positive nor negative points:&lt;br /&gt;
&lt;br /&gt;
[[File:CLOZE question with student comment and teacher feedback.png]]&lt;br /&gt;
&lt;br /&gt;
The full question for the above example is:&lt;br /&gt;
&lt;br /&gt;
 Which of the following options is the right answer ?&lt;br /&gt;
 {1:MULTICHOICE_VS:~A wrong answer~Another wrong answer~Yet another wrong answer~%100%This is the only right answer}&lt;br /&gt;
 Optionally:Write a personal note: {0:SHORTANSWER:~%0%I want to have a longer input box for the note.~%100%*}&lt;br /&gt;
 Optionally:Send feedback to teacher:{0:SHORTANSWER:~%0%I want to have a longer input box for the feedback.~%100%*}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* See the [http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php online Cloze question generator].&lt;br /&gt;
* Download the newest version of the [[Cloze editor for TinyMCE]] for Moodle 1.9 and for Moodle 2.0 to 3.3 from [https://moodle.org/plugins/view.php?plugin=tinymce_clozeeditor the Moodle plugins database]&lt;br /&gt;
* Easily edit embedded answer questions with the additional plugin [[Cloze editor for Atto]] for Moodle 2.7+&lt;br /&gt;
&lt;br /&gt;
This information was drawn from:&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=36521 Is there a guide to using the cloze format?] forum discussion&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=36430&amp;amp;parent=170308 Cloze-type question syntax] forum post&lt;br /&gt;
&lt;br /&gt;
[[Category:Language teaching]]&lt;br /&gt;
&lt;br /&gt;
[[de:Fragetyp Lückentext (Cloze)]]&lt;br /&gt;
[[es:Tipo de Pregunta con respuestas incrustadas (Cloze)]]&lt;br /&gt;
[[fr:Question Cloze à réponses intégrées]]&lt;br /&gt;
[[ja: 穴埋め問題 ( Cloze ) タイプ]]&lt;br /&gt;
[[zh:填空題(克漏字)]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Debugging&amp;diff=132913</id>
		<title>Debugging</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Debugging&amp;diff=132913"/>
		<updated>2018-12-31T14:47:54Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Debug SQL queries */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Developer tools}}&lt;br /&gt;
==Using debugging messages==&lt;br /&gt;
&lt;br /&gt;
Debugging messages are intended to help diagnose problems and/or help Moodle developers. If you have a problem with your Moodle site and ask for help in a Moodle.org forum, a developer may ask you to turn enable debugging i.e. turn debugging messages on, in order to locate the cause of the problem. If you are having problems such as a blank screen or incomplete screens, then turning on debugging is usually the first thing to try. &lt;br /&gt;
&lt;br /&gt;
==Enabling debugging==&lt;br /&gt;
&lt;br /&gt;
To enable debugging, go to Debugging in the Site administration.&lt;br /&gt;
&lt;br /&gt;
===Debug messages===&lt;br /&gt;
&lt;br /&gt;
The options are:&lt;br /&gt;
&lt;br /&gt;
* NONE: Do not show any errors or warnings (Default) &lt;br /&gt;
* MINIMAL: Show only fatal errors&lt;br /&gt;
* NORMAL: Show warnings, errors and notices&lt;br /&gt;
* ALL: Show all reasonable PHP debug messages&lt;br /&gt;
* DEVELOPER: extra Moodle debug messages for developers&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
&lt;br /&gt;
# It is recommended that a record of error messages is kept, and for the admin to regularly monitor the error logs. This may be done by setting &#039;Debug messages&#039; (debug) to Normal and leaving &#039;Display debug messages&#039; (debugdisplay) off (unticked). Error messages are then recorded in the server logs.&lt;br /&gt;
# If &#039;Debug messages&#039; is set to Developer on a production (public) site, it is recommended to copy and paste the debugging message obtained and then turn off Developer debugging. This is because debugging messages can give clues to a hacker as to the set-up of your site.&lt;br /&gt;
&lt;br /&gt;
===Debug email sending===&lt;br /&gt;
&lt;br /&gt;
Determines whether or not to enable verbose debug information during sending of email messages to SMTP server.&lt;br /&gt;
&lt;br /&gt;
==== More tools for debugging outgoing mail (SMTP) ====&lt;br /&gt;
You can also use the config.php file to turn on more &amp;quot;tools&amp;quot; which will assist you with debugging the outgoing emails (and SMTP server configuration):&lt;br /&gt;
* Redirect all outgoing emails to a specific address:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Divert all outgoing emails to this address to test and debug emailing features&lt;br /&gt;
// $CFG-&amp;gt;divertallemailsto = &#039;root@localhost.local&#039;; // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Turn on the CRON debugging and run CLI cron.php script.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Force developer level debug and add debug info to the output of cron&lt;br /&gt;
// $CFG-&amp;gt;showcrondebugging = true;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
And then use SSH (or putty.exe, on windows) to run:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
you@moodle-server(/var/www/html/moodle)# php admin/cli/cron.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Turn on verbose SMTP debugging and output it into system&#039;s error_log (code hack):&lt;br /&gt;
As [https://moodle.org/mod/forum/discuss.php?d=316222#p1289850 suggested] on Moodle&#039;s discussion forums:&lt;br /&gt;
Open [https://github.com/moodle/moodle/blob/master/lib/moodlelib.php#L5379 lib/moodlelib.php L5379] and change it to:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($CFG-&amp;gt;debugsmtp)) {&lt;br /&gt;
    $mailer-&amp;gt;SMTPDebug = 1;  // 0 - no debug ... 4 - low level full debug&lt;br /&gt;
    $mailer-&amp;gt;Debugoutput = &amp;quot;error_log&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
See more info about [https://github.com/moodle/moodle/blob/master/lib/phpmailer/class.phpmailer.php#L314 SMTPDebug] parameters &amp;amp; [https://github.com/moodle/moodle/blob/master/lib/phpmailer/class.phpmailer.php#L328 Debugoutput] parameters,&lt;br /&gt;
Set-up mailcatcher (https://mailcatcher.me/).&lt;br /&gt;
&lt;br /&gt;
===Debug SQL queries===&lt;br /&gt;
You can add (turn ON) any of the following dboptions in your config.php files, which log different types of SQL queries into mdl_log_queires table:&lt;br /&gt;
* &#039;&#039;&#039;logall&#039;&#039;&#039; - log all queries - suitable only for developers, causes high server loads and NOT recommended for production.&lt;br /&gt;
* &#039;&#039;&#039;logslow&#039;&#039;&#039; - log queries that take longer than specified number of seconds (float values are accepted).&lt;br /&gt;
* &#039;&#039;&#039;logerrors&#039;&#039;&#039; - log all error queries.&lt;br /&gt;
&lt;br /&gt;
Full sample:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;dboptions = array (&lt;br /&gt;
  //&#039;logall&#039;   =&amp;gt; true,&lt;br /&gt;
  &#039;logslow&#039;  =&amp;gt; 5,&lt;br /&gt;
  &#039;logerrors&#039;  =&amp;gt; true,&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Performance info===&lt;br /&gt;
&lt;br /&gt;
The Performance info option determines whether performance info will be included in the footer of the standard theme (and some other themes). Performance info includes the time for the page to load, the amount of memory used to generate the page, cpu usage, load, and the record cache hit/miss ration.&lt;br /&gt;
&lt;br /&gt;
If you add&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
define(&#039;MDL_PERF&#039;, true);&lt;br /&gt;
define(&#039;MDL_PERFDB&#039;, true);&lt;br /&gt;
define(&#039;MDL_PERFTOLOG&#039;, true);&lt;br /&gt;
define(&#039;MDL_PERFTOFOOT&#039;, true);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
to your config.php file, then it will also count database queries. (This has to be in config.php, because Moodle starts doing DB queries before it loads the config information in the database!)&lt;br /&gt;
&lt;br /&gt;
To hide performance info from ordinary users, see the discussion [https://moodle.org/mod/forum/discuss.php?d=358032 Performance info only for admins?]&lt;br /&gt;
&lt;br /&gt;
===Show origin of language strings===&lt;br /&gt;
&lt;br /&gt;
Helps with [[:dev:Translation|translation]] and also with [[Language customization]]. Sometimes &amp;lt;code&amp;gt;?strings=1&amp;lt;/code&amp;gt; should be added; other times &amp;lt;code&amp;gt;&amp;amp;strings=1&amp;lt;/code&amp;gt;. See the Wikipedia article [http://en.wikipedia.org/wiki/Query_string Query string] for details.&lt;br /&gt;
&lt;br /&gt;
===Show validator links===&lt;br /&gt;
Be careful, read the warning.&lt;br /&gt;
&lt;br /&gt;
===Show page information===&lt;br /&gt;
To show page information printed in the page footer.&lt;br /&gt;
&lt;br /&gt;
==What to do if you cannot get to the admin screens==&lt;br /&gt;
&lt;br /&gt;
If the error is stopping you even getting to the admin screens to turn on debugging, then you can set the debugging setting manually.&lt;br /&gt;
&lt;br /&gt;
===Try typing the URL directly===&lt;br /&gt;
&lt;br /&gt;
The debug settings are at the URL &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;http://.../admin/settings.php?section=debugging&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; on your server. Sometimes that URL will work, even though the pages you need to go to get there (for example the site front page) do not. So it is worth trying to enter that URL directly.&lt;br /&gt;
&lt;br /&gt;
===In config.php===&lt;br /&gt;
&lt;br /&gt;
In [[Configuration file|config.php]] you can uncomment lines (delete the // at the start of the line) under Section 7 to enable debugging for all or just specific users:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//=========================================================================&lt;br /&gt;
// 7. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!!&lt;br /&gt;
//=========================================================================&lt;br /&gt;
//&lt;br /&gt;
// Force a debugging mode regardless the settings in the site administration&lt;br /&gt;
// @error_reporting(E_ALL | E_STRICT);   // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
// @ini_set(&#039;display_errors&#039;, &#039;1&#039;);         // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
// $CFG-&amp;gt;debug = (E_ALL | E_STRICT);   // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
// $CFG-&amp;gt;debugdisplay = 1;              // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
//&lt;br /&gt;
// You can specify a comma separated list of user ids that that always see&lt;br /&gt;
// debug messages, this overrides the debug flag in $CFG-&amp;gt;debug and $CFG-&amp;gt;debugdisplay&lt;br /&gt;
// for these users only.&lt;br /&gt;
// $CFG-&amp;gt;debugusers = &#039;2&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to comment those lines again (reinsert the // at the start of the line) when you have finished diagnosing your problem.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE 1&#039;&#039;&#039;: do not try to modify the config database table directly, it will not work because the values are cached in MUC.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE 2&#039;&#039;&#039;: if you find your config.php does not have the above settings (you have a cut down approx 30 lines config.php) look for a &amp;quot;config-dist.php&amp;quot; file that contains the full details. I would suggest transferring your details in the current config.php file you have into the full config file and renaming that one to &amp;quot;config.php&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Developers can also use [http://xdebug.org/ XDEBUG] (Installed as a module on the Apache server) to further dig into the code, step by step using an [http://xdebug.org/docs/remote XDEBUG client application]. Probably, as part of their favorite IDE. For example: [http://php.netbeans.org/ NetBeans], [http://www.jetbrains.com/phpstorm/ phpStorm] or...&lt;br /&gt;
&lt;br /&gt;
[[es:Depuración]]&lt;br /&gt;
[[fr:Débogage]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Debugging&amp;diff=132912</id>
		<title>Debugging</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Debugging&amp;diff=132912"/>
		<updated>2018-12-31T14:41:19Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Debug email sending */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Developer tools}}&lt;br /&gt;
==Using debugging messages==&lt;br /&gt;
&lt;br /&gt;
Debugging messages are intended to help diagnose problems and/or help Moodle developers. If you have a problem with your Moodle site and ask for help in a Moodle.org forum, a developer may ask you to turn enable debugging i.e. turn debugging messages on, in order to locate the cause of the problem. If you are having problems such as a blank screen or incomplete screens, then turning on debugging is usually the first thing to try. &lt;br /&gt;
&lt;br /&gt;
==Enabling debugging==&lt;br /&gt;
&lt;br /&gt;
To enable debugging, go to Debugging in the Site administration.&lt;br /&gt;
&lt;br /&gt;
===Debug messages===&lt;br /&gt;
&lt;br /&gt;
The options are:&lt;br /&gt;
&lt;br /&gt;
* NONE: Do not show any errors or warnings (Default) &lt;br /&gt;
* MINIMAL: Show only fatal errors&lt;br /&gt;
* NORMAL: Show warnings, errors and notices&lt;br /&gt;
* ALL: Show all reasonable PHP debug messages&lt;br /&gt;
* DEVELOPER: extra Moodle debug messages for developers&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
&lt;br /&gt;
# It is recommended that a record of error messages is kept, and for the admin to regularly monitor the error logs. This may be done by setting &#039;Debug messages&#039; (debug) to Normal and leaving &#039;Display debug messages&#039; (debugdisplay) off (unticked). Error messages are then recorded in the server logs.&lt;br /&gt;
# If &#039;Debug messages&#039; is set to Developer on a production (public) site, it is recommended to copy and paste the debugging message obtained and then turn off Developer debugging. This is because debugging messages can give clues to a hacker as to the set-up of your site.&lt;br /&gt;
&lt;br /&gt;
===Debug email sending===&lt;br /&gt;
&lt;br /&gt;
Determines whether or not to enable verbose debug information during sending of email messages to SMTP server.&lt;br /&gt;
&lt;br /&gt;
==== More tools for debugging outgoing mail (SMTP) ====&lt;br /&gt;
You can also use the config.php file to turn on more &amp;quot;tools&amp;quot; which will assist you with debugging the outgoing emails (and SMTP server configuration):&lt;br /&gt;
* Redirect all outgoing emails to a specific address:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Divert all outgoing emails to this address to test and debug emailing features&lt;br /&gt;
// $CFG-&amp;gt;divertallemailsto = &#039;root@localhost.local&#039;; // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Turn on the CRON debugging and run CLI cron.php script.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Force developer level debug and add debug info to the output of cron&lt;br /&gt;
// $CFG-&amp;gt;showcrondebugging = true;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
And then use SSH (or putty.exe, on windows) to run:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
you@moodle-server(/var/www/html/moodle)# php admin/cli/cron.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Turn on verbose SMTP debugging and output it into system&#039;s error_log (code hack):&lt;br /&gt;
As [https://moodle.org/mod/forum/discuss.php?d=316222#p1289850 suggested] on Moodle&#039;s discussion forums:&lt;br /&gt;
Open [https://github.com/moodle/moodle/blob/master/lib/moodlelib.php#L5379 lib/moodlelib.php L5379] and change it to:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($CFG-&amp;gt;debugsmtp)) {&lt;br /&gt;
    $mailer-&amp;gt;SMTPDebug = 1;  // 0 - no debug ... 4 - low level full debug&lt;br /&gt;
    $mailer-&amp;gt;Debugoutput = &amp;quot;error_log&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
See more info about [https://github.com/moodle/moodle/blob/master/lib/phpmailer/class.phpmailer.php#L314 SMTPDebug] parameters &amp;amp; [https://github.com/moodle/moodle/blob/master/lib/phpmailer/class.phpmailer.php#L328 Debugoutput] parameters,&lt;br /&gt;
Set-up mailcatcher (https://mailcatcher.me/).&lt;br /&gt;
&lt;br /&gt;
===Debug SQL queries===&lt;br /&gt;
You can add (turn ON) any of the following dboptions in your config.php files, which log different types of SQL queries into mdl_log_queires table:&lt;br /&gt;
* logerrors&lt;br /&gt;
* logslow&lt;br /&gt;
* logall (be careful !!! logs all SQL queries and can slow the site, NOT recommended for production)&lt;br /&gt;
Full sample:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;dboptions = array (&lt;br /&gt;
  &#039;dbpersist&#039; =&amp;gt; 0,&lt;br /&gt;
  &#039;dbport&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
  &#039;dbsocket&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
  &#039;logerrors&#039; =&amp;gt; &#039;1&#039;,&lt;br /&gt;
  &#039;logslow&#039; =&amp;gt; &#039;1&#039;,&lt;br /&gt;
  //&#039;logall&#039; =&amp;gt; &#039;1&#039;,&lt;br /&gt;
  &#039;dbcollation&#039; =&amp;gt; &#039;utf8mb4_general_ci&#039;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Performance info===&lt;br /&gt;
&lt;br /&gt;
The Performance info option determines whether performance info will be included in the footer of the standard theme (and some other themes). Performance info includes the time for the page to load, the amount of memory used to generate the page, cpu usage, load, and the record cache hit/miss ration.&lt;br /&gt;
&lt;br /&gt;
If you add&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
define(&#039;MDL_PERF&#039;, true);&lt;br /&gt;
define(&#039;MDL_PERFDB&#039;, true);&lt;br /&gt;
define(&#039;MDL_PERFTOLOG&#039;, true);&lt;br /&gt;
define(&#039;MDL_PERFTOFOOT&#039;, true);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
to your config.php file, then it will also count database queries. (This has to be in config.php, because Moodle starts doing DB queries before it loads the config information in the database!)&lt;br /&gt;
&lt;br /&gt;
To hide performance info from ordinary users, see the discussion [https://moodle.org/mod/forum/discuss.php?d=358032 Performance info only for admins?]&lt;br /&gt;
&lt;br /&gt;
===Show origin of language strings===&lt;br /&gt;
&lt;br /&gt;
Helps with [[:dev:Translation|translation]] and also with [[Language customization]]. Sometimes &amp;lt;code&amp;gt;?strings=1&amp;lt;/code&amp;gt; should be added; other times &amp;lt;code&amp;gt;&amp;amp;strings=1&amp;lt;/code&amp;gt;. See the Wikipedia article [http://en.wikipedia.org/wiki/Query_string Query string] for details.&lt;br /&gt;
&lt;br /&gt;
===Show validator links===&lt;br /&gt;
Be careful, read the warning.&lt;br /&gt;
&lt;br /&gt;
===Show page information===&lt;br /&gt;
To show page information printed in the page footer.&lt;br /&gt;
&lt;br /&gt;
==What to do if you cannot get to the admin screens==&lt;br /&gt;
&lt;br /&gt;
If the error is stopping you even getting to the admin screens to turn on debugging, then you can set the debugging setting manually.&lt;br /&gt;
&lt;br /&gt;
===Try typing the URL directly===&lt;br /&gt;
&lt;br /&gt;
The debug settings are at the URL &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;http://.../admin/settings.php?section=debugging&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; on your server. Sometimes that URL will work, even though the pages you need to go to get there (for example the site front page) do not. So it is worth trying to enter that URL directly.&lt;br /&gt;
&lt;br /&gt;
===In config.php===&lt;br /&gt;
&lt;br /&gt;
In [[Configuration file|config.php]] you can uncomment lines (delete the // at the start of the line) under Section 7 to enable debugging for all or just specific users:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//=========================================================================&lt;br /&gt;
// 7. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!!&lt;br /&gt;
//=========================================================================&lt;br /&gt;
//&lt;br /&gt;
// Force a debugging mode regardless the settings in the site administration&lt;br /&gt;
// @error_reporting(E_ALL | E_STRICT);   // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
// @ini_set(&#039;display_errors&#039;, &#039;1&#039;);         // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
// $CFG-&amp;gt;debug = (E_ALL | E_STRICT);   // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
// $CFG-&amp;gt;debugdisplay = 1;              // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
//&lt;br /&gt;
// You can specify a comma separated list of user ids that that always see&lt;br /&gt;
// debug messages, this overrides the debug flag in $CFG-&amp;gt;debug and $CFG-&amp;gt;debugdisplay&lt;br /&gt;
// for these users only.&lt;br /&gt;
// $CFG-&amp;gt;debugusers = &#039;2&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to comment those lines again (reinsert the // at the start of the line) when you have finished diagnosing your problem.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE 1&#039;&#039;&#039;: do not try to modify the config database table directly, it will not work because the values are cached in MUC.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE 2&#039;&#039;&#039;: if you find your config.php does not have the above settings (you have a cut down approx 30 lines config.php) look for a &amp;quot;config-dist.php&amp;quot; file that contains the full details. I would suggest transferring your details in the current config.php file you have into the full config file and renaming that one to &amp;quot;config.php&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Developers can also use [http://xdebug.org/ XDEBUG] (Installed as a module on the Apache server) to further dig into the code, step by step using an [http://xdebug.org/docs/remote XDEBUG client application]. Probably, as part of their favorite IDE. For example: [http://php.netbeans.org/ NetBeans], [http://www.jetbrains.com/phpstorm/ phpStorm] or...&lt;br /&gt;
&lt;br /&gt;
[[es:Depuración]]&lt;br /&gt;
[[fr:Débogage]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=132847</id>
		<title>ad-hoc contributed reports</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=132847"/>
		<updated>2018-12-19T12:17:41Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Lists &amp;quot;loggedin users&amp;quot; from the last 120 days */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Sitewide reports}}&lt;br /&gt;
==User and Role Report==&lt;br /&gt;
&lt;br /&gt;
===Count number of distinct learners and teachers enrolled per category (including all its sub categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;SELECT COUNT(DISTINCT lra.userid) AS learners, COUNT(DISTINCT tra.userid) as teachers&lt;br /&gt;
FROM prefix_course AS c #, mdl_course_categories AS cats&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments  AS lra ON lra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role_assignments  AS tra ON tra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category = cats.id&lt;br /&gt;
AND (&lt;br /&gt;
	cats.path LIKE &#039;%/CATEGORYID/%&#039; #Replace CATEGORYID with the category id you want to count (eg: 80)&lt;br /&gt;
	OR cats.path LIKE &#039;%/CATEGORYID&#039;&lt;br /&gt;
	)&lt;br /&gt;
AND lra.roleid=5&lt;br /&gt;
AND tra.roleid=3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each ROLE (TEACHER, NON-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT r.name, l.action, COUNT( l.userid ) AS counter&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_role AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE ra.roleid IN ( 3, 4, 5 ) &lt;br /&gt;
GROUP BY roleid, l.action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student (user) COUNT in each Course===&lt;br /&gt;
Including (optional) filter by: year (if included in course fullname).&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/index.php?contextid=&#039;,context.id,&#039;&amp;quot;&amp;gt;Show users&amp;lt;/a&amp;gt;&#039;) AS Users&lt;br /&gt;
, COUNT(course.id) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS asg&lt;br /&gt;
JOIN prefix_context AS context ON asg.contextid = context.id AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_user AS user ON user.id = asg.userid&lt;br /&gt;
JOIN prefix_course AS course ON context.instanceid = course.id&lt;br /&gt;
WHERE asg.roleid = 5 &lt;br /&gt;
# AND course.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
GROUP BY course.id&lt;br /&gt;
ORDER BY COUNT(course.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enrolment count in each Course ===&lt;br /&gt;
&lt;br /&gt;
Shows the total number of enroled users of all roles in each course. Sorted by course name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname, COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LIST of all site USERS by COURSE enrollment (Moodle 2.x)===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) as Role&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) as RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course as course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enrolled users,which did not login into the Course, even once (Moodle 2)===&lt;br /&gt;
Designed forMoodle 2 table structure and uses special plugin filter : %%FILTER_SEARCHTEXT:table.field%%&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id as ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
user2.idnumber AS IDNumber,&lt;br /&gt;
user2.phone1 AS Phone,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
&lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id and courseid=c.id) as CourseLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id and e.courseid = c.id) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments as ue&lt;br /&gt;
JOIN prefix_enrol as e on e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user as user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess as ul on ul.userid = user2.id&lt;br /&gt;
WHERE c.id=16 AND ul.timeaccess IS NULL&lt;br /&gt;
%%FILTER_SEARCHTEXT:user2.firstname%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Role assignments on categories===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS category,&lt;br /&gt;
cc.depth, cc.path, r.name AS role,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php?id=&#039;,usr.id,&#039;&amp;quot;&amp;gt;&#039;,usr.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS name,&lt;br /&gt;
usr.firstname, usr.username, usr.email&lt;br /&gt;
FROM prefix_course_categories cc&lt;br /&gt;
INNER JOIN prefix_context cx ON cc.id = cx.instanceid&lt;br /&gt;
AND cx.contextlevel = &#039;40&#039;&lt;br /&gt;
INNER JOIN prefix_role_assignments ra ON cx.id = ra.contextid&lt;br /&gt;
INNER JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
INNER JOIN prefix_user usr ON ra.userid = usr.id&lt;br /&gt;
ORDER BY cc.depth, cc.path, usr.lastname, usr.firstname, r.name, cc.name&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Permissions Overides on Categories===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712834 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT rc.id, ct.instanceid, ccat.name, rc.roleid, rc.capability, rc.permission, &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( rc.timemodified ) , &#039;%Y-%m-%d&#039; ) AS timemodified, rc.modifierid, ct.instanceid, ct.path, ct.depth&lt;br /&gt;
FROM `prefix_role_capabilities` AS rc&lt;br /&gt;
INNER JOIN `prefix_context` AS ct ON rc.contextid = ct.id&lt;br /&gt;
INNER JOIN `prefix_course_categories` AS ccat ON ccat.id = ct.instanceid&lt;br /&gt;
AND `contextlevel` =40&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;Totally Opened Courses&amp;quot; (visible, opened to guests, with no password)===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712837 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Course&#039;,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/enrol/instances.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Méthodes inscription&amp;lt;/a&amp;gt;&#039;) AS &#039;Enrollment plugins&#039;,&lt;br /&gt;
e.sortorder&lt;br /&gt;
FROM prefix_enrol AS e, prefix_course AS c&lt;br /&gt;
WHERE e.enrol=&#039;guest&#039; AND e.status=0 AND e.password=&#039;&#039; AND c.id=e.courseid AND c.visible=1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;loggedin users&amp;quot; from the last 120 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id,username,FROM_UNIXTIME(`lastlogin`) as days &lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;and user count for that same population:&#039;&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(id) as Users  FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Users loggedin within the last 7 days ====&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    l.* FROM mdl_logstore_standard_log l&lt;br /&gt;
WHERE&lt;br /&gt;
   l.eventname = &#039;\\core\\event\\user_loggedin&#039;&lt;br /&gt;
   AND FROM_UNIXTIME(l.timecreated, &#039;%Y-%m-%d&#039;) &amp;gt;= DATE_SUB(NOW(), INTERVAL 7 DAY)&lt;br /&gt;
&lt;br /&gt;
SELECT l.eventname FROM mdl_logstore_standard_log l&lt;br /&gt;
GROUP BY l.eventname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists the users who have only logged into the site once===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, username, firstname, lastname, idnumber&lt;br /&gt;
FROM prefix_user&lt;br /&gt;
WHERE prefix_user.deleted = 0&lt;br /&gt;
AND prefix_user.lastlogin = 0 &lt;br /&gt;
AND prefix_user.lastaccess &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Students in all courses of some institute===&lt;br /&gt;
What is the status (deleted or not) of all Students (roleid = 5) in all courses of some Institute&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname, u.firstname, u.lastname, u.deleted&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND u.institution = &#039;please enter school name here&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Full User info (for deleted users)===&lt;br /&gt;
Including extra custom profile fields (from prefix_user_info_data)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT * &lt;br /&gt;
FROM prefix_user as u &lt;br /&gt;
JOIN prefix_user_info_data as uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_user_info_field as uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;class&#039;)&lt;br /&gt;
WHERE `deleted` = &amp;quot;1&amp;quot; and `institution`=&amp;quot;your school name&amp;quot; and `department` = &amp;quot;your department&amp;quot; and `data` = &amp;quot;class level and number&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User&#039;s courses===&lt;br /&gt;
change &amp;quot;u.id = 2&amp;quot; with a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, c.id, c.fullname&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE u.id = 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Users with extra info (email) in current course===&lt;br /&gt;
blocks/configurable_reports replaces %%COURSEID%% with course id.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, u.email&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Students with enrollment and completion dates in current course===&lt;br /&gt;
This is meant to be a &amp;quot;global&amp;quot; report in Configurable Reports containing the following:&lt;br /&gt;
firstname, lastname, idnumber, institution, department, email, student enrolment date, student completion date&lt;br /&gt;
Note: for PGSQL, use to_timestamp() instead of FROM_UNIXTIME()&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.firstname&lt;br /&gt;
, u.lastname&lt;br /&gt;
, u.idnumber&lt;br /&gt;
, u.institution&lt;br /&gt;
, u.department&lt;br /&gt;
, u.email&lt;br /&gt;
, FROM_UNIXTIME(cc.timeenrolled)&lt;br /&gt;
, FROM_UNIXTIME(cc.timecompleted)&lt;br /&gt;
&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_completions AS cc ON cc.course = c.id AND cc.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Special Roles===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.roleid,r.name&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,ra.userid,&#039;&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Username&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON (ctx.id = ra.contextid AND ctx.contextlevel = 50)&lt;br /&gt;
JOIN prefix_course AS c ON ctx.instanceid = c.id&lt;br /&gt;
WHERE ra.roleid &amp;gt; 6&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses without Teachers===&lt;br /&gt;
Actually, shows the number of Teachers in a course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Teachers&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
ORDER BY Teachers ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of users who have been enrolled for more than 4 weeks===&lt;br /&gt;
For Moodle 2.2 , by  Isuru Madushanka Weerarathna &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT uenr.userid As User, IF(enr.courseid=uenr.courseid ,&#039;Y&#039;,&#039;N&#039;) As Enrolled, &lt;br /&gt;
IF(DATEDIFF(NOW(), FROM_UNIXTIME(uenr.timecreated))&amp;gt;=28,&#039;Y&#039;,&#039;N&#039;) As EnrolledMoreThan4Weeks&lt;br /&gt;
FROM prefix_enrol As enr, prefix_user_enrolments AS uenr&lt;br /&gt;
WHERE enr.id = uenr.enrolid AND enr.status = uenr.status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with language===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
This will show you the language setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, lang from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools.&lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;en&#039; to &#039;en_us&#039; for all users:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To do this for only users who have a particular country set, use this as an example:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE country = &#039;US&#039; AND lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with Authentication ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Sometimes you need to do mass changes of authentication methods. A common case is changing default manual to LDAP. &lt;br /&gt;
&lt;br /&gt;
This will show you the Authentication setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, auth from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools. &lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;manual&#039; to &#039;ldap&#039; 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.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET auth = &#039;ldap&#039; WHERE auth = &#039;manual&#039; AND id &amp;gt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compare role capability and permissions ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT mrc.capability &lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;1&#039; AND rc.contextid = &#039;1&#039;) AS Manager&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;2&#039; AND rc.contextid = &#039;1&#039;) AS CourseCreator&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;3&#039; AND rc.contextid = &#039;1&#039;) AS Teacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;4&#039; AND rc.contextid = &#039;1&#039;) AS AssistantTeacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;5&#039; AND rc.contextid = &#039;1&#039;) AS Student&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;6&#039; AND rc.contextid = &#039;1&#039;) AS Guest&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_role_capabilities` AS mrc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User&#039;s accumulative time spent in course ===&lt;br /&gt;
A sum up of the time delta between logstore_standard_log user&#039;s records, considering the a 2 hour session limit.&lt;br /&gt;
&lt;br /&gt;
Uses: current user&#039;s id %%USERID%% and current course&#039;s id %%COURSEID%%  &lt;br /&gt;
&lt;br /&gt;
And also using a date filter (which can be ignored)  &lt;br /&gt;
&lt;br /&gt;
The extra &amp;quot;User&amp;quot; field is used as a dummy field for the Line chart Series field, in which I use X=id, Series=Type, Y=delta.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
l.id, &lt;br /&gt;
l.timecreated, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(l.timecreated),&#039;%d-%m-%Y&#039;) AS dTime,&lt;br /&gt;
@prevtime := (SELECT max(timecreated) FROM mdl_logstore_standard_log &lt;br /&gt;
		WHERE userid = %%USERID%% and id &amp;lt; l.id ORDER BY id ASC LIMIT 1) AS prev_time,&lt;br /&gt;
IF (l.timecreated - @prevtime &amp;lt; 7200, @delta := @delta + (l.timecreated-@prevtime),0) AS sumtime,&lt;br /&gt;
l.timecreated-@prevtime AS delta,&lt;br /&gt;
&amp;quot;User&amp;quot; as type&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log as l, &lt;br /&gt;
(SELECT @delta := 0) AS s_init &lt;br /&gt;
# Change UserID&lt;br /&gt;
WHERE l.userid = %%USERID%% AND l.courseid = %%COURSEID%%&lt;br /&gt;
%%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Low-Participation Student Report ===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
This report returns a list of students who are enrolled in courses filtered by a short-name text marker (in this case &amp;quot;OL-&amp;quot;) in the specified category, but have very low participation in the course during the specified time period (fewer than 2 &amp;quot;Edits&amp;quot; to Activity Modules, indicating few active contributions to the course). The number of &amp;quot;Edits&amp;quot; is provided for each student for the time period specified.&lt;br /&gt;
&lt;br /&gt;
An &amp;quot;Edit&amp;quot; is defined as course activity other than viewing content. Click the &amp;quot;Logs&amp;quot; link to review the student activity. The Logs offer the option to review &amp;quot;View&amp;quot; activity as well as &amp;quot;Edit&amp;quot; activity.&lt;br /&gt;
&lt;br /&gt;
Only &amp;quot;visible&amp;quot; courses are included in this report. The report may be downloaded as an Excel spreadsheet.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t forget to set up Filters: &amp;quot;Start / End date filter&amp;quot; and &amp;quot;Filter categories&amp;quot; on the Filters tab in Configurable reports.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname AS Last, u.firstname AS First, u.idnumber AS IDnumber, u.email AS email, c.shortname AS CourseID,  count(l.id) AS Edits, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;https://learn.granite.edu/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=-view&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id AND l.action NOT LIKE &amp;quot;view%&amp;quot; %%FILTER_STARTTIME:l.TIME:&amp;gt;%% %%FILTER_ENDTIME:l.TIME:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.visible=1&lt;br /&gt;
# This prefix filter allows the exclusion of non-online courses at the original institution. Alter this to fit your institution, or remove it.&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
%%FILTER_CATEGORIES:c.category%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
HAVING Edits &amp;lt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Messages of All Users in a Specific Course ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
NOTE: This query will probably not work at all in 3.5 now due to the changes in the structure of the Messages database. - RT&lt;br /&gt;
&lt;br /&gt;
This query shows the personal messages between users in a specific course, given the course id number. Properly speaking, personal messages pertain only to users and are not part of courses, but by filtering enrollments for roles in a course, you can show this. &lt;br /&gt;
&lt;br /&gt;
This report as is shows only the messages between Teachers and Students, as the WHERE statement contains and AND ((...))) section that restrict this report to ONLY messages between Teachers (role id = 3) and Students (role id =5). Remove that part of the statement if you wish to see _all_ messages between all users, e.g. teachers to teachers, student to student. &lt;br /&gt;
&lt;br /&gt;
Also, if you have created custom roles, you can replace the default id numbers with custom ones to further enhance the report.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.username AS &#039;From&#039;,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS &#039;From Name&#039;,&lt;br /&gt;
u2.username AS &#039;To&#039;,&lt;br /&gt;
CONCAT(u2.firstname ,&#039; &#039;,u2.lastname) AS &#039;To Name&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(me.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;,&lt;br /&gt;
me.subject AS &#039;Subject&#039;, &lt;br /&gt;
me.smallmessage AS &#039;Message&#039;&lt;br /&gt;
FROM prefix_message me&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = me.useridfrom AND ra.roleid IN (3,4,5)  &lt;br /&gt;
JOIN prefix_role_assignments AS ra2 ON ra2.userid = me.useridto AND ra2.roleid IN (3,4,5)  &lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id AND ra2.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_user u ON u.id = me.useridfrom&lt;br /&gt;
JOIN prefix_user u2 ON u2.id = me.useridto&lt;br /&gt;
WHERE c.id=## &lt;br /&gt;
AND ((ra.roleid = 3 AND ra2.roleid = 5) OR (ra.roleid = 5 AND ra2.roleid = 3)) &lt;br /&gt;
ORDER BY me.useridfrom, me.useridto, me.timecreated&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Log Activity Reports==&lt;br /&gt;
===Count all Active Users by ROLE in a course category (including all of its sub-categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT l.userid) as active&lt;br /&gt;
FROM mdl_course as c&lt;br /&gt;
JOIN mdl_context AS ctx ON  ctx.instanceid=c.id&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN mdl_user_lastaccess as l ON ra.userid = l.userid&lt;br /&gt;
JOIN mdl_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category=cats.id AND (&lt;br /&gt;
	cats.path LIKE &#039;%/80/%&#039;&lt;br /&gt;
	OR cats.path LIKE &#039;%/80&#039;&lt;br /&gt;
) &lt;br /&gt;
AND ra.roleid=3  AND ctx.contextlevel=50  #ra.roleid= TEACHER 3, NON-EDITING TEACHER 4, STUDENT 5&lt;br /&gt;
AND  l.timeaccess &amp;gt; (unix_timestamp() - ((60*60*24)*NO_OF_DAYS)) #NO_OF_DAYS change to number&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Detailed &amp;quot;VIEW&amp;quot; ACTION for each ROLE (TEACHER,NONE-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT l.action, count( l.userid ) as counter , r.name&lt;br /&gt;
FROM `prefix_log` as l&lt;br /&gt;
JOIN `prefix_role_assignments` AS ra on l.userid = ra.userid&lt;br /&gt;
JOIN `prefix_role` AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE (ra.roleid IN (3,4,5)) AND (l.action LIKE &#039;%view%&#039; )&lt;br /&gt;
GROUP BY roleid,l.action&lt;br /&gt;
order by r.name,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total Activity of Roles:&amp;quot;Teacher&amp;quot; and &amp;quot;None-Editing Teacher&amp;quot; by Dates and by Hours===&lt;br /&gt;
The output columns of this report table can be used as base for a Pivot-Table&lt;br /&gt;
which will show the amount of &#039;&#039;&#039;activity&#039;&#039;&#039; per &#039;&#039;&#039;hour&#039;&#039;&#039; per &#039;&#039;&#039;days&#039;&#039;&#039; in 3D graph view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%Y-%m-%d&#039; ) AS grptimed ,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%k&#039; ) AS grptimeh  , count( l.userid ) AS counter &lt;br /&gt;
FROM `prefix_log` AS l&lt;br /&gt;
JOIN prefix_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
WHERE ra.roleid IN (3,4)&lt;br /&gt;
GROUP BY grptimed,grptimeh&lt;br /&gt;
ORDER BY grptimed,grptimeh&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many LOGINs per user and user&#039;s Activity===&lt;br /&gt;
+ link username to a user activity graph report&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,u.id,&#039;&amp;amp;mode=alllogs&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) as Username&lt;br /&gt;
,count(*) as logins&lt;br /&gt;
,(SELECT count(*) FROM prefix_log WHERE userid = l.userid GROUP BY userid) as Activity &lt;br /&gt;
FROM prefix_log as l JOIN prefix_user as u ON l.userid = u.id &lt;br /&gt;
WHERE `action` LIKE &#039;%login%&#039; group by userid&lt;br /&gt;
ORDER BY Activity DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Distinct user logins per month===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
The following will show you the months of the current calendar year with the total number of distinct, unique user logins per month. Change the year in the WHERE clause to the year you need.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
 COUNT(DISTINCT l.userid) AS &#039;DistinctUserLogins&#039;, &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%M&#039;) AS &#039;Month&#039;&lt;br /&gt;
FROM prefix_logstore_standard_log l&lt;br /&gt;
WHERE l.action = &#039;loggedin&#039; AND YEAR(FROM_UNIXTIME(l.timecreated)) = &#039;2017&#039; &lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(l.timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total activity per course, per unique user on the last 24h===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    COUNT(DISTINCT userid) AS countUsers&lt;br /&gt;
  , COUNT(l.courseid) AS countVisits&lt;br /&gt;
  , CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
  JOIN mdl_course AS c ON c.id = l.courseid&lt;br /&gt;
WHERE l.courseid &amp;gt; 0&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 1 DAY)&lt;br /&gt;
      AND c.fullname LIKE &#039;%תשעו%&#039;&lt;br /&gt;
GROUP BY l.courseid&lt;br /&gt;
ORDER BY countVisits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Instructor Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of instructors in all courses per week of a term, including pre-term and post-term edits. An edit is defined as a change to the course, such as a discussion post, the grading of an assignment, or the uploading of file attachments, as well as alterations to course content.&lt;br /&gt;
&lt;br /&gt;
* To specify a subject and/or course number, use % as a wildcard, e.g. ARTS% or ARTS501%&lt;br /&gt;
* To match part of a last name, use %, e.g. Smi% will match &amp;quot;Smith&amp;quot;, &amp;quot;Smile&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
At our institution, we include filters on the course name or category to constrain by terms. These are very specific to how course names and categories are constructed at our institution, so I&#039;ve removed those elements from this code. Also, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; lines for longer terms, or remove lines for shorter terms.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version uses legacy (pre-2.7) logs. See below for post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, c.startdate AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time)) - WEEK(FROM_UNIXTIME(c.startdate))&amp;lt;0,1,0)) AS BeforeTerm&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=0,1,0)) AS Week1&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=1,1,0)) AS Week2&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=2,1,0)) AS Week3&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=3,1,0)) AS Week4&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=4,1,0)) AS Week5&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=5,1,0)) AS Week6&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=6,1,0)) AS Week7&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=7,1,0)) AS Week8&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=8,1,0)) AS Week9&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=9,1,0)) AS Week10&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=10,1,0)) AS Week11&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=11,1,0)) AS Week12&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))&amp;gt;=12,1,0)) AS AfterTerm&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE :course&lt;br /&gt;
AND u.lastname LIKE :last_name&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 log version:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(DISTINCT l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
AND cc.idnumber LIKE &#039;%current%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
#HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY RIGHT(c.shortname,2), c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Student Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of students in the current course by week, including pre-term and post-term edits. An 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 (if permitted).&lt;br /&gt;
&lt;br /&gt;
Links to three other reports are also provided:&lt;br /&gt;
&lt;br /&gt;
* Logs: complete log entries for the student in the course, organized by date&lt;br /&gt;
* Activity Outline: the &amp;quot;Outline Report&amp;quot; from the User Activity Reports, summarizing the student&#039;s activity in the course, organized by course content&lt;br /&gt;
* Consolidated Activity Report: the &amp;quot;Complete Report&amp;quot; from the User Activity Reports, detailing the student&#039;s activity in the course, organized by course content (includes text of forum posts)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). At our institution, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for a post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF((l.time-c.startdate)/7&amp;lt;0,1,0)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=0,1,0)) AS &#039;Week 1&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=1,1,0)) AS &#039;Week 2&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=2,1,0)) AS &#039;Week 3&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=3,1,0)) AS &#039;Week 4&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=4,1,0)) AS &#039;Week 5&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=5,1,0)) AS &#039;Week 6&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=6,1,0)) AS &#039;Week 7&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=7,1,0)) AS &#039;Week 8&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=8,1,0)) AS &#039;Week 9&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=9,1,0)) AS &#039;Week 10&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=10,1,0)) AS &#039;Week 11&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=11,1,0)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))&amp;gt;=15,1,0)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 (Standard Logs) version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
# Our institution stores academic advisor names and emails in custom profile fields&lt;br /&gt;
#, CONCAT(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,uce.data,&#039;&amp;quot;&amp;gt;&#039;,uid.data, &#039;&amp;lt;/a&amp;gt;&#039;)  AS &#039;Academic Advisor&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,&#039;Posts&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Posts&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# student academic coach - you can include custom profile field data with these methods&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uid ON u.id = uid.userid AND uid.fieldid = &#039;2&#039;&lt;br /&gt;
# student academic coach email&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uce on u.id = uce.userid AND uce.fieldid = &#039;6&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===My Weekly Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of the &#039;&#039;&#039;current user&#039;&#039;&#039; in the &#039;&#039;&#039;current course&#039;&#039;&#039; 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).&lt;br /&gt;
&lt;br /&gt;
This report uses Standard Logs (post 2.7).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
l.component AS &#039;activity&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS &#039;Total&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE 1&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
AND u.id = %%USERID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY l.component&lt;br /&gt;
&lt;br /&gt;
ORDER BY l.component&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Faculty/Student Interactions===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Returns a count of instructor and other-student responses to student activity for the specified time period. This report can help indicate whether students&#039; comments are being responded to, as well as summarizing post activity by students during the specified time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for the post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This report can take a long time to run. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
LEFT JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
# We care about messages that involve both the instructor and students of this course&lt;br /&gt;
# messages from instructor to students:&lt;br /&gt;
# LEFT JOIN prefix_message AS mts ON mts.useridfrom = instr.id AND mts.useridto = allstu.id&lt;br /&gt;
# LEFT JOIN prefix_message AS mfs ON mfs.useridfrom = instr.id AND mfs.useridto = allstu.id&lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 Standard Logs version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
 JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student Resource Usage===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Standard Logs&amp;quot; from Moodle 2.7+.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
, m.name AS &#039;item type&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&lt;br /&gt;
COALESCE(a.name, &#039;&#039;), &lt;br /&gt;
COALESCE(b.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cert.name,&#039;&#039;), &lt;br /&gt;
COALESCE(chat.name,&#039;&#039;), &lt;br /&gt;
COALESCE(choice.name,&#039;&#039;), &lt;br /&gt;
COALESCE(data.name,&#039;&#039;), &lt;br /&gt;
COALESCE(feedback.name,&#039;&#039;), &lt;br /&gt;
COALESCE(folder.name,&#039;&#039;), &lt;br /&gt;
COALESCE(forum.name,&#039;&#039;), &lt;br /&gt;
COALESCE(glossary.name,&#039;&#039;), &lt;br /&gt;
COALESCE(imscp.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lesson.name,&#039;&#039;), &lt;br /&gt;
COALESCE(p.name,&#039;&#039;),&lt;br /&gt;
COALESCE(questionnaire.name,&#039;&#039;), &lt;br /&gt;
COALESCE(quiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cr.name,&#039;&#039;), &lt;br /&gt;
COALESCE(scorm.name,&#039;&#039;), &lt;br /&gt;
COALESCE(survey.name,&#039;&#039;), &lt;br /&gt;
COALESCE(url.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(workshop.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kalvidassign.name,&#039;&#039;), &lt;br /&gt;
COALESCE(attendance.name,&#039;&#039;), &lt;br /&gt;
COALESCE(checklist.name,&#039;&#039;), &lt;br /&gt;
COALESCE(flashcard.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lti.name,&#039;&#039;), &lt;br /&gt;
COALESCE(oublog.name,&#039;&#039;), &lt;br /&gt;
COALESCE(ouwiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(subpage.name,&#039;&#039;), &lt;br /&gt;
COALESCE(journal.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lightboxgallery.name,&#039;&#039;), &lt;br /&gt;
COALESCE(elluminate.name,&#039;&#039;), &lt;br /&gt;
COALESCE(adaptivequiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(hotpot.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiziq.name,&#039;&#039;), &lt;br /&gt;
COALESCE(turnitintooltwo.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kvr.name,&#039;&#039;)&lt;br /&gt;
) AS &#039;item name&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;r&#039;),1,0)) AS &#039;total views&#039;&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),1,0)) AS &#039;total submissions&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;r&#039;),u.id,NULL)) AS &#039;count of students who viewed&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),u.id,NULL)) AS &#039;count of students who submitted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 #AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module AND m.name NOT LIKE &#039;label&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON a.id = cm.instance AND m.name = &#039;assign&#039;&lt;br /&gt;
LEFT JOIN prefix_book AS b ON b.id = cm.instance AND m.name = &#039;book&#039;&lt;br /&gt;
LEFT JOIN prefix_certificate AS cert ON cert.id = cm.instance AND m.name = &#039;certificate&#039;&lt;br /&gt;
LEFT JOIN prefix_chat AS chat ON chat.id = cm.instance AND m.name = &#039;chat&#039;&lt;br /&gt;
LEFT JOIN prefix_choice AS choice ON choice.id = cm.instance AND m.name = &#039;choice&#039;&lt;br /&gt;
LEFT JOIN prefix_data AS data ON data.id = cm.instance AND m.name = &#039;data&#039;&lt;br /&gt;
LEFT JOIN prefix_feedback AS feedback ON feedback.id = cm.instance AND m.name = &#039;feedback&#039;&lt;br /&gt;
LEFT JOIN prefix_folder AS folder ON folder.id = cm.instance AND m.name = &#039;folder&#039;&lt;br /&gt;
LEFT JOIN prefix_forum AS forum ON forum.id = cm.instance AND m.name = &#039;forum&#039;&lt;br /&gt;
LEFT JOIN prefix_glossary AS glossary ON glossary.id = cm.instance AND m.name = &#039;glossary&#039;&lt;br /&gt;
LEFT JOIN prefix_imscp AS imscp ON imscp.id = cm.instance AND m.name = &#039;imscp&#039;&lt;br /&gt;
LEFT JOIN prefix_lesson AS lesson ON lesson.id = cm.instance AND m.name = &#039;lesson&#039;&lt;br /&gt;
LEFT JOIN prefix_page AS p ON p.id = cm.instance AND m.name = &#039;page&#039;&lt;br /&gt;
LEFT JOIN prefix_questionnaire AS questionnaire ON questionnaire.id = cm.instance AND m.name = &#039;questionnaire&#039;&lt;br /&gt;
LEFT JOIN prefix_quiz AS quiz ON quiz.id = cm.instance AND m.name = &#039;quiz&#039;&lt;br /&gt;
LEFT JOIN prefix_resource AS cr ON cr.id = cm.instance AND m.name = &#039;resource&#039;&lt;br /&gt;
LEFT JOIN prefix_scorm AS scorm ON scorm.id = cm.instance AND m.name = &#039;scorm&#039;&lt;br /&gt;
LEFT JOIN prefix_survey AS survey ON survey.id = cm.instance AND m.name = &#039;survey&#039;&lt;br /&gt;
LEFT JOIN prefix_url AS url ON url.id = cm.instance AND m.name = &#039;url&#039;&lt;br /&gt;
LEFT JOIN prefix_wiki AS wiki ON wiki.id = cm.instance AND m.name = &#039;wiki&#039;&lt;br /&gt;
LEFT JOIN prefix_workshop AS workshop ON workshop.id = cm.instance AND m.name = &#039;workshop&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidassign AS kalvidassign ON kalvidassign.id = cm.instance AND m.name = &#039;kalvidassign&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidres AS kvr ON kvr.id = cm.instance AND m.name = &#039;kalvidres&#039;&lt;br /&gt;
LEFT JOIN prefix_attendance AS attendance ON attendance.id = cm.instance AND m.name = &#039;attendance&#039;&lt;br /&gt;
LEFT JOIN prefix_checklist AS checklist ON checklist.id = cm.instance AND m.name = &#039;checklist&#039;&lt;br /&gt;
LEFT JOIN prefix_flashcard AS flashcard ON flashcard.id = cm.instance AND m.name = &#039;flashcard&#039;&lt;br /&gt;
LEFT JOIN prefix_lti AS lti ON lti.id = cm.instance AND m.name = &#039;lti&#039;&lt;br /&gt;
LEFT JOIN prefix_oublog AS oublog ON oublog.id = cm.instance AND m.name = &#039;oublog&#039;&lt;br /&gt;
LEFT JOIN prefix_ouwiki AS ouwiki ON ouwiki.id = cm.instance AND m.name = &#039;ouwiki&#039;&lt;br /&gt;
LEFT JOIN prefix_subpage AS subpage ON subpage.id = cm.instance AND m.name = &#039;subpage&#039;&lt;br /&gt;
LEFT JOIN prefix_journal AS journal ON journal.id = cm.instance AND m.name = &#039;journal&#039;&lt;br /&gt;
LEFT JOIN prefix_lightboxgallery AS lightboxgallery ON lightboxgallery.id = cm.instance AND m.name = &#039;lightboxgallery&#039;&lt;br /&gt;
LEFT JOIN prefix_elluminate AS elluminate ON elluminate.id = cm.instance AND m.name = &#039;elluminate&#039;&lt;br /&gt;
LEFT JOIN prefix_adaptivequiz AS adaptivequiz ON adaptivequiz.id = cm.instance AND m.name = &#039;adaptivequiz&#039;&lt;br /&gt;
LEFT JOIN prefix_hotpot AS hotpot ON hotpot.id = cm.instance AND m.name = &#039;hotpot&#039;&lt;br /&gt;
LEFT JOIN prefix_wiziq AS wiziq ON wiziq.id = cm.instance AND m.name = &#039;wiziq&#039;&lt;br /&gt;
LEFT JOIN prefix_turnitintooltwo AS turnitintooltwo ON turnitintooltwo.id = cm.instance AND m.name = &#039;turnitintooltwo&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cm.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Hits) between dates===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module, COUNT( * ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME( l.`time` ) BETWEEN  &#039;2012-10-01 00:00:00&#039; AND  &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
GROUP BY module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Instances and Hits) for each academic year===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2010-10-01 00:00:00&#039; AND &#039;2011-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2010-10-01 00:00:00&#039; AND &#039;2011-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2011-10-01 00:00:00&#039; AND &#039;2012-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2011&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2011-10-01 00:00:00&#039; AND &#039;2012-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2011&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2012-10-01 00:00:00&#039; AND &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2012&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2012-10-01 00:00:00&#039; AND &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2012&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_modules AS m&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Unique user sessions per day and month + graph===&lt;br /&gt;
The &amp;quot;graph&amp;quot; column is used when displaying a graph (which needs at least three columns to pick from)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT userid) AS &amp;quot;Unique User Logins&amp;quot;&lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y /%m / %d&amp;quot;) AS &amp;quot;Year / Month / Day&amp;quot;, &amp;quot;Graph&amp;quot; &lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE action LIKE &#039;loggedin&#039;&lt;br /&gt;
#AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) # optional start date&lt;br /&gt;
#AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:00&#039;) # optional end date&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And...&lt;br /&gt;
&lt;br /&gt;
Counting user&#039;s global and unique hits per day + counting individual usage of specific activities and resources (on that day),&lt;br /&gt;
&lt;br /&gt;
And since I am using phpMyAdmin&#039;s &amp;quot;Display Graph&amp;quot; feature (at the bottom of the query&#039;s output page), I have scaled down the &amp;quot;User Hits&amp;quot; by 10 to fit the graph. that&#039;s it.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y-%m-%d&amp;quot;) AS &amp;quot;Datez&amp;quot;&lt;br /&gt;
,COUNT(DISTINCT userid) AS &amp;quot;Unique Users&amp;quot;&lt;br /&gt;
,ROUND(COUNT(*)/10) &amp;quot;User Hits (K)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_quiz&#039;,1,0)) &amp;quot;Quizzes&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_forum&#039; or component=&#039;mod_forumng&#039;,1,0)) &amp;quot;Forums&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_assign&#039;,1,0)) &amp;quot;Assignments&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_oublog&#039;,1,0)) &amp;quot;Blogs&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_resource&#039;,1,0)) &amp;quot;Files (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_url&#039;,1,0)) &amp;quot;Links (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_page&#039;,1,0)) &amp;quot;Pages (Resource)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE 1=1&lt;br /&gt;
AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-03-01 00:00:00&#039;) # optional START DATE&lt;br /&gt;
AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-05-31 23:59:00&#039;) # optional END DATE&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide, daily unique user hits for the last 7 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
  DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%m%d&#039;) &#039;Day&#039;&lt;br /&gt;
  ,COUNT(DISTINCT l.userid) AS &#039;Distinct Users Hits&#039;&lt;br /&gt;
  ,COUNT( l.userid) AS &#039;Users Hits&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
WHERE l.courseid &amp;gt; 1&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 7 DAY)&lt;br /&gt;
GROUP BY DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User detailed activity in course modules===&lt;br /&gt;
Considering only several modules: url, resource, forum, quiz, questionnaire.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.id, ra.roleid,&lt;br /&gt;
CONCAT(u.lastname, &#039; &#039;, u.firstname) AS &#039;Student&#039;&lt;br /&gt;
,COUNT(l.id) AS &#039;Actions&#039;&lt;br /&gt;
,l.component &amp;quot;Module type&amp;quot;&lt;br /&gt;
,l.objectid &amp;quot;Module ID&amp;quot;&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN l.component = &#039;mod_url&#039; THEN (SELECT u.name FROM mdl_url AS u WHERE u.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_resource&#039; THEN (SELECT r.name FROM mdl_resource AS r WHERE r.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_forum&#039; THEN (SELECT f.name FROM mdl_forum AS f WHERE f.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_quiz&#039; THEN (SELECT q.name FROM mdl_quiz AS q WHERE q.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_questionnaire&#039; THEN (SELECT q.name FROM mdl_questionnaire AS q WHERE q.id = l.objectid )&lt;br /&gt;
END AS &#039;Module name&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = l.courseid AND m.userid = u.id) &amp;quot;user_groups&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT s.name &lt;br /&gt;
  FROM mdl_course_modules AS cm &lt;br /&gt;
  JOIN mdl_course_sections AS s ON s.course = cm.course AND s.id = cm.section &lt;br /&gt;
  WHERE cm.id = l.contextinstanceid) AS &amp;quot;Section name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l  &lt;br /&gt;
JOIN mdl_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.userid = l.userid &lt;br /&gt;
  AND ra.contextid = (SELECT id FROM mdl_context WHERE instanceid = l.courseid AND contextlevel = 50) &lt;br /&gt;
WHERE l.courseid = %%COURSEID%%&lt;br /&gt;
  AND l.component IN (&#039;mod_url&#039;, &#039;mod_resource&#039;, &#039;mod_forum&#039;, &#039;mod_quiz&#039;, &#039;mod_questionnaire&#039;) &lt;br /&gt;
  %%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%%&lt;br /&gt;
 &lt;br /&gt;
GROUP BY u.id, l.component&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What teachers and courses considered active?===&lt;br /&gt;
This report display several calculations and parameters that help the Online academic training team find teachers that might need more support getting their courses more supporting of online learning pedagogical methodologies.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,&lt;br /&gt;
			  course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
#,course.shortname&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2012%&#039; THEN &#039;2012&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2013%&#039; THEN &#039;2013&#039; &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2014%&#039; THEN &#039;2014&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2015%&#039; THEN &#039;2015&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester a%&#039; THEN &#039;Spring semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester b%&#039; THEN &#039;Fall semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester s%&#039; THEN &#039;Summer semester&#039;&lt;br /&gt;
END AS Semester&lt;br /&gt;
&lt;br /&gt;
,IF(course.startdate&amp;gt;0, DATE_FORMAT(FROM_UNIXTIME(startdate), &#039;%d-%m-%Y&#039;), &#039;no date&#039;) AS &amp;quot;Course Start Date&amp;quot; &lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 4 AND ctx.instanceid = course.id&lt;br /&gt;
) AS &amp;quot;Assistant teacher&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
&lt;br /&gt;
# Uncomment to use the new Moodle 2.8+ logstore&lt;br /&gt;
#,(SELECT COUNT(*) FROM mdl_logstore_standard_log AS l WHERE l.courseid = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Student HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Teacher HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_log AS l WHERE l.course = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course c&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = c.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND c.id = course.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
  &lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = course.id) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(DISTINCT cm.module) FROM prefix_course_modules cm &lt;br /&gt;
  WHERE cm.course = course.id) UniqueModules&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(DISTINCT m.name) &lt;br /&gt;
  FROM prefix_course_modules cm &lt;br /&gt;
  JOIN mdl_modules as m ON m.id = cm.module&lt;br /&gt;
  WHERE cm.course = course.id) UniqueModuleNames&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;ouwiki&#039;, &#039;wiki&#039;) ) &amp;quot;Num Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;oublog&#039;) ) &amp;quot;Num Blogs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;forum&#039;, &#039;forumng&#039;) ) &amp;quot;Num Forums&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;resource&#039;, &#039;folder&#039;, &#039;url&#039;, &#039;tab&#039;, &#039;file&#039;, &#039;book&#039;, &#039;page&#039;) ) Resources&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;forum&#039;, &#039;forumng&#039;, &#039;oublog&#039;, &#039;page&#039;, &#039;file&#039;, &#039;url&#039;, &#039;wiki&#039; , &#039;ouwiki&#039;) ) &amp;quot;Basic Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;advmindmap&#039;, &#039;assign&#039;, &#039;attendance&#039;, &#039;book&#039;, &#039;choice&#039;, &#039;folder&#039;, &#039;tab&#039;, &#039;glossary&#039;, &#039;questionnaire&#039;, &#039;quiz&#039;, &#039;label&#039; ) ) &amp;quot;Avarage Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;elluminate&#039;, &#039;game&#039;, &#039;workshop&#039;) ) &amp;quot;Advanced Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course&lt;br /&gt;
&lt;br /&gt;
#WHERE course.shortname LIKE &#039;%2015%&#039;&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_SEARCHTEXT:course.shortname:~%%&lt;br /&gt;
&lt;br /&gt;
WHERE course.fullname LIKE &#039;%2015%&#039; &lt;br /&gt;
&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY UniqueModules DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly attendance report===&lt;br /&gt;
This report display weekly report in format HH:M:SS This MySQL query works together with AttendaceRegister module, and gather Log information from Attendanceregister_log table. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, SEC_TO_TIME (SUM(arsess.duration)) AS weekly_online_attendance,  FROM_UNIXTIME (arsess.logout) AS Last_Logout&lt;br /&gt;
FROM prefix_attendanceregister_session AS arsess&lt;br /&gt;
JOIN prefix_user AS u ON arsess.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE (((arsess.logout) BETWEEN UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 7 DAY)) AND UNIX_TIMESTAMP(CURDATE())))&lt;br /&gt;
&lt;br /&gt;
GROUP BY arsess.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many distinct users connected to Moodle using the app by month===&lt;br /&gt;
https://moodle.org/mod/forum/discuss.php?d=336086#p1354194 by &lt;br /&gt;
Iñigo Zendegi Urzelai&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;) as year, &lt;br /&gt;
  to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;) as month, &lt;br /&gt;
  count(distinct userid) as distinct_users&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log m&lt;br /&gt;
WHERE m.origin=&#039;ws&#039;&lt;br /&gt;
GROUP BY to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;), to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;) &lt;br /&gt;
ORDER BY to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;), to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Course Reports==&lt;br /&gt;
===Most Active courses===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(l.userid) AS Views&lt;br /&gt;
FROM `mdl_logstore_standard_log` l, `mdl_user` u, `mdl_role_assignments` r&lt;br /&gt;
WHERE l.courseid=35&lt;br /&gt;
AND l.userid = u.id&lt;br /&gt;
AND (l.timecreated &amp;gt; UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) AND l.timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:59&#039;))AND r.contextid= (&lt;br /&gt;
	 SELECT id&lt;br /&gt;
	 FROM mdl_context&lt;br /&gt;
	 WHERE contextlevel=50 AND instanceid=l.courseid&lt;br /&gt;
 )&lt;br /&gt;
AND r.roleid=5&lt;br /&gt;
AND r.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active courses, advanced===&lt;br /&gt;
Including: Teacher&#039;s name, link to the course, All types of log activities, special YEAR generated field, Activities and Resource count, enrolled Student count&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשע&#039; THEN &#039;תשע&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעא&#039; THEN &#039;תשעא&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעב&#039; THEN &#039;תשעב&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = l.course) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_log l &lt;br /&gt;
INNER JOIN prefix_course c ON l.course = c.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
#The following line restricts the courses returned to those having more than 2 modules.  Adjust based on your needs.&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY Year DESC, hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Least active or probably empty courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;-1&amp;quot; instead of &amp;quot;0&amp;quot; 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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
c.fullname,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;CourseLink&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timecreated&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timemodified&#039;,&lt;br /&gt;
CASE&lt;br /&gt;
 WHEN c.timecreated = c.timemodified THEN &#039;-1&#039;&lt;br /&gt;
 ELSE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated))&lt;br /&gt;
END AS &#039;DateDifference&#039;,&lt;br /&gt;
COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
LEFT JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
WHERE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated) ) &amp;lt; 60&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
HAVING COUNT(ue.id) &amp;lt;= 3&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Count unique teachers with courses that use at least X module (Moodle19)===&lt;br /&gt;
You can remove the outer &amp;quot;SELECT COUNT(*) FROM (...) AS ActiveTeachers&amp;quot; SQL query and get the list of the Teachers and Courses.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(*)&lt;br /&gt;
FROM (SELECT c.id AS CourseID, c.fullname AS Course, ra.roleid AS RoleID, CONCAT(u.firstname, &#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = c.id) AS Modules&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid AND ctx.contextlevel = 50 &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE  ra.roleid = 3 &lt;br /&gt;
GROUP BY u.id&lt;br /&gt;
HAVING Modules &amp;gt; 5) AS ActiveTeachers&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RESOURCE count for each COURSE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) count, l.course, c.fullname coursename&lt;br /&gt;
FROM prefix_resource l INNER JOIN prefix_course c on l.course = c.id&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY count DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Common resource types count for each Category (Moodle19)===&lt;br /&gt;
Including sub-categories in total count.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category&lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Links&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference NOT LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Files&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;directory&#039; &lt;br /&gt;
) AS Folders&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;html&#039; &lt;br /&gt;
) AS Pages&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM stats_log_context_role_course &lt;br /&gt;
WHERE roleid = 5 AND module = &#039;resource&#039; AND category = mcc.id&lt;br /&gt;
) AS Hits&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Where &amp;quot;stats_log_context_role_course&amp;quot; (in the above SQL query) is a VIEW generated by:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
CREATE VIEW stats_log_context_role_course AS&lt;br /&gt;
SELECT l.course, c.category, cc.path, l.module, l.action, ra.userid, ra.roleid&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = l.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Same query but for Moodle2+&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category,&lt;br /&gt;
mcc.path,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_url AS u&lt;br /&gt;
JOIN prefix_course AS c ON c.id = u.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS URLs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_folder AS f&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS FOLDERs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_page AS p&lt;br /&gt;
JOIN prefix_course AS c ON c.id = p.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS PAGEs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_book AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS BOOKs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_label AS l&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS LABELs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_tab AS t&lt;br /&gt;
JOIN prefix_course AS c ON c.id = t.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS TABs&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed Resource COUNT by Teacher in each course===&lt;br /&gt;
&lt;br /&gt;
Including (optional) filter by: year, semester and course id.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
, c.id&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעב%&#039; THEN &#039;2012&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעא%&#039; THEN &#039;2011&#039;&lt;br /&gt;
END ) as Year&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר א%&#039; THEN &#039;Semester A&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ב%&#039; THEN &#039;Semester B&#039;&lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ק%&#039; THEN &#039;Semester C&#039;&lt;br /&gt;
END ) as Semester&lt;br /&gt;
,COUNT(c.id) AS Total&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 20) AS TABs&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 33) AS BOOKs&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_resource` as r &lt;br /&gt;
JOIN `prefix_course` AS c on c.id = r.course&lt;br /&gt;
#WHERE type= &#039;file&#039; and reference NOT LIKE &#039;http://%&#039; &lt;br /&gt;
&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
#AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY COUNT(c.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses that are defined as using GROUPs===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/group/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = c.id) Modules&lt;br /&gt;
,(SELECT count(*) FROM prefix_groups g WHERE g.courseid = c.id) Groups&lt;br /&gt;
 FROM `prefix_course` AS c&lt;br /&gt;
WHERE groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Groups===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with Groups in them (groupmode &amp;gt; 0). You can also use groupmode=1 to list just Separate type groups or groupmode=2 to list Visible type groups.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name, c.groupmode&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON c.id = g.courseid&lt;br /&gt;
WHERE c.groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users enrolled in a course with groups but not assigned a group ===&lt;br /&gt;
&lt;br /&gt;
Displays by course all enrolled users that have not been assigned a group in courses that have groups. NOTE: This needs to be optimized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) AS ROLE&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = course.id&lt;br /&gt;
&lt;br /&gt;
WHERE ue.enrolid NOT IN (select userid from prefix_groups_members WHERE g.id=groupid)&lt;br /&gt;
&lt;br /&gt;
ORDER BY Course, Lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Groups in course with member list===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List the groups in a course (replace the # by the course id number) with the members of each group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name AS Groupname, u.username&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_user AS u ON m.userid = u.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Group Export===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
There&#039;s a [[Import_groups|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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT g.name AS groupname, g.description, g.enrolmentkey&lt;br /&gt;
FROM prefix_groups AS g &lt;br /&gt;
JOIN prefix_course as c ON g.courseid = c.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Courses in and below a certain category===&lt;br /&gt;
Use this SQL code to retrieve all courses that exist in or under a set category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the category you want to know about...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course. * , prefix_course_categories. *&lt;br /&gt;
FROM prefix_course, prefix_course_categories&lt;br /&gt;
WHERE prefix_course.category = prefix_course_categories.id&lt;br /&gt;
AND (&lt;br /&gt;
prefix_course_categories.path LIKE &#039;%/$s/%&#039;&lt;br /&gt;
OR prefix_course_categories.path LIKE &#039;%/$s&#039;&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Categories in one level below a certain category===&lt;br /&gt;
Use this PHP code to retrieve a list of all categories below a certain category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the top level category you are interested in.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
require_once(&#039;./config.php&#039;);&lt;br /&gt;
&lt;br /&gt;
$parent_id = $s;&lt;br /&gt;
&lt;br /&gt;
$categories= array();&lt;br /&gt;
&lt;br /&gt;
$categories = get_categories($parent_id);&lt;br /&gt;
&lt;br /&gt;
echo &#039;&amp;lt;ol&amp;gt;&#039;;&lt;br /&gt;
foreach ($categories as $category)&lt;br /&gt;
        {&lt;br /&gt;
        echo &#039;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&#039;.$CFG-&amp;gt;wwwroot.&#039;/course/category.php?id=&#039;.$category-&amp;gt;id.&#039;&amp;quot;&amp;gt;&#039;.$category-&amp;gt;name.&#039;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
        }&lt;br /&gt;
echo &#039;&amp;lt;/ol&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Blog activity per Course (not including VIEW)===&lt;br /&gt;
Filter activity logging to some specific Course Categories!&lt;br /&gt;
+ link course name to actual course (for quick reference)&lt;br /&gt;
(you can change %blog% to %wiki% to filter down all wiki activity or any other module you wish)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID&lt;br /&gt;
,m.name ,count(cm.id) as counter &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS Students&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE `module` LIKE &#039;%blog%&#039; AND course = c.id AND action NOT LIKE &#039;%view%&#039; ) as BlogActivity&lt;br /&gt;
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 &lt;br /&gt;
WHERE m.name LIKE &#039;%blog%&#039; AND c.category IN ( 8,13,15)&lt;br /&gt;
GROUP BY cm.course,cm.module order by counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student&#039;s posts content in all course blogs (oublog)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
b.name &lt;br /&gt;
,op.title&lt;br /&gt;
,op.message&lt;br /&gt;
,( SELECT CONCAT(u.firstname, &#039; &#039;,u.lastname) FROM prefix_user AS u WHERE u.id = oi.userid) AS &amp;quot;Username&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_oublog_posts AS op&lt;br /&gt;
JOIN prefix_oublog_instances AS oi ON oi.id = op.oubloginstancesid &lt;br /&gt;
JOIN prefix_oublog as b ON b.id = oi.oublogid&lt;br /&gt;
JOIN prefix_course AS c ON b.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Courses which uploaded a Syllabus file===&lt;br /&gt;
+ under specific Category&lt;br /&gt;
+ show first Teacher in that course&lt;br /&gt;
+ link Course&#039;s fullname to actual course&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) as Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user as u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) as Teacher&lt;br /&gt;
FROM prefix_resource as r &lt;br /&gt;
JOIN prefix_course as c ON r.course = c.id&lt;br /&gt;
WHERE ( r.name LIKE &#039;%סילבוס%&#039; OR r.name LIKE &#039;%סילאבוס%&#039; OR r.name LIKE &#039;%syllabus%&#039; OR r.name LIKE &#039;%תכנית הקורס%&#039; ) &lt;br /&gt;
AND c.category IN (10,18,26,13,28)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
===Site-wide completed SCORM activities by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===All users enrolled in a course without a role===&lt;br /&gt;
Identifies All users that are enrolled in a course but are not assigned a role.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user.firstname AS Firstname,&lt;br /&gt;
user.lastname AS Lastname,&lt;br /&gt;
user.idnumber Employee_ID,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user as user ON user.id = ue.userid&lt;br /&gt;
&lt;br /&gt;
WHERE user.id NOT IN (&lt;br /&gt;
SELECT u.id&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE c.id=course.id&lt;br /&gt;
)&lt;br /&gt;
ORDER BY Course, Lastname, Firstname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List course resources accumulative file size and count===&lt;br /&gt;
This is the main (first) report, which has a link (alias) to a second report (the following on this page) which list each file in the course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id &amp;quot;CourseID&amp;quot;, context.id &amp;quot;ContextID&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;, c.id, &#039;&amp;quot;&amp;gt;&#039;, c.fullname ,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Course Name&amp;quot;&lt;br /&gt;
, COUNT(*) &amp;quot;Course Files&amp;quot; , ROUND( SUM( f.filesize ) /1048576 ) AS file_size_MB&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/blocks/configurable_reports/viewreport.php?alias=coursefiles&amp;amp;courseid=1&amp;amp;filter_courses=&#039;, c.id, &#039;&amp;quot;&amp;gt;List files&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List Files&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
JOIN mdl_context AS context ON context.id = f.contextid&lt;br /&gt;
JOIN mdl_course AS c ON c.id = (&lt;br /&gt;
  SELECT instanceid&lt;br /&gt;
  FROM mdl_context&lt;br /&gt;
  WHERE id = SUBSTRING_INDEX( SUBSTRING_INDEX( context.path, &#039;/&#039; , -2 ) , &#039;/&#039;, 1 ) )&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this report, you will have to define &amp;quot;alias&amp;quot; report property to &amp;quot;coursefiles&amp;quot; for it to be able to be called from the above report.&lt;br /&gt;
And also setup (add) a FILTER_COURSES filter. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id ,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/pluginfile.php/&#039;, contextid, &#039;/&#039;, component, &#039;/&#039;, filearea, &#039;/&#039;, itemid, &#039;/&#039;, filename, &#039;&amp;quot;&amp;gt;&#039;, filename,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;File&amp;quot;&lt;br /&gt;
,filesize, mimetype ,author, license, timecreated, component, filearea, filepath&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
            AND f.contextid&lt;br /&gt;
            IN (   SELECT id&lt;br /&gt;
                     FROM mdl_context&lt;br /&gt;
                    WHERE path &lt;br /&gt;
                     LIKE (   SELECT CONCAT(&#039;%/&#039;,id,&#039;/%&#039;)&lt;br /&gt;
                                  AS contextquery&lt;br /&gt;
                                FROM mdl_context&lt;br /&gt;
                               WHERE 1=1&lt;br /&gt;
			        %%FILTER_COURSES:instanceid%%&lt;br /&gt;
                                 AND contextlevel = 50&lt;br /&gt;
                           )&lt;br /&gt;
                )&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Which courses has redundant topics===&lt;br /&gt;
This report list several &amp;quot;active topics&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
The following, second SQL query, could be used to &amp;quot;trim&amp;quot; down those redundant course topics/sections/weeks by updating the course format&#039;s numsection (Number of sections) setting. (It&#039;s a per course format setting!)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, format,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT value  FROM  `mdl_course_format_options` WHERE  `courseid` = c.id AND `format` = c.format AND `name` = &#039;numsections&#039; ) AS &amp;quot;numsections&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND `sequence` !=  &#039;&#039; ) AS &amp;quot;Non empty sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id ) AS &amp;quot;Total section count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND sequence IS NOT NULL) AS &amp;quot;Non NULL sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND name != &#039;&#039;) AS &amp;quot;Non empty section Name count&amp;quot;&lt;br /&gt;
 ,(SELECT COUNT(*) FROM mdl_course_modules cm WHERE cm.course = c.id) &amp;quot;Modules count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course AS c&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following SQL REPLACE query is used for &amp;quot;fixing&amp;quot; (updating) the &amp;quot;numsections&amp;quot; of a specific course format &amp;quot;onetopics&amp;quot; (you can always change it, or discard it to use this SQL REPLACE on all course formats) &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
REPLACE INTO `mdl_course_format_options` (`id`, `courseid`, `format`, `sectionid`, `name`, `value`) &lt;br /&gt;
SELECT NULL, c.id, &#039;onetopic&#039;, &#039;0&#039;, &#039;numsections&#039;, (SELECT COUNT(*) FROM `mdl_course_sections` WHERE `course` = c.id AND name != &#039;&#039;)&lt;br /&gt;
FROM `mdl_course` c where format = &#039;onetopic&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hidden Courses with Students Enrolled===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.visible AS Visible, &lt;br /&gt;
DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors,&lt;br /&gt;
&lt;br /&gt;
(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;, &lt;br /&gt;
&lt;br /&gt;
now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
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) &amp;gt; 0&lt;br /&gt;
ORDER BY StartDate, Instructor_Email, Course_ID&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Course Design Reports==&lt;br /&gt;
&lt;br /&gt;
These are reports which summarize course design aspects, such as activity and resource modules per section, types of activities used, etc.&lt;br /&gt;
&lt;br /&gt;
===Course Content/Week===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report assumes that the first 14 sections in a course, not including the &amp;quot;0&amp;quot; or &amp;quot;Welcome&amp;quot; section, correspond to weeks (with &amp;quot;Subsections&amp;quot; given numbers much higher in the sequence). Of those sections, each is checked to count the number of:&lt;br /&gt;
&lt;br /&gt;
    Forums&lt;br /&gt;
    Graded Activities (may include Forums)&lt;br /&gt;
    Resources (not including a Label)&lt;br /&gt;
&lt;br /&gt;
Totals of each of these types of content elements per section are provided.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Only visible resources and activities are counted.&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: this is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
 &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT LIKE &#039;label&#039;),cm.id,NULL)) AS &#039;Ungraded Resources&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Graded Activities&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cs.section&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments and Weights===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Categories with weights of 0 are not included in this report.&lt;br /&gt;
&lt;br /&gt;
Only visible activities are included in this report.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This is designed to be a &amp;quot;Global&amp;quot; report in Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;) AS &#039;Grade Book Category&#039;&lt;br /&gt;
, IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND(SUM(DISTINCT gi.aggregationcoef), 2)+ROUND(SUM(DISTINCT mgi.aggregationcoef), 2)) AS &#039;Category weight&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT_WS(&#039;, &#039;,GROUP_CONCAT(DISTINCT gi.itemmodule SEPARATOR &#039;, &#039;), IF(mgi.id, &#039;manual&#039;,NULL)) AS &#039;Activity Types&#039;&lt;br /&gt;
, COUNT(DISTINCT gi.itemmodule) + IF(mgi.id,1,0) AS &#039;Different Activity Types&#039;&lt;br /&gt;
, CONCAT_WS(&#039;&amp;lt;br&amp;gt;&#039;, GROUP_CONCAT(DISTINCT gi.itemname ORDER BY gi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;), GROUP_CONCAT(DISTINCT mgi.itemname ORDER BY mgi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;)) AS &#039;Activity Names&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) + COUNT(DISTINCT mgi.id) AS &#039;Activity Count&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
&lt;br /&gt;
#get grade categories&lt;br /&gt;
LEFT JOIN prefix_grade_categories AS gc ON gc.courseid = c.id &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
JOIN prefix_grade_items AS gic ON gic.courseid = c.id AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
&lt;br /&gt;
# attach activities to course&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = c.id &lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.iteminstance = cm.instance AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.id&lt;br /&gt;
ORDER BY gc.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pre-Term Course Review===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
#   &amp;quot;Required blocks&amp;quot; include Instructor Block (mooprofile), Activities, and the Research block.&lt;br /&gt;
#    &amp;quot;Instructor Details&amp;quot; block is not the &amp;quot;Instructor&amp;quot; block (mooprofile) automatically provided by the system. It is an optional block that can be edited by the instructor. If not edited to remove boilerplate text, it should be hidden.&lt;br /&gt;
#    All courses should be in the &amp;quot;Collapsed Topics&amp;quot; format with the &amp;quot;Weeks&amp;quot; structure.&lt;br /&gt;
#    &amp;quot;Weeks defined in course settings&amp;quot; is taken from our SIS when the course shells are created, but can be edited by faculty. &amp;quot;# of weeks named and visible&amp;quot; should usually match or exceed this value.&lt;br /&gt;
#    We recommend that each week contain at least one forum, at least one graded activity, and at least one ungraded resource.&lt;br /&gt;
#    &amp;quot;Syllabus updated&amp;quot; date is for the first attached file found with the text &amp;quot;syllabus&amp;quot; in the name. The &amp;quot;Days ago&amp;quot; calculation is included for convenience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: At our institution, we construct categories each term, and insert a text string &amp;quot;staging&amp;quot; in the Category ID for pre-term courses during the preparation or &amp;quot;staging&amp;quot; phase of course development. We remove this text string (and change it to &amp;quot;production&amp;quot;) when courses go live at the start of the new term.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
#,RIGHT(c.idnumber,2) AS Type # Specific to GSC &amp;quot;Instructional Method&amp;quot; storage&lt;br /&gt;
&lt;br /&gt;
#, substring_index(substr(c.shortname FROM locate(&#039;.&#039;,c.shortname)+1),&#039;-&#039;,1) AS Section # Specific to GSC&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.lastname,&#039;, &#039;, u.firstname,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
,(SELECT IF((u2.description IS NULL) OR (u2.description LIKE &#039;&#039;),&#039;NO&#039;, &#039;YES&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT IF(u3.picture &amp;gt; 0,&#039;YES&#039;,&#039;NO&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u3 ON u3.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Picture&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(((bpi.visible IS NULL) OR (bpi.visible !=0)) AND ((bpm.visible IS NULL) OR (bpm.visible !=0)) AND ((bpa.visible IS NULL) OR (bpa.visible !=0)) AND ((bpr.visible IS NULL) OR (bpr.visible !=0)),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Required blocks visible&#039;&lt;br /&gt;
#, IF((bpm.visible IS NULL) OR (bpm.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Messages block visible&#039;&lt;br /&gt;
#, IF((bpa.visible IS NULL) OR (bpa.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;activities block visible&#039;&lt;br /&gt;
#, IF((bpr.visible IS NULL) OR (bpr.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;research block visible&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)) AND (bip.visible !=0),&#039;YES&#039;,&#039;&#039;) AS &#039;Instructor Details Block visible&#039; # This is a hack based on UUencoded string data from the title of HTML &amp;quot;Instructor Details&amp;quot; block&lt;br /&gt;
&lt;br /&gt;
#, IF(bi.configdata LIKE &#039;%ZGl0IHRoaXMgYmxvY2s%&#039;,&#039;NO&#039;,&#039;&#039;) AS &#039;Instructor Details Block Updated&#039; # HTML block has string &#039;dit this block&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(COUNT(bi.id) -  SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)),&#039;YES&#039;,&#039;&#039;) AS &#039;possible extra instructor blocks&#039; #looking for any HTML block with &amp;quot;instructor&amp;quot; in the title&lt;br /&gt;
&lt;br /&gt;
, IF(c.format=&#039;topcoll&#039;,&#039;YES&#039;, c.format) AS &#039;Collapsed Topics course format&#039; # change this if you want to test for a different format&lt;br /&gt;
, IF(cfo.value = 2, &#039;YES&#039;,&#039;NO&#039;) AS &#039;weeks structure&#039;&lt;br /&gt;
&lt;br /&gt;
, cfw.value AS &#039;weeks defined in course settings&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(((cs.name IS NOT NULL) AND (cs.visible = 1) AND (cs.section != &#039;0&#039;) AND (cs.sequence IS NOT NULL)),cs.id,NULL)) AS &#039;# of weeks named &amp;amp; visible (includes orphans)&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039; ,cs.id , NULL)) AS &#039;Weeks with Forum&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cs.id, NULL)) AS &#039;Weeks with Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT mgi.id) AS &#039;Manual Grade Items&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)),cm.id,NULL)) AS &#039;Resources&#039;&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)), cs.id, NULL)) AS &#039;Weeks with Resources&#039;&lt;br /&gt;
&lt;br /&gt;
# Here are some other things you could check for per course&lt;br /&gt;
#,(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 &#039;%forum%&#039;) AS Forums&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%quiz%&#039;) AS Quizzes&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%assign%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_resource.id) FROM prefix_resource JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course) AS Files&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_url.id) FROM prefix_url JOIN prefix_course ON prefix_course.id = prefix_url.course WHERE c.id = prefix_url.course) AS Links&lt;br /&gt;
&lt;br /&gt;
,(SELECT FROM_UNIXTIME(MAX(prefix_resource.timemodified))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS SyllabusDate&lt;br /&gt;
&lt;br /&gt;
,(SELECT TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(MAX(prefix_resource.timemodified)))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS DaysAgo&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, f.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement Forum Visible&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, fd.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement posted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
LEFT JOIN prefix_context AS ctxx ON c.id = ctxx.instanceid &lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpi ON bpi.contextid = ctxx.id AND bpi.blockinstanceid = &#039;43692&#039; # mooprofile&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpm ON bpm.contextid = ctxx.id AND bpm.blockinstanceid = &#039;43962&#039; # messages&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpa ON bpa.contextid = ctxx.id AND bpa.blockinstanceid = &#039;43963&#039; # activities&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpr ON bpr.contextid = ctxx.id AND bpr.blockinstanceid = &#039;38368&#039; # html research help&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.visible = 1 AND cs.sequence IS NOT NULL&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
LEFT JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_forum AS f ON f.course = c.id AND cm.instance = f.id AND cm.visible = 1&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.forum = f.id&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfo ON cfo.courseid = c.id AND cfo.name = &#039;layoutstructure&#039;&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfw ON cfw.courseid = c.id AND cfw.name = &#039;numsections&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_instances AS bi ON bi.parentcontextid = ctxx.id AND bi.blockname = &#039;html&#039; AND (bi.configdata LIKE &#039;%SW5zdHJ1Y3Rvc%&#039; or bi.configdata LIKE &#039;%bnN0cnVjdG9y%&#039;)&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bip ON bip.blockinstanceid = bi.id&lt;br /&gt;
&lt;br /&gt;
WHERE RIGHT(c.idnumber,2) IN (&#039;OL&#039;, &#039;BL&#039;, &#039;HY&#039;) &lt;br /&gt;
# AND substring(cc.path,2,2) IN (&#039;26&#039;) # Staging&lt;br /&gt;
#AND substring(cc.path,2,3) IN (&#039;158&#039;) # UG&lt;br /&gt;
AND cc.idnumber LIKE &#039;%staging%&#039;&lt;br /&gt;
AND ctxx.contextlevel = 50&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module instances + Module HITs by role teacher and student in course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
m.name AS &amp;quot;Module name&amp;quot;&lt;br /&gt;
, COUNT(*) AS &amp;quot;Module count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name ) AS &amp;quot;Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course_modules AS cm&lt;br /&gt;
JOIN mdl_modules AS m on m.id = cm.module&lt;br /&gt;
WHERE cm.course = &#039;%%COURSEID%%&#039;&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Syllabus===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Course Policies&amp;quot; and &amp;quot;Teaching Philosophy&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.fullname AS &#039;fullname&#039;&lt;br /&gt;
, ec.idnumber AS &#039;elis-id&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.startdate), &#039;%b %e, %Y&#039;) AS &#039;start&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.enddate), &#039;%b %e, %Y&#039;) AS &#039;end&#039;&lt;br /&gt;
, ecd.name AS &#039;longname&#039;&lt;br /&gt;
, ecd.code AS &#039;coursecode&#039;&lt;br /&gt;
, ecd.credits AS &#039;coursecredits&#039;&lt;br /&gt;
, ecd.syllabus AS &#039;description&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;learning-outcomes&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;outcomes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.firstname,&#039; &#039;, u.lastname,&#039;&amp;lt;/a&amp;gt; &#039;, u.email)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
, (SELECT  efc.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_char AS efc&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = efc.fieldid AND ef.shortname = &#039;term-code&#039;&lt;br /&gt;
WHERE ctxci.id = efc.contextid) AS &#039;termcode&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;prerequisites&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;prerequisites&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;textbooks&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;textbooks&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;other-class-materials&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;other-class-materials&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-policies&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-policies&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;teaching-philosophy&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;teaching-philosophy&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-methods&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-methods&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT u2.description&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT&lt;br /&gt;
&lt;br /&gt;
GROUP_CONCAT(DISTINCT CONCAT(&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;tr&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt;&#039;,IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;)&lt;br /&gt;
, &#039; &amp;lt;/td&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt; &#039;&lt;br /&gt;
,IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND( gi.aggregationcoef, 2)+ROUND(mgi.aggregationcoef, 2))&lt;br /&gt;
&lt;br /&gt;
) SEPARATOR &#039;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&#039;)&lt;br /&gt;
#get grade categories&lt;br /&gt;
FROM prefix_grade_categories AS gc &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gic ON gic.courseid = gc.courseid AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = gc.courseid  AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = gc.courseid and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
WHERE gc.courseid = c.id  ) AS &#039;grade categories&#039;&lt;br /&gt;
&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;50%&amp;quot; &amp;gt;&#039; AS &#039;table start&#039;&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;100%&amp;quot; &amp;gt;&#039; AS &#039;table start 2&#039;&lt;br /&gt;
, &#039;&amp;lt;/table&amp;gt;&#039; AS &#039;table end&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;activities-schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;schedule&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;grading-scale&#039;&lt;br /&gt;
WHERE ctxepm.id = eft.contextid) AS &#039;gradescale&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
# connect moodle course to ELIS class instance&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls_mdl AS ecm ON ecm.moodlecourseid = c.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls AS ec ON ec.id = ecm.classid&lt;br /&gt;
# class instance context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxci ON ctxci.instanceid = ec.id AND ctxci.contextlevel = &#039;14&#039;&lt;br /&gt;
&lt;br /&gt;
# connect ELIS class instance to ELIS course description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_crs AS ecd ON ecd.id = ec.courseid&lt;br /&gt;
# course description context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxecd ON ctxecd.instanceid = ecd.id AND ctxecd.contextlevel = &#039;13&#039;&lt;br /&gt;
&lt;br /&gt;
#connect ELIS program to ELIS Course Description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm_crs AS epc ON epc.courseid = ecd.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm AS epm ON epm.id = epc.curriculumid&lt;br /&gt;
# course program context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxepm ON ctxepm.instanceid = epm.id AND ctxepm.contextlevel = &#039;11&#039;&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Activities Helper===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report provides a list of the graded activities in a course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: Only graded activities are displayed.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This report assumes that course sections each last one week.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
# 303 Course Activities Helper&lt;br /&gt;
&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
gi.itemmodule AS &#039;activity type&#039;&lt;br /&gt;
# cs.section AS &#039;section number&#039;&lt;br /&gt;
&lt;br /&gt;
# Calculation assumes each section lasts one week&lt;br /&gt;
, CONCAT(DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section-1))), &#039;%b %e, %Y&#039;),&#039; - &amp;lt;br&amp;gt;&#039;,DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section))), &#039;%b %e, %Y&#039;)) AS &#039;Date&#039;&lt;br /&gt;
&lt;br /&gt;
, gi.itemname AS &#039;activity name&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = cm.instance) AS &#039;intro&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT f.intro FROM prefix_forum AS f WHERE f.id = cm.instance) AS &#039;f intro&#039;&lt;br /&gt;
&lt;br /&gt;
, CASE gi.itemmodule &lt;br /&gt;
WHEN &#039;assign&#039; THEN (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;forum&#039; THEN (SELECT f.intro FROM prefix_forum AS f WHERE f.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;quiz&#039; THEN (SELECT q.intro FROM prefix_quiz AS q WHERE q.id = gi.iteminstance) &lt;br /&gt;
END AS &#039;test case&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT GROUP_CONCAT(CONCAT(&#039; - &#039;,gi.itemname) SEPARATOR &#039;&amp;lt;BR&amp;gt;&#039;) FROM  prefix_grade_items AS gi  JOIN prefix_course_modules AS cm ON  gi.iteminstance = cm.instance WHERE gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id ) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
#get grade sections&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id  AND cs.section &amp;gt; 0 AND cs.section &amp;lt;=14&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_assign AS asg ON asg.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_grade_items AS gi  ON  gi.iteminstance = cm.instance AND gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
&lt;br /&gt;
ORDER BY gi.itemmodule, cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Grade and Course Completion Reports==&lt;br /&gt;
===Site-Wide Grade Report with All Items===&lt;br /&gt;
Shows grades for all course items along with course totals for each student. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, &lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
For MySQL users, you&#039;ll need to use the MySQL DATE_ADD function instead of DATEADD. Replace the line:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
And:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
CONCAT(u.firstname,&#039; &#039;,u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site-Wide Grade Report with Just Course Totals===&lt;br /&gt;
A second site-wide grade report for all students that just shows course totals. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id AND gi.itemtype = &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For MySQL users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN CONCAT(c.fullname, &#039; - Total&#039;)&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS TIME&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
 &lt;br /&gt;
WHERE  gi.courseid = c.id AND gi.itemtype = &#039;course&#039;&lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Learner report by Learner with grades===&lt;br /&gt;
Which Learners in which course and what are the grades&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;Name&#039; , u.lastname AS &#039;Surname&#039;, c.fullname AS &#039;Course&#039;, cc.name AS &#039;Category&#039;, &lt;br /&gt;
CASE WHEN gi.itemtype = &#039;Course&#039;    &lt;br /&gt;
THEN c.fullname + &#039; Course Total&#039;  &lt;br /&gt;
ELSE gi.itemname &lt;br /&gt;
END AS &#039;Item Name&#039;, ROUND(gg.finalgrade,2) AS Score,ROUND(gg.rawgrademax,2) AS Max, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) as Percentage,&lt;br /&gt;
&lt;br /&gt;
if (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) &amp;gt; 79,&#039;Yes&#039; , &#039;No&#039;) as Pass&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id &lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid &lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category &lt;br /&gt;
WHERE  gi.courseid = c.id and gi.itemname != &#039;Attendance&#039;&lt;br /&gt;
ORDER BY `Name` ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A very simple report with a list of course completion status by username. Completions are noted by date, blank otherwise. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  u.username, &lt;br /&gt;
  c.shortname,  &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%Y-%m-%d&#039;) AS completed&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion with Criteria===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A report with course completions by username, with Aggregation method, Criteria types, and Criteria detail where available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username AS user, &lt;br /&gt;
c.shortname AS course,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(t.timecompleted),&#039;%Y-%m-%d&#039;) AS completed,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = c.id AND a.criteriatype IS NULL) = 1) THEN &amp;quot;Any&amp;quot;&lt;br /&gt;
ELSE &amp;quot;All&amp;quot;&lt;br /&gt;
END AS aggregation,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;Self&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN &amp;quot;By Date&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 3 THEN &amp;quot;Unenrol Status&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &amp;quot;Activity&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 5 THEN &amp;quot;Duration&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 6 THEN &amp;quot;Course Grade&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 7 THEN &amp;quot;Approve by Role&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 8 THEN &amp;quot;Previous Course&amp;quot;&lt;br /&gt;
END AS criteriatype,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;*&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(p.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN p.criteriatype = 3 THEN t.unenroled&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,p.module,&#039;/view.php?id=&#039;,p.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,p.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN p.criteriatype = 5 THEN p.enrolperiod&lt;br /&gt;
WHEN p.criteriatype = 6 THEN CONCAT(&#039;Needed: &#039;,ROUND(p.gradepass,2),&#039; Achieved: &#039;,ROUND(t.gradefinal,2)) &lt;br /&gt;
WHEN p.criteriatype = 7 THEN p.role&lt;br /&gt;
WHEN p.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = p.courseinstance)&lt;br /&gt;
END AS criteriadetail &lt;br /&gt;
FROM prefix_course_completion_crit_compl AS t&lt;br /&gt;
JOIN prefix_user AS u ON t.userid = u.id&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
JOIN prefix_course_completion_criteria AS p ON t.criteriaid = p.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Completion Enabled and their settings===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with completion enabled and their Aggregation setting, Criteria types, and Criteria details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT c.shortname AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = t.course AND a.criteriatype IS NULL)) = 2 THEN &amp;quot;All&amp;quot;&lt;br /&gt;
ELSE &amp;quot;Any&amp;quot;&lt;br /&gt;
END AS Course_Aggregation,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;Self completion&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN &amp;quot;Date done by&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;Unenrolement&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 4 THEN &amp;quot;Activity completion&amp;quot;   &lt;br /&gt;
WHEN t.criteriatype = 5 THEN &amp;quot;Duration in days&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 6 THEN &amp;quot;Final grade&amp;quot;     &lt;br /&gt;
WHEN t.criteriatype = 7 THEN &amp;quot;Approve by role&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 8 THEN &amp;quot;Previous course&amp;quot;&lt;br /&gt;
END AS Criteria_type,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(t.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 4 THEN&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,t.module,&#039;/view.php?id=&#039;,t.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,t.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN t.criteriatype = 5 THEN ROUND(t.enrolperiod/86400)&lt;br /&gt;
WHEN t.criteriatype = 6 THEN ROUND(t.gradepass,2)&lt;br /&gt;
WHEN t.criteriatype = 7 THEN (SELECT r.shortname FROM prefix_role AS r WHERE r.id = t.role)&lt;br /&gt;
WHEN t.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = t.courseinstance)&lt;br /&gt;
END AS Criteria_detail&lt;br /&gt;
FROM prefix_course_completion_criteria as t&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Completion Report with custom dates===&lt;br /&gt;
&lt;br /&gt;
List of users who completed multiple or single course/s from a start date to end date chosen by the user. The output gives username, name, course name, completion date and score&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT u.username AS &#039;User Name&#039;,&lt;br /&gt;
CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Name&#039;,&lt;br /&gt;
c.shortname AS &#039;Course Name&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%W %e %M, %Y&#039;) AS &#039;Completed Date&#039;,&lt;br /&gt;
ROUND(c4.gradefinal,2) AS &#039;Score&#039;&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
JOIN prefix_course_completion_crit_compl AS c4 ON u.id = c4.userid&lt;br /&gt;
WHERE c.enablecompletion = 1  AND (p.timecompleted IS NOT NULL OR p.timecompleted !=&#039;&#039;) &lt;br /&gt;
AND (p.timecompleted&amp;gt;= :start_date AND p.timecompleted&amp;lt;=:end_date)&lt;br /&gt;
GROUP BY u.username&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scales used in activities===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT scale.name&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,gi.itemmodule,&#039;/view.php?id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module View&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/modedit.php?up&#039;,&#039;date=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module Settings&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON c.id = gi.courseid&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = gi.courseid AND cm.instance = gi.iteminstance&lt;br /&gt;
JOIN prefix_scale AS scale ON scale.id = gi.scaleid&lt;br /&gt;
WHERE gi.scaleid IS NOT NULL&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Extra Credit Items by Name Only===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
This query identifies grade items in visible courses with student enrollment that have &amp;quot;extra credit&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, gi.itemname AS Item_Name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors&lt;br /&gt;
&lt;br /&gt;
,(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;&lt;br /&gt;
&lt;br /&gt;
,now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON gi.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE gi.itemname LIKE &#039;%extra credit%&#039; &lt;br /&gt;
	AND gi.gradetype = &#039;1&#039; &lt;br /&gt;
	AND gi.hidden = &#039;0&#039; &lt;br /&gt;
	AND gi.aggregationcoef = &#039;0&#039; &lt;br /&gt;
	AND c.visible = 1&lt;br /&gt;
	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) &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
GROUP BY Course_ID, gi.id&lt;br /&gt;
ORDER BY StartDate, Course_ID&lt;br /&gt;
 &lt;br /&gt;
%%FILTER_SEARCHTEXT:Course_ID:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site Wide Number of Courses Completed by User===&lt;br /&gt;
Contributed by Ken St. John&lt;br /&gt;
&lt;br /&gt;
Simple report that shows the number of completed courses for all users site wide&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname, u.firstname,&lt;br /&gt;
COUNT(p.timecompleted) AS TotalCompletions&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
GROUP BY p.userid&lt;br /&gt;
ORDER BY u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Activity Module Reports==&lt;br /&gt;
&lt;br /&gt;
=== User activity completions with dates===&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.username As &#039;User&#039;,&lt;br /&gt;
c.shortname AS &#039;Course&#039;,&lt;br /&gt;
m.name AS Activitytype, &lt;br /&gt;
CASE &lt;br /&gt;
    WHEN cm.module = 1 THEN (SELECT a1.name FROM prefix_assign a1            WHERE a1.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 2 THEN (SELECT a2.name FROM prefix_assignment a2    WHERE a2.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 3 THEN (SELECT a3.name FROM prefix_book a3               WHERE a3.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 4 THEN (SELECT a4.name FROM prefix_chat a4                WHERE a4.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 5 THEN (SELECT a5.name FROM prefix_choice a5            WHERE a5.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 6 THEN (SELECT a6.name FROM prefix_data a6                WHERE a6.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 7 THEN (SELECT a7.name FROM prefix_feedback a7        WHERE a7.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 8 THEN (SELECT a8.name FROM prefix_folder a8              WHERE a8.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 9 THEN (SELECT a9.name FROM prefix_forum a9              WHERE a9.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 10 THEN (SELECT a10.name FROM prefix_glossary a10         WHERE a10.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 11 THEN (SELECT a11.name FROM prefix_imscp  a11           WHERE a11.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 12 THEN (SELECT a12.name FROM prefix_label a12              WHERE a12.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 13 THEN (SELECT a13.name FROM prefix_lesson a13            WHERE a13.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 14 THEN (SELECT a14.name FROM prefix_lti a14                    WHERE a14.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 15 THEN (SELECT a15.name FROM prefix_page a15               WHERE a15.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 16 THEN (SELECT a16.name FROM prefix_quiz  a16               WHERE a16.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 17 THEN (SELECT a17.name FROM prefix_resource a17         WHERE a17.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 18 THEN (SELECT a18.name FROM prefix_scorm a18             WHERE a18.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 19 THEN (SELECT a19.name FROM prefix_survey a19             WHERE a19.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 20 THEN (SELECT a20.name FROM prefix_url a20                      WHERE a20.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 21 THEN (SELECT a21.name FROM prefix_wiki a21                    WHERE a21.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 22 THEN (SELECT a22.name FROM prefix_workshop a22           WHERE a22.id = cm.instance)&lt;br /&gt;
END AS Actvityname,&lt;br /&gt;
# cm.section AS Coursesection,&lt;br /&gt;
CASE&lt;br /&gt;
    WHEN cm.completion = 0 THEN &#039;0 None&#039;&lt;br /&gt;
    WHEN cm.completion = 1 THEN &#039;1 Self&#039;&lt;br /&gt;
    WHEN cm.completion = 2 THEN &#039;2 Auto&#039;&lt;br /&gt;
END AS Activtycompletiontype, &lt;br /&gt;
CASE&lt;br /&gt;
   WHEN cmc.completionstate = 0 THEN &#039;In Progress&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 1 THEN &#039;Completed&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 2 THEN &#039;Completed with Pass&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 3 THEN &#039;Completed with Fail&#039;&lt;br /&gt;
   ELSE &#039;Unknown&#039;&lt;br /&gt;
END AS &#039;Progress&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(cmc.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;&lt;br /&gt;
FROM prefix_course_modules_completion cmc &lt;br /&gt;
JOIN prefix_user u ON cmc.userid = u.id&lt;br /&gt;
JOIN prefix_course_modules cm ON cmc.coursemoduleid = cm.id&lt;br /&gt;
JOIN prefix_course c ON cm.course = c.id&lt;br /&gt;
JOIN prefix_modules m ON cm.module = m.id&lt;br /&gt;
# skip the predefined admin and guest user&lt;br /&gt;
WHERE u.id &amp;gt; 2&lt;br /&gt;
# config reports filters&lt;br /&gt;
%%FILTER_USERS:u.username%%&lt;br /&gt;
%%FILTER_SEARCHTEXT:m.name:~%%&lt;br /&gt;
%%FILTER_STARTTIME:cmc.timemodified:&amp;gt;%% %%FILTER_ENDTIME:cmc.timemodified:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many SCORM activities are used in each Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cm.course,c.fullname ,m.name &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/scorm/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,count(cm.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS Counter&lt;br /&gt;
 &lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
  JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
  JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%scorm%&#039; &lt;br /&gt;
GROUP BY cm.course,cm.module &lt;br /&gt;
ORDER BY count(cm.id) desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===SCORM Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of SCORM activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, scm.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;SCO%&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_scorm AS scm ON scm.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LTI (External Tool) Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of  LTI (External Tool) Usage activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, lti.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;lti&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_lti AS lti ON lti.id = cm.instance&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each MODULE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module,action,count(id) as counter&lt;br /&gt;
FROM prefix_log&lt;br /&gt;
GROUP BY module,action&lt;br /&gt;
ORDER BY module,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Most popular ACTIVITY===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, module&lt;br /&gt;
FROM prefix_log l&lt;br /&gt;
WHERE module != &#039;login&#039; AND module != &#039;course&#039; AND module != &#039;role&#039;&lt;br /&gt;
GROUP BY module&lt;br /&gt;
ORDER BY hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide use of ACTIVITIES and RESOURCES===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count( cm.id ) AS counter, m.name&lt;br /&gt;
FROM `prefix_course_modules` AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
ORDER BY counter DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LOG file ACTIONS per MODULE per COURSE (IDs)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select course,module,action,count(action) as summa from prefix_log&lt;br /&gt;
where action &amp;lt;&amp;gt; &#039;new&#039;&lt;br /&gt;
group by course,action,module&lt;br /&gt;
order by course,module,action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System Wide usage count of various course Activities===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
Like: Forum, Wiki, Blog, Assignment, Database,&lt;br /&gt;
#Within specific category&lt;br /&gt;
#Teacher name in course&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS Forums&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%data%&#039;) AS Databses&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%assignment%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 18)&lt;br /&gt;
ORDER BY Wikis DESC,Blogs DESC, Forums DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course wiki usage/activity over the last 6 semesters===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &amp;quot;Courses with Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester A%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester A&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester B%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester B&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed WIKI activity (per wiki per course)===&lt;br /&gt;
Including Number of Students in course (for reference)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID  &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id ) AS Students&lt;br /&gt;
,m.name&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%updat%&#039; ) as &#039;UPDAT E&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%annotate%&#039; ) as ANNOTATE&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%comment%&#039; ) as COMMENT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%add%&#039; ) as &#039;A DD&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%edit%&#039; ) as EDIT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action NOT LIKE &#039;%view%&#039; ) as &#039;All (NO View)&#039;&lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
GROUP BY cm.course,cm.module&lt;br /&gt;
ORDER BY &#039;All (NO View)&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wiki usage, system wide===&lt;br /&gt;
(you can filter the output by selecting some specific course categories : &amp;quot;WHERE c.category IN ( 8,13,15)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039;) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%add%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ADD&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%edit%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;EDIT&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%annotate%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ANNOTATE&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%comments%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;Comments&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_ouwiki_pages as ouwp&lt;br /&gt;
JOIN prefix_ouwiki as ouw ON ouw.id = ouwp.subwikiid&lt;br /&gt;
WHERE ouw.course = c.id GROUP BY ouw.course  ) as OUWikiPages&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( DISTINCT nwp.pagename ) FROM prefix_wiki_pages AS nwp&lt;br /&gt;
JOIN prefix_wiki AS nw ON nw.id = nwp.dfwiki WHERE nw.course = c.id ) As NWikiPages&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Wikis &amp;gt; 0&lt;br /&gt;
ORDER BY &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Aggregated Teacher activity by &amp;quot;WEB2&amp;quot; Modules===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
The NV column shows activity without VIEW log activity&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.userid, u.firstname,u.lastname&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039;) AS Wiki&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Wiki_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039;) AS Forum&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Forum_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039;) AS Blog&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Blog_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039;) AS Assignment&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Assignment_NV&lt;br /&gt;
FROM prefix_role_assignments AS ra &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
WHERE ra.roleid = 3 &lt;br /&gt;
GROUP BY ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the certificates issued, sort by variables in the custom profile fields===&lt;br /&gt;
Note: The SQL queries look intimidating at first, but isn&#039;t really that difficult to learn. I&#039;ve seen in the forums that users wanted to do &#039;site-wide&#039; groups in 1.9x. This is sort of the idea. It pulls all the certificates issued to all users sorted by the custom profile fields, which in my case is the Units or Depts (i.e. my site wide groups). Why certificates? I&#039;ve explored with both grades and quizzes, the course admins are not really interested in the actual grades but whether the learner received a certificate (i.e. passed the course with x, y, z activities). It also saves me from creating groups and assigning them into the right groups. Even assigning in bulk is not efficient, since I have upward of 25 groups per course and constantly new learners enrolling in courses. The limitation is something to do with the server? as it only pull 5000 rows of data. If anyone figured out how to change this, please let me know. In the meantime, the work around is to pull only a few units/depts at a time to limit the number of rows. This is fine at the moment, since each course admin are only responsible for certain units/depts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(prefix_certificate_issues.timecreated), &#039;%Y-%m-%d&#039; ) AS Date,&lt;br /&gt;
prefix_certificate_issues.classname AS Topic,&lt;br /&gt;
prefix_certificate.name AS Certificate,&lt;br /&gt;
prefix_certificate_issues.studentname as Name,&lt;br /&gt;
prefix_user_info_data.data AS Units&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_certificate_issues&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_user_info_data&lt;br /&gt;
on prefix_certificate_issues.userid = prefix_user_info_data.userid&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_certificate&lt;br /&gt;
on prefix_certificate_issues.certificateid = prefix_certificate.id&lt;br /&gt;
&lt;br /&gt;
WHERE prefix_user_info_data.data=&#039;Unit 1&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 2&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 3&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY Units, Name, Topic ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== All Simple Certificates Earned in the Site===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 [http://www.mysqltutorial.org/mysql-date_format/ DATE_FORMAT] function.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
CONCAT (u.firstname, &#039; &#039;,u.lastname) As &#039;User&#039;,&lt;br /&gt;
c.fullname AS &#039;Course&#039;,&lt;br /&gt;
sc.name AS &#039;Certificate&#039;,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(sci.timecreated), &#039;%Y-%m-%d&#039; ) As &#039;Date Awarded&#039;&lt;br /&gt;
# sci.code &#039;CertificateId&#039;&lt;br /&gt;
FROM prefix_simplecertificate_issues sci&lt;br /&gt;
JOIN prefix_user u ON sci.userid = u.id&lt;br /&gt;
JOIN prefix_simplecertificate sc ON sci.certificateid = sc.id&lt;br /&gt;
JOIN prefix_course AS c ON sc.course = c.id&lt;br /&gt;
ORDER BY sci.timecreated DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE DATEDIFF(NOW(),FROM_UNIXTIME(sci.timecreated) ) &amp;lt; 30&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Counter Blog usage in Courses,system wide===&lt;br /&gt;
What teachers in what courses, uses blogs and how many + student count in that course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT ( @counter := @counter+1) as counter, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c, (SELECT @counter := 0) as s_init&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Blogs &amp;gt; 0&lt;br /&gt;
ORDER BY Blogs DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Elluminate (Blackboard Collaborate) - system wide usage===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT e.name As Session ,er.recordingsize&lt;br /&gt;
,c.fullname As Course&lt;br /&gt;
,u.firstname,u.lastname &lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(e.timestart),&#039;%d-%m-%Y&#039;) AS dTimeStart&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/moodle/mod/elluminate/loadrecording.php?id=&#039;,er.id,&#039;&amp;quot;&amp;gt;Show&amp;lt;/a&amp;gt;&#039;) AS RecordedSession&lt;br /&gt;
&lt;br /&gt;
FROM prefix_elluminate_recordings AS er&lt;br /&gt;
JOIN prefix_elluminate AS e ON e.meetingid = er.meetingid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = e.creator &lt;br /&gt;
ORDER BY er.recordingsize DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choice ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Results of the Choice activity. For all courses, shows course shortname, username, the Choice text, and the answer chosen by the user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname AS course, u.username, h.name as question, o.text AS answer&lt;br /&gt;
FROM prefix_choice AS h&lt;br /&gt;
JOIN prefix_course AS c ON h.course = c.id&lt;br /&gt;
JOIN prefix_choice_answers AS a ON h.id = a.choiceid&lt;br /&gt;
JOIN prefix_user AS u ON a.userid = u.id&lt;br /&gt;
JOIN prefix_choice_options AS o ON a.optionid = o.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment type usage in courses ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assign/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_assign WHERE c.id = course) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;file&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
#GROUP BY apc.plugin&lt;br /&gt;
) AS &amp;quot;File Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;onlinetext&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Online Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;pdf&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;PDF Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;offline&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Offline Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;comments&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Assignments Comments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_assign AS assign&lt;br /&gt;
JOIN prefix_course AS c ON c.id = assign.course&lt;br /&gt;
GROUP BY c.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moodle Learning Analytics Reports==&lt;br /&gt;
&lt;br /&gt;
===Average Cognitive Depth and Social Breadth===&lt;br /&gt;
&lt;br /&gt;
Here is a simple SQL snippet to calculate average cognitive depth and social breadth indicators for all students in the system. This one ignores  indicator values of 0, as they are nulls as defined in this model.&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
i.contextid,&lt;br /&gt;
i.sampleid,&lt;br /&gt;
&lt;br /&gt;
TRUNC(AVG(CASE&lt;br /&gt;
WHEN i.indicator LIKE &#039;%cognitive%&#039; THEN i.value &lt;br /&gt;
ELSE &#039;0&#039;&lt;br /&gt;
END),2) AS &amp;quot;Average Cognitive Depth&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
TRUNC(AVG(CASE&lt;br /&gt;
WHEN i.indicator LIKE &#039;%social%&#039; THEN i.value &lt;br /&gt;
ELSE &#039;0&#039;&lt;br /&gt;
END),2) AS &amp;quot;Average Social Breadth&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_analytics_indicator_calc as i&lt;br /&gt;
WHERE&lt;br /&gt;
i.value != 0&lt;br /&gt;
GROUP BY i.contextid, i.sampleid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Assignment Module Reports==&lt;br /&gt;
===All Ungraded Assignments===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
Returns all the submitted assignments that still need grading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id&lt;br /&gt;
and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Ungraded Assignments w/ Link===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;a href=&amp;quot;http://education.varonis.com/mod/assignment/submissions.php&#039; + char(63) +&lt;br /&gt;
+ &#039;id=&#039; + cast(cm.id as varchar) + &#039;&amp;amp;userid=&#039; + cast(u.id as varchar) &lt;br /&gt;
+ &#039;&amp;amp;mode=single&amp;amp;filter=0&amp;amp;offset=2&amp;quot;&amp;gt;&#039; + a.name + &#039;&amp;lt;/a&amp;gt;&#039;&lt;br /&gt;
AS &amp;quot;Assignmentlink&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments (and Quizzes) waiting to be graded===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This report requires a YEAR filter to be added (Available when using the latest block/configurable_reports)&lt;br /&gt;
&lt;br /&gt;
Which you can always remove, to make this query work on earlier versions.&lt;br /&gt;
&lt;br /&gt;
The report includes: &lt;br /&gt;
*number of quizzes&lt;br /&gt;
*unFinished Quiz attempts&lt;br /&gt;
*Finished Quiz attempts&lt;br /&gt;
*number of students&lt;br /&gt;
*number of Assignments&lt;br /&gt;
*number of submitted answers by students &lt;br /&gt;
*number of unchecked assignments (waiting for the Teacher) in a Course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
 &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assignment/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;מטלות&amp;lt;/a&amp;gt;&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;בחנים&amp;lt;/a&amp;gt;&#039;) AS &#039;Quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_course_modules cm &lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module &lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039; AND cm.course = c.id &lt;br /&gt;
GROUP BY cm.course &lt;br /&gt;
) AS &#039;nQuizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish = 0&lt;br /&gt;
GROUP BY q.course) AS &#039;unFinished Quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish &amp;gt; 0&lt;br /&gt;
GROUP BY q.course) AS &#039;finished quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS nStudents&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(a.id)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) nAssignments&lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE a.course = c.id AND FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course&lt;br /&gt;
) &#039;Open &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(ROUND( (100 / iAssignments ) * iOpenAssignments ) ,&#039;%&#039;) &#039;unFinished &amp;lt;br/&amp;gt;Assignments &amp;lt;br/&amp;gt;(percent)&#039;&lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE asb.grade &amp;lt; 0 AND cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;unChecked  &amp;lt;br/&amp;gt;Submissions&#039; &lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;Submitted  &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblAssignmentsCount ON tblAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iOpenAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblOpenAssignmentsCount ON tblOpenAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1  &lt;br /&gt;
#AND c.fullname LIKE &#039;%תשעג%&#039;&lt;br /&gt;
%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
ORDER BY &#039;Open &amp;lt;br/&amp;gt;Assignments&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rubrics without zero values in criteria===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
Rubric calculations in Moodle can fail to align with instructors expectations if they lack a zero value for each criterion used in the assessment. From documentation at https://docs.moodle.org/32/en/Rubrics#Grade_calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;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.&lt;br /&gt;
TIP: To avoid confusion from this sort of thing, we recommend including a level with 0 points in every rubric criterion.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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&#039; favor.&lt;br /&gt;
&lt;br /&gt;
Includes search filter of course idnumber.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cat.name AS Department, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, &lt;br /&gt;
c.fullname AS Course_Name, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/grading/form/rubric/edit.php&#039;,CHAR(63),&#039;areaid=&#039;,gd.areaid,&#039;&amp;quot;&amp;gt;&#039;,gd.areaid,&#039;&amp;lt;/a&amp;gt;&#039;) AS Rubric&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_categories AS cat &lt;br /&gt;
ON cat.id = c.category&lt;br /&gt;
JOIN prefix_course_modules AS cm &lt;br /&gt;
ON c.id=cm.course&lt;br /&gt;
JOIN prefix_context AS ctx &lt;br /&gt;
ON cm.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_grading_areas AS garea &lt;br /&gt;
ON ctx.id = garea.contextid&lt;br /&gt;
JOIN prefix_grading_definitions AS gd &lt;br /&gt;
ON garea.id = gd.areaid&lt;br /&gt;
JOIN prefix_gradingform_rubric_criteria AS crit &lt;br /&gt;
ON gd.id = crit.definitionid&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id&lt;br /&gt;
WHERE cm.visible=&#039;1&#039; AND garea.activemethod = &#039;rubric&#039; AND (crit.id NOT IN&lt;br /&gt;
(SELECT crit.id&lt;br /&gt;
FROM prefix_gradingform_rubric_criteria AS crit&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id WHERE levels.score = &#039;0&#039;))&lt;br /&gt;
&lt;br /&gt;
GROUP BY Rubric&lt;br /&gt;
ORDER BY Course_ID, Rubric&lt;br /&gt;
&lt;br /&gt;
%%FILTER_SEARCHTEXT:c.idnumber:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Who is using &amp;quot;Single File Upload&amp;quot; assignment===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,ass.name as &amp;quot;Assignment Name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM &lt;br /&gt;
prefix_assignment as ass&lt;br /&gt;
&lt;br /&gt;
JOIN &lt;br /&gt;
prefix_course as c ON c.id = ass.course&lt;br /&gt;
&lt;br /&gt;
WHERE `assignmenttype` LIKE &#039;uploadsingle&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Feedback Module Reports==&lt;br /&gt;
===List the answers to all the Feedback activities within the current course, submitted by the current user===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT /* crs.fullname as &amp;quot;Course name&amp;quot;, f.name AS &amp;quot;Journal name&amp;quot;, CONCAT(u.firstname,&#039; &#039;,UPPER(u.lastname)) as &amp;quot;Participant&amp;quot;, */ /* include these fields if you want to check the composition of the recordset */&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified),&#039;%W %e %M, %Y&#039;) as &amp;quot;Answer Date&amp;quot;,&lt;br /&gt;
CASE i.typ WHEN &#039;label&#039; THEN i.presentation ELSE i.name END as &amp;quot;Topic&amp;quot;,  /* usually labels are used as section titles, so you&#039;d want them present in the recordset */&lt;br /&gt;
v.value as &amp;quot;My Answer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback AS f&lt;br /&gt;
INNER JOIN prefix_course as crs on crs.id=f.course %%FILTER_COURSES:f.course%% &lt;br /&gt;
INNER JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
INNER JOIN prefix_feedback_completed AS c on f.id=c.feedback %%FILTER_COURSEUSER:c.userid%% &lt;br /&gt;
LEFT JOIN prefix_feedback_value AS v on v.completed=c.id AND v.item=i.id&lt;br /&gt;
INNER JOIN prefix_user AS u on c.userid=u.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%% AND u.id = %%USERID%%  AND c.anonymous_response = 1  /* This clause limits the recordset to the current course and the current user and includes/ excludes the anonymous responses as needed */&lt;br /&gt;
&lt;br /&gt;
ORDER BY f.id, c.timemodified, i.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show all Feedbacks from all courses for all users including showing names of anonymous users===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &#039;Not-logged-in&#039; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS Course, &lt;br /&gt;
f.name AS Feedback,&lt;br /&gt;
# i.id AS Itemid,&lt;br /&gt;
i.name AS Itemname,&lt;br /&gt;
i.label AS Itemlabel,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN f.anonymous = 1 AND u.id != 0 THEN CONCAT(u.username, &#039; :ANON&#039;)&lt;br /&gt;
 WHEN fc.userid = 0 THEN &#039;Not-logged-in&#039;&lt;br /&gt;
 ELSE u.username&lt;br /&gt;
END AS &#039;User&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(fc.timemodified),&#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;Completed&amp;quot;,&lt;br /&gt;
v.value AS &amp;quot;Choice&amp;quot;,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN i.typ = &#039;multichoice&#039; THEN&lt;br /&gt;
     IF (  SUBSTRING(i.presentation,1,6)=&#039;d&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&#039;,&lt;br /&gt;
	       SUBSTRING(i.presentation,7),&lt;br /&gt;
		   i.presentation)&lt;br /&gt;
 ELSE i.presentation&lt;br /&gt;
END AS &amp;quot;Answers&amp;quot;,&lt;br /&gt;
i.typ,&lt;br /&gt;
i.dependitem,&lt;br /&gt;
i.dependvalue&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback f&lt;br /&gt;
JOIN prefix_course c ON c.id=f.course &lt;br /&gt;
JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
JOIN prefix_feedback_completed fc ON f.id=fc.feedback&lt;br /&gt;
LEFT JOIN prefix_feedback_value v ON v.completed=fc.id AND v.item=i.id&lt;br /&gt;
LEFT JOIN prefix_user AS u ON fc.userid=u.id&lt;br /&gt;
WHERE i.typ != &#039;pagebreak&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Resource Module Reports==&lt;br /&gt;
===List &amp;quot;Recently uploaded files&amp;quot;===&lt;br /&gt;
see what users are uploading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT FROM_UNIXTIME(time,&#039;%Y %M %D %h:%i:%s&#039;) as time ,ip,userid,url,info  &lt;br /&gt;
FROM `prefix_log` &lt;br /&gt;
WHERE `action` LIKE &#039;upload&#039; &lt;br /&gt;
ORDER BY `prefix_log`.`time`  DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Courses that loaded a specific file: &amp;quot;X&amp;quot;===&lt;br /&gt;
Did the Teacher (probably) uploaded course&#039;s Syllabus ?&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname  FROM `prefix_log` as l &lt;br /&gt;
JOIN prefix_course as c ON c.id = l.course &lt;br /&gt;
WHERE `action` LIKE &#039;%upload%&#039; AND ( info LIKE &#039;%Syllabus%&#039; OR info LIKE &#039;%Sylabus%&#039; ) GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All resources that link to some specific external website===&lt;br /&gt;
+ link to course&lt;br /&gt;
+ who&#039;s the teacher&lt;br /&gt;
+ link to external resource&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/resource/view.php?id=&#039;,r.id,&#039;&amp;quot;&amp;gt;&#039;,r.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Resource&lt;br /&gt;
FROM prefix_resource AS r &lt;br /&gt;
JOIN prefix_course AS c ON r.course = c.id&lt;br /&gt;
WHERE r.reference LIKE &#039;http://info.oranim.ac.il/home%&#039; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;quot;Compose Web Page&amp;quot; RESOURCE count===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT course,prefix_course.fullname, COUNT(*) AS Total&lt;br /&gt;
FROM `prefix_resource`&lt;br /&gt;
JOIN `prefix_course` ON prefix_course.id = prefix_resource.course&lt;br /&gt;
WHERE type=&#039;html&#039;&lt;br /&gt;
GROUP BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resource count in courses===&lt;br /&gt;
+ (First)Teacher name&lt;br /&gt;
+ Where course is inside some specific Categories&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
COUNT(*) AS count&lt;br /&gt;
,r.course &lt;br /&gt;
,c.shortname shortname&lt;br /&gt;
,c.fullname coursename&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user as u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = r.course AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
FROM prefix_resource r &lt;br /&gt;
JOIN prefix_course c ON r.course = c.id&lt;br /&gt;
WHERE c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY r.course&lt;br /&gt;
ORDER BY COUNT(*) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Delete all the automated backup files===&lt;br /&gt;
Prepare bash cli script to delete all the automated backup files on the file system. (clean up some disk space)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT( &#039;rm -f /var/moodledatanew/filedir/&#039;, SUBSTRING( contenthash, 1, 2 ) , &#039;/&#039;, SUBSTRING( contenthash, 3, 2 ) , &#039;/&#039;, contenthash ) &lt;br /&gt;
FROM `mdl_files` &lt;br /&gt;
WHERE `filename` LIKE &#039;%mbz%&#039;&lt;br /&gt;
AND filearea = &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find out how much disk space is used by all automated backup files:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT SUM(filesize)/(1024*1024*1024) FROM `mdl_files` WHERE  `filename` LIKE &#039;%mbz%&#039; AND filearea =  &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Forum Module Reports==&lt;br /&gt;
===print all User&#039;s post in course Forums===&lt;br /&gt;
%%COURSEID%% is a variable the is replace by the current CourseID you are running the sql report from. if you are using the latest block/configurable_reports ! (You can always change it to a fixed course or remove it to display all courses.)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php?course=&#039;,c.id,&#039;&amp;amp;id=&#039;,u.id,&#039;&amp;amp;mode=posts&amp;quot;&amp;gt;&#039;,CONCAT(u.firstname,&#039; &#039;, u.lastname),&#039;&amp;lt;/a&amp;gt;&#039;) As Fullname&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Forum&lt;br /&gt;
,count(*) as Posts&lt;br /&gt;
,(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&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_user as u ON u.id = fp.userid &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = fd.course &lt;br /&gt;
WHERE fd.course = %%COURSEID%% &lt;br /&gt;
GROUP BY f.id,u.id&lt;br /&gt;
ORDER BY u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE by type -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, prefix_forum.type, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course,prefix_forum.type&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Forum activity - system wide===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,c.fullname as Course&lt;br /&gt;
,f.type&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
, fd.forum, f.name,count(*) AS cPostAndDisc&lt;br /&gt;
,(SELECT count(*) FROM prefix_forum_discussions AS ifd WHERE ifd.forum = f.id) AS cDiscussion&lt;br /&gt;
FROM prefix_forum_posts AS fp&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type != &#039;news&#039; AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
## WHERE 1=1 &lt;br /&gt;
## %%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count( * ) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Activity In Forums===&lt;br /&gt;
Trying to figure out how much real activity we have in Forums by aggregating:&lt;br /&gt;
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...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname,f.name,f.type &lt;br /&gt;
,(SELECT count(id) FROM prefix_forum_discussions as fd WHERE f.id = fd.forum) as Discussions&lt;br /&gt;
,(SELECT count(distinct fd.userid) FROM prefix_forum_discussions as fd WHERE fd.forum = f.id) as UniqueUsersDiscussions&lt;br /&gt;
,(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&lt;br /&gt;
,(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&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS StudentsCount&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Teachers&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS &#039;Teacher&amp;lt;br/&amp;gt;Count&#039;&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid IN (3,5)&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS UserCount&lt;br /&gt;
, (SELECT (UniqueUsersDiscussions / StudentsCount )) as StudentDissUsage&lt;br /&gt;
, (SELECT (UniqueUsersPosts /StudentsCount)) as StudentPostUsage&lt;br /&gt;
FROM prefix_forum as f &lt;br /&gt;
JOIN prefix_course as c ON f.course = c.id&lt;br /&gt;
WHERE `type` != &#039;news&#039;&lt;br /&gt;
ORDER BY StudentPostUsage DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Forum type:NEWS===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT f.id, f.name&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
WHERE m.name = &#039;forum&#039;&lt;br /&gt;
AND f.type = &#039;news&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All new forum NEWS items (discussions) from all my Courses===&lt;br /&gt;
change &amp;quot;userid = 26&amp;quot; and &amp;quot;id = 26&amp;quot; to a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname,f.name,fd.name,FROM_UNIXTIME(fd.timemodified ,&amp;quot;%d %M %Y &amp;quot;) as Date&lt;br /&gt;
FROM prefix_forum_discussions as fd &lt;br /&gt;
JOIN prefix_forum as f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = f.course &lt;br /&gt;
JOIN prefix_user_lastaccess as ul ON (c.id = ul.courseid AND ul.userid = 26)&lt;br /&gt;
WHERE fd.timemodified &amp;gt; ul.timeaccess  &lt;br /&gt;
 AND fd.forum IN (SELECT f.id&lt;br /&gt;
 FROM prefix_course_modules AS cm&lt;br /&gt;
 JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
 JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
 WHERE m.name = &#039;forum&#039;&lt;br /&gt;
 AND f.type = &#039;news&#039;)&lt;br /&gt;
  AND c.id IN (SELECT c.id&lt;br /&gt;
   FROM prefix_course AS c&lt;br /&gt;
   JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
   JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
   JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
   WHERE u.id = 26) ORDER BY `fd`.`timemodified` DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===News Forum - Discussions COUNT===&lt;br /&gt;
Which is actually... How much instructions students get from their teachers&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname ,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,count(fd.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS DiscussionsSum&lt;br /&gt;
FROM prefix_forum_discussions AS fd&lt;br /&gt;
INNER JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
INNER JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type = &#039;news&#039; AND c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count(fd.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cantidad de foros que han sido posteados por profesor===&lt;br /&gt;
&lt;br /&gt;
(Number of forums that have been posted by teacher/Google translator)&lt;br /&gt;
&lt;br /&gt;
Queriamos saber cuales son las acciones del profesor dentro de los foros de cada curso, por ello se hizo este informe.&lt;br /&gt;
&lt;br /&gt;
(We wanted to know what the teacher&#039;s actions are in the forums of each course, so this report was made. /Google translator)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS curso,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Facilitador,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( m.name ) AS COUNT FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS foros,&lt;br /&gt;
&lt;br /&gt;
COUNT(*) AS Posts&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course AS c ON c.id = fd.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = fp.userid &lt;br /&gt;
&lt;br /&gt;
WHERE fp.userid =&lt;br /&gt;
(&lt;br /&gt;
select distinct prefix_user.id&lt;br /&gt;
from prefix_user &lt;br /&gt;
join prefix_role_assignments as ra on ra.userid = prefix_user.id &lt;br /&gt;
where ra.roleid = 3 &lt;br /&gt;
and userid = fp.userid&lt;br /&gt;
limit 1&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
and c.shortname like &#039;%2014-2-1%&#039;&lt;br /&gt;
GROUP BY c.id, u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all the Forums that got high rating===&lt;br /&gt;
We setup a scale that let teachers and students Rate forum post with &amp;quot;Important, interesting, valuable, not rated&amp;quot; scale&lt;br /&gt;
And then add a link to the following report at the begining of the course &amp;quot;Link to all interesting posts&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,f.id,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;,fd.id,&#039;#p&#039;,fp.id,&#039;&amp;quot;&amp;gt;&#039;,fp.subject,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post link&#039;,&lt;br /&gt;
SUM(r.rating) AS &#039;Rating&#039;&lt;br /&gt;
FROM mdl_rating AS r&lt;br /&gt;
  JOIN mdl_forum_posts AS fp ON fp.id = r.itemid&lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
WHERE r.component = &#039;mod_forum&#039; AND r.ratingarea = &#039;post&#039; AND f.course = %%COURSEID%%&lt;br /&gt;
GROUP BY r.itemid&lt;br /&gt;
ORDER BY SUM(r.rating) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all Discussions of a single Forum===&lt;br /&gt;
This report is used to help export all the student&#039;s posts and discussions of a single forum, by passing the context module id as a parameter to the report using &amp;quot;&amp;amp;filter_var=cmid&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;, f.id, &#039;&amp;quot;&amp;gt;&#039;, f.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name&#039;,&lt;br /&gt;
fd.name AS &#039;Discussion&#039;, &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;, fd.id, &#039;#p&#039;, fp.id, &#039;&amp;quot;&amp;gt;&#039;, fp.subject, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post (link)&#039;,&lt;br /&gt;
fp.message&lt;br /&gt;
&lt;br /&gt;
FROM mdl_forum_posts AS fp &lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
  JOIN mdl_course_modules AS cm ON cm.module = 9 AND cm.instance = f.id&lt;br /&gt;
WHERE cm.id = %%FILTER_VAR%%&lt;br /&gt;
ORDER BY f.id, fd.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Quiz Module Reports==&lt;br /&gt;
===Generate a list of instructors and their email addresses for those courses that has &amp;quot;essay questions&amp;quot; in their quizzes===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT qu.id AS quiz_id, qu.course AS course_id, qu.questions,&lt;br /&gt;
                co.fullname AS course_fullname, co.shortname AS course_shortname,&lt;br /&gt;
                qu.name AS quiz_name, FROM_UNIXTIME(qu.timeopen) AS quiz_timeopen, FROM_UNIXTIME(qu.timeclose) AS quiz_timeclose,&lt;br /&gt;
                u.firstname, u.lastname, u.email,&lt;br /&gt;
FROM prefix_quiz qu, prefix_course co, prefix_role re, prefix_context ct, prefix_role_assignments ra, prefix_user u&lt;br /&gt;
WHERE FROM_UNIXTIME(timeopen) &amp;gt; &#039;2008-05-14&#039; AND&lt;br /&gt;
                qu.course = co.id AND&lt;br /&gt;
                co.id = ct.instanceid AND&lt;br /&gt;
                ra.roleid = re.id AND&lt;br /&gt;
                re.name = &#039;Teacher&#039; AND&lt;br /&gt;
                ra.contextid = ct.id AND&lt;br /&gt;
                ra.userid = u.id&lt;br /&gt;
 &lt;br /&gt;
SELECT Count(&#039;x&#039;) As NumOfStudents&lt;br /&gt;
                                FROM prefix_role_assignments a&lt;br /&gt;
                                JOIN prefix_user u ON userid = u.id&lt;br /&gt;
                                WHERE roleid = 5 AND contextid = (SELECT id FROM prefix_context WHERE instanceid = 668 AND contextlevel = 50)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Number of Quizes per Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Link&amp;lt;/a&amp;gt;&#039;) AS Quizes&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules cm&lt;br /&gt;
JOIN prefix_course c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module&lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039;&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all MultiAnswer (Cloze) Questions===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/attempt.php?q=&#039;, quiz.id, &#039;&amp;quot;&amp;gt;&#039;, quiz.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS Quiz&lt;br /&gt;
,question.id question_id, question.questiontext &lt;br /&gt;
FROM  prefix_question question&lt;br /&gt;
JOIN prefix_quiz_question_instances qqi ON question.id = qqi.question&lt;br /&gt;
JOIN prefix_quiz quiz ON qqi.quiz = quiz.id&lt;br /&gt;
WHERE  `qtype` LIKE  &#039;multianswer&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List courses with MANUAL grades===&lt;br /&gt;
Which is basically and indication to teachers using Moodle to hold offline grades inside Moodle&#039;s Gradebook,&lt;br /&gt;
So grades could be uploaded into an administrative SIS. Use with Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT( * )&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php?showadvanced=1&amp;amp;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM  prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course as c ON c.id = gi.courseid&lt;br /&gt;
WHERE  `itemtype` =  &#039;manual&#039;&lt;br /&gt;
GROUP BY courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===List the users that did not took the Quiz===&lt;br /&gt;
Do not forget to change &amp;quot;c.id = 14&amp;quot; and q.name LIKE &#039;%quiz name goes here%&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id AS ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.username AS IDNumber,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
 &lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id AND courseid=c.id) AS CourseLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id AND e.courseid = c.id) AS RoleName&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess AS ul ON ul.userid = user2.id&lt;br /&gt;
WHERE c.id=14 and ue.userid NOT IN (SELECT qa.userid FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON qa.quiz = q.id&lt;br /&gt;
JOIN prefix_course AS c ON q.course = c.id&lt;br /&gt;
WHERE c.id = 14 AND q.name LIKE &#039;%quiz name goes here%&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List Questions in each Quiz===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT quiz.id,quiz.name, q.id, q.name&lt;br /&gt;
FROM mdl_quiz AS quiz&lt;br /&gt;
JOIN mdl_question AS q ON FIND_IN_SET(q.id, quiz.questions)&lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
ORDER BY quiz.id ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this query does not work in Moodle 2.8. There is no mdl_quiz.questions field. It will need to be rewritten to use the usage/contextid organization.&lt;br /&gt;
&lt;br /&gt;
===Quiz activity research===&lt;br /&gt;
This report was made to extract student full activity in quizzes for an academic research about adapting instructional design teaching methods in online learning. The students do not use the Quiz module as a standard quiz but more as Study booklets or mini courses with embedded questions and hints to assist students evaluate their progress (Similar to what you expect to find in a SCORM activity)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cm.course &amp;quot;course_id&amp;quot;, cm.id &amp;quot;moduel_id&amp;quot;, q.id &amp;quot;quiz_id&amp;quot;, q.name &amp;quot;quiz_name&amp;quot;,&lt;br /&gt;
 &lt;br /&gt;
CASE q.grademethod&lt;br /&gt;
      WHEN 1 THEN &amp;quot;GRADEHIGHEST&amp;quot;&lt;br /&gt;
      WHEN 2 THEN &amp;quot;GRADEAVERAGE&amp;quot;&lt;br /&gt;
      WHEN 3 THEN &amp;quot;ATTEMPTFIRST&amp;quot;&lt;br /&gt;
      WHEN 4 THEN &amp;quot;ATTEMPTLAST&amp;quot;&lt;br /&gt;
END &amp;quot;grade method&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
, q.attempts &amp;quot;quiz_attempts_allowed&amp;quot;, cm.groupmode &amp;quot;group_mode&amp;quot;&lt;br /&gt;
, qa.id &amp;quot;attempt_id&amp;quot;, qa.state &amp;quot;attempt_state&amp;quot;, qa.sumgrades &amp;quot;attempt_grade&amp;quot;, qg.grade &amp;quot;user_final_grade&amp;quot;, q.grade &amp;quot;quiz_max_grade&amp;quot;&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = q.course AND m.userid = u.id) &amp;quot;user_groups&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timestart), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_start&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timefinish), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_finish&amp;quot;,&lt;br /&gt;
u.id &amp;quot;user_id&amp;quot;, u.firstname, u.lastname,&lt;br /&gt;
question.id &amp;quot;question_id&amp;quot;, question.name &amp;quot;question_name&amp;quot;,&lt;br /&gt;
qas.state &amp;quot;question_step_state&amp;quot;,qas.fraction &amp;quot;question_grade&amp;quot;, qh.hint, question.qtype &amp;quot;question_type&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz as q&lt;br /&gt;
JOIN mdl_course_modules as cm ON cm.instance = q.id and cm.module = 14 &lt;br /&gt;
JOIN mdl_quiz_attempts qa ON q.id = qa.quiz&lt;br /&gt;
LEFT JOIN mdl_quiz_grades as qg ON qg.quiz = q.id and qg.userid = qa.userid&lt;br /&gt;
JOIN mdl_user as u ON u.id = qa.userid&lt;br /&gt;
JOIN mdl_question_usages as qu ON qu.id = qa.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts as qatt ON qatt.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question as question ON question.id = qatt.questionid&lt;br /&gt;
JOIN mdl_question_attempt_steps as qas ON qas.questionattemptid = qatt.id&lt;br /&gt;
LEFT JOIN mdl_question_hints as qh ON qh.questionid = q.id&lt;br /&gt;
#WHERE q.id = &amp;quot;SOME QUIZ ID&amp;quot;&lt;br /&gt;
WHERE cm.course = &amp;quot;SOME COURSE ID&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quiz Usage in Courses by Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Multiple Choice&amp;quot; questions include true/false and matching question types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Short Answer&amp;quot; are questions that accept a single phrase.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Other&amp;quot; questions include fixed numerical, calculated, essay, and various drag and drop types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Min Quiz Age&amp;quot; and &amp;quot;Max Quiz Age&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: In Configurable Reports, the Date Filter is not applied until the &amp;quot;Apply&amp;quot; button is clicked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.shortname AS &#039;Course&#039;&lt;br /&gt;
#, u.lastname AS &#039;Instructor&#039;&lt;br /&gt;
, COUNT(DISTINCT q.id) AS &#039;Quizzes&#039;&lt;br /&gt;
, COUNT(DISTINCT qu.id) AS &#039;Questions&#039;&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 ))  AS &#039;multichoice&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT( qu.id) - SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;Other&#039;&lt;br /&gt;
&lt;br /&gt;
, (SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )))/COUNT( qu.id) AS &#039;Percent MC&#039;&lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;numerical&#039;, 1, 0 )) AS &#039;numerical&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype LIKE &#039;calc%&#039;, 1, 0 )) AS &#039;calculated&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;random&#039;, 1, 0 )) AS &#039;random&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;essay&#039;, 1, 0 )) AS &#039;essay&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, IF(q.shufflequestions &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Questions&#039;&lt;br /&gt;
, IF(q.shuffleanswers &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Answers&#039;&lt;br /&gt;
 &lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
#, FROM_UNIXTIME(MIN(q.timemodified)) AS &#039;Last Modified&#039;&lt;br /&gt;
&lt;br /&gt;
#, DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(MIN(q.timemodified))) AS &#039;Quiz age&#039;&lt;br /&gt;
&lt;br /&gt;
, MIN(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Min Quiz Age&#039; &lt;br /&gt;
, MAX(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Max Quiz Age&#039; &lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified)) &amp;lt; 90, 1,0)) AS &#039;new quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_quiz AS q&lt;br /&gt;
JOIN prefix_course AS c on c.id = q.course&lt;br /&gt;
JOIN prefix_quiz_question_instances AS qqi ON qqi.quiz = q.id&lt;br /&gt;
LEFT JOIN prefix_question AS qu ON qu.id = qqi.question&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%% %%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student responses (answers) to quiz questions===&lt;br /&gt;
(Contributed by Juan F with help from Tim hunt and fellow Moodlers on the forums)&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    concat( u.firstname, &amp;quot; &amp;quot;, u.lastname ) AS &amp;quot;Student Name&amp;quot;,&lt;br /&gt;
    u.id,&lt;br /&gt;
    quiza.userid,&lt;br /&gt;
    q.course,&lt;br /&gt;
    q.name,&lt;br /&gt;
    quiza.attempt,&lt;br /&gt;
    qa.slot,&lt;br /&gt;
    que.questiontext AS &#039;Question&#039;,&lt;br /&gt;
    qa.rightanswer AS &#039;Correct Answer&#039;,&lt;br /&gt;
    qa.responsesummary AS &#039;Student Answer&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz_attempts quiza&lt;br /&gt;
JOIN mdl_quiz q ON q.id=quiza.quiz&lt;br /&gt;
JOIN mdl_question_usages qu ON qu.id = quiza.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts qa ON qa.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question que ON que.id = qa.questionid&lt;br /&gt;
JOIN mdl_user u ON u.id = quiza.userid&lt;br /&gt;
&lt;br /&gt;
WHERE q.name = &amp;quot;BIO 208 Post Test Assessment&amp;quot;&lt;br /&gt;
AND q.course = &amp;quot;17926&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ORDER BY quiza.userid, quiza.attempt, qa.slot&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==SCORM Activity Reports==&lt;br /&gt;
&lt;br /&gt;
===Lists All completed SCORM activites by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists SCORM status for all enrolled users by Course name===&lt;br /&gt;
This report will list the SCORM status for all users enrolled in the course. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. This can be limited to individual courses by adding to the where clause the course id to report on.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.firstname AS First,&lt;br /&gt;
u.lastname AS Last, &lt;br /&gt;
u.idnumber AS Employee_ID,  &lt;br /&gt;
u.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
u.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course, &lt;br /&gt;
st.attempt AS Attempt,&lt;br /&gt;
st.value AS Status,&lt;br /&gt;
FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) AS Date &lt;br /&gt;
&lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
&lt;br /&gt;
WHERE st.element=&#039;cmi.core.lesson_status&#039; AND m.userid=u.id&lt;br /&gt;
&lt;br /&gt;
UNION&lt;br /&gt;
&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS First,&lt;br /&gt;
user2.lastname AS Last,&lt;br /&gt;
user2. idnumber AS Employee_ID,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
user2.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Attempt,&lt;br /&gt;
&amp;quot;not_started&amp;quot; AS Status,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Date&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = user2.id &lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.course=c.id&lt;br /&gt;
Left Join prefix_scorm_scoes_track AS st on st.scormid=sc.id AND st.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
WHERE  st.timemodified IS NULL AND m.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY  Course, Last, First, Attempt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Badges==&lt;br /&gt;
&lt;br /&gt;
=== All badges issued, by User ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, b.name AS badgename, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN&lt;br /&gt;
(SELECT c.shortname&lt;br /&gt;
    FROM prefix_course AS c&lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Context,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 1 THEN &amp;quot;Activity Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 2 THEN &amp;quot;Activity Completion (Any)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 2 AND t.method = 2 THEN &amp;quot;Manual Award&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 1 THEN &amp;quot;Course Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 2 THEN &amp;quot;Course Completion (Any)&amp;quot;&lt;br /&gt;
  ELSE CONCAT (&#039;Other: &#039;, t.criteriatype)&lt;br /&gt;
END AS Criteriatype,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateissued ) , &#039;%Y-%m-%d&#039; ) AS dateissued,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateexpire ), &#039;%Y-%m-%d&#039; ) AS dateexpires,&lt;br /&gt;
CONCAT (&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/badge.php?hash=&#039;,d.uniquehash,&#039;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&#039;) AS Details&lt;br /&gt;
FROM prefix_badge_issued AS d &lt;br /&gt;
JOIN prefix_badge AS b ON d.badgeid = b.id&lt;br /&gt;
JOIN prefix_user AS u ON d.userid = u.id&lt;br /&gt;
JOIN prefix_badge_criteria AS t on b.id = t.badgeid &lt;br /&gt;
WHERE t.criteriatype &amp;lt;&amp;gt; 0&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&lt;br /&gt;
=== All badges available in the system, with Earned count ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.type = 1 THEN &amp;quot;System&amp;quot;&lt;br /&gt;
WHEN b.type = 2 THEN &amp;quot;Course&amp;quot;&lt;br /&gt;
END AS Context, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN &lt;br /&gt;
(SELECT c.shortname &lt;br /&gt;
    FROM prefix_course AS c &lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 2 THEN &amp;quot;No&amp;quot;&lt;br /&gt;
WHEN b.status = 1 OR b.status = 3 THEN &amp;quot;Yes&amp;quot;&lt;br /&gt;
WHEN b.status = 4 THEN &amp;quot;x&amp;quot;&lt;br /&gt;
END AS Available,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 1 THEN &amp;quot;0&amp;quot;&lt;br /&gt;
WHEN b.status = 2 OR b.status = 3 OR b.status = 4 THEN &lt;br /&gt;
 (SELECT COUNT(*) &lt;br /&gt;
   FROM prefix_badge_issued AS d&lt;br /&gt;
   WHERE d.badgeid = b.id&lt;br /&gt;
 )&lt;br /&gt;
END AS Earned&lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Badges Leaderboard ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A simple list of usernames and how many badges they have earned overall.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, (SELECT COUNT(*) FROM prefix_badge_issued AS d WHERE d.userid = u.id) AS earned&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
ORDER BY earned DESC, u.username ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Manage badges (System &amp;amp; Course) ===&lt;br /&gt;
&lt;br /&gt;
List system wide badges, course and system level badges + a link to relevant &amp;quot;manage badges&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description &lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN b.type = 1 THEN &#039;System&#039;&lt;br /&gt;
  WHEN b.type = 2 THEN &#039;Course&#039;&lt;br /&gt;
END AS Level&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/index.php?type=&#039;, b.type, &#039;&amp;amp;id=&#039;,&lt;br /&gt;
			  c.id, &#039;&amp;quot;&amp;gt;Manage badges in: &#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Manage &lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Administrator Reports==&lt;br /&gt;
&lt;br /&gt;
===Config changes in Export friendly form===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( g.timemodified ) , &#039;%Y-%m-%d&#039; ) AS date, &lt;br /&gt;
u.username AS user, &lt;br /&gt;
g.name AS setting, &lt;br /&gt;
CASE &lt;br /&gt;
 WHEN g.plugin IS NULL THEN &amp;quot;core&amp;quot;&lt;br /&gt;
 ELSE g.plugin&lt;br /&gt;
END AS plugin, &lt;br /&gt;
g.value AS new_value, &lt;br /&gt;
g.oldvalue AS original_value&lt;br /&gt;
FROM prefix_config_log  AS g&lt;br /&gt;
JOIN prefix_user AS u ON g.userid = u.id&lt;br /&gt;
ORDER BY date DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts by user===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
How to get a list of all users and which cohorts they belong to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, h.idnumber, h.name&lt;br /&gt;
FROM prefix_cohort AS h&lt;br /&gt;
JOIN prefix_cohort_members AS hm ON h.id = hm.cohortid&lt;br /&gt;
JOIN prefix_user AS u ON hm.userid = u.id&lt;br /&gt;
ORDER BY u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts with Courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all cohorts with name, id, visibility, and which courses they are enrolled in.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
# h.id,&lt;br /&gt;
# e.customint1,&lt;br /&gt;
h.name AS Cohort,&lt;br /&gt;
h.idnumber AS Cohortid,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN h.visible = 1 THEN &#039;Yes&#039;&lt;br /&gt;
 ELSE &#039;-&#039;&lt;br /&gt;
END AS Cohortvisible,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;, CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_cohort h&lt;br /&gt;
JOIN prefix_enrol e ON h.id = e.customint1&lt;br /&gt;
JOIN prefix_course c ON c.id = e.courseid %%FILTER_COURSES:e.courseid%% &lt;br /&gt;
WHERE e.enrol = &#039;cohort&#039; AND e.roleid = 5&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses created And Active courses by Year===&lt;br /&gt;
Active courses is counting course that have at least one Hit, And &amp;quot;Active_MoreThan100Hits&amp;quot; counts courses that have at least 100 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `timecreated` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT course ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY course &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 100) AS courses_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( courses_log.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan100Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_course` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users created And Active users by Year===&lt;br /&gt;
Active users is counting users that have at least one Hit, And &amp;quot;Active_MoreThan500Hits&amp;quot; counts users that have at least 500 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `firstaccess` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT userid ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY userid &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 500) AS users_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( users_log.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan500Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Aggregation Report===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In particular, be on the lookout for any courses with the following combinations of parameters, which are known to cause changes in calculations:&lt;br /&gt;
&lt;br /&gt;
# mean of grades set with aggregate with subcategory.&lt;br /&gt;
# Simple weighted mean of grades with aggregate with sub category and drop the lowest&lt;br /&gt;
# Sum of grades drop the lowest&lt;br /&gt;
&lt;br /&gt;
Also review:&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48618&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48634&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-49257&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50089&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50062&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
COUNT(c.shortname) AS &#039;Count of Courses&#039;&lt;br /&gt;
&lt;br /&gt;
# If you want to display all the courses for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, c.shortname AS &#039;course name&#039;&lt;br /&gt;
&lt;br /&gt;
# If you need to display grade categories for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, gc.fullname AS &#039;grade category name&#039;&lt;br /&gt;
&lt;br /&gt;
, gc.aggregation AS &#039;aggregation method&#039;&lt;br /&gt;
&lt;br /&gt;
#These aggregation text strings appear to be hard-coded. I couldn&#039;t find a table for them. If you have aggregation types I haven&#039;t included here, they&#039;ll be blank in your report results.&lt;br /&gt;
, CASE gc.aggregation&lt;br /&gt;
  WHEN 0 THEN &#039;Mean of Grades&#039;&lt;br /&gt;
  WHEN 2 THEN &#039;Median of Grades&#039;&lt;br /&gt;
  WHEN 6 THEN &#039;Highest Grade&#039;&lt;br /&gt;
  WHEN 8 THEN &#039;Mode of Grades&#039;&lt;br /&gt;
  WHEN 10 THEN &#039;Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 11 THEN &#039;Simple Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 12 THEN &#039;Mean of Grades (with extra credits)&#039;&lt;br /&gt;
  WHEN 13 THEN &#039;Sum of Grades&#039;&lt;br /&gt;
END AS &#039;aggregation name&#039;&lt;br /&gt;
&lt;br /&gt;
# Note that gc.aggregatesubcats column is eliminated in 2.8 and later per MDL-47503, so comment that line on updated systems or you&#039;ll get an error&lt;br /&gt;
, gc.keephigh AS &#039;keep high&#039;&lt;br /&gt;
, gc.droplow AS &#039;dr0p low&#039;&lt;br /&gt;
, gc.aggregateonlygraded AS &#039;Aggregate only graded&#039;&lt;br /&gt;
, gc.aggregateoutcomes AS &#039;aggregate outcomes&#039;&lt;br /&gt;
, gc.aggregatesubcats AS &#039;aggregate subcategories&#039;&lt;br /&gt;
&lt;br /&gt;
# If you are displaying data about individual courses, you may want to know how old they are&lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;course start date&#039;&lt;br /&gt;
&lt;br /&gt;
# 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&#039;ll need to uncomment the necessary JOINs below&lt;br /&gt;
#, gi.itemname AS &#039;grade item&#039;&lt;br /&gt;
#, gg.finalgrade AS &#039;final grade&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
&lt;br /&gt;
prefix_course AS c&lt;br /&gt;
JOIN prefix_grade_categories AS gc ON gc.courseid = c.id&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id #AND gi.categoryid=gc.id&lt;br /&gt;
#LEFT JOIN prefix_grade_grades AS gg ON gg.itemid = gi.id AND gg.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
#AND gc.aggregation = 13 #only the dreaded Sum of Grades aggregations&lt;br /&gt;
#AND gc.depth = 1 # if for some reason you only want course aggregations, not subcategories&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.aggregation, gc.keephigh, gc.droplow, gc.aggregateonlygraded, gc.aggregateoutcomes, gc.aggregatesubcats&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running Cron jobs (task_scheduled) ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT classname&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(lastruntime), &#039;%H:%i [%d]&#039;) AS &#039;last&#039;&lt;br /&gt;
  ,DATE_FORMAT(now(), &#039;%H:%i&#039;) AS &#039;now&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(nextruntime), &#039;%H:%i [%d]&#039;) AS &#039;next&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP()-nextruntime), &#039;%i&#039;) AS &#039;next in min&#039;&lt;br /&gt;
FROM mdl_task_scheduled&lt;br /&gt;
WHERE now() &amp;gt; FROM_UNIXTIME(nextruntime)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== All Meta courses with Parent and Child course relationships ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
This shows the list of courses with Meta course link enrollments in them (&#039;Parent course&#039;), and the courses which are connected to them to provide enrollments (&#039;Child courses&#039;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.fullname AS &#039;Parent course name&#039;,&lt;br /&gt;
c.shortname AS &#039;Parent course shortname&#039;,&lt;br /&gt;
en.courseid AS &#039;Parent course id&#039;,&lt;br /&gt;
(SELECT fullname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course name&#039;,&lt;br /&gt;
(SELECT shortname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course shortname&#039;,&lt;br /&gt;
en.customint1 AS &#039;Child course id&#039;&lt;br /&gt;
FROM prefix_enrol en&lt;br /&gt;
JOIN prefix_course c ON c.id = en.courseid&lt;br /&gt;
WHERE en.enrol = &#039;meta&#039;&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Useful sub queries ==&lt;br /&gt;
&lt;br /&gt;
IN this section please put any short one purpose sub queries that show how common procedures often useful as part of larger queries.&lt;br /&gt;
&lt;br /&gt;
=== All teachers in the course ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This snippet shows how to get teachers from a course. The contextevel for course objects is 50. And the default Teacher role is role id 3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course ic&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = ic.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND ic.id = c.id&lt;br /&gt;
GROUP BY ic.id&lt;br /&gt;
) AS TeacherNames&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Get custom User profile fields for a user ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON uid.fieldid = uif.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to limit it to one of those fields, you can restrict it by shortname of the custom profile field, so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;shortname1&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will show you only the data from the custom profile field with the shortname &#039;shortname1&#039;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, d1.data AS &#039;Profile One&#039;, d2.data As &#039;Profile Two&#039;&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
JOIN prefix_user_info_data d1 ON d1.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
JOIN prefix_user_info_data d2 ON d2.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f2 ON d2.fieldid = f2.id AND f2.shortname = &#039;shortname2&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== NOTE: Alternate Method ====&lt;br /&gt;
&lt;br /&gt;
If you have more than a couple of fields you need to use, then this query may time out or not return data due to too many joins. The limit seems to be around 10 custom profile fields. &lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thefirstfield&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname2&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thesecondfield&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== How to use Configurable Reports Date Time Filters===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Here is a simple example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.firstaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;FirstAccess&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.lastaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;LastAccess&#039;   &lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1&lt;br /&gt;
%%FILTER_STARTTIME:u.firstaccess:&amp;gt;%% &lt;br /&gt;
%%FILTER_ENDTIME:u.lastaccess:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2) You MUST then add the Start / End date filter on the Filters tab of the Report. If you don&#039;t, the report will still run, probably, but the filter will be ignored.&lt;br /&gt;
&lt;br /&gt;
Note: the WHERE 1=1 statement is a peculiarity of the filters in Config reports: if you don&#039;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.)&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://github.com/jleyva/moodle-configurable_reports_repository Configurable Reports Repository on GitHub]&lt;br /&gt;
* [https://moodleschema.zoola.io/index.html Moodle DB schema explorer] - searching and filtering tables, fields and external key connections between tables.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;br /&gt;
&lt;br /&gt;
[[es:Reportes específicos hechos por usuarios]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Google_Apps_Integration&amp;diff=132785</id>
		<title>Google Apps Integration</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Google_Apps_Integration&amp;diff=132785"/>
		<updated>2018-12-09T12:16:43Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This guide shows how to integrate Moodle and Google to take the maximum advantage of both platforms working together. This guide is divided in two principal sections, authentication and plugins. The proper functioning of the plugins depends on the correct authentication deployment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
=== Identifying needs ===&lt;br /&gt;
&lt;br /&gt;
It’s important to detect the following variables before start.&lt;br /&gt;
Planning on a centralized authentication. Which authorization mechanism prefers the institution?&lt;br /&gt;
* Login using Google Apps credentials&lt;br /&gt;
* Login using Moodle credentials&lt;br /&gt;
* Login using centralized login mechanism&lt;br /&gt;
PHP version&lt;br /&gt;
* &amp;lt; 5.5&lt;br /&gt;
* &amp;gt;= 5.5&lt;br /&gt;
Moodle version&lt;br /&gt;
* Moodle 1.x&lt;br /&gt;
* Moodle 2.0 - 2.6&lt;br /&gt;
* &amp;gt;= Moodle 2.7&lt;br /&gt;
&lt;br /&gt;
=== Considerations ===&lt;br /&gt;
&lt;br /&gt;
This guide only applies to 2.x versions, if you are running an 1.x version you can update to 2.x following [https://docs.moodle.org/27/en/Upgrading_to_Moodle_2.0 this guide].&lt;br /&gt;
&lt;br /&gt;
=== Download the plugins package ===&lt;br /&gt;
&lt;br /&gt;
All the plugins explained in this guide are available to download in [https://github.com/jrschumacher/moodle-google_apps this package].  Some of them are already installed as default, therefore it is not necessary to replace them. For latest versions of each plugin you can download separately.&lt;br /&gt;
&lt;br /&gt;
=== Creating a project in the Google Developers Console ===&lt;br /&gt;
&lt;br /&gt;
Follow [https://developers.google.com/console/help/new/#managingprojects this guide] that shows how to create a project in Google Developers Console.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Authentication ==&lt;br /&gt;
&lt;br /&gt;
The first step is to centralize the authentication process. If your institution already has a centralized directory we can still use it and just connect both Moodle and Google to it. If you prefer to use the Moodle or Google credentials, you need to know which are the right modules that will help in each case. These are the possible authentication scenarios: &lt;br /&gt;
&lt;br /&gt;
=== Credentials stored in Moodle ===&lt;br /&gt;
&lt;br /&gt;
If you choose Moodle as identity provider, you can implement an SSO solution in order to preserve the session between systems and avoid direct connections to database. One of the principal SSO protocols is SAML which can be integrated through a third party plugin that runs a SAML server within Moodle. Google Apps will connect to Moodle SAML endpoint and rely on the Moodle stored credentials. Remember that username and email address must match in both sides.&lt;br /&gt;
&lt;br /&gt;
The required plugins are:&lt;br /&gt;
&lt;br /&gt;
====  Plugin: GSAML plugin ====&lt;br /&gt;
* Description: This plugin enables Moodle as a SAML server and is ready to configure Google Apps as a SAML client. &lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: auth/gsaml&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Domain Name: Google Apps Domain (e.g., yourschool.edu) &lt;br /&gt;
** RSA key: Plain-text from the RSA key (pem) file. Note that the SAML service supports RSA signed keys only.&lt;br /&gt;
** SSL signing certificate: Plain-text from the X.509 Certificate file here. Note that this is the same file you will upload to Google.&lt;br /&gt;
* More information: [http://www.appsedudemo.com/home/lmsthirdparty/moodlegeneral/moodle-auth-gsaml Admin guide]&lt;br /&gt;
* Plugin page: Moodle [https://github.com/jrschumacher/moodle-google_apps/tree/master/auth/gsaml plugin page] (outdated)&lt;br /&gt;
&lt;br /&gt;
==== Block: User Sync block ====&lt;br /&gt;
* Description: This tool syncs users from Moodle to Google. It can create, update and delete users. Users can be synced by an event or by a cron process.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: blocks/gdata&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Google Apps username: This is the username (without domain) used to administer your Google Apps account. For example, if you login to Google Apps as &#039;foo@yourschool.edu&#039;, your username is &#039;foo&#039;.&lt;br /&gt;
** Google Apps password: This is the password associated with the above username.&lt;br /&gt;
** Google Apps domain: This is the domain associated with your Google Apps account. For example, if you login to Google Apps as &#039;foo@yourschool.edu&#039;, your domain is &#039;yourschool.edu&#039;.&lt;br /&gt;
** Use Google Apps email (Yes/No): Update Moodle&#039;s user record with the email from the Google Apps domain. The update will occur during the Moodle to Google Apps synchronization.&lt;br /&gt;
** Enable events (Yes/No): If this setting is enabled, then a Moodle user&#039;s account will be instantly updated in Google Apps when the user edits his/her account in Moodle&#039;s standard edit profile interface. Also, if a Moodle user&#039;s account is deleted, then the associated Google Apps account will also be instantly deleted. This only applies to Moodle accounts that are currently being synchronized to Google Apps. This feature is \&amp;quot;best attempt\&amp;quot; only, so failures will fallback to the cron to perform the synchronization.&lt;br /&gt;
** Cron interval (minutes): Enter in how often the Moodle to Google Apps synchronization should be executed on the cron. Enter zero to stop running the synchronization.&lt;br /&gt;
** Cron expire (hours): When the synchronization runs, it locks the cron from being executed again until it has finished. This setting is used to determine when that lock has expired. Consider setting this to a high value especially on first runs with a lot of users.&lt;br /&gt;
* Considerations:&lt;br /&gt;
** Supported from version 2.0 to 2.6.5+.&lt;br /&gt;
** Moodle credentials are stored in a database and the passwords are hashed on different algorithms depending the PHP version that is used. Moodle uses the MD5 hashing algorithm on PHP &amp;lt; 5.5 and BCrypt on PHP &amp;gt;= 5.5. Only clear text, MD5 and SHA1 passwords are supported for Google Apps password syncing proposes. For changing hash algorithm follow [https://sites.google.com/a/appsedudemo.com/site/home/lmsthirdparty/moodlegeneral/moodle-changing-bcrypt-to-md5 this guide].&lt;br /&gt;
* More information: [https://docs.moodle.org/24/en/Google_Apps_Integration#User_Sync_Block_Settings Admin guide]&lt;br /&gt;
* Plugin page: Moodle [https://github.com/jrschumacher/moodle-google_apps/tree/master/blocks/gdata plugin page]&lt;br /&gt;
&lt;br /&gt;
Follow [http://www.appsedudemo.com/home/lmsthirdparty/moodlegeneral/moodle-auth-gsaml this guide] to configure properly both plugins.&lt;br /&gt;
&lt;br /&gt;
=== Credentials stored in Google ===&lt;br /&gt;
&lt;br /&gt;
Users can login to Moodle using the Google Apps stored credentials through OAuth2 sign in method. Remember that OpenID 2.0 authentication method is deprecated and it has been migrated to OAuth 2.0 (OpenID Connect). In this case user and mail fields must match in both platforms. Moodle has a third party plugin that has been already configured to support Google Apps service.&lt;br /&gt;
&lt;br /&gt;
==== Plugin: OAuth2 plugin ====&lt;br /&gt;
* Description: This plugin is ready to connect to Google Apps server just configuring the project information of the Google developers console.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: auth/googleoauth2&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Google Client ID: Your client ID can be generated in the Google console.&lt;br /&gt;
** Google Client secret: Your client Secret can be generated in the Google console.&lt;br /&gt;
* More information: [https://github.com/mouneyrac/moodle-auth_googleoauth2 Admin guide]&lt;br /&gt;
* Plugin page: [https://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Moodle plugin page]&lt;br /&gt;
&lt;br /&gt;
Follow [http://mouneyrac.github.io/moodle-auth_googleoauth2/ this guide] to configure properly the plugin.&lt;br /&gt;
&lt;br /&gt;
=== Credentials stored in other identity provider ===&lt;br /&gt;
&lt;br /&gt;
If the organization is using an existing identity provider (e.g. LDAP, Active Directory, DB, etc) it is recommended to configure an SSO solution in order to allow access to Moodle and Google with the same credentials and to keep alive the session between them. We recommend installing and configuring an Access Management Solution like OpenAM that works as a SAML/OAuth2 server to interconnect the institution&#039;s systems. If you only configure the LDAP plugin in Moodle, it will use same credentials but it won’t start a session in Google and the Google related plugins will request to user to login again. This is why the SSO server is important.&lt;br /&gt;
&lt;br /&gt;
Two options are available in order to connect Moodle to an SSO server. You can either install a SAML client or an OAuth2 client, depending the type of SSO server you are using. If you don’t have an SSO server please follow [http://www.appsedudemo.com/home/simple-sign-on/installing-openam this guide] that explains how to install an Access Management Solution ( OpenAM ).&lt;br /&gt;
&lt;br /&gt;
-First case: Connecting to a SAML server&lt;br /&gt;
&lt;br /&gt;
==== Plugin: OneLogin plugin ====&lt;br /&gt;
* Description: This plugin works as a SAML client and connects to your SAML server (like SimpleSAML, OpenAM, etc) displaying the authorization mechanism and getting back to Moodle with a logged in status.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: auth/onelogin_saml&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** SSO Identity Provider URL: Single sign-on identity provider URL for your server SSO SAML Issuer URL: SAML Issuer URL for your company&lt;br /&gt;
** Automatically create users? (Yes/No) : Check to automatically create local user accounts which do not already exist. By default, the accounts are created without a password, and the user must login via SAML identity verification.&lt;br /&gt;
** Certificate Key: Secret digital security encryption certificate key.&lt;br /&gt;
* More information: [https://onelogin.zendesk.com/hc/en-us/articles/201173644-Configuring-SAML-for-Moodle2 Admin guide]&lt;br /&gt;
* Plugin page: [https://moodle.org/plugins/view.php?plugin=auth_onelogin_saml Moodle plugin page]&lt;br /&gt;
&lt;br /&gt;
Follow [http://www.appsedudemo.com/home/simple-sign-on/adapting-existing-system-to-connect-to-openam-via-saml-using-onelogin-developed-client this guide] to configure properly the plugin ( based on OpenAM ).&lt;br /&gt;
&lt;br /&gt;
-Second case: Connecting to an OAuth2 server&lt;br /&gt;
&lt;br /&gt;
==== Plugin: Customized OAuth2 plugin ====&lt;br /&gt;
* Description: This plugin needs some code edited in order to connect with your own SSO server.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: auth/googleoauth2&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Google Client ID: Your client ID can be generated in the Google console.&lt;br /&gt;
** Google Client secret: Your client Secret can be generated in the Google console.&lt;br /&gt;
* More information: [http://mouneyrac.github.io/moodle-auth_googleoauth2/ Admin guide]&lt;br /&gt;
* Plugin page: [https://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Moodle plugin page]&lt;br /&gt;
&lt;br /&gt;
Follow [http://www.appsedudemo.com/home/simple-sign-on/adapting-existing-systems-to-connect-with-openam-via-oauth2-using-a-generic-code-library this guide] to configure properly the plugin ( based on OpenAM ).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Plugins and configurations ==&lt;br /&gt;
&lt;br /&gt;
Some of this plugins are already installed in Moodle 2.x, some others require to be installed (just copying the files to their respective directory) and the rest are Moodle features that can be configured to integrate with Google services.&lt;br /&gt;
&lt;br /&gt;
=== Google Apps menu ===&lt;br /&gt;
&lt;br /&gt;
==== Block: Google Apps block ====&lt;br /&gt;
* Description: A Google Apps block on the Moodle Front Page displays links to Google Start Page, Google Docs, Google Calendar and Gmail.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: blocks/gaccess&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Domain Name: This is your Google Apps Domain Name (e.g., yourschool.edu)&lt;br /&gt;
** New Window Links (Yes/No): If selected links will open in new window.&lt;br /&gt;
** Show GMail Link (Yes/No): If selected GMail link will be shown. &lt;br /&gt;
** Show Google Drive Link (Yes/No): If selected Google Drive link will be shown.&lt;br /&gt;
** Show Google+ Link (Yes/No): If selected Google+ link will be shown.&lt;br /&gt;
** Show Google Calendar Link (Yes/No): If selected Google Calendar link will be shown.&lt;br /&gt;
** Show Google Classroom Link (Yes/No): If selected Google Classroom link will be shown.&lt;br /&gt;
** More information: [https://docs.moodle.org/24/en/Google_Apps_Integration#Google_Apps_Block_Settings Admin guide]&lt;br /&gt;
** Plugin page: [https://github.com/jrschumacher/moodle-google_apps/tree/master/blocks/gdata Moodle plugin page]&lt;br /&gt;
&lt;br /&gt;
=== Mail integration ===&lt;br /&gt;
&lt;br /&gt;
==== Block: Gmail block ====&lt;br /&gt;
* Description: A Gmail block in Moodle that displays the latest Gmail messages on the Moodle Front Page.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: blocks/gmail&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Domain Name: This is your Google Apps Domain Name (e.g., yourschool.edu)&lt;br /&gt;
** User Name from: This is the Moodle user field that the Google User is derived from - defaults to username, but email is another possibility&lt;br /&gt;
** OAuth Consumer Secret: This is the same value you find on Google&#039;s Manage OAuth Access page under Advanced tools.&lt;br /&gt;
** Unread Message Count: The number of unread messages you would like displayed in the gmail block. Leave as zero for no limit.&lt;br /&gt;
** New Window Links (Yes/No): If selected links will open in new window.&lt;br /&gt;
** Show First Name (Yes/No): Show the author&#039;s first name next to their message.&lt;br /&gt;
** Show Last Name (Yes/No): Show the author&#039;s last name next to their message.&lt;br /&gt;
* More information: [https://docs.moodle.org/24/en/Google_Apps_Integration#Gmail_Block Admin guide]&lt;br /&gt;
* Plugin page: [https://github.com/jrschumacher/moodle-google_apps/tree/master/blocks/gmail Moodle plugin page]&lt;br /&gt;
* Considerations: &lt;br /&gt;
** This plugin only works when we use Moodle as identity provider, GSAML plugin is enabled and the SSO configuration is enabled in Google Apps.&lt;br /&gt;
&lt;br /&gt;
=== Drive integration ===&lt;br /&gt;
&lt;br /&gt;
==== Plugin: Google Drive repository ====&lt;br /&gt;
* Description: This is a repository add-on that pulls files from Google Drive to Moodle.&lt;br /&gt;
* Included in Moodle: Yes&lt;br /&gt;
* Path: /repository/googledrive&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Repository plugin name: Name to be displayed.&lt;br /&gt;
** Client ID: Developer console project ID.&lt;br /&gt;
** Secret: Developer console project Secret.&lt;br /&gt;
* More information: [https://docs.moodle.org/310/en/Google_Drive_repository Admin guide]&lt;br /&gt;
&lt;br /&gt;
==== Plugin: Google Drive portfolio ====&lt;br /&gt;
* Description: This is a portfolio add-on that push files from your computer to Google Drive and then to Moodle.&lt;br /&gt;
* Included in Moodle: Yes&lt;br /&gt;
* Path: /portfolio/googledocs&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Repository plugin name: Name to be displayed.&lt;br /&gt;
** Client ID: Developer console project ID.&lt;br /&gt;
** Secret: Developer console project Secret.&lt;br /&gt;
* More information: [https://docs.moodle.org/310/en/Google_Drive_portfolio Admin guide]&lt;br /&gt;
&lt;br /&gt;
=== Google+ integration ===&lt;br /&gt;
&lt;br /&gt;
==== Plugin: Picasa Web Album repository (Google+ Photos) ====&lt;br /&gt;
* Description: This is a repository add-on that pulls photos from Picasa to Moodle.&lt;br /&gt;
* Included in Moodle: Yes&lt;br /&gt;
* Path: /repository/picasa&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Repository plugin name: Name to be displayed.&lt;br /&gt;
** Client ID: Developer console project ID.&lt;br /&gt;
** Secret: Developer console project Secret.&lt;br /&gt;
* More information: [https://docs.moodle.org/310/en/Picasa_web_album_repository Admin guide]&lt;br /&gt;
&lt;br /&gt;
==== Plugin: Picasa Web Album portfolio (Google+ Photos) ====&lt;br /&gt;
* Description: This is a portfolio add-on that pushes photos to Picasa from Moodle.&lt;br /&gt;
* Included in Moodle: Yes&lt;br /&gt;
* Path: /portfolio/picasa&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Repository plugin name: Name to be displayed.&lt;br /&gt;
** Client ID: Developer console project ID.&lt;br /&gt;
** Secret: Developer console project Secret.&lt;br /&gt;
* More information: [https://docs.moodle.org/310/en/Picasa_portfolio Admin guide]&lt;br /&gt;
&lt;br /&gt;
=== Youtube integration ===&lt;br /&gt;
&lt;br /&gt;
==== Configuration: Youtube video repository ====&lt;br /&gt;
* Description: This is a repository add-on that pulls videos from Youtube to Moodle.&lt;br /&gt;
* Included in Moodle: Yes&lt;br /&gt;
* Path: /repository/youtube&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Repository plugin name: Name to be displayed.&lt;br /&gt;
* More information: [https://docs.moodle.org/310/en/Youtube_videos_repository Admin guide]&lt;br /&gt;
&lt;br /&gt;
=== Hangouts integration ===&lt;br /&gt;
&lt;br /&gt;
==== Block: Hangouts ====&lt;br /&gt;
* Description: a plugin for Hangouts integration.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Configuration: Install block&lt;br /&gt;
* More information: [http://www.moodlenews.com/2016/video-moodle-google-hangout-integration-by-paradisosol/ Moodlenews]&lt;br /&gt;
&lt;br /&gt;
==== Block: Students Hangouts ====&lt;br /&gt;
* Description: a plugin for Hangouts integration.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Configuration: Install block (WIP - Beta)&lt;br /&gt;
* More information: [https://github.com/nadavkav/moodle-block_google_hangout Github]&lt;br /&gt;
&lt;br /&gt;
==== Configuration: Embedding Hangouts ====&lt;br /&gt;
* Description: There’s no a plugin for Hangouts integration, but it can be used embedding the URLs.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Configuration:&lt;br /&gt;
* More information: [http://www.appsedudemo.com/home/lmsthirdparty/moodlegeneral/moodle-and-google-hangouts-integration Admin guide]&lt;br /&gt;
&lt;br /&gt;
=== Calendar integration ===&lt;br /&gt;
&lt;br /&gt;
==== Configuration: Calendar syncing ====&lt;br /&gt;
* Description: There’s no a plugin for Google Calendar, but the Moodle calendar has an option * to import external calendars.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Configuration:&lt;br /&gt;
* More information: [https://docs.moodle.org/310/en/Using_Calendar#Google_calendar Admin guide]&lt;br /&gt;
&lt;br /&gt;
=== Classroom integration ===&lt;br /&gt;
&lt;br /&gt;
==== Configuration: Importing grades ====&lt;br /&gt;
* Description: There’s no a plugin for Google Classroom, but Classroom grades can be exported and imported into Moodle.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Configuration: &lt;br /&gt;
** Exporting grades from Google Classroom [https://support.google.com/edu/classroom/answer/6020294?hl=en guide]&lt;br /&gt;
** Adapting format to Google Classroom [http://www.appsedudemo.com/home/lmsthirdparty/moodlegeneral/adapt-classroom-assignment-grades-to-moodle-format guide]&lt;br /&gt;
** Importing grades to Moodle [https://docs.moodle.org/27/en/Grade_import guide]&lt;br /&gt;
* More information: &lt;br /&gt;
&lt;br /&gt;
=== Other integrations ===&lt;br /&gt;
&lt;br /&gt;
==== Plugin: Fusion Tables export ====&lt;br /&gt;
* Description: Export grades to a Google Fusion Table&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: /grade/export/fusion&lt;br /&gt;
* Configuration:&lt;br /&gt;
* More information: [https://github.com/piersharding/moodle-google/tree/master/grade/export/fusion Admin guide]&lt;br /&gt;
&lt;br /&gt;
==== UK Open University plugins ====&lt;br /&gt;
* [http://www.open.ac.uk/blogs/douls/?p=241 Moodle Portfolio activity] (Uses Google drive collections/folders)&lt;br /&gt;
* [http://www.open.ac.uk/blogs/douls/?p=262 Google Collaborative activity]&lt;br /&gt;
&lt;br /&gt;
[[Category:Plugin]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Google_Apps_Integration&amp;diff=132784</id>
		<title>Google Apps Integration</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Google_Apps_Integration&amp;diff=132784"/>
		<updated>2018-12-09T12:14:15Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This guide shows how to integrate Moodle and Google to take the maximum advantage of both platforms working together. This guide is divided in two principal sections, authentication and plugins. The proper functioning of the plugins depends on the correct authentication deployment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
=== Identifying needs ===&lt;br /&gt;
&lt;br /&gt;
It’s important to detect the following variables before start.&lt;br /&gt;
Planning on a centralized authentication. Which authorization mechanism prefers the institution?&lt;br /&gt;
* Login using Google Apps credentials&lt;br /&gt;
* Login using Moodle credentials&lt;br /&gt;
* Login using centralized login mechanism&lt;br /&gt;
PHP version&lt;br /&gt;
* &amp;lt; 5.5&lt;br /&gt;
* &amp;gt;= 5.5&lt;br /&gt;
Moodle version&lt;br /&gt;
* Moodle 1.x&lt;br /&gt;
* Moodle 2.0 - 2.6&lt;br /&gt;
* &amp;gt;= Moodle 2.7&lt;br /&gt;
&lt;br /&gt;
=== Considerations ===&lt;br /&gt;
&lt;br /&gt;
This guide only applies to 2.x versions, if you are running an 1.x version you can update to 2.x following [https://docs.moodle.org/27/en/Upgrading_to_Moodle_2.0 this guide].&lt;br /&gt;
&lt;br /&gt;
=== Download the plugins package ===&lt;br /&gt;
&lt;br /&gt;
All the plugins explained in this guide are available to download in [https://github.com/jrschumacher/moodle-google-apps this package].  Some of them are already installed as default, therefore it is not necessary to replace them. For latest versions of each plugin you can download separately.&lt;br /&gt;
&lt;br /&gt;
=== Creating a project in the Google Developers Console ===&lt;br /&gt;
&lt;br /&gt;
Follow [https://developers.google.com/console/help/new/#managingprojects this guide] that shows how to create a project in Google Developers Console.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Authentication ==&lt;br /&gt;
&lt;br /&gt;
The first step is to centralize the authentication process. If your institution already has a centralized directory we can still use it and just connect both Moodle and Google to it. If you prefer to use the Moodle or Google credentials, you need to know which are the right modules that will help in each case. These are the possible authentication scenarios: &lt;br /&gt;
&lt;br /&gt;
=== Credentials stored in Moodle ===&lt;br /&gt;
&lt;br /&gt;
If you choose Moodle as identity provider, you can implement an SSO solution in order to preserve the session between systems and avoid direct connections to database. One of the principal SSO protocols is SAML which can be integrated through a third party plugin that runs a SAML server within Moodle. Google Apps will connect to Moodle SAML endpoint and rely on the Moodle stored credentials. Remember that username and email address must match in both sides.&lt;br /&gt;
&lt;br /&gt;
The required plugins are:&lt;br /&gt;
&lt;br /&gt;
====  Plugin: GSAML plugin ====&lt;br /&gt;
* Description: This plugin enables Moodle as a SAML server and is ready to configure Google Apps as a SAML client. &lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: auth/gsaml&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Domain Name: Google Apps Domain (e.g., yourschool.edu) &lt;br /&gt;
** RSA key: Plain-text from the RSA key (pem) file. Note that the SAML service supports RSA signed keys only.&lt;br /&gt;
** SSL signing certificate: Plain-text from the X.509 Certificate file here. Note that this is the same file you will upload to Google.&lt;br /&gt;
* More information: [http://www.appsedudemo.com/home/lmsthirdparty/moodlegeneral/moodle-auth-gsaml Admin guide]&lt;br /&gt;
* Plugin page: Moodle [https://github.com/jrschumacher/moodle-google-apps/tree/master/auth/gsaml plugin page] (outdated)&lt;br /&gt;
&lt;br /&gt;
==== Block: User Sync block ====&lt;br /&gt;
* Description: This tool syncs users from Moodle to Google. It can create, update and delete users. Users can be synced by an event or by a cron process.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: blocks/gdata&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Google Apps username: This is the username (without domain) used to administer your Google Apps account. For example, if you login to Google Apps as &#039;foo@yourschool.edu&#039;, your username is &#039;foo&#039;.&lt;br /&gt;
** Google Apps password: This is the password associated with the above username.&lt;br /&gt;
** Google Apps domain: This is the domain associated with your Google Apps account. For example, if you login to Google Apps as &#039;foo@yourschool.edu&#039;, your domain is &#039;yourschool.edu&#039;.&lt;br /&gt;
** Use Google Apps email (Yes/No): Update Moodle&#039;s user record with the email from the Google Apps domain. The update will occur during the Moodle to Google Apps synchronization.&lt;br /&gt;
** Enable events (Yes/No): If this setting is enabled, then a Moodle user&#039;s account will be instantly updated in Google Apps when the user edits his/her account in Moodle&#039;s standard edit profile interface. Also, if a Moodle user&#039;s account is deleted, then the associated Google Apps account will also be instantly deleted. This only applies to Moodle accounts that are currently being synchronized to Google Apps. This feature is \&amp;quot;best attempt\&amp;quot; only, so failures will fallback to the cron to perform the synchronization.&lt;br /&gt;
** Cron interval (minutes): Enter in how often the Moodle to Google Apps synchronization should be executed on the cron. Enter zero to stop running the synchronization.&lt;br /&gt;
** Cron expire (hours): When the synchronization runs, it locks the cron from being executed again until it has finished. This setting is used to determine when that lock has expired. Consider setting this to a high value especially on first runs with a lot of users.&lt;br /&gt;
* Considerations:&lt;br /&gt;
** Supported from version 2.0 to 2.6.5+.&lt;br /&gt;
** Moodle credentials are stored in a database and the passwords are hashed on different algorithms depending the PHP version that is used. Moodle uses the MD5 hashing algorithm on PHP &amp;lt; 5.5 and BCrypt on PHP &amp;gt;= 5.5. Only clear text, MD5 and SHA1 passwords are supported for Google Apps password syncing proposes. For changing hash algorithm follow [https://sites.google.com/a/appsedudemo.com/site/home/lmsthirdparty/moodlegeneral/moodle-changing-bcrypt-to-md5 this guide].&lt;br /&gt;
* More information: [https://docs.moodle.org/24/en/Google_Apps_Integration#User_Sync_Block_Settings Admin guide]&lt;br /&gt;
* Plugin page: Moodle [https://github.com/jrschumacher/moodle-google-apps/tree/master/blocks/gdata plugin page]&lt;br /&gt;
&lt;br /&gt;
Follow [http://www.appsedudemo.com/home/lmsthirdparty/moodlegeneral/moodle-auth-gsaml this guide] to configure properly both plugins.&lt;br /&gt;
&lt;br /&gt;
=== Credentials stored in Google ===&lt;br /&gt;
&lt;br /&gt;
Users can login to Moodle using the Google Apps stored credentials through OAuth2 sign in method. Remember that OpenID 2.0 authentication method is deprecated and it has been migrated to OAuth 2.0 (OpenID Connect). In this case user and mail fields must match in both platforms. Moodle has a third party plugin that has been already configured to support Google Apps service.&lt;br /&gt;
&lt;br /&gt;
==== Plugin: OAuth2 plugin ====&lt;br /&gt;
* Description: This plugin is ready to connect to Google Apps server just configuring the project information of the Google developers console.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: auth/googleoauth2&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Google Client ID: Your client ID can be generated in the Google console.&lt;br /&gt;
** Google Client secret: Your client Secret can be generated in the Google console.&lt;br /&gt;
* More information: [https://github.com/mouneyrac/moodle-auth_googleoauth2 Admin guide]&lt;br /&gt;
* Plugin page: [https://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Moodle plugin page]&lt;br /&gt;
&lt;br /&gt;
Follow [http://mouneyrac.github.io/moodle-auth_googleoauth2/ this guide] to configure properly the plugin.&lt;br /&gt;
&lt;br /&gt;
=== Credentials stored in other identity provider ===&lt;br /&gt;
&lt;br /&gt;
If the organization is using an existing identity provider (e.g. LDAP, Active Directory, DB, etc) it is recommended to configure an SSO solution in order to allow access to Moodle and Google with the same credentials and to keep alive the session between them. We recommend installing and configuring an Access Management Solution like OpenAM that works as a SAML/OAuth2 server to interconnect the institution&#039;s systems. If you only configure the LDAP plugin in Moodle, it will use same credentials but it won’t start a session in Google and the Google related plugins will request to user to login again. This is why the SSO server is important.&lt;br /&gt;
&lt;br /&gt;
Two options are available in order to connect Moodle to an SSO server. You can either install a SAML client or an OAuth2 client, depending the type of SSO server you are using. If you don’t have an SSO server please follow [http://www.appsedudemo.com/home/simple-sign-on/installing-openam this guide] that explains how to install an Access Management Solution ( OpenAM ).&lt;br /&gt;
&lt;br /&gt;
-First case: Connecting to a SAML server&lt;br /&gt;
&lt;br /&gt;
==== Plugin: OneLogin plugin ====&lt;br /&gt;
* Description: This plugin works as a SAML client and connects to your SAML server (like SimpleSAML, OpenAM, etc) displaying the authorization mechanism and getting back to Moodle with a logged in status.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: auth/onelogin_saml&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** SSO Identity Provider URL: Single sign-on identity provider URL for your server SSO SAML Issuer URL: SAML Issuer URL for your company&lt;br /&gt;
** Automatically create users? (Yes/No) : Check to automatically create local user accounts which do not already exist. By default, the accounts are created without a password, and the user must login via SAML identity verification.&lt;br /&gt;
** Certificate Key: Secret digital security encryption certificate key.&lt;br /&gt;
* More information: [https://onelogin.zendesk.com/hc/en-us/articles/201173644-Configuring-SAML-for-Moodle2 Admin guide]&lt;br /&gt;
* Plugin page: [https://moodle.org/plugins/view.php?plugin=auth_onelogin_saml Moodle plugin page]&lt;br /&gt;
&lt;br /&gt;
Follow [http://www.appsedudemo.com/home/simple-sign-on/adapting-existing-system-to-connect-to-openam-via-saml-using-onelogin-developed-client this guide] to configure properly the plugin ( based on OpenAM ).&lt;br /&gt;
&lt;br /&gt;
-Second case: Connecting to an OAuth2 server&lt;br /&gt;
&lt;br /&gt;
==== Plugin: Customized OAuth2 plugin ====&lt;br /&gt;
* Description: This plugin needs some code edited in order to connect with your own SSO server.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: auth/googleoauth2&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Google Client ID: Your client ID can be generated in the Google console.&lt;br /&gt;
** Google Client secret: Your client Secret can be generated in the Google console.&lt;br /&gt;
* More information: [http://mouneyrac.github.io/moodle-auth_googleoauth2/ Admin guide]&lt;br /&gt;
* Plugin page: [https://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Moodle plugin page]&lt;br /&gt;
&lt;br /&gt;
Follow [http://www.appsedudemo.com/home/simple-sign-on/adapting-existing-systems-to-connect-with-openam-via-oauth2-using-a-generic-code-library this guide] to configure properly the plugin ( based on OpenAM ).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Plugins and configurations ==&lt;br /&gt;
&lt;br /&gt;
Some of this plugins are already installed in Moodle 2.x, some others require to be installed (just copying the files to their respective directory) and the rest are Moodle features that can be configured to integrate with Google services.&lt;br /&gt;
&lt;br /&gt;
=== Google Apps menu ===&lt;br /&gt;
&lt;br /&gt;
==== Block: Google Apps block ====&lt;br /&gt;
* Description: A Google Apps block on the Moodle Front Page displays links to Google Start Page, Google Docs, Google Calendar and Gmail.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: blocks/gaccess&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Domain Name: This is your Google Apps Domain Name (e.g., yourschool.edu)&lt;br /&gt;
** New Window Links (Yes/No): If selected links will open in new window.&lt;br /&gt;
** Show GMail Link (Yes/No): If selected GMail link will be shown. &lt;br /&gt;
** Show Google Drive Link (Yes/No): If selected Google Drive link will be shown.&lt;br /&gt;
** Show Google+ Link (Yes/No): If selected Google+ link will be shown.&lt;br /&gt;
** Show Google Calendar Link (Yes/No): If selected Google Calendar link will be shown.&lt;br /&gt;
** Show Google Classroom Link (Yes/No): If selected Google Classroom link will be shown.&lt;br /&gt;
** More information: [https://docs.moodle.org/24/en/Google_Apps_Integration#Google_Apps_Block_Settings Admin guide]&lt;br /&gt;
** Plugin page: [https://github.com/jrschumacher/moodle-google-apps/tree/master/blocks/gdata Moodle plugin page]&lt;br /&gt;
&lt;br /&gt;
=== Mail integration ===&lt;br /&gt;
&lt;br /&gt;
==== Block: Gmail block ====&lt;br /&gt;
* Description: A Gmail block in Moodle that displays the latest Gmail messages on the Moodle Front Page.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: blocks/gmail&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Domain Name: This is your Google Apps Domain Name (e.g., yourschool.edu)&lt;br /&gt;
** User Name from: This is the Moodle user field that the Google User is derived from - defaults to username, but email is another possibility&lt;br /&gt;
** OAuth Consumer Secret: This is the same value you find on Google&#039;s Manage OAuth Access page under Advanced tools.&lt;br /&gt;
** Unread Message Count: The number of unread messages you would like displayed in the gmail block. Leave as zero for no limit.&lt;br /&gt;
** New Window Links (Yes/No): If selected links will open in new window.&lt;br /&gt;
** Show First Name (Yes/No): Show the author&#039;s first name next to their message.&lt;br /&gt;
** Show Last Name (Yes/No): Show the author&#039;s last name next to their message.&lt;br /&gt;
* More information: [https://docs.moodle.org/24/en/Google_Apps_Integration#Gmail_Block Admin guide]&lt;br /&gt;
* Plugin page: [https://github.com/jrschumacher/moodle-google-apps/tree/master/blocks/gmail Moodle plugin page]&lt;br /&gt;
* Considerations: &lt;br /&gt;
** This plugin only works when we use Moodle as identity provider, GSAML plugin is enabled and the SSO configuration is enabled in Google Apps.&lt;br /&gt;
&lt;br /&gt;
=== Drive integration ===&lt;br /&gt;
&lt;br /&gt;
==== Plugin: Google Drive repository ====&lt;br /&gt;
* Description: This is a repository add-on that pulls files from Google Drive to Moodle.&lt;br /&gt;
* Included in Moodle: Yes&lt;br /&gt;
* Path: /repository/googledrive&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Repository plugin name: Name to be displayed.&lt;br /&gt;
** Client ID: Developer console project ID.&lt;br /&gt;
** Secret: Developer console project Secret.&lt;br /&gt;
* More information: [https://docs.moodle.org/310/en/Google_Drive_repository Admin guide]&lt;br /&gt;
&lt;br /&gt;
==== Plugin: Google Drive portfolio ====&lt;br /&gt;
* Description: This is a portfolio add-on that push files from your computer to Google Drive and then to Moodle.&lt;br /&gt;
* Included in Moodle: Yes&lt;br /&gt;
* Path: /portfolio/googledocs&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Repository plugin name: Name to be displayed.&lt;br /&gt;
** Client ID: Developer console project ID.&lt;br /&gt;
** Secret: Developer console project Secret.&lt;br /&gt;
* More information: [https://docs.moodle.org/310/en/Google_Drive_portfolio Admin guide]&lt;br /&gt;
&lt;br /&gt;
=== Google+ integration ===&lt;br /&gt;
&lt;br /&gt;
==== Plugin: Picasa Web Album repository (Google+ Photos) ====&lt;br /&gt;
* Description: This is a repository add-on that pulls photos from Picasa to Moodle.&lt;br /&gt;
* Included in Moodle: Yes&lt;br /&gt;
* Path: /repository/picasa&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Repository plugin name: Name to be displayed.&lt;br /&gt;
** Client ID: Developer console project ID.&lt;br /&gt;
** Secret: Developer console project Secret.&lt;br /&gt;
* More information: [https://docs.moodle.org/310/en/Picasa_web_album_repository Admin guide]&lt;br /&gt;
&lt;br /&gt;
==== Plugin: Picasa Web Album portfolio (Google+ Photos) ====&lt;br /&gt;
* Description: This is a portfolio add-on that pushes photos to Picasa from Moodle.&lt;br /&gt;
* Included in Moodle: Yes&lt;br /&gt;
* Path: /portfolio/picasa&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Repository plugin name: Name to be displayed.&lt;br /&gt;
** Client ID: Developer console project ID.&lt;br /&gt;
** Secret: Developer console project Secret.&lt;br /&gt;
* More information: [https://docs.moodle.org/310/en/Picasa_portfolio Admin guide]&lt;br /&gt;
&lt;br /&gt;
=== Youtube integration ===&lt;br /&gt;
&lt;br /&gt;
==== Configuration: Youtube video repository ====&lt;br /&gt;
* Description: This is a repository add-on that pulls videos from Youtube to Moodle.&lt;br /&gt;
* Included in Moodle: Yes&lt;br /&gt;
* Path: /repository/youtube&lt;br /&gt;
* Configuration parameters:&lt;br /&gt;
** Repository plugin name: Name to be displayed.&lt;br /&gt;
* More information: [https://docs.moodle.org/310/en/Youtube_videos_repository Admin guide]&lt;br /&gt;
&lt;br /&gt;
=== Hangouts integration ===&lt;br /&gt;
&lt;br /&gt;
==== Block: Hangouts ====&lt;br /&gt;
* Description: a plugin for Hangouts integration.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Configuration: Install block&lt;br /&gt;
* More information: [http://www.moodlenews.com/2016/video-moodle-google-hangout-integration-by-paradisosol/ Moodlenews]&lt;br /&gt;
&lt;br /&gt;
==== Block: Students Hangouts ====&lt;br /&gt;
* Description: a plugin for Hangouts integration.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Configuration: Install block (WIP - Beta)&lt;br /&gt;
* More information: [https://github.com/nadavkav/moodle-block_google_hangout Github]&lt;br /&gt;
&lt;br /&gt;
==== Configuration: Embedding Hangouts ====&lt;br /&gt;
* Description: There’s no a plugin for Hangouts integration, but it can be used embedding the URLs.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Configuration:&lt;br /&gt;
* More information: [http://www.appsedudemo.com/home/lmsthirdparty/moodlegeneral/moodle-and-google-hangouts-integration Admin guide]&lt;br /&gt;
&lt;br /&gt;
=== Calendar integration ===&lt;br /&gt;
&lt;br /&gt;
==== Configuration: Calendar syncing ====&lt;br /&gt;
* Description: There’s no a plugin for Google Calendar, but the Moodle calendar has an option * to import external calendars.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Configuration:&lt;br /&gt;
* More information: [https://docs.moodle.org/310/en/Using_Calendar#Google_calendar Admin guide]&lt;br /&gt;
&lt;br /&gt;
=== Classroom integration ===&lt;br /&gt;
&lt;br /&gt;
==== Configuration: Importing grades ====&lt;br /&gt;
* Description: There’s no a plugin for Google Classroom, but Classroom grades can be exported and imported into Moodle.&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Configuration: &lt;br /&gt;
** Exporting grades from Google Classroom [https://support.google.com/edu/classroom/answer/6020294?hl=en guide]&lt;br /&gt;
** Adapting format to Google Classroom [http://www.appsedudemo.com/home/lmsthirdparty/moodlegeneral/adapt-classroom-assignment-grades-to-moodle-format guide]&lt;br /&gt;
** Importing grades to Moodle [https://docs.moodle.org/27/en/Grade_import guide]&lt;br /&gt;
* More information: &lt;br /&gt;
&lt;br /&gt;
=== Other integrations ===&lt;br /&gt;
&lt;br /&gt;
==== Plugin: Fusion Tables export ====&lt;br /&gt;
* Description: Export grades to a Google Fusion Table&lt;br /&gt;
* Included in Moodle: No&lt;br /&gt;
* Path: /grade/export/fusion&lt;br /&gt;
* Configuration:&lt;br /&gt;
* More information: [https://github.com/piersharding/moodle-google/tree/master/grade/export/fusion Admin guide]&lt;br /&gt;
&lt;br /&gt;
==== UK Open University plugins ====&lt;br /&gt;
* [http://www.open.ac.uk/blogs/douls/?p=241 Moodle Portfolio activity] (Uses Google drive collections/folders)&lt;br /&gt;
* [http://www.open.ac.uk/blogs/douls/?p=262 Google Collaborative activity]&lt;br /&gt;
&lt;br /&gt;
[[Category:Plugin]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=132065</id>
		<title>ad-hoc contributed reports</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=132065"/>
		<updated>2018-10-13T11:24:16Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Student (user) COUNT in each Course */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Sitewide reports}}&lt;br /&gt;
==User and Role Report==&lt;br /&gt;
&lt;br /&gt;
===Count number of distinct learners and teachers enrolled per category (including all its sub categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;SELECT COUNT(DISTINCT lra.userid) AS learners, COUNT(DISTINCT tra.userid) as teachers&lt;br /&gt;
FROM prefix_course AS c #, mdl_course_categories AS cats&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments  AS lra ON lra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role_assignments  AS tra ON tra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category = cats.id&lt;br /&gt;
AND (&lt;br /&gt;
	cats.path LIKE &#039;%/CATEGORYID/%&#039; #Replace CATEGORYID with the category id you want to count (eg: 80)&lt;br /&gt;
	OR cats.path LIKE &#039;%/CATEGORYID&#039;&lt;br /&gt;
	)&lt;br /&gt;
AND lra.roleid=5&lt;br /&gt;
AND tra.roleid=3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each ROLE (TEACHER, NON-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT r.name, l.action, COUNT( l.userid ) AS counter&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_role AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE ra.roleid IN ( 3, 4, 5 ) &lt;br /&gt;
GROUP BY roleid, l.action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student (user) COUNT in each Course===&lt;br /&gt;
Including (optional) filter by: year (if included in course fullname).&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/index.php?contextid=&#039;,context.id,&#039;&amp;quot;&amp;gt;Show users&amp;lt;/a&amp;gt;&#039;) AS Users&lt;br /&gt;
, COUNT(course.id) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS asg&lt;br /&gt;
JOIN prefix_context AS context ON asg.contextid = context.id AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_user AS user ON user.id = asg.userid&lt;br /&gt;
JOIN prefix_course AS course ON context.instanceid = course.id&lt;br /&gt;
WHERE asg.roleid = 5 &lt;br /&gt;
# AND course.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
GROUP BY course.id&lt;br /&gt;
ORDER BY COUNT(course.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enrolment count in each Course ===&lt;br /&gt;
&lt;br /&gt;
Shows the total number of enroled users of all roles in each course. Sorted by course name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname, COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LIST of all site USERS by COURSE enrollment (Moodle 2.x)===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) as Role&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) as RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course as course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enrolled users,which did not login into the Course, even once (Moodle 2)===&lt;br /&gt;
Designed forMoodle 2 table structure and uses special plugin filter : %%FILTER_SEARCHTEXT:table.field%%&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id as ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
user2.idnumber AS IDNumber,&lt;br /&gt;
user2.phone1 AS Phone,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
&lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id and courseid=c.id) as CourseLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id and e.courseid = c.id) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments as ue&lt;br /&gt;
JOIN prefix_enrol as e on e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user as user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess as ul on ul.userid = user2.id&lt;br /&gt;
WHERE c.id=16 AND ul.timeaccess IS NULL&lt;br /&gt;
%%FILTER_SEARCHTEXT:user2.firstname%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Role assignments on categories===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS category,&lt;br /&gt;
cc.depth, cc.path, r.name AS role,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php?id=&#039;,usr.id,&#039;&amp;quot;&amp;gt;&#039;,usr.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS name,&lt;br /&gt;
usr.firstname, usr.username, usr.email&lt;br /&gt;
FROM prefix_course_categories cc&lt;br /&gt;
INNER JOIN prefix_context cx ON cc.id = cx.instanceid&lt;br /&gt;
AND cx.contextlevel = &#039;40&#039;&lt;br /&gt;
INNER JOIN prefix_role_assignments ra ON cx.id = ra.contextid&lt;br /&gt;
INNER JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
INNER JOIN prefix_user usr ON ra.userid = usr.id&lt;br /&gt;
ORDER BY cc.depth, cc.path, usr.lastname, usr.firstname, r.name, cc.name&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Permissions Overides on Categories===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712834 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT rc.id, ct.instanceid, ccat.name, rc.roleid, rc.capability, rc.permission, &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( rc.timemodified ) , &#039;%Y-%m-%d&#039; ) AS timemodified, rc.modifierid, ct.instanceid, ct.path, ct.depth&lt;br /&gt;
FROM `prefix_role_capabilities` AS rc&lt;br /&gt;
INNER JOIN `prefix_context` AS ct ON rc.contextid = ct.id&lt;br /&gt;
INNER JOIN `prefix_course_categories` AS ccat ON ccat.id = ct.instanceid&lt;br /&gt;
AND `contextlevel` =40&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;Totally Opened Courses&amp;quot; (visible, opened to guests, with no password)===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712837 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Course&#039;,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/enrol/instances.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Méthodes inscription&amp;lt;/a&amp;gt;&#039;) AS &#039;Enrollment plugins&#039;,&lt;br /&gt;
e.sortorder&lt;br /&gt;
FROM prefix_enrol AS e, prefix_course AS c&lt;br /&gt;
WHERE e.enrol=&#039;guest&#039; AND e.status=0 AND e.password=&#039;&#039; AND c.id=e.courseid AND c.visible=1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;loggedin users&amp;quot; from the last 120 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id,username,FROM_UNIXTIME(`lastlogin`) as days &lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;and user count for that same population:&#039;&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(id) as Users  FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists the users who have only logged into the site once===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, username, firstname, lastname, idnumber&lt;br /&gt;
FROM prefix_user&lt;br /&gt;
WHERE prefix_user.deleted = 0&lt;br /&gt;
AND prefix_user.lastlogin = 0 &lt;br /&gt;
AND prefix_user.lastaccess &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Students in all courses of some institute===&lt;br /&gt;
What is the status (deleted or not) of all Students (roleid = 5) in all courses of some Institute&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname, u.firstname, u.lastname, u.deleted&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND u.institution = &#039;please enter school name here&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Full User info (for deleted users)===&lt;br /&gt;
Including extra custom profile fields (from prefix_user_info_data)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT * &lt;br /&gt;
FROM prefix_user as u &lt;br /&gt;
JOIN prefix_user_info_data as uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_user_info_field as uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;class&#039;)&lt;br /&gt;
WHERE `deleted` = &amp;quot;1&amp;quot; and `institution`=&amp;quot;your school name&amp;quot; and `department` = &amp;quot;your department&amp;quot; and `data` = &amp;quot;class level and number&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User&#039;s courses===&lt;br /&gt;
change &amp;quot;u.id = 2&amp;quot; with a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, c.id, c.fullname&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE u.id = 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Users with extra info (email) in current course===&lt;br /&gt;
blocks/configurable_reports replaces %%COURSEID%% with course id.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, u.email&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Students with enrollment and completion dates in current course===&lt;br /&gt;
This is meant to be a &amp;quot;global&amp;quot; report in Configurable Reports containing the following:&lt;br /&gt;
firstname, lastname, idnumber, institution, department, email, student enrolment date, student completion date&lt;br /&gt;
Note: for PGSQL, use to_timestamp() instead of FROM_UNIXTIME()&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.firstname&lt;br /&gt;
, u.lastname&lt;br /&gt;
, u.idnumber&lt;br /&gt;
, u.institution&lt;br /&gt;
, u.department&lt;br /&gt;
, u.email&lt;br /&gt;
, FROM_UNIXTIME(cc.timeenrolled)&lt;br /&gt;
, FROM_UNIXTIME(cc.timecompleted)&lt;br /&gt;
&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_completions AS cc ON cc.course = c.id AND cc.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Special Roles===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.roleid,r.name&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,ra.userid,&#039;&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Username&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON (ctx.id = ra.contextid AND ctx.contextlevel = 50)&lt;br /&gt;
JOIN prefix_course AS c ON ctx.instanceid = c.id&lt;br /&gt;
WHERE ra.roleid &amp;gt; 6&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses without Teachers===&lt;br /&gt;
Actually, shows the number of Teachers in a course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Teachers&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
ORDER BY Teachers ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of users who have been enrolled for more than 4 weeks===&lt;br /&gt;
For Moodle 2.2 , by  Isuru Madushanka Weerarathna &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT uenr.userid As User, IF(enr.courseid=uenr.courseid ,&#039;Y&#039;,&#039;N&#039;) As Enrolled, &lt;br /&gt;
IF(DATEDIFF(NOW(), FROM_UNIXTIME(uenr.timecreated))&amp;gt;=28,&#039;Y&#039;,&#039;N&#039;) As EnrolledMoreThan4Weeks&lt;br /&gt;
FROM prefix_enrol As enr, prefix_user_enrolments AS uenr&lt;br /&gt;
WHERE enr.id = uenr.enrolid AND enr.status = uenr.status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with language===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
This will show you the language setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, lang from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools.&lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;en&#039; to &#039;en_us&#039; for all users:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To do this for only users who have a particular country set, use this as an example:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE country = &#039;US&#039; AND lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with Authentication ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Sometimes you need to do mass changes of authentication methods. A common case is changing default manual to LDAP. &lt;br /&gt;
&lt;br /&gt;
This will show you the Authentication setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, auth from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools. &lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;manual&#039; to &#039;ldap&#039; 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.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET auth = &#039;ldap&#039; WHERE auth = &#039;manual&#039; AND id &amp;gt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compare role capability and permissions ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT mrc.capability &lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;1&#039; AND rc.contextid = &#039;1&#039;) AS Manager&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;2&#039; AND rc.contextid = &#039;1&#039;) AS CourseCreator&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;3&#039; AND rc.contextid = &#039;1&#039;) AS Teacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;4&#039; AND rc.contextid = &#039;1&#039;) AS AssistantTeacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;5&#039; AND rc.contextid = &#039;1&#039;) AS Student&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;6&#039; AND rc.contextid = &#039;1&#039;) AS Guest&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_role_capabilities` AS mrc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User&#039;s accumulative time spent in course ===&lt;br /&gt;
A sum up of the time delta between logstore_standard_log user&#039;s records, considering the a 2 hour session limit.&lt;br /&gt;
&lt;br /&gt;
Uses: current user&#039;s id %%USERID%% and current course&#039;s id %%COURSEID%%  &lt;br /&gt;
&lt;br /&gt;
And also using a date filter (which can be ignored)  &lt;br /&gt;
&lt;br /&gt;
The extra &amp;quot;User&amp;quot; field is used as a dummy field for the Line chart Series field, in which I use X=id, Series=Type, Y=delta.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
l.id, &lt;br /&gt;
l.timecreated, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(l.timecreated),&#039;%d-%m-%Y&#039;) AS dTime,&lt;br /&gt;
@prevtime := (SELECT max(timecreated) FROM mdl_logstore_standard_log &lt;br /&gt;
		WHERE userid = %%USERID%% and id &amp;lt; l.id ORDER BY id ASC LIMIT 1) AS prev_time,&lt;br /&gt;
IF (l.timecreated - @prevtime &amp;lt; 7200, @delta := @delta + (l.timecreated-@prevtime),0) AS sumtime,&lt;br /&gt;
l.timecreated-@prevtime AS delta,&lt;br /&gt;
&amp;quot;User&amp;quot; as type&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log as l, &lt;br /&gt;
(SELECT @delta := 0) AS s_init &lt;br /&gt;
# Change UserID&lt;br /&gt;
WHERE l.userid = %%USERID%% AND l.courseid = %%COURSEID%%&lt;br /&gt;
%%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Low-Participation Student Report ===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
This report returns a list of students who are enrolled in courses filtered by a short-name text marker (in this case &amp;quot;OL-&amp;quot;) in the specified category, but have very low participation in the course during the specified time period (fewer than 2 &amp;quot;Edits&amp;quot; to Activity Modules, indicating few active contributions to the course). The number of &amp;quot;Edits&amp;quot; is provided for each student for the time period specified.&lt;br /&gt;
&lt;br /&gt;
An &amp;quot;Edit&amp;quot; is defined as course activity other than viewing content. Click the &amp;quot;Logs&amp;quot; link to review the student activity. The Logs offer the option to review &amp;quot;View&amp;quot; activity as well as &amp;quot;Edit&amp;quot; activity.&lt;br /&gt;
&lt;br /&gt;
Only &amp;quot;visible&amp;quot; courses are included in this report. The report may be downloaded as an Excel spreadsheet.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t forget to set up Filters: &amp;quot;Start / End date filter&amp;quot; and &amp;quot;Filter categories&amp;quot; on the Filters tab in Configurable reports.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname AS Last, u.firstname AS First, u.idnumber AS IDnumber, u.email AS email, c.shortname AS CourseID,  count(l.id) AS Edits, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;https://learn.granite.edu/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=-view&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id AND l.action NOT LIKE &amp;quot;view%&amp;quot; %%FILTER_STARTTIME:l.TIME:&amp;gt;%% %%FILTER_ENDTIME:l.TIME:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.visible=1&lt;br /&gt;
# This prefix filter allows the exclusion of non-online courses at the original institution. Alter this to fit your institution, or remove it.&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
%%FILTER_CATEGORIES:c.category%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
HAVING Edits &amp;lt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Messages of All Users in a Specific Course ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
NOTE: This query will probably not work at all in 3.5 now due to the changes in the structure of the Messages database. - RT&lt;br /&gt;
&lt;br /&gt;
This query shows the personal messages between users in a specific course, given the course id number. Properly speaking, personal messages pertain only to users and are not part of courses, but by filtering enrollments for roles in a course, you can show this. &lt;br /&gt;
&lt;br /&gt;
This report as is shows only the messages between Teachers and Students, as the WHERE statement contains and AND ((...))) section that restrict this report to ONLY messages between Teachers (role id = 3) and Students (role id =5). Remove that part of the statement if you wish to see _all_ messages between all users, e.g. teachers to teachers, student to student. &lt;br /&gt;
&lt;br /&gt;
Also, if you have created custom roles, you can replace the default id numbers with custom ones to further enhance the report.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.username AS &#039;From&#039;,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS &#039;From Name&#039;,&lt;br /&gt;
u2.username AS &#039;To&#039;,&lt;br /&gt;
CONCAT(u2.firstname ,&#039; &#039;,u2.lastname) AS &#039;To Name&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(me.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;,&lt;br /&gt;
me.subject AS &#039;Subject&#039;, &lt;br /&gt;
me.smallmessage AS &#039;Message&#039;&lt;br /&gt;
FROM prefix_message me&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = me.useridfrom AND ra.roleid IN (3,4,5)  &lt;br /&gt;
JOIN prefix_role_assignments AS ra2 ON ra2.userid = me.useridto AND ra2.roleid IN (3,4,5)  &lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id AND ra2.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_user u ON u.id = me.useridfrom&lt;br /&gt;
JOIN prefix_user u2 ON u2.id = me.useridto&lt;br /&gt;
WHERE c.id=## &lt;br /&gt;
AND ((ra.roleid = 3 AND ra2.roleid = 5) OR (ra.roleid = 5 AND ra2.roleid = 3)) &lt;br /&gt;
ORDER BY me.useridfrom, me.useridto, me.timecreated&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Log Activity Reports==&lt;br /&gt;
===Count all Active Users by ROLE in a course category (including all of its sub-categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT l.userid) as active&lt;br /&gt;
FROM mdl_course as c&lt;br /&gt;
JOIN mdl_context AS ctx ON  ctx.instanceid=c.id&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN mdl_user_lastaccess as l ON ra.userid = l.userid&lt;br /&gt;
JOIN mdl_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category=cats.id AND (&lt;br /&gt;
	cats.path LIKE &#039;%/80/%&#039;&lt;br /&gt;
	OR cats.path LIKE &#039;%/80&#039;&lt;br /&gt;
) &lt;br /&gt;
AND ra.roleid=3  AND ctx.contextlevel=50  #ra.roleid= TEACHER 3, NON-EDITING TEACHER 4, STUDENT 5&lt;br /&gt;
AND  l.timeaccess &amp;gt; (unix_timestamp() - ((60*60*24)*NO_OF_DAYS)) #NO_OF_DAYS change to number&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Detailed &amp;quot;VIEW&amp;quot; ACTION for each ROLE (TEACHER,NONE-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT l.action, count( l.userid ) as counter , r.name&lt;br /&gt;
FROM `prefix_log` as l&lt;br /&gt;
JOIN `prefix_role_assignments` AS ra on l.userid = ra.userid&lt;br /&gt;
JOIN `prefix_role` AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE (ra.roleid IN (3,4,5)) AND (l.action LIKE &#039;%view%&#039; )&lt;br /&gt;
GROUP BY roleid,l.action&lt;br /&gt;
order by r.name,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total Activity of Roles:&amp;quot;Teacher&amp;quot; and &amp;quot;None-Editing Teacher&amp;quot; by Dates and by Hours===&lt;br /&gt;
The output columns of this report table can be used as base for a Pivot-Table&lt;br /&gt;
which will show the amount of &#039;&#039;&#039;activity&#039;&#039;&#039; per &#039;&#039;&#039;hour&#039;&#039;&#039; per &#039;&#039;&#039;days&#039;&#039;&#039; in 3D graph view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%Y-%m-%d&#039; ) AS grptimed ,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%k&#039; ) AS grptimeh  , count( l.userid ) AS counter &lt;br /&gt;
FROM `prefix_log` AS l&lt;br /&gt;
JOIN prefix_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
WHERE ra.roleid IN (3,4)&lt;br /&gt;
GROUP BY grptimed,grptimeh&lt;br /&gt;
ORDER BY grptimed,grptimeh&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many LOGINs per user and user&#039;s Activity===&lt;br /&gt;
+ link username to a user activity graph report&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,u.id,&#039;&amp;amp;mode=alllogs&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) as Username&lt;br /&gt;
,count(*) as logins&lt;br /&gt;
,(SELECT count(*) FROM prefix_log WHERE userid = l.userid GROUP BY userid) as Activity &lt;br /&gt;
FROM prefix_log as l JOIN prefix_user as u ON l.userid = u.id &lt;br /&gt;
WHERE `action` LIKE &#039;%login%&#039; group by userid&lt;br /&gt;
ORDER BY Activity DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Distinct user logins per month===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
The following will show you the months of the current calendar year with the total number of distinct, unique user logins per month. Change the year in the WHERE clause to the year you need.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
 COUNT(DISTINCT l.userid) AS &#039;DistinctUserLogins&#039;, &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%M&#039;) AS &#039;Month&#039;&lt;br /&gt;
FROM prefix_logstore_standard_log l&lt;br /&gt;
WHERE l.action = &#039;loggedin&#039; AND YEAR(FROM_UNIXTIME(l.timecreated)) = &#039;2017&#039; &lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(l.timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total activity per course, per unique user on the last 24h===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    COUNT(DISTINCT userid) AS countUsers&lt;br /&gt;
  , COUNT(l.courseid) AS countVisits&lt;br /&gt;
  , CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
  JOIN mdl_course AS c ON c.id = l.courseid&lt;br /&gt;
WHERE l.courseid &amp;gt; 0&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 1 DAY)&lt;br /&gt;
      AND c.fullname LIKE &#039;%תשעו%&#039;&lt;br /&gt;
GROUP BY l.courseid&lt;br /&gt;
ORDER BY countVisits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Instructor Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of instructors in all courses per week of a term, including pre-term and post-term edits. An edit is defined as a change to the course, such as a discussion post, the grading of an assignment, or the uploading of file attachments, as well as alterations to course content.&lt;br /&gt;
&lt;br /&gt;
* To specify a subject and/or course number, use % as a wildcard, e.g. ARTS% or ARTS501%&lt;br /&gt;
* To match part of a last name, use %, e.g. Smi% will match &amp;quot;Smith&amp;quot;, &amp;quot;Smile&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
At our institution, we include filters on the course name or category to constrain by terms. These are very specific to how course names and categories are constructed at our institution, so I&#039;ve removed those elements from this code. Also, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; lines for longer terms, or remove lines for shorter terms.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version uses legacy (pre-2.7) logs. See below for post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, c.startdate AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time)) - WEEK(FROM_UNIXTIME(c.startdate))&amp;lt;0,1,0)) AS BeforeTerm&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=0,1,0)) AS Week1&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=1,1,0)) AS Week2&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=2,1,0)) AS Week3&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=3,1,0)) AS Week4&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=4,1,0)) AS Week5&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=5,1,0)) AS Week6&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=6,1,0)) AS Week7&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=7,1,0)) AS Week8&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=8,1,0)) AS Week9&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=9,1,0)) AS Week10&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=10,1,0)) AS Week11&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=11,1,0)) AS Week12&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))&amp;gt;=12,1,0)) AS AfterTerm&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE :course&lt;br /&gt;
AND u.lastname LIKE :last_name&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 log version:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(DISTINCT l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
AND cc.idnumber LIKE &#039;%current%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
#HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY RIGHT(c.shortname,2), c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Student Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of students in the current course by week, including pre-term and post-term edits. An 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 (if permitted).&lt;br /&gt;
&lt;br /&gt;
Links to three other reports are also provided:&lt;br /&gt;
&lt;br /&gt;
* Logs: complete log entries for the student in the course, organized by date&lt;br /&gt;
* Activity Outline: the &amp;quot;Outline Report&amp;quot; from the User Activity Reports, summarizing the student&#039;s activity in the course, organized by course content&lt;br /&gt;
* Consolidated Activity Report: the &amp;quot;Complete Report&amp;quot; from the User Activity Reports, detailing the student&#039;s activity in the course, organized by course content (includes text of forum posts)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). At our institution, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for a post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF((l.time-c.startdate)/7&amp;lt;0,1,0)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=0,1,0)) AS &#039;Week 1&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=1,1,0)) AS &#039;Week 2&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=2,1,0)) AS &#039;Week 3&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=3,1,0)) AS &#039;Week 4&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=4,1,0)) AS &#039;Week 5&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=5,1,0)) AS &#039;Week 6&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=6,1,0)) AS &#039;Week 7&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=7,1,0)) AS &#039;Week 8&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=8,1,0)) AS &#039;Week 9&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=9,1,0)) AS &#039;Week 10&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=10,1,0)) AS &#039;Week 11&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=11,1,0)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))&amp;gt;=15,1,0)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 (Standard Logs) version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
# Our institution stores academic advisor names and emails in custom profile fields&lt;br /&gt;
#, CONCAT(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,uce.data,&#039;&amp;quot;&amp;gt;&#039;,uid.data, &#039;&amp;lt;/a&amp;gt;&#039;)  AS &#039;Academic Advisor&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,&#039;Posts&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Posts&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# student academic coach - you can include custom profile field data with these methods&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uid ON u.id = uid.userid AND uid.fieldid = &#039;2&#039;&lt;br /&gt;
# student academic coach email&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uce on u.id = uce.userid AND uce.fieldid = &#039;6&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===My Weekly Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of the &#039;&#039;&#039;current user&#039;&#039;&#039; in the &#039;&#039;&#039;current course&#039;&#039;&#039; 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).&lt;br /&gt;
&lt;br /&gt;
This report uses Standard Logs (post 2.7).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
l.component AS &#039;activity&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS &#039;Total&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE 1&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
AND u.id = %%USERID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY l.component&lt;br /&gt;
&lt;br /&gt;
ORDER BY l.component&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Faculty/Student Interactions===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Returns a count of instructor and other-student responses to student activity for the specified time period. This report can help indicate whether students&#039; comments are being responded to, as well as summarizing post activity by students during the specified time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for the post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This report can take a long time to run. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
LEFT JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
# We care about messages that involve both the instructor and students of this course&lt;br /&gt;
# messages from instructor to students:&lt;br /&gt;
# LEFT JOIN prefix_message AS mts ON mts.useridfrom = instr.id AND mts.useridto = allstu.id&lt;br /&gt;
# LEFT JOIN prefix_message AS mfs ON mfs.useridfrom = instr.id AND mfs.useridto = allstu.id&lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 Standard Logs version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
 JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student Resource Usage===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Standard Logs&amp;quot; from Moodle 2.7+.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
, m.name AS &#039;item type&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&lt;br /&gt;
COALESCE(a.name, &#039;&#039;), &lt;br /&gt;
COALESCE(b.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cert.name,&#039;&#039;), &lt;br /&gt;
COALESCE(chat.name,&#039;&#039;), &lt;br /&gt;
COALESCE(choice.name,&#039;&#039;), &lt;br /&gt;
COALESCE(data.name,&#039;&#039;), &lt;br /&gt;
COALESCE(feedback.name,&#039;&#039;), &lt;br /&gt;
COALESCE(folder.name,&#039;&#039;), &lt;br /&gt;
COALESCE(forum.name,&#039;&#039;), &lt;br /&gt;
COALESCE(glossary.name,&#039;&#039;), &lt;br /&gt;
COALESCE(imscp.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lesson.name,&#039;&#039;), &lt;br /&gt;
COALESCE(p.name,&#039;&#039;),&lt;br /&gt;
COALESCE(questionnaire.name,&#039;&#039;), &lt;br /&gt;
COALESCE(quiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cr.name,&#039;&#039;), &lt;br /&gt;
COALESCE(scorm.name,&#039;&#039;), &lt;br /&gt;
COALESCE(survey.name,&#039;&#039;), &lt;br /&gt;
COALESCE(url.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(workshop.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kalvidassign.name,&#039;&#039;), &lt;br /&gt;
COALESCE(attendance.name,&#039;&#039;), &lt;br /&gt;
COALESCE(checklist.name,&#039;&#039;), &lt;br /&gt;
COALESCE(flashcard.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lti.name,&#039;&#039;), &lt;br /&gt;
COALESCE(oublog.name,&#039;&#039;), &lt;br /&gt;
COALESCE(ouwiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(subpage.name,&#039;&#039;), &lt;br /&gt;
COALESCE(journal.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lightboxgallery.name,&#039;&#039;), &lt;br /&gt;
COALESCE(elluminate.name,&#039;&#039;), &lt;br /&gt;
COALESCE(adaptivequiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(hotpot.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiziq.name,&#039;&#039;), &lt;br /&gt;
COALESCE(turnitintooltwo.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kvr.name,&#039;&#039;)&lt;br /&gt;
) AS &#039;item name&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;r&#039;),1,0)) AS &#039;total views&#039;&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),1,0)) AS &#039;total submissions&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;r&#039;),u.id,NULL)) AS &#039;count of students who viewed&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),u.id,NULL)) AS &#039;count of students who submitted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 #AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module AND m.name NOT LIKE &#039;label&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON a.id = cm.instance AND m.name = &#039;assign&#039;&lt;br /&gt;
LEFT JOIN prefix_book AS b ON b.id = cm.instance AND m.name = &#039;book&#039;&lt;br /&gt;
LEFT JOIN prefix_certificate AS cert ON cert.id = cm.instance AND m.name = &#039;certificate&#039;&lt;br /&gt;
LEFT JOIN prefix_chat AS chat ON chat.id = cm.instance AND m.name = &#039;chat&#039;&lt;br /&gt;
LEFT JOIN prefix_choice AS choice ON choice.id = cm.instance AND m.name = &#039;choice&#039;&lt;br /&gt;
LEFT JOIN prefix_data AS data ON data.id = cm.instance AND m.name = &#039;data&#039;&lt;br /&gt;
LEFT JOIN prefix_feedback AS feedback ON feedback.id = cm.instance AND m.name = &#039;feedback&#039;&lt;br /&gt;
LEFT JOIN prefix_folder AS folder ON folder.id = cm.instance AND m.name = &#039;folder&#039;&lt;br /&gt;
LEFT JOIN prefix_forum AS forum ON forum.id = cm.instance AND m.name = &#039;forum&#039;&lt;br /&gt;
LEFT JOIN prefix_glossary AS glossary ON glossary.id = cm.instance AND m.name = &#039;glossary&#039;&lt;br /&gt;
LEFT JOIN prefix_imscp AS imscp ON imscp.id = cm.instance AND m.name = &#039;imscp&#039;&lt;br /&gt;
LEFT JOIN prefix_lesson AS lesson ON lesson.id = cm.instance AND m.name = &#039;lesson&#039;&lt;br /&gt;
LEFT JOIN prefix_page AS p ON p.id = cm.instance AND m.name = &#039;page&#039;&lt;br /&gt;
LEFT JOIN prefix_questionnaire AS questionnaire ON questionnaire.id = cm.instance AND m.name = &#039;questionnaire&#039;&lt;br /&gt;
LEFT JOIN prefix_quiz AS quiz ON quiz.id = cm.instance AND m.name = &#039;quiz&#039;&lt;br /&gt;
LEFT JOIN prefix_resource AS cr ON cr.id = cm.instance AND m.name = &#039;resource&#039;&lt;br /&gt;
LEFT JOIN prefix_scorm AS scorm ON scorm.id = cm.instance AND m.name = &#039;scorm&#039;&lt;br /&gt;
LEFT JOIN prefix_survey AS survey ON survey.id = cm.instance AND m.name = &#039;survey&#039;&lt;br /&gt;
LEFT JOIN prefix_url AS url ON url.id = cm.instance AND m.name = &#039;url&#039;&lt;br /&gt;
LEFT JOIN prefix_wiki AS wiki ON wiki.id = cm.instance AND m.name = &#039;wiki&#039;&lt;br /&gt;
LEFT JOIN prefix_workshop AS workshop ON workshop.id = cm.instance AND m.name = &#039;workshop&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidassign AS kalvidassign ON kalvidassign.id = cm.instance AND m.name = &#039;kalvidassign&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidres AS kvr ON kvr.id = cm.instance AND m.name = &#039;kalvidres&#039;&lt;br /&gt;
LEFT JOIN prefix_attendance AS attendance ON attendance.id = cm.instance AND m.name = &#039;attendance&#039;&lt;br /&gt;
LEFT JOIN prefix_checklist AS checklist ON checklist.id = cm.instance AND m.name = &#039;checklist&#039;&lt;br /&gt;
LEFT JOIN prefix_flashcard AS flashcard ON flashcard.id = cm.instance AND m.name = &#039;flashcard&#039;&lt;br /&gt;
LEFT JOIN prefix_lti AS lti ON lti.id = cm.instance AND m.name = &#039;lti&#039;&lt;br /&gt;
LEFT JOIN prefix_oublog AS oublog ON oublog.id = cm.instance AND m.name = &#039;oublog&#039;&lt;br /&gt;
LEFT JOIN prefix_ouwiki AS ouwiki ON ouwiki.id = cm.instance AND m.name = &#039;ouwiki&#039;&lt;br /&gt;
LEFT JOIN prefix_subpage AS subpage ON subpage.id = cm.instance AND m.name = &#039;subpage&#039;&lt;br /&gt;
LEFT JOIN prefix_journal AS journal ON journal.id = cm.instance AND m.name = &#039;journal&#039;&lt;br /&gt;
LEFT JOIN prefix_lightboxgallery AS lightboxgallery ON lightboxgallery.id = cm.instance AND m.name = &#039;lightboxgallery&#039;&lt;br /&gt;
LEFT JOIN prefix_elluminate AS elluminate ON elluminate.id = cm.instance AND m.name = &#039;elluminate&#039;&lt;br /&gt;
LEFT JOIN prefix_adaptivequiz AS adaptivequiz ON adaptivequiz.id = cm.instance AND m.name = &#039;adaptivequiz&#039;&lt;br /&gt;
LEFT JOIN prefix_hotpot AS hotpot ON hotpot.id = cm.instance AND m.name = &#039;hotpot&#039;&lt;br /&gt;
LEFT JOIN prefix_wiziq AS wiziq ON wiziq.id = cm.instance AND m.name = &#039;wiziq&#039;&lt;br /&gt;
LEFT JOIN prefix_turnitintooltwo AS turnitintooltwo ON turnitintooltwo.id = cm.instance AND m.name = &#039;turnitintooltwo&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cm.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Hits) between dates===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module, COUNT( * ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME( l.`time` ) BETWEEN  &#039;2012-10-01 00:00:00&#039; AND  &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
GROUP BY module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Instances and Hits) for each academic year===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2010-10-01 00:00:00&#039; AND &#039;2011-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2010-10-01 00:00:00&#039; AND &#039;2011-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2011-10-01 00:00:00&#039; AND &#039;2012-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2011&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2011-10-01 00:00:00&#039; AND &#039;2012-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2011&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2012-10-01 00:00:00&#039; AND &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2012&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2012-10-01 00:00:00&#039; AND &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2012&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_modules AS m&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Unique user sessions per day and month + graph===&lt;br /&gt;
The &amp;quot;graph&amp;quot; column is used when displaying a graph (which needs at least three columns to pick from)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT userid) AS &amp;quot;Unique User Logins&amp;quot;&lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y /%m / %d&amp;quot;) AS &amp;quot;Year / Month / Day&amp;quot;, &amp;quot;Graph&amp;quot; &lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE action LIKE &#039;loggedin&#039;&lt;br /&gt;
#AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) # optional start date&lt;br /&gt;
#AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:00&#039;) # optional end date&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And...&lt;br /&gt;
&lt;br /&gt;
Counting user&#039;s global and unique hits per day + counting individual usage of specific activities and resources (on that day),&lt;br /&gt;
&lt;br /&gt;
And since I am using phpMyAdmin&#039;s &amp;quot;Display Graph&amp;quot; feature (at the bottom of the query&#039;s output page), I have scaled down the &amp;quot;User Hits&amp;quot; by 10 to fit the graph. that&#039;s it.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y-%m-%d&amp;quot;) AS &amp;quot;Datez&amp;quot;&lt;br /&gt;
,COUNT(DISTINCT userid) AS &amp;quot;Unique Users&amp;quot;&lt;br /&gt;
,ROUND(COUNT(*)/10) &amp;quot;User Hits (K)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_quiz&#039;,1,0)) &amp;quot;Quizzes&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_forum&#039; or component=&#039;mod_forumng&#039;,1,0)) &amp;quot;Forums&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_assign&#039;,1,0)) &amp;quot;Assignments&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_oublog&#039;,1,0)) &amp;quot;Blogs&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_resource&#039;,1,0)) &amp;quot;Files (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_url&#039;,1,0)) &amp;quot;Links (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_page&#039;,1,0)) &amp;quot;Pages (Resource)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE 1=1&lt;br /&gt;
AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-03-01 00:00:00&#039;) # optional START DATE&lt;br /&gt;
AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-05-31 23:59:00&#039;) # optional END DATE&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide, daily unique user hits for the last 7 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
  DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%m%d&#039;) &#039;Day&#039;&lt;br /&gt;
  ,COUNT(DISTINCT l.userid) AS &#039;Distinct Users Hits&#039;&lt;br /&gt;
  ,COUNT( l.userid) AS &#039;Users Hits&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
WHERE l.courseid &amp;gt; 1&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 7 DAY)&lt;br /&gt;
GROUP BY DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User detailed activity in course modules===&lt;br /&gt;
Considering only several modules: url, resource, forum, quiz, questionnaire.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.id, ra.roleid,&lt;br /&gt;
CONCAT(u.lastname, &#039; &#039;, u.firstname) AS &#039;Student&#039;&lt;br /&gt;
,COUNT(l.id) AS &#039;Actions&#039;&lt;br /&gt;
,l.component &amp;quot;Module type&amp;quot;&lt;br /&gt;
,l.objectid &amp;quot;Module ID&amp;quot;&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN l.component = &#039;mod_url&#039; THEN (SELECT u.name FROM mdl_url AS u WHERE u.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_resource&#039; THEN (SELECT r.name FROM mdl_resource AS r WHERE r.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_forum&#039; THEN (SELECT f.name FROM mdl_forum AS f WHERE f.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_quiz&#039; THEN (SELECT q.name FROM mdl_quiz AS q WHERE q.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_questionnaire&#039; THEN (SELECT q.name FROM mdl_questionnaire AS q WHERE q.id = l.objectid )&lt;br /&gt;
END AS &#039;Module name&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = l.courseid AND m.userid = u.id) &amp;quot;user_groups&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT s.name &lt;br /&gt;
  FROM mdl_course_modules AS cm &lt;br /&gt;
  JOIN mdl_course_sections AS s ON s.course = cm.course AND s.id = cm.section &lt;br /&gt;
  WHERE cm.id = l.contextinstanceid) AS &amp;quot;Section name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l  &lt;br /&gt;
JOIN mdl_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.userid = l.userid &lt;br /&gt;
  AND ra.contextid = (SELECT id FROM mdl_context WHERE instanceid = l.courseid AND contextlevel = 50) &lt;br /&gt;
WHERE l.courseid = %%COURSEID%%&lt;br /&gt;
  AND l.component IN (&#039;mod_url&#039;, &#039;mod_resource&#039;, &#039;mod_forum&#039;, &#039;mod_quiz&#039;, &#039;mod_questionnaire&#039;) &lt;br /&gt;
  %%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%%&lt;br /&gt;
 &lt;br /&gt;
GROUP BY u.id, l.component&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What teachers and courses considered active?===&lt;br /&gt;
This report display several calculations and parameters that help the Online academic training team find teachers that might need more support getting their courses more supporting of online learning pedagogical methodologies.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,&lt;br /&gt;
			  course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
#,course.shortname&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2012%&#039; THEN &#039;2012&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2013%&#039; THEN &#039;2013&#039; &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2014%&#039; THEN &#039;2014&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2015%&#039; THEN &#039;2015&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester a%&#039; THEN &#039;Spring semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester b%&#039; THEN &#039;Fall semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester s%&#039; THEN &#039;Summer semester&#039;&lt;br /&gt;
END AS Semester&lt;br /&gt;
&lt;br /&gt;
,IF(course.startdate&amp;gt;0, DATE_FORMAT(FROM_UNIXTIME(startdate), &#039;%d-%m-%Y&#039;), &#039;no date&#039;) AS &amp;quot;Course Start Date&amp;quot; &lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 4 AND ctx.instanceid = course.id&lt;br /&gt;
) AS &amp;quot;Assistant teacher&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
&lt;br /&gt;
# Uncomment to use the new Moodle 2.8+ logstore&lt;br /&gt;
#,(SELECT COUNT(*) FROM mdl_logstore_standard_log AS l WHERE l.courseid = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Student HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Teacher HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_log AS l WHERE l.course = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course c&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = c.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND c.id = course.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
  &lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = course.id) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(DISTINCT cm.module) FROM prefix_course_modules cm &lt;br /&gt;
  WHERE cm.course = course.id) UniqueModules&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(DISTINCT m.name) &lt;br /&gt;
  FROM prefix_course_modules cm &lt;br /&gt;
  JOIN mdl_modules as m ON m.id = cm.module&lt;br /&gt;
  WHERE cm.course = course.id) UniqueModuleNames&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;ouwiki&#039;, &#039;wiki&#039;) ) &amp;quot;Num Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;oublog&#039;) ) &amp;quot;Num Blogs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;forum&#039;, &#039;forumng&#039;) ) &amp;quot;Num Forums&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;resource&#039;, &#039;folder&#039;, &#039;url&#039;, &#039;tab&#039;, &#039;file&#039;, &#039;book&#039;, &#039;page&#039;) ) Resources&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;forum&#039;, &#039;forumng&#039;, &#039;oublog&#039;, &#039;page&#039;, &#039;file&#039;, &#039;url&#039;, &#039;wiki&#039; , &#039;ouwiki&#039;) ) &amp;quot;Basic Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;advmindmap&#039;, &#039;assign&#039;, &#039;attendance&#039;, &#039;book&#039;, &#039;choice&#039;, &#039;folder&#039;, &#039;tab&#039;, &#039;glossary&#039;, &#039;questionnaire&#039;, &#039;quiz&#039;, &#039;label&#039; ) ) &amp;quot;Avarage Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;elluminate&#039;, &#039;game&#039;, &#039;workshop&#039;) ) &amp;quot;Advanced Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course&lt;br /&gt;
&lt;br /&gt;
#WHERE course.shortname LIKE &#039;%2015%&#039;&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_SEARCHTEXT:course.shortname:~%%&lt;br /&gt;
&lt;br /&gt;
WHERE course.fullname LIKE &#039;%2015%&#039; &lt;br /&gt;
&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY UniqueModules DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly attendance report===&lt;br /&gt;
This report display weekly report in format HH:M:SS This MySQL query works together with AttendaceRegister module, and gather Log information from Attendanceregister_log table. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, SEC_TO_TIME (SUM(arsess.duration)) AS weekly_online_attendance,  FROM_UNIXTIME (arsess.logout) AS Last_Logout&lt;br /&gt;
FROM prefix_attendanceregister_session AS arsess&lt;br /&gt;
JOIN prefix_user AS u ON arsess.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE (((arsess.logout) BETWEEN UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 7 DAY)) AND UNIX_TIMESTAMP(CURDATE())))&lt;br /&gt;
&lt;br /&gt;
GROUP BY arsess.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many distinct users connected to Moodle using the app by month===&lt;br /&gt;
https://moodle.org/mod/forum/discuss.php?d=336086#p1354194 by &lt;br /&gt;
Iñigo Zendegi Urzelai&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;) as year, &lt;br /&gt;
  to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;) as month, &lt;br /&gt;
  count(distinct userid) as distinct_users&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log m&lt;br /&gt;
WHERE m.origin=&#039;ws&#039;&lt;br /&gt;
GROUP BY to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;), to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;) &lt;br /&gt;
ORDER BY to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;), to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Course Reports==&lt;br /&gt;
===Most Active courses===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(l.userid) AS Views&lt;br /&gt;
FROM `mdl_logstore_standard_log` l, `mdl_user` u, `mdl_role_assignments` r&lt;br /&gt;
WHERE l.courseid=35&lt;br /&gt;
AND l.userid = u.id&lt;br /&gt;
AND (l.timecreated &amp;gt; UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) AND l.timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:59&#039;))AND r.contextid= (&lt;br /&gt;
	 SELECT id&lt;br /&gt;
	 FROM mdl_context&lt;br /&gt;
	 WHERE contextlevel=50 AND instanceid=l.courseid&lt;br /&gt;
 )&lt;br /&gt;
AND r.roleid=5&lt;br /&gt;
AND r.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active courses, advanced===&lt;br /&gt;
Including: Teacher&#039;s name, link to the course, All types of log activities, special YEAR generated field, Activities and Resource count, enrolled Student count&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשע&#039; THEN &#039;תשע&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעא&#039; THEN &#039;תשעא&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעב&#039; THEN &#039;תשעב&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = l.course) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_log l &lt;br /&gt;
INNER JOIN prefix_course c ON l.course = c.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
#The following line restricts the courses returned to those having more than 2 modules.  Adjust based on your needs.&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY Year DESC, hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Least active or probably empty courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;-1&amp;quot; instead of &amp;quot;0&amp;quot; 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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
c.fullname,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;CourseLink&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timecreated&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timemodified&#039;,&lt;br /&gt;
CASE&lt;br /&gt;
 WHEN c.timecreated = c.timemodified THEN &#039;-1&#039;&lt;br /&gt;
 ELSE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated))&lt;br /&gt;
END AS &#039;DateDifference&#039;,&lt;br /&gt;
COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
LEFT JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
WHERE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated) ) &amp;lt; 60&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
HAVING COUNT(ue.id) &amp;lt;= 3&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Count unique teachers with courses that use at least X module (Moodle19)===&lt;br /&gt;
You can remove the outer &amp;quot;SELECT COUNT(*) FROM (...) AS ActiveTeachers&amp;quot; SQL query and get the list of the Teachers and Courses.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(*)&lt;br /&gt;
FROM (SELECT c.id AS CourseID, c.fullname AS Course, ra.roleid AS RoleID, CONCAT(u.firstname, &#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = c.id) AS Modules&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid AND ctx.contextlevel = 50 &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE  ra.roleid = 3 &lt;br /&gt;
GROUP BY u.id&lt;br /&gt;
HAVING Modules &amp;gt; 5) AS ActiveTeachers&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RESOURCE count for each COURSE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) count, l.course, c.fullname coursename&lt;br /&gt;
FROM prefix_resource l INNER JOIN prefix_course c on l.course = c.id&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY count DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Common resource types count for each Category (Moodle19)===&lt;br /&gt;
Including sub-categories in total count.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category&lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Links&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference NOT LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Files&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;directory&#039; &lt;br /&gt;
) AS Folders&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;html&#039; &lt;br /&gt;
) AS Pages&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM stats_log_context_role_course &lt;br /&gt;
WHERE roleid = 5 AND module = &#039;resource&#039; AND category = mcc.id&lt;br /&gt;
) AS Hits&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Where &amp;quot;stats_log_context_role_course&amp;quot; (in the above SQL query) is a VIEW generated by:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
CREATE VIEW stats_log_context_role_course AS&lt;br /&gt;
SELECT l.course, c.category, cc.path, l.module, l.action, ra.userid, ra.roleid&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = l.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Same query but for Moodle2+&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category,&lt;br /&gt;
mcc.path,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_url AS u&lt;br /&gt;
JOIN prefix_course AS c ON c.id = u.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS URLs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_folder AS f&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS FOLDERs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_page AS p&lt;br /&gt;
JOIN prefix_course AS c ON c.id = p.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS PAGEs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_book AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS BOOKs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_label AS l&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS LABELs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_tab AS t&lt;br /&gt;
JOIN prefix_course AS c ON c.id = t.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS TABs&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed Resource COUNT by Teacher in each course===&lt;br /&gt;
&lt;br /&gt;
Including (optional) filter by: year, semester and course id.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
, c.id&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעב%&#039; THEN &#039;2012&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעא%&#039; THEN &#039;2011&#039;&lt;br /&gt;
END ) as Year&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר א%&#039; THEN &#039;Semester A&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ב%&#039; THEN &#039;Semester B&#039;&lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ק%&#039; THEN &#039;Semester C&#039;&lt;br /&gt;
END ) as Semester&lt;br /&gt;
,COUNT(c.id) AS Total&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 20) AS TABs&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 33) AS BOOKs&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_resource` as r &lt;br /&gt;
JOIN `prefix_course` AS c on c.id = r.course&lt;br /&gt;
#WHERE type= &#039;file&#039; and reference NOT LIKE &#039;http://%&#039; &lt;br /&gt;
&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
#AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY COUNT(c.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses that are defined as using GROUPs===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/group/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = c.id) Modules&lt;br /&gt;
,(SELECT count(*) FROM prefix_groups g WHERE g.courseid = c.id) Groups&lt;br /&gt;
 FROM `prefix_course` AS c&lt;br /&gt;
WHERE groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Groups===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with Groups in them (groupmode &amp;gt; 0). You can also use groupmode=1 to list just Separate type groups or groupmode=2 to list Visible type groups.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name, c.groupmode&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON c.id = g.courseid&lt;br /&gt;
WHERE c.groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users enrolled in a course with groups but not assigned a group ===&lt;br /&gt;
&lt;br /&gt;
Displays by course all enrolled users that have not been assigned a group in courses that have groups. NOTE: This needs to be optimized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) AS ROLE&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = course.id&lt;br /&gt;
&lt;br /&gt;
WHERE ue.enrolid NOT IN (select userid from prefix_groups_members WHERE g.id=groupid)&lt;br /&gt;
&lt;br /&gt;
ORDER BY Course, Lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Groups in course with member list===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List the groups in a course (replace the # by the course id number) with the members of each group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name AS Groupname, u.username&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_user AS u ON m.userid = u.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Group Export===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
There&#039;s a [[Import_groups|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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT g.name AS groupname, g.description, g.enrolmentkey&lt;br /&gt;
FROM prefix_groups AS g &lt;br /&gt;
JOIN prefix_course as c ON g.courseid = c.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Courses in and below a certain category===&lt;br /&gt;
Use this SQL code to retrieve all courses that exist in or under a set category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the category you want to know about...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course. * , prefix_course_categories. *&lt;br /&gt;
FROM prefix_course, prefix_course_categories&lt;br /&gt;
WHERE prefix_course.category = prefix_course_categories.id&lt;br /&gt;
AND (&lt;br /&gt;
prefix_course_categories.path LIKE &#039;/$s/%&#039;&lt;br /&gt;
OR prefix_course_categories.path LIKE &#039;/$s&#039;&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Categories in one level below a certain category===&lt;br /&gt;
Use this PHP code to retrieve a list of all categories below a certain category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the top level category you are interested in.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
require_once(&#039;./config.php&#039;);&lt;br /&gt;
&lt;br /&gt;
$parent_id = $s;&lt;br /&gt;
&lt;br /&gt;
$categories= array();&lt;br /&gt;
&lt;br /&gt;
$categories = get_categories($parent_id);&lt;br /&gt;
&lt;br /&gt;
echo &#039;&amp;lt;ol&amp;gt;&#039;;&lt;br /&gt;
foreach ($categories as $category)&lt;br /&gt;
        {&lt;br /&gt;
        echo &#039;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&#039;.$CFG-&amp;gt;wwwroot.&#039;/course/category.php?id=&#039;.$category-&amp;gt;id.&#039;&amp;quot;&amp;gt;&#039;.$category-&amp;gt;name.&#039;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
        }&lt;br /&gt;
echo &#039;&amp;lt;/ol&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Blog activity per Course (not including VIEW)===&lt;br /&gt;
Filter activity logging to some specific Course Categories!&lt;br /&gt;
+ link course name to actual course (for quick reference)&lt;br /&gt;
(you can change %blog% to %wiki% to filter down all wiki activity or any other module you wish)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID&lt;br /&gt;
,m.name ,count(cm.id) as counter &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS Students&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE `module` LIKE &#039;%blog%&#039; AND course = c.id AND action NOT LIKE &#039;%view%&#039; ) as BlogActivity&lt;br /&gt;
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 &lt;br /&gt;
WHERE m.name LIKE &#039;%blog%&#039; AND c.category IN ( 8,13,15)&lt;br /&gt;
GROUP BY cm.course,cm.module order by counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student&#039;s posts content in all course blogs (oublog)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
b.name &lt;br /&gt;
,op.title&lt;br /&gt;
,op.message&lt;br /&gt;
,( SELECT CONCAT(u.firstname, &#039; &#039;,u.lastname) FROM prefix_user AS u WHERE u.id = oi.userid) AS &amp;quot;Username&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_oublog_posts AS op&lt;br /&gt;
JOIN prefix_oublog_instances AS oi ON oi.id = op.oubloginstancesid &lt;br /&gt;
JOIN prefix_oublog as b ON b.id = oi.oublogid&lt;br /&gt;
JOIN prefix_course AS c ON b.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Courses which uploaded a Syllabus file===&lt;br /&gt;
+ under specific Category&lt;br /&gt;
+ show first Teacher in that course&lt;br /&gt;
+ link Course&#039;s fullname to actual course&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) as Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user as u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) as Teacher&lt;br /&gt;
FROM prefix_resource as r &lt;br /&gt;
JOIN prefix_course as c ON r.course = c.id&lt;br /&gt;
WHERE ( r.name LIKE &#039;%סילבוס%&#039; OR r.name LIKE &#039;%סילאבוס%&#039; OR r.name LIKE &#039;%syllabus%&#039; OR r.name LIKE &#039;%תכנית הקורס%&#039; ) &lt;br /&gt;
AND c.category IN (10,18,26,13,28)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
===Site-wide completed SCORM activities by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===All users enrolled in a course without a role===&lt;br /&gt;
Identifies All users that are enrolled in a course but are not assigned a role.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user.firstname AS Firstname,&lt;br /&gt;
user.lastname AS Lastname,&lt;br /&gt;
user.idnumber Employee_ID,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user as user ON user.id = ue.userid&lt;br /&gt;
&lt;br /&gt;
WHERE user.id NOT IN (&lt;br /&gt;
SELECT u.id&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE c.id=course.id&lt;br /&gt;
)&lt;br /&gt;
ORDER BY Course, Lastname, Firstname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List course resources accumulative file size and count===&lt;br /&gt;
This is the main (first) report, which has a link (alias) to a second report (the following on this page) which list each file in the course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id &amp;quot;CourseID&amp;quot;, context.id &amp;quot;ContextID&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;, c.id, &#039;&amp;quot;&amp;gt;&#039;, c.fullname ,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Course Name&amp;quot;&lt;br /&gt;
, COUNT(*) &amp;quot;Course Files&amp;quot; , ROUND( SUM( f.filesize ) /1048576 ) AS file_size_MB&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/blocks/configurable_reports/viewreport.php?alias=coursefiles&amp;amp;courseid=1&amp;amp;filter_courses=&#039;, c.id, &#039;&amp;quot;&amp;gt;List files&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List Files&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
JOIN mdl_context AS context ON context.id = f.contextid&lt;br /&gt;
JOIN mdl_course AS c ON c.id = (&lt;br /&gt;
  SELECT instanceid&lt;br /&gt;
  FROM mdl_context&lt;br /&gt;
  WHERE id = SUBSTRING_INDEX( SUBSTRING_INDEX( context.path, &#039;/&#039; , -2 ) , &#039;/&#039;, 1 ) )&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this report, you will have to define &amp;quot;alias&amp;quot; report property to &amp;quot;coursefiles&amp;quot; for it to be able to be called from the above report.&lt;br /&gt;
And also setup (add) a FILTER_COURSES filter. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id ,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/pluginfile.php/&#039;, contextid, &#039;/&#039;, component, &#039;/&#039;, filearea, &#039;/&#039;, itemid, &#039;/&#039;, filename, &#039;&amp;quot;&amp;gt;&#039;, filename,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;File&amp;quot;&lt;br /&gt;
,filesize, mimetype ,author, license, timecreated, component, filearea, filepath&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
            AND f.contextid&lt;br /&gt;
            IN (   SELECT id&lt;br /&gt;
                     FROM mdl_context&lt;br /&gt;
                    WHERE path &lt;br /&gt;
                     LIKE (   SELECT CONCAT(&#039;%/&#039;,id,&#039;/%&#039;)&lt;br /&gt;
                                  AS contextquery&lt;br /&gt;
                                FROM mdl_context&lt;br /&gt;
                               WHERE 1=1&lt;br /&gt;
			        %%FILTER_COURSES:instanceid%%&lt;br /&gt;
                                 AND contextlevel = 50&lt;br /&gt;
                           )&lt;br /&gt;
                )&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Which courses has redundant topics===&lt;br /&gt;
This report list several &amp;quot;active topics&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
The following, second SQL query, could be used to &amp;quot;trim&amp;quot; down those redundant course topics/sections/weeks by updating the course format&#039;s numsection (Number of sections) setting. (It&#039;s a per course format setting!)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, format,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT value  FROM  `mdl_course_format_options` WHERE  `courseid` = c.id AND `format` = c.format AND `name` = &#039;numsections&#039; ) AS &amp;quot;numsections&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND `sequence` !=  &#039;&#039; ) AS &amp;quot;Non empty sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id ) AS &amp;quot;Total section count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND sequence IS NOT NULL) AS &amp;quot;Non NULL sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND name != &#039;&#039;) AS &amp;quot;Non empty section Name count&amp;quot;&lt;br /&gt;
 ,(SELECT COUNT(*) FROM mdl_course_modules cm WHERE cm.course = c.id) &amp;quot;Modules count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course AS c&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following SQL REPLACE query is used for &amp;quot;fixing&amp;quot; (updating) the &amp;quot;numsections&amp;quot; of a specific course format &amp;quot;onetopics&amp;quot; (you can always change it, or discard it to use this SQL REPLACE on all course formats) &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
REPLACE INTO `mdl_course_format_options` (`id`, `courseid`, `format`, `sectionid`, `name`, `value`) &lt;br /&gt;
SELECT NULL, c.id, &#039;onetopic&#039;, &#039;0&#039;, &#039;numsections&#039;, (SELECT COUNT(*) FROM `mdl_course_sections` WHERE `course` = c.id AND name != &#039;&#039;)&lt;br /&gt;
FROM `mdl_course` c where format = &#039;onetopic&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hidden Courses with Students Enrolled===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.visible AS Visible, &lt;br /&gt;
DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors,&lt;br /&gt;
&lt;br /&gt;
(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;, &lt;br /&gt;
&lt;br /&gt;
now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
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) &amp;gt; 0&lt;br /&gt;
ORDER BY StartDate, Instructor_Email, Course_ID&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Course Design Reports==&lt;br /&gt;
&lt;br /&gt;
These are reports which summarize course design aspects, such as activity and resource modules per section, types of activities used, etc.&lt;br /&gt;
&lt;br /&gt;
===Course Content/Week===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report assumes that the first 14 sections in a course, not including the &amp;quot;0&amp;quot; or &amp;quot;Welcome&amp;quot; section, correspond to weeks (with &amp;quot;Subsections&amp;quot; given numbers much higher in the sequence). Of those sections, each is checked to count the number of:&lt;br /&gt;
&lt;br /&gt;
    Forums&lt;br /&gt;
    Graded Activities (may include Forums)&lt;br /&gt;
    Resources (not including a Label)&lt;br /&gt;
&lt;br /&gt;
Totals of each of these types of content elements per section are provided.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Only visible resources and activities are counted.&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: this is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
 &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT LIKE &#039;label&#039;),cm.id,NULL)) AS &#039;Ungraded Resources&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Graded Activities&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cs.section&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments and Weights===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Categories with weights of 0 are not included in this report.&lt;br /&gt;
&lt;br /&gt;
Only visible activities are included in this report.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This is designed to be a &amp;quot;Global&amp;quot; report in Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;) AS &#039;Grade Book Category&#039;&lt;br /&gt;
, IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND(SUM(DISTINCT gi.aggregationcoef), 2)+ROUND(SUM(DISTINCT mgi.aggregationcoef), 2)) AS &#039;Category weight&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT_WS(&#039;, &#039;,GROUP_CONCAT(DISTINCT gi.itemmodule SEPARATOR &#039;, &#039;), IF(mgi.id, &#039;manual&#039;,NULL)) AS &#039;Activity Types&#039;&lt;br /&gt;
, COUNT(DISTINCT gi.itemmodule) + IF(mgi.id,1,0) AS &#039;Different Activity Types&#039;&lt;br /&gt;
, CONCAT_WS(&#039;&amp;lt;br&amp;gt;&#039;, GROUP_CONCAT(DISTINCT gi.itemname ORDER BY gi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;), GROUP_CONCAT(DISTINCT mgi.itemname ORDER BY mgi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;)) AS &#039;Activity Names&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) + COUNT(DISTINCT mgi.id) AS &#039;Activity Count&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
&lt;br /&gt;
#get grade categories&lt;br /&gt;
LEFT JOIN prefix_grade_categories AS gc ON gc.courseid = c.id &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
JOIN prefix_grade_items AS gic ON gic.courseid = c.id AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
&lt;br /&gt;
# attach activities to course&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = c.id &lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.iteminstance = cm.instance AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.id&lt;br /&gt;
ORDER BY gc.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pre-Term Course Review===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
#   &amp;quot;Required blocks&amp;quot; include Instructor Block (mooprofile), Activities, and the Research block.&lt;br /&gt;
#    &amp;quot;Instructor Details&amp;quot; block is not the &amp;quot;Instructor&amp;quot; block (mooprofile) automatically provided by the system. It is an optional block that can be edited by the instructor. If not edited to remove boilerplate text, it should be hidden.&lt;br /&gt;
#    All courses should be in the &amp;quot;Collapsed Topics&amp;quot; format with the &amp;quot;Weeks&amp;quot; structure.&lt;br /&gt;
#    &amp;quot;Weeks defined in course settings&amp;quot; is taken from our SIS when the course shells are created, but can be edited by faculty. &amp;quot;# of weeks named and visible&amp;quot; should usually match or exceed this value.&lt;br /&gt;
#    We recommend that each week contain at least one forum, at least one graded activity, and at least one ungraded resource.&lt;br /&gt;
#    &amp;quot;Syllabus updated&amp;quot; date is for the first attached file found with the text &amp;quot;syllabus&amp;quot; in the name. The &amp;quot;Days ago&amp;quot; calculation is included for convenience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: At our institution, we construct categories each term, and insert a text string &amp;quot;staging&amp;quot; in the Category ID for pre-term courses during the preparation or &amp;quot;staging&amp;quot; phase of course development. We remove this text string (and change it to &amp;quot;production&amp;quot;) when courses go live at the start of the new term.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
#,RIGHT(c.idnumber,2) AS Type # Specific to GSC &amp;quot;Instructional Method&amp;quot; storage&lt;br /&gt;
&lt;br /&gt;
#, substring_index(substr(c.shortname FROM locate(&#039;.&#039;,c.shortname)+1),&#039;-&#039;,1) AS Section # Specific to GSC&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.lastname,&#039;, &#039;, u.firstname,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
,(SELECT IF((u2.description IS NULL) OR (u2.description LIKE &#039;&#039;),&#039;NO&#039;, &#039;YES&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT IF(u3.picture &amp;gt; 0,&#039;YES&#039;,&#039;NO&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u3 ON u3.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Picture&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(((bpi.visible IS NULL) OR (bpi.visible !=0)) AND ((bpm.visible IS NULL) OR (bpm.visible !=0)) AND ((bpa.visible IS NULL) OR (bpa.visible !=0)) AND ((bpr.visible IS NULL) OR (bpr.visible !=0)),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Required blocks visible&#039;&lt;br /&gt;
#, IF((bpm.visible IS NULL) OR (bpm.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Messages block visible&#039;&lt;br /&gt;
#, IF((bpa.visible IS NULL) OR (bpa.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;activities block visible&#039;&lt;br /&gt;
#, IF((bpr.visible IS NULL) OR (bpr.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;research block visible&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)) AND (bip.visible !=0),&#039;YES&#039;,&#039;&#039;) AS &#039;Instructor Details Block visible&#039; # This is a hack based on UUencoded string data from the title of HTML &amp;quot;Instructor Details&amp;quot; block&lt;br /&gt;
&lt;br /&gt;
#, IF(bi.configdata LIKE &#039;%ZGl0IHRoaXMgYmxvY2s%&#039;,&#039;NO&#039;,&#039;&#039;) AS &#039;Instructor Details Block Updated&#039; # HTML block has string &#039;dit this block&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(COUNT(bi.id) -  SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)),&#039;YES&#039;,&#039;&#039;) AS &#039;possible extra instructor blocks&#039; #looking for any HTML block with &amp;quot;instructor&amp;quot; in the title&lt;br /&gt;
&lt;br /&gt;
, IF(c.format=&#039;topcoll&#039;,&#039;YES&#039;, c.format) AS &#039;Collapsed Topics course format&#039; # change this if you want to test for a different format&lt;br /&gt;
, IF(cfo.value = 2, &#039;YES&#039;,&#039;NO&#039;) AS &#039;weeks structure&#039;&lt;br /&gt;
&lt;br /&gt;
, cfw.value AS &#039;weeks defined in course settings&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(((cs.name IS NOT NULL) AND (cs.visible = 1) AND (cs.section != &#039;0&#039;) AND (cs.sequence IS NOT NULL)),cs.id,NULL)) AS &#039;# of weeks named &amp;amp; visible (includes orphans)&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039; ,cs.id , NULL)) AS &#039;Weeks with Forum&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cs.id, NULL)) AS &#039;Weeks with Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT mgi.id) AS &#039;Manual Grade Items&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)),cm.id,NULL)) AS &#039;Resources&#039;&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)), cs.id, NULL)) AS &#039;Weeks with Resources&#039;&lt;br /&gt;
&lt;br /&gt;
# Here are some other things you could check for per course&lt;br /&gt;
#,(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 &#039;%forum%&#039;) AS Forums&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%quiz%&#039;) AS Quizzes&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%assign%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_resource.id) FROM prefix_resource JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course) AS Files&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_url.id) FROM prefix_url JOIN prefix_course ON prefix_course.id = prefix_url.course WHERE c.id = prefix_url.course) AS Links&lt;br /&gt;
&lt;br /&gt;
,(SELECT FROM_UNIXTIME(MAX(prefix_resource.timemodified))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS SyllabusDate&lt;br /&gt;
&lt;br /&gt;
,(SELECT TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(MAX(prefix_resource.timemodified)))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS DaysAgo&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, f.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement Forum Visible&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, fd.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement posted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
LEFT JOIN prefix_context AS ctxx ON c.id = ctxx.instanceid &lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpi ON bpi.contextid = ctxx.id AND bpi.blockinstanceid = &#039;43692&#039; # mooprofile&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpm ON bpm.contextid = ctxx.id AND bpm.blockinstanceid = &#039;43962&#039; # messages&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpa ON bpa.contextid = ctxx.id AND bpa.blockinstanceid = &#039;43963&#039; # activities&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpr ON bpr.contextid = ctxx.id AND bpr.blockinstanceid = &#039;38368&#039; # html research help&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.visible = 1 AND cs.sequence IS NOT NULL&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
LEFT JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_forum AS f ON f.course = c.id AND cm.instance = f.id AND cm.visible = 1&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.forum = f.id&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfo ON cfo.courseid = c.id AND cfo.name = &#039;layoutstructure&#039;&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfw ON cfw.courseid = c.id AND cfw.name = &#039;numsections&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_instances AS bi ON bi.parentcontextid = ctxx.id AND bi.blockname = &#039;html&#039; AND (bi.configdata LIKE &#039;%SW5zdHJ1Y3Rvc%&#039; or bi.configdata LIKE &#039;%bnN0cnVjdG9y%&#039;)&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bip ON bip.blockinstanceid = bi.id&lt;br /&gt;
&lt;br /&gt;
WHERE RIGHT(c.idnumber,2) IN (&#039;OL&#039;, &#039;BL&#039;, &#039;HY&#039;) &lt;br /&gt;
# AND substring(cc.path,2,2) IN (&#039;26&#039;) # Staging&lt;br /&gt;
#AND substring(cc.path,2,3) IN (&#039;158&#039;) # UG&lt;br /&gt;
AND cc.idnumber LIKE &#039;%staging%&#039;&lt;br /&gt;
AND ctxx.contextlevel = 50&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module instances + Module HITs by role teacher and student in course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
m.name AS &amp;quot;Module name&amp;quot;&lt;br /&gt;
, COUNT(*) AS &amp;quot;Module count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name ) AS &amp;quot;Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course_modules AS cm&lt;br /&gt;
JOIN mdl_modules AS m on m.id = cm.module&lt;br /&gt;
WHERE cm.course = &#039;%%COURSEID%%&#039;&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Syllabus===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Course Policies&amp;quot; and &amp;quot;Teaching Philosophy&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.fullname AS &#039;fullname&#039;&lt;br /&gt;
, ec.idnumber AS &#039;elis-id&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.startdate), &#039;%b %e, %Y&#039;) AS &#039;start&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.enddate), &#039;%b %e, %Y&#039;) AS &#039;end&#039;&lt;br /&gt;
, ecd.name AS &#039;longname&#039;&lt;br /&gt;
, ecd.code AS &#039;coursecode&#039;&lt;br /&gt;
, ecd.credits AS &#039;coursecredits&#039;&lt;br /&gt;
, ecd.syllabus AS &#039;description&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;learning-outcomes&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;outcomes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.firstname,&#039; &#039;, u.lastname,&#039;&amp;lt;/a&amp;gt; &#039;, u.email)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
, (SELECT  efc.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_char AS efc&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = efc.fieldid AND ef.shortname = &#039;term-code&#039;&lt;br /&gt;
WHERE ctxci.id = efc.contextid) AS &#039;termcode&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;prerequisites&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;prerequisites&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;textbooks&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;textbooks&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;other-class-materials&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;other-class-materials&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-policies&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-policies&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;teaching-philosophy&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;teaching-philosophy&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-methods&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-methods&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT u2.description&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT&lt;br /&gt;
&lt;br /&gt;
GROUP_CONCAT(DISTINCT CONCAT(&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;tr&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt;&#039;,IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;)&lt;br /&gt;
, &#039; &amp;lt;/td&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt; &#039;&lt;br /&gt;
,IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND( gi.aggregationcoef, 2)+ROUND(mgi.aggregationcoef, 2))&lt;br /&gt;
&lt;br /&gt;
) SEPARATOR &#039;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&#039;)&lt;br /&gt;
#get grade categories&lt;br /&gt;
FROM prefix_grade_categories AS gc &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gic ON gic.courseid = gc.courseid AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = gc.courseid  AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = gc.courseid and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
WHERE gc.courseid = c.id  ) AS &#039;grade categories&#039;&lt;br /&gt;
&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;50%&amp;quot; &amp;gt;&#039; AS &#039;table start&#039;&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;100%&amp;quot; &amp;gt;&#039; AS &#039;table start 2&#039;&lt;br /&gt;
, &#039;&amp;lt;/table&amp;gt;&#039; AS &#039;table end&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;activities-schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;schedule&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;grading-scale&#039;&lt;br /&gt;
WHERE ctxepm.id = eft.contextid) AS &#039;gradescale&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
# connect moodle course to ELIS class instance&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls_mdl AS ecm ON ecm.moodlecourseid = c.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls AS ec ON ec.id = ecm.classid&lt;br /&gt;
# class instance context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxci ON ctxci.instanceid = ec.id AND ctxci.contextlevel = &#039;14&#039;&lt;br /&gt;
&lt;br /&gt;
# connect ELIS class instance to ELIS course description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_crs AS ecd ON ecd.id = ec.courseid&lt;br /&gt;
# course description context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxecd ON ctxecd.instanceid = ecd.id AND ctxecd.contextlevel = &#039;13&#039;&lt;br /&gt;
&lt;br /&gt;
#connect ELIS program to ELIS Course Description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm_crs AS epc ON epc.courseid = ecd.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm AS epm ON epm.id = epc.curriculumid&lt;br /&gt;
# course program context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxepm ON ctxepm.instanceid = epm.id AND ctxepm.contextlevel = &#039;11&#039;&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Activities Helper===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report provides a list of the graded activities in a course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: Only graded activities are displayed.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This report assumes that course sections each last one week.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
# 303 Course Activities Helper&lt;br /&gt;
&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
gi.itemmodule AS &#039;activity type&#039;&lt;br /&gt;
# cs.section AS &#039;section number&#039;&lt;br /&gt;
&lt;br /&gt;
# Calculation assumes each section lasts one week&lt;br /&gt;
, CONCAT(DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section-1))), &#039;%b %e, %Y&#039;),&#039; - &amp;lt;br&amp;gt;&#039;,DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section))), &#039;%b %e, %Y&#039;)) AS &#039;Date&#039;&lt;br /&gt;
&lt;br /&gt;
, gi.itemname AS &#039;activity name&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = cm.instance) AS &#039;intro&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT f.intro FROM prefix_forum AS f WHERE f.id = cm.instance) AS &#039;f intro&#039;&lt;br /&gt;
&lt;br /&gt;
, CASE gi.itemmodule &lt;br /&gt;
WHEN &#039;assign&#039; THEN (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;forum&#039; THEN (SELECT f.intro FROM prefix_forum AS f WHERE f.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;quiz&#039; THEN (SELECT q.intro FROM prefix_quiz AS q WHERE q.id = gi.iteminstance) &lt;br /&gt;
END AS &#039;test case&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT GROUP_CONCAT(CONCAT(&#039; - &#039;,gi.itemname) SEPARATOR &#039;&amp;lt;BR&amp;gt;&#039;) FROM  prefix_grade_items AS gi  JOIN prefix_course_modules AS cm ON  gi.iteminstance = cm.instance WHERE gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id ) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
#get grade sections&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id  AND cs.section &amp;gt; 0 AND cs.section &amp;lt;=14&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_assign AS asg ON asg.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_grade_items AS gi  ON  gi.iteminstance = cm.instance AND gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
&lt;br /&gt;
ORDER BY gi.itemmodule, cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Grade and Course Completion Reports==&lt;br /&gt;
===Site-Wide Grade Report with All Items===&lt;br /&gt;
Shows grades for all course items along with course totals for each student. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, &lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
For MySQL users, you&#039;ll need to use the MySQL DATE_ADD function instead of DATEADD. Replace the line:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
And:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
CONCAT(u.firstname,&#039; &#039;,u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site-Wide Grade Report with Just Course Totals===&lt;br /&gt;
A second site-wide grade report for all students that just shows course totals. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id AND gi.itemtype = &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For MySQL users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN CONCAT(c.fullname, &#039; - Total&#039;)&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS TIME&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
 &lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Learner report by Learner with grades===&lt;br /&gt;
Which Learners in which course and what are the grades&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;Name&#039; , u.lastname AS &#039;Surname&#039;, c.fullname AS &#039;Course&#039;, cc.name AS &#039;Category&#039;, &lt;br /&gt;
CASE WHEN gi.itemtype = &#039;Course&#039;    &lt;br /&gt;
THEN c.fullname + &#039; Course Total&#039;  &lt;br /&gt;
ELSE gi.itemname &lt;br /&gt;
END AS &#039;Item Name&#039;, ROUND(gg.finalgrade,2) AS Score,ROUND(gg.rawgrademax,2) AS Max, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) as Percentage,&lt;br /&gt;
&lt;br /&gt;
if (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) &amp;gt; 79,&#039;Yes&#039; , &#039;No&#039;) as Pass&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id &lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid &lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category &lt;br /&gt;
WHERE  gi.courseid = c.id and gi.itemname != &#039;Attendance&#039;&lt;br /&gt;
ORDER BY `Name` ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A very simple report with a list of course completion status by username. Completions are noted by date, blank otherwise. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  u.username, &lt;br /&gt;
  c.shortname,  &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%Y-%m-%d&#039;) AS completed&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion with Criteria===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A report with course completions by username, with Aggregation method, Criteria types, and Criteria detail where available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username AS user, &lt;br /&gt;
c.shortname AS course,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(t.timecompleted),&#039;%Y-%m-%d&#039;) AS completed,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = c.id AND a.criteriatype IS NULL) = 1) THEN &amp;quot;Any&amp;quot;&lt;br /&gt;
ELSE &amp;quot;All&amp;quot;&lt;br /&gt;
END AS aggregation,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;Self&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN &amp;quot;By Date&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 3 THEN &amp;quot;Unenrol Status&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &amp;quot;Activity&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 5 THEN &amp;quot;Duration&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 6 THEN &amp;quot;Course Grade&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 7 THEN &amp;quot;Approve by Role&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 8 THEN &amp;quot;Previous Course&amp;quot;&lt;br /&gt;
END AS criteriatype,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;*&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(p.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN p.criteriatype = 3 THEN t.unenroled&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,p.module,&#039;/view.php?id=&#039;,p.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,p.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN p.criteriatype = 5 THEN p.enrolperiod&lt;br /&gt;
WHEN p.criteriatype = 6 THEN CONCAT(&#039;Needed: &#039;,ROUND(p.gradepass,2),&#039; Achieved: &#039;,ROUND(t.gradefinal,2)) &lt;br /&gt;
WHEN p.criteriatype = 7 THEN p.role&lt;br /&gt;
WHEN p.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = p.courseinstance)&lt;br /&gt;
END AS criteriadetail &lt;br /&gt;
FROM prefix_course_completion_crit_compl AS t&lt;br /&gt;
JOIN prefix_user AS u ON t.userid = u.id&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
JOIN prefix_course_completion_criteria AS p ON t.criteriaid = p.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Completion Enabled and their settings===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with completion enabled and their Aggregation setting, Criteria types, and Criteria details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT c.shortname AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = t.course AND a.criteriatype IS NULL)) = 2 THEN &amp;quot;All&amp;quot;&lt;br /&gt;
ELSE &amp;quot;Any&amp;quot;&lt;br /&gt;
END AS Course_Aggregation,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;Self completion&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN &amp;quot;Date done by&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;Unenrolement&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 4 THEN &amp;quot;Activity completion&amp;quot;   &lt;br /&gt;
WHEN t.criteriatype = 5 THEN &amp;quot;Duration in days&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 6 THEN &amp;quot;Final grade&amp;quot;     &lt;br /&gt;
WHEN t.criteriatype = 7 THEN &amp;quot;Approve by role&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 8 THEN &amp;quot;Previous course&amp;quot;&lt;br /&gt;
END AS Criteria_type,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(t.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 4 THEN&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,t.module,&#039;/view.php?id=&#039;,t.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,t.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN t.criteriatype = 5 THEN ROUND(t.enrolperiod/86400)&lt;br /&gt;
WHEN t.criteriatype = 6 THEN ROUND(t.gradepass,2)&lt;br /&gt;
WHEN t.criteriatype = 7 THEN (SELECT r.shortname FROM prefix_role AS r WHERE r.id = t.role)&lt;br /&gt;
WHEN t.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = t.courseinstance)&lt;br /&gt;
END AS Criteria_detail&lt;br /&gt;
FROM prefix_course_completion_criteria as t&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Completion Report with custom dates===&lt;br /&gt;
&lt;br /&gt;
List of users who completed multiple or single course/s from a start date to end date chosen by the user. The output gives username, name, course name, completion date and score&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT u.username AS &#039;User Name&#039;,&lt;br /&gt;
CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Name&#039;,&lt;br /&gt;
c.shortname AS &#039;Course Name&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%W %e %M, %Y&#039;) AS &#039;Completed Date&#039;,&lt;br /&gt;
ROUND(c4.gradefinal,2) AS &#039;Score&#039;&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
JOIN prefix_course_completion_crit_compl AS c4 ON u.id = c4.userid&lt;br /&gt;
WHERE c.enablecompletion = 1  AND (p.timecompleted IS NOT NULL OR p.timecompleted !=&#039;&#039;) &lt;br /&gt;
AND (p.timecompleted&amp;gt;= :start_date AND p.timecompleted&amp;lt;=:end_date)&lt;br /&gt;
GROUP BY u.username&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scales used in activities===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT scale.name&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,gi.itemmodule,&#039;/view.php?id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module View&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/modedit.php?up&#039;,&#039;date=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module Settings&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON c.id = gi.courseid&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = gi.courseid AND cm.instance = gi.iteminstance&lt;br /&gt;
JOIN prefix_scale AS scale ON scale.id = gi.scaleid&lt;br /&gt;
WHERE gi.scaleid IS NOT NULL&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Extra Credit Items by Name Only===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
This query identifies grade items in visible courses with student enrollment that have &amp;quot;extra credit&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, gi.itemname AS Item_Name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors&lt;br /&gt;
&lt;br /&gt;
,(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;&lt;br /&gt;
&lt;br /&gt;
,now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON gi.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE gi.itemname LIKE &#039;%extra credit%&#039; &lt;br /&gt;
	AND gi.gradetype = &#039;1&#039; &lt;br /&gt;
	AND gi.hidden = &#039;0&#039; &lt;br /&gt;
	AND gi.aggregationcoef = &#039;0&#039; &lt;br /&gt;
	AND c.visible = 1&lt;br /&gt;
	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) &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
GROUP BY Course_ID, gi.id&lt;br /&gt;
ORDER BY StartDate, Course_ID&lt;br /&gt;
 &lt;br /&gt;
%%FILTER_SEARCHTEXT:Course_ID:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site Wide Number of Courses Completed by User===&lt;br /&gt;
Contributed by Ken St. John&lt;br /&gt;
&lt;br /&gt;
Simple report that shows the number of completed courses for all users site wide&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname, u.firstname,&lt;br /&gt;
COUNT(p.timecompleted) AS TotalCompletions&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
GROUP BY p.userid&lt;br /&gt;
ORDER BY u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Activity Module Reports==&lt;br /&gt;
&lt;br /&gt;
=== User activity completions with dates===&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.username As &#039;User&#039;,&lt;br /&gt;
c.shortname AS &#039;Course&#039;,&lt;br /&gt;
m.name AS Activitytype, &lt;br /&gt;
CASE &lt;br /&gt;
    WHEN cm.module = 1 THEN (SELECT a1.name FROM prefix_assign a1            WHERE a1.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 2 THEN (SELECT a2.name FROM prefix_assignment a2    WHERE a2.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 3 THEN (SELECT a3.name FROM prefix_book a3               WHERE a3.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 4 THEN (SELECT a4.name FROM prefix_chat a4                WHERE a4.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 5 THEN (SELECT a5.name FROM prefix_choice a5            WHERE a5.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 6 THEN (SELECT a6.name FROM prefix_data a6                WHERE a6.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 7 THEN (SELECT a7.name FROM prefix_feedback a7        WHERE a7.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 8 THEN (SELECT a8.name FROM prefix_folder a8              WHERE a8.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 9 THEN (SELECT a9.name FROM prefix_forum a9              WHERE a9.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 10 THEN (SELECT a10.name FROM prefix_glossary a10         WHERE a10.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 11 THEN (SELECT a11.name FROM prefix_imscp  a11           WHERE a11.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 12 THEN (SELECT a12.name FROM prefix_label a12              WHERE a12.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 13 THEN (SELECT a13.name FROM prefix_lesson a13            WHERE a13.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 14 THEN (SELECT a14.name FROM prefix_lti a14                    WHERE a14.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 15 THEN (SELECT a15.name FROM prefix_page a15               WHERE a15.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 16 THEN (SELECT a16.name FROM prefix_quiz  a16               WHERE a16.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 17 THEN (SELECT a17.name FROM prefix_resource a17         WHERE a17.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 18 THEN (SELECT a18.name FROM prefix_scorm a18             WHERE a18.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 19 THEN (SELECT a19.name FROM prefix_survey a19             WHERE a19.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 20 THEN (SELECT a20.name FROM prefix_url a20                      WHERE a20.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 21 THEN (SELECT a21.name FROM prefix_wiki a21                    WHERE a21.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 22 THEN (SELECT a22.name FROM prefix_workshop a22           WHERE a22.id = cm.instance)&lt;br /&gt;
END AS Actvityname,&lt;br /&gt;
# cm.section AS Coursesection,&lt;br /&gt;
CASE&lt;br /&gt;
    WHEN cm.completion = 0 THEN &#039;0 None&#039;&lt;br /&gt;
    WHEN cm.completion = 1 THEN &#039;1 Self&#039;&lt;br /&gt;
    WHEN cm.completion = 2 THEN &#039;2 Auto&#039;&lt;br /&gt;
END AS Activtycompletiontype, &lt;br /&gt;
CASE&lt;br /&gt;
   WHEN cmc.completionstate = 0 THEN &#039;In Progress&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 1 THEN &#039;Completed&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 2 THEN &#039;Completed with Pass&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 3 THEN &#039;Completed with Fail&#039;&lt;br /&gt;
   ELSE &#039;Unknown&#039;&lt;br /&gt;
END AS &#039;Progress&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(cmc.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;&lt;br /&gt;
FROM prefix_course_modules_completion cmc &lt;br /&gt;
JOIN prefix_user u ON cmc.userid = u.id&lt;br /&gt;
JOIN prefix_course_modules cm ON cmc.coursemoduleid = cm.id&lt;br /&gt;
JOIN prefix_course c ON cm.course = c.id&lt;br /&gt;
JOIN prefix_modules m ON cm.module = m.id&lt;br /&gt;
# skip the predefined admin and guest user&lt;br /&gt;
WHERE u.id &amp;gt; 2&lt;br /&gt;
# config reports filters&lt;br /&gt;
%%FILTER_USERS:u.username%%&lt;br /&gt;
%%FILTER_SEARCHTEXT:m.name:~%%&lt;br /&gt;
%%FILTER_STARTTIME:cmc.timemodified:&amp;gt;%% %%FILTER_ENDTIME:cmc.timemodified:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many SCORM activities are used in each Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cm.course,c.fullname ,m.name &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/scorm/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,count(cm.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS Counter&lt;br /&gt;
 &lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
  JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
  JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%scorm%&#039; &lt;br /&gt;
GROUP BY cm.course,cm.module &lt;br /&gt;
ORDER BY count(cm.id) desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===SCORM Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of SCORM activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, scm.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;SCO%&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_scorm AS scm ON scm.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LTI (External Tool) Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of  LTI (External Tool) Usage activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, lti.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;lti&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_lti AS lti ON lti.id = cm.instance&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each MODULE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module,action,count(id) as counter&lt;br /&gt;
FROM prefix_log&lt;br /&gt;
GROUP BY module,action&lt;br /&gt;
ORDER BY module,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Most popular ACTIVITY===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, module&lt;br /&gt;
FROM prefix_log l&lt;br /&gt;
WHERE module != &#039;login&#039; AND module != &#039;course&#039; AND module != &#039;role&#039;&lt;br /&gt;
GROUP BY module&lt;br /&gt;
ORDER BY hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide use of ACTIVITIES and RESOURCES===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count( cm.id ) AS counter, m.name&lt;br /&gt;
FROM `prefix_course_modules` AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
ORDER BY counter DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LOG file ACTIONS per MODULE per COURSE (IDs)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select course,module,action,count(action) as summa from prefix_log&lt;br /&gt;
where action &amp;lt;&amp;gt; &#039;new&#039;&lt;br /&gt;
group by course,action,module&lt;br /&gt;
order by course,module,action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System Wide usage count of various course Activities===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
Like: Forum, Wiki, Blog, Assignment, Database,&lt;br /&gt;
#Within specific category&lt;br /&gt;
#Teacher name in course&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS Forums&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%data%&#039;) AS Databses&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%assignment%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 18)&lt;br /&gt;
ORDER BY Wikis DESC,Blogs DESC, Forums DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course wiki usage/activity over the last 6 semesters===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &amp;quot;Courses with Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester A%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester A&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester B%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester B&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed WIKI activity (per wiki per course)===&lt;br /&gt;
Including Number of Students in course (for reference)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID  &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id ) AS Students&lt;br /&gt;
,m.name&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%updat%&#039; ) as &#039;UPDAT E&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%annotate%&#039; ) as ANNOTATE&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%comment%&#039; ) as COMMENT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%add%&#039; ) as &#039;A DD&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%edit%&#039; ) as EDIT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action NOT LIKE &#039;%view%&#039; ) as &#039;All (NO View)&#039;&lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
GROUP BY cm.course,cm.module&lt;br /&gt;
ORDER BY &#039;All (NO View)&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wiki usage, system wide===&lt;br /&gt;
(you can filter the output by selecting some specific course categories : &amp;quot;WHERE c.category IN ( 8,13,15)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039;) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%add%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ADD&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%edit%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;EDIT&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%annotate%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ANNOTATE&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%comments%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;Comments&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_ouwiki_pages as ouwp&lt;br /&gt;
JOIN prefix_ouwiki as ouw ON ouw.id = ouwp.subwikiid&lt;br /&gt;
WHERE ouw.course = c.id GROUP BY ouw.course  ) as OUWikiPages&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( DISTINCT nwp.pagename ) FROM prefix_wiki_pages AS nwp&lt;br /&gt;
JOIN prefix_wiki AS nw ON nw.id = nwp.dfwiki WHERE nw.course = c.id ) As NWikiPages&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Wikis &amp;gt; 0&lt;br /&gt;
ORDER BY &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Aggregated Teacher activity by &amp;quot;WEB2&amp;quot; Modules===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
The NV column shows activity without VIEW log activity&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.userid, u.firstname,u.lastname&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039;) AS Wiki&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Wiki_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039;) AS Forum&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Forum_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039;) AS Blog&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Blog_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039;) AS Assignment&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Assignment_NV&lt;br /&gt;
FROM prefix_role_assignments AS ra &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
WHERE ra.roleid = 3 &lt;br /&gt;
GROUP BY ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the certificates issued, sort by variables in the custom profile fields===&lt;br /&gt;
Note: The SQL queries look intimidating at first, but isn&#039;t really that difficult to learn. I&#039;ve seen in the forums that users wanted to do &#039;site-wide&#039; groups in 1.9x. This is sort of the idea. It pulls all the certificates issued to all users sorted by the custom profile fields, which in my case is the Units or Depts (i.e. my site wide groups). Why certificates? I&#039;ve explored with both grades and quizzes, the course admins are not really interested in the actual grades but whether the learner received a certificate (i.e. passed the course with x, y, z activities). It also saves me from creating groups and assigning them into the right groups. Even assigning in bulk is not efficient, since I have upward of 25 groups per course and constantly new learners enrolling in courses. The limitation is something to do with the server? as it only pull 5000 rows of data. If anyone figured out how to change this, please let me know. In the meantime, the work around is to pull only a few units/depts at a time to limit the number of rows. This is fine at the moment, since each course admin are only responsible for certain units/depts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(prefix_certificate_issues.timecreated), &#039;%Y-%m-%d&#039; ) AS Date,&lt;br /&gt;
prefix_certificate_issues.classname AS Topic,&lt;br /&gt;
prefix_certificate.name AS Certificate,&lt;br /&gt;
prefix_certificate_issues.studentname as Name,&lt;br /&gt;
prefix_user_info_data.data AS Units&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_certificate_issues&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_user_info_data&lt;br /&gt;
on prefix_certificate_issues.userid = prefix_user_info_data.userid&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_certificate&lt;br /&gt;
on prefix_certificate_issues.certificateid = prefix_certificate.id&lt;br /&gt;
&lt;br /&gt;
WHERE prefix_user_info_data.data=&#039;Unit 1&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 2&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 3&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY Units, Name, Topic ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== All Simple Certificates Earned in the Site===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 [http://www.mysqltutorial.org/mysql-date_format/ DATE_FORMAT] function.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
CONCAT (u.firstname, &#039; &#039;,u.lastname) As &#039;User&#039;,&lt;br /&gt;
c.fullname AS &#039;Course&#039;,&lt;br /&gt;
sc.name AS &#039;Certificate&#039;,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(sci.timecreated), &#039;%Y-%m-%d&#039; ) As &#039;Date Awarded&#039;&lt;br /&gt;
# sci.code &#039;CertificateId&#039;&lt;br /&gt;
FROM prefix_simplecertificate_issues sci&lt;br /&gt;
JOIN prefix_user u ON sci.userid = u.id&lt;br /&gt;
JOIN prefix_simplecertificate sc ON sci.certificateid = sc.id&lt;br /&gt;
JOIN prefix_course AS c ON sc.course = c.id&lt;br /&gt;
ORDER BY sci.timecreated DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE DATEDIFF(NOW(),FROM_UNIXTIME(sci.timecreated) ) &amp;lt; 30&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Counter Blog usage in Courses,system wide===&lt;br /&gt;
What teachers in what courses, uses blogs and how many + student count in that course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT ( @counter := @counter+1) as counter, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c, (SELECT @counter := 0) as s_init&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Blogs &amp;gt; 0&lt;br /&gt;
ORDER BY Blogs DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Elluminate (Blackboard Collaborate) - system wide usage===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT e.name As Session ,er.recordingsize&lt;br /&gt;
,c.fullname As Course&lt;br /&gt;
,u.firstname,u.lastname &lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(e.timestart),&#039;%d-%m-%Y&#039;) AS dTimeStart&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/moodle/mod/elluminate/loadrecording.php?id=&#039;,er.id,&#039;&amp;quot;&amp;gt;Show&amp;lt;/a&amp;gt;&#039;) AS RecordedSession&lt;br /&gt;
&lt;br /&gt;
FROM prefix_elluminate_recordings AS er&lt;br /&gt;
JOIN prefix_elluminate AS e ON e.meetingid = er.meetingid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = e.creator &lt;br /&gt;
ORDER BY er.recordingsize DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choice ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Results of the Choice activity. For all courses, shows course shortname, username, the Choice text, and the answer chosen by the user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname AS course, u.username, h.name as question, o.text AS answer&lt;br /&gt;
FROM prefix_choice AS h&lt;br /&gt;
JOIN prefix_course AS c ON h.course = c.id&lt;br /&gt;
JOIN prefix_choice_answers AS a ON h.id = a.choiceid&lt;br /&gt;
JOIN prefix_user AS u ON a.userid = u.id&lt;br /&gt;
JOIN prefix_choice_options AS o ON a.optionid = o.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment type usage in courses ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assign/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_assign WHERE c.id = course) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;file&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
#GROUP BY apc.plugin&lt;br /&gt;
) AS &amp;quot;File Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;onlinetext&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Online Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;pdf&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;PDF Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;offline&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Offline Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;comments&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Assignments Comments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_assign AS assign&lt;br /&gt;
JOIN prefix_course AS c ON c.id = assign.course&lt;br /&gt;
GROUP BY c.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Assignment Module Reports==&lt;br /&gt;
===All Ungraded Assignments===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
Returns all the submitted assignments that still need grading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id&lt;br /&gt;
and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Ungraded Assignments w/ Link===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;a href=&amp;quot;http://education.varonis.com/mod/assignment/submissions.php&#039; + char(63) +&lt;br /&gt;
+ &#039;id=&#039; + cast(cm.id as varchar) + &#039;&amp;amp;userid=&#039; + cast(u.id as varchar) &lt;br /&gt;
+ &#039;&amp;amp;mode=single&amp;amp;filter=0&amp;amp;offset=2&amp;quot;&amp;gt;&#039; + a.name + &#039;&amp;lt;/a&amp;gt;&#039;&lt;br /&gt;
AS &amp;quot;Assignmentlink&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments (and Quizzes) waiting to be graded===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This report requires a YEAR filter to be added (Available when using the latest block/configurable_reports)&lt;br /&gt;
&lt;br /&gt;
Which you can always remove, to make this query work on earlier versions.&lt;br /&gt;
&lt;br /&gt;
The report includes: &lt;br /&gt;
*number of quizzes&lt;br /&gt;
*unFinished Quiz attempts&lt;br /&gt;
*Finished Quiz attempts&lt;br /&gt;
*number of students&lt;br /&gt;
*number of Assignments&lt;br /&gt;
*number of submitted answers by students &lt;br /&gt;
*number of unchecked assignments (waiting for the Teacher) in a Course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
 &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assignment/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;מטלות&amp;lt;/a&amp;gt;&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;בחנים&amp;lt;/a&amp;gt;&#039;) AS &#039;Quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_course_modules cm &lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module &lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039; AND cm.course = c.id &lt;br /&gt;
GROUP BY cm.course &lt;br /&gt;
) AS &#039;nQuizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish = 0&lt;br /&gt;
GROUP BY q.course) AS &#039;unFinished Quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish &amp;gt; 0&lt;br /&gt;
GROUP BY q.course) AS &#039;finished quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS nStudents&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(a.id)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) nAssignments&lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE a.course = c.id AND FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course&lt;br /&gt;
) &#039;Open &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(ROUND( (100 / iAssignments ) * iOpenAssignments ) ,&#039;%&#039;) &#039;unFinished &amp;lt;br/&amp;gt;Assignments &amp;lt;br/&amp;gt;(percent)&#039;&lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE asb.grade &amp;lt; 0 AND cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;unChecked  &amp;lt;br/&amp;gt;Submissions&#039; &lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;Submitted  &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblAssignmentsCount ON tblAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iOpenAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblOpenAssignmentsCount ON tblOpenAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1  &lt;br /&gt;
#AND c.fullname LIKE &#039;%תשעג%&#039;&lt;br /&gt;
%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
ORDER BY &#039;Open &amp;lt;br/&amp;gt;Assignments&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rubrics without zero values in criteria===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
Rubric calculations in Moodle can fail to align with instructors expectations if they lack a zero value for each criterion used in the assessment. From documentation at https://docs.moodle.org/32/en/Rubrics#Grade_calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;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.&lt;br /&gt;
TIP: To avoid confusion from this sort of thing, we recommend including a level with 0 points in every rubric criterion.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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&#039; favor.&lt;br /&gt;
&lt;br /&gt;
Includes search filter of course idnumber.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cat.name AS Department, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, &lt;br /&gt;
c.fullname AS Course_Name, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/grading/form/rubric/edit.php&#039;,CHAR(63),&#039;areaid=&#039;,gd.areaid,&#039;&amp;quot;&amp;gt;&#039;,gd.areaid,&#039;&amp;lt;/a&amp;gt;&#039;) AS Rubric&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_categories AS cat &lt;br /&gt;
ON cat.id = c.category&lt;br /&gt;
JOIN prefix_course_modules AS cm &lt;br /&gt;
ON c.id=cm.course&lt;br /&gt;
JOIN prefix_context AS ctx &lt;br /&gt;
ON cm.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_grading_areas AS garea &lt;br /&gt;
ON ctx.id = garea.contextid&lt;br /&gt;
JOIN prefix_grading_definitions AS gd &lt;br /&gt;
ON garea.id = gd.areaid&lt;br /&gt;
JOIN prefix_gradingform_rubric_criteria AS crit &lt;br /&gt;
ON gd.id = crit.definitionid&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id&lt;br /&gt;
WHERE cm.visible=&#039;1&#039; AND garea.activemethod = &#039;rubric&#039; AND (crit.id NOT IN&lt;br /&gt;
(SELECT crit.id&lt;br /&gt;
FROM prefix_gradingform_rubric_criteria AS crit&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id WHERE levels.score = &#039;0&#039;))&lt;br /&gt;
&lt;br /&gt;
GROUP BY Rubric&lt;br /&gt;
ORDER BY Course_ID, Rubric&lt;br /&gt;
&lt;br /&gt;
%%FILTER_SEARCHTEXT:c.idnumber:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Who is using &amp;quot;Single File Upload&amp;quot; assignment===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,ass.name as &amp;quot;Assignment Name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM &lt;br /&gt;
prefix_assignment as ass&lt;br /&gt;
&lt;br /&gt;
JOIN &lt;br /&gt;
prefix_course as c ON c.id = ass.course&lt;br /&gt;
&lt;br /&gt;
WHERE `assignmenttype` LIKE &#039;uploadsingle&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Feedback Module Reports==&lt;br /&gt;
===List the answers to all the Feedback activities within the current course, submitted by the current user===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT /* crs.fullname as &amp;quot;Course name&amp;quot;, f.name AS &amp;quot;Journal name&amp;quot;, CONCAT(u.firstname,&#039; &#039;,UPPER(u.lastname)) as &amp;quot;Participant&amp;quot;, */ /* include these fields if you want to check the composition of the recordset */&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified),&#039;%W %e %M, %Y&#039;) as &amp;quot;Answer Date&amp;quot;,&lt;br /&gt;
CASE i.typ WHEN &#039;label&#039; THEN i.presentation ELSE i.name END as &amp;quot;Topic&amp;quot;,  /* usually labels are used as section titles, so you&#039;d want them present in the recordset */&lt;br /&gt;
v.value as &amp;quot;My Answer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback AS f&lt;br /&gt;
INNER JOIN prefix_course as crs on crs.id=f.course %%FILTER_COURSES:f.course%% &lt;br /&gt;
INNER JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
INNER JOIN prefix_feedback_completed AS c on f.id=c.feedback %%FILTER_COURSEUSER:c.userid%% &lt;br /&gt;
LEFT JOIN prefix_feedback_value AS v on v.completed=c.id AND v.item=i.id&lt;br /&gt;
INNER JOIN prefix_user AS u on c.userid=u.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%% AND u.id = %%USERID%%  AND c.anonymous_response = 1  /* This clause limits the recordset to the current course and the current user and includes/ excludes the anonymous responses as needed */&lt;br /&gt;
&lt;br /&gt;
ORDER BY f.id, c.timemodified, i.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show all Feedbacks from all courses for all users including showing names of anonymous users===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &#039;Not-logged-in&#039; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS Course, &lt;br /&gt;
f.name AS Feedback,&lt;br /&gt;
# i.id AS Itemid,&lt;br /&gt;
i.name AS Itemname,&lt;br /&gt;
i.label AS Itemlabel,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN f.anonymous = 1 AND u.id != 0 THEN CONCAT(u.username, &#039; :ANON&#039;)&lt;br /&gt;
 WHEN fc.userid = 0 THEN &#039;Not-logged-in&#039;&lt;br /&gt;
 ELSE u.username&lt;br /&gt;
END AS &#039;User&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(fc.timemodified),&#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;Completed&amp;quot;,&lt;br /&gt;
v.value AS &amp;quot;Choice&amp;quot;,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN i.typ = &#039;multichoice&#039; THEN&lt;br /&gt;
     IF (  SUBSTRING(i.presentation,1,6)=&#039;d&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&#039;,&lt;br /&gt;
	       SUBSTRING(i.presentation,7),&lt;br /&gt;
		   i.presentation)&lt;br /&gt;
 ELSE i.presentation&lt;br /&gt;
END AS &amp;quot;Answers&amp;quot;,&lt;br /&gt;
i.typ,&lt;br /&gt;
i.dependitem,&lt;br /&gt;
i.dependvalue&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback f&lt;br /&gt;
JOIN prefix_course c ON c.id=f.course &lt;br /&gt;
JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
JOIN prefix_feedback_completed fc ON f.id=fc.feedback&lt;br /&gt;
LEFT JOIN prefix_feedback_value v ON v.completed=fc.id AND v.item=i.id&lt;br /&gt;
LEFT JOIN prefix_user AS u ON fc.userid=u.id&lt;br /&gt;
WHERE i.typ != &#039;pagebreak&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Resource Module Reports==&lt;br /&gt;
===List &amp;quot;Recently uploaded files&amp;quot;===&lt;br /&gt;
see what users are uploading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT FROM_UNIXTIME(time,&#039;%Y %M %D %h:%i:%s&#039;) as time ,ip,userid,url,info  &lt;br /&gt;
FROM `prefix_log` &lt;br /&gt;
WHERE `action` LIKE &#039;upload&#039; &lt;br /&gt;
ORDER BY `prefix_log`.`time`  DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Courses that loaded a specific file: &amp;quot;X&amp;quot;===&lt;br /&gt;
Did the Teacher (probably) uploaded course&#039;s Syllabus ?&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname  FROM `prefix_log` as l &lt;br /&gt;
JOIN prefix_course as c ON c.id = l.course &lt;br /&gt;
WHERE `action` LIKE &#039;%upload%&#039; AND ( info LIKE &#039;%Syllabus%&#039; OR info LIKE &#039;%Sylabus%&#039; ) GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All resources that link to some specific external website===&lt;br /&gt;
+ link to course&lt;br /&gt;
+ who&#039;s the teacher&lt;br /&gt;
+ link to external resource&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/resource/view.php?id=&#039;,r.id,&#039;&amp;quot;&amp;gt;&#039;,r.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Resource&lt;br /&gt;
FROM prefix_resource AS r &lt;br /&gt;
JOIN prefix_course AS c ON r.course = c.id&lt;br /&gt;
WHERE r.reference LIKE &#039;http://info.oranim.ac.il/home%&#039; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;quot;Compose Web Page&amp;quot; RESOURCE count===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT course,prefix_course.fullname, COUNT(*) AS Total&lt;br /&gt;
FROM `prefix_resource`&lt;br /&gt;
JOIN `prefix_course` ON prefix_course.id = prefix_resource.course&lt;br /&gt;
WHERE type=&#039;html&#039;&lt;br /&gt;
GROUP BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resource count in courses===&lt;br /&gt;
+ (First)Teacher name&lt;br /&gt;
+ Where course is inside some specific Categories&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
COUNT(*) AS count&lt;br /&gt;
,r.course &lt;br /&gt;
,c.shortname shortname&lt;br /&gt;
,c.fullname coursename&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user as u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = r.course AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
FROM prefix_resource r &lt;br /&gt;
JOIN prefix_course c ON r.course = c.id&lt;br /&gt;
WHERE c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY r.course&lt;br /&gt;
ORDER BY COUNT(*) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Delete all the automated backup files===&lt;br /&gt;
Prepare bash cli script to delete all the automated backup files on the file system. (clean up some disk space)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT( &#039;rm -f /var/moodledatanew/filedir/&#039;, SUBSTRING( contenthash, 1, 2 ) , &#039;/&#039;, SUBSTRING( contenthash, 3, 2 ) , &#039;/&#039;, contenthash ) &lt;br /&gt;
FROM `mdl_files` &lt;br /&gt;
WHERE `filename` LIKE &#039;%mbz%&#039;&lt;br /&gt;
AND filearea = &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find out how much disk space is used by all automated backup files:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT SUM(filesize)/(1024*1024*1024) FROM `mdl_files` WHERE  `filename` LIKE &#039;%mbz%&#039; AND filearea =  &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Forum Module Reports==&lt;br /&gt;
===print all User&#039;s post in course Forums===&lt;br /&gt;
%%COURSEID%% is a variable the is replace by the current CourseID you are running the sql report from. if you are using the latest block/configurable_reports ! (You can always change it to a fixed course or remove it to display all courses.)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php?course=&#039;,c.id,&#039;&amp;amp;id=&#039;,u.id,&#039;&amp;amp;mode=posts&amp;quot;&amp;gt;&#039;,CONCAT(u.firstname,&#039; &#039;, u.lastname),&#039;&amp;lt;/a&amp;gt;&#039;) As Fullname&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Forum&lt;br /&gt;
,count(*) as Posts&lt;br /&gt;
,(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&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_user as u ON u.id = fp.userid &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = fd.course &lt;br /&gt;
WHERE fd.course = %%COURSEID%% &lt;br /&gt;
GROUP BY f.id,u.id&lt;br /&gt;
ORDER BY u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE by type -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, prefix_forum.type, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course,prefix_forum.type&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Forum activity - system wide===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,c.fullname as Course&lt;br /&gt;
,f.type&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
, fd.forum, f.name,count(*) AS cPostAndDisc&lt;br /&gt;
,(SELECT count(*) FROM prefix_forum_discussions AS ifd WHERE ifd.forum = f.id) AS cDiscussion&lt;br /&gt;
FROM prefix_forum_posts AS fp&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type != &#039;news&#039; AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
## WHERE 1=1 &lt;br /&gt;
## %%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count( * ) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Activity In Forums===&lt;br /&gt;
Trying to figure out how much real activity we have in Forums by aggregating:&lt;br /&gt;
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...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname,f.name,f.type &lt;br /&gt;
,(SELECT count(id) FROM prefix_forum_discussions as fd WHERE f.id = fd.forum) as Discussions&lt;br /&gt;
,(SELECT count(distinct fd.userid) FROM prefix_forum_discussions as fd WHERE fd.forum = f.id) as UniqueUsersDiscussions&lt;br /&gt;
,(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&lt;br /&gt;
,(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&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS StudentsCount&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Teachers&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS &#039;Teacher&amp;lt;br/&amp;gt;Count&#039;&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid IN (3,5)&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS UserCount&lt;br /&gt;
, (SELECT (UniqueUsersDiscussions / StudentsCount )) as StudentDissUsage&lt;br /&gt;
, (SELECT (UniqueUsersPosts /StudentsCount)) as StudentPostUsage&lt;br /&gt;
FROM prefix_forum as f &lt;br /&gt;
JOIN prefix_course as c ON f.course = c.id&lt;br /&gt;
WHERE `type` != &#039;news&#039;&lt;br /&gt;
ORDER BY StudentPostUsage DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Forum type:NEWS===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT f.id, f.name&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
WHERE m.name = &#039;forum&#039;&lt;br /&gt;
AND f.type = &#039;news&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All new forum NEWS items (discussions) from all my Courses===&lt;br /&gt;
change &amp;quot;userid = 26&amp;quot; and &amp;quot;id = 26&amp;quot; to a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname,f.name,fd.name,FROM_UNIXTIME(fd.timemodified ,&amp;quot;%d %M %Y &amp;quot;) as Date&lt;br /&gt;
FROM prefix_forum_discussions as fd &lt;br /&gt;
JOIN prefix_forum as f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = f.course &lt;br /&gt;
JOIN prefix_user_lastaccess as ul ON (c.id = ul.courseid AND ul.userid = 26)&lt;br /&gt;
WHERE fd.timemodified &amp;gt; ul.timeaccess  &lt;br /&gt;
 AND fd.forum IN (SELECT f.id&lt;br /&gt;
 FROM prefix_course_modules AS cm&lt;br /&gt;
 JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
 JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
 WHERE m.name = &#039;forum&#039;&lt;br /&gt;
 AND f.type = &#039;news&#039;)&lt;br /&gt;
  AND c.id IN (SELECT c.id&lt;br /&gt;
   FROM prefix_course AS c&lt;br /&gt;
   JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
   JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
   JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
   WHERE u.id = 26) ORDER BY `fd`.`timemodified` DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===News Forum - Discussions COUNT===&lt;br /&gt;
Which is actually... How much instructions students get from their teachers&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname ,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,count(fd.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS DiscussionsSum&lt;br /&gt;
FROM prefix_forum_discussions AS fd&lt;br /&gt;
INNER JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
INNER JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type = &#039;news&#039; AND c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count(fd.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cantidad de foros que han sido posteados por profesor===&lt;br /&gt;
&lt;br /&gt;
(Number of forums that have been posted by teacher/Google translator)&lt;br /&gt;
&lt;br /&gt;
Queriamos saber cuales son las acciones del profesor dentro de los foros de cada curso, por ello se hizo este informe.&lt;br /&gt;
&lt;br /&gt;
(We wanted to know what the teacher&#039;s actions are in the forums of each course, so this report was made. /Google translator)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS curso,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Facilitador,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( m.name ) AS COUNT FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS foros,&lt;br /&gt;
&lt;br /&gt;
COUNT(*) AS Posts&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course AS c ON c.id = fd.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = fp.userid &lt;br /&gt;
&lt;br /&gt;
WHERE fp.userid =&lt;br /&gt;
(&lt;br /&gt;
select distinct prefix_user.id&lt;br /&gt;
from prefix_user &lt;br /&gt;
join prefix_role_assignments as ra on ra.userid = prefix_user.id &lt;br /&gt;
where ra.roleid = 3 &lt;br /&gt;
and userid = fp.userid&lt;br /&gt;
limit 1&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
and c.shortname like &#039;%2014-2-1%&#039;&lt;br /&gt;
GROUP BY c.id, u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all the Forums that got high rating===&lt;br /&gt;
We setup a scale that let teachers and students Rate forum post with &amp;quot;Important, interesting, valuable, not rated&amp;quot; scale&lt;br /&gt;
And then add a link to the following report at the begining of the course &amp;quot;Link to all interesting posts&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,f.id,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;,fd.id,&#039;#p&#039;,fp.id,&#039;&amp;quot;&amp;gt;&#039;,fp.subject,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post link&#039;,&lt;br /&gt;
SUM(r.rating) AS &#039;Rating&#039;&lt;br /&gt;
FROM mdl_rating AS r&lt;br /&gt;
  JOIN mdl_forum_posts AS fp ON fp.id = r.itemid&lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
WHERE r.component = &#039;mod_forum&#039; AND r.ratingarea = &#039;post&#039; AND f.course = %%COURSEID%%&lt;br /&gt;
GROUP BY r.itemid&lt;br /&gt;
ORDER BY SUM(r.rating) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all Discussions of a single Forum===&lt;br /&gt;
This report is used to help export all the student&#039;s posts and discussions of a single forum, by passing the context module id as a parameter to the report using &amp;quot;&amp;amp;filter_var=cmid&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;, f.id, &#039;&amp;quot;&amp;gt;&#039;, f.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name&#039;,&lt;br /&gt;
fd.name AS &#039;Discussion&#039;, &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;, fd.id, &#039;#p&#039;, fp.id, &#039;&amp;quot;&amp;gt;&#039;, fp.subject, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post (link)&#039;,&lt;br /&gt;
fp.message&lt;br /&gt;
&lt;br /&gt;
FROM mdl_forum_posts AS fp &lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
  JOIN mdl_course_modules AS cm ON cm.module = 9 AND cm.instance = f.id&lt;br /&gt;
WHERE cm.id = %%FILTER_VAR%%&lt;br /&gt;
ORDER BY f.id, fd.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Quiz Module Reports==&lt;br /&gt;
===Generate a list of instructors and their email addresses for those courses that has &amp;quot;essay questions&amp;quot; in their quizzes===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT qu.id AS quiz_id, qu.course AS course_id, qu.questions,&lt;br /&gt;
                co.fullname AS course_fullname, co.shortname AS course_shortname,&lt;br /&gt;
                qu.name AS quiz_name, FROM_UNIXTIME(qu.timeopen) AS quiz_timeopen, FROM_UNIXTIME(qu.timeclose) AS quiz_timeclose,&lt;br /&gt;
                u.firstname, u.lastname, u.email,&lt;br /&gt;
FROM prefix_quiz qu, prefix_course co, prefix_role re, prefix_context ct, prefix_role_assignments ra, prefix_user u&lt;br /&gt;
WHERE FROM_UNIXTIME(timeopen) &amp;gt; &#039;2008-05-14&#039; AND&lt;br /&gt;
                qu.course = co.id AND&lt;br /&gt;
                co.id = ct.instanceid AND&lt;br /&gt;
                ra.roleid = re.id AND&lt;br /&gt;
                re.name = &#039;Teacher&#039; AND&lt;br /&gt;
                ra.contextid = ct.id AND&lt;br /&gt;
                ra.userid = u.id&lt;br /&gt;
 &lt;br /&gt;
SELECT Count(&#039;x&#039;) As NumOfStudents&lt;br /&gt;
                                FROM prefix_role_assignments a&lt;br /&gt;
                                JOIN prefix_user u ON userid = u.id&lt;br /&gt;
                                WHERE roleid = 5 AND contextid = (SELECT id FROM prefix_context WHERE instanceid = 668 AND contextlevel = 50)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Number of Quizes per Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Link&amp;lt;/a&amp;gt;&#039;) AS Quizes&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules cm&lt;br /&gt;
JOIN prefix_course c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module&lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039;&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all MultiAnswer (Cloze) Questions===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/attempt.php?q=&#039;, quiz.id, &#039;&amp;quot;&amp;gt;&#039;, quiz.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS Quiz&lt;br /&gt;
,question.id question_id, question.questiontext &lt;br /&gt;
FROM  prefix_question question&lt;br /&gt;
JOIN prefix_quiz_question_instances qqi ON question.id = qqi.question&lt;br /&gt;
JOIN prefix_quiz quiz ON qqi.quiz = quiz.id&lt;br /&gt;
WHERE  `qtype` LIKE  &#039;multianswer&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List courses with MANUAL grades===&lt;br /&gt;
Which is basically and indication to teachers using Moodle to hold offline grades inside Moodle&#039;s Gradebook,&lt;br /&gt;
So grades could be uploaded into an administrative SIS. Use with Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT( * )&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php?showadvanced=1&amp;amp;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM  prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course as c ON c.id = gi.courseid&lt;br /&gt;
WHERE  `itemtype` =  &#039;manual&#039;&lt;br /&gt;
GROUP BY courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===List the users that did not took the Quiz===&lt;br /&gt;
Do not forget to change &amp;quot;c.id = 14&amp;quot; and q.name LIKE &#039;%quiz name goes here%&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id AS ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.username AS IDNumber,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
 &lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id AND courseid=c.id) AS CourseLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id AND e.courseid = c.id) AS RoleName&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess AS ul ON ul.userid = user2.id&lt;br /&gt;
WHERE c.id=14 and ue.userid NOT IN (SELECT qa.userid FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON qa.quiz = q.id&lt;br /&gt;
JOIN prefix_course AS c ON q.course = c.id&lt;br /&gt;
WHERE c.id = 14 AND q.name LIKE &#039;%quiz name goes here%&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List Questions in each Quiz===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT quiz.id,quiz.name, q.id, q.name&lt;br /&gt;
FROM mdl_quiz AS quiz&lt;br /&gt;
JOIN mdl_question AS q ON FIND_IN_SET(q.id, quiz.questions)&lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
ORDER BY quiz.id ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this query does not work in Moodle 2.8. There is no mdl_quiz.questions field. It will need to be rewritten to use the usage/contextid organization.&lt;br /&gt;
&lt;br /&gt;
===Quiz activity research===&lt;br /&gt;
This report was made to extract student full activity in quizzes for an academic research about adapting instructional design teaching methods in online learning. The students do not use the Quiz module as a standard quiz but more as Study booklets or mini courses with embedded questions and hints to assist students evaluate their progress (Similar to what you expect to find in a SCORM activity)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cm.course &amp;quot;course_id&amp;quot;, cm.id &amp;quot;moduel_id&amp;quot;, q.id &amp;quot;quiz_id&amp;quot;, q.name &amp;quot;quiz_name&amp;quot;,&lt;br /&gt;
 &lt;br /&gt;
CASE q.grademethod&lt;br /&gt;
      WHEN 1 THEN &amp;quot;GRADEHIGHEST&amp;quot;&lt;br /&gt;
      WHEN 2 THEN &amp;quot;GRADEAVERAGE&amp;quot;&lt;br /&gt;
      WHEN 3 THEN &amp;quot;ATTEMPTFIRST&amp;quot;&lt;br /&gt;
      WHEN 4 THEN &amp;quot;ATTEMPTLAST&amp;quot;&lt;br /&gt;
END &amp;quot;grade method&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
, q.attempts &amp;quot;quiz_attempts_allowed&amp;quot;, cm.groupmode &amp;quot;group_mode&amp;quot;&lt;br /&gt;
, qa.id &amp;quot;attempt_id&amp;quot;, qa.state &amp;quot;attempt_state&amp;quot;, qa.sumgrades &amp;quot;attempt_grade&amp;quot;, qg.grade &amp;quot;user_final_grade&amp;quot;, q.grade &amp;quot;quiz_max_grade&amp;quot;&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = q.course AND m.userid = u.id) &amp;quot;user_groups&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timestart), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_start&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timefinish), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_finish&amp;quot;,&lt;br /&gt;
u.id &amp;quot;user_id&amp;quot;, u.firstname, u.lastname,&lt;br /&gt;
question.id &amp;quot;question_id&amp;quot;, question.name &amp;quot;question_name&amp;quot;,&lt;br /&gt;
qas.state &amp;quot;question_step_state&amp;quot;,qas.fraction &amp;quot;question_grade&amp;quot;, qh.hint, question.qtype &amp;quot;question_type&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz as q&lt;br /&gt;
JOIN mdl_course_modules as cm ON cm.instance = q.id and cm.module = 14 &lt;br /&gt;
JOIN mdl_quiz_attempts qa ON q.id = qa.quiz&lt;br /&gt;
LEFT JOIN mdl_quiz_grades as qg ON qg.quiz = q.id and qg.userid = qa.userid&lt;br /&gt;
JOIN mdl_user as u ON u.id = qa.userid&lt;br /&gt;
JOIN mdl_question_usages as qu ON qu.id = qa.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts as qatt ON qatt.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question as question ON question.id = qatt.questionid&lt;br /&gt;
JOIN mdl_question_attempt_steps as qas ON qas.questionattemptid = qatt.id&lt;br /&gt;
LEFT JOIN mdl_question_hints as qh ON qh.questionid = q.id&lt;br /&gt;
#WHERE q.id = &amp;quot;SOME QUIZ ID&amp;quot;&lt;br /&gt;
WHERE cm.course = &amp;quot;SOME COURSE ID&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quiz Usage in Courses by Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Multiple Choice&amp;quot; questions include true/false and matching question types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Short Answer&amp;quot; are questions that accept a single phrase.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Other&amp;quot; questions include fixed numerical, calculated, essay, and various drag and drop types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Min Quiz Age&amp;quot; and &amp;quot;Max Quiz Age&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: In Configurable Reports, the Date Filter is not applied until the &amp;quot;Apply&amp;quot; button is clicked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.shortname AS &#039;Course&#039;&lt;br /&gt;
#, u.lastname AS &#039;Instructor&#039;&lt;br /&gt;
, COUNT(DISTINCT q.id) AS &#039;Quizzes&#039;&lt;br /&gt;
, COUNT(DISTINCT qu.id) AS &#039;Questions&#039;&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 ))  AS &#039;multichoice&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT( qu.id) - SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;Other&#039;&lt;br /&gt;
&lt;br /&gt;
, (SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )))/COUNT( qu.id) AS &#039;Percent MC&#039;&lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;numerical&#039;, 1, 0 )) AS &#039;numerical&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype LIKE &#039;calc%&#039;, 1, 0 )) AS &#039;calculated&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;random&#039;, 1, 0 )) AS &#039;random&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;essay&#039;, 1, 0 )) AS &#039;essay&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, IF(q.shufflequestions &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Questions&#039;&lt;br /&gt;
, IF(q.shuffleanswers &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Answers&#039;&lt;br /&gt;
 &lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
#, FROM_UNIXTIME(MIN(q.timemodified)) AS &#039;Last Modified&#039;&lt;br /&gt;
&lt;br /&gt;
#, DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(MIN(q.timemodified))) AS &#039;Quiz age&#039;&lt;br /&gt;
&lt;br /&gt;
, MIN(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Min Quiz Age&#039; &lt;br /&gt;
, MAX(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Max Quiz Age&#039; &lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified)) &amp;lt; 90, 1,0)) AS &#039;new quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_quiz AS q&lt;br /&gt;
JOIN prefix_course AS c on c.id = q.course&lt;br /&gt;
JOIN prefix_quiz_question_instances AS qqi ON qqi.quiz = q.id&lt;br /&gt;
LEFT JOIN prefix_question AS qu ON qu.id = qqi.question&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%% %%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student responses (answers) to quiz questions===&lt;br /&gt;
(Contributed by Juan F with help from Tim hunt and fellow Moodlers on the forums)&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    concat( u.firstname, &amp;quot; &amp;quot;, u.lastname ) AS &amp;quot;Student Name&amp;quot;,&lt;br /&gt;
    u.id,&lt;br /&gt;
    quiza.userid,&lt;br /&gt;
    q.course,&lt;br /&gt;
    q.name,&lt;br /&gt;
    quiza.attempt,&lt;br /&gt;
    qa.slot,&lt;br /&gt;
    que.questiontext AS &#039;Question&#039;,&lt;br /&gt;
    qa.rightanswer AS &#039;Correct Answer&#039;,&lt;br /&gt;
    qa.responsesummary AS &#039;Student Answer&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz_attempts quiza&lt;br /&gt;
JOIN mdl_quiz q ON q.id=quiza.quiz&lt;br /&gt;
JOIN mdl_question_usages qu ON qu.id = quiza.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts qa ON qa.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question que ON que.id = qa.questionid&lt;br /&gt;
JOIN mdl_user u ON u.id = quiza.userid&lt;br /&gt;
&lt;br /&gt;
WHERE q.name = &amp;quot;BIO 208 Post Test Assessment&amp;quot;&lt;br /&gt;
AND q.course = &amp;quot;17926&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ORDER BY quiza.userid, quiza.attempt, qa.slot&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==SCORM Activity Reports==&lt;br /&gt;
&lt;br /&gt;
===Lists All completed SCORM activites by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists SCORM status for all enrolled users by Course name===&lt;br /&gt;
This report will list the SCORM status for all users enrolled in the course. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. This can be limited to individual courses by adding to the where clause the course id to report on.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.firstname AS First,&lt;br /&gt;
u.lastname AS Last, &lt;br /&gt;
u.idnumber AS Employee_ID,  &lt;br /&gt;
u.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
u.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course, &lt;br /&gt;
st.attempt AS Attempt,&lt;br /&gt;
st.value AS Status,&lt;br /&gt;
FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) AS Date &lt;br /&gt;
&lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
&lt;br /&gt;
WHERE st.element=&#039;cmi.core.lesson_status&#039; AND m.userid=u.id&lt;br /&gt;
&lt;br /&gt;
UNION&lt;br /&gt;
&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS First,&lt;br /&gt;
user2.lastname AS Last,&lt;br /&gt;
user2. idnumber AS Employee_ID,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
user2.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Attempt,&lt;br /&gt;
&amp;quot;not_started&amp;quot; AS Status,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Date&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = user2.id &lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.course=c.id&lt;br /&gt;
Left Join prefix_scorm_scoes_track AS st on st.scormid=sc.id AND st.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
WHERE  st.timemodified IS NULL AND m.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY  Course, Last, First, Attempt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Badges==&lt;br /&gt;
&lt;br /&gt;
=== All badges issued, by User ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, b.name AS badgename, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN&lt;br /&gt;
(SELECT c.shortname&lt;br /&gt;
    FROM prefix_course AS c&lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Context,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 1 THEN &amp;quot;Activity Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 2 THEN &amp;quot;Activity Completion (Any)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 2 AND t.method = 2 THEN &amp;quot;Manual Award&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 1 THEN &amp;quot;Course Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 2 THEN &amp;quot;Course Completion (Any)&amp;quot;&lt;br /&gt;
  ELSE CONCAT (&#039;Other: &#039;, t.criteriatype)&lt;br /&gt;
END AS Criteriatype,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateissued ) , &#039;%Y-%m-%d&#039; ) AS dateissued,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateexpire ), &#039;%Y-%m-%d&#039; ) AS dateexpires,&lt;br /&gt;
CONCAT (&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/badge.php?hash=&#039;,d.uniquehash,&#039;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&#039;) AS Details&lt;br /&gt;
FROM prefix_badge_issued AS d &lt;br /&gt;
JOIN prefix_badge AS b ON d.badgeid = b.id&lt;br /&gt;
JOIN prefix_user AS u ON d.userid = u.id&lt;br /&gt;
JOIN prefix_badge_criteria AS t on b.id = t.badgeid &lt;br /&gt;
WHERE t.criteriatype &amp;lt;&amp;gt; 0&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&lt;br /&gt;
=== All badges available in the system, with Earned count ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.type = 1 THEN &amp;quot;System&amp;quot;&lt;br /&gt;
WHEN b.type = 2 THEN &amp;quot;Course&amp;quot;&lt;br /&gt;
END AS Context, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN &lt;br /&gt;
(SELECT c.shortname &lt;br /&gt;
    FROM prefix_course AS c &lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 2 THEN &amp;quot;No&amp;quot;&lt;br /&gt;
WHEN b.status = 1 OR b.status = 3 THEN &amp;quot;Yes&amp;quot;&lt;br /&gt;
WHEN b.status = 4 THEN &amp;quot;x&amp;quot;&lt;br /&gt;
END AS Available,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 1 THEN &amp;quot;0&amp;quot;&lt;br /&gt;
WHEN b.status = 2 OR b.status = 3 OR b.status = 4 THEN &lt;br /&gt;
 (SELECT COUNT(*) &lt;br /&gt;
   FROM prefix_badge_issued AS d&lt;br /&gt;
   WHERE d.badgeid = b.id&lt;br /&gt;
 )&lt;br /&gt;
END AS Earned&lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Badges Leaderboard ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A simple list of usernames and how many badges they have earned overall.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, (SELECT COUNT(*) FROM prefix_badge_issued AS d WHERE d.userid = u.id) AS earned&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
ORDER BY earned DESC, u.username ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Manage badges (System &amp;amp; Course) ===&lt;br /&gt;
&lt;br /&gt;
List system wide badges, course and system level badges + a link to relevant &amp;quot;manage badges&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description &lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN b.type = 1 THEN &#039;System&#039;&lt;br /&gt;
  WHEN b.type = 2 THEN &#039;Course&#039;&lt;br /&gt;
END AS Level&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/index.php?type=&#039;, b.type, &#039;&amp;amp;id=&#039;,&lt;br /&gt;
			  c.id, &#039;&amp;quot;&amp;gt;Manage badges in: &#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Manage &lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Administrator Reports==&lt;br /&gt;
&lt;br /&gt;
===Config changes in Export friendly form===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( g.timemodified ) , &#039;%Y-%m-%d&#039; ) AS date, &lt;br /&gt;
u.username AS user, &lt;br /&gt;
g.name AS setting, &lt;br /&gt;
CASE &lt;br /&gt;
 WHEN g.plugin IS NULL THEN &amp;quot;core&amp;quot;&lt;br /&gt;
 ELSE g.plugin&lt;br /&gt;
END AS plugin, &lt;br /&gt;
g.value AS new_value, &lt;br /&gt;
g.oldvalue AS original_value&lt;br /&gt;
FROM prefix_config_log  AS g&lt;br /&gt;
JOIN prefix_user AS u ON g.userid = u.id&lt;br /&gt;
ORDER BY date DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts by user===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
How to get a list of all users and which cohorts they belong to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, h.idnumber, h.name&lt;br /&gt;
FROM prefix_cohort AS h&lt;br /&gt;
JOIN prefix_cohort_members AS hm ON h.id = hm.cohortid&lt;br /&gt;
JOIN prefix_user AS u ON hm.userid = u.id&lt;br /&gt;
ORDER BY u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts with Courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all cohorts with name, id, visibility, and which courses they are enrolled in.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
# h.id,&lt;br /&gt;
# e.customint1,&lt;br /&gt;
h.name AS Cohort,&lt;br /&gt;
h.idnumber AS Cohortid,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN h.visible = 1 THEN &#039;Yes&#039;&lt;br /&gt;
 ELSE &#039;-&#039;&lt;br /&gt;
END AS Cohortvisible,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;, CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_cohort h&lt;br /&gt;
JOIN prefix_enrol e ON h.id = e.customint1&lt;br /&gt;
JOIN prefix_course c ON c.id = e.courseid %%FILTER_COURSES:e.courseid%% &lt;br /&gt;
WHERE e.enrol = &#039;cohort&#039; AND e.roleid = 5&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses created And Active courses by Year===&lt;br /&gt;
Active courses is counting course that have at least one Hit, And &amp;quot;Active_MoreThan100Hits&amp;quot; counts courses that have at least 100 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `timecreated` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT course ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY course &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 100) AS courses_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( courses_log.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan100Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_course` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users created And Active users by Year===&lt;br /&gt;
Active users is counting users that have at least one Hit, And &amp;quot;Active_MoreThan500Hits&amp;quot; counts users that have at least 500 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `firstaccess` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT userid ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY userid &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 500) AS users_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( users_log.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan500Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Aggregation Report===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In particular, be on the lookout for any courses with the following combinations of parameters, which are known to cause changes in calculations:&lt;br /&gt;
&lt;br /&gt;
# mean of grades set with aggregate with subcategory.&lt;br /&gt;
# Simple weighted mean of grades with aggregate with sub category and drop the lowest&lt;br /&gt;
# Sum of grades drop the lowest&lt;br /&gt;
&lt;br /&gt;
Also review:&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48618&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48634&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-49257&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50089&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50062&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
COUNT(c.shortname) AS &#039;Count of Courses&#039;&lt;br /&gt;
&lt;br /&gt;
# If you want to display all the courses for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, c.shortname AS &#039;course name&#039;&lt;br /&gt;
&lt;br /&gt;
# If you need to display grade categories for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, gc.fullname AS &#039;grade category name&#039;&lt;br /&gt;
&lt;br /&gt;
, gc.aggregation AS &#039;aggregation method&#039;&lt;br /&gt;
&lt;br /&gt;
#These aggregation text strings appear to be hard-coded. I couldn&#039;t find a table for them. If you have aggregation types I haven&#039;t included here, they&#039;ll be blank in your report results.&lt;br /&gt;
, CASE gc.aggregation&lt;br /&gt;
  WHEN 0 THEN &#039;Mean of Grades&#039;&lt;br /&gt;
  WHEN 2 THEN &#039;Median of Grades&#039;&lt;br /&gt;
  WHEN 6 THEN &#039;Highest Grade&#039;&lt;br /&gt;
  WHEN 8 THEN &#039;Mode of Grades&#039;&lt;br /&gt;
  WHEN 10 THEN &#039;Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 11 THEN &#039;Simple Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 12 THEN &#039;Mean of Grades (with extra credits)&#039;&lt;br /&gt;
  WHEN 13 THEN &#039;Sum of Grades&#039;&lt;br /&gt;
END AS &#039;aggregation name&#039;&lt;br /&gt;
&lt;br /&gt;
# Note that gc.aggregatesubcats column is eliminated in 2.8 and later per MDL-47503, so comment that line on updated systems or you&#039;ll get an error&lt;br /&gt;
, gc.keephigh AS &#039;keep high&#039;&lt;br /&gt;
, gc.droplow AS &#039;dr0p low&#039;&lt;br /&gt;
, gc.aggregateonlygraded AS &#039;Aggregate only graded&#039;&lt;br /&gt;
, gc.aggregateoutcomes AS &#039;aggregate outcomes&#039;&lt;br /&gt;
, gc.aggregatesubcats AS &#039;aggregate subcategories&#039;&lt;br /&gt;
&lt;br /&gt;
# If you are displaying data about individual courses, you may want to know how old they are&lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;course start date&#039;&lt;br /&gt;
&lt;br /&gt;
# 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&#039;ll need to uncomment the necessary JOINs below&lt;br /&gt;
#, gi.itemname AS &#039;grade item&#039;&lt;br /&gt;
#, gg.finalgrade AS &#039;final grade&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
&lt;br /&gt;
prefix_course AS c&lt;br /&gt;
JOIN prefix_grade_categories AS gc ON gc.courseid = c.id&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id #AND gi.categoryid=gc.id&lt;br /&gt;
#LEFT JOIN prefix_grade_grades AS gg ON gg.itemid = gi.id AND gg.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
#AND gc.aggregation = 13 #only the dreaded Sum of Grades aggregations&lt;br /&gt;
#AND gc.depth = 1 # if for some reason you only want course aggregations, not subcategories&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.aggregation, gc.keephigh, gc.droplow, gc.aggregateonlygraded, gc.aggregateoutcomes, gc.aggregatesubcats&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running Cron jobs (task_scheduled) ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT classname&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(lastruntime), &#039;%H:%i [%d]&#039;) AS &#039;last&#039;&lt;br /&gt;
  ,DATE_FORMAT(now(), &#039;%H:%i&#039;) AS &#039;now&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(nextruntime), &#039;%H:%i [%d]&#039;) AS &#039;next&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP()-nextruntime), &#039;%i&#039;) AS &#039;next in min&#039;&lt;br /&gt;
FROM mdl_task_scheduled&lt;br /&gt;
WHERE now() &amp;gt; FROM_UNIXTIME(nextruntime)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== All Meta courses with Parent and Child course relationships ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
This shows the list of courses with Meta course link enrollments in them (&#039;Parent course&#039;), and the courses which are connected to them to provide enrollments (&#039;Child courses&#039;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.fullname AS &#039;Parent course name&#039;,&lt;br /&gt;
c.shortname AS &#039;Parent course shortname&#039;,&lt;br /&gt;
en.courseid AS &#039;Parent course id&#039;,&lt;br /&gt;
(SELECT fullname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course name&#039;,&lt;br /&gt;
(SELECT shortname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course shortname&#039;,&lt;br /&gt;
en.customint1 AS &#039;Child course id&#039;&lt;br /&gt;
FROM prefix_enrol en&lt;br /&gt;
JOIN prefix_course c ON c.id = en.courseid&lt;br /&gt;
WHERE en.enrol = &#039;meta&#039;&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Useful sub queries ==&lt;br /&gt;
&lt;br /&gt;
IN this section please put any short one purpose sub queries that show how common procedures often useful as part of larger queries.&lt;br /&gt;
&lt;br /&gt;
=== All teachers in the course ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This snippet shows how to get teachers from a course. The contextevel for course objects is 50. And the default Teacher role is role id 3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course ic&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = ic.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND ic.id = c.id&lt;br /&gt;
GROUP BY ic.id&lt;br /&gt;
) AS TeacherNames&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Get custom User profile fields for a user ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON uid.fieldid = uif.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to limit it to one of those fields, you can restrict it by shortname of the custom profile field, so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;shortname1&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will show you only the data from the custom profile field with the shortname &#039;shortname1&#039;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, d1.data AS &#039;Profile One&#039;, d2.data As &#039;Profile Two&#039;&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
JOIN prefix_user_info_data d1 ON d1.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
JOIN prefix_user_info_data d2 ON d2.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f2 ON d2.fieldid = f2.id AND f2.shortname = &#039;shortname2&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== NOTE: Alternate Method ====&lt;br /&gt;
&lt;br /&gt;
If you have more than a couple of fields you need to use, then this query may time out or not return data due to too many joins. The limit seems to be around 10 custom profile fields. &lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thefirstfield&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname2&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thesecondfield&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== How to use Configurable Reports Date Time Filters===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Here is a simple example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.firstaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;FirstAccess&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.lastaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;LastAccess&#039;   &lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1&lt;br /&gt;
%%FILTER_STARTTIME:u.firstaccess:&amp;gt;%% &lt;br /&gt;
%%FILTER_ENDTIME:u.lastaccess:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2) You MUST then add the Start / End date filter on the Filters tab of the Report. If you don&#039;t, the report will still run, probably, but the filter will be ignored.&lt;br /&gt;
&lt;br /&gt;
Note: the WHERE 1=1 statement is a peculiarity of the filters in Config reports: if you don&#039;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.)&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://github.com/jleyva/moodle-configurable_reports_repository Configurable Reports Repository on GitHub]&lt;br /&gt;
* [https://moodleschema.zoola.io/index.html Moodle DB schema explorer] - searching and filtering tables, fields and external key connections between tables.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;br /&gt;
&lt;br /&gt;
[[es:Reportes específicos hechos por usuarios]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=132008</id>
		<title>ad-hoc contributed reports</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=132008"/>
		<updated>2018-10-01T08:59:30Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Weekly attendance report */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Sitewide reports}}&lt;br /&gt;
==User and Role Report==&lt;br /&gt;
&lt;br /&gt;
===Count number of distinct learners and teachers enrolled per category (including all its sub categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;SELECT COUNT(DISTINCT lra.userid) AS learners, COUNT(DISTINCT tra.userid) as teachers&lt;br /&gt;
FROM prefix_course AS c #, mdl_course_categories AS cats&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments  AS lra ON lra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role_assignments  AS tra ON tra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category = cats.id&lt;br /&gt;
AND (&lt;br /&gt;
	cats.path LIKE &#039;%/CATEGORYID/%&#039; #Replace CATEGORYID with the category id you want to count (eg: 80)&lt;br /&gt;
	OR cats.path LIKE &#039;%/CATEGORYID&#039;&lt;br /&gt;
	)&lt;br /&gt;
AND lra.roleid=5&lt;br /&gt;
AND tra.roleid=3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each ROLE (TEACHER, NON-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT r.name, l.action, COUNT( l.userid ) AS counter&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_role AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE ra.roleid IN ( 3, 4, 5 ) &lt;br /&gt;
GROUP BY roleid, l.action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student (user) COUNT in each Course===&lt;br /&gt;
Including (optional) filter by: year (if included in course fullname).&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/index.php?contextid=&#039;,context.id,&#039;&amp;quot;&amp;gt;Show users&amp;lt;/a&amp;gt;&#039;) AS Users&lt;br /&gt;
, COUNT(course.id) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS asg&lt;br /&gt;
JOIN prefix_context AS context ON asg.contextid = context.id AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_user AS user ON user.id = asg.userid&lt;br /&gt;
JOIN prefix_course AS course ON context.instanceid = course.id&lt;br /&gt;
WHERE asg.roleid = 5 &lt;br /&gt;
# AND course.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
GROUP BY course.id&lt;br /&gt;
ORDER BY COUNT(course.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enrolment count in each Course ===&lt;br /&gt;
&lt;br /&gt;
Shows the total number of enroled users of all roles in each course. Sorted by course name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname, COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LIST of all site USERS by COURSE enrollment (Moodle 2.x)===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) as Role&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) as RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course as course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enrolled users,which did not login into the Course, even once (Moodle 2)===&lt;br /&gt;
Designed forMoodle 2 table structure and uses special plugin filter : %%FILTER_SEARCHTEXT:table.field%%&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id as ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
user2.idnumber AS IDNumber,&lt;br /&gt;
user2.phone1 AS Phone,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
&lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id and courseid=c.id) as CourseLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id and e.courseid = c.id) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments as ue&lt;br /&gt;
JOIN prefix_enrol as e on e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user as user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess as ul on ul.userid = user2.id&lt;br /&gt;
WHERE c.id=16 AND ul.timeaccess IS NULL&lt;br /&gt;
%%FILTER_SEARCHTEXT:user2.firstname%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Role assignments on categories===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS category,&lt;br /&gt;
cc.depth, cc.path, r.name AS role,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php?id=&#039;,usr.id,&#039;&amp;quot;&amp;gt;&#039;,usr.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS name,&lt;br /&gt;
usr.firstname, usr.username, usr.email&lt;br /&gt;
FROM prefix_course_categories cc&lt;br /&gt;
INNER JOIN prefix_context cx ON cc.id = cx.instanceid&lt;br /&gt;
AND cx.contextlevel = &#039;40&#039;&lt;br /&gt;
INNER JOIN prefix_role_assignments ra ON cx.id = ra.contextid&lt;br /&gt;
INNER JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
INNER JOIN prefix_user usr ON ra.userid = usr.id&lt;br /&gt;
ORDER BY cc.depth, cc.path, usr.lastname, usr.firstname, r.name, cc.name&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Permissions Overides on Categories===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712834 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT rc.id, ct.instanceid, ccat.name, rc.roleid, rc.capability, rc.permission, &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( rc.timemodified ) , &#039;%Y-%m-%d&#039; ) AS timemodified, rc.modifierid, ct.instanceid, ct.path, ct.depth&lt;br /&gt;
FROM `prefix_role_capabilities` AS rc&lt;br /&gt;
INNER JOIN `prefix_context` AS ct ON rc.contextid = ct.id&lt;br /&gt;
INNER JOIN `prefix_course_categories` AS ccat ON ccat.id = ct.instanceid&lt;br /&gt;
AND `contextlevel` =40&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;Totally Opened Courses&amp;quot; (visible, opened to guests, with no password)===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712837 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Course&#039;,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/enrol/instances.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Méthodes inscription&amp;lt;/a&amp;gt;&#039;) AS &#039;Enrollment plugins&#039;,&lt;br /&gt;
e.sortorder&lt;br /&gt;
FROM prefix_enrol AS e, prefix_course AS c&lt;br /&gt;
WHERE e.enrol=&#039;guest&#039; AND e.status=0 AND e.password=&#039;&#039; AND c.id=e.courseid AND c.visible=1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;loggedin users&amp;quot; from the last 120 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id,username,FROM_UNIXTIME(`lastlogin`) as days &lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;and user count for that same population:&#039;&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(id) as Users  FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists the users who have only logged into the site once===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, username, firstname, lastname, idnumber&lt;br /&gt;
FROM prefix_user&lt;br /&gt;
WHERE prefix_user.deleted = 0&lt;br /&gt;
AND prefix_user.lastlogin = 0 &lt;br /&gt;
AND prefix_user.lastaccess &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Students in all courses of some institute===&lt;br /&gt;
What is the status (deleted or not) of all Students (roleid = 5) in all courses of some Institute&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname, u.firstname, u.lastname, u.deleted&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND u.institution = &#039;please enter school name here&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Full User info (for deleted users)===&lt;br /&gt;
Including extra custom profile fields (from prefix_user_info_data)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT * &lt;br /&gt;
FROM prefix_user as u &lt;br /&gt;
JOIN prefix_user_info_data as uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_user_info_field as uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;class&#039;)&lt;br /&gt;
WHERE `deleted` = &amp;quot;1&amp;quot; and `institution`=&amp;quot;your school name&amp;quot; and `department` = &amp;quot;your department&amp;quot; and `data` = &amp;quot;class level and number&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User&#039;s courses===&lt;br /&gt;
change &amp;quot;u.id = 2&amp;quot; with a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, c.id, c.fullname&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE u.id = 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Users with extra info (email) in current course===&lt;br /&gt;
blocks/configurable_reports replaces %%COURSEID%% with course id.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, u.email&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Students with enrollment and completion dates in current course===&lt;br /&gt;
This is meant to be a &amp;quot;global&amp;quot; report in Configurable Reports containing the following:&lt;br /&gt;
firstname, lastname, idnumber, institution, department, email, student enrolment date, student completion date&lt;br /&gt;
Note: for PGSQL, use to_timestamp() instead of FROM_UNIXTIME()&lt;br /&gt;
Contributed by Elizabeth Dalton, Moodle HQ&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.firstname&lt;br /&gt;
, u.lastname&lt;br /&gt;
, u.idnumber&lt;br /&gt;
, u.institution&lt;br /&gt;
, u.department&lt;br /&gt;
, u.email&lt;br /&gt;
, FROM_UNIXTIME(cc.timeenrolled)&lt;br /&gt;
, FROM_UNIXTIME(cc.timecompleted)&lt;br /&gt;
&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_completions AS cc ON cc.course = c.id AND cc.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Special Roles===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.roleid,r.name&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,ra.userid,&#039;&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Username&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON (ctx.id = ra.contextid AND ctx.contextlevel = 50)&lt;br /&gt;
JOIN prefix_course AS c ON ctx.instanceid = c.id&lt;br /&gt;
WHERE ra.roleid &amp;gt; 6&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses without Teachers===&lt;br /&gt;
Actually, shows the number of Teachers in a course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Teachers&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
ORDER BY Teachers ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of users who have been enrolled for more than 4 weeks===&lt;br /&gt;
For Moodle 2.2 , by  Isuru Madushanka Weerarathna &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT uenr.userid As User, IF(enr.courseid=uenr.courseid ,&#039;Y&#039;,&#039;N&#039;) As Enrolled, &lt;br /&gt;
IF(DATEDIFF(NOW(), FROM_UNIXTIME(uenr.timecreated))&amp;gt;=28,&#039;Y&#039;,&#039;N&#039;) As EnrolledMoreThan4Weeks&lt;br /&gt;
FROM prefix_enrol As enr, prefix_user_enrolments AS uenr&lt;br /&gt;
WHERE enr.id = uenr.enrolid AND enr.status = uenr.status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with language===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
This will show you the language setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, lang from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools.&lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;en&#039; to &#039;en_us&#039; for all users:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To do this for only users who have a particular country set, use this as an example:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE country = &#039;US&#039; AND lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with Authentication ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Sometimes you need to do mass changes of authentication methods. A common case is changing default manual to LDAP. &lt;br /&gt;
&lt;br /&gt;
This will show you the Authentication setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, auth from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools. &lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;manual&#039; to &#039;ldap&#039; 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.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET auth = &#039;ldap&#039; WHERE auth = &#039;manual&#039; AND id &amp;gt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compare role capability and permissions ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT mrc.capability &lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;1&#039; AND rc.contextid = &#039;1&#039;) AS Manager&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;2&#039; AND rc.contextid = &#039;1&#039;) AS CourseCreator&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;3&#039; AND rc.contextid = &#039;1&#039;) AS Teacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;4&#039; AND rc.contextid = &#039;1&#039;) AS AssistantTeacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;5&#039; AND rc.contextid = &#039;1&#039;) AS Student&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;6&#039; AND rc.contextid = &#039;1&#039;) AS Guest&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_role_capabilities` AS mrc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User&#039;s accumulative time spent in course ===&lt;br /&gt;
A sum up of the time delta between logstore_standard_log user&#039;s records, considering the a 2 hour session limit.&lt;br /&gt;
&lt;br /&gt;
Uses: current user&#039;s id %%USERID%% and current course&#039;s id %%COURSEID%%  &lt;br /&gt;
&lt;br /&gt;
And also using a date filter (which can be ignored)  &lt;br /&gt;
&lt;br /&gt;
The extra &amp;quot;User&amp;quot; field is used as a dummy field for the Line chart Series field, in which I use X=id, Series=Type, Y=delta.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
l.id, &lt;br /&gt;
l.timecreated, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(l.timecreated),&#039;%d-%m-%Y&#039;) AS dTime,&lt;br /&gt;
@prevtime := (SELECT max(timecreated) FROM mdl_logstore_standard_log &lt;br /&gt;
		WHERE userid = %%USERID%% and id &amp;lt; l.id ORDER BY id ASC LIMIT 1) AS prev_time,&lt;br /&gt;
IF (l.timecreated - @prevtime &amp;lt; 7200, @delta := @delta + (l.timecreated-@prevtime),0) AS sumtime,&lt;br /&gt;
l.timecreated-@prevtime AS delta,&lt;br /&gt;
&amp;quot;User&amp;quot; as type&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log as l, &lt;br /&gt;
(SELECT @delta := 0) AS s_init &lt;br /&gt;
# Change UserID&lt;br /&gt;
WHERE l.userid = %%USERID%% AND l.courseid = %%COURSEID%%&lt;br /&gt;
%%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Low-Participation Student Report ===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
This report returns a list of students who are enrolled in courses filtered by a short-name text marker (in this case &amp;quot;OL-&amp;quot;) in the specified category, but have very low participation in the course during the specified time period (fewer than 2 &amp;quot;Edits&amp;quot; to Activity Modules, indicating few active contributions to the course). The number of &amp;quot;Edits&amp;quot; is provided for each student for the time period specified.&lt;br /&gt;
&lt;br /&gt;
An &amp;quot;Edit&amp;quot; is defined as course activity other than viewing content. Click the &amp;quot;Logs&amp;quot; link to review the student activity. The Logs offer the option to review &amp;quot;View&amp;quot; activity as well as &amp;quot;Edit&amp;quot; activity.&lt;br /&gt;
&lt;br /&gt;
Only &amp;quot;visible&amp;quot; courses are included in this report. The report may be downloaded as an Excel spreadsheet.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t forget to set up Filters: &amp;quot;Start / End date filter&amp;quot; and &amp;quot;Filter categories&amp;quot; on the Filters tab in Configurable reports.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname AS Last, u.firstname AS First, u.idnumber AS IDnumber, u.email AS email, c.shortname AS CourseID,  count(l.id) AS Edits, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;https://learn.granite.edu/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=-view&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id AND l.action NOT LIKE &amp;quot;view%&amp;quot; %%FILTER_STARTTIME:l.TIME:&amp;gt;%% %%FILTER_ENDTIME:l.TIME:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.visible=1&lt;br /&gt;
# This prefix filter allows the exclusion of non-online courses at the original institution. Alter this to fit your institution, or remove it.&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
%%FILTER_CATEGORIES:c.category%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
HAVING Edits &amp;lt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Messages of All Users in a Specific Course ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
NOTE: This query will probably not work at all in 3.5 now due to the changes in the structure of the Messages database. - RT&lt;br /&gt;
&lt;br /&gt;
This query shows the personal messages between users in a specific course, given the course id number. Properly speaking, personal messages pertain only to users and are not part of courses, but by filtering enrollments for roles in a course, you can show this. &lt;br /&gt;
&lt;br /&gt;
This report as is shows only the messages between Teachers and Students, as the WHERE statement contains and AND ((...))) section that restrict this report to ONLY messages between Teachers (role id = 3) and Students (role id =5). Remove that part of the statement if you wish to see _all_ messages between all users, e.g. teachers to teachers, student to student. &lt;br /&gt;
&lt;br /&gt;
Also, if you have created custom roles, you can replace the default id numbers with custom ones to further enhance the report.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.username AS &#039;From&#039;,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS &#039;From Name&#039;,&lt;br /&gt;
u2.username AS &#039;To&#039;,&lt;br /&gt;
CONCAT(u2.firstname ,&#039; &#039;,u2.lastname) AS &#039;To Name&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(me.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;,&lt;br /&gt;
me.subject AS &#039;Subject&#039;, &lt;br /&gt;
me.smallmessage AS &#039;Message&#039;&lt;br /&gt;
FROM prefix_message me&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = me.useridfrom AND ra.roleid IN (3,4,5)  &lt;br /&gt;
JOIN prefix_role_assignments AS ra2 ON ra2.userid = me.useridto AND ra2.roleid IN (3,4,5)  &lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id AND ra2.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_user u ON u.id = me.useridfrom&lt;br /&gt;
JOIN prefix_user u2 ON u2.id = me.useridto&lt;br /&gt;
WHERE c.id=## &lt;br /&gt;
AND ((ra.roleid = 3 AND ra2.roleid = 5) OR (ra.roleid = 5 AND ra2.roleid = 3)) &lt;br /&gt;
ORDER BY me.useridfrom, me.useridto, me.timecreated&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Log Activity Reports==&lt;br /&gt;
===Count all Active Users by ROLE in a course category (including all of its sub-categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT l.userid) as active&lt;br /&gt;
FROM mdl_course as c&lt;br /&gt;
JOIN mdl_context AS ctx ON  ctx.instanceid=c.id&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN mdl_user_lastaccess as l ON ra.userid = l.userid&lt;br /&gt;
JOIN mdl_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category=cats.id AND (&lt;br /&gt;
	cats.path LIKE &#039;%/80/%&#039;&lt;br /&gt;
	OR cats.path LIKE &#039;%/80&#039;&lt;br /&gt;
) &lt;br /&gt;
AND ra.roleid=3  AND ctx.contextlevel=50  #ra.roleid= TEACHER 3, NON-EDITING TEACHER 4, STUDENT 5&lt;br /&gt;
AND  l.timeaccess &amp;gt; (unix_timestamp() - ((60*60*24)*NO_OF_DAYS)) #NO_OF_DAYS change to number&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Detailed &amp;quot;VIEW&amp;quot; ACTION for each ROLE (TEACHER,NONE-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT l.action, count( l.userid ) as counter , r.name&lt;br /&gt;
FROM `prefix_log` as l&lt;br /&gt;
JOIN `prefix_role_assignments` AS ra on l.userid = ra.userid&lt;br /&gt;
JOIN `prefix_role` AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE (ra.roleid IN (3,4,5)) AND (l.action LIKE &#039;%view%&#039; )&lt;br /&gt;
GROUP BY roleid,l.action&lt;br /&gt;
order by r.name,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total Activity of Roles:&amp;quot;Teacher&amp;quot; and &amp;quot;None-Editing Teacher&amp;quot; by Dates and by Hours===&lt;br /&gt;
The output columns of this report table can be used as base for a Pivot-Table&lt;br /&gt;
which will show the amount of &#039;&#039;&#039;activity&#039;&#039;&#039; per &#039;&#039;&#039;hour&#039;&#039;&#039; per &#039;&#039;&#039;days&#039;&#039;&#039; in 3D graph view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%Y-%m-%d&#039; ) AS grptimed ,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%k&#039; ) AS grptimeh  , count( l.userid ) AS counter &lt;br /&gt;
FROM `prefix_log` AS l&lt;br /&gt;
JOIN prefix_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
WHERE ra.roleid IN (3,4)&lt;br /&gt;
GROUP BY grptimed,grptimeh&lt;br /&gt;
ORDER BY grptimed,grptimeh&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many LOGINs per user and user&#039;s Activity===&lt;br /&gt;
+ link username to a user activity graph report&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,u.id,&#039;&amp;amp;mode=alllogs&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) as Username&lt;br /&gt;
,count(*) as logins&lt;br /&gt;
,(SELECT count(*) FROM prefix_log WHERE userid = l.userid GROUP BY userid) as Activity &lt;br /&gt;
FROM prefix_log as l JOIN prefix_user as u ON l.userid = u.id &lt;br /&gt;
WHERE `action` LIKE &#039;%login%&#039; group by userid&lt;br /&gt;
ORDER BY Activity DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Distinct user logins per month===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
The following will show you the months of the current calendar year with the total number of distinct, unique user logins per month. Change the year in the WHERE clause to the year you need.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
 COUNT(DISTINCT l.userid) AS &#039;DistinctUserLogins&#039;, &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%M&#039;) AS &#039;Month&#039;&lt;br /&gt;
FROM prefix_logstore_standard_log l&lt;br /&gt;
WHERE l.action = &#039;loggedin&#039; AND YEAR(FROM_UNIXTIME(l.timecreated)) = &#039;2017&#039; &lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(l.timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total activity per course, per unique user on the last 24h===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    COUNT(DISTINCT userid) AS countUsers&lt;br /&gt;
  , COUNT(l.courseid) AS countVisits&lt;br /&gt;
  , CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
  JOIN mdl_course AS c ON c.id = l.courseid&lt;br /&gt;
WHERE l.courseid &amp;gt; 0&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 1 DAY)&lt;br /&gt;
      AND c.fullname LIKE &#039;%תשעו%&#039;&lt;br /&gt;
GROUP BY l.courseid&lt;br /&gt;
ORDER BY countVisits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Instructor Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of instructors in all courses per week of a term, including pre-term and post-term edits. An edit is defined as a change to the course, such as a discussion post, the grading of an assignment, or the uploading of file attachments, as well as alterations to course content.&lt;br /&gt;
&lt;br /&gt;
* To specify a subject and/or course number, use % as a wildcard, e.g. ARTS% or ARTS501%&lt;br /&gt;
* To match part of a last name, use %, e.g. Smi% will match &amp;quot;Smith&amp;quot;, &amp;quot;Smile&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
At our institution, we include filters on the course name or category to constrain by terms. These are very specific to how course names and categories are constructed at our institution, so I&#039;ve removed those elements from this code. Also, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; lines for longer terms, or remove lines for shorter terms.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version uses legacy (pre-2.7) logs. See below for post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, c.startdate AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time)) - WEEK(FROM_UNIXTIME(c.startdate))&amp;lt;0,1,0)) AS BeforeTerm&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=0,1,0)) AS Week1&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=1,1,0)) AS Week2&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=2,1,0)) AS Week3&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=3,1,0)) AS Week4&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=4,1,0)) AS Week5&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=5,1,0)) AS Week6&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=6,1,0)) AS Week7&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=7,1,0)) AS Week8&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=8,1,0)) AS Week9&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=9,1,0)) AS Week10&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=10,1,0)) AS Week11&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=11,1,0)) AS Week12&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))&amp;gt;=12,1,0)) AS AfterTerm&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE :course&lt;br /&gt;
AND u.lastname LIKE :last_name&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 log version:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(DISTINCT l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
AND cc.idnumber LIKE &#039;%current%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
#HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY RIGHT(c.shortname,2), c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Student Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of students in the current course by week, including pre-term and post-term edits. An 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 (if permitted).&lt;br /&gt;
&lt;br /&gt;
Links to three other reports are also provided:&lt;br /&gt;
&lt;br /&gt;
* Logs: complete log entries for the student in the course, organized by date&lt;br /&gt;
* Activity Outline: the &amp;quot;Outline Report&amp;quot; from the User Activity Reports, summarizing the student&#039;s activity in the course, organized by course content&lt;br /&gt;
* Consolidated Activity Report: the &amp;quot;Complete Report&amp;quot; from the User Activity Reports, detailing the student&#039;s activity in the course, organized by course content (includes text of forum posts)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). At our institution, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for a post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF((l.time-c.startdate)/7&amp;lt;0,1,0)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=0,1,0)) AS &#039;Week 1&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=1,1,0)) AS &#039;Week 2&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=2,1,0)) AS &#039;Week 3&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=3,1,0)) AS &#039;Week 4&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=4,1,0)) AS &#039;Week 5&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=5,1,0)) AS &#039;Week 6&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=6,1,0)) AS &#039;Week 7&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=7,1,0)) AS &#039;Week 8&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=8,1,0)) AS &#039;Week 9&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=9,1,0)) AS &#039;Week 10&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=10,1,0)) AS &#039;Week 11&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=11,1,0)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))&amp;gt;=15,1,0)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 (Standard Logs) version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
# Our institution stores academic advisor names and emails in custom profile fields&lt;br /&gt;
#, CONCAT(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,uce.data,&#039;&amp;quot;&amp;gt;&#039;,uid.data, &#039;&amp;lt;/a&amp;gt;&#039;)  AS &#039;Academic Advisor&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,&#039;Posts&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Posts&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# student academic coach - you can include custom profile field data with these methods&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uid ON u.id = uid.userid AND uid.fieldid = &#039;2&#039;&lt;br /&gt;
# student academic coach email&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uce on u.id = uce.userid AND uce.fieldid = &#039;6&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===My Weekly Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of the &#039;&#039;&#039;current user&#039;&#039;&#039; in the &#039;&#039;&#039;current course&#039;&#039;&#039; 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).&lt;br /&gt;
&lt;br /&gt;
This report uses Standard Logs (post 2.7).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
l.component AS &#039;activity&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS &#039;Total&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE 1&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
AND u.id = %%USERID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY l.component&lt;br /&gt;
&lt;br /&gt;
ORDER BY l.component&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Faculty/Student Interactions===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Returns a count of instructor and other-student responses to student activity for the specified time period. This report can help indicate whether students&#039; comments are being responded to, as well as summarizing post activity by students during the specified time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for the post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This report can take a long time to run. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
LEFT JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
# We care about messages that involve both the instructor and students of this course&lt;br /&gt;
# messages from instructor to students:&lt;br /&gt;
# LEFT JOIN prefix_message AS mts ON mts.useridfrom = instr.id AND mts.useridto = allstu.id&lt;br /&gt;
# LEFT JOIN prefix_message AS mfs ON mfs.useridfrom = instr.id AND mfs.useridto = allstu.id&lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 Standard Logs version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
 JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student Resource Usage===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Standard Logs&amp;quot; from Moodle 2.7+.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
, m.name AS &#039;item type&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&lt;br /&gt;
COALESCE(a.name, &#039;&#039;), &lt;br /&gt;
COALESCE(b.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cert.name,&#039;&#039;), &lt;br /&gt;
COALESCE(chat.name,&#039;&#039;), &lt;br /&gt;
COALESCE(choice.name,&#039;&#039;), &lt;br /&gt;
COALESCE(data.name,&#039;&#039;), &lt;br /&gt;
COALESCE(feedback.name,&#039;&#039;), &lt;br /&gt;
COALESCE(folder.name,&#039;&#039;), &lt;br /&gt;
COALESCE(forum.name,&#039;&#039;), &lt;br /&gt;
COALESCE(glossary.name,&#039;&#039;), &lt;br /&gt;
COALESCE(imscp.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lesson.name,&#039;&#039;), &lt;br /&gt;
COALESCE(p.name,&#039;&#039;),&lt;br /&gt;
COALESCE(questionnaire.name,&#039;&#039;), &lt;br /&gt;
COALESCE(quiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cr.name,&#039;&#039;), &lt;br /&gt;
COALESCE(scorm.name,&#039;&#039;), &lt;br /&gt;
COALESCE(survey.name,&#039;&#039;), &lt;br /&gt;
COALESCE(url.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(workshop.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kalvidassign.name,&#039;&#039;), &lt;br /&gt;
COALESCE(attendance.name,&#039;&#039;), &lt;br /&gt;
COALESCE(checklist.name,&#039;&#039;), &lt;br /&gt;
COALESCE(flashcard.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lti.name,&#039;&#039;), &lt;br /&gt;
COALESCE(oublog.name,&#039;&#039;), &lt;br /&gt;
COALESCE(ouwiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(subpage.name,&#039;&#039;), &lt;br /&gt;
COALESCE(journal.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lightboxgallery.name,&#039;&#039;), &lt;br /&gt;
COALESCE(elluminate.name,&#039;&#039;), &lt;br /&gt;
COALESCE(adaptivequiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(hotpot.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiziq.name,&#039;&#039;), &lt;br /&gt;
COALESCE(turnitintooltwo.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kvr.name,&#039;&#039;)&lt;br /&gt;
) AS &#039;item name&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;r&#039;),1,0)) AS &#039;total views&#039;&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),1,0)) AS &#039;total submissions&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;r&#039;),u.id,NULL)) AS &#039;count of students who viewed&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),u.id,NULL)) AS &#039;count of students who submitted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 #AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module AND m.name NOT LIKE &#039;label&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON a.id = cm.instance AND m.name = &#039;assign&#039;&lt;br /&gt;
LEFT JOIN prefix_book AS b ON b.id = cm.instance AND m.name = &#039;book&#039;&lt;br /&gt;
LEFT JOIN prefix_certificate AS cert ON cert.id = cm.instance AND m.name = &#039;certificate&#039;&lt;br /&gt;
LEFT JOIN prefix_chat AS chat ON chat.id = cm.instance AND m.name = &#039;chat&#039;&lt;br /&gt;
LEFT JOIN prefix_choice AS choice ON choice.id = cm.instance AND m.name = &#039;choice&#039;&lt;br /&gt;
LEFT JOIN prefix_data AS data ON data.id = cm.instance AND m.name = &#039;data&#039;&lt;br /&gt;
LEFT JOIN prefix_feedback AS feedback ON feedback.id = cm.instance AND m.name = &#039;feedback&#039;&lt;br /&gt;
LEFT JOIN prefix_folder AS folder ON folder.id = cm.instance AND m.name = &#039;folder&#039;&lt;br /&gt;
LEFT JOIN prefix_forum AS forum ON forum.id = cm.instance AND m.name = &#039;forum&#039;&lt;br /&gt;
LEFT JOIN prefix_glossary AS glossary ON glossary.id = cm.instance AND m.name = &#039;glossary&#039;&lt;br /&gt;
LEFT JOIN prefix_imscp AS imscp ON imscp.id = cm.instance AND m.name = &#039;imscp&#039;&lt;br /&gt;
LEFT JOIN prefix_lesson AS lesson ON lesson.id = cm.instance AND m.name = &#039;lesson&#039;&lt;br /&gt;
LEFT JOIN prefix_page AS p ON p.id = cm.instance AND m.name = &#039;page&#039;&lt;br /&gt;
LEFT JOIN prefix_questionnaire AS questionnaire ON questionnaire.id = cm.instance AND m.name = &#039;questionnaire&#039;&lt;br /&gt;
LEFT JOIN prefix_quiz AS quiz ON quiz.id = cm.instance AND m.name = &#039;quiz&#039;&lt;br /&gt;
LEFT JOIN prefix_resource AS cr ON cr.id = cm.instance AND m.name = &#039;resource&#039;&lt;br /&gt;
LEFT JOIN prefix_scorm AS scorm ON scorm.id = cm.instance AND m.name = &#039;scorm&#039;&lt;br /&gt;
LEFT JOIN prefix_survey AS survey ON survey.id = cm.instance AND m.name = &#039;survey&#039;&lt;br /&gt;
LEFT JOIN prefix_url AS url ON url.id = cm.instance AND m.name = &#039;url&#039;&lt;br /&gt;
LEFT JOIN prefix_wiki AS wiki ON wiki.id = cm.instance AND m.name = &#039;wiki&#039;&lt;br /&gt;
LEFT JOIN prefix_workshop AS workshop ON workshop.id = cm.instance AND m.name = &#039;workshop&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidassign AS kalvidassign ON kalvidassign.id = cm.instance AND m.name = &#039;kalvidassign&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidres AS kvr ON kvr.id = cm.instance AND m.name = &#039;kalvidres&#039;&lt;br /&gt;
LEFT JOIN prefix_attendance AS attendance ON attendance.id = cm.instance AND m.name = &#039;attendance&#039;&lt;br /&gt;
LEFT JOIN prefix_checklist AS checklist ON checklist.id = cm.instance AND m.name = &#039;checklist&#039;&lt;br /&gt;
LEFT JOIN prefix_flashcard AS flashcard ON flashcard.id = cm.instance AND m.name = &#039;flashcard&#039;&lt;br /&gt;
LEFT JOIN prefix_lti AS lti ON lti.id = cm.instance AND m.name = &#039;lti&#039;&lt;br /&gt;
LEFT JOIN prefix_oublog AS oublog ON oublog.id = cm.instance AND m.name = &#039;oublog&#039;&lt;br /&gt;
LEFT JOIN prefix_ouwiki AS ouwiki ON ouwiki.id = cm.instance AND m.name = &#039;ouwiki&#039;&lt;br /&gt;
LEFT JOIN prefix_subpage AS subpage ON subpage.id = cm.instance AND m.name = &#039;subpage&#039;&lt;br /&gt;
LEFT JOIN prefix_journal AS journal ON journal.id = cm.instance AND m.name = &#039;journal&#039;&lt;br /&gt;
LEFT JOIN prefix_lightboxgallery AS lightboxgallery ON lightboxgallery.id = cm.instance AND m.name = &#039;lightboxgallery&#039;&lt;br /&gt;
LEFT JOIN prefix_elluminate AS elluminate ON elluminate.id = cm.instance AND m.name = &#039;elluminate&#039;&lt;br /&gt;
LEFT JOIN prefix_adaptivequiz AS adaptivequiz ON adaptivequiz.id = cm.instance AND m.name = &#039;adaptivequiz&#039;&lt;br /&gt;
LEFT JOIN prefix_hotpot AS hotpot ON hotpot.id = cm.instance AND m.name = &#039;hotpot&#039;&lt;br /&gt;
LEFT JOIN prefix_wiziq AS wiziq ON wiziq.id = cm.instance AND m.name = &#039;wiziq&#039;&lt;br /&gt;
LEFT JOIN prefix_turnitintooltwo AS turnitintooltwo ON turnitintooltwo.id = cm.instance AND m.name = &#039;turnitintooltwo&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cm.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Hits) between dates===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module, COUNT( * ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME( l.`time` ) BETWEEN  &#039;2012-10-01 00:00:00&#039; AND  &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
GROUP BY module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Instances and Hits) for each academic year===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2010-10-01 00:00:00&#039; AND &#039;2011-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2010-10-01 00:00:00&#039; AND &#039;2011-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2011-10-01 00:00:00&#039; AND &#039;2012-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2011&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2011-10-01 00:00:00&#039; AND &#039;2012-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2011&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2012-10-01 00:00:00&#039; AND &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2012&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2012-10-01 00:00:00&#039; AND &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2012&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_modules AS m&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Unique user sessions per day and month + graph===&lt;br /&gt;
The &amp;quot;graph&amp;quot; column is used when displaying a graph (which needs at least three columns to pick from)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT userid) AS &amp;quot;Unique User Logins&amp;quot;&lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y /%m / %d&amp;quot;) AS &amp;quot;Year / Month / Day&amp;quot;, &amp;quot;Graph&amp;quot; &lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE action LIKE &#039;loggedin&#039;&lt;br /&gt;
#AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) # optional start date&lt;br /&gt;
#AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:00&#039;) # optional end date&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And...&lt;br /&gt;
&lt;br /&gt;
Counting user&#039;s global and unique hits per day + counting individual usage of specific activities and resources (on that day),&lt;br /&gt;
&lt;br /&gt;
And since I am using phpMyAdmin&#039;s &amp;quot;Display Graph&amp;quot; feature (at the bottom of the query&#039;s output page), I have scaled down the &amp;quot;User Hits&amp;quot; by 10 to fit the graph. that&#039;s it.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y-%m-%d&amp;quot;) AS &amp;quot;Datez&amp;quot;&lt;br /&gt;
,COUNT(DISTINCT userid) AS &amp;quot;Unique Users&amp;quot;&lt;br /&gt;
,ROUND(COUNT(*)/10) &amp;quot;User Hits (K)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_quiz&#039;,1,0)) &amp;quot;Quizzes&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_forum&#039; or component=&#039;mod_forumng&#039;,1,0)) &amp;quot;Forums&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_assign&#039;,1,0)) &amp;quot;Assignments&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_oublog&#039;,1,0)) &amp;quot;Blogs&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_resource&#039;,1,0)) &amp;quot;Files (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_url&#039;,1,0)) &amp;quot;Links (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_page&#039;,1,0)) &amp;quot;Pages (Resource)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE 1=1&lt;br /&gt;
AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-03-01 00:00:00&#039;) # optional START DATE&lt;br /&gt;
AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-05-31 23:59:00&#039;) # optional END DATE&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide, daily unique user hits for the last 7 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
  DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%m%d&#039;) &#039;Day&#039;&lt;br /&gt;
  ,COUNT(DISTINCT l.userid) AS &#039;Distinct Users Hits&#039;&lt;br /&gt;
  ,COUNT( l.userid) AS &#039;Users Hits&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
WHERE l.courseid &amp;gt; 1&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 7 DAY)&lt;br /&gt;
GROUP BY DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User detailed activity in course modules===&lt;br /&gt;
Considering only several modules: url, resource, forum, quiz, questionnaire.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.id, ra.roleid,&lt;br /&gt;
CONCAT(u.lastname, &#039; &#039;, u.firstname) AS &#039;Student&#039;&lt;br /&gt;
,COUNT(l.id) AS &#039;Actions&#039;&lt;br /&gt;
,l.component &amp;quot;Module type&amp;quot;&lt;br /&gt;
,l.objectid &amp;quot;Module ID&amp;quot;&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN l.component = &#039;mod_url&#039; THEN (SELECT u.name FROM mdl_url AS u WHERE u.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_resource&#039; THEN (SELECT r.name FROM mdl_resource AS r WHERE r.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_forum&#039; THEN (SELECT f.name FROM mdl_forum AS f WHERE f.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_quiz&#039; THEN (SELECT q.name FROM mdl_quiz AS q WHERE q.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_questionnaire&#039; THEN (SELECT q.name FROM mdl_questionnaire AS q WHERE q.id = l.objectid )&lt;br /&gt;
END AS &#039;Module name&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = l.courseid AND m.userid = u.id) &amp;quot;user_groups&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT s.name &lt;br /&gt;
  FROM mdl_course_modules AS cm &lt;br /&gt;
  JOIN mdl_course_sections AS s ON s.course = cm.course AND s.id = cm.section &lt;br /&gt;
  WHERE cm.id = l.contextinstanceid) AS &amp;quot;Section name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l  &lt;br /&gt;
JOIN mdl_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.userid = l.userid &lt;br /&gt;
  AND ra.contextid = (SELECT id FROM mdl_context WHERE instanceid = l.courseid AND contextlevel = 50) &lt;br /&gt;
WHERE l.courseid = %%COURSEID%%&lt;br /&gt;
  AND l.component IN (&#039;mod_url&#039;, &#039;mod_resource&#039;, &#039;mod_forum&#039;, &#039;mod_quiz&#039;, &#039;mod_questionnaire&#039;) &lt;br /&gt;
  %%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%%&lt;br /&gt;
 &lt;br /&gt;
GROUP BY u.id, l.component&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What teachers and courses considered active?===&lt;br /&gt;
This report display several calculations and parameters that help the Online academic training team find teachers that might need more support getting their courses more supporting of online learning pedagogical methodologies.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,&lt;br /&gt;
			  course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
#,course.shortname&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2012%&#039; THEN &#039;2012&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2013%&#039; THEN &#039;2013&#039; &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2014%&#039; THEN &#039;2014&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2015%&#039; THEN &#039;2015&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester a%&#039; THEN &#039;Spring semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester b%&#039; THEN &#039;Fall semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester s%&#039; THEN &#039;Summer semester&#039;&lt;br /&gt;
END AS Semester&lt;br /&gt;
&lt;br /&gt;
,IF(course.startdate&amp;gt;0, DATE_FORMAT(FROM_UNIXTIME(startdate), &#039;%d-%m-%Y&#039;), &#039;no date&#039;) AS &amp;quot;Course Start Date&amp;quot; &lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 4 AND ctx.instanceid = course.id&lt;br /&gt;
) AS &amp;quot;Assistant teacher&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
&lt;br /&gt;
# Uncomment to use the new Moodle 2.8+ logstore&lt;br /&gt;
#,(SELECT COUNT(*) FROM mdl_logstore_standard_log AS l WHERE l.courseid = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Student HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Teacher HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_log AS l WHERE l.course = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course c&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = c.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND c.id = course.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
  &lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = course.id) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(DISTINCT cm.module) FROM prefix_course_modules cm &lt;br /&gt;
  WHERE cm.course = course.id) UniqueModules&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(DISTINCT m.name) &lt;br /&gt;
  FROM prefix_course_modules cm &lt;br /&gt;
  JOIN mdl_modules as m ON m.id = cm.module&lt;br /&gt;
  WHERE cm.course = course.id) UniqueModuleNames&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;ouwiki&#039;, &#039;wiki&#039;) ) &amp;quot;Num Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;oublog&#039;) ) &amp;quot;Num Blogs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;forum&#039;, &#039;forumng&#039;) ) &amp;quot;Num Forums&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;resource&#039;, &#039;folder&#039;, &#039;url&#039;, &#039;tab&#039;, &#039;file&#039;, &#039;book&#039;, &#039;page&#039;) ) Resources&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;forum&#039;, &#039;forumng&#039;, &#039;oublog&#039;, &#039;page&#039;, &#039;file&#039;, &#039;url&#039;, &#039;wiki&#039; , &#039;ouwiki&#039;) ) &amp;quot;Basic Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;advmindmap&#039;, &#039;assign&#039;, &#039;attendance&#039;, &#039;book&#039;, &#039;choice&#039;, &#039;folder&#039;, &#039;tab&#039;, &#039;glossary&#039;, &#039;questionnaire&#039;, &#039;quiz&#039;, &#039;label&#039; ) ) &amp;quot;Avarage Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;elluminate&#039;, &#039;game&#039;, &#039;workshop&#039;) ) &amp;quot;Advanced Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course&lt;br /&gt;
&lt;br /&gt;
#WHERE course.shortname LIKE &#039;%2015%&#039;&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_SEARCHTEXT:course.shortname:~%%&lt;br /&gt;
&lt;br /&gt;
WHERE course.fullname LIKE &#039;%2015%&#039; &lt;br /&gt;
&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY UniqueModules DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly attendance report===&lt;br /&gt;
This report display weekly report in format HH:M:SS This MySQL query works together with AttendaceRegister module, and gather Log information from Attendanceregister_log table. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, SEC_TO_TIME (SUM(arsess.duration)) AS weekly_online_attendance,  FROM_UNIXTIME (arsess.logout) AS Last_Logout&lt;br /&gt;
FROM prefix_attendanceregister_session AS arsess&lt;br /&gt;
JOIN prefix_user AS u ON arsess.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE (((arsess.logout) BETWEEN UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 7 DAY)) AND UNIX_TIMESTAMP(CURDATE())))&lt;br /&gt;
&lt;br /&gt;
GROUP BY arsess.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many distinct users connected to Moodle using the app by month===&lt;br /&gt;
https://moodle.org/mod/forum/discuss.php?d=336086#p1354194 by &lt;br /&gt;
Iñigo Zendegi Urzelai&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;) as year, &lt;br /&gt;
  to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;) as month, &lt;br /&gt;
  count(distinct userid) as distinct_users&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log m&lt;br /&gt;
WHERE m.origin=&#039;ws&#039;&lt;br /&gt;
GROUP BY to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;), to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;) &lt;br /&gt;
ORDER BY to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;YYYY&#039;), to_char(to_timestamp(&amp;quot;timecreated&amp;quot;),&#039;MM&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Course Reports==&lt;br /&gt;
===Most Active courses===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(l.userid) AS Views&lt;br /&gt;
FROM `mdl_logstore_standard_log` l, `mdl_user` u, `mdl_role_assignments` r&lt;br /&gt;
WHERE l.courseid=35&lt;br /&gt;
AND l.userid = u.id&lt;br /&gt;
AND (l.timecreated &amp;gt; UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) AND l.timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:59&#039;))AND r.contextid= (&lt;br /&gt;
	 SELECT id&lt;br /&gt;
	 FROM mdl_context&lt;br /&gt;
	 WHERE contextlevel=50 AND instanceid=l.courseid&lt;br /&gt;
 )&lt;br /&gt;
AND r.roleid=5&lt;br /&gt;
AND r.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active courses, advanced===&lt;br /&gt;
Including: Teacher&#039;s name, link to the course, All types of log activities, special YEAR generated field, Activities and Resource count, enrolled Student count&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשע&#039; THEN &#039;תשע&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעא&#039; THEN &#039;תשעא&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעב&#039; THEN &#039;תשעב&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = l.course) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_log l &lt;br /&gt;
INNER JOIN prefix_course c ON l.course = c.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
#The following line restricts the courses returned to those having more than 2 modules.  Adjust based on your needs.&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY Year DESC, hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Least active or probably empty courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;-1&amp;quot; instead of &amp;quot;0&amp;quot; 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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
c.fullname,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;CourseLink&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timecreated&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timemodified&#039;,&lt;br /&gt;
CASE&lt;br /&gt;
 WHEN c.timecreated = c.timemodified THEN &#039;-1&#039;&lt;br /&gt;
 ELSE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated))&lt;br /&gt;
END AS &#039;DateDifference&#039;,&lt;br /&gt;
COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
LEFT JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
WHERE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated) ) &amp;lt; 60&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
HAVING COUNT(ue.id) &amp;lt;= 3&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Count unique teachers with courses that use at least X module (Moodle19)===&lt;br /&gt;
You can remove the outer &amp;quot;SELECT COUNT(*) FROM (...) AS ActiveTeachers&amp;quot; SQL query and get the list of the Teachers and Courses.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(*)&lt;br /&gt;
FROM (SELECT c.id AS CourseID, c.fullname AS Course, ra.roleid AS RoleID, CONCAT(u.firstname, &#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = c.id) AS Modules&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid AND ctx.contextlevel = 50 &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE  ra.roleid = 3 &lt;br /&gt;
GROUP BY u.id&lt;br /&gt;
HAVING Modules &amp;gt; 5) AS ActiveTeachers&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RESOURCE count for each COURSE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) count, l.course, c.fullname coursename&lt;br /&gt;
FROM prefix_resource l INNER JOIN prefix_course c on l.course = c.id&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY count DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Common resource types count for each Category (Moodle19)===&lt;br /&gt;
Including sub-categories in total count.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category&lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Links&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference NOT LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Files&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;directory&#039; &lt;br /&gt;
) AS Folders&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;html&#039; &lt;br /&gt;
) AS Pages&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM stats_log_context_role_course &lt;br /&gt;
WHERE roleid = 5 AND module = &#039;resource&#039; AND category = mcc.id&lt;br /&gt;
) AS Hits&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Where &amp;quot;stats_log_context_role_course&amp;quot; (in the above SQL query) is a VIEW generated by:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
CREATE VIEW stats_log_context_role_course AS&lt;br /&gt;
SELECT l.course, c.category, cc.path, l.module, l.action, ra.userid, ra.roleid&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = l.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Same query but for Moodle2+&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category,&lt;br /&gt;
mcc.path,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_url AS u&lt;br /&gt;
JOIN prefix_course AS c ON c.id = u.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS URLs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_folder AS f&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS FOLDERs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_page AS p&lt;br /&gt;
JOIN prefix_course AS c ON c.id = p.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS PAGEs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_book AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS BOOKs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_label AS l&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS LABELs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_tab AS t&lt;br /&gt;
JOIN prefix_course AS c ON c.id = t.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS TABs&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed Resource COUNT by Teacher in each course===&lt;br /&gt;
&lt;br /&gt;
Including (optional) filter by: year, semester and course id.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
, c.id&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעב%&#039; THEN &#039;2012&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעא%&#039; THEN &#039;2011&#039;&lt;br /&gt;
END ) as Year&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר א%&#039; THEN &#039;Semester A&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ב%&#039; THEN &#039;Semester B&#039;&lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ק%&#039; THEN &#039;Semester C&#039;&lt;br /&gt;
END ) as Semester&lt;br /&gt;
,COUNT(c.id) AS Total&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 20) AS TABs&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 33) AS BOOKs&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_resource` as r &lt;br /&gt;
JOIN `prefix_course` AS c on c.id = r.course&lt;br /&gt;
#WHERE type= &#039;file&#039; and reference NOT LIKE &#039;http://%&#039; &lt;br /&gt;
&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
#AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY COUNT(c.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses that are defined as using GROUPs===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/group/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = c.id) Modules&lt;br /&gt;
,(SELECT count(*) FROM prefix_groups g WHERE g.courseid = c.id) Groups&lt;br /&gt;
 FROM `prefix_course` AS c&lt;br /&gt;
WHERE groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Groups===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with Groups in them (groupmode &amp;gt; 0). You can also use groupmode=1 to list just Separate type groups or groupmode=2 to list Visible type groups.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name, c.groupmode&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON c.id = g.courseid&lt;br /&gt;
WHERE c.groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users enrolled in a course with groups but not assigned a group ===&lt;br /&gt;
&lt;br /&gt;
Displays by course all enrolled users that have not been assigned a group in courses that have groups. NOTE: This needs to be optimized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) AS ROLE&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = course.id&lt;br /&gt;
&lt;br /&gt;
WHERE ue.enrolid NOT IN (select userid from prefix_groups_members WHERE g.id=groupid)&lt;br /&gt;
&lt;br /&gt;
ORDER BY Course, Lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Groups in course with member list===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List the groups in a course (replace the # by the course id number) with the members of each group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name AS Groupname, u.username&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_user AS u ON m.userid = u.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Group Export===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
There&#039;s a [[Import_groups|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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT g.name AS groupname, g.description, g.enrolmentkey&lt;br /&gt;
FROM prefix_groups AS g &lt;br /&gt;
JOIN prefix_course as c ON g.courseid = c.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Courses in and below a certain category===&lt;br /&gt;
Use this SQL code to retrieve all courses that exist in or under a set category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the category you want to know about...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course. * , prefix_course_categories. *&lt;br /&gt;
FROM prefix_course, prefix_course_categories&lt;br /&gt;
WHERE prefix_course.category = prefix_course_categories.id&lt;br /&gt;
AND (&lt;br /&gt;
prefix_course_categories.path LIKE &#039;/$s/%&#039;&lt;br /&gt;
OR prefix_course_categories.path LIKE &#039;/$s&#039;&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Categories in one level below a certain category===&lt;br /&gt;
Use this PHP code to retrieve a list of all categories below a certain category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the top level category you are interested in.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
require_once(&#039;./config.php&#039;);&lt;br /&gt;
&lt;br /&gt;
$parent_id = $s;&lt;br /&gt;
&lt;br /&gt;
$categories= array();&lt;br /&gt;
&lt;br /&gt;
$categories = get_categories($parent_id);&lt;br /&gt;
&lt;br /&gt;
echo &#039;&amp;lt;ol&amp;gt;&#039;;&lt;br /&gt;
foreach ($categories as $category)&lt;br /&gt;
        {&lt;br /&gt;
        echo &#039;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&#039;.$CFG-&amp;gt;wwwroot.&#039;/course/category.php?id=&#039;.$category-&amp;gt;id.&#039;&amp;quot;&amp;gt;&#039;.$category-&amp;gt;name.&#039;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
        }&lt;br /&gt;
echo &#039;&amp;lt;/ol&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Blog activity per Course (not including VIEW)===&lt;br /&gt;
Filter activity logging to some specific Course Categories!&lt;br /&gt;
+ link course name to actual course (for quick reference)&lt;br /&gt;
(you can change %blog% to %wiki% to filter down all wiki activity or any other module you wish)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID&lt;br /&gt;
,m.name ,count(cm.id) as counter &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS Students&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE `module` LIKE &#039;%blog%&#039; AND course = c.id AND action NOT LIKE &#039;%view%&#039; ) as BlogActivity&lt;br /&gt;
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 &lt;br /&gt;
WHERE m.name LIKE &#039;%blog%&#039; AND c.category IN ( 8,13,15)&lt;br /&gt;
GROUP BY cm.course,cm.module order by counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student&#039;s posts content in all course blogs (oublog)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
b.name &lt;br /&gt;
,op.title&lt;br /&gt;
,op.message&lt;br /&gt;
,( SELECT CONCAT(u.firstname, &#039; &#039;,u.lastname) FROM prefix_user AS u WHERE u.id = oi.userid) AS &amp;quot;Username&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_oublog_posts AS op&lt;br /&gt;
JOIN prefix_oublog_instances AS oi ON oi.id = op.oubloginstancesid &lt;br /&gt;
JOIN prefix_oublog as b ON b.id = oi.oublogid&lt;br /&gt;
JOIN prefix_course AS c ON b.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Courses which uploaded a Syllabus file===&lt;br /&gt;
+ under specific Category&lt;br /&gt;
+ show first Teacher in that course&lt;br /&gt;
+ link Course&#039;s fullname to actual course&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) as Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user as u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) as Teacher&lt;br /&gt;
FROM prefix_resource as r &lt;br /&gt;
JOIN prefix_course as c ON r.course = c.id&lt;br /&gt;
WHERE ( r.name LIKE &#039;%סילבוס%&#039; OR r.name LIKE &#039;%סילאבוס%&#039; OR r.name LIKE &#039;%syllabus%&#039; OR r.name LIKE &#039;%תכנית הקורס%&#039; ) &lt;br /&gt;
AND c.category IN (10,18,26,13,28)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
===Site-wide completed SCORM activities by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===All users enrolled in a course without a role===&lt;br /&gt;
Identifies All users that are enrolled in a course but are not assigned a role.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user.firstname AS Firstname,&lt;br /&gt;
user.lastname AS Lastname,&lt;br /&gt;
user.idnumber Employee_ID,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user as user ON user.id = ue.userid&lt;br /&gt;
&lt;br /&gt;
WHERE user.id NOT IN (&lt;br /&gt;
SELECT u.id&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE c.id=course.id&lt;br /&gt;
)&lt;br /&gt;
ORDER BY Course, Lastname, Firstname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List course resources accumulative file size and count===&lt;br /&gt;
This is the main (first) report, which has a link (alias) to a second report (the following on this page) which list each file in the course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id &amp;quot;CourseID&amp;quot;, context.id &amp;quot;ContextID&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;, c.id, &#039;&amp;quot;&amp;gt;&#039;, c.fullname ,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Course Name&amp;quot;&lt;br /&gt;
, COUNT(*) &amp;quot;Course Files&amp;quot; , ROUND( SUM( f.filesize ) /1048576 ) AS file_size_MB&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/blocks/configurable_reports/viewreport.php?alias=coursefiles&amp;amp;courseid=1&amp;amp;filter_courses=&#039;, c.id, &#039;&amp;quot;&amp;gt;List files&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List Files&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
JOIN mdl_context AS context ON context.id = f.contextid&lt;br /&gt;
JOIN mdl_course AS c ON c.id = (&lt;br /&gt;
  SELECT instanceid&lt;br /&gt;
  FROM mdl_context&lt;br /&gt;
  WHERE id = SUBSTRING_INDEX( SUBSTRING_INDEX( context.path, &#039;/&#039; , -2 ) , &#039;/&#039;, 1 ) )&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this report, you will have to define &amp;quot;alias&amp;quot; report property to &amp;quot;coursefiles&amp;quot; for it to be able to be called from the above report.&lt;br /&gt;
And also setup (add) a FILTER_COURSES filter. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id ,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/pluginfile.php/&#039;, contextid, &#039;/&#039;, component, &#039;/&#039;, filearea, &#039;/&#039;, itemid, &#039;/&#039;, filename, &#039;&amp;quot;&amp;gt;&#039;, filename,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;File&amp;quot;&lt;br /&gt;
,filesize, mimetype ,author, license, timecreated, component, filearea, filepath&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
            AND f.contextid&lt;br /&gt;
            IN (   SELECT id&lt;br /&gt;
                     FROM mdl_context&lt;br /&gt;
                    WHERE path &lt;br /&gt;
                     LIKE (   SELECT CONCAT(&#039;%/&#039;,id,&#039;/%&#039;)&lt;br /&gt;
                                  AS contextquery&lt;br /&gt;
                                FROM mdl_context&lt;br /&gt;
                               WHERE 1=1&lt;br /&gt;
			        %%FILTER_COURSES:instanceid%%&lt;br /&gt;
                                 AND contextlevel = 50&lt;br /&gt;
                           )&lt;br /&gt;
                )&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Which courses has redundant topics===&lt;br /&gt;
This report list several &amp;quot;active topics&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
The following, second SQL query, could be used to &amp;quot;trim&amp;quot; down those redundant course topics/sections/weeks by updating the course format&#039;s numsection (Number of sections) setting. (It&#039;s a per course format setting!)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, format,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT value  FROM  `mdl_course_format_options` WHERE  `courseid` = c.id AND `format` = c.format AND `name` = &#039;numsections&#039; ) AS &amp;quot;numsections&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND `sequence` !=  &#039;&#039; ) AS &amp;quot;Non empty sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id ) AS &amp;quot;Total section count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND sequence IS NOT NULL) AS &amp;quot;Non NULL sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND name != &#039;&#039;) AS &amp;quot;Non empty section Name count&amp;quot;&lt;br /&gt;
 ,(SELECT COUNT(*) FROM mdl_course_modules cm WHERE cm.course = c.id) &amp;quot;Modules count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course AS c&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following SQL REPLACE query is used for &amp;quot;fixing&amp;quot; (updating) the &amp;quot;numsections&amp;quot; of a specific course format &amp;quot;onetopics&amp;quot; (you can always change it, or discard it to use this SQL REPLACE on all course formats) &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
REPLACE INTO `mdl_course_format_options` (`id`, `courseid`, `format`, `sectionid`, `name`, `value`) &lt;br /&gt;
SELECT NULL, c.id, &#039;onetopic&#039;, &#039;0&#039;, &#039;numsections&#039;, (SELECT COUNT(*) FROM `mdl_course_sections` WHERE `course` = c.id AND name != &#039;&#039;)&lt;br /&gt;
FROM `mdl_course` c where format = &#039;onetopic&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hidden Courses with Students Enrolled===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.visible AS Visible, &lt;br /&gt;
DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors,&lt;br /&gt;
&lt;br /&gt;
(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;, &lt;br /&gt;
&lt;br /&gt;
now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
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) &amp;gt; 0&lt;br /&gt;
ORDER BY StartDate, Instructor_Email, Course_ID&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Course Design Reports==&lt;br /&gt;
&lt;br /&gt;
These are reports which summarize course design aspects, such as activity and resource modules per section, types of activities used, etc.&lt;br /&gt;
&lt;br /&gt;
===Course Content/Week===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report assumes that the first 14 sections in a course, not including the &amp;quot;0&amp;quot; or &amp;quot;Welcome&amp;quot; section, correspond to weeks (with &amp;quot;Subsections&amp;quot; given numbers much higher in the sequence). Of those sections, each is checked to count the number of:&lt;br /&gt;
&lt;br /&gt;
    Forums&lt;br /&gt;
    Graded Activities (may include Forums)&lt;br /&gt;
    Resources (not including a Label)&lt;br /&gt;
&lt;br /&gt;
Totals of each of these types of content elements per section are provided.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Only visible resources and activities are counted.&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: this is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
 &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT LIKE &#039;label&#039;),cm.id,NULL)) AS &#039;Ungraded Resources&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Graded Activities&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cs.section&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments and Weights===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Categories with weights of 0 are not included in this report.&lt;br /&gt;
&lt;br /&gt;
Only visible activities are included in this report.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This is designed to be a &amp;quot;Global&amp;quot; report in Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;) AS &#039;Grade Book Category&#039;&lt;br /&gt;
, IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND(SUM(DISTINCT gi.aggregationcoef), 2)+ROUND(SUM(DISTINCT mgi.aggregationcoef), 2)) AS &#039;Category weight&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT_WS(&#039;, &#039;,GROUP_CONCAT(DISTINCT gi.itemmodule SEPARATOR &#039;, &#039;), IF(mgi.id, &#039;manual&#039;,NULL)) AS &#039;Activity Types&#039;&lt;br /&gt;
, COUNT(DISTINCT gi.itemmodule) + IF(mgi.id,1,0) AS &#039;Different Activity Types&#039;&lt;br /&gt;
, CONCAT_WS(&#039;&amp;lt;br&amp;gt;&#039;, GROUP_CONCAT(DISTINCT gi.itemname ORDER BY gi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;), GROUP_CONCAT(DISTINCT mgi.itemname ORDER BY mgi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;)) AS &#039;Activity Names&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) + COUNT(DISTINCT mgi.id) AS &#039;Activity Count&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
&lt;br /&gt;
#get grade categories&lt;br /&gt;
LEFT JOIN prefix_grade_categories AS gc ON gc.courseid = c.id &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
JOIN prefix_grade_items AS gic ON gic.courseid = c.id AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
&lt;br /&gt;
# attach activities to course&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = c.id &lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.iteminstance = cm.instance AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.id&lt;br /&gt;
ORDER BY gc.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pre-Term Course Review===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
#   &amp;quot;Required blocks&amp;quot; include Instructor Block (mooprofile), Activities, and the Research block.&lt;br /&gt;
#    &amp;quot;Instructor Details&amp;quot; block is not the &amp;quot;Instructor&amp;quot; block (mooprofile) automatically provided by the system. It is an optional block that can be edited by the instructor. If not edited to remove boilerplate text, it should be hidden.&lt;br /&gt;
#    All courses should be in the &amp;quot;Collapsed Topics&amp;quot; format with the &amp;quot;Weeks&amp;quot; structure.&lt;br /&gt;
#    &amp;quot;Weeks defined in course settings&amp;quot; is taken from our SIS when the course shells are created, but can be edited by faculty. &amp;quot;# of weeks named and visible&amp;quot; should usually match or exceed this value.&lt;br /&gt;
#    We recommend that each week contain at least one forum, at least one graded activity, and at least one ungraded resource.&lt;br /&gt;
#    &amp;quot;Syllabus updated&amp;quot; date is for the first attached file found with the text &amp;quot;syllabus&amp;quot; in the name. The &amp;quot;Days ago&amp;quot; calculation is included for convenience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: At our institution, we construct categories each term, and insert a text string &amp;quot;staging&amp;quot; in the Category ID for pre-term courses during the preparation or &amp;quot;staging&amp;quot; phase of course development. We remove this text string (and change it to &amp;quot;production&amp;quot;) when courses go live at the start of the new term.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
#,RIGHT(c.idnumber,2) AS Type # Specific to GSC &amp;quot;Instructional Method&amp;quot; storage&lt;br /&gt;
&lt;br /&gt;
#, substring_index(substr(c.shortname FROM locate(&#039;.&#039;,c.shortname)+1),&#039;-&#039;,1) AS Section # Specific to GSC&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.lastname,&#039;, &#039;, u.firstname,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
,(SELECT IF((u2.description IS NULL) OR (u2.description LIKE &#039;&#039;),&#039;NO&#039;, &#039;YES&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT IF(u3.picture &amp;gt; 0,&#039;YES&#039;,&#039;NO&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u3 ON u3.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Picture&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(((bpi.visible IS NULL) OR (bpi.visible !=0)) AND ((bpm.visible IS NULL) OR (bpm.visible !=0)) AND ((bpa.visible IS NULL) OR (bpa.visible !=0)) AND ((bpr.visible IS NULL) OR (bpr.visible !=0)),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Required blocks visible&#039;&lt;br /&gt;
#, IF((bpm.visible IS NULL) OR (bpm.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Messages block visible&#039;&lt;br /&gt;
#, IF((bpa.visible IS NULL) OR (bpa.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;activities block visible&#039;&lt;br /&gt;
#, IF((bpr.visible IS NULL) OR (bpr.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;research block visible&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)) AND (bip.visible !=0),&#039;YES&#039;,&#039;&#039;) AS &#039;Instructor Details Block visible&#039; # This is a hack based on UUencoded string data from the title of HTML &amp;quot;Instructor Details&amp;quot; block&lt;br /&gt;
&lt;br /&gt;
#, IF(bi.configdata LIKE &#039;%ZGl0IHRoaXMgYmxvY2s%&#039;,&#039;NO&#039;,&#039;&#039;) AS &#039;Instructor Details Block Updated&#039; # HTML block has string &#039;dit this block&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(COUNT(bi.id) -  SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)),&#039;YES&#039;,&#039;&#039;) AS &#039;possible extra instructor blocks&#039; #looking for any HTML block with &amp;quot;instructor&amp;quot; in the title&lt;br /&gt;
&lt;br /&gt;
, IF(c.format=&#039;topcoll&#039;,&#039;YES&#039;, c.format) AS &#039;Collapsed Topics course format&#039; # change this if you want to test for a different format&lt;br /&gt;
, IF(cfo.value = 2, &#039;YES&#039;,&#039;NO&#039;) AS &#039;weeks structure&#039;&lt;br /&gt;
&lt;br /&gt;
, cfw.value AS &#039;weeks defined in course settings&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(((cs.name IS NOT NULL) AND (cs.visible = 1) AND (cs.section != &#039;0&#039;) AND (cs.sequence IS NOT NULL)),cs.id,NULL)) AS &#039;# of weeks named &amp;amp; visible (includes orphans)&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039; ,cs.id , NULL)) AS &#039;Weeks with Forum&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cs.id, NULL)) AS &#039;Weeks with Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT mgi.id) AS &#039;Manual Grade Items&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)),cm.id,NULL)) AS &#039;Resources&#039;&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)), cs.id, NULL)) AS &#039;Weeks with Resources&#039;&lt;br /&gt;
&lt;br /&gt;
# Here are some other things you could check for per course&lt;br /&gt;
#,(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 &#039;%forum%&#039;) AS Forums&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%quiz%&#039;) AS Quizzes&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%assign%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_resource.id) FROM prefix_resource JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course) AS Files&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_url.id) FROM prefix_url JOIN prefix_course ON prefix_course.id = prefix_url.course WHERE c.id = prefix_url.course) AS Links&lt;br /&gt;
&lt;br /&gt;
,(SELECT FROM_UNIXTIME(MAX(prefix_resource.timemodified))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS SyllabusDate&lt;br /&gt;
&lt;br /&gt;
,(SELECT TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(MAX(prefix_resource.timemodified)))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS DaysAgo&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, f.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement Forum Visible&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, fd.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement posted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
LEFT JOIN prefix_context AS ctxx ON c.id = ctxx.instanceid &lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpi ON bpi.contextid = ctxx.id AND bpi.blockinstanceid = &#039;43692&#039; # mooprofile&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpm ON bpm.contextid = ctxx.id AND bpm.blockinstanceid = &#039;43962&#039; # messages&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpa ON bpa.contextid = ctxx.id AND bpa.blockinstanceid = &#039;43963&#039; # activities&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpr ON bpr.contextid = ctxx.id AND bpr.blockinstanceid = &#039;38368&#039; # html research help&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.visible = 1 AND cs.sequence IS NOT NULL&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
LEFT JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_forum AS f ON f.course = c.id AND cm.instance = f.id AND cm.visible = 1&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.forum = f.id&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfo ON cfo.courseid = c.id AND cfo.name = &#039;layoutstructure&#039;&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfw ON cfw.courseid = c.id AND cfw.name = &#039;numsections&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_instances AS bi ON bi.parentcontextid = ctxx.id AND bi.blockname = &#039;html&#039; AND (bi.configdata LIKE &#039;%SW5zdHJ1Y3Rvc%&#039; or bi.configdata LIKE &#039;%bnN0cnVjdG9y%&#039;)&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bip ON bip.blockinstanceid = bi.id&lt;br /&gt;
&lt;br /&gt;
WHERE RIGHT(c.idnumber,2) IN (&#039;OL&#039;, &#039;BL&#039;, &#039;HY&#039;) &lt;br /&gt;
# AND substring(cc.path,2,2) IN (&#039;26&#039;) # Staging&lt;br /&gt;
#AND substring(cc.path,2,3) IN (&#039;158&#039;) # UG&lt;br /&gt;
AND cc.idnumber LIKE &#039;%staging%&#039;&lt;br /&gt;
AND ctxx.contextlevel = 50&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module instances + Module HITs by role teacher and student in course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
m.name AS &amp;quot;Module name&amp;quot;&lt;br /&gt;
, COUNT(*) AS &amp;quot;Module count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name ) AS &amp;quot;Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course_modules AS cm&lt;br /&gt;
JOIN mdl_modules AS m on m.id = cm.module&lt;br /&gt;
WHERE cm.course = &#039;%%COURSEID%%&#039;&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Syllabus===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Course Policies&amp;quot; and &amp;quot;Teaching Philosophy&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.fullname AS &#039;fullname&#039;&lt;br /&gt;
, ec.idnumber AS &#039;elis-id&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.startdate), &#039;%b %e, %Y&#039;) AS &#039;start&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.enddate), &#039;%b %e, %Y&#039;) AS &#039;end&#039;&lt;br /&gt;
, ecd.name AS &#039;longname&#039;&lt;br /&gt;
, ecd.code AS &#039;coursecode&#039;&lt;br /&gt;
, ecd.credits AS &#039;coursecredits&#039;&lt;br /&gt;
, ecd.syllabus AS &#039;description&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;learning-outcomes&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;outcomes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.firstname,&#039; &#039;, u.lastname,&#039;&amp;lt;/a&amp;gt; &#039;, u.email)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
, (SELECT  efc.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_char AS efc&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = efc.fieldid AND ef.shortname = &#039;term-code&#039;&lt;br /&gt;
WHERE ctxci.id = efc.contextid) AS &#039;termcode&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;prerequisites&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;prerequisites&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;textbooks&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;textbooks&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;other-class-materials&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;other-class-materials&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-policies&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-policies&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;teaching-philosophy&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;teaching-philosophy&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-methods&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-methods&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT u2.description&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT&lt;br /&gt;
&lt;br /&gt;
GROUP_CONCAT(DISTINCT CONCAT(&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;tr&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt;&#039;,IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;)&lt;br /&gt;
, &#039; &amp;lt;/td&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt; &#039;&lt;br /&gt;
,IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND( gi.aggregationcoef, 2)+ROUND(mgi.aggregationcoef, 2))&lt;br /&gt;
&lt;br /&gt;
) SEPARATOR &#039;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&#039;)&lt;br /&gt;
#get grade categories&lt;br /&gt;
FROM prefix_grade_categories AS gc &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gic ON gic.courseid = gc.courseid AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = gc.courseid  AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = gc.courseid and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
WHERE gc.courseid = c.id  ) AS &#039;grade categories&#039;&lt;br /&gt;
&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;50%&amp;quot; &amp;gt;&#039; AS &#039;table start&#039;&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;100%&amp;quot; &amp;gt;&#039; AS &#039;table start 2&#039;&lt;br /&gt;
, &#039;&amp;lt;/table&amp;gt;&#039; AS &#039;table end&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;activities-schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;schedule&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;grading-scale&#039;&lt;br /&gt;
WHERE ctxepm.id = eft.contextid) AS &#039;gradescale&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
# connect moodle course to ELIS class instance&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls_mdl AS ecm ON ecm.moodlecourseid = c.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls AS ec ON ec.id = ecm.classid&lt;br /&gt;
# class instance context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxci ON ctxci.instanceid = ec.id AND ctxci.contextlevel = &#039;14&#039;&lt;br /&gt;
&lt;br /&gt;
# connect ELIS class instance to ELIS course description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_crs AS ecd ON ecd.id = ec.courseid&lt;br /&gt;
# course description context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxecd ON ctxecd.instanceid = ecd.id AND ctxecd.contextlevel = &#039;13&#039;&lt;br /&gt;
&lt;br /&gt;
#connect ELIS program to ELIS Course Description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm_crs AS epc ON epc.courseid = ecd.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm AS epm ON epm.id = epc.curriculumid&lt;br /&gt;
# course program context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxepm ON ctxepm.instanceid = epm.id AND ctxepm.contextlevel = &#039;11&#039;&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Activities Helper===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report provides a list of the graded activities in a course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: Only graded activities are displayed.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This report assumes that course sections each last one week.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
# 303 Course Activities Helper&lt;br /&gt;
&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
gi.itemmodule AS &#039;activity type&#039;&lt;br /&gt;
# cs.section AS &#039;section number&#039;&lt;br /&gt;
&lt;br /&gt;
# Calculation assumes each section lasts one week&lt;br /&gt;
, CONCAT(DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section-1))), &#039;%b %e, %Y&#039;),&#039; - &amp;lt;br&amp;gt;&#039;,DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section))), &#039;%b %e, %Y&#039;)) AS &#039;Date&#039;&lt;br /&gt;
&lt;br /&gt;
, gi.itemname AS &#039;activity name&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = cm.instance) AS &#039;intro&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT f.intro FROM prefix_forum AS f WHERE f.id = cm.instance) AS &#039;f intro&#039;&lt;br /&gt;
&lt;br /&gt;
, CASE gi.itemmodule &lt;br /&gt;
WHEN &#039;assign&#039; THEN (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;forum&#039; THEN (SELECT f.intro FROM prefix_forum AS f WHERE f.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;quiz&#039; THEN (SELECT q.intro FROM prefix_quiz AS q WHERE q.id = gi.iteminstance) &lt;br /&gt;
END AS &#039;test case&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT GROUP_CONCAT(CONCAT(&#039; - &#039;,gi.itemname) SEPARATOR &#039;&amp;lt;BR&amp;gt;&#039;) FROM  prefix_grade_items AS gi  JOIN prefix_course_modules AS cm ON  gi.iteminstance = cm.instance WHERE gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id ) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
#get grade sections&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id  AND cs.section &amp;gt; 0 AND cs.section &amp;lt;=14&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_assign AS asg ON asg.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_grade_items AS gi  ON  gi.iteminstance = cm.instance AND gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
&lt;br /&gt;
ORDER BY gi.itemmodule, cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Grade and Course Completion Reports==&lt;br /&gt;
===Site-Wide Grade Report with All Items===&lt;br /&gt;
Shows grades for all course items along with course totals for each student. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, &lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
For MySQL users, you&#039;ll need to use the MySQL DATE_ADD function instead of DATEADD. Replace the line:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
And:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
CONCAT(u.firstname,&#039; &#039;,u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site-Wide Grade Report with Just Course Totals===&lt;br /&gt;
A second site-wide grade report for all students that just shows course totals. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id AND gi.itemtype = &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For MySQL users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN CONCAT(c.fullname, &#039; - Total&#039;)&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS TIME&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
 &lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Learner report by Learner with grades===&lt;br /&gt;
Which Learners in which course and what are the grades&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;Name&#039; , u.lastname AS &#039;Surname&#039;, c.fullname AS &#039;Course&#039;, cc.name AS &#039;Category&#039;, &lt;br /&gt;
CASE WHEN gi.itemtype = &#039;Course&#039;    &lt;br /&gt;
THEN c.fullname + &#039; Course Total&#039;  &lt;br /&gt;
ELSE gi.itemname &lt;br /&gt;
END AS &#039;Item Name&#039;, ROUND(gg.finalgrade,2) AS Score,ROUND(gg.rawgrademax,2) AS Max, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) as Percentage,&lt;br /&gt;
&lt;br /&gt;
if (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) &amp;gt; 79,&#039;Yes&#039; , &#039;No&#039;) as Pass&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id &lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid &lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category &lt;br /&gt;
WHERE  gi.courseid = c.id and gi.itemname != &#039;Attendance&#039;&lt;br /&gt;
ORDER BY `Name` ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A very simple report with a list of course completion status by username. Completions are noted by date, blank otherwise. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  u.username, &lt;br /&gt;
  c.shortname,  &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%Y-%m-%d&#039;) AS completed&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion with Criteria===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A report with course completions by username, with Aggregation method, Criteria types, and Criteria detail where available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username AS user, &lt;br /&gt;
c.shortname AS course,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(t.timecompleted),&#039;%Y-%m-%d&#039;) AS completed,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = c.id AND a.criteriatype IS NULL) = 1) THEN &amp;quot;Any&amp;quot;&lt;br /&gt;
ELSE &amp;quot;All&amp;quot;&lt;br /&gt;
END AS aggregation,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;Self&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN &amp;quot;By Date&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 3 THEN &amp;quot;Unenrol Status&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &amp;quot;Activity&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 5 THEN &amp;quot;Duration&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 6 THEN &amp;quot;Course Grade&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 7 THEN &amp;quot;Approve by Role&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 8 THEN &amp;quot;Previous Course&amp;quot;&lt;br /&gt;
END AS criteriatype,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;*&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(p.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN p.criteriatype = 3 THEN t.unenroled&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,p.module,&#039;/view.php?id=&#039;,p.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,p.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN p.criteriatype = 5 THEN p.enrolperiod&lt;br /&gt;
WHEN p.criteriatype = 6 THEN CONCAT(&#039;Needed: &#039;,ROUND(p.gradepass,2),&#039; Achieved: &#039;,ROUND(t.gradefinal,2)) &lt;br /&gt;
WHEN p.criteriatype = 7 THEN p.role&lt;br /&gt;
WHEN p.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = p.courseinstance)&lt;br /&gt;
END AS criteriadetail &lt;br /&gt;
FROM prefix_course_completion_crit_compl AS t&lt;br /&gt;
JOIN prefix_user AS u ON t.userid = u.id&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
JOIN prefix_course_completion_criteria AS p ON t.criteriaid = p.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Completion Enabled and their settings===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with completion enabled and their Aggregation setting, Criteria types, and Criteria details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT c.shortname AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = t.course AND a.criteriatype IS NULL)) = 2 THEN &amp;quot;All&amp;quot;&lt;br /&gt;
ELSE &amp;quot;Any&amp;quot;&lt;br /&gt;
END AS Course_Aggregation,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;Self completion&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN &amp;quot;Date done by&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;Unenrolement&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 4 THEN &amp;quot;Activity completion&amp;quot;   &lt;br /&gt;
WHEN t.criteriatype = 5 THEN &amp;quot;Duration in days&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 6 THEN &amp;quot;Final grade&amp;quot;     &lt;br /&gt;
WHEN t.criteriatype = 7 THEN &amp;quot;Approve by role&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 8 THEN &amp;quot;Previous course&amp;quot;&lt;br /&gt;
END AS Criteria_type,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(t.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 4 THEN&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,t.module,&#039;/view.php?id=&#039;,t.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,t.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN t.criteriatype = 5 THEN ROUND(t.enrolperiod/86400)&lt;br /&gt;
WHEN t.criteriatype = 6 THEN ROUND(t.gradepass,2)&lt;br /&gt;
WHEN t.criteriatype = 7 THEN (SELECT r.shortname FROM prefix_role AS r WHERE r.id = t.role)&lt;br /&gt;
WHEN t.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = t.courseinstance)&lt;br /&gt;
END AS Criteria_detail&lt;br /&gt;
FROM prefix_course_completion_criteria as t&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Completion Report with custom dates===&lt;br /&gt;
&lt;br /&gt;
List of users who completed multiple or single course/s from a start date to end date chosen by the user. The output gives username, name, course name, completion date and score&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT u.username AS &#039;User Name&#039;,&lt;br /&gt;
CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Name&#039;,&lt;br /&gt;
c.shortname AS &#039;Course Name&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%W %e %M, %Y&#039;) AS &#039;Completed Date&#039;,&lt;br /&gt;
ROUND(c4.gradefinal,2) AS &#039;Score&#039;&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
JOIN prefix_course_completion_crit_compl AS c4 ON u.id = c4.userid&lt;br /&gt;
WHERE c.enablecompletion = 1  AND (p.timecompleted IS NOT NULL OR p.timecompleted !=&#039;&#039;) &lt;br /&gt;
AND (p.timecompleted&amp;gt;= :start_date AND p.timecompleted&amp;lt;=:end_date)&lt;br /&gt;
GROUP BY u.username&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scales used in activities===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT scale.name&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,gi.itemmodule,&#039;/view.php?id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module View&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/modedit.php?up&#039;,&#039;date=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module Settings&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON c.id = gi.courseid&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = gi.courseid AND cm.instance = gi.iteminstance&lt;br /&gt;
JOIN prefix_scale AS scale ON scale.id = gi.scaleid&lt;br /&gt;
WHERE gi.scaleid IS NOT NULL&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Extra Credit Items by Name Only===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
This query identifies grade items in visible courses with student enrollment that have &amp;quot;extra credit&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, gi.itemname AS Item_Name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors&lt;br /&gt;
&lt;br /&gt;
,(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;&lt;br /&gt;
&lt;br /&gt;
,now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON gi.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE gi.itemname LIKE &#039;%extra credit%&#039; &lt;br /&gt;
	AND gi.gradetype = &#039;1&#039; &lt;br /&gt;
	AND gi.hidden = &#039;0&#039; &lt;br /&gt;
	AND gi.aggregationcoef = &#039;0&#039; &lt;br /&gt;
	AND c.visible = 1&lt;br /&gt;
	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) &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
GROUP BY Course_ID, gi.id&lt;br /&gt;
ORDER BY StartDate, Course_ID&lt;br /&gt;
 &lt;br /&gt;
%%FILTER_SEARCHTEXT:Course_ID:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site Wide Number of Courses Completed by User===&lt;br /&gt;
Contributed by Ken St. John&lt;br /&gt;
&lt;br /&gt;
Simple report that shows the number of completed courses for all users site wide&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname, u.firstname,&lt;br /&gt;
COUNT(p.timecompleted) AS TotalCompletions&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
GROUP BY p.userid&lt;br /&gt;
ORDER BY u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Activity Module Reports==&lt;br /&gt;
&lt;br /&gt;
=== User activity completions with dates===&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.username As &#039;User&#039;,&lt;br /&gt;
c.shortname AS &#039;Course&#039;,&lt;br /&gt;
m.name AS Activitytype, &lt;br /&gt;
CASE &lt;br /&gt;
    WHEN cm.module = 1 THEN (SELECT a1.name FROM prefix_assign a1            WHERE a1.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 2 THEN (SELECT a2.name FROM prefix_assignment a2    WHERE a2.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 3 THEN (SELECT a3.name FROM prefix_book a3               WHERE a3.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 4 THEN (SELECT a4.name FROM prefix_chat a4                WHERE a4.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 5 THEN (SELECT a5.name FROM prefix_choice a5            WHERE a5.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 6 THEN (SELECT a6.name FROM prefix_data a6                WHERE a6.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 7 THEN (SELECT a7.name FROM prefix_feedback a7        WHERE a7.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 8 THEN (SELECT a8.name FROM prefix_folder a8              WHERE a8.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 9 THEN (SELECT a9.name FROM prefix_forum a9              WHERE a9.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 10 THEN (SELECT a10.name FROM prefix_glossary a10         WHERE a10.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 11 THEN (SELECT a11.name FROM prefix_imscp  a11           WHERE a11.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 12 THEN (SELECT a12.name FROM prefix_label a12              WHERE a12.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 13 THEN (SELECT a13.name FROM prefix_lesson a13            WHERE a13.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 14 THEN (SELECT a14.name FROM prefix_lti a14                    WHERE a14.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 15 THEN (SELECT a15.name FROM prefix_page a15               WHERE a15.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 16 THEN (SELECT a16.name FROM prefix_quiz  a16               WHERE a16.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 17 THEN (SELECT a17.name FROM prefix_resource a17         WHERE a17.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 18 THEN (SELECT a18.name FROM prefix_scorm a18             WHERE a18.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 19 THEN (SELECT a19.name FROM prefix_survey a19             WHERE a19.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 20 THEN (SELECT a20.name FROM prefix_url a20                      WHERE a20.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 21 THEN (SELECT a21.name FROM prefix_wiki a21                    WHERE a21.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 22 THEN (SELECT a22.name FROM prefix_workshop a22           WHERE a22.id = cm.instance)&lt;br /&gt;
END AS Actvityname,&lt;br /&gt;
# cm.section AS Coursesection,&lt;br /&gt;
CASE&lt;br /&gt;
    WHEN cm.completion = 0 THEN &#039;0 None&#039;&lt;br /&gt;
    WHEN cm.completion = 1 THEN &#039;1 Self&#039;&lt;br /&gt;
    WHEN cm.completion = 2 THEN &#039;2 Auto&#039;&lt;br /&gt;
END AS Activtycompletiontype, &lt;br /&gt;
CASE&lt;br /&gt;
   WHEN cmc.completionstate = 0 THEN &#039;In Progress&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 1 THEN &#039;Completed&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 2 THEN &#039;Completed with Pass&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 3 THEN &#039;Completed with Fail&#039;&lt;br /&gt;
   ELSE &#039;Unknown&#039;&lt;br /&gt;
END AS &#039;Progress&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(cmc.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;&lt;br /&gt;
FROM prefix_course_modules_completion cmc &lt;br /&gt;
JOIN prefix_user u ON cmc.userid = u.id&lt;br /&gt;
JOIN prefix_course_modules cm ON cmc.coursemoduleid = cm.id&lt;br /&gt;
JOIN prefix_course c ON cm.course = c.id&lt;br /&gt;
JOIN prefix_modules m ON cm.module = m.id&lt;br /&gt;
# skip the predefined admin and guest user&lt;br /&gt;
WHERE u.id &amp;gt; 2&lt;br /&gt;
# config reports filters&lt;br /&gt;
%%FILTER_USERS:u.username%%&lt;br /&gt;
%%FILTER_SEARCHTEXT:m.name:~%%&lt;br /&gt;
%%FILTER_STARTTIME:cmc.timemodified:&amp;gt;%% %%FILTER_ENDTIME:cmc.timemodified:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many SCORM activities are used in each Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cm.course,c.fullname ,m.name &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/scorm/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,count(cm.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS Counter&lt;br /&gt;
 &lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
  JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
  JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%scorm%&#039; &lt;br /&gt;
GROUP BY cm.course,cm.module &lt;br /&gt;
ORDER BY count(cm.id) desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===SCORM Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of SCORM activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, scm.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;SCO%&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_scorm AS scm ON scm.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LTI (External Tool) Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of  LTI (External Tool) Usage activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, lti.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;lti&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_lti AS lti ON lti.id = cm.instance&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each MODULE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module,action,count(id) as counter&lt;br /&gt;
FROM prefix_log&lt;br /&gt;
GROUP BY module,action&lt;br /&gt;
ORDER BY module,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Most popular ACTIVITY===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, module&lt;br /&gt;
FROM prefix_log l&lt;br /&gt;
WHERE module != &#039;login&#039; AND module != &#039;course&#039; AND module != &#039;role&#039;&lt;br /&gt;
GROUP BY module&lt;br /&gt;
ORDER BY hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide use of ACTIVITIES and RESOURCES===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count( cm.id ) AS counter, m.name&lt;br /&gt;
FROM `prefix_course_modules` AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
ORDER BY counter DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LOG file ACTIONS per MODULE per COURSE (IDs)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select course,module,action,count(action) as summa from prefix_log&lt;br /&gt;
where action &amp;lt;&amp;gt; &#039;new&#039;&lt;br /&gt;
group by course,action,module&lt;br /&gt;
order by course,module,action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System Wide usage count of various course Activities===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
Like: Forum, Wiki, Blog, Assignment, Database,&lt;br /&gt;
#Within specific category&lt;br /&gt;
#Teacher name in course&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS Forums&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%data%&#039;) AS Databses&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%assignment%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 18)&lt;br /&gt;
ORDER BY Wikis DESC,Blogs DESC, Forums DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course wiki usage/activity over the last 6 semesters===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &amp;quot;Courses with Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester A%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester A&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester B%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester B&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed WIKI activity (per wiki per course)===&lt;br /&gt;
Including Number of Students in course (for reference)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID  &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id ) AS Students&lt;br /&gt;
,m.name&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%updat%&#039; ) as &#039;UPDAT E&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%annotate%&#039; ) as ANNOTATE&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%comment%&#039; ) as COMMENT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%add%&#039; ) as &#039;A DD&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%edit%&#039; ) as EDIT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action NOT LIKE &#039;%view%&#039; ) as &#039;All (NO View)&#039;&lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
GROUP BY cm.course,cm.module&lt;br /&gt;
ORDER BY &#039;All (NO View)&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wiki usage, system wide===&lt;br /&gt;
(you can filter the output by selecting some specific course categories : &amp;quot;WHERE c.category IN ( 8,13,15)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039;) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%add%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ADD&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%edit%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;EDIT&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%annotate%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ANNOTATE&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%comments%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;Comments&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_ouwiki_pages as ouwp&lt;br /&gt;
JOIN prefix_ouwiki as ouw ON ouw.id = ouwp.subwikiid&lt;br /&gt;
WHERE ouw.course = c.id GROUP BY ouw.course  ) as OUWikiPages&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( DISTINCT nwp.pagename ) FROM prefix_wiki_pages AS nwp&lt;br /&gt;
JOIN prefix_wiki AS nw ON nw.id = nwp.dfwiki WHERE nw.course = c.id ) As NWikiPages&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Wikis &amp;gt; 0&lt;br /&gt;
ORDER BY &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Aggregated Teacher activity by &amp;quot;WEB2&amp;quot; Modules===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
The NV column shows activity without VIEW log activity&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.userid, u.firstname,u.lastname&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039;) AS Wiki&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Wiki_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039;) AS Forum&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Forum_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039;) AS Blog&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Blog_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039;) AS Assignment&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Assignment_NV&lt;br /&gt;
FROM prefix_role_assignments AS ra &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
WHERE ra.roleid = 3 &lt;br /&gt;
GROUP BY ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the certificates issued, sort by variables in the custom profile fields===&lt;br /&gt;
Note: The SQL queries look intimidating at first, but isn&#039;t really that difficult to learn. I&#039;ve seen in the forums that users wanted to do &#039;site-wide&#039; groups in 1.9x. This is sort of the idea. It pulls all the certificates issued to all users sorted by the custom profile fields, which in my case is the Units or Depts (i.e. my site wide groups). Why certificates? I&#039;ve explored with both grades and quizzes, the course admins are not really interested in the actual grades but whether the learner received a certificate (i.e. passed the course with x, y, z activities). It also saves me from creating groups and assigning them into the right groups. Even assigning in bulk is not efficient, since I have upward of 25 groups per course and constantly new learners enrolling in courses. The limitation is something to do with the server? as it only pull 5000 rows of data. If anyone figured out how to change this, please let me know. In the meantime, the work around is to pull only a few units/depts at a time to limit the number of rows. This is fine at the moment, since each course admin are only responsible for certain units/depts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(prefix_certificate_issues.timecreated), &#039;%Y-%m-%d&#039; ) AS Date,&lt;br /&gt;
prefix_certificate_issues.classname AS Topic,&lt;br /&gt;
prefix_certificate.name AS Certificate,&lt;br /&gt;
prefix_certificate_issues.studentname as Name,&lt;br /&gt;
prefix_user_info_data.data AS Units&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_certificate_issues&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_user_info_data&lt;br /&gt;
on prefix_certificate_issues.userid = prefix_user_info_data.userid&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_certificate&lt;br /&gt;
on prefix_certificate_issues.certificateid = prefix_certificate.id&lt;br /&gt;
&lt;br /&gt;
WHERE prefix_user_info_data.data=&#039;Unit 1&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 2&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 3&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY Units, Name, Topic ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== All Simple Certificates Earned in the Site===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 [http://www.mysqltutorial.org/mysql-date_format/ DATE_FORMAT] function.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
CONCAT (u.firstname, &#039; &#039;,u.lastname) As &#039;User&#039;,&lt;br /&gt;
c.fullname AS &#039;Course&#039;,&lt;br /&gt;
sc.name AS &#039;Certificate&#039;,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(sci.timecreated), &#039;%Y-%m-%d&#039; ) As &#039;Date Awarded&#039;&lt;br /&gt;
# sci.code &#039;CertificateId&#039;&lt;br /&gt;
FROM prefix_simplecertificate_issues sci&lt;br /&gt;
JOIN prefix_user u ON sci.userid = u.id&lt;br /&gt;
JOIN prefix_simplecertificate sc ON sci.certificateid = sc.id&lt;br /&gt;
JOIN prefix_course AS c ON sc.course = c.id&lt;br /&gt;
ORDER BY sci.timecreated DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE DATEDIFF(NOW(),FROM_UNIXTIME(sci.timecreated) ) &amp;lt; 30&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Counter Blog usage in Courses,system wide===&lt;br /&gt;
What teachers in what courses, uses blogs and how many + student count in that course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT ( @counter := @counter+1) as counter, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c, (SELECT @counter := 0) as s_init&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Blogs &amp;gt; 0&lt;br /&gt;
ORDER BY Blogs DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Elluminate (Blackboard Collaborate) - system wide usage===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT e.name As Session ,er.recordingsize&lt;br /&gt;
,c.fullname As Course&lt;br /&gt;
,u.firstname,u.lastname &lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(e.timestart),&#039;%d-%m-%Y&#039;) AS dTimeStart&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/moodle/mod/elluminate/loadrecording.php?id=&#039;,er.id,&#039;&amp;quot;&amp;gt;Show&amp;lt;/a&amp;gt;&#039;) AS RecordedSession&lt;br /&gt;
&lt;br /&gt;
FROM prefix_elluminate_recordings AS er&lt;br /&gt;
JOIN prefix_elluminate AS e ON e.meetingid = er.meetingid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = e.creator &lt;br /&gt;
ORDER BY er.recordingsize DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choice ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Results of the Choice activity. For all courses, shows course shortname, username, the Choice text, and the answer chosen by the user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname AS course, u.username, h.name as question, o.text AS answer&lt;br /&gt;
FROM prefix_choice AS h&lt;br /&gt;
JOIN prefix_course AS c ON h.course = c.id&lt;br /&gt;
JOIN prefix_choice_answers AS a ON h.id = a.choiceid&lt;br /&gt;
JOIN prefix_user AS u ON a.userid = u.id&lt;br /&gt;
JOIN prefix_choice_options AS o ON a.optionid = o.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment type usage in courses ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assign/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_assign WHERE c.id = course) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;file&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
#GROUP BY apc.plugin&lt;br /&gt;
) AS &amp;quot;File Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;onlinetext&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Online Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;pdf&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;PDF Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;offline&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Offline Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;comments&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Assignments Comments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_assign AS assign&lt;br /&gt;
JOIN prefix_course AS c ON c.id = assign.course&lt;br /&gt;
GROUP BY c.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Assignment Module Reports==&lt;br /&gt;
===All Ungraded Assignments===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
Returns all the submitted assignments that still need grading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id&lt;br /&gt;
and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Ungraded Assignments w/ Link===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;a href=&amp;quot;http://education.varonis.com/mod/assignment/submissions.php&#039; + char(63) +&lt;br /&gt;
+ &#039;id=&#039; + cast(cm.id as varchar) + &#039;&amp;amp;userid=&#039; + cast(u.id as varchar) &lt;br /&gt;
+ &#039;&amp;amp;mode=single&amp;amp;filter=0&amp;amp;offset=2&amp;quot;&amp;gt;&#039; + a.name + &#039;&amp;lt;/a&amp;gt;&#039;&lt;br /&gt;
AS &amp;quot;Assignmentlink&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments (and Quizzes) waiting to be graded===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This report requires a YEAR filter to be added (Available when using the latest block/configurable_reports)&lt;br /&gt;
&lt;br /&gt;
Which you can always remove, to make this query work on earlier versions.&lt;br /&gt;
&lt;br /&gt;
The report includes: &lt;br /&gt;
*number of quizzes&lt;br /&gt;
*unFinished Quiz attempts&lt;br /&gt;
*Finished Quiz attempts&lt;br /&gt;
*number of students&lt;br /&gt;
*number of Assignments&lt;br /&gt;
*number of submitted answers by students &lt;br /&gt;
*number of unchecked assignments (waiting for the Teacher) in a Course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
 &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assignment/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;מטלות&amp;lt;/a&amp;gt;&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;בחנים&amp;lt;/a&amp;gt;&#039;) AS &#039;Quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_course_modules cm &lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module &lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039; AND cm.course = c.id &lt;br /&gt;
GROUP BY cm.course &lt;br /&gt;
) AS &#039;nQuizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish = 0&lt;br /&gt;
GROUP BY q.course) AS &#039;unFinished Quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish &amp;gt; 0&lt;br /&gt;
GROUP BY q.course) AS &#039;finished quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS nStudents&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(a.id)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) nAssignments&lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE a.course = c.id AND FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course&lt;br /&gt;
) &#039;Open &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(ROUND( (100 / iAssignments ) * iOpenAssignments ) ,&#039;%&#039;) &#039;unFinished &amp;lt;br/&amp;gt;Assignments &amp;lt;br/&amp;gt;(percent)&#039;&lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE asb.grade &amp;lt; 0 AND cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;unChecked  &amp;lt;br/&amp;gt;Submissions&#039; &lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;Submitted  &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblAssignmentsCount ON tblAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iOpenAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblOpenAssignmentsCount ON tblOpenAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1  &lt;br /&gt;
#AND c.fullname LIKE &#039;%תשעג%&#039;&lt;br /&gt;
%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
ORDER BY &#039;Open &amp;lt;br/&amp;gt;Assignments&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rubrics without zero values in criteria===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
Rubric calculations in Moodle can fail to align with instructors expectations if they lack a zero value for each criterion used in the assessment. From documentation at https://docs.moodle.org/32/en/Rubrics#Grade_calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;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.&lt;br /&gt;
TIP: To avoid confusion from this sort of thing, we recommend including a level with 0 points in every rubric criterion.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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&#039; favor.&lt;br /&gt;
&lt;br /&gt;
Includes search filter of course idnumber.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cat.name AS Department, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, &lt;br /&gt;
c.fullname AS Course_Name, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/grading/form/rubric/edit.php&#039;,CHAR(63),&#039;areaid=&#039;,gd.areaid,&#039;&amp;quot;&amp;gt;&#039;,gd.areaid,&#039;&amp;lt;/a&amp;gt;&#039;) AS Rubric&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_categories AS cat &lt;br /&gt;
ON cat.id = c.category&lt;br /&gt;
JOIN prefix_course_modules AS cm &lt;br /&gt;
ON c.id=cm.course&lt;br /&gt;
JOIN prefix_context AS ctx &lt;br /&gt;
ON cm.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_grading_areas AS garea &lt;br /&gt;
ON ctx.id = garea.contextid&lt;br /&gt;
JOIN prefix_grading_definitions AS gd &lt;br /&gt;
ON garea.id = gd.areaid&lt;br /&gt;
JOIN prefix_gradingform_rubric_criteria AS crit &lt;br /&gt;
ON gd.id = crit.definitionid&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id&lt;br /&gt;
WHERE cm.visible=&#039;1&#039; AND garea.activemethod = &#039;rubric&#039; AND (crit.id NOT IN&lt;br /&gt;
(SELECT crit.id&lt;br /&gt;
FROM prefix_gradingform_rubric_criteria AS crit&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id WHERE levels.score = &#039;0&#039;))&lt;br /&gt;
&lt;br /&gt;
GROUP BY Rubric&lt;br /&gt;
ORDER BY Course_ID, Rubric&lt;br /&gt;
&lt;br /&gt;
%%FILTER_SEARCHTEXT:c.idnumber:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Who is using &amp;quot;Single File Upload&amp;quot; assignment===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,ass.name as &amp;quot;Assignment Name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM &lt;br /&gt;
prefix_assignment as ass&lt;br /&gt;
&lt;br /&gt;
JOIN &lt;br /&gt;
prefix_course as c ON c.id = ass.course&lt;br /&gt;
&lt;br /&gt;
WHERE `assignmenttype` LIKE &#039;uploadsingle&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Feedback Module Reports==&lt;br /&gt;
===List the answers to all the Feedback activities within the current course, submitted by the current user===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT /* crs.fullname as &amp;quot;Course name&amp;quot;, f.name AS &amp;quot;Journal name&amp;quot;, CONCAT(u.firstname,&#039; &#039;,UPPER(u.lastname)) as &amp;quot;Participant&amp;quot;, */ /* include these fields if you want to check the composition of the recordset */&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified),&#039;%W %e %M, %Y&#039;) as &amp;quot;Answer Date&amp;quot;,&lt;br /&gt;
CASE i.typ WHEN &#039;label&#039; THEN i.presentation ELSE i.name END as &amp;quot;Topic&amp;quot;,  /* usually labels are used as section titles, so you&#039;d want them present in the recordset */&lt;br /&gt;
v.value as &amp;quot;My Answer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback AS f&lt;br /&gt;
INNER JOIN prefix_course as crs on crs.id=f.course %%FILTER_COURSES:f.course%% &lt;br /&gt;
INNER JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
INNER JOIN prefix_feedback_completed AS c on f.id=c.feedback %%FILTER_COURSEUSER:c.userid%% &lt;br /&gt;
LEFT JOIN prefix_feedback_value AS v on v.completed=c.id AND v.item=i.id&lt;br /&gt;
INNER JOIN prefix_user AS u on c.userid=u.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%% AND u.id = %%USERID%%  AND c.anonymous_response = 1  /* This clause limits the recordset to the current course and the current user and includes/ excludes the anonymous responses as needed */&lt;br /&gt;
&lt;br /&gt;
ORDER BY f.id, c.timemodified, i.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show all Feedbacks from all courses for all users including showing names of anonymous users===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &#039;Not-logged-in&#039; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS Course, &lt;br /&gt;
f.name AS Feedback,&lt;br /&gt;
# i.id AS Itemid,&lt;br /&gt;
i.name AS Itemname,&lt;br /&gt;
i.label AS Itemlabel,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN f.anonymous = 1 AND u.id != 0 THEN CONCAT(u.username, &#039; :ANON&#039;)&lt;br /&gt;
 WHEN fc.userid = 0 THEN &#039;Not-logged-in&#039;&lt;br /&gt;
 ELSE u.username&lt;br /&gt;
END AS &#039;User&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(fc.timemodified),&#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;Completed&amp;quot;,&lt;br /&gt;
v.value AS &amp;quot;Choice&amp;quot;,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN i.typ = &#039;multichoice&#039; THEN&lt;br /&gt;
     IF (  SUBSTRING(i.presentation,1,6)=&#039;d&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&#039;,&lt;br /&gt;
	       SUBSTRING(i.presentation,7),&lt;br /&gt;
		   i.presentation)&lt;br /&gt;
 ELSE i.presentation&lt;br /&gt;
END AS &amp;quot;Answers&amp;quot;,&lt;br /&gt;
i.typ,&lt;br /&gt;
i.dependitem,&lt;br /&gt;
i.dependvalue&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback f&lt;br /&gt;
JOIN prefix_course c ON c.id=f.course &lt;br /&gt;
JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
JOIN prefix_feedback_completed fc ON f.id=fc.feedback&lt;br /&gt;
LEFT JOIN prefix_feedback_value v ON v.completed=fc.id AND v.item=i.id&lt;br /&gt;
LEFT JOIN prefix_user AS u ON fc.userid=u.id&lt;br /&gt;
WHERE i.typ != &#039;pagebreak&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Resource Module Reports==&lt;br /&gt;
===List &amp;quot;Recently uploaded files&amp;quot;===&lt;br /&gt;
see what users are uploading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT FROM_UNIXTIME(time,&#039;%Y %M %D %h:%i:%s&#039;) as time ,ip,userid,url,info  &lt;br /&gt;
FROM `prefix_log` &lt;br /&gt;
WHERE `action` LIKE &#039;upload&#039; &lt;br /&gt;
ORDER BY `prefix_log`.`time`  DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Courses that loaded a specific file: &amp;quot;X&amp;quot;===&lt;br /&gt;
Did the Teacher (probably) uploaded course&#039;s Syllabus ?&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname  FROM `prefix_log` as l &lt;br /&gt;
JOIN prefix_course as c ON c.id = l.course &lt;br /&gt;
WHERE `action` LIKE &#039;%upload%&#039; AND ( info LIKE &#039;%Syllabus%&#039; OR info LIKE &#039;%Sylabus%&#039; ) GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All resources that link to some specific external website===&lt;br /&gt;
+ link to course&lt;br /&gt;
+ who&#039;s the teacher&lt;br /&gt;
+ link to external resource&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/resource/view.php?id=&#039;,r.id,&#039;&amp;quot;&amp;gt;&#039;,r.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Resource&lt;br /&gt;
FROM prefix_resource AS r &lt;br /&gt;
JOIN prefix_course AS c ON r.course = c.id&lt;br /&gt;
WHERE r.reference LIKE &#039;http://info.oranim.ac.il/home%&#039; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;quot;Compose Web Page&amp;quot; RESOURCE count===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT course,prefix_course.fullname, COUNT(*) AS Total&lt;br /&gt;
FROM `prefix_resource`&lt;br /&gt;
JOIN `prefix_course` ON prefix_course.id = prefix_resource.course&lt;br /&gt;
WHERE type=&#039;html&#039;&lt;br /&gt;
GROUP BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resource count in courses===&lt;br /&gt;
+ (First)Teacher name&lt;br /&gt;
+ Where course is inside some specific Categories&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
COUNT(*) AS count&lt;br /&gt;
,r.course &lt;br /&gt;
,c.shortname shortname&lt;br /&gt;
,c.fullname coursename&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user as u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = r.course AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
FROM prefix_resource r &lt;br /&gt;
JOIN prefix_course c ON r.course = c.id&lt;br /&gt;
WHERE c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY r.course&lt;br /&gt;
ORDER BY COUNT(*) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Delete all the automated backup files===&lt;br /&gt;
Prepare bash cli script to delete all the automated backup files on the file system. (clean up some disk space)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT( &#039;rm -f /var/moodledatanew/filedir/&#039;, SUBSTRING( contenthash, 1, 2 ) , &#039;/&#039;, SUBSTRING( contenthash, 3, 2 ) , &#039;/&#039;, contenthash ) &lt;br /&gt;
FROM `mdl_files` &lt;br /&gt;
WHERE `filename` LIKE &#039;%mbz%&#039;&lt;br /&gt;
AND filearea = &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find out how much disk space is used by all automated backup files:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT SUM(filesize)/(1024*1024*1024) FROM `mdl_files` WHERE  `filename` LIKE &#039;%mbz%&#039; AND filearea =  &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Forum Module Reports==&lt;br /&gt;
===print all User&#039;s post in course Forums===&lt;br /&gt;
%%COURSEID%% is a variable the is replace by the current CourseID you are running the sql report from. if you are using the latest block/configurable_reports ! (You can always change it to a fixed course or remove it to display all courses.)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php?course=&#039;,c.id,&#039;&amp;amp;id=&#039;,u.id,&#039;&amp;amp;mode=posts&amp;quot;&amp;gt;&#039;,CONCAT(u.firstname,&#039; &#039;, u.lastname),&#039;&amp;lt;/a&amp;gt;&#039;) As Fullname&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Forum&lt;br /&gt;
,count(*) as Posts&lt;br /&gt;
,(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&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_user as u ON u.id = fp.userid &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = fd.course &lt;br /&gt;
WHERE fd.course = %%COURSEID%% &lt;br /&gt;
GROUP BY f.id,u.id&lt;br /&gt;
ORDER BY u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE by type -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, prefix_forum.type, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course,prefix_forum.type&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Forum activity - system wide===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,c.fullname as Course&lt;br /&gt;
,f.type&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
, fd.forum, f.name,count(*) AS cPostAndDisc&lt;br /&gt;
,(SELECT count(*) FROM prefix_forum_discussions AS ifd WHERE ifd.forum = f.id) AS cDiscussion&lt;br /&gt;
FROM prefix_forum_posts AS fp&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type != &#039;news&#039; AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
## WHERE 1=1 &lt;br /&gt;
## %%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count( * ) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Activity In Forums===&lt;br /&gt;
Trying to figure out how much real activity we have in Forums by aggregating:&lt;br /&gt;
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...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname,f.name,f.type &lt;br /&gt;
,(SELECT count(id) FROM prefix_forum_discussions as fd WHERE f.id = fd.forum) as Discussions&lt;br /&gt;
,(SELECT count(distinct fd.userid) FROM prefix_forum_discussions as fd WHERE fd.forum = f.id) as UniqueUsersDiscussions&lt;br /&gt;
,(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&lt;br /&gt;
,(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&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS StudentsCount&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Teachers&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS &#039;Teacher&amp;lt;br/&amp;gt;Count&#039;&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid IN (3,5)&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS UserCount&lt;br /&gt;
, (SELECT (UniqueUsersDiscussions / StudentsCount )) as StudentDissUsage&lt;br /&gt;
, (SELECT (UniqueUsersPosts /StudentsCount)) as StudentPostUsage&lt;br /&gt;
FROM prefix_forum as f &lt;br /&gt;
JOIN prefix_course as c ON f.course = c.id&lt;br /&gt;
WHERE `type` != &#039;news&#039;&lt;br /&gt;
ORDER BY StudentPostUsage DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Forum type:NEWS===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT f.id, f.name&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
WHERE m.name = &#039;forum&#039;&lt;br /&gt;
AND f.type = &#039;news&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All new forum NEWS items (discussions) from all my Courses===&lt;br /&gt;
change &amp;quot;userid = 26&amp;quot; and &amp;quot;id = 26&amp;quot; to a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname,f.name,fd.name,FROM_UNIXTIME(fd.timemodified ,&amp;quot;%d %M %Y &amp;quot;) as Date&lt;br /&gt;
FROM prefix_forum_discussions as fd &lt;br /&gt;
JOIN prefix_forum as f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = f.course &lt;br /&gt;
JOIN prefix_user_lastaccess as ul ON (c.id = ul.courseid AND ul.userid = 26)&lt;br /&gt;
WHERE fd.timemodified &amp;gt; ul.timeaccess  &lt;br /&gt;
 AND fd.forum IN (SELECT f.id&lt;br /&gt;
 FROM prefix_course_modules AS cm&lt;br /&gt;
 JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
 JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
 WHERE m.name = &#039;forum&#039;&lt;br /&gt;
 AND f.type = &#039;news&#039;)&lt;br /&gt;
  AND c.id IN (SELECT c.id&lt;br /&gt;
   FROM prefix_course AS c&lt;br /&gt;
   JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
   JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
   JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
   WHERE u.id = 26) ORDER BY `fd`.`timemodified` DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===News Forum - Discussions COUNT===&lt;br /&gt;
Which is actually... How much instructions students get from their teachers&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname ,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,count(fd.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS DiscussionsSum&lt;br /&gt;
FROM prefix_forum_discussions AS fd&lt;br /&gt;
INNER JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
INNER JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type = &#039;news&#039; AND c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count(fd.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cantidad de foros que han sido posteados por profesor===&lt;br /&gt;
&lt;br /&gt;
(Number of forums that have been posted by teacher/Google translator)&lt;br /&gt;
&lt;br /&gt;
Queriamos saber cuales son las acciones del profesor dentro de los foros de cada curso, por ello se hizo este informe.&lt;br /&gt;
&lt;br /&gt;
(We wanted to know what the teacher&#039;s actions are in the forums of each course, so this report was made. /Google translator)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS curso,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Facilitador,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( m.name ) AS COUNT FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS foros,&lt;br /&gt;
&lt;br /&gt;
COUNT(*) AS Posts&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course AS c ON c.id = fd.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = fp.userid &lt;br /&gt;
&lt;br /&gt;
WHERE fp.userid =&lt;br /&gt;
(&lt;br /&gt;
select distinct prefix_user.id&lt;br /&gt;
from prefix_user &lt;br /&gt;
join prefix_role_assignments as ra on ra.userid = prefix_user.id &lt;br /&gt;
where ra.roleid = 3 &lt;br /&gt;
and userid = fp.userid&lt;br /&gt;
limit 1&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
and c.shortname like &#039;%2014-2-1%&#039;&lt;br /&gt;
GROUP BY c.id, u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all the Forums that got high rating===&lt;br /&gt;
We setup a scale that let teachers and students Rate forum post with &amp;quot;Important, interesting, valuable, not rated&amp;quot; scale&lt;br /&gt;
And then add a link to the following report at the begining of the course &amp;quot;Link to all interesting posts&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,f.id,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;,fd.id,&#039;#p&#039;,fp.id,&#039;&amp;quot;&amp;gt;&#039;,fp.subject,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post link&#039;,&lt;br /&gt;
SUM(r.rating) AS &#039;Rating&#039;&lt;br /&gt;
FROM mdl_rating AS r&lt;br /&gt;
  JOIN mdl_forum_posts AS fp ON fp.id = r.itemid&lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
WHERE r.component = &#039;mod_forum&#039; AND r.ratingarea = &#039;post&#039; AND f.course = %%COURSEID%%&lt;br /&gt;
GROUP BY r.itemid&lt;br /&gt;
ORDER BY SUM(r.rating) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all Discussions of a single Forum===&lt;br /&gt;
This report is used to help export all the student&#039;s posts and discussions of a single forum, by passing the context module id as a parameter to the report using &amp;quot;&amp;amp;filter_var=cmid&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;, f.id, &#039;&amp;quot;&amp;gt;&#039;, f.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name&#039;,&lt;br /&gt;
fd.name AS &#039;Discussion&#039;, &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;, fd.id, &#039;#p&#039;, fp.id, &#039;&amp;quot;&amp;gt;&#039;, fp.subject, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post (link)&#039;,&lt;br /&gt;
fp.message&lt;br /&gt;
&lt;br /&gt;
FROM mdl_forum_posts AS fp &lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
  JOIN mdl_course_modules AS cm ON cm.module = 9 AND cm.instance = f.id&lt;br /&gt;
WHERE cm.id = %%FILTER_VAR%%&lt;br /&gt;
ORDER BY f.id, fd.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Quiz Module Reports==&lt;br /&gt;
===Generate a list of instructors and their email addresses for those courses that has &amp;quot;essay questions&amp;quot; in their quizzes===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT qu.id AS quiz_id, qu.course AS course_id, qu.questions,&lt;br /&gt;
                co.fullname AS course_fullname, co.shortname AS course_shortname,&lt;br /&gt;
                qu.name AS quiz_name, FROM_UNIXTIME(qu.timeopen) AS quiz_timeopen, FROM_UNIXTIME(qu.timeclose) AS quiz_timeclose,&lt;br /&gt;
                u.firstname, u.lastname, u.email,&lt;br /&gt;
FROM prefix_quiz qu, prefix_course co, prefix_role re, prefix_context ct, prefix_role_assignments ra, prefix_user u&lt;br /&gt;
WHERE FROM_UNIXTIME(timeopen) &amp;gt; &#039;2008-05-14&#039; AND&lt;br /&gt;
                qu.course = co.id AND&lt;br /&gt;
                co.id = ct.instanceid AND&lt;br /&gt;
                ra.roleid = re.id AND&lt;br /&gt;
                re.name = &#039;Teacher&#039; AND&lt;br /&gt;
                ra.contextid = ct.id AND&lt;br /&gt;
                ra.userid = u.id&lt;br /&gt;
 &lt;br /&gt;
SELECT Count(&#039;x&#039;) As NumOfStudents&lt;br /&gt;
                                FROM prefix_role_assignments a&lt;br /&gt;
                                JOIN prefix_user u ON userid = u.id&lt;br /&gt;
                                WHERE roleid = 5 AND contextid = (SELECT id FROM prefix_context WHERE instanceid = 668 AND contextlevel = 50)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Number of Quizes per Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Link&amp;lt;/a&amp;gt;&#039;) AS Quizes&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules cm&lt;br /&gt;
JOIN prefix_course c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module&lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039;&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all MultiAnswer (Cloze) Questions===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/attempt.php?q=&#039;, quiz.id, &#039;&amp;quot;&amp;gt;&#039;, quiz.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS Quiz&lt;br /&gt;
,question.id question_id, question.questiontext &lt;br /&gt;
FROM  prefix_question question&lt;br /&gt;
JOIN prefix_quiz_question_instances qqi ON question.id = qqi.question&lt;br /&gt;
JOIN prefix_quiz quiz ON qqi.quiz = quiz.id&lt;br /&gt;
WHERE  `qtype` LIKE  &#039;multianswer&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List courses with MANUAL grades===&lt;br /&gt;
Which is basically and indication to teachers using Moodle to hold offline grades inside Moodle&#039;s Gradebook,&lt;br /&gt;
So grades could be uploaded into an administrative SIS. Use with Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT( * )&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php?showadvanced=1&amp;amp;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM  prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course as c ON c.id = gi.courseid&lt;br /&gt;
WHERE  `itemtype` =  &#039;manual&#039;&lt;br /&gt;
GROUP BY courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===List the users that did not took the Quiz===&lt;br /&gt;
Do not forget to change &amp;quot;c.id = 14&amp;quot; and q.name LIKE &#039;%quiz name goes here%&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id AS ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.username AS IDNumber,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
 &lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id AND courseid=c.id) AS CourseLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id AND e.courseid = c.id) AS RoleName&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess AS ul ON ul.userid = user2.id&lt;br /&gt;
WHERE c.id=14 and ue.userid NOT IN (SELECT qa.userid FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON qa.quiz = q.id&lt;br /&gt;
JOIN prefix_course AS c ON q.course = c.id&lt;br /&gt;
WHERE c.id = 14 AND q.name LIKE &#039;%quiz name goes here%&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List Questions in each Quiz===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT quiz.id,quiz.name, q.id, q.name&lt;br /&gt;
FROM mdl_quiz AS quiz&lt;br /&gt;
JOIN mdl_question AS q ON FIND_IN_SET(q.id, quiz.questions)&lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
ORDER BY quiz.id ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this query does not work in Moodle 2.8. There is no mdl_quiz.questions field. It will need to be rewritten to use the usage/contextid organization.&lt;br /&gt;
&lt;br /&gt;
===Quiz activity research===&lt;br /&gt;
This report was made to extract student full activity in quizzes for an academic research about adapting instructional design teaching methods in online learning. The students do not use the Quiz module as a standard quiz but more as Study booklets or mini courses with embedded questions and hints to assist students evaluate their progress (Similar to what you expect to find in a SCORM activity)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cm.course &amp;quot;course_id&amp;quot;, cm.id &amp;quot;moduel_id&amp;quot;, q.id &amp;quot;quiz_id&amp;quot;, q.name &amp;quot;quiz_name&amp;quot;,&lt;br /&gt;
 &lt;br /&gt;
CASE q.grademethod&lt;br /&gt;
      WHEN 1 THEN &amp;quot;GRADEHIGHEST&amp;quot;&lt;br /&gt;
      WHEN 2 THEN &amp;quot;GRADEAVERAGE&amp;quot;&lt;br /&gt;
      WHEN 3 THEN &amp;quot;ATTEMPTFIRST&amp;quot;&lt;br /&gt;
      WHEN 4 THEN &amp;quot;ATTEMPTLAST&amp;quot;&lt;br /&gt;
END &amp;quot;grade method&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
, q.attempts &amp;quot;quiz_attempts_allowed&amp;quot;, cm.groupmode &amp;quot;group_mode&amp;quot;&lt;br /&gt;
, qa.id &amp;quot;attempt_id&amp;quot;, qa.state &amp;quot;attempt_state&amp;quot;, qa.sumgrades &amp;quot;attempt_grade&amp;quot;, qg.grade &amp;quot;user_final_grade&amp;quot;, q.grade &amp;quot;quiz_max_grade&amp;quot;&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = q.course AND m.userid = u.id) &amp;quot;user_groups&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timestart), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_start&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timefinish), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_finish&amp;quot;,&lt;br /&gt;
u.id &amp;quot;user_id&amp;quot;, u.firstname, u.lastname,&lt;br /&gt;
question.id &amp;quot;question_id&amp;quot;, question.name &amp;quot;question_name&amp;quot;,&lt;br /&gt;
qas.state &amp;quot;question_step_state&amp;quot;,qas.fraction &amp;quot;question_grade&amp;quot;, qh.hint, question.qtype &amp;quot;question_type&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz as q&lt;br /&gt;
JOIN mdl_course_modules as cm ON cm.instance = q.id and cm.module = 14 &lt;br /&gt;
JOIN mdl_quiz_attempts qa ON q.id = qa.quiz&lt;br /&gt;
LEFT JOIN mdl_quiz_grades as qg ON qg.quiz = q.id and qg.userid = qa.userid&lt;br /&gt;
JOIN mdl_user as u ON u.id = qa.userid&lt;br /&gt;
JOIN mdl_question_usages as qu ON qu.id = qa.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts as qatt ON qatt.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question as question ON question.id = qatt.questionid&lt;br /&gt;
JOIN mdl_question_attempt_steps as qas ON qas.questionattemptid = qatt.id&lt;br /&gt;
LEFT JOIN mdl_question_hints as qh ON qh.questionid = q.id&lt;br /&gt;
#WHERE q.id = &amp;quot;SOME QUIZ ID&amp;quot;&lt;br /&gt;
WHERE cm.course = &amp;quot;SOME COURSE ID&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quiz Usage in Courses by Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Multiple Choice&amp;quot; questions include true/false and matching question types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Short Answer&amp;quot; are questions that accept a single phrase.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Other&amp;quot; questions include fixed numerical, calculated, essay, and various drag and drop types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Min Quiz Age&amp;quot; and &amp;quot;Max Quiz Age&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: In Configurable Reports, the Date Filter is not applied until the &amp;quot;Apply&amp;quot; button is clicked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.shortname AS &#039;Course&#039;&lt;br /&gt;
#, u.lastname AS &#039;Instructor&#039;&lt;br /&gt;
, COUNT(DISTINCT q.id) AS &#039;Quizzes&#039;&lt;br /&gt;
, COUNT(DISTINCT qu.id) AS &#039;Questions&#039;&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 ))  AS &#039;multichoice&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT( qu.id) - SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;Other&#039;&lt;br /&gt;
&lt;br /&gt;
, (SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )))/COUNT( qu.id) AS &#039;Percent MC&#039;&lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;numerical&#039;, 1, 0 )) AS &#039;numerical&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype LIKE &#039;calc%&#039;, 1, 0 )) AS &#039;calculated&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;random&#039;, 1, 0 )) AS &#039;random&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;essay&#039;, 1, 0 )) AS &#039;essay&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, IF(q.shufflequestions &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Questions&#039;&lt;br /&gt;
, IF(q.shuffleanswers &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Answers&#039;&lt;br /&gt;
 &lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
#, FROM_UNIXTIME(MIN(q.timemodified)) AS &#039;Last Modified&#039;&lt;br /&gt;
&lt;br /&gt;
#, DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(MIN(q.timemodified))) AS &#039;Quiz age&#039;&lt;br /&gt;
&lt;br /&gt;
, MIN(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Min Quiz Age&#039; &lt;br /&gt;
, MAX(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Max Quiz Age&#039; &lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified)) &amp;lt; 90, 1,0)) AS &#039;new quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_quiz AS q&lt;br /&gt;
JOIN prefix_course AS c on c.id = q.course&lt;br /&gt;
JOIN prefix_quiz_question_instances AS qqi ON qqi.quiz = q.id&lt;br /&gt;
LEFT JOIN prefix_question AS qu ON qu.id = qqi.question&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%% %%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student responses (answers) to quiz questions===&lt;br /&gt;
(Contributed by Juan F with help from Tim hunt and fellow Moodlers on the forums)&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    concat( u.firstname, &amp;quot; &amp;quot;, u.lastname ) AS &amp;quot;Student Name&amp;quot;,&lt;br /&gt;
    u.id,&lt;br /&gt;
    quiza.userid,&lt;br /&gt;
    q.course,&lt;br /&gt;
    q.name,&lt;br /&gt;
    quiza.attempt,&lt;br /&gt;
    qa.slot,&lt;br /&gt;
    que.questiontext AS &#039;Question&#039;,&lt;br /&gt;
    qa.rightanswer AS &#039;Correct Answer&#039;,&lt;br /&gt;
    qa.responsesummary AS &#039;Student Answer&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz_attempts quiza&lt;br /&gt;
JOIN mdl_quiz q ON q.id=quiza.quiz&lt;br /&gt;
JOIN mdl_question_usages qu ON qu.id = quiza.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts qa ON qa.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question que ON que.id = qa.questionid&lt;br /&gt;
JOIN mdl_user u ON u.id = quiza.userid&lt;br /&gt;
&lt;br /&gt;
WHERE q.name = &amp;quot;BIO 208 Post Test Assessment&amp;quot;&lt;br /&gt;
AND q.course = &amp;quot;17926&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ORDER BY quiza.userid, quiza.attempt, qa.slot&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==SCORM Activity Reports==&lt;br /&gt;
&lt;br /&gt;
===Lists All completed SCORM activites by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists SCORM status for all enrolled users by Course name===&lt;br /&gt;
This report will list the SCORM status for all users enrolled in the course. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. This can be limited to individual courses by adding to the where clause the course id to report on.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.firstname AS First,&lt;br /&gt;
u.lastname AS Last, &lt;br /&gt;
u.idnumber AS Employee_ID,  &lt;br /&gt;
u.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
u.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course, &lt;br /&gt;
st.attempt AS Attempt,&lt;br /&gt;
st.value AS Status,&lt;br /&gt;
FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) AS Date &lt;br /&gt;
&lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
&lt;br /&gt;
WHERE st.element=&#039;cmi.core.lesson_status&#039; AND m.userid=u.id&lt;br /&gt;
&lt;br /&gt;
UNION&lt;br /&gt;
&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS First,&lt;br /&gt;
user2.lastname AS Last,&lt;br /&gt;
user2. idnumber AS Employee_ID,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
user2.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Attempt,&lt;br /&gt;
&amp;quot;not_started&amp;quot; AS Status,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Date&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = user2.id &lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.course=c.id&lt;br /&gt;
Left Join prefix_scorm_scoes_track AS st on st.scormid=sc.id AND st.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
WHERE  st.timemodified IS NULL AND m.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY  Course, Last, First, Attempt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Badges==&lt;br /&gt;
&lt;br /&gt;
=== All badges issued, by User ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, b.name AS badgename, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN&lt;br /&gt;
(SELECT c.shortname&lt;br /&gt;
    FROM prefix_course AS c&lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Context,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 1 THEN &amp;quot;Activity Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 2 THEN &amp;quot;Activity Completion (Any)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 2 AND t.method = 2 THEN &amp;quot;Manual Award&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 1 THEN &amp;quot;Course Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 2 THEN &amp;quot;Course Completion (Any)&amp;quot;&lt;br /&gt;
  ELSE CONCAT (&#039;Other: &#039;, t.criteriatype)&lt;br /&gt;
END AS Criteriatype,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateissued ) , &#039;%Y-%m-%d&#039; ) AS dateissued,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateexpire ), &#039;%Y-%m-%d&#039; ) AS dateexpires,&lt;br /&gt;
CONCAT (&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/badge.php?hash=&#039;,d.uniquehash,&#039;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&#039;) AS Details&lt;br /&gt;
FROM prefix_badge_issued AS d &lt;br /&gt;
JOIN prefix_badge AS b ON d.badgeid = b.id&lt;br /&gt;
JOIN prefix_user AS u ON d.userid = u.id&lt;br /&gt;
JOIN prefix_badge_criteria AS t on b.id = t.badgeid &lt;br /&gt;
WHERE t.criteriatype &amp;lt;&amp;gt; 0&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&lt;br /&gt;
=== All badges available in the system, with Earned count ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.type = 1 THEN &amp;quot;System&amp;quot;&lt;br /&gt;
WHEN b.type = 2 THEN &amp;quot;Course&amp;quot;&lt;br /&gt;
END AS Context, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN &lt;br /&gt;
(SELECT c.shortname &lt;br /&gt;
    FROM prefix_course AS c &lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 2 THEN &amp;quot;No&amp;quot;&lt;br /&gt;
WHEN b.status = 1 OR b.status = 3 THEN &amp;quot;Yes&amp;quot;&lt;br /&gt;
WHEN b.status = 4 THEN &amp;quot;x&amp;quot;&lt;br /&gt;
END AS Available,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 1 THEN &amp;quot;0&amp;quot;&lt;br /&gt;
WHEN b.status = 2 OR b.status = 3 OR b.status = 4 THEN &lt;br /&gt;
 (SELECT COUNT(*) &lt;br /&gt;
   FROM prefix_badge_issued AS d&lt;br /&gt;
   WHERE d.badgeid = b.id&lt;br /&gt;
 )&lt;br /&gt;
END AS Earned&lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Badges Leaderboard ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A simple list of usernames and how many badges they have earned overall.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, (SELECT COUNT(*) FROM prefix_badge_issued AS d WHERE d.userid = u.id) AS earned&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
ORDER BY earned DESC, u.username ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Manage badges (System &amp;amp; Course) ===&lt;br /&gt;
&lt;br /&gt;
List system wide badges, course and system level badges + a link to relevant &amp;quot;manage badges&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description &lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN b.type = 1 THEN &#039;System&#039;&lt;br /&gt;
  WHEN b.type = 2 THEN &#039;Course&#039;&lt;br /&gt;
END AS Level&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/index.php?type=&#039;, b.type, &#039;&amp;amp;id=&#039;,&lt;br /&gt;
			  c.id, &#039;&amp;quot;&amp;gt;Manage badges in: &#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Manage &lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Administrator Reports==&lt;br /&gt;
&lt;br /&gt;
===Config changes in Export friendly form===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( g.timemodified ) , &#039;%Y-%m-%d&#039; ) AS date, &lt;br /&gt;
u.username AS user, &lt;br /&gt;
g.name AS setting, &lt;br /&gt;
CASE &lt;br /&gt;
 WHEN g.plugin IS NULL THEN &amp;quot;core&amp;quot;&lt;br /&gt;
 ELSE g.plugin&lt;br /&gt;
END AS plugin, &lt;br /&gt;
g.value AS new_value, &lt;br /&gt;
g.oldvalue AS original_value&lt;br /&gt;
FROM prefix_config_log  AS g&lt;br /&gt;
JOIN prefix_user AS u ON g.userid = u.id&lt;br /&gt;
ORDER BY date DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts by user===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
How to get a list of all users and which cohorts they belong to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, h.idnumber, h.name&lt;br /&gt;
FROM prefix_cohort AS h&lt;br /&gt;
JOIN prefix_cohort_members AS hm ON h.id = hm.cohortid&lt;br /&gt;
JOIN prefix_user AS u ON hm.userid = u.id&lt;br /&gt;
ORDER BY u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts with Courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all cohorts with name, id, visibility, and which courses they are enrolled in.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
# h.id,&lt;br /&gt;
# e.customint1,&lt;br /&gt;
h.name AS Cohort,&lt;br /&gt;
h.idnumber AS Cohortid,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN h.visible = 1 THEN &#039;Yes&#039;&lt;br /&gt;
 ELSE &#039;-&#039;&lt;br /&gt;
END AS Cohortvisible,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;, CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_cohort h&lt;br /&gt;
JOIN prefix_enrol e ON h.id = e.customint1&lt;br /&gt;
JOIN prefix_course c ON c.id = e.courseid %%FILTER_COURSES:e.courseid%% &lt;br /&gt;
WHERE e.enrol = &#039;cohort&#039; AND e.roleid = 5&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses created And Active courses by Year===&lt;br /&gt;
Active courses is counting course that have at least one Hit, And &amp;quot;Active_MoreThan100Hits&amp;quot; counts courses that have at least 100 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `timecreated` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT course ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY course &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 100) AS courses_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( courses_log.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan100Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_course` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users created And Active users by Year===&lt;br /&gt;
Active users is counting users that have at least one Hit, And &amp;quot;Active_MoreThan500Hits&amp;quot; counts users that have at least 500 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `firstaccess` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT userid ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY userid &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 500) AS users_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( users_log.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan500Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Aggregation Report===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In particular, be on the lookout for any courses with the following combinations of parameters, which are known to cause changes in calculations:&lt;br /&gt;
&lt;br /&gt;
# mean of grades set with aggregate with subcategory.&lt;br /&gt;
# Simple weighted mean of grades with aggregate with sub category and drop the lowest&lt;br /&gt;
# Sum of grades drop the lowest&lt;br /&gt;
&lt;br /&gt;
Also review:&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48618&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48634&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-49257&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50089&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50062&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
COUNT(c.shortname) AS &#039;Count of Courses&#039;&lt;br /&gt;
&lt;br /&gt;
# If you want to display all the courses for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, c.shortname AS &#039;course name&#039;&lt;br /&gt;
&lt;br /&gt;
# If you need to display grade categories for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, gc.fullname AS &#039;grade category name&#039;&lt;br /&gt;
&lt;br /&gt;
, gc.aggregation AS &#039;aggregation method&#039;&lt;br /&gt;
&lt;br /&gt;
#These aggregation text strings appear to be hard-coded. I couldn&#039;t find a table for them. If you have aggregation types I haven&#039;t included here, they&#039;ll be blank in your report results.&lt;br /&gt;
, CASE gc.aggregation&lt;br /&gt;
  WHEN 0 THEN &#039;Mean of Grades&#039;&lt;br /&gt;
  WHEN 2 THEN &#039;Median of Grades&#039;&lt;br /&gt;
  WHEN 6 THEN &#039;Highest Grade&#039;&lt;br /&gt;
  WHEN 8 THEN &#039;Mode of Grades&#039;&lt;br /&gt;
  WHEN 10 THEN &#039;Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 11 THEN &#039;Simple Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 12 THEN &#039;Mean of Grades (with extra credits)&#039;&lt;br /&gt;
  WHEN 13 THEN &#039;Sum of Grades&#039;&lt;br /&gt;
END AS &#039;aggregation name&#039;&lt;br /&gt;
&lt;br /&gt;
# Note that gc.aggregatesubcats column is eliminated in 2.8 and later per MDL-47503, so comment that line on updated systems or you&#039;ll get an error&lt;br /&gt;
, gc.keephigh AS &#039;keep high&#039;&lt;br /&gt;
, gc.droplow AS &#039;dr0p low&#039;&lt;br /&gt;
, gc.aggregateonlygraded AS &#039;Aggregate only graded&#039;&lt;br /&gt;
, gc.aggregateoutcomes AS &#039;aggregate outcomes&#039;&lt;br /&gt;
, gc.aggregatesubcats AS &#039;aggregate subcategories&#039;&lt;br /&gt;
&lt;br /&gt;
# If you are displaying data about individual courses, you may want to know how old they are&lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;course start date&#039;&lt;br /&gt;
&lt;br /&gt;
# 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&#039;ll need to uncomment the necessary JOINs below&lt;br /&gt;
#, gi.itemname AS &#039;grade item&#039;&lt;br /&gt;
#, gg.finalgrade AS &#039;final grade&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
&lt;br /&gt;
prefix_course AS c&lt;br /&gt;
JOIN prefix_grade_categories AS gc ON gc.courseid = c.id&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id #AND gi.categoryid=gc.id&lt;br /&gt;
#LEFT JOIN prefix_grade_grades AS gg ON gg.itemid = gi.id AND gg.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
#AND gc.aggregation = 13 #only the dreaded Sum of Grades aggregations&lt;br /&gt;
#AND gc.depth = 1 # if for some reason you only want course aggregations, not subcategories&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.aggregation, gc.keephigh, gc.droplow, gc.aggregateonlygraded, gc.aggregateoutcomes, gc.aggregatesubcats&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running Cron jobs (task_scheduled) ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT classname&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(lastruntime), &#039;%H:%i [%d]&#039;) AS &#039;last&#039;&lt;br /&gt;
  ,DATE_FORMAT(now(), &#039;%H:%i&#039;) AS &#039;now&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(nextruntime), &#039;%H:%i [%d]&#039;) AS &#039;next&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP()-nextruntime), &#039;%i&#039;) AS &#039;next in min&#039;&lt;br /&gt;
FROM mdl_task_scheduled&lt;br /&gt;
WHERE now() &amp;gt; FROM_UNIXTIME(nextruntime)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== All Meta courses with Parent and Child course relationships ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
This shows the list of courses with Meta course link enrollments in them (&#039;Parent course&#039;), and the courses which are connected to them to provide enrollments (&#039;Child courses&#039;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.fullname AS &#039;Parent course name&#039;,&lt;br /&gt;
c.shortname AS &#039;Parent course shortname&#039;,&lt;br /&gt;
en.courseid AS &#039;Parent course id&#039;,&lt;br /&gt;
(SELECT fullname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course name&#039;,&lt;br /&gt;
(SELECT shortname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course shortname&#039;,&lt;br /&gt;
en.customint1 AS &#039;Child course id&#039;&lt;br /&gt;
FROM prefix_enrol en&lt;br /&gt;
JOIN prefix_course c ON c.id = en.courseid&lt;br /&gt;
WHERE en.enrol = &#039;meta&#039;&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Useful sub queries ==&lt;br /&gt;
&lt;br /&gt;
IN this section please put any short one purpose sub queries that show how common procedures often useful as part of larger queries.&lt;br /&gt;
&lt;br /&gt;
=== All teachers in the course ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This snippet shows how to get teachers from a course. The contextevel for course objects is 50. And the default Teacher role is role id 3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course ic&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = ic.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND ic.id = c.id&lt;br /&gt;
GROUP BY ic.id&lt;br /&gt;
) AS TeacherNames&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Get custom User profile fields for a user ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON uid.fieldid = uif.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to limit it to one of those fields, you can restrict it by shortname of the custom profile field, so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;shortname1&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will show you only the data from the custom profile field with the shortname &#039;shortname1&#039;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, d1.data AS &#039;Profile One&#039;, d2.data As &#039;Profile Two&#039;&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
JOIN prefix_user_info_data d1 ON d1.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
JOIN prefix_user_info_data d2 ON d2.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f2 ON d2.fieldid = f2.id AND f2.shortname = &#039;shortname2&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== NOTE: Alternate Method ====&lt;br /&gt;
&lt;br /&gt;
If you have more than a couple of fields you need to use, then this query may time out or not return data due to too many joins. The limit seems to be around 10 custom profile fields. &lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thefirstfield&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname2&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thesecondfield&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== How to use Configurable Reports Date Time Filters===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Here is a simple example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.firstaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;FirstAccess&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.lastaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;LastAccess&#039;   &lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1&lt;br /&gt;
%%FILTER_STARTTIME:u.firstaccess:&amp;gt;%% &lt;br /&gt;
%%FILTER_ENDTIME:u.lastaccess:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2) You MUST then add the Start / End date filter on the Filters tab of the Report. If you don&#039;t, the report will still run, probably, but the filter will be ignored.&lt;br /&gt;
&lt;br /&gt;
Note: the WHERE 1=1 statement is a peculiarity of the filters in Config reports: if you don&#039;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.)&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://github.com/jleyva/moodle-configurable_reports_repository Configurable Reports Repository on GitHub]&lt;br /&gt;
* [https://moodleschema.zoola.io/index.html Moodle DB schema explorer] - searching and filtering tables, fields and external key connections between tables.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;br /&gt;
&lt;br /&gt;
[[es:Reportes específicos hechos por usuarios]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Debugging&amp;diff=131185</id>
		<title>Debugging</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Debugging&amp;diff=131185"/>
		<updated>2018-06-12T13:13:15Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* More tools for debugging outgoing mail */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Developer tools}}&lt;br /&gt;
==Using debugging messages==&lt;br /&gt;
&lt;br /&gt;
Debugging messages are intended to help diagnose problems and/or help Moodle developers. If you have a problem with your Moodle site and ask for help in a Moodle.org forum, a developer may ask you to turn enable debugging i.e. turn debugging messages on, in order to locate the cause of the problem. If you are having problems such as a blank screen or incomplete screens, then turning on debugging is usually the first thing to try. &lt;br /&gt;
&lt;br /&gt;
==Enabling debugging==&lt;br /&gt;
&lt;br /&gt;
To enable debugging, go to Debugging in the Site administration.&lt;br /&gt;
&lt;br /&gt;
===Debug messages===&lt;br /&gt;
&lt;br /&gt;
The options are:&lt;br /&gt;
&lt;br /&gt;
* NONE: Do not show any errors or warnings (Default) &lt;br /&gt;
* MINIMAL: Show only fatal errors&lt;br /&gt;
* NORMAL: Show warnings, errors and notices&lt;br /&gt;
* ALL: Show all reasonable PHP debug messages&lt;br /&gt;
* DEVELOPER: extra Moodle debug messages for developers&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
&lt;br /&gt;
# It is recommended that a record of error messages is kept, and for the admin to regularly monitor the error logs. This may be done by setting &#039;Debug messages&#039; (debug) to Normal and leaving &#039;Display debug messages&#039; (debugdisplay) off (unticked). Error messages are then recorded in the server logs.&lt;br /&gt;
# If &#039;Debug messages&#039; is set to Developer on a production (public) site, it is recommended to copy and paste the debugging message obtained and then turn off Developer debugging. This is because debugging messages can give clues to a hacker as to the set-up of your site.&lt;br /&gt;
&lt;br /&gt;
===Debug email sending===&lt;br /&gt;
&lt;br /&gt;
Determines whether or not to enable verbose debug information during sending of email messages to SMTP server.&lt;br /&gt;
&lt;br /&gt;
==== More tools for debugging outgoing mail (SMTP) ====&lt;br /&gt;
You can also use the config.php file to turn on more &amp;quot;tools&amp;quot; which will assist you with debugging the outgoing emails (and SMTP server configuration):&lt;br /&gt;
* Redirect all outgoing emails to a specific address:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Divert all outgoing emails to this address to test and debug emailing features&lt;br /&gt;
// $CFG-&amp;gt;divertallemailsto = &#039;root@localhost.local&#039;; // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Turn on the CRON debugging and run CLI cron.php script.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Force developer level debug and add debug info to the output of cron&lt;br /&gt;
// $CFG-&amp;gt;showcrondebugging = true;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
And then use SSH (or putty.exe, on windows) to run:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
you@moodle-server(/var/www/html/moodle)# php admin/cli/cron.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Turn on verbose SMTP debugging and output it into system&#039;s error_log (code hack):&lt;br /&gt;
As [https://moodle.org/mod/forum/discuss.php?d=316222#p1289850 suggested] on Moodle&#039;s discussion forums:&lt;br /&gt;
Open [https://github.com/moodle/moodle/blob/master/lib/moodlelib.php#L5379 lib/moodlelib.php L5379] and change it to:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($CFG-&amp;gt;debugsmtp)) {&lt;br /&gt;
    $mailer-&amp;gt;SMTPDebug = 1;  // 0 - no debug ... 4 - low level full debug&lt;br /&gt;
    $mailer-&amp;gt;Debugoutput = &amp;quot;error_log&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
See more info about [https://github.com/moodle/moodle/blob/master/lib/phpmailer/class.phpmailer.php#L314 SMTPDebug] parameters &amp;amp; [https://github.com/moodle/moodle/blob/master/lib/phpmailer/class.phpmailer.php#L328 Debugoutput] parameters,&lt;br /&gt;
Set-up mailcatcher (https://mailcatcher.me/).&lt;br /&gt;
&lt;br /&gt;
===Performance info===&lt;br /&gt;
&lt;br /&gt;
The Performance info option determines whether performance info will be included in the footer of the standard theme (and some other themes). Performance info includes the time for the page to load, the amount of memory used to generate the page, cpu usage, load, and the record cache hit/miss ration.&lt;br /&gt;
&lt;br /&gt;
If you add&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
define(&#039;MDL_PERF&#039;, true);&lt;br /&gt;
define(&#039;MDL_PERFDB&#039;, true);&lt;br /&gt;
define(&#039;MDL_PERFTOLOG&#039;, true);&lt;br /&gt;
define(&#039;MDL_PERFTOFOOT&#039;, true);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
to your config.php file, then it will also count database queries. (This has to be in config.php, because Moodle starts doing DB queries before it loads the config information in the database!)&lt;br /&gt;
&lt;br /&gt;
To hide performance info from ordinary users, see the discussion [https://moodle.org/mod/forum/discuss.php?d=358032 Performance info only for admins?]&lt;br /&gt;
&lt;br /&gt;
===Show origin of language strings===&lt;br /&gt;
&lt;br /&gt;
Helps with [[:dev:Translation|translation]] and also with [[Language customization]]. Sometimes &amp;lt;code&amp;gt;?strings=1&amp;lt;/code&amp;gt; should be added; other times &amp;lt;code&amp;gt;&amp;amp;strings=1&amp;lt;/code&amp;gt;. See the Wikipedia article [http://en.wikipedia.org/wiki/Query_string Query string] for details.&lt;br /&gt;
&lt;br /&gt;
===Show validator links===&lt;br /&gt;
Be careful, read the warning.&lt;br /&gt;
&lt;br /&gt;
===Show page information===&lt;br /&gt;
To show page information printed in the page footer.&lt;br /&gt;
&lt;br /&gt;
==What to do if you cannot get to the admin screens==&lt;br /&gt;
&lt;br /&gt;
If the error is stopping you even getting to the admin screens to turn on debugging, then you can set the debugging setting manually.&lt;br /&gt;
&lt;br /&gt;
===Try typing the URL directly===&lt;br /&gt;
&lt;br /&gt;
The debug settings are at the URL &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;http://.../admin/settings.php?section=debugging&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; on your server. Sometimes that URL will work, even though the pages you need to go to get there (for example the site front page) do not. So it is worth trying to enter that URL directly.&lt;br /&gt;
&lt;br /&gt;
===In config.php===&lt;br /&gt;
&lt;br /&gt;
In [[Configuration file|config.php]] you can uncomment lines (delete the // at the start of the line) under Section 7 to enable debugging for all or just specific users:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//=========================================================================&lt;br /&gt;
// 7. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!!&lt;br /&gt;
//=========================================================================&lt;br /&gt;
//&lt;br /&gt;
// Force a debugging mode regardless the settings in the site administration&lt;br /&gt;
// @error_reporting(E_ALL | E_STRICT);   // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
// @ini_set(&#039;display_errors&#039;, &#039;1&#039;);         // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
// $CFG-&amp;gt;debug = (E_ALL | E_STRICT);   // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
// $CFG-&amp;gt;debugdisplay = 1;              // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
//&lt;br /&gt;
// You can specify a comma separated list of user ids that that always see&lt;br /&gt;
// debug messages, this overrides the debug flag in $CFG-&amp;gt;debug and $CFG-&amp;gt;debugdisplay&lt;br /&gt;
// for these users only.&lt;br /&gt;
// $CFG-&amp;gt;debugusers = &#039;2&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to comment those lines again (reinsert the // at the start of the line) when you have finished diagnosing your problem.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE 1&#039;&#039;&#039;: do not try to modify the config database table directly, it will not work because the values are cached in MUC.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE 2&#039;&#039;&#039;: if you find your config.php does not have the above settings (you have a cut down approx 30 lines config.php) look for a &amp;quot;config-dist.php&amp;quot; file that contains the full details. I would suggest transferring your details in the current config.php file you have into the full config file and renaming that one to &amp;quot;config.php&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Developers can also use [http://xdebug.org/ XDEBUG] (Installed as a module on the Apache server) to further dig into the code, step by step using an [http://xdebug.org/docs/remote XDEBUG client application]. Probably, as part of their favorite IDE. For example: [http://php.netbeans.org/ NetBeans], [http://www.jetbrains.com/phpstorm/ phpStorm] or...&lt;br /&gt;
&lt;br /&gt;
[[es:Depuración]]&lt;br /&gt;
[[fr:Débogage]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Debugging&amp;diff=131184</id>
		<title>Debugging</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Debugging&amp;diff=131184"/>
		<updated>2018-06-12T13:12:45Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* More tools for debugging outgoing mail */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Developer tools}}&lt;br /&gt;
==Using debugging messages==&lt;br /&gt;
&lt;br /&gt;
Debugging messages are intended to help diagnose problems and/or help Moodle developers. If you have a problem with your Moodle site and ask for help in a Moodle.org forum, a developer may ask you to turn enable debugging i.e. turn debugging messages on, in order to locate the cause of the problem. If you are having problems such as a blank screen or incomplete screens, then turning on debugging is usually the first thing to try. &lt;br /&gt;
&lt;br /&gt;
==Enabling debugging==&lt;br /&gt;
&lt;br /&gt;
To enable debugging, go to Debugging in the Site administration.&lt;br /&gt;
&lt;br /&gt;
===Debug messages===&lt;br /&gt;
&lt;br /&gt;
The options are:&lt;br /&gt;
&lt;br /&gt;
* NONE: Do not show any errors or warnings (Default) &lt;br /&gt;
* MINIMAL: Show only fatal errors&lt;br /&gt;
* NORMAL: Show warnings, errors and notices&lt;br /&gt;
* ALL: Show all reasonable PHP debug messages&lt;br /&gt;
* DEVELOPER: extra Moodle debug messages for developers&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
&lt;br /&gt;
# It is recommended that a record of error messages is kept, and for the admin to regularly monitor the error logs. This may be done by setting &#039;Debug messages&#039; (debug) to Normal and leaving &#039;Display debug messages&#039; (debugdisplay) off (unticked). Error messages are then recorded in the server logs.&lt;br /&gt;
# If &#039;Debug messages&#039; is set to Developer on a production (public) site, it is recommended to copy and paste the debugging message obtained and then turn off Developer debugging. This is because debugging messages can give clues to a hacker as to the set-up of your site.&lt;br /&gt;
&lt;br /&gt;
===Debug email sending===&lt;br /&gt;
&lt;br /&gt;
Determines whether or not to enable verbose debug information during sending of email messages to SMTP server.&lt;br /&gt;
&lt;br /&gt;
==== More tools for debugging outgoing mail ====&lt;br /&gt;
You can also use the config.php file to turn on more &amp;quot;tools&amp;quot; which will assist you with debugging the outgoing emails (and SMTP server configuration):&lt;br /&gt;
* Redirect all outgoing emails to a specific address:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Divert all outgoing emails to this address to test and debug emailing features&lt;br /&gt;
// $CFG-&amp;gt;divertallemailsto = &#039;root@localhost.local&#039;; // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Turn on the CRON debugging and run CLI cron.php script.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Force developer level debug and add debug info to the output of cron&lt;br /&gt;
// $CFG-&amp;gt;showcrondebugging = true;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
And then use SSH (or putty.exe, on windows) to run:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
you@moodle-server(/var/www/html/moodle)# php admin/cli/cron.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Turn on verbose SMTP debugging and output it into system&#039;s error_log (code hack):&lt;br /&gt;
As [https://moodle.org/mod/forum/discuss.php?d=316222#p1289850 suggested] on Moodle&#039;s discussion forums:&lt;br /&gt;
Open [https://github.com/moodle/moodle/blob/master/lib/moodlelib.php#L5379 lib/moodlelib.php L5379] and change it to:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($CFG-&amp;gt;debugsmtp)) {&lt;br /&gt;
    $mailer-&amp;gt;SMTPDebug = 1;  // 0 - no debug ... 4 - low level full debug&lt;br /&gt;
    $mailer-&amp;gt;Debugoutput = &amp;quot;error_log&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
See more info about [https://github.com/moodle/moodle/blob/master/lib/phpmailer/class.phpmailer.php#L314 SMTPDebug] parameters &amp;amp; [https://github.com/moodle/moodle/blob/master/lib/phpmailer/class.phpmailer.php#L328 Debugoutput] parameters,&lt;br /&gt;
Set-up mailcatcher (https://mailcatcher.me/).&lt;br /&gt;
&lt;br /&gt;
===Performance info===&lt;br /&gt;
&lt;br /&gt;
The Performance info option determines whether performance info will be included in the footer of the standard theme (and some other themes). Performance info includes the time for the page to load, the amount of memory used to generate the page, cpu usage, load, and the record cache hit/miss ration.&lt;br /&gt;
&lt;br /&gt;
If you add&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
define(&#039;MDL_PERF&#039;, true);&lt;br /&gt;
define(&#039;MDL_PERFDB&#039;, true);&lt;br /&gt;
define(&#039;MDL_PERFTOLOG&#039;, true);&lt;br /&gt;
define(&#039;MDL_PERFTOFOOT&#039;, true);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
to your config.php file, then it will also count database queries. (This has to be in config.php, because Moodle starts doing DB queries before it loads the config information in the database!)&lt;br /&gt;
&lt;br /&gt;
To hide performance info from ordinary users, see the discussion [https://moodle.org/mod/forum/discuss.php?d=358032 Performance info only for admins?]&lt;br /&gt;
&lt;br /&gt;
===Show origin of language strings===&lt;br /&gt;
&lt;br /&gt;
Helps with [[:dev:Translation|translation]] and also with [[Language customization]]. Sometimes &amp;lt;code&amp;gt;?strings=1&amp;lt;/code&amp;gt; should be added; other times &amp;lt;code&amp;gt;&amp;amp;strings=1&amp;lt;/code&amp;gt;. See the Wikipedia article [http://en.wikipedia.org/wiki/Query_string Query string] for details.&lt;br /&gt;
&lt;br /&gt;
===Show validator links===&lt;br /&gt;
Be careful, read the warning.&lt;br /&gt;
&lt;br /&gt;
===Show page information===&lt;br /&gt;
To show page information printed in the page footer.&lt;br /&gt;
&lt;br /&gt;
==What to do if you cannot get to the admin screens==&lt;br /&gt;
&lt;br /&gt;
If the error is stopping you even getting to the admin screens to turn on debugging, then you can set the debugging setting manually.&lt;br /&gt;
&lt;br /&gt;
===Try typing the URL directly===&lt;br /&gt;
&lt;br /&gt;
The debug settings are at the URL &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;http://.../admin/settings.php?section=debugging&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; on your server. Sometimes that URL will work, even though the pages you need to go to get there (for example the site front page) do not. So it is worth trying to enter that URL directly.&lt;br /&gt;
&lt;br /&gt;
===In config.php===&lt;br /&gt;
&lt;br /&gt;
In [[Configuration file|config.php]] you can uncomment lines (delete the // at the start of the line) under Section 7 to enable debugging for all or just specific users:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//=========================================================================&lt;br /&gt;
// 7. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!!&lt;br /&gt;
//=========================================================================&lt;br /&gt;
//&lt;br /&gt;
// Force a debugging mode regardless the settings in the site administration&lt;br /&gt;
// @error_reporting(E_ALL | E_STRICT);   // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
// @ini_set(&#039;display_errors&#039;, &#039;1&#039;);         // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
// $CFG-&amp;gt;debug = (E_ALL | E_STRICT);   // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
// $CFG-&amp;gt;debugdisplay = 1;              // NOT FOR PRODUCTION SERVERS!&lt;br /&gt;
//&lt;br /&gt;
// You can specify a comma separated list of user ids that that always see&lt;br /&gt;
// debug messages, this overrides the debug flag in $CFG-&amp;gt;debug and $CFG-&amp;gt;debugdisplay&lt;br /&gt;
// for these users only.&lt;br /&gt;
// $CFG-&amp;gt;debugusers = &#039;2&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to comment those lines again (reinsert the // at the start of the line) when you have finished diagnosing your problem.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE 1&#039;&#039;&#039;: do not try to modify the config database table directly, it will not work because the values are cached in MUC.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE 2&#039;&#039;&#039;: if you find your config.php does not have the above settings (you have a cut down approx 30 lines config.php) look for a &amp;quot;config-dist.php&amp;quot; file that contains the full details. I would suggest transferring your details in the current config.php file you have into the full config file and renaming that one to &amp;quot;config.php&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Developers can also use [http://xdebug.org/ XDEBUG] (Installed as a module on the Apache server) to further dig into the code, step by step using an [http://xdebug.org/docs/remote XDEBUG client application]. Probably, as part of their favorite IDE. For example: [http://php.netbeans.org/ NetBeans], [http://www.jetbrains.com/phpstorm/ phpStorm] or...&lt;br /&gt;
&lt;br /&gt;
[[es:Depuración]]&lt;br /&gt;
[[fr:Débogage]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=130240</id>
		<title>ad-hoc contributed reports</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=130240"/>
		<updated>2018-03-06T20:36:54Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Sitewide reports}}&lt;br /&gt;
==User and Role Report==&lt;br /&gt;
&lt;br /&gt;
===Count number of distinct learners and teachers enrolled per category (including all its sub categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;SELECT COUNT(DISTINCT lra.userid) AS learners, COUNT(DISTINCT tra.userid) as teachers&lt;br /&gt;
FROM prefix_course AS c #, mdl_course_categories AS cats&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments  AS lra ON lra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role_assignments  AS tra ON tra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category = cats.id&lt;br /&gt;
AND (&lt;br /&gt;
	cats.path LIKE &#039;%/CATEGORYID/%&#039; #Replace CATEGORYID with the category id you want to count (eg: 80)&lt;br /&gt;
	OR cats.path LIKE &#039;%/CATEGORYID&#039;&lt;br /&gt;
	)&lt;br /&gt;
AND lra.roleid=5&lt;br /&gt;
AND tra.roleid=3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each ROLE (TEACHER, NON-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT r.name, l.action, COUNT( l.userid ) AS counter&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_role AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE ra.roleid IN ( 3, 4, 5 ) &lt;br /&gt;
GROUP BY roleid, l.action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student (user) COUNT in each Course===&lt;br /&gt;
Including (optional) filter by: year (if included in course fullname).&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/index.php?contextid=&#039;,context.id,&#039;&amp;quot;&amp;gt;Show users&amp;lt;/a&amp;gt;&#039;) AS Users&lt;br /&gt;
, COUNT(course.id) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS asg&lt;br /&gt;
JOIN prefix_context AS context ON asg.contextid = context.id AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_user AS user ON user.id = asg.userid&lt;br /&gt;
JOIN prefix_course AS course ON context.instanceid = course.id&lt;br /&gt;
WHERE asg.roleid = 5 &lt;br /&gt;
# AND course.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
GROUP BY course.id&lt;br /&gt;
ORDER BY COUNT(course.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enrolment count in each Course ===&lt;br /&gt;
&lt;br /&gt;
Shows the total number of enroled users of all roles in each course. Sorted by course name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname, COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LIST of all site USERS by COURSE enrollment (Moodle 2.x)===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) as Role&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) as RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course as course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enrolled users,which did not login into the Course, even once (Moodle 2)===&lt;br /&gt;
Designed forMoodle 2 table structure and uses special plugin filter : %%FILTER_SEARCHTEXT:table.field%%&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id as ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
user2.idnumber AS IDNumber,&lt;br /&gt;
user2.phone1 AS Phone,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
&lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id and courseid=c.id) as CourseLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id and e.courseid = c.id) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments as ue&lt;br /&gt;
JOIN prefix_enrol as e on e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user as user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess as ul on ul.userid = user2.id&lt;br /&gt;
WHERE c.id=16 AND ul.timeaccess IS NULL&lt;br /&gt;
%%FILTER_SEARCHTEXT:user2.firstname%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Role assignments on categories===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS category,&lt;br /&gt;
cc.depth, cc.path, r.name AS role,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php?id=&#039;,usr.id,&#039;&amp;quot;&amp;gt;&#039;,usr.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS name,&lt;br /&gt;
usr.firstname, usr.username, usr.email&lt;br /&gt;
FROM prefix_course_categories cc&lt;br /&gt;
INNER JOIN prefix_context cx ON cc.id = cx.instanceid&lt;br /&gt;
AND cx.contextlevel = &#039;40&#039;&lt;br /&gt;
INNER JOIN prefix_role_assignments ra ON cx.id = ra.contextid&lt;br /&gt;
INNER JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
INNER JOIN prefix_user usr ON ra.userid = usr.id&lt;br /&gt;
ORDER BY cc.depth, cc.path, usr.lastname, usr.firstname, r.name, cc.name&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Permissions Overides on Categories===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712834 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT rc.id, ct.instanceid, ccat.name, rc.roleid, rc.capability, rc.permission, &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( rc.timemodified ) , &#039;%Y-%m-%d&#039; ) AS timemodified, rc.modifierid, ct.instanceid, ct.path, ct.depth&lt;br /&gt;
FROM `prefix_role_capabilities` AS rc&lt;br /&gt;
INNER JOIN `prefix_context` AS ct ON rc.contextid = ct.id&lt;br /&gt;
INNER JOIN `prefix_course_categories` AS ccat ON ccat.id = ct.instanceid&lt;br /&gt;
AND `contextlevel` =40&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;Totally Opened Courses&amp;quot; (visible, opened to guests, with no password)===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712837 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Course&#039;,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/enrol/instances.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Méthodes inscription&amp;lt;/a&amp;gt;&#039;) AS &#039;Enrollment plugins&#039;,&lt;br /&gt;
e.sortorder&lt;br /&gt;
FROM prefix_enrol AS e, prefix_course AS c&lt;br /&gt;
WHERE e.enrol=&#039;guest&#039; AND e.status=0 AND e.password=&#039;&#039; AND c.id=e.courseid AND c.visible=1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;loggedin users&amp;quot; from the last 120 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id,username,FROM_UNIXTIME(`lastlogin`) as days &lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;and user count for that same population:&#039;&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(id) as Users  FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists the users who have only logged into the site once===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, username, firstname, lastname, idnumber&lt;br /&gt;
FROM prefix_user&lt;br /&gt;
WHERE prefix_user.deleted = 0&lt;br /&gt;
AND prefix_user.lastlogin = 0 &lt;br /&gt;
AND prefix_user.lastaccess &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Students in all courses of some institute===&lt;br /&gt;
What is the status (deleted or not) of all Students (roleid = 5) in all courses of some Institute&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname, u.firstname, u.lastname, u.deleted&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND u.institution = &#039;please enter school name here&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Full User info (for deleted users)===&lt;br /&gt;
Including extra custom profile fields (from prefix_user_info_data)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT * &lt;br /&gt;
FROM prefix_user as u &lt;br /&gt;
JOIN prefix_user_info_data as uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_user_info_field as uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;class&#039;)&lt;br /&gt;
WHERE `deleted` = &amp;quot;1&amp;quot; and `institution`=&amp;quot;your school name&amp;quot; and `department` = &amp;quot;your department&amp;quot; and `data` = &amp;quot;class level and number&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User&#039;s courses===&lt;br /&gt;
change &amp;quot;u.id = 2&amp;quot; with a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, c.id, c.fullname&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE u.id = 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Users with extra info (email) in current course===&lt;br /&gt;
blocks/configurable_reports replaces %%COURSEID%% with course id.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, u.email&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Special Roles===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.roleid,r.name&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,ra.userid,&#039;&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Username&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON (ctx.id = ra.contextid AND ctx.contextlevel = 50)&lt;br /&gt;
JOIN prefix_course AS c ON ctx.instanceid = c.id&lt;br /&gt;
WHERE ra.roleid &amp;gt; 6&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses without Teachers===&lt;br /&gt;
Actually, shows the number of Teachers in a course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Teachers&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
ORDER BY Teachers ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of users who have been enrolled for more than 4 weeks===&lt;br /&gt;
For Moodle 2.2 , by  Isuru Madushanka Weerarathna &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT uenr.userid As User, IF(enr.courseid=uenr.courseid ,&#039;Y&#039;,&#039;N&#039;) As Enrolled, &lt;br /&gt;
IF(DATEDIFF(NOW(), FROM_UNIXTIME(uenr.timecreated))&amp;gt;=28,&#039;Y&#039;,&#039;N&#039;) As EnrolledMoreThan4Weeks&lt;br /&gt;
FROM prefix_enrol As enr, prefix_user_enrolments AS uenr&lt;br /&gt;
WHERE enr.id = uenr.enrolid AND enr.status = uenr.status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with language===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
This will show you the language setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, lang from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools.&lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;en&#039; to &#039;en_us&#039; for all users:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To do this for only users who have a particular country set, use this as an example:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE country = &#039;US&#039; AND lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with Authentication ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Sometimes you need to do mass changes of authentication methods. A common case is changing default manual to LDAP. &lt;br /&gt;
&lt;br /&gt;
This will show you the Authentication setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, auth from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools. &lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;manual&#039; to &#039;ldap&#039; 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.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET auth = &#039;ldap&#039; WHERE auth = &#039;manual&#039; AND id &amp;gt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compare role capability and permissions ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT mrc.capability &lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;1&#039; AND rc.contextid = &#039;1&#039;) AS Manager&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;2&#039; AND rc.contextid = &#039;1&#039;) AS CourseCreator&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;3&#039; AND rc.contextid = &#039;1&#039;) AS Teacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;4&#039; AND rc.contextid = &#039;1&#039;) AS AssistantTeacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;5&#039; AND rc.contextid = &#039;1&#039;) AS Student&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;6&#039; AND rc.contextid = &#039;1&#039;) AS Guest&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_role_capabilities` AS mrc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User&#039;s accumulative time spent in course ===&lt;br /&gt;
A sum up of the time delta between logstore_standard_log user&#039;s records, considering the a 2 hour session limit.&lt;br /&gt;
&lt;br /&gt;
Uses: current user&#039;s id %%USERID%% and current course&#039;s id %%COURSEID%%  &lt;br /&gt;
&lt;br /&gt;
And also using a date filter (which can be ignored)  &lt;br /&gt;
&lt;br /&gt;
The extra &amp;quot;User&amp;quot; field is used as a dummy field for the Line chart Series field, in which I use X=id, Series=Type, Y=delta.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
l.id, &lt;br /&gt;
l.timecreated, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(l.timecreated),&#039;%d-%m-%Y&#039;) AS dTime,&lt;br /&gt;
@prevtime := (SELECT max(timecreated) FROM mdl_logstore_standard_log &lt;br /&gt;
		WHERE userid = %%USERID%% and id &amp;lt; l.id ORDER BY id ASC LIMIT 1) AS prev_time,&lt;br /&gt;
IF (l.timecreated - @prevtime &amp;lt; 7200, @delta := @delta + (l.timecreated-@prevtime),0) AS sumtime,&lt;br /&gt;
l.timecreated-@prevtime AS delta,&lt;br /&gt;
&amp;quot;User&amp;quot; as type&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log as l, &lt;br /&gt;
(SELECT @delta := 0) AS s_init &lt;br /&gt;
# Change UserID&lt;br /&gt;
WHERE l.userid = %%USERID%% AND l.courseid = %%COURSEID%%&lt;br /&gt;
%%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Low-Participation Student Report ===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
This report returns a list of students who are enrolled in courses filtered by a short-name text marker (in this case &amp;quot;OL-&amp;quot;) in the specified category, but have very low participation in the course during the specified time period (fewer than 2 &amp;quot;Edits&amp;quot; to Activity Modules, indicating few active contributions to the course). The number of &amp;quot;Edits&amp;quot; is provided for each student for the time period specified.&lt;br /&gt;
&lt;br /&gt;
An &amp;quot;Edit&amp;quot; is defined as course activity other than viewing content. Click the &amp;quot;Logs&amp;quot; link to review the student activity. The Logs offer the option to review &amp;quot;View&amp;quot; activity as well as &amp;quot;Edit&amp;quot; activity.&lt;br /&gt;
&lt;br /&gt;
Only &amp;quot;visible&amp;quot; courses are included in this report. The report may be downloaded as an Excel spreadsheet.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t forget to set up Filters: &amp;quot;Start / End date filter&amp;quot; and &amp;quot;Filter categories&amp;quot; on the Filters tab in Configurable reports.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname AS Last, u.firstname AS First, u.idnumber AS IDnumber, u.email AS email, c.shortname AS CourseID,  count(l.id) AS Edits, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;https://learn.granite.edu/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=-view&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id AND l.action NOT LIKE &amp;quot;view%&amp;quot; %%FILTER_STARTTIME:l.TIME:&amp;gt;%% %%FILTER_ENDTIME:l.TIME:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.visible=1&lt;br /&gt;
# This prefix filter allows the exclusion of non-online courses at the original institution. Alter this to fit your institution, or remove it.&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
%%FILTER_CATEGORIES:c.category%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
HAVING Edits &amp;lt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Messages of All Users in a Specific Course ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
This query shows the personal messages between users in a specific course, given the course id number. Properly speaking, personal messages pertain only to users and are not part of courses, but by filtering enrollments for roles in a course, you can show this. &lt;br /&gt;
&lt;br /&gt;
This report as is shows only the messages between Teachers and Students, as the WHERE statement contains and AND ((...))) section that restrict this report to ONLY messages between Teachers (role id = 3) and Students (role id =5). Remove that part of the statement if you wish to see _all_ messages between all users, e.g. teachers to teachers, student to student. &lt;br /&gt;
&lt;br /&gt;
Also, if you have created custom roles, you can replace the default id numbers with custom ones to further enhance the report.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.username AS &#039;From&#039;,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS &#039;From Name&#039;,&lt;br /&gt;
u2.username AS &#039;To&#039;,&lt;br /&gt;
CONCAT(u2.firstname ,&#039; &#039;,u2.lastname) AS &#039;To Name&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(me.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;,&lt;br /&gt;
me.subject AS &#039;Subject&#039;, &lt;br /&gt;
me.smallmessage AS &#039;Message&#039;&lt;br /&gt;
FROM prefix_message me&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = me.useridfrom AND ra.roleid IN (3,4,5)  &lt;br /&gt;
JOIN prefix_role_assignments AS ra2 ON ra2.userid = me.useridto AND ra2.roleid IN (3,4,5)  &lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id AND ra2.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_user u ON u.id = me.useridfrom&lt;br /&gt;
JOIN prefix_user u2 ON u2.id = me.useridto&lt;br /&gt;
WHERE c.id=## &lt;br /&gt;
AND ((ra.roleid = 3 AND ra2.roleid = 5) OR (ra.roleid = 5 AND ra2.roleid = 3)) &lt;br /&gt;
ORDER BY me.useridfrom, me.useridto, me.timecreated&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Log Activity Reports==&lt;br /&gt;
===Count all Active Users by ROLE in a course category (including all of its sub-categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT l.userid) as active&lt;br /&gt;
FROM mdl_course as c&lt;br /&gt;
JOIN mdl_context AS ctx ON  ctx.instanceid=c.id&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN mdl_user_lastaccess as l ON ra.userid = l.userid&lt;br /&gt;
JOIN mdl_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category=cats.id AND (&lt;br /&gt;
	cats.path LIKE &#039;%/80/%&#039;&lt;br /&gt;
	OR cats.path LIKE &#039;%/80&#039;&lt;br /&gt;
) &lt;br /&gt;
AND ra.roleid=3  AND ctx.contextlevel=50  #ra.roleid= TEACHER 3, NON-EDITING TEACHER 4, STUDENT 5&lt;br /&gt;
AND  l.timeaccess &amp;gt; (unix_timestamp() - ((60*60*24)*NO_OF_DAYS)) #NO_OF_DAYS change to number&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Detailed &amp;quot;VIEW&amp;quot; ACTION for each ROLE (TEACHER,NONE-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT l.action, count( l.userid ) as counter , r.name&lt;br /&gt;
FROM `prefix_log` as l&lt;br /&gt;
JOIN `prefix_role_assignments` AS ra on l.userid = ra.userid&lt;br /&gt;
JOIN `prefix_role` AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE (ra.roleid IN (3,4,5)) AND (l.action LIKE &#039;%view%&#039; )&lt;br /&gt;
GROUP BY roleid,l.action&lt;br /&gt;
order by r.name,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total Activity of Roles:&amp;quot;Teacher&amp;quot; and &amp;quot;None-Editing Teacher&amp;quot; by Dates and by Hours===&lt;br /&gt;
The output columns of this report table can be used as base for a Pivot-Table&lt;br /&gt;
which will show the amount of &#039;&#039;&#039;activity&#039;&#039;&#039; per &#039;&#039;&#039;hour&#039;&#039;&#039; per &#039;&#039;&#039;days&#039;&#039;&#039; in 3D graph view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%Y-%m-%d&#039; ) AS grptimed ,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%k&#039; ) AS grptimeh  , count( l.userid ) AS counter &lt;br /&gt;
FROM `prefix_log` AS l&lt;br /&gt;
JOIN prefix_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
WHERE ra.roleid IN (3,4)&lt;br /&gt;
GROUP BY grptimed,grptimeh&lt;br /&gt;
ORDER BY grptimed,grptimeh&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many LOGINs per user and user&#039;s Activity===&lt;br /&gt;
+ link username to a user activity graph report&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,u.id,&#039;&amp;amp;mode=alllogs&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) as Username&lt;br /&gt;
,count(*) as logins&lt;br /&gt;
,(SELECT count(*) FROM prefix_log WHERE userid = l.userid GROUP BY userid) as Activity &lt;br /&gt;
FROM prefix_log as l JOIN prefix_user as u ON l.userid = u.id &lt;br /&gt;
WHERE `action` LIKE &#039;%login%&#039; group by userid&lt;br /&gt;
ORDER BY Activity DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Distinct user logins per month===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
The following will show you the months of the current calendar year with the total number of distinct, unique user logins per month. Change the year in the WHERE clause to the year you need.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
 COUNT(DISTINCT l.userid) AS &#039;DistinctUserLogins&#039;, &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%M&#039;) AS &#039;Month&#039;&lt;br /&gt;
FROM prefix_logstore_standard_log l&lt;br /&gt;
WHERE l.action = &#039;loggedin&#039; AND YEAR(FROM_UNIXTIME(l.timecreated)) = &#039;2017&#039; &lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(l.timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total activity per course, per unique user on the last 24h===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    COUNT(DISTINCT userid) AS countUsers&lt;br /&gt;
  , COUNT(l.courseid) AS countVisits&lt;br /&gt;
  , CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
  JOIN mdl_course AS c ON c.id = l.courseid&lt;br /&gt;
WHERE l.courseid &amp;gt; 0&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 1 DAY)&lt;br /&gt;
      AND c.fullname LIKE &#039;%תשעו%&#039;&lt;br /&gt;
GROUP BY l.courseid&lt;br /&gt;
ORDER BY countVisits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Instructor Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of instructors in all courses per week of a term, including pre-term and post-term edits. An edit is defined as a change to the course, such as a discussion post, the grading of an assignment, or the uploading of file attachments, as well as alterations to course content.&lt;br /&gt;
&lt;br /&gt;
* To specify a subject and/or course number, use % as a wildcard, e.g. ARTS% or ARTS501%&lt;br /&gt;
* To match part of a last name, use %, e.g. Smi% will match &amp;quot;Smith&amp;quot;, &amp;quot;Smile&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
At our institution, we include filters on the course name or category to constrain by terms. These are very specific to how course names and categories are constructed at our institution, so I&#039;ve removed those elements from this code. Also, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; lines for longer terms, or remove lines for shorter terms.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version uses legacy (pre-2.7) logs. See below for post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, c.startdate AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time)) - WEEK(FROM_UNIXTIME(c.startdate))&amp;lt;0,1,0)) AS BeforeTerm&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=0,1,0)) AS Week1&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=1,1,0)) AS Week2&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=2,1,0)) AS Week3&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=3,1,0)) AS Week4&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=4,1,0)) AS Week5&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=5,1,0)) AS Week6&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=6,1,0)) AS Week7&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=7,1,0)) AS Week8&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=8,1,0)) AS Week9&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=9,1,0)) AS Week10&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=10,1,0)) AS Week11&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=11,1,0)) AS Week12&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))&amp;gt;=12,1,0)) AS AfterTerm&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE :course&lt;br /&gt;
AND u.lastname LIKE :last_name&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 log version:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(DISTINCT l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
AND cc.idnumber LIKE &#039;%current%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
#HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY RIGHT(c.shortname,2), c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Student Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of students in the current course by week, including pre-term and post-term edits. An 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 (if permitted).&lt;br /&gt;
&lt;br /&gt;
Links to three other reports are also provided:&lt;br /&gt;
&lt;br /&gt;
* Logs: complete log entries for the student in the course, organized by date&lt;br /&gt;
* Activity Outline: the &amp;quot;Outline Report&amp;quot; from the User Activity Reports, summarizing the student&#039;s activity in the course, organized by course content&lt;br /&gt;
* Consolidated Activity Report: the &amp;quot;Complete Report&amp;quot; from the User Activity Reports, detailing the student&#039;s activity in the course, organized by course content (includes text of forum posts)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). At our institution, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for a post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF((l.time-c.startdate)/7&amp;lt;0,1,0)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=0,1,0)) AS &#039;Week 1&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=1,1,0)) AS &#039;Week 2&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=2,1,0)) AS &#039;Week 3&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=3,1,0)) AS &#039;Week 4&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=4,1,0)) AS &#039;Week 5&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=5,1,0)) AS &#039;Week 6&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=6,1,0)) AS &#039;Week 7&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=7,1,0)) AS &#039;Week 8&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=8,1,0)) AS &#039;Week 9&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=9,1,0)) AS &#039;Week 10&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=10,1,0)) AS &#039;Week 11&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=11,1,0)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))&amp;gt;=15,1,0)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 (Standard Logs) version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
# Our institution stores academic advisor names and emails in custom profile fields&lt;br /&gt;
#, CONCAT(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,uce.data,&#039;&amp;quot;&amp;gt;&#039;,uid.data, &#039;&amp;lt;/a&amp;gt;&#039;)  AS &#039;Academic Advisor&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,&#039;Posts&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Posts&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# student academic coach - you can include custom profile field data with these methods&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uid ON u.id = uid.userid AND uid.fieldid = &#039;2&#039;&lt;br /&gt;
# student academic coach email&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uce on u.id = uce.userid AND uce.fieldid = &#039;6&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===My Weekly Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of the &#039;&#039;&#039;current user&#039;&#039;&#039; in the &#039;&#039;&#039;current course&#039;&#039;&#039; 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).&lt;br /&gt;
&lt;br /&gt;
This report uses Standard Logs (post 2.7).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
l.component AS &#039;activity&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS &#039;Total&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE 1&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
AND u.id = %%USERID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY l.component&lt;br /&gt;
&lt;br /&gt;
ORDER BY l.component&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Faculty/Student Interactions===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Returns a count of instructor and other-student responses to student activity for the specified time period. This report can help indicate whether students&#039; comments are being responded to, as well as summarizing post activity by students during the specified time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for the post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This report can take a long time to run. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
LEFT JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
# We care about messages that involve both the instructor and students of this course&lt;br /&gt;
# messages from instructor to students:&lt;br /&gt;
# LEFT JOIN prefix_message AS mts ON mts.useridfrom = instr.id AND mts.useridto = allstu.id&lt;br /&gt;
# LEFT JOIN prefix_message AS mfs ON mfs.useridfrom = instr.id AND mfs.useridto = allstu.id&lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 Standard Logs version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
 JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student Resource Usage===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Standard Logs&amp;quot; from Moodle 2.7+.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
, m.name AS &#039;item type&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&lt;br /&gt;
COALESCE(a.name, &#039;&#039;), &lt;br /&gt;
COALESCE(b.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cert.name,&#039;&#039;), &lt;br /&gt;
COALESCE(chat.name,&#039;&#039;), &lt;br /&gt;
COALESCE(choice.name,&#039;&#039;), &lt;br /&gt;
COALESCE(data.name,&#039;&#039;), &lt;br /&gt;
COALESCE(feedback.name,&#039;&#039;), &lt;br /&gt;
COALESCE(folder.name,&#039;&#039;), &lt;br /&gt;
COALESCE(forum.name,&#039;&#039;), &lt;br /&gt;
COALESCE(glossary.name,&#039;&#039;), &lt;br /&gt;
COALESCE(imscp.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lesson.name,&#039;&#039;), &lt;br /&gt;
COALESCE(p.name,&#039;&#039;),&lt;br /&gt;
COALESCE(questionnaire.name,&#039;&#039;), &lt;br /&gt;
COALESCE(quiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cr.name,&#039;&#039;), &lt;br /&gt;
COALESCE(scorm.name,&#039;&#039;), &lt;br /&gt;
COALESCE(survey.name,&#039;&#039;), &lt;br /&gt;
COALESCE(url.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(workshop.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kalvidassign.name,&#039;&#039;), &lt;br /&gt;
COALESCE(attendance.name,&#039;&#039;), &lt;br /&gt;
COALESCE(checklist.name,&#039;&#039;), &lt;br /&gt;
COALESCE(flashcard.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lti.name,&#039;&#039;), &lt;br /&gt;
COALESCE(oublog.name,&#039;&#039;), &lt;br /&gt;
COALESCE(ouwiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(subpage.name,&#039;&#039;), &lt;br /&gt;
COALESCE(journal.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lightboxgallery.name,&#039;&#039;), &lt;br /&gt;
COALESCE(elluminate.name,&#039;&#039;), &lt;br /&gt;
COALESCE(adaptivequiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(hotpot.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiziq.name,&#039;&#039;), &lt;br /&gt;
COALESCE(turnitintooltwo.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kvr.name,&#039;&#039;)&lt;br /&gt;
) AS &#039;item name&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;r&#039;),1,0)) AS &#039;total views&#039;&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),1,0)) AS &#039;total submissions&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;r&#039;),u.id,NULL)) AS &#039;count of students who viewed&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),u.id,NULL)) AS &#039;count of students who submitted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 #AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module AND m.name NOT LIKE &#039;label&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON a.id = cm.instance AND m.name = &#039;assign&#039;&lt;br /&gt;
LEFT JOIN prefix_book AS b ON b.id = cm.instance AND m.name = &#039;book&#039;&lt;br /&gt;
LEFT JOIN prefix_certificate AS cert ON cert.id = cm.instance AND m.name = &#039;certificate&#039;&lt;br /&gt;
LEFT JOIN prefix_chat AS chat ON chat.id = cm.instance AND m.name = &#039;chat&#039;&lt;br /&gt;
LEFT JOIN prefix_choice AS choice ON choice.id = cm.instance AND m.name = &#039;choice&#039;&lt;br /&gt;
LEFT JOIN prefix_data AS data ON data.id = cm.instance AND m.name = &#039;data&#039;&lt;br /&gt;
LEFT JOIN prefix_feedback AS feedback ON feedback.id = cm.instance AND m.name = &#039;feedback&#039;&lt;br /&gt;
LEFT JOIN prefix_folder AS folder ON folder.id = cm.instance AND m.name = &#039;folder&#039;&lt;br /&gt;
LEFT JOIN prefix_forum AS forum ON forum.id = cm.instance AND m.name = &#039;forum&#039;&lt;br /&gt;
LEFT JOIN prefix_glossary AS glossary ON glossary.id = cm.instance AND m.name = &#039;glossary&#039;&lt;br /&gt;
LEFT JOIN prefix_imscp AS imscp ON imscp.id = cm.instance AND m.name = &#039;imscp&#039;&lt;br /&gt;
LEFT JOIN prefix_lesson AS lesson ON lesson.id = cm.instance AND m.name = &#039;lesson&#039;&lt;br /&gt;
LEFT JOIN prefix_page AS p ON p.id = cm.instance AND m.name = &#039;page&#039;&lt;br /&gt;
LEFT JOIN prefix_questionnaire AS questionnaire ON questionnaire.id = cm.instance AND m.name = &#039;questionnaire&#039;&lt;br /&gt;
LEFT JOIN prefix_quiz AS quiz ON quiz.id = cm.instance AND m.name = &#039;quiz&#039;&lt;br /&gt;
LEFT JOIN prefix_resource AS cr ON cr.id = cm.instance AND m.name = &#039;resource&#039;&lt;br /&gt;
LEFT JOIN prefix_scorm AS scorm ON scorm.id = cm.instance AND m.name = &#039;scorm&#039;&lt;br /&gt;
LEFT JOIN prefix_survey AS survey ON survey.id = cm.instance AND m.name = &#039;survey&#039;&lt;br /&gt;
LEFT JOIN prefix_url AS url ON url.id = cm.instance AND m.name = &#039;url&#039;&lt;br /&gt;
LEFT JOIN prefix_wiki AS wiki ON wiki.id = cm.instance AND m.name = &#039;wiki&#039;&lt;br /&gt;
LEFT JOIN prefix_workshop AS workshop ON workshop.id = cm.instance AND m.name = &#039;workshop&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidassign AS kalvidassign ON kalvidassign.id = cm.instance AND m.name = &#039;kalvidassign&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidres AS kvr ON kvr.id = cm.instance AND m.name = &#039;kalvidres&#039;&lt;br /&gt;
LEFT JOIN prefix_attendance AS attendance ON attendance.id = cm.instance AND m.name = &#039;attendance&#039;&lt;br /&gt;
LEFT JOIN prefix_checklist AS checklist ON checklist.id = cm.instance AND m.name = &#039;checklist&#039;&lt;br /&gt;
LEFT JOIN prefix_flashcard AS flashcard ON flashcard.id = cm.instance AND m.name = &#039;flashcard&#039;&lt;br /&gt;
LEFT JOIN prefix_lti AS lti ON lti.id = cm.instance AND m.name = &#039;lti&#039;&lt;br /&gt;
LEFT JOIN prefix_oublog AS oublog ON oublog.id = cm.instance AND m.name = &#039;oublog&#039;&lt;br /&gt;
LEFT JOIN prefix_ouwiki AS ouwiki ON ouwiki.id = cm.instance AND m.name = &#039;ouwiki&#039;&lt;br /&gt;
LEFT JOIN prefix_subpage AS subpage ON subpage.id = cm.instance AND m.name = &#039;subpage&#039;&lt;br /&gt;
LEFT JOIN prefix_journal AS journal ON journal.id = cm.instance AND m.name = &#039;journal&#039;&lt;br /&gt;
LEFT JOIN prefix_lightboxgallery AS lightboxgallery ON lightboxgallery.id = cm.instance AND m.name = &#039;lightboxgallery&#039;&lt;br /&gt;
LEFT JOIN prefix_elluminate AS elluminate ON elluminate.id = cm.instance AND m.name = &#039;elluminate&#039;&lt;br /&gt;
LEFT JOIN prefix_adaptivequiz AS adaptivequiz ON adaptivequiz.id = cm.instance AND m.name = &#039;adaptivequiz&#039;&lt;br /&gt;
LEFT JOIN prefix_hotpot AS hotpot ON hotpot.id = cm.instance AND m.name = &#039;hotpot&#039;&lt;br /&gt;
LEFT JOIN prefix_wiziq AS wiziq ON wiziq.id = cm.instance AND m.name = &#039;wiziq&#039;&lt;br /&gt;
LEFT JOIN prefix_turnitintooltwo AS turnitintooltwo ON turnitintooltwo.id = cm.instance AND m.name = &#039;turnitintooltwo&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cm.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Hits) between dates===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module, COUNT( * ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME( l.`time` ) BETWEEN  &#039;2012-10-01 00:00:00&#039; AND  &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
GROUP BY module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Instances and Hits) for each academic year===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2010-10-01 00:00:00&#039; AND &#039;2011-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2010-10-01 00:00:00&#039; AND &#039;2011-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2011-10-01 00:00:00&#039; AND &#039;2012-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2011&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2011-10-01 00:00:00&#039; AND &#039;2012-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2011&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2012-10-01 00:00:00&#039; AND &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2012&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2012-10-01 00:00:00&#039; AND &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2012&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_modules AS m&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Unique user sessions per day and month + graph===&lt;br /&gt;
The &amp;quot;graph&amp;quot; column is used when displaying a graph (which needs at least three columns to pick from)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT userid) AS &amp;quot;Unique User Logins&amp;quot;&lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y /%m / %d&amp;quot;) AS &amp;quot;Year / Month / Day&amp;quot;, &amp;quot;Graph&amp;quot; &lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE action LIKE &#039;loggedin&#039;&lt;br /&gt;
#AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) # optional start date&lt;br /&gt;
#AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:00&#039;) # optional end date&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And...&lt;br /&gt;
&lt;br /&gt;
Counting user&#039;s global and unique hits per day + counting individual usage of specific activities and resources (on that day),&lt;br /&gt;
&lt;br /&gt;
And since I am using phpMyAdmin&#039;s &amp;quot;Display Graph&amp;quot; feature (at the bottom of the query&#039;s output page), I have scaled down the &amp;quot;User Hits&amp;quot; by 10 to fit the graph. that&#039;s it.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y-%m-%d&amp;quot;) AS &amp;quot;Datez&amp;quot;&lt;br /&gt;
,COUNT(DISTINCT userid) AS &amp;quot;Unique Users&amp;quot;&lt;br /&gt;
,ROUND(COUNT(*)/10) &amp;quot;User Hits (K)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_quiz&#039;,1,0)) &amp;quot;Quizzes&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_forum&#039; or component=&#039;mod_forumng&#039;,1,0)) &amp;quot;Forums&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_assign&#039;,1,0)) &amp;quot;Assignments&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_oublog&#039;,1,0)) &amp;quot;Blogs&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_resource&#039;,1,0)) &amp;quot;Files (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_url&#039;,1,0)) &amp;quot;Links (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_page&#039;,1,0)) &amp;quot;Pages (Resource)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE 1=1&lt;br /&gt;
AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-03-01 00:00:00&#039;) # optional START DATE&lt;br /&gt;
AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-05-31 23:59:00&#039;) # optional END DATE&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide, daily unique user hits for the last 7 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
  DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%m%d&#039;) &#039;Day&#039;&lt;br /&gt;
  ,COUNT(DISTINCT l.userid) AS &#039;Distinct Users Hits&#039;&lt;br /&gt;
  ,COUNT( l.userid) AS &#039;Users Hits&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
WHERE l.courseid &amp;gt; 1&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 7 DAY)&lt;br /&gt;
GROUP BY DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User detailed activity in course modules===&lt;br /&gt;
Considering only several modules: url, resource, forum, quiz, questionnaire.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.id, ra.roleid,&lt;br /&gt;
CONCAT(u.lastname, &#039; &#039;, u.firstname) AS &#039;Student&#039;&lt;br /&gt;
,COUNT(l.id) AS &#039;Actions&#039;&lt;br /&gt;
,l.component &amp;quot;Module type&amp;quot;&lt;br /&gt;
,l.objectid &amp;quot;Module ID&amp;quot;&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN l.component = &#039;mod_url&#039; THEN (SELECT u.name FROM mdl_url AS u WHERE u.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_resource&#039; THEN (SELECT r.name FROM mdl_resource AS r WHERE r.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_forum&#039; THEN (SELECT f.name FROM mdl_forum AS f WHERE f.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_quiz&#039; THEN (SELECT q.name FROM mdl_quiz AS q WHERE q.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_questionnaire&#039; THEN (SELECT q.name FROM mdl_questionnaire AS q WHERE q.id = l.objectid )&lt;br /&gt;
END AS &#039;Module name&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = l.courseid AND m.userid = u.id) &amp;quot;user_groups&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT s.name &lt;br /&gt;
  FROM mdl_course_modules AS cm &lt;br /&gt;
  JOIN mdl_course_sections AS s ON s.course = cm.course AND s.id = cm.section &lt;br /&gt;
  WHERE cm.id = l.contextinstanceid) AS &amp;quot;Section name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l  &lt;br /&gt;
JOIN mdl_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.userid = l.userid &lt;br /&gt;
  AND ra.contextid = (SELECT id FROM mdl_context WHERE instanceid = l.courseid AND contextlevel = 50) &lt;br /&gt;
WHERE l.courseid = %%COURSEID%%&lt;br /&gt;
  AND l.component IN (&#039;mod_url&#039;, &#039;mod_resource&#039;, &#039;mod_forum&#039;, &#039;mod_quiz&#039;, &#039;mod_questionnaire&#039;) &lt;br /&gt;
  %%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%%&lt;br /&gt;
 &lt;br /&gt;
GROUP BY u.id, l.component&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What teachers and courses considered active?===&lt;br /&gt;
This report display several calculations and parameters that help the Online academic training team find teachers that might need more support getting their courses more supporting of online learning pedagogical methodologies.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,&lt;br /&gt;
			  course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
#,course.shortname&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2012%&#039; THEN &#039;2012&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2013%&#039; THEN &#039;2013&#039; &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2014%&#039; THEN &#039;2014&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2015%&#039; THEN &#039;2015&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester a%&#039; THEN &#039;Spring semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester b%&#039; THEN &#039;Fall semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester s%&#039; THEN &#039;Summer semester&#039;&lt;br /&gt;
END AS Semester&lt;br /&gt;
&lt;br /&gt;
,IF(course.startdate&amp;gt;0, DATE_FORMAT(FROM_UNIXTIME(startdate), &#039;%d-%m-%Y&#039;), &#039;no date&#039;) AS &amp;quot;Course Start Date&amp;quot; &lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 4 AND ctx.instanceid = course.id&lt;br /&gt;
) AS &amp;quot;Assistant teacher&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
&lt;br /&gt;
# Uncomment to use the new Moodle 2.8+ logstore&lt;br /&gt;
#,(SELECT COUNT(*) FROM mdl_logstore_standard_log AS l WHERE l.courseid = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Student HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Teacher HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_log AS l WHERE l.course = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course c&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = c.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND c.id = course.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
  &lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = course.id) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(DISTINCT cm.module) FROM prefix_course_modules cm &lt;br /&gt;
  WHERE cm.course = course.id) UniqueModules&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(DISTINCT m.name) &lt;br /&gt;
  FROM prefix_course_modules cm &lt;br /&gt;
  JOIN mdl_modules as m ON m.id = cm.module&lt;br /&gt;
  WHERE cm.course = course.id) UniqueModuleNames&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;ouwiki&#039;, &#039;wiki&#039;) ) &amp;quot;Num Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;oublog&#039;) ) &amp;quot;Num Blogs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;forum&#039;, &#039;forumng&#039;) ) &amp;quot;Num Forums&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;resource&#039;, &#039;folder&#039;, &#039;url&#039;, &#039;tab&#039;, &#039;file&#039;, &#039;book&#039;, &#039;page&#039;) ) Resources&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;forum&#039;, &#039;forumng&#039;, &#039;oublog&#039;, &#039;page&#039;, &#039;file&#039;, &#039;url&#039;, &#039;wiki&#039; , &#039;ouwiki&#039;) ) &amp;quot;Basic Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;advmindmap&#039;, &#039;assign&#039;, &#039;attendance&#039;, &#039;book&#039;, &#039;choice&#039;, &#039;folder&#039;, &#039;tab&#039;, &#039;glossary&#039;, &#039;questionnaire&#039;, &#039;quiz&#039;, &#039;label&#039; ) ) &amp;quot;Avarage Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;elluminate&#039;, &#039;game&#039;, &#039;workshop&#039;) ) &amp;quot;Advanced Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course&lt;br /&gt;
&lt;br /&gt;
#WHERE course.shortname LIKE &#039;%2015%&#039;&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_SEARCHTEXT:course.shortname:~%%&lt;br /&gt;
&lt;br /&gt;
WHERE course.fullname LIKE &#039;%2015%&#039; &lt;br /&gt;
&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY UniqueModules DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly attendance report===&lt;br /&gt;
This report display weekly report in format HH:M:SS This MySQL query works together with AttendaceRegister module, and gather Log information from Attendanceregister_log table. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, SEC_TO_TIME (SUM(arsess.duration)) AS weekly_online_attendance,  FROM_UNIXTIME (arsess.logout) AS Last_Logout&lt;br /&gt;
FROM prefix_attendanceregister_session AS arsess&lt;br /&gt;
JOIN prefix_user AS u ON arsess.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE (((arsess.logout) BETWEEN UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 7 DAY)) AND UNIX_TIMESTAMP(CURDATE())))&lt;br /&gt;
&lt;br /&gt;
GROUP BY arsess.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Course Reports==&lt;br /&gt;
===Most Active courses===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(l.userid) AS Views&lt;br /&gt;
FROM `mdl_logstore_standard_log` l, `mdl_user` u, `mdl_role_assignments` r&lt;br /&gt;
WHERE l.courseid=35&lt;br /&gt;
AND l.userid = u.id&lt;br /&gt;
AND (l.timecreated &amp;gt; UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) AND l.timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:59&#039;))AND r.contextid= (&lt;br /&gt;
	 SELECT id&lt;br /&gt;
	 FROM mdl_context&lt;br /&gt;
	 WHERE contextlevel=50 AND instanceid=l.courseid&lt;br /&gt;
 )&lt;br /&gt;
AND r.roleid=5&lt;br /&gt;
AND r.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active courses, advanced===&lt;br /&gt;
Including: Teacher&#039;s name, link to the course, All types of log activities, special YEAR generated field, Activities and Resource count, enrolled Student count&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשע&#039; THEN &#039;תשע&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעא&#039; THEN &#039;תשעא&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעב&#039; THEN &#039;תשעב&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = l.course) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_log l &lt;br /&gt;
INNER JOIN prefix_course c ON l.course = c.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
#The following line restricts the courses returned to those having more than 2 modules.  Adjust based on your needs.&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY Year DESC, hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Least active or probably empty courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;-1&amp;quot; instead of &amp;quot;0&amp;quot; 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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
c.fullname,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;CourseLink&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timecreated&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timemodified&#039;,&lt;br /&gt;
CASE&lt;br /&gt;
 WHEN c.timecreated = c.timemodified THEN &#039;-1&#039;&lt;br /&gt;
 ELSE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated))&lt;br /&gt;
END AS &#039;DateDifference&#039;,&lt;br /&gt;
COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
LEFT JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
WHERE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated) ) &amp;lt; 60&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
HAVING COUNT(ue.id) &amp;lt;= 3&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Count unique teachers with courses that use at least X module (Moodle19)===&lt;br /&gt;
You can remove the outer &amp;quot;SELECT COUNT(*) FROM (...) AS ActiveTeachers&amp;quot; SQL query and get the list of the Teachers and Courses.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(*)&lt;br /&gt;
FROM (SELECT c.id AS CourseID, c.fullname AS Course, ra.roleid AS RoleID, CONCAT(u.firstname, &#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = c.id) AS Modules&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid AND ctx.contextlevel = 50 &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE  ra.roleid = 3 &lt;br /&gt;
GROUP BY u.id&lt;br /&gt;
HAVING Modules &amp;gt; 5) AS ActiveTeachers&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RESOURCE count for each COURSE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) count, l.course, c.fullname coursename&lt;br /&gt;
FROM prefix_resource l INNER JOIN prefix_course c on l.course = c.id&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY count DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Common resource types count for each Category (Moodle19)===&lt;br /&gt;
Including sub-categories in total count.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category&lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Links&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference NOT LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Files&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;directory&#039; &lt;br /&gt;
) AS Folders&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;html&#039; &lt;br /&gt;
) AS Pages&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM stats_log_context_role_course &lt;br /&gt;
WHERE roleid = 5 AND module = &#039;resource&#039; AND category = mcc.id&lt;br /&gt;
) AS Hits&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Where &amp;quot;stats_log_context_role_course&amp;quot; (in the above SQL query) is a VIEW generated by:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
CREATE VIEW stats_log_context_role_course AS&lt;br /&gt;
SELECT l.course, c.category, cc.path, l.module, l.action, ra.userid, ra.roleid&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = l.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Same query but for Moodle2+&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category,&lt;br /&gt;
mcc.path,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_url AS u&lt;br /&gt;
JOIN prefix_course AS c ON c.id = u.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS URLs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_folder AS f&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS FOLDERs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_page AS p&lt;br /&gt;
JOIN prefix_course AS c ON c.id = p.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS PAGEs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_book AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS BOOKs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_label AS l&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS LABELs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_tab AS t&lt;br /&gt;
JOIN prefix_course AS c ON c.id = t.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS TABs&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed Resource COUNT by Teacher in each course===&lt;br /&gt;
&lt;br /&gt;
Including (optional) filter by: year, semester and course id.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
, c.id&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעב%&#039; THEN &#039;2012&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעא%&#039; THEN &#039;2011&#039;&lt;br /&gt;
END ) as Year&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר א%&#039; THEN &#039;Semester A&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ב%&#039; THEN &#039;Semester B&#039;&lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ק%&#039; THEN &#039;Semester C&#039;&lt;br /&gt;
END ) as Semester&lt;br /&gt;
,COUNT(c.id) AS Total&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 20) AS TABs&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 33) AS BOOKs&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_resource` as r &lt;br /&gt;
JOIN `prefix_course` AS c on c.id = r.course&lt;br /&gt;
#WHERE type= &#039;file&#039; and reference NOT LIKE &#039;http://%&#039; &lt;br /&gt;
&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
#AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY COUNT(c.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses that are defined as using GROUPs===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/group/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = c.id) Modules&lt;br /&gt;
,(SELECT count(*) FROM prefix_groups g WHERE g.courseid = c.id) Groups&lt;br /&gt;
 FROM `prefix_course` AS c&lt;br /&gt;
WHERE groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Groups===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with Groups in them (groupmode &amp;gt; 0). You can also use groupmode=1 to list just Separate type groups or groupmode=2 to list Visible type groups.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name, c.groupmode&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON c.id = g.courseid&lt;br /&gt;
WHERE c.groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users enrolled in a course with groups but not assigned a group ===&lt;br /&gt;
&lt;br /&gt;
Displays by course all enrolled users that have not been assigned a group in courses that have groups. NOTE: This needs to be optimized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) AS ROLE&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = course.id&lt;br /&gt;
&lt;br /&gt;
WHERE ue.enrolid NOT IN (select userid from prefix_groups_members WHERE g.id=groupid)&lt;br /&gt;
&lt;br /&gt;
ORDER BY Course, Lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Groups in course with member list===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List the groups in a course (replace the # by the course id number) with the members of each group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name AS Groupname, u.username&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_user AS u ON m.userid = u.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Group Export===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
There&#039;s a [[Import_groups|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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT g.name AS groupname, g.description, g.enrolmentkey&lt;br /&gt;
FROM prefix_groups AS g &lt;br /&gt;
JOIN prefix_course as c ON g.courseid = c.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Courses in and below a certain category===&lt;br /&gt;
Use this SQL code to retrieve all courses that exist in or under a set category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the category you want to know about...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course. * , prefix_course_categories. *&lt;br /&gt;
FROM prefix_course, prefix_course_categories&lt;br /&gt;
WHERE prefix_course.category = prefix_course_categories.id&lt;br /&gt;
AND (&lt;br /&gt;
prefix_course_categories.path LIKE &#039;/$s/%&#039;&lt;br /&gt;
OR prefix_course_categories.path LIKE &#039;/$s&#039;&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Categories in one level below a certain category===&lt;br /&gt;
Use this PHP code to retrieve a list of all categories below a certain category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the top level category you are interested in.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
require_once(&#039;./config.php&#039;);&lt;br /&gt;
&lt;br /&gt;
$parent_id = $s;&lt;br /&gt;
&lt;br /&gt;
$categories= array();&lt;br /&gt;
&lt;br /&gt;
$categories = get_categories($parent_id);&lt;br /&gt;
&lt;br /&gt;
echo &#039;&amp;lt;ol&amp;gt;&#039;;&lt;br /&gt;
foreach ($categories as $category)&lt;br /&gt;
        {&lt;br /&gt;
        echo &#039;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&#039;.$CFG-&amp;gt;wwwroot.&#039;/course/category.php?id=&#039;.$category-&amp;gt;id.&#039;&amp;quot;&amp;gt;&#039;.$category-&amp;gt;name.&#039;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
        }&lt;br /&gt;
echo &#039;&amp;lt;/ol&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Blog activity per Course (not including VIEW)===&lt;br /&gt;
Filter activity logging to some specific Course Categories!&lt;br /&gt;
+ link course name to actual course (for quick reference)&lt;br /&gt;
(you can change %blog% to %wiki% to filter down all wiki activity or any other module you wish)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID&lt;br /&gt;
,m.name ,count(cm.id) as counter &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS Students&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE `module` LIKE &#039;%blog%&#039; AND course = c.id AND action NOT LIKE &#039;%view%&#039; ) as BlogActivity&lt;br /&gt;
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 &lt;br /&gt;
WHERE m.name LIKE &#039;%blog%&#039; AND c.category IN ( 8,13,15)&lt;br /&gt;
GROUP BY cm.course,cm.module order by counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student&#039;s posts content in all course blogs (oublog)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
b.name &lt;br /&gt;
,op.title&lt;br /&gt;
,op.message&lt;br /&gt;
,( SELECT CONCAT(u.firstname, &#039; &#039;,u.lastname) FROM prefix_user AS u WHERE u.id = oi.userid) AS &amp;quot;Username&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_oublog_posts AS op&lt;br /&gt;
JOIN prefix_oublog_instances AS oi ON oi.id = op.oubloginstancesid &lt;br /&gt;
JOIN prefix_oublog as b ON b.id = oi.oublogid&lt;br /&gt;
JOIN prefix_course AS c ON b.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Courses which uploaded a Syllabus file===&lt;br /&gt;
+ under specific Category&lt;br /&gt;
+ show first Teacher in that course&lt;br /&gt;
+ link Course&#039;s fullname to actual course&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) as Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user as u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) as Teacher&lt;br /&gt;
FROM prefix_resource as r &lt;br /&gt;
JOIN prefix_course as c ON r.course = c.id&lt;br /&gt;
WHERE ( r.name LIKE &#039;%סילבוס%&#039; OR r.name LIKE &#039;%סילאבוס%&#039; OR r.name LIKE &#039;%syllabus%&#039; OR r.name LIKE &#039;%תכנית הקורס%&#039; ) &lt;br /&gt;
AND c.category IN (10,18,26,13,28)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
===Site-wide completed SCORM activities by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===All users enrolled in a course without a role===&lt;br /&gt;
Identifies All users that are enrolled in a course but are not assigned a role.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user.firstname AS Firstname,&lt;br /&gt;
user.lastname AS Lastname,&lt;br /&gt;
user.idnumber Employee_ID,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user as user ON user.id = ue.userid&lt;br /&gt;
&lt;br /&gt;
WHERE user.id NOT IN (&lt;br /&gt;
SELECT u.id&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE c.id=course.id&lt;br /&gt;
)&lt;br /&gt;
ORDER BY Course, Lastname, Firstname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List course resources accumulative file size and count===&lt;br /&gt;
This is the main (first) report, which has a link (alias) to a second report (the following on this page) which list each file in the course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id &amp;quot;CourseID&amp;quot;, context.id &amp;quot;ContextID&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;, c.id, &#039;&amp;quot;&amp;gt;&#039;, c.fullname ,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Course Name&amp;quot;&lt;br /&gt;
, COUNT(*) &amp;quot;Course Files&amp;quot; , ROUND( SUM( f.filesize ) /1048576 ) AS file_size_MB&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/blocks/configurable_reports/viewreport.php?alias=coursefiles&amp;amp;courseid=1&amp;amp;filter_courses=&#039;, c.id, &#039;&amp;quot;&amp;gt;List files&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List Files&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
JOIN mdl_context AS context ON context.id = f.contextid&lt;br /&gt;
JOIN mdl_course AS c ON c.id = (&lt;br /&gt;
  SELECT instanceid&lt;br /&gt;
  FROM mdl_context&lt;br /&gt;
  WHERE id = SUBSTRING_INDEX( SUBSTRING_INDEX( context.path, &#039;/&#039; , -2 ) , &#039;/&#039;, 1 ) )&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this report, you will have to define &amp;quot;alias&amp;quot; report property to &amp;quot;coursefiles&amp;quot; for it to be able to be called from the above report.&lt;br /&gt;
And also setup (add) a FILTER_COURSES filter. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id ,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/pluginfile.php/&#039;, contextid, &#039;/&#039;, component, &#039;/&#039;, filearea, &#039;/&#039;, itemid, &#039;/&#039;, filename, &#039;&amp;quot;&amp;gt;&#039;, filename,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;File&amp;quot;&lt;br /&gt;
,filesize, mimetype ,author, license, timecreated, component, filearea, filepath&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
            AND f.contextid&lt;br /&gt;
            IN (   SELECT id&lt;br /&gt;
                     FROM mdl_context&lt;br /&gt;
                    WHERE path &lt;br /&gt;
                     LIKE (   SELECT CONCAT(&#039;%/&#039;,id,&#039;/%&#039;)&lt;br /&gt;
                                  AS contextquery&lt;br /&gt;
                                FROM mdl_context&lt;br /&gt;
                               WHERE 1=1&lt;br /&gt;
			        %%FILTER_COURSES:instanceid%%&lt;br /&gt;
                                 AND contextlevel = 50&lt;br /&gt;
                           )&lt;br /&gt;
                )&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Which courses has redundant topics===&lt;br /&gt;
This report list several &amp;quot;active topics&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
The following, second SQL query, could be used to &amp;quot;trim&amp;quot; down those redundant course topics/sections/weeks by updating the course format&#039;s numsection (Number of sections) setting. (It&#039;s a per course format setting!)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, format,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT value  FROM  `mdl_course_format_options` WHERE  `courseid` = c.id AND `format` = c.format AND `name` = &#039;numsections&#039; ) AS &amp;quot;numsections&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND `sequence` !=  &#039;&#039; ) AS &amp;quot;Non empty sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id ) AS &amp;quot;Total section count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND sequence IS NOT NULL) AS &amp;quot;Non NULL sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND name != &#039;&#039;) AS &amp;quot;Non empty section Name count&amp;quot;&lt;br /&gt;
 ,(SELECT COUNT(*) FROM mdl_course_modules cm WHERE cm.course = c.id) &amp;quot;Modules count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course AS c&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following SQL REPLACE query is used for &amp;quot;fixing&amp;quot; (updating) the &amp;quot;numsections&amp;quot; of a specific course format &amp;quot;onetopics&amp;quot; (you can always change it, or discard it to use this SQL REPLACE on all course formats) &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
REPLACE INTO `mdl_course_format_options` (`id`, `courseid`, `format`, `sectionid`, `name`, `value`) &lt;br /&gt;
SELECT NULL, c.id, &#039;onetopic&#039;, &#039;0&#039;, &#039;numsections&#039;, (SELECT COUNT(*) FROM `mdl_course_sections` WHERE `course` = c.id AND name != &#039;&#039;)&lt;br /&gt;
FROM `mdl_course` c where format = &#039;onetopic&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hidden Courses with Students Enrolled===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.visible AS Visible, &lt;br /&gt;
DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors,&lt;br /&gt;
&lt;br /&gt;
(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;, &lt;br /&gt;
&lt;br /&gt;
now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
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) &amp;gt; 0&lt;br /&gt;
ORDER BY StartDate, Instructor_Email, Course_ID&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Course Design Reports==&lt;br /&gt;
&lt;br /&gt;
These are reports which summarize course design aspects, such as activity and resource modules per section, types of activities used, etc.&lt;br /&gt;
&lt;br /&gt;
===Course Content/Week===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report assumes that the first 14 sections in a course, not including the &amp;quot;0&amp;quot; or &amp;quot;Welcome&amp;quot; section, correspond to weeks (with &amp;quot;Subsections&amp;quot; given numbers much higher in the sequence). Of those sections, each is checked to count the number of:&lt;br /&gt;
&lt;br /&gt;
    Forums&lt;br /&gt;
    Graded Activities (may include Forums)&lt;br /&gt;
    Resources (not including a Label)&lt;br /&gt;
&lt;br /&gt;
Totals of each of these types of content elements per section are provided.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Only visible resources and activities are counted.&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: this is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
 &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT LIKE &#039;label&#039;),cm.id,NULL)) AS &#039;Ungraded Resources&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Graded Activities&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cs.section&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments and Weights===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Categories with weights of 0 are not included in this report.&lt;br /&gt;
&lt;br /&gt;
Only visible activities are included in this report.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This is designed to be a &amp;quot;Global&amp;quot; report in Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;) AS &#039;Grade Book Category&#039;&lt;br /&gt;
, IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND(SUM(DISTINCT gi.aggregationcoef), 2)+ROUND(SUM(DISTINCT mgi.aggregationcoef), 2)) AS &#039;Category weight&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT_WS(&#039;, &#039;,GROUP_CONCAT(DISTINCT gi.itemmodule SEPARATOR &#039;, &#039;), IF(mgi.id, &#039;manual&#039;,NULL)) AS &#039;Activity Types&#039;&lt;br /&gt;
, COUNT(DISTINCT gi.itemmodule) + IF(mgi.id,1,0) AS &#039;Different Activity Types&#039;&lt;br /&gt;
, CONCAT_WS(&#039;&amp;lt;br&amp;gt;&#039;, GROUP_CONCAT(DISTINCT gi.itemname ORDER BY gi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;), GROUP_CONCAT(DISTINCT mgi.itemname ORDER BY mgi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;)) AS &#039;Activity Names&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) + COUNT(DISTINCT mgi.id) AS &#039;Activity Count&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
&lt;br /&gt;
#get grade categories&lt;br /&gt;
LEFT JOIN prefix_grade_categories AS gc ON gc.courseid = c.id &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
JOIN prefix_grade_items AS gic ON gic.courseid = c.id AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
&lt;br /&gt;
# attach activities to course&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = c.id &lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.iteminstance = cm.instance AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.id&lt;br /&gt;
ORDER BY gc.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pre-Term Course Review===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
#   &amp;quot;Required blocks&amp;quot; include Instructor Block (mooprofile), Activities, and the Research block.&lt;br /&gt;
#    &amp;quot;Instructor Details&amp;quot; block is not the &amp;quot;Instructor&amp;quot; block (mooprofile) automatically provided by the system. It is an optional block that can be edited by the instructor. If not edited to remove boilerplate text, it should be hidden.&lt;br /&gt;
#    All courses should be in the &amp;quot;Collapsed Topics&amp;quot; format with the &amp;quot;Weeks&amp;quot; structure.&lt;br /&gt;
#    &amp;quot;Weeks defined in course settings&amp;quot; is taken from our SIS when the course shells are created, but can be edited by faculty. &amp;quot;# of weeks named and visible&amp;quot; should usually match or exceed this value.&lt;br /&gt;
#    We recommend that each week contain at least one forum, at least one graded activity, and at least one ungraded resource.&lt;br /&gt;
#    &amp;quot;Syllabus updated&amp;quot; date is for the first attached file found with the text &amp;quot;syllabus&amp;quot; in the name. The &amp;quot;Days ago&amp;quot; calculation is included for convenience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: At our institution, we construct categories each term, and insert a text string &amp;quot;staging&amp;quot; in the Category ID for pre-term courses during the preparation or &amp;quot;staging&amp;quot; phase of course development. We remove this text string (and change it to &amp;quot;production&amp;quot;) when courses go live at the start of the new term.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
#,RIGHT(c.idnumber,2) AS Type # Specific to GSC &amp;quot;Instructional Method&amp;quot; storage&lt;br /&gt;
&lt;br /&gt;
#, substring_index(substr(c.shortname FROM locate(&#039;.&#039;,c.shortname)+1),&#039;-&#039;,1) AS Section # Specific to GSC&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.lastname,&#039;, &#039;, u.firstname,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
,(SELECT IF((u2.description IS NULL) OR (u2.description LIKE &#039;&#039;),&#039;NO&#039;, &#039;YES&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT IF(u3.picture &amp;gt; 0,&#039;YES&#039;,&#039;NO&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u3 ON u3.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Picture&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(((bpi.visible IS NULL) OR (bpi.visible !=0)) AND ((bpm.visible IS NULL) OR (bpm.visible !=0)) AND ((bpa.visible IS NULL) OR (bpa.visible !=0)) AND ((bpr.visible IS NULL) OR (bpr.visible !=0)),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Required blocks visible&#039;&lt;br /&gt;
#, IF((bpm.visible IS NULL) OR (bpm.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Messages block visible&#039;&lt;br /&gt;
#, IF((bpa.visible IS NULL) OR (bpa.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;activities block visible&#039;&lt;br /&gt;
#, IF((bpr.visible IS NULL) OR (bpr.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;research block visible&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)) AND (bip.visible !=0),&#039;YES&#039;,&#039;&#039;) AS &#039;Instructor Details Block visible&#039; # This is a hack based on UUencoded string data from the title of HTML &amp;quot;Instructor Details&amp;quot; block&lt;br /&gt;
&lt;br /&gt;
#, IF(bi.configdata LIKE &#039;%ZGl0IHRoaXMgYmxvY2s%&#039;,&#039;NO&#039;,&#039;&#039;) AS &#039;Instructor Details Block Updated&#039; # HTML block has string &#039;dit this block&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(COUNT(bi.id) -  SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)),&#039;YES&#039;,&#039;&#039;) AS &#039;possible extra instructor blocks&#039; #looking for any HTML block with &amp;quot;instructor&amp;quot; in the title&lt;br /&gt;
&lt;br /&gt;
, IF(c.format=&#039;topcoll&#039;,&#039;YES&#039;, c.format) AS &#039;Collapsed Topics course format&#039; # change this if you want to test for a different format&lt;br /&gt;
, IF(cfo.value = 2, &#039;YES&#039;,&#039;NO&#039;) AS &#039;weeks structure&#039;&lt;br /&gt;
&lt;br /&gt;
, cfw.value AS &#039;weeks defined in course settings&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(((cs.name IS NOT NULL) AND (cs.visible = 1) AND (cs.section != &#039;0&#039;) AND (cs.sequence IS NOT NULL)),cs.id,NULL)) AS &#039;# of weeks named &amp;amp; visible (includes orphans)&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039; ,cs.id , NULL)) AS &#039;Weeks with Forum&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cs.id, NULL)) AS &#039;Weeks with Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT mgi.id) AS &#039;Manual Grade Items&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)),cm.id,NULL)) AS &#039;Resources&#039;&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)), cs.id, NULL)) AS &#039;Weeks with Resources&#039;&lt;br /&gt;
&lt;br /&gt;
# Here are some other things you could check for per course&lt;br /&gt;
#,(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 &#039;%forum%&#039;) AS Forums&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%quiz%&#039;) AS Quizzes&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%assign%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_resource.id) FROM prefix_resource JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course) AS Files&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_url.id) FROM prefix_url JOIN prefix_course ON prefix_course.id = prefix_url.course WHERE c.id = prefix_url.course) AS Links&lt;br /&gt;
&lt;br /&gt;
,(SELECT FROM_UNIXTIME(MAX(prefix_resource.timemodified))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS SyllabusDate&lt;br /&gt;
&lt;br /&gt;
,(SELECT TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(MAX(prefix_resource.timemodified)))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS DaysAgo&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, f.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement Forum Visible&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, fd.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement posted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
LEFT JOIN prefix_context AS ctxx ON c.id = ctxx.instanceid &lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpi ON bpi.contextid = ctxx.id AND bpi.blockinstanceid = &#039;43692&#039; # mooprofile&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpm ON bpm.contextid = ctxx.id AND bpm.blockinstanceid = &#039;43962&#039; # messages&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpa ON bpa.contextid = ctxx.id AND bpa.blockinstanceid = &#039;43963&#039; # activities&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpr ON bpr.contextid = ctxx.id AND bpr.blockinstanceid = &#039;38368&#039; # html research help&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.visible = 1 AND cs.sequence IS NOT NULL&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
LEFT JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_forum AS f ON f.course = c.id AND cm.instance = f.id AND cm.visible = 1&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.forum = f.id&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfo ON cfo.courseid = c.id AND cfo.name = &#039;layoutstructure&#039;&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfw ON cfw.courseid = c.id AND cfw.name = &#039;numsections&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_instances AS bi ON bi.parentcontextid = ctxx.id AND bi.blockname = &#039;html&#039; AND (bi.configdata LIKE &#039;%SW5zdHJ1Y3Rvc%&#039; or bi.configdata LIKE &#039;%bnN0cnVjdG9y%&#039;)&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bip ON bip.blockinstanceid = bi.id&lt;br /&gt;
&lt;br /&gt;
WHERE RIGHT(c.idnumber,2) IN (&#039;OL&#039;, &#039;BL&#039;, &#039;HY&#039;) &lt;br /&gt;
# AND substring(cc.path,2,2) IN (&#039;26&#039;) # Staging&lt;br /&gt;
#AND substring(cc.path,2,3) IN (&#039;158&#039;) # UG&lt;br /&gt;
AND cc.idnumber LIKE &#039;%staging%&#039;&lt;br /&gt;
AND ctxx.contextlevel = 50&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module instances + Module HITs by role teacher and student in course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
m.name AS &amp;quot;Module name&amp;quot;&lt;br /&gt;
, COUNT(*) AS &amp;quot;Module count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name ) AS &amp;quot;Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course_modules AS cm&lt;br /&gt;
JOIN mdl_modules AS m on m.id = cm.module&lt;br /&gt;
WHERE cm.course = &#039;%%COURSEID%%&#039;&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Syllabus===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College / Moodle HQ&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Course Policies&amp;quot; and &amp;quot;Teaching Philosophy&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.fullname AS &#039;fullname&#039;&lt;br /&gt;
, ec.idnumber AS &#039;elis-id&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.startdate), &#039;%b %e, %Y&#039;) AS &#039;start&#039;&lt;br /&gt;
, DATE_FORMAT(FROM_UNIXTIME(ec.enddate), &#039;%b %e, %Y&#039;) AS &#039;end&#039;&lt;br /&gt;
, ecd.name AS &#039;longname&#039;&lt;br /&gt;
, ecd.code AS &#039;coursecode&#039;&lt;br /&gt;
, ecd.credits AS &#039;coursecredits&#039;&lt;br /&gt;
, ecd.syllabus AS &#039;description&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;learning-outcomes&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;outcomes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.firstname,&#039; &#039;, u.lastname,&#039;&amp;lt;/a&amp;gt; &#039;, u.email)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
, (SELECT  efc.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_char AS efc&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = efc.fieldid AND ef.shortname = &#039;term-code&#039;&lt;br /&gt;
WHERE ctxci.id = efc.contextid) AS &#039;termcode&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;prerequisites&#039;&lt;br /&gt;
WHERE ctxecd.id = eft.contextid) AS &#039;prerequisites&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;textbooks&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;textbooks&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;other-class-materials&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;other-class-materials&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-policies&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-policies&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;teaching-philosophy&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;teaching-philosophy&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;course-methods&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;course-methods&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT u2.description&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT&lt;br /&gt;
&lt;br /&gt;
GROUP_CONCAT(DISTINCT CONCAT(&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;tr&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt;&#039;,IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;)&lt;br /&gt;
, &#039; &amp;lt;/td&amp;gt;&amp;lt;td style=&amp;quot;border: solid #000 .5px&amp;quot;&amp;gt; &#039;&lt;br /&gt;
,IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND( gi.aggregationcoef, 2)+ROUND(mgi.aggregationcoef, 2))&lt;br /&gt;
&lt;br /&gt;
) SEPARATOR &#039;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&#039;)&lt;br /&gt;
#get grade categories&lt;br /&gt;
FROM prefix_grade_categories AS gc &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gic ON gic.courseid = gc.courseid AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = gc.courseid  AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = gc.courseid and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
WHERE gc.courseid = c.id  ) AS &#039;grade categories&#039;&lt;br /&gt;
&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;50%&amp;quot; &amp;gt;&#039; AS &#039;table start&#039;&lt;br /&gt;
, &#039;&amp;lt;table width = &amp;quot;100%&amp;quot; &amp;gt;&#039; AS &#039;table start 2&#039;&lt;br /&gt;
, &#039;&amp;lt;/table&amp;gt;&#039; AS &#039;table end&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;activities-schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;schedule&#039;&lt;br /&gt;
WHERE ctxci.id = eft.contextid) AS &#039;schedule&#039;&lt;br /&gt;
&lt;br /&gt;
, (SELECT  eft.data&lt;br /&gt;
FROM prefix_local_eliscore_fld_data_text AS eft&lt;br /&gt;
JOIN prefix_local_eliscore_field AS ef ON ef.id = eft.fieldid AND ef.shortname = &#039;grading-scale&#039;&lt;br /&gt;
WHERE ctxepm.id = eft.contextid) AS &#039;gradescale&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
# connect moodle course to ELIS class instance&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls_mdl AS ecm ON ecm.moodlecourseid = c.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_cls AS ec ON ec.id = ecm.classid&lt;br /&gt;
# class instance context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxci ON ctxci.instanceid = ec.id AND ctxci.contextlevel = &#039;14&#039;&lt;br /&gt;
&lt;br /&gt;
# connect ELIS class instance to ELIS course description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_crs AS ecd ON ecd.id = ec.courseid&lt;br /&gt;
# course description context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxecd ON ctxecd.instanceid = ecd.id AND ctxecd.contextlevel = &#039;13&#039;&lt;br /&gt;
&lt;br /&gt;
#connect ELIS program to ELIS Course Description&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm_crs AS epc ON epc.courseid = ecd.id&lt;br /&gt;
LEFT JOIN prefix_local_elisprogram_pgm AS epm ON epm.id = epc.curriculumid&lt;br /&gt;
# course program context&lt;br /&gt;
LEFT JOIN prefix_context AS ctxepm ON ctxepm.instanceid = epm.id AND ctxepm.contextlevel = &#039;11&#039;&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Activities Helper===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report provides a list of the graded activities in a course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: Only graded activities are displayed.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This is a &amp;quot;Global&amp;quot; report. Run it within a course to see a summary of the contents of that course.&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This report assumes that course sections each last one week.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
# 303 Course Activities Helper&lt;br /&gt;
&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
gi.itemmodule AS &#039;activity type&#039;&lt;br /&gt;
# cs.section AS &#039;section number&#039;&lt;br /&gt;
&lt;br /&gt;
# Calculation assumes each section lasts one week&lt;br /&gt;
, CONCAT(DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section-1))), &#039;%b %e, %Y&#039;),&#039; - &amp;lt;br&amp;gt;&#039;,DATE_FORMAT(FROM_UNIXTIME(c.startdate + (7*24*60*60* (cs.section))), &#039;%b %e, %Y&#039;)) AS &#039;Date&#039;&lt;br /&gt;
&lt;br /&gt;
, gi.itemname AS &#039;activity name&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = cm.instance) AS &#039;intro&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT f.intro FROM prefix_forum AS f WHERE f.id = cm.instance) AS &#039;f intro&#039;&lt;br /&gt;
&lt;br /&gt;
, CASE gi.itemmodule &lt;br /&gt;
WHEN &#039;assign&#039; THEN (SELECT asg.intro FROM prefix_assign AS asg WHERE asg.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;forum&#039; THEN (SELECT f.intro FROM prefix_forum AS f WHERE f.id = gi.iteminstance) &lt;br /&gt;
WHEN &#039;quiz&#039; THEN (SELECT q.intro FROM prefix_quiz AS q WHERE q.id = gi.iteminstance) &lt;br /&gt;
END AS &#039;test case&#039;&lt;br /&gt;
&lt;br /&gt;
#, (SELECT GROUP_CONCAT(CONCAT(&#039; - &#039;,gi.itemname) SEPARATOR &#039;&amp;lt;BR&amp;gt;&#039;) FROM  prefix_grade_items AS gi  JOIN prefix_course_modules AS cm ON  gi.iteminstance = cm.instance WHERE gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id ) AS &#039;activities&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_course AS c &lt;br /&gt;
&lt;br /&gt;
#get grade sections&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id  AND cs.section &amp;gt; 0 AND cs.section &amp;lt;=14&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_assign AS asg ON asg.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_grade_items AS gi  ON  gi.iteminstance = cm.instance AND gi.gradetype = 1 AND gi.hidden != 1 AND gi.courseid = c.id AND cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
c.id = %%COURSEID%%&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
&lt;br /&gt;
ORDER BY gi.itemmodule, cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Grade and Course Completion Reports==&lt;br /&gt;
===Site-Wide Grade Report with All Items===&lt;br /&gt;
Shows grades for all course items along with course totals for each student. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, &lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
For MySQL users, you&#039;ll need to use the MySQL DATE_ADD function instead of DATEADD. Replace the line:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
And:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
CONCAT(u.firstname,&#039; &#039;,u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site-Wide Grade Report with Just Course Totals===&lt;br /&gt;
A second site-wide grade report for all students that just shows course totals. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id AND gi.itemtype = &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For MySQL users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN CONCAT(c.fullname, &#039; - Total&#039;)&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS TIME&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
 &lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Learner report by Learner with grades===&lt;br /&gt;
Which Learners in which course and what are the grades&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;Name&#039; , u.lastname AS &#039;Surname&#039;, c.fullname AS &#039;Course&#039;, cc.name AS &#039;Category&#039;, &lt;br /&gt;
CASE WHEN gi.itemtype = &#039;Course&#039;    &lt;br /&gt;
THEN c.fullname + &#039; Course Total&#039;  &lt;br /&gt;
ELSE gi.itemname &lt;br /&gt;
END AS &#039;Item Name&#039;, ROUND(gg.finalgrade,2) AS Score,ROUND(gg.rawgrademax,2) AS Max, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) as Percentage,&lt;br /&gt;
&lt;br /&gt;
if (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) &amp;gt; 79,&#039;Yes&#039; , &#039;No&#039;) as Pass&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id &lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid &lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category &lt;br /&gt;
WHERE  gi.courseid = c.id and gi.itemname != &#039;Attendance&#039;&lt;br /&gt;
ORDER BY `Name` ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A very simple report with a list of course completion status by username. Completions are noted by date, blank otherwise. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  u.username, &lt;br /&gt;
  c.shortname,  &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%Y-%m-%d&#039;) AS completed&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion with Criteria===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A report with course completions by username, with Aggregation method, Criteria types, and Criteria detail where available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username AS user, &lt;br /&gt;
c.shortname AS course,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(t.timecompleted),&#039;%Y-%m-%d&#039;) AS completed,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = c.id AND a.criteriatype IS NULL) = 1) THEN &amp;quot;Any&amp;quot;&lt;br /&gt;
ELSE &amp;quot;All&amp;quot;&lt;br /&gt;
END AS aggregation,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;Self&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN &amp;quot;By Date&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 3 THEN &amp;quot;Unenrol Status&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &amp;quot;Activity&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 5 THEN &amp;quot;Duration&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 6 THEN &amp;quot;Course Grade&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 7 THEN &amp;quot;Approve by Role&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 8 THEN &amp;quot;Previous Course&amp;quot;&lt;br /&gt;
END AS criteriatype,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;*&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(p.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN p.criteriatype = 3 THEN t.unenroled&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,p.module,&#039;/view.php?id=&#039;,p.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,p.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN p.criteriatype = 5 THEN p.enrolperiod&lt;br /&gt;
WHEN p.criteriatype = 6 THEN CONCAT(&#039;Needed: &#039;,ROUND(p.gradepass,2),&#039; Achieved: &#039;,ROUND(t.gradefinal,2)) &lt;br /&gt;
WHEN p.criteriatype = 7 THEN p.role&lt;br /&gt;
WHEN p.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = p.courseinstance)&lt;br /&gt;
END AS criteriadetail &lt;br /&gt;
FROM prefix_course_completion_crit_compl AS t&lt;br /&gt;
JOIN prefix_user AS u ON t.userid = u.id&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
JOIN prefix_course_completion_criteria AS p ON t.criteriaid = p.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Completion Enabled and their settings===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with completion enabled and their Aggregation setting, Criteria types, and Criteria details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT c.shortname AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = t.course AND a.criteriatype IS NULL)) = 2 THEN &amp;quot;All&amp;quot;&lt;br /&gt;
ELSE &amp;quot;Any&amp;quot;&lt;br /&gt;
END AS Course_Aggregation,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;Self completion&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN &amp;quot;Date done by&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;Unenrolement&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 4 THEN &amp;quot;Activity completion&amp;quot;   &lt;br /&gt;
WHEN t.criteriatype = 5 THEN &amp;quot;Duration in days&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 6 THEN &amp;quot;Final grade&amp;quot;     &lt;br /&gt;
WHEN t.criteriatype = 7 THEN &amp;quot;Approve by role&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 8 THEN &amp;quot;Previous course&amp;quot;&lt;br /&gt;
END AS Criteria_type,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(t.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 4 THEN&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,t.module,&#039;/view.php?id=&#039;,t.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,t.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN t.criteriatype = 5 THEN ROUND(t.enrolperiod/86400)&lt;br /&gt;
WHEN t.criteriatype = 6 THEN ROUND(t.gradepass,2)&lt;br /&gt;
WHEN t.criteriatype = 7 THEN (SELECT r.shortname FROM prefix_role AS r WHERE r.id = t.role)&lt;br /&gt;
WHEN t.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = t.courseinstance)&lt;br /&gt;
END AS Criteria_detail&lt;br /&gt;
FROM prefix_course_completion_criteria as t&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Completion Report with custom dates===&lt;br /&gt;
&lt;br /&gt;
List of users who completed multiple or single course/s from a start date to end date chosen by the user. The output gives username, name, course name, completion date and score&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT u.username AS &#039;User Name&#039;,&lt;br /&gt;
CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Name&#039;,&lt;br /&gt;
c.shortname AS &#039;Course Name&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%W %e %M, %Y&#039;) AS &#039;Completed Date&#039;,&lt;br /&gt;
ROUND(c4.gradefinal,2) AS &#039;Score&#039;&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
JOIN prefix_course_completion_crit_compl AS c4 ON u.id = c4.userid&lt;br /&gt;
WHERE c.enablecompletion = 1  AND (p.timecompleted IS NOT NULL OR p.timecompleted !=&#039;&#039;) &lt;br /&gt;
AND (p.timecompleted&amp;gt;= :start_date AND p.timecompleted&amp;lt;=:end_date)&lt;br /&gt;
GROUP BY u.username&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scales used in activities===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT scale.name&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,gi.itemmodule,&#039;/view.php?id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module View&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/modedit.php?up&#039;,&#039;date=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module Settings&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON c.id = gi.courseid&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = gi.courseid AND cm.instance = gi.iteminstance&lt;br /&gt;
JOIN prefix_scale AS scale ON scale.id = gi.scaleid&lt;br /&gt;
WHERE gi.scaleid IS NOT NULL&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Extra Credit Items by Name Only===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
This query identifies grade items in visible courses with student enrollment that have &amp;quot;extra credit&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, gi.itemname AS Item_Name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors&lt;br /&gt;
&lt;br /&gt;
,(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;&lt;br /&gt;
&lt;br /&gt;
,now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON gi.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE gi.itemname LIKE &#039;%extra credit%&#039; &lt;br /&gt;
	AND gi.gradetype = &#039;1&#039; &lt;br /&gt;
	AND gi.hidden = &#039;0&#039; &lt;br /&gt;
	AND gi.aggregationcoef = &#039;0&#039; &lt;br /&gt;
	AND c.visible = 1&lt;br /&gt;
	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) &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
GROUP BY Course_ID, gi.id&lt;br /&gt;
ORDER BY StartDate, Course_ID&lt;br /&gt;
 &lt;br /&gt;
%%FILTER_SEARCHTEXT:Course_ID:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site Wide Number of Courses Completed by User===&lt;br /&gt;
Contributed by Ken St. John&lt;br /&gt;
&lt;br /&gt;
Simple report that shows the number of completed courses for all users site wide&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname, u.firstname,&lt;br /&gt;
COUNT(p.timecompleted) AS TotalCompletions&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
GROUP BY p.userid&lt;br /&gt;
ORDER BY u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Activity Module Reports==&lt;br /&gt;
&lt;br /&gt;
=== User activity completions with dates===&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.username As &#039;User&#039;,&lt;br /&gt;
c.shortname AS &#039;Course&#039;,&lt;br /&gt;
m.name AS Activitytype, &lt;br /&gt;
CASE &lt;br /&gt;
    WHEN cm.module = 1 THEN (SELECT a1.name FROM prefix_assign a1            WHERE a1.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 2 THEN (SELECT a2.name FROM prefix_assignment a2    WHERE a2.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 3 THEN (SELECT a3.name FROM prefix_book a3               WHERE a3.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 4 THEN (SELECT a4.name FROM prefix_chat a4                WHERE a4.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 5 THEN (SELECT a5.name FROM prefix_choice a5            WHERE a5.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 6 THEN (SELECT a6.name FROM prefix_data a6                WHERE a6.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 7 THEN (SELECT a7.name FROM prefix_feedback a7        WHERE a7.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 8 THEN (SELECT a8.name FROM prefix_folder a8              WHERE a8.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 9 THEN (SELECT a9.name FROM prefix_forum a9              WHERE a9.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 10 THEN (SELECT a10.name FROM prefix_glossary a10         WHERE a10.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 11 THEN (SELECT a11.name FROM prefix_imscp  a11           WHERE a11.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 12 THEN (SELECT a12.name FROM prefix_label a12              WHERE a12.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 13 THEN (SELECT a13.name FROM prefix_lesson a13            WHERE a13.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 14 THEN (SELECT a14.name FROM prefix_lti a14                    WHERE a14.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 15 THEN (SELECT a15.name FROM prefix_page a15               WHERE a15.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 16 THEN (SELECT a16.name FROM prefix_quiz  a16               WHERE a16.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 17 THEN (SELECT a17.name FROM prefix_resource a17         WHERE a17.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 18 THEN (SELECT a18.name FROM prefix_scorm a18             WHERE a18.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 19 THEN (SELECT a19.name FROM prefix_survey a19             WHERE a19.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 20 THEN (SELECT a20.name FROM prefix_url a20                      WHERE a20.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 21 THEN (SELECT a21.name FROM prefix_wiki a21                    WHERE a21.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 22 THEN (SELECT a22.name FROM prefix_workshop a22           WHERE a22.id = cm.instance)&lt;br /&gt;
END AS Actvityname,&lt;br /&gt;
# cm.section AS Coursesection,&lt;br /&gt;
CASE&lt;br /&gt;
    WHEN cm.completion = 0 THEN &#039;0 None&#039;&lt;br /&gt;
    WHEN cm.completion = 1 THEN &#039;1 Self&#039;&lt;br /&gt;
    WHEN cm.completion = 2 THEN &#039;2 Auto&#039;&lt;br /&gt;
END AS Activtycompletiontype, &lt;br /&gt;
CASE&lt;br /&gt;
   WHEN cmc.completionstate = 0 THEN &#039;In Progress&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 1 THEN &#039;Completed&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 2 THEN &#039;Completed with Pass&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 3 THEN &#039;Completed with Fail&#039;&lt;br /&gt;
   ELSE &#039;Unknown&#039;&lt;br /&gt;
END AS &#039;Progress&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(cmc.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;&lt;br /&gt;
FROM prefix_course_modules_completion cmc &lt;br /&gt;
JOIN prefix_user u ON cmc.userid = u.id&lt;br /&gt;
JOIN prefix_course_modules cm ON cmc.coursemoduleid = cm.id&lt;br /&gt;
JOIN prefix_course c ON cm.course = c.id&lt;br /&gt;
JOIN prefix_modules m ON cm.module = m.id&lt;br /&gt;
# skip the predefined admin and guest user&lt;br /&gt;
WHERE u.id &amp;gt; 2&lt;br /&gt;
# config reports filters&lt;br /&gt;
%%FILTER_USERS:u.username%%&lt;br /&gt;
%%FILTER_SEARCHTEXT:m.name:~%%&lt;br /&gt;
%%FILTER_STARTTIME:cmc.timemodified:&amp;gt;%% %%FILTER_ENDTIME:cmc.timemodified:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many SCORM activities are used in each Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cm.course,c.fullname ,m.name &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/scorm/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,count(cm.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS Counter&lt;br /&gt;
 &lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
  JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
  JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%scorm%&#039; &lt;br /&gt;
GROUP BY cm.course,cm.module &lt;br /&gt;
ORDER BY count(cm.id) desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===SCORM Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of SCORM activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, scm.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;SCO%&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_scorm AS scm ON scm.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LTI (External Tool) Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of  LTI (External Tool) Usage activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, lti.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;lti&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_lti AS lti ON lti.id = cm.instance&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each MODULE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module,action,count(id) as counter&lt;br /&gt;
FROM prefix_log&lt;br /&gt;
GROUP BY module,action&lt;br /&gt;
ORDER BY module,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Most popular ACTIVITY===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, module&lt;br /&gt;
FROM prefix_log l&lt;br /&gt;
WHERE module != &#039;login&#039; AND module != &#039;course&#039; AND module != &#039;role&#039;&lt;br /&gt;
GROUP BY module&lt;br /&gt;
ORDER BY hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide use of ACTIVITIES and RESOURCES===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count( cm.id ) AS counter, m.name&lt;br /&gt;
FROM `prefix_course_modules` AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
ORDER BY counter DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LOG file ACTIONS per MODULE per COURSE (IDs)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select course,module,action,count(action) as summa from prefix_log&lt;br /&gt;
where action &amp;lt;&amp;gt; &#039;new&#039;&lt;br /&gt;
group by course,action,module&lt;br /&gt;
order by course,module,action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System Wide usage count of various course Activities===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
Like: Forum, Wiki, Blog, Assignment, Database,&lt;br /&gt;
#Within specific category&lt;br /&gt;
#Teacher name in course&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS Forums&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%data%&#039;) AS Databses&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%assignment%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 18)&lt;br /&gt;
ORDER BY Wikis DESC,Blogs DESC, Forums DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course wiki usage/activity over the last 6 semesters===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &amp;quot;Courses with Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester A%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester A&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester B%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester B&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed WIKI activity (per wiki per course)===&lt;br /&gt;
Including Number of Students in course (for reference)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID  &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id ) AS Students&lt;br /&gt;
,m.name&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%updat%&#039; ) as &#039;UPDAT E&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%annotate%&#039; ) as ANNOTATE&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%comment%&#039; ) as COMMENT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%add%&#039; ) as &#039;A DD&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%edit%&#039; ) as EDIT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action NOT LIKE &#039;%view%&#039; ) as &#039;All (NO View)&#039;&lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
GROUP BY cm.course,cm.module&lt;br /&gt;
ORDER BY &#039;All (NO View)&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wiki usage, system wide===&lt;br /&gt;
(you can filter the output by selecting some specific course categories : &amp;quot;WHERE c.category IN ( 8,13,15)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039;) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%add%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ADD&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%edit%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;EDIT&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%annotate%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ANNOTATE&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%comments%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;Comments&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_ouwiki_pages as ouwp&lt;br /&gt;
JOIN prefix_ouwiki as ouw ON ouw.id = ouwp.subwikiid&lt;br /&gt;
WHERE ouw.course = c.id GROUP BY ouw.course  ) as OUWikiPages&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( DISTINCT nwp.pagename ) FROM prefix_wiki_pages AS nwp&lt;br /&gt;
JOIN prefix_wiki AS nw ON nw.id = nwp.dfwiki WHERE nw.course = c.id ) As NWikiPages&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Wikis &amp;gt; 0&lt;br /&gt;
ORDER BY &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Aggregated Teacher activity by &amp;quot;WEB2&amp;quot; Modules===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
The NV column shows activity without VIEW log activity&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.userid, u.firstname,u.lastname&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039;) AS Wiki&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Wiki_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039;) AS Forum&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Forum_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039;) AS Blog&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Blog_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039;) AS Assignment&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Assignment_NV&lt;br /&gt;
FROM prefix_role_assignments AS ra &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
WHERE ra.roleid = 3 &lt;br /&gt;
GROUP BY ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the certificates issued, sort by variables in the custom profile fields===&lt;br /&gt;
Note: The SQL queries look intimidating at first, but isn&#039;t really that difficult to learn. I&#039;ve seen in the forums that users wanted to do &#039;site-wide&#039; groups in 1.9x. This is sort of the idea. It pulls all the certificates issued to all users sorted by the custom profile fields, which in my case is the Units or Depts (i.e. my site wide groups). Why certificates? I&#039;ve explored with both grades and quizzes, the course admins are not really interested in the actual grades but whether the learner received a certificate (i.e. passed the course with x, y, z activities). It also saves me from creating groups and assigning them into the right groups. Even assigning in bulk is not efficient, since I have upward of 25 groups per course and constantly new learners enrolling in courses. The limitation is something to do with the server? as it only pull 5000 rows of data. If anyone figured out how to change this, please let me know. In the meantime, the work around is to pull only a few units/depts at a time to limit the number of rows. This is fine at the moment, since each course admin are only responsible for certain units/depts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(prefix_certificate_issues.timecreated), &#039;%Y-%m-%d&#039; ) AS Date,&lt;br /&gt;
prefix_certificate_issues.classname AS Topic,&lt;br /&gt;
prefix_certificate.name AS Certificate,&lt;br /&gt;
prefix_certificate_issues.studentname as Name,&lt;br /&gt;
prefix_user_info_data.data AS Units&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_certificate_issues&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_user_info_data&lt;br /&gt;
on prefix_certificate_issues.userid = prefix_user_info_data.userid&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_certificate&lt;br /&gt;
on prefix_certificate_issues.certificateid = prefix_certificate.id&lt;br /&gt;
&lt;br /&gt;
WHERE prefix_user_info_data.data=&#039;Unit 1&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 2&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 3&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY Units, Name, Topic ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== All Simple Certificates Earned in the Site===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 [http://www.mysqltutorial.org/mysql-date_format/ DATE_FORMAT] function.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
CONCAT (u.firstname, &#039; &#039;,u.lastname) As &#039;User&#039;,&lt;br /&gt;
c.fullname AS &#039;Course&#039;,&lt;br /&gt;
sc.name AS &#039;Certificate&#039;,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(sci.timecreated), &#039;%Y-%m-%d&#039; ) As &#039;Date Awarded&#039;&lt;br /&gt;
# sci.code &#039;CertificateId&#039;&lt;br /&gt;
FROM prefix_simplecertificate_issues sci&lt;br /&gt;
JOIN prefix_user u ON sci.userid = u.id&lt;br /&gt;
JOIN prefix_simplecertificate sc ON sci.certificateid = sc.id&lt;br /&gt;
JOIN prefix_course AS c ON sc.course = c.id&lt;br /&gt;
ORDER BY sci.timecreated DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE DATEDIFF(NOW(),FROM_UNIXTIME(sci.timecreated) ) &amp;lt; 30&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Counter Blog usage in Courses,system wide===&lt;br /&gt;
What teachers in what courses, uses blogs and how many + student count in that course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT ( @counter := @counter+1) as counter, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c, (SELECT @counter := 0) as s_init&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Blogs &amp;gt; 0&lt;br /&gt;
ORDER BY Blogs DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Elluminate (Blackboard Collaborate) - system wide usage===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT e.name As Session ,er.recordingsize&lt;br /&gt;
,c.fullname As Course&lt;br /&gt;
,u.firstname,u.lastname &lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(e.timestart),&#039;%d-%m-%Y&#039;) AS dTimeStart&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/moodle/mod/elluminate/loadrecording.php?id=&#039;,er.id,&#039;&amp;quot;&amp;gt;Show&amp;lt;/a&amp;gt;&#039;) AS RecordedSession&lt;br /&gt;
&lt;br /&gt;
FROM prefix_elluminate_recordings AS er&lt;br /&gt;
JOIN prefix_elluminate AS e ON e.meetingid = er.meetingid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = e.creator &lt;br /&gt;
ORDER BY er.recordingsize DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choice ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Results of the Choice activity. For all courses, shows course shortname, username, the Choice text, and the answer chosen by the user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname AS course, u.username, h.name as question, o.text AS answer&lt;br /&gt;
FROM prefix_choice AS h&lt;br /&gt;
JOIN prefix_course AS c ON h.course = c.id&lt;br /&gt;
JOIN prefix_choice_answers AS a ON h.id = a.choiceid&lt;br /&gt;
JOIN prefix_user AS u ON a.userid = u.id&lt;br /&gt;
JOIN prefix_choice_options AS o ON a.optionid = o.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment type usage in courses ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assign/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_assign WHERE c.id = course) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;file&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
#GROUP BY apc.plugin&lt;br /&gt;
) AS &amp;quot;File Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;onlinetext&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Online Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;pdf&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;PDF Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;offline&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Offline Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;comments&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Assignments Comments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_assign AS assign&lt;br /&gt;
JOIN prefix_course AS c ON c.id = assign.course&lt;br /&gt;
GROUP BY c.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Assignment Module Reports==&lt;br /&gt;
===All Ungraded Assignments===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
Returns all the submitted assignments that still need grading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id&lt;br /&gt;
and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Ungraded Assignments w/ Link===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;a href=&amp;quot;http://education.varonis.com/mod/assignment/submissions.php&#039; + char(63) +&lt;br /&gt;
+ &#039;id=&#039; + cast(cm.id as varchar) + &#039;&amp;amp;userid=&#039; + cast(u.id as varchar) &lt;br /&gt;
+ &#039;&amp;amp;mode=single&amp;amp;filter=0&amp;amp;offset=2&amp;quot;&amp;gt;&#039; + a.name + &#039;&amp;lt;/a&amp;gt;&#039;&lt;br /&gt;
AS &amp;quot;Assignmentlink&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments (and Quizzes) waiting to be graded===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This report requires a YEAR filter to be added (Available when using the latest block/configurable_reports)&lt;br /&gt;
&lt;br /&gt;
Which you can always remove, to make this query work on earlier versions.&lt;br /&gt;
&lt;br /&gt;
The report includes: &lt;br /&gt;
*number of quizzes&lt;br /&gt;
*unFinished Quiz attempts&lt;br /&gt;
*Finished Quiz attempts&lt;br /&gt;
*number of students&lt;br /&gt;
*number of Assignments&lt;br /&gt;
*number of submitted answers by students &lt;br /&gt;
*number of unchecked assignments (waiting for the Teacher) in a Course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
 &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assignment/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;מטלות&amp;lt;/a&amp;gt;&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;בחנים&amp;lt;/a&amp;gt;&#039;) AS &#039;Quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_course_modules cm &lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module &lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039; AND cm.course = c.id &lt;br /&gt;
GROUP BY cm.course &lt;br /&gt;
) AS &#039;nQuizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish = 0&lt;br /&gt;
GROUP BY q.course) AS &#039;unFinished Quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish &amp;gt; 0&lt;br /&gt;
GROUP BY q.course) AS &#039;finished quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS nStudents&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(a.id)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) nAssignments&lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE a.course = c.id AND FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course&lt;br /&gt;
) &#039;Open &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(ROUND( (100 / iAssignments ) * iOpenAssignments ) ,&#039;%&#039;) &#039;unFinished &amp;lt;br/&amp;gt;Assignments &amp;lt;br/&amp;gt;(percent)&#039;&lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE asb.grade &amp;lt; 0 AND cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;unChecked  &amp;lt;br/&amp;gt;Submissions&#039; &lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;Submitted  &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblAssignmentsCount ON tblAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iOpenAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblOpenAssignmentsCount ON tblOpenAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1  &lt;br /&gt;
#AND c.fullname LIKE &#039;%תשעג%&#039;&lt;br /&gt;
%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
ORDER BY &#039;Open &amp;lt;br/&amp;gt;Assignments&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rubrics without zero values in criteria===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
Rubric calculations in Moodle can fail to align with instructors expectations if they lack a zero value for each criterion used in the assessment. From documentation at https://docs.moodle.org/32/en/Rubrics#Grade_calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;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.&lt;br /&gt;
TIP: To avoid confusion from this sort of thing, we recommend including a level with 0 points in every rubric criterion.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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&#039; favor.&lt;br /&gt;
&lt;br /&gt;
Includes search filter of course idnumber.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cat.name AS Department, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, &lt;br /&gt;
c.fullname AS Course_Name, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/grading/form/rubric/edit.php&#039;,CHAR(63),&#039;areaid=&#039;,gd.areaid,&#039;&amp;quot;&amp;gt;&#039;,gd.areaid,&#039;&amp;lt;/a&amp;gt;&#039;) AS Rubric&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_categories AS cat &lt;br /&gt;
ON cat.id = c.category&lt;br /&gt;
JOIN prefix_course_modules AS cm &lt;br /&gt;
ON c.id=cm.course&lt;br /&gt;
JOIN prefix_context AS ctx &lt;br /&gt;
ON cm.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_grading_areas AS garea &lt;br /&gt;
ON ctx.id = garea.contextid&lt;br /&gt;
JOIN prefix_grading_definitions AS gd &lt;br /&gt;
ON garea.id = gd.areaid&lt;br /&gt;
JOIN prefix_gradingform_rubric_criteria AS crit &lt;br /&gt;
ON gd.id = crit.definitionid&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id&lt;br /&gt;
WHERE cm.visible=&#039;1&#039; AND garea.activemethod = &#039;rubric&#039; AND (crit.id NOT IN&lt;br /&gt;
(SELECT crit.id&lt;br /&gt;
FROM prefix_gradingform_rubric_criteria AS crit&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id WHERE levels.score = &#039;0&#039;))&lt;br /&gt;
&lt;br /&gt;
GROUP BY Rubric&lt;br /&gt;
ORDER BY Course_ID, Rubric&lt;br /&gt;
&lt;br /&gt;
%%FILTER_SEARCHTEXT:c.idnumber:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Who is using &amp;quot;Single File Upload&amp;quot; assignment===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,ass.name as &amp;quot;Assignment Name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM &lt;br /&gt;
prefix_assignment as ass&lt;br /&gt;
&lt;br /&gt;
JOIN &lt;br /&gt;
prefix_course as c ON c.id = ass.course&lt;br /&gt;
&lt;br /&gt;
WHERE `assignmenttype` LIKE &#039;uploadsingle&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Feedback Module Reports==&lt;br /&gt;
===List the answers to all the Feedback activities within the current course, submitted by the current user===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT /* crs.fullname as &amp;quot;Course name&amp;quot;, f.name AS &amp;quot;Journal name&amp;quot;, CONCAT(u.firstname,&#039; &#039;,UPPER(u.lastname)) as &amp;quot;Participant&amp;quot;, */ /* include these fields if you want to check the composition of the recordset */&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified),&#039;%W %e %M, %Y&#039;) as &amp;quot;Answer Date&amp;quot;,&lt;br /&gt;
CASE i.typ WHEN &#039;label&#039; THEN i.presentation ELSE i.name END as &amp;quot;Topic&amp;quot;,  /* usually labels are used as section titles, so you&#039;d want them present in the recordset */&lt;br /&gt;
v.value as &amp;quot;My Answer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback AS f&lt;br /&gt;
INNER JOIN prefix_course as crs on crs.id=f.course %%FILTER_COURSES:f.course%% &lt;br /&gt;
INNER JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
INNER JOIN prefix_feedback_completed AS c on f.id=c.feedback %%FILTER_COURSEUSER:c.userid%% &lt;br /&gt;
LEFT JOIN prefix_feedback_value AS v on v.completed=c.id AND v.item=i.id&lt;br /&gt;
INNER JOIN prefix_user AS u on c.userid=u.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%% AND u.id = %%USERID%%  AND c.anonymous_response = 1  /* This clause limits the recordset to the current course and the current user and includes/ excludes the anonymous responses as needed */&lt;br /&gt;
&lt;br /&gt;
ORDER BY f.id, c.timemodified, i.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show all Feedbacks from all courses for all users including showing names of anonymous users===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &#039;Not-logged-in&#039; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS Course, &lt;br /&gt;
f.name AS Feedback,&lt;br /&gt;
# i.id AS Itemid,&lt;br /&gt;
i.name AS Itemname,&lt;br /&gt;
i.label AS Itemlabel,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN f.anonymous = 1 AND u.id != 0 THEN CONCAT(u.username, &#039; :ANON&#039;)&lt;br /&gt;
 WHEN fc.userid = 0 THEN &#039;Not-logged-in&#039;&lt;br /&gt;
 ELSE u.username&lt;br /&gt;
END AS &#039;User&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(fc.timemodified),&#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;Completed&amp;quot;,&lt;br /&gt;
v.value AS &amp;quot;Choice&amp;quot;,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN i.typ = &#039;multichoice&#039; THEN&lt;br /&gt;
     IF (  SUBSTRING(i.presentation,1,6)=&#039;d&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&#039;,&lt;br /&gt;
	       SUBSTRING(i.presentation,7),&lt;br /&gt;
		   i.presentation)&lt;br /&gt;
 ELSE i.presentation&lt;br /&gt;
END AS &amp;quot;Answers&amp;quot;,&lt;br /&gt;
i.typ,&lt;br /&gt;
i.dependitem,&lt;br /&gt;
i.dependvalue&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback f&lt;br /&gt;
JOIN prefix_course c ON c.id=f.course &lt;br /&gt;
JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
JOIN prefix_feedback_completed fc ON f.id=fc.feedback&lt;br /&gt;
LEFT JOIN prefix_feedback_value v ON v.completed=fc.id AND v.item=i.id&lt;br /&gt;
LEFT JOIN prefix_user AS u ON fc.userid=u.id&lt;br /&gt;
WHERE i.typ != &#039;pagebreak&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Resource Module Reports==&lt;br /&gt;
===List &amp;quot;Recently uploaded files&amp;quot;===&lt;br /&gt;
see what users are uploading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT FROM_UNIXTIME(time,&#039;%Y %M %D %h:%i:%s&#039;) as time ,ip,userid,url,info  &lt;br /&gt;
FROM `prefix_log` &lt;br /&gt;
WHERE `action` LIKE &#039;upload&#039; &lt;br /&gt;
ORDER BY `prefix_log`.`time`  DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Courses that loaded a specific file: &amp;quot;X&amp;quot;===&lt;br /&gt;
Did the Teacher (probably) uploaded course&#039;s Syllabus ?&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname  FROM `prefix_log` as l &lt;br /&gt;
JOIN prefix_course as c ON c.id = l.course &lt;br /&gt;
WHERE `action` LIKE &#039;%upload%&#039; AND ( info LIKE &#039;%Syllabus%&#039; OR info LIKE &#039;%Sylabus%&#039; ) GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All resources that link to some specific external website===&lt;br /&gt;
+ link to course&lt;br /&gt;
+ who&#039;s the teacher&lt;br /&gt;
+ link to external resource&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/resource/view.php?id=&#039;,r.id,&#039;&amp;quot;&amp;gt;&#039;,r.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Resource&lt;br /&gt;
FROM prefix_resource AS r &lt;br /&gt;
JOIN prefix_course AS c ON r.course = c.id&lt;br /&gt;
WHERE r.reference LIKE &#039;http://info.oranim.ac.il/home%&#039; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;quot;Compose Web Page&amp;quot; RESOURCE count===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT course,prefix_course.fullname, COUNT(*) AS Total&lt;br /&gt;
FROM `prefix_resource`&lt;br /&gt;
JOIN `prefix_course` ON prefix_course.id = prefix_resource.course&lt;br /&gt;
WHERE type=&#039;html&#039;&lt;br /&gt;
GROUP BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resource count in courses===&lt;br /&gt;
+ (First)Teacher name&lt;br /&gt;
+ Where course is inside some specific Categories&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
COUNT(*) AS count&lt;br /&gt;
,r.course &lt;br /&gt;
,c.shortname shortname&lt;br /&gt;
,c.fullname coursename&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user as u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = r.course AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
FROM prefix_resource r &lt;br /&gt;
JOIN prefix_course c ON r.course = c.id&lt;br /&gt;
WHERE c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY r.course&lt;br /&gt;
ORDER BY COUNT(*) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Delete all the automated backup files===&lt;br /&gt;
Prepare bash cli script to delete all the automated backup files on the file system. (clean up some disk space)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT( &#039;rm -f /var/moodledatanew/filedir/&#039;, SUBSTRING( contenthash, 1, 2 ) , &#039;/&#039;, SUBSTRING( contenthash, 3, 2 ) , &#039;/&#039;, contenthash ) &lt;br /&gt;
FROM `mdl_files` &lt;br /&gt;
WHERE `filename` LIKE &#039;%mbz%&#039;&lt;br /&gt;
AND filearea = &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find out how much disk space is used by all automated backup files:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT SUM(filesize)/(1024*1024*1024) FROM `mdl_files` WHERE  `filename` LIKE &#039;%mbz%&#039; AND filearea =  &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Forum Module Reports==&lt;br /&gt;
===print all User&#039;s post in course Forums===&lt;br /&gt;
%%COURSEID%% is a variable the is replace by the current CourseID you are running the sql report from. if you are using the latest block/configurable_reports ! (You can always change it to a fixed course or remove it to display all courses.)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php?course=&#039;,c.id,&#039;&amp;amp;id=&#039;,u.id,&#039;&amp;amp;mode=posts&amp;quot;&amp;gt;&#039;,CONCAT(u.firstname,&#039; &#039;, u.lastname),&#039;&amp;lt;/a&amp;gt;&#039;) As Fullname&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Forum&lt;br /&gt;
,count(*) as Posts&lt;br /&gt;
,(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&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_user as u ON u.id = fp.userid &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = fd.course &lt;br /&gt;
WHERE fd.course = %%COURSEID%% &lt;br /&gt;
GROUP BY f.id,u.id&lt;br /&gt;
ORDER BY u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE by type -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, prefix_forum.type, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course,prefix_forum.type&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Forum activity - system wide===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,c.fullname as Course&lt;br /&gt;
,f.type&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
, fd.forum, f.name,count(*) AS cPostAndDisc&lt;br /&gt;
,(SELECT count(*) FROM prefix_forum_discussions AS ifd WHERE ifd.forum = f.id) AS cDiscussion&lt;br /&gt;
FROM prefix_forum_posts AS fp&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type != &#039;news&#039; AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
## WHERE 1=1 &lt;br /&gt;
## %%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count( * ) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Activity In Forums===&lt;br /&gt;
Trying to figure out how much real activity we have in Forums by aggregating:&lt;br /&gt;
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...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname,f.name,f.type &lt;br /&gt;
,(SELECT count(id) FROM prefix_forum_discussions as fd WHERE f.id = fd.forum) as Discussions&lt;br /&gt;
,(SELECT count(distinct fd.userid) FROM prefix_forum_discussions as fd WHERE fd.forum = f.id) as UniqueUsersDiscussions&lt;br /&gt;
,(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&lt;br /&gt;
,(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&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS StudentsCount&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Teachers&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS &#039;Teacher&amp;lt;br/&amp;gt;Count&#039;&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid IN (3,5)&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS UserCount&lt;br /&gt;
, (SELECT (UniqueUsersDiscussions / StudentsCount )) as StudentDissUsage&lt;br /&gt;
, (SELECT (UniqueUsersPosts /StudentsCount)) as StudentPostUsage&lt;br /&gt;
FROM prefix_forum as f &lt;br /&gt;
JOIN prefix_course as c ON f.course = c.id&lt;br /&gt;
WHERE `type` != &#039;news&#039;&lt;br /&gt;
ORDER BY StudentPostUsage DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Forum type:NEWS===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT f.id, f.name&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
WHERE m.name = &#039;forum&#039;&lt;br /&gt;
AND f.type = &#039;news&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All new forum NEWS items (discussions) from all my Courses===&lt;br /&gt;
change &amp;quot;userid = 26&amp;quot; and &amp;quot;id = 26&amp;quot; to a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname,f.name,fd.name,FROM_UNIXTIME(fd.timemodified ,&amp;quot;%d %M %Y &amp;quot;) as Date&lt;br /&gt;
FROM prefix_forum_discussions as fd &lt;br /&gt;
JOIN prefix_forum as f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = f.course &lt;br /&gt;
JOIN prefix_user_lastaccess as ul ON (c.id = ul.courseid AND ul.userid = 26)&lt;br /&gt;
WHERE fd.timemodified &amp;gt; ul.timeaccess  &lt;br /&gt;
 AND fd.forum IN (SELECT f.id&lt;br /&gt;
 FROM prefix_course_modules AS cm&lt;br /&gt;
 JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
 JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
 WHERE m.name = &#039;forum&#039;&lt;br /&gt;
 AND f.type = &#039;news&#039;)&lt;br /&gt;
  AND c.id IN (SELECT c.id&lt;br /&gt;
   FROM prefix_course AS c&lt;br /&gt;
   JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
   JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
   JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
   WHERE u.id = 26) ORDER BY `fd`.`timemodified` DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===News Forum - Discussions COUNT===&lt;br /&gt;
Which is actually... How much instructions students get from their teachers&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname ,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,count(fd.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS DiscussionsSum&lt;br /&gt;
FROM prefix_forum_discussions AS fd&lt;br /&gt;
INNER JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
INNER JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type = &#039;news&#039; AND c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count(fd.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cantidad de foros que han sido posteados por profesor===&lt;br /&gt;
&lt;br /&gt;
(Number of forums that have been posted by teacher/Google translator)&lt;br /&gt;
&lt;br /&gt;
Queriamos saber cuales son las acciones del profesor dentro de los foros de cada curso, por ello se hizo este informe.&lt;br /&gt;
&lt;br /&gt;
(We wanted to know what the teacher&#039;s actions are in the forums of each course, so this report was made. /Google translator)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS curso,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Facilitador,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( m.name ) AS COUNT FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS foros,&lt;br /&gt;
&lt;br /&gt;
COUNT(*) AS Posts&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course AS c ON c.id = fd.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = fp.userid &lt;br /&gt;
&lt;br /&gt;
WHERE fp.userid =&lt;br /&gt;
(&lt;br /&gt;
select distinct prefix_user.id&lt;br /&gt;
from prefix_user &lt;br /&gt;
join prefix_role_assignments as ra on ra.userid = prefix_user.id &lt;br /&gt;
where ra.roleid = 3 &lt;br /&gt;
and userid = fp.userid&lt;br /&gt;
limit 1&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
and c.shortname like &#039;%2014-2-1%&#039;&lt;br /&gt;
GROUP BY c.id, u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all the Forums that got high rating===&lt;br /&gt;
We setup a scale that let teachers and students Rate forum post with &amp;quot;Important, interesting, valuable, not rated&amp;quot; scale&lt;br /&gt;
And then add a link to the following report at the begining of the course &amp;quot;Link to all interesting posts&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,f.id,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;,fd.id,&#039;#p&#039;,fp.id,&#039;&amp;quot;&amp;gt;&#039;,fp.subject,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post link&#039;,&lt;br /&gt;
SUM(r.rating) AS &#039;Rating&#039;&lt;br /&gt;
FROM mdl_rating AS r&lt;br /&gt;
  JOIN mdl_forum_posts AS fp ON fp.id = r.itemid&lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
WHERE r.component = &#039;mod_forum&#039; AND r.ratingarea = &#039;post&#039; AND f.course = %%COURSEID%%&lt;br /&gt;
GROUP BY r.itemid&lt;br /&gt;
ORDER BY SUM(r.rating) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all Discussions of a single Forum===&lt;br /&gt;
This report is used to help export all the student&#039;s posts and discussions of a single forum, by passing the context module id as a parameter to the report using &amp;quot;&amp;amp;filter_var=cmid&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;, f.id, &#039;&amp;quot;&amp;gt;&#039;, f.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name&#039;,&lt;br /&gt;
fd.name AS &#039;Discussion&#039;, &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;, fd.id, &#039;#p&#039;, fp.id, &#039;&amp;quot;&amp;gt;&#039;, fp.subject, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post (link)&#039;,&lt;br /&gt;
fp.message&lt;br /&gt;
&lt;br /&gt;
FROM mdl_forum_posts AS fp &lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
  JOIN mdl_course_modules AS cm ON cm.module = 9 AND cm.instance = f.id&lt;br /&gt;
WHERE cm.id = %%FILTER_VAR%%&lt;br /&gt;
ORDER BY f.id, fd.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Quiz Module Reports==&lt;br /&gt;
===Generate a list of instructors and their email addresses for those courses that has &amp;quot;essay questions&amp;quot; in their quizzes===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT qu.id AS quiz_id, qu.course AS course_id, qu.questions,&lt;br /&gt;
                co.fullname AS course_fullname, co.shortname AS course_shortname,&lt;br /&gt;
                qu.name AS quiz_name, FROM_UNIXTIME(qu.timeopen) AS quiz_timeopen, FROM_UNIXTIME(qu.timeclose) AS quiz_timeclose,&lt;br /&gt;
                u.firstname, u.lastname, u.email,&lt;br /&gt;
FROM prefix_quiz qu, prefix_course co, prefix_role re, prefix_context ct, prefix_role_assignments ra, prefix_user u&lt;br /&gt;
WHERE FROM_UNIXTIME(timeopen) &amp;gt; &#039;2008-05-14&#039; AND&lt;br /&gt;
                qu.course = co.id AND&lt;br /&gt;
                co.id = ct.instanceid AND&lt;br /&gt;
                ra.roleid = re.id AND&lt;br /&gt;
                re.name = &#039;Teacher&#039; AND&lt;br /&gt;
                ra.contextid = ct.id AND&lt;br /&gt;
                ra.userid = u.id&lt;br /&gt;
 &lt;br /&gt;
SELECT Count(&#039;x&#039;) As NumOfStudents&lt;br /&gt;
                                FROM prefix_role_assignments a&lt;br /&gt;
                                JOIN prefix_user u ON userid = u.id&lt;br /&gt;
                                WHERE roleid = 5 AND contextid = (SELECT id FROM prefix_context WHERE instanceid = 668 AND contextlevel = 50)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Number of Quizes per Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Link&amp;lt;/a&amp;gt;&#039;) AS Quizes&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules cm&lt;br /&gt;
JOIN prefix_course c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module&lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039;&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all MultiAnswer (Cloze) Questions===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/attempt.php?q=&#039;, quiz.id, &#039;&amp;quot;&amp;gt;&#039;, quiz.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS Quiz&lt;br /&gt;
,question.id question_id, question.questiontext &lt;br /&gt;
FROM  prefix_question question&lt;br /&gt;
JOIN prefix_quiz_question_instances qqi ON question.id = qqi.question&lt;br /&gt;
JOIN prefix_quiz quiz ON qqi.quiz = quiz.id&lt;br /&gt;
WHERE  `qtype` LIKE  &#039;multianswer&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List courses with MANUAL grades===&lt;br /&gt;
Which is basically and indication to teachers using Moodle to hold offline grades inside Moodle&#039;s Gradebook,&lt;br /&gt;
So grades could be uploaded into an administrative SIS. Use with Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT( * )&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php?showadvanced=1&amp;amp;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM  prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course as c ON c.id = gi.courseid&lt;br /&gt;
WHERE  `itemtype` =  &#039;manual&#039;&lt;br /&gt;
GROUP BY courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===List the users that did not took the Quiz===&lt;br /&gt;
Do not forget to change &amp;quot;c.id = 14&amp;quot; and q.name LIKE &#039;%quiz name goes here%&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id AS ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.username AS IDNumber,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
 &lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id AND courseid=c.id) AS CourseLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id AND e.courseid = c.id) AS RoleName&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess AS ul ON ul.userid = user2.id&lt;br /&gt;
WHERE c.id=14 and ue.userid NOT IN (SELECT qa.userid FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON qa.quiz = q.id&lt;br /&gt;
JOIN prefix_course AS c ON q.course = c.id&lt;br /&gt;
WHERE c.id = 14 AND q.name LIKE &#039;%quiz name goes here%&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List Questions in each Quiz===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT quiz.id,quiz.name, q.id, q.name&lt;br /&gt;
FROM mdl_quiz AS quiz&lt;br /&gt;
JOIN mdl_question AS q ON FIND_IN_SET(q.id, quiz.questions)&lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
ORDER BY quiz.id ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this query does not work in Moodle 2.8. There is no mdl_quiz.questions field. It will need to be rewritten to use the usage/contextid organization.&lt;br /&gt;
&lt;br /&gt;
===Quiz activity research===&lt;br /&gt;
This report was made to extract student full activity in quizzes for an academic research about adapting instructional design teaching methods in online learning. The students do not use the Quiz module as a standard quiz but more as Study booklets or mini courses with embedded questions and hints to assist students evaluate their progress (Similar to what you expect to find in a SCORM activity)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cm.course &amp;quot;course_id&amp;quot;, cm.id &amp;quot;moduel_id&amp;quot;, q.id &amp;quot;quiz_id&amp;quot;, q.name &amp;quot;quiz_name&amp;quot;,&lt;br /&gt;
 &lt;br /&gt;
CASE q.grademethod&lt;br /&gt;
      WHEN 1 THEN &amp;quot;GRADEHIGHEST&amp;quot;&lt;br /&gt;
      WHEN 2 THEN &amp;quot;GRADEAVERAGE&amp;quot;&lt;br /&gt;
      WHEN 3 THEN &amp;quot;ATTEMPTFIRST&amp;quot;&lt;br /&gt;
      WHEN 4 THEN &amp;quot;ATTEMPTLAST&amp;quot;&lt;br /&gt;
END &amp;quot;grade method&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
, q.attempts &amp;quot;quiz_attempts_allowed&amp;quot;, cm.groupmode &amp;quot;group_mode&amp;quot;&lt;br /&gt;
, qa.id &amp;quot;attempt_id&amp;quot;, qa.state &amp;quot;attempt_state&amp;quot;, qa.sumgrades &amp;quot;attempt_grade&amp;quot;, qg.grade &amp;quot;user_final_grade&amp;quot;, q.grade &amp;quot;quiz_max_grade&amp;quot;&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = q.course AND m.userid = u.id) &amp;quot;user_groups&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timestart), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_start&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timefinish), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_finish&amp;quot;,&lt;br /&gt;
u.id &amp;quot;user_id&amp;quot;, u.firstname, u.lastname,&lt;br /&gt;
question.id &amp;quot;question_id&amp;quot;, question.name &amp;quot;question_name&amp;quot;,&lt;br /&gt;
qas.state &amp;quot;question_step_state&amp;quot;,qas.fraction &amp;quot;question_grade&amp;quot;, qh.hint, question.qtype &amp;quot;question_type&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz as q&lt;br /&gt;
JOIN mdl_course_modules as cm ON cm.instance = q.id and cm.module = 14 &lt;br /&gt;
JOIN mdl_quiz_attempts qa ON q.id = qa.quiz&lt;br /&gt;
LEFT JOIN mdl_quiz_grades as qg ON qg.quiz = q.id and qg.userid = qa.userid&lt;br /&gt;
JOIN mdl_user as u ON u.id = qa.userid&lt;br /&gt;
JOIN mdl_question_usages as qu ON qu.id = qa.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts as qatt ON qatt.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question as question ON question.id = qatt.questionid&lt;br /&gt;
JOIN mdl_question_attempt_steps as qas ON qas.questionattemptid = qatt.id&lt;br /&gt;
LEFT JOIN mdl_question_hints as qh ON qh.questionid = q.id&lt;br /&gt;
#WHERE q.id = &amp;quot;SOME QUIZ ID&amp;quot;&lt;br /&gt;
WHERE cm.course = &amp;quot;SOME COURSE ID&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quiz Usage in Courses by Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Multiple Choice&amp;quot; questions include true/false and matching question types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Short Answer&amp;quot; are questions that accept a single phrase.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Other&amp;quot; questions include fixed numerical, calculated, essay, and various drag and drop types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Min Quiz Age&amp;quot; and &amp;quot;Max Quiz Age&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: In Configurable Reports, the Date Filter is not applied until the &amp;quot;Apply&amp;quot; button is clicked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.shortname AS &#039;Course&#039;&lt;br /&gt;
#, u.lastname AS &#039;Instructor&#039;&lt;br /&gt;
, COUNT(DISTINCT q.id) AS &#039;Quizzes&#039;&lt;br /&gt;
, COUNT(DISTINCT qu.id) AS &#039;Questions&#039;&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 ))  AS &#039;multichoice&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT( qu.id) - SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;Other&#039;&lt;br /&gt;
&lt;br /&gt;
, (SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )))/COUNT( qu.id) AS &#039;Percent MC&#039;&lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;numerical&#039;, 1, 0 )) AS &#039;numerical&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype LIKE &#039;calc%&#039;, 1, 0 )) AS &#039;calculated&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;random&#039;, 1, 0 )) AS &#039;random&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;essay&#039;, 1, 0 )) AS &#039;essay&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, IF(q.shufflequestions &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Questions&#039;&lt;br /&gt;
, IF(q.shuffleanswers &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Answers&#039;&lt;br /&gt;
 &lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
#, FROM_UNIXTIME(MIN(q.timemodified)) AS &#039;Last Modified&#039;&lt;br /&gt;
&lt;br /&gt;
#, DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(MIN(q.timemodified))) AS &#039;Quiz age&#039;&lt;br /&gt;
&lt;br /&gt;
, MIN(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Min Quiz Age&#039; &lt;br /&gt;
, MAX(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Max Quiz Age&#039; &lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified)) &amp;lt; 90, 1,0)) AS &#039;new quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_quiz AS q&lt;br /&gt;
JOIN prefix_course AS c on c.id = q.course&lt;br /&gt;
JOIN prefix_quiz_question_instances AS qqi ON qqi.quiz = q.id&lt;br /&gt;
LEFT JOIN prefix_question AS qu ON qu.id = qqi.question&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%% %%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student responses (answers) to quiz questions===&lt;br /&gt;
(Contributed by Juan F with help from Tim hunt and fellow Moodlers on the forums)&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    concat( u.firstname, &amp;quot; &amp;quot;, u.lastname ) AS &amp;quot;Student Name&amp;quot;,&lt;br /&gt;
    u.id,&lt;br /&gt;
    quiza.userid,&lt;br /&gt;
    q.course,&lt;br /&gt;
    q.name,&lt;br /&gt;
    quiza.attempt,&lt;br /&gt;
    qa.slot,&lt;br /&gt;
    que.questiontext AS &#039;Question&#039;,&lt;br /&gt;
    qa.rightanswer AS &#039;Correct Answer&#039;,&lt;br /&gt;
    qa.responsesummary AS &#039;Student Answer&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz_attempts quiza&lt;br /&gt;
JOIN mdl_quiz q ON q.id=quiza.quiz&lt;br /&gt;
JOIN mdl_question_usages qu ON qu.id = quiza.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts qa ON qa.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question que ON que.id = qa.questionid&lt;br /&gt;
JOIN mdl_user u ON u.id = quiza.userid&lt;br /&gt;
&lt;br /&gt;
WHERE q.name = &amp;quot;BIO 208 Post Test Assessment&amp;quot;&lt;br /&gt;
AND q.course = &amp;quot;17926&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ORDER BY quiza.userid, quiza.attempt, qa.slot&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==SCORM Activity Reports==&lt;br /&gt;
&lt;br /&gt;
===Lists All completed SCORM activites by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists SCORM status for all enrolled users by Course name===&lt;br /&gt;
This report will list the SCORM status for all users enrolled in the course. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. This can be limited to individual courses by adding to the where clause the course id to report on.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.firstname AS First,&lt;br /&gt;
u.lastname AS Last, &lt;br /&gt;
u.idnumber AS Employee_ID,  &lt;br /&gt;
u.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
u.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course, &lt;br /&gt;
st.attempt AS Attempt,&lt;br /&gt;
st.value AS Status,&lt;br /&gt;
FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) AS Date &lt;br /&gt;
&lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
&lt;br /&gt;
WHERE st.element=&#039;cmi.core.lesson_status&#039; AND m.userid=u.id&lt;br /&gt;
&lt;br /&gt;
UNION&lt;br /&gt;
&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS First,&lt;br /&gt;
user2.lastname AS Last,&lt;br /&gt;
user2. idnumber AS Employee_ID,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
user2.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Attempt,&lt;br /&gt;
&amp;quot;not_started&amp;quot; AS Status,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Date&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = user2.id &lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.course=c.id&lt;br /&gt;
Left Join prefix_scorm_scoes_track AS st on st.scormid=sc.id AND st.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
WHERE  st.timemodified IS NULL AND m.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY  Course, Last, First, Attempt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Badges==&lt;br /&gt;
&lt;br /&gt;
=== All badges issued, by User ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, b.name AS badgename, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN&lt;br /&gt;
(SELECT c.shortname&lt;br /&gt;
    FROM prefix_course AS c&lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Context,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 1 THEN &amp;quot;Activity Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 2 THEN &amp;quot;Activity Completion (Any)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 2 AND t.method = 2 THEN &amp;quot;Manual Award&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 1 THEN &amp;quot;Course Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 2 THEN &amp;quot;Course Completion (Any)&amp;quot;&lt;br /&gt;
  ELSE CONCAT (&#039;Other: &#039;, t.criteriatype)&lt;br /&gt;
END AS Criteriatype,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateissued ) , &#039;%Y-%m-%d&#039; ) AS dateissued,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateexpire ), &#039;%Y-%m-%d&#039; ) AS dateexpires,&lt;br /&gt;
CONCAT (&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/badge.php?hash=&#039;,d.uniquehash,&#039;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&#039;) AS Details&lt;br /&gt;
FROM prefix_badge_issued AS d &lt;br /&gt;
JOIN prefix_badge AS b ON d.badgeid = b.id&lt;br /&gt;
JOIN prefix_user AS u ON d.userid = u.id&lt;br /&gt;
JOIN prefix_badge_criteria AS t on b.id = t.badgeid &lt;br /&gt;
WHERE t.criteriatype &amp;lt;&amp;gt; 0&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&lt;br /&gt;
=== All badges available in the system, with Earned count ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.type = 1 THEN &amp;quot;System&amp;quot;&lt;br /&gt;
WHEN b.type = 2 THEN &amp;quot;Course&amp;quot;&lt;br /&gt;
END AS Context, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN &lt;br /&gt;
(SELECT c.shortname &lt;br /&gt;
    FROM prefix_course AS c &lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 2 THEN &amp;quot;No&amp;quot;&lt;br /&gt;
WHEN b.status = 1 OR b.status = 3 THEN &amp;quot;Yes&amp;quot;&lt;br /&gt;
WHEN b.status = 4 THEN &amp;quot;x&amp;quot;&lt;br /&gt;
END AS Available,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 1 THEN &amp;quot;0&amp;quot;&lt;br /&gt;
WHEN b.status = 2 OR b.status = 3 OR b.status = 4 THEN &lt;br /&gt;
 (SELECT COUNT(*) &lt;br /&gt;
   FROM prefix_badge_issued AS d&lt;br /&gt;
   WHERE d.badgeid = b.id&lt;br /&gt;
 )&lt;br /&gt;
END AS Earned&lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Badges Leaderboard ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A simple list of usernames and how many badges they have earned overall.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, (SELECT COUNT(*) FROM prefix_badge_issued AS d WHERE d.userid = u.id) AS earned&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
ORDER BY earned DESC, u.username ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Manage badges (System &amp;amp; Course) ===&lt;br /&gt;
&lt;br /&gt;
List system wide badges, course and system level badges + a link to relevant &amp;quot;manage badges&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description &lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN b.type = 1 THEN &#039;System&#039;&lt;br /&gt;
  WHEN b.type = 2 THEN &#039;Course&#039;&lt;br /&gt;
END AS Level&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/index.php?type=&#039;, b.type, &#039;&amp;amp;id=&#039;,&lt;br /&gt;
			  c.id, &#039;&amp;quot;&amp;gt;Manage badges in: &#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Manage &lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Administrator Reports==&lt;br /&gt;
&lt;br /&gt;
===Config changes in Export friendly form===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( g.timemodified ) , &#039;%Y-%m-%d&#039; ) AS date, &lt;br /&gt;
u.username AS user, &lt;br /&gt;
g.name AS setting, &lt;br /&gt;
CASE &lt;br /&gt;
 WHEN g.plugin IS NULL THEN &amp;quot;core&amp;quot;&lt;br /&gt;
 ELSE g.plugin&lt;br /&gt;
END AS plugin, &lt;br /&gt;
g.value AS new_value, &lt;br /&gt;
g.oldvalue AS original_value&lt;br /&gt;
FROM prefix_config_log  AS g&lt;br /&gt;
JOIN prefix_user AS u ON g.userid = u.id&lt;br /&gt;
ORDER BY date DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts by user===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
How to get a list of all users and which cohorts they belong to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, h.idnumber, h.name&lt;br /&gt;
FROM prefix_cohort AS h&lt;br /&gt;
JOIN prefix_cohort_members AS hm ON h.id = hm.cohortid&lt;br /&gt;
JOIN prefix_user AS u ON hm.userid = u.id&lt;br /&gt;
ORDER BY u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts with Courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all cohorts with name, id, visibility, and which courses they are enrolled in.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
# h.id,&lt;br /&gt;
# e.customint1,&lt;br /&gt;
h.name AS Cohort,&lt;br /&gt;
h.idnumber AS Cohortid,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN h.visible = 1 THEN &#039;Yes&#039;&lt;br /&gt;
 ELSE &#039;-&#039;&lt;br /&gt;
END AS Cohortvisible,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;, CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_cohort h&lt;br /&gt;
JOIN prefix_enrol e ON h.id = e.customint1&lt;br /&gt;
JOIN prefix_course c ON c.id = e.courseid %%FILTER_COURSES:e.courseid%% &lt;br /&gt;
WHERE e.enrol = &#039;cohort&#039; AND e.roleid = 5&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses created And Active courses by Year===&lt;br /&gt;
Active courses is counting course that have at least one Hit, And &amp;quot;Active_MoreThan100Hits&amp;quot; counts courses that have at least 100 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `timecreated` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT course ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY course &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 100) AS courses_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( courses_log.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan100Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_course` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users created And Active users by Year===&lt;br /&gt;
Active users is counting users that have at least one Hit, And &amp;quot;Active_MoreThan500Hits&amp;quot; counts users that have at least 500 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `firstaccess` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT userid ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY userid &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 500) AS users_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( users_log.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan500Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Aggregation Report===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In particular, be on the lookout for any courses with the following combinations of parameters, which are known to cause changes in calculations:&lt;br /&gt;
&lt;br /&gt;
# mean of grades set with aggregate with subcategory.&lt;br /&gt;
# Simple weighted mean of grades with aggregate with sub category and drop the lowest&lt;br /&gt;
# Sum of grades drop the lowest&lt;br /&gt;
&lt;br /&gt;
Also review:&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48618&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48634&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-49257&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50089&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50062&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
COUNT(c.shortname) AS &#039;Count of Courses&#039;&lt;br /&gt;
&lt;br /&gt;
# If you want to display all the courses for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, c.shortname AS &#039;course name&#039;&lt;br /&gt;
&lt;br /&gt;
# If you need to display grade categories for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, gc.fullname AS &#039;grade category name&#039;&lt;br /&gt;
&lt;br /&gt;
, gc.aggregation AS &#039;aggregation method&#039;&lt;br /&gt;
&lt;br /&gt;
#These aggregation text strings appear to be hard-coded. I couldn&#039;t find a table for them. If you have aggregation types I haven&#039;t included here, they&#039;ll be blank in your report results.&lt;br /&gt;
, CASE gc.aggregation&lt;br /&gt;
  WHEN 0 THEN &#039;Mean of Grades&#039;&lt;br /&gt;
  WHEN 2 THEN &#039;Median of Grades&#039;&lt;br /&gt;
  WHEN 6 THEN &#039;Highest Grade&#039;&lt;br /&gt;
  WHEN 8 THEN &#039;Mode of Grades&#039;&lt;br /&gt;
  WHEN 10 THEN &#039;Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 11 THEN &#039;Simple Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 12 THEN &#039;Mean of Grades (with extra credits)&#039;&lt;br /&gt;
  WHEN 13 THEN &#039;Sum of Grades&#039;&lt;br /&gt;
END AS &#039;aggregation name&#039;&lt;br /&gt;
&lt;br /&gt;
# Note that gc.aggregatesubcats column is eliminated in 2.8 and later per MDL-47503, so comment that line on updated systems or you&#039;ll get an error&lt;br /&gt;
, gc.keephigh AS &#039;keep high&#039;&lt;br /&gt;
, gc.droplow AS &#039;dr0p low&#039;&lt;br /&gt;
, gc.aggregateonlygraded AS &#039;Aggregate only graded&#039;&lt;br /&gt;
, gc.aggregateoutcomes AS &#039;aggregate outcomes&#039;&lt;br /&gt;
, gc.aggregatesubcats AS &#039;aggregate subcategories&#039;&lt;br /&gt;
&lt;br /&gt;
# If you are displaying data about individual courses, you may want to know how old they are&lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;course start date&#039;&lt;br /&gt;
&lt;br /&gt;
# 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&#039;ll need to uncomment the necessary JOINs below&lt;br /&gt;
#, gi.itemname AS &#039;grade item&#039;&lt;br /&gt;
#, gg.finalgrade AS &#039;final grade&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
&lt;br /&gt;
prefix_course AS c&lt;br /&gt;
JOIN prefix_grade_categories AS gc ON gc.courseid = c.id&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id #AND gi.categoryid=gc.id&lt;br /&gt;
#LEFT JOIN prefix_grade_grades AS gg ON gg.itemid = gi.id AND gg.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
#AND gc.aggregation = 13 #only the dreaded Sum of Grades aggregations&lt;br /&gt;
#AND gc.depth = 1 # if for some reason you only want course aggregations, not subcategories&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.aggregation, gc.keephigh, gc.droplow, gc.aggregateonlygraded, gc.aggregateoutcomes, gc.aggregatesubcats&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running Cron jobs (task_scheduled) ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT classname&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(lastruntime), &#039;%H:%i [%d]&#039;) AS &#039;last&#039;&lt;br /&gt;
  ,DATE_FORMAT(now(), &#039;%H:%i&#039;) AS &#039;now&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(nextruntime), &#039;%H:%i [%d]&#039;) AS &#039;next&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP()-nextruntime), &#039;%i&#039;) AS &#039;next in min&#039;&lt;br /&gt;
FROM mdl_task_scheduled&lt;br /&gt;
WHERE now() &amp;gt; FROM_UNIXTIME(nextruntime)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== All Meta courses with Parent and Child course relationships ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
This shows the list of courses with Meta course link enrollments in them (&#039;Parent course&#039;), and the courses which are connected to them to provide enrollments (&#039;Child courses&#039;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.fullname AS &#039;Parent course name&#039;,&lt;br /&gt;
c.shortname AS &#039;Parent course shortname&#039;,&lt;br /&gt;
en.courseid AS &#039;Parent course id&#039;,&lt;br /&gt;
(SELECT fullname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course name&#039;,&lt;br /&gt;
(SELECT shortname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course shortname&#039;,&lt;br /&gt;
en.customint1 AS &#039;Child course id&#039;&lt;br /&gt;
FROM prefix_enrol en&lt;br /&gt;
JOIN prefix_course c ON c.id = en.courseid&lt;br /&gt;
WHERE en.enrol = &#039;meta&#039;&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Useful sub queries ==&lt;br /&gt;
&lt;br /&gt;
IN this section please put any short one purpose sub queries that show how common procedures often useful as part of larger queries.&lt;br /&gt;
&lt;br /&gt;
=== All teachers in the course ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This snippet shows how to get teachers from a course. The contextevel for course objects is 50. And the default Teacher role is role id 3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course ic&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = ic.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND ic.id = c.id&lt;br /&gt;
GROUP BY ic.id&lt;br /&gt;
) AS TeacherNames&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Get custom User profile fields for a user ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON uid.fieldid = uif.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to limit it to one of those fields, you can restrict it by shortname of the custom profile field, so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;shortname1&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will show you only the data from the custom profile field with the shortname &#039;shortname1&#039;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, d1.data AS &#039;Profile One&#039;, d2.data As &#039;Profile Two&#039;&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
JOIN prefix_user_info_data d1 ON d1.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
JOIN prefix_user_info_data d2 ON d2.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f2 ON d2.fieldid = f2.id AND f2.shortname = &#039;shortname2&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== NOTE: Alternate Method ====&lt;br /&gt;
&lt;br /&gt;
If you have more than a couple of fields you need to use, then this query may time out or not return data due to too many joins. The limit seems to be around 10 custom profile fields. &lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thefirstfield&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname2&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thesecondfield&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== How to use Configurable Reports Date Time Filters===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Here is a simple example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.firstaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;FirstAccess&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.lastaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;LastAccess&#039;   &lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1&lt;br /&gt;
%%FILTER_STARTTIME:u.firstaccess:&amp;gt;%% &lt;br /&gt;
%%FILTER_ENDTIME:u.lastaccess:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2) You MUST then add the Start / End date filter on the Filters tab of the Report. If you don&#039;t, the report will still run, probably, but the filter will be ignored.&lt;br /&gt;
&lt;br /&gt;
Note: the WHERE 1=1 statement is a peculiarity of the filters in Config reports: if you don&#039;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.)&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://github.com/jleyva/moodle-configurable_reports_repository Configurable Reports Repository on GitHub]&lt;br /&gt;
* [https://moodleschema.zoola.io/index.html Moodle DB schema explorer] - searching and filtering tables, fields and external key connections between tables.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;br /&gt;
&lt;br /&gt;
[[es:Reportes específicos hechos por usuarios]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Nginx&amp;diff=130139</id>
		<title>Nginx</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Nginx&amp;diff=130139"/>
		<updated>2018-02-17T14:23:00Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Nginx */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}[[Nginx]] [engine x] is an HTTP and reverse proxy server, as well as a mail proxy server, written by Igor Sysoev. The nginx project started with a strong focus on high concurrency, high performance and low memory usage. It is licensed under the 2-clause BSD-like license and it runs on Linux, BSD variants, Mac OS X, Solaris, AIX, HP-UX, as well as on other *nix flavours. It also has a proof of concept port for Microsoft Windows.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The following is community-contributed documentation on Nginx configuration. Amendments and additions are welcome.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Nginx configuration ==&lt;br /&gt;
&lt;br /&gt;
=== PHP-FPM ===&lt;br /&gt;
&lt;br /&gt;
Nginx is usually configured to interface with PHP via [http://php.net/manual/en/install.fpm.php php-fpm]. This is both fast and robust.&lt;br /&gt;
&lt;br /&gt;
PHP-FPM&#039;s default behaviour for pools is usually to restrict the execution of scripts to a specific extension, i.e. .php. You should ensure that this behaviour is configured within your particular package/distribution, e.g. for debian,&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;/etc/php5/fpm/pool.d/www.conf&#039;&#039;&#039;&lt;br /&gt;
 security.limit_extensions = .php&lt;br /&gt;
&lt;br /&gt;
=== Nginx ===&lt;br /&gt;
&lt;br /&gt;
Add the following &#039;slash arguments&#039; compatible &#039;location&#039; block to your vhosts &#039;server&#039; in your nginx configuration (further explanation at &#039;[[Using slash arguments]]&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;nginx.conf location:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location ~ [^/]\.php(/|$) {&lt;br /&gt;
    fastcgi_split_path_info  ^(.+\.php)(/.+)$;&lt;br /&gt;
    fastcgi_index            index.php;&lt;br /&gt;
    fastcgi_pass             127.0.0.1:9000 (or your php-fpm socket);&lt;br /&gt;
    include                  fastcgi_params;&lt;br /&gt;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;&lt;br /&gt;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you find that this does not work (scripts, styles, and images not loading) &#039;&#039;&#039;and&#039;&#039;&#039; that there are &amp;lt;code&amp;gt;open() &amp;quot;...&amp;quot; failed (20: Not a directory)&amp;lt;/code&amp;gt; lines appearing in your logs: Check whether there are any directives related to static content &#039;&#039;&#039;before&#039;&#039;&#039; this block and try moving them &#039;&#039;&#039;after&#039;&#039;&#039; this block.&lt;br /&gt;
&lt;br /&gt;
===== XSendfile aka X-Accel-Redirect =====&lt;br /&gt;
&lt;br /&gt;
Setting Moodle and Nginx to use XSendfile functionality is a big win as it frees PHP from delivering files allowing Nginx to do what it does best, i.e. deliver files. &lt;br /&gt;
&lt;br /&gt;
Enable xsendfile for Nginx in Moodles config.php, this is documented in the config-dist.php, a minimal configuration look like this,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;xsendfile = &#039;X-Accel-Redirect&#039;;&lt;br /&gt;
$CFG-&amp;gt;xsendfilealiases = array(&lt;br /&gt;
    &#039;/dataroot/&#039; =&amp;gt; $CFG-&amp;gt;dataroot&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Accompany this with a matching &#039;location&#039; block in your nginx server configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location /dataroot/ {&lt;br /&gt;
    internal;&lt;br /&gt;
    alias &amp;amp;lt;full_moodledata_path&amp;amp;gt;; # ensure the path ends with /&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The definition of &#039;internal&#039; here is &#039;&#039;&#039;critical&#039;&#039;&#039; as it prevents client access to your dataroot.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* Real &amp;lt;tt&amp;gt;PATH_INFO&amp;lt;/tt&amp;gt; support:&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=278916&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=307388&lt;br /&gt;
* &#039;&#039;&#039;[Deprecated]&#039;&#039;&#039; Internal rewriting to the HTTP GET &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=83445&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;br /&gt;
&lt;br /&gt;
[[es:Nginx]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=User_profiles&amp;diff=129694</id>
		<title>User profiles</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=User_profiles&amp;diff=129694"/>
		<updated>2017-12-15T18:03:16Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Site appearance}}&lt;br /&gt;
Every user in Moodle has a Profile page which may be reached from the user menu top right and then clicking Profile.  This page contains links to further pages allowing the user to [[Edit profile |edit their profile information]] and preferences, view their forum/blog posts, and check any reports they have access to.&lt;br /&gt;
&lt;br /&gt;
[[File:34Profile.png|thumb|center|600px|Example of a user&#039;s Profile page. Click to expand]]&lt;br /&gt;
&lt;br /&gt;
{{New features}}&lt;br /&gt;
If mobile access is enabled, a link to download the [[Moodle Mobile app]] is visible on the profile. (See screenshot above.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Viewing others&#039;s profiles==&lt;br /&gt;
&lt;br /&gt;
Users with permission to view the profiles of other users can view them by clicking on their name. If they click on the name of a user within a course, the course profile will be displayed and the full profile may be viewed (if allowed)  by clicking the link  &amp;quot;Full profile&amp;quot; in the Miscellaneous section:&lt;br /&gt;
&lt;br /&gt;
[[File:fullprofilelink.png]]&lt;br /&gt;
&lt;br /&gt;
Note: All users are allowed to view the full profile of users listed as course contacts in the course description.&lt;br /&gt;
&lt;br /&gt;
See [[View profile]] for more information on how the profile information is displayed and [[Edit profile]] for information on updating profiles.&lt;br /&gt;
&lt;br /&gt;
==Site administration settings==&lt;br /&gt;
&lt;br /&gt;
===Site policies===&lt;br /&gt;
&lt;br /&gt;
An administrator can force users to login for profiles and select which roles are visible in user profiles (by default teacher, non-editing teacher and student) in &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Security &amp;gt; Site policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Default profile page===&lt;br /&gt;
&lt;br /&gt;
An administrator or manager (or any other user with the capability [[Capabilities/moodle/user:managesyspages|moodle/user:managesyspages]]) can set which blocks appear on the default profile page for all users from &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Appearance &amp;gt; Default profile page&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Clicking the button &#039;Reset profile for all users&#039; will then apply these settings to the profile pages of everyone on the site.&lt;br /&gt;
&lt;br /&gt;
==Preventing users from customizing their profile page==&lt;br /&gt;
&lt;br /&gt;
By default, users can customize their public profile page and add blocks. To prevent this&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;&lt;br /&gt;
# Edit the authenticated user role and untick the capability [[Capabilities/moodle/user:manageownblocks|moodle/user:manageownblocks]]&lt;br /&gt;
&lt;br /&gt;
==User profile capabilities==&lt;br /&gt;
&lt;br /&gt;
System:&lt;br /&gt;
*[[Capabilities/moodle/user:editownprofile|Edit own user profile]]&lt;br /&gt;
*[[Capabilities/moodle/user:manageownblocks|Manage blocks on own public user profile]]&lt;br /&gt;
*[[Capabilities/moodle/user:managesyspages|Configure default page layout for public user profiles]]&lt;br /&gt;
*[[Capabilities/moodle/user:update|Update user profiles]]&lt;br /&gt;
&lt;br /&gt;
Users:&lt;br /&gt;
*[[Capabilities/moodle/user:editprofile|Edit user profile]]&lt;br /&gt;
*[[Capabilities/moodle/user:manageblocks|Manage blocks on user profile of other users]]&lt;br /&gt;
*[[Capabilities/moodle/user:viewalldetails|View user full information]]&lt;br /&gt;
&lt;br /&gt;
Course:&lt;br /&gt;
*[[Capabilities/moodle/user:viewdetails|View user profiles]]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[My profile]]&lt;br /&gt;
*[[View profile]]&lt;br /&gt;
*[[Activity report]]&lt;br /&gt;
*[[User profile fields]]&lt;br /&gt;
*[[Site policies]]&lt;br /&gt;
*[[Update profile]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Nutzerprofil]]&lt;br /&gt;
[[es:Perfiles de usuario]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Activity_report&amp;diff=129693</id>
		<title>Activity report</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Activity_report&amp;diff=129693"/>
		<updated>2017-12-15T17:47:15Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Course reports}}&lt;br /&gt;
==Course activity reports==&lt;br /&gt;
[[Image:courseactivityreport.png|thumb|Course activity report]]&lt;br /&gt;
&lt;br /&gt;
A course activity report, showing the number of views for each activity and resource (and any related blog entries), can be viewed by managers, teachers and non-editing teachers (and any other users with the capability [[Capabilities/report/outline:view|report/outline:view]]) in &#039;&#039;Administration &amp;gt; Course administration &amp;gt; Reports &amp;gt; Activity report&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
An activity report for the front page is available for administrators and managers in &#039;&#039;Administration &amp;gt; Front page settings&amp;gt;Reports &amp;gt; Activity report&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The length of time that the activity report covers is determined by the loglifetime setting in &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Courses &amp;gt; Backups &amp;gt; General backup defaults&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
An activity report is computed from the course&#039;s start date (in the [[Course settings|course settings]]).&lt;br /&gt;
&lt;br /&gt;
==Individual activity reports==&lt;br /&gt;
&lt;br /&gt;
If activity reports are enabled for a course in the course settings, each course participant can access reports of their contributions, such as forum posts or assignment submissions, logs and a statistics report.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;span id=&amp;quot;complete-report&amp;quot;&amp;gt;.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Complete Report==&lt;br /&gt;
&lt;br /&gt;
The Complete report helps instructors to view a detailed list of an individual student&#039;s last log and activity in the Activities and resources in your Moodle course, including detailed contribution to any of the various types of course activities. The activities and resources are displayed in the same order as they are on the main course page. it might resemble a student&#039;s portfolio at a specific course.&lt;br /&gt;
&lt;br /&gt;
[[{{ns:file}}:screencapture-school-demo-moodle-net-report-outline-user-php-1513359209412.png|400px|thumb|left|Complete report (user full activity and contribution in a course)&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
[[de:Aktivitätenbericht]]&lt;br /&gt;
[[es:Reporte de actividad]]&lt;br /&gt;
[[eu:Jardueraren_txostena]]&lt;br /&gt;
[[fr:Rapport d&#039;activité]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Activity_report&amp;diff=129692</id>
		<title>Activity report</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Activity_report&amp;diff=129692"/>
		<updated>2017-12-15T17:43:33Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Course reports}}&lt;br /&gt;
==Course activity reports==&lt;br /&gt;
[[Image:courseactivityreport.png|thumb|Course activity report]]&lt;br /&gt;
&lt;br /&gt;
A course activity report, showing the number of views for each activity and resource (and any related blog entries), can be viewed by managers, teachers and non-editing teachers (and any other users with the capability [[Capabilities/report/outline:view|report/outline:view]]) in &#039;&#039;Administration &amp;gt; Course administration &amp;gt; Reports &amp;gt; Activity report&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
An activity report for the front page is available for administrators and managers in &#039;&#039;Administration &amp;gt; Front page settings&amp;gt;Reports &amp;gt; Activity report&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The length of time that the activity report covers is determined by the loglifetime setting in &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Courses &amp;gt; Backups &amp;gt; General backup defaults&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
An activity report is computed from the course&#039;s start date (in the [[Course settings|course settings]]).&lt;br /&gt;
&lt;br /&gt;
==Individual activity reports==&lt;br /&gt;
&lt;br /&gt;
If activity reports are enabled for a course in the course settings, each course participant can access reports of their contributions, such as forum posts or assignment submissions, logs and a statistics report.&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
==Complete Report==&lt;br /&gt;
&lt;br /&gt;
The Complete report helps instructors to view a detailed list of an individual student&#039;s last log and activity in the Activities and resources in your Moodle course, including detailed contribution to any of the various types of course activities. The activities and resources are displayed in the same order as they are on the main course page. it might resemble a student&#039;s portfolio at a specific course.&lt;br /&gt;
&lt;br /&gt;
[[{{ns:file}}:screencapture-school-demo-moodle-net-report-outline-user-php-1513359209412.png|400px|thumb|left|Complete report (user full activity and contribution in a course)&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
[[de:Aktivitätenbericht]]&lt;br /&gt;
[[es:Reporte de actividad]]&lt;br /&gt;
[[eu:Jardueraren_txostena]]&lt;br /&gt;
[[fr:Rapport d&#039;activité]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=File:screencapture-school-demo-moodle-net-report-outline-user-php-1513359209412.png&amp;diff=129691</id>
		<title>File:screencapture-school-demo-moodle-net-report-outline-user-php-1513359209412.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=File:screencapture-school-demo-moodle-net-report-outline-user-php-1513359209412.png&amp;diff=129691"/>
		<updated>2017-12-15T17:37:14Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: Complete report (user full activity and contribution in a course)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Complete report (user full activity and contribution in a course)&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Activity_report&amp;diff=129690</id>
		<title>Activity report</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Activity_report&amp;diff=129690"/>
		<updated>2017-12-15T17:32:22Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Course reports}}&lt;br /&gt;
==Course activity reports==&lt;br /&gt;
[[Image:courseactivityreport.png|thumb|Course activity report]]&lt;br /&gt;
A course activity report, showing the number of views for each activity and resource (and any related blog entries), can be viewed by managers, teachers and non-editing teachers (and any other users with the capability [[Capabilities/report/outline:view|report/outline:view]]) in &#039;&#039;Administration &amp;gt; Course administration &amp;gt; Reports &amp;gt; Activity report&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
An activity report for the front page is available for administrators and managers in &#039;&#039;Administration &amp;gt; Front page settings&amp;gt;Reports &amp;gt; Activity report&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The length of time that the activity report covers is determined by the loglifetime setting in &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Courses &amp;gt; Backups &amp;gt; General backup defaults&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
An activity report is computed from the course&#039;s start date (in the [[Course settings|course settings]]).&lt;br /&gt;
&lt;br /&gt;
==Individual activity reports==&lt;br /&gt;
&lt;br /&gt;
If activity reports are enabled for a course in the course settings, each course participant can access reports of their contributions, such as forum posts or assignment submissions, logs and a statistics report.&lt;br /&gt;
&lt;br /&gt;
==Complete Report==&lt;br /&gt;
The Complete report helps instructors to view a detailed list of an individual student&#039;s last log and activity in the Activities and resources in your Moodle course, including detailed contribution to any of the various types of course activities. The activities and resources are displayed in the same order as they are on the main course page. it might resemble a student&#039;s portfolio at a specific course.&lt;br /&gt;
&lt;br /&gt;
[[de:Aktivitätenbericht]]&lt;br /&gt;
[[es:Reporte de actividad]]&lt;br /&gt;
[[eu:Jardueraren_txostena]]&lt;br /&gt;
[[fr:Rapport d&#039;activité]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Installing_Moodle&amp;diff=129480</id>
		<title>Installing Moodle</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Installing_Moodle&amp;diff=129480"/>
		<updated>2017-11-23T21:01:26Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Settings within Moodle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Installing Moodle}}&lt;br /&gt;
&#039;&#039;This page explains how to install Moodle. If you are an expert and/or in a hurry try [[Installation Quickstart]].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you just want to try Moodle on a standalone machine there are &#039;one-click&#039; installers for Windows (see [[Complete install packages for Windows]]) and for OSX (see [[Complete Install Packages for Mac OS X]]) or [[ install on OS X]]. These are unsuitable for production servers. &lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Moodle is primarily developed in Linux using [[Apache]], [[PostgreSQL]]/[[MySQL]]/[[MariaDB]] and [[PHP]] (sometimes known as the LAMP platform). Typically this is also how Moodle is run, although there are other options as long as the software requirements of the  [{{Release notes}} release] are met.&lt;br /&gt;
&lt;br /&gt;
If you are installing Moodle in a Windows server, note that from php5.5 onwards, you will also need to have  the Visual C++ Redistributable for Visual Studio 2012 installed from:&lt;br /&gt;
http://www.microsoft.com/en-us/download/details.aspx?id=30679 Visual C++] ( x86 or x64)  &lt;br /&gt;
&lt;br /&gt;
The basic requirements for Moodle are as follows:&lt;br /&gt;
&lt;br /&gt;
=== Hardware === &lt;br /&gt;
* Disk space: 200MB for the Moodle code, plus as much as you need to store content. 5GB is probably a realistic minimum. &lt;br /&gt;
* Processor: 1GHz (min), 2GHz dual core or more recommended.&lt;br /&gt;
* Memory: 512MB (min), 1GB or more is recommended. 8GB plus is likely on a large production server&lt;br /&gt;
* Consider separate servers for the web &amp;quot;front ends&amp;quot; and the database. It is much easier to &amp;quot;tune&amp;quot;&lt;br /&gt;
&lt;br /&gt;
All the above requirements will vary depending on specific hardware and software combinations as well as the type of use and load; busy sites may well require additional resources. Further guidance can be found under [[Performance_recommendations|performance recommendations]]. Moodle scales easily by increasing hardware.&lt;br /&gt;
&lt;br /&gt;
For very large sites, you are much better starting with a small pilot and gaining some experience and insight. A &amp;quot;what hardware do I need for 50,000 user?&amp;quot; style post in the forums is highly unlikely to get a useful answer.&lt;br /&gt;
&lt;br /&gt;
=== Software ===&lt;br /&gt;
&lt;br /&gt;
See the [{{Release notes}} release notes] in the dev docs for software requirements.&lt;br /&gt;
&lt;br /&gt;
== Set up your server ==&lt;br /&gt;
&lt;br /&gt;
Depending the use case a Moodle server may be anything from a Desktop PC (e.g. for testing and evaluating) to a rackmounted or  [[Server cluster|clustered]] solution. As mentioned above there are lots of possibilities for installing the basic server software, some links and pointers are at [[Installing AMP]], [[Internet_Information_Services|IIS]], [[Nginx]]. &lt;br /&gt;
&lt;br /&gt;
It will help hugely, regardless of your deployment choices, if time is taken to understand how to configure the different parts of your software stack (HTTP daemon, database,  PHP etc). Do not expect the standard server configuration to be optimal for Moodle. For example, the web server and database servers will almost certainly require tuning to get the best out of Moodle.&lt;br /&gt;
&lt;br /&gt;
If a hosting provider is being used  ensure that all Moodle [{{Release notes}}#Server_requirements requirments] (such as PHP version) are met by the hosting platform before attempting the installation. It will help to become familiar with changing settings within the hosting provider&#039;s platform (e.g. PHP file upload maximums) as the options and tools provided vary.&lt;br /&gt;
&lt;br /&gt;
== Download and copy files into place ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT: While there are now a number of places you can get the Moodle code (including host provided Moodle installers), you are strongly advised to only obtain Moodle from moodle.org. If you run into problems it will be a great deal easier to support you.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You have two options:&lt;br /&gt;
* Download your required version from http://moodle.org/downloads and unzip/unpack...&lt;br /&gt;
* &#039;&#039;&#039;OR&#039;&#039;&#039; Pull the code from the Git repository (recommended for developers and also makes upgrading very simple):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git clone -b MOODLE_{{Version3}}_STABLE git://git.moodle.org/moodle.git  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other options you might consider:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;--depth=1&#039;&#039;  for shallow cloning (only) latest revision (be advised! If you are a developer, you will not be able to easily make git updates and modification later on when this feature is used) &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;--single-branch&#039;&#039;  to limit cloning to a single branch, this fetches the Moodle {{Version}} Stable branch (latest weekly build). For a fuller discussion see [[Git for Administrators]]. &lt;br /&gt;
&lt;br /&gt;
Either of the above should result in a directory called &#039;&#039;&#039;moodle&#039;&#039;&#039;, containing a number of files and folders. &lt;br /&gt;
&lt;br /&gt;
You can typically place the whole folder in your web server documents directory, in which case the site will be located at &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://yourwebserver.com/moodle&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;, or you can copy all the contents straight into the main web server documents directory, in which case the site will be simply &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://yourwebserver.com&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;. See the documentation for your system and/or web server if you are unsure. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;Tip:&#039;&#039; If you are downloading Moodle to your local computer and then uploading it to your hosted web site, if possible upload the compressed file and decompress at the remote end (check your &#039;file manager&#039;). Failing that, watch FTP progress carefully for errors or missed files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Secure the Moodle files:&#039;&#039;&#039; It is vital that the files are not writeable by the web server user. For example, on Unix/Linux (as root):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chown -R root /path/to/moodle&lt;br /&gt;
# chmod -R 0755 /path/to/moodle&lt;br /&gt;
# find /path/to/moodle -type f -exec chmod 0644 {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(files are owned by the administrator/superuser and are only writeable by them - readable by everyone else)&lt;br /&gt;
&lt;br /&gt;
The third command finds all the regular files and executes the chmod command 0644 on them. &lt;br /&gt;
&lt;br /&gt;
If you want to use the built-in plugin installer you need to make the directory writable by web server user. It is strongly recommended to use ACL when your server supports it, for example if your Apache server uses account www-data: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chmod -R +a &amp;quot;www-data allow read,delete,write,append,file_inherit,directory_inherit&amp;quot; /path/to/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The effect of the previous command is to allow the Apache user account (www-data in this case) to access and change files within the moodle site. Many people would consider this a brave move for a new site admin to implement. In a new moodle you can safely leave this out. A default Ubuntu install does not have the +a option for the chmod command anyway. The +a attribute is an ACL (Access Control List) facility which allows you to set per user access for individual files. For example, OSX has this by default.&lt;br /&gt;
&lt;br /&gt;
== Create an empty database ==&lt;br /&gt;
&lt;br /&gt;
Next create a new, empty database for your installation. You need to find and make a note of following information for use during the final installation stage:&lt;br /&gt;
* &#039;&#039;&#039;dbhost&#039;&#039;&#039; - the database server hostname. Probably &#039;&#039;localhost&#039;&#039; if the database and web server are the same machine, otherwise the name of the database server&lt;br /&gt;
* &#039;&#039;&#039;dbname&#039;&#039;&#039; - the database name. Whatever you called it, e.g. &#039;&#039;moodle&#039;&#039; &lt;br /&gt;
* &#039;&#039;&#039;dbuser&#039;&#039;&#039; - the username for the database. Whatever you assigned, e.g. &#039;&#039;moodleuser&#039;&#039; - do not use the root/superuser account. Create a proper account with the minimum permissions needed.&lt;br /&gt;
* &#039;&#039;&#039;dbpass&#039;&#039;&#039; - the password for the above user&lt;br /&gt;
&lt;br /&gt;
If your site is hosted you should find a web-based administration page for databases as part of the control panel (or ask your administrator). For everyone else or for detailed instructions, see the page for your chosen database server:&lt;br /&gt;
* [[PostgreSQL]] (recommended)&lt;br /&gt;
* [[MariaDB]] (recommended)&lt;br /&gt;
* [[MySQL]]&lt;br /&gt;
* [[MSSQL]]&lt;br /&gt;
* [[Oracle]] (not recommended)&lt;br /&gt;
&lt;br /&gt;
== Create the (&#039;&#039;moodledata&#039;&#039;) data directory  ==&lt;br /&gt;
&lt;br /&gt;
Moodle requires a directory to store all of its files (all your site&#039;s uploaded files, temporary data, cache, session data etc.). The web server needs to be able to write to this directory. On larger systems consider how much free space you are going to use when allocating this directory. &lt;br /&gt;
&lt;br /&gt;
Due to the default way Moodle caches data you may have serious performance issues if you use relatively slow storage (e.g. NFS) for this directory. Read the [[Performance_recommendations]] carefully and consider using (e.g.) redis or memcached for [[Caching]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This directory must &#039;&#039;&#039;NOT&#039;&#039;&#039; be accessible directly via the web. This would be a serious security hole. Do not try to place it inside your web root or inside your Moodle program files directory. Moodle will not install. It can go anywhere else convenient. &lt;br /&gt;
&lt;br /&gt;
Here is an example (Unix/Linux) of creating the directory and setting the permissions for &#039;&#039;&#039;anyone&#039;&#039;&#039; on the server to write here. This is only appropriate for Moodle servers that are not shared. Discuss this with your server administrator for better permissions that just allow the web server user to access these files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# mkdir /path/to/moodledata&lt;br /&gt;
# chmod 0777 /path/to/moodledata&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your server supports ACL it is recommended to set following permissions, for example if your Apache server uses account www-data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chmod -R +a &amp;quot;www-data allow read,delete,write,append,file_inherit,directory_inherit&amp;quot; /path/to/moodledata&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are planning to execute PHP scripts from the command line you should set the same permissions for the current user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo chmod -R +a &amp;quot;`whoami` allow read,delete,write,append,file_inherit,directory_inherit&amp;quot; /path/to/moodledata&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Securing moodledata in a web directory ====&lt;br /&gt;
&lt;br /&gt;
If you are using a hosted site and you have no option but to place &#039;moodledata&#039; in a web accessible directory. You may be able to secure it by creating an .htaccess file in the &#039;moodledata&#039; directory. This does not work on all systems - see your host/administrator. Create a file called .htaccess containing only the following lines:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
order deny,allow&lt;br /&gt;
deny from all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Start Moodle install ==&lt;br /&gt;
It&#039;s now time to run the installer to create the database tables and configure your new site. The recommended method is to use the command line installer. If you cannot do this for any reason (e.g. on a Windows server) the web based installer is still available.&lt;br /&gt;
&lt;br /&gt;
=== Command line installer ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s best to run the command line as your system&#039;s web user. You need to know what that is - see your system&#039;s documentation (e.g. Ubuntu/Debian is &#039;www-data&#039;, Centos is &#039;apache&#039;)&lt;br /&gt;
&lt;br /&gt;
* Example of using the command-line  (as root - substitute &#039;www-data&#039; for your web user):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chown www-data /path/to/moodle&lt;br /&gt;
# cd /path/to/moodle/admin/cli&lt;br /&gt;
# sudo -u www-data /usr/bin/php install.php&lt;br /&gt;
# chown -R root /path/to/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The chowns allow the script to write a new config.php file. More information about the options can be found using &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# php install.php --help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be asked for other settings that have not been discussed on this page - if unsure just accept the defaults. For a full discussion see [[Administration via command line]]&lt;br /&gt;
&lt;br /&gt;
=== Web based installer ===&lt;br /&gt;
&lt;br /&gt;
For ease of use you can install Moodle via the web. We recommend configuring your web server so that the page is not publicly accessible until the installation is complete.&lt;br /&gt;
&lt;br /&gt;
To run the web installer script, just go to your Moodle&#039;s main URL using a web browser.&lt;br /&gt;
&lt;br /&gt;
The installation process will take you through a number of pages. You should be asked to confirm the copyright, see the database tables being created, supply administrator account details and supply the site details. The database creation can take some time - please be patient. You should eventually end up at the Moodle front page with an invitation to create a new course. &lt;br /&gt;
&lt;br /&gt;
It is very likely that you will be asked to download the new config.php file and upload it to your Moodle installation - just follow the on-screen instructions.&lt;br /&gt;
&lt;br /&gt;
==Final configuration==&lt;br /&gt;
&lt;br /&gt;
=== Settings within Moodle ===&lt;br /&gt;
There are a number of options within the Moodle Site Administration screens (accessible from the &#039;Site administration&#039; tab in the &#039;Administration&#039; block. Here are a few of the more important ones that you will probably want to check:&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Plugins &amp;gt; Message Outputs &amp;gt; Email&#039;&#039;: Set your smtp server and authentication if required (so your Moodle site can send emails). The support contact for your site is also set on this page. &lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; System paths&#039;&#039;: Set the paths to du, dot and aspell binaries.&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; HTTP&#039;&#039;: If you are behind a firewall you may need to set your proxy credentials in the &#039;Web proxy&#039; section.&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Location &amp;gt; Update timezones&#039;&#039;: Run this to make sure your timezone information is up to date. (more info [[Location]])&lt;br /&gt;
** [http://php.net/manual/en/timezones.php Set server&#039;s local timezone] inside &amp;lt;tt&amp;gt;php.ini&amp;lt;/tt&amp;gt; (should probably be inside &amp;lt;tt&amp;gt;/etc/php.ini&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;/etc/php.d/date.ini&amp;lt;/tt&amp;gt;, depending on the underline OS):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
[Date] &lt;br /&gt;
; Defines the default timezone used by the date functions &lt;br /&gt;
date.timezone = &amp;quot;YOUR LOCAL TIMEZONE&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remaining tasks ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configure Cron&#039;&#039;&#039;: Moodle&#039;s background tasks (e.g. sending out forum emails and performing course backups) are performed by a script which you can set to execute at specific times of the day. This is known as a cron script. Please refer to the [[Cron|Cron instructions]].&lt;br /&gt;
* &#039;&#039;&#039;Set up backups&#039;&#039;&#039;: See [[Site backup]] and [[Automated course backup]].&lt;br /&gt;
* &#039;&#039;&#039;Check mail works&#039;&#039;&#039;: [[Add a new user|Create a test user]] with a valid email address and [[message|send them a message]]. Do they receive an email copy of the message? If not, check the settings in &#039;&#039;Settings &amp;gt; Site administration &amp;gt; Plugins &amp;gt; Message outputs &amp;gt; Email&#039;&#039;. Don&#039;t be tempted to skip this step (clue: email is used to recover lost passwords, including the administrator password when you forget it!)&lt;br /&gt;
* &#039;&#039;&#039;Secure your Moodle site&#039;&#039;&#039;: Read the [[Security recommendations]].&lt;br /&gt;
*&#039;&#039;&#039;Increasing the maximum upload size&#039;&#039;&#039;  See [[Installation FAQ]] Maximum upload file size - how to change it?&lt;br /&gt;
&lt;br /&gt;
=== Installation is complete :) ===&lt;br /&gt;
&lt;br /&gt;
* Create a new course: You can now access Moodle through your web browser (using the same URL as you set during the install process), log in as your admin user and creatse a new course. See  [[Adding a new course|create a new course]].&lt;br /&gt;
&lt;br /&gt;
=== If something goes wrong... ===&lt;br /&gt;
&lt;br /&gt;
Here are some things you should try...&lt;br /&gt;
&lt;br /&gt;
* Check the [[Installation FAQ]]&lt;br /&gt;
* Check your file permissions carefully. Can your web server read (but not write) the Moodle program files? Can your web server read and write your Moodle data directory? If you don&#039;t fully understand how file ownership and permissions work on your operating system it would be time very well spent to find out.&lt;br /&gt;
* Check your database permissions. Have you set up your database user with the correct rights and permissions for your configuration (especially if the web server and database server are different machines)?&lt;br /&gt;
* Create your [[Configuration file]] (config.php) by hand. Copy config-dist.php (in the root of the Moodle program directory) to config.php, edit it and set your database/site options there. Installation will continue from the right place. &lt;br /&gt;
* Once you have a config.php (see previous tip) you can edit it to turn on debugging (in section 8). This may give you extra information to help track down a problem. If you have access, check your web server error log(s).&lt;br /&gt;
* Re-check your php.ini / .htaccess settings. Are they appropriate (e.g. memory_limit), did you edit the correct php.ini / .htaccess file and (if required) did you re-start the web server after making changes?&lt;br /&gt;
* Did you include any non-core (optional) plugins, themes or other code before starting the installation script? If so, remove it and try again (it may be broken or incompatible).&lt;br /&gt;
* Explain your problem in the [http://moodle.org/mod/forum/view.php?id=28 Installation problems forum]. &#039;&#039;&#039;PLEASE&#039;&#039;&#039; list your software versions; explain what you did, what happened and what error messages you saw (if any); explain what you tried. There is no such thing as &#039;nothing&#039;, even a blank page is something!&lt;br /&gt;
&lt;br /&gt;
== Platform specific instructions ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Much of this information is provided by the community. It may not have been checked and may be out of date. Please read in conjunction with the above installation instructions.&lt;br /&gt;
&lt;br /&gt;
* [[Windows installation]]&lt;br /&gt;
** [[Installing Moodle on SmarterASP.NET]]&lt;br /&gt;
* [[Unix or Linux Installation]]&lt;br /&gt;
* [[Mac Installation]]&lt;br /&gt;
* [[Amazon EC2 Cloud Services Installation]]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [http://www.slideshare.net/gb2048/my-own-moodle Slideshare presentation by Gareth Barnard on installing a local installation of Moodle] and accompanying [https://drive.google.com/folderview?id=0B17B0rYH2zERU21sQnVweUZCUFk&amp;amp;usp=sharing  help guides]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=182086 New Video Tutorial- How to Install Moodle on Shared Hosting via cPanel (Not Fantastico)]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=199542 Video Tutorial - Install Moodle on a Virtual Box from scratch] &lt;br /&gt;
&lt;br /&gt;
[[es:Instalaci%C3%B3n_de_moodle]]&lt;br /&gt;
[[de:Installation von Moodle]]&lt;br /&gt;
[[fr:Installation de Moodle]]&lt;br /&gt;
[[ja:Moodleのインストール]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Installing_Moodle&amp;diff=129479</id>
		<title>Installing Moodle</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Installing_Moodle&amp;diff=129479"/>
		<updated>2017-11-23T20:57:33Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Download and copy files into place */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Installing Moodle}}&lt;br /&gt;
&#039;&#039;This page explains how to install Moodle. If you are an expert and/or in a hurry try [[Installation Quickstart]].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you just want to try Moodle on a standalone machine there are &#039;one-click&#039; installers for Windows (see [[Complete install packages for Windows]]) and for OSX (see [[Complete Install Packages for Mac OS X]]) or [[ install on OS X]]. These are unsuitable for production servers. &lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Moodle is primarily developed in Linux using [[Apache]], [[PostgreSQL]]/[[MySQL]]/[[MariaDB]] and [[PHP]] (sometimes known as the LAMP platform). Typically this is also how Moodle is run, although there are other options as long as the software requirements of the  [{{Release notes}} release] are met.&lt;br /&gt;
&lt;br /&gt;
If you are installing Moodle in a Windows server, note that from php5.5 onwards, you will also need to have  the Visual C++ Redistributable for Visual Studio 2012 installed from:&lt;br /&gt;
http://www.microsoft.com/en-us/download/details.aspx?id=30679 Visual C++] ( x86 or x64)  &lt;br /&gt;
&lt;br /&gt;
The basic requirements for Moodle are as follows:&lt;br /&gt;
&lt;br /&gt;
=== Hardware === &lt;br /&gt;
* Disk space: 200MB for the Moodle code, plus as much as you need to store content. 5GB is probably a realistic minimum. &lt;br /&gt;
* Processor: 1GHz (min), 2GHz dual core or more recommended.&lt;br /&gt;
* Memory: 512MB (min), 1GB or more is recommended. 8GB plus is likely on a large production server&lt;br /&gt;
* Consider separate servers for the web &amp;quot;front ends&amp;quot; and the database. It is much easier to &amp;quot;tune&amp;quot;&lt;br /&gt;
&lt;br /&gt;
All the above requirements will vary depending on specific hardware and software combinations as well as the type of use and load; busy sites may well require additional resources. Further guidance can be found under [[Performance_recommendations|performance recommendations]]. Moodle scales easily by increasing hardware.&lt;br /&gt;
&lt;br /&gt;
For very large sites, you are much better starting with a small pilot and gaining some experience and insight. A &amp;quot;what hardware do I need for 50,000 user?&amp;quot; style post in the forums is highly unlikely to get a useful answer.&lt;br /&gt;
&lt;br /&gt;
=== Software ===&lt;br /&gt;
&lt;br /&gt;
See the [{{Release notes}} release notes] in the dev docs for software requirements.&lt;br /&gt;
&lt;br /&gt;
== Set up your server ==&lt;br /&gt;
&lt;br /&gt;
Depending the use case a Moodle server may be anything from a Desktop PC (e.g. for testing and evaluating) to a rackmounted or  [[Server cluster|clustered]] solution. As mentioned above there are lots of possibilities for installing the basic server software, some links and pointers are at [[Installing AMP]], [[Internet_Information_Services|IIS]], [[Nginx]]. &lt;br /&gt;
&lt;br /&gt;
It will help hugely, regardless of your deployment choices, if time is taken to understand how to configure the different parts of your software stack (HTTP daemon, database,  PHP etc). Do not expect the standard server configuration to be optimal for Moodle. For example, the web server and database servers will almost certainly require tuning to get the best out of Moodle.&lt;br /&gt;
&lt;br /&gt;
If a hosting provider is being used  ensure that all Moodle [{{Release notes}}#Server_requirements requirments] (such as PHP version) are met by the hosting platform before attempting the installation. It will help to become familiar with changing settings within the hosting provider&#039;s platform (e.g. PHP file upload maximums) as the options and tools provided vary.&lt;br /&gt;
&lt;br /&gt;
== Download and copy files into place ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT: While there are now a number of places you can get the Moodle code (including host provided Moodle installers), you are strongly advised to only obtain Moodle from moodle.org. If you run into problems it will be a great deal easier to support you.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You have two options:&lt;br /&gt;
* Download your required version from http://moodle.org/downloads and unzip/unpack...&lt;br /&gt;
* &#039;&#039;&#039;OR&#039;&#039;&#039; Pull the code from the Git repository (recommended for developers and also makes upgrading very simple):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git clone -b MOODLE_{{Version3}}_STABLE git://git.moodle.org/moodle.git  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other options you might consider:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;--depth=1&#039;&#039;  for shallow cloning (only) latest revision (be advised! If you are a developer, you will not be able to easily make git updates and modification later on when this feature is used) &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;--single-branch&#039;&#039;  to limit cloning to a single branch, this fetches the Moodle {{Version}} Stable branch (latest weekly build). For a fuller discussion see [[Git for Administrators]]. &lt;br /&gt;
&lt;br /&gt;
Either of the above should result in a directory called &#039;&#039;&#039;moodle&#039;&#039;&#039;, containing a number of files and folders. &lt;br /&gt;
&lt;br /&gt;
You can typically place the whole folder in your web server documents directory, in which case the site will be located at &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://yourwebserver.com/moodle&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;, or you can copy all the contents straight into the main web server documents directory, in which case the site will be simply &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://yourwebserver.com&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;. See the documentation for your system and/or web server if you are unsure. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;Tip:&#039;&#039; If you are downloading Moodle to your local computer and then uploading it to your hosted web site, if possible upload the compressed file and decompress at the remote end (check your &#039;file manager&#039;). Failing that, watch FTP progress carefully for errors or missed files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Secure the Moodle files:&#039;&#039;&#039; It is vital that the files are not writeable by the web server user. For example, on Unix/Linux (as root):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chown -R root /path/to/moodle&lt;br /&gt;
# chmod -R 0755 /path/to/moodle&lt;br /&gt;
# find /path/to/moodle -type f -exec chmod 0644 {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(files are owned by the administrator/superuser and are only writeable by them - readable by everyone else)&lt;br /&gt;
&lt;br /&gt;
The third command finds all the regular files and executes the chmod command 0644 on them. &lt;br /&gt;
&lt;br /&gt;
If you want to use the built-in plugin installer you need to make the directory writable by web server user. It is strongly recommended to use ACL when your server supports it, for example if your Apache server uses account www-data: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chmod -R +a &amp;quot;www-data allow read,delete,write,append,file_inherit,directory_inherit&amp;quot; /path/to/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The effect of the previous command is to allow the Apache user account (www-data in this case) to access and change files within the moodle site. Many people would consider this a brave move for a new site admin to implement. In a new moodle you can safely leave this out. A default Ubuntu install does not have the +a option for the chmod command anyway. The +a attribute is an ACL (Access Control List) facility which allows you to set per user access for individual files. For example, OSX has this by default.&lt;br /&gt;
&lt;br /&gt;
== Create an empty database ==&lt;br /&gt;
&lt;br /&gt;
Next create a new, empty database for your installation. You need to find and make a note of following information for use during the final installation stage:&lt;br /&gt;
* &#039;&#039;&#039;dbhost&#039;&#039;&#039; - the database server hostname. Probably &#039;&#039;localhost&#039;&#039; if the database and web server are the same machine, otherwise the name of the database server&lt;br /&gt;
* &#039;&#039;&#039;dbname&#039;&#039;&#039; - the database name. Whatever you called it, e.g. &#039;&#039;moodle&#039;&#039; &lt;br /&gt;
* &#039;&#039;&#039;dbuser&#039;&#039;&#039; - the username for the database. Whatever you assigned, e.g. &#039;&#039;moodleuser&#039;&#039; - do not use the root/superuser account. Create a proper account with the minimum permissions needed.&lt;br /&gt;
* &#039;&#039;&#039;dbpass&#039;&#039;&#039; - the password for the above user&lt;br /&gt;
&lt;br /&gt;
If your site is hosted you should find a web-based administration page for databases as part of the control panel (or ask your administrator). For everyone else or for detailed instructions, see the page for your chosen database server:&lt;br /&gt;
* [[PostgreSQL]] (recommended)&lt;br /&gt;
* [[MariaDB]] (recommended)&lt;br /&gt;
* [[MySQL]]&lt;br /&gt;
* [[MSSQL]]&lt;br /&gt;
* [[Oracle]] (not recommended)&lt;br /&gt;
&lt;br /&gt;
== Create the (&#039;&#039;moodledata&#039;&#039;) data directory  ==&lt;br /&gt;
&lt;br /&gt;
Moodle requires a directory to store all of its files (all your site&#039;s uploaded files, temporary data, cache, session data etc.). The web server needs to be able to write to this directory. On larger systems consider how much free space you are going to use when allocating this directory. &lt;br /&gt;
&lt;br /&gt;
Due to the default way Moodle caches data you may have serious performance issues if you use relatively slow storage (e.g. NFS) for this directory. Read the [[Performance_recommendations]] carefully and consider using (e.g.) redis or memcached for [[Caching]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This directory must &#039;&#039;&#039;NOT&#039;&#039;&#039; be accessible directly via the web. This would be a serious security hole. Do not try to place it inside your web root or inside your Moodle program files directory. Moodle will not install. It can go anywhere else convenient. &lt;br /&gt;
&lt;br /&gt;
Here is an example (Unix/Linux) of creating the directory and setting the permissions for &#039;&#039;&#039;anyone&#039;&#039;&#039; on the server to write here. This is only appropriate for Moodle servers that are not shared. Discuss this with your server administrator for better permissions that just allow the web server user to access these files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# mkdir /path/to/moodledata&lt;br /&gt;
# chmod 0777 /path/to/moodledata&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your server supports ACL it is recommended to set following permissions, for example if your Apache server uses account www-data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chmod -R +a &amp;quot;www-data allow read,delete,write,append,file_inherit,directory_inherit&amp;quot; /path/to/moodledata&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are planning to execute PHP scripts from the command line you should set the same permissions for the current user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo chmod -R +a &amp;quot;`whoami` allow read,delete,write,append,file_inherit,directory_inherit&amp;quot; /path/to/moodledata&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Securing moodledata in a web directory ====&lt;br /&gt;
&lt;br /&gt;
If you are using a hosted site and you have no option but to place &#039;moodledata&#039; in a web accessible directory. You may be able to secure it by creating an .htaccess file in the &#039;moodledata&#039; directory. This does not work on all systems - see your host/administrator. Create a file called .htaccess containing only the following lines:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
order deny,allow&lt;br /&gt;
deny from all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Start Moodle install ==&lt;br /&gt;
It&#039;s now time to run the installer to create the database tables and configure your new site. The recommended method is to use the command line installer. If you cannot do this for any reason (e.g. on a Windows server) the web based installer is still available.&lt;br /&gt;
&lt;br /&gt;
=== Command line installer ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s best to run the command line as your system&#039;s web user. You need to know what that is - see your system&#039;s documentation (e.g. Ubuntu/Debian is &#039;www-data&#039;, Centos is &#039;apache&#039;)&lt;br /&gt;
&lt;br /&gt;
* Example of using the command-line  (as root - substitute &#039;www-data&#039; for your web user):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chown www-data /path/to/moodle&lt;br /&gt;
# cd /path/to/moodle/admin/cli&lt;br /&gt;
# sudo -u www-data /usr/bin/php install.php&lt;br /&gt;
# chown -R root /path/to/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The chowns allow the script to write a new config.php file. More information about the options can be found using &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# php install.php --help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be asked for other settings that have not been discussed on this page - if unsure just accept the defaults. For a full discussion see [[Administration via command line]]&lt;br /&gt;
&lt;br /&gt;
=== Web based installer ===&lt;br /&gt;
&lt;br /&gt;
For ease of use you can install Moodle via the web. We recommend configuring your web server so that the page is not publicly accessible until the installation is complete.&lt;br /&gt;
&lt;br /&gt;
To run the web installer script, just go to your Moodle&#039;s main URL using a web browser.&lt;br /&gt;
&lt;br /&gt;
The installation process will take you through a number of pages. You should be asked to confirm the copyright, see the database tables being created, supply administrator account details and supply the site details. The database creation can take some time - please be patient. You should eventually end up at the Moodle front page with an invitation to create a new course. &lt;br /&gt;
&lt;br /&gt;
It is very likely that you will be asked to download the new config.php file and upload it to your Moodle installation - just follow the on-screen instructions.&lt;br /&gt;
&lt;br /&gt;
==Final configuration==&lt;br /&gt;
&lt;br /&gt;
=== Settings within Moodle ===&lt;br /&gt;
There are a number of options within the Moodle Site Administration screens (accessible from the &#039;Site administration&#039; tab in the &#039;Administration&#039; block. Here are a few of the more important ones that you will probably want to check:&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Plugins &amp;gt; Message Outputs &amp;gt; Email&#039;&#039;: Set your smtp server and authentication if required (so your Moodle site can send emails). The support contact for your site is also set on this page. &lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; System paths&#039;&#039;: Set the paths to du, dot and aspell binaries.&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; HTTP&#039;&#039;: If you are behind a firewall you may need to set your proxy credentials in the &#039;Web proxy&#039; section.&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Location &amp;gt; Update timezones&#039;&#039;: Run this to make sure your timezone information is up to date. (more info [[Location]])&lt;br /&gt;
** [http://php.net/manual/en/timezones.php Set server&#039;s local timezone] inside &amp;lt;tt&amp;gt;php.ini&amp;lt;/tt&amp;gt; (should probably be inside &amp;lt;tt&amp;gt;/etc/php.ini&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;/etc/php.d/date.ini&amp;lt;/tt&amp;gt;, depending on the underline OS):&lt;br /&gt;
**: &amp;lt;code ini&amp;gt;[Date]&lt;br /&gt;
; Defines the default timezone used by the date functions&lt;br /&gt;
date.timezone = &amp;quot;YOUR LOCAL TIMEZONE&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remaining tasks ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configure Cron&#039;&#039;&#039;: Moodle&#039;s background tasks (e.g. sending out forum emails and performing course backups) are performed by a script which you can set to execute at specific times of the day. This is known as a cron script. Please refer to the [[Cron|Cron instructions]].&lt;br /&gt;
* &#039;&#039;&#039;Set up backups&#039;&#039;&#039;: See [[Site backup]] and [[Automated course backup]].&lt;br /&gt;
* &#039;&#039;&#039;Check mail works&#039;&#039;&#039;: [[Add a new user|Create a test user]] with a valid email address and [[message|send them a message]]. Do they receive an email copy of the message? If not, check the settings in &#039;&#039;Settings &amp;gt; Site administration &amp;gt; Plugins &amp;gt; Message outputs &amp;gt; Email&#039;&#039;. Don&#039;t be tempted to skip this step (clue: email is used to recover lost passwords, including the administrator password when you forget it!)&lt;br /&gt;
* &#039;&#039;&#039;Secure your Moodle site&#039;&#039;&#039;: Read the [[Security recommendations]].&lt;br /&gt;
*&#039;&#039;&#039;Increasing the maximum upload size&#039;&#039;&#039;  See [[Installation FAQ]] Maximum upload file size - how to change it?&lt;br /&gt;
&lt;br /&gt;
=== Installation is complete :) ===&lt;br /&gt;
&lt;br /&gt;
* Create a new course: You can now access Moodle through your web browser (using the same URL as you set during the install process), log in as your admin user and creatse a new course. See  [[Adding a new course|create a new course]].&lt;br /&gt;
&lt;br /&gt;
=== If something goes wrong... ===&lt;br /&gt;
&lt;br /&gt;
Here are some things you should try...&lt;br /&gt;
&lt;br /&gt;
* Check the [[Installation FAQ]]&lt;br /&gt;
* Check your file permissions carefully. Can your web server read (but not write) the Moodle program files? Can your web server read and write your Moodle data directory? If you don&#039;t fully understand how file ownership and permissions work on your operating system it would be time very well spent to find out.&lt;br /&gt;
* Check your database permissions. Have you set up your database user with the correct rights and permissions for your configuration (especially if the web server and database server are different machines)?&lt;br /&gt;
* Create your [[Configuration file]] (config.php) by hand. Copy config-dist.php (in the root of the Moodle program directory) to config.php, edit it and set your database/site options there. Installation will continue from the right place. &lt;br /&gt;
* Once you have a config.php (see previous tip) you can edit it to turn on debugging (in section 8). This may give you extra information to help track down a problem. If you have access, check your web server error log(s).&lt;br /&gt;
* Re-check your php.ini / .htaccess settings. Are they appropriate (e.g. memory_limit), did you edit the correct php.ini / .htaccess file and (if required) did you re-start the web server after making changes?&lt;br /&gt;
* Did you include any non-core (optional) plugins, themes or other code before starting the installation script? If so, remove it and try again (it may be broken or incompatible).&lt;br /&gt;
* Explain your problem in the [http://moodle.org/mod/forum/view.php?id=28 Installation problems forum]. &#039;&#039;&#039;PLEASE&#039;&#039;&#039; list your software versions; explain what you did, what happened and what error messages you saw (if any); explain what you tried. There is no such thing as &#039;nothing&#039;, even a blank page is something!&lt;br /&gt;
&lt;br /&gt;
== Platform specific instructions ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Much of this information is provided by the community. It may not have been checked and may be out of date. Please read in conjunction with the above installation instructions.&lt;br /&gt;
&lt;br /&gt;
* [[Windows installation]]&lt;br /&gt;
** [[Installing Moodle on SmarterASP.NET]]&lt;br /&gt;
* [[Unix or Linux Installation]]&lt;br /&gt;
* [[Mac Installation]]&lt;br /&gt;
* [[Amazon EC2 Cloud Services Installation]]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [http://www.slideshare.net/gb2048/my-own-moodle Slideshare presentation by Gareth Barnard on installing a local installation of Moodle] and accompanying [https://drive.google.com/folderview?id=0B17B0rYH2zERU21sQnVweUZCUFk&amp;amp;usp=sharing  help guides]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=182086 New Video Tutorial- How to Install Moodle on Shared Hosting via cPanel (Not Fantastico)]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=199542 Video Tutorial - Install Moodle on a Virtual Box from scratch] &lt;br /&gt;
&lt;br /&gt;
[[es:Instalaci%C3%B3n_de_moodle]]&lt;br /&gt;
[[de:Installation von Moodle]]&lt;br /&gt;
[[fr:Installation de Moodle]]&lt;br /&gt;
[[ja:Moodleのインストール]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Mathematics&amp;diff=129443</id>
		<title>Mathematics</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Mathematics&amp;diff=129443"/>
		<updated>2017-11-18T09:56:49Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Main page}}&lt;br /&gt;
==NEWS==&lt;br /&gt;
Until there is time to integrate in to the rest of this page, the time has come to note that development of SEE (Super Equation Editor, a nickname for a set of plugins being developed by Mauno that now far outstrips the notion of a &amp;quot;plain old equation editor&amp;quot;) that Colin has created a page to address those tools at [[Advanced_Maths_Tools]] (yes, Maths has an &amp;quot;s&amp;quot; which makes the page arguably undiscoverable by people in the US, but Americans don&#039;t speak English anyway.)&lt;br /&gt;
&lt;br /&gt;
Why is this exciting?  Because so many of the tools you (student, pupil, admin) need are handily packaged up in something that approaches a transparent and universal Mathematics interface. Yes, you can use the editor to create and modify constructions, yes you have graphing calculators, yes you have TeX and asciimathml and mathml and the list goes on and on and on.  BUT, this is not yet a full production package and the docs are &amp;quot;alpha&amp;quot; - Please install and use and report.&lt;br /&gt;
&lt;br /&gt;
==Equation Construction and Display==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Tools===&lt;br /&gt;
There are a variety of tools that are available for the purpose of constructing equations, providing text expressions that can be converted to equations, and displaying equations. &lt;br /&gt;
&lt;br /&gt;
The most common text expression syntax is LaTeX or a derivative with probably the most common form of display being a conversion of the equation to an image file. However, is demonstrated with ASCIIMathML simple text expressions can now be be converted to MathML on the fly.&lt;br /&gt;
&lt;br /&gt;
Some tools for creating and displaying equations on-line that may be of interest to those teaching mathematics are:&lt;br /&gt;
* Moodle offers in core a basic TeX filter and an Algebra filter. These are simple but not simplistic. An overview of using these tools can be found at the [[Using TeX Notation]] pages. Be aware that these packages are subsets of complete TeX packages and the conventions used are designed more for ease of use within Moodle rather than as complete TeX packages. &lt;br /&gt;
* [[ASCIIMathML]],  which both converts equations into MathML on the fly and provides a text expression syntax more easily mastered than Tex, though the filter will convert TeX expressions as well. [http://sourceforge.net/project/showfiles.php?group_id=106148 The ASCIIMathML 2.0.2 zip] provides all the files necessary for setting ASCIIMathML up as  a Moodle filter as well creating run-time graphs with ASCIIsvg. An on-line calculator is also included. Just recently an  ASCIIMathML export format for DragMath was added to version 0.7.2, [https://docs.moodle.org/en/DragMath_equation_editor available here],  so that you have access to both a GUI and text expression syntax for creating and displaying equations. Quick and GIFless. [http://math.chapman.edu/~jipsen/asciencepad/asciencepad.html  ASciencePad is also available] and consists of htmlarea enhanced with the ASCIIMathML functionality. &lt;br /&gt;
* [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=916 Tim Hunt&#039;s Moodle MathTran Module] converts Tex into images on the fly. You can also use  [http://www.mathtran.org/wiki/index.php/TeX_image mathtran_img.js] on a page by page basis.&lt;br /&gt;
* The [[jsMath]] filter, which does a similar job but using [[Javascript]] on the user&#039;s computer&lt;br /&gt;
* [[MathJax_filter]], a next generation for jsMath from David Cervone et al that now includes MathML and web font features: [http://MathJax.org] A discussion regarding deploying the beta release can be found here: [http://moodle.org/mod/forum/discuss.php?d=142785]&lt;br /&gt;
* [[Calculated question type]]&lt;br /&gt;
* [[DragMath equation editor]], a WYSIWYG equation editor that integrates easily with the Moodle HTML editor.&lt;br /&gt;
* [[WIRIS]], is a suite of math and science tools. [http://www.wiris.com/moodle/ www.wiris.com/moodle/]&lt;br /&gt;
** WYSIWYG equation editor with a Javascript interface. Based on MathML.&lt;br /&gt;
** Advanced calculator. Integrals, derivatives, limits, ploting in 2D and 3D,...&lt;br /&gt;
** New question types for math and science topics&lt;br /&gt;
&lt;br /&gt;
* [http://www.dessci.com/en/products/mathtype MathType], a commercial product created by DSI (the folk who also offer MathPlayer, a plugin many IE users employ). Bob Mathews recently posted [http://moodle.org/mod/forum/discuss.php?d=93728&amp;amp;parent=549428] that info on how to use MathType with Moodle can be found at http://www.dessci.com/en/products/mathtype/works_with.htm?target=moodle. Beginning with MathType 6.7, MathType includes a &amp;quot;translator&amp;quot; to convert a MathType equation into the LaTeX code required by the Moodle TeX filter.&lt;br /&gt;
Mathematics teachers may also be interested to follow the work of [http://maths.york.ac.uk York University Maths department], who are working on [http://maths.york.ac.uk/serving_maths/ some projects] to augment Moodle, particularly its [[Quiz module]] for online assessment, for example by integrating a system which is able to mark algebraic and trigonometric answers to open-ended questions.&lt;br /&gt;
&lt;br /&gt;
===Accessibility Display Matrix===&lt;br /&gt;
&lt;br /&gt;
{{Expand-section|date=August 2008}}&lt;br /&gt;
&lt;br /&gt;
■ Feature Key appears below the matrix.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
!width=&amp;quot;12%&amp;quot;|Notation&lt;br /&gt;
!width=&amp;quot;22%&amp;quot;|Tex/LaTex&lt;br /&gt;
!width=&amp;quot;22%&amp;quot;|ASCIIMath&lt;br /&gt;
!width=&amp;quot;22%&amp;quot;|MathML&lt;br /&gt;
!width=&amp;quot;22%&amp;quot;|WIRIS&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|Ease of Use&lt;br /&gt;
|Plain text system. Knowledge of LaTeX notation required. Being a plain text system, LaTeX notation is straightforward to create and edit. &lt;br /&gt;
|Plain text system. Easy to learn. Notation simple. Being a plain text system, ASCIIMath is very easy to create and edit.&lt;br /&gt;
|XML-based. Not easy to create and edit: an editor is required.&lt;br /&gt;
|Visual interface for MathML.&amp;lt;br&amp;gt;Toolbar navigation is accessible.&amp;lt;br&amp;gt;LateX plain text notation is also available.&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|Conversion to Braille&lt;br /&gt;
|Output directly to Braille display via screen reader (fn 2)&lt;br /&gt;
|ASCIIMath notation is converted to MathML or LaTeX. Please refer to those formats for details.&lt;br /&gt;
|Converted to suitable textual format and Brailled using screen reader (fn 3)&lt;br /&gt;
|Image alternative text outputs directly to Braille display via screen reader (fn4)&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|Transmission via TTS&lt;br /&gt;
|Notation spoken &amp;quot;as-is&amp;quot; via screen reader (fn 2)&lt;br /&gt;
|ASCIIMath notation is converted to MathML or LaTeX. Please refer to those formats for details.&lt;br /&gt;
|Converted to suitable textual format and spoken using screen reader. Note that MathPlayer add-on for IE has TTS functionality built-in (fn 3).&lt;br /&gt;
|Image alternative text spoken via screen reader (fn 4)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;fn1&amp;quot;&amp;gt;&#039;&#039;&#039;fn1.&#039;&#039;&#039;&amp;lt;/span&amp;gt;&lt;br /&gt;
MathPlayer claims to do math-to-speech by parsing the MathML, not by parsing TeX. See http://www.dessci.com/en/products/mathplayer/tech/accessibility.htm where it is stated:&lt;br /&gt;
&lt;br /&gt;
All of these examples were written in Microsoft Word and MathType and exported to MathML using MathType’s “MathPage” technology. MathPage technology was added to MathType in version 5.0. No special work is needed to author the expressions to make them accessible. Any product that exports MathML will produce pages that MathPlayer can speak.&lt;br /&gt;
&lt;br /&gt;
For a larger real life example, see this page. Also, MSN Encarta uses MathML on many of their web pages that contain math, so much of their Math should be accessible using MathPlayer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;fn2&amp;quot;&amp;gt;&#039;&#039;&#039;fn2. &#039;&#039;&#039;&amp;lt;/span&amp;gt;&lt;br /&gt;
The alt attribute of the rendered graphic is spoken and/or Braillled. As LaTeX is a plain text notation, the notation can be spoken and Brailled by the screen reader directly. This does, of course, assume an understanding of LaTeX notation on the part of the screen reader user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;fn3&amp;quot;&amp;gt;&#039;&#039;&#039;fn3. &#039;&#039;&#039;&amp;lt;/span&amp;gt;&lt;br /&gt;
In the case of Internet Explorer, screen readers require the MathPlayer plugin to be installed before MathML is rendered (IE does not include native MathML support). By using MSAA, the screen reader can obtain a textual version of the math notation from MathPlayer, which it can then TTS and Braille. Note that MathPlayer also contains built-in TTS functionality (employing MS SAPI) which can be used to speak the math notation without having to employ a screen reader. See [http://www.dessci.com/en/products/mathplayer/tech/accessibility.htm] for further details. At time of writing, screen reader support for Firefox is via MSAA and a special custom, Firefox-specific IAccessible2 interface (to reveal text attributes and character positions). Math notation is spoken via a screen reader which interrogates these interfaces.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;fn1&amp;quot;&amp;gt;&#039;&#039;&#039;fn4.&#039;&#039;&#039;&amp;lt;/span&amp;gt;&lt;br /&gt;
The alt attribute of the rendered image is filled with a textual version of the math notation. Screen readers can read the alternative text without additional plugins.&lt;br /&gt;
&lt;br /&gt;
==Using Java for Curriculum==&lt;br /&gt;
===Java Tools for Building Applets for Interactive Demonstration===&lt;br /&gt;
These tools can be integrated in or used with Moodle Resources&lt;br /&gt;
&lt;br /&gt;
==== Java Sketchpad ====&lt;br /&gt;
http://www.dynamicgeometry.com/JavaSketchpad/About_JavaSketchpad.html, is an applet developed by Key Curriculum Press. The applet has been the focus of quite a bit of discussion and demonstrations and discussions are widely available.  An introductory article from the Journal of Online Mathematics can be found here: http://mathdl.maa.org/mathDL/4/?nodeId=508&amp;amp;pa=content&amp;amp;sa=viewDocument. Usage focuses largely on Geometry&lt;br /&gt;
&lt;br /&gt;
==== CabriJava ====&lt;br /&gt;
http://www-cabri.imag.fr/cabrijava/, an applet offered by the University of Cabri,  also focuses on interactive geometry. Quite a number of examples employing CabriJava can be found here: http://www.mathsnet.net/cabri/index.html.&lt;br /&gt;
&lt;br /&gt;
==== Descartes ==== &lt;br /&gt;
http://descartes.cnice.mec.es/, is an applet developed under the auspices of the Spanish Ministerio de Educacion Politica Social y Diporte.  An English introduction can be found here at http://descartes.cnice.mec.es/ingles/index.html.  The Ministery has produced an extensive Mathematics curriculum using Descartes,  which is available in English and can be freely downloaded and used. Much of what is available is still only in Spanish so anyone interested in doing translation work please post to the Moodle Math Tools forum.&lt;br /&gt;
&lt;br /&gt;
==== Sympl ==== &lt;br /&gt;
http://www.sympl.org/, an open source Java application/applet for creating interactive graphs.&lt;br /&gt;
&lt;br /&gt;
===Additional Curricular Use of Applets===&lt;br /&gt;
*Euclid&#039;s Elements -  http://aleph0.clarku.edu/~djoyce/java/elements/elements.html&lt;br /&gt;
*Tutorials employing applets (applets can be downloaded and used in Moodle) http://www.analyzemath.com/&lt;br /&gt;
*Ultrastudio.org - Applet-capable wiki with over 100 educational applets and explaining articles next to them, best covering mathematics (especially complex plane) but also physics and many other topics. CC-BY-SA texts, most of applets open source - http://ultrastudio.org/#Mathematics.&lt;br /&gt;
&lt;br /&gt;
===Applet Tools===&lt;br /&gt;
*Graphing - http://www.langara.bc.ca/mathstats/resource/GraphExplorer/&lt;br /&gt;
*Geometry Construction - http://www.cs.rice.edu/~jwarren/grace/&lt;br /&gt;
*GeoGebra - http://www.geogebra.org/&lt;br /&gt;
*Physics Applets for Drawing (PAD) - http://www.wku.edu/pads/ These can make interactive activities that can both check for correctness and give guiding feedback. Includes modules for graphs (2D functions), vectors (even in/out and other lines and arrows and bar-graphs), motion analysis, equation recognition and more. Uses don&#039;t have to be just for Physics. Math, of course. VectorPAD can be used for placing markers (as points, lines, small pictures, [http://www.wku.edu/pads/exercise.php?id=mgaazqzoakmqgfrkkmqgaaayo arrows) on a picture], that could be used in almost any subject. They can be incorporating in SCORM packages which can interact with Moodle. There is no Moodle module now (july 2009) for using them directly, but that would add a lot more power (compared to SCORM), like being able to save states, turn on/off feedback, etc.&lt;br /&gt;
*GraphApplet 1.05: both calculator and graphapplet - http://www.lundin.info/graphapplet.aspx&lt;br /&gt;
*Physlets: large suite of applets about physics but includes [http://webphysics.davidson.edu/physletprob/ch16_datagraph/default.html advanced graphing] too. [http://www.tupo.biz/kurser/javaapplets/Fysik/java/Physlets/CFL/3dimDiag.htm A time dependent 3D example (Swedish!)]&lt;br /&gt;
&lt;br /&gt;
===Java Applet Collections===&lt;br /&gt;
* http://cs.jsu.edu/mcis/faculty/leathrum/Mathlets/&lt;br /&gt;
* http://www.walter-fendt.de/m14e/&lt;br /&gt;
&lt;br /&gt;
* Probability and Statistics&lt;br /&gt;
**http://www.mste.uiuc.edu/pavel/java/dilemma/&lt;br /&gt;
**http://lstat.kuleuven.be/java/&lt;br /&gt;
**http://www.math.csusb.edu/faculty/stanton/m262/&lt;br /&gt;
&lt;br /&gt;
*http://www.mste.uiuc.edu/murphy/JavaOverview/default.html&lt;br /&gt;
*Math and Physics - http://www.falstad.com/mathphysics.html&lt;br /&gt;
*Curves - http://www-groups.dcs.st-and.ac.uk/~history/Java/index.html&lt;br /&gt;
*Chaos and Fractals - http://math.bu.edu/DYSYS/applets/index.html&lt;br /&gt;
*For sale, but extensive - http://www.cut-the-knot.org/Curriculum/index.shtml&lt;br /&gt;
&lt;br /&gt;
==Mathematics Assessment==&lt;br /&gt;
&lt;br /&gt;
Assessment is a key driver for mathematics.  There are a number of ways of getting students to answer mathematical questions through Moodle.&lt;br /&gt;
* WebWork, see http://webwork.maa.org/wiki/Main_Page  http://webwork.math.rochester.edu/docs/docs/, and http://webwork.maa.org/moodle/ is an independent web application for assessing student Math progress, and there is a Moodle Module for interfacing WebWork to Moodle that can be found here: http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=332, though the resources on the WeBWork wiki are probably more current as the code  in the Moodle CVS has not been updated for some time.&lt;br /&gt;
* STACK provides very mathematical questions for the Moodle quiz module.  These are supported by the CAS Maxima.  The home page for STACK can be found on http://stack.bham.ac.uk/&lt;br /&gt;
* WIRIS quizzes [http://www.wiris.com/quizzes wiris.com/quizzes]&lt;br /&gt;
**Random variables and graphics&lt;br /&gt;
**Automatic evaluation of open answers&lt;br /&gt;
**Syntax checking of answers&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Mathematics tools FAQ]]&lt;br /&gt;
Using Moodle forum discussions:&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=46009 Best practices for teaching Math(s) in Moodle]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=61993 How do you deal with the challenge of writing equations?]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=62002 How do you deal with the challenge of drawing graphs and diagrams?]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=62014 How do you deal with the challenge of interactive exercises and simulations?]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=95950 How can I have a student enter a fraction as an answer?]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=127867 What are the components of an exemplary high school Moodle course?]&lt;br /&gt;
&lt;br /&gt;
[[Category:Mathematics]]&lt;br /&gt;
[[Category:Teacher]]&lt;br /&gt;
&lt;br /&gt;
[[es:Matemáticas]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Installing_Moodle&amp;diff=128933</id>
		<title>Installing Moodle</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Installing_Moodle&amp;diff=128933"/>
		<updated>2017-10-09T16:08:18Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Download and copy files into place */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Installing Moodle}}&lt;br /&gt;
&#039;&#039;This page explains how to install Moodle. If you are an expert and/or in a hurry try [[Installation Quickstart]].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you just want to try Moodle on a standalone machine there are &#039;one-click&#039; installers for Windows (see [[Complete install packages for Windows]]) and for OSX (see [[Complete Install Packages for Mac OS X]]) or [[ install on OS X]]. These are unsuitable for production servers. &lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Moodle is primarily developed in Linux using [[Apache]], [[PostgreSQL]]/[[MySQL]]/[[MariaDB]] and [[PHP]] (sometimes known as the LAMP platform). Typically this is also how Moodle is run, although there are other options as long as the software requirements of the  [{{Release notes}} release] are met.&lt;br /&gt;
&lt;br /&gt;
If you are installing Moodle in a Windows server, note that from php5.5 onwards, you will also need to have  the Visual C++ Redistributable for Visual Studio 2012 installed from:&lt;br /&gt;
http://www.microsoft.com/en-us/download/details.aspx?id=30679 Visual C++] ( x86 or x64)  &lt;br /&gt;
&lt;br /&gt;
The basic requirements for Moodle are as follows:&lt;br /&gt;
&lt;br /&gt;
=== Hardware === &lt;br /&gt;
* Disk space: 200MB for the Moodle code, plus as much as you need to store content. 5GB is probably a realistic minimum. &lt;br /&gt;
* Processor: 1GHz (min), 2GHz dual core or more recommended.&lt;br /&gt;
* Memory: 512MB (min), 1GB or more is recommended. 8GB plus is likely on a large production server&lt;br /&gt;
* Consider separate servers for the web &amp;quot;front ends&amp;quot; and the database. It is much easier to &amp;quot;tune&amp;quot;&lt;br /&gt;
&lt;br /&gt;
All the above requirements will vary depending on specific hardware and software combinations as well as the type of use and load; busy sites may well require additional resources. Further guidance can be found under [[Performance_recommendations|performance recommendations]]. Moodle scales easily by increasing hardware.&lt;br /&gt;
&lt;br /&gt;
For very large sites, you are much better starting with a small pilot and gaining some experience and insight. A &amp;quot;what hardware do I need for 50,000 user?&amp;quot; style post in the forums is highly unlikely to get a useful answer.&lt;br /&gt;
&lt;br /&gt;
=== Software ===&lt;br /&gt;
&lt;br /&gt;
See the [{{Release notes}} release notes] in the dev docs for software requirements.&lt;br /&gt;
&lt;br /&gt;
== Set up your server ==&lt;br /&gt;
&lt;br /&gt;
Depending the use case a Moodle server may be anything from a Desktop PC (e.g. for testing and evaluating) to a rackmounted or  [[Server cluster|clustered]] solution. As mentioned above there are lots of possibilities for installing the basic server software, some links and pointers are at [[Installing AMP]], [[Internet_Information_Services|IIS]], [[Nginx]]. &lt;br /&gt;
&lt;br /&gt;
It will help hugely, regardless of your deployment choices, if time is taken to understand how to configure the different parts of your software stack (HTTP daemon, database,  PHP etc). Do not expect the standard server configuration to be optimal for Moodle. For example, the web server and database servers will almost certainly require tuning to get the best out of Moodle.&lt;br /&gt;
&lt;br /&gt;
If a hosting provider is being used  ensure that all Moodle [{{Release notes}}#Server_requirements requirments] (such as PHP version) are met by the hosting platform before attempting the installation. It will help to become familiar with changing settings within the hosting provider&#039;s platform (e.g. PHP file upload maximums) as the options and tools provided vary.&lt;br /&gt;
&lt;br /&gt;
== Download and copy files into place ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT: While there are now a number of places you can get the Moodle code (including host provided Moodle installers), you are strongly advised to only obtain Moodle from moodle.org. If you run into problems it will be a great deal easier to support you.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You have two options:&lt;br /&gt;
* Download your required version from http://moodle.org/downloads and unzip/unpack...&lt;br /&gt;
* &#039;&#039;&#039;OR&#039;&#039;&#039; Pull the code from the Git repository (recommended for developers and also makes upgrading very simple):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git clone -b MOODLE_{{Version2}}_STABLE git://git.moodle.org/moodle.git  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other options you might consider:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;--depth=1&#039;&#039;  for shallow cloning (only) latest revision (be advised! If you are a developer, you will not be able to easily make git updates and modification later on when this feature is used) &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;--single-branch&#039;&#039;  to limit cloning to a single branch, this fetches the Moodle {{Version}} Stable branch (latest weekly build). For a fuller discussion see [[Git for Administrators]]. &lt;br /&gt;
&lt;br /&gt;
Either of the above should result in a directory called &#039;&#039;&#039;moodle&#039;&#039;&#039;, containing a number of files and folders. &lt;br /&gt;
&lt;br /&gt;
You can typically place the whole folder in your web server documents directory, in which case the site will be located at &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://yourwebserver.com/moodle&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;, or you can copy all the contents straight into the main web server documents directory, in which case the site will be simply &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://yourwebserver.com&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;. See the documentation for your system and/or web server if you are unsure. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;Tip:&#039;&#039; If you are downloading Moodle to your local computer and then uploading it to your hosted web site, if possible upload the compressed file and decompress at the remote end (check your &#039;file manager&#039;). Failing that, watch FTP progress carefully for errors or missed files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Secure the Moodle files:&#039;&#039;&#039; It is vital that the files are not writeable by the web server user. For example, on Unix/Linux (as root):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chown -R root /path/to/moodle&lt;br /&gt;
# chmod -R 0755 /path/to/moodle&lt;br /&gt;
# find /path/to/moodle -type f -exec chmod 0644 {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(files are owned by the administrator/superuser and are only writeable by them - readable by everyone else)&lt;br /&gt;
&lt;br /&gt;
The third command finds all the regular files and executes the chmod command 0644 on them. &lt;br /&gt;
&lt;br /&gt;
If you want to use the built-in plugin installer you need to make the directory writable by web server user. It is strongly recommended to use ACL when your server supports it, for example if your Apache server uses account www-data: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chmod -R +a &amp;quot;www-data allow read,delete,write,append,file_inherit,directory_inherit&amp;quot; /path/to/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The effect of the previous command is to allow the Apache user account (www-data in this case) to access and change files within the moodle site. Many people would consider this a brave move for a new site admin to implement. In a new moodle you can safely leave this out. A default Ubuntu install does not have the +a option for the chmod command anyway. The +a attribute is an ACL (Access Control List) facility which allows you to set per user access for individual files. For example, OSX has this by default.&lt;br /&gt;
&lt;br /&gt;
== Create an empty database ==&lt;br /&gt;
&lt;br /&gt;
Next create a new, empty database for your installation. You need to find and make a note of following information for use during the final installation stage:&lt;br /&gt;
* &#039;&#039;&#039;dbhost&#039;&#039;&#039; - the database server hostname. Probably &#039;&#039;localhost&#039;&#039; if the database and web server are the same machine, otherwise the name of the database server&lt;br /&gt;
* &#039;&#039;&#039;dbname&#039;&#039;&#039; - the database name. Whatever you called it, e.g. &#039;&#039;moodle&#039;&#039; &lt;br /&gt;
* &#039;&#039;&#039;dbuser&#039;&#039;&#039; - the username for the database. Whatever you assigned, e.g. &#039;&#039;moodleuser&#039;&#039; - do not use the root/superuser account. Create a proper account with the minimum permissions needed.&lt;br /&gt;
* &#039;&#039;&#039;dbpass&#039;&#039;&#039; - the password for the above user&lt;br /&gt;
&lt;br /&gt;
If your site is hosted you should find a web-based administration page for databases as part of the control panel (or ask your administrator). For everyone else or for detailed instructions, see the page for your chosen database server:&lt;br /&gt;
* [[PostgreSQL]] (recommended)&lt;br /&gt;
* [[MariaDB]] (recommended)&lt;br /&gt;
* [[MySQL]]&lt;br /&gt;
* [[MSSQL]]&lt;br /&gt;
* [[Oracle]] (not recommended)&lt;br /&gt;
&lt;br /&gt;
== Create the (&#039;&#039;moodledata&#039;&#039;) data directory  ==&lt;br /&gt;
&lt;br /&gt;
Moodle requires a directory to store all of its files (all your site&#039;s uploaded files, temporary data, cache, session data etc.). The web server needs to be able to write to this directory. On larger systems consider how much free space you are going to use when allocating this directory. &lt;br /&gt;
&lt;br /&gt;
Due to the default way Moodle caches data you may have serious performance issues if you use relatively slow storage (e.g. NFS) for this directory. Read the [[Performance_recommendations]] carefully and consider using (e.g.) redis or memcached for [[Caching]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This directory must &#039;&#039;&#039;NOT&#039;&#039;&#039; be accessible directly via the web. This would be a serious security hole. Do not try to place it inside your web root or inside your Moodle program files directory. Moodle will not install. It can go anywhere else convenient. &lt;br /&gt;
&lt;br /&gt;
Here is an example (Unix/Linux) of creating the directory and setting the permissions for &#039;&#039;&#039;anyone&#039;&#039;&#039; on the server to write here. This is only appropriate for Moodle servers that are not shared. Discuss this with your server administrator for better permissions that just allow the web server user to access these files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# mkdir /path/to/moodledata&lt;br /&gt;
# chmod 0777 /path/to/moodledata&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your server supports ACL it is recommended to set following permissions, for example if your Apache server uses account www-data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chmod -R +a &amp;quot;www-data allow read,delete,write,append,file_inherit,directory_inherit&amp;quot; /path/to/moodledata&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are planning to execute PHP scripts from the command line you should set the same permissions for the current user:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo chmod -R +a &amp;quot;`whoami` allow read,delete,write,append,file_inherit,directory_inherit&amp;quot; /path/to/moodledata&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Securing moodledata in a web directory ====&lt;br /&gt;
&lt;br /&gt;
If you are using a hosted site and you have no option but to place &#039;moodledata&#039; in a web accessible directory. You may be able to secure it by creating an .htaccess file in the &#039;moodledata&#039; directory. This does not work on all systems - see your host/administrator. Create a file called .htaccess containing only the following lines:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
order deny,allow&lt;br /&gt;
deny from all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Start Moodle install ==&lt;br /&gt;
It&#039;s now time to run the installer to create the database tables and configure your new site. The recommended method is to use the command line installer. If you cannot do this for any reason (e.g. on a Windows server) the web based installer is still available.&lt;br /&gt;
&lt;br /&gt;
=== Command line installer ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s best to run the command line as your system&#039;s web user. You need to know what that is - see your system&#039;s documentation (e.g. Ubuntu/Debian is &#039;www-data&#039;, Centos is &#039;apache&#039;)&lt;br /&gt;
&lt;br /&gt;
* Example of using the command-line  (as root - substitute &#039;www-data&#039; for your web user):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chown www-data /path/to/moodle&lt;br /&gt;
# cd /path/to/moodle/admin/cli&lt;br /&gt;
# sudo -u www-data /usr/bin/php install.php&lt;br /&gt;
# chown -R root /path/to/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The chowns allow the script to write a new config.php file. More information about the options can be found using &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# php install.php --help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be asked for other settings that have not been discussed on this page - if unsure just accept the defaults. For a full discussion see [[Administration via command line]]&lt;br /&gt;
&lt;br /&gt;
=== Web based installer ===&lt;br /&gt;
&lt;br /&gt;
For ease of use you can install Moodle via the web. We recommend configuring your web server so that the page is not publicly accessible until the installation is complete.&lt;br /&gt;
&lt;br /&gt;
To run the web installer script, just go to your Moodle&#039;s main URL using a web browser.&lt;br /&gt;
&lt;br /&gt;
The installation process will take you through a number of pages. You should be asked to confirm the copyright, see the database tables being created, supply administrator account details and supply the site details. The database creation can take some time - please be patient. You should eventually end up at the Moodle front page with an invitation to create a new course. &lt;br /&gt;
&lt;br /&gt;
It is very likely that you will be asked to download the new config.php file and upload it to your Moodle installation - just follow the on-screen instructions.&lt;br /&gt;
&lt;br /&gt;
==Final configuration==&lt;br /&gt;
&lt;br /&gt;
=== Settings within Moodle ===&lt;br /&gt;
There are a number of options within the Moodle Site Administration screens (accessible from the &#039;Site administration&#039; tab in the &#039;Administration&#039; block. Here are a few of the more important ones that you will probably want to check:&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Plugins &amp;gt; Message Outputs &amp;gt; Email&#039;&#039;: Set your smtp server and authentication if required (so your Moodle site can send emails). The support contact for your site is also set on this page. &lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; System paths&#039;&#039;: Set the paths to du, dot and aspell binaries.&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; HTTP&#039;&#039;: If you are behind a firewall you may need to set your proxy credentials in the &#039;Web proxy&#039; section.&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Location &amp;gt; Update timezones&#039;&#039;: Run this to make sure your timezone information is up to date. (more info [[Location]])&lt;br /&gt;
** [http://php.net/manual/en/timezones.php Set server&#039;s local timezone] inside &amp;lt;tt&amp;gt;php.ini&amp;lt;/tt&amp;gt; (should probably be inside &amp;lt;tt&amp;gt;/etc/php.ini&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;/etc/php.d/date.ini&amp;lt;/tt&amp;gt;, depending on the underline OS):&lt;br /&gt;
**: &amp;lt;code ini&amp;gt;[Date]&lt;br /&gt;
; Defines the default timezone used by the date functions&lt;br /&gt;
date.timezone = &amp;quot;YOUR LOCAL TIMEZONE&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remaining tasks ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configure Cron&#039;&#039;&#039;: Moodle&#039;s background tasks (e.g. sending out forum emails and performing course backups) are performed by a script which you can set to execute at specific times of the day. This is known as a cron script. Please refer to the [[Cron|Cron instructions]].&lt;br /&gt;
* &#039;&#039;&#039;Set up backups&#039;&#039;&#039;: See [[Site backup]] and [[Automated course backup]].&lt;br /&gt;
* &#039;&#039;&#039;Check mail works&#039;&#039;&#039;: [[Add a new user|Create a test user]] with a valid email address and [[message|send them a message]]. Do they receive an email copy of the message? If not, check the settings in &#039;&#039;Settings &amp;gt; Site administration &amp;gt; Plugins &amp;gt; Message outputs &amp;gt; Email&#039;&#039;. Don&#039;t be tempted to skip this step (clue: email is used to recover lost passwords, including the administrator password when you forget it!)&lt;br /&gt;
* &#039;&#039;&#039;Secure your Moodle site&#039;&#039;&#039;: Read the [[Security recommendations]].&lt;br /&gt;
*&#039;&#039;&#039;Increasing the maximum upload size&#039;&#039;&#039;  See [[Installation FAQ]] Maximum upload file size - how to change it?&lt;br /&gt;
&lt;br /&gt;
=== Installation is complete :) ===&lt;br /&gt;
&lt;br /&gt;
* Create a new course: You can now access Moodle through your web browser (using the same URL as you set during the install process), log in as your admin user and creatse a new course. See  [[Adding a new course|create a new course]].&lt;br /&gt;
&lt;br /&gt;
=== If something goes wrong... ===&lt;br /&gt;
&lt;br /&gt;
Here are some things you should try...&lt;br /&gt;
&lt;br /&gt;
* Check the [[Installation FAQ]]&lt;br /&gt;
* Check your file permissions carefully. Can your web server read (but not write) the Moodle program files? Can your web server read and write your Moodle data directory? If you don&#039;t fully understand how file ownership and permissions work on your operating system it would be time very well spent to find out.&lt;br /&gt;
* Check your database permissions. Have you set up your database user with the correct rights and permissions for your configuration (especially if the web server and database server are different machines)?&lt;br /&gt;
* Create your [[Configuration file]] (config.php) by hand. Copy config-dist.php (in the root of the Moodle program directory) to config.php, edit it and set your database/site options there. Installation will continue from the right place. &lt;br /&gt;
* Once you have a config.php (see previous tip) you can edit it to turn on debugging (in section 8). This may give you extra information to help track down a problem. If you have access, check your web server error log(s).&lt;br /&gt;
* Re-check your php.ini / .htaccess settings. Are they appropriate (e.g. memory_limit), did you edit the correct php.ini / .htaccess file and (if required) did you re-start the web server after making changes?&lt;br /&gt;
* Did you include any non-core (optional) plugins, themes or other code before starting the installation script? If so, remove it and try again (it may be broken or incompatible).&lt;br /&gt;
* Explain your problem in the [http://moodle.org/mod/forum/view.php?id=28 Installation problems forum]. &#039;&#039;&#039;PLEASE&#039;&#039;&#039; list your software versions; explain what you did, what happened and what error messages you saw (if any); explain what you tried. There is no such thing as &#039;nothing&#039;, even a blank page is something!&lt;br /&gt;
&lt;br /&gt;
== Platform specific instructions ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Much of this information is provided by the community. It may not have been checked and may be out of date. Please read in conjunction with the above installation instructions.&lt;br /&gt;
&lt;br /&gt;
* [[Windows installation]]&lt;br /&gt;
** [[Installing Moodle on SmarterASP.NET]]&lt;br /&gt;
* [[Unix or Linux Installation]]&lt;br /&gt;
* [[Mac Installation]]&lt;br /&gt;
* [[Amazon EC2 Cloud Services Installation]]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [http://www.slideshare.net/gb2048/my-own-moodle Slideshare presentation by Gareth Barnard on installing a local installation of Moodle] and accompanying [https://drive.google.com/folderview?id=0B17B0rYH2zERU21sQnVweUZCUFk&amp;amp;usp=sharing  help guides]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=182086 New Video Tutorial- How to Install Moodle on Shared Hosting via cPanel (Not Fantastico)]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=199542 Video Tutorial - Install Moodle on a Virtual Box from scratch] &lt;br /&gt;
&lt;br /&gt;
[[es:Instalaci%C3%B3n_de_moodle]]&lt;br /&gt;
[[de:Installation von Moodle]]&lt;br /&gt;
[[fr:Installation de Moodle]]&lt;br /&gt;
[[ja:Moodleのインストール]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=128904</id>
		<title>ad-hoc contributed reports</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=128904"/>
		<updated>2017-10-01T16:13:49Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* Quiz Usage in Courses by Date */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Sitewide reports}}&lt;br /&gt;
==User and Role Report==&lt;br /&gt;
&lt;br /&gt;
===Count number of distinct learners and teachers enrolled per category (including all its sub categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;SELECT COUNT(DISTINCT lra.userid) AS learners, COUNT(DISTINCT tra.userid) as teachers&lt;br /&gt;
FROM prefix_course AS c #, mdl_course_categories AS cats&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments  AS lra ON lra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role_assignments  AS tra ON tra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category = cats.id&lt;br /&gt;
AND (&lt;br /&gt;
	cats.path LIKE &#039;%/CATEGORYID/%&#039; #Replace CATEGORYID with the category id you want to count (eg: 80)&lt;br /&gt;
	OR cats.path LIKE &#039;%/CATEGORYID&#039;&lt;br /&gt;
	)&lt;br /&gt;
AND lra.roleid=5&lt;br /&gt;
AND tra.roleid=3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each ROLE (TEACHER, NON-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT r.name, l.action, COUNT( l.userid ) AS counter&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_role AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE ra.roleid IN ( 3, 4, 5 ) &lt;br /&gt;
GROUP BY roleid, l.action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student (user) COUNT in each Course===&lt;br /&gt;
Including (optional) filter by: year (if included in course fullname).&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/index.php?contextid=&#039;,context.id,&#039;&amp;quot;&amp;gt;Show users&amp;lt;/a&amp;gt;&#039;) AS Users&lt;br /&gt;
, COUNT(course.id) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS asg&lt;br /&gt;
JOIN prefix_context AS context ON asg.contextid = context.id AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_user AS user ON user.id = asg.userid&lt;br /&gt;
JOIN prefix_course AS course ON context.instanceid = course.id&lt;br /&gt;
WHERE asg.roleid = 5 &lt;br /&gt;
# AND course.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
GROUP BY course.id&lt;br /&gt;
ORDER BY COUNT(course.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enrolment count in each Course ===&lt;br /&gt;
&lt;br /&gt;
Shows the total number of enroled users of all roles in each course. Sorted by course name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname, COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LIST of all site USERS by COURSE enrollment (Moodle 2.x)===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) as Role&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) as RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course as course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enrolled users,which did not login into the Course, even once (Moodle 2)===&lt;br /&gt;
Designed forMoodle 2 table structure and uses special plugin filter : %%FILTER_SEARCHTEXT:table.field%%&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id as ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
user2.idnumber AS IDNumber,&lt;br /&gt;
user2.phone1 AS Phone,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
&lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id and courseid=c.id) as CourseLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id and e.courseid = c.id) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments as ue&lt;br /&gt;
JOIN prefix_enrol as e on e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user as user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess as ul on ul.userid = user2.id&lt;br /&gt;
WHERE c.id=16 AND ul.timeaccess IS NULL&lt;br /&gt;
%%FILTER_SEARCHTEXT:user2.firstname%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Role assignments on categories===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS category,&lt;br /&gt;
cc.depth, cc.path, r.name AS role,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php?id=&#039;,usr.id,&#039;&amp;quot;&amp;gt;&#039;,usr.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS name,&lt;br /&gt;
usr.firstname, usr.username, usr.email&lt;br /&gt;
FROM prefix_course_categories cc&lt;br /&gt;
INNER JOIN prefix_context cx ON cc.id = cx.instanceid&lt;br /&gt;
AND cx.contextlevel = &#039;40&#039;&lt;br /&gt;
INNER JOIN prefix_role_assignments ra ON cx.id = ra.contextid&lt;br /&gt;
INNER JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
INNER JOIN prefix_user usr ON ra.userid = usr.id&lt;br /&gt;
ORDER BY cc.depth, cc.path, usr.lastname, usr.firstname, r.name, cc.name&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Permissions Overides on Categories===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712834 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT rc.id, ct.instanceid, ccat.name, rc.roleid, rc.capability, rc.permission, &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( rc.timemodified ) , &#039;%Y-%m-%d&#039; ) AS timemodified, rc.modifierid, ct.instanceid, ct.path, ct.depth&lt;br /&gt;
FROM `prefix_role_capabilities` AS rc&lt;br /&gt;
INNER JOIN `prefix_context` AS ct ON rc.contextid = ct.id&lt;br /&gt;
INNER JOIN `prefix_course_categories` AS ccat ON ccat.id = ct.instanceid&lt;br /&gt;
AND `contextlevel` =40&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;Totally Opened Courses&amp;quot; (visible, opened to guests, with no password)===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712837 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Course&#039;,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/enrol/instances.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Méthodes inscription&amp;lt;/a&amp;gt;&#039;) AS &#039;Enrollment plugins&#039;,&lt;br /&gt;
e.sortorder&lt;br /&gt;
FROM prefix_enrol AS e, prefix_course AS c&lt;br /&gt;
WHERE e.enrol=&#039;guest&#039; AND e.status=0 AND e.password=&#039;&#039; AND c.id=e.courseid AND c.visible=1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;loggedin users&amp;quot; from the last 120 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id,username,FROM_UNIXTIME(`lastlogin`) as days &lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;and user count for that same population:&#039;&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(id) as Users  FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists the users who have only logged into the site once===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, username, firstname, lastname, idnumber&lt;br /&gt;
FROM prefix_user&lt;br /&gt;
WHERE prefix_user.deleted = 0&lt;br /&gt;
AND prefix_user.lastlogin = 0 &lt;br /&gt;
AND prefix_user.lastaccess &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Students in all courses of some institute===&lt;br /&gt;
What is the status (deleted or not) of all Students (roleid = 5) in all courses of some Institute&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname, u.firstname, u.lastname, u.deleted&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND u.institution = &#039;please enter school name here&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Full User info (for deleted users)===&lt;br /&gt;
Including extra custom profile fields (from prefix_user_info_data)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT * &lt;br /&gt;
FROM prefix_user as u &lt;br /&gt;
JOIN prefix_user_info_data as uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_user_info_field as uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;class&#039;)&lt;br /&gt;
WHERE `deleted` = &amp;quot;1&amp;quot; and `institution`=&amp;quot;your school name&amp;quot; and `department` = &amp;quot;your department&amp;quot; and `data` = &amp;quot;class level and number&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User&#039;s courses===&lt;br /&gt;
change &amp;quot;u.id = 2&amp;quot; with a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, c.id, c.fullname&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE u.id = 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Users with extra info (email) in current course===&lt;br /&gt;
blocks/configurable_reports replaces %%COURSEID%% with course id.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, u.email&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Special Roles===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.roleid,r.name&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,ra.userid,&#039;&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Username&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON (ctx.id = ra.contextid AND ctx.contextlevel = 50)&lt;br /&gt;
JOIN prefix_course AS c ON ctx.instanceid = c.id&lt;br /&gt;
WHERE ra.roleid &amp;gt; 6&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses without Teachers===&lt;br /&gt;
Actually, shows the number of Teachers in a course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Teachers&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
ORDER BY Teachers ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of users who have been enrolled for more than 4 weeks===&lt;br /&gt;
For Moodle 2.2 , by  Isuru Madushanka Weerarathna &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT uenr.userid As User, IF(enr.courseid=uenr.courseid ,&#039;Y&#039;,&#039;N&#039;) As Enrolled, &lt;br /&gt;
IF(DATEDIFF(NOW(), FROM_UNIXTIME(uenr.timecreated))&amp;gt;=28,&#039;Y&#039;,&#039;N&#039;) As EnrolledMoreThan4Weeks&lt;br /&gt;
FROM prefix_enrol As enr, prefix_user_enrolments AS uenr&lt;br /&gt;
WHERE enr.id = uenr.enrolid AND enr.status = uenr.status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with language===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
This will show you the language setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, lang from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools.&lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;en&#039; to &#039;en_us&#039; for all users:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To do this for only users who have a particular country set, use this as an example:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE country = &#039;US&#039; AND lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with Authentication ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Sometimes you need to do mass changes of authentication methods. A common case is changing default manual to LDAP. &lt;br /&gt;
&lt;br /&gt;
This will show you the Authentication setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, auth from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools. &lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;manual&#039; to &#039;ldap&#039; 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.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET auth = &#039;ldap&#039; WHERE auth = &#039;manual&#039; AND id &amp;gt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compare role capability and permissions ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT mrc.capability &lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;1&#039; AND rc.contextid = &#039;1&#039;) AS Manager&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;2&#039; AND rc.contextid = &#039;1&#039;) AS CourseCreator&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;3&#039; AND rc.contextid = &#039;1&#039;) AS Teacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;4&#039; AND rc.contextid = &#039;1&#039;) AS AssistantTeacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;5&#039; AND rc.contextid = &#039;1&#039;) AS Student&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;6&#039; AND rc.contextid = &#039;1&#039;) AS Guest&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_role_capabilities` AS mrc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User&#039;s accumulative time spent in course ===&lt;br /&gt;
A sum up of the time delta between logstore_standard_log user&#039;s records, considering the a 2 hour session limit.&lt;br /&gt;
&lt;br /&gt;
Uses: current user&#039;s id %%USERID%% and current course&#039;s id %%COURSEID%%  &lt;br /&gt;
&lt;br /&gt;
And also using a date filter (which can be ignored)  &lt;br /&gt;
&lt;br /&gt;
The extra &amp;quot;User&amp;quot; field is used as a dummy field for the Line chart Series field, in which I use X=id, Series=Type, Y=delta.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
l.id, &lt;br /&gt;
l.timecreated, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(l.timecreated),&#039;%d-%m-%Y&#039;) AS dTime,&lt;br /&gt;
@prevtime := (SELECT max(timecreated) FROM mdl_logstore_standard_log &lt;br /&gt;
		WHERE userid = %%USERID%% and id &amp;lt; l.id ORDER BY id ASC LIMIT 1) AS prev_time,&lt;br /&gt;
IF (l.timecreated - @prevtime &amp;lt; 7200, @delta := @delta + (l.timecreated-@prevtime),0) AS sumtime,&lt;br /&gt;
l.timecreated-@prevtime AS delta,&lt;br /&gt;
&amp;quot;User&amp;quot; as type&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log as l, &lt;br /&gt;
(SELECT @delta := 0) AS s_init &lt;br /&gt;
# Change UserID&lt;br /&gt;
WHERE l.userid = %%USERID%% AND l.courseid = %%COURSEID%%&lt;br /&gt;
%%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Log Activity Reports==&lt;br /&gt;
===Count all Active Users by ROLE in a course category (including all of its sub-categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT l.userid) as active&lt;br /&gt;
FROM mdl_course as c&lt;br /&gt;
JOIN mdl_context AS ctx ON  ctx.instanceid=c.id&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN mdl_user_lastaccess as l ON ra.userid = l.userid&lt;br /&gt;
JOIN mdl_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category=cats.id AND (&lt;br /&gt;
	cats.path LIKE &#039;%/80/%&#039;&lt;br /&gt;
	OR cats.path LIKE &#039;%/80&#039;&lt;br /&gt;
) &lt;br /&gt;
AND ra.roleid=3  AND ctx.contextlevel=50  #ra.roleid= TEACHER 3, NON-EDITING TEACHER 4, STUDENT 5&lt;br /&gt;
AND  l.timeaccess &amp;gt; (unix_timestamp() - ((60*60*24)*NO_OF_DAYS)) #NO_OF_DAYS change to number&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Detailed &amp;quot;VIEW&amp;quot; ACTION for each ROLE (TEACHER,NONE-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT l.action, count( l.userid ) as counter , r.name&lt;br /&gt;
FROM `prefix_log` as l&lt;br /&gt;
JOIN `prefix_role_assignments` AS ra on l.userid = ra.userid&lt;br /&gt;
JOIN `prefix_role` AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE (ra.roleid IN (3,4,5)) AND (l.action LIKE &#039;%view%&#039; )&lt;br /&gt;
GROUP BY roleid,l.action&lt;br /&gt;
order by r.name,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total Activity of Roles:&amp;quot;Teacher&amp;quot; and &amp;quot;None-Editing Teacher&amp;quot; by Dates and by Hours===&lt;br /&gt;
The output columns of this report table can be used as base for a Pivot-Table&lt;br /&gt;
which will show the amount of &#039;&#039;&#039;activity&#039;&#039;&#039; per &#039;&#039;&#039;hour&#039;&#039;&#039; per &#039;&#039;&#039;days&#039;&#039;&#039; in 3D graph view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%Y-%m-%d&#039; ) AS grptimed ,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%k&#039; ) AS grptimeh  , count( l.userid ) AS counter &lt;br /&gt;
FROM `prefix_log` AS l&lt;br /&gt;
JOIN prefix_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
WHERE ra.roleid IN (3,4)&lt;br /&gt;
GROUP BY grptimed,grptimeh&lt;br /&gt;
ORDER BY grptimed,grptimeh&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many LOGINs per user and user&#039;s Activity===&lt;br /&gt;
+ link username to a user activity graph report&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,u.id,&#039;&amp;amp;mode=alllogs&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) as Username&lt;br /&gt;
,count(*) as logins&lt;br /&gt;
,(SELECT count(*) FROM prefix_log WHERE userid = l.userid GROUP BY userid) as Activity &lt;br /&gt;
FROM prefix_log as l JOIN prefix_user as u ON l.userid = u.id &lt;br /&gt;
WHERE `action` LIKE &#039;%login%&#039; group by userid&lt;br /&gt;
ORDER BY Activity DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Distinct user logins per month===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
The following will show you the months of the current calendar year with the total number of distinct, unique user logins per month. Change the year in the WHERE clause to the year you need.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
 COUNT(DISTINCT l.userid) AS &#039;DistinctUserLogins&#039;, &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%M&#039;) AS &#039;Month&#039;&lt;br /&gt;
FROM prefix_logstore_standard_log l&lt;br /&gt;
WHERE l.action = &#039;loggedin&#039; AND YEAR(FROM_UNIXTIME(l.timecreated)) = &#039;2017&#039; &lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(l.timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total activity per course, per unique user on the last 24h===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    COUNT(DISTINCT userid) AS countUsers&lt;br /&gt;
  , COUNT(l.courseid) AS countVisits&lt;br /&gt;
  , CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
  JOIN mdl_course AS c ON c.id = l.courseid&lt;br /&gt;
WHERE l.courseid &amp;gt; 0&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 1 DAY)&lt;br /&gt;
      AND c.fullname LIKE &#039;%תשעו%&#039;&lt;br /&gt;
GROUP BY l.courseid&lt;br /&gt;
ORDER BY countVisits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Instructor Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of instructors in all courses per week of a term, including pre-term and post-term edits. An edit is defined as a change to the course, such as a discussion post, the grading of an assignment, or the uploading of file attachments, as well as alterations to course content.&lt;br /&gt;
&lt;br /&gt;
* To specify a subject and/or course number, use % as a wildcard, e.g. ARTS% or ARTS501%&lt;br /&gt;
* To match part of a last name, use %, e.g. Smi% will match &amp;quot;Smith&amp;quot;, &amp;quot;Smile&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
At our institution, we include filters on the course name or category to constrain by terms. These are very specific to how course names and categories are constructed at our institution, so I&#039;ve removed those elements from this code. Also, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; lines for longer terms, or remove lines for shorter terms.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version uses legacy (pre-2.7) logs. See below for post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, c.startdate AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time)) - WEEK(FROM_UNIXTIME(c.startdate))&amp;lt;0,1,0)) AS BeforeTerm&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=0,1,0)) AS Week1&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=1,1,0)) AS Week2&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=2,1,0)) AS Week3&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=3,1,0)) AS Week4&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=4,1,0)) AS Week5&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=5,1,0)) AS Week6&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=6,1,0)) AS Week7&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=7,1,0)) AS Week8&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=8,1,0)) AS Week9&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=9,1,0)) AS Week10&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=10,1,0)) AS Week11&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=11,1,0)) AS Week12&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))&amp;gt;=12,1,0)) AS AfterTerm&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE :course&lt;br /&gt;
AND u.lastname LIKE :last_name&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 log version:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(DISTINCT l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
AND cc.idnumber LIKE &#039;%current%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
#HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY RIGHT(c.shortname,2), c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Student Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of students in the current course by week, including pre-term and post-term edits. An 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 (if permitted).&lt;br /&gt;
&lt;br /&gt;
Links to three other reports are also provided:&lt;br /&gt;
&lt;br /&gt;
* Logs: complete log entries for the student in the course, organized by date&lt;br /&gt;
* Activity Outline: the &amp;quot;Outline Report&amp;quot; from the User Activity Reports, summarizing the student&#039;s activity in the course, organized by course content&lt;br /&gt;
* Consolidated Activity Report: the &amp;quot;Complete Report&amp;quot; from the User Activity Reports, detailing the student&#039;s activity in the course, organized by course content (includes text of forum posts)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). At our institution, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for a post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF((l.time-c.startdate)/7&amp;lt;0,1,0)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=0,1,0)) AS &#039;Week 1&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=1,1,0)) AS &#039;Week 2&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=2,1,0)) AS &#039;Week 3&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=3,1,0)) AS &#039;Week 4&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=4,1,0)) AS &#039;Week 5&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=5,1,0)) AS &#039;Week 6&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=6,1,0)) AS &#039;Week 7&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=7,1,0)) AS &#039;Week 8&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=8,1,0)) AS &#039;Week 9&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=9,1,0)) AS &#039;Week 10&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=10,1,0)) AS &#039;Week 11&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=11,1,0)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))&amp;gt;=15,1,0)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 (Standard Logs) version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
# Our institution stores academic advisor names and emails in custom profile fields&lt;br /&gt;
#, CONCAT(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,uce.data,&#039;&amp;quot;&amp;gt;&#039;,uid.data, &#039;&amp;lt;/a&amp;gt;&#039;)  AS &#039;Academic Advisor&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,&#039;Posts&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Posts&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# student academic coach - you can include custom profile field data with these methods&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uid ON u.id = uid.userid AND uid.fieldid = &#039;2&#039;&lt;br /&gt;
# student academic coach email&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uce on u.id = uce.userid AND uce.fieldid = &#039;6&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===My Weekly Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of the &#039;&#039;&#039;current user&#039;&#039;&#039; in the &#039;&#039;&#039;current course&#039;&#039;&#039; 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).&lt;br /&gt;
&lt;br /&gt;
This report uses Standard Logs (post 2.7).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
l.component AS &#039;activity&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS &#039;Total&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE 1&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
AND u.id = %%USERID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY l.component&lt;br /&gt;
&lt;br /&gt;
ORDER BY l.component&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Faculty/Student Interactions===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Returns a count of instructor and other-student responses to student activity for the specified time period. This report can help indicate whether students&#039; comments are being responded to, as well as summarizing post activity by students during the specified time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for the post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This report can take a long time to run. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
LEFT JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
# We care about messages that involve both the instructor and students of this course&lt;br /&gt;
# messages from instructor to students:&lt;br /&gt;
# LEFT JOIN prefix_message AS mts ON mts.useridfrom = instr.id AND mts.useridto = allstu.id&lt;br /&gt;
# LEFT JOIN prefix_message AS mfs ON mfs.useridfrom = instr.id AND mfs.useridto = allstu.id&lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 Standard Logs version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
 JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student Resource Usage===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Standard Logs&amp;quot; from Moodle 2.7+.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
, m.name AS &#039;item type&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&lt;br /&gt;
COALESCE(a.name, &#039;&#039;), &lt;br /&gt;
COALESCE(b.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cert.name,&#039;&#039;), &lt;br /&gt;
COALESCE(chat.name,&#039;&#039;), &lt;br /&gt;
COALESCE(choice.name,&#039;&#039;), &lt;br /&gt;
COALESCE(data.name,&#039;&#039;), &lt;br /&gt;
COALESCE(feedback.name,&#039;&#039;), &lt;br /&gt;
COALESCE(folder.name,&#039;&#039;), &lt;br /&gt;
COALESCE(forum.name,&#039;&#039;), &lt;br /&gt;
COALESCE(glossary.name,&#039;&#039;), &lt;br /&gt;
COALESCE(imscp.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lesson.name,&#039;&#039;), &lt;br /&gt;
COALESCE(p.name,&#039;&#039;),&lt;br /&gt;
COALESCE(questionnaire.name,&#039;&#039;), &lt;br /&gt;
COALESCE(quiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cr.name,&#039;&#039;), &lt;br /&gt;
COALESCE(scorm.name,&#039;&#039;), &lt;br /&gt;
COALESCE(survey.name,&#039;&#039;), &lt;br /&gt;
COALESCE(url.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(workshop.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kalvidassign.name,&#039;&#039;), &lt;br /&gt;
COALESCE(attendance.name,&#039;&#039;), &lt;br /&gt;
COALESCE(checklist.name,&#039;&#039;), &lt;br /&gt;
COALESCE(flashcard.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lti.name,&#039;&#039;), &lt;br /&gt;
COALESCE(oublog.name,&#039;&#039;), &lt;br /&gt;
COALESCE(ouwiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(subpage.name,&#039;&#039;), &lt;br /&gt;
COALESCE(journal.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lightboxgallery.name,&#039;&#039;), &lt;br /&gt;
COALESCE(elluminate.name,&#039;&#039;), &lt;br /&gt;
COALESCE(adaptivequiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(hotpot.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiziq.name,&#039;&#039;), &lt;br /&gt;
COALESCE(turnitintooltwo.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kvr.name,&#039;&#039;)&lt;br /&gt;
) AS &#039;item name&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;r&#039;),1,0)) AS &#039;total views&#039;&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),1,0)) AS &#039;total submissions&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;r&#039;),u.id,NULL)) AS &#039;count of students who viewed&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),u.id,NULL)) AS &#039;count of students who submitted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 #AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module AND m.name NOT LIKE &#039;label&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON a.id = cm.instance AND m.name = &#039;assign&#039;&lt;br /&gt;
LEFT JOIN prefix_book AS b ON b.id = cm.instance AND m.name = &#039;book&#039;&lt;br /&gt;
LEFT JOIN prefix_certificate AS cert ON cert.id = cm.instance AND m.name = &#039;certificate&#039;&lt;br /&gt;
LEFT JOIN prefix_chat AS chat ON chat.id = cm.instance AND m.name = &#039;chat&#039;&lt;br /&gt;
LEFT JOIN prefix_choice AS choice ON choice.id = cm.instance AND m.name = &#039;choice&#039;&lt;br /&gt;
LEFT JOIN prefix_data AS data ON data.id = cm.instance AND m.name = &#039;data&#039;&lt;br /&gt;
LEFT JOIN prefix_feedback AS feedback ON feedback.id = cm.instance AND m.name = &#039;feedback&#039;&lt;br /&gt;
LEFT JOIN prefix_folder AS folder ON folder.id = cm.instance AND m.name = &#039;folder&#039;&lt;br /&gt;
LEFT JOIN prefix_forum AS forum ON forum.id = cm.instance AND m.name = &#039;forum&#039;&lt;br /&gt;
LEFT JOIN prefix_glossary AS glossary ON glossary.id = cm.instance AND m.name = &#039;glossary&#039;&lt;br /&gt;
LEFT JOIN prefix_imscp AS imscp ON imscp.id = cm.instance AND m.name = &#039;imscp&#039;&lt;br /&gt;
LEFT JOIN prefix_lesson AS lesson ON lesson.id = cm.instance AND m.name = &#039;lesson&#039;&lt;br /&gt;
LEFT JOIN prefix_page AS p ON p.id = cm.instance AND m.name = &#039;page&#039;&lt;br /&gt;
LEFT JOIN prefix_questionnaire AS questionnaire ON questionnaire.id = cm.instance AND m.name = &#039;questionnaire&#039;&lt;br /&gt;
LEFT JOIN prefix_quiz AS quiz ON quiz.id = cm.instance AND m.name = &#039;quiz&#039;&lt;br /&gt;
LEFT JOIN prefix_resource AS cr ON cr.id = cm.instance AND m.name = &#039;resource&#039;&lt;br /&gt;
LEFT JOIN prefix_scorm AS scorm ON scorm.id = cm.instance AND m.name = &#039;scorm&#039;&lt;br /&gt;
LEFT JOIN prefix_survey AS survey ON survey.id = cm.instance AND m.name = &#039;survey&#039;&lt;br /&gt;
LEFT JOIN prefix_url AS url ON url.id = cm.instance AND m.name = &#039;url&#039;&lt;br /&gt;
LEFT JOIN prefix_wiki AS wiki ON wiki.id = cm.instance AND m.name = &#039;wiki&#039;&lt;br /&gt;
LEFT JOIN prefix_workshop AS workshop ON workshop.id = cm.instance AND m.name = &#039;workshop&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidassign AS kalvidassign ON kalvidassign.id = cm.instance AND m.name = &#039;kalvidassign&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidres AS kvr ON kvr.id = cm.instance AND m.name = &#039;kalvidres&#039;&lt;br /&gt;
LEFT JOIN prefix_attendance AS attendance ON attendance.id = cm.instance AND m.name = &#039;attendance&#039;&lt;br /&gt;
LEFT JOIN prefix_checklist AS checklist ON checklist.id = cm.instance AND m.name = &#039;checklist&#039;&lt;br /&gt;
LEFT JOIN prefix_flashcard AS flashcard ON flashcard.id = cm.instance AND m.name = &#039;flashcard&#039;&lt;br /&gt;
LEFT JOIN prefix_lti AS lti ON lti.id = cm.instance AND m.name = &#039;lti&#039;&lt;br /&gt;
LEFT JOIN prefix_oublog AS oublog ON oublog.id = cm.instance AND m.name = &#039;oublog&#039;&lt;br /&gt;
LEFT JOIN prefix_ouwiki AS ouwiki ON ouwiki.id = cm.instance AND m.name = &#039;ouwiki&#039;&lt;br /&gt;
LEFT JOIN prefix_subpage AS subpage ON subpage.id = cm.instance AND m.name = &#039;subpage&#039;&lt;br /&gt;
LEFT JOIN prefix_journal AS journal ON journal.id = cm.instance AND m.name = &#039;journal&#039;&lt;br /&gt;
LEFT JOIN prefix_lightboxgallery AS lightboxgallery ON lightboxgallery.id = cm.instance AND m.name = &#039;lightboxgallery&#039;&lt;br /&gt;
LEFT JOIN prefix_elluminate AS elluminate ON elluminate.id = cm.instance AND m.name = &#039;elluminate&#039;&lt;br /&gt;
LEFT JOIN prefix_adaptivequiz AS adaptivequiz ON adaptivequiz.id = cm.instance AND m.name = &#039;adaptivequiz&#039;&lt;br /&gt;
LEFT JOIN prefix_hotpot AS hotpot ON hotpot.id = cm.instance AND m.name = &#039;hotpot&#039;&lt;br /&gt;
LEFT JOIN prefix_wiziq AS wiziq ON wiziq.id = cm.instance AND m.name = &#039;wiziq&#039;&lt;br /&gt;
LEFT JOIN prefix_turnitintooltwo AS turnitintooltwo ON turnitintooltwo.id = cm.instance AND m.name = &#039;turnitintooltwo&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cm.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Hits) between dates===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module, COUNT( * ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME( l.`time` ) BETWEEN  &#039;2012-10-01 00:00:00&#039; AND  &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
GROUP BY module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Instances and Hits) for each academic year===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2010-10-01 00:00:00&#039; AND &#039;2011-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2010-10-01 00:00:00&#039; AND &#039;2011-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2011-10-01 00:00:00&#039; AND &#039;2012-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2011&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2011-10-01 00:00:00&#039; AND &#039;2012-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2011&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2012-10-01 00:00:00&#039; AND &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2012&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2012-10-01 00:00:00&#039; AND &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2012&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_modules AS m&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Unique user sessions per day and month + graph===&lt;br /&gt;
The &amp;quot;graph&amp;quot; column is used when displaying a graph (which needs at least three columns to pick from)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT userid) AS &amp;quot;Unique User Logins&amp;quot;&lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y /%m / %d&amp;quot;) AS &amp;quot;Year / Month / Day&amp;quot;, &amp;quot;Graph&amp;quot; &lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE action LIKE &#039;loggedin&#039;&lt;br /&gt;
#AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) # optional start date&lt;br /&gt;
#AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:00&#039;) # optional end date&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And...&lt;br /&gt;
&lt;br /&gt;
Counting user&#039;s global and unique hits per day + counting individual usage of specific activities and resources (on that day),&lt;br /&gt;
&lt;br /&gt;
And since I am using phpMyAdmin&#039;s &amp;quot;Display Graph&amp;quot; feature (at the bottom of the query&#039;s output page), I have scaled down the &amp;quot;User Hits&amp;quot; by 10 to fit the graph. that&#039;s it.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y-%m-%d&amp;quot;) AS &amp;quot;Datez&amp;quot;&lt;br /&gt;
,COUNT(DISTINCT userid) AS &amp;quot;Unique Users&amp;quot;&lt;br /&gt;
,ROUND(COUNT(*)/10) &amp;quot;User Hits (K)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_quiz&#039;,1,0)) &amp;quot;Quizzes&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_forum&#039; or component=&#039;mod_forumng&#039;,1,0)) &amp;quot;Forums&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_assign&#039;,1,0)) &amp;quot;Assignments&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_oublog&#039;,1,0)) &amp;quot;Blogs&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_resource&#039;,1,0)) &amp;quot;Files (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_url&#039;,1,0)) &amp;quot;Links (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_page&#039;,1,0)) &amp;quot;Pages (Resource)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE 1=1&lt;br /&gt;
AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-03-01 00:00:00&#039;) # optional START DATE&lt;br /&gt;
AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-05-31 23:59:00&#039;) # optional END DATE&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide, daily unique user hits for the last 7 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
  DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%m%d&#039;) &#039;Day&#039;&lt;br /&gt;
  ,COUNT(DISTINCT l.userid) AS &#039;Distinct Users Hits&#039;&lt;br /&gt;
  ,COUNT( l.userid) AS &#039;Users Hits&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
WHERE l.courseid &amp;gt; 1&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 7 DAY)&lt;br /&gt;
GROUP BY DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User detailed activity in course modules===&lt;br /&gt;
Considering only several modules: url, resource, forum, quiz, questionnaire.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.id, ra.roleid,&lt;br /&gt;
CONCAT(u.lastname, &#039; &#039;, u.firstname) AS &#039;Student&#039;&lt;br /&gt;
,COUNT(l.id) AS &#039;Actions&#039;&lt;br /&gt;
,l.component &amp;quot;Module type&amp;quot;&lt;br /&gt;
,l.objectid &amp;quot;Module ID&amp;quot;&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN l.component = &#039;mod_url&#039; THEN (SELECT u.name FROM mdl_url AS u WHERE u.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_resource&#039; THEN (SELECT r.name FROM mdl_resource AS r WHERE r.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_forum&#039; THEN (SELECT f.name FROM mdl_forum AS f WHERE f.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_quiz&#039; THEN (SELECT q.name FROM mdl_quiz AS q WHERE q.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_questionnaire&#039; THEN (SELECT q.name FROM mdl_questionnaire AS q WHERE q.id = l.objectid )&lt;br /&gt;
END AS &#039;Module name&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = l.courseid AND m.userid = u.id) &amp;quot;user_groups&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT s.name &lt;br /&gt;
  FROM mdl_course_modules AS cm &lt;br /&gt;
  JOIN mdl_course_sections AS s ON s.course = cm.course AND s.id = cm.section &lt;br /&gt;
  WHERE cm.id = l.contextinstanceid) AS &amp;quot;Section name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l  &lt;br /&gt;
JOIN mdl_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.userid = l.userid &lt;br /&gt;
  AND ra.contextid = (SELECT id FROM mdl_context WHERE instanceid = l.courseid AND contextlevel = 50) &lt;br /&gt;
WHERE l.courseid = %%COURSEID%%&lt;br /&gt;
  AND l.component IN (&#039;mod_url&#039;, &#039;mod_resource&#039;, &#039;mod_forum&#039;, &#039;mod_quiz&#039;, &#039;mod_questionnaire&#039;) &lt;br /&gt;
  %%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%%&lt;br /&gt;
 &lt;br /&gt;
GROUP BY u.id, l.component&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What teachers and courses considered active?===&lt;br /&gt;
This report display several calculations and parameters that help the Online academic training team find teachers that might need more support getting their courses more supporting of online learning pedagogical methodologies.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,&lt;br /&gt;
			  course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
#,course.shortname&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2012%&#039; THEN &#039;2012&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2013%&#039; THEN &#039;2013&#039; &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2014%&#039; THEN &#039;2014&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2015%&#039; THEN &#039;2015&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester a%&#039; THEN &#039;Spring semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester b%&#039; THEN &#039;Fall semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester s%&#039; THEN &#039;Summer semester&#039;&lt;br /&gt;
END AS Semester&lt;br /&gt;
&lt;br /&gt;
,IF(course.startdate&amp;gt;0, DATE_FORMAT(FROM_UNIXTIME(startdate), &#039;%d-%m-%Y&#039;), &#039;no date&#039;) AS &amp;quot;Course Start Date&amp;quot; &lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 4 AND ctx.instanceid = course.id&lt;br /&gt;
) AS &amp;quot;Assistant teacher&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
&lt;br /&gt;
# Uncomment to use the new Moodle 2.8+ logstore&lt;br /&gt;
#,(SELECT COUNT(*) FROM mdl_logstore_standard_log AS l WHERE l.courseid = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Student HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Teacher HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_log AS l WHERE l.course = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course c&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = c.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND c.id = course.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
  &lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = course.id) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(DISTINCT cm.module) FROM prefix_course_modules cm &lt;br /&gt;
  WHERE cm.course = course.id) UniqueModules&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(DISTINCT m.name) &lt;br /&gt;
  FROM prefix_course_modules cm &lt;br /&gt;
  JOIN mdl_modules as m ON m.id = cm.module&lt;br /&gt;
  WHERE cm.course = course.id) UniqueModuleNames&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;ouwiki&#039;, &#039;wiki&#039;) ) &amp;quot;Num Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;oublog&#039;) ) &amp;quot;Num Blogs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;forum&#039;, &#039;forumng&#039;) ) &amp;quot;Num Forums&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;resource&#039;, &#039;folder&#039;, &#039;url&#039;, &#039;tab&#039;, &#039;file&#039;, &#039;book&#039;, &#039;page&#039;) ) Resources&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;forum&#039;, &#039;forumng&#039;, &#039;oublog&#039;, &#039;page&#039;, &#039;file&#039;, &#039;url&#039;, &#039;wiki&#039; , &#039;ouwiki&#039;) ) &amp;quot;Basic Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;advmindmap&#039;, &#039;assign&#039;, &#039;attendance&#039;, &#039;book&#039;, &#039;choice&#039;, &#039;folder&#039;, &#039;tab&#039;, &#039;glossary&#039;, &#039;questionnaire&#039;, &#039;quiz&#039;, &#039;label&#039; ) ) &amp;quot;Avarage Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;elluminate&#039;, &#039;game&#039;, &#039;workshop&#039;) ) &amp;quot;Advanced Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course&lt;br /&gt;
&lt;br /&gt;
#WHERE course.shortname LIKE &#039;%2015%&#039;&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_SEARCHTEXT:course.shortname:~%%&lt;br /&gt;
&lt;br /&gt;
WHERE course.fullname LIKE &#039;%2015%&#039; &lt;br /&gt;
&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY UniqueModules DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Course Reports==&lt;br /&gt;
===Most Active courses===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(l.userid) AS Views&lt;br /&gt;
FROM `mdl_logstore_standard_log` l, `mdl_user` u, `mdl_role_assignments` r&lt;br /&gt;
WHERE l.courseid=35&lt;br /&gt;
AND l.userid = u.id&lt;br /&gt;
AND (l.timecreated &amp;gt; UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) AND l.timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:59&#039;))AND r.contextid= (&lt;br /&gt;
	 SELECT id&lt;br /&gt;
	 FROM mdl_context&lt;br /&gt;
	 WHERE contextlevel=50 AND instanceid=l.courseid&lt;br /&gt;
 )&lt;br /&gt;
AND r.roleid=5&lt;br /&gt;
AND r.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active courses, advanced===&lt;br /&gt;
Including: Teacher&#039;s name, link to the course, All types of log activities, special YEAR generated field, Activities and Resource count, enrolled Student count&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשע&#039; THEN &#039;תשע&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעא&#039; THEN &#039;תשעא&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעב&#039; THEN &#039;תשעב&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = l.course) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_log l &lt;br /&gt;
INNER JOIN prefix_course c ON l.course = c.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
#The following line restricts the courses returned to those having more than 2 modules.  Adjust based on your needs.&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY Year DESC, hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Least active or probably empty courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;-1&amp;quot; instead of &amp;quot;0&amp;quot; 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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
c.fullname,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;CourseLink&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timecreated&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timemodified&#039;,&lt;br /&gt;
CASE&lt;br /&gt;
 WHEN c.timecreated = c.timemodified THEN &#039;-1&#039;&lt;br /&gt;
 ELSE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated))&lt;br /&gt;
END AS &#039;DateDifference&#039;,&lt;br /&gt;
COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
LEFT JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
WHERE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated) ) &amp;lt; 60&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
HAVING COUNT(ue.id) &amp;lt;= 3&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Count unique teachers with courses that use at least X module (Moodle19)===&lt;br /&gt;
You can remove the outer &amp;quot;SELECT COUNT(*) FROM (...) AS ActiveTeachers&amp;quot; SQL query and get the list of the Teachers and Courses.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(*)&lt;br /&gt;
FROM (SELECT c.id AS CourseID, c.fullname AS Course, ra.roleid AS RoleID, CONCAT(u.firstname, &#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = c.id) AS Modules&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid AND ctx.contextlevel = 50 &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE  ra.roleid = 3 &lt;br /&gt;
GROUP BY u.id&lt;br /&gt;
HAVING Modules &amp;gt; 5) AS ActiveTeachers&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RESOURCE count for each COURSE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) count, l.course, c.fullname coursename&lt;br /&gt;
FROM prefix_resource l INNER JOIN prefix_course c on l.course = c.id&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY count DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Common resource types count for each Category (Moodle19)===&lt;br /&gt;
Including sub-categories in total count.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category&lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Links&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference NOT LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Files&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;directory&#039; &lt;br /&gt;
) AS Folders&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;html&#039; &lt;br /&gt;
) AS Pages&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM stats_log_context_role_course &lt;br /&gt;
WHERE roleid = 5 AND module = &#039;resource&#039; AND category = mcc.id&lt;br /&gt;
) AS Hits&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Where &amp;quot;stats_log_context_role_course&amp;quot; (in the above SQL query) is a VIEW generated by:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
CREATE VIEW stats_log_context_role_course AS&lt;br /&gt;
SELECT l.course, c.category, cc.path, l.module, l.action, ra.userid, ra.roleid&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = l.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Same query but for Moodle2+&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category,&lt;br /&gt;
mcc.path,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_url AS u&lt;br /&gt;
JOIN prefix_course AS c ON c.id = u.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS URLs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_folder AS f&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS FOLDERs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_page AS p&lt;br /&gt;
JOIN prefix_course AS c ON c.id = p.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS PAGEs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_book AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS BOOKs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_label AS l&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS LABELs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_tab AS t&lt;br /&gt;
JOIN prefix_course AS c ON c.id = t.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS TABs&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed Resource COUNT by Teacher in each course===&lt;br /&gt;
&lt;br /&gt;
Including (optional) filter by: year, semester and course id.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
, c.id&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעב%&#039; THEN &#039;2012&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעא%&#039; THEN &#039;2011&#039;&lt;br /&gt;
END ) as Year&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר א%&#039; THEN &#039;Semester A&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ב%&#039; THEN &#039;Semester B&#039;&lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ק%&#039; THEN &#039;Semester C&#039;&lt;br /&gt;
END ) as Semester&lt;br /&gt;
,COUNT(c.id) AS Total&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 20) AS TABs&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 33) AS BOOKs&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_resource` as r &lt;br /&gt;
JOIN `prefix_course` AS c on c.id = r.course&lt;br /&gt;
#WHERE type= &#039;file&#039; and reference NOT LIKE &#039;http://%&#039; &lt;br /&gt;
&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
#AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY COUNT(c.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses that are defined as using GROUPs===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/group/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = c.id) Modules&lt;br /&gt;
,(SELECT count(*) FROM prefix_groups g WHERE g.courseid = c.id) Groups&lt;br /&gt;
 FROM `prefix_course` AS c&lt;br /&gt;
WHERE groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Groups===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with Groups in them (groupmode &amp;gt; 0). You can also use groupmode=1 to list just Separate type groups or groupmode=2 to list Visible type groups.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name, c.groupmode&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON c.id = g.courseid&lt;br /&gt;
WHERE c.groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users enrolled in a course with groups but not assigned a group ===&lt;br /&gt;
&lt;br /&gt;
Displays by course all enrolled users that have not been assigned a group in courses that have groups. NOTE: This needs to be optimized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) AS ROLE&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = course.id&lt;br /&gt;
&lt;br /&gt;
WHERE ue.enrolid NOT IN (select userid from prefix_groups_members WHERE g.id=groupid)&lt;br /&gt;
&lt;br /&gt;
ORDER BY Course, Lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Groups in course with member list===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List the groups in a course (replace the # by the course id number) with the members of each group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name AS Groupname, u.username&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_user AS u ON m.userid = u.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Group Export===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
There&#039;s a [[Import_groups|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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT g.name AS groupname, g.description, g.enrolmentkey&lt;br /&gt;
FROM prefix_groups AS g &lt;br /&gt;
JOIN prefix_course as c ON g.courseid = c.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Courses in and below a certain category===&lt;br /&gt;
Use this SQL code to retrieve all courses that exist in or under a set category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the category you want to know about...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course. * , prefix_course_categories. *&lt;br /&gt;
FROM prefix_course, prefix_course_categories&lt;br /&gt;
WHERE prefix_course.category = prefix_course_categories.id&lt;br /&gt;
AND (&lt;br /&gt;
prefix_course_categories.path LIKE &#039;/$s/%&#039;&lt;br /&gt;
OR prefix_course_categories.path LIKE &#039;/$s&#039;&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Categories in one level below a certain category===&lt;br /&gt;
Use this PHP code to retrieve a list of all categories below a certain category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the top level category you are interested in.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
require_once(&#039;./config.php&#039;);&lt;br /&gt;
&lt;br /&gt;
$parent_id = $s;&lt;br /&gt;
&lt;br /&gt;
$categories= array();&lt;br /&gt;
&lt;br /&gt;
$categories = get_categories($parent_id);&lt;br /&gt;
&lt;br /&gt;
echo &#039;&amp;lt;ol&amp;gt;&#039;;&lt;br /&gt;
foreach ($categories as $category)&lt;br /&gt;
        {&lt;br /&gt;
        echo &#039;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&#039;.$CFG-&amp;gt;wwwroot.&#039;/course/category.php?id=&#039;.$category-&amp;gt;id.&#039;&amp;quot;&amp;gt;&#039;.$category-&amp;gt;name.&#039;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
        }&lt;br /&gt;
echo &#039;&amp;lt;/ol&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Blog activity per Course (not including VIEW)===&lt;br /&gt;
Filter activity logging to some specific Course Categories!&lt;br /&gt;
+ link course name to actual course (for quick reference)&lt;br /&gt;
(you can change %blog% to %wiki% to filter down all wiki activity or any other module you wish)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID&lt;br /&gt;
,m.name ,count(cm.id) as counter &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS Students&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE `module` LIKE &#039;%blog%&#039; AND course = c.id AND action NOT LIKE &#039;%view%&#039; ) as BlogActivity&lt;br /&gt;
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 &lt;br /&gt;
WHERE m.name LIKE &#039;%blog%&#039; AND c.category IN ( 8,13,15)&lt;br /&gt;
GROUP BY cm.course,cm.module order by counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student&#039;s posts content in all course blogs (oublog)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
b.name &lt;br /&gt;
,op.title&lt;br /&gt;
,op.message&lt;br /&gt;
,( SELECT CONCAT(u.firstname, &#039; &#039;,u.lastname) FROM prefix_user AS u WHERE u.id = oi.userid) AS &amp;quot;Username&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_oublog_posts AS op&lt;br /&gt;
JOIN prefix_oublog_instances AS oi ON oi.id = op.oubloginstancesid &lt;br /&gt;
JOIN prefix_oublog as b ON b.id = oi.oublogid&lt;br /&gt;
JOIN prefix_course AS c ON b.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Courses which uploaded a Syllabus file===&lt;br /&gt;
+ under specific Category&lt;br /&gt;
+ show first Teacher in that course&lt;br /&gt;
+ link Course&#039;s fullname to actual course&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) as Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user as u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) as Teacher&lt;br /&gt;
FROM prefix_resource as r &lt;br /&gt;
JOIN prefix_course as c ON r.course = c.id&lt;br /&gt;
WHERE ( r.name LIKE &#039;%סילבוס%&#039; OR r.name LIKE &#039;%סילאבוס%&#039; OR r.name LIKE &#039;%syllabus%&#039; OR r.name LIKE &#039;%תכנית הקורס%&#039; ) &lt;br /&gt;
AND c.category IN (10,18,26,13,28)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
===Site-wide completed SCORM activities by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===All users enrolled in a course without a role===&lt;br /&gt;
Identifies All users that are enrolled in a course but are not assigned a role.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user.firstname AS Firstname,&lt;br /&gt;
user.lastname AS Lastname,&lt;br /&gt;
user.idnumber Employee_ID,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user as user ON user.id = ue.userid&lt;br /&gt;
&lt;br /&gt;
WHERE user.id NOT IN (&lt;br /&gt;
SELECT u.id&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE c.id=course.id&lt;br /&gt;
)&lt;br /&gt;
ORDER BY Course, Lastname, Firstname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List course resources accumulative file size and count===&lt;br /&gt;
This is the main (first) report, which has a link (alias) to a second report (the following on this page) which list each file in the course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id &amp;quot;CourseID&amp;quot;, context.id &amp;quot;ContextID&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;, c.id, &#039;&amp;quot;&amp;gt;&#039;, c.fullname ,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Course Name&amp;quot;&lt;br /&gt;
, COUNT(*) &amp;quot;Course Files&amp;quot; , ROUND( SUM( f.filesize ) /1048576 ) AS file_size_MB&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/blocks/configurable_reports/viewreport.php?alias=coursefiles&amp;amp;courseid=1&amp;amp;filter_courses=&#039;, c.id, &#039;&amp;quot;&amp;gt;List files&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List Files&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
JOIN mdl_context AS context ON context.id = f.contextid&lt;br /&gt;
JOIN mdl_course AS c ON c.id = (&lt;br /&gt;
  SELECT instanceid&lt;br /&gt;
  FROM mdl_context&lt;br /&gt;
  WHERE id = SUBSTRING_INDEX( SUBSTRING_INDEX( context.path, &#039;/&#039; , -2 ) , &#039;/&#039;, 1 ) )&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this report, you will have to define &amp;quot;alias&amp;quot; report property to &amp;quot;coursefiles&amp;quot; for it to be able to be called from the above report.&lt;br /&gt;
And also setup (add) a FILTER_COURSES filter. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id ,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/pluginfile.php/&#039;, contextid, &#039;/&#039;, component, &#039;/&#039;, filearea, &#039;/&#039;, itemid, &#039;/&#039;, filename, &#039;&amp;quot;&amp;gt;&#039;, filename,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;File&amp;quot;&lt;br /&gt;
,filesize, mimetype ,author, license, timecreated, component, filearea, filepath&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
            AND f.contextid&lt;br /&gt;
            IN (   SELECT id&lt;br /&gt;
                     FROM mdl_context&lt;br /&gt;
                    WHERE path &lt;br /&gt;
                     LIKE (   SELECT CONCAT(&#039;%/&#039;,id,&#039;/%&#039;)&lt;br /&gt;
                                  AS contextquery&lt;br /&gt;
                                FROM mdl_context&lt;br /&gt;
                               WHERE 1=1&lt;br /&gt;
			        %%FILTER_COURSES:instanceid%%&lt;br /&gt;
                                 AND contextlevel = 50&lt;br /&gt;
                           )&lt;br /&gt;
                )&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Which courses has redundant topics===&lt;br /&gt;
This report list several &amp;quot;active topics&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
The following, second SQL query, could be used to &amp;quot;trim&amp;quot; down those redundant course topics/sections/weeks by updating the course format&#039;s numsection (Number of sections) setting. (It&#039;s a per course format setting!)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, format,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT value  FROM  `mdl_course_format_options` WHERE  `courseid` = c.id AND `format` = c.format AND `name` = &#039;numsections&#039; ) AS &amp;quot;numsections&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND `sequence` !=  &#039;&#039; ) AS &amp;quot;Non empty sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id ) AS &amp;quot;Total section count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND sequence IS NOT NULL) AS &amp;quot;Non NULL sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND name != &#039;&#039;) AS &amp;quot;Non empty section Name count&amp;quot;&lt;br /&gt;
 ,(SELECT COUNT(*) FROM mdl_course_modules cm WHERE cm.course = c.id) &amp;quot;Modules count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course AS c&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following SQL REPLACE query is used for &amp;quot;fixing&amp;quot; (updating) the &amp;quot;numsections&amp;quot; of a specific course format &amp;quot;onetopics&amp;quot; (you can always change it, or discard it to use this SQL REPLACE on all course formats) &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
REPLACE INTO `mdl_course_format_options` (`id`, `courseid`, `format`, `sectionid`, `name`, `value`) &lt;br /&gt;
SELECT NULL, c.id, &#039;onetopic&#039;, &#039;0&#039;, &#039;numsections&#039;, (SELECT COUNT(*) FROM `mdl_course_sections` WHERE `course` = c.id AND name != &#039;&#039;)&lt;br /&gt;
FROM `mdl_course` c where format = &#039;onetopic&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hidden Courses with Students Enrolled===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.visible AS Visible, &lt;br /&gt;
DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors,&lt;br /&gt;
&lt;br /&gt;
(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;, &lt;br /&gt;
&lt;br /&gt;
now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
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) &amp;gt; 0&lt;br /&gt;
ORDER BY StartDate, Instructor_Email, Course_ID&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Course Design Reports==&lt;br /&gt;
&lt;br /&gt;
These are reports which summarize course design aspects, such as activity and resource modules per section, types of activities used, etc.&lt;br /&gt;
&lt;br /&gt;
===Course Content/Week===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report assumes that the first 14 sections in a course, not including the &amp;quot;0&amp;quot; or &amp;quot;Welcome&amp;quot; section, correspond to weeks (with &amp;quot;Subsections&amp;quot; given numbers much higher in the sequence). Of those sections, each is checked to count the number of:&lt;br /&gt;
&lt;br /&gt;
    Forums&lt;br /&gt;
    Graded Activities (may include Forums)&lt;br /&gt;
    Resources (not including a Label)&lt;br /&gt;
&lt;br /&gt;
Totals of each of these types of content elements per section are provided.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Only visible resources and activities are counted.&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: this is a &amp;quot;Global&amp;quot; report.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
 &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT LIKE &#039;label&#039;),cm.id,NULL)) AS &#039;Ungraded Resources&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Graded Activities&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cs.section&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments and Weights===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Categories with weights of 0 are not included in this report.&lt;br /&gt;
&lt;br /&gt;
Only visible activities are included in this report.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This is designed to be a &amp;quot;Global&amp;quot; report in Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;) AS &#039;Grade Book Category&#039;&lt;br /&gt;
, IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND(SUM(DISTINCT gi.aggregationcoef), 2)+ROUND(SUM(DISTINCT mgi.aggregationcoef), 2)) AS &#039;Category weight&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT_WS(&#039;, &#039;,GROUP_CONCAT(DISTINCT gi.itemmodule SEPARATOR &#039;, &#039;), IF(mgi.id, &#039;manual&#039;,NULL)) AS &#039;Activity Types&#039;&lt;br /&gt;
, COUNT(DISTINCT gi.itemmodule) + IF(mgi.id,1,0) AS &#039;Different Activity Types&#039;&lt;br /&gt;
, CONCAT_WS(&#039;&amp;lt;br&amp;gt;&#039;, GROUP_CONCAT(DISTINCT gi.itemname ORDER BY gi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;), GROUP_CONCAT(DISTINCT mgi.itemname ORDER BY mgi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;)) AS &#039;Activity Names&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) + COUNT(DISTINCT mgi.id) AS &#039;Activity Count&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
&lt;br /&gt;
#get grade categories&lt;br /&gt;
LEFT JOIN prefix_grade_categories AS gc ON gc.courseid = c.id &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
JOIN prefix_grade_items AS gic ON gic.courseid = c.id AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
&lt;br /&gt;
# attach activities to course&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = c.id &lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.iteminstance = cm.instance AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.id&lt;br /&gt;
ORDER BY gc.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pre-Term Course Review===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
#   &amp;quot;Required blocks&amp;quot; include Instructor Block (mooprofile), Activities, and the Research block.&lt;br /&gt;
#    &amp;quot;Instructor Details&amp;quot; block is not the &amp;quot;Instructor&amp;quot; block (mooprofile) automatically provided by the system. It is an optional block that can be edited by the instructor. If not edited to remove boilerplate text, it should be hidden.&lt;br /&gt;
#    All courses should be in the &amp;quot;Collapsed Topics&amp;quot; format with the &amp;quot;Weeks&amp;quot; structure.&lt;br /&gt;
#    &amp;quot;Weeks defined in course settings&amp;quot; is taken from our SIS when the course shells are created, but can be edited by faculty. &amp;quot;# of weeks named and visible&amp;quot; should usually match or exceed this value.&lt;br /&gt;
#    We recommend that each week contain at least one forum, at least one graded activity, and at least one ungraded resource.&lt;br /&gt;
#    &amp;quot;Syllabus updated&amp;quot; date is for the first attached file found with the text &amp;quot;syllabus&amp;quot; in the name. The &amp;quot;Days ago&amp;quot; calculation is included for convenience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: At our institution, we construct categories each term, and insert a text string &amp;quot;staging&amp;quot; in the Category ID for pre-term courses during the preparation or &amp;quot;staging&amp;quot; phase of course development. We remove this text string (and change it to &amp;quot;production&amp;quot;) when courses go live at the start of the new term.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
#,RIGHT(c.idnumber,2) AS Type # Specific to GSC &amp;quot;Instructional Method&amp;quot; storage&lt;br /&gt;
&lt;br /&gt;
#, substring_index(substr(c.shortname FROM locate(&#039;.&#039;,c.shortname)+1),&#039;-&#039;,1) AS Section # Specific to GSC&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.lastname,&#039;, &#039;, u.firstname,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
,(SELECT IF((u2.description IS NULL) OR (u2.description LIKE &#039;&#039;),&#039;NO&#039;, &#039;YES&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT IF(u3.picture &amp;gt; 0,&#039;YES&#039;,&#039;NO&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u3 ON u3.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Picture&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(((bpi.visible IS NULL) OR (bpi.visible !=0)) AND ((bpm.visible IS NULL) OR (bpm.visible !=0)) AND ((bpa.visible IS NULL) OR (bpa.visible !=0)) AND ((bpr.visible IS NULL) OR (bpr.visible !=0)),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Required blocks visible&#039;&lt;br /&gt;
#, IF((bpm.visible IS NULL) OR (bpm.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Messages block visible&#039;&lt;br /&gt;
#, IF((bpa.visible IS NULL) OR (bpa.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;activities block visible&#039;&lt;br /&gt;
#, IF((bpr.visible IS NULL) OR (bpr.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;research block visible&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)) AND (bip.visible !=0),&#039;YES&#039;,&#039;&#039;) AS &#039;Instructor Details Block visible&#039; # This is a hack based on UUencoded string data from the title of HTML &amp;quot;Instructor Details&amp;quot; block&lt;br /&gt;
&lt;br /&gt;
#, IF(bi.configdata LIKE &#039;%ZGl0IHRoaXMgYmxvY2s%&#039;,&#039;NO&#039;,&#039;&#039;) AS &#039;Instructor Details Block Updated&#039; # HTML block has string &#039;dit this block&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(COUNT(bi.id) -  SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)),&#039;YES&#039;,&#039;&#039;) AS &#039;possible extra instructor blocks&#039; #looking for any HTML block with &amp;quot;instructor&amp;quot; in the title&lt;br /&gt;
&lt;br /&gt;
, IF(c.format=&#039;topcoll&#039;,&#039;YES&#039;, c.format) AS &#039;Collapsed Topics course format&#039; # change this if you want to test for a different format&lt;br /&gt;
, IF(cfo.value = 2, &#039;YES&#039;,&#039;NO&#039;) AS &#039;weeks structure&#039;&lt;br /&gt;
&lt;br /&gt;
, cfw.value AS &#039;weeks defined in course settings&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(((cs.name IS NOT NULL) AND (cs.visible = 1) AND (cs.section != &#039;0&#039;) AND (cs.sequence IS NOT NULL)),cs.id,NULL)) AS &#039;# of weeks named &amp;amp; visible (includes orphans)&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039; ,cs.id , NULL)) AS &#039;Weeks with Forum&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cs.id, NULL)) AS &#039;Weeks with Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT mgi.id) AS &#039;Manual Grade Items&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)),cm.id,NULL)) AS &#039;Resources&#039;&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)), cs.id, NULL)) AS &#039;Weeks with Resources&#039;&lt;br /&gt;
&lt;br /&gt;
# Here are some other things you could check for per course&lt;br /&gt;
#,(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 &#039;%forum%&#039;) AS Forums&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%quiz%&#039;) AS Quizzes&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%assign%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_resource.id) FROM prefix_resource JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course) AS Files&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_url.id) FROM prefix_url JOIN prefix_course ON prefix_course.id = prefix_url.course WHERE c.id = prefix_url.course) AS Links&lt;br /&gt;
&lt;br /&gt;
,(SELECT FROM_UNIXTIME(MAX(prefix_resource.timemodified))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS SyllabusDate&lt;br /&gt;
&lt;br /&gt;
,(SELECT TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(MAX(prefix_resource.timemodified)))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS DaysAgo&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, f.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement Forum Visible&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, fd.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement posted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
LEFT JOIN prefix_context AS ctxx ON c.id = ctxx.instanceid &lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpi ON bpi.contextid = ctxx.id AND bpi.blockinstanceid = &#039;43692&#039; # mooprofile&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpm ON bpm.contextid = ctxx.id AND bpm.blockinstanceid = &#039;43962&#039; # messages&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpa ON bpa.contextid = ctxx.id AND bpa.blockinstanceid = &#039;43963&#039; # activities&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpr ON bpr.contextid = ctxx.id AND bpr.blockinstanceid = &#039;38368&#039; # html research help&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.visible = 1 AND cs.sequence IS NOT NULL&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
LEFT JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_forum AS f ON f.course = c.id AND cm.instance = f.id AND cm.visible = 1&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.forum = f.id&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfo ON cfo.courseid = c.id AND cfo.name = &#039;layoutstructure&#039;&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfw ON cfw.courseid = c.id AND cfw.name = &#039;numsections&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_instances AS bi ON bi.parentcontextid = ctxx.id AND bi.blockname = &#039;html&#039; AND (bi.configdata LIKE &#039;%SW5zdHJ1Y3Rvc%&#039; or bi.configdata LIKE &#039;%bnN0cnVjdG9y%&#039;)&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bip ON bip.blockinstanceid = bi.id&lt;br /&gt;
&lt;br /&gt;
WHERE RIGHT(c.idnumber,2) IN (&#039;OL&#039;, &#039;BL&#039;, &#039;HY&#039;) &lt;br /&gt;
# AND substring(cc.path,2,2) IN (&#039;26&#039;) # Staging&lt;br /&gt;
#AND substring(cc.path,2,3) IN (&#039;158&#039;) # UG&lt;br /&gt;
AND cc.idnumber LIKE &#039;%staging%&#039;&lt;br /&gt;
AND ctxx.contextlevel = 50&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module instances + Module HITs by role teacher and student in course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
m.name AS &amp;quot;Module name&amp;quot;&lt;br /&gt;
, COUNT(*) AS &amp;quot;Module count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name ) AS &amp;quot;Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course_modules AS cm&lt;br /&gt;
JOIN mdl_modules AS m on m.id = cm.module&lt;br /&gt;
WHERE cm.course = &#039;%%COURSEID%%&#039;&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Grade and Course Completion Reports==&lt;br /&gt;
===Site-Wide Grade Report with All Items===&lt;br /&gt;
Shows grades for all course items along with course totals for each student. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gi.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
For MySQL users, you&#039;ll need to use the MySQL DATE_ADD function instead of DATEADD. Replace the line&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
DATEADD(ss,gi.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
DATE_ADD(&#039;1970-01-01&#039;, INTERVAL gi.timemodified SECOND) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site-Wide Grade Report with Just Course Totals===&lt;br /&gt;
A second site-wide grade report for all students that just shows course totals. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id AND gi.itemtype = &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For MySQL users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN CONCAT(c.fullname, &#039; - Total&#039;)&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS TIME&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
 &lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Learner report by Learner with grades===&lt;br /&gt;
Which Learners in which course and what are the grades&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;Name&#039; , u.lastname AS &#039;Surname&#039;, c.fullname AS &#039;Course&#039;, cc.name AS &#039;Category&#039;, &lt;br /&gt;
CASE WHEN gi.itemtype = &#039;Course&#039;    &lt;br /&gt;
THEN c.fullname + &#039; Course Total&#039;  &lt;br /&gt;
ELSE gi.itemname &lt;br /&gt;
END AS &#039;Item Name&#039;, ROUND(gg.finalgrade,2) AS Score,ROUND(gg.rawgrademax,2) AS Max, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) as Percentage,&lt;br /&gt;
&lt;br /&gt;
if (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) &amp;gt; 79,&#039;Yes&#039; , &#039;No&#039;) as Pass&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id &lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid &lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category &lt;br /&gt;
WHERE  gi.courseid = c.id and gi.itemname != &#039;Attendance&#039;&lt;br /&gt;
ORDER BY `Name` ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A very simple report with a list of course completion status by username. Completions are noted by date, blank otherwise. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  u.username, &lt;br /&gt;
  c.shortname,  &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%Y-%m-%d&#039;) AS completed&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion with Criteria===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A report with course completions by username, with Aggregation method, Criteria types, and Criteria detail where available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username AS user, &lt;br /&gt;
c.shortname AS course,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(t.timecompleted),&#039;%Y-%m-%d&#039;) AS completed,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = c.id AND a.criteriatype IS NULL) = 1) THEN &amp;quot;Any&amp;quot;&lt;br /&gt;
ELSE &amp;quot;All&amp;quot;&lt;br /&gt;
END AS aggregation,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;Self&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN &amp;quot;By Date&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 3 THEN &amp;quot;Unenrol Status&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &amp;quot;Activity&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 5 THEN &amp;quot;Duration&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 6 THEN &amp;quot;Course Grade&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 7 THEN &amp;quot;Approve by Role&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 8 THEN &amp;quot;Previous Course&amp;quot;&lt;br /&gt;
END AS criteriatype,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;*&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(p.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN p.criteriatype = 3 THEN t.unenroled&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,p.module,&#039;/view.php?id=&#039;,p.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,p.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN p.criteriatype = 5 THEN p.enrolperiod&lt;br /&gt;
WHEN p.criteriatype = 6 THEN CONCAT(&#039;Needed: &#039;,ROUND(p.gradepass,2),&#039; Achieved: &#039;,ROUND(t.gradefinal,2)) &lt;br /&gt;
WHEN p.criteriatype = 7 THEN p.role&lt;br /&gt;
WHEN p.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = p.courseinstance)&lt;br /&gt;
END AS criteriadetail &lt;br /&gt;
FROM prefix_course_completion_crit_compl AS t&lt;br /&gt;
JOIN prefix_user AS u ON t.userid = u.id&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
JOIN prefix_course_completion_criteria AS p ON t.criteriaid = p.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Completion Enabled and their settings===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with completion enabled and their Aggregation setting, Criteria types, and Criteria details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT c.shortname AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = t.course AND a.criteriatype IS NULL)) = 2 THEN &amp;quot;All&amp;quot;&lt;br /&gt;
ELSE &amp;quot;Any&amp;quot;&lt;br /&gt;
END AS Course_Aggregation,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;Self completion&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN &amp;quot;Date done by&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;Unenrolement&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 4 THEN &amp;quot;Activity completion&amp;quot;   &lt;br /&gt;
WHEN t.criteriatype = 5 THEN &amp;quot;Duration in days&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 6 THEN &amp;quot;Final grade&amp;quot;     &lt;br /&gt;
WHEN t.criteriatype = 7 THEN &amp;quot;Approve by role&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 8 THEN &amp;quot;Previous course&amp;quot;&lt;br /&gt;
END AS Criteria_type,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(t.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 4 THEN&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,t.module,&#039;/view.php?id=&#039;,t.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,t.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN t.criteriatype = 5 THEN ROUND(t.enrolperiod/86400)&lt;br /&gt;
WHEN t.criteriatype = 6 THEN ROUND(t.gradepass,2)&lt;br /&gt;
WHEN t.criteriatype = 7 THEN (SELECT r.shortname FROM prefix_role AS r WHERE r.id = t.role)&lt;br /&gt;
WHEN t.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = t.courseinstance)&lt;br /&gt;
END AS Criteria_detail&lt;br /&gt;
FROM prefix_course_completion_criteria as t&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Completion Report with custom dates===&lt;br /&gt;
&lt;br /&gt;
List of users who completed multiple or single course/s from a start date to end date chosen by the user. The output gives username, name, course name, completion date and score&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT u.username AS &#039;User Name&#039;,&lt;br /&gt;
CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Name&#039;,&lt;br /&gt;
c.shortname AS &#039;Course Name&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%W %e %M, %Y&#039;) AS &#039;Completed Date&#039;,&lt;br /&gt;
ROUND(c4.gradefinal,2) AS &#039;Score&#039;&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
JOIN prefix_course_completion_crit_compl AS c4 ON u.id = c4.userid&lt;br /&gt;
WHERE c.enablecompletion = 1  AND (p.timecompleted IS NOT NULL OR p.timecompleted !=&#039;&#039;) &lt;br /&gt;
AND (p.timecompleted&amp;gt;= :start_date AND p.timecompleted&amp;lt;=:end_date)&lt;br /&gt;
GROUP BY u.username&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scales used in activities===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT scale.name&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,gi.itemmodule,&#039;/view.php?id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module View&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/modedit.php?up&#039;,&#039;date=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module Settings&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON c.id = gi.courseid&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = gi.courseid AND cm.instance = gi.iteminstance&lt;br /&gt;
JOIN prefix_scale AS scale ON scale.id = gi.scaleid&lt;br /&gt;
WHERE gi.scaleid IS NOT NULL&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Extra Credit Items by Name Only===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
This query identifies grade items in visible courses with student enrollment that have &amp;quot;extra credit&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, gi.itemname AS Item_Name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors&lt;br /&gt;
&lt;br /&gt;
,(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;&lt;br /&gt;
&lt;br /&gt;
,now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON gi.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE gi.itemname LIKE &#039;%extra credit%&#039; &lt;br /&gt;
	AND gi.gradetype = &#039;1&#039; &lt;br /&gt;
	AND gi.hidden = &#039;0&#039; &lt;br /&gt;
	AND gi.aggregationcoef = &#039;0&#039; &lt;br /&gt;
	AND c.visible = 1&lt;br /&gt;
	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) &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
GROUP BY Course_ID, gi.id&lt;br /&gt;
ORDER BY StartDate, Course_ID&lt;br /&gt;
 &lt;br /&gt;
%%FILTER_SEARCHTEXT:Course_ID:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site Wide Number of Courses Completed by User===&lt;br /&gt;
Contributed by Ken St. John&lt;br /&gt;
&lt;br /&gt;
Simple report that shows the number of completed courses for all users site wide&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname, u.firstname,&lt;br /&gt;
COUNT(p.timecompleted) AS TotalCompletions&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
GROUP BY p.userid&lt;br /&gt;
ORDER BY u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Activity Module Reports==&lt;br /&gt;
&lt;br /&gt;
=== User activity completions with dates===&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.username As &#039;User&#039;,&lt;br /&gt;
c.shortname AS &#039;Course&#039;,&lt;br /&gt;
m.name AS Activitytype, &lt;br /&gt;
CASE &lt;br /&gt;
    WHEN cm.module = 1 THEN (SELECT a1.name FROM prefix_assign a1            WHERE a1.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 2 THEN (SELECT a2.name FROM prefix_assignment a2    WHERE a2.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 3 THEN (SELECT a3.name FROM prefix_book a3               WHERE a3.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 4 THEN (SELECT a4.name FROM prefix_chat a4                WHERE a4.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 5 THEN (SELECT a5.name FROM prefix_choice a5            WHERE a5.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 6 THEN (SELECT a6.name FROM prefix_data a6                WHERE a6.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 7 THEN (SELECT a7.name FROM prefix_feedback a7        WHERE a7.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 8 THEN (SELECT a8.name FROM prefix_folder a8              WHERE a8.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 9 THEN (SELECT a9.name FROM prefix_forum a9              WHERE a9.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 10 THEN (SELECT a10.name FROM prefix_glossary a10         WHERE a10.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 11 THEN (SELECT a11.name FROM prefix_imscp  a11           WHERE a11.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 12 THEN (SELECT a12.name FROM prefix_label a12              WHERE a12.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 13 THEN (SELECT a13.name FROM prefix_lesson a13            WHERE a13.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 14 THEN (SELECT a14.name FROM prefix_lti a14                    WHERE a14.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 15 THEN (SELECT a15.name FROM prefix_page a15               WHERE a15.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 16 THEN (SELECT a16.name FROM prefix_quiz  a16               WHERE a16.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 17 THEN (SELECT a17.name FROM prefix_resource a17         WHERE a17.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 18 THEN (SELECT a18.name FROM prefix_scorm a18             WHERE a18.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 19 THEN (SELECT a19.name FROM prefix_survey a19             WHERE a19.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 20 THEN (SELECT a20.name FROM prefix_url a20                      WHERE a20.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 21 THEN (SELECT a21.name FROM prefix_wiki a21                    WHERE a21.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 22 THEN (SELECT a22.name FROM prefix_workshop a22           WHERE a22.id = cm.instance)&lt;br /&gt;
END AS Actvityname,&lt;br /&gt;
# cm.section AS Coursesection,&lt;br /&gt;
CASE&lt;br /&gt;
    WHEN cm.completion = 0 THEN &#039;0 None&#039;&lt;br /&gt;
    WHEN cm.completion = 1 THEN &#039;1 Self&#039;&lt;br /&gt;
    WHEN cm.completion = 2 THEN &#039;2 Auto&#039;&lt;br /&gt;
END AS Activtycompletiontype, &lt;br /&gt;
CASE&lt;br /&gt;
   WHEN cmc.completionstate = 0 THEN &#039;In Progress&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 1 THEN &#039;Completed&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 2 THEN &#039;Completed with Pass&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 3 THEN &#039;Completed with Fail&#039;&lt;br /&gt;
   ELSE &#039;Unknown&#039;&lt;br /&gt;
END AS &#039;Progress&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(cmc.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;&lt;br /&gt;
FROM prefix_course_modules_completion cmc &lt;br /&gt;
JOIN prefix_user u ON cmc.userid = u.id&lt;br /&gt;
JOIN prefix_course_modules cm ON cmc.coursemoduleid = cm.id&lt;br /&gt;
JOIN prefix_course c ON cm.course = c.id&lt;br /&gt;
JOIN prefix_modules m ON cm.module = m.id&lt;br /&gt;
# skip the predefined admin and guest user&lt;br /&gt;
WHERE u.id &amp;gt; 2&lt;br /&gt;
# config reports filters&lt;br /&gt;
%%FILTER_USERS:u.username%%&lt;br /&gt;
%%FILTER_SEARCHTEXT:m.name:~%%&lt;br /&gt;
%%FILTER_STARTTIME:cmc.timemodified:&amp;gt;%% %%FILTER_ENDTIME:cmc.timemodified:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many SCORM activities are used in each Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cm.course,c.fullname ,m.name &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/scorm/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,count(cm.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS Counter&lt;br /&gt;
 &lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
  JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
  JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%scorm%&#039; &lt;br /&gt;
GROUP BY cm.course,cm.module &lt;br /&gt;
ORDER BY count(cm.id) desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===SCORM Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of SCORM activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, scm.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;SCO%&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_scorm AS scm ON scm.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LTI (External Tool) Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of  LTI (External Tool) Usage activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, lti.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;lti&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_lti AS lti ON lti.id = cm.instance&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each MODULE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module,action,count(id) as counter&lt;br /&gt;
FROM prefix_log&lt;br /&gt;
GROUP BY module,action&lt;br /&gt;
ORDER BY module,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Most popular ACTIVITY===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, module&lt;br /&gt;
FROM prefix_log l&lt;br /&gt;
WHERE module != &#039;login&#039; AND module != &#039;course&#039; AND module != &#039;role&#039;&lt;br /&gt;
GROUP BY module&lt;br /&gt;
ORDER BY hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide use of ACTIVITIES and RESOURCES===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count( cm.id ) AS counter, m.name&lt;br /&gt;
FROM `prefix_course_modules` AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
ORDER BY counter DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LOG file ACTIONS per MODULE per COURSE (IDs)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select course,module,action,count(action) as summa from prefix_log&lt;br /&gt;
where action &amp;lt;&amp;gt; &#039;new&#039;&lt;br /&gt;
group by course,action,module&lt;br /&gt;
order by course,module,action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System Wide usage count of various course Activities===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
Like: Forum, Wiki, Blog, Assignment, Database,&lt;br /&gt;
#Within specific category&lt;br /&gt;
#Teacher name in course&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS Forums&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%data%&#039;) AS Databses&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%assignment%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 18)&lt;br /&gt;
ORDER BY Wikis DESC,Blogs DESC, Forums DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course wiki usage/activity over the last 6 semesters===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &amp;quot;Courses with Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester A%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester A&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester B%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester B&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed WIKI activity (per wiki per course)===&lt;br /&gt;
Including Number of Students in course (for reference)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID  &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id ) AS Students&lt;br /&gt;
,m.name&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%updat%&#039; ) as &#039;UPDAT E&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%annotate%&#039; ) as ANNOTATE&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%comment%&#039; ) as COMMENT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%add%&#039; ) as &#039;A DD&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%edit%&#039; ) as EDIT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action NOT LIKE &#039;%view%&#039; ) as &#039;All (NO View)&#039;&lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
GROUP BY cm.course,cm.module&lt;br /&gt;
ORDER BY &#039;All (NO View)&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wiki usage, system wide===&lt;br /&gt;
(you can filter the output by selecting some specific course categories : &amp;quot;WHERE c.category IN ( 8,13,15)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039;) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%add%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ADD&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%edit%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;EDIT&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%annotate%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ANNOTATE&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%comments%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;Comments&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_ouwiki_pages as ouwp&lt;br /&gt;
JOIN prefix_ouwiki as ouw ON ouw.id = ouwp.subwikiid&lt;br /&gt;
WHERE ouw.course = c.id GROUP BY ouw.course  ) as OUWikiPages&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( DISTINCT nwp.pagename ) FROM prefix_wiki_pages AS nwp&lt;br /&gt;
JOIN prefix_wiki AS nw ON nw.id = nwp.dfwiki WHERE nw.course = c.id ) As NWikiPages&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Wikis &amp;gt; 0&lt;br /&gt;
ORDER BY &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Aggregated Teacher activity by &amp;quot;WEB2&amp;quot; Modules===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
The NV column shows activity without VIEW log activity&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.userid, u.firstname,u.lastname&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039;) AS Wiki&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Wiki_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039;) AS Forum&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Forum_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039;) AS Blog&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Blog_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039;) AS Assignment&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Assignment_NV&lt;br /&gt;
FROM prefix_role_assignments AS ra &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
WHERE ra.roleid = 3 &lt;br /&gt;
GROUP BY ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the certificates issued, sort by variables in the custom profile fields===&lt;br /&gt;
Note: The SQL queries look intimidating at first, but isn&#039;t really that difficult to learn. I&#039;ve seen in the forums that users wanted to do &#039;site-wide&#039; groups in 1.9x. This is sort of the idea. It pulls all the certificates issued to all users sorted by the custom profile fields, which in my case is the Units or Depts (i.e. my site wide groups). Why certificates? I&#039;ve explored with both grades and quizzes, the course admins are not really interested in the actual grades but whether the learner received a certificate (i.e. passed the course with x, y, z activities). It also saves me from creating groups and assigning them into the right groups. Even assigning in bulk is not efficient, since I have upward of 25 groups per course and constantly new learners enrolling in courses. The limitation is something to do with the server? as it only pull 5000 rows of data. If anyone figured out how to change this, please let me know. In the meantime, the work around is to pull only a few units/depts at a time to limit the number of rows. This is fine at the moment, since each course admin are only responsible for certain units/depts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(prefix_certificate_issues.timecreated), &#039;%Y-%m-%d&#039; ) AS Date,&lt;br /&gt;
prefix_certificate_issues.classname AS Topic,&lt;br /&gt;
prefix_certificate.name AS Certificate,&lt;br /&gt;
prefix_certificate_issues.studentname as Name,&lt;br /&gt;
prefix_user_info_data.data AS Units&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_certificate_issues&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_user_info_data&lt;br /&gt;
on prefix_certificate_issues.userid = prefix_user_info_data.userid&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_certificate&lt;br /&gt;
on prefix_certificate_issues.certificateid = prefix_certificate.id&lt;br /&gt;
&lt;br /&gt;
WHERE prefix_user_info_data.data=&#039;Unit 1&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 2&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 3&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY Units, Name, Topic ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== All Simple Certificates Earned in the Site===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 [http://www.mysqltutorial.org/mysql-date_format/ DATE_FORMAT] function.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
CONCAT (u.firstname, &#039; &#039;,u.lastname) As &#039;User&#039;,&lt;br /&gt;
c.fullname AS &#039;Course&#039;,&lt;br /&gt;
sc.name AS &#039;Certificate&#039;,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(sci.timecreated), &#039;%Y-%m-%d&#039; ) As &#039;Date Awarded&#039;&lt;br /&gt;
# sci.code &#039;CertificateId&#039;&lt;br /&gt;
FROM prefix_simplecertificate_issues sci&lt;br /&gt;
JOIN prefix_user u ON sci.userid = u.id&lt;br /&gt;
JOIN prefix_simplecertificate sc ON sci.certificateid = sc.id&lt;br /&gt;
JOIN prefix_course AS c ON sc.course = c.id&lt;br /&gt;
ORDER BY sci.timecreated DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE DATEDIFF(NOW(),FROM_UNIXTIME(sci.timecreated) ) &amp;lt; 30&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Counter Blog usage in Courses,system wide===&lt;br /&gt;
What teachers in what courses, uses blogs and how many + student count in that course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT ( @counter := @counter+1) as counter, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c, (SELECT @counter := 0) as s_init&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Blogs &amp;gt; 0&lt;br /&gt;
ORDER BY Blogs DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Elluminate (Blackboard Collaborate) - system wide usage===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT e.name As Session ,er.recordingsize&lt;br /&gt;
,c.fullname As Course&lt;br /&gt;
,u.firstname,u.lastname &lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(e.timestart),&#039;%d-%m-%Y&#039;) AS dTimeStart&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/moodle/mod/elluminate/loadrecording.php?id=&#039;,er.id,&#039;&amp;quot;&amp;gt;Show&amp;lt;/a&amp;gt;&#039;) AS RecordedSession&lt;br /&gt;
&lt;br /&gt;
FROM prefix_elluminate_recordings AS er&lt;br /&gt;
JOIN prefix_elluminate AS e ON e.meetingid = er.meetingid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = e.creator &lt;br /&gt;
ORDER BY er.recordingsize DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choice ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Results of the Choice activity. For all courses, shows course shortname, username, the Choice text, and the answer chosen by the user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname AS course, u.username, h.name as question, o.text AS answer&lt;br /&gt;
FROM prefix_choice AS h&lt;br /&gt;
JOIN prefix_course AS c ON h.course = c.id&lt;br /&gt;
JOIN prefix_choice_answers AS a ON h.id = a.choiceid&lt;br /&gt;
JOIN prefix_user AS u ON a.userid = u.id&lt;br /&gt;
JOIN prefix_choice_options AS o ON a.optionid = o.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment type usage in courses ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assign/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_assign WHERE c.id = course) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;file&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
#GROUP BY apc.plugin&lt;br /&gt;
) AS &amp;quot;File Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;onlinetext&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Online Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;pdf&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;PDF Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;offline&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Offline Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;comments&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Assignments Comments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_assign AS assign&lt;br /&gt;
JOIN prefix_course AS c ON c.id = assign.course&lt;br /&gt;
GROUP BY c.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Assignment Module Reports==&lt;br /&gt;
===All Ungraded Assignments===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
Returns all the submitted assignments that still need grading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id&lt;br /&gt;
and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Ungraded Assignments w/ Link===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;a href=&amp;quot;http://education.varonis.com/mod/assignment/submissions.php&#039; + char(63) +&lt;br /&gt;
+ &#039;id=&#039; + cast(cm.id as varchar) + &#039;&amp;amp;userid=&#039; + cast(u.id as varchar) &lt;br /&gt;
+ &#039;&amp;amp;mode=single&amp;amp;filter=0&amp;amp;offset=2&amp;quot;&amp;gt;&#039; + a.name + &#039;&amp;lt;/a&amp;gt;&#039;&lt;br /&gt;
AS &amp;quot;Assignmentlink&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments (and Quizzes) waiting to be graded===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This report requires a YEAR filter to be added (Available when using the latest block/configurable_reports)&lt;br /&gt;
&lt;br /&gt;
Which you can always remove, to make this query work on earlier versions.&lt;br /&gt;
&lt;br /&gt;
The report includes: &lt;br /&gt;
*number of quizzes&lt;br /&gt;
*unFinished Quiz attempts&lt;br /&gt;
*Finished Quiz attempts&lt;br /&gt;
*number of students&lt;br /&gt;
*number of Assignments&lt;br /&gt;
*number of submitted answers by students &lt;br /&gt;
*number of unchecked assignments (waiting for the Teacher) in a Course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
 &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assignment/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;מטלות&amp;lt;/a&amp;gt;&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;בחנים&amp;lt;/a&amp;gt;&#039;) AS &#039;Quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_course_modules cm &lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module &lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039; AND cm.course = c.id &lt;br /&gt;
GROUP BY cm.course &lt;br /&gt;
) AS &#039;nQuizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish = 0&lt;br /&gt;
GROUP BY q.course) AS &#039;unFinished Quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish &amp;gt; 0&lt;br /&gt;
GROUP BY q.course) AS &#039;finished quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS nStudents&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(a.id)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) nAssignments&lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE a.course = c.id AND FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course&lt;br /&gt;
) &#039;Open &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(ROUND( (100 / iAssignments ) * iOpenAssignments ) ,&#039;%&#039;) &#039;unFinished &amp;lt;br/&amp;gt;Assignments &amp;lt;br/&amp;gt;(percent)&#039;&lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE asb.grade &amp;lt; 0 AND cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;unChecked  &amp;lt;br/&amp;gt;Submissions&#039; &lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;Submitted  &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblAssignmentsCount ON tblAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iOpenAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblOpenAssignmentsCount ON tblOpenAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1  &lt;br /&gt;
#AND c.fullname LIKE &#039;%תשעג%&#039;&lt;br /&gt;
%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
ORDER BY &#039;Open &amp;lt;br/&amp;gt;Assignments&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rubrics without zero values in criteria===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
Rubric calculations in Moodle can fail to align with instructors expectations if they lack a zero value for each criterion used in the assessment. From documentation at https://docs.moodle.org/32/en/Rubrics#Grade_calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;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.&lt;br /&gt;
TIP: To avoid confusion from this sort of thing, we recommend including a level with 0 points in every rubric criterion.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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&#039; favor.&lt;br /&gt;
&lt;br /&gt;
Includes search filter of course idnumber.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cat.name AS Department, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, &lt;br /&gt;
c.fullname AS Course_Name, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/grading/form/rubric/edit.php&#039;,CHAR(63),&#039;areaid=&#039;,gd.areaid,&#039;&amp;quot;&amp;gt;&#039;,gd.areaid,&#039;&amp;lt;/a&amp;gt;&#039;) AS Rubric&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_categories AS cat &lt;br /&gt;
ON cat.id = c.category&lt;br /&gt;
JOIN prefix_course_modules AS cm &lt;br /&gt;
ON c.id=cm.course&lt;br /&gt;
JOIN prefix_context AS ctx &lt;br /&gt;
ON cm.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_grading_areas AS garea &lt;br /&gt;
ON ctx.id = garea.contextid&lt;br /&gt;
JOIN prefix_grading_definitions AS gd &lt;br /&gt;
ON garea.id = gd.areaid&lt;br /&gt;
JOIN prefix_gradingform_rubric_criteria AS crit &lt;br /&gt;
ON gd.id = crit.definitionid&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id&lt;br /&gt;
WHERE cm.visible=&#039;1&#039; AND garea.activemethod = &#039;rubric&#039; AND (crit.id NOT IN&lt;br /&gt;
(SELECT crit.id&lt;br /&gt;
FROM prefix_gradingform_rubric_criteria AS crit&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id WHERE levels.score = &#039;0&#039;))&lt;br /&gt;
&lt;br /&gt;
GROUP BY Rubric&lt;br /&gt;
ORDER BY Course_ID, Rubric&lt;br /&gt;
&lt;br /&gt;
%%FILTER_SEARCHTEXT:c.idnumber:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Who is using &amp;quot;Single File Upload&amp;quot; assignment===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,ass.name as &amp;quot;Assignment Name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM &lt;br /&gt;
prefix_assignment as ass&lt;br /&gt;
&lt;br /&gt;
JOIN &lt;br /&gt;
prefix_course as c ON c.id = ass.course&lt;br /&gt;
&lt;br /&gt;
WHERE `assignmenttype` LIKE &#039;uploadsingle&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Feedback Module Reports==&lt;br /&gt;
===List the answers to all the Feedback activities within the current course, submitted by the current user===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT /* crs.fullname as &amp;quot;Course name&amp;quot;, f.name AS &amp;quot;Journal name&amp;quot;, CONCAT(u.firstname,&#039; &#039;,UPPER(u.lastname)) as &amp;quot;Participant&amp;quot;, */ /* include these fields if you want to check the composition of the recordset */&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified),&#039;%W %e %M, %Y&#039;) as &amp;quot;Answer Date&amp;quot;,&lt;br /&gt;
CASE i.typ WHEN &#039;label&#039; THEN i.presentation ELSE i.name END as &amp;quot;Topic&amp;quot;,  /* usually labels are used as section titles, so you&#039;d want them present in the recordset */&lt;br /&gt;
v.value as &amp;quot;My Answer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback AS f&lt;br /&gt;
INNER JOIN prefix_course as crs on crs.id=f.course %%FILTER_COURSES:f.course%% &lt;br /&gt;
INNER JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
INNER JOIN prefix_feedback_completed AS c on f.id=c.feedback %%FILTER_COURSEUSER:c.userid%% &lt;br /&gt;
LEFT JOIN prefix_feedback_value AS v on v.completed=c.id AND v.item=i.id&lt;br /&gt;
INNER JOIN prefix_user AS u on c.userid=u.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%% AND u.id = %%USERID%%  AND c.anonymous_response = 1  /* This clause limits the recordset to the current course and the current user and includes/ excludes the anonymous responses as needed */&lt;br /&gt;
&lt;br /&gt;
ORDER BY f.id, c.timemodified, i.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show all Feedbacks from all courses for all users including showing names of anonymous users===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &#039;Not-logged-in&#039; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS Course, &lt;br /&gt;
f.name AS Feedback,&lt;br /&gt;
# i.id AS Itemid,&lt;br /&gt;
i.name AS Itemname,&lt;br /&gt;
i.label AS Itemlabel,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN f.anonymous = 1 AND u.id != 0 THEN CONCAT(u.username, &#039; :ANON&#039;)&lt;br /&gt;
 WHEN fc.userid = 0 THEN &#039;Not-logged-in&#039;&lt;br /&gt;
 ELSE u.username&lt;br /&gt;
END AS &#039;User&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(fc.timemodified),&#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;Completed&amp;quot;,&lt;br /&gt;
v.value AS &amp;quot;Choice&amp;quot;,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN i.typ = &#039;multichoice&#039; THEN&lt;br /&gt;
     IF (  SUBSTRING(i.presentation,1,6)=&#039;d&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&#039;,&lt;br /&gt;
	       SUBSTRING(i.presentation,7),&lt;br /&gt;
		   i.presentation)&lt;br /&gt;
 ELSE i.presentation&lt;br /&gt;
END AS &amp;quot;Answers&amp;quot;,&lt;br /&gt;
i.typ,&lt;br /&gt;
i.dependitem,&lt;br /&gt;
i.dependvalue&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback f&lt;br /&gt;
JOIN prefix_course c ON c.id=f.course &lt;br /&gt;
JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
JOIN prefix_feedback_completed fc ON f.id=fc.feedback&lt;br /&gt;
LEFT JOIN prefix_feedback_value v ON v.completed=fc.id AND v.item=i.id&lt;br /&gt;
LEFT JOIN prefix_user AS u ON fc.userid=u.id&lt;br /&gt;
WHERE i.typ != &#039;pagebreak&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Resource Module Reports==&lt;br /&gt;
===List &amp;quot;Recently uploaded files&amp;quot;===&lt;br /&gt;
see what users are uploading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT FROM_UNIXTIME(time,&#039;%Y %M %D %h:%i:%s&#039;) as time ,ip,userid,url,info  &lt;br /&gt;
FROM `prefix_log` &lt;br /&gt;
WHERE `action` LIKE &#039;upload&#039; &lt;br /&gt;
ORDER BY `prefix_log`.`time`  DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Courses that loaded a specific file: &amp;quot;X&amp;quot;===&lt;br /&gt;
Did the Teacher (probably) uploaded course&#039;s Syllabus ?&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname  FROM `prefix_log` as l &lt;br /&gt;
JOIN prefix_course as c ON c.id = l.course &lt;br /&gt;
WHERE `action` LIKE &#039;%upload%&#039; AND ( info LIKE &#039;%Syllabus%&#039; OR info LIKE &#039;%Sylabus%&#039; ) GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All resources that link to some specific external website===&lt;br /&gt;
+ link to course&lt;br /&gt;
+ who&#039;s the teacher&lt;br /&gt;
+ link to external resource&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/resource/view.php?id=&#039;,r.id,&#039;&amp;quot;&amp;gt;&#039;,r.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Resource&lt;br /&gt;
FROM prefix_resource AS r &lt;br /&gt;
JOIN prefix_course AS c ON r.course = c.id&lt;br /&gt;
WHERE r.reference LIKE &#039;http://info.oranim.ac.il/home%&#039; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;quot;Compose Web Page&amp;quot; RESOURCE count===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT course,prefix_course.fullname, COUNT(*) AS Total&lt;br /&gt;
FROM `prefix_resource`&lt;br /&gt;
JOIN `prefix_course` ON prefix_course.id = prefix_resource.course&lt;br /&gt;
WHERE type=&#039;html&#039;&lt;br /&gt;
GROUP BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resource count in courses===&lt;br /&gt;
+ (First)Teacher name&lt;br /&gt;
+ Where course is inside some specific Categories&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
COUNT(*) AS count&lt;br /&gt;
,r.course &lt;br /&gt;
,c.shortname shortname&lt;br /&gt;
,c.fullname coursename&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user as u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = r.course AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
FROM prefix_resource r &lt;br /&gt;
JOIN prefix_course c ON r.course = c.id&lt;br /&gt;
WHERE c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY r.course&lt;br /&gt;
ORDER BY COUNT(*) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Delete all the automated backup files===&lt;br /&gt;
Prepare bash cli script to delete all the automated backup files on the file system. (clean up some disk space)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT( &#039;rm -f /var/moodledatanew/filedir/&#039;, SUBSTRING( contenthash, 1, 2 ) , &#039;/&#039;, SUBSTRING( contenthash, 3, 2 ) , &#039;/&#039;, contenthash ) &lt;br /&gt;
FROM `mdl_files` &lt;br /&gt;
WHERE `filename` LIKE &#039;%mbz%&#039;&lt;br /&gt;
AND filearea = &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find out how much disk space is used by all automated backup files:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT SUM(filesize)/(1024*1024*1024) FROM `mdl_files` WHERE  `filename` LIKE &#039;%mbz%&#039; AND filearea =  &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Forum Module Reports==&lt;br /&gt;
===print all User&#039;s post in course Forums===&lt;br /&gt;
%%COURSEID%% is a variable the is replace by the current CourseID you are running the sql report from. if you are using the latest block/configurable_reports ! (You can always change it to a fixed course or remove it to display all courses.)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php?course=&#039;,c.id,&#039;&amp;amp;id=&#039;,u.id,&#039;&amp;amp;mode=posts&amp;quot;&amp;gt;&#039;,CONCAT(u.firstname,&#039; &#039;, u.lastname),&#039;&amp;lt;/a&amp;gt;&#039;) As Fullname&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Forum&lt;br /&gt;
,count(*) as Posts&lt;br /&gt;
,(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&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_user as u ON u.id = fp.userid &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = fd.course &lt;br /&gt;
WHERE fd.course = %%COURSEID%% &lt;br /&gt;
GROUP BY f.id,u.id&lt;br /&gt;
ORDER BY u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE by type -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, prefix_forum.type, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course,prefix_forum.type&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Forum activity - system wide===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,c.fullname as Course&lt;br /&gt;
,f.type&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
, fd.forum, f.name,count(*) AS cPostAndDisc&lt;br /&gt;
,(SELECT count(*) FROM prefix_forum_discussions AS ifd WHERE ifd.forum = f.id) AS cDiscussion&lt;br /&gt;
FROM prefix_forum_posts AS fp&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type != &#039;news&#039; AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
## WHERE 1=1 &lt;br /&gt;
## %%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count( * ) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Activity In Forums===&lt;br /&gt;
Trying to figure out how much real activity we have in Forums by aggregating:&lt;br /&gt;
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...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname,f.name,f.type &lt;br /&gt;
,(SELECT count(id) FROM prefix_forum_discussions as fd WHERE f.id = fd.forum) as Discussions&lt;br /&gt;
,(SELECT count(distinct fd.userid) FROM prefix_forum_discussions as fd WHERE fd.forum = f.id) as UniqueUsersDiscussions&lt;br /&gt;
,(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&lt;br /&gt;
,(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&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS StudentsCount&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Teachers&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS &#039;Teacher&amp;lt;br/&amp;gt;Count&#039;&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid IN (3,5)&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS UserCount&lt;br /&gt;
, (SELECT (UniqueUsersDiscussions / StudentsCount )) as StudentDissUsage&lt;br /&gt;
, (SELECT (UniqueUsersPosts /StudentsCount)) as StudentPostUsage&lt;br /&gt;
FROM prefix_forum as f &lt;br /&gt;
JOIN prefix_course as c ON f.course = c.id&lt;br /&gt;
WHERE `type` != &#039;news&#039;&lt;br /&gt;
ORDER BY StudentPostUsage DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Forum type:NEWS===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT f.id, f.name&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
WHERE m.name = &#039;forum&#039;&lt;br /&gt;
AND f.type = &#039;news&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All new forum NEWS items (discussions) from all my Courses===&lt;br /&gt;
change &amp;quot;userid = 26&amp;quot; and &amp;quot;id = 26&amp;quot; to a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname,f.name,fd.name,FROM_UNIXTIME(fd.timemodified ,&amp;quot;%d %M %Y &amp;quot;) as Date&lt;br /&gt;
FROM prefix_forum_discussions as fd &lt;br /&gt;
JOIN prefix_forum as f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = f.course &lt;br /&gt;
JOIN prefix_user_lastaccess as ul ON (c.id = ul.courseid AND ul.userid = 26)&lt;br /&gt;
WHERE fd.timemodified &amp;gt; ul.timeaccess  &lt;br /&gt;
 AND fd.forum IN (SELECT f.id&lt;br /&gt;
 FROM prefix_course_modules AS cm&lt;br /&gt;
 JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
 JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
 WHERE m.name = &#039;forum&#039;&lt;br /&gt;
 AND f.type = &#039;news&#039;)&lt;br /&gt;
  AND c.id IN (SELECT c.id&lt;br /&gt;
   FROM prefix_course AS c&lt;br /&gt;
   JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
   JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
   JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
   WHERE u.id = 26) ORDER BY `fd`.`timemodified` DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===News Forum - Discussions COUNT===&lt;br /&gt;
Which is actually... How much instructions students get from their teachers&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname ,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,count(fd.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS DiscussionsSum&lt;br /&gt;
FROM prefix_forum_discussions AS fd&lt;br /&gt;
INNER JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
INNER JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type = &#039;news&#039; AND c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count(fd.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cantidad de foros que han sido posteados por profesor===&lt;br /&gt;
&lt;br /&gt;
(Number of forums that have been posted by teacher/Google translator)&lt;br /&gt;
&lt;br /&gt;
Queriamos saber cuales son las acciones del profesor dentro de los foros de cada curso, por ello se hizo este informe.&lt;br /&gt;
&lt;br /&gt;
(We wanted to know what the teacher&#039;s actions are in the forums of each course, so this report was made. /Google translator)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS curso,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Facilitador,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( m.name ) AS COUNT FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS foros,&lt;br /&gt;
&lt;br /&gt;
COUNT(*) AS Posts&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course AS c ON c.id = fd.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = fp.userid &lt;br /&gt;
&lt;br /&gt;
WHERE fp.userid =&lt;br /&gt;
(&lt;br /&gt;
select distinct prefix_user.id&lt;br /&gt;
from prefix_user &lt;br /&gt;
join prefix_role_assignments as ra on ra.userid = prefix_user.id &lt;br /&gt;
where ra.roleid = 3 &lt;br /&gt;
and userid = fp.userid&lt;br /&gt;
limit 1&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
and c.shortname like &#039;%2014-2-1%&#039;&lt;br /&gt;
GROUP BY c.id, u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all the Forums that got high rating===&lt;br /&gt;
We setup a scale that let teachers and students Rate forum post with &amp;quot;Important, interesting, valuable, not rated&amp;quot; scale&lt;br /&gt;
And then add a link to the following report at the begining of the course &amp;quot;Link to all interesting posts&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,f.id,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;,fd.id,&#039;#p&#039;,fp.id,&#039;&amp;quot;&amp;gt;&#039;,fp.subject,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post link&#039;,&lt;br /&gt;
SUM(r.rating) AS &#039;Rating&#039;&lt;br /&gt;
FROM mdl_rating AS r&lt;br /&gt;
  JOIN mdl_forum_posts AS fp ON fp.id = r.itemid&lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
WHERE r.component = &#039;mod_forum&#039; AND r.ratingarea = &#039;post&#039; AND f.course = %%COURSEID%%&lt;br /&gt;
GROUP BY r.itemid&lt;br /&gt;
ORDER BY SUM(r.rating) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all Discussions of a single Forum===&lt;br /&gt;
This report is used to help export all the student&#039;s posts and discussions of a single forum, by passing the context module id as a parameter to the report using &amp;quot;&amp;amp;filter_var=cmid&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;, f.id, &#039;&amp;quot;&amp;gt;&#039;, f.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name&#039;,&lt;br /&gt;
fd.name AS &#039;Discussion&#039;, &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;, fd.id, &#039;#p&#039;, fp.id, &#039;&amp;quot;&amp;gt;&#039;, fp.subject, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post (link)&#039;,&lt;br /&gt;
fp.message&lt;br /&gt;
&lt;br /&gt;
FROM mdl_forum_posts AS fp &lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
  JOIN mdl_course_modules AS cm ON cm.module = 9 AND cm.instance = f.id&lt;br /&gt;
WHERE cm.id = %%FILTER_VAR%%&lt;br /&gt;
ORDER BY f.id, fd.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Quiz Module Reports==&lt;br /&gt;
===Generate a list of instructors and their email addresses for those courses that has &amp;quot;essay questions&amp;quot; in their quizzes===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT qu.id AS quiz_id, qu.course AS course_id, qu.questions,&lt;br /&gt;
                co.fullname AS course_fullname, co.shortname AS course_shortname,&lt;br /&gt;
                qu.name AS quiz_name, FROM_UNIXTIME(qu.timeopen) AS quiz_timeopen, FROM_UNIXTIME(qu.timeclose) AS quiz_timeclose,&lt;br /&gt;
                u.firstname, u.lastname, u.email,&lt;br /&gt;
FROM prefix_quiz qu, prefix_course co, prefix_role re, prefix_context ct, prefix_role_assignments ra, prefix_user u&lt;br /&gt;
WHERE FROM_UNIXTIME(timeopen) &amp;gt; &#039;2008-05-14&#039; AND&lt;br /&gt;
                qu.course = co.id AND&lt;br /&gt;
                co.id = ct.instanceid AND&lt;br /&gt;
                ra.roleid = re.id AND&lt;br /&gt;
                re.name = &#039;Teacher&#039; AND&lt;br /&gt;
                ra.contextid = ct.id AND&lt;br /&gt;
                ra.userid = u.id&lt;br /&gt;
 &lt;br /&gt;
SELECT Count(&#039;x&#039;) As NumOfStudents&lt;br /&gt;
                                FROM prefix_role_assignments a&lt;br /&gt;
                                JOIN prefix_user u ON userid = u.id&lt;br /&gt;
                                WHERE roleid = 5 AND contextid = (SELECT id FROM prefix_context WHERE instanceid = 668 AND contextlevel = 50)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Number of Quizes per Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Link&amp;lt;/a&amp;gt;&#039;) AS Quizes&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules cm&lt;br /&gt;
JOIN prefix_course c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module&lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039;&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all MultiAnswer (Cloze) Questions===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/attempt.php?q=&#039;, quiz.id, &#039;&amp;quot;&amp;gt;&#039;, quiz.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS Quiz&lt;br /&gt;
,question.id question_id, question.questiontext &lt;br /&gt;
FROM  prefix_question question&lt;br /&gt;
JOIN prefix_quiz_question_instances qqi ON question.id = qqi.question&lt;br /&gt;
JOIN prefix_quiz quiz ON qqi.quiz = quiz.id&lt;br /&gt;
WHERE  `qtype` LIKE  &#039;multianswer&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List courses with MANUAL grades===&lt;br /&gt;
Which is basically and indication to teachers using Moodle to hold offline grades inside Moodle&#039;s Gradebook,&lt;br /&gt;
So grades could be uploaded into an administrative SIS. Use with Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT( * )&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php?showadvanced=1&amp;amp;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM  prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course as c ON c.id = gi.courseid&lt;br /&gt;
WHERE  `itemtype` =  &#039;manual&#039;&lt;br /&gt;
GROUP BY courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===List the users that did not took the Quiz===&lt;br /&gt;
Do not forget to change &amp;quot;c.id = 14&amp;quot; and q.name LIKE &#039;%quiz name goes here%&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id AS ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.username AS IDNumber,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
 &lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id AND courseid=c.id) AS CourseLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id AND e.courseid = c.id) AS RoleName&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess AS ul ON ul.userid = user2.id&lt;br /&gt;
WHERE c.id=14 and ue.userid NOT IN (SELECT qa.userid FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON qa.quiz = q.id&lt;br /&gt;
JOIN prefix_course AS c ON q.course = c.id&lt;br /&gt;
WHERE c.id = 14 AND q.name LIKE &#039;%quiz name goes here%&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List Questions in each Quiz===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT quiz.id,quiz.name, q.id, q.name&lt;br /&gt;
FROM mdl_quiz AS quiz&lt;br /&gt;
JOIN mdl_question AS q ON FIND_IN_SET(q.id, quiz.questions)&lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
ORDER BY quiz.id ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this query does not work in Moodle 2.8. There is no mdl_quiz.questions field. It will need to be rewritten to use the usage/contextid organization.&lt;br /&gt;
&lt;br /&gt;
===Quiz activity research===&lt;br /&gt;
This report was made to extract student full activity in quizzes for an academic research about adapting instructional design teaching methods in online learning. The students do not use the Quiz module as a standard quiz but more as Study booklets or mini courses with embedded questions and hints to assist students evaluate their progress (Similar to what you expect to find in a SCORM activity)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cm.course &amp;quot;course_id&amp;quot;, cm.id &amp;quot;moduel_id&amp;quot;, q.id &amp;quot;quiz_id&amp;quot;, q.name &amp;quot;quiz_name&amp;quot;,&lt;br /&gt;
 &lt;br /&gt;
CASE q.grademethod&lt;br /&gt;
      WHEN 1 THEN &amp;quot;GRADEHIGHEST&amp;quot;&lt;br /&gt;
      WHEN 2 THEN &amp;quot;GRADEAVERAGE&amp;quot;&lt;br /&gt;
      WHEN 3 THEN &amp;quot;ATTEMPTFIRST&amp;quot;&lt;br /&gt;
      WHEN 4 THEN &amp;quot;ATTEMPTLAST&amp;quot;&lt;br /&gt;
END &amp;quot;grade method&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
, q.attempts &amp;quot;quiz_attempts_allowed&amp;quot;, cm.groupmode &amp;quot;group_mode&amp;quot;&lt;br /&gt;
, qa.id &amp;quot;attempt_id&amp;quot;, qa.state &amp;quot;attempt_state&amp;quot;, qa.sumgrades &amp;quot;attempt_grade&amp;quot;, qg.grade &amp;quot;user_final_grade&amp;quot;, q.grade &amp;quot;quiz_max_grade&amp;quot;&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = q.course AND m.userid = u.id) &amp;quot;user_groups&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timestart), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_start&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timefinish), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_finish&amp;quot;,&lt;br /&gt;
u.id &amp;quot;user_id&amp;quot;, u.firstname, u.lastname,&lt;br /&gt;
question.id &amp;quot;question_id&amp;quot;, question.name &amp;quot;question_name&amp;quot;,&lt;br /&gt;
qas.state &amp;quot;question_step_state&amp;quot;,qas.fraction &amp;quot;question_grade&amp;quot;, qh.hint, question.qtype &amp;quot;question_type&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz as q&lt;br /&gt;
JOIN mdl_course_modules as cm ON cm.instance = q.id and cm.module = 14 &lt;br /&gt;
JOIN mdl_quiz_attempts qa ON q.id = qa.quiz&lt;br /&gt;
LEFT JOIN mdl_quiz_grades as qg ON qg.quiz = q.id and qg.userid = qa.userid&lt;br /&gt;
JOIN mdl_user as u ON u.id = qa.userid&lt;br /&gt;
JOIN mdl_question_usages as qu ON qu.id = qa.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts as qatt ON qatt.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question as question ON question.id = qatt.questionid&lt;br /&gt;
JOIN mdl_question_attempt_steps as qas ON qas.questionattemptid = qatt.id&lt;br /&gt;
LEFT JOIN mdl_question_hints as qh ON qh.questionid = q.id&lt;br /&gt;
#WHERE q.id = &amp;quot;SOME QUIZ ID&amp;quot;&lt;br /&gt;
WHERE cm.course = &amp;quot;SOME COURSE ID&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quiz Usage in Courses by Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Multiple Choice&amp;quot; questions include true/false and matching question types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Short Answer&amp;quot; are questions that accept a single phrase.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Other&amp;quot; questions include fixed numerical, calculated, essay, and various drag and drop types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Min Quiz Age&amp;quot; and &amp;quot;Max Quiz Age&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: In Configurable Reports, the Date Filter is not applied until the &amp;quot;Apply&amp;quot; button is clicked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.shortname AS &#039;Course&#039;&lt;br /&gt;
#, u.lastname AS &#039;Instructor&#039;&lt;br /&gt;
, COUNT(DISTINCT q.id) AS &#039;Quizzes&#039;&lt;br /&gt;
, COUNT(DISTINCT qu.id) AS &#039;Questions&#039;&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 ))  AS &#039;multichoice&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT( qu.id) - SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;Other&#039;&lt;br /&gt;
&lt;br /&gt;
, (SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )))/COUNT( qu.id) AS &#039;Percent MC&#039;&lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;numerical&#039;, 1, 0 )) AS &#039;numerical&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype LIKE &#039;calc%&#039;, 1, 0 )) AS &#039;calculated&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;random&#039;, 1, 0 )) AS &#039;random&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;essay&#039;, 1, 0 )) AS &#039;essay&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, IF(q.shufflequestions &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Questions&#039;&lt;br /&gt;
, IF(q.shuffleanswers &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Answers&#039;&lt;br /&gt;
 &lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
#, FROM_UNIXTIME(MIN(q.timemodified)) AS &#039;Last Modified&#039;&lt;br /&gt;
&lt;br /&gt;
#, DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(MIN(q.timemodified))) AS &#039;Quiz age&#039;&lt;br /&gt;
&lt;br /&gt;
, MIN(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Min Quiz Age&#039; &lt;br /&gt;
, MAX(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Max Quiz Age&#039; &lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified)) &amp;lt; 90, 1,0)) AS &#039;new quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_quiz AS q&lt;br /&gt;
JOIN prefix_course AS c on c.id = q.course&lt;br /&gt;
JOIN prefix_quiz_question_instances AS qqi ON qqi.quiz = q.id&lt;br /&gt;
LEFT JOIN prefix_question AS qu ON qu.id = qqi.question&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%% %%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student responses (answers) to quiz questions===&lt;br /&gt;
(Contributed by Juan F with help from Tim hunt and fellow Moodlers on the forums)&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    concat( u.firstname, &amp;quot; &amp;quot;, u.lastname ) AS &amp;quot;Student Name&amp;quot;,&lt;br /&gt;
    u.id,&lt;br /&gt;
    quiza.userid,&lt;br /&gt;
    q.course,&lt;br /&gt;
    q.name,&lt;br /&gt;
    quiza.attempt,&lt;br /&gt;
    qa.slot,&lt;br /&gt;
    que.questiontext AS &#039;Question&#039;,&lt;br /&gt;
    qa.rightanswer AS &#039;Correct Answer&#039;,&lt;br /&gt;
    qa.responsesummary AS &#039;Student Answer&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz_attempts quiza&lt;br /&gt;
JOIN mdl_quiz q ON q.id=quiza.quiz&lt;br /&gt;
JOIN mdl_question_usages qu ON qu.id = quiza.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts qa ON qa.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question que ON que.id = qa.questionid&lt;br /&gt;
JOIN mdl_user u ON u.id = quiza.userid&lt;br /&gt;
&lt;br /&gt;
WHERE q.name = &amp;quot;BIO 208 Post Test Assessment&amp;quot;&lt;br /&gt;
AND q.course = &amp;quot;17926&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ORDER BY quiza.userid, quiza.attempt, qa.slot&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==SCORM Activity Reports==&lt;br /&gt;
&lt;br /&gt;
===Lists All completed SCORM activites by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists SCORM status for all enrolled users by Course name===&lt;br /&gt;
This report will list the SCORM status for all users enrolled in the course. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. This can be limited to individual courses by adding to the where clause the course id to report on.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.firstname AS First,&lt;br /&gt;
u.lastname AS Last, &lt;br /&gt;
u.idnumber AS Employee_ID,  &lt;br /&gt;
u.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
u.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course, &lt;br /&gt;
st.attempt AS Attempt,&lt;br /&gt;
st.value AS Status,&lt;br /&gt;
FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) AS Date &lt;br /&gt;
&lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
&lt;br /&gt;
WHERE st.element=&#039;cmi.core.lesson_status&#039; AND m.userid=u.id&lt;br /&gt;
&lt;br /&gt;
UNION&lt;br /&gt;
&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS First,&lt;br /&gt;
user2.lastname AS Last,&lt;br /&gt;
user2. idnumber AS Employee_ID,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
user2.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Attempt,&lt;br /&gt;
&amp;quot;not_started&amp;quot; AS Status,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Date&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = user2.id &lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.course=c.id&lt;br /&gt;
Left Join prefix_scorm_scoes_track AS st on st.scormid=sc.id AND st.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
WHERE  st.timemodified IS NULL AND m.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY  Course, Last, First, Attempt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Badges==&lt;br /&gt;
&lt;br /&gt;
=== All badges issued, by User ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, b.name AS badgename, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN&lt;br /&gt;
(SELECT c.shortname&lt;br /&gt;
    FROM prefix_course AS c&lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Context,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 1 THEN &amp;quot;Activity Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 2 THEN &amp;quot;Activity Completion (Any)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 2 AND t.method = 2 THEN &amp;quot;Manual Award&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 1 THEN &amp;quot;Course Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 2 THEN &amp;quot;Course Completion (Any)&amp;quot;&lt;br /&gt;
  ELSE CONCAT (&#039;Other: &#039;, t.criteriatype)&lt;br /&gt;
END AS Criteriatype,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateissued ) , &#039;%Y-%m-%d&#039; ) AS dateissued,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateexpire ), &#039;%Y-%m-%d&#039; ) AS dateexpires,&lt;br /&gt;
CONCAT (&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/badge.php?hash=&#039;,d.uniquehash,&#039;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&#039;) AS Details&lt;br /&gt;
FROM prefix_badge_issued AS d &lt;br /&gt;
JOIN prefix_badge AS b ON d.badgeid = b.id&lt;br /&gt;
JOIN prefix_user AS u ON d.userid = u.id&lt;br /&gt;
JOIN prefix_badge_criteria AS t on b.id = t.badgeid &lt;br /&gt;
WHERE t.criteriatype &amp;lt;&amp;gt; 0&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&lt;br /&gt;
=== All badges available in the system, with Earned count ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.type = 1 THEN &amp;quot;System&amp;quot;&lt;br /&gt;
WHEN b.type = 2 THEN &amp;quot;Course&amp;quot;&lt;br /&gt;
END AS Context, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN &lt;br /&gt;
(SELECT c.shortname &lt;br /&gt;
    FROM prefix_course AS c &lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 2 THEN &amp;quot;No&amp;quot;&lt;br /&gt;
WHEN b.status = 1 OR b.status = 3 THEN &amp;quot;Yes&amp;quot;&lt;br /&gt;
WHEN b.status = 4 THEN &amp;quot;x&amp;quot;&lt;br /&gt;
END AS Available,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 1 THEN &amp;quot;0&amp;quot;&lt;br /&gt;
WHEN b.status = 2 OR b.status = 3 OR b.status = 4 THEN &lt;br /&gt;
 (SELECT COUNT(*) &lt;br /&gt;
   FROM prefix_badge_issued AS d&lt;br /&gt;
   WHERE d.badgeid = b.id&lt;br /&gt;
 )&lt;br /&gt;
END AS Earned&lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Badges Leaderboard ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A simple list of usernames and how many badges they have earned overall.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, (SELECT COUNT(*) FROM prefix_badge_issued AS d WHERE d.userid = u.id) AS earned&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
ORDER BY earned DESC, u.username ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Manage badges (System &amp;amp; Course) ===&lt;br /&gt;
&lt;br /&gt;
List system wide badges, course and system level badges + a link to relevant &amp;quot;manage badges&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description &lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN b.type = 1 THEN &#039;System&#039;&lt;br /&gt;
  WHEN b.type = 2 THEN &#039;Course&#039;&lt;br /&gt;
END AS Level&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/index.php?type=&#039;, b.type, &#039;&amp;amp;id=&#039;,&lt;br /&gt;
			  c.id, &#039;&amp;quot;&amp;gt;Manage badges in: &#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Manage &lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Administrator Reports==&lt;br /&gt;
&lt;br /&gt;
===Config changes in Export friendly form===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( g.timemodified ) , &#039;%Y-%m-%d&#039; ) AS date, &lt;br /&gt;
u.username AS user, &lt;br /&gt;
g.name AS setting, &lt;br /&gt;
CASE &lt;br /&gt;
 WHEN g.plugin IS NULL THEN &amp;quot;core&amp;quot;&lt;br /&gt;
 ELSE g.plugin&lt;br /&gt;
END AS plugin, &lt;br /&gt;
g.value AS new_value, &lt;br /&gt;
g.oldvalue AS original_value&lt;br /&gt;
FROM prefix_config_log  AS g&lt;br /&gt;
JOIN prefix_user AS u ON g.userid = u.id&lt;br /&gt;
ORDER BY date DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts by user===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
How to get a list of all users and which cohorts they belong to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, h.idnumber, h.name&lt;br /&gt;
FROM prefix_cohort AS h&lt;br /&gt;
JOIN prefix_cohort_members AS hm ON h.id = hm.cohortid&lt;br /&gt;
JOIN prefix_user AS u ON hm.userid = u.id&lt;br /&gt;
ORDER BY u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts with Courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all cohorts with name, id, visibility, and which courses they are enrolled in.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
# h.id,&lt;br /&gt;
# e.customint1,&lt;br /&gt;
h.name AS Cohort,&lt;br /&gt;
h.idnumber AS Cohortid,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN h.visible = 1 THEN &#039;Yes&#039;&lt;br /&gt;
 ELSE &#039;-&#039;&lt;br /&gt;
END AS Cohortvisible,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;, CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_cohort h&lt;br /&gt;
JOIN prefix_enrol e ON h.id = e.customint1&lt;br /&gt;
JOIN prefix_course c ON c.id = e.courseid %%FILTER_COURSES:e.courseid%% &lt;br /&gt;
WHERE e.enrol = &#039;cohort&#039; AND e.roleid = 5&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses created And Active courses by Year===&lt;br /&gt;
Active courses is counting course that have at least one Hit, And &amp;quot;Active_MoreThan100Hits&amp;quot; counts courses that have at least 100 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `timecreated` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT course ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY course &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 100) AS courses_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( courses_log.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan100Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_course` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users created And Active users by Year===&lt;br /&gt;
Active users is counting users that have at least one Hit, And &amp;quot;Active_MoreThan500Hits&amp;quot; counts users that have at least 500 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `firstaccess` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT userid ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY userid &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 500) AS users_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( users_log.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan500Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Aggregation Report===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In particular, be on the lookout for any courses with the following combinations of parameters, which are known to cause changes in calculations:&lt;br /&gt;
&lt;br /&gt;
# mean of grades set with aggregate with subcategory.&lt;br /&gt;
# Simple weighted mean of grades with aggregate with sub category and drop the lowest&lt;br /&gt;
# Sum of grades drop the lowest&lt;br /&gt;
&lt;br /&gt;
Also review:&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48618&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48634&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-49257&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50089&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50062&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
COUNT(c.shortname) AS &#039;Count of Courses&#039;&lt;br /&gt;
&lt;br /&gt;
# If you want to display all the courses for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, c.shortname AS &#039;course name&#039;&lt;br /&gt;
&lt;br /&gt;
# If you need to display grade categories for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, gc.fullname AS &#039;grade category name&#039;&lt;br /&gt;
&lt;br /&gt;
, gc.aggregation AS &#039;aggregation method&#039;&lt;br /&gt;
&lt;br /&gt;
#These aggregation text strings appear to be hard-coded. I couldn&#039;t find a table for them. If you have aggregation types I haven&#039;t included here, they&#039;ll be blank in your report results.&lt;br /&gt;
, CASE gc.aggregation&lt;br /&gt;
  WHEN 0 THEN &#039;Mean of Grades&#039;&lt;br /&gt;
  WHEN 2 THEN &#039;Median of Grades&#039;&lt;br /&gt;
  WHEN 6 THEN &#039;Highest Grade&#039;&lt;br /&gt;
  WHEN 8 THEN &#039;Mode of Grades&#039;&lt;br /&gt;
  WHEN 10 THEN &#039;Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 11 THEN &#039;Simple Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 12 THEN &#039;Mean of Grades (with extra credits)&#039;&lt;br /&gt;
  WHEN 13 THEN &#039;Sum of Grades&#039;&lt;br /&gt;
END AS &#039;aggregation name&#039;&lt;br /&gt;
&lt;br /&gt;
# Note that gc.aggregatesubcats column is eliminated in 2.8 and later per MDL-47503, so comment that line on updated systems or you&#039;ll get an error&lt;br /&gt;
, gc.keephigh AS &#039;keep high&#039;&lt;br /&gt;
, gc.droplow AS &#039;dr0p low&#039;&lt;br /&gt;
, gc.aggregateonlygraded AS &#039;Aggregate only graded&#039;&lt;br /&gt;
, gc.aggregateoutcomes AS &#039;aggregate outcomes&#039;&lt;br /&gt;
, gc.aggregatesubcats AS &#039;aggregate subcategories&#039;&lt;br /&gt;
&lt;br /&gt;
# If you are displaying data about individual courses, you may want to know how old they are&lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;course start date&#039;&lt;br /&gt;
&lt;br /&gt;
# 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&#039;ll need to uncomment the necessary JOINs below&lt;br /&gt;
#, gi.itemname AS &#039;grade item&#039;&lt;br /&gt;
#, gg.finalgrade AS &#039;final grade&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
&lt;br /&gt;
prefix_course AS c&lt;br /&gt;
JOIN prefix_grade_categories AS gc ON gc.courseid = c.id&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id #AND gi.categoryid=gc.id&lt;br /&gt;
#LEFT JOIN prefix_grade_grades AS gg ON gg.itemid = gi.id AND gg.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
#AND gc.aggregation = 13 #only the dreaded Sum of Grades aggregations&lt;br /&gt;
#AND gc.depth = 1 # if for some reason you only want course aggregations, not subcategories&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.aggregation, gc.keephigh, gc.droplow, gc.aggregateonlygraded, gc.aggregateoutcomes, gc.aggregatesubcats&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running Cron jobs (task_scheduled) ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT classname&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(lastruntime), &#039;%H:%i [%d]&#039;) AS &#039;last&#039;&lt;br /&gt;
  ,DATE_FORMAT(now(), &#039;%H:%i&#039;) AS &#039;now&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(nextruntime), &#039;%H:%i [%d]&#039;) AS &#039;next&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP()-nextruntime), &#039;%i&#039;) AS &#039;next in min&#039;&lt;br /&gt;
FROM mdl_task_scheduled&lt;br /&gt;
WHERE now() &amp;gt; FROM_UNIXTIME(nextruntime)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== All Meta courses with Parent and Child course relationships ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
This shows the list of courses with Meta course link enrollments in them (&#039;Parent course&#039;), and the courses which are connected to them to provide enrollments (&#039;Child courses&#039;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.fullname AS &#039;Parent course name&#039;,&lt;br /&gt;
c.shortname AS &#039;Parent course shortname&#039;,&lt;br /&gt;
en.courseid AS &#039;Parent course id&#039;,&lt;br /&gt;
(SELECT fullname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course name&#039;,&lt;br /&gt;
(SELECT shortname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course shortname&#039;,&lt;br /&gt;
en.customint1 AS &#039;Child course id&#039;&lt;br /&gt;
FROM prefix_enrol en&lt;br /&gt;
JOIN prefix_course c ON c.id = en.courseid&lt;br /&gt;
WHERE en.enrol = &#039;meta&#039;&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Useful sub queries ==&lt;br /&gt;
&lt;br /&gt;
IN this section please put any short one purpose sub queries that show how common procedures often useful as part of larger queries.&lt;br /&gt;
&lt;br /&gt;
=== All teachers in the course ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This snippet shows how to get teachers from a course. The contextevel for course objects is 50. And the default Teacher role is role id 3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course ic&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = ic.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND ic.id = c.id&lt;br /&gt;
GROUP BY ic.id&lt;br /&gt;
) AS TeacherNames&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Get custom User profile fields for a user ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON uid.fieldid = uif.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to limit it to one of those fields, you can restrict it by shortname of the custom profile field, so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;shortname1&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will show you only the data from the custom profile field with the shortname &#039;shortname1&#039;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, d1.data AS &#039;Profile One&#039;, d2.data As &#039;Profile Two&#039;&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
JOIN prefix_user_info_data d1 ON d1.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
JOIN prefix_user_info_data d2 ON d2.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f2 ON d2.fieldid = f2.id AND f2.shortname = &#039;shortname2&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== NOTE: Alternate Method ====&lt;br /&gt;
&lt;br /&gt;
If you have more than a couple of fields you need to use, then this query may time out or not return data due to too many joins. The limit seems to be around 10 custom profile fields. &lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thefirstfield&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname2&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thesecondfield&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== How to use Configurable Reports Date Time Filters===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Here is a simple example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.firstaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;FirstAccess&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.lastaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;LastAccess&#039;   &lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1&lt;br /&gt;
%%FILTER_STARTTIME:u.firstaccess:&amp;gt;%% &lt;br /&gt;
%%FILTER_ENDTIME:u.lastaccess:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2) You MUST then add the Start / End date filter on the Filters tab of the Report. If you don&#039;t, the report will still run, probably, but the filter will be ignored.&lt;br /&gt;
&lt;br /&gt;
Note: the WHERE 1=1 statement is a peculiarity of the filters in Config reports: if you don&#039;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.)&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
[https://github.com/jleyva/moodle-configurable_reports_repository Configurable Reports Repository on GitHub]&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;br /&gt;
&lt;br /&gt;
[[es:Reportes específicos hechos por usuarios]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Analytics_plugins&amp;diff=128693</id>
		<title>Analytics plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Analytics_plugins&amp;diff=128693"/>
		<updated>2017-08-29T19:53:48Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Tracking progress}}&lt;br /&gt;
Learning Analytics are any piece of information that can help an LMS user improve learning outcomes. Users include students, teachers, administrators and decision-makers.&lt;br /&gt;
&lt;br /&gt;
== Moodle Plugins ==&lt;br /&gt;
&lt;br /&gt;
There are a number of reports, blocks and other plugins for Moodle that provide learning analytics.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Plugin &lt;br /&gt;
! Plugin type&lt;br /&gt;
! Standard / Additional&lt;br /&gt;
! Useful for&lt;br /&gt;
! Description&lt;br /&gt;
! Reported usage*&lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Logs|Logs]]&lt;br /&gt;
| Report&lt;br /&gt;
| Standard&lt;br /&gt;
| Teachers, Admins, Decision-makers&lt;br /&gt;
| Filterable log of events&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 71.4%&lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Activity_report|Activity]]&lt;br /&gt;
| Report&lt;br /&gt;
| Standard&lt;br /&gt;
| Teachers&lt;br /&gt;
| View count of activities in course&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 69.1%&lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Using_Activity_completion|Activity completion]], see also [[:en:Using_Course_completion|Course completion]]&lt;br /&gt;
| Report&lt;br /&gt;
| Standard&lt;br /&gt;
| Teachers&lt;br /&gt;
| Completion matrix of students and activities&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 66.3%&lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Logs|Live logs]]&lt;br /&gt;
| Report&lt;br /&gt;
| Standard&lt;br /&gt;
| Teachers, Admins&lt;br /&gt;
| Automatically refreshing log of events&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 55.2% &lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Feedback_activity|Feedback]]&lt;br /&gt;
| Activity&lt;br /&gt;
| Standard&lt;br /&gt;
| Teachers, Researchers&lt;br /&gt;
| Configurable survey tool&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 59.5% &lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Quiz_statistics_report|(Quiz) Statistics]]&lt;br /&gt;
| Report&lt;br /&gt;
| Standard&lt;br /&gt;
| Teachers&lt;br /&gt;
| Student quiz performance report&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 53.0%&lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Participation_report|(Course) Participation]]&lt;br /&gt;
| Report&lt;br /&gt;
| Standard&lt;br /&gt;
| Teachers&lt;br /&gt;
| Single student&#039;s participation in course&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 49.9%&lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Survey_module|Survey]]&lt;br /&gt;
| Activity&lt;br /&gt;
| Standard&lt;br /&gt;
| Teachers, Researchers&lt;br /&gt;
| Set of standardised educational surveys&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 45.6%&lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Inspire|Inspire]]&lt;br /&gt;
| Administrative Tool&lt;br /&gt;
| Additional migrating to Standard&lt;br /&gt;
| Teachers, Researchers&lt;br /&gt;
| Moodle native descriptive and predictive learning analytics&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | n/a&lt;br /&gt;
|-&lt;br /&gt;
| [http://moodle.org/plugins/view.php?plugin=mod_questionnaire Questionnaire]&lt;br /&gt;
| Activity&lt;br /&gt;
| Additional&lt;br /&gt;
| Teachers, Researchers&lt;br /&gt;
| Configurable survey tool&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 45.3%&lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Course_overview_report|Course overview]]&lt;br /&gt;
| Report&lt;br /&gt;
| Standard&lt;br /&gt;
| Admins, Decision-makers&lt;br /&gt;
| Comparison of participation across multiple courses&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 45.0%&lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Course_completion_status_block|Course completion status]]&lt;br /&gt;
| Block&lt;br /&gt;
| Standard&lt;br /&gt;
| Students&lt;br /&gt;
| View of student&#039;s own completion of activities&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 41.4%&lt;br /&gt;
|-&lt;br /&gt;
| [http://moodle.org/plugins/view.php?plugin=block_progress Progress Bar]&lt;br /&gt;
| Block&lt;br /&gt;
| Additional&lt;br /&gt;
| Students, Teachers&lt;br /&gt;
| Time management tool for students with overview for teachers&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 32.0%&lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Events_list_report|Events list]]&lt;br /&gt;
| Report&lt;br /&gt;
| Standard&lt;br /&gt;
| Teachers, Admins&lt;br /&gt;
| Events that can be monitored/searched in logs&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 28.6%&lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Activity_results_block|Activity results block]]&lt;br /&gt;
| Block&lt;br /&gt;
| Standard&lt;br /&gt;
| Students&lt;br /&gt;
| Leader-board of results in single activity&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 26.1%&lt;br /&gt;
|-&lt;br /&gt;
| [http://moodle.org/plugins/view.php?id=82 Configurable Reports] &lt;br /&gt;
([https://docs.moodle.org/29/en/ad-hoc_contributed_reports A list of contributed reports])&lt;br /&gt;
| Block ([https://github.com/nadavkav/moodle-report_configurablereports Report] [https://github.com/nadavkav/moodle-filter_crgraph Graphs filter])&lt;br /&gt;
| Additional&lt;br /&gt;
| Teachers, Admins, Decision-makers&lt;br /&gt;
| Report generation and viewing&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | 22.7%&lt;br /&gt;
|-&lt;br /&gt;
| [[Overview_report|(Gradebook) Overview]]&lt;br /&gt;
| Report&lt;br /&gt;
| Standard&lt;br /&gt;
| Teachers, Students&lt;br /&gt;
| View of student grades across activites&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [[Statistics]]&lt;br /&gt;
| Report&lt;br /&gt;
| Standard&lt;br /&gt;
| Admins, Decision-makers&lt;br /&gt;
| Daily activity across site&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [[:en:Event_monitoring|Event monitor]]&lt;br /&gt;
| Report&lt;br /&gt;
| Standard&lt;br /&gt;
| Teachers, Admins, Decision-makers&lt;br /&gt;
| Proactive, focussed monitor tool&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [http://moodle.org/plugins/view/report_customsql Ad-hoc database queries]&lt;br /&gt;
| Report&lt;br /&gt;
| Additional&lt;br /&gt;
| Teachers, Admins, Decision-makers&lt;br /&gt;
| SQL-based report generation and viewing&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [http://moodle.org/plugins/browse.php?list=set&amp;amp;id=20 Engagement Analytics]&lt;br /&gt;
| Block, Report, Activity module&lt;br /&gt;
| Additional&lt;br /&gt;
| Teachers&lt;br /&gt;
| Configurable engagement measurement report and block&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [http://moodle.org/plugins/view/block_dedication Course Dedication]&lt;br /&gt;
| Block&lt;br /&gt;
| Additional&lt;br /&gt;
| Students, Teachers&lt;br /&gt;
| Estimated time online for students&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [http://moodle.org/plugins/view.php?plugin=block_graph_stats Graph Stats]&lt;br /&gt;
| Block&lt;br /&gt;
| Additional&lt;br /&gt;
| Teachers, Admins&lt;br /&gt;
| Daily visits to site or course&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [http://moodle.org/plugins/view/block_gismo GISMO]&lt;br /&gt;
| Block&lt;br /&gt;
| Additional&lt;br /&gt;
| Teachers&lt;br /&gt;
| Numerous charts of student activity participation&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [http://moodle.org/plugins/view/block_xp Level Up!]&lt;br /&gt;
| Block&lt;br /&gt;
| Additional&lt;br /&gt;
| Students, Teachers&lt;br /&gt;
| Incentive-drive participation meter&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [http://moodle.org/plugins/report_forumgraph Forum Graph]&lt;br /&gt;
| Report&lt;br /&gt;
| Additional&lt;br /&gt;
| Teachers&lt;br /&gt;
| Graph of forum interactions&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [https://moodle.org/plugins/block_analytics_graphs Analytics Graphs]&lt;br /&gt;
| Block&lt;br /&gt;
| Additional&lt;br /&gt;
| Teachers&lt;br /&gt;
| Visualisation of student participation&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [https://moodle.org/plugins/block_heatmap Heatmap]&lt;br /&gt;
| Block&lt;br /&gt;
| Additional&lt;br /&gt;
| Teachers&lt;br /&gt;
| Colour-coded indication of activity views on course page&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [https://moodle.org/plugins/local_analytics Analytics]&lt;br /&gt;
| Local&lt;br /&gt;
| Additional&lt;br /&gt;
| Admins, Decision-makers&lt;br /&gt;
| Enriched feed to Google Analytics and Pywick&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [https://moodle.org/plugins/gradereport_gradedist Grade distribution]&lt;br /&gt;
| report&lt;br /&gt;
| Additional&lt;br /&gt;
| Teachers&lt;br /&gt;
| Visualizes the grades of students in a course&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|-&lt;br /&gt;
| [https://moodle.org/plugins/logstore_xapi Logstore xAPI]&lt;br /&gt;
| Logstore&lt;br /&gt;
| Additional&lt;br /&gt;
| Admins, Decision-makers, Researchers&lt;br /&gt;
| xAPI event stream output&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot; | N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; Reported usage is drawn from the [http://research.moodle.net/71/1/Plugins%20Usage%20Survey%202015%20Report.pdf Plugins Usage Survey from 2015].&lt;br /&gt;
&lt;br /&gt;
== Integrations with Moodle ==&lt;br /&gt;
&lt;br /&gt;
A number of systems integrate with Moodle to provide learning analytics information externally.&lt;br /&gt;
&lt;br /&gt;
* [http://damos.world/2013/08/30/the-moodle-activity-viewer-mav-heatmaps-of-student-activity/ Moodle Activity Viewer] (MAV) ([https://github.com/damoclark/mav-enterprise Git]), consider [https://moodle.org/plugins/block_heatmap Heatmap] as an alternative&lt;br /&gt;
* [http://www.intelliboard.net/ Intelliboard]&lt;br /&gt;
* [http://www.lambdasolutions.net/products/lmsreporting/ Zoola (was Analytika)]&lt;br /&gt;
* [https://learninglocker.net/ Learning Locker], can be used with [https://moodle.org/plugins/logstore_xapi Logstore xAPI]&lt;br /&gt;
* [http://klassdata.com/smartklass-learning-analytics-plugin/learning-analytics-moodle-smartklass/ SmartKlass]&lt;br /&gt;
* [http://www.blackboard.com/education-analytics/blackboard-predict.aspx Blackboard Predict]&lt;br /&gt;
* [http://melbourne-cshe.unimelb.edu.au/research/edutech/completing-the-loop Completing the loop]&lt;br /&gt;
* [https://www.iadlearning.com/ IADlearning] offers institutions and educators a rich set of analytics allowing them to understand the quality of their training content, as well as the quality of the ongoing learning processes.&lt;br /&gt;
&lt;br /&gt;
== Dimensions of Analytics ==&lt;br /&gt;
&lt;br /&gt;
Learning analytics are a concept that has been emerging under a number of different names through the past decades. Its origins lie in research in data mining and intelligent tutoring systems. LA tools can be categorised in a number of ways:&lt;br /&gt;
&lt;br /&gt;
* Descriptive&lt;br /&gt;
* Predictive&lt;br /&gt;
* Diagnostic&lt;br /&gt;
* Prescriptive&lt;br /&gt;
&lt;br /&gt;
== See also... ==&lt;br /&gt;
* [https://moodle.org/mod/forum/view.php?id=8044 Analytics and reporting forum]&lt;br /&gt;
* [https://moodle.org/mod/forum/view.php?id=8205 Moodle Research forum]&lt;br /&gt;
* [[:dev:Moodle_research|Moodle research page]]&lt;br /&gt;
* [[Logging]]&lt;br /&gt;
* [[:en:Events_list_report|Events list]]&lt;br /&gt;
* [[:dev:Learning_Analytics_Specification|Learning Analytics API specification]]&lt;br /&gt;
* [[:dev:Working_Groups#Assessment_Analytics|Assessment Analytics working group details and issues]]&lt;br /&gt;
* [[:dev:Event_2|Events specification]]&lt;br /&gt;
* [[:dev:Logging_2|Logging specification]]&lt;br /&gt;
* [[:dev:reportbuilder/API|Report Builder API specification]]&lt;br /&gt;
* Use [https://moodle.org/plugins/filter_generico Generico filter] to display custom DB reports with graphs [https://moodle.org/mod/forum/discuss.php?d=324771#p1334032 Demo / Forums]&lt;br /&gt;
* [https://www.jisc.ac.uk/blog/solving-the-ethical-and-legal-issues-around-learning-analytics-a-series-of-podcasts-11-mar-2016 Solving the ethical and legal issues around learning analytics: a series of podcasts]&lt;br /&gt;
* [http://plugins.moodlebites.com A number of free Moodle analytics plugins you can try] available on http://plugins.moodlebites.com&lt;br /&gt;
&lt;br /&gt;
== Presentations ==&lt;br /&gt;
* [https://www.youtube.com/watch?v=MHv4vp1hxQc&amp;amp;index=5&amp;amp;list=TLGCVIc9g1-qUMUxOTEwMjAxNg Moodle Analytics Plans I Elizabeth Dalton at MoodleMoot Australia 2016] (video 24m)&lt;br /&gt;
&lt;br /&gt;
[[Category:Report]]&lt;br /&gt;
&lt;br /&gt;
[[es:Análisis del aprendizaje]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=128594</id>
		<title>ad-hoc contributed reports</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=ad-hoc_contributed_reports&amp;diff=128594"/>
		<updated>2017-08-13T07:47:17Z</updated>

		<summary type="html">&lt;p&gt;Nadavkav: /* List all the Posts in all the Forums that got high rating */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Sitewide reports}}&lt;br /&gt;
==User and Role Report==&lt;br /&gt;
&lt;br /&gt;
===Count number of distinct learners and teachers enrolled per category (including all its sub categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;SELECT COUNT(DISTINCT lra.userid) AS learners, COUNT(DISTINCT tra.userid) as teachers&lt;br /&gt;
FROM prefix_course AS c #, mdl_course_categories AS cats&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments  AS lra ON lra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role_assignments  AS tra ON tra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category = cats.id&lt;br /&gt;
AND (&lt;br /&gt;
	cats.path LIKE &#039;%/CATEGORYID/%&#039; #Replace CATEGORYID with the category id you want to count (eg: 80)&lt;br /&gt;
	OR cats.path LIKE &#039;%/CATEGORYID&#039;&lt;br /&gt;
	)&lt;br /&gt;
AND lra.roleid=5&lt;br /&gt;
AND tra.roleid=3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each ROLE (TEACHER, NON-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT r.name, l.action, COUNT( l.userid ) AS counter&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_role AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE ra.roleid IN ( 3, 4, 5 ) &lt;br /&gt;
GROUP BY roleid, l.action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student (user) COUNT in each Course===&lt;br /&gt;
Including (optional) filter by: year (if included in course fullname).&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/index.php?contextid=&#039;,context.id,&#039;&amp;quot;&amp;gt;Show users&amp;lt;/a&amp;gt;&#039;) AS Users&lt;br /&gt;
, COUNT(course.id) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS asg&lt;br /&gt;
JOIN prefix_context AS context ON asg.contextid = context.id AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_user AS user ON user.id = asg.userid&lt;br /&gt;
JOIN prefix_course AS course ON context.instanceid = course.id&lt;br /&gt;
WHERE asg.roleid = 5 &lt;br /&gt;
# AND course.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
GROUP BY course.id&lt;br /&gt;
ORDER BY COUNT(course.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enrolment count in each Course ===&lt;br /&gt;
&lt;br /&gt;
Shows the total number of enroled users of all roles in each course. Sorted by course name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname, COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LIST of all site USERS by COURSE enrollment (Moodle 2.x)===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) as Role&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) as RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course as course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enrolled users,which did not login into the Course, even once (Moodle 2)===&lt;br /&gt;
Designed forMoodle 2 table structure and uses special plugin filter : %%FILTER_SEARCHTEXT:table.field%%&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id as ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
user2.idnumber AS IDNumber,&lt;br /&gt;
user2.phone1 AS Phone,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
&lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id and courseid=c.id) as CourseLastAccess&lt;br /&gt;
&lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id and e.courseid = c.id) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments as ue&lt;br /&gt;
JOIN prefix_enrol as e on e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user as user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess as ul on ul.userid = user2.id&lt;br /&gt;
WHERE c.id=16 AND ul.timeaccess IS NULL&lt;br /&gt;
%%FILTER_SEARCHTEXT:user2.firstname%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Role assignments on categories===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/category.php?id=&#039;,cc.id,&#039;&amp;quot;&amp;gt;&#039;,cc.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS category,&lt;br /&gt;
cc.depth, cc.path, r.name AS role,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php?id=&#039;,usr.id,&#039;&amp;quot;&amp;gt;&#039;,usr.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS name,&lt;br /&gt;
usr.firstname, usr.username, usr.email&lt;br /&gt;
FROM prefix_course_categories cc&lt;br /&gt;
INNER JOIN prefix_context cx ON cc.id = cx.instanceid&lt;br /&gt;
AND cx.contextlevel = &#039;40&#039;&lt;br /&gt;
INNER JOIN prefix_role_assignments ra ON cx.id = ra.contextid&lt;br /&gt;
INNER JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
INNER JOIN prefix_user usr ON ra.userid = usr.id&lt;br /&gt;
ORDER BY cc.depth, cc.path, usr.lastname, usr.firstname, r.name, cc.name&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Permissions Overides on Categories===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712834 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT rc.id, ct.instanceid, ccat.name, rc.roleid, rc.capability, rc.permission, &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( rc.timemodified ) , &#039;%Y-%m-%d&#039; ) AS timemodified, rc.modifierid, ct.instanceid, ct.path, ct.depth&lt;br /&gt;
FROM `prefix_role_capabilities` AS rc&lt;br /&gt;
INNER JOIN `prefix_context` AS ct ON rc.contextid = ct.id&lt;br /&gt;
INNER JOIN `prefix_course_categories` AS ccat ON ccat.id = ct.instanceid&lt;br /&gt;
AND `contextlevel` =40&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;Totally Opened Courses&amp;quot; (visible, opened to guests, with no password)===&lt;br /&gt;
(By: [http://moodle.org/mod/forum/discuss.php?d=153059#p712837 Séverin Terrier] )&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS id,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Course&#039;,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/enrol/instances.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Méthodes inscription&amp;lt;/a&amp;gt;&#039;) AS &#039;Enrollment plugins&#039;,&lt;br /&gt;
e.sortorder&lt;br /&gt;
FROM prefix_enrol AS e, prefix_course AS c&lt;br /&gt;
WHERE e.enrol=&#039;guest&#039; AND e.status=0 AND e.password=&#039;&#039; AND c.id=e.courseid AND c.visible=1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists &amp;quot;loggedin users&amp;quot; from the last 120 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id,username,FROM_UNIXTIME(`lastlogin`) as days &lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;and user count for that same population:&#039;&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(id) as Users  FROM `prefix_user` &lt;br /&gt;
WHERE DATEDIFF( NOW(),FROM_UNIXTIME(`lastlogin`) ) &amp;lt; 120&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists the users who have only logged into the site once===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, username, firstname, lastname, idnumber&lt;br /&gt;
FROM prefix_user&lt;br /&gt;
WHERE prefix_user.deleted = 0&lt;br /&gt;
AND prefix_user.lastlogin = 0 &lt;br /&gt;
AND prefix_user.lastaccess &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Students in all courses of some institute===&lt;br /&gt;
What is the status (deleted or not) of all Students (roleid = 5) in all courses of some Institute&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname, u.firstname, u.lastname, u.deleted&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND u.institution = &#039;please enter school name here&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Full User info (for deleted users)===&lt;br /&gt;
Including extra custom profile fields (from prefix_user_info_data)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT * &lt;br /&gt;
FROM prefix_user as u &lt;br /&gt;
JOIN prefix_user_info_data as uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_user_info_field as uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;class&#039;)&lt;br /&gt;
WHERE `deleted` = &amp;quot;1&amp;quot; and `institution`=&amp;quot;your school name&amp;quot; and `department` = &amp;quot;your department&amp;quot; and `data` = &amp;quot;class level and number&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User&#039;s courses===&lt;br /&gt;
change &amp;quot;u.id = 2&amp;quot; with a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, c.id, c.fullname&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE u.id = 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Users with extra info (email) in current course===&lt;br /&gt;
blocks/configurable_reports replaces %%COURSEID%% with course id.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, u.email&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS context ON context.id = ra.contextid AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_course AS c ON c.id = context.instanceid AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Special Roles===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.roleid,r.name&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,ra.userid,&#039;&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Username&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON (ctx.id = ra.contextid AND ctx.contextlevel = 50)&lt;br /&gt;
JOIN prefix_course AS c ON ctx.instanceid = c.id&lt;br /&gt;
WHERE ra.roleid &amp;gt; 6&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses without Teachers===&lt;br /&gt;
Actually, shows the number of Teachers in a course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Teachers&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
ORDER BY Teachers ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List of users who have been enrolled for more than 4 weeks===&lt;br /&gt;
For Moodle 2.2 , by  Isuru Madushanka Weerarathna &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT uenr.userid As User, IF(enr.courseid=uenr.courseid ,&#039;Y&#039;,&#039;N&#039;) As Enrolled, &lt;br /&gt;
IF(DATEDIFF(NOW(), FROM_UNIXTIME(uenr.timecreated))&amp;gt;=28,&#039;Y&#039;,&#039;N&#039;) As EnrolledMoreThan4Weeks&lt;br /&gt;
FROM prefix_enrol As enr, prefix_user_enrolments AS uenr&lt;br /&gt;
WHERE enr.id = uenr.enrolid AND enr.status = uenr.status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with language===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
This will show you the language setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, lang from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools.&lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;en&#039; to &#039;en_us&#039; for all users:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To do this for only users who have a particular country set, use this as an example:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET lang = &#039;en_us&#039; WHERE country = &#039;US&#039; AND lang = &#039;en&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of users with Authentication ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Sometimes you need to do mass changes of authentication methods. A common case is changing default manual to LDAP. &lt;br /&gt;
&lt;br /&gt;
This will show you the Authentication setting for all users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT username, auth from prefix_user &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: UPDATE commands require the ability to alter the database directly via tools like Adminer or PHPMyAdmin or other db tools. &lt;br /&gt;
&lt;br /&gt;
This code will change the setting from &#039;manual&#039; to &#039;ldap&#039; 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.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
UPDATE prefix_user SET auth = &#039;ldap&#039; WHERE auth = &#039;manual&#039; AND id &amp;gt; 2&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compare role capability and permissions ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT mrc.capability &lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;1&#039; AND rc.contextid = &#039;1&#039;) AS Manager&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;2&#039; AND rc.contextid = &#039;1&#039;) AS CourseCreator&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;3&#039; AND rc.contextid = &#039;1&#039;) AS Teacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;4&#039; AND rc.contextid = &#039;1&#039;) AS AssistantTeacher&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;5&#039; AND rc.contextid = &#039;1&#039;) AS Student&lt;br /&gt;
,(SELECT rc.permission FROM `mdl_role_capabilities` AS rc WHERE rc.capability = mrc.capability &lt;br /&gt;
  AND rc.roleid = &#039;6&#039; AND rc.contextid = &#039;1&#039;) AS Guest&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_role_capabilities` AS mrc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User&#039;s accumulative time spent in course ===&lt;br /&gt;
A sum up of the time delta between logstore_standard_log user&#039;s records, considering the a 2 hour session limit.&lt;br /&gt;
&lt;br /&gt;
Uses: current user&#039;s id %%USERID%% and current course&#039;s id %%COURSEID%%  &lt;br /&gt;
&lt;br /&gt;
And also using a date filter (which can be ignored)  &lt;br /&gt;
&lt;br /&gt;
The extra &amp;quot;User&amp;quot; field is used as a dummy field for the Line chart Series field, in which I use X=id, Series=Type, Y=delta.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
l.id, &lt;br /&gt;
l.timecreated, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(l.timecreated),&#039;%d-%m-%Y&#039;) AS dTime,&lt;br /&gt;
@prevtime := (SELECT max(timecreated) FROM mdl_logstore_standard_log &lt;br /&gt;
		WHERE userid = %%USERID%% and id &amp;lt; l.id ORDER BY id ASC LIMIT 1) AS prev_time,&lt;br /&gt;
IF (l.timecreated - @prevtime &amp;lt; 7200, @delta := @delta + (l.timecreated-@prevtime),0) AS sumtime,&lt;br /&gt;
l.timecreated-@prevtime AS delta,&lt;br /&gt;
&amp;quot;User&amp;quot; as type&lt;br /&gt;
&lt;br /&gt;
FROM prefix_logstore_standard_log as l, &lt;br /&gt;
(SELECT @delta := 0) AS s_init &lt;br /&gt;
# Change UserID&lt;br /&gt;
WHERE l.userid = %%USERID%% AND l.courseid = %%COURSEID%%&lt;br /&gt;
%%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Log Activity Reports==&lt;br /&gt;
===Count all Active Users by ROLE in a course category (including all of its sub-categories)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT l.userid) as active&lt;br /&gt;
FROM mdl_course as c&lt;br /&gt;
JOIN mdl_context AS ctx ON  ctx.instanceid=c.id&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN mdl_user_lastaccess as l ON ra.userid = l.userid&lt;br /&gt;
JOIN mdl_course_categories AS cats ON c.category = cats.id&lt;br /&gt;
WHERE c.category=cats.id AND (&lt;br /&gt;
	cats.path LIKE &#039;%/80/%&#039;&lt;br /&gt;
	OR cats.path LIKE &#039;%/80&#039;&lt;br /&gt;
) &lt;br /&gt;
AND ra.roleid=3  AND ctx.contextlevel=50  #ra.roleid= TEACHER 3, NON-EDITING TEACHER 4, STUDENT 5&lt;br /&gt;
AND  l.timeaccess &amp;gt; (unix_timestamp() - ((60*60*24)*NO_OF_DAYS)) #NO_OF_DAYS change to number&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Detailed &amp;quot;VIEW&amp;quot; ACTION for each ROLE (TEACHER,NONE-EDITING TEACHER and STUDENT)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT l.action, count( l.userid ) as counter , r.name&lt;br /&gt;
FROM `prefix_log` as l&lt;br /&gt;
JOIN `prefix_role_assignments` AS ra on l.userid = ra.userid&lt;br /&gt;
JOIN `prefix_role` AS r ON ra.roleid = r.id&lt;br /&gt;
WHERE (ra.roleid IN (3,4,5)) AND (l.action LIKE &#039;%view%&#039; )&lt;br /&gt;
GROUP BY roleid,l.action&lt;br /&gt;
order by r.name,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total Activity of Roles:&amp;quot;Teacher&amp;quot; and &amp;quot;None-Editing Teacher&amp;quot; by Dates and by Hours===&lt;br /&gt;
The output columns of this report table can be used as base for a Pivot-Table&lt;br /&gt;
which will show the amount of &#039;&#039;&#039;activity&#039;&#039;&#039; per &#039;&#039;&#039;hour&#039;&#039;&#039; per &#039;&#039;&#039;days&#039;&#039;&#039; in 3D graph view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%Y-%m-%d&#039; ) AS grptimed ,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( l.time ) , &#039;%k&#039; ) AS grptimeh  , count( l.userid ) AS counter &lt;br /&gt;
FROM `prefix_log` AS l&lt;br /&gt;
JOIN prefix_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON l.userid = ra.userid&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
WHERE ra.roleid IN (3,4)&lt;br /&gt;
GROUP BY grptimed,grptimeh&lt;br /&gt;
ORDER BY grptimed,grptimeh&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many LOGINs per user and user&#039;s Activity===&lt;br /&gt;
+ link username to a user activity graph report&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/user.php?id=1&amp;amp;user=&#039;,u.id,&#039;&amp;amp;mode=alllogs&amp;quot;&amp;gt;&#039;,u.firstname ,&#039; &#039;,u.lastname,&#039;&amp;lt;/a&amp;gt;&#039;) as Username&lt;br /&gt;
,count(*) as logins&lt;br /&gt;
,(SELECT count(*) FROM prefix_log WHERE userid = l.userid GROUP BY userid) as Activity &lt;br /&gt;
FROM prefix_log as l JOIN prefix_user as u ON l.userid = u.id &lt;br /&gt;
WHERE `action` LIKE &#039;%login%&#039; group by userid&lt;br /&gt;
ORDER BY Activity DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===Distinct user logins per month===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
The following will show you the months of the current calendar year with the total number of distinct, unique user logins per month. Change the year in the WHERE clause to the year you need.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
 COUNT(DISTINCT l.userid) AS &#039;DistinctUserLogins&#039;, &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%M&#039;) AS &#039;Month&#039;&lt;br /&gt;
FROM prefix_logstore_standard_log l&lt;br /&gt;
WHERE l.action = &#039;loggedin&#039; AND YEAR(FROM_UNIXTIME(l.timecreated)) = &#039;2017&#039; &lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(l.timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Total activity per course, per unique user on the last 24h===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
    COUNT(DISTINCT userid) AS countUsers&lt;br /&gt;
  , COUNT(l.courseid) AS countVisits&lt;br /&gt;
  , CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
  JOIN mdl_course AS c ON c.id = l.courseid&lt;br /&gt;
WHERE l.courseid &amp;gt; 0&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 1 DAY)&lt;br /&gt;
      AND c.fullname LIKE &#039;%תשעו%&#039;&lt;br /&gt;
GROUP BY l.courseid&lt;br /&gt;
ORDER BY countVisits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Instructor Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of instructors in all courses per week of a term, including pre-term and post-term edits. An edit is defined as a change to the course, such as a discussion post, the grading of an assignment, or the uploading of file attachments, as well as alterations to course content.&lt;br /&gt;
&lt;br /&gt;
* To specify a subject and/or course number, use % as a wildcard, e.g. ARTS% or ARTS501%&lt;br /&gt;
* To match part of a last name, use %, e.g. Smi% will match &amp;quot;Smith&amp;quot;, &amp;quot;Smile&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
At our institution, we include filters on the course name or category to constrain by terms. These are very specific to how course names and categories are constructed at our institution, so I&#039;ve removed those elements from this code. Also, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; lines for longer terms, or remove lines for shorter terms.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version uses legacy (pre-2.7) logs. See below for post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, c.startdate AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time)) - WEEK(FROM_UNIXTIME(c.startdate))&amp;lt;0,1,0)) AS BeforeTerm&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=0,1,0)) AS Week1&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=1,1,0)) AS Week2&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=2,1,0)) AS Week3&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=3,1,0)) AS Week4&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=4,1,0)) AS Week5&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=5,1,0)) AS Week6&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=6,1,0)) AS Week7&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=7,1,0)) AS Week8&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=8,1,0)) AS Week9&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=9,1,0)) AS Week10&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=10,1,0)) AS Week11&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))=11,1,0)) AS Week12&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(WEEK(FROM_UNIXTIME(l.time))-WEEK(FROM_UNIXTIME(c.startdate))&amp;gt;=12,1,0)) AS AfterTerm&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE :course&lt;br /&gt;
AND u.lastname LIKE :last_name&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 log version:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS CourseID&lt;br /&gt;
, cc.name AS Category&lt;br /&gt;
, CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Instructor&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( ra2.userid ) AS Users2 FROM prefix_role_assignments AS ra2&lt;br /&gt;
JOIN prefix_context AS ctx2 ON ra2.contextid = ctx2.id&lt;br /&gt;
WHERE ra2.roleid = 5 AND ctx2.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS Course_Start_Date&lt;br /&gt;
&lt;br /&gt;
, c.visible AS Visible&lt;br /&gt;
&lt;br /&gt;
,  COUNT(DISTINCT l.id) AS Edits&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS Link&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
LEFT JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND c.shortname LIKE &#039;%OL-%&#039;&lt;br /&gt;
AND cc.idnumber LIKE &#039;%current%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber, c.id&lt;br /&gt;
#HAVING students &amp;gt; 0&lt;br /&gt;
ORDER BY RIGHT(c.shortname,2), c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Weekly Student Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of students in the current course by week, including pre-term and post-term edits. An 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 (if permitted).&lt;br /&gt;
&lt;br /&gt;
Links to three other reports are also provided:&lt;br /&gt;
&lt;br /&gt;
* Logs: complete log entries for the student in the course, organized by date&lt;br /&gt;
* Activity Outline: the &amp;quot;Outline Report&amp;quot; from the User Activity Reports, summarizing the student&#039;s activity in the course, organized by course content&lt;br /&gt;
* Consolidated Activity Report: the &amp;quot;Complete Report&amp;quot; from the User Activity Reports, detailing the student&#039;s activity in the course, organized by course content (includes text of forum posts)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). At our institution, our terms are 12 weeks long. You would want to insert additional &amp;quot;SUM&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for a post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF((l.time-c.startdate)/7&amp;lt;0,1,0)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=0,1,0)) AS &#039;Week 1&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=1,1,0)) AS &#039;Week 2&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=2,1,0)) AS &#039;Week 3&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=3,1,0)) AS &#039;Week 4&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=4,1,0)) AS &#039;Week 5&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=5,1,0)) AS &#039;Week 6&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=6,1,0)) AS &#039;Week 7&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=7,1,0)) AS &#039;Week 8&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=8,1,0)) AS &#039;Week 9&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=9,1,0)) AS &#039;Week 10&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=10,1,0)) AS &#039;Week 11&#039;&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))=11,1,0)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(FLOOR((l.time - c.startdate)/(60*60*24*7))&amp;gt;=15,1,0)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_log AS l ON l.userid = u.id AND l.course = c.id  AND l.action NOT LIKE &amp;quot;view%&amp;quot;&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 (Standard Logs) version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
u.lastname AS &#039;Last Name&#039;&lt;br /&gt;
, u.firstname AS &#039;First Name&#039;&lt;br /&gt;
,  COUNT(l.id) AS &#039;Edits&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
# Our institution stores academic advisor names and emails in custom profile fields&lt;br /&gt;
#, CONCAT(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,uce.data,&#039;&amp;quot;&amp;gt;&#039;,uid.data, &#039;&amp;lt;/a&amp;gt;&#039;)  AS &#039;Academic Advisor&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/log/index.php&#039;,CHAR(63),&#039;chooselog=1&amp;amp;showusers=1&amp;amp;showcourses=0&amp;amp;id=&#039;,c.id,&#039;&amp;amp;user=&#039;,u.id,&#039;&amp;amp;date=0&amp;amp;modid=&amp;amp;modaction=&amp;amp;logformat=showashtml&#039;,&#039;&amp;quot;&amp;gt;&#039;,&#039;Logs&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Logs&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=outline&amp;quot;&amp;gt;&#039;,&#039;Outline&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Activity Outline&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/report/outline/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;amp;mode=complete&amp;quot;&amp;gt;&#039;,&#039;Activity&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Consolidated Activity&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;amp;course=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,&#039;Posts&#039;,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Posts&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# student academic coach - you can include custom profile field data with these methods&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uid ON u.id = uid.userid AND uid.fieldid = &#039;2&#039;&lt;br /&gt;
# student academic coach email&lt;br /&gt;
# LEFT JOIN prefix_user_info_data as uce on u.id = uce.userid AND uce.fieldid = &#039;6&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY u.idnumber&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===My Weekly Online Participation===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Displays participation of the &#039;&#039;&#039;current user&#039;&#039;&#039; in the &#039;&#039;&#039;current course&#039;&#039;&#039; 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).&lt;br /&gt;
&lt;br /&gt;
This report uses Standard Logs (post 2.7).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
l.component AS &#039;activity&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((l.timecreated-c.startdate)&amp;lt;0,l.id,NULL)) AS &#039;Before Term&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=0,l.id,NULL)) AS &#039;Week 1&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=1,l.id,NULL)) AS &#039;Week 2&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=2,l.id,NULL)) AS &#039;Week 3&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=3,l.id,NULL)) AS &#039;Week 4&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=4,l.id,NULL)) AS &#039;Week 5&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=5,l.id,NULL)) AS &#039;Week 6&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=6,l.id,NULL)) AS &#039;Week 7&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=7,l.id,NULL)) AS &#039;Week 8&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=8,l.id,NULL)) AS &#039;Week 9&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=9,l.id,NULL)) AS &#039;Week 10&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=10,l.id,NULL)) AS &#039;Week 11&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))=11,l.id,NULL)) AS &#039;Week 12&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(FLOOR((l.timecreated - c.startdate)/(60*60*24*7))&amp;gt;=12,l.id,NULL)) AS &#039;After Term&#039;&lt;br /&gt;
&lt;br /&gt;
,  COUNT(l.id) AS &#039;Total&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id  AND l.crud IN (&#039;c&#039;,&#039;u&#039;)&lt;br /&gt;
&lt;br /&gt;
WHERE 1&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
AND u.id = %%USERID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY l.component&lt;br /&gt;
&lt;br /&gt;
ORDER BY l.component&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Faculty/Student Interactions===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
Returns a count of instructor and other-student responses to student activity for the specified time period. This report can help indicate whether students&#039; comments are being responded to, as well as summarizing post activity by students during the specified time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This version of the report uses legacy (pre-2.7) logs. See below for the post-2.7 Standard Logs version.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This report can take a long time to run. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
LEFT JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
LEFT JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
LEFT JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
# We care about messages that involve both the instructor and students of this course&lt;br /&gt;
# messages from instructor to students:&lt;br /&gt;
# LEFT JOIN prefix_message AS mts ON mts.useridfrom = instr.id AND mts.useridto = allstu.id&lt;br /&gt;
# LEFT JOIN prefix_message AS mfs ON mfs.useridfrom = instr.id AND mfs.useridto = allstu.id&lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Post-2.7 Standard Logs version&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
# Identify student&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/message/index.php?id=&#039; , allstu.id , &#039;&amp;quot;&amp;gt;&#039; , allstu.firstname , &#039; &#039; , allstu.lastname , &#039;&amp;lt;/a&amp;gt;&#039; ) AS &#039;Student - click to send message&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL))&amp;gt;0) OR  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Participated This week&#039;&lt;br /&gt;
&lt;br /&gt;
, IF((COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) )&amp;gt;0) OR (COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL))&amp;gt;0) OR (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Student Contacted This week&#039;&lt;br /&gt;
&lt;br /&gt;
## Only posts within last 7 days&lt;br /&gt;
&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT IF(fps.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fps.id,NULL)) AS &#039;Forum Stu Posts - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Instr Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) - COUNT(DISTINCT IF(fpi.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpi.id,NULL) ) AS &#039;Forum Stu Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT IF(fpsr.created &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),fpsr.id,NULL)) AS &#039;Forum All Replies - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - 7 days&lt;br /&gt;
, COUNT(DISTINCT IF(asb.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asb.id,NULL)) AS &#039;Assign Submit - 7 days&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(asg.timemodified &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60)),asg.id,NULL)) AS &#039;Assign Grades - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - 7 days&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id AND mfs.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Stu to Instr - 7 days&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id  AND mts.timecreated &amp;gt; (UNIX_TIMESTAMP()  - (7*24*60*60))) AS &#039;Msg Instr to Stu - 7 days&#039;&lt;br /&gt;
&lt;br /&gt;
## All posts in course so far&lt;br /&gt;
# Count posts by student&lt;br /&gt;
, COUNT(DISTINCT fps.id) AS &#039;Forum Stu Posts - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Count replies to student posts by instructors&lt;br /&gt;
, COUNT(DISTINCT fpi.id) AS &#039;Forum Instr Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# using link back to student posts on replies, get unique student IDs responded&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) - COUNT(DISTINCT fpi.id) AS &#039;Forum Stu Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# all replies&lt;br /&gt;
, COUNT(DISTINCT fpsr.id) AS &#039;Forum All Replies - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# add in count of graded assignments - whole course&lt;br /&gt;
, COUNT(DISTINCT asb.id) AS &#039;Assign Submit - to date&#039;&lt;br /&gt;
, COUNT(DISTINCT asg.id) AS &#039;Assign Grades - to date&#039;&lt;br /&gt;
&lt;br /&gt;
# Messages between students and instructors - to date&lt;br /&gt;
,  (SELECT COUNT(DISTINCT mfs.id) FROM prefix_message AS mfs WHERE mfs.useridfrom = allstu.id AND mfs.useridto = instr.id ) AS &#039;Msg Stu to Instr - to date&#039;&lt;br /&gt;
, (SELECT COUNT(DISTINCT mts.id) FROM prefix_message AS mts WHERE mts.useridfrom = instr.id AND mts.useridto = allstu.id) AS &#039;Msg Instr to Stu - to date&#039;&lt;br /&gt;
&lt;br /&gt;
## JOINS&lt;br /&gt;
&lt;br /&gt;
# Start by getting all the students in the course&lt;br /&gt;
FROM prefix_user AS allstu &lt;br /&gt;
JOIN prefix_role_assignments AS ras ON allstu.id = ras.userid AND ras.roleid = 5&lt;br /&gt;
JOIN prefix_context AS ctx  ON ras.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
# Now we get the forums and forum discussions from this course only&lt;br /&gt;
JOIN prefix_forum AS frm ON frm.course = c.id AND c.id = %%COURSEID%%&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.course = %%COURSEID%% AND fd.forum = frm.id&lt;br /&gt;
&lt;br /&gt;
# These are forum discussion posts just by students within specified time&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fps ON fps.userid = allstu.id AND fps.discussion = fd.id&lt;br /&gt;
&lt;br /&gt;
# Separately, we connect the instructors of the courses&lt;br /&gt;
# We can use the context we have already gotten for the students&lt;br /&gt;
JOIN prefix_role_assignments AS rai ON rai.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS instr ON instr.id = rai.userid AND rai.roleid =3&lt;br /&gt;
&lt;br /&gt;
# Now we will connect to posts by instructors that are replies to student posts&lt;br /&gt;
# This is a left join, because we don&#039;t want to eliminate any students from the list&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpi ON fpi.discussion = fd.id AND fpi.userid = instr.id AND fpi.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# To get identities of only those students who were replied to:&lt;br /&gt;
# Connect from instr replies back up to parent posts by students again&lt;br /&gt;
# This has to be a LEFT JOIN, we know these posts exist but don&#039;t eliminate non-responded students&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpir ON fpir.id = fpi.parent&lt;br /&gt;
&lt;br /&gt;
# We also want to know if students are replying to one another&lt;br /&gt;
# These are posts that are replies to student posts&lt;br /&gt;
# Again, a left join&lt;br /&gt;
LEFT JOIN prefix_forum_posts AS fpsr ON fpsr.discussion = fd.id AND fpsr.parent = fps.id&lt;br /&gt;
&lt;br /&gt;
# get the activity modules&lt;br /&gt;
JOIN prefix_course_modules AS cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
# get the assignments&lt;br /&gt;
 JOIN prefix_assign AS a ON  cm.instance = a.id&lt;br /&gt;
 LEFT JOIN prefix_assign_submission AS asb ON a.id = asb.assignment AND asb.userid=allstu.id &lt;br /&gt;
LEFT JOIN prefix_assign_grades AS asg ON asg.assignment = a.id AND asg.userid = allstu.id AND asg.assignment = asb.assignment &lt;br /&gt;
&lt;br /&gt;
WHERE  &lt;br /&gt;
c.id = %%COURSEID%% &lt;br /&gt;
&lt;br /&gt;
# GROUP BY c.shortname , allstu.id&lt;br /&gt;
GROUP BY allstu.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY allstu.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student Resource Usage===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;Standard Logs&amp;quot; from Moodle 2.7+.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This should be defined as a &amp;quot;Global&amp;quot; report (visible from within all courses). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
, m.name AS &#039;item type&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(&lt;br /&gt;
COALESCE(a.name, &#039;&#039;), &lt;br /&gt;
COALESCE(b.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cert.name,&#039;&#039;), &lt;br /&gt;
COALESCE(chat.name,&#039;&#039;), &lt;br /&gt;
COALESCE(choice.name,&#039;&#039;), &lt;br /&gt;
COALESCE(data.name,&#039;&#039;), &lt;br /&gt;
COALESCE(feedback.name,&#039;&#039;), &lt;br /&gt;
COALESCE(folder.name,&#039;&#039;), &lt;br /&gt;
COALESCE(forum.name,&#039;&#039;), &lt;br /&gt;
COALESCE(glossary.name,&#039;&#039;), &lt;br /&gt;
COALESCE(imscp.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lesson.name,&#039;&#039;), &lt;br /&gt;
COALESCE(p.name,&#039;&#039;),&lt;br /&gt;
COALESCE(questionnaire.name,&#039;&#039;), &lt;br /&gt;
COALESCE(quiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(cr.name,&#039;&#039;), &lt;br /&gt;
COALESCE(scorm.name,&#039;&#039;), &lt;br /&gt;
COALESCE(survey.name,&#039;&#039;), &lt;br /&gt;
COALESCE(url.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(workshop.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kalvidassign.name,&#039;&#039;), &lt;br /&gt;
COALESCE(attendance.name,&#039;&#039;), &lt;br /&gt;
COALESCE(checklist.name,&#039;&#039;), &lt;br /&gt;
COALESCE(flashcard.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lti.name,&#039;&#039;), &lt;br /&gt;
COALESCE(oublog.name,&#039;&#039;), &lt;br /&gt;
COALESCE(ouwiki.name,&#039;&#039;), &lt;br /&gt;
COALESCE(subpage.name,&#039;&#039;), &lt;br /&gt;
COALESCE(journal.name,&#039;&#039;), &lt;br /&gt;
COALESCE(lightboxgallery.name,&#039;&#039;), &lt;br /&gt;
COALESCE(elluminate.name,&#039;&#039;), &lt;br /&gt;
COALESCE(adaptivequiz.name,&#039;&#039;), &lt;br /&gt;
COALESCE(hotpot.name,&#039;&#039;), &lt;br /&gt;
COALESCE(wiziq.name,&#039;&#039;), &lt;br /&gt;
COALESCE(turnitintooltwo.name,&#039;&#039;), &lt;br /&gt;
COALESCE(kvr.name,&#039;&#039;)&lt;br /&gt;
) AS &#039;item name&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;r&#039;),1,0)) AS &#039;total views&#039;&lt;br /&gt;
, SUM(IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),1,0)) AS &#039;total submissions&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;r&#039;),u.id,NULL)) AS &#039;count of students who viewed&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(l.crud IN (&#039;c&#039;,&#039;u&#039;),u.id,NULL)) AS &#039;count of students who submitted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 #AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id&lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module AND m.name NOT LIKE &#039;label&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_assign AS a ON a.id = cm.instance AND m.name = &#039;assign&#039;&lt;br /&gt;
LEFT JOIN prefix_book AS b ON b.id = cm.instance AND m.name = &#039;book&#039;&lt;br /&gt;
LEFT JOIN prefix_certificate AS cert ON cert.id = cm.instance AND m.name = &#039;certificate&#039;&lt;br /&gt;
LEFT JOIN prefix_chat AS chat ON chat.id = cm.instance AND m.name = &#039;chat&#039;&lt;br /&gt;
LEFT JOIN prefix_choice AS choice ON choice.id = cm.instance AND m.name = &#039;choice&#039;&lt;br /&gt;
LEFT JOIN prefix_data AS data ON data.id = cm.instance AND m.name = &#039;data&#039;&lt;br /&gt;
LEFT JOIN prefix_feedback AS feedback ON feedback.id = cm.instance AND m.name = &#039;feedback&#039;&lt;br /&gt;
LEFT JOIN prefix_folder AS folder ON folder.id = cm.instance AND m.name = &#039;folder&#039;&lt;br /&gt;
LEFT JOIN prefix_forum AS forum ON forum.id = cm.instance AND m.name = &#039;forum&#039;&lt;br /&gt;
LEFT JOIN prefix_glossary AS glossary ON glossary.id = cm.instance AND m.name = &#039;glossary&#039;&lt;br /&gt;
LEFT JOIN prefix_imscp AS imscp ON imscp.id = cm.instance AND m.name = &#039;imscp&#039;&lt;br /&gt;
LEFT JOIN prefix_lesson AS lesson ON lesson.id = cm.instance AND m.name = &#039;lesson&#039;&lt;br /&gt;
LEFT JOIN prefix_page AS p ON p.id = cm.instance AND m.name = &#039;page&#039;&lt;br /&gt;
LEFT JOIN prefix_questionnaire AS questionnaire ON questionnaire.id = cm.instance AND m.name = &#039;questionnaire&#039;&lt;br /&gt;
LEFT JOIN prefix_quiz AS quiz ON quiz.id = cm.instance AND m.name = &#039;quiz&#039;&lt;br /&gt;
LEFT JOIN prefix_resource AS cr ON cr.id = cm.instance AND m.name = &#039;resource&#039;&lt;br /&gt;
LEFT JOIN prefix_scorm AS scorm ON scorm.id = cm.instance AND m.name = &#039;scorm&#039;&lt;br /&gt;
LEFT JOIN prefix_survey AS survey ON survey.id = cm.instance AND m.name = &#039;survey&#039;&lt;br /&gt;
LEFT JOIN prefix_url AS url ON url.id = cm.instance AND m.name = &#039;url&#039;&lt;br /&gt;
LEFT JOIN prefix_wiki AS wiki ON wiki.id = cm.instance AND m.name = &#039;wiki&#039;&lt;br /&gt;
LEFT JOIN prefix_workshop AS workshop ON workshop.id = cm.instance AND m.name = &#039;workshop&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidassign AS kalvidassign ON kalvidassign.id = cm.instance AND m.name = &#039;kalvidassign&#039;&lt;br /&gt;
LEFT JOIN prefix_kalvidres AS kvr ON kvr.id = cm.instance AND m.name = &#039;kalvidres&#039;&lt;br /&gt;
LEFT JOIN prefix_attendance AS attendance ON attendance.id = cm.instance AND m.name = &#039;attendance&#039;&lt;br /&gt;
LEFT JOIN prefix_checklist AS checklist ON checklist.id = cm.instance AND m.name = &#039;checklist&#039;&lt;br /&gt;
LEFT JOIN prefix_flashcard AS flashcard ON flashcard.id = cm.instance AND m.name = &#039;flashcard&#039;&lt;br /&gt;
LEFT JOIN prefix_lti AS lti ON lti.id = cm.instance AND m.name = &#039;lti&#039;&lt;br /&gt;
LEFT JOIN prefix_oublog AS oublog ON oublog.id = cm.instance AND m.name = &#039;oublog&#039;&lt;br /&gt;
LEFT JOIN prefix_ouwiki AS ouwiki ON ouwiki.id = cm.instance AND m.name = &#039;ouwiki&#039;&lt;br /&gt;
LEFT JOIN prefix_subpage AS subpage ON subpage.id = cm.instance AND m.name = &#039;subpage&#039;&lt;br /&gt;
LEFT JOIN prefix_journal AS journal ON journal.id = cm.instance AND m.name = &#039;journal&#039;&lt;br /&gt;
LEFT JOIN prefix_lightboxgallery AS lightboxgallery ON lightboxgallery.id = cm.instance AND m.name = &#039;lightboxgallery&#039;&lt;br /&gt;
LEFT JOIN prefix_elluminate AS elluminate ON elluminate.id = cm.instance AND m.name = &#039;elluminate&#039;&lt;br /&gt;
LEFT JOIN prefix_adaptivequiz AS adaptivequiz ON adaptivequiz.id = cm.instance AND m.name = &#039;adaptivequiz&#039;&lt;br /&gt;
LEFT JOIN prefix_hotpot AS hotpot ON hotpot.id = cm.instance AND m.name = &#039;hotpot&#039;&lt;br /&gt;
LEFT JOIN prefix_wiziq AS wiziq ON wiziq.id = cm.instance AND m.name = &#039;wiziq&#039;&lt;br /&gt;
LEFT JOIN prefix_turnitintooltwo AS turnitintooltwo ON turnitintooltwo.id = cm.instance AND m.name = &#039;turnitintooltwo&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_logstore_standard_log AS l ON l.userid = u.id AND l.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
AND cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cm.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Hits) between dates===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module, COUNT( * ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME( l.`time` ) BETWEEN  &#039;2012-10-01 00:00:00&#039; AND  &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
GROUP BY module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module activity (Instances and Hits) for each academic year===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2010-10-01 00:00:00&#039; AND &#039;2011-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2010-10-01 00:00:00&#039; AND &#039;2011-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2011-10-01 00:00:00&#039; AND &#039;2012-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2011&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2011-10-01 00:00:00&#039; AND &#039;2012-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2011&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2012-10-01 00:00:00&#039; AND &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name AND l.action = &#039;add&#039;&lt;br /&gt;
) AS &amp;quot;Added 2012&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
WHERE (FROM_UNIXTIME(l.`time`) BETWEEN &#039;2012-10-01 00:00:00&#039; AND &#039;2013-09-31 00:00:00&#039;)&lt;br /&gt;
AND l.module = m.name&lt;br /&gt;
) AS &amp;quot;Used 2012&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_modules AS m&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Unique user sessions per day and month + graph===&lt;br /&gt;
The &amp;quot;graph&amp;quot; column is used when displaying a graph (which needs at least three columns to pick from)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(DISTINCT userid) AS &amp;quot;Unique User Logins&amp;quot;&lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y /%m / %d&amp;quot;) AS &amp;quot;Year / Month / Day&amp;quot;, &amp;quot;Graph&amp;quot; &lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE action LIKE &#039;loggedin&#039;&lt;br /&gt;
#AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) # optional start date&lt;br /&gt;
#AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:00&#039;) # optional end date&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And...&lt;br /&gt;
&lt;br /&gt;
Counting user&#039;s global and unique hits per day + counting individual usage of specific activities and resources (on that day),&lt;br /&gt;
&lt;br /&gt;
And since I am using phpMyAdmin&#039;s &amp;quot;Display Graph&amp;quot; feature (at the bottom of the query&#039;s output page), I have scaled down the &amp;quot;User Hits&amp;quot; by 10 to fit the graph. that&#039;s it.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT(FROM_UNIXTIME(timecreated), &amp;quot;%y-%m-%d&amp;quot;) AS &amp;quot;Datez&amp;quot;&lt;br /&gt;
,COUNT(DISTINCT userid) AS &amp;quot;Unique Users&amp;quot;&lt;br /&gt;
,ROUND(COUNT(*)/10) &amp;quot;User Hits (K)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_quiz&#039;,1,0)) &amp;quot;Quizzes&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_forum&#039; or component=&#039;mod_forumng&#039;,1,0)) &amp;quot;Forums&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_assign&#039;,1,0)) &amp;quot;Assignments&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_oublog&#039;,1,0)) &amp;quot;Blogs&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_resource&#039;,1,0)) &amp;quot;Files (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_url&#039;,1,0)) &amp;quot;Links (Resource)&amp;quot;&lt;br /&gt;
,SUM(IF(component=&#039;mod_page&#039;,1,0)) &amp;quot;Pages (Resource)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `mdl_logstore_standard_log` &lt;br /&gt;
WHERE 1=1&lt;br /&gt;
AND timecreated &amp;gt;  UNIX_TIMESTAMP(&#039;2015-03-01 00:00:00&#039;) # optional START DATE&lt;br /&gt;
AND timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-05-31 23:59:00&#039;) # optional END DATE&lt;br /&gt;
GROUP BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
ORDER BY MONTH(FROM_UNIXTIME(timecreated)), DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide, daily unique user hits for the last 7 days===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
  DATE_FORMAT(FROM_UNIXTIME(l.timecreated), &#039;%m%d&#039;) &#039;Day&#039;&lt;br /&gt;
  ,COUNT(DISTINCT l.userid) AS &#039;Distinct Users Hits&#039;&lt;br /&gt;
  ,COUNT( l.userid) AS &#039;Users Hits&#039;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l&lt;br /&gt;
WHERE l.courseid &amp;gt; 1&lt;br /&gt;
      AND FROM_UNIXTIME(l.timecreated) &amp;gt;= DATE_SUB(NOW(), INTERVAL 7 DAY)&lt;br /&gt;
GROUP BY DAY(FROM_UNIXTIME(timecreated))&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User detailed activity in course modules===&lt;br /&gt;
Considering only several modules: url, resource, forum, quiz, questionnaire.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.id, ra.roleid,&lt;br /&gt;
CONCAT(u.lastname, &#039; &#039;, u.firstname) AS &#039;Student&#039;&lt;br /&gt;
,COUNT(l.id) AS &#039;Actions&#039;&lt;br /&gt;
,l.component &amp;quot;Module type&amp;quot;&lt;br /&gt;
,l.objectid &amp;quot;Module ID&amp;quot;&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN l.component = &#039;mod_url&#039; THEN (SELECT u.name FROM mdl_url AS u WHERE u.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_resource&#039; THEN (SELECT r.name FROM mdl_resource AS r WHERE r.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_forum&#039; THEN (SELECT f.name FROM mdl_forum AS f WHERE f.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_quiz&#039; THEN (SELECT q.name FROM mdl_quiz AS q WHERE q.id = l.objectid )&lt;br /&gt;
  WHEN l.component = &#039;mod_questionnaire&#039; THEN (SELECT q.name FROM mdl_questionnaire AS q WHERE q.id = l.objectid )&lt;br /&gt;
END AS &#039;Module name&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = l.courseid AND m.userid = u.id) &amp;quot;user_groups&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT s.name &lt;br /&gt;
  FROM mdl_course_modules AS cm &lt;br /&gt;
  JOIN mdl_course_sections AS s ON s.course = cm.course AND s.id = cm.section &lt;br /&gt;
  WHERE cm.id = l.contextinstanceid) AS &amp;quot;Section name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_logstore_standard_log AS l  &lt;br /&gt;
JOIN mdl_user AS u ON u.id = l.userid&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.userid = l.userid &lt;br /&gt;
  AND ra.contextid = (SELECT id FROM mdl_context WHERE instanceid = l.courseid AND contextlevel = 50) &lt;br /&gt;
WHERE l.courseid = %%COURSEID%%&lt;br /&gt;
  AND l.component IN (&#039;mod_url&#039;, &#039;mod_resource&#039;, &#039;mod_forum&#039;, &#039;mod_quiz&#039;, &#039;mod_questionnaire&#039;) &lt;br /&gt;
  %%FILTER_STARTTIME:l.timecreated:&amp;gt;%% %%FILTER_ENDTIME:l.timecreated:&amp;lt;%%&lt;br /&gt;
 &lt;br /&gt;
GROUP BY u.id, l.component&lt;br /&gt;
ORDER BY u.lastname, u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What teachers and courses considered active?===&lt;br /&gt;
This report display several calculations and parameters that help the Online academic training team find teachers that might need more support getting their courses more supporting of online learning pedagogical methodologies.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,&lt;br /&gt;
			  course.id,&#039;&amp;quot;&amp;gt;&#039;,course.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
#,course.shortname&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2012%&#039; THEN &#039;2012&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2013%&#039; THEN &#039;2013&#039; &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2014%&#039; THEN &#039;2014&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%2015%&#039; THEN &#039;2015&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester a%&#039; THEN &#039;Spring semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester b%&#039; THEN &#039;Fall semester&#039;&lt;br /&gt;
  WHEN course.fullname LIKE &#039;%semester s%&#039; THEN &#039;Summer semester&#039;&lt;br /&gt;
END AS Semester&lt;br /&gt;
&lt;br /&gt;
,IF(course.startdate&amp;gt;0, DATE_FORMAT(FROM_UNIXTIME(startdate), &#039;%d-%m-%Y&#039;), &#039;no date&#039;) AS &amp;quot;Course Start Date&amp;quot; &lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 4 AND ctx.instanceid = course.id&lt;br /&gt;
) AS &amp;quot;Assistant teacher&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = course.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
&lt;br /&gt;
# Uncomment to use the new Moodle 2.8+ logstore&lt;br /&gt;
#,(SELECT COUNT(*) FROM mdl_logstore_standard_log AS l WHERE l.courseid = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Student HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(*)&lt;br /&gt;
#FROM mdl_logstore_standard_log AS l&lt;br /&gt;
#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) &lt;br /&gt;
#WHERE l.courseid = course.id ) AS &amp;quot;Teacher HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_log AS l WHERE l.course = course.id) AS Hits&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM mdl_log AS l&lt;br /&gt;
JOIN mdl_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN mdl_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = course.id) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course c&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = c.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND c.id = course.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
) AS Teachers&lt;br /&gt;
  &lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = course.id) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(DISTINCT cm.module) FROM prefix_course_modules cm &lt;br /&gt;
  WHERE cm.course = course.id) UniqueModules&lt;br /&gt;
&lt;br /&gt;
,(SELECT GROUP_CONCAT(DISTINCT m.name) &lt;br /&gt;
  FROM prefix_course_modules cm &lt;br /&gt;
  JOIN mdl_modules as m ON m.id = cm.module&lt;br /&gt;
  WHERE cm.course = course.id) UniqueModuleNames&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;ouwiki&#039;, &#039;wiki&#039;) ) &amp;quot;Num Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;oublog&#039;) ) &amp;quot;Num Blogs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM mdl_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN ( &#039;forum&#039;, &#039;forumng&#039;) ) &amp;quot;Num Forums&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;resource&#039;, &#039;folder&#039;, &#039;url&#039;, &#039;tab&#039;, &#039;file&#039;, &#039;book&#039;, &#039;page&#039;) ) Resources&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;forum&#039;, &#039;forumng&#039;, &#039;oublog&#039;, &#039;page&#039;, &#039;file&#039;, &#039;url&#039;, &#039;wiki&#039; , &#039;ouwiki&#039;) ) &amp;quot;Basic Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;advmindmap&#039;, &#039;assign&#039;, &#039;attendance&#039;, &#039;book&#039;, &#039;choice&#039;, &#039;folder&#039;, &#039;tab&#039;, &#039;glossary&#039;, &#039;questionnaire&#039;, &#039;quiz&#039;, &#039;label&#039; ) ) &amp;quot;Avarage Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm JOIN mdl_modules as m ON m.id = cm.module &lt;br /&gt;
  WHERE cm.course = course.id AND m.name IN (&#039;elluminate&#039;, &#039;game&#039;, &#039;workshop&#039;) ) &amp;quot;Advanced Activities&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course&lt;br /&gt;
&lt;br /&gt;
#WHERE course.shortname LIKE &#039;%2015%&#039;&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_SEARCHTEXT:course.shortname:~%%&lt;br /&gt;
&lt;br /&gt;
WHERE course.fullname LIKE &#039;%2015%&#039; &lt;br /&gt;
&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY UniqueModules DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Course Reports==&lt;br /&gt;
===Most Active courses===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(l.userid) AS Views&lt;br /&gt;
FROM `mdl_logstore_standard_log` l, `mdl_user` u, `mdl_role_assignments` r&lt;br /&gt;
WHERE l.courseid=35&lt;br /&gt;
AND l.userid = u.id&lt;br /&gt;
AND (l.timecreated &amp;gt; UNIX_TIMESTAMP(&#039;2015-01-01 00:00:00&#039;) AND l.timecreated &amp;lt;= UNIX_TIMESTAMP(&#039;2015-01-31 23:59:59&#039;))AND r.contextid= (&lt;br /&gt;
	 SELECT id&lt;br /&gt;
	 FROM mdl_context&lt;br /&gt;
	 WHERE contextlevel=50 AND instanceid=l.courseid&lt;br /&gt;
 )&lt;br /&gt;
AND r.roleid=5&lt;br /&gt;
AND r.userid = u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Active courses, advanced===&lt;br /&gt;
Including: Teacher&#039;s name, link to the course, All types of log activities, special YEAR generated field, Activities and Resource count, enrolled Student count&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשע&#039; THEN &#039;תשע&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעא&#039; THEN &#039;תשעא&#039;&lt;br /&gt;
  WHEN c.fullname LIKE &#039;%תשעב&#039; THEN &#039;תשעב&#039;&lt;br /&gt;
END AS Year&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = l.course) Modules&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_log l &lt;br /&gt;
INNER JOIN prefix_course c ON l.course = c.id&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
#The following line restricts the courses returned to those having more than 2 modules.  Adjust based on your needs.&lt;br /&gt;
HAVING Modules &amp;gt; 2&lt;br /&gt;
ORDER BY Year DESC, hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Least active or probably empty courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;-1&amp;quot; instead of &amp;quot;0&amp;quot; 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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
c.fullname,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;CourseLink&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timecreated), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timecreated&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;Timemodified&#039;,&lt;br /&gt;
CASE&lt;br /&gt;
 WHEN c.timecreated = c.timemodified THEN &#039;-1&#039;&lt;br /&gt;
 ELSE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated))&lt;br /&gt;
END AS &#039;DateDifference&#039;,&lt;br /&gt;
COUNT(ue.id) AS Enroled&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = c.id&lt;br /&gt;
LEFT JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
WHERE DATEDIFF(FROM_UNIXTIME(c.timemodified),FROM_UNIXTIME(c.timecreated) ) &amp;lt; 60&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
HAVING COUNT(ue.id) &amp;lt;= 3&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Count unique teachers with courses that use at least X module (Moodle19)===&lt;br /&gt;
You can remove the outer &amp;quot;SELECT COUNT(*) FROM (...) AS ActiveTeachers&amp;quot; SQL query and get the list of the Teachers and Courses.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(*)&lt;br /&gt;
FROM (SELECT c.id AS CourseID, c.fullname AS Course, ra.roleid AS RoleID, CONCAT(u.firstname, &#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_course_modules cm WHERE cm.course = c.id) AS Modules&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid AND ctx.contextlevel = 50 &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE  ra.roleid = 3 &lt;br /&gt;
GROUP BY u.id&lt;br /&gt;
HAVING Modules &amp;gt; 5) AS ActiveTeachers&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RESOURCE count for each COURSE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) count, l.course, c.fullname coursename&lt;br /&gt;
FROM prefix_resource l INNER JOIN prefix_course c on l.course = c.id&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY count DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Common resource types count for each Category (Moodle19)===&lt;br /&gt;
Including sub-categories in total count.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category&lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Links&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;file&#039; AND r.reference NOT LIKE &#039;http://%&#039;&lt;br /&gt;
) AS Files&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;directory&#039; &lt;br /&gt;
) AS Folders&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT( * ) &lt;br /&gt;
FROM prefix_resource AS r&lt;br /&gt;
JOIN prefix_course AS c ON c.id = r.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%&#039;, mccid, &#039;%&#039; ) AND r.TYPE = &#039;html&#039; &lt;br /&gt;
) AS Pages&lt;br /&gt;
 &lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM stats_log_context_role_course &lt;br /&gt;
WHERE roleid = 5 AND module = &#039;resource&#039; AND category = mcc.id&lt;br /&gt;
) AS Hits&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Where &amp;quot;stats_log_context_role_course&amp;quot; (in the above SQL query) is a VIEW generated by:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
CREATE VIEW stats_log_context_role_course AS&lt;br /&gt;
SELECT l.course, c.category, cc.path, l.module, l.action, ra.userid, ra.roleid&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS context ON context.instanceid = l.course AND context.contextlevel = 50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.userid = l.userid AND ra.contextid = context.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Same query but for Moodle2+&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT mcc.id AS mccid, CONCAT( LPAD( &#039;&#039;, mcc.depth, &#039;.&#039; ) , mcc.name ) AS Category,&lt;br /&gt;
mcc.path,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_url AS u&lt;br /&gt;
JOIN prefix_course AS c ON c.id = u.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS URLs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_folder AS f&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS FOLDERs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_page AS p&lt;br /&gt;
JOIN prefix_course AS c ON c.id = p.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS PAGEs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_book AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS BOOKs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_label AS l&lt;br /&gt;
JOIN prefix_course AS c ON c.id = l.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS LABELs,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_tab AS t&lt;br /&gt;
JOIN prefix_course AS c ON c.id = t.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
WHERE cc.path LIKE CONCAT( &#039;%/&#039;, mccid, &#039;%&#039; )&lt;br /&gt;
) AS TABs&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_categories AS mcc&lt;br /&gt;
ORDER BY mcc.path&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed Resource COUNT by Teacher in each course===&lt;br /&gt;
&lt;br /&gt;
Including (optional) filter by: year, semester and course id.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
, c.id&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעב%&#039; THEN &#039;2012&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%תשעא%&#039; THEN &#039;2011&#039;&lt;br /&gt;
END ) as Year&lt;br /&gt;
, (CASE &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר א%&#039; THEN &#039;Semester A&#039; &lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ב%&#039; THEN &#039;Semester B&#039;&lt;br /&gt;
WHEN c.fullname LIKE &#039;%סמסטר ק%&#039; THEN &#039;Semester C&#039;&lt;br /&gt;
END ) as Semester&lt;br /&gt;
,COUNT(c.id) AS Total&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 20) AS TABs&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules AS cm WHERE cm.course = c.id AND cm.module= 33) AS BOOKs&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_resource` as r &lt;br /&gt;
JOIN `prefix_course` AS c on c.id = r.course&lt;br /&gt;
#WHERE type= &#039;file&#039; and reference NOT LIKE &#039;http://%&#039; &lt;br /&gt;
&lt;br /&gt;
#WHERE 1=1&lt;br /&gt;
#%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
#AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
&lt;br /&gt;
GROUP BY course&lt;br /&gt;
ORDER BY COUNT(c.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses that are defined as using GROUPs===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/group/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,(SELECT count(*) FROM prefix_course_modules cm WHERE cm.course = c.id) Modules&lt;br /&gt;
,(SELECT count(*) FROM prefix_groups g WHERE g.courseid = c.id) Groups&lt;br /&gt;
 FROM `prefix_course` AS c&lt;br /&gt;
WHERE groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Groups===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with Groups in them (groupmode &amp;gt; 0). You can also use groupmode=1 to list just Separate type groups or groupmode=2 to list Visible type groups.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name, c.groupmode&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON c.id = g.courseid&lt;br /&gt;
WHERE c.groupmode &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users enrolled in a course with groups but not assigned a group ===&lt;br /&gt;
&lt;br /&gt;
Displays by course all enrolled users that have not been assigned a group in courses that have groups. NOTE: This needs to be optimized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DISTINCT&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
,(SELECT shortname FROM prefix_role WHERE id=en.roleid) AS ROLE&lt;br /&gt;
,(SELECT name FROM prefix_role WHERE id=en.roleid) AS RoleName&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user AS user2 ON ue.userid = user2.id&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = course.id&lt;br /&gt;
&lt;br /&gt;
WHERE ue.enrolid NOT IN (select userid from prefix_groups_members WHERE g.id=groupid)&lt;br /&gt;
&lt;br /&gt;
ORDER BY Course, Lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Groups in course with member list===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List the groups in a course (replace the # by the course id number) with the members of each group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname, g.name AS Groupname, u.username&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_user AS u ON m.userid = u.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Group Export===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
There&#039;s a [[Import_groups|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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT g.name AS groupname, g.description, g.enrolmentkey&lt;br /&gt;
FROM prefix_groups AS g &lt;br /&gt;
JOIN prefix_course as c ON g.courseid = c.id&lt;br /&gt;
WHERE c.id = #&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: if you are using Configurable Reports block and want to perform this query on the current course you are in, then you can use a WHERE clause like this:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Courses in and below a certain category===&lt;br /&gt;
Use this SQL code to retrieve all courses that exist in or under a set category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the category you want to know about...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course. * , prefix_course_categories. *&lt;br /&gt;
FROM prefix_course, prefix_course_categories&lt;br /&gt;
WHERE prefix_course.category = prefix_course_categories.id&lt;br /&gt;
AND (&lt;br /&gt;
prefix_course_categories.path LIKE &#039;/$s/%&#039;&lt;br /&gt;
OR prefix_course_categories.path LIKE &#039;/$s&#039;&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all Categories in one level below a certain category===&lt;br /&gt;
Use this PHP code to retrieve a list of all categories below a certain category.&lt;br /&gt;
&lt;br /&gt;
$s should be the id of the top level category you are interested in.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
require_once(&#039;./config.php&#039;);&lt;br /&gt;
&lt;br /&gt;
$parent_id = $s;&lt;br /&gt;
&lt;br /&gt;
$categories= array();&lt;br /&gt;
&lt;br /&gt;
$categories = get_categories($parent_id);&lt;br /&gt;
&lt;br /&gt;
echo &#039;&amp;lt;ol&amp;gt;&#039;;&lt;br /&gt;
foreach ($categories as $category)&lt;br /&gt;
        {&lt;br /&gt;
        echo &#039;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&#039;.$CFG-&amp;gt;wwwroot.&#039;/course/category.php?id=&#039;.$category-&amp;gt;id.&#039;&amp;quot;&amp;gt;&#039;.$category-&amp;gt;name.&#039;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&#039;;&lt;br /&gt;
        }&lt;br /&gt;
echo &#039;&amp;lt;/ol&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Blog activity per Course (not including VIEW)===&lt;br /&gt;
Filter activity logging to some specific Course Categories!&lt;br /&gt;
+ link course name to actual course (for quick reference)&lt;br /&gt;
(you can change %blog% to %wiki% to filter down all wiki activity or any other module you wish)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID&lt;br /&gt;
,m.name ,count(cm.id) as counter &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS Students&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE `module` LIKE &#039;%blog%&#039; AND course = c.id AND action NOT LIKE &#039;%view%&#039; ) as BlogActivity&lt;br /&gt;
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 &lt;br /&gt;
WHERE m.name LIKE &#039;%blog%&#039; AND c.category IN ( 8,13,15)&lt;br /&gt;
GROUP BY cm.course,cm.module order by counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Student&#039;s posts content in all course blogs (oublog)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
b.name &lt;br /&gt;
,op.title&lt;br /&gt;
,op.message&lt;br /&gt;
,( SELECT CONCAT(u.firstname, &#039; &#039;,u.lastname) FROM prefix_user AS u WHERE u.id = oi.userid) AS &amp;quot;Username&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_oublog_posts AS op&lt;br /&gt;
JOIN prefix_oublog_instances AS oi ON oi.id = op.oubloginstancesid &lt;br /&gt;
JOIN prefix_oublog as b ON b.id = oi.oublogid&lt;br /&gt;
JOIN prefix_course AS c ON b.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Courses which uploaded a Syllabus file===&lt;br /&gt;
+ under specific Category&lt;br /&gt;
+ show first Teacher in that course&lt;br /&gt;
+ link Course&#039;s fullname to actual course&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) as Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user as u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) as Teacher&lt;br /&gt;
FROM prefix_resource as r &lt;br /&gt;
JOIN prefix_course as c ON r.course = c.id&lt;br /&gt;
WHERE ( r.name LIKE &#039;%סילבוס%&#039; OR r.name LIKE &#039;%סילאבוס%&#039; OR r.name LIKE &#039;%syllabus%&#039; OR r.name LIKE &#039;%תכנית הקורס%&#039; ) &lt;br /&gt;
AND c.category IN (10,18,26,13,28)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
===Site-wide completed SCORM activities by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===All users enrolled in a course without a role===&lt;br /&gt;
Identifies All users that are enrolled in a course but are not assigned a role.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user.firstname AS Firstname,&lt;br /&gt;
user.lastname AS Lastname,&lt;br /&gt;
user.idnumber Employee_ID,&lt;br /&gt;
course.fullname AS Course&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS course &lt;br /&gt;
JOIN prefix_enrol AS en ON en.courseid = course.id&lt;br /&gt;
JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id&lt;br /&gt;
JOIN prefix_user as user ON user.id = ue.userid&lt;br /&gt;
&lt;br /&gt;
WHERE user.id NOT IN (&lt;br /&gt;
SELECT u.id&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_role AS r ON r.id = ra.roleid&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE c.id=course.id&lt;br /&gt;
)&lt;br /&gt;
ORDER BY Course, Lastname, Firstname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List course resources accumulative file size and count===&lt;br /&gt;
This is the main (first) report, which has a link (alias) to a second report (the following on this page) which list each file in the course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id &amp;quot;CourseID&amp;quot;, context.id &amp;quot;ContextID&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;, c.id, &#039;&amp;quot;&amp;gt;&#039;, c.fullname ,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Course Name&amp;quot;&lt;br /&gt;
, COUNT(*) &amp;quot;Course Files&amp;quot; , ROUND( SUM( f.filesize ) /1048576 ) AS file_size_MB&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/blocks/configurable_reports/viewreport.php?alias=coursefiles&amp;amp;courseid=1&amp;amp;filter_courses=&#039;, c.id, &#039;&amp;quot;&amp;gt;List files&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List Files&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
JOIN mdl_context AS context ON context.id = f.contextid&lt;br /&gt;
JOIN mdl_course AS c ON c.id = (&lt;br /&gt;
  SELECT instanceid&lt;br /&gt;
  FROM mdl_context&lt;br /&gt;
  WHERE id = SUBSTRING_INDEX( SUBSTRING_INDEX( context.path, &#039;/&#039; , -2 ) , &#039;/&#039;, 1 ) )&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this report, you will have to define &amp;quot;alias&amp;quot; report property to &amp;quot;coursefiles&amp;quot; for it to be able to be called from the above report.&lt;br /&gt;
And also setup (add) a FILTER_COURSES filter. &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
id ,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/pluginfile.php/&#039;, contextid, &#039;/&#039;, component, &#039;/&#039;, filearea, &#039;/&#039;, itemid, &#039;/&#039;, filename, &#039;&amp;quot;&amp;gt;&#039;, filename,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;File&amp;quot;&lt;br /&gt;
,filesize, mimetype ,author, license, timecreated, component, filearea, filepath&lt;br /&gt;
&lt;br /&gt;
FROM mdl_files AS f&lt;br /&gt;
WHERE filesize &amp;gt;0&lt;br /&gt;
            AND f.contextid&lt;br /&gt;
            IN (   SELECT id&lt;br /&gt;
                     FROM mdl_context&lt;br /&gt;
                    WHERE path &lt;br /&gt;
                     LIKE (   SELECT CONCAT(&#039;%/&#039;,id,&#039;/%&#039;)&lt;br /&gt;
                                  AS contextquery&lt;br /&gt;
                                FROM mdl_context&lt;br /&gt;
                               WHERE 1=1&lt;br /&gt;
			        %%FILTER_COURSES:instanceid%%&lt;br /&gt;
                                 AND contextlevel = 50&lt;br /&gt;
                           )&lt;br /&gt;
                )&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Which courses has redundant topics===&lt;br /&gt;
This report list several &amp;quot;active topics&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
The following, second SQL query, could be used to &amp;quot;trim&amp;quot; down those redundant course topics/sections/weeks by updating the course format&#039;s numsection (Number of sections) setting. (It&#039;s a per course format setting!)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT id, format,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;, c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course &lt;br /&gt;
&lt;br /&gt;
,(SELECT value  FROM  `mdl_course_format_options` WHERE  `courseid` = c.id AND `format` = c.format AND `name` = &#039;numsections&#039; ) AS &amp;quot;numsections&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND `sequence` !=  &#039;&#039; ) AS &amp;quot;Non empty sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id ) AS &amp;quot;Total section count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND sequence IS NOT NULL) AS &amp;quot;Non NULL sections count&amp;quot;&lt;br /&gt;
,(SELECT COUNT(*) FROM  `mdl_course_sections` WHERE  `course` = c.id AND name != &#039;&#039;) AS &amp;quot;Non empty section Name count&amp;quot;&lt;br /&gt;
 ,(SELECT COUNT(*) FROM mdl_course_modules cm WHERE cm.course = c.id) &amp;quot;Modules count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course AS c&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following SQL REPLACE query is used for &amp;quot;fixing&amp;quot; (updating) the &amp;quot;numsections&amp;quot; of a specific course format &amp;quot;onetopics&amp;quot; (you can always change it, or discard it to use this SQL REPLACE on all course formats) &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
REPLACE INTO `mdl_course_format_options` (`id`, `courseid`, `format`, `sectionid`, `name`, `value`) &lt;br /&gt;
SELECT NULL, c.id, &#039;onetopic&#039;, &#039;0&#039;, &#039;numsections&#039;, (SELECT COUNT(*) FROM `mdl_course_sections` WHERE `course` = c.id AND name != &#039;&#039;)&lt;br /&gt;
FROM `mdl_course` c where format = &#039;onetopic&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hidden Courses with Students Enrolled===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.visible AS Visible, &lt;br /&gt;
DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors,&lt;br /&gt;
&lt;br /&gt;
(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;, &lt;br /&gt;
&lt;br /&gt;
now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
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) &amp;gt; 0&lt;br /&gt;
ORDER BY StartDate, Instructor_Email, Course_ID&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Course Design Reports==&lt;br /&gt;
&lt;br /&gt;
These are reports which summarize course design aspects, such as activity and resource modules per section, types of activities used, etc.&lt;br /&gt;
&lt;br /&gt;
===Course Content/Week===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
This report assumes that the first 14 sections in a course, not including the &amp;quot;0&amp;quot; or &amp;quot;Welcome&amp;quot; section, correspond to weeks (with &amp;quot;Subsections&amp;quot; given numbers much higher in the sequence). Of those sections, each is checked to count the number of:&lt;br /&gt;
&lt;br /&gt;
    Forums&lt;br /&gt;
    Graded Activities (may include Forums)&lt;br /&gt;
    Resources (not including a Label)&lt;br /&gt;
&lt;br /&gt;
Totals of each of these types of content elements per section are provided.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Only visible resources and activities are counted.&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: this is a &amp;quot;Global&amp;quot; report.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
 &lt;br /&gt;
cs.section AS &#039;Week&#039;&lt;br /&gt;
, cs.name AS &#039;Section Name&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT LIKE &#039;label&#039;),cm.id,NULL)) AS &#039;Ungraded Resources&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Graded Activities&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.section &amp;lt;= 14 AND cs.section &amp;gt; 0&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cs.visible = 1&lt;br /&gt;
AND cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY cs.section&lt;br /&gt;
ORDER BY cs.section&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments and Weights===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Categories with weights of 0 are not included in this report.&lt;br /&gt;
&lt;br /&gt;
Only visible activities are included in this report.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: This is designed to be a &amp;quot;Global&amp;quot; report in Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
IF(gc.parent IS NOT NULL, gc.fullname, &#039;None&#039;) AS &#039;Grade Book Category&#039;&lt;br /&gt;
, IF(gc.parent IS NOT NULL, ROUND(gic.aggregationcoef, 2), ROUND(SUM(DISTINCT gi.aggregationcoef), 2)+ROUND(SUM(DISTINCT mgi.aggregationcoef), 2)) AS &#039;Category weight&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT_WS(&#039;, &#039;,GROUP_CONCAT(DISTINCT gi.itemmodule SEPARATOR &#039;, &#039;), IF(mgi.id, &#039;manual&#039;,NULL)) AS &#039;Activity Types&#039;&lt;br /&gt;
, COUNT(DISTINCT gi.itemmodule) + IF(mgi.id,1,0) AS &#039;Different Activity Types&#039;&lt;br /&gt;
, CONCAT_WS(&#039;&amp;lt;br&amp;gt;&#039;, GROUP_CONCAT(DISTINCT gi.itemname ORDER BY gi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;), GROUP_CONCAT(DISTINCT mgi.itemname ORDER BY mgi.itemname SEPARATOR &#039;&amp;lt;br&amp;gt;&#039;)) AS &#039;Activity Names&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) + COUNT(DISTINCT mgi.id) AS &#039;Activity Count&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
&lt;br /&gt;
#get grade categories&lt;br /&gt;
LEFT JOIN prefix_grade_categories AS gc ON gc.courseid = c.id &lt;br /&gt;
# back from categories to grade items to get aggregations and weights&lt;br /&gt;
JOIN prefix_grade_items AS gic ON gic.courseid = c.id AND gic.itemtype = &#039;category&#039; AND gic.aggregationcoef != 0 AND (LOCATE(gic.iteminstance, gc.path) OR (gc.parent IS NULL))&lt;br /&gt;
&lt;br /&gt;
# attach activities to course&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = c.id &lt;br /&gt;
# attach grade items to activities&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.iteminstance = cm.instance AND gi.itemtype = &#039;mod&#039; AND gi.categoryid = gc.id AND gi.hidden != 1&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039; AND mgi.categoryid = gc.id&lt;br /&gt;
&lt;br /&gt;
WHERE &lt;br /&gt;
cm.visible = 1&lt;br /&gt;
AND c.id = %%COURSEID%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.id&lt;br /&gt;
ORDER BY gc.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Pre-Term Course Review===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
#   &amp;quot;Required blocks&amp;quot; include Instructor Block (mooprofile), Activities, and the Research block.&lt;br /&gt;
#    &amp;quot;Instructor Details&amp;quot; block is not the &amp;quot;Instructor&amp;quot; block (mooprofile) automatically provided by the system. It is an optional block that can be edited by the instructor. If not edited to remove boilerplate text, it should be hidden.&lt;br /&gt;
#    All courses should be in the &amp;quot;Collapsed Topics&amp;quot; format with the &amp;quot;Weeks&amp;quot; structure.&lt;br /&gt;
#    &amp;quot;Weeks defined in course settings&amp;quot; is taken from our SIS when the course shells are created, but can be edited by faculty. &amp;quot;# of weeks named and visible&amp;quot; should usually match or exceed this value.&lt;br /&gt;
#    We recommend that each week contain at least one forum, at least one graded activity, and at least one ungraded resource.&lt;br /&gt;
#    &amp;quot;Syllabus updated&amp;quot; date is for the first attached file found with the text &amp;quot;syllabus&amp;quot; in the name. The &amp;quot;Days ago&amp;quot; calculation is included for convenience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: At our institution, we construct categories each term, and insert a text string &amp;quot;staging&amp;quot; in the Category ID for pre-term courses during the preparation or &amp;quot;staging&amp;quot; phase of course development. We remove this text string (and change it to &amp;quot;production&amp;quot;) when courses go live at the start of the new term.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
#,RIGHT(c.idnumber,2) AS Type # Specific to GSC &amp;quot;Instructional Method&amp;quot; storage&lt;br /&gt;
&lt;br /&gt;
#, substring_index(substr(c.shortname FROM locate(&#039;.&#039;,c.shortname)+1),&#039;-&#039;,1) AS Section # Specific to GSC&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/user/view.php&#039;,CHAR(63),&#039;id=&#039;,u.id,&#039;&amp;quot;&amp;gt;&#039;,u.lastname,&#039;, &#039;, u.firstname,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Instructor&#039; &lt;br /&gt;
&lt;br /&gt;
,(SELECT IF((u2.description IS NULL) OR (u2.description LIKE &#039;&#039;),&#039;NO&#039;, &#039;YES&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u2 ON u2.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Bio&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT IF(u3.picture &amp;gt; 0,&#039;YES&#039;,&#039;NO&#039;)&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u3 ON u3.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS &#039;Profile Has Picture&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(((bpi.visible IS NULL) OR (bpi.visible !=0)) AND ((bpm.visible IS NULL) OR (bpm.visible !=0)) AND ((bpa.visible IS NULL) OR (bpa.visible !=0)) AND ((bpr.visible IS NULL) OR (bpr.visible !=0)),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Required blocks visible&#039;&lt;br /&gt;
#, IF((bpm.visible IS NULL) OR (bpm.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;Messages block visible&#039;&lt;br /&gt;
#, IF((bpa.visible IS NULL) OR (bpa.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;activities block visible&#039;&lt;br /&gt;
#, IF((bpr.visible IS NULL) OR (bpr.visible !=0),&#039;YES&#039;,&#039;NO&#039;) AS &#039;research block visible&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)) AND (bip.visible !=0),&#039;YES&#039;,&#039;&#039;) AS &#039;Instructor Details Block visible&#039; # This is a hack based on UUencoded string data from the title of HTML &amp;quot;Instructor Details&amp;quot; block&lt;br /&gt;
&lt;br /&gt;
#, IF(bi.configdata LIKE &#039;%ZGl0IHRoaXMgYmxvY2s%&#039;,&#039;NO&#039;,&#039;&#039;) AS &#039;Instructor Details Block Updated&#039; # HTML block has string &#039;dit this block&#039;&lt;br /&gt;
&lt;br /&gt;
#, IF(COUNT(bi.id) -  SUM(IF(bi.configdata LIKE &#039;Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoxODoiSW5zdHJ1Y3RvciBEZXRhaWxzI%&#039;,1,0)),&#039;YES&#039;,&#039;&#039;) AS &#039;possible extra instructor blocks&#039; #looking for any HTML block with &amp;quot;instructor&amp;quot; in the title&lt;br /&gt;
&lt;br /&gt;
, IF(c.format=&#039;topcoll&#039;,&#039;YES&#039;, c.format) AS &#039;Collapsed Topics course format&#039; # change this if you want to test for a different format&lt;br /&gt;
, IF(cfo.value = 2, &#039;YES&#039;,&#039;NO&#039;) AS &#039;weeks structure&#039;&lt;br /&gt;
&lt;br /&gt;
, cfw.value AS &#039;weeks defined in course settings&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(((cs.name IS NOT NULL) AND (cs.visible = 1) AND (cs.section != &#039;0&#039;) AND (cs.sequence IS NOT NULL)),cs.id,NULL)) AS &#039;# of weeks named &amp;amp; visible (includes orphans)&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039;, cm.id, NULL)) AS &#039;Forums&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(m.name LIKE &#039;forum&#039; ,cs.id , NULL)) AS &#039;Weeks with Forum&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cm.id, NULL)) AS &#039;Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT IF(gi.id, cs.id, NULL)) AS &#039;Weeks with Activities&#039;&lt;br /&gt;
, COUNT(DISTINCT mgi.id) AS &#039;Manual Grade Items&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)),cm.id,NULL)) AS &#039;Resources&#039;&lt;br /&gt;
, COUNT(DISTINCT IF((gi.id IS NULL) AND (m.name NOT IN (&#039;forum&#039;,&#039;label&#039;)), cs.id, NULL)) AS &#039;Weeks with Resources&#039;&lt;br /&gt;
&lt;br /&gt;
# Here are some other things you could check for per course&lt;br /&gt;
#,(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 &#039;%forum%&#039;) AS Forums&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%quiz%&#039;) AS Quizzes&lt;br /&gt;
 &lt;br /&gt;
#,(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 &#039;%assign%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_resource.id) FROM prefix_resource JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course) AS Files&lt;br /&gt;
&lt;br /&gt;
#,(SELECT COUNT(prefix_url.id) FROM prefix_url JOIN prefix_course ON prefix_course.id = prefix_url.course WHERE c.id = prefix_url.course) AS Links&lt;br /&gt;
&lt;br /&gt;
,(SELECT FROM_UNIXTIME(MAX(prefix_resource.timemodified))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS SyllabusDate&lt;br /&gt;
&lt;br /&gt;
,(SELECT TO_DAYS(NOW())-TO_DAYS(FROM_UNIXTIME(MAX(prefix_resource.timemodified)))&lt;br /&gt;
FROM prefix_resource&lt;br /&gt;
JOIN prefix_course ON prefix_course.id = prefix_resource.course WHERE c.id = prefix_resource.course AND prefix_resource.name LIKE &#039;%syllabus%&#039;) AS DaysAgo&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, f.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement Forum Visible&#039;&lt;br /&gt;
&lt;br /&gt;
, IF(COUNT(DISTINCT IF(f.type LIKE &#039;news&#039;, fd.id,NULL)),&#039;YES&#039;,&#039;NO&#039; ) AS &#039;Announcement posted&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN prefix_course_categories as cc ON c.category = cc.id&lt;br /&gt;
LEFT JOIN prefix_context AS ctxx ON c.id = ctxx.instanceid &lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpi ON bpi.contextid = ctxx.id AND bpi.blockinstanceid = &#039;43692&#039; # mooprofile&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpm ON bpm.contextid = ctxx.id AND bpm.blockinstanceid = &#039;43962&#039; # messages&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpa ON bpa.contextid = ctxx.id AND bpa.blockinstanceid = &#039;43963&#039; # activities&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bpr ON bpr.contextid = ctxx.id AND bpr.blockinstanceid = &#039;38368&#039; # html research help&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_sections AS cs ON cs.course = c.id AND cs.visible = 1 AND cs.sequence IS NOT NULL&lt;br /&gt;
LEFT JOIN prefix_course_modules AS cm ON cm.course = c.id AND cm.section = cs.id &lt;br /&gt;
LEFT JOIN prefix_modules AS m ON m.id = cm.module&lt;br /&gt;
LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_forum AS f ON f.course = c.id AND cm.instance = f.id AND cm.visible = 1&lt;br /&gt;
LEFT JOIN prefix_forum_discussions AS fd ON fd.forum = f.id&lt;br /&gt;
&lt;br /&gt;
# attach manual grade items to course-- they don&#039;t have modules&lt;br /&gt;
LEFT JOIN prefix_grade_items AS mgi ON mgi.courseid = c.id and mgi.itemtype = &#039;manual&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfo ON cfo.courseid = c.id AND cfo.name = &#039;layoutstructure&#039;&lt;br /&gt;
LEFT JOIN prefix_course_format_options AS cfw ON cfw.courseid = c.id AND cfw.name = &#039;numsections&#039;&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN prefix_block_instances AS bi ON bi.parentcontextid = ctxx.id AND bi.blockname = &#039;html&#039; AND (bi.configdata LIKE &#039;%SW5zdHJ1Y3Rvc%&#039; or bi.configdata LIKE &#039;%bnN0cnVjdG9y%&#039;)&lt;br /&gt;
LEFT JOIN prefix_block_positions AS bip ON bip.blockinstanceid = bi.id&lt;br /&gt;
&lt;br /&gt;
WHERE RIGHT(c.idnumber,2) IN (&#039;OL&#039;, &#039;BL&#039;, &#039;HY&#039;) &lt;br /&gt;
# AND substring(cc.path,2,2) IN (&#039;26&#039;) # Staging&lt;br /&gt;
#AND substring(cc.path,2,3) IN (&#039;158&#039;) # UG&lt;br /&gt;
AND cc.idnumber LIKE &#039;%staging%&#039;&lt;br /&gt;
AND ctxx.contextlevel = 50&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Module instances + Module HITs by role teacher and student in course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
m.name AS &amp;quot;Module name&amp;quot;&lt;br /&gt;
, COUNT(*) AS &amp;quot;Module count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name ) AS &amp;quot;Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 5 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Students HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
JOIN prefix_context AS con ON con.instanceid= l.course AND con.contextlevel=50&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid= con.id AND ra.userid= l.userid AND ra.roleid = 3 &lt;br /&gt;
WHERE l.course = cm.course AND l.module = m.name) AS &amp;quot;Teachers HITs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_course_modules AS cm&lt;br /&gt;
JOIN mdl_modules AS m on m.id = cm.module&lt;br /&gt;
WHERE cm.course = &#039;%%COURSEID%%&#039;&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Grade and Course Completion Reports==&lt;br /&gt;
===Site-Wide Grade Report with All Items===&lt;br /&gt;
Shows grades for all course items along with course totals for each student. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gi.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
For MySQL users, you&#039;ll need to use the MySQL DATE_ADD function instead of DATEADD. Replace the line&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
DATEADD(ss,gi.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
with&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
DATE_ADD(&#039;1970-01-01&#039;, INTERVAL gi.timemodified SECOND) AS Time&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site-Wide Grade Report with Just Course Totals===&lt;br /&gt;
A second site-wide grade report for all students that just shows course totals. Works with ad-hoc reports or Configurable Reports&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, u.firstname + &#039; &#039; + u.lastname AS &#039;Display Name&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN c.fullname + &#039; Course Total&#039;&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
DATEADD(ss,gg.timemodified,&#039;1970-01-01&#039;) AS Time&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories as cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
WHERE  gi.courseid = c.id AND gi.itemtype = &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For MySQL users:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;First&#039; , u.lastname AS &#039;Last&#039;, CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Display Name&#039;, &lt;br /&gt;
c.fullname AS &#039;Course&#039;, &lt;br /&gt;
cc.name AS &#039;Category&#039;,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN gi.itemtype = &#039;course&#039; &lt;br /&gt;
   THEN CONCAT(c.fullname, &#039; - Total&#039;)&lt;br /&gt;
  ELSE gi.itemname&lt;br /&gt;
END AS &#039;Item Name&#039;,&lt;br /&gt;
&lt;br /&gt;
ROUND(gg.finalgrade,2) AS Grade,&lt;br /&gt;
FROM_UNIXTIME(gg.timemodified) AS TIME&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id&lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
 &lt;br /&gt;
WHERE  gi.courseid = c.id &lt;br /&gt;
ORDER BY lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Learner report by Learner with grades===&lt;br /&gt;
Which Learners in which course and what are the grades&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname AS &#039;Name&#039; , u.lastname AS &#039;Surname&#039;, c.fullname AS &#039;Course&#039;, cc.name AS &#039;Category&#039;, &lt;br /&gt;
CASE WHEN gi.itemtype = &#039;Course&#039;    &lt;br /&gt;
THEN c.fullname + &#039; Course Total&#039;  &lt;br /&gt;
ELSE gi.itemname &lt;br /&gt;
END AS &#039;Item Name&#039;, ROUND(gg.finalgrade,2) AS Score,ROUND(gg.rawgrademax,2) AS Max, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) as Percentage,&lt;br /&gt;
&lt;br /&gt;
if (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) &amp;gt; 79,&#039;Yes&#039; , &#039;No&#039;) as Pass&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c &lt;br /&gt;
JOIN prefix_context AS ctx ON c.id = ctx.instanceid &lt;br /&gt;
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
JOIN prefix_grade_grades AS gg ON gg.userid = u.id &lt;br /&gt;
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid &lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category &lt;br /&gt;
WHERE  gi.courseid = c.id and gi.itemname != &#039;Attendance&#039;&lt;br /&gt;
ORDER BY `Name` ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A very simple report with a list of course completion status by username. Completions are noted by date, blank otherwise. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
  u.username, &lt;br /&gt;
  c.shortname,  &lt;br /&gt;
 DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%Y-%m-%d&#039;) AS completed&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===User Course Completion with Criteria===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A report with course completions by username, with Aggregation method, Criteria types, and Criteria detail where available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username AS user, &lt;br /&gt;
c.shortname AS course,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(t.timecompleted),&#039;%Y-%m-%d&#039;) AS completed,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = c.id AND a.criteriatype IS NULL) = 1) THEN &amp;quot;Any&amp;quot;&lt;br /&gt;
ELSE &amp;quot;All&amp;quot;&lt;br /&gt;
END AS aggregation,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;Self&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN &amp;quot;By Date&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 3 THEN &amp;quot;Unenrol Status&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &amp;quot;Activity&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 5 THEN &amp;quot;Duration&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 6 THEN &amp;quot;Course Grade&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 7 THEN &amp;quot;Approve by Role&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 8 THEN &amp;quot;Previous Course&amp;quot;&lt;br /&gt;
END AS criteriatype,&lt;br /&gt;
CASE &lt;br /&gt;
WHEN p.criteriatype = 1 THEN &amp;quot;*&amp;quot;&lt;br /&gt;
WHEN p.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(p.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN p.criteriatype = 3 THEN t.unenroled&lt;br /&gt;
WHEN p.criteriatype = 4 THEN &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,p.module,&#039;/view.php?id=&#039;,p.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,p.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN p.criteriatype = 5 THEN p.enrolperiod&lt;br /&gt;
WHEN p.criteriatype = 6 THEN CONCAT(&#039;Needed: &#039;,ROUND(p.gradepass,2),&#039; Achieved: &#039;,ROUND(t.gradefinal,2)) &lt;br /&gt;
WHEN p.criteriatype = 7 THEN p.role&lt;br /&gt;
WHEN p.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = p.courseinstance)&lt;br /&gt;
END AS criteriadetail &lt;br /&gt;
FROM prefix_course_completion_crit_compl AS t&lt;br /&gt;
JOIN prefix_user AS u ON t.userid = u.id&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
JOIN prefix_course_completion_criteria AS p ON t.criteriaid = p.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses with Completion Enabled and their settings===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all courses with completion enabled and their Aggregation setting, Criteria types, and Criteria details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT c.shortname AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN (SELECT a.method FROM prefix_course_completion_aggr_methd AS a  WHERE (a.course = t.course AND a.criteriatype IS NULL)) = 2 THEN &amp;quot;All&amp;quot;&lt;br /&gt;
ELSE &amp;quot;Any&amp;quot;&lt;br /&gt;
END AS Course_Aggregation,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;Self completion&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN &amp;quot;Date done by&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;Unenrolement&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 4 THEN &amp;quot;Activity completion&amp;quot;   &lt;br /&gt;
WHEN t.criteriatype = 5 THEN &amp;quot;Duration in days&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 6 THEN &amp;quot;Final grade&amp;quot;     &lt;br /&gt;
WHEN t.criteriatype = 7 THEN &amp;quot;Approve by role&amp;quot; &lt;br /&gt;
WHEN t.criteriatype = 8 THEN &amp;quot;Previous course&amp;quot;&lt;br /&gt;
END AS Criteria_type,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN t.criteriatype = 1 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 2 THEN DATE_FORMAT(FROM_UNIXTIME(t.timeend),&#039;%Y-%m-%d&#039;)&lt;br /&gt;
WHEN t.criteriatype = 3 THEN &amp;quot;On&amp;quot;&lt;br /&gt;
WHEN t.criteriatype = 4 THEN&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,t.module,&#039;/view.php?id=&#039;,t.moduleinstance,&#039;&amp;quot;&amp;gt;&#039;,t.module,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
WHEN t.criteriatype = 5 THEN ROUND(t.enrolperiod/86400)&lt;br /&gt;
WHEN t.criteriatype = 6 THEN ROUND(t.gradepass,2)&lt;br /&gt;
WHEN t.criteriatype = 7 THEN (SELECT r.shortname FROM prefix_role AS r WHERE r.id = t.role)&lt;br /&gt;
WHEN t.criteriatype = 8 THEN (SELECT pc.shortname FROM prefix_course AS pc WHERE pc.id = t.courseinstance)&lt;br /&gt;
END AS Criteria_detail&lt;br /&gt;
FROM prefix_course_completion_criteria as t&lt;br /&gt;
JOIN prefix_course AS c ON t.course = c.id&lt;br /&gt;
WHERE c.enablecompletion = 1&lt;br /&gt;
ORDER BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Completion Report with custom dates===&lt;br /&gt;
&lt;br /&gt;
List of users who completed multiple or single course/s from a start date to end date chosen by the user. The output gives username, name, course name, completion date and score&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT u.username AS &#039;User Name&#039;,&lt;br /&gt;
CONCAT(u.firstname , &#039; &#039; , u.lastname) AS &#039;Name&#039;,&lt;br /&gt;
c.shortname AS &#039;Course Name&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(p.timecompleted),&#039;%W %e %M, %Y&#039;) AS &#039;Completed Date&#039;,&lt;br /&gt;
ROUND(c4.gradefinal,2) AS &#039;Score&#039;&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_course AS c ON p.course = c.id&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
JOIN prefix_course_completion_crit_compl AS c4 ON u.id = c4.userid&lt;br /&gt;
WHERE c.enablecompletion = 1  AND (p.timecompleted IS NOT NULL OR p.timecompleted !=&#039;&#039;) &lt;br /&gt;
AND (p.timecompleted&amp;gt;= :start_date AND p.timecompleted&amp;lt;=:end_date)&lt;br /&gt;
GROUP BY u.username&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Scales used in activities===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT scale.name&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/&#039;,gi.itemmodule,&#039;/view.php?id=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module View&amp;quot;&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/modedit.php?up&#039;,&#039;date=&#039;,cm.id,&#039;&amp;quot;&amp;gt;&#039;,gi.itemname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;Module Settings&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON c.id = gi.courseid&lt;br /&gt;
JOIN prefix_course_modules AS cm ON cm.course = gi.courseid AND cm.instance = gi.iteminstance&lt;br /&gt;
JOIN prefix_scale AS scale ON scale.id = gi.scaleid&lt;br /&gt;
WHERE gi.scaleid IS NOT NULL&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Extra Credit Items by Name Only===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
This query identifies grade items in visible courses with student enrollment that have &amp;quot;extra credit&amp;quot; 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).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT DATE(FROM_UNIXTIME(c.startdate)) AS StartDate, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, gi.itemname AS Item_Name&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT( ra.userid ) FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id) AS Instructors&lt;br /&gt;
&lt;br /&gt;
,(SELECT DISTINCT concat(&#039;&amp;lt;a href=&amp;quot;mailto:&#039;,u.email,&#039;&amp;quot;&amp;gt;&#039;,u.email,&#039;&amp;lt;/a&amp;gt;&#039;)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS &#039;Instructor_Email&#039;&lt;br /&gt;
&lt;br /&gt;
,now() AS Report_Timestamp&lt;br /&gt;
&lt;br /&gt;
FROM prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course AS c ON gi.courseid = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE gi.itemname LIKE &#039;%extra credit%&#039; &lt;br /&gt;
	AND gi.gradetype = &#039;1&#039; &lt;br /&gt;
	AND gi.hidden = &#039;0&#039; &lt;br /&gt;
	AND gi.aggregationcoef = &#039;0&#039; &lt;br /&gt;
	AND c.visible = 1&lt;br /&gt;
	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) &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
GROUP BY Course_ID, gi.id&lt;br /&gt;
ORDER BY StartDate, Course_ID&lt;br /&gt;
 &lt;br /&gt;
%%FILTER_SEARCHTEXT:Course_ID:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Site Wide Number of Courses Completed by User===&lt;br /&gt;
Contributed by Ken St. John&lt;br /&gt;
&lt;br /&gt;
Simple report that shows the number of completed courses for all users site wide&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.lastname, u.firstname,&lt;br /&gt;
COUNT(p.timecompleted) AS TotalCompletions&lt;br /&gt;
FROM prefix_course_completions AS p&lt;br /&gt;
JOIN prefix_user AS u ON p.userid = u.id&lt;br /&gt;
GROUP BY p.userid&lt;br /&gt;
ORDER BY u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Activity Module Reports==&lt;br /&gt;
&lt;br /&gt;
=== User activity completions with dates===&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.username As &#039;User&#039;,&lt;br /&gt;
c.shortname AS &#039;Course&#039;,&lt;br /&gt;
m.name AS Activitytype, &lt;br /&gt;
CASE &lt;br /&gt;
    WHEN cm.module = 1 THEN (SELECT a1.name FROM prefix_assign a1            WHERE a1.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 2 THEN (SELECT a2.name FROM prefix_assignment a2    WHERE a2.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 3 THEN (SELECT a3.name FROM prefix_book a3               WHERE a3.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 4 THEN (SELECT a4.name FROM prefix_chat a4                WHERE a4.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 5 THEN (SELECT a5.name FROM prefix_choice a5            WHERE a5.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 6 THEN (SELECT a6.name FROM prefix_data a6                WHERE a6.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 7 THEN (SELECT a7.name FROM prefix_feedback a7        WHERE a7.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 8 THEN (SELECT a8.name FROM prefix_folder a8              WHERE a8.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 9 THEN (SELECT a9.name FROM prefix_forum a9              WHERE a9.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 10 THEN (SELECT a10.name FROM prefix_glossary a10         WHERE a10.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 11 THEN (SELECT a11.name FROM prefix_imscp  a11           WHERE a11.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 12 THEN (SELECT a12.name FROM prefix_label a12              WHERE a12.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 13 THEN (SELECT a13.name FROM prefix_lesson a13            WHERE a13.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 14 THEN (SELECT a14.name FROM prefix_lti a14                    WHERE a14.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 15 THEN (SELECT a15.name FROM prefix_page a15               WHERE a15.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 16 THEN (SELECT a16.name FROM prefix_quiz  a16               WHERE a16.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 17 THEN (SELECT a17.name FROM prefix_resource a17         WHERE a17.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 18 THEN (SELECT a18.name FROM prefix_scorm a18             WHERE a18.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 19 THEN (SELECT a19.name FROM prefix_survey a19             WHERE a19.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 20 THEN (SELECT a20.name FROM prefix_url a20                      WHERE a20.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 21 THEN (SELECT a21.name FROM prefix_wiki a21                    WHERE a21.id = cm.instance)&lt;br /&gt;
    WHEN cm.module = 22 THEN (SELECT a22.name FROM prefix_workshop a22           WHERE a22.id = cm.instance)&lt;br /&gt;
END AS Actvityname,&lt;br /&gt;
# cm.section AS Coursesection,&lt;br /&gt;
CASE&lt;br /&gt;
    WHEN cm.completion = 0 THEN &#039;0 None&#039;&lt;br /&gt;
    WHEN cm.completion = 1 THEN &#039;1 Self&#039;&lt;br /&gt;
    WHEN cm.completion = 2 THEN &#039;2 Auto&#039;&lt;br /&gt;
END AS Activtycompletiontype, &lt;br /&gt;
CASE&lt;br /&gt;
   WHEN cmc.completionstate = 0 THEN &#039;In Progress&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 1 THEN &#039;Completed&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 2 THEN &#039;Completed with Pass&#039;&lt;br /&gt;
   WHEN cmc.completionstate = 3 THEN &#039;Completed with Fail&#039;&lt;br /&gt;
   ELSE &#039;Unknown&#039;&lt;br /&gt;
END AS &#039;Progress&#039;, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(cmc.timemodified), &#039;%Y-%m-%d %H:%i&#039;) AS &#039;When&#039;&lt;br /&gt;
FROM prefix_course_modules_completion cmc &lt;br /&gt;
JOIN prefix_user u ON cmc.userid = u.id&lt;br /&gt;
JOIN prefix_course_modules cm ON cmc.coursemoduleid = cm.id&lt;br /&gt;
JOIN prefix_course c ON cm.course = c.id&lt;br /&gt;
JOIN prefix_modules m ON cm.module = m.id&lt;br /&gt;
# skip the predefined admin and guest user&lt;br /&gt;
WHERE u.id &amp;gt; 2&lt;br /&gt;
# config reports filters&lt;br /&gt;
%%FILTER_USERS:u.username%%&lt;br /&gt;
%%FILTER_SEARCHTEXT:m.name:~%%&lt;br /&gt;
%%FILTER_STARTTIME:cmc.timemodified:&amp;gt;%% %%FILTER_ENDTIME:cmc.timemodified:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How many SCORM activities are used in each Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cm.course,c.fullname ,m.name &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/scorm/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,count(cm.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS Counter&lt;br /&gt;
 &lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
  JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
  JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%scorm%&#039; &lt;br /&gt;
GROUP BY cm.course,cm.module &lt;br /&gt;
ORDER BY count(cm.id) desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===SCORM Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of SCORM activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, scm.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;SCO%&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_scorm AS scm ON scm.id = cm.instance&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LTI (External Tool) Usage by Course Start Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College &lt;br /&gt;
&lt;br /&gt;
Report of number of inclusions of  LTI (External Tool) Usage activities in courses, filtered by course start date.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;course&#039;&lt;br /&gt;
&lt;br /&gt;
, cc.name AS &#039;Category&#039;&lt;br /&gt;
, lti.name AS &#039;Sample Activity Name&#039;&lt;br /&gt;
, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
, COUNT(DISTINCT cm.id) AS &#039;Resources Used&#039;&lt;br /&gt;
#, FROM_UNIXTIME(cm.added) AS &#039;resource added&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id AND m.name LIKE &#039;lti&#039;&lt;br /&gt;
&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
JOIN prefix_lti AS lti ON lti.id = cm.instance&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%%&lt;br /&gt;
%%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.shortname, m.name&lt;br /&gt;
ORDER BY c.startdate, c.shortname &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed ACTIONs for each MODULE===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT module,action,count(id) as counter&lt;br /&gt;
FROM prefix_log&lt;br /&gt;
GROUP BY module,action&lt;br /&gt;
ORDER BY module,counter desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Most popular ACTIVITY===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT(l.id) hits, module&lt;br /&gt;
FROM prefix_log l&lt;br /&gt;
WHERE module != &#039;login&#039; AND module != &#039;course&#039; AND module != &#039;role&#039;&lt;br /&gt;
GROUP BY module&lt;br /&gt;
ORDER BY hits DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System wide use of ACTIVITIES and RESOURCES===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count( cm.id ) AS counter, m.name&lt;br /&gt;
FROM `prefix_course_modules` AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
GROUP BY cm.module&lt;br /&gt;
ORDER BY counter DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LOG file ACTIONS per MODULE per COURSE (IDs)===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select course,module,action,count(action) as summa from prefix_log&lt;br /&gt;
where action &amp;lt;&amp;gt; &#039;new&#039;&lt;br /&gt;
group by course,action,module&lt;br /&gt;
order by course,module,action&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System Wide usage count of various course Activities===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
Like: Forum, Wiki, Blog, Assignment, Database,&lt;br /&gt;
#Within specific category&lt;br /&gt;
#Teacher name in course&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS Forums&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%data%&#039;) AS Databses&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%assignment%&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 18)&lt;br /&gt;
ORDER BY Wikis DESC,Blogs DESC, Forums DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course wiki usage/activity over the last 6 semesters===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &amp;quot;Courses with Wikis&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester A%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester A&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;2010&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%Semester B%&#039;) AS &#039;2010 &amp;lt;br/&amp;gt; Semester B&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעא&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעא &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעב&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעב &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר א%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר א&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_course AS c ON c.id = cm.course&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
 and c.fullname LIKE CONCAT(&#039;%&#039;,&#039;תשעג&#039;,&#039;%&#039;) and c.fullname LIKE &#039;%סמסטר ב%&#039;) AS &#039;תשעג &amp;lt;br/&amp;gt; סמסטר ב&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Detailed WIKI activity (per wiki per course)===&lt;br /&gt;
Including Number of Students in course (for reference)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,cm.course,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as CourseID  &lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id ) AS Students&lt;br /&gt;
,m.name&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%updat%&#039; ) as &#039;UPDAT E&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%annotate%&#039; ) as ANNOTATE&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%comment%&#039; ) as COMMENT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%add%&#039; ) as &#039;A DD&#039;&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action LIKE &#039;%edit%&#039; ) as EDIT&lt;br /&gt;
, ( SELECT count(id) FROM prefix_log WHERE cmid = cm.id AND action NOT LIKE &#039;%view%&#039; ) as &#039;All (NO View)&#039;&lt;br /&gt;
FROM `prefix_course_modules` as cm &lt;br /&gt;
JOIN prefix_modules as m ON cm.module=m.id &lt;br /&gt;
JOIN prefix_course as c ON cm.course = c.id &lt;br /&gt;
WHERE m.name LIKE &#039;%wiki%&#039;&lt;br /&gt;
GROUP BY cm.course,cm.module&lt;br /&gt;
ORDER BY &#039;All (NO View)&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Wiki usage, system wide===&lt;br /&gt;
(you can filter the output by selecting some specific course categories : &amp;quot;WHERE c.category IN ( 8,13,15)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%wiki%&#039;) AS Wikis&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039;) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%add%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ADD&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%edit%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;EDIT&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%annotate%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;ANNOTATE&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.course = c.id AND l.module LIKE &#039;%wiki%&#039; and l.action LIKE &#039;%comments%&#039; ) AS &#039;WikiActivity&amp;lt;br/&amp;gt;Comments&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
,(SELECT count(*) FROM prefix_ouwiki_pages as ouwp&lt;br /&gt;
JOIN prefix_ouwiki as ouw ON ouw.id = ouwp.subwikiid&lt;br /&gt;
WHERE ouw.course = c.id GROUP BY ouw.course  ) as OUWikiPages&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( DISTINCT nwp.pagename ) FROM prefix_wiki_pages AS nwp&lt;br /&gt;
JOIN prefix_wiki AS nw ON nw.id = nwp.dfwiki WHERE nw.course = c.id ) As NWikiPages&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Wikis &amp;gt; 0&lt;br /&gt;
ORDER BY &#039;WikiActivity&amp;lt;br/&amp;gt;ALL&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Aggregated Teacher activity by &amp;quot;WEB2&amp;quot; Modules===&lt;br /&gt;
(Tested and works fine in Moodle 2.x)&lt;br /&gt;
The NV column shows activity without VIEW log activity&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT ra.userid, u.firstname,u.lastname&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039;) AS Wiki&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%wiki%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Wiki_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039;) AS Forum&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%forum%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Forum_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039;) AS Blog&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%blog%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Blog_NV&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039;) AS Assignment&lt;br /&gt;
,(SELECT count(*) FROM prefix_log as l WHERE l.userid = u.id AND l.module LIKE &#039;%assignment%&#039; AND l.action NOT LIKE &#039;%view%&#039;) AS Assignment_NV&lt;br /&gt;
FROM prefix_role_assignments AS ra &lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid &lt;br /&gt;
WHERE ra.roleid = 3 &lt;br /&gt;
GROUP BY ra.userid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the certificates issued, sort by variables in the custom profile fields===&lt;br /&gt;
Note: The SQL queries look intimidating at first, but isn&#039;t really that difficult to learn. I&#039;ve seen in the forums that users wanted to do &#039;site-wide&#039; groups in 1.9x. This is sort of the idea. It pulls all the certificates issued to all users sorted by the custom profile fields, which in my case is the Units or Depts (i.e. my site wide groups). Why certificates? I&#039;ve explored with both grades and quizzes, the course admins are not really interested in the actual grades but whether the learner received a certificate (i.e. passed the course with x, y, z activities). It also saves me from creating groups and assigning them into the right groups. Even assigning in bulk is not efficient, since I have upward of 25 groups per course and constantly new learners enrolling in courses. The limitation is something to do with the server? as it only pull 5000 rows of data. If anyone figured out how to change this, please let me know. In the meantime, the work around is to pull only a few units/depts at a time to limit the number of rows. This is fine at the moment, since each course admin are only responsible for certain units/depts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(prefix_certificate_issues.timecreated), &#039;%Y-%m-%d&#039; ) AS Date,&lt;br /&gt;
prefix_certificate_issues.classname AS Topic,&lt;br /&gt;
prefix_certificate.name AS Certificate,&lt;br /&gt;
prefix_certificate_issues.studentname as Name,&lt;br /&gt;
prefix_user_info_data.data AS Units&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
prefix_certificate_issues&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_user_info_data&lt;br /&gt;
on prefix_certificate_issues.userid = prefix_user_info_data.userid&lt;br /&gt;
&lt;br /&gt;
INNER JOIN prefix_certificate&lt;br /&gt;
on prefix_certificate_issues.certificateid = prefix_certificate.id&lt;br /&gt;
&lt;br /&gt;
WHERE prefix_user_info_data.data=&#039;Unit 1&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 2&#039;&lt;br /&gt;
OR prefix_user_info_data.data=&#039;Unit 3&#039;&lt;br /&gt;
&lt;br /&gt;
ORDER BY Units, Name, Topic ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== All Simple Certificates Earned in the Site===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 [http://www.mysqltutorial.org/mysql-date_format/ DATE_FORMAT] function.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
CONCAT (u.firstname, &#039; &#039;,u.lastname) As &#039;User&#039;,&lt;br /&gt;
c.fullname AS &#039;Course&#039;,&lt;br /&gt;
sc.name AS &#039;Certificate&#039;,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME(sci.timecreated), &#039;%Y-%m-%d&#039; ) As &#039;Date Awarded&#039;&lt;br /&gt;
# sci.code &#039;CertificateId&#039;&lt;br /&gt;
FROM prefix_simplecertificate_issues sci&lt;br /&gt;
JOIN prefix_user u ON sci.userid = u.id&lt;br /&gt;
JOIN prefix_simplecertificate sc ON sci.certificateid = sc.id&lt;br /&gt;
JOIN prefix_course AS c ON sc.course = c.id&lt;br /&gt;
ORDER BY sci.timecreated DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
WHERE DATEDIFF(NOW(),FROM_UNIXTIME(sci.timecreated) ) &amp;lt; 30&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Counter Blog usage in Courses,system wide===&lt;br /&gt;
What teachers in what courses, uses blogs and how many + student count in that course.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SELECT ( @counter := @counter+1) as counter, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) as Course&lt;br /&gt;
&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
&lt;br /&gt;
,(SELECT count( m.name ) AS count FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%blog%&#039;) AS Blogs&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course AS c, (SELECT @counter := 0) as s_init&lt;br /&gt;
WHERE c.category IN ( 8,13,15)&lt;br /&gt;
HAVING Blogs &amp;gt; 0&lt;br /&gt;
ORDER BY Blogs DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Elluminate (Blackboard Collaborate) - system wide usage===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT e.name As Session ,er.recordingsize&lt;br /&gt;
,c.fullname As Course&lt;br /&gt;
,u.firstname,u.lastname &lt;br /&gt;
,DATE_FORMAT(FROM_UNIXTIME(e.timestart),&#039;%d-%m-%Y&#039;) AS dTimeStart&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/moodle/mod/elluminate/loadrecording.php?id=&#039;,er.id,&#039;&amp;quot;&amp;gt;Show&amp;lt;/a&amp;gt;&#039;) AS RecordedSession&lt;br /&gt;
&lt;br /&gt;
FROM prefix_elluminate_recordings AS er&lt;br /&gt;
JOIN prefix_elluminate AS e ON e.meetingid = er.meetingid&lt;br /&gt;
JOIN prefix_course as c ON c.id = e.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = e.creator &lt;br /&gt;
ORDER BY er.recordingsize DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choice ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
Results of the Choice activity. For all courses, shows course shortname, username, the Choice text, and the answer chosen by the user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname AS course, u.username, h.name as question, o.text AS answer&lt;br /&gt;
FROM prefix_choice AS h&lt;br /&gt;
JOIN prefix_course AS c ON h.course = c.id&lt;br /&gt;
JOIN prefix_choice_answers AS a ON h.id = a.choiceid&lt;br /&gt;
JOIN prefix_user AS u ON a.userid = u.id&lt;br /&gt;
JOIN prefix_choice_options AS o ON a.optionid = o.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment type usage in courses ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assign/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS &amp;quot;List assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM prefix_assign WHERE c.id = course) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;file&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
#GROUP BY apc.plugin&lt;br /&gt;
) AS &amp;quot;File Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;onlinetext&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Online Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;pdf&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;PDF Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;offline&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Offline Assignments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_assign_plugin_config AS apc&lt;br /&gt;
JOIN prefix_assign AS iassign ON iassign.id = apc.assignment &lt;br /&gt;
WHERE iassign.course = c.id AND apc.plugin = &#039;comments&#039; AND apc.subtype = &#039;assignsubmission&#039; AND apc.name = &#039;enabled&#039; AND apc.value = &#039;1&#039;&lt;br /&gt;
) AS &amp;quot;Assignments Comments&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_assign AS assign&lt;br /&gt;
JOIN prefix_course AS c ON c.id = assign.course&lt;br /&gt;
GROUP BY c.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Assignment Module Reports==&lt;br /&gt;
===All Ungraded Assignments===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
Returns all the submitted assignments that still need grading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id&lt;br /&gt;
and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Ungraded Assignments w/ Link===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
select &lt;br /&gt;
u.firstname AS &amp;quot;First&amp;quot;,&lt;br /&gt;
u.lastname AS &amp;quot;Last&amp;quot;,&lt;br /&gt;
c.fullname AS &amp;quot;Course&amp;quot;,&lt;br /&gt;
a.name AS &amp;quot;Assignment&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
&#039;&amp;lt;a href=&amp;quot;http://education.varonis.com/mod/assignment/submissions.php&#039; + char(63) +&lt;br /&gt;
+ &#039;id=&#039; + cast(cm.id as varchar) + &#039;&amp;amp;userid=&#039; + cast(u.id as varchar) &lt;br /&gt;
+ &#039;&amp;amp;mode=single&amp;amp;filter=0&amp;amp;offset=2&amp;quot;&amp;gt;&#039; + a.name + &#039;&amp;lt;/a&amp;gt;&#039;&lt;br /&gt;
AS &amp;quot;Assignmentlink&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
from prefix_assignment_submissions as asb&lt;br /&gt;
join prefix_assignment as a ON a.id = asb.assignment&lt;br /&gt;
join prefix_user as u ON u.id = asb.userid&lt;br /&gt;
join prefix_course as c ON c.id = a.course&lt;br /&gt;
join prefix_course_modules as cm ON c.id = cm.course&lt;br /&gt;
&lt;br /&gt;
where asb.grade &amp;lt; 0 and cm.instance = a.id and cm.module = 1&lt;br /&gt;
&lt;br /&gt;
order by c.fullname, a.name, u.lastname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assignments (and Quizzes) waiting to be graded===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: This query is for the deprecated old Assignment module from Moodle 2.2, not the new Assignments module. Please update this query if you are the author or it will be removed as the 2.2 Assignment module is no longer supported since release 2.7.&lt;br /&gt;
&#039;&#039;&#039; See: [https://docs.moodle.org/dev/Moodle_2.7_release_notes#Assignment]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This report requires a YEAR filter to be added (Available when using the latest block/configurable_reports)&lt;br /&gt;
&lt;br /&gt;
Which you can always remove, to make this query work on earlier versions.&lt;br /&gt;
&lt;br /&gt;
The report includes: &lt;br /&gt;
*number of quizzes&lt;br /&gt;
*unFinished Quiz attempts&lt;br /&gt;
*Finished Quiz attempts&lt;br /&gt;
*number of students&lt;br /&gt;
*number of Assignments&lt;br /&gt;
*number of submitted answers by students &lt;br /&gt;
*number of unchecked assignments (waiting for the Teacher) in a Course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
 &lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/assignment/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;מטלות&amp;lt;/a&amp;gt;&#039;) AS Assignments&lt;br /&gt;
&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;בחנים&amp;lt;/a&amp;gt;&#039;) AS &#039;Quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) &lt;br /&gt;
FROM prefix_course_modules cm &lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module &lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039; AND cm.course = c.id &lt;br /&gt;
GROUP BY cm.course &lt;br /&gt;
) AS &#039;nQuizzes&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish = 0&lt;br /&gt;
GROUP BY q.course) AS &#039;unFinished Quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*)&lt;br /&gt;
FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON q.id = qa.quiz&lt;br /&gt;
WHERE q.course = c.id&lt;br /&gt;
AND qa.timefinish &amp;gt; 0&lt;br /&gt;
GROUP BY q.course) AS &#039;finished quiz attempts&#039;&lt;br /&gt;
&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS nStudents&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(a.id)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) nAssignments&lt;br /&gt;
&lt;br /&gt;
,(&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE a.course = c.id AND FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course&lt;br /&gt;
) &#039;Open &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
&lt;br /&gt;
, CONCAT(ROUND( (100 / iAssignments ) * iOpenAssignments ) ,&#039;%&#039;) &#039;unFinished &amp;lt;br/&amp;gt;Assignments &amp;lt;br/&amp;gt;(percent)&#039;&lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE asb.grade &amp;lt; 0 AND cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;unChecked  &amp;lt;br/&amp;gt;Submissions&#039; &lt;br /&gt;
 &lt;br /&gt;
,(&lt;br /&gt;
SELECT count(asb.id)&lt;br /&gt;
FROM prefix_assignment_submissions AS asb&lt;br /&gt;
JOIN prefix_assignment AS a ON a.id = asb.assignment&lt;br /&gt;
JOIN prefix_course_modules AS cm ON a.course = cm.course &lt;br /&gt;
WHERE cm.instance = a.id AND cm.module = 1 AND a.course = c.id&lt;br /&gt;
) &#039;Submitted  &amp;lt;br/&amp;gt;Assignments&#039;&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblAssignmentsCount ON tblAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
LEFT JOIN (&lt;br /&gt;
SELECT course, count(*) AS iOpenAssignments&lt;br /&gt;
FROM prefix_assignment AS a &lt;br /&gt;
WHERE FROM_UNIXTIME(a.timedue) &amp;gt; NOW()&lt;br /&gt;
GROUP BY a.course &lt;br /&gt;
) AS tblOpenAssignmentsCount ON tblOpenAssignmentsCount.course = c.id&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1  &lt;br /&gt;
#AND c.fullname LIKE &#039;%תשעג%&#039;&lt;br /&gt;
%%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
ORDER BY &#039;Open &amp;lt;br/&amp;gt;Assignments&#039; DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rubrics without zero values in criteria===&lt;br /&gt;
Contributed by Eric Strom&lt;br /&gt;
&lt;br /&gt;
Rubric calculations in Moodle can fail to align with instructors expectations if they lack a zero value for each criterion used in the assessment. From documentation at https://docs.moodle.org/32/en/Rubrics#Grade_calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;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.&lt;br /&gt;
TIP: To avoid confusion from this sort of thing, we recommend including a level with 0 points in every rubric criterion.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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&#039; favor.&lt;br /&gt;
&lt;br /&gt;
Includes search filter of course idnumber.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT cat.name AS Department, concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;,CHAR(63),&#039;id=&#039;,&lt;br /&gt;
c.id,&#039;&amp;quot;&amp;gt;&#039;,c.idnumber,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course_ID, &lt;br /&gt;
c.fullname AS Course_Name, &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/grading/form/rubric/edit.php&#039;,CHAR(63),&#039;areaid=&#039;,gd.areaid,&#039;&amp;quot;&amp;gt;&#039;,gd.areaid,&#039;&amp;lt;/a&amp;gt;&#039;) AS Rubric&lt;br /&gt;
FROM prefix_course AS c&lt;br /&gt;
JOIN prefix_course_categories AS cat &lt;br /&gt;
ON cat.id = c.category&lt;br /&gt;
JOIN prefix_course_modules AS cm &lt;br /&gt;
ON c.id=cm.course&lt;br /&gt;
JOIN prefix_context AS ctx &lt;br /&gt;
ON cm.id = ctx.instanceid&lt;br /&gt;
JOIN prefix_grading_areas AS garea &lt;br /&gt;
ON ctx.id = garea.contextid&lt;br /&gt;
JOIN prefix_grading_definitions AS gd &lt;br /&gt;
ON garea.id = gd.areaid&lt;br /&gt;
JOIN prefix_gradingform_rubric_criteria AS crit &lt;br /&gt;
ON gd.id = crit.definitionid&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id&lt;br /&gt;
WHERE cm.visible=&#039;1&#039; AND garea.activemethod = &#039;rubric&#039; AND (crit.id NOT IN&lt;br /&gt;
(SELECT crit.id&lt;br /&gt;
FROM prefix_gradingform_rubric_criteria AS crit&lt;br /&gt;
JOIN prefix_gradingform_rubric_levels AS levels &lt;br /&gt;
ON levels.criterionid = crit.id WHERE levels.score = &#039;0&#039;))&lt;br /&gt;
&lt;br /&gt;
GROUP BY Rubric&lt;br /&gt;
ORDER BY Course_ID, Rubric&lt;br /&gt;
&lt;br /&gt;
%%FILTER_SEARCHTEXT:c.idnumber:~%%&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Who is using &amp;quot;Single File Upload&amp;quot; assignment===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
 &lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher &lt;br /&gt;
&lt;br /&gt;
,ass.name as &amp;quot;Assignment Name&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM &lt;br /&gt;
prefix_assignment as ass&lt;br /&gt;
&lt;br /&gt;
JOIN &lt;br /&gt;
prefix_course as c ON c.id = ass.course&lt;br /&gt;
&lt;br /&gt;
WHERE `assignmenttype` LIKE &#039;uploadsingle&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Feedback Module Reports==&lt;br /&gt;
===List the answers to all the Feedback activities within the current course, submitted by the current user===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT /* crs.fullname as &amp;quot;Course name&amp;quot;, f.name AS &amp;quot;Journal name&amp;quot;, CONCAT(u.firstname,&#039; &#039;,UPPER(u.lastname)) as &amp;quot;Participant&amp;quot;, */ /* include these fields if you want to check the composition of the recordset */&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(c.timemodified),&#039;%W %e %M, %Y&#039;) as &amp;quot;Answer Date&amp;quot;,&lt;br /&gt;
CASE i.typ WHEN &#039;label&#039; THEN i.presentation ELSE i.name END as &amp;quot;Topic&amp;quot;,  /* usually labels are used as section titles, so you&#039;d want them present in the recordset */&lt;br /&gt;
v.value as &amp;quot;My Answer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback AS f&lt;br /&gt;
INNER JOIN prefix_course as crs on crs.id=f.course %%FILTER_COURSES:f.course%% &lt;br /&gt;
INNER JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
INNER JOIN prefix_feedback_completed AS c on f.id=c.feedback %%FILTER_COURSEUSER:c.userid%% &lt;br /&gt;
LEFT JOIN prefix_feedback_value AS v on v.completed=c.id AND v.item=i.id&lt;br /&gt;
INNER JOIN prefix_user AS u on c.userid=u.id&lt;br /&gt;
&lt;br /&gt;
WHERE c.id = %%COURSEID%% AND u.id = %%USERID%%  AND c.anonymous_response = 1  /* This clause limits the recordset to the current course and the current user and includes/ excludes the anonymous responses as needed */&lt;br /&gt;
&lt;br /&gt;
ORDER BY f.id, c.timemodified, i.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Show all Feedbacks from all courses for all users including showing names of anonymous users===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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 &#039;Not-logged-in&#039; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.shortname AS Course, &lt;br /&gt;
f.name AS Feedback,&lt;br /&gt;
# i.id AS Itemid,&lt;br /&gt;
i.name AS Itemname,&lt;br /&gt;
i.label AS Itemlabel,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN f.anonymous = 1 AND u.id != 0 THEN CONCAT(u.username, &#039; :ANON&#039;)&lt;br /&gt;
 WHEN fc.userid = 0 THEN &#039;Not-logged-in&#039;&lt;br /&gt;
 ELSE u.username&lt;br /&gt;
END AS &#039;User&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(fc.timemodified),&#039;%Y-%m-%d %H:%i&#039;) AS &amp;quot;Completed&amp;quot;,&lt;br /&gt;
v.value AS &amp;quot;Choice&amp;quot;,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN i.typ = &#039;multichoice&#039; THEN&lt;br /&gt;
     IF (  SUBSTRING(i.presentation,1,6)=&#039;d&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&#039;,&lt;br /&gt;
	       SUBSTRING(i.presentation,7),&lt;br /&gt;
		   i.presentation)&lt;br /&gt;
 ELSE i.presentation&lt;br /&gt;
END AS &amp;quot;Answers&amp;quot;,&lt;br /&gt;
i.typ,&lt;br /&gt;
i.dependitem,&lt;br /&gt;
i.dependvalue&lt;br /&gt;
&lt;br /&gt;
FROM prefix_feedback f&lt;br /&gt;
JOIN prefix_course c ON c.id=f.course &lt;br /&gt;
JOIN prefix_feedback_item AS i ON f.id=i.feedback&lt;br /&gt;
JOIN prefix_feedback_completed fc ON f.id=fc.feedback&lt;br /&gt;
LEFT JOIN prefix_feedback_value v ON v.completed=fc.id AND v.item=i.id&lt;br /&gt;
LEFT JOIN prefix_user AS u ON fc.userid=u.id&lt;br /&gt;
WHERE i.typ != &#039;pagebreak&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Resource Module Reports==&lt;br /&gt;
===List &amp;quot;Recently uploaded files&amp;quot;===&lt;br /&gt;
see what users are uploading&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT FROM_UNIXTIME(time,&#039;%Y %M %D %h:%i:%s&#039;) as time ,ip,userid,url,info  &lt;br /&gt;
FROM `prefix_log` &lt;br /&gt;
WHERE `action` LIKE &#039;upload&#039; &lt;br /&gt;
ORDER BY `prefix_log`.`time`  DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List Courses that loaded a specific file: &amp;quot;X&amp;quot;===&lt;br /&gt;
Did the Teacher (probably) uploaded course&#039;s Syllabus ?&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.id, c.fullname  FROM `prefix_log` as l &lt;br /&gt;
JOIN prefix_course as c ON c.id = l.course &lt;br /&gt;
WHERE `action` LIKE &#039;%upload%&#039; AND ( info LIKE &#039;%Syllabus%&#039; OR info LIKE &#039;%Sylabus%&#039; ) GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All resources that link to some specific external website===&lt;br /&gt;
+ link to course&lt;br /&gt;
+ who&#039;s the teacher&lt;br /&gt;
+ link to external resource&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,c.shortname,r.name&lt;br /&gt;
,(SELECT CONCAT(u.firstname,&#039; &#039;, u.lastname) AS Teacher&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
WHERE ra.roleid = 3 AND ctx.instanceid = c.id LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/resource/view.php?id=&#039;,r.id,&#039;&amp;quot;&amp;gt;&#039;,r.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Resource&lt;br /&gt;
FROM prefix_resource AS r &lt;br /&gt;
JOIN prefix_course AS c ON r.course = c.id&lt;br /&gt;
WHERE r.reference LIKE &#039;http://info.oranim.ac.il/home%&#039; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;quot;Compose Web Page&amp;quot; RESOURCE count===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT course,prefix_course.fullname, COUNT(*) AS Total&lt;br /&gt;
FROM `prefix_resource`&lt;br /&gt;
JOIN `prefix_course` ON prefix_course.id = prefix_resource.course&lt;br /&gt;
WHERE type=&#039;html&#039;&lt;br /&gt;
GROUP BY course&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resource count in courses===&lt;br /&gt;
+ (First)Teacher name&lt;br /&gt;
+ Where course is inside some specific Categories&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
COUNT(*) AS count&lt;br /&gt;
,r.course &lt;br /&gt;
,c.shortname shortname&lt;br /&gt;
,c.fullname coursename&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user as u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = r.course AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
FROM prefix_resource r &lt;br /&gt;
JOIN prefix_course c ON r.course = c.id&lt;br /&gt;
WHERE c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY r.course&lt;br /&gt;
ORDER BY COUNT(*) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Delete all the automated backup files===&lt;br /&gt;
Prepare bash cli script to delete all the automated backup files on the file system. (clean up some disk space)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT CONCAT( &#039;rm -f /var/moodledatanew/filedir/&#039;, SUBSTRING( contenthash, 1, 2 ) , &#039;/&#039;, SUBSTRING( contenthash, 3, 2 ) , &#039;/&#039;, contenthash ) &lt;br /&gt;
FROM `mdl_files` &lt;br /&gt;
WHERE `filename` LIKE &#039;%mbz%&#039;&lt;br /&gt;
AND filearea = &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find out how much disk space is used by all automated backup files:&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT SUM(filesize)/(1024*1024*1024) FROM `mdl_files` WHERE  `filename` LIKE &#039;%mbz%&#039; AND filearea =  &#039;automated&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Forum Module Reports==&lt;br /&gt;
===print all User&#039;s post in course Forums===&lt;br /&gt;
%%COURSEID%% is a variable the is replace by the current CourseID you are running the sql report from. if you are using the latest block/configurable_reports ! (You can always change it to a fixed course or remove it to display all courses.)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/user.php?course=&#039;,c.id,&#039;&amp;amp;id=&#039;,u.id,&#039;&amp;amp;mode=posts&amp;quot;&amp;gt;&#039;,CONCAT(u.firstname,&#039; &#039;, u.lastname),&#039;&amp;lt;/a&amp;gt;&#039;) As Fullname&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS Forum&lt;br /&gt;
,count(*) as Posts&lt;br /&gt;
,(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&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_user as u ON u.id = fp.userid &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = fd.course &lt;br /&gt;
WHERE fd.course = %%COURSEID%% &lt;br /&gt;
GROUP BY f.id,u.id&lt;br /&gt;
ORDER BY u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===FORUM use Count per COURSE by type -- not including NEWS Forum!===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT prefix_course.fullname, prefix_forum.course, prefix_forum.type, count(*) as total FROM prefix_forum&lt;br /&gt;
INNER JOIN prefix_course&lt;br /&gt;
ON prefix_course.id = prefix_forum.course&lt;br /&gt;
WHERE NOT(prefix_forum.type = &#039;news&#039;)&lt;br /&gt;
GROUP BY prefix_forum.course,prefix_forum.type&lt;br /&gt;
ORDER BY total desc&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Forum activity - system wide===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.id,&#039;&amp;lt;/a&amp;gt;&#039;) AS CourseID&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,c.fullname as Course&lt;br /&gt;
,f.type&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid = 5 AND ctx.instanceid = c.id) AS Students&lt;br /&gt;
, fd.forum, f.name,count(*) AS cPostAndDisc&lt;br /&gt;
,(SELECT count(*) FROM prefix_forum_discussions AS ifd WHERE ifd.forum = f.id) AS cDiscussion&lt;br /&gt;
FROM prefix_forum_posts AS fp&lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type != &#039;news&#039; AND c.fullname LIKE &#039;%2013%&#039;&lt;br /&gt;
## WHERE 1=1 &lt;br /&gt;
## %%FILTER_YEARS:c.fullname%%&lt;br /&gt;
## You can enable the SEMESTER filter as well, &lt;br /&gt;
## by uncommenting the following line:&lt;br /&gt;
## %%FILTER_SEMESTERS:c.fullname%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count( * ) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Activity In Forums===&lt;br /&gt;
Trying to figure out how much real activity we have in Forums by aggregating:&lt;br /&gt;
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...&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.fullname,f.name,f.type &lt;br /&gt;
,(SELECT count(id) FROM prefix_forum_discussions as fd WHERE f.id = fd.forum) as Discussions&lt;br /&gt;
,(SELECT count(distinct fd.userid) FROM prefix_forum_discussions as fd WHERE fd.forum = f.id) as UniqueUsersDiscussions&lt;br /&gt;
,(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&lt;br /&gt;
,(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&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Students&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =5&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS StudentsCount&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Teachers&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid =3&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS &#039;Teacher&amp;lt;br/&amp;gt;Count&#039;&lt;br /&gt;
,(SELECT Count( ra.userid ) AS Users&lt;br /&gt;
FROM prefix_role_assignments AS ra&lt;br /&gt;
JOIN prefix_context AS ctx ON ra.contextid = ctx.id&lt;br /&gt;
WHERE ra.roleid IN (3,5)&lt;br /&gt;
AND ctx.instanceid = c.id&lt;br /&gt;
) AS UserCount&lt;br /&gt;
, (SELECT (UniqueUsersDiscussions / StudentsCount )) as StudentDissUsage&lt;br /&gt;
, (SELECT (UniqueUsersPosts /StudentsCount)) as StudentPostUsage&lt;br /&gt;
FROM prefix_forum as f &lt;br /&gt;
JOIN prefix_course as c ON f.course = c.id&lt;br /&gt;
WHERE `type` != &#039;news&#039;&lt;br /&gt;
ORDER BY StudentPostUsage DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All Forum type:NEWS===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT f.id, f.name&lt;br /&gt;
FROM prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
WHERE m.name = &#039;forum&#039;&lt;br /&gt;
AND f.type = &#039;news&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===All new forum NEWS items (discussions) from all my Courses===&lt;br /&gt;
change &amp;quot;userid = 26&amp;quot; and &amp;quot;id = 26&amp;quot; to a new user id&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname,f.name,fd.name,FROM_UNIXTIME(fd.timemodified ,&amp;quot;%d %M %Y &amp;quot;) as Date&lt;br /&gt;
FROM prefix_forum_discussions as fd &lt;br /&gt;
JOIN prefix_forum as f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course as c ON c.id = f.course &lt;br /&gt;
JOIN prefix_user_lastaccess as ul ON (c.id = ul.courseid AND ul.userid = 26)&lt;br /&gt;
WHERE fd.timemodified &amp;gt; ul.timeaccess  &lt;br /&gt;
 AND fd.forum IN (SELECT f.id&lt;br /&gt;
 FROM prefix_course_modules AS cm&lt;br /&gt;
 JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
 JOIN prefix_forum AS f ON cm.instance = f.id&lt;br /&gt;
 WHERE m.name = &#039;forum&#039;&lt;br /&gt;
 AND f.type = &#039;news&#039;)&lt;br /&gt;
  AND c.id IN (SELECT c.id&lt;br /&gt;
   FROM prefix_course AS c&lt;br /&gt;
   JOIN prefix_context AS ctx ON c.id = ctx.instanceid&lt;br /&gt;
   JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id&lt;br /&gt;
   JOIN prefix_user AS u ON u.id = ra.userid&lt;br /&gt;
   WHERE u.id = 26) ORDER BY `fd`.`timemodified` DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===News Forum - Discussions COUNT===&lt;br /&gt;
Which is actually... How much instructions students get from their teachers&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT c.shortname ,&lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,( SELECT DISTINCT CONCAT(u.firstname,&#039; &#039;,u.lastname)&lt;br /&gt;
  FROM prefix_role_assignments AS ra&lt;br /&gt;
  JOIN prefix_user AS u ON ra.userid = u.id&lt;br /&gt;
  JOIN prefix_context AS ctx ON ctx.id = ra.contextid&lt;br /&gt;
  WHERE ra.roleid = 3 AND ctx.instanceid = c.id AND ctx.contextlevel = 50 LIMIT 1) AS Teacher&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,fd.forum,&#039;&amp;quot;&amp;gt;&#039;,count(fd.id),&#039;&amp;lt;/a&amp;gt;&#039;) AS DiscussionsSum&lt;br /&gt;
FROM prefix_forum_discussions AS fd&lt;br /&gt;
INNER JOIN prefix_forum AS f ON f.id = fd.forum&lt;br /&gt;
INNER JOIN prefix_course AS c ON c.id = f.course&lt;br /&gt;
WHERE f.type = &#039;news&#039; AND c.category IN (10,13,28,18,26)&lt;br /&gt;
GROUP BY fd.forum&lt;br /&gt;
ORDER BY count(fd.id) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cantidad de foros que han sido posteados por profesor===&lt;br /&gt;
&lt;br /&gt;
(Number of forums that have been posted by teacher/Google translator)&lt;br /&gt;
&lt;br /&gt;
Queriamos saber cuales son las acciones del profesor dentro de los foros de cada curso, por ello se hizo este informe.&lt;br /&gt;
&lt;br /&gt;
(We wanted to know what the teacher&#039;s actions are in the forums of each course, so this report was made. /Google translator)&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.shortname,&#039;&amp;lt;/a&amp;gt;&#039;) AS curso,&lt;br /&gt;
CONCAT(u.firstname ,&#039; &#039;,u.lastname) AS Facilitador,&lt;br /&gt;
&lt;br /&gt;
(SELECT COUNT( m.name ) AS COUNT FROM &lt;br /&gt;
prefix_course_modules AS cm&lt;br /&gt;
JOIN prefix_modules AS m ON cm.module = m.id&lt;br /&gt;
WHERE cm.course = c.id AND m.name LIKE &#039;%forum%&#039;) AS foros,&lt;br /&gt;
&lt;br /&gt;
COUNT(*) AS Posts&lt;br /&gt;
&lt;br /&gt;
FROM prefix_forum_posts AS fp &lt;br /&gt;
JOIN prefix_forum_discussions AS fd ON fp.discussion = fd.id &lt;br /&gt;
JOIN prefix_forum AS f ON f.id = fd.forum &lt;br /&gt;
JOIN prefix_course AS c ON c.id = fd.course&lt;br /&gt;
JOIN prefix_user AS u ON u.id = fp.userid &lt;br /&gt;
&lt;br /&gt;
WHERE fp.userid =&lt;br /&gt;
(&lt;br /&gt;
select distinct prefix_user.id&lt;br /&gt;
from prefix_user &lt;br /&gt;
join prefix_role_assignments as ra on ra.userid = prefix_user.id &lt;br /&gt;
where ra.roleid = 3 &lt;br /&gt;
and userid = fp.userid&lt;br /&gt;
limit 1&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
and c.shortname like &#039;%2014-2-1%&#039;&lt;br /&gt;
GROUP BY c.id, u.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all the Forums that got high rating===&lt;br /&gt;
We setup a scale that let teachers and students Rate forum post with &amp;quot;Important, interesting, valuable, not rated&amp;quot; scale&lt;br /&gt;
And then add a link to the following report at the begining of the course &amp;quot;Link to all interesting posts&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;,f.id,&#039;&amp;quot;&amp;gt;&#039;,f.name,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;,fd.id,&#039;#p&#039;,fp.id,&#039;&amp;quot;&amp;gt;&#039;,fp.subject,&#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post link&#039;,&lt;br /&gt;
SUM(r.rating) AS &#039;Rating&#039;&lt;br /&gt;
FROM mdl_rating AS r&lt;br /&gt;
  JOIN mdl_forum_posts AS fp ON fp.id = r.itemid&lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
WHERE r.component = &#039;mod_forum&#039; AND r.ratingarea = &#039;post&#039; AND f.course = %%COURSEID%%&lt;br /&gt;
GROUP BY r.itemid&lt;br /&gt;
ORDER BY SUM(r.rating) DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all the Posts in all Discussions of a single Forum===&lt;br /&gt;
This report is used to help export all the student&#039;s posts and discussions of a single forum, by passing the context module id as a parameter to the report using &amp;quot;&amp;amp;filter_var=cmid&amp;quot;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/view.php?f=&#039;, f.id, &#039;&amp;quot;&amp;gt;&#039;, f.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Forum name&#039;,&lt;br /&gt;
fd.name AS &#039;Discussion&#039;, &lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/forum/discuss.php?d=&#039;, fd.id, &#039;#p&#039;, fp.id, &#039;&amp;quot;&amp;gt;&#039;, fp.subject, &#039;&amp;lt;/a&amp;gt;&#039;) AS &#039;Post (link)&#039;,&lt;br /&gt;
fp.message&lt;br /&gt;
&lt;br /&gt;
FROM mdl_forum_posts AS fp &lt;br /&gt;
  JOIN mdl_forum_discussions AS fd ON fd.id = fp.discussion&lt;br /&gt;
  JOIN mdl_forum AS f ON f.id = fd.forum&lt;br /&gt;
  JOIN mdl_course_modules AS cm ON cm.module = 9 AND cm.instance = f.id&lt;br /&gt;
WHERE cm.id = %%FILTER_VAR%%&lt;br /&gt;
ORDER BY f.id, fd.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Quiz Module Reports==&lt;br /&gt;
===Generate a list of instructors and their email addresses for those courses that has &amp;quot;essay questions&amp;quot; in their quizzes===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT qu.id AS quiz_id, qu.course AS course_id, qu.questions,&lt;br /&gt;
                co.fullname AS course_fullname, co.shortname AS course_shortname,&lt;br /&gt;
                qu.name AS quiz_name, FROM_UNIXTIME(qu.timeopen) AS quiz_timeopen, FROM_UNIXTIME(qu.timeclose) AS quiz_timeclose,&lt;br /&gt;
                u.firstname, u.lastname, u.email,&lt;br /&gt;
FROM prefix_quiz qu, prefix_course co, prefix_role re, prefix_context ct, prefix_role_assignments ra, prefix_user u&lt;br /&gt;
WHERE FROM_UNIXTIME(timeopen) &amp;gt; &#039;2008-05-14&#039; AND&lt;br /&gt;
                qu.course = co.id AND&lt;br /&gt;
                co.id = ct.instanceid AND&lt;br /&gt;
                ra.roleid = re.id AND&lt;br /&gt;
                re.name = &#039;Teacher&#039; AND&lt;br /&gt;
                ra.contextid = ct.id AND&lt;br /&gt;
                ra.userid = u.id&lt;br /&gt;
 &lt;br /&gt;
SELECT Count(&#039;x&#039;) As NumOfStudents&lt;br /&gt;
                                FROM prefix_role_assignments a&lt;br /&gt;
                                JOIN prefix_user u ON userid = u.id&lt;br /&gt;
                                WHERE roleid = 5 AND contextid = (SELECT id FROM prefix_context WHERE instanceid = 668 AND contextlevel = 50)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Number of Quizes per Course===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT count(*)&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/index.php?id=&#039;,c.id,&#039;&amp;quot;&amp;gt;Link&amp;lt;/a&amp;gt;&#039;) AS Quizes&lt;br /&gt;
&lt;br /&gt;
FROM prefix_course_modules cm&lt;br /&gt;
JOIN prefix_course c ON c.id = cm.course&lt;br /&gt;
JOIN prefix_modules as m ON m.id = cm.module&lt;br /&gt;
WHERE m.name LIKE &#039;quiz&#039;&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List all MultiAnswer (Cloze) Questions===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/mod/quiz/attempt.php?q=&#039;, quiz.id, &#039;&amp;quot;&amp;gt;&#039;, quiz.name, &#039;&amp;lt;/a&amp;gt;&#039;) AS Quiz&lt;br /&gt;
,question.id question_id, question.questiontext &lt;br /&gt;
FROM  prefix_question question&lt;br /&gt;
JOIN prefix_quiz_question_instances qqi ON question.id = qqi.question&lt;br /&gt;
JOIN prefix_quiz quiz ON qqi.quiz = quiz.id&lt;br /&gt;
WHERE  `qtype` LIKE  &#039;multianswer&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===List courses with MANUAL grades===&lt;br /&gt;
Which is basically and indication to teachers using Moodle to hold offline grades inside Moodle&#039;s Gradebook,&lt;br /&gt;
So grades could be uploaded into an administrative SIS. Use with Configurable Reports.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT COUNT( * )&lt;br /&gt;
,concat(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/grade/edit/tree/index.php?showadvanced=1&amp;amp;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM  prefix_grade_items AS gi&lt;br /&gt;
JOIN prefix_course as c ON c.id = gi.courseid&lt;br /&gt;
WHERE  `itemtype` =  &#039;manual&#039;&lt;br /&gt;
GROUP BY courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===List the users that did not took the Quiz===&lt;br /&gt;
Do not forget to change &amp;quot;c.id = 14&amp;quot; and q.name LIKE &#039;%quiz name goes here%&#039;&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
user2.id AS ID,&lt;br /&gt;
ul.timeaccess,&lt;br /&gt;
user2.firstname AS Firstname,&lt;br /&gt;
user2.lastname AS Lastname,&lt;br /&gt;
user2.email AS Email,&lt;br /&gt;
user2.username AS IDNumber,&lt;br /&gt;
user2.institution AS Institution,&lt;br /&gt;
 &lt;br /&gt;
IF (user2.lastaccess = 0,&#039;never&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(user2.lastaccess),&#039;%Y-%m-%d&#039;)) AS dLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT DATE_FORMAT(FROM_UNIXTIME(timeaccess),&#039;%Y-%m-%d&#039;) FROM prefix_user_lastaccess WHERE userid=user2.id AND courseid=c.id) AS CourseLastAccess&lt;br /&gt;
 &lt;br /&gt;
,(SELECT r.name&lt;br /&gt;
FROM  prefix_user_enrolments AS uenrol&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = uenrol.enrolid&lt;br /&gt;
JOIN prefix_role AS r ON e.id = r.id&lt;br /&gt;
WHERE uenrol.userid=user2.id AND e.courseid = c.id) AS RoleName&lt;br /&gt;
 &lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
LEFT JOIN prefix_user_lastaccess AS ul ON ul.userid = user2.id&lt;br /&gt;
WHERE c.id=14 and ue.userid NOT IN (SELECT qa.userid FROM prefix_quiz_attempts AS qa&lt;br /&gt;
JOIN prefix_quiz AS q ON qa.quiz = q.id&lt;br /&gt;
JOIN prefix_course AS c ON q.course = c.id&lt;br /&gt;
WHERE c.id = 14 AND q.name LIKE &#039;%quiz name goes here%&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===List Questions in each Quiz===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT quiz.id,quiz.name, q.id, q.name&lt;br /&gt;
FROM mdl_quiz AS quiz&lt;br /&gt;
JOIN mdl_question AS q ON FIND_IN_SET(q.id, quiz.questions)&lt;br /&gt;
WHERE quiz.course = %%COURSEID%%&lt;br /&gt;
ORDER BY quiz.id ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this query does not work in Moodle 2.8. There is no mdl_quiz.questions field. It will need to be rewritten to use the usage/contextid organization.&lt;br /&gt;
&lt;br /&gt;
===Quiz activity research===&lt;br /&gt;
This report was made to extract student full activity in quizzes for an academic research about adapting instructional design teaching methods in online learning. The students do not use the Quiz module as a standard quiz but more as Study booklets or mini courses with embedded questions and hints to assist students evaluate their progress (Similar to what you expect to find in a SCORM activity)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
cm.course &amp;quot;course_id&amp;quot;, cm.id &amp;quot;moduel_id&amp;quot;, q.id &amp;quot;quiz_id&amp;quot;, q.name &amp;quot;quiz_name&amp;quot;,&lt;br /&gt;
 &lt;br /&gt;
CASE q.grademethod&lt;br /&gt;
      WHEN 1 THEN &amp;quot;GRADEHIGHEST&amp;quot;&lt;br /&gt;
      WHEN 2 THEN &amp;quot;GRADEAVERAGE&amp;quot;&lt;br /&gt;
      WHEN 3 THEN &amp;quot;ATTEMPTFIRST&amp;quot;&lt;br /&gt;
      WHEN 4 THEN &amp;quot;ATTEMPTLAST&amp;quot;&lt;br /&gt;
END &amp;quot;grade method&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
, q.attempts &amp;quot;quiz_attempts_allowed&amp;quot;, cm.groupmode &amp;quot;group_mode&amp;quot;&lt;br /&gt;
, qa.id &amp;quot;attempt_id&amp;quot;, qa.state &amp;quot;attempt_state&amp;quot;, qa.sumgrades &amp;quot;attempt_grade&amp;quot;, qg.grade &amp;quot;user_final_grade&amp;quot;, q.grade &amp;quot;quiz_max_grade&amp;quot;&lt;br /&gt;
,(SELECT GROUP_CONCAT(g.name) FROM mdl_groups AS g&lt;br /&gt;
JOIN mdl_groups_members AS m ON g.id = m.groupid WHERE g.courseid = q.course AND m.userid = u.id) &amp;quot;user_groups&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timestart), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_start&amp;quot;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(qa.timefinish), &#039;%d-%m-%Y %h:%k&#039;) &amp;quot;attempt_finish&amp;quot;,&lt;br /&gt;
u.id &amp;quot;user_id&amp;quot;, u.firstname, u.lastname,&lt;br /&gt;
question.id &amp;quot;question_id&amp;quot;, question.name &amp;quot;question_name&amp;quot;,&lt;br /&gt;
qas.state &amp;quot;question_step_state&amp;quot;,qas.fraction &amp;quot;question_grade&amp;quot;, qh.hint, question.qtype &amp;quot;question_type&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM mdl_quiz as q&lt;br /&gt;
JOIN mdl_course_modules as cm ON cm.instance = q.id and cm.module = 14 &lt;br /&gt;
JOIN mdl_quiz_attempts qa ON q.id = qa.quiz&lt;br /&gt;
LEFT JOIN mdl_quiz_grades as qg ON qg.quiz = q.id and qg.userid = qa.userid&lt;br /&gt;
JOIN mdl_user as u ON u.id = qa.userid&lt;br /&gt;
JOIN mdl_question_usages as qu ON qu.id = qa.uniqueid&lt;br /&gt;
JOIN mdl_question_attempts as qatt ON qatt.questionusageid = qu.id&lt;br /&gt;
JOIN mdl_question as question ON question.id = qatt.questionid&lt;br /&gt;
JOIN mdl_question_attempt_steps as qas ON qas.questionattemptid = qatt.id&lt;br /&gt;
LEFT JOIN mdl_question_hints as qh ON qh.questionid = q.id&lt;br /&gt;
#WHERE q.id = &amp;quot;SOME QUIZ ID&amp;quot;&lt;br /&gt;
WHERE cm.course = &amp;quot;SOME COURSE ID&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Quiz Usage in Courses by Date===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Multiple Choice&amp;quot; questions include true/false and matching question types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Short Answer&amp;quot; are questions that accept a single phrase.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Other&amp;quot; questions include fixed numerical, calculated, essay, and various drag and drop types.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Min Quiz Age&amp;quot; and &amp;quot;Max Quiz Age&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: In Configurable Reports, the Date Filter is not applied until the &amp;quot;Apply&amp;quot; button is clicked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
c.shortname AS &#039;Course&#039;&lt;br /&gt;
#, u.lastname AS &#039;Instructor&#039;&lt;br /&gt;
, COUNT(DISTINCT q.id) AS &#039;Quizzes&#039;&lt;br /&gt;
, COUNT(DISTINCT qu.id) AS &#039;Questions&#039;&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 ))  AS &#039;multichoice&#039;&lt;br /&gt;
&lt;br /&gt;
, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
&lt;br /&gt;
, COUNT( qu.id) - SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )) - SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;Other&#039;&lt;br /&gt;
&lt;br /&gt;
, (SUM(IF (qu.qtype = &#039;multichoice&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;truefalse&#039;, 1, 0 )) + SUM(IF (qu.qtype = &#039;match&#039;, 1, 0 )))/COUNT( qu.id) AS &#039;Percent MC&#039;&lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;numerical&#039;, 1, 0 )) AS &#039;numerical&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype LIKE &#039;calc%&#039;, 1, 0 )) AS &#039;calculated&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;random&#039;, 1, 0 )) AS &#039;random&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;shortanswer&#039;, 1, 0 )) AS &#039;shortanswer&#039;&lt;br /&gt;
#, SUM(IF (qu.qtype = &#039;essay&#039;, 1, 0 )) AS &#039;essay&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
, IF(q.shufflequestions &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Questions&#039;&lt;br /&gt;
, IF(q.shuffleanswers &amp;gt; 0,&#039;Yes&#039;,&#039;No&#039;) AS &#039;Randomized Answers&#039;&lt;br /&gt;
 &lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;Course Start Date&#039;&lt;br /&gt;
#, FROM_UNIXTIME(MIN(q.timemodified)) AS &#039;Last Modified&#039;&lt;br /&gt;
&lt;br /&gt;
#, DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(MIN(q.timemodified))) AS &#039;Quiz age&#039;&lt;br /&gt;
&lt;br /&gt;
, MIN(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Min Quiz Age&#039; &lt;br /&gt;
, MAX(DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified))) AS &#039;Max Quiz Age&#039; &lt;br /&gt;
&lt;br /&gt;
#, SUM(IF (DATEDIFF(FROM_UNIXTIME(c.startdate),FROM_UNIXTIME(q.timemodified)) &amp;lt; 90, 1,0)) AS &#039;new quizzes&#039;&lt;br /&gt;
&lt;br /&gt;
FROM prefix_quiz AS q&lt;br /&gt;
JOIN prefix_course AS c on c.id = q.course&lt;br /&gt;
JOIN prefix_quiz_question_instances AS qqi ON qqi.quiz = q.id&lt;br /&gt;
LEFT JOIN prefix_question AS qu ON qu.id = qqi.question&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
%%FILTER_STARTTIME:c.startdate:&amp;gt;%% %%FILTER_ENDTIME:c.startdate:&amp;lt;%%&lt;br /&gt;
&lt;br /&gt;
GROUP BY c.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY c.shortname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==SCORM Activity Reports==&lt;br /&gt;
&lt;br /&gt;
===Lists All completed SCORM activites by Course name===&lt;br /&gt;
This report will list all completed attempts for all SCORM activities. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname First,u.lastname Last,c.fullname Course, st.attempt Attempt,st.value Status,FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) Date &lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
WHERE st.value=&#039;completed&#039; &lt;br /&gt;
ORDER BY c.fullname, u.lastname,u.firstname, st.attempt&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lists SCORM status for all enrolled users by Course name===&lt;br /&gt;
This report will list the SCORM status for all users enrolled in the course. It is ordered first by Course name, then student&#039;s last name, then student&#039;s first name, then attempt number. This can be limited to individual courses by adding to the where clause the course id to report on.  &lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
u.firstname AS First,&lt;br /&gt;
u.lastname AS Last, &lt;br /&gt;
u.idnumber AS Employee_ID,  &lt;br /&gt;
u.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
u.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course, &lt;br /&gt;
st.attempt AS Attempt,&lt;br /&gt;
st.value AS Status,&lt;br /&gt;
FROM_UNIXTIME(st.timemodified,&amp;quot;%m-%d-%Y&amp;quot;) AS Date &lt;br /&gt;
&lt;br /&gt;
FROM prefix_scorm_scoes_track AS st &lt;br /&gt;
JOIN prefix_user AS u ON st.userid=u.id&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id &lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.id=st.scormid&lt;br /&gt;
JOIN prefix_course AS c ON c.id=sc.course&lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
&lt;br /&gt;
WHERE st.element=&#039;cmi.core.lesson_status&#039; AND m.userid=u.id&lt;br /&gt;
&lt;br /&gt;
UNION&lt;br /&gt;
&lt;br /&gt;
SELECT&lt;br /&gt;
user2.firstname AS First,&lt;br /&gt;
user2.lastname AS Last,&lt;br /&gt;
user2. idnumber AS Employee_ID,&lt;br /&gt;
user2.city AS City,&lt;br /&gt;
uid.data AS State,&lt;br /&gt;
user2.country AS Country,&lt;br /&gt;
g.name AS Group_name,&lt;br /&gt;
c.fullname AS Course,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Attempt,&lt;br /&gt;
&amp;quot;not_started&amp;quot; AS Status,&lt;br /&gt;
&amp;quot;-&amp;quot; AS Date&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user_enrolments AS ue&lt;br /&gt;
JOIN prefix_enrol AS e ON e.id = ue.enrolid&lt;br /&gt;
JOIN prefix_course AS c ON c.id = e.courseid&lt;br /&gt;
JOIN prefix_user AS user2 ON user2 .id = ue.userid&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = user2.id &lt;br /&gt;
JOIN prefix_groups AS g ON g.courseid = c.id&lt;br /&gt;
JOIN prefix_groups_members AS m ON g.id = m.groupid&lt;br /&gt;
JOIN prefix_scorm AS sc ON sc.course=c.id&lt;br /&gt;
Left Join prefix_scorm_scoes_track AS st on st.scormid=sc.id AND st.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
WHERE  st.timemodified IS NULL AND m.userid=user2.id&lt;br /&gt;
&lt;br /&gt;
ORDER BY  Course, Last, First, Attempt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Badges==&lt;br /&gt;
&lt;br /&gt;
=== All badges issued, by User ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, b.name AS badgename, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN&lt;br /&gt;
(SELECT c.shortname&lt;br /&gt;
    FROM prefix_course AS c&lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Context,&lt;br /&gt;
CASE &lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 1 THEN &amp;quot;Activity Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 1 AND t.method = 2 THEN &amp;quot;Activity Completion (Any)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 2 AND t.method = 2 THEN &amp;quot;Manual Award&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 1 THEN &amp;quot;Course Completion (All)&amp;quot;&lt;br /&gt;
  WHEN t.criteriatype = 4 AND t.method = 2 THEN &amp;quot;Course Completion (Any)&amp;quot;&lt;br /&gt;
  ELSE CONCAT (&#039;Other: &#039;, t.criteriatype)&lt;br /&gt;
END AS Criteriatype,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateissued ) , &#039;%Y-%m-%d&#039; ) AS dateissued,&lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( d.dateexpire ), &#039;%Y-%m-%d&#039; ) AS dateexpires,&lt;br /&gt;
CONCAT (&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/badge.php?hash=&#039;,d.uniquehash,&#039;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&#039;) AS Details&lt;br /&gt;
FROM prefix_badge_issued AS d &lt;br /&gt;
JOIN prefix_badge AS b ON d.badgeid = b.id&lt;br /&gt;
JOIN prefix_user AS u ON d.userid = u.id&lt;br /&gt;
JOIN prefix_badge_criteria AS t on b.id = t.badgeid &lt;br /&gt;
WHERE t.criteriatype &amp;lt;&amp;gt; 0&lt;br /&gt;
ORDER BY u.username&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please note: the FROM_UNIXTIME command is for MySQL.&lt;br /&gt;
&lt;br /&gt;
=== All badges available in the system, with Earned count ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.type = 1 THEN &amp;quot;System&amp;quot;&lt;br /&gt;
WHEN b.type = 2 THEN &amp;quot;Course&amp;quot;&lt;br /&gt;
END AS Context, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.courseid IS NOT NULL THEN &lt;br /&gt;
(SELECT c.shortname &lt;br /&gt;
    FROM prefix_course AS c &lt;br /&gt;
    WHERE c.id = b.courseid)&lt;br /&gt;
WHEN b.courseid IS NULL THEN &amp;quot;*&amp;quot;&lt;br /&gt;
END AS Course, &lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 2 THEN &amp;quot;No&amp;quot;&lt;br /&gt;
WHEN b.status = 1 OR b.status = 3 THEN &amp;quot;Yes&amp;quot;&lt;br /&gt;
WHEN b.status = 4 THEN &amp;quot;x&amp;quot;&lt;br /&gt;
END AS Available,&lt;br /&gt;
CASE&lt;br /&gt;
WHEN b.status = 0 OR b.status = 1 THEN &amp;quot;0&amp;quot;&lt;br /&gt;
WHEN b.status = 2 OR b.status = 3 OR b.status = 4 THEN &lt;br /&gt;
 (SELECT COUNT(*) &lt;br /&gt;
   FROM prefix_badge_issued AS d&lt;br /&gt;
   WHERE d.badgeid = b.id&lt;br /&gt;
 )&lt;br /&gt;
END AS Earned&lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Badges Leaderboard ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
A simple list of usernames and how many badges they have earned overall.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, (SELECT COUNT(*) FROM prefix_badge_issued AS d WHERE d.userid = u.id) AS earned&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
ORDER BY earned DESC, u.username ASC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Manage badges (System &amp;amp; Course) ===&lt;br /&gt;
&lt;br /&gt;
List system wide badges, course and system level badges + a link to relevant &amp;quot;manage badges&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT b.id, b.name, b.description &lt;br /&gt;
,CASE &lt;br /&gt;
  WHEN b.type = 1 THEN &#039;System&#039;&lt;br /&gt;
  WHEN b.type = 2 THEN &#039;Course&#039;&lt;br /&gt;
END AS Level&lt;br /&gt;
,CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/badges/index.php?type=&#039;, b.type, &#039;&amp;amp;id=&#039;,&lt;br /&gt;
			  c.id, &#039;&amp;quot;&amp;gt;Manage badges in: &#039;, c.fullname, &#039;&amp;lt;/a&amp;gt;&#039;) AS Manage &lt;br /&gt;
FROM prefix_badge AS b&lt;br /&gt;
JOIN prefix_course AS c ON c.id = b.courseid&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Administrator Reports==&lt;br /&gt;
&lt;br /&gt;
===Config changes in Export friendly form===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
DATE_FORMAT( FROM_UNIXTIME( g.timemodified ) , &#039;%Y-%m-%d&#039; ) AS date, &lt;br /&gt;
u.username AS user, &lt;br /&gt;
g.name AS setting, &lt;br /&gt;
CASE &lt;br /&gt;
 WHEN g.plugin IS NULL THEN &amp;quot;core&amp;quot;&lt;br /&gt;
 ELSE g.plugin&lt;br /&gt;
END AS plugin, &lt;br /&gt;
g.value AS new_value, &lt;br /&gt;
g.oldvalue AS original_value&lt;br /&gt;
FROM prefix_config_log  AS g&lt;br /&gt;
JOIN prefix_user AS u ON g.userid = u.id&lt;br /&gt;
ORDER BY date DESC&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts by user===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
How to get a list of all users and which cohorts they belong to.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.firstname, u.lastname, h.idnumber, h.name&lt;br /&gt;
FROM prefix_cohort AS h&lt;br /&gt;
JOIN prefix_cohort_members AS hm ON h.id = hm.cohortid&lt;br /&gt;
JOIN prefix_user AS u ON hm.userid = u.id&lt;br /&gt;
ORDER BY u.firstname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cohorts with Courses===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
List of all cohorts with name, id, visibility, and which courses they are enrolled in.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
# h.id,&lt;br /&gt;
# e.customint1,&lt;br /&gt;
h.name AS Cohort,&lt;br /&gt;
h.idnumber AS Cohortid,&lt;br /&gt;
CASE &lt;br /&gt;
 WHEN h.visible = 1 THEN &#039;Yes&#039;&lt;br /&gt;
 ELSE &#039;-&#039;&lt;br /&gt;
END AS Cohortvisible,&lt;br /&gt;
CONCAT(&#039;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;%%WWWROOT%%/course/view.php&#039;, CHAR(63),&#039;id=&#039;,c.id,&#039;&amp;quot;&amp;gt;&#039;,c.fullname,&#039;&amp;lt;/a&amp;gt;&#039;) AS Course&lt;br /&gt;
FROM prefix_cohort h&lt;br /&gt;
JOIN prefix_enrol e ON h.id = e.customint1&lt;br /&gt;
JOIN prefix_course c ON c.id = e.courseid %%FILTER_COURSES:e.courseid%% &lt;br /&gt;
WHERE e.enrol = &#039;cohort&#039; AND e.roleid = 5&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Courses created And Active courses by Year===&lt;br /&gt;
Active courses is counting course that have at least one Hit, And &amp;quot;Active_MoreThan100Hits&amp;quot; counts courses that have at least 100 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `timecreated` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT course ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY course &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 100) AS courses_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( courses_log.`time` ) ) = YEAR( FROM_UNIXTIME( `timecreated` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan100Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_course` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Users created And Active users by Year===&lt;br /&gt;
Active users is counting users that have at least one Hit, And &amp;quot;Active_MoreThan500Hits&amp;quot; counts users that have at least 500 Hits&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
&lt;br /&gt;
YEAR( FROM_UNIXTIME( `firstaccess` ) ) AS YEAR, COUNT( * ) AS Counter&lt;br /&gt;
&lt;br /&gt;
, (SELECT COUNT( DISTINCT userid ) &lt;br /&gt;
FROM prefix_log AS l&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( l.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active&amp;quot;&lt;br /&gt;
&lt;br /&gt;
,(SELECT COUNT(*) FROM ( &lt;br /&gt;
SELECT COUNT( * ),time &lt;br /&gt;
FROM prefix_log AS l &lt;br /&gt;
GROUP BY userid &lt;br /&gt;
HAVING COUNT(*) &amp;gt; 500) AS users_log&lt;br /&gt;
WHERE YEAR( FROM_UNIXTIME( users_log.`time` ) ) = YEAR( FROM_UNIXTIME( `firstaccess` ) )&lt;br /&gt;
) AS &amp;quot;Active_MoreThan500Hits&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FROM `prefix_user` &lt;br /&gt;
GROUP BY YEAR( FROM_UNIXTIME( `timecreated` ) ) &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Course Aggregation Report===&lt;br /&gt;
Contributed by Elizabeth Dalton, Granite State College&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
In particular, be on the lookout for any courses with the following combinations of parameters, which are known to cause changes in calculations:&lt;br /&gt;
&lt;br /&gt;
# mean of grades set with aggregate with subcategory.&lt;br /&gt;
# Simple weighted mean of grades with aggregate with sub category and drop the lowest&lt;br /&gt;
# Sum of grades drop the lowest&lt;br /&gt;
&lt;br /&gt;
Also review:&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48618&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-48634&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-49257&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50089&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-50062&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT&lt;br /&gt;
&lt;br /&gt;
COUNT(c.shortname) AS &#039;Count of Courses&#039;&lt;br /&gt;
&lt;br /&gt;
# If you want to display all the courses for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, c.shortname AS &#039;course name&#039;&lt;br /&gt;
&lt;br /&gt;
# If you need to display grade categories for each aggregation type, uncomment the next line and change GROUP BY settings&lt;br /&gt;
#, gc.fullname AS &#039;grade category name&#039;&lt;br /&gt;
&lt;br /&gt;
, gc.aggregation AS &#039;aggregation method&#039;&lt;br /&gt;
&lt;br /&gt;
#These aggregation text strings appear to be hard-coded. I couldn&#039;t find a table for them. If you have aggregation types I haven&#039;t included here, they&#039;ll be blank in your report results.&lt;br /&gt;
, CASE gc.aggregation&lt;br /&gt;
  WHEN 0 THEN &#039;Mean of Grades&#039;&lt;br /&gt;
  WHEN 2 THEN &#039;Median of Grades&#039;&lt;br /&gt;
  WHEN 6 THEN &#039;Highest Grade&#039;&lt;br /&gt;
  WHEN 8 THEN &#039;Mode of Grades&#039;&lt;br /&gt;
  WHEN 10 THEN &#039;Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 11 THEN &#039;Simple Weighted Mean of Grades&#039;&lt;br /&gt;
  WHEN 12 THEN &#039;Mean of Grades (with extra credits)&#039;&lt;br /&gt;
  WHEN 13 THEN &#039;Sum of Grades&#039;&lt;br /&gt;
END AS &#039;aggregation name&#039;&lt;br /&gt;
&lt;br /&gt;
# Note that gc.aggregatesubcats column is eliminated in 2.8 and later per MDL-47503, so comment that line on updated systems or you&#039;ll get an error&lt;br /&gt;
, gc.keephigh AS &#039;keep high&#039;&lt;br /&gt;
, gc.droplow AS &#039;dr0p low&#039;&lt;br /&gt;
, gc.aggregateonlygraded AS &#039;Aggregate only graded&#039;&lt;br /&gt;
, gc.aggregateoutcomes AS &#039;aggregate outcomes&#039;&lt;br /&gt;
, gc.aggregatesubcats AS &#039;aggregate subcategories&#039;&lt;br /&gt;
&lt;br /&gt;
# If you are displaying data about individual courses, you may want to know how old they are&lt;br /&gt;
#, FROM_UNIXTIME(c.startdate) AS &#039;course start date&#039;&lt;br /&gt;
&lt;br /&gt;
# 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&#039;ll need to uncomment the necessary JOINs below&lt;br /&gt;
#, gi.itemname AS &#039;grade item&#039;&lt;br /&gt;
#, gg.finalgrade AS &#039;final grade&#039;&lt;br /&gt;
&lt;br /&gt;
FROM&lt;br /&gt;
&lt;br /&gt;
prefix_course AS c&lt;br /&gt;
JOIN prefix_grade_categories AS gc ON gc.courseid = c.id&lt;br /&gt;
JOIN prefix_course_categories AS cc ON cc.id = c.category&lt;br /&gt;
&lt;br /&gt;
#LEFT JOIN prefix_grade_items AS gi ON gi.courseid = c.id #AND gi.categoryid=gc.id&lt;br /&gt;
#LEFT JOIN prefix_grade_grades AS gg ON gg.itemid = gi.id AND gg.userid = u.id&lt;br /&gt;
&lt;br /&gt;
WHERE&lt;br /&gt;
1&lt;br /&gt;
#AND gc.aggregation = 13 #only the dreaded Sum of Grades aggregations&lt;br /&gt;
#AND gc.depth = 1 # if for some reason you only want course aggregations, not subcategories&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GROUP BY gc.aggregation, gc.keephigh, gc.droplow, gc.aggregateonlygraded, gc.aggregateoutcomes, gc.aggregatesubcats&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running Cron jobs (task_scheduled) ===&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT classname&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(lastruntime), &#039;%H:%i [%d]&#039;) AS &#039;last&#039;&lt;br /&gt;
  ,DATE_FORMAT(now(), &#039;%H:%i&#039;) AS &#039;now&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(nextruntime), &#039;%H:%i [%d]&#039;) AS &#039;next&#039;&lt;br /&gt;
  ,DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP()-nextruntime), &#039;%i&#039;) AS &#039;next in min&#039;&lt;br /&gt;
FROM mdl_task_scheduled&lt;br /&gt;
WHERE now() &amp;gt; FROM_UNIXTIME(nextruntime)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== All Meta courses with Parent and Child course relationships ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
This shows the list of courses with Meta course link enrollments in them (&#039;Parent course&#039;), and the courses which are connected to them to provide enrollments (&#039;Child courses&#039;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT &lt;br /&gt;
c.fullname AS &#039;Parent course name&#039;,&lt;br /&gt;
c.shortname AS &#039;Parent course shortname&#039;,&lt;br /&gt;
en.courseid AS &#039;Parent course id&#039;,&lt;br /&gt;
(SELECT fullname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course name&#039;,&lt;br /&gt;
(SELECT shortname FROM prefix_course WHERE prefix_course.id = en.customint1) As &#039;Child course shortname&#039;,&lt;br /&gt;
en.customint1 AS &#039;Child course id&#039;&lt;br /&gt;
FROM prefix_enrol en&lt;br /&gt;
JOIN prefix_course c ON c.id = en.courseid&lt;br /&gt;
WHERE en.enrol = &#039;meta&#039;&lt;br /&gt;
ORDER BY c.fullname&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Useful sub queries ==&lt;br /&gt;
&lt;br /&gt;
IN this section please put any short one purpose sub queries that show how common procedures often useful as part of larger queries.&lt;br /&gt;
&lt;br /&gt;
=== All teachers in the course ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This snippet shows how to get teachers from a course. The contextevel for course objects is 50. And the default Teacher role is role id 3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
,(SELECT GROUP_CONCAT( CONCAT( u.firstname,  &amp;quot; &amp;quot;, u.lastname ) ) &lt;br /&gt;
FROM prefix_course ic&lt;br /&gt;
JOIN prefix_context con ON con.instanceid = ic.id&lt;br /&gt;
JOIN prefix_role_assignments ra ON con.id = ra.contextid AND con.contextlevel = 50&lt;br /&gt;
JOIN prefix_role r ON ra.roleid = r.id&lt;br /&gt;
JOIN prefix_user u ON u.id = ra.userid&lt;br /&gt;
WHERE r.id = 3 AND ic.id = c.id&lt;br /&gt;
GROUP BY ic.id&lt;br /&gt;
) AS TeacherNames&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Get custom User profile fields for a user ===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON uid.fieldid = uif.id &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to limit it to one of those fields, you can restrict it by shortname of the custom profile field, so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, uif.name, uid.data&lt;br /&gt;
FROM prefix_user AS u&lt;br /&gt;
JOIN prefix_user_info_data AS uid ON uid.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field AS uif ON (uid.fieldid = uif.id AND uif.shortname = &#039;shortname1&#039;)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will show you only the data from the custom profile field with the shortname &#039;shortname1&#039;.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, d1.data AS &#039;Profile One&#039;, d2.data As &#039;Profile Two&#039;&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
JOIN prefix_user_info_data d1 ON d1.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
JOIN prefix_user_info_data d2 ON d2.userid = u.id&lt;br /&gt;
JOIN prefix_user_info_field f2 ON d2.fieldid = f2.id AND f2.shortname = &#039;shortname2&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== NOTE: Alternate Method ====&lt;br /&gt;
&lt;br /&gt;
If you have more than a couple of fields you need to use, then this query may time out or not return data due to too many joins. The limit seems to be around 10 custom profile fields. &lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname1&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thefirstfield&lt;br /&gt;
&lt;br /&gt;
,(SELECT d1.data FROM prefix_user_info_data d1&lt;br /&gt;
 JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = &#039;shortname2&#039;&lt;br /&gt;
 WHERE d1.userid = u.id&lt;br /&gt;
) AS thesecondfield&lt;br /&gt;
&lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== How to use Configurable Reports Date Time Filters===&lt;br /&gt;
&lt;br /&gt;
Contributed by: [https://moodle.org/user/profile.php?id=88992 Randy Thornton]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Here is a simple example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sql&amp;gt;&lt;br /&gt;
SELECT u.username, &lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.firstaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;FirstAccess&#039;,&lt;br /&gt;
DATE_FORMAT(FROM_UNIXTIME(u.lastaccess),&#039;%Y-%m-%d %H:%i&#039;) AS &#039;LastAccess&#039;   &lt;br /&gt;
FROM prefix_user u&lt;br /&gt;
&lt;br /&gt;
WHERE 1=1&lt;br /&gt;
%%FILTER_STARTTIME:u.firstaccess:&amp;gt;%% &lt;br /&gt;
%%FILTER_ENDTIME:u.lastaccess:&amp;lt;%% &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
2) You MUST then add the Start / End date filter on the Filters tab of the Report. If you don&#039;t, the report will still run, probably, but the filter will be ignored.&lt;br /&gt;
&lt;br /&gt;
Note: the WHERE 1=1 statement is a peculiarity of the filters in Config reports: if you don&#039;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.)&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
[https://github.com/jleyva/moodle-configurable_reports_repository Configurable Reports Repository on GitHub]&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;br /&gt;
&lt;br /&gt;
[[es:Reportes específicos hechos por usuarios]]&lt;/div&gt;</summary>
		<author><name>Nadavkav</name></author>
	</entry>
</feed>