Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

Class registration

Copyright: 2017 Marina Glancy
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 598 lines (24 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: registration  - X-Ref

Methods to use when registering the site at the moodle sites directory.

get_registration($confirmed = true)   X-Ref
Get site registration

param: bool $confirmed
return: stdClass|null

require_registration()   X-Ref
Same as get_registration except it throws exception if site not registered

return: stdClass

is_registered()   X-Ref
Checks if site is registered

return: bool

get_token($strictness = IGNORE_MISSING)   X-Ref
Returns registration token

param: int $strictness if set to MUST_EXIST and site is not registered will throw an exception
return: null

get_last_updated()   X-Ref
When was the registration last updated

return: int|null timestamp or null if site is not registered

get_site_info($defaults = [])   X-Ref
Calculates and prepares site information to send to the sites directory as a part of registration.

param: array $defaults default values for inputs in the registration form (if site was never registered before)
return: array site info

get_stats_summary($siteinfo)   X-Ref
Human-readable summary of data that will be sent to the sites directory.

param: array $siteinfo result of get_site_info()
return: string

save_site_info($formdata)   X-Ref
Save registration info locally so it can be retrieved when registration needs to be updated

param: stdClass $formdata data from {@link site_registration_form}

update_manual()   X-Ref
Updates site registration when "Update reigstration" button is clicked by admin


update_cron()   X-Ref
Updates site registration via cron


confirm_registration($token, $newtoken, $hubname)   X-Ref
Confirms registration by the sites directory.

param: string $token
param: string $newtoken
param: string $hubname

site_privacy_options()   X-Ref
Retrieve the options for site privacy form element to use in registration form

return: array

register($returnurl)   X-Ref
Registers a site

This method will make sure that unconfirmed registration record is created and then redirect to
registration script on the sites directory.
The sites directory will check that the site is accessible, register it and redirect back
to /admin/registration/confirmregistration.php

param: string $returnurl

unregister($unpublishalladvertisedcourses, $unpublishalluploadedcourses)   X-Ref
Unregister site

param: bool $unpublishalladvertisedcourses
param: bool $unpublishalluploadedcourses
return: bool

reset_token()   X-Ref
Resets the registration token without changing site identifier so site can be re-registered

return: bool

reset_site_identifier($token)   X-Ref
Generate a new token for the site that is not registered

param: string $token

get_moodlenet_info()   X-Ref
Returns information about the sites directory.

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: array|null

show_after_install($markasviewed = null)   X-Ref
Does admin need to be redirected to the registration page after install?

param: bool|null $markasviewed if set to true will mark the registration form as viewed and admin will not be redirected
return: bool

get_new_registration_fields()   X-Ref
Returns the list of the fields in the registration form that were added since registration or last manual update

If this list is not empty the scheduled task will be paused and admin will be reminded to update registration manually.

return: array

registration_reminder($url)   X-Ref
Redirect to the site registration form if it's a new install or registration needs updating

param: string|moodle_url $url