Moodle

In a users profile, can you display the coures in a drop down list instead of listing them comma delimited.

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 1.8, 2.3
  • Fix Version/s: None
  • Component/s: General
  • Labels:
    None
  • Affected Branches:
    MOODLE_18_STABLE, MOODLE_23_STABLE

Description

Because of the moodle bug where admin users show every course in their profile, you have patched the problem with a limit of viewable text in the courses list. Not only does this not improve the load time it takes while viewing a user with alot of courses, but it also causes some courses to not show at all.

Could you use a simple dropdown list to fill the courses and a goto button to redirect to that course?

Issue Links

Activity

Hide
Matthew Davidson added a comment - - edited

from moodle/user/view.php

        • Replace *******

if ($mycourses = get_my_courses($user->id,'visible DESC,sortorder ASC', '*', false, 21)) {
$shown=0;
$courselisting = '';
foreach ($mycourses as $mycourse) {
if ($mycourse->visible and $mycourse->category) {
$courselisting .=
if ($mycourse->id != $course->id){ $courselisting .= "<option value='$mycourse->id'>$mycourse->fullname</option>"; $courselisting .= "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$mycourse->id\">" . format_string($mycourse->fullname) . "</a>, "; }
else { $courselisting .= format_string($mycourse->fullname) . ", "; }
}
$shown++;
if($shown==20) { $courselisting.= "..."; break; }
}
print_row(get_string('courses').':', rtrim($courselisting,', '));
}

        • With*******

if ($mycourses = get_my_courses($user->id,'visible DESC,fullname ASC,sortorder ASC', '*', false, 0)) {
$courselisting = '<select id="courseselector">';
foreach ($mycourses as $mycourse) {
if ($mycourse->visible and $mycourse->category) { $courselisting .= "<option value=\"".$mycourse->id."\">".$mycourse->fullname."</option>"; }
}
$courselisting .= '</select><input type="button" value="Go" onClick="Javascript:window.location=\''."$CFG->wwwroot/user/view.php?id=$user->id&course=".'\'+document.getElementById(\'courseselector\').value;">';
print_row(get_string('courses').':', rtrim($courselisting,', '));
}

NOTE: This should only be used if the improved get_my_courses() function is implemented. But my users really like this setup better than the text based course output currently used.

Show
Matthew Davidson added a comment - - edited from moodle/user/view.php
        • Replace *******
if ($mycourses = get_my_courses($user->id,'visible DESC,sortorder ASC', '*', false, 21)) { $shown=0; $courselisting = ''; foreach ($mycourses as $mycourse) { if ($mycourse->visible and $mycourse->category) { $courselisting .= if ($mycourse->id != $course->id){ $courselisting .= "<option value='$mycourse->id'>$mycourse->fullname</option>"; $courselisting .= "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$mycourse->id\">" . format_string($mycourse->fullname) . "</a>, "; } else { $courselisting .= format_string($mycourse->fullname) . ", "; } } $shown++; if($shown==20) { $courselisting.= "..."; break; } } print_row(get_string('courses').':', rtrim($courselisting,', ')); }
        • With*******
if ($mycourses = get_my_courses($user->id,'visible DESC,fullname ASC,sortorder ASC', '*', false, 0)) { $courselisting = '<select id="courseselector">'; foreach ($mycourses as $mycourse) { if ($mycourse->visible and $mycourse->category) { $courselisting .= "<option value=\"".$mycourse->id."\">".$mycourse->fullname."</option>"; } } $courselisting .= '</select><input type="button" value="Go" onClick="Javascript:window.location=\''."$CFG->wwwroot/user/view.php?id=$user->id&course=".'\'+document.getElementById(\'courseselector\').value;">'; print_row(get_string('courses').':', rtrim($courselisting,', ')); } NOTE: This should only be used if the improved get_my_courses() function is implemented. But my users really like this setup better than the text based course output currently used.
Hide
Matthew Davidson added a comment - - edited

edit

Show
Matthew Davidson added a comment - - edited edit
Hide
Matthew Davidson added a comment - - edited

edit

Show
Matthew Davidson added a comment - - edited edit
Hide
Matthew Davidson added a comment - - edited

edit

Show
Matthew Davidson added a comment - - edited edit
Hide
Charlie Owen (SonniesEdge) added a comment -

