Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

Class for providing quiz settings, to make setting up quiz form manageable. To make sure there are no inconsistencies between data sets, run tests in tests/phpunit/settings_provider_test.php.

Author: Luca Bösch <luca.boesch@bfh.ch>
Author: Andrew Madden <andrewmadden@catalyst-au.net>
Author: Dmitrii Metelkin <dmitriim@catalyst-au.net>
Copyright: 2019 Catalyst IT
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1118 lines (43 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: settings_provider  - X-Ref

Helper class for providing quiz settings, to make setting up quiz form manageable.

insert_element(\mod_quiz_mod_form $quizform,\MoodleQuickForm $mform, \HTML_QuickForm_element $element, $before = 'security')   X-Ref
Insert form element.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.
param: \HTML_QuickForm_element $element Element to insert.
param: string $before Insert element before.

remove_element(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform, string $elementname)   X-Ref
Remove element from the form.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.
param: string $elementname Element name.

add_help_button(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform, string $elementname)   X-Ref
Add help button to the element.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.
param: string $elementname Element name.

set_default(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform, string $elementname, $value)   X-Ref
Set default value for the element.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.
param: string $elementname Element name.
param: mixed $value Default value.

set_type(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform, string $elementname, string $type)   X-Ref
Set element type.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.
param: string $elementname Element name.
param: string $type Type of the form element.

freeze_element(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform, string $elementname)   X-Ref
Freeze form element.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.
param: string $elementname Element name.

add_seb_header_element(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform)   X-Ref
Add SEB header element to  the form.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.

add_seb_usage_options(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform)   X-Ref
Add SEB usage element with all available options.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.

add_seb_templates(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform)   X-Ref
Add Templates element.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.

add_seb_config_file(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform)   X-Ref
Add upload config file element.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.

add_seb_show_download_link(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform)   X-Ref
Add Show Safe Exam Browser download button.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.

add_seb_allowedbrowserexamkeys(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform)   X-Ref
Add Allowed Browser Exam Keys setting.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.

add_seb_config_elements(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform)   X-Ref
Add SEB config elements.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.

add_seb_settings_fields(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform)   X-Ref
Add setting fields.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.

hide_seb_elements(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform)   X-Ref
Hide SEB elements if required.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.

lock_seb_elements(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform)   X-Ref
Lock SEB elements if required.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.

get_uploaded_seb_file_download_link(\mod_quiz_mod_form $quizform, \MoodleQuickForm $mform)   X-Ref
Return uploaded SEB config file link.

param: \mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: \MoodleQuickForm $mform the wrapped MoodleQuickForm.
return: string

get_seb_config_elements()   X-Ref
Get the type of element for each of the form elements in quiz settings.

Contains all setting elements. Array key is name of 'form element'/'database column (excluding prefix)'.

return: array All quiz form elements to be added and their types.

get_seb_config_element_types()   X-Ref
Get the types of the quiz settings elements.

return: array List of types for the setting elements.

is_conflicting_permissions(\context $context)   X-Ref
Check that we have conflicting permissions.

In Some point we can have settings save by the person who use specific
type of SEB usage (e.g. use templates). But then another person who can't
use template (but still can update other settings) edit the same quiz. This is
conflict of permissions and we'd like to build the settings form having this in
mind.

param: \context $context Context used with capability checking.
return: bool

get_requiresafeexambrowser_options(\context $context)   X-Ref
Returns a list of all options of SEB usage.

param: \context $context Context used with capability checking selection options.
return: array

get_template_options()   X-Ref
Returns a list of templates.

return: array

get_filemanager_options()   X-Ref
Returns a list of options for the file manager element.

return: array

get_seb_config_element_defaults()   X-Ref
Get the default values of the quiz settings.

Array key is name of 'form element'/'database column (excluding prefix)'.

return: array List of settings and their defaults.

validate_draftarea_configfile($itemid)   X-Ref
Validate that if a file has been uploaded by current user, that it is a valid PLIST XML file.
This function is only called if requiresafeexambrowser == settings_provider::USE_SEB_UPLOAD_CONFIG.

param: string $itemid Item ID of file in user draft file area.
return: void|lang_string

get_current_user_draft_file(string $itemid)   X-Ref
Try and get a file in the user draft filearea by itemid.

param: string $itemid Item ID of the file.
return: stored_file|null Returns null if no file is found.

get_module_context_sebconfig_file(string $cmid)   X-Ref
Get the file that is stored in the course module file area.

param: string $cmid The course module id which is used as an itemid reference.
return: stored_file|null Returns null if no file is found.

save_filemanager_sebconfigfile_draftarea(string $draftitemid, string $cmid)   X-Ref
Saves filemanager_sebconfigfile files to the moodle storage backend.

param: string $draftitemid The id of the draft area to use.
param: string $cmid The cmid of for the quiz.
return: bool Always true

delete_uploaded_config_file(string $cmid)   X-Ref
Cleanup function to delete the saved config when it has not been specified.
This will be called when settings_provider::USE_SEB_UPLOAD_CONFIG is not true.

param: string $cmid The cmid of for the quiz.
return: bool Always true or exception if error occurred

can_configure_seb(\context $context)   X-Ref
Check if the current user can configure SEB.

param: \context $context Context to check access in.
return: bool

can_use_seb_template(\context $context)   X-Ref
Check if the current user can use preconfigured templates.

param: \context $context Context to check access in.
return: bool

can_upload_seb_file(\context $context)   X-Ref
Check if the current user can upload own SEB config file.

param: \context $context Context to check access in.
return: bool

can_change_seb_showsebdownloadlink(\context $context)   X-Ref
Check if the current user can change Show Safe Exam Browser download button setting.

param: \context $context Context to check access in.
return: bool

can_change_seb_allowedbrowserexamkeys(\context $context)   X-Ref
Check if the current user can change Allowed Browser Exam Keys setting.

param: \context $context Context to check access in.
return: bool

can_configure_manually(\context $context)   X-Ref
Check if the current user can config SEB manually.

param: \context $context Context to check access in.
return: bool

can_manage_seb_config_setting(string $settingname, \context $context)   X-Ref
Check if the current user can manage provided SEB setting.

param: string $settingname Name of the setting.
param: \context $context Context to check access in.
return: bool

build_config_capabilities_to_check(string $settingname, array $settings)   X-Ref
Helper method to build a list of capabilities to check.

param: string $settingname Given setting name to build caps for.
param: array $settings A list of settings to go through.
return: array

get_seb_settings_map()   X-Ref
Helper method to return a map of all settings.

return: array

get_allowed_settings(int $requiresafeexambrowser)   X-Ref
Get allowed settings for provided SEB usage type.

param: int $requiresafeexambrowser SEB usage type.
return: array

build_allowed_settings(array $settings)   X-Ref
Recursive method to build a list of allowed settings.

param: array $settings A list of settings from settings map.
return: array

get_quiz_hideifs()   X-Ref
Get the conditions that an element should be hid in the form. Expects matching using 'eq'.

Array key is name of 'form element'/'database column (excluding prefix)'.
Values are instances of hideif_rule class.

return: array List of rules per element.

build_setting_capability_name(string $settingname)   X-Ref
Build a capability name for the provided SEB setting.

param: string $settingname Name of the setting.
return: string

is_seb_settings_locked($quizid)   X-Ref
Check if settings is locked.

param: int $quizid Quiz ID.
return: bool

filter_by_prefix(\stdClass $settings)   X-Ref
Filter a standard class by prefix.

param: stdClass $settings Quiz settings object.
return: stdClass Filtered object.

filter_by_settings_map(stdClass $settings)   X-Ref
Filter settings based on the setting map. Set value of not allowed settings to null.

param: stdClass $settings Quiz settings.
return: \stdClass

filter_plugin_settings(stdClass $settings)   X-Ref
Filter quiz settings for this plugin only.

param: stdClass $settings Quiz settings.
return: stdClass Filtered settings.

strip_all_prefixes(\stdClass $settings)   X-Ref
Strip the seb_ prefix from each setting key.

param: \stdClass $settings Object containing settings.
return: \stdClass The modified settings object.

add_prefix(string $name)   X-Ref
Add prefix to string.

param: string $name String to add prefix to.
return: string String with prefix.