【问题标题】:Get course contents using webservice使用网络服务获取课程内容
【发布时间】:2017-01-03 10:47:52
【问题描述】:

我正在使用 Moodle 3.1+。我正在尝试使用网络服务获取课程内容。我创建了一个带有活动“课程”的课程。现在,当我尝试使用网络服务“core_course_get_contents”获取课程内容时,我收到以下响应。

[{"id":36,"name":" 0","visible":1,"summary":"","summaryformat":1,"modules":[{"id":18,"url":"http:\/\/localhost\/moodle\/mod\/lesson\/view.php?id=18","name":"Lesson1","instance":1,"visible":1,"modicon":"http:\/\/localhost\/moodle\/theme\/image.php\/mentornetz\/lesson\/1483338014\/icon","modname":"lesson","modplural":"Lessons","indent":0}]}]

但响应中不包含课程详细信息。

Moodle API 文档说响应包含以下我的响应中缺少的详细信息。

contents list of ( 
object {
type string   //a file or a folder or external link
filename string   //filename
filepath string   //filepath
filesize int   //filesize
fileurl string  Optional //downloadable file url
content string  Optional //Raw content, will be used when type is content
timecreated int   //Time created
timemodified int   //Time modified
sortorder int   //Content sort order
userid int   //User who added this content to moodle
author string   //Content owner
license string   //Content license
} 

以下是 webservice core_course_get_course_module 的响应

object {
cm object {
id int   //The course module id
course int   //The course id
module int   //The module type id
name string   //The activity name
modname string   //The module component name (forum, assign, etc..)
instance int   //The activity instance id
section int   //The module section id
sectionnum int   //The module section number
groupmode int   //Group mode
groupingid int   //Grouping id
completion int   //If completion is enabled
idnumber string  Optional //Module id number
added int  Optional //Time added
score int  Optional //Score
indent int  Optional //Indentation
visible int  Optional //If visible
visibleold int  Optional //Visible old
completiongradeitemnumber int  Optional //Completion grade item
completionview int  Optional //Completion view setting
completionexpected int  Optional //Completion time expected
showdescription int  Optional //If the description is showed
availability string  Optional //Availability settings
} 
warnings  Optional //list of warnings
list of ( 
  //warning
object {
item string  Optional //item
itemid int  Optional //item id
warningcode string   //the warning code can be used by the client app to implement specific behaviour
message string   //untranslated english message to explain the warning
} 
)} 

如何获取课程内容?请帮忙。

【问题讨论】:

  • 好吧,他们的 API 文档说明了如何做到这一点?
  • @arkascha 没有足够的可用文档。
  • 文档说core_course_get_contents 提供课程模块,包括它们的 URL。然后,您可能必须随后致电core_course_get_course_module 以获取有关该课程中特定模块的更多详细信息。我认为这在docs.moodle.org/dev/Web_service_API_functions 的文档中非常明显
  • @arkascha 我已经更新了这个问题。 core_course_get_course_module 将提供模块详细信息而不是模块的内容。
  • 那次调用做了什么响应?

标签: php moodle moodle-api


【解决方案1】:

并非所有模块都支持导出其内容。根据快速 grep,我发现它主要限于 resources:book、page、file、url、...

如果您将 URL 资源添加到课程中,则 Web 服务应返回其内容。

【讨论】:

  • 如果您希望按课程获取资源内容mod_page_get_pages_by_courses 函数可能会有所帮助。 Moodle 网络服务文档没有很好的文档记录,所以这个信息很难找到,花了我一段时间,我想如果有人也在寻找,我会发布。
【解决方案2】:

如果我理解正确,您说的是从 课程 类型的资源中获取内容。 mod_lesson_get_page_data 函数在这里可能会有所帮助。它会在您的一堂课中返回有关页面的大量信息。来自 Moodle 文档(经过改编以突出更重要的信息):

返回给定页面的信息,包括其内容。

参数

  • lessonid(必填)- 课程实例 ID
  • pageid(必填)- 页面 ID
  • returncontents(默认为“”) - 如果我们必须在渲染后返回完整的页面内容

注意returncontents 应该是int。可能是1,但没有记录。

响应

object {
page  Optional //Page fields
object {
id int   //The id of this lesson page
lessonid int   //The id of the lesson this page belongs to
prevpageid int   //The id of the page before this one
nextpageid int   //The id of the next page in the page sequence
qtype int   //Identifies the page type of this page
qoption int   //Used to record page type specific options
layout int   //Used to record page specific layout selections
display int   //Used to record page specific display selections
timecreated int   //Timestamp for when the page was created
timemodified int   //Timestamp for when the page was last modified
title string  Optional //The title of this page
contents string  Optional //The contents of this page
contentsformat int  Optional //contents format (1 = HTML, 0 = MOODLE, 2 = PLAIN or 4 = MARKDOWN)
displayinmenublock int   //Toggles display in the left menu block
type int   //The type of the page [question | structure]
typeid int   //The unique identifier for the page type
typestring string   //The string that describes this page type
} 
newpageid int   //New page id (if a jump was made)
pagecontent string  Optional //Page html content
ongoingscore string   //The ongoing score message
progress int   //Progress percentage in the lesson
contentfiles   //List of files.
list of ( 
  //File.
object {
filename string  Optional //File name.
filepath string  Optional //File path.
filesize int  Optional //File size.
fileurl string  Optional //Downloadable file url.
timemodified int  Optional //Time modified.
mimetype string  Optional //File mime type.
isexternalfile int  Optional //Whether is an external file.
repositorytype string  Optional //The repository type for external files.
} 
)answers list of ( 
  //The page answers
object {
id int   //The ID of this answer in the database
answerfiles   //List of files.
list of ( 
  //File.
object {
filename string  Optional //File name.
filepath string  Optional //File path.
filesize int  Optional //File size.
fileurl string  Optional //Downloadable file url.
timemodified int  Optional //Time modified.
mimetype string  Optional //File mime type.
isexternalfile int  Optional //Whether is an external file.
repositorytype string  Optional //The repository type for external files.
} 
)responsefiles   //List of files.
list of ( 
  //File.
object {
filename string  Optional //File name.
filepath string  Optional //File path.
filesize int  Optional //File size.
fileurl string  Optional //Downloadable file url.
timemodified int  Optional //Time modified.
mimetype string  Optional //File mime type.
isexternalfile int  Optional //Whether is an external file.
repositorytype string  Optional //The repository type for external files.
} 
)jumpto int  Optional //Identifies where the user goes upon completing a page with this answer
grade int  Optional //The grade this answer is worth
score int  Optional //The score this answer will give
flags int  Optional //Used to store options for the answer
timecreated int  Optional //A timestamp of when the answer was created
timemodified int  Optional //A timestamp of when the answer was modified
answer string  Optional //Possible answer text
answerformat int  Optional //answer format (1 = HTML, 0 = MOODLE, 2 = PLAIN or 4 = MARKDOWN)
response string  Optional //Response text for the answer
responseformat int  Optional //response format (1 = HTML, 0 = MOODLE, 2 = PLAIN or 4 = MARKDOWN)
} 
)messages list of ( 
  //The lesson generated messages
object {
message string   //Message.
type string   //Message type: usually a CSS identifier like:
                                success, info, warning, error, notifyproblem, notifyerror, notifytiny, notifysuccess
} 
)displaymenu int   //Whether we should display the menu or not in this page.
warnings  Optional //list of warnings
list of ( 
  //warning
object {
item string  Optional //item
itemid int  Optional //item id
warningcode string   //the warning code can be used by the client app to implement specific behaviour
message string   //untranslated english message to explain the warning
} 
)} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2017-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多