I've tried your code on Moodle 1.8.2 and it works as intended - good job!

However, I'd raise a concern over accessibility - a user with javascript turned off would not be able to use your dropdown form at all.

To make the form accessible it would need to have a way of redirecting the user to the appropriate page with no javascript. This could be done by specifying a redirect script as a destination in the form action and sending the desired URL to this script: It would then redirect as appropriate.

How about?:

if ($mycourses = get_my_courses($user->id,'visible DESC,fullname ASC,sortorder ASC', '*', false, 0)) {
$courselisting = '<form action="redirect.php" method="GET">';
$courselisting .= '<select name="targetcourseid" onChange=submit()>';
foreach ($mycourses as $mycourse) {
if ($mycourse->visible and $mycourse->category) {
$courselisting .= '<option value="' .$mycourse->id . '"';
if ($mycourse->id == $course->id) {$courselisting .= ' selected="selected"';}
$courselisting .= '>';
$courselisting .= $mycourse->fullname.'</option>';
}
}
$courselisting .= '</select>';
$courselisting .='<input type="hidden" name="targetuserid" value="'.$user->id.'">';
$courselisting .='<noscript><input type="submit" value="Go"></noscript>';
$courselisting .= '</form>';
print_row(get_string('courses').':', rtrim($courselisting,', '));
}

and then a new file in the same directory called "redirect.php" that would take the passed parameters and redirect to the appropriate URL. I'll attach it after this comment.

However, is there already such a redirect file already in Moodle? I don't want to be duplicating it if there is.

Show
Charlie Owen (SonniesEdge) added a comment - I've tried your code on Moodle 1.8.2 and it works as intended - good job! However, I'd raise a concern over accessibility - a user with javascript turned off would not be able to use your dropdown form at all. To make the form accessible it would need to have a way of redirecting the user to the appropriate page with no javascript. This could be done by specifying a redirect script as a destination in the form action and sending the desired URL to this script: It would then redirect as appropriate. How about?: if ($mycourses = get_my_courses($user->id,'visible DESC,fullname ASC,sortorder ASC', '*', false, 0)) { $courselisting = '<form action="redirect.php" method="GET">'; $courselisting .= '<select name="targetcourseid" onChange=submit()>'; foreach ($mycourses as $mycourse) { if ($mycourse->visible and $mycourse->category) { $courselisting .= '<option value="' .$mycourse->id . '"'; if ($mycourse->id == $course->id) {$courselisting .= ' selected="selected"';} $courselisting .= '>'; $courselisting .= $mycourse->fullname.'</option>'; } } $courselisting .= '</select>'; $courselisting .='<input type="hidden" name="targetuserid" value="'.$user->id.'">'; $courselisting .='<noscript><input type="submit" value="Go"></noscript>'; $courselisting .= '</form>'; print_row(get_string('courses').':', rtrim($courselisting,', ')); } and then a new file in the same directory called "redirect.php" that would take the passed parameters and redirect to the appropriate URL. I'll attach it after this comment. However, is there already such a redirect file already in Moodle? I don't want to be duplicating it if there is.
Hide
Charlie Owen (SonniesEdge) added a comment -

redirect.php

Show
Charlie Owen (SonniesEdge) added a comment - redirect.php
Hide
Pawel Suwinski added a comment -

I needed listing whole courses grouped by assigned roles, so I do the change in another way. Attached below. Patch for Moodle 1.9.5. Any comments are welcome .

Show
Pawel Suwinski added a comment - I needed listing whole courses grouped by assigned roles, so I do the change in another way. Attached below. Patch for Moodle 1.9.5. Any comments are welcome .
Hide
Pawel Suwinski added a comment -

moodle195-MDL_9446-user_view_php-patch-201007221410.diff.gz

Show
Pawel Suwinski added a comment - moodle195-MDL_9446-user_view_php-patch-201007221410.diff.gz
Hide
Charles Fulton added a comment -

I've updated the patches here for 2.3 using a select box: https://github.com/mackensen/moodle/compare/master...MDL-9446.

Show
Charles Fulton added a comment - I've updated the patches here for 2.3 using a select box: https://github.com/mackensen/moodle/compare/master...MDL-9446.

People

Dates

  • Created:
    Updated: