Получить содержание курса с помощью веб-сервиса

Я использую 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
} 

Ниже приведен ответ для веб-сервиса 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
} 
)} 

Как я могу получить содержание курса? Пожалуйста помоги.


person Akhilesh    schedule 03.01.2017    source источник
comment
Ну, что говорит их документация по API, как это сделать?   -  person arkascha    schedule 03.01.2017
comment
@arkascha Недостаточно документации.   -  person Akhilesh    schedule 03.01.2017
comment
В документации сказано, что core_course_get_contents доставляет модули курсов, включая их URL. Затем, вероятно, вам придется сделать последующий вызов core_course_get_course_module, чтобы получить более подробную информацию о конкретном модуле в этом курсе. Думаю, это очевидно из документации по адресу docs.moodle.org/dev/Web_service_API_functions.   -  person arkascha    schedule 03.01.2017
comment
@arkascha Я обновил вопрос. core_course_get_course_module предоставит сведения о модуле, а не его содержимое.   -  person Akhilesh    schedule 03.01.2017
comment
И какой ответ дает этот звонок?   -  person arkascha    schedule 03.01.2017
comment
@arkascha обновил вопрос с ответом   -  person Akhilesh    schedule 03.01.2017


Ответы (2)


Не все модули поддерживают экспорт своего содержимого. Согласно быстрому grep, я обнаружил, что он в основном ограничен ресурсами: книгой, страницей, файлом, URL-адресом, ...

Если вы добавите ресурс URL в свой курс, веб-сервис должен вернуть его содержимое.

person FMCorz    schedule 03.01.2017
comment
Если вы хотите получить содержимое ресурса для каждого курса, может оказаться полезной функция mod_page_get_pages_by_courses. Документы веб-сервиса Moodle плохо документированы, поэтому эту информацию трудно найти, и мне потребовалось некоторое время, я подумал, что опубликую, если кто-то тоже ее ищет. - person martin-martin; 16.09.2020

Если я правильно понимаю, вы говорите о получении контента из ресурсов типа урок. Здесь может помочь функция mod_lesson_get_page_data. Он возвращает много информации о странице одного из ваших уроков. Из документов Moodle (адаптировано, чтобы выделить более важную информацию):

Возвращает информацию о данной странице, включая ее содержимое.

Аргументы

  • lessonid (обязательно) - идентификатор экземпляра урока
  • pageid (обязательно) - идентификатор страницы
  • 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
} 
)} 
person martin-martin    schedule 16.09.2020