Courses available without enrolling

Re: Courses available without enrolling

by Zbigniew Fiedorowicz -
Number of replies: 5
You can do this in version 1.5 (not in previous versions) as follows. First put an enrolment key on the course, but also allow guests to enter without the enrolment key. When a student clicks on the course link, they are sent to the enrolment page, but that page has an extra button: "Login as guest". Also if you add "&username=guest" to the course link, the student would automatically be sent into the course logged in as a guest, bypassing the enrolment page entirely.

Average of ratings: Useful (1)
In reply to Zbigniew Fiedorowicz

Re: Courses available without enrolling

by Mat Cannings -

I had not tried that combination, I think that should do exactly what I wanted as I am using 1.5.

Thankyou for your help Zbigniew and Darren.

In reply to Mat Cannings

Re: Courses available without enrolling

by Mat Cannings -

Have realised that our live site does not allow guest access. I am looking into 'hacking' the section of code that displays "My Courses" so that it does not display certain course ids.

This way the students will be able to enrol (or be automatically enrolled using enrol=1) on the library course but will not see it.

I will post the hack once it is working.

In reply to Mat Cannings

Re: Courses available without enrolling

by Mat Cannings -
This was relatively easy to achieve.
Firstly the function that displays the "My Courses" list is 'print_my_moodle' which is located in '/course/lib.php'

In this file I made a copy of the function 'print_my_moodle' and named it 'print_my_moodle_custom'

I added an array to list the course ids I want hidden and then check against this when writing to the screen (modified/added lines in blue at the end of the post)

Then finally change the function call in 'index.php' from 'print_my_moodle' to 'print_my_moodle_custom'

function print_my_moodle_custom() {

/// Prints custom user information on the home page.
/// Over time this can include all sorts of information

global $USER, $CFG;
$courses_to_hide = array('6','7');

if (!isset($USER->id)) {
error("It shouldn't be possible to see My Moodle without being logged in.");
}

if ($courses = get_my_courses($USER->id)) {
foreach ($courses as $course) {
if (!$course->category) {
continue;
}
if (!in_array($course->id,$courses_to_hide)){
print_course($course, "100%");
}
}

if (count_records("course") > (count($courses) + 1) ) { // Some courses not being displayed
echo "<table width=\"100%\"><tr><td align=\"center\">";
print_course_search("", false, "short");
echo "</td><td align=\"center\">";
print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get");
echo "</td></tr></table>\n";
}
} else {
if (count_records("course_categories") > 1) {
print_simple_box_start("center", "100%", "#FFFFFF", 5, "categorybox");
print_whole_category_list();
print_simple_box_end();
} else {
print_courses(0, "100%");
}
}
}

In reply to Mat Cannings

Re: Courses available without enrolling

by Dawn Wright -

Matthew

I'd like to use your approach to do the same thing but I am not a programer. I'm hoping all I have to do is to replace the course numbers in your array (i.e. 6 & 7) with Moodle course numbers for the courses I'm interested in hiding. Is this correct?

thanks for your sharing this.

dawn

In reply to Dawn Wright

Re: Courses available without enrolling

by Mat Cannings -
That is correct the 6 and 7 are the coursid's and would need to correspond to whichever courses you want hidden. More courses can be added to this array, they just need to be seperated by a comma.

You will still need to enrol the students on to the hidden courses somehow. This can be done manually or using the method detailed by Darren in the link that he posted earlier in this thread.

On the site I am using the hidden courses have been added to a HTML block
The links are of the format www.yourwebsite/moodle/course/enrol.php?id=6&confirm=1

This enrols the student automatically on the course when they click it and takes them straight in, avoiding the "would you like to enrol" message