My Moodle: show courses by category

My Moodle: show courses by category

by Kate McKelvey -
Number of replies: 24
Has anybody tried to display courses on the my moodle page in category groups? I have had a request to group the courses by category so the students/teachers can see which term the course belongs to (our terms overlap a bit).

Any ideas?
Average of ratings: -
In reply to Kate McKelvey

Re: My Moodle: show courses by category

by Dale Davies -
Hi, this is a snippet from something I was developing, you may have to fiddle a bit but it should work...

<?php
$mycourses = get_my_courses($USER->id);
$catArr = array();

foreach ($mycourses as $mycourse){
array_push($catArr,$mycourse->category);
}

$catArr = array_unique($catArr);

sort($catArr);

foreach ($catArr as $cat){
$myCat = get_records_select('course_categories',"id='$cat'",'name ASC','id, name');
foreach ($myCat as $mCat){
echo '<h4>'.$mCat->name.'</h4>';
}
echo '<ul>';
foreach ($mycourses as $mycourse){
if ($mycourse->category == $cat){
echo '<li><a href="../course/view.php?id='.$mycourse->id.'">'.$mycourse->fullname.'</a></li>';
}
}
echo '</ul>';
}
?>


In reply to Dale Davies

Re: My Moodle: show courses by category

by Kate McKelvey -
Dale that is fantastic! Works like a charm. I tweaked it a bit to get it formated the way we had it before. In case anyone is interested, here is a screenshot of our MyMoodle page
Attachment Picture_1.png
In reply to Kate McKelvey

Re: My Moodle: show courses by category

by Barbara Lawrence -
Kate
I can display the categories by using Dale's code but not the activity within the courses as you have in your screenshot. How did you do it?
Barbara
In reply to Dale Davies

Re: My Moodle: show courses by category

by tan tan -

Hi,

Can i know where to edit or add this code into ? index.php ?

In reply to Dale Davies

Re: My Moodle: show courses by category

by Olaf Nöhring -
Hi

I created a little update to your script:

Categories sorted by name, Courses in categories sorted by name, Categories & courses color coded with css!

Install:
Extract the nicemy.zip to a folder of your local harddisk.

1. rename (=backup) the /moodle/my directory
2. copy the my folder (extracted by now) to /moodle/my (so you have a new my folder).
3. Adjust your themes stylesheet styles_layout.css: Add the contents of the file add2-styles_layout.css into your theme into the file styles_layout.css !

See the image: This is what your moodle/my could look like!
colored my
Any feedback?
Average of ratings: Useful (4)
In reply to Olaf Nöhring

Re: My Moodle: show courses by category

by Olaf Nöhring -
Hi

