首页 > 解决方案 > 如何从课程中的 Moodle 作业中获取所有文件?

问题描述

我想从 Moodle 的作业中获取所有文件。有没有办法获取所有文件?

当我从本地 Moodle 实例调用 core_course_get_contents时

http://localhost:8077/webservice/rest/server.php?wstoken=11e2d8b7f8e21ca1804e41e9cac5a816&wsfunction=core_course_get_contents&courseid=4&moodlewsrestformat=json

我收到的回复如下:

[
    {
        "id": 22,
        "name": "General",
        "visible": 1,
        "summary": "",
        "summaryformat": 1,
        "section": 0,
        "hiddenbynumsections": 0,
        "uservisible": true,
        "modules": []
    },
    {
        "id": 23,
        "name": "Introduction",
        "visible": 1,
        "summary": "",
        "summaryformat": 1,
        "section": 1,
        "hiddenbynumsections": 0,
        "uservisible": true,
        "modules": [
            {
                "id": 44,
                "url": "http://localhost:8077/mod/assign/view.php?id=44",
                "name": "Assignment",
                "instance": 3,
                "contextid": 99,
                "visible": 1,
                "uservisible": true,
                "visibleoncoursepage": 1,
                "modicon": "http://localhost:8077/theme/image.php/boost/assign/1613571924/icon",
                "modname": "assign",
                "modplural": "Assignments",
                "indent": 0,
                "onclick": "",
                "afterlink": null,
                "customdata": "\"\"",
                "noviewlink": false,
                "completion": 1,
                "completiondata": {
                    "state": 0,
                    "timecompleted": 0,
                    "overrideby": null,
                    "valueused": false
                }
            },
            {
                "id": 46,
                "url": "http://localhost:8077/mod/resource/view.php?id=46",
                "name": "test(.txt)",
                "instance": 24,
                "contextid": 102,
                "visible": 1,
                "uservisible": true,
                "visibleoncoursepage": 1,
                "modicon": "http://localhost:8077/theme/image.php/boost/core/1613571924/f/text-24",
                "modname": "resource",
                "modplural": "Files",
                "indent": 0,
                "onclick": "",
                "afterlink": null,
                "customdata": "\"a:1:{s:10:\\\"printintro\\\";i:1;}\"",
                "noviewlink": false,
                "completion": 1,
                "completiondata": {
                    "state": 0,
                    "timecompleted": 0,
                    "overrideby": null,
                    "valueused": false
                },
                "contents": [
                    {
                        "type": "file",
                        "filename": "test.txt",
                        "filepath": "/",
                        "filesize": 935,
                        "fileurl": "http://localhost:8077/webservice/pluginfile.php/102/mod_resource/content/1/test.txt?forcedownload=1",
                        "timecreated": 1621949734,
                        "timemodified": 1621949744,
                        "sortorder": 1,
                        "mimetype": "text/plain",
                        "isexternalfile": false,
                        "userid": 2,
                        "author": "ABC",
                        "license": "unknown"
                    }
                ],
                "contentsinfo": {
                    "filescount": 1,
                    "filessize": 935,
                    "lastmodified": 1621949744,
                    "mimetypes": [
                        "text/plain"
                    ],
                    "repositorytype": ""
                }
            }
        ]
    }
]

我想从作业中获取文件。有没有办法做到这一点?

标签: moodlemoodle-api

解决方案


推荐阅读