New block: Child courses block

New block: Child courses block

by Marty Jacobs -
Number of replies: 26

Just created a very simple block that displays the child courses for a Meta course.

Here's the page for the block in the Modules and plugins DB:

http://moodle.org/mod/data/view.php?d=13&rid=1723

Enjoy,

Marty
Average of ratings: -
In reply to Marty Jacobs

Re: New block: Child courses block

by John Hill -

Hi Marty,

This might not be the most appropriate place to ask but it relates to the use of child courses. We would like to use child courses that are accessed from within the Meta course as your block operates but is there a way to hide the child courses in the list of available courses to students when they login. So what we are aiming to do is only show for example a top level English course that students login to and through this course they see access to individual child English modules but this would be the only point of entry so the top level English course acts as a kind of portal.

Hope you can help and that this isn't too far off the point of your block.

Thanks
John

In reply to John Hill

Re: New block: Child courses block

by Marty Jacobs -
Hi John,

Yes there is. What you need to do is created a hidden category and put your child courses in it. Make sure the child courses are not hidden themselves though, or your students wont be able to access them.

Before your students can access these courses, you must also allow visible courses in hidden categories. This is a site setting and can be found by going to the site administration block and clicking on Front page > Front page settings. Make sure the 'allow visible courses in hidden categories' is ticked.

Hope this helps,

Marty

P.S. If I was using a meta course like a portal, I'd be inclined to leave enrolment open on the child courses. This way, you can force enrolment at the Meta course level, but then students can self enrol on the child courses that are relevant to them (this is kinda how I had anticipated people would use this block).

Otherwise, you will need a way of making sure the correct students are enrolled on each child course or they won't be able to access them, even if they're enrolled on the Meta course (you'll need to investigate different methods of enrollment to do this, but then perhaps you've done this already!).
Average of ratings: Useful (1)
In reply to Marty Jacobs

Re: New block: Child courses block

by John Hill -

Hi Marty,

Thanks for your suggestion I can see that it works for Moodle installations that are allowing students to access their courses by working through the categories but unfortunately we are trying to set up our installation so that students only see a list of courses they are enrolled on, once logged in. So we use the 'List of courses' option in the Front page settings and this unfortunately displays courses that are open in hidden categoires. We are going down this path as a way of keeping it simple for students to login and only see their own courses because we intend to handle all enrollment on courses behind the scences by integrating Moodle with our other systems.

It is early days with our use of Moodle, which is still really in a trial stage so your suggestion has given us a decision about how we best let students access their courses. Unless anyone knows of a way to hide courses in this 'List of courses' view and still have them accessible to students.

Thanks again for your help
John

In reply to John Hill

Re: New block: Child courses block

by Marty Jacobs -
Ah, I think I understand what you want to do now - you want the list of courses to only display Meta courses (portal courses) and not child courses.

Doing this would involve hacking core files, something that is generally considered bad practice. However, sometimes you have to do it!

Luckily, this modification only involves minimal changes. This might not be the best way to do it, but it was quick to implement and worked for me. You need to make changes to three files in Moodle, namely datalib.php, lib.php and block_course_list.php. Here's what you need to do:

1) Go to Moodle/lib/datalib.php, find this chunk of code:

$basefields = array('id', 'category', 'sortorder',
'shortname', 'fullname', 'idnumber',
'teacher', 'teachers', 'student', 'students',
'guest', 'startdate', 'visible',
'newsitems', 'cost', 'enrol',
'groupmode', 'groupmodeforce');

and add 'metacourse' to the end of the list, e.g 'groupmode', 'groupmodeforce', 'metacourse');.

2) Go to moodle/course/lib.php and locate the print_my_moodle() function. Next find this part of the code in the function:

foreach ($courses as $course) {
if ($course->id == SITEID) {

continue;
}

and add this code after it:

if (!$course->metacourse) {
continue;
}

3) Go to moodle/blocks/course_list/block_course_list.php and find this chunck of code:

