This query simply counts the number of completed courses.
SELECT
COUNT(*)
FROM mdl_certificate_issues
WHERE userid = CURRENT_USER
This query shows the total number of credits the user has completed. (I use the certificate plugin and rely on the printhours field in mdl_certificate)
SELECT SUM(printhours)
FROM mdl_certificate
INNER JOIN mdl_certificate_issues
ON mdl_certificate.id = mdl_certificate_issues.certificateid
WHERE mdl_certificate_issues.userid = CURRENT_USER
I have tried everything, I am frazzled, I think that there are a couple things missing or formatted wrong? After looking around and lots of trial and error I think that the MySQL SUM function cannot be used here because of the format $DB->get_records_sql call function does not allow it? However, I do see a reference to COUNT here... https://docs.moodle.org/dev/Data_manipulation_API and I'm not sure how to use it. OR I could be wrong and just be using the wrong syntax in the dataset. I have listed below all the not empty settings in my first template Course Count.
Autofill template with a Preset --custom--
The key that identifies template: coursecount
Template Name: Course Count
The body of template:
My User ID is @@CERTIFICATE_ISSUES:userid@@ in the mdl_certificates_issues table.
(I guess this doesn't work because it returns more than one value?)
@@USER:id@@ <-- value here proves generico is working keep looking.
What I would like to see here is...
Total Courses Completed: @@CERTIFICATE_ISSUES:COUNT(*)@@
Dataset: "SELECT COUNT(*) FROM {certificate_issues} WHERE userid = ?;"
Dataset Variables: @@USER:id@@, @@CERTIFICATE_ISSUES:COUNT(*)@@
I am thinking that course count can be fixed with some changes to the dataset setting?
The Second query with SUM(printhours) I'm not sure will work here? So my thought was to create a table on the fly that can be used as a dataset? where the query creates the table to be used in the dataset,
The other thought was creating a .php file and going that route but I don't know php but could piece together whats needed after looking at some tutorials but my thought was these two simple query should be a perfect fit for using in generico and this would give me some new functions with informing the students how many credits and courses they have completed.