Completed courses list in user profile

Completed courses list in user profile

by Christopher O'Kelly -
Number of replies: 3

Hi guys,

 

I am looking at setting up moodle to show a list of completed courses on the user profile. nothing flash, just something along the lines of

"

...

First access: Tuesday, 13 March 2012, 12:58 PM  (13 days 23 hours)
Last access: Tuesday, 27 March 2012, 12:21 PM  (now)
Interests: *nix, Vehicle Safety, Training, Moodle, Al Fresco
Courses Completed:
  • Safety Induction
  • 2012 General Training
  • Test Course

"

at the end of the user profile.

My first instinct, having not found a plugin specifically for this, was that I could modify the /user/profile.php with a quick bit of SQL to pull it out of mdl_course_completions, but I know this will get killed on every update and it's not the best option. I haven't done much work into extending moodle at all, so I am not 100% sure how successful I would be in creating a plugin for the purpose.

I get the feeling though that this seems like a feature which would already exist somewhere, I am mainly just wondering if anyone can point me in the direction of the setting or plugin I have missed if this is the case.

Average of ratings: -
In reply to Christopher O'Kelly

Re: Completed courses list in user profile

by Christopher O'Kelly -

quick update - I have added this temporarily by directly modifying profile.php (I know, I know, it's totally the wrong way to do it, this is more of a proof of concept). I inserted this code starting at line 356 of profile.php (between the 'suspended' hidden field and the echo "</table></div></div>")

$courseCheckCon = mysql_connect("localhost","username","secret");
mysql_select_db("moodle", $courseCheckCon);
$completedCoursesQuery =        "SELECT mdl_course.fullname " .
                                                        "FROM mdl_course " .
                                                        "INNER JOIN mdl_course_completions " .
                                                        "ON mdl_course.id=mdl_course_completions.course " .
                                                        "WHERE mdl_course_completions.userid=" . $_GET["id"];
$completedCourses = mysql_query($completedCoursesQuery,$courseCheckCon);
echo "<tr><td class=\"label c0\">Courses Completed: </td><td class=\"info c1\"><ul>";
while ($eachCompletedCourse = mysql_fetch_array($completedCourses))
        {
        echo "<li>" . $eachCompletedCourse["fullname"] . "</li>";
        }
echo "</ul></td></tr>";
mysql_close($courseCheckCon);

This works fine, it displays the completed courses exactly as I want it to. My next step is figuring out how to use this in the form of a plugin for future proofing. I have looked through http://docs.moodle.org/dev/Plugins and I think the  closest match for what I need would be the user profile fields plugin type. The issue is that this seems to be defined for the type of custom fields where the user can enter them, as opposed to dynamic, automatically populated fields. I had a look at the local plugin type but it seems more suited to adding blocks or responding to events on a backend scale. I may be totally misreading the documentation but I get the idea that the plugin system is designed more for adding or overlaying objects to the existing moodle layout without changing the already existing content (such as profile.php).

Is there a way for me to replicate the changes I have made here using plugins, or should I just consign myself to copying my script back into place whenever we update?

In reply to Christopher O'Kelly

Re: Completed courses list in user profile

by Julie Grundy -

Did you get anywhere with this? I'd like to do something similar and list the completed but archived courses on each user's profile. My problem (apart from any changes being wiped on upgrade) is that once a course is 'archived' i.e. deleted there's no reference to it in Moodle anymore.

I've added a "completed courses" field to the default profile, and can export the details from our database to a CSV for uploading in bulk to Moodle. But each time I upload, I'll be wiping any previous data in that field, I think.

In reply to Julie Grundy

Re: Completed courses list in user profile

by Dimo Dimov -

I am looking for a way to add the completed courses field to the user profile page but I want this field to be listed in the "User profile fields" area.