Moodle API Lessons - C0D3D3V/Moodle-DL GitHub Wiki

To download lessons the following functions are of interest:

Area Name Introduced in Description
mod_lesson mod_lesson_get_lessons_by_courses 3.3 (2017051500) Returns a list of lessons in a provided list of courses, if no list is provided all lessons that the user can view will be returned.
mod_lesson mod_lesson_get_pages 3.3 (2017051500) Return the list of pages in a lesson (based on the user permissions).
mod_lesson mod_lesson_get_page_data 3.3 (2017051500) Return information of a given page, including its contents.
mod_lesson mod_lesson_get_user_attempt 3.3 (2017051500) Return information about the given user attempt (including answers).

Lessons are part of the course content.

An example module which returns core_course_get_contents:

{
    "id": 60,
    "url": "http://archlinux-vm/moodle/mod/lesson/view.php?id=60",
    "name": "Nice Lesson",
    "instance": 1,
    "contextid": 115,
    "visible": 1,
    "uservisible": true,
    "visibleoncoursepage": 1,
    "modicon": "http://archlinux-vm/moodle/theme/image.php/boost/lesson/1633802793/icon",
    "modname": "lesson",
    "modplural": "Lektionen",
    "indent": 0,
    "onclick": "",
    "afterlink": null,
    "customdata": "\"\"",
    "noviewlink": false,
    "completion": 1,
    "completiondata": {
        "state": 0,
        "timecompleted": 0,
        "overrideby": null,
        "valueused": false
    }
}

The module indicates where the lesson is located in the course, nothing more can be derived from it.

Load a list of all lessons

mod_lesson_get_lessons_by_courses

Parameter
Funktion
Returns

With the help of mod_lesson_get_lessons_by_courses all lessons-id's of all courses can be loaded. It exists since Version 3.3.

  • courseids is an array of the course-ids from which the forums are to be loaded.

mod_lesson_get_lessons_by_courses returns a list of lessons:

{
    "lessons": [
        {
            "id": 1,
            "course": 3,
            "coursemodule": 60,
            "name": "Nice Lesson",
            "intro": "<p dir=\"ltr\" style=\"text-align: left;\">Nice Lesson<br></p>",
            "introformat": 1,
            "practice": false,
            "modattempts": true,
            "usepassword": false,
            "grade": 100,
            "custom": true,
            "ongoing": false,
            "usemaxgrade": 0,
            "maxanswers": 5,
            "maxattempts": 1,
            "review": false,
            "nextpagedefault": 0,
            "feedback": false,
            "minquestions": 0,
            "maxpages": 2,
            "timelimit": 0,
            "retake": false,
            "mediafile": "",
            "mediaheight": 480,
            "mediawidth": 640,
            "mediaclose": 0,
            "slideshow": false,
            "width": 640,
            "height": 480,
            "bgcolor": "#FFFFFF",
            "displayleft": false,
            "displayleftif": 0,
            "progressbar": true,
            "allowofflineattempts": false,
            "introfiles": [],
            "mediafiles": []
        }
    ],
    "warnings": []
}

Important attributes:

  • course is the id of the course the lesson belongs to.
  • id is the id of the lesson
  • coursemodule is the module id that was returned by core_course_get_contents
  • name is the name of the lesson

Load a list of all pages of a lesson

mod_lesson_get_pages

Parameter
Funktion
Returns
Structure

To get the data of all pages in a lesson there are two functions. mod_lesson_get_page_data is used to get the date of a single page (this is normally used by the app if you run the lesson) and mod_lesson_get_user_attempt is used to get al json with all pages, but they are in little fragments that need to be combined in a table format like the web app does it.

mod_lesson_get_page_data

Parameter
Funktion
Returns

Important returncontents needs to be 1, to get the whole html content. Interestingly, this function often still returns the page data even though mod_lesson_get_pages already disallows access to the lesson.

mod_lesson_get_user_attempt

Parameter
Funktion
Returns

Interestingly, this function often still returns the page data even though mod_lesson_get_page_data already disallows access to the lesson. So this would be the best option to download the lessons, because it provides the longest time the data and provides all the data at once, but the data must be prepared nicely.

To finally download all pages as a single html file you need to merge all pages into one HTML file and add a stylesheed (https://your.moodle/theme/styles.php/boost/-1/all)

⚠️ **GitHub.com Fallback** ⚠️