Assign course to multiple categories

Assign course to multiple categories

by Jason Carroll -
Number of replies: 13

Hello,

I am in the process of creating several courses in Moodle. The courses are for teachers instead of students. Some courses fit under multiple categories (i.e. Elementary Teachers, Science, Math, and Social Studies). However, I currently can only add a course to one category.

Does anyone know of a way to add courses to multiple categories? Or a way to tag courses and have the tags show up in the navigation bar on left of screen?

Any advice is much appreciated. I am using Moodle 2.7.

Average of ratings: -
In reply to Jason Carroll

Re: Assign course to multiple categories

by Inbar Dotan -

Hi Jason, 

A course can only be associated with one course category.  There is a way to go around it by:

  1. Creating a new course under a different course category
  2. Using "single activity" course format for the new course
  3. Choosing "URL" as the single activity
  4. Adding the original course's url (and display option = "open")
Now you have two courses, each under a different course category, and both are actually the same course. 

You can use metalink to automatically enroll all of the original course users to the other course. On the downside, the users will see two identical courses on the front page.   

Obviously, this is not a reasonable solution for a large amount of courses. 


Hope this helps!

Inbar. 

Average of ratings: Useful (5)
In reply to Inbar Dotan

Re: Assign course to multiple categories

by Nadav Kavalerchik -
Picture of Core developers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Inbar,

This is a very beautiful idea smile

Which made me think, from a developer perspective...

That you can also develop a tiny patch to course's theme which check if you added the phrase "link: XXX" in the course's "idnumber" field, and if so, it will automatically redirect the user to the XXX course.

It is only a few lines of code added to the theme, for this to happen, here is a general idea...

<?php
if (strpos($COURSE->idnumber, ':')) {
list($islink, $linkcourseid) = explode(':', $COURSE->idnumber);
if (!empty($islink) and $islink == 'link') {
$redirectlink = new moodle_url($CFG->wwwroot.'/course/view.php?id='.$linkcourseid);
if (has_capability('moodle/course:changeidnumber', context_system::instance())) {
echo html_writer::link($redirectlink, 'Click to redirect to the real course');
} else {
redirect($redirectlink);
}
}
}
?>

Then, it is much easier to manage adding an automatic "link" from each virtual course to the real course.

Considering a large amount of courses, You can update it using the bulk course upload (csv) tool. And create the categories using the bulk category upload tool.

Average of ratings: Useful (1)
In reply to Nadav Kavalerchik

Re: Assign course to multiple categories

by Michael Veit -

Hi Nadav,

this seems an interesting solution. In wich file I put the code: theme/mytheme/config.php?

Regards,

Michael

In reply to Michael Veit

Re: Assign course to multiple categories

by Michael Veit -

Hi,

I found an intersting website (https://docs.moodle.org/24/en/Course_FAQ#Can_I_put_a_course_in_more_than_one_category.3F) and so the correct file: moodle/course/view.php

I added the code before 'context_helper::preload_course' (moodle version: 2.6) in the line 39.


I changed the code of Nadav slightly:
  • Between the second if-statement and the variable $redirectlink I added the line so that any added whitespace are filtered out:  $linkcourseid = trim($linkcourseid);
  • I changed the law, so that someone, which have the role of course creator in the course category, can go directly to the pseudo-course if he also has the role of trainer in this course: moodle/course:create
    The law 'moodle/course:changeidnumber' has in the course category only the admin and the manager but not the trainer, so the trainer can't go later in his pseudo-course.

Thank you very much for the code, Nadav.

Regards,

Michael


In reply to Michael Veit

Re: Assign course to multiple categories

by Michael Veit -

I changed again the right, so that only the respective trainer of the pseudo course, the manager and the administrator come into it.

if (strpos($course->idnumber, ':')) {
        list($islink, $linkcourseid) = explode(':', $course->idnumber);
            if (!empty($islink) and $islink == 'link') {
                $linkcourseid = trim($linkcourseid);
                $redirectlink = new moodle_url($CFG->wwwroot.'/course/view.php?id='.$linkcourseid);
              if (has_capability('moodle/course:changeidnumber', context_course::instance($course->id, MUST_EXIST))) {
                echo html_writer::link($redirectlink, 'Click to redirect to the real course.');
              } 
              else {
                redirect($redirectlink);
              }
            }
        }
In reply to Michael Veit

Re: Assign course to multiple categories

by Nadav Kavalerchik -
Picture of Core developers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Michael,

Sorry for the looooong delay, I was on a long vacation smile

The above suggested code should go into the theme's layout pages (not the config.php)

Especially, the page layout that is marked as "course" page layout in the theme's config.php file.

(Which is the page used by the theme to display the front page of the course)

I will put this on my todo list, and upload a more useful example, soon.

Nadav

In reply to Nadav Kavalerchik

Re: Assign course to multiple categories

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

And just for the benefit of anyone who comes to this thread via Google - since 2.6 it is also possible to use the Single Activity course format to do the same but without any coding - see the latest version of that FAQ https://docs.moodle.org/28/en/Course_FAQ#Can_I_put_a_course_in_more_than_one_category.3F (and perhaps you'd like to add your edited code to the docs there again as well?)

In reply to Inbar Dotan

Re: Assign course to multiple categories

by Jason Carroll -

This is very helpful. Thanks Inbar. We have around 50 courses however, and if each is in an average of three categories that would put 150 courses on the frontpage with many duplicates, so don't think this would work for us.

In reply to Jason Carroll

Re: Assign course to multiple categories

by Mark Sharp -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

You can use meta courses which will let you use a single course for content, and the other courses for enrolments.

Average of ratings: Useful (1)
In reply to Mark Sharp

Re: Assign course to multiple categories

by Jason Carroll -

Hi Mark, I'm not familiar with meta courses. Would that pose the same issue of the copies of courses I need in multiple categories also showing up on front page?

Thanks,

Jason 

In reply to Jason Carroll

Re: Assign course to multiple categories

by Mark Sharp -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
Meta course enrolment allows you to enrol people who are on different courses onto a new course without individually enrolling them.

Let's suppose you have the following courses: CourseA, CourseB, CourseC
CourseA, CourseB and CourseC are identical, but they have different people enrolled on them. You want all the students to see the same material in one place.

You could nominate CourseA to be the course you want to be the main course page. In that course, you select the meta-course enrolment method, and tell it you want all the students from CourseB to be enrolled on this course. Then you do the same with CourseC.

Now, whenever the enrolment for CourseB or CourseC changes, the enrolments for CourseA automatically update to match.

The students will see all the information they need in CourseA.

I've not tested this, but if you then decide to hide CourseB or CourseC, they will be hidden, but all the students from those courses will still be able to see the material in CourseA.
In reply to Mark Sharp

Re: Assign course to multiple categories

by Jason Carroll -

This makes sense. Thanks Mark.

We already have a customized enrollment solution we are using so this may not work for us. 

Seems like there would be a way to add a course to multiple categories. Will continue to look for workarounds.

Jason

In reply to Jason Carroll

Re: Assign course to multiple categories

by Melanie Scott -
Picture of Particularly helpful Moodlers
Another option (and a very simple one) is this:
Copy the URL for the course.
Go to the categories you want the course to show up in (one by one) and click Edit Category in Administration.

Type in any information you want to share, including the title of the course, etc.  You can even probably make it look a lot like a normal course listing. 

Highlight the title, click the link option, paste in the url.

Save.

This is what some of my individual facilities do when I put several dozen courses out in several places and they only to choose which ones they require for their staff...so in their area, the staff get a list of courses relevant to them and the courses actually live somewhere else.


Average of ratings: Useful (1)