Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Static Public Member Functions | Public Attributes | Static Protected Member Functions | List of all members
core\hub\api Class Reference

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...
 

Detailed Description

Provides methods to communicate with the hub (sites directory) web services.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ add_screenshot()

static core\hub\api::add_screenshot (   $hubcourseid,
stored_file  $file,
  $screenshotnumber 
)
static

Uploads a screenshot for the published course.

Deprecated:
since Moodle 3.8. Moodle.net has been sunsetted making this function useless.
Parameters
int$hubcourseidid of the published course on the hub, it must be published from this site
stored_file$file
int$screenshotnumberordinal number of the screenshot

◆ call()

static core\hub\api::call (   $function,
array  $data = [],
  $allowpublic = false 
)
staticprotected

Calls a remote function exposed via web services on the hub.

Parameters
string$functionname of WS function
array$dataparameters of WS function
bool$allowpublicallow request without registration on the hub
Return values
mixeddepends on the function
Exceptions
moodle_exception

◆ call_rest()

static core\hub\api::call_rest (   $token,
  $function,
array  $data 
)
staticprotected

Performs a REST request to the hub site (using the GET method).

Parameters
string$token
string$function
array$data
Return values
mixed
Exceptions
moodle_exception

◆ download_course_backup()

static core\hub\api::download_course_backup (   $hubcourseid,
  $path 
)
static

Downloads course backup.

Deprecated:
since Moodle 3.8. Moodle.net has been sunsetted making this function useless.
Parameters
int$hubcourseidid of the course on the hub
string$pathlocal path (in tempdir) to save the downloaded backup to.

◆ get_courses()

static core\hub\api::get_courses (   $search,
  $downloadable,
  $enrollable,
  $options 
)
static

Calls WS function hub_get_courses.

Deprecated:
since Moodle 3.8. Moodle.net has been sunsetted making this function useless.

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

Parameters
string$searchsearch string
bool$downloadablereturn downloadable courses
bool$enrollablereturn enrollable courses
array | stdClass$optionsother options from the list of allowed options: 'ids', 'sitecourseids', 'coverage', 'licenceshortname', 'subject', 'audience', 'educationallevel', 'language', 'orderby', 'givememore', 'allsitecourses'
Return values
arrayof two elements: [$courses, $coursetotal]
Exceptions
coding_exception
moodle_exception

◆ get_hub_info()

static core\hub\api::get_hub_info ( )
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" }

Return values
array
Exceptions
moodle_exception

◆ process_curl_exception()

static core\hub\api::process_curl_exception (   $token,
  $curloutput 
)
staticprotected

Analyses exception received from the hub server.

Parameters
string$tokentoken used for CURL request
array$curloutputoutput from CURL request
Exceptions
moodle_exception

◆ register_course()

static core\hub\api::register_course (   $courseinfo)
static

Publish one course.

Deprecated:
since Moodle 3.8. Moodle.net has been sunsetted making this function useless.

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) ]

Parameters
array | stdClass$courseinfo
Return values
intid of the published course on the hub
Exceptions
moodle_exceptionif the communication with the hub failed or the course could not be published

◆ unregister_courses()

static core\hub\api::unregister_courses (   $courseids)
static

Unpublish courses.

Deprecated:
since Moodle 3.8. Moodle.net has been sunsetted making this function useless.
Parameters
int[] | int$courseids
Exceptions
moodle_exception

◆ unregister_site()

static core\hub\api::unregister_site ( )
static

Unregister the site.

Exceptions
moodle_exception

◆ update_registration()

static core\hub\api::update_registration ( array  $siteinfo)
static

Update site registration on the hub.

Parameters
array$siteinfo
Exceptions
moodle_exception

◆ upload_course_backup()

static core\hub\api::upload_course_backup (   $hubcourseid,
stored_file  $backupfile 
)
static

Uploads a course backup.

Deprecated:
since Moodle 3.8. Moodle.net has been sunsetted making this function useless.
Parameters
int$hubcourseidid of the published course on the hub, it must be published from this site
stored_file$backupfile

The documentation for this class was generated from the following file: