As per the standard functionality of Moodle when a student/tutor/administrator logs into Moodle, In his homepage he would see the list of course categories and also the number of courses populated for each category in the parentheses present beside each course category and this is a standard functionality of Moodle.
Here comes the need for customizing this functionality as a Student/Tutor will only be enrolled to a limited number of courses which belongs to a limited number of course categories.
It is undesirable and also creates ambiguity for a user to find all the courses in each category in the parentheses present beside each course category.
We have provided a solution to this by customizing the course category in Moodle such that a student/tutor when logs in would only see the total sum of his enrolled courses in the parentheses for every course category which he has enrolled.
Consider a Student X who has enrolled to Two courses from Summer 2015 course category, Three courses from Spring 2015 and One course from Fall 2014 Course category.
The total number of populated courses for Fall 2015 and Spring 2014 couse categories are 524 and 483 respectively. As per the standard functionality of Moodle when Student X logs in, he would see all the number of courses populated for a category, for all the course categories in the parentheses as observed in the image.
A customization is provided to resolve this concern where the Student/ Tutor barring Administrator would only see the total number of enrolled courses in the parentheses beside the course categories which they have enrolled.
The code is modified such that the parentheses beside the concerned course category will only display the list of enrolled courses for a Student/ Tutor.
After successful implementation of the code, a Student/Tutor would only see only the sum of their enrolled courses in their respective course category parentheses as observed in the image.
Here the student/tutor could only see the total number of enrolled courses in the parentheses for a respective course category.
As per the above example, Student X when logs in would see the total number of enrolled courses in the parentheses for Summer 2015, Spring 2014 and Fall 2014.
Hence the requirement is fulfilled.
Steps for Course Category customization in moodle.
Need to show the count of enrolled courses beside of course category namesin course / site home page under categories section for Moodle student/faculty except admin.
Solution:
Please check our next blog on rubrics rounding up in moodle
Step1 : Find the get_courses_count () method definition at linenumber -1524
publicfunction get_courses_count($options = array()) {
}
Step2 : Customize the code in /moodle/lib/coursecatlib.php file and add the belowcode in place.
Codesnippet :
$enrolledCourses= array();
global$USER;
$admins= get_admins(); $isadmin = false;
foreach($admins as $admin) {
if($USER->id == $admin->id) {
$isadmin= true; break; } }
if(!$isadmin&& !empty($courses)){
foreach($courses as $course) {
if(!$isadmin && isloggedin()) { // Show all
$context= context_course::instance($course);
$enrolled = is_enrolled($context,$USER->id, ”, true);
if($enrolled)
$enrolledCourses[]= $course;
}
}
$cnt= count($enrolledCourses);
}
return$cnt;