Hi all,
I'm trying to create a report which shows:
- All the students in the current course
- The groups those students belong to
- Whether or not the students have completed the course
- Several of the students' custom profile fields
The output I'm trying to get is something like:
Username | Country | Custom profile field 1 (Organisation Type) |
Custom profile field 2 (Role Type) |
Course | Group | Completed (Y/N) |
---|---|---|---|---|---|---|
student1 | UK | Research institute | Scientist | Pest Management | CABI | Y |
student1 | UK | Research institute | Scientist | Pest Management | Researchers | Y |
student2 | FR | Government body | Trainer | Pest Management | Researchers | N |
Username | Country | Custom profile field 1 (Organisation Type) |
Custom profile field 2 (Role Type) |
Course | Group | Completed (Y/N) |
---|---|---|---|---|---|---|
student1 | UK | Research institute | Scientist | Pest Management | CABI | Y |
student1 | UK | Research institute | Scientist | Pest Management | Researchers | Y |
student1 | UK | Research institute | Scientist | Pest Management | Researchers | Y |
student2 | FR | Government body | Trainer | Pest Management | Researchers | Y |
I'm using the Certificate Issued (custom certificate plugin) as a proxy for completion, but happy to go with an alternative method.
A student may be in more than one group.
You can see in the actual output that I'm ending up with:
- Duplicate lines
- Everyone is showing as completed
The query I'm working with is shown below:
SELECT c.shortname AS Course, u.username AS 'Username', u.country AS 'Country', uid.data AS 'Organisation Type', uir.data AS 'Role Type', g.name AS Groupname,
CASE WHEN i.userid IS NOT NULL # Should test to see whether the student has a certificate or not
THEN 'Yes'
ELSE "No"
END
AS "Has certificate"
FROM prefix_course AS c
# Select the certificate
JOIN prefix_customcert AS cc ON cc.course = c.id # Select the certificates that have been issued
JOIN prefix_customcert_issues AS i ON i.customcertid = cc.id
# Connect the user to the certificate issues
RIGHT JOIN prefix_user AS u ON i.userid = u.id # Why is this showing that everyone has a certificate?
# Show custom profile fields
JOIN prefix_user_info_data as uid ON uid.userid = u.id
JOIN prefix_user_info_field as uif1 ON (uid.fieldid = uif1.id AND uif1.shortname = 'OrganisationType')
JOIN prefix_user_info_data as uir ON uir.userid = u.id
JOIN prefix_user_info_field as uif2 ON (uir.fieldid = uif2.id AND uif2.shortname = 'RoleType')
JOIN prefix_groups_members AS m ON u.id = m.userid
JOIN prefix_groups AS g ON g.id = m.groupid
WHERE c.id = %%COURSEID%%
Any help gratefully received!
Thanks,
Mark