【问题标题】:How to get course image from Moodle API如何从 Moodle API 获取课程图片
【发布时间】:2020-05-15 12:09:22
【问题描述】:

我正在通过 API 从我的 Moodle 网站中提取课程列表,但响应中没有图像 URL 或图像名称。有没有办法得到它?

也许我使用的特定端点是错误的,但我找不到另一个列出所有课程的端点(对于未登录的用户,所以所有可用的课程)

https://example.com/webservice/rest/server.php?wstoken=12312312312123&wsfunction=core_course_get_courses&moodlewsrestformat=json

示例响应:

{
"id": 1,
"shortname": "A course title",
"categoryid": 3,
"categorysortorder": 10001,
"fullname": "A full course name ",
"displayname": "Some course",
"idnumber": "",
"summary": "",
"summaryformat": 1,
"format": "topics",
"showgrades": 1,
"newsitems": 5,
"startdate": 1588716000,
"enddate": 0,
"numsections": 7,
"maxbytes": 0,
"showreports": 0,
"visible": 1,
"hiddensections": 0,
"groupmode": 0,
"groupmodeforce": 0,
"defaultgroupingid": 0,
"timecreated": 1588703577,
"timemodified": 1589199433,
"enablecompletion": 1,
"completionnotify": 0,
"lang": "",
"forcetheme": "",
"courseformatoptions": [
{
"name": "hiddensections",
"value": 0
},
{
"name": "coursedisplay",
"value": 0
}
]
},

【问题讨论】:

    标签: moodle moodle-api moodle-mobile


    【解决方案1】:

    在您的网络服务网址上使用此

    core_course_get_courses_by_field 具有特定课程 ID 或 ID 列表的函数。

    改为core_course_get_courses

    【讨论】:

      【解决方案2】:

      只看/course/externallib.php中的代码

      看起来服务core_course_search_courses 为每门课程返回一个名为overviewfiles 的字段 - 其中包含应该是图片链接的fileurl

      我自己没试过。

      【讨论】:

      • 谢谢你,我会看看并在适当的时候回复。
      • 当我尝试得到一个错误:invalid_parameter_exception。我认为它可能希望我将一些数据传递给这个,但我不想传递任何东西,我实际上只是想获取所有课程的列表,供前端用户在网站上查看。他们不必登录。
      • 除了url需要添加{&token=yourtoken}
      【解决方案3】:

      这是最简单的方法:

      $course = get_course($courseid);
      \core_course\external\course_summary_exporter::get_course_image($course);
      

      course_summary_exporter 函数需要一个描述课程的普通对象(基本上是课程表中的一行作为对象)并返回图像的 URL,如果没有设置图像,则返回 false

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-11
        • 1970-01-01
        相关资源
        最近更新 更多