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