Showing which courses a student is enrolled in

Showing which courses a student is enrolled in

by Gustav W Delius -
Number of replies: 5

If you would find it convenient to have a list of all the courses that a student is enrolled in showing up in the student's full profile then you could add the following lines to cvs:/moodle/user/view.php:

    if ($students = get_records("user_students", "userid", $user->id)) {
        $strcourses = "";
        foreach ($students as $student) {
            $course = get_record("course", "id", $student->course);
            if ($course->visible) {
                $strcourses .= "<a href=\"{$CFG->wwwroot}/course/view.php?id=$course->id\">$course->fullname</a>, ";
            }
        }
        print_row("Enrolled in:", $strcourses);
    }

A good place to add this is right after the lines

    if ($user->icq) {
        print_row("icq:","<a href=\"$user->icq">http://web.icq.com/wwp?uin=$user->icq\">$user->icq <img src=\"http://web.icq.com/whitepages/online?icq=$user->icq&img=5\" width=18 height=18 border=0></a>");
    }

                        
Average of ratings: -
In reply to Gustav W Delius

Re: Showing which courses a student is enrolled in

by Przemyslaw Stencel -
Hi Gustav,

I've pasted your code exactly after the icq condition, but I'm getting this error message:
Parse error: parse error in /home/users/online/www/user/view.php on line 127

I think line 127 is this one:
                $strcourses .= "<a href="{$CFG->wwwroot}/course/view.php?id=$course->id">$course->fullname</a>, ";

Any ideas?
In reply to Przemyslaw Stencel

Re: Showing which courses a student is enrolled in

by Thomas Robb -
This is a great addition.  I actually needed it last night.  Gustav, where were you? :-)

Przemyslaw, I would look at the next line of code and make sure that there is a semi-colon at the end and that everything else is well-formed, but you could just copy & paste the one below and try again.  (I found that the spaces had been replaced by &nbsp; in my system and had to restore the real spaces.  Could that be the problem?)

I'd like to suggest two minor enhancements to the code, one so that only teachers can see the course display, and another to peel off the final comma and trailing space from the listing:

if (isteacher($course->id)){
    if ($students = get_records("user_students", "userid", $user->id)) {
        $strcourses = "";
        foreach ($students as $student) {
            $course = get_record("course", "id", $student->course);
            if ($course->visible) {
                $strcourses .= "<a href=¥"{$CFG->wwwroot}/course/view.php?id=$course->id¥">$course->fullname</a>, ";
            }
        }
        print_row("Enrolled in:", rtrim($strcourses,", "));
    }
}
In reply to Thomas Robb

Re: Showing which courses a student is enrolled in

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I'll see your hack of Gustav's hack, and raise it with a datalib function and a CVS checkin.  smile

    if (isteacher($course->id)) {
        if ($mycourses = get_my_courses($user->id)) {
            $courselisting = '';
            foreach ($mycourses as $mycourse) {
                if ($mycourse->visible) {
                    $courselisting .= "<a href=\"$CFG->wwwroot/course/view.php?id=$mycourse->id\">$mycourse->fullname</a>, ";
                }
            }
            print_row(get_string('courses').':', rtrim($courselisting,', '));
        }
    }

In reply to Gustav W Delius

Re: Showing which courses a student is enrolled in

by Marc Dastous -
This works AWESOME!!!  Thank you!!!