Front Page Categories

Front Page Categories

by Wesley Eccles -
Number of replies: 1

Hi all,

I'm trying to display, on the front page, when logged in only the Courses AND Categories the user is enrolled in.

I've tried selecting in the front page setting the "List of Categories" from the drop down menu but it displays all courses, not just the courses the user is enrolled in.

In a nut shell, im looking for a way for a user to log in and see a list of Categories first (Only the categories they are enrolled in) and then when the click on a Category the only see the courses they are enrolled in.


Is this possible?


Thanks in advance.

Average of ratings: -
In reply to Wesley Eccles

Re: Front Page Categories

by Sooraj Singh -

Hi Wesley Eccles,

Yes you can do this by using this patch:

$coursecontext=context_course::instance($course->id);
if(!is_enrolled($coursecontext,$USER->id,'',true))
{
continue;
}

just put this patch in course/renderer.php

in this below Function (this way as i highlighted the patch) 

protected function coursecat_courses(coursecat_helper $chelper, $courses, $totalcount = null) {
        global $CFG;
        if ($totalcount === null) {
            $totalcount = count($courses);
        }
        if (!$totalcount) {
            // Courses count is cached during courses retrieval.
            return '';
        }

        if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO) {
            // In 'auto' course display mode we analyse if number of courses is more or less than $CFG->courseswithsummarieslimit
            if ($totalcount <= $CFG->courseswithsummarieslimit) {
                $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED);
            } else {
                $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED);
            }
        }

        // prepare content of paging bar if it is needed
        $paginationurl = $chelper->get_courses_display_option('paginationurl');
        $paginationallowall = $chelper->get_courses_display_option('paginationallowall');
        if ($totalcount > count($courses)) {
            // there are more results that can fit on one page
            if ($paginationurl) {
                // the option paginationurl was specified, display pagingbar
                $perpage = $chelper->get_courses_display_option('limit', $CFG->coursesperpage);
                $page = $chelper->get_courses_display_option('offset') / $perpage;
                $pagingbar = $this->paging_bar($totalcount, $page, $perpage,
                        $paginationurl->out(false, array('perpage' => $perpage)));
                if ($paginationallowall) {
                    $pagingbar .= html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => 'all')),
                            get_string('showall', '', $totalcount)), array('class' => 'paging paging-showall'));
                }
            } else if ($viewmoreurl = $chelper->get_courses_display_option('viewmoreurl')) {
                // the option for 'View more' link was specified, display more link
                $viewmoretext = $chelper->get_courses_display_option('viewmoretext', new lang_string('viewmore'));
                $morelink = html_writer::tag('div', html_writer::link($viewmoreurl, $viewmoretext),
                        array('class' => 'paging paging-morelink'));
            }
        } else if (($totalcount > $CFG->coursesperpage) && $paginationurl && $paginationallowall) {
            // there are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode
            $pagingbar = html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => $CFG->coursesperpage)),
                get_string('showperpage', '', $CFG->coursesperpage)), array('class' => 'paging paging-showperpage'));
        }

        // display list of courses
        $attributes = $chelper->get_and_erase_attributes('courses');
        $content = html_writer::start_tag('div', $attributes);

        if (!empty($pagingbar)) {
            $content .= $pagingbar;
        }

        $coursecount = 0;
        foreach ($courses as $course) {
$coursecontext=context_course::instance($course->id); if(!is_enrolled($coursecontext,$USER->id,'',true)) { continue; }
$coursecount ++; $classes = ($coursecount%2) ? 'odd' : 'even'; if ($coursecount == 1) { $classes .= ' first'; } if ($coursecount >= count($courses)) { $classes .= ' last'; } $content .= $this->coursecat_coursebox($chelper, $course, $classes); } if (!empty($pagingbar)) { $content .= $pagingbar; } if (!empty($morelink)) { $content .= $morelink; } $content .= html_writer::end_tag('div'); // .courses return $content; }

Regards:

Sooraj Singh