Moodle API Folders - C0D3D3V/Moodle-DL GitHub Wiki

To download folders the following function is of interest:

Area Name Introduced in Description
mod_folder mod_folder_get_folders_by_courses 3.3 (2017051500) Returns a list of folders in a provided list of courses, if no list is provided all folders that the user can view will be returned. Please note that this WS is not returning the folder contents.

Fodlers are part of the course content.

An example module which returns core_course_get_contents:

{
    "id": 65,
    "url": "http://archlinux-vm/moodle/mod/folder/view.php?id=65",
    "name": "rogl",
    "instance": 1,
    "contextid": 130,
    "visible": 1,
    "uservisible": true,
    "visibleoncoursepage": 1,
    "modicon": "http://archlinux-vm/moodle/theme/image.php/boost/folder/1633802793/icon",
    "modname": "folder",
    "modplural": "Verzeichnisse",
    "indent": 0,
    "onclick": "",
    "afterlink": null,
    "customdata": "\"\"",
    "noviewlink": false,
    "completion": 1,
    "completiondata": {
        "state": 0,
        "timecompleted": 0,
        "overrideby": null,
        "valueused": false
    },
    "contents": [
        {
            "type": "file",
            "filename": "animes.md",
            "filepath": "/",
            "filesize": 211,
            "fileurl": "http://archlinux-vm/moodle/webservice/pluginfile.php/130/mod_folder/content/2/animes.md?forcedownload=1",
            "timecreated": 1637168388,
            "timemodified": 1637168441,
            "sortorder": 0,
            "mimetype": "text/plain",
            "isexternalfile": false,
            "userid": 3,
            "author": "c0d3 d3v",
            "license": "unknown"
        },
        {
            "type": "file",
            "filename": "linux_server",
            "filepath": "/",
            "filesize": 730980,
            "fileurl": "http://archlinux-vm/moodle/webservice/pluginfile.php/130/mod_folder/content/2/linux_server?forcedownload=1",
            "timecreated": 1637168439,
            "timemodified": 1637168441,
            "sortorder": 0,
            "mimetype": "document/unknown",
            "isexternalfile": false,
            "userid": 3,
            "author": "c0d3 d3v",
            "license": "unknown"
        }
    ],
    "contentsinfo": {
        "filescount": 2,
        "filessize": 731191,
        "lastmodified": 1637168441,
        "mimetypes": [
            "text/plain",
            "document/unknown"
        ],
        "repositorytype": ""
    }
}

As you can see in contents are all files in the folder linked.

To get also the description of folders we use mod_folder_get_folders_by_courses.

Load a list of all folders

mod_folder_get_folders_by_courses

Parameter
Funktion
Returns

With the help of mod_folder_get_folders_by_courses all descriptions of all folders can be loaded. It exists since Version 3.3.

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

mod_folder_get_folders_by_courses returns a list of pages:

{
    "folders": [
        {
            "id": 1,
            "coursemodule": 65,
            "course": 3,
            "name": "rogl",
            "intro": "<p dir=\"ltr\" style=\"text-align: left;\">sdfsdfsfdsfdvvvvv<a href=\"http://archlinux-vm/moodle/webservice/pluginfile.php/130/mod_folder/intro/2021-06-29_11-06.png\" title=\"\" style=\"\">http://archlinux-vm/moodle/webservice/pluginfile.php/130/mod_folder/intro/2021-06-29_11-06.png</a></p><p dir=\"ltr\" style=\"text-align: left;\"><div class=\"mediaplugin mediaplugin_videojs d-block\"><div style=\"max-width:400px;\"><video data-setup-lazy=\"{&quot;language&quot;: &quot;de&quot;, &quot;fluid&quot;: true}\" id=\"id_videojs_61965f384dfde_1\" class=\"video-js\" preload=\"auto\" controls=\"true\" title=\"playlist.m3u8\"><source src=\"http://archlinux-vm/moodle/webservice/pluginfile.php/130/mod_folder/intro/playlist.m3u8\" type=\"application/x-mpegURL\" /><a class=\"mediafallbacklink\" href=\"http://archlinux-vm/moodle/webservice/pluginfile.php/130/mod_folder/intro/playlist.m3u8\">playlist.m3u8</a></video></div></div></p><p dir=\"ltr\" style=\"text-align: left;\"><div class=\"vsc-controller\"></div>&nbsp;<div class=\"mediaplugin mediaplugin_videojs d-block\"><div style=\"max-width:400px;\"><video controls=\"true\" data-setup-lazy=\"{&quot;techOrder&quot;: [&quot;youtube&quot;], &quot;sources&quot;: [{&quot;type&quot;: &quot;video/youtube&quot;, &quot;src&quot;:&quot;https://www.youtube.com/watch?v=xqNpWq4nA20&quot;}], &quot;language&quot;: &quot;de&quot;, &quot;fluid&quot;: true}\" id=\"id_videojs_61965f384e0fa_2\" class=\"video-js\" title=\"watch\"><a href=\"https://www.youtube.com/watch?v=xqNpWq4nA20\" class=\"_blanktarget\">https://www.youtube.com/watch?v=xqNpWq4nA20</a></video></div></div>&nbsp;<br></p><p dir=\"ltr\" style=\"text-align: left;\"><div class=\"mediaplugin mediaplugin_videojs d-block\"><div style=\"max-width:400px;\"><video data-setup-lazy=\"{&quot;techOrder&quot;: [&quot;youtube&quot;], &quot;sources&quot;: [{&quot;type&quot;: &quot;video/youtube&quot;, &quot;src&quot;:&quot;https://www.youtube.com/watch?v=xqNpWq4nA20&quot;}], &quot;language&quot;: &quot;de&quot;, &quot;fluid&quot;: true}\" id=\"id_videojs_61965f384e273_3\" class=\"video-js\" preload=\"auto\" controls=\"true\" title=\"watch\"><a class=\"mediafallbacklink\" href=\"https://www.youtube.com/watch?v=xqNpWq4nA20\">watch</a></video></div></div><br></p>",
            "introformat": 1,
            "introfiles": [
                {
                    "filename": "2021-06-29_11-06.png",
                    "filepath": "/",
                    "filesize": 152064,
                    "fileurl": "http://archlinux-vm/moodle/webservice/pluginfile.php/130/mod_folder/intro/2021-06-29_11-06.png",
                    "timemodified": 1637168441,
                    "mimetype": "image/png",
                    "isexternalfile": false
                },
                {
                    "filename": "playlist.m3u8",
                    "filepath": "/",
                    "filesize": 250,
                    "fileurl": "http://archlinux-vm/moodle/webservice/pluginfile.php/130/mod_folder/intro/playlist.m3u8",
                    "timemodified": 1637168441,
                    "mimetype": "application/x-mpegURL",
                    "isexternalfile": false
                }
            ],
            "revision": 2,
            "timemodified": 1637168525,
            "display": 0,
            "showexpanded": 1,
            "showdownloadfolder": 1,
            "forcedownload": 1,
            "section": 4,
            "visible": 1,
            "groupmode": 0,
            "groupingid": 0
        }
    ],
    "warnings": []
}

Important attributes:

  • course is the id of the course the folder belongs to.
  • id is the id of the folder
  • coursemodule is the module id that was returned by core_course_get_contents
  • name is the name of the folder
⚠️ **GitHub.com Fallback** ⚠️