Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Provides methods to communicate with the hub (sites directory) web services. More...
Static Public Member Functions | |
static | add_screenshot ($hubcourseid, stored_file $file, $screenshotnumber) |
Uploads a screenshot for the published course. More... | |
static | download_course_backup ($hubcourseid, $path) |
Downloads course backup. More... | |
static | get_courses ($search, $downloadable, $enrollable, $options) |
Calls WS function hub_get_courses. More... | |
static | get_hub_info () |
Returns information about the hub. More... | |
static | register_course ($courseinfo) |
Publish one course. More... | |
static | unregister_courses ($courseids) |
Unpublish courses. More... | |
static | unregister_site () |
Unregister the site. More... | |
static | update_registration (array $siteinfo) |
Update site registration on the hub. More... | |
static | upload_course_backup ($hubcourseid, stored_file $backupfile) |
Uploads a course backup. More... | |
Public Attributes | |
File const | HUB_BACKUP_FILE_TYPE = 'backup' |
type: Backup | |
File const | HUB_HUBSCREENSHOT_FILE_TYPE = 'hubscreenshot' |
type: Hub screenshot | |
File const | HUB_SCREENSHOT_FILE_TYPE = 'screenshot' |
type: Course screenshot | |
Static Protected Member Functions | |
static | call ($function, array $data=[], $allowpublic=false) |
Calls a remote function exposed via web services on the hub. More... | |
static | call_rest ($token, $function, array $data) |
Performs a REST request to the hub site (using the GET method). More... | |
static | process_curl_exception ($token, $curloutput) |
Analyses exception received from the hub server. More... | |
Provides methods to communicate with the hub (sites directory) web services.
|
static |
Uploads a screenshot for the published course.
int | $hubcourseid | id of the published course on the hub, it must be published from this site |
stored_file | $file | |
int | $screenshotnumber | ordinal number of the screenshot |
|
staticprotected |
Calls a remote function exposed via web services on the hub.
string | $function | name of WS function |
array | $data | parameters of WS function |
bool | $allowpublic | allow request without registration on the hub |
mixed | depends on the function |
moodle_exception |
|
staticprotected |
Performs a REST request to the hub site (using the GET method).
string | $token | |
string | $function | |
array | $data |
mixed |
moodle_exception |
|
static |
Downloads course backup.
int | $hubcourseid | id of the course on the hub |
string | $path | local path (in tempdir) to save the downloaded backup to. |
|
static |
Calls WS function hub_get_courses.
Parameter $options may have any of these fields: [ 'ids' => new external_multiple_structure(new external_value(PARAM_INTEGER, 'id of a course in the hub course directory'), 'ids of course', VALUE_OPTIONAL), 'sitecourseids' => new external_multiple_structure(new external_value(PARAM_INTEGER, 'id of a course in the site'), 'ids of course in the site', VALUE_OPTIONAL), 'coverage' => new external_value(PARAM_TEXT, 'coverage', VALUE_OPTIONAL), 'licenceshortname' => new external_value(PARAM_ALPHANUMEXT, 'licence short name', VALUE_OPTIONAL), 'subject' => new external_value(PARAM_ALPHANUM, 'subject', VALUE_OPTIONAL), 'audience' => new external_value(PARAM_ALPHA, 'audience', VALUE_OPTIONAL), 'educationallevel' => new external_value(PARAM_ALPHA, 'educational level', VALUE_OPTIONAL), 'language' => new external_value(PARAM_ALPHANUMEXT, 'language', VALUE_OPTIONAL), 'orderby' => new external_value(PARAM_ALPHA, 'orderby method: newest, eldest, publisher, fullname, ratingaverage', VALUE_OPTIONAL), 'givememore' => new external_value(PARAM_INT, 'next range of result - range size being set by the hub server ', VALUE_OPTIONAL), 'allsitecourses' => new external_value(PARAM_INTEGER, 'if 1 return all not visible and visible courses whose siteid is the site matching token. Only courses of this site are returned. givememore parameter is ignored if this param = 1. In case of public token access, this param option is ignored', VALUE_DEFAULT, 0), ]
Each course in the returned array of courses will have fields: [ 'id' => new external_value(PARAM_INTEGER, 'id'), 'fullname' => new external_value(PARAM_TEXT, 'course name'), 'shortname' => new external_value(PARAM_TEXT, 'course short name'), 'description' => new external_value(PARAM_TEXT, 'course description'), 'language' => new external_value(PARAM_ALPHANUMEXT, 'course language'), 'publishername' => new external_value(PARAM_TEXT, 'publisher name'), 'publisheremail' => new external_value(PARAM_EMAIL, 'publisher email', VALUE_OPTIONAL), 'privacy' => new external_value(PARAM_INT, 'privacy: published or not', VALUE_OPTIONAL), 'sitecourseid' => new external_value(PARAM_INT, 'course id on the site', VALUE_OPTIONAL), 'contributornames' => new external_value(PARAM_TEXT, 'contributor names', VALUE_OPTIONAL), 'coverage' => new external_value(PARAM_TEXT, 'coverage', VALUE_OPTIONAL), 'creatorname' => new external_value(PARAM_TEXT, 'creator name'), 'licenceshortname' => new external_value(PARAM_ALPHANUMEXT, 'licence short name'), 'subject' => new external_value(PARAM_ALPHANUM, 'subject'), 'audience' => new external_value(PARAM_ALPHA, 'audience'), 'educationallevel' => new external_value(PARAM_ALPHA, 'educational level'), 'creatornotes' => new external_value(PARAM_RAW, 'creator notes'), 'creatornotesformat' => new external_value(PARAM_INTEGER, 'notes format'), 'demourl' => new external_value(PARAM_URL, 'demo URL', VALUE_OPTIONAL), 'courseurl' => new external_value(PARAM_URL, 'course URL', VALUE_OPTIONAL), 'backupsize' => new external_value(PARAM_INT, 'course backup size in bytes', VALUE_OPTIONAL), 'enrollable' => new external_value(PARAM_BOOL, 'is the course enrollable'), 'screenshots' => new external_value(PARAM_INT, 'total number of screenshots'), 'timemodified' => new external_value(PARAM_INT, 'time of last modification - timestamp'), 'contents' => new external_multiple_structure(new external_single_structure( array( 'moduletype' => new external_value(PARAM_ALPHA, 'the type of module (activity/block)'), 'modulename' => new external_value(PARAM_TEXT, 'the name of the module (forum, resource etc)'), 'contentcount' => new external_value(PARAM_INT, 'how many time the module is used in the course'), )), 'contents', VALUE_OPTIONAL), 'rating' => new external_single_structure ( array( 'aggregate' => new external_value(PARAM_FLOAT, 'Rating average', VALUE_OPTIONAL), 'scaleid' => new external_value(PARAM_INT, 'Rating scale'), 'count' => new external_value(PARAM_INT, 'Rating count'), ), 'rating', VALUE_OPTIONAL), 'comments' => new external_multiple_structure(new external_single_structure ( array( 'comment' => new external_value(PARAM_TEXT, 'the comment'), 'commentator' => new external_value(PARAM_TEXT, 'the name of commentator'), 'date' => new external_value(PARAM_INT, 'date of the comment'), )), 'contents', VALUE_OPTIONAL), 'outcomes' => new external_multiple_structure(new external_single_structure( array( 'fullname' => new external_value(PARAM_TEXT, 'the outcome fullname') )), 'outcomes', VALUE_OPTIONAL) ]
Additional fields for each course: 'screenshotbaseurl' (moodle_url) URL of the first screenshot, only set if $course['screenshots']>0 'commenturl' (moodle_url) URL for comments
string | $search | search string |
bool | $downloadable | return downloadable courses |
bool | $enrollable | return enrollable courses |
array | stdClass | $options | other options from the list of allowed options: 'ids', 'sitecourseids', 'coverage', 'licenceshortname', 'subject', 'audience', 'educationallevel', 'language', 'orderby', 'givememore', 'allsitecourses' |
array | of two elements: [$courses, $coursetotal] |
coding_exception | |
moodle_exception |
|
static |
Returns information about the hub.
Example of the return array: { "courses": 384, "description": "Official Moodle sites directory.", "downloadablecourses": 0, "enrollablecourses": 0, "hublogo": 1, "language": "en", "name": "moodle", "sites": 274175, "url": "https://stats.moodle.org", "imgurl": "https://stats.moodle.org/local/hub/webservice/download.php?filetype=hubscreenshot" }
array |
moodle_exception |
|
staticprotected |
Analyses exception received from the hub server.
string | $token | token used for CURL request |
array | $curloutput | output from CURL request |
moodle_exception |
|
static |
Publish one course.
Expected contents of $courseinfo: [ 'sitecourseid' => new external_value(PARAM_INT, 'the id of the course on the publishing site'), 'fullname' => new external_value(PARAM_TEXT, 'course name'), 'shortname' => new external_value(PARAM_TEXT, 'course short name'), 'description' => new external_value(PARAM_TEXT, 'course description'), 'language' => new external_value(PARAM_ALPHANUMEXT, 'course language'), 'publishername' => new external_value(PARAM_TEXT, 'publisher name'), 'publisheremail' => new external_value(PARAM_EMAIL, 'publisher email'), 'contributornames' => new external_value(PARAM_TEXT, 'contributor names'), 'coverage' => new external_value(PARAM_TEXT, 'coverage'), 'creatorname' => new external_value(PARAM_TEXT, 'creator name'), 'licenceshortname' => new external_value(PARAM_ALPHANUMEXT, 'licence short name'), 'subject' => new external_value(PARAM_ALPHANUM, 'subject'), 'audience' => new external_value(PARAM_ALPHA, 'audience'), 'educationallevel' => new external_value(PARAM_ALPHA, 'educational level'), 'creatornotes' => new external_value(PARAM_RAW, 'creator notes'), 'creatornotesformat' => new external_value(PARAM_INTEGER, 'notes format'), 'demourl' => new external_value(PARAM_URL, 'demo URL', VALUE_OPTIONAL), 'courseurl' => new external_value(PARAM_URL, 'course URL', VALUE_OPTIONAL), 'enrollable' => new external_value(PARAM_BOOL, 'is the course enrollable', VALUE_DEFAULT, 0), 'screenshots' => new external_value(PARAM_INT, 'the number of screenhots', VALUE_OPTIONAL), 'deletescreenshots' => new external_value(PARAM_INT, 'ask to delete all the existing screenshot files (it does not reset the screenshot number)', VALUE_DEFAULT, 0), 'contents' => new external_multiple_structure(new external_single_structure( array( 'moduletype' => new external_value(PARAM_ALPHA, 'the type of module (activity/block)'), 'modulename' => new external_value(PARAM_TEXT, 'the name of the module (forum, resource etc)'), 'contentcount' => new external_value(PARAM_INT, 'how many time the module is used in the course'), )), 'contents', VALUE_OPTIONAL), 'outcomes' => new external_multiple_structure(new external_single_structure( array( 'fullname' => new external_value(PARAM_TEXT, 'the outcome fullname') )), 'outcomes', VALUE_OPTIONAL) ]
array | stdClass | $courseinfo |
int | id of the published course on the hub |
moodle_exception | if the communication with the hub failed or the course could not be published |
|
static |
Unpublish courses.
int[] | int | $courseids |
moodle_exception |
|
static |
Unregister the site.
moodle_exception |
|
static |
|
static |
Uploads a course backup.
int | $hubcourseid | id of the published course on the hub, it must be published from this site |
stored_file | $backupfile |