Course Completion Report for a single student.

Course Completion Report for a single student.

by Chris Webb -
Number of replies: 5

Hi all,


I am trying  to set up a report that will show a user all of the courses that they are enrolled in and whether they have completed the courses or not. I am not familiar with SQL so I have been trying to achieve this by creating Course and User reports though I am happy to do this in SQL if someone can point me in the right direction. I have used: 


  • Course field column to display the course name
  • Current user final grade in course to display the course grade
  • A Current User enrolled courses condition to filter it to a single user.
This gives me a report like the image below. Does anyone know how I could create a column the would give the course status like "Completed", "Not Completed", "In Progress", etc.


I can figure out how to do this with a User Report but it is for all users in a single course. I want to do it for all courses for just the current user who is looking at the report so that a student can use the report to see what courses they have completed and which ones are still pending.


Report

Average of ratings: -
In reply to Chris Webb

Re: Course Completion Report for a single student.

by Melanie Scott -
Picture of Particularly helpful Moodlers

This is what I use (SQL report).  It doesn't include a grade but it does show activities completed vs assigned.  Because Feedback doesn't show up in the gradebook, it won't be counted in completed/assigned activities. There is specical code in there to also give a link to the course listed.  I don't think you can get completed without SQL.  The Where clause specifies student role, where the student id is the same as the person asking for the report (this allows your student to get their list, not someone else's or everyone's) and it links student to specific role assignments and context so you get everything.  You may (or may not) have to replace the prefix_ with mdl_...just depends on your installation.  When I run the report on the site, I use prefix but if I run it in Adminer, I use mdl...


SELECT u.firstname AS 'First Name'
,
u.lastname AS 'Last Name'
,
concat('<a target="_new" href="%%WWWROOT%%/course/view.php?id=',c.id,'">',c.fullname,'</a>') AS 'Course'

,
IFNULL((SELECT COUNT(gg.finalgrade)
  FROM prefix_grade_grades AS gg
  JOIN prefix_grade_items AS gi ON gg.itemid=gi.id
  WHERE gi.courseid=c.id
   AND gg.userid=u.id
   AND gi.itemtype='mod'
   GROUP BY u.id,c.id),'0') AS 'Activities Completed'
,
 
IFNULL((SELECT COUNT(gi.itemname)
  FROM prefix_grade_items AS gi
  WHERE gi.courseid = c.id
   AND gi.itemtype='mod'), '0') AS 'Activities Assigned'
,
 
/*show 100% complete and date if course completion record exists. show incomplete otherwise*/
(SELECT IF(cc.timecompleted<>0,
(SELECT CONCAT('100% completed ', FROM_UNIXTIME(MAX(cc.timecompleted),'%m/%d/%Y'))
FROM prefix_course_completions
WHERE prefix_course_completions.course=c.id
AND prefix_course_completions.userid=u.id), 'incomplete')) AS 'Date Completed'

 
 
FROM prefix_user u
JOIN prefix_user_enrolments ue ON ue.userid=u.id
JOIN prefix_enrol e ON e.id=ue.enrolid
JOIN prefix_course c ON c.id = e.courseid
RIGHT JOIN prefix_course_completions cc ON cc.course=c.id and cc.userid=u.id
JOIN prefix_context AS ctx ON ctx.instanceid = c.id
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id
###JOIN prefix_role AS r ON r.id = e.roleid
RIGHT join prefix_course_info_data hrs on
c.id = hrs.courseid
 
WHERE ra.userid=u.id
AND ctx.instanceid=c.id
AND u.id=%%USERID%%
/*AND ue.status='0'*/ ### "0" for active, "1" for suspended. Leave commented out to include both.
AND ra.roleid='5' ### "5" = student
AND c.visible='1' ### "1" for course visible, "0" for hidden
AND c.startdate = '1372654800'
GROUP BY u.id, c.id
ORDER BY u.lastname, u.firstname, c.fullname

In reply to Melanie Scott

Re: Course Completion Report for a single student.

by Chris Webb -

Hi Melainie,


Thanks for your help. I appreciate it.

Unfortunately I was not able to get it to work. I did a find and replace tried both prefix_ and mdl_ throughout the script and it seemed to want a prefix as when I used mdl_ I got a prefix not defined error.

When I used the script as is, I got an "Error reading from database" error. 

Is there anything that I need to remove from the script to get it to work.  There seems to be a number of comments such as "for course visible" or "for hidden."


I'm afraid I don't know much about SQL.


Thanks,


Chris



In reply to Chris Webb

Re: Course Completion Report for a single student.

by Melanie Scott -
Picture of Particularly helpful Moodlers

To be honest, I'm not much of a sql person either...I've had a little training but mostly I steal code from other places and poke it until it works.  Sometimes I beg for help from one of our techs that does sql.  That said...it may have something to do with your particular installation...you may need something other than prefix or mdl.

I copied what I gave you (which is what I use with a bunch of stuff taken out) and I pasted it into a new sql configurable report.  It saved and ran.  I'm assuming you use course completions...if that's turned off I could see it failing. 

I just looked over it again as I was responding...there is a RIGHT join on course_info_data...which you might not have.  Take that out (the last two lines of the FROM statement) and try it.

In reply to Melanie Scott

Re: Course Completion Report for a single student.

by Chris Webb -

Hi Melanie,


Sorry for taking a while to respond. Thanks a lot for the help. I turned on debugging mode and you were right about the  RIGHT join on course_info_data statement. It was getting hung up on that. When I removed that line in went a bit further and got hung up on WHERE ra.userid=u.id. 


When I have time I will see if I can troubleshoot that. It might be to do with our version of SQL or perhaps even how we handle user IDs. We use LDAP authentification and to be honest we don't have it set up quite right.

Thanks a lot of the SQL Query though. I am sure with a bit of tweaking I can get it to work. I might have to go to the library first though and read a bit about SQL : )


Cheers,


Chris



In reply to Chris Webb

Re: Course Completion Report for a single student.

by Melanie Scott -
Picture of Particularly helpful Moodlers

Did you ever get this figured out?  The Where for role assignment matched to user id is pretty standard.  No idea why it would hang up.