just to let you know: I am working on an improved version (better CSS naming, user defined sort (similar to http://moodle.org/mod/forum/discuss.php?d=122236#p555851), show/hide categories)

Olaf
In reply to Olaf Nöhring

Re: My Moodle: show courses by category

by Chris Delaney -
Olaf,

Your colour code my courses is excellent. My teachers really appreciated it.

How did you get on with the user defined my courses?

Cheers

Chris
In reply to Olaf Nöhring

Re: My Moodle: show courses by category

by Daniel Rivera -
I think this is quite useful Olaf. Thanks.

The tree view in "Meine Kurs" block - how did you do that? It looks very convenient for the learner especially is there are many courses enrolled.

And what does the colour-coding (blue, orange, grey) describe?

Dan
In reply to Daniel Rivera

Re: My Moodle: show courses by category

by Olaf Nöhring -
Hi

the color coding is the category and the courses. I used a simple online color picker to choose some nice matching colors for each category and it's entries, but differnt colors for different categories so that they are easy to distinguish.

The "Meine Kurse" is a block: http://moodle.org/mod/forum/discuss.php?d=67494#p545593 (you can search the moodle forum, but I simnply uploaded the block (exactly as I downloaded it - also the filename) (also look here for comparison: http://moodle.org/mod/forum/discuss.php?d=55625#p253733 )

Just remove the original block in moodle settings -> blocks -> fixed blocks -> my page and replace it with this block.

Olaf
In reply to Olaf Nöhring

Re: My Moodle: show courses by category

by Rosario Carcò -

Hey !! (Lieber Olaf...)

Why did you not give credit to JULIAN RIDDEN and ROSARIO CARCÒ who adapted and reworked the original myCourses Block out of the FN_Moodle project?

NEVER upload such copies of code because all development is done and documented in its original Forum Thread.

Since Version 06r a lot of enhancements have been done and there is also a block called siteNavigation which shows up ALL categories and ALL courses of your Moodle-Site.

So navigate to the original threads if you want to use and upgrade your myCourses and/or siteNavigation Blocks:

myCourses: http://moodle.org/mod/forum/discuss.php?d=67494

siteNavigation: http://moodle.org/mod/forum/discuss.php?d=103703

Rosario

In reply to Daniel Rivera

Re: My Moodle: show courses by category

by Olaf Nöhring -
Hi again

oh, that color coding: you (as admin/user, depending on settings) can switch things on/off with these "buttons". Please try or read forum link I posted before.

Olaf
In reply to Olaf Nöhring

Re: My Moodle: show courses by category

by José Ángel Polo -
But does not show news in the forums, assigment, etc.
It is a pity, the work is magnificent
In reply to Olaf Nöhring

Re: My Moodle: show courses by category

by jonathan z -
Hi, i like so much this way to order the courses, i used it and works very well, but in my Moodle i have two levels in the categories, and i have a question there is some way to order the courses by the two levels?


like this


medicine faculty --- first level category

Medicine --- second level category
course1
course2 --- courses
course3

Nursery --- second level
course1
course2
course3




In reply to jonathan z

Re: My Moodle: show courses by category

by Rosario Carcò -

One of my promises, when I coded the siteNavigation Block, was to create also a copy of the code to be used in the center part of the FrontPage.

Unfortunately develpment and enhancement of the code still takes all my resources. Actually I am rewriting the code to display myCourses and siteNavigation in a popUp-window because the block width of 210 pixels is simply too small/narrow for large scale sites with more than 1'500 courses deeply nested into more than 1'000 categories.

But as soon as I have this code, it could simply be extracted to put the php-code into any place where you can output HTML-Code.

Have a look at the siteNavigation thread to observe development:

http://moodle.org/mod/forum/discuss.php?d=103703

Rosario

In reply to Olaf Nöhring

Re: My Moodle: show courses by category

by Laura Laura -

Hello,

Does anyone know how to display the categories and the subcategories?

Olaf Code' displays only the latest level of the category but I need The fist level of categories and the second level (sub-categories).

I hope somebody can help us.

Thanks! I'm sorry about my english!

In reply to Olaf Nöhring

Re: My Moodle: show courses by category

by Ali Hastie -

Hi

Has anyone configured Olaf's nicemy for Moodle 2.+?

Cheers

In reply to Dale Davies

Re: My Moodle: show courses by category

by iwan ariz -
Dear Dale and Kate

Where file should i put this code into?

regrds
combro
In reply to iwan ariz

Re: My Moodle: show courses by category

by Dale Davies -
Paste the code snippet into your My Moodle index page, so...

www/my/index.php

This would eventually replace whatever existing code you have in there to output the course list.
In reply to Dale Davies

Re: My Moodle: show courses by category

by Tulix Velásquez -
Hello

Can i know where to edit or add this code into ? index.php ?
In reply to Dale Davies

Re: My Moodle: show courses by category

by nikhil pednekar -

Hi Dale,

I copied your code to my index.php. But when i clicked on myhome...it shows 

Fatal error: Call to undefined function get_records_select() in C:\wamp\www\moodleNew\my\index.php on line 157......


Can you help me out of this.....it's very important for me......

Thanks.