foreach ($courses as $course) {
if ($course->id == SITEID) {
continue;
}

Add the following code after it:

if (!$course->metacourse) {
continue;
}

Once you have applied these three small hacks, the front page list of courses and 'My courses' block should only display Meta courses.

Obviously you should backup the original files before making these changes. If you need any help with this, just give me a shout.

All the best,

Marty

P.S. This hack doesn't take into account 'www.yourmoodleurl.com/my'. You could apply a similar hack, but there's no point unless you plan to re-direct users to this page after login.

To see this hack in action, login to moodle.martyjacobs.net with the username 'megaman' and the password 'capcom'. I may reverse the hack soon, so take a look asap!
In reply to Marty Jacobs

Re: New block: Child courses block

by John Hill -

Thanks Marty, Thats exactly what we would like to do and this has provided me with a useful workaround. I take it from the code that all individual courses that don't have child courses attached would still need to be assigned meta course status in order to be displayed in the course list. I'm guessing this doesn't have any impact anywhere else it is just a setting to apply on setting up each course.

Thanks for your help and access to the test area to see it in practice.

Cheers
John

In reply to John Hill

Re: New block: Child courses block

by Marty Jacobs -
Yeah, a course must have Meta course status to appear on the course list on the homepage, or in the 'My courses' block. If you have a course that isn't a child course or a Meta course it will not appear in either of these lists.

However, all courses are listed on the /my page and the all courses page (course/index.php). This, to me, seems like a good 'happy medium' because you wont end up with orphaned courses this way, i.e. there are alternative routes to get to courses that are not Meta or child courses, but these links are hidden by obscurity. You could obviously, apply a similar hack to these pages too if you wanted to, but this might restrict your flexibility when setting up courses.

All the best,

Marty

P.S.
You need to set Meta course status before you add any other student enrolments to the course, otherwise you'll have to go into the database to change it into a Meta course (you wont be able to change the Meta course setting on the course settings page).

If you want to set courses as Meta courses, but you don't want them to have any child courses, take a look at this workaround in the bug tracker.
In reply to Marty Jacobs

Re: New block: Child courses block

by John Hill -

Hi Marty,

Thanks for the tips on how we can hide our child courses. It is important to know this is possible and I will explore these avenues in more detail in the coming months as we develop our new Moodle installation.

Thanks
John

In reply to Marty Jacobs

Re: New block: Child courses block

by Marty Jacobs -
The 'Child courses' block is now called the 'Related courses' block to better reflect the two ways you can use Meta courses in Moodle (see this page in Moodle Docs).

A BIG thanks to Daniele Cordella for bringing this to my attention and making changes to the code so that the block works with scenario 2.

Happy Moodling,

Marty
In reply to Marty Jacobs

Re: New block: Child courses block

by Matt Smith -
Hi I have been Reading this thread with great interest. Many thanks . I am interested in hiding courses from the my course block. However I was wondering what could be done to do the reverse of the above . The reasoning behind this is that I am experimenting with a reverse meta course system. My 'portal' course(which represents a course programme area) is not a meta course but the courses that it links to ( which are the imdividual units of the course programme) are meta courses. The portal course is the child of these so that enrolements
On the portal course automatically populate the other courses. What I would therefore like to do is hide the meta courses so that the students only see the portal course

I hope I am making sense. Please be gentle - this is my first posting on moodle.org ever!

Many thanks

Matt
In reply to Matt Smith

Re: New block: Child courses block

by Marty Jacobs -

Hi Matt,

Welcome to the Moodle community. Don't worry, we're a friendly bunch, honest!

It is very easy to modify the above hack to display only normal/child courses and hide metacourses. Follow the steps above, but during steps 2 and 3 and remove the "!" from the line of code, e.g.

if ($course->metacourse) {
    continue;
}

instead of:

if (!$course->metacourse) {
    continue;
}

Also, during step 1, make sure you make the addition to the correct section of code, as there are two very similar snippets in the page. The one you're looking for is within the function called get_my_courses.

Please bear in mind that the metacourses will still show on the "all courses" listings page and the "my moodle" page, see following example URLs:

http://www.mymoodlesite.com/course/index.php

http://www.mymoodlesite.com/my

However, I'm pretty sure these pages could be easily hacked too.

Give me a shout if you need help with this hack.

Hope this helps,

Marty

P.S. To see this hack in action, login to moodle.martyjacobs.net with the username 'megaman' and the password c4Pc0m*!. As before, I may reverse the hack soon, so take a look asap!

In reply to Marty Jacobs

Re: New block: Child courses block

by Marty Jacobs -

I didn't initially notice how old your original post was Matt, sorry for not replying sooner!

Your metacourse model works well, I've created some demo courses on my site so that you can see how this would work:

http://moodle.martyjacobs.net/course/view.php?id=34

Use the username and password mentioned in my last post (see above).

All the best,

Marty

In reply to Marty Jacobs

Re: New block: Child courses block

by Rahmat Costas -

Hi Marty,

I am very interested in hiding the meta courses. I juts need to know what file (PHP) I need to make this modification to. Is it in all of the three files you mentioned above?

Thanks for your help.

Rahmat.

In reply to Rahmat Costas

Re: New block: Child courses block

by Marty Jacobs -
Hi Rahmat,

Sorry for not replying to your post sooner, I've not been very active in the Moodle forums lately.

Anyway, yes you just need to alter the three files I mention higher up in this thread. I'll double check the hack today just to make sure, as I posted the original information a while ago!

Marty
In reply to Marty Jacobs

Related courses block

by Andy Hediger -

Hi Marty

Thank you very much for this block! it is very useful, we use it for a library-scenrio:
courses are related to a metacourse, called "Mediathek" and we named your block "Kontext": it shows the link
to the library and back:
in the course <-------------->      in the Library or "Mediathek"

 

What happens is: a user that is entering the library, sees a link also to our test-course (which is also a child of the library).

But this link should not be visible for a "normal" user because, she/he can't enter our test course (and will get such a message, after clicking the link).

Therefore our Question: could the Links to the Child-Courses in the Related_courses Block be visible under the condition that the user has the capability/is allowed to see the child course,

because it is frustrating the user, clicking the link and then she/he gets obviously the message : not allowed to enter this course.

thank you from switzerland

In reply to Marty Jacobs

Re: New block: Child courses block

by Domenico Beato -

I installed “Related Courses Block” plugin on Moodle 1.9.9. 

But I cannot see the “Related Courses Block” option in the “add block” list box.

 

What should I check?

 

Thanks very much

Domenico

In reply to Domenico Beato

Re: New block: Child courses block

by Andy Hediger -

Hi Dominco

have you defined a meta course for the course you want to test the block with?

after that the block should be in the list

andy

In reply to Marty Jacobs

Re: New block: Child courses block

by Russell Robshaw -

Hi

I'm using Moodle 1.9.7.

Is it possible to hide, or otherwise, prevent the display of courses on the Related Courses block, whose availability in course settings is selected as This course is not available to students?

Thanks

Russell

In reply to Marty Jacobs

Re: New block: Child courses block

by Matt Elvey -

Moodle 2.1 handles meta courses as an enrolment type so the original version of the block no longer works. 

Attached is a modified version that queries the enrolment table to identify meta courses attached as a parent or child to the current course. 

It is worth nothing that a course can now be both a mata course and have metacourses attached to it (so it is in both parent and child relationships) so this modified block will display both although it does not identify which are which. 

I hope this is of some assistance. I forgot to include a readme so just extract the archive into the blocks directory and it should get picked up.

Average of ratings: Useful (1)
In reply to Matt Elvey

Re: New block: Child courses block

by Russell Robshaw -

Hi Matt

Thanks for the information – I'll let you know how the modified block works.

Russell

In reply to Matt Elvey

Re: New block: Child courses block

by Adam Barbary -

Just to clarify Matt Elvey's version is for Moodle 2.1+ 

In reply to Adam Barbary

Re: New block: Child courses block

by Russell Robshaw -

Ahhhh!  OK – thanks for that Adam – guess I'll have to wait until we move to Moodle 2.1. mixed

In reply to Matt Elvey

Re: New block: Child courses block

by Jaymin Limbachiya -

HI, Matt

 

Your Provided Related_Course_BLock is not Working in Moodle 2.0 version

In reply to Jaymin Limbachiya

Re: New block: Child courses block

by Matt Elvey -

Hi Jaymin,

I developed and tested the block on moodle 2.1 so I am not sure that it will work on 2.0. 

Unfortunately I am not in a position to test/develop the plugin for 2.0 and can only recommend upgrading to 2.1. If it still does not work in 2.1 please enable full debugging and post the log file in order that I might see where it is failing. 

Also any details on what is actually happening would be helpful. I suspect the most lilely scenario is that the page fails to render (you get a blank page) but the more deatils you can provide the better. 

In reply to Matt Elvey

Re: New block: Child courses block

by Jaymin Limbachiya -

Thanks for reply Matt Now I am redevelop Child Course Block and if i have any query asking you.