|
| can_manage () |
| Checks to see if the user has permission to manage the preset.
|
|
| delete () |
| Deletes all files related to a saved preset.
|
|
| export () |
| Export this preset.
|
|
| get_fields (bool $forpreview=false) |
| Return the field instances of the preset.
|
|
| get_fullname () |
| Return the preset fullname.
|
|
| get_path () |
| Returns the preset path.
|
|
| get_sample_entries (int $count=1) |
| Return sample entries to preview this preset.
|
|
| get_template_content (string $templatename) |
| Return the template content from the preset.
|
|
| get_userid () |
| Return the preset author.
|
|
| save () |
| Save this preset.
|
|
|
string | $description |
| The preset description.
|
|
bool | $isplugin |
| whether the preset is a plugin or has been saved by the user.
|
|
string | $name |
| The preset name.
|
|
string | $shortname |
| The preset shortname.
|
|
stored_file | $storedfile |
| For saved presets that's the file object for the root folder.
|
|
|
| __construct (?manager $manager, bool $isplugin, string $name, string $shortname, ?string $description='', ?stored_file $storedfile=null) |
| Class constructor.
|
|
| generate_preset_xml () |
| Helper method to generate the XML for this preset.
|
|
| load_preset_xml () |
| Load all the information from the preset.xml.
|
|
|
static | get_attribute_value (string $filepath, string $name) |
| Helper to get the value of one of the elements in the presets.xml file.
|
|
static | get_content_from_file (string $filepath, string $filename) |
| Helper method to retrieve the contents of a file.
|
|
static | get_filerecord (string $filename, string $filepath, int $userid) |
| Helper method to get a file record given a filename, a filepath and a userid, for any of the preset files.
|
|
|
stdClass null | $xmlinfo = null |
| the preset.xml parsed information.
|
|
◆ __construct()
mod_data\preset::__construct |
( |
?manager | $manager, |
|
|
bool | $isplugin, |
|
|
string | $name, |
|
|
string | $shortname, |
|
|
?string | $description = '', |
|
|
?stored_file | $storedfile = null ) |
|
protected |
Class constructor.
- Parameters
-
manager | null | $manager | the current instance manager |
bool | $isplugin | whether the preset is a plugin or has been saved by the user |
string | $name | the preset name |
string | $shortname | the preset shortname |
string | null | $description | the preset description |
stored_file | null | $storedfile | for saved presets, that's the file for the root folder |
- Exceptions
-
◆ can_manage()
mod_data\preset::can_manage |
( |
| ) |
|
Checks to see if the user has permission to manage the preset.
- Return values
-
bool | Returns true if the user can manage this preset, false otherwise. |
◆ create_from_fullname()
static mod_data\preset::create_from_fullname |
( |
manager | $manager, |
|
|
string | $fullname ) |
|
static |
Create a preset instance from the preset fullname.
The preset fullname is a concatenation of userid and pluginname|presetname used by most preset pages. Plugins uses userid zero while preset instances has the owner as identifier.
This method will throw an exception if the preset instance has a different userid thant the one from the $fullname. However, it won't check the current user capabilities.
- Parameters
-
manager | $manager | the current instance manager |
string | $fullname | the preset full name |
- Return values
-
◆ create_from_instance()
static mod_data\preset::create_from_instance |
( |
manager | $manager, |
|
|
string | $presetname, |
|
|
?string | $description = '' ) |
|
static |
Create a preset instance from a data_record entry, a preset name and a description.
- Parameters
-
manager | $manager | the current instance manager |
string | $presetname | the preset name |
string | null | $description | the preset description |
- Return values
-
◆ create_from_plugin()
static mod_data\preset::create_from_plugin |
( |
?manager | $manager, |
|
|
string | $pluginname ) |
|
static |
Create a preset instance from a plugin.
- Parameters
-
manager | null | $manager | the current instance manager |
string | $pluginname | the datapreset plugin name |
- Return values
-
preset|null | The plugin preset or null if there is no datapreset plugin with the given name. |
◆ create_from_storedfile()
Create a preset instance from a stored file.
- Parameters
-
manager | $manager | the current instance manager |
stored_file | $file | the preset root folder |
- Return values
-
preset|null | If the given file doesn't belong to the expected component/filearea/context, null will be returned |
◆ delete()
mod_data\preset::delete |
( |
| ) |
|
Deletes all files related to a saved preset.
- Return values
-
bool | True if the preset is a saved preset and the file exists in the file system; false otherwise. |
◆ export()
mod_data\preset::export |
( |
| ) |
|
Export this preset.
- Return values
-
string | the full path to the exported preset file. |
◆ generate_preset_xml()
mod_data\preset::generate_preset_xml |
( |
| ) |
|
|
protected |
Helper method to generate the XML for this preset.
- Return values
-
string | The XML for the preset |
◆ get_attribute_value()
static mod_data\preset::get_attribute_value |
( |
string | $filepath, |
|
|
string | $name ) |
|
staticprotected |
Helper to get the value of one of the elements in the presets.xml file.
- Parameters
-
string | $filepath | The preset filepath. |
string | $name | Attribute name to return. |
- Return values
-
string|null | The attribute value; null if the it doesn't exist or the file is not a valid XML. |
◆ get_content_from_file()
static mod_data\preset::get_content_from_file |
( |
string | $filepath, |
|
|
string | $filename ) |
|
staticprotected |
Helper method to retrieve the contents of a file.
- Parameters
-
string | $filepath | the directory to look in |
string | $filename | the name of the file we want |
- Return values
-
string|null | the contents of the file or null if the file doesn't exist. |
◆ get_description_from_plugin()
static mod_data\preset::get_description_from_plugin |
( |
string | $pluginname | ) |
|
|
static |
Returns the description to show for a datapreset plugin.
- Parameters
-
string | $pluginname | The datapreset plugin name. |
- Return values
-
string | The plugin preset description to display. |
◆ get_fields()
mod_data\preset::get_fields |
( |
bool | $forpreview = false | ) |
|
Return the field instances of the preset.
- Parameters
-
bool | $forpreview | if the fields are only for preview |
- Return values
-
data_field_base[] | and array with field objects |
◆ get_file()
static mod_data\preset::get_file |
( |
string | $filepath, |
|
|
string | $filename ) |
|
static |
Helper method to retrieve a file.
- Parameters
-
string | $filepath | the directory to look in |
string | $filename | the name of the file we want |
- Return values
-
stored_file|null | the file or null if the file doesn't exist. |
◆ get_filerecord()
static mod_data\preset::get_filerecord |
( |
string | $filename, |
|
|
string | $filepath, |
|
|
int | $userid ) |
|
staticprotected |
Helper method to get a file record given a filename, a filepath and a userid, for any of the preset files.
- Parameters
-
string | $filename | The filename for the filerecord that will be returned. |
string | $filepath | The filepath for the filerecord that will be returned. |
int | $userid | The userid for the filerecord that will be returned. |
- Return values
-
stdClass | A filerecord object with the datapreset context, component and filearea and the given information. |
◆ get_fullname()
mod_data\preset::get_fullname |
( |
| ) |
|
Return the preset fullname.
Preset fullname is used mostly for urls.
- Return values
-
string | the preset fullname |
◆ get_name_from_plugin()
static mod_data\preset::get_name_from_plugin |
( |
string | $pluginname | ) |
|
|
static |
Returns the best name to show for a datapreset plugin.
- Parameters
-
string | $pluginname | The datapreset plugin name. |
- Return values
-
string | The plugin preset name to display. |
◆ get_path()
mod_data\preset::get_path |
( |
| ) |
|
Returns the preset path.
- Return values
-
string|null | the preset path is null for plugins and /presetname/ for saved presets. |
◆ get_sample_entries()
mod_data\preset::get_sample_entries |
( |
int | $count = 1 | ) |
|
Return sample entries to preview this preset.
- Parameters
-
int | $count | the number of entries to generate. |
- Return values
-
◆ get_template_content()
mod_data\preset::get_template_content |
( |
string | $templatename | ) |
|
Return the template content from the preset.
- Parameters
-
string | $templatename | the template name |
- Return values
-
string | the template content |
◆ get_userid()
mod_data\preset::get_userid |
( |
| ) |
|
Return the preset author.
Preset plugins do not have any user id.
- Return values
-
int|null | the userid or null if it is a plugin |
◆ is_directory_a_preset()
static mod_data\preset::is_directory_a_preset |
( |
string | $directory | ) |
|
|
static |
Checks if a directory contains all the required files to define a preset.
- Parameters
-
string | $directory | The patch to check if it contains the preset files or not. |
- Return values
-
bool | True if the directory contains all the preset files; false otherwise. |
◆ save()
mod_data\preset::save |
( |
| ) |
|
Save this preset.
- Return values
-
bool | true if the preset has been saved; false otherwise. |
◆ $shortname
string mod_data\preset::$shortname |
The preset shortname.
For datapreset plugins that is the folder; for saved presets, that's the preset name.
◆ $storedfile
For saved presets that's the file object for the root folder.
It's null for plugins or for presets that haven't been saved yet.
The documentation for this class was generated from the following file:
- mod/data/classes/preset.php