General developer forum

View all courses without categories

Picture of Sandip Shrestha
Re: View all courses without categories

After you have created a new course helper and set the display option by doing

$chelper = new coursecat_helper();



    'recursive' => true,

    'limit' => $CFG->frontpagecourselimit,

    'sort' => array('sortorder' => 0),

    'viewmoreurl' => new moodle_url('/course/index.php'),

    'viewmoretext' => new lang_string('fulllistofcourses'),


you will need to fetch all courses by doing

$courses = coursecat::get(0)->get_courses($chelper->get_courses_display_options());
it returns an indexed array of objects (key is courseid and value is course object). Then you can sort it using something like
Average of ratings: -