Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all courses on moodle?

Tags:

moodle

I need to show all moodle courses in menu listing. Can anyone suggest me that how can I get all courses using php code or moodle inbuilt functions.

Thanks

like image 494
rahul saini Avatar asked Aug 12 '13 05:08

rahul saini


People also ask

How do I show all courses in Moodle?

The block title shows as "My courses" and allows one-click access to a course's home page. There is a also the option to list All courses... available within the Moodle site. This will display a list of course types and a click on one of the types will reveal all the courses in that category.

Why are my courses not showing up on Moodle?

There are several reasons why your course might not be showing in Moodle. Your instructor has not set the course to 'Visible' yet. All courses are hidden by default.

How do I access old Moodle courses?

To access an archived course, click on the link within the Kiosk. To view all courses, click "Show all X courses" where X is the number of hidden courses. Any gray links indicate courses that are hidden from student view.


1 Answers

Assuming you are writing code to be run within Moodle, you can use the get_courses() function defined within lib/datalib.php. For example:

<?php
require_once(PATH_TO_MOODLE_ROOT . '/config.php');
$courses = get_courses();
print_r($courses);

will print out a data-dump of the returned array, showing details of all the courses in your Moodle site. This example is obviously not appropriate to use on a production site!

If you check the function definition in lib/datalib.php you will see the options available for restricting the result set to particular fields or controlling the sort order.

like image 188
Chris Throup Avatar answered Sep 20 '22 14:09

Chris Throup