Showing which courses a student is enrolled in

Showing which courses a student is enrolled in

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>");
    }

                        
評比平均分數: -
In reply to Gustav W Delius

Re: Showing which courses a student is enrolled in

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

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

Martin Dougiamas發表於
Core developers的相片 Documentation writers的相片 Moodle HQ的相片 Particularly helpful Moodlers的相片 Plugin developers的相片 Testers的相片
I'll see your hack of Gustav's hack, and raise it with a datalib function and a CVS checkin.  微笑

    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 Przemyslaw Stencel

Re: Showing which courses a student is enrolled in

Zbigniew Fiedorowicz發表於

The problem is caused by backslashes in front of certain quotation marks being stripped out. See the following discussion: http://moodle.org/mod/forum/discuss.php?d=3522#15609

There should be a backslash before the quote right after href= and another one before the quote following $course->id.