Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
core_adminpresets\manager Class Reference

Public Member Functions

 apply_preset (int $presetid, bool $simulate=false)
 Apply a given preset.
 
 delete_preset (int $presetid)
 Delete given preset.
 
 download_preset (int $presetid)
 Create the XML content for a given preset.
 
 export_preset (stdClass $data)
 Create a preset with the current settings and plugins information.
 
 get_setting ($settingdata, $currentvalue)
 Returns the class type object.
 
 get_settings (array $dbsettings, bool $sitedbvalues=false, array $settings=[], $children=false)
 Constructs an array with all the system settings.
 
 get_settings_from_db (array $dbsettings)
 Gets the standarized settings array from DB records.
 
 get_site_settings ()
 Gets the system settings.
 
 import_preset (string $xmlcontent, ?string $presetname=null)
 Import a given XML preset.
 
 revert_preset (int $presetappid)
 Revert a given preset applied previously.
 

Static Public Member Functions

static get_settings_class (string $classname)
 Returns the settings class mapped to the defined $classname or null if it doesn't exist any associated class.
 

Public Attributes

int const FULL_PRESET = 2
 Full preset.
 
int const NONCORE_PRESET = 0
 Non-core preset.
 
int const STARTER_PRESET = 1
 Starter preset.
 

Protected Member Functions

 apply_plugins (int $presetid, bool $simulate=false, ?int $adminpresetapplyid=null)
 Apply plugins from a preset.
 
 apply_settings (int $presetid, bool $simulate=false, ?int $adminpresetapplyid=null)
 Apply settings from a preset.
 

Static Protected Attributes

static array $dbxmlrelations
 Relation between database fields and XML files.
 
static array $settingclassesmap
 Setting classes mapping, to associated the local/setting class that should be used when there is no specific class.
 

Member Function Documentation

◆ apply_plugins()

core_adminpresets\manager::apply_plugins ( int $presetid,
bool $simulate = false,
?int $adminpresetapplyid = null )
protected

Apply plugins from a preset.

Parameters
int$presetidThe preset identifier to apply.
bool$simulateWhether this is a simulation or not.
int | null$adminpresetapplyidThe identifier of the adminpresetapply or null if it hasn't been created previously.
Return values
arrayList with an array with the applied settings, another with the skipped ones and the adminpresetapplyid.

◆ apply_preset()

core_adminpresets\manager::apply_preset ( int $presetid,
bool $simulate = false )

Apply a given preset.

Parameters
int$presetidThe preset identifier to apply.
bool$simulateWhether this is a simulation or not.
Return values
arrayList with an array with the applied settings and another with the skipped ones.

◆ apply_settings()

core_adminpresets\manager::apply_settings ( int $presetid,
bool $simulate = false,
?int $adminpresetapplyid = null )
protected

Apply settings from a preset.

Parameters
int$presetidThe preset identifier to apply.
bool$simulateWhether this is a simulation or not.
int | null$adminpresetapplyidThe identifier of the adminpresetapply or null if it hasn't been created previously.
Return values
arrayList with an array with the applied settings, another with the skipped ones and the adminpresetapplyid.

◆ delete_preset()

core_adminpresets\manager::delete_preset ( int $presetid)

Delete given preset.

Parameters
int$presetidPreset identifier to delete.
Return values
void

◆ download_preset()

core_adminpresets\manager::download_preset ( int $presetid)

Create the XML content for a given preset.

Parameters
int$presetidThe preset to download.
Return values
arrayList with the XML content (string) and a filename proposal based on the preset name (string).

◆ export_preset()

core_adminpresets\manager::export_preset ( stdClass $data)

Create a preset with the current settings and plugins information.

Parameters
stdClass$dataPreset info, such as name or description, to be used when creating the preset with the current settings and plugins.
Return values
arrayList with an the presetid created (int), a boolean to define if any setting has been found and another boolean to specify if any plugin has been found.

◆ get_setting()

core_adminpresets\manager::get_setting ( $settingdata,
$currentvalue )

Returns the class type object.

Parameters
object$settingdataSetting data
mixed$currentvalue
Return values
mixed

◆ get_settings()

core_adminpresets\manager::get_settings ( array $dbsettings,
bool $sitedbvalues = false,
array $settings = [],
$children = false )

Constructs an array with all the system settings.

If a setting value can't be found on the DB it considers the default value as the setting value

Settings without plugin are marked as 'none' in the plugin field

Returns an standarized settings array format.

Parameters
array$dbsettingsStandarized array, format $array['plugin']['name'] = obj('name'=>'settingname', 'value'=>'settingvalue')
boolean$sitedbvaluesIndicates if $dbsettings comes from the site db or not
array$settingsArray format $array['plugin']['settingname'] = settings_types child class
array | false$childrenArray of admin_category children or false
Return values
core_adminpresets\local\setting\adminpresets_setting[][]Array format $array['plugin']['settingname'] = adminpresets_setting child class

◆ get_settings_class()

static core_adminpresets\manager::get_settings_class ( string $classname)
static

Returns the settings class mapped to the defined $classname or null if it doesn't exist any associated class.

Parameters
string$classnameThe classname to get the mapped class.
Return values
string|null

◆ get_settings_from_db()

core_adminpresets\manager::get_settings_from_db ( array $dbsettings)

Gets the standarized settings array from DB records.

Parameters
array$dbsettingsArray of objects
Return values
arrayStandarized array, format $array['plugin']['name'] = obj('name'=>'settingname', 'value'=>'settingvalue')

◆ get_site_settings()

core_adminpresets\manager::get_site_settings ( )

Gets the system settings.

Loads the DB $CFG->prefix.'config' values and the $CFG->prefix.'config_plugins' values and redirects the flow through $this->get_settings()

Return values
array\$settingsArray format $array['plugin']['settingname'] = settings_types child class

◆ import_preset()

core_adminpresets\manager::import_preset ( string $xmlcontent,
?string $presetname = null )

Import a given XML preset.

Parameters
string$xmlcontentThe XML context with the preset to be imported.
string | null$presetnameThe preset name that will overwrite the one given in the XML file.
Return values
arrayList with an the XML element (SimpleXMLElement|null), the imported preset (stdClass|null), a boolean to define if any setting has been found and another boolean to specify if any plugin has been found.

◆ revert_preset()

core_adminpresets\manager::revert_preset ( int $presetappid)

Revert a given preset applied previously.

It backs settings and plugins to their original state before applying the presset and removes the applied preset information from DB.

Parameters
int$presetappidThe appplied preset identifier to be reverted.
Return values
arrayList with the presetapp removed (or null if there was some error), an array with the rollback settings/plugins changed and an array with the failures.

Member Data Documentation

◆ $dbxmlrelations

array core_adminpresets\manager::$dbxmlrelations
staticprotected
Initial value:
= [
'name' => 'NAME',
'comments' => 'COMMENTS',
'timecreated' => 'PRESET_DATE',
'site' => 'SITE_URL',
'author' => 'AUTHOR',
'moodleversion' => 'MOODLE_VERSION',
'moodlerelease' => 'MOODLE_RELEASE'
]

Relation between database fields and XML files.


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