diff --git a/docs/apis/core/activitycompletion/index.md b/docs/apis/core/activitycompletion/index.md index eb48c69b7..f491c29b3 100644 --- a/docs/apis/core/activitycompletion/index.md +++ b/docs/apis/core/activitycompletion/index.md @@ -26,7 +26,8 @@ To support the completion system, your activity must include a `[activityname]_s * @param string $feature * @return null|bool */ -function forum_supports(string $feature): bool { +function forum_supports(string $feature): bool +{ switch($feature) { case FEATURE_COMPLETION_TRACKS_VIEWS: return true; @@ -154,7 +155,8 @@ You will need to add information about the custom rules into the activities `cm_ * @return cached_cm_info An object on information that the courses * will know about (most noticeably, an icon). */ -function forum_get_coursemodule_info($coursemodule) { +function forum_get_coursemodule_info($coursemodule) +{ global $DB; $dbparams = ['id' => $coursemodule->instance]; @@ -224,7 +226,8 @@ First, the function that adds these controls: * @category completion * @return array List of added element names, or names of wrapping group elements. */ -public function add_completion_rules() { +public function add_completion_rules() +{ $mform = $this->_form; @@ -264,7 +267,8 @@ public function add_completion_rules() { return [$this->get_suffixed_name('completionpostsgroup')]; } -protected function get_suffixed_name(string $fieldname): string { +protected function get_suffixed_name(string $fieldname): string +{ return $fieldname . $this->get_suffix(); } ``` @@ -284,7 +288,8 @@ Next, a function for checking whether the user selected this option: * @param array $data Input data not yet validated. * @return bool True if one or more rules is enabled, false if none are. */ -public function completion_rule_enabled($data) { +public function completion_rule_enabled($data) +{ return (!empty($data[$this->get_suffixed_name('completionpostsenabled')]) && $data[$this->get_suffixed_name('completionposts')] != 0); } @@ -295,7 +300,8 @@ public function completion_rule_enabled($data) { That's all the 'required' functions, but we need to add some extra code to support the checkbox behaviour. I overrode `get_data` so that if there is a value in the edit field, but the checkbox is not ticked, the value counts as zero (the rule will not be enabled). ```php -function get_data() { +function get_data() +{ $data = parent::get_data(); if (!$data) { return $data; @@ -316,7 +322,8 @@ You may have noticed the `completionunlocked` check. When some users have alread Finally, forum already had a `data_preprocessing` function but I added code to this to set up the checkboxes when the form is displayed, and to make the default value of the text fields 1 instead of 0: ```php -function data_preprocessing(&$default_values){ +function data_preprocessing(&$default_values) +{ // [Existing code, not shown] // Set up the completion checkboxes which aren't part of standard data. @@ -360,7 +367,8 @@ Here's the function for forum (simplified to include only the one completion opt * @param bool $type Type of comparison (or/and; can be used as return value if no conditions) * @return bool True if completed, false if not, $type if conditions not set. */ - function forum_get_completion_state($course, $cm, $userid, $type) { + function forum_get_completion_state($course, $cm, $userid, $type) + { global $CFG,$DB; // Get forum details @@ -402,7 +410,8 @@ You need to return an array of strings for each completion rule that is active. * @param cm_info|stdClass $cm object with fields ->completion and ->customdata['customcompletionrules'] * @return array $descriptions the array of descriptions for the custom rules. */ -function mod_forum_get_completion_active_rule_descriptions($cm) { +function mod_forum_get_completion_active_rule_descriptions($cm) +{ // Values will be present in cm_info, and we assume these are up to date. if (empty($cm->customdata['customcompletionrules']) || $cm->completion != COMPLETION_TRACKING_AUTOMATIC) { return []; diff --git a/docs/apis/core/calendar/index.md b/docs/apis/core/calendar/index.md index 03ca98f0f..11d7f9903 100644 --- a/docs/apis/core/calendar/index.md +++ b/docs/apis/core/calendar/index.md @@ -103,7 +103,8 @@ where '$prioritiesforeventtype1' is an associative array that has the timestamp * @param int $lessonid The lesson ID. * @return array|null Array of group override priorities for open and close times. Null if there are no group overrides. */ -function lesson_get_group_override_priorities($lessonid) { +function lesson_get_group_override_priorities($lessonid) +{ global $DB; // Fetch group overrides. @@ -182,7 +183,8 @@ This callback determines if an event should be visible throughout the site. For * @param calendar_event $event * @return bool Returns true if the event is visible to the current user, false otherwise. */ -function mod_assign_core_calendar_is_event_visible(calendar_event $event) { +function mod_assign_core_calendar_is_event_visible(calendar_event $event) +{ global $CFG, $USER; require_once($CFG->dirroot . '/mod/assign/locallib.php'); @@ -259,7 +261,8 @@ Eg. * @param int $itemcount The item count associated with the action event. * @return bool */ -function mod_assign_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) { +function mod_assign_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) +{ // List of event types where the action event's item count should be shown. $eventtypesshowingitemcount = [ ASSIGN_EVENT_TYPE_GRADINGDUE @@ -320,7 +323,8 @@ This callback handles updating the activity instance based on the changed action Example: ```php -function mod_feedback_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $feedback) { +function mod_feedback_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $feedback) +{ global $CFG, $DB; if (empty($event->instance) || $event->modulename != 'feedback') { @@ -406,7 +410,8 @@ If the calendar event has no valid `timestart` values then the callback should r Example: ```php -function mod_feedback_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $instance) { +function mod_feedback_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $instance) +{ $mindate = null; $maxdate = null; diff --git a/docs/apis/core/clock/index.md b/docs/apis/core/clock/index.md index de70bd68b..5528cf4c3 100644 --- a/docs/apis/core/clock/index.md +++ b/docs/apis/core/clock/index.md @@ -46,13 +46,15 @@ The recommended approach is to have the Dependency Injector inject into the cons ```php title="Usage in injected classes" namespace mod_example; -class post { +class post +{ public function __construct( protected readonly \core\clock $clock, protected readonly \moodle_database $db, ) - public function create_thing(\stdClass $data): \stdClass { + public function create_thing(\stdClass $data): \stdClass + { $data->timecreated = $this->clock->time(); $data->id = $this->db->insert_record('example_thing', $data); @@ -99,8 +101,10 @@ The incrementing clock increases the time by one second every time it is called. A helper method, `mock_clock_with_incrementing(?int $starttime = null): \core\clock`, is provided within the standard testcase: ```php title="Obtaining the incrementing clock" -class my_test extends \advanced_testcase { - public function test_create_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_create_thing(): void + { // This class inserts data into the database. $this->resetAfterTest(true); @@ -134,8 +138,10 @@ The frozen clock uses a time which does not change, unless manually set. This ca A helper method, `mock_clock_with_frozen(?int $time = null): \core\clock`, is provided within the standard testcase: ```php title="Obtaining and using the frozen clock" -class my_test extends \advanced_testcase { - public function test_create_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_create_thing(): void + { // This class inserts data into the database. $this->resetAfterTest(true); @@ -182,27 +188,33 @@ class my_test extends \advanced_testcase { If the standard cases are not suitable for you, then you can create a custom clock and inject it into the DI container. ```php title="Creating a custom clock" -class my_clock implements \core\clock { +class my_clock implements \core\clock +{ public int $time; - public function __construct() { + public function __construct() + { $this->time = time(); } - public function now(): \DateTimeImmutable { + public function now(): \DateTimeImmutable + { $time = new \DateTimeImmutable('@' . $this->time); $this->time = $this->time += 5; return $time; } - public function time(): int { + public function time(): int + { return $this->now()->getTimestamp(); } } -class my_test extends \advanced_testcase { - public function test_my_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_my_thing(): void + { $clock = new my_clock(); \core\di:set(\core\clock::class, $clock); diff --git a/docs/apis/core/comment/index.md b/docs/apis/core/comment/index.md index adb05cbe0..6a5749381 100644 --- a/docs/apis/core/comment/index.md +++ b/docs/apis/core/comment/index.md @@ -94,7 +94,8 @@ This is an example of a possible callback for plugin `mod_myplugin`: * @param stdClass $args * @return boolean */ -function mod_myplugin_comment_display(stdClass $comments, stdClass $args): stdClass { +function mod_myplugin_comment_display(stdClass $comments, stdClass $args): stdClass +{ if ($args->commentarea != 'entry_comments') { throw new comment_exception('invalidcommentarea'); } diff --git a/docs/apis/core/customfields/index.md b/docs/apis/core/customfields/index.md index a4644919c..43acc73ad 100644 --- a/docs/apis/core/customfields/index.md +++ b/docs/apis/core/customfields/index.md @@ -105,7 +105,8 @@ The list of fields is cached in the handler and these two functions can be calle ::: ```php title="Example code for course custom fields. This function will return all the custom fields for a given courseid" -function get_course_metadata($courseid) { +function get_course_metadata($courseid) +{ $handler = \core_customfield\handler::get_handler('core_course', 'course'); // This is equivalent to the line above. //$handler = \core_course\customfield\course_handler::create(); diff --git a/docs/apis/core/deprecation/index.md b/docs/apis/core/deprecation/index.md index 8df0d5dee..2ce423a71 100644 --- a/docs/apis/core/deprecation/index.md +++ b/docs/apis/core/deprecation/index.md @@ -40,24 +40,29 @@ The attribute is a Moodle PHP Attribute and can be applied to: ```php title="Example attribute usage" // On a global function: #[\core\attribute\deprecated('random_bytes', since: '4.3')] -function random_bytes_emulate($length) { +function random_bytes_emulate($length) +{ // Replaced by random_bytes since Moodle 4.3. } // On a class: #[\core\attribute\deprecated(replacement: null, since: '4.4', reason: 'This functionality has been removed.')] -class example { +class example +{ #[\core\attribute\deprecated( replacement: '\core\example::do_something', since: '4.3', reason: 'No longer required', mdl: 'MDL-12345', )] - public function do_something(): void {} + public function do_something(): void + { + } } // On an enum case: -enum example { +enum example +{ #[\core\attribute\deprecated('example::OPTION', since: '4.4', final: true)] case OPTION; } @@ -75,7 +80,8 @@ The `\core\deprecation` class contains helper methods to inspect for use of the // A method which has been initially deprecated, and replaced by 'random_bytes'. It should show debugging. /** @deprecated since 4.3 */ #[\core\attribute\deprecated('random_bytes', since: '4.3')] -function random_bytes_emulate($length) { +function random_bytes_emulate($length) +{ \core\deprecation::emit_deprecation_if_present(__FUNCTION__); return random_bytes($length); } @@ -83,7 +89,8 @@ function random_bytes_emulate($length) { // A method which has been finally deprecated and should throw an exception. /** @deprecated since 2.7 */ #[\core\attribute\deprecated(replacement: 'Events API', since: '2.3', final: true)] -function add_to_log() { +function add_to_log() +{ \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } diff --git a/docs/apis/core/di/index.md b/docs/apis/core/di/index.md index 0529877c9..0fbcfd8bd 100644 --- a/docs/apis/core/di/index.md +++ b/docs/apis/core/di/index.md @@ -21,7 +21,8 @@ Dependencies are stored using a string id attribute, which is typically the clas When accessing dependencies within a class, it is advisable to inject them into the constructor, for example: ```php title="Fetching a instance of the \core\http_client class from within a class" -class my_thing { +class my_thing +{ public function __construct( protected readonly \core\http_client $client, ) { @@ -48,7 +49,8 @@ The use of readonly properties is also highly recommended as it ensures that dep These language features are available in all Moodle versions supporting Dependency Injection. ```php -class example_without_promotion { +class example_without_promotion +{ protected \core\http_client $client; public function __construct( @@ -58,7 +60,8 @@ class example_without_promotion { } } -class example_with_promotion { +class example_with_promotion +{ public function __construct( protected readonly \core\http_client $client, ) { @@ -101,8 +104,10 @@ namespace mod_example; use core\hook\di_configuration; -class hook_listener { - public static function inject_dependencies(di_configuration $hook): void { +class hook_listener +{ + public static function inject_dependencies(di_configuration $hook): void + { $hook->add_definition( id: complex_client::class, definition: function ( @@ -139,8 +144,10 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; use GuzzleHttp\Psr7\Response; -class example_test extends \advanced_testcase { - public function test_the_thing(): void { +class example_test extends \advanced_testcase +{ + public function test_the_thing(): void + { // Mock our responses to the http_client. $handlerstack = HandlerStack::create(new MockHandler([ new Response(200, [], json_encode(['name' => 'Colin'])), @@ -170,13 +177,15 @@ Dependencies can be usually be easily injected into classes which are themselves In most cases in Moodle, this should be via the class constructor, for example: ```php title="Injecting via the constructor" -class thing_manager { +class thing_manager +{ public function __construct( protected readonly \moodle_database $db, ) { } - public function get_things(): array { + public function get_things(): array + { return $this->db->get_records('example_things'); } } @@ -186,13 +195,15 @@ $manager = \core\di::get(thing_manager::class); $things = $manager->get_things(); // Using it in a child class: -class other_thing { +class other_thing +{ public function __construct( protected readonly thing_manager $manager, ) { } - public function manage_things(): void { + public function manage_things(): void + { $this->manager->get_things(); } } diff --git a/docs/apis/core/dml/ddl.md b/docs/apis/core/dml/ddl.md index 83534afad..c33184f78 100644 --- a/docs/apis/core/dml/ddl.md +++ b/docs/apis/core/dml/ddl.md @@ -24,7 +24,8 @@ Of course, feel free to clarify, complete and add more info to all this document - All the function calls in this page are public methods of the **database manager**, accessible from the $DB global object. You will need to "import" it within the upgrade function of your **upgrade.php** main function using the `global` keyword, for example: ```php -function xmldb_xxxx_upgrade { +function xmldb_xxxx_upgrade +{ global $DB; // Load the DDL manager and xmldb API. diff --git a/docs/apis/core/dml/index.md b/docs/apis/core/dml/index.md index 8b63d7dca..d856ea79e 100644 --- a/docs/apis/core/dml/index.md +++ b/docs/apis/core/dml/index.md @@ -33,7 +33,8 @@ require(__DIR__ . '/config.php'); ```php title="example.php" \mod_example\local\entitychanges\create_example::class, @@ -156,7 +158,8 @@ namespace mod_activity\hook; #[\core\attribute\label('Hook dispatched at the very end of installation of mod_activity plugin.')] #[\core\attribute\tags('installation')] -final class installation_finished { +final class installation_finished +{ public function __construct( public readonly string $version, ) { @@ -172,17 +175,20 @@ final class installation_finished { dispatch($hook); } @@ -219,7 +226,8 @@ Using DI for dependency injection has the benefit that the hook manager can use ```php title="Mocking a hook listener" // Unit test. -public function test_before_standard_footer_html_hooked(): void { +public function test_before_standard_footer_html_hooked(): void +{ // Load the callback classes. require_once(__DIR__ . '/fixtures/core_renderer/before_standard_footer_html_callbacks.php'); @@ -242,7 +250,8 @@ public function test_before_standard_footer_html_hooked(): void { } // fixtures/core_renderer/before_standard_footer_html_callbacks.php -final class before_standard_footer_html_callbacks { +final class before_standard_footer_html_callbacks +{ public static function before_standard_footer_html( \core\hook\output\before_standard_footer_html $hook, ): void { @@ -321,8 +330,10 @@ a hook as parameter. namespace local_stuff\local; use \mod_activity\hook\installation_finished; -class hook_callbacks { - public static function activity_installation_finished(installation_finished $hook): void { +class hook_callbacks +{ + public static function activity_installation_finished(installation_finished $hook): void + { if (during_initial_install()) { return; } @@ -395,7 +406,8 @@ use core\attribute; #[attribute\label('Hook dispatched at the very end of lib/setup.php')] #[attribute\tags('config')] #[attribute\hook\replaces_callbacks('after_config')] -final class after_config { +final class after_config +{ } ``` @@ -407,16 +419,20 @@ final class after_config { stopped; } - public function stop(): void { + public function stop(): void + { $this->stopped = true; } } @@ -527,8 +546,10 @@ A callback will only be called if the hook was not stopped before-hand. Dependin namespace local_myplugin; -class callbacks { - public static function block_pre_delete(\core\hook\block_delete_pre $hook): void { +class callbacks +{ + public static function block_pre_delete(\core\hook\block_delete_pre $hook): void + { // ... $hook->stop(); } diff --git a/docs/apis/core/navigation/index.md b/docs/apis/core/navigation/index.md index 159250ee1..eaae0aa97 100644 --- a/docs/apis/core/navigation/index.md +++ b/docs/apis/core/navigation/index.md @@ -235,7 +235,8 @@ function {modulename}_extend_settings_navigation( You may be required to add a node in a specified order within the menu navigation menus. To do this you need to examine the node object as given in the respective parameters in the functions above, then find the key of the child node you wish to place the link before. For example, applying the code below will put a direct link to grade report. ```php -function my_plugin_extend_settings_navigation($settingsnav, $context){ +function my_plugin_extend_settings_navigation($settingsnav, $context) +{ $addnode = $context->contextlevel === 50; $addnode = $addnode && has_capability('gradereport/grader:view', $context); if ($addnode) { diff --git a/docs/apis/core/reportbuilder/index.md b/docs/apis/core/reportbuilder/index.md index b7984b9ff..a7ab677d0 100644 --- a/docs/apis/core/reportbuilder/index.md +++ b/docs/apis/core/reportbuilder/index.md @@ -216,7 +216,8 @@ The first method that we need is ***initialise()*** : /** * Initialise report, we need to set the main table, load our entities and set columns/filters */ -protected function initialise(): void { +protected function initialise(): void +{ ``` The initialise method needs to get the main entity, set the main table it needs to use and add the entity to the report: @@ -336,7 +337,8 @@ The first method you need to build is `initialise()` /** * Initialise report, we need to set the main table, load our entities and set columns/filters */ -protected function initialise(): void { +protected function initialise(): void +{ ``` The initialise method needs to get the main entity, set the main table it needs to use and add the entity to the report: @@ -397,7 +399,8 @@ You will need to specify the name that is displayed to the end user for the data * * @return string */ - public static function get_name(): string { + public static function get_name(): string + { return get_string('tasklogs', 'core_admin'); } ``` @@ -412,7 +415,8 @@ Once all entities have been added you need to define which columns it will show * * @return string[] */ -public function get_default_columns(): array { +public function get_default_columns(): array +{ return [ 'task_log:name', 'task_log:starttime', @@ -430,7 +434,8 @@ You may also optionally define the sorting that will be applied to the default r * * @return int[] */ -public function get_default_column_sorting(): array { +public function get_default_column_sorting(): array +{ return [ 'task_log:starttime' => SORT_DESC, ]; @@ -447,7 +452,8 @@ The filters allow the end user of the report to only see a subset of the data th * * @return string[] */ -public function get_default_filters(): array { +public function get_default_filters(): array +{ return [ 'task_log:timestart', 'task_log:result', @@ -465,7 +471,8 @@ The conditions allow the user creating the report to define which data it will r * * @return string[] */ -public function get_default_conditions(): array { +public function get_default_conditions(): array +{ return [ 'task_log:type', 'task_log:timestart', @@ -482,7 +489,8 @@ You may also optionally define the [initial values for any of the default condit * * @return array */ -public function get_default_condition_values(): array { +public function get_default_condition_values(): array +{ return [ 'task_log:type_operator' => select::EQUAL_TO, 'task_log:type_value' => \core\task\database_logger::TYPE_SCHEDULED, @@ -508,7 +516,8 @@ require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php"); * @copyright 2023 Paul Holden * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class categories_test extends core_reportbuilder_testcase { +class categories_test extends core_reportbuilder_testcase +{ ``` The `core_reportbuilder_testcase` will not autoload so we first ensure that it is loaded with the `require_once`. After this there are a few things you should look to test: @@ -526,7 +535,8 @@ For this you want a step that sets up will return enough data allows you test al /** * Test default datasource */ - public function test_datasource_default(): void { + public function test_datasource_default(): void + { $this->resetAfterTest(); $category = $this->getDataGenerator()->create_category(['name' => 'Zoo', 'idnumber' => 'Z01']); @@ -618,7 +628,8 @@ None of these tests checks that the data is what you want, but will ensure that * * In order to execute this test PHPUNIT_LONGTEST should be defined as true in phpunit.xml or directly in config.php */ - public function test_stress_datasource(): void { + public function test_stress_datasource(): void + { if (!PHPUNIT_LONGTEST) { $this->markTestSkipped('PHPUNIT_LONGTEST is not defined'); } diff --git a/docs/apis/plugintypes/ai/placement.md b/docs/apis/plugintypes/ai/placement.md index dfa4d6c48..e33e4cfc7 100644 --- a/docs/apis/plugintypes/ai/placement.md +++ b/docs/apis/plugintypes/ai/placement.md @@ -39,7 +39,8 @@ They must also implement the following methods: This is the list of Actions that are supported by this Placement, for example the `aiplacement_editor` plugin defines this as: ```php -public function get_action_list(): array { +public function get_action_list(): array +{ return [ \core_ai\aiactions\generate_text::class, \core_ai\aiactions\generate_image::class, diff --git a/docs/apis/plugintypes/ai/provider.md b/docs/apis/plugintypes/ai/provider.md index c5eaa4c50..0b1e3661c 100644 --- a/docs/apis/plugintypes/ai/provider.md +++ b/docs/apis/plugintypes/ai/provider.md @@ -41,7 +41,8 @@ They must also implement the following methods: This is the list of Actions that are supported by this Provider, for example the `aiprovider_openai` plugin defines this as: ```php -public static function get_action_list(): array { +public static function get_action_list(): array +{ return [ \core_ai\aiactions\generate_text::class, \core_ai\aiactions\generate_image::class, @@ -62,7 +63,8 @@ For example, the `aiprovider_azureai` provider checks values are set for `$this- the result. ```php -public function is_provider_configured(): bool { +public function is_provider_configured(): bool +{ return !empty($this->config['apikey']) && !empty($this->config['endpoint']); } ``` @@ -171,14 +173,16 @@ For example, the `aiprovider_openai` plugin defines this: namespace aiprovider_openai; use core_ai\hook\after_ai_provider_form_hook; -class hook_listener { +class hook_listener +{ /** * Hook listener for the Open AI instance setup form. * * @param after_ai_provider_form_hook $hook The hook to add to the AI instance setup. */ - public static function set_form_definition_for_aiprovider_openai(after_ai_provider_form_hook $hook): void { + public static function set_form_definition_for_aiprovider_openai(after_ai_provider_form_hook $hook): void + { if ($hook->plugin !== 'aiprovider_openai') { return; } @@ -260,9 +264,11 @@ These classes should extend the `core_ai\form\action_settings_form` class, and m For example, the `aiprovider_openai` plugin defines this: ```php -class action_generate_text_form extends action_settings_form { +class action_generate_text_form extends action_settings_form +{ #[\Override] - protected function definition() { + protected function definition() + { $mform = $this->_form; $actionconfig = $this->_customdata['actionconfig']['settings'] ?? []; $returnurl = $this->_customdata['returnurl'] ?? null; @@ -302,14 +308,17 @@ namespace aiprovider_openai\aimodel; use core_ai\aimodel\base; use MoodleQuickForm; -class gpt4o extends base implements openai_base { +class gpt4o extends base implements openai_base +{ #[\Override] - public function get_model_name(): string { + public function get_model_name(): string + { return 'gpt-4o'; } #[\Override] - public function get_model_display_name(): string { + public function get_model_display_name(): string + { return 'GPT-4o'; } @@ -325,12 +334,14 @@ To add configurable settings for individual models: ```php #[\Override] - public function has_model_settings(): bool { + public function has_model_settings(): bool + { return true; } #[\Override] - public function add_model_settings(MoodleQuickForm $mform): void { + public function add_model_settings(MoodleQuickForm $mform): void + { $mform->addElement( 'text', 'top_p', @@ -354,13 +365,15 @@ To add configurable settings for individual models: ```php namespace aiprovider_openai; - class helper { + class helper + { /** * Get all model classes. * * @return array Array of model classes */ - public static function get_model_classes(): array { + public static function get_model_classes(): array + { $models = []; $modelclasses = \core_component::get_component_classes_in_namespace('aiprovider_openai', 'aimodel'); foreach ($modelclasses as $class => $path) { @@ -378,7 +391,8 @@ To add configurable settings for individual models: * @param string $modelname The model name * @return \core_ai\aimodel\base|null The model class or null if not found */ - public static function get_model_class(string $modelname): ?\core_ai\aimodel\base { + public static function get_model_class(string $modelname): ?\core_ai\aimodel\base + { foreach (self::get_model_classes() as $modelclass) { $model = new $modelclass(); if ($model->get_model_name() === $modelname) { @@ -399,7 +413,8 @@ For example, the `aiprovider_openai` plugin does these: 1. Create a hook listener that adds model settings to the action form: ```php - public static function set_model_form_definition_for_aiprovider_openai(after_ai_action_settings_form_hook $hook): void { + public static function set_model_form_definition_for_aiprovider_openai(after_ai_action_settings_form_hook $hook): void + { if ($hook->plugin !== 'aiprovider_openai') { return; } diff --git a/docs/apis/plugintypes/assign/feedback.md b/docs/apis/plugintypes/assign/feedback.md index 0634bccbf..c77a995f3 100644 --- a/docs/apis/plugintypes/assign/feedback.md +++ b/docs/apis/plugintypes/assign/feedback.md @@ -121,7 +121,8 @@ All feedback plugins should include one setting named 'default' to indicate if t This is where all the functionality for this plugin is defined. We will step through this file and describe each part as we go. ```php -class assign_feedback_file extends assign_feedback_plugin { +class assign_feedback_file extends assign_feedback_plugin +{ ``` #### get_name() {/* #get_name */} @@ -129,7 +130,8 @@ class assign_feedback_file extends assign_feedback_plugin { All feedback plugins MUST define a class with the component name of the plugin that extends assign_feedback_plugin. ```php -public function get_name() { +public function get_name() +{ return get_string('file', 'assignfeedback_file'); } ``` @@ -139,7 +141,8 @@ This function is abstract in the parent class (feedback_plugin) and must be defi #### get_settings() {/* #get_settings */} ```php -public function get_settings(MoodleQuickForm $mform) { +public function get_settings(MoodleQuickForm $mform) +{ $mform->addElement( 'assignfeedback_file_fileextensions', get_string('allowedfileextensions', 'assignfeedback_file') @@ -153,7 +156,8 @@ This function is called when building the settings page for the assignment. It a #### save_settings() {/* #save_settings */} ```php -public function save_settings(stdClass $data) { +public function save_settings(stdClass $data) +{ $this->set_config('allowedfileextensions', $data->allowedfileextensions); return true; } @@ -204,7 +208,8 @@ This function is called when building the feedback form. It functions identicall #### is_feedback_modified() {/* #is_feedback_modified */} ```php -public function is_feedback_modified(stdClass $grade, stdClass $data) { +public function is_feedback_modified(stdClass $grade, stdClass $data) +{ $commenttext = ''; if ($grade) { $feedbackcomments = $this->get_feedback_comments($grade->id); @@ -226,7 +231,8 @@ This function is called before feedback is saved. If feedback has not been modif #### save() {/* #save */} ```php -public function save(stdClass $grade, stdClass $data) { +public function save(stdClass $grade, stdClass $data) +{ global $DB; $fileoptions = $this->get_file_options(); @@ -263,7 +269,8 @@ This function is called to save a graders feedback. The parameters are the grade #### view_summary() {/* #view_summary */} ```php -public function view_summary(stdClass $grade, & $showviewlink) { +public function view_summary(stdClass $grade, & $showviewlink) +{ $count = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA); // show a view all link if the number of files is over this limit $showviewlink = $count > ASSIGNFEEDBACK_FILE_MAXSUMMARYFILES; @@ -285,7 +292,8 @@ This function is called to display a summary of the feedback to both markers and #### view() {/* #view */} ```php -public function view(stdClass $grade) { +public function view(stdClass $grade) +{ return $this->assignment->render_area_files( 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, @@ -299,7 +307,8 @@ This function is called to display the entire feedback to both markers and stude #### can_upgrade() {/* #can_upgrade */} ```php -public function can_upgrade($type, $version) { +public function can_upgrade($type, $version) +{ if (($type == 'upload' || $type == 'uploadsingle') && $version >= 2011112900) { return true; @@ -311,7 +320,8 @@ public function can_upgrade($type, $version) { This function is used to identify old "Assignment 2.2" subtypes that can be upgraded by this plugin. This plugin supports upgrades from the old "upload" and "uploadsingle" assignment subtypes. ```php -public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) { +public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) +{ // first upgrade settings (nothing to do) return true; } @@ -360,7 +370,8 @@ This function upgrades a single submission from the old assignment type to the n #### is_empty() {/* #is_empty */} ```php -public function is_empty(stdClass $submission) { +public function is_empty(stdClass $submission) +{ return $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA) == 0; } ``` @@ -370,7 +381,8 @@ If a plugin has no data to show then this function should return true from the ` #### get_file_areas() {/* #get_file_areas */} ```php -public function get_file_areas() { +public function get_file_areas() +{ return [ASSIGNFEEDBACK_FILE_FILEAREA => $this->get_name()]; } ``` @@ -380,7 +392,8 @@ A plugin should implement `get_file_areas` if it supports saving of any files to #### delete_instance() {/* #delete_instance */} ```php -public function delete_instance() { +public function delete_instance() +{ global $DB; // will throw exception on failure $DB->delete_records('assignfeedback_file', [ @@ -396,11 +409,13 @@ This function is called when a plugin is deleted. Note only database records nee #### Gradebook features {/* #gradebook-features */} ```php -public function format_for_gradebook(stdClass $grade) { +public function format_for_gradebook(stdClass $grade) +{ return FORMAT_MOODLE; } -public function text_for_gradebook(stdClass $grade) { +public function text_for_gradebook(stdClass $grade) +{ return ''; } ``` @@ -413,7 +428,8 @@ Only one feedback plugin can push comments to the gradebook. Usually this is the * * @return boolean - True if the plugin supports quickgrading */ -public function supports_quickgrading() { +public function supports_quickgrading() +{ return false; } @@ -424,7 +440,8 @@ public function supports_quickgrading() { * @param mixed $grade grade or null - The grade data. May be null if there are no grades for this user (yet) * @return mixed - A html string containing the html form elements required for quickgrading or false to indicate this plugin does not support quickgrading */ -public function get_quickgrading_html($userid, $grade) { +public function get_quickgrading_html($userid, $grade) +{ return false; } @@ -435,7 +452,8 @@ public function get_quickgrading_html($userid, $grade) { * @param stdClass $grade The grade * @return boolean - true if the quickgrading form element has been modified */ -public function is_quickgrading_modified($userid, $grade) { +public function is_quickgrading_modified($userid, $grade) +{ return false; } @@ -446,7 +464,8 @@ public function is_quickgrading_modified($userid, $grade) { * @param stdClass $grade The grade * @return boolean - true if the grade changes were saved correctly */ -public function save_quickgrading_changes($userid, $grade) { +public function save_quickgrading_changes($userid, $grade) +{ return false; } ``` @@ -457,7 +476,8 @@ These 4 functions can be implemented to allow a plugin to support quick-grading. /** * Run cron for this plugin */ -public static function cron() { +public static function cron() +{ } ``` @@ -471,7 +491,8 @@ A plugin can run code when cron runs by implementing this method. * @return array - An array of action and description strings. * The action will be passed to grading_action. */ -public function get_grading_actions() { +public function get_grading_actions() +{ return []; } @@ -481,7 +502,8 @@ public function get_grading_actions() { * @param string $gradingaction The action chosen from the grading actions menu * @return string The page containing the form */ -public function grading_action($gradingaction) { +public function grading_action($gradingaction) +{ return ''; } ``` @@ -495,7 +517,8 @@ Grading actions appear in the select menu above the grading table and apply to t * @return array - An array of action and description strings. * The action will be passed to grading_batch_operation. */ -public function get_grading_batch_operations() { +public function get_grading_batch_operations() +{ return []; } @@ -506,7 +529,8 @@ public function get_grading_batch_operations() { * @param array $users The list of selected userids * @return string The page containing the form */ -public function grading_batch_operation($action, $users) { +public function grading_batch_operation($action, $users) +{ return ''; } ``` diff --git a/docs/apis/plugintypes/assign/submission.md b/docs/apis/plugintypes/assign/submission.md index d4e43f75e..e643dbe16 100644 --- a/docs/apis/plugintypes/assign/submission.md +++ b/docs/apis/plugintypes/assign/submission.md @@ -118,7 +118,8 @@ This example from the submission_file plugin also checks to see if there is a ma This is where all the functionality for this plugin is defined. We will step through this file and describe each part as we go. ```php -class assign_submission_file extends assign_submission_plugin { +class assign_submission_file extends assign_submission_plugin +{ ``` All submission plugins MUST define a class with the component name of the plugin that extends assign_submission_plugin. @@ -126,7 +127,8 @@ All submission plugins MUST define a class with the component name of the plugin #### get_name() {/* #get_name */} ```php -public function get_name() { +public function get_name() +{ return get_string('file', 'assignsubmission_file'); } ``` @@ -136,7 +138,8 @@ Get name is abstract in submission_plugin and must be defined in your new plugin #### get_settings() {/* #get_settings */} ```php -public function get_settings(MoodleQuickForm $mform) { +public function get_settings(MoodleQuickForm $mform) +{ global $CFG, $COURSE; $defaultmaxfilesubmissions = $this->get_config('maxfilesubmissions'); @@ -193,7 +196,8 @@ The "get_settings" function is called when building the settings page for the as #### save_settings() {/* #save_settings */} ```php -public function save_settings(stdClass $data) { +public function save_settings(stdClass $data) +{ $this->set_config('maxfilesubmissions', $data->assignsubmission_file_maxfiles); $this->set_config('maxsubmissionsizebytes', $data->assignsubmission_file_maxsizebytes); return true; @@ -205,7 +209,8 @@ The "save_settings" function is called when the assignment settings page is subm #### get_form_elements() {/* #get_form_elements */} ```php -public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data) { +public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data) +{ if ($this->get_config('maxfilesubmissions') <= 0) { return false; } @@ -240,7 +245,8 @@ The get_form_elements function is called when building the submission form. It f #### save() {/* #save */} ```php -public function save(stdClass $submission, stdClass $data) { +public function save(stdClass $submission, stdClass $data) +{ global $USER, $DB; $fileoptions = $this->get_file_options(); @@ -305,7 +311,8 @@ The "save" function is called to save a user submission. The parameters are the #### get_files() {/* #get_files */} ```php -public function get_files($submission) { +public function get_files($submission) +{ $result = []; $fs = get_file_storage(); @@ -330,7 +337,8 @@ If this submission plugin produces one or more files, it should implement "get_f #### view_summary() {/* #view_summary */} ```php -public function view_summary(stdClass $submission, & $showviewlink) { +public function view_summary(stdClass $submission, & $showviewlink) +{ $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); // Show we show a link to view all files for this plugin. @@ -352,7 +360,8 @@ The view_summary function is called to display a summary of the submission to bo #### view() {/* #view */} ```php -public function view($submission) { +public function view($submission) +{ return $this->assignment->render_area_files( 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, @@ -367,7 +376,8 @@ The view function is called to display the entire submission to both markers and ```php #[\Override] -public function submission_summary_for_messages(stdClass $submission): array { +public function submission_summary_for_messages(stdClass $submission): array +{ global $PAGE; $onlinetextsubmission = $this->get_onlinetext_submission($submission->id); @@ -392,7 +402,8 @@ This method produces a summary of what was submitted, in a form suitable to incl #### can_upgrade() {/* #can_upgrade */} ```php -public function can_upgrade($type, $version) { +public function can_upgrade($type, $version) +{ $uploadsingle_type ='uploadsingle'; $upload_type ='upload'; @@ -408,7 +419,8 @@ The can_upgrade function is used to identify old "Assignment 2.2" subtypes that #### upgrade_settings() {/* #upgrade_settings */} ```php -public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) { +public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) +{ global $DB; if ($oldassignment->assignmenttype == 'uploadsingle') { @@ -450,7 +462,8 @@ This function is called once per assignment instance to upgrade the settings fro #### upgrade() {/* #upgrade */} ```php -public function upgrade($oldcontext, $oldassignment, $oldsubmission, $submission, &$log) { +public function upgrade($oldcontext, $oldassignment, $oldsubmission, $submission, &$log) +{ global $DB; $filesubmission = (object) [ @@ -486,7 +499,8 @@ The "upgrade" function upgrades a single submission from the old assignment type #### get_editor_fields() {/* #get_editor_fields */} ```php -public function () { +public function () +{ return [ 'onlinetext' => get_string('pluginname', 'assignsubmission_comments'), ]; @@ -498,7 +512,8 @@ This example is from assignsubmission_onlinetext. If the plugin uses a text-edit #### get_editor_text() {/* #get_editor_text */} ```php -public function get_editor_text($name, $submissionid) { +public function get_editor_text($name, $submissionid) +{ if ($name == 'onlinetext') { $onlinetextsubmission = $this->get_onlinetext_submission($submissionid); if ($onlinetextsubmission) { @@ -515,7 +530,8 @@ This example is from assignsubmission_onlinetext. If the plugin uses a text-edit #### get_editor_format() {/* #get_editor_format */} ```php -public function get_editor_format($name, $submissionid) { +public function get_editor_format($name, $submissionid) +{ if ($name == 'onlinetext') { $onlinetextsubmission = $this->get_onlinetext_submission($submissionid); if ($onlinetextsubmission) { @@ -532,7 +548,8 @@ This example is from assignsubmission_onlinetext. For the same reason as the pre #### is_empty() {/* #is_empty */} ```php -public function is_empty(stdClass $submission) { +public function is_empty(stdClass $submission) +{ return $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA) == 0; } ``` @@ -542,7 +559,8 @@ If a plugin has no submission data to show - it can return true from the is_empt #### submission_is_empty() {/* #submission_is_empty */} ```php -public function submission_is_empty() { +public function submission_is_empty() +{ global $USER; $fs = get_file_storage(); @@ -565,7 +583,8 @@ Determine if a submission is empty. This is distinct from is_empty() in that it #### get_file_areas() {/* #get_file_areas */} ```php -public function get_file_areas() { +public function get_file_areas() +{ return [ASSIGNSUBMISSION_FILE_FILEAREA=>$this->get_name()]; } ``` @@ -575,7 +594,8 @@ A plugin should implement get_file_areas if it supports saving of any files to m #### copy_submission() {/* #copy_submission */} ```php -public function copy_submission(stdClass $sourcesubmission, stdClass $destsubmission) { +public function copy_submission(stdClass $sourcesubmission, stdClass $destsubmission) +{ global $DB; // Copy the files across. @@ -609,7 +629,8 @@ Since Moodle 2.5 - a students submission can be copied to create a new submissio #### format_for_log() {/* #format_for_log */} ```php -public function format_for_log(stdClass $submission) { +public function format_for_log(stdClass $submission) +{ // Format the information for each submission plugin add_to_log $filecount = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); return ' the number of file(s) : ' . $filecount . " file(s).
"; @@ -621,7 +642,8 @@ The format_for_log function lets a plugin produce a really short summary of a su #### delete_instance() {/* #delete_instance */} ```php -public function delete_instance() { +public function delete_instance() +{ global $DB; // Will throw exception on failure $DB->delete_records('assignsubmission_file', [ diff --git a/docs/apis/plugintypes/availability/index.md b/docs/apis/plugintypes/availability/index.md index fe15d4233..19dcc032c 100644 --- a/docs/apis/plugintypes/availability/index.md +++ b/docs/apis/plugintypes/availability/index.md @@ -83,12 +83,14 @@ Here's an outline of the code (with standard PHPdoc comments omitted to save spa // You must use the right namespace (matching your plugin component name). namespace availability_name; -class condition extends \core_availability\condition { +class condition extends \core_availability\condition +{ // Any data associated with the condition can be stored in member // variables. Here's an example variable: protected $allow; - public function __construct($structure) { + public function __construct($structure) + { // Retrieve any necessary data from the $structure here. The // structure is extracted from JSON data stored in the database // as part of the tree structure of conditions relating to an @@ -100,7 +102,8 @@ class condition extends \core_availability\condition { // throw a coding_exception if the structure is wrong. } - public function save() { + public function save() + { // Save back the data into a plain array similar to $structure above. return (object)array('type' => 'name', 'allow' => $this->allow); } @@ -142,7 +145,8 @@ class condition extends \core_availability\condition { return $allow ? 'Users are allowed' : 'Users not allowed'; } - protected function get_debug_string() { + protected function get_debug_string() + { // This function is only normally used for unit testing and // stuff like that. Just make a short string representation // of the values of the condition, suitable for developers. @@ -162,9 +166,11 @@ The class is required, but all the functions are theoretically optional; you can ```php namespace availability_name; -class frontend extends \core_availability\frontend { +class frontend extends \core_availability\frontend +{ - protected function get_javascript_strings() { + protected function get_javascript_strings() + { // You can return a list of names within your language file and the // system will include them here. // Should you need strings from another language file, you can also diff --git a/docs/apis/plugintypes/blocks/index.md b/docs/apis/plugintypes/blocks/index.md index bc56f7024..b42ddf26f 100644 --- a/docs/apis/plugintypes/blocks/index.md +++ b/docs/apis/plugintypes/blocks/index.md @@ -160,7 +160,8 @@ This function is called on your subclass right after an instance is loaded. It i Example of a specialization method using the instance configuration. ```php -function specialization() { +function specialization() +{ if (isset($this->config->title)) { $this->title = format_string($this->config->title, true, ['context' => $this->context]); } else { @@ -180,11 +181,13 @@ In order to get our block to actually display something on screen, we need to ad ```php -class block_pluginname extends block_base { +class block_pluginname extends block_base +{ // (...) - public function get_content() { + public function get_content() + { if ($this->content !== null) { return $this->content; } @@ -202,11 +205,13 @@ class block_pluginname extends block_base { ```php -class block_pluginname extends block_list { +class block_pluginname extends block_list +{ // (...) - public function get_content() { + public function get_content() + { global $OUTPUT; if ($this->content !== null) { return $this->content; @@ -256,7 +261,8 @@ By default, only one instance of each block plugin can be added to a page. Howev
```php -public function instance_allow_multiple() { +public function instance_allow_multiple() +{ return true; } ``` @@ -279,7 +285,8 @@ Using this method each block instance can decide if the standard block header is
```php -public function hide_header() { +public function hide_header() +{ return true; } ``` @@ -298,7 +305,8 @@ By default, each block section in the page will use a standard `block` class and
```php -public function html_attributes() { +public function html_attributes() +{ // Get default values. $attributes = parent::html_attributes(); // Append our class to class attribute. @@ -351,7 +359,8 @@ However, for some cases like the Atto HTML editor, you may want to store them in
```php title="Example of adding data before storing it -public function instance_config_save($data,$nolongerused =false) { +public function instance_config_save($data,$nolongerused =false) +{ // Example of add new data. $data->somenewattribute = 'Some new value'; @@ -393,7 +402,8 @@ While in other Moodle pulgins the existence of a settings.php is enough to enabl
```php" -function has_config() { +function has_config() +{ return true; } ``` @@ -421,7 +431,8 @@ Each page in Moodle can define it's own page type name. However, there are some
```php -public function applicable_formats() { +public function applicable_formats() +{ return [ 'admin' => false, 'site-index' => false, diff --git a/docs/apis/plugintypes/enrol/index.md b/docs/apis/plugintypes/enrol/index.md index bd2695079..da1a3c56d 100644 --- a/docs/apis/plugintypes/enrol/index.md +++ b/docs/apis/plugintypes/enrol/index.md @@ -151,7 +151,8 @@ By default, all enrolment plugins will have *editing enrolment* and *user unenro * @param stdClass $userenrolment * @return array An array of user_enrolment_actions */ -public function get_user_enrolment_actions(course_enrolment_manager $manager, $userenrolment) { +public function get_user_enrolment_actions(course_enrolment_manager $manager, $userenrolment) +{ $actions = parent::get_user_enrolment_actions($manager, $userenrolment); $context = $manager->get_context(); $instance = $userenrolment->enrolmentinstance; @@ -191,7 +192,8 @@ The unenrol action will allow resetif all following conditions are met:
```php -public function allow_unenrol(stdClass $instance) { +public function allow_unenrol(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -224,7 +226,8 @@ The unenrol action will be displayed if all following conditions are met:
```php -public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) { +public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) +{ // Add any extra validation here. return true; } @@ -241,7 +244,8 @@ It is quite common in enrolment plugins to allow unenrol only if the user enrolm
```php -public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) { +public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) +{ if ($userenrolment->status == ENROL_USER_SUSPENDED) { return true; } @@ -270,7 +274,8 @@ The edit manual enrolment action will be displayed if if all following condition
```php -public function allow_enrol(stdClass $instance) { +public function allow_enrol(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -343,7 +348,8 @@ The edit enrolment action in the participants list will be displayed if if all f
```php -public function allow_manage(stdClass $instance) { +public function allow_manage(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -363,7 +369,8 @@ Enrolment plugins can protect roles from being modified by any other plugin. Ret
```php -public function roles_protected() { +public function roles_protected() +{ // Add any extra validation here if necessary. return false; } @@ -393,7 +400,8 @@ The only exception is *enrol_self* - although it is not possible to uniquely ide
```php -public function find_instance(array $enrolmentdata, int $courseid) : ?stdClass { +public function find_instance(array $enrolmentdata, int $courseid) : ?stdClass +{ global $DB; $instances = enrol_get_instances($courseid, false); diff --git a/docs/apis/plugintypes/fileconverter/index.md b/docs/apis/plugintypes/fileconverter/index.md index e2d7464a6..daedef81a 100644 --- a/docs/apis/plugintypes/fileconverter/index.md +++ b/docs/apis/plugintypes/fileconverter/index.md @@ -54,7 +54,8 @@ This function informs the File Converter API whether the system requirements of It should be lightweight to call and cache where required. ```php title="Example implementation" -public static function are_requirements_met() { +public static function are_requirements_met() +{ return extension_loaded('my_php_extension'); } ``` @@ -72,9 +73,11 @@ The `start_document_conversion()` function starts a conversion, whilst `poll_con This function allows the plugin to answer whether it supports conversion between two formats. It is typically only used internally by the File Conversion subsystem. ```php title="Example implementation" -class converter implements \core_files\converter_interface { +class converter implements \core_files\converter_interface +{ // ... - public static function supports($from, $to) { + public static function supports($from, $to) + { // This plugin supports conversion from doc and docx to pdf only. if ($from !== 'doc' && $from !== 'docx') { return false; diff --git a/docs/apis/plugintypes/filter/index.md b/docs/apis/plugintypes/filter/index.md index 70c2dbbde..81afdeaf7 100644 --- a/docs/apis/plugintypes/filter/index.md +++ b/docs/apis/plugintypes/filter/index.md @@ -107,7 +107,8 @@ If a filter uses a special syntax or it is based on an appearance of a substring /** * Example of a filter that uses links in some way. */ -public function filter($text, array $options = []) { +public function filter($text, array $options = []) +{ if (!is_string($text) or empty($text)) { // Non-string data can not be filtered anyway. @@ -138,8 +139,10 @@ To support this behaviour, a filter plugin must provide a `filterlocalsettings.p
```php title="filterlocalsettings.php" -class pluginfile_filter_local_settings_form extends \core_filters\form\local_settings_form { - protected function definition_inner(\MoodleQuickForm $mform) { +class pluginfile_filter_local_settings_form extends \core_filters\form\local_settings_form +{ + protected function definition_inner(\MoodleQuickForm $mform) + { $mform->addElement( 'text', 'word', @@ -164,8 +167,10 @@ All the local configurations can be accessed in the main filter class in the `$t localconfig['word'] ?? 'default'; diff --git a/docs/apis/plugintypes/format/index.md b/docs/apis/plugintypes/format/index.md index 37dbd3c82..063809119 100644 --- a/docs/apis/plugintypes/format/index.md +++ b/docs/apis/plugintypes/format/index.md @@ -536,8 +536,10 @@ In the example the extra output classes can look like: dirroot . '/mod/forum/lib.php'); @@ -808,9 +819,11 @@ This feature has been implemented by: ```php title="mod/resource/classes/output/courseformat/activitybadge.php" namespace mod_resource\output\courseformat; - class activitybadge extends \core_courseformat\output\activitybadge { + class activitybadge extends \core_courseformat\output\activitybadge + { - protected function update_content(): void { + protected function update_content(): void + { $options = (object) ['displayoptions' => $this->cminfo->customdata['displayoptions']]; $this->content = resource_get_optional_filetype($options, $this->cminfo); } diff --git a/docs/apis/plugintypes/format/linear_navigation.md b/docs/apis/plugintypes/format/linear_navigation.md index 25ee5e8b5..e88f4ccbd 100644 --- a/docs/apis/plugintypes/format/linear_navigation.md +++ b/docs/apis/plugintypes/format/linear_navigation.md @@ -20,13 +20,15 @@ To support linear navigation, your course format must override the `uses_linear_ /** * Custom course format class. */ -class format_mycustomformat extends \core_courseformat\base { +class format_mycustomformat extends \core_courseformat\base +{ /** * Determines whether the course format supports linear navigation. * * @return bool True if linear navigation is supported, false otherwise. */ - public static function uses_linear_navigation(): bool { + public static function uses_linear_navigation(): bool + { // Return true to unconditionally enable it. return true; } @@ -44,7 +46,8 @@ If your course format requires configuration at the course settings level (simil * @param bool $foreditform True if it's being requested for the course edit form. * @return array Array of options. */ - public function course_format_options($foreditform = false) { + public function course_format_options($foreditform = false) + { static $courseformatoptions = false; // Initialise the course format options array if it hasn't been done yet with the default values. if ($courseformatoptions === false) { diff --git a/docs/apis/plugintypes/mod/_files/lib_description.md b/docs/apis/plugintypes/mod/_files/lib_description.md index 6615a48be..667d074f2 100644 --- a/docs/apis/plugintypes/mod/_files/lib_description.md +++ b/docs/apis/plugintypes/mod/_files/lib_description.md @@ -41,7 +41,8 @@ Each feature is identified by a constant, which is defined in the `lib
```php -function [modname]_supports($feature) { +function [modname]_supports($feature) +{ return match ($feature) { FEATURE_GROUPS => true, FEATURE_GROUPINGS => true, @@ -70,7 +71,8 @@ Optionally, if your plugin fits in a secondary purpose, you should add the `FEAT
```php -function [modname]_supports(string $feature) { +function [modname]_supports(string $feature) +{ return match ($feature) { // The rest of features should be listed here... FEATURE_MOD_PURPOSE => MOD_PURPOSE_COLLABORATION, diff --git a/docs/apis/plugintypes/mod/courseoverview.md b/docs/apis/plugintypes/mod/courseoverview.md index 9577a60f8..06ac10b83 100644 --- a/docs/apis/plugintypes/mod/courseoverview.md +++ b/docs/apis/plugintypes/mod/courseoverview.md @@ -30,7 +30,8 @@ namespace mod_PLUGINNAME\courseformat; use core_courseformat\activityoverviewbase; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ // Implement methods here. } ``` @@ -65,9 +66,11 @@ use core_courseformat\activityoverviewbase; use core_courseformat\local\overview\overviewitem; use core\output\pix_icon; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ #[\Override] - public function get_extra_overview_items(): array { + public function get_extra_overview_items(): array + { return [ 'submitted' => $this->get_extra_submitted_overview(), ]; @@ -78,7 +81,8 @@ class overview extends activityoverviewbase { * * @return overviewitem|null */ - private function get_extra_submitted_overview(): ?overviewitem { + private function get_extra_submitted_overview(): ?overviewitem + { // Validate if the user needs this overview information. Return null otherwise. if (!has_capability('mod/PLUGINNAME:complete', $this->context)) { return null; @@ -137,9 +141,11 @@ namespace mod_PLUGINNAME\courseformat; use core_courseformat\activityoverviewbase; use core_courseformat\local\overview\overviewitem; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ #[\Override] - public function get_due_date_overview(): ?overviewitem { + public function get_due_date_overview(): ?overviewitem + { // Implement here how to get the due date of the activity. $duedate = DO_SOMETHING_TO_GET_YOUR_PLUGIN_DUE_DATE(); @@ -177,9 +183,11 @@ use core\output\action_link; use core\output\local\properties\button; use core\output\local\properties\text_align; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ #[\Override] - public function get_actions_overview(): ?overviewitem { + public function get_actions_overview(): ?overviewitem + { // Validate if the user can do the action. Return null otherwise. if (!has_capability('mod/PLUGINNAME:viewreports', $this->context)) { return null; @@ -229,7 +237,8 @@ This is an example of a plugin with two grade items: ```php #[\Override] -protected function get_grade_item_names(array $items): array { +protected function get_grade_item_names(array $items): array +{ // Add some fallback in case some grade item is missing. if (count($items) != 2) { return parent::get_grade_item_names($items); @@ -262,7 +271,8 @@ namespace mod_PLUGINNAME\courseformat; use core_course\activityoverviewbase; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ public function __construct( /** @var cm_info $cm the activity course module. */ cm_info $cm, diff --git a/docs/apis/plugintypes/mod/visibility.md b/docs/apis/plugintypes/mod/visibility.md index 182e57640..68efc3b24 100644 --- a/docs/apis/plugintypes/mod/visibility.md +++ b/docs/apis/plugintypes/mod/visibility.md @@ -37,7 +37,8 @@ The course cache is only updated when somebody edits a module, so it can't be us The function should return a value of class `cached_cm_info`. For example: ```php -function mod_frog_get_coursemodule_info($cm) { +function mod_frog_get_coursemodule_info($cm) +{ $info = new cached_cm_info(); $info->content = '

This will display below the module.

'; return $info; @@ -62,7 +63,8 @@ Don't use renderers in this function (see MDL-41074). If you have data you would You can customise module display dynamically (when the page loads). For example you might want to alter it based on the permissions of the current user. ```php -function mod_frog_cm_info_dynamic(cm_info $cm) { +function mod_frog_cm_info_dynamic(cm_info $cm) +{ $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!has_capability('some/capability', $context)) { $cm->set_user_visible(false); @@ -81,7 +83,8 @@ Most things are set using functions (as above; another example would be `set_con Sometimes you need to display custom information for the current user that appears only on the course view page. For example, the forum module displays unread information on the view page. This information doesn't show on other pages (it isn't included in the navigation, for instance). ```php -function mod_frog_cm_info_view(cm_info $cm) { +function mod_frog_cm_info_view(cm_info $cm) +{ $cm->set_after_link('Last tadpole: 22:17'); } ``` @@ -106,7 +109,8 @@ $cm = $modinfo->get_cm($cmid); The cm_info objects contain additional information that is not present in the course_modules database row, such as the module's name, and the icon and associated content mentioned above. In order to distinguish these from the plain database objects, you can specify the cm_info class in a function definition: ```php -function my_clever_function(cm_info $cm) { +function my_clever_function(cm_info $cm) +{ if (!$cm->uservisible) { // The module is not visible or available to current user, // so do something clever instead. diff --git a/docs/apis/plugintypes/qbank/filters.md b/docs/apis/plugintypes/qbank/filters.md index 340c714e0..036341bdd 100644 --- a/docs/apis/plugintypes/qbank/filters.md +++ b/docs/apis/plugintypes/qbank/filters.md @@ -37,7 +37,8 @@ namespace qbank_myplugin; use core_question\local\bank\condition; -class myfilter_condition extends condition { +class myfilter_condition extends condition +{ } ``` @@ -47,8 +48,10 @@ Modify your `plugin_feature` class to return an instance of your condition from ```php title="question/bank/myplugin/classes/plugin_feature.php" namespace qbank_myplugin; -class plugin_feature extends core_question\local\bank\plugin_features_base { - public function get_question_filters(?core_question\local\bank\view $qbank = null): array { +class plugin_feature extends core_question\local\bank\plugin_features_base +{ + public function get_question_filters(?core_question\local\bank\view $qbank = null): array + { return [ new myfilter_condition($qbank), ]; @@ -59,7 +62,8 @@ class plugin_feature extends core_question\local\bank\plugin_features_base { Back in your `condition` class, define the `get_name()` method, which returns the label displayed in the filter UI. ```php title="Define the condition name" -public function get_name(): string { +public function get_name(): string +{ return get_string('myfilter_name', 'myplugin'); } ``` @@ -67,7 +71,8 @@ public function get_name(): string { Define `get_condition_key()`, which returns a unique machine-readable ID for this filter condition, used when passing the filter as a parameter. ```php title="Define the condition key" -public function get_condition_key(): string { +public function get_condition_key(): string +{ return 'myfilter'; } ``` @@ -78,7 +83,8 @@ The `$filter` parameter receives an array with a `'values'` key, containing an a The conditions from each filter are combined with the query in [`core_question\local\bank\view::build_query()`](https://github.com/moodle/moodle/blob/c741492c38b9945abbfc7e90dfe8f943279f8265/question/classes/local/bank/view.php#L733) ```php title="Filter questions" -public function build_query_from_filter(array $filter): array { +public function build_query_from_filter(array $filter): array +{ $andor = ' AND '; $equal = '='; if ($filter['jointype'] === self::JOINTYPE_ANY) { @@ -109,7 +115,8 @@ Following this pattern with your own fields and options will give you a basic fu To define the list of possible filter values, define `get_initial_values()`, which returns an array of `['value', 'title']` for each option. These will then be searchable and selectable in the autocomplete field. ```php title="Define initial filter values" -public function get_initial_values(): string { +public function get_initial_values(): string +{ return [ [ 'value' => 0, @@ -128,7 +135,8 @@ public function get_initial_values(): string { To restrict the possible filter terms to only those returned from `get_initial_values()`, define `allow_custom()` and have it return `false`. ```php title="Disable custom terms" -public function allow_custom(): bool { +public function allow_custom(): bool +{ return false; } ``` @@ -138,7 +146,8 @@ public function allow_custom(): bool { Not all join types are relevant to all filters. If each question will only match one of the selected values, it does not make sense to allow `JOINTYPE_ALL`. Define `get_join_list()` and return an array of the applicable join types. ```php title="Define a restricted list of join types" -public function get_join_list(): array { +public function get_join_list(): array +{ return [ datafilter::JOINTYPE_ANY, datafilter::JOINTYPE_NONE, @@ -152,7 +161,8 @@ By default, conditions allow multiple values to be selected and use the selected If your condition should only allow a single value at a time, override `allow_multiple()` to return false. ```php title="Disable selection of multiple values" -public function allow_multiple(): bool { +public function allow_multiple(): bool +{ return false; } ``` @@ -162,7 +172,8 @@ public function allow_multiple(): bool { By default, conditions can be left empty, and therefore will not be included in the filter. To make it compulsory to select a value for this condition when it is added, override `allow_empty()` to return false. ```php title="Disable empty values" -public function allow_empty(): bool { +public function allow_empty(): bool +{ return false; } ``` @@ -172,7 +183,8 @@ public function allow_empty(): bool { If it is compulsory that your condition is always displayed, override `is_required()` to return true. ```php title="Make the condition compulsory" -public function is_required(): bool { +public function is_required(): bool +{ return true; } ``` @@ -188,7 +200,8 @@ You can either use a different core filter type from `/lib/amd/src/datafilter/fi To tell your filter condition to use a different filter class, override the `get_filter_class()` method to return the namespaced path to your JavaScript class. ```php title="Override the default filter class" -public function get_filter_class(): string { +public function get_filter_class(): string +{ return 'qbank_myplugin/datafilter/filtertype/myfilter'; } ``` diff --git a/docs/apis/plugintypes/qtype/newquestiondefaults.md b/docs/apis/plugintypes/qtype/newquestiondefaults.md index c34ce0a02..fb8d4be87 100644 --- a/docs/apis/plugintypes/qtype/newquestiondefaults.md +++ b/docs/apis/plugintypes/qtype/newquestiondefaults.md @@ -41,7 +41,8 @@ $mform->setDefault('shuffleanswers', $this->get_default_value('shuffleanswers', Here we need to override the method `save_defaults_for_new_questions` to save the values these settings. For example: ```php - public function save_defaults_for_new_questions(stdClass $fromform): void { + public function save_defaults_for_new_questions(stdClass $fromform): void + { parent::save_defaults_for_new_questions($fromform); $this->set_default_value('shuffleanswers', $fromform->shuffleanswers); } diff --git a/docs/apis/plugintypes/qtype/restore.md b/docs/apis/plugintypes/qtype/restore.md index 845357130..ee30b631e 100644 --- a/docs/apis/plugintypes/qtype/restore.md +++ b/docs/apis/plugintypes/qtype/restore.md @@ -83,7 +83,8 @@ an array of fields to remove from the `$questiondata` structure. For example, i records with the fields `id`, `questionid` and `data`, you might need to define the following: ```php title="question/type/example/backup/moodle2/restore_qtype_example_plugin.class.php" -protected function define_excluded_identity_hash_fields(): array { +protected function define_excluded_identity_hash_fields(): array +{ return [ '/options/extradata/id', '/options/extradata/questionid', @@ -102,7 +103,8 @@ additional data, then passes `$questiondata` on to the parent method. For exampl setting at `$questiondata->options->pluginconfig`, you might need to define the following: ```php title="question/type/example/backup/moodle2/restore_qtype_example_plugin.class.php" -public static function remove_excluded_question_data(stdClass $questiondata, array $excludefields = []): stdClass { +public static function remove_excluded_question_data(stdClass $questiondata, array $excludefields = []): stdClass +{ if (isset($questiondata->options->pluginconfig)) { unset($questiondata->options->pluginconfig); } diff --git a/docs/apis/plugintypes/repository/index.md b/docs/apis/plugintypes/repository/index.md index 0e940f7ab..c23a86a16 100644 --- a/docs/apis/plugintypes/repository/index.md +++ b/docs/apis/plugintypes/repository/index.md @@ -122,7 +122,8 @@ Return any combination of the following values: ```php -function supported_returntypes() { +function supported_returntypes() +{ return FILE_INTERNAL | FILE_EXTERNAL | FILE_REFERENCE | FILE_CONTROLLED_LINK; } ``` @@ -151,7 +152,8 @@ Supported file types can be specified using standard mimetypes (such as `image/g ```php -function supported_filetypes() { +function supported_filetypes() +{ // Allow any kind of file. return '*'; } @@ -161,7 +163,8 @@ function supported_filetypes() { ```php -function supported_filetypes() { +function supported_filetypes() +{ // Example of image mimetypes. return ['image/gif', 'image/jpeg', 'image/png']; } @@ -171,7 +174,8 @@ function supported_filetypes() { ```php -function supported_filetypes() { +function supported_filetypes() +{ // Example of a file group. return ['web_image']; } @@ -204,7 +208,8 @@ Parent function returns an array with a single item - pluginname.
```php -public static function get_type_option_names() { +public static function get_type_option_names() +{ return array_merge(parent::get_type_option_names(), ['rootpath']); } ``` @@ -225,7 +230,8 @@ Optional. This is for modifying the Moodle form displaying the plugin settings. For example, to display the standard repository plugin settings along with the custom ones use: ```php -public static function type_config_form($mform, $classname='repository') { +public static function type_config_form($mform, $classname='repository') +{ parent::type_config_form($mform); $rootpath = get_config('repository_pluginname', 'rootpath'); @@ -244,7 +250,8 @@ This function must be declared static Optional. Use this function if you need to validate some variables submitted by plugin settings form. To use it, check through the associative array of data provided ('settingname' => value) for any errors. Then push the items to $error array in the format ("fieldname" => "human readable error message") to have them highlighted in the form. ```php -public static function type_form_validation($mform, $data, $errors) { +public static function type_form_validation($mform, $data, $errors) +{ if (!is_dir($data['rootpath'])) { $errors['rootpath'] = get_string('invalidrootpath', 'repository_pluginname'); } @@ -271,7 +278,8 @@ Parent function returns an empty array. This is equivalent to **get_type_option_
```php -public static function get_instance_option_names() { +public static function get_instance_option_names() +{ return ['fs_path']; // From repository_filesystem } ``` @@ -292,7 +300,8 @@ Optional. This is for modifying the Moodle form displaying the settings specific For example, to add a required text box called email_address: ```php -public static function get_instance_option_names() { +public static function get_instance_option_names() +{ $mform->addElement( 'text', 'email_address', @@ -318,7 +327,8 @@ This function must be declared static Optional. This allows us to validate what has been submitted in the instance configuration form. This is equivalent to ''type_form_validation($mform, $data, $errors), but for instances. For example: ```php -public static function instance_form_validation($mform, $data, $errors) { +public static function instance_form_validation($mform, $data, $errors) +{ if (empty($data['email_address'])) { $errors['email_address'] = get_string('invalidemailsettingname', 'repository_flickr_public'); } @@ -357,7 +367,8 @@ Firstly the skeleton: * * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ -class repository_flickr_public extends repository { +class repository_flickr_public extends repository +{ } ``` @@ -453,7 +464,8 @@ This function will return a list of files to be displayed to the user, the list * @param string $page * @return array the list of files, including meta information */ -public function get_listing($encodedpath = '', $page = '') { +public function get_listing($encodedpath = '', $page = '') +{ // This methods return [ //this will be used to build navigation bar. @@ -578,7 +590,8 @@ For plugins that do not fully process the login via a popup window, the submitte
```php title="lib/alfresco/lib.php" -public function __construct($repositoryid, $context = SYSCONTEXTID, $options = []) { +public function __construct($repositoryid, $context = SYSCONTEXTID, $options = []) +{ global $SESSION; /* Skipping code that is not relevant to user login */ @@ -618,7 +631,8 @@ Many types include a single element of type 'popup' with the param 'url' pointin
```php title="Code taken from repository_boxnet" -public function print_login() { +public function print_login() +{ $ticket = $this->boxclient->getTicket(); if ($this->options['ajax']) { $loginbtn = (object)[ @@ -652,7 +666,8 @@ This function will return a boolean value to tell Moodle whether the user has lo By default, this function will return true. ```php -public function check_login(): bool { +public function check_login(): bool +{ global $SESSION; return !empty($SESSION->{$this->sessname}); } @@ -663,7 +678,8 @@ public function check_login(): bool { When a user clicks the logout button in file picker, this function will be called. You may clean up the session or disconnect the connection with remote server here. After this the code should return something suitable to display to the user (usually the results of calling **$this->print_login()**): ```php title="lib/alfresco/lib.php" -public function logout() { +public function logout() +{ global $SESSION; unset($SESSION->{$this->sessname}); return $this->print_login(); @@ -689,7 +705,8 @@ For FILE_INTERNAL or FILE_REFERENCE this function is called at the point when th ```php -public function get_file($url, $filename = '') { +public function get_file($url, $filename = '') +{ // Default implementation from the base 'repository' class $path = $this->prepare_file($filename); // Generate a unique temporary filename $curlobject = new curl(); @@ -707,7 +724,8 @@ public function get_file($url, $filename = '') { Slightly extended version taken from repository_equella ```php -public function get_file($reference, $filename = '') { +public function get_file($reference, $filename = '') +{ global $USER; // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference->reference)); @@ -768,7 +786,8 @@ A custom search form must include the following:
```php title="The default implementation in class 'repository'" -public function print_search() { +public function print_search() +{ global $PAGE; $renderer = $PAGE->get_renderer('core', 'files'); return $renderer->repository_default_searchform(); @@ -793,7 +812,8 @@ The return should return an array containing:
```php title="Example from repoistory_googledocs" -public function search($search_text, $page = 0) { +public function search($search_text, $page = 0) +{ $gdocs = new google_docs($this->googleoauth); return [ 'dynload' => true, @@ -822,7 +842,8 @@ Note that external file is synchronised by moodle when UI wants to show the file Return minimum number of seconds before checking for changes to the file (default implementation = 1 day) ```php -public function get_reference_file_lifetime($ref) { +public function get_reference_file_lifetime($ref) +{ return DAYSECS; // One day, 60 * 60 * 24 seconds. } ``` @@ -832,7 +853,8 @@ public function get_reference_file_lifetime($ref) { Called after the file has reached the 'lifetime' specified above to see if it should now be synchronised (default implementation is to return true) ```php -public function sync_individual_file(stored_file $storedfile) { +public function sync_individual_file(stored_file $storedfile) +{ return true; } ``` @@ -851,7 +873,8 @@ This is usually prefixed with the repository name, and a semicolon. For example:
```php title="lib.php" -public function get_reference_details($reference, $filestatus = 0) { +public function get_reference_details($reference, $filestatus = 0) +{ if (!$filestatus) { // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference); @@ -879,7 +902,8 @@ Returns up-to-date information about the original file, only called when the 'li
```php title="/lib.php" -public function get_file_by_reference($reference) { +public function get_file_by_reference($reference) +{ global $USER; // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference->reference)); @@ -946,7 +970,8 @@ It is up to the repository developer to decide whether to actually download the
```php title="/lib.php" -public function send_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) { +public function send_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) +{ // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($stored_file->get_reference())); $url = $this->appendtoken($details->url); diff --git a/docs/apis/plugintypes/sms/index.md b/docs/apis/plugintypes/sms/index.md index 1e9235bff..8baec2ec7 100644 --- a/docs/apis/plugintypes/sms/index.md +++ b/docs/apis/plugintypes/sms/index.md @@ -65,7 +65,8 @@ namespace smsgateway_aws; use smsgateway_aws\local\service\aws_sns; -class gateway extends \core_sms\gateway { +class gateway extends \core_sms\gateway +{ #[\Override] public function send( message $message, @@ -95,7 +96,8 @@ class gateway extends \core_sms\gateway { ); } - private function get_gateway_service(\stdClass $config): string { + private function get_gateway_service(\stdClass $config): string + { return match ($config->gateway) { 'aws_sns' => aws_sns::class, default => throw new moodle_exception("Unknown Message Handler {$config->gateway}"), @@ -103,7 +105,8 @@ class gateway extends \core_sms\gateway { } #[\Override] - public function get_send_priority(message $message): int { + public function get_send_priority(message $message): int + { return 50; } } @@ -120,7 +123,8 @@ It is necessary for plugins developers to assess these hooks and implement accor This hook will allow plugins to add required form fields to assist users in configuring their SMS gateway. ```php title="Listener method for after_sms_gateway_form_hook" -public static function set_form_definition_for_aws_sms_gateway(after_sms_gateway_form_hook $hook): void { +public static function set_form_definition_for_aws_sms_gateway(after_sms_gateway_form_hook $hook): void +{ if ($hook->plugin !== 'smsgateway_example') { return; } diff --git a/docs/apis/plugintypes/theme/index.md b/docs/apis/plugintypes/theme/index.md index 371b703c4..c3cd0b8b0 100644 --- a/docs/apis/plugintypes/theme/index.md +++ b/docs/apis/plugintypes/theme/index.md @@ -108,7 +108,8 @@ $THEME->sheets = []; $THEME->editor_sheets = []; $THEME->editor_scss = ['editor']; $THEME->usefallback = true; -$THEME->scss = function($theme) { +$THEME->scss = function($theme) +{ return theme_boost_get_main_scss_content($theme); }; diff --git a/docs/apis/plugintypes/tiny/index.md b/docs/apis/plugintypes/tiny/index.md index 831f0cfef..38dbd3cbe 100644 --- a/docs/apis/plugintypes/tiny/index.md +++ b/docs/apis/plugintypes/tiny/index.md @@ -398,7 +398,8 @@ use context; use editor_tiny\plugin; use editor_tiny\plugin_with_configuration; -class plugininfo extends plugin implements plugin_with_configuration { +class plugininfo extends plugin implements plugin_with_configuration +{ public static function get_plugin_configuration_for_context( context $context, array $options, diff --git a/docs/apis/subsystems/access.md b/docs/apis/subsystems/access.md index 06ea7efeb..d0b39391d 100644 --- a/docs/apis/subsystems/access.md +++ b/docs/apis/subsystems/access.md @@ -167,7 +167,8 @@ By default checks the capabilities of the current user, but you can pass a diffe Function require_capability() is very similar, it is throwing access control exception if user does not have the capability. ```php -function require_capability($capability, context $context, $userid = null, $doanything = true, $errormessage = 'nopermissions', $stringfile = _) { +function require_capability($capability, context $context, $userid = null, $doanything = true, $errormessage = 'nopermissions', $stringfile = _) +{ ``` ### Enrolment functions {/* #enrolment-functions */} diff --git a/docs/apis/subsystems/ai/index.md b/docs/apis/subsystems/ai/index.md index 8f6f7a0cd..d2e63732e 100644 --- a/docs/apis/subsystems/ai/index.md +++ b/docs/apis/subsystems/ai/index.md @@ -162,7 +162,8 @@ public function __construct( ```php title="Example: The store() method for the generate_image Action" #[\Override] -public function store(response_base $response): int { +public function store(response_base $response): int +{ global $DB; $responsearr = $response->get_response_data(); @@ -225,7 +226,8 @@ it sets these against class variables so they can be retrieved by the Manager an ```php title="Example: The set_response_data() for the generate_image Action response" #[\Override] - public function set_response_data(array $response): void { + public function set_response_data(array $response): void + { $this->draftfile = $response['draftfile'] ?? null; $this->revisedprompt = $response['revisedprompt'] ?? null; $this->sourceurl = $response['sourceurl'] ?? null; @@ -238,7 +240,8 @@ Returns the set response data. ```php title="Example: The get_response_data() for the generate_image Action response" #[\Override] - public function get_response_data(): array { + public function get_response_data(): array + { return [ 'draftfile' => $this->draftfile, 'revisedprompt' => $this->revisedprompt, diff --git a/docs/apis/subsystems/analytics/index.md b/docs/apis/subsystems/analytics/index.md index 1f4c3e3e7..20b1eddc8 100644 --- a/docs/apis/subsystems/analytics/index.md +++ b/docs/apis/subsystems/analytics/index.md @@ -378,7 +378,8 @@ You can overwrite a `new one_sample_per_analysable()` method if the analysables * * @return bool */ -public static function one_sample_per_analysable() { +public static function one_sample_per_analysable() +{ return true; } ``` @@ -398,7 +399,8 @@ You can use `required_sample_data` to specify what your indicator needs to be ca * * @return null|string[] Name of the required elements (use the database tablename) */ -public static function required_sample_data() { +public static function required_sample_data() +{ return null; } ``` diff --git a/docs/apis/subsystems/backup/index.md b/docs/apis/subsystems/backup/index.md index 95245f909..10089ab62 100644 --- a/docs/apis/subsystems/backup/index.md +++ b/docs/apis/subsystems/backup/index.md @@ -95,9 +95,11 @@ Here is a minimalistic task: ```php require_once($CFG->dirroot . '/backup/moodle2/backup_tool_plugin.class.php'); -class backup_tool_foobar_plugin extends backup_tool_plugin { +class backup_tool_foobar_plugin extends backup_tool_plugin +{ - protected function define_course_plugin_structure() { + protected function define_course_plugin_structure() + { $this->step->log('Yay, backup!', backup::LOG_DEBUG); return $plugin; } diff --git a/docs/apis/subsystems/backup/restore.md b/docs/apis/subsystems/backup/restore.md index 16aca9f2a..cf5ee2123 100644 --- a/docs/apis/subsystems/backup/restore.md +++ b/docs/apis/subsystems/backup/restore.md @@ -41,9 +41,11 @@ Here is a minimalistic task: ```php require_once($CFG->dirroot . '/backup/moodle2/restore_tool_plugin.class.php'); -class restore_tool_foobar_plugin extends restore_tool_plugin { +class restore_tool_foobar_plugin extends restore_tool_plugin +{ - protected function define_course_plugin_structure() { + protected function define_course_plugin_structure() + { $paths = array(); $this->step->log('Yay, restore!', backup::LOG_DEBUG); return $paths; diff --git a/docs/apis/subsystems/check/index.md b/docs/apis/subsystems/check/index.md index 51b97ca38..5fbc14021 100644 --- a/docs/apis/subsystems/check/index.md +++ b/docs/apis/subsystems/check/index.md @@ -103,14 +103,17 @@ namespace mod_myplugin\check; use core\check\check; use core\check\result; -class foobar extends check { +class foobar extends check +{ - public function get_action_link(): ?\action_link { + public function get_action_link(): ?\action_link + { $url = new \moodle_url('/mod/myplugin/dosomething.php'); return new \action_link($url, get_string('sitepolicies', 'admin')); } - public function get_result(): result { + public function get_result(): result + { if (some_check()) { $status = result::ERROR; $summary = get_string('check_foobar_error', 'mod_myplugin'); @@ -145,7 +148,8 @@ Next decide on what type of check it should be which determines what report it w Implement the right callback in lib.php for the report you want to add it to, and return an array (usually with only 1 item) of check objects: ```php title="/mod/myplugin/lib.php" -function mod_myplugin_security_checks(): array { +function mod_myplugin_security_checks(): array +{ return [new \mod_myplugin\check\foobar()]; } ``` @@ -157,7 +161,8 @@ Checks have been designed to be dynamic so you can return different checks depen If you plan to return multiple instances of a check class, make sure that each instance has a unique id. ```php -function mod_myplugin_security_checks(): array { +function mod_myplugin_security_checks(): array +{ return [ new \mod_myplugin\check\foobar('one'), new \mod_myplugin\check\foobar('two'), @@ -170,14 +175,17 @@ Set the internal id in a way which is unique across all instances in your compon ```php namespace mod_myplugin\check; -class foobar extends \core\check\check { +class foobar extends \core\check\check +{ protected $id = ''; - public function __construct($id) { + public function __construct($id) + { $this->id = "foobar{$id}"; } - public function get_id(): string { + public function get_id(): string + { return $this->id; } ... @@ -197,17 +205,21 @@ Checks can provide details on a check, such as the complete list of bad records. namespace mod_myplugin\check; -class foobar extends \core\check\check { - public function get_result(): result { +class foobar extends \core\check\check +{ + public function get_result(): result + { return new foobar_result(); } } ``` ```php -class foobar_result extends \core\check\result { +class foobar_result extends \core\check\result +{ ... - public function get_details(): string { + public function get_details(): string + { // Do expensive lookups in here. } } diff --git a/docs/apis/subsystems/communication/index.md b/docs/apis/subsystems/communication/index.md index b1107afd4..36697cea8 100644 --- a/docs/apis/subsystems/communication/index.md +++ b/docs/apis/subsystems/communication/index.md @@ -291,8 +291,10 @@ This method accepts the following parameters: For example, we have a form where we want to have the communication settings, we can use the below code to add the form elements to the form. ```php -class configure_form extends \moodleform { - public function definition() { +class configure_form extends \moodleform +{ + public function definition() + { $mform = $this->_form; $communication = \core_communication\api::load_by_instance( context: $context, diff --git a/docs/apis/subsystems/external/files.md b/docs/apis/subsystems/external/files.md index 627d27648..4eb1fbf23 100644 --- a/docs/apis/subsystems/external/files.md +++ b/docs/apis/subsystems/external/files.md @@ -119,7 +119,8 @@ $forum->introfiles = external_util::get_area_files($context->id, 'mod_forum', 'i You can also use the `external_files` structure definition in combination with the method to return the most common file fields required by WS clients. ```php -public static function execute_returns(): external_multiple_structure { +public static function execute_returns(): external_multiple_structure +{ return new external_multiple_structure( new external_single_structure([ 'id' => new external_value(PARAM_INT, 'Forum id'), diff --git a/docs/apis/subsystems/external/functions.md b/docs/apis/subsystems/external/functions.md index 295a3cca0..617f40ba8 100644 --- a/docs/apis/subsystems/external/functions.md +++ b/docs/apis/subsystems/external/functions.md @@ -65,8 +65,10 @@ use core_external\external_multiple_structure; use core_external\external_single_structure; use core_external\external_value; -class create_groups extends \core_external\external_api { - public static function execute_parameters(): external_function_parameters { +class create_groups extends \core_external\external_api +{ + public static function execute_parameters(): external_function_parameters + { return new external_function_parameters([ 'groups' => new external_multiple_structure( new external_single_structure([ @@ -92,7 +94,8 @@ class create_groups extends \core_external\external_api { ]); } - public static function execute(array $groups): array { + public static function execute(array $groups): array + { // Validate all of the parameters. [ 'groups' => $groups, @@ -114,7 +117,8 @@ class create_groups extends \core_external\external_api { ]; } - public static function execute_returns(): external_single_structure { + public static function execute_returns(): external_single_structure + { return new external_single_structure([ 'groups' => new external_multiple_structure([ 'id' => new external_value(PARAM_INT, 'Id of the created user'), diff --git a/docs/apis/subsystems/external/security.md b/docs/apis/subsystems/external/security.md index b6c0cc685..2d9a721e3 100644 --- a/docs/apis/subsystems/external/security.md +++ b/docs/apis/subsystems/external/security.md @@ -22,7 +22,8 @@ To do so you should call the `validate_parameters()` function, passing in the re The `validate_parameters()` function is defined on the `\core_external\external_api` class, and can be called as follows: ```php title="local/groupmanager/classes/external/create_groups.php" -public static function execute(array $groups): array { +public static function execute(array $groups): array +{ [ 'groups' => $groups, ] = self::validate_parameters(self::execute_parameters(), [ @@ -45,7 +46,8 @@ If your function operates on multiple contexts (like a list of courses), you mus The `validate_context()` function is defined on the `\core_external\external_api` class, and can be called as follows: ```php title="local/groupmanager/classes/external/create_groups.php" -public static function execute(array $groups): array { +public static function execute(array $groups): array +{ // ... foreach ($groups as $group) { $coursecontext = \context_course::instance($group['courseid']); diff --git a/docs/apis/subsystems/external/testing.md b/docs/apis/subsystems/external/testing.md index 8277a6dc9..ab5acac24 100644 --- a/docs/apis/subsystems/external/testing.md +++ b/docs/apis/subsystems/external/testing.md @@ -57,14 +57,16 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/webservice/tests/helpers.php'); -class get_fruit_test extends externallib_advanced_testcase { +class get_fruit_test extends externallib_advanced_testcase +{ /** * Test the execute function when capabilities are present. * * @covers \mod_fruit\external\get_fruit::execute */ - public function test_capabilities(): void { + public function test_capabilities(): void + { $this->resetAfterTest(true); $course = $this->getDataGenerator()->create_course(); @@ -99,7 +101,8 @@ class get_fruit_test extends externallib_advanced_testcase { * * @covers \mod_fruit\external\get_fruit::execute */ - public function test_capabilities_missing(): void { + public function test_capabilities_missing(): void + { global $USER; $this->resetAfterTest(true); diff --git a/docs/apis/subsystems/external/writing-a-service.md b/docs/apis/subsystems/external/writing-a-service.md index ff27b17c1..87aa9a1a3 100644 --- a/docs/apis/subsystems/external/writing-a-service.md +++ b/docs/apis/subsystems/external/writing-a-service.md @@ -150,13 +150,15 @@ use core_external\external_multiple_structure; use core_external\external_single_structure; use core_external\external_value; -class create_groups extends \core_external\external_api { +class create_groups extends \core_external\external_api +{ /** * Returns description of method parameters * @return external_function_parameters */ - public static function execute_parameters() { + public static function execute_parameters() + { return new external_function_parameters([ 'groups' => new external_multiple_structure( new external_single_structure([ @@ -187,7 +189,8 @@ A web service function without parameters will have a parameter description func * Returns description of method parameters * @return external_function_parameters */ -public static function execute_parameters(): external_function_parameters { +public static function execute_parameters(): external_function_parameters +{ return new external_function_parameters([ // If this function had any parameters, they would be described here. // This example has no parameters, so the array is empty. @@ -208,7 +211,8 @@ Our `create_groups()` function expects one parameter named `groups`, so we will * Returns description of method parameters * @return external_function_parameters */ -public static function execute_parameters(): external_function_parameters { +public static function execute_parameters(): external_function_parameters +{ return new external_function_parameters([ 'groups' => ... ]); @@ -280,7 +284,8 @@ We add them to the description : It's similar to execute_parameters(), but instead of describing the parameters, it describes the return values. ```php -public static function execute_returns() { +public static function execute_returns() +{ return new external_multiple_structure( new external_single_structure([ 'id' => new external_value(PARAM_INT, 'group record id'), @@ -312,7 +317,8 @@ Because some web service protocols are strict about the number and types of argu ```php -public static function get_biscuit_parameters() { +public static function get_biscuit_parameters() +{ return new external_function_parameters([ 'chocolatechips' => new external_value( PARAM_BOOL, @@ -340,7 +346,8 @@ public static function get_biscuit_parameters() { ```php -public static function get_biscuit_parameters() { +public static function get_biscuit_parameters() +{ return new external_function_parameters([ 'ifeellike' => new external_single_structure([ 'chocolatechips' => new external_value( @@ -379,7 +386,8 @@ We declared our web service function and we defined the external function parame * @param array $groups array of group description arrays (with keys groupname and courseid) * @return array of newly created groups */ - public static function execute($groups) { + public static function execute($groups) + { global $CFG, $DB; require_once("$CFG->dirroot/group/lib.php"); @@ -471,7 +479,8 @@ External functions deprecation process is slightly different from the standard d * Mark the function as deprecated. * @return bool */ - public static function execute_is_deprecated() { + public static function execute_is_deprecated() + { return true; } ``` diff --git a/docs/apis/subsystems/files/browsing.md b/docs/apis/subsystems/files/browsing.md index ca758d27a..ba98c974f 100644 --- a/docs/apis/subsystems/files/browsing.md +++ b/docs/apis/subsystems/files/browsing.md @@ -12,7 +12,8 @@ The File Browser API is a supplemental API which can be used to fetch informatio This example demonstrates using the `filebrowser` API to fetch the parent folders of a file. ```php -public function get_file_breadcrumbs(\stored_file $file): ?array { +public function get_file_breadcrumbs(\stored_file $file): ?array +{ $browser = get_file_browser(); $context = get_system_context(); diff --git a/docs/apis/subsystems/form/advanced/checkbox-controller.md b/docs/apis/subsystems/form/advanced/checkbox-controller.md index 2a212175e..3f7c3961a 100644 --- a/docs/apis/subsystems/form/advanced/checkbox-controller.md +++ b/docs/apis/subsystems/form/advanced/checkbox-controller.md @@ -16,7 +16,8 @@ You can add as many groups of checkboxes as you like, as long as they are unique When adding checkboxes, you can add them in _groups_. Each group of checkboxes must have a unique integer name, for example: ```php title="classes/form/example_form.php" -public function definition(): void { +public function definition(): void +{ // These two elements are part of group 1. $mform->addElement('advcheckbox', 'test1', 'Test 1', null, ['group' => 1]); $mform->addElement('advcheckbox', 'test2', 'Test 2', null, ['group' => 1]); diff --git a/docs/apis/subsystems/form/index.md b/docs/apis/subsystems/form/index.md index 065b76e6a..6a57843ec 100644 --- a/docs/apis/subsystems/form/index.md +++ b/docs/apis/subsystems/form/index.md @@ -41,9 +41,11 @@ namespace [plugintype]_[pluginname]\form; // moodleform is defined in formslib.php require_once("$CFG->libdir/formslib.php"); -class simplehtml_form extends \moodleform { +class simplehtml_form extends \moodleform +{ // Add elements to form. - public function definition() { + public function definition() + { // A reference to the form is stored in $this->form. // A common convention is to store it in a variable, such as `$mform`. $mform = $this->_form; // Don't forget the underscore! @@ -59,7 +61,8 @@ class simplehtml_form extends \moodleform { } // Custom validation should be added here. - function validation($data, $files) { + function validation($data, $files) + { return []; } } @@ -99,12 +102,15 @@ If you wish to use the form within a block then you should consider using the re Note that the render method does the same as the display method, except returning the HTML rather than outputting it to the browser, as with above make sure you've included the file which contains the class for your Moodle form. ```php -class block_yourblock extends block_base { - public function init(){ +class block_yourblock extends block_base +{ + public function init() + { $this->title = 'Your Block'; } - public function get_content(){ + public function get_content() + { $this->content = (object) [ 'text' => '', ]; @@ -237,7 +243,8 @@ public function add_action_buttons( The `add_action_buttons` function is defined on the `moodleform` class, and not a part of `$this->_form`, for example: ```php - public function definition() { + public function definition() + { // Add your form elements here. $this->_form->addElement(...); @@ -296,7 +303,8 @@ In some cases this is not the desired behaviour, in which case the [disable_form For example: ```php -public function definition() { +public function definition() +{ // Your definition goes here. // Disable the form change checker for this form. @@ -313,7 +321,8 @@ Only header names would be accepted and added to `_shownonlyelements` array. Headers included in `_shownonlyelements` will be shown expanded in the form. The rest of the headers will be hidden. ```php -public function filter_shown_headers(array $shownonly): void { +public function filter_shown_headers(array $shownonly): void +{ $this->_shownonlyelements = []; if (empty($shownonly)) { return; diff --git a/docs/apis/subsystems/form/usage/index.md b/docs/apis/subsystems/form/usage/index.md index 0369cddb1..f1fc7de14 100644 --- a/docs/apis/subsystems/form/usage/index.md +++ b/docs/apis/subsystems/form/usage/index.md @@ -79,7 +79,8 @@ In most cases you can place this in an auto-loadable class, in which case it sho namespace mod_forum\form; -class myform extends \moodleform { +class myform extends \moodleform +{ // ... } ``` @@ -127,8 +128,10 @@ Moodle has a set of standard form elements used by all Activity modules. These a The `standard_coursemodule_elements()` function is used to add these common elements, and it should be called _before_ the standard action elements are added, for example: ```php -class mod_example_mod_form extends \moodleform_mod { - public function definition() { +class mod_example_mod_form extends \moodleform_mod +{ + public function definition() + { // Add the various form elements. $this->_form->addElement( ... ); diff --git a/docs/apis/subsystems/output/index.md b/docs/apis/subsystems/output/index.md index af2615519..acd8b8fb2 100644 --- a/docs/apis/subsystems/output/index.md +++ b/docs/apis/subsystems/output/index.md @@ -115,20 +115,23 @@ In the example above, we used `$PAGE->get_renderer('tool_demo')` to get an insta Instead, you can use the `core\output\renderer_helper` class to get any renderer instance without using the global. This is an example of how to use the `renderer_helper` class to get a renderer instance: ```php -class my_di_example { +class my_di_example +{ public function __construct( /** @var \core\output\renderer_helper $rendererhelper the renderer helper */ protected readonly \core\output\renderer_helper $rendererhelper, ) { } - public function do_something_with_my_renderer() { + public function do_something_with_my_renderer() + { /** @var \tool_demo\output\renderer $renderer */ $renderer = $this->rendererhelper->get_renderer('tool_demo'); // Do something with the renderer. } - public function do_something_with_core_renderer() { + public function do_something_with_core_renderer() + { // For convenience, the renderer helper also provides a method to get the core renderer. $renderer = $this->rendererhelper->get_core_renderer(); // Do something with the core renderer. @@ -157,11 +160,13 @@ use renderer_base; use templatable; use stdClass; -class index_page implements renderable, templatable { +class index_page implements renderable, templatable +{ /** @var string $sometext Some text to show how to pass data to a template. */ private $sometext = null; - public function __construct($sometext): void { + public function __construct($sometext): void + { $this->sometext = $sometext; } @@ -170,7 +175,8 @@ class index_page implements renderable, templatable { * * @return stdClass */ - public function export_for_template(renderer_base $output): stdClass { + public function export_for_template(renderer_base $output): stdClass + { $data = new stdClass(); $data->sometext = $this->sometext; return $data; @@ -193,7 +199,8 @@ If you wish to use a specific template to render the content you may specify any * * @return string */ - public function get_template_name(\renderer_base $renderer): string { + public function get_template_name(\renderer_base $renderer): string + { return 'tool_demo/index_page'; } ``` @@ -208,7 +215,8 @@ namespace tool_demo\output; use plugin_renderer_base; -class renderer extends plugin_renderer_base { +class renderer extends plugin_renderer_base +{ /** * Defer to template. * @@ -216,7 +224,8 @@ class renderer extends plugin_renderer_base { * * @return string html for the page */ - public function render_index_page($page): string { + public function render_index_page($page): string + { $data = $page->export_for_template($this); return parent::render_from_template('tool_demo/index_page', $data); } @@ -474,11 +483,13 @@ mtrace('DONE'); Or a scheduled or adhoc task, via a trait. Example: ```php -class stored_progress_scheduled_task_example extends \core\task\scheduled_task { +class stored_progress_scheduled_task_example extends \core\task\scheduled_task +{ use \core\task\stored_progress_task_trait; - public function execute() { + public function execute() + { // This simulates a specific count of iterations the task will do, e.g. x number of courses to loop through and do something. $iterations = 100; @@ -537,7 +548,8 @@ use core_courseformat\base as course_format; use mod_MYPLUGIN\external\myname_exporter; use stdClass; -class myname implements externable, named_templatable, renderable { +class myname implements externable, named_templatable, renderable +{ public function __construct( /** @var cm_info The course module. */ public cm_info $cm, @@ -545,7 +557,8 @@ class myname implements externable, named_templatable, renderable { } #[\Override] - public function export_for_template(renderer_base $output): stdClass { + public function export_for_template(renderer_base $output): stdClass + { // This method is used to prepare data for rendering in a template. // It is related to the `templatable` interface and could return an object or array. $cm = $this->cm; @@ -562,14 +575,16 @@ class myname implements externable, named_templatable, renderable { } #[\Override] - public function get_template_name(renderer_base $renderer): string { + public function get_template_name(renderer_base $renderer): string + { // This method is used to specify the template name for rendering. // It is not used for webservice clients, but it is required by the named_templatable interface. return 'core_courseformat/local/overview/activityname'; } #[\Override] - public function get_exporter(?\core\context $context = null): myname_exporter { + public function get_exporter(?\core\context $context = null): myname_exporter + { $context = $context ?? \core\context\system::instance(); return new myname_exporter($this, ['context' => $context]); } @@ -583,7 +598,8 @@ class myname implements externable, named_templatable, renderable { } #[\Override] - public static function read_properties_definition(): array { + public static function read_properties_definition(): array + { return myname_exporter::read_properties_definition(); } @@ -614,7 +630,8 @@ namespace mod_MYPLUGIN\external; use core\external\exporter; use mod_MYPLUGIN\output\myname; -class myname_exporter extends exporter { +class myname_exporter extends exporter +{ /** * Constructor with parameter type hints. * @@ -629,12 +646,14 @@ class myname_exporter extends exporter { } #[\Override] - protected static function define_properties(): array { + protected static function define_properties(): array + { return []; } #[\Override] - protected static function define_related() { + protected static function define_related() + { // Most exporter need to define the context as related data to parse texts. return [ 'context' => 'context', @@ -642,7 +661,8 @@ class myname_exporter extends exporter { } #[\Override] - protected static function define_other_properties() { + protected static function define_other_properties() + { return [ 'activityname' => [ 'type' => PARAM_TEXT, @@ -663,7 +683,8 @@ class myname_exporter extends exporter { } #[\Override] - protected function get_other_values(\renderer_base $output) { + protected function get_other_values(\renderer_base $output) + { /** @var \cm_info $cm */ $cm = $this->data->cm; @@ -694,14 +715,17 @@ use core\output\renderer_helper; use mod_MYPLUGIN\output\myname; use stdClass; -class get_my_name extends external_api { - public static function execute_parameters(): external_function_parameters { +class get_my_name extends external_api +{ + public static function execute_parameters(): external_function_parameters + { return new external_function_parameters([ 'cmid' => new external_value(PARAM_INT, 'Course module id', VALUE_REQUIRED), ]); } - public static function execute(int $cmid): stdClass { + public static function execute(int $cmid): stdClass + { [ 'cmid' => $cmid, ] = external_api::validate_parameters(self::execute_parameters(), [ @@ -727,7 +751,8 @@ class get_my_name extends external_api { * * @return external_single_structure */ - public static function execute_returns(): external_single_structure { + public static function execute_returns(): external_single_structure + { return myname::get_read_structure(); } } diff --git a/docs/apis/subsystems/output/inplace.md b/docs/apis/subsystems/output/inplace.md index fa1bfdf99..dc7f5c5f0 100644 --- a/docs/apis/subsystems/output/inplace.md +++ b/docs/apis/subsystems/output/inplace.md @@ -17,7 +17,8 @@ The best way is to explain the usage on a simple example. Imagine we have plugin Define a callback in `/admin/tool/mytest/lib.php` that starts with the plugin name and ends with `_inplace_editable`: ```php title="admin/tool/mytest/lib.php" -function tool_mytest_inplace_editable($itemtype, $itemid, $newvalue) { +function tool_mytest_inplace_editable($itemtype, $itemid, $newvalue) +{ global $DB; if ($itemtype === 'mytestname') { @@ -80,13 +81,15 @@ This was a very simplified example, in the real life you will probably want to: ```php title="admin/tool/mytest/classes/local/inplace_edit_text.php" -class inplace_edit_text extends \core\output\inplace_editable { +class inplace_edit_text extends \core\output\inplace_editable +{ /** * Constructor. * * @param object $record */ - public function __construct($record) { + public function __construct($record) + { parent::__construct( component: 'tool_mytest', // The item type as managed your plugin. @@ -119,7 +122,8 @@ class inplace_edit_text extends \core\output\inplace_editable { * @param mixed $newvalue * @return \self */ - public static function update($itemid, $newvalue) { + public static function update($itemid, $newvalue) + { // Clean the new value. $newvalue = clean_param($newvalue, PARAM_INT); @@ -194,13 +198,15 @@ $tmpl->set_type_toggle([0, 1]);
```php title="admin/tool/mytest/classes/local/inplace_edit_select.php" -class inplace_edit_select extends \core\output\inplace_editable { +class inplace_edit_select extends \core\output\inplace_editable +{ /** * Constructor. * * @param \stdClass $record */ - public function __construct($record) { + public function __construct($record) + { // Get the options for inplace_edit select box. // The array needs the format: // $options = [ @@ -241,7 +247,8 @@ class inplace_edit_select extends \core\output\inplace_editable { * @param mixed $newvalue * @return \self */ - public static function update($itemid, $newvalue) { + public static function update($itemid, $newvalue) + { // Clean the new value. $newvalue = clean_param($newvalue, PARAM_INT); diff --git a/docs/apis/subsystems/privacy/index.md b/docs/apis/subsystems/privacy/index.md index 83e341479..35c99c1b4 100644 --- a/docs/apis/subsystems/privacy/index.md +++ b/docs/apis/subsystems/privacy/index.md @@ -119,7 +119,8 @@ class provider implements * * @return string */ - public static function get_reason(): string { + public static function get_reason(): string + { return 'privacy:metadata'; } } @@ -179,7 +180,8 @@ class provider implements // This plugin does store personal user data. \core_privacy\local\metadata\provider { - public static function get_metadata(collection $collection): collection { + public static function get_metadata(collection $collection): collection + { // Here you will add more items into the collection. @@ -214,7 +216,8 @@ Some subsystems which store user data do not need to be listed: ##### Example {/* #example-2 */} ```php title="mod/forum/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_subsystem_link( 'core_files', @@ -243,7 +246,8 @@ It is a matter of judgement which fields contain user data and which don't. Anyt ##### Example {/* #example-3 */} ```php title="mod/forum/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_database_table( 'forum_discussion_subs', @@ -291,7 +295,8 @@ Any plugin providing user preferences must also implement the `\core_privacy\loc ##### Example {/* #example-4 */} ```php title="admin/tool/usertours/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_user_preference('tool_usertours_tour_completion_time', 'privacy:metadata:preference:tool_usertours_tour_completion_time'); @@ -318,7 +323,8 @@ You can indicate this by calling the `add_external_location_link()` method on th ##### Example {/* #example-5 */} ```php title="mod/lti/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_external_location_link('lti_client', [ 'userid' => 'privacy:metadata:lti_client:userid', 'fullname' => 'privacy:metadata:lti_client:fullname', @@ -385,15 +391,16 @@ if (interface_exists('\core_privacy\local\request\userlist')) { } -class provider implements my_userlist { +class provider implements my_userlist +{ /** * Get the list of users who have data within a context. * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ - public static function get_users_in_context(userlist $userlist) { - + public static function get_users_in_context(userlist $userlist) + { } /** @@ -401,8 +408,8 @@ class provider implements my_userlist { * * @param approved_userlist $userlist The approved context and user information to delete information for. */ - public static function delete_data_for_users(approved_userlist $userlist) { - + public static function delete_data_for_users(approved_userlist $userlist) + { } } @@ -421,7 +428,9 @@ Contexts are retrieved using the `get_contexts_for_userid` function which takes * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist {} +public static function get_contexts_for_userid(int $userid): contextlist +{ +} ``` The function returns a `\core_privacy\local\request\contextlist` which is used to keep a set of contexts together in a fixed fashion. @@ -443,7 +452,8 @@ The following example simply fetches the contextid for all forums where a user h * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist { +public static function get_contexts_for_userid(int $userid): contextlist +{ $contextlist = new \core_privacy\local\request\contextlist(); $sql = "SELECT c.id @@ -490,7 +500,8 @@ In the case of the rating data, this will include any post where the user has ra * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist { +public static function get_contexts_for_userid(int $userid): contextlist +{ $ratingsql = \core_rating\privacy\provider::get_sql_join('rat', 'mod_forum', 'post', 'p.id', $userid); // Fetch all forum discussions, and forum posts. $sql = "SELECT c.id @@ -555,7 +566,9 @@ This method is very similar to the `get_contexts_for_userid` function but has so * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ -public static function get_users_in_context(userlist $userlist) {} +public static function get_users_in_context(userlist $userlist) +{ +} ``` ###### Basic example {/* #basic-example-1 */} @@ -568,8 +581,8 @@ The following example simply fetches the userid for all users in a given forum c * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ -public static function get_users_in_context(userlist $userlist) { - +public static function get_users_in_context(userlist $userlist) +{ $context = $userlist->get_context(); if (!$context instanceof \context_module) { @@ -616,7 +629,9 @@ This is achieved through use of the `export_user_data` function which takes the * * @param approved_contextlist $contextlist The approved contexts to export information for. */ -public static function export_user_data(approved_contextlist $contextlist) {} +public static function export_user_data(approved_contextlist $contextlist) +{ +} ``` The `approved_contextlist` includes both the user record, and a list of contexts, which can be retrieved by either processing it as an Iterator, or by calling `get_contextids()` or `get_contexts()` as required. @@ -642,7 +657,8 @@ You need to provide a description of the value of the user preference. (This des * * @param int $userid The userid of the user whose data is to be exported. */ -public static function export_user_preferences(int $userid) { +public static function export_user_preferences(int $userid) +{ $markasreadonnotification = get_user_preferences('markasreadonnotification', null, $userid); if (null !== $markasreadonnotification) { switch ($markasreadonnotification) { @@ -829,7 +845,8 @@ When expiring content for a high-level context such as a course context, the fun * * @param context $context Context to delete data from. */ -public static function delete_data_for_all_users_in_context(\context $context) { +public static function delete_data_for_all_users_in_context(\context $context) +{ global $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -850,7 +867,8 @@ public static function delete_data_for_all_users_in_context(\context $context) { An *approved_contextlist* is given and user data related to that user should either be completely deleted, or overwritten if a structure needs to be maintained. This will be called when a user has requested the right to be forgotten. All attempts should be made to delete this data where practical while still allowing the plugin to be used by other users. ```php title="mod/choice/classes/privacy/provider.php" -public static function delete_data_for_user(approved_contextlist $contextlist) { +public static function delete_data_for_user(approved_contextlist $contextlist) +{ global $DB; if (empty($contextlist->count())) { @@ -874,7 +892,8 @@ An *approved_userlist* is given and user data related to all users in the specif * * @param approved_userlist $userlist The approved context and user information to delete information for. */ -public static function delete_data_for_users(approved_userlist $userlist) { +public static function delete_data_for_users(approved_userlist $userlist) +{ global $DB; $context = $userlist->get_context(); @@ -915,7 +934,8 @@ class provider implements use \core_privacy\local\legacy_polyfill; // The required methods must be in this format starting with an underscore. - public static function _get_metadata(collection $collection) { + public static function _get_metadata(collection $collection) + { // Code for returning metadata goes here. } ``` @@ -943,12 +963,14 @@ class provider implements use \core_plagiarism\privacy\plagiarism_provider\legacy_polyfill; // The required methods must be in this format starting with an underscore. - public static function _get_metadata(collection $collection) { + public static function _get_metadata(collection $collection) + { // Code for returning metadata goes here. } // This is one of the polyfilled methods from the plagiarism provider. - public static function _export_plagiarism_user_data($userid, \context $context, array $subcontext, array $linkarray) { + public static function _export_plagiarism_user_data($userid, \context $context, array $subcontext, array $linkarray) + { // ... } ``` @@ -969,7 +991,8 @@ if (interface_exists('\core_privacy\local\request\core_userlist_provider')) { interface core_userlist_provider {} } -class provider implements core_userlist_provider { +class provider implements core_userlist_provider +{ ``` ## Tips for development {/* #tips-for-development */} diff --git a/docs/apis/subsystems/privacy/utils.md b/docs/apis/subsystems/privacy/utils.md index fdbcfb74f..c47c10086 100644 --- a/docs/apis/subsystems/privacy/utils.md +++ b/docs/apis/subsystems/privacy/utils.md @@ -108,7 +108,8 @@ foreach ($list->good as $component) { echo "\n\n== Done ==\n"; -function check_implements($component, $interface) { +function check_implements($component, $interface) +{ $manager = new \core_privacy\manager(); $rc = new \ReflectionClass(\core_privacy\manager::class); $rcm = $rc->getMethod('component_implements'); diff --git a/docs/apis/subsystems/routing/index.md b/docs/apis/subsystems/routing/index.md index 38b150921..bce11a503 100644 --- a/docs/apis/subsystems/routing/index.md +++ b/docs/apis/subsystems/routing/index.md @@ -54,7 +54,8 @@ use core\router\schema\response\payload_response; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -class example { +class example +{ #[\core\router\route( // Resolves to https://example.com/moodle/api/rest/v2/mod_example/example path: '/example', diff --git a/docs/apis/subsystems/routing/parameters.md b/docs/apis/subsystems/routing/parameters.md index 75474757b..b57c1a944 100644 --- a/docs/apis/subsystems/routing/parameters.md +++ b/docs/apis/subsystems/routing/parameters.md @@ -36,7 +36,8 @@ use core\param; use core\router\route; use core\router\schema\parameters\path_parameter; -class example { +class example +{ #[route( path: '/users/{username}', pathtypes: [ @@ -70,7 +71,8 @@ use core\param; use core\router\route; use core\router\schema\parameters\path_parameter; -class example { +class example +{ #[route( path: '/users/{username}', pathtypes: [ @@ -533,7 +535,8 @@ class path_course extends \core\router\schema\parameters\path_parameter implemen * @return object * @throws not_found_exception If the course cannot be found */ - protected function get_course_for_value(string $value): mixed { + protected function get_course_for_value(string $value): mixed + { global $DB; $data = false; @@ -572,7 +575,8 @@ class path_course extends \core\router\schema\parameters\path_parameter implemen } #[\Override] - public function get_schema_from_type(param $type): \stdClass { + public function get_schema_from_type(param $type): \stdClass + { $schema = parent::get_schema_from_type($type); $schema->pattern = "^("; diff --git a/docs/apis/subsystems/routing/responses.md b/docs/apis/subsystems/routing/responses.md index 64f7c8f50..6118fd23e 100644 --- a/docs/apis/subsystems/routing/responses.md +++ b/docs/apis/subsystems/routing/responses.md @@ -49,7 +49,8 @@ use core\router\schema\response\payload_response; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -class example { +class example +{ #[\core\router\route( // Resolves to https://example.com/moodle/api/rest/v2/mod_example/example path: '/example', diff --git a/docs/apis/subsystems/routing/shortlinks.md b/docs/apis/subsystems/routing/shortlinks.md index bd90f632c..af7202bad 100644 --- a/docs/apis/subsystems/routing/shortlinks.md +++ b/docs/apis/subsystems/routing/shortlinks.md @@ -76,9 +76,11 @@ Each component using shortlinks will need to have a `shortlink_handler` class. T - `process_shortlink()` ```php -class shortlink_handler implements shortlink_handler_interface { +class shortlink_handler implements shortlink_handler_interface +{ #[\Override] - public function get_valid_linktypes(): array { + public function get_valid_linktypes(): array + { return [ 'view', ]; diff --git a/docs/apis/subsystems/routing/testing.md b/docs/apis/subsystems/routing/testing.md index a698b1c51..79f248815 100644 --- a/docs/apis/subsystems/routing/testing.md +++ b/docs/apis/subsystems/routing/testing.md @@ -22,8 +22,10 @@ You can quickly and easily create a copy of the Moodle Router using the `route_t This is a fully-configured copy of the Moodle Router, and allows to handle requests directly. ```php -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $router = $this->get_router(); } } @@ -56,8 +58,10 @@ You can easily add existing routes to mocking route loader either individually, To add an individual route, you can use the `\route_testcase::add_route_to_route_loader()` method, for example: ```php title="Adding a single route to the route loader" -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $this->add_route_to_route_loader( my_route::class, 'my_route_method', @@ -71,8 +75,10 @@ final class my_test extends \route_testcase { You can also add all routes in a class to the route loader using the `\route_testcase::add_class_routes_to_route_loader()` method, for example: ```php title="Adding all routes in a class to the route loader" -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $this->add_class_routes_to_route_loader( my_route::class, ); @@ -90,7 +96,8 @@ The `\route_testcase` also includes several methods to simplify generating a Req You can create a request and manually pass it to Router using the `\route_testcase::create_request()` method, for example: ```php title="Creating an example request and processing it" -public function test_example(): void { +public function test_example(): void +{ $this->add_class_routes_to_route_loader( my_route::class, ); @@ -114,7 +121,8 @@ When creating a request the default is to use the Route Group for the REST API, The `\route_testcase::process_request()` and `\route_testcsae::process_api_request()` methods act as a shortcut for creating the request, fetching the router, and the app, and handling the request to return a response. The above example can therefore be simplified to: ```php title="Creating and processing an example request" -public function test_example(): void { +public function test_example(): void +{ $this->add_class_routes_to_route_loader( my_route::class, ); @@ -131,7 +139,8 @@ All of these methods also accept: As an example, to call the route `/api/rest/v2/question/bank/{course}/question_counts`, you would do the following: ```php title="Creating and processing a question_counts request" -public function test_question_counts(): void { +public function test_question_counts(): void +{ $this->resetAfterTest(); $course = self::getDataGenerator()->create_course(); diff --git a/docs/apis/subsystems/tag/index.md b/docs/apis/subsystems/tag/index.md index a847586f5..6b5a97652 100644 --- a/docs/apis/subsystems/tag/index.md +++ b/docs/apis/subsystems/tag/index.md @@ -151,7 +151,8 @@ If you have created a course activity that uses tags you should also remember to * * @param moodleform $mform */ -function book_reset_course_form_definition(&$mform) { +function book_reset_course_form_definition(&$mform) +{ $mform->addElement('header', 'bookheader', get_string('modulenameplural', 'book')); $mform->addElement('checkbox', 'reset_book_tags', get_string('removeallbooktags', 'book')); } @@ -161,7 +162,8 @@ function book_reset_course_form_definition(&$mform) { * @param $data the data submitted from the reset course. * @return array status array */ -function book_reset_userdata($data) { +function book_reset_userdata($data) +{ global $DB; $status = []; @@ -207,7 +209,8 @@ When you tag contents inside the course the plugin has to hook into backup and r You can choose to backup and restore tags for each item individually (as it is done in mod_wiki) OR backup all tags in the context at once (as it is done in mod_glossary or mod_forum). Second option is preferable for performance reasons. Make sure to take into account `$userinfo` (whether user information is backed up / restored), for example wiki pages is not user information but glossary entries are, tags on them follow the same rule. ```php title="mod/glossary/backup_glossary_stepslib.php" -protected function define_structure() { +protected function define_structure() +{ // ... $tags = new backup_nested_element('entriestags'); $tag = new backup_nested_element('tag', ['id'], ['itemid', 'rawname']); @@ -232,7 +235,8 @@ protected function define_structure() { ``` ```php title="mod/glossary/restore_glossary_stepslib.php" -protected function define_structure() { +protected function define_structure() +{ // ... if ($userinfo) { $paths[] = new restore_path_element('glossary_entry_tag', '/activity/glossary/entriestags/tag'); @@ -240,7 +244,8 @@ protected function define_structure() { // ... } -protected function process_glossary_entry_tag($data) { +protected function process_glossary_entry_tag($data) +{ $data = (object)$data; if (!core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) { // Tags disabled on this site, nothing to process. @@ -265,7 +270,8 @@ Given a user searches for any items tagged with a specified tag, only the items To limit the performance impact of checking user access against items the following class ``core_tag_index_builder()`` can assist with the retrieval and caching of records, especially within both course and activity modules. ```php -function mod_wiki_get_tagged_pages($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0) { +function mod_wiki_get_tagged_pages($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0) +{ // Find items. // Please refer to existing callbacks in core for examples. diff --git a/docs/apis/subsystems/task/adhoc.md b/docs/apis/subsystems/task/adhoc.md index 0dd508de0..5d057312d 100644 --- a/docs/apis/subsystems/task/adhoc.md +++ b/docs/apis/subsystems/task/adhoc.md @@ -38,12 +38,13 @@ namespace mod_example\task; /** * An example of an adhoc task. */ -class do_something extends \core\task\adhoc_task { - +class do_something extends \core\task\adhoc_task +{ /** * Execute the task. */ - public function execute() { + public function execute() + { // Call your own api } } @@ -62,8 +63,8 @@ It can be fetched using the `get_custom_data(): mixed` method. We recommend only ever calling `set_custom_data()` from within a factory method in the task class itself. ```php -class do_something extends \core\task\adhoc_task { - +class do_something extends \core\task\adhoc_task +{ public static function instance( int $id, string $status, @@ -77,7 +78,8 @@ class do_something extends \core\task\adhoc_task { return $task; } - public function execute() { + public function execute() + { $data = $this->get_custom_data(); mtrace($data->id); mtrace($data->status); @@ -177,7 +179,8 @@ $task->get_attempts_available(); Tasks are retried by default, but this behaviour can be modified by overriding the `retry_until_success()` method in your task class, for example: ```php -public function retry_until_success(): bool { +public function retry_until_success(): bool +{ return false; } ``` diff --git a/docs/apis/subsystems/task/index.md b/docs/apis/subsystems/task/index.md index 4689e0e5a..e6d746e05 100644 --- a/docs/apis/subsystems/task/index.md +++ b/docs/apis/subsystems/task/index.md @@ -92,8 +92,10 @@ Since Moodle 3.5 it is safe to use the [Output API](../output/index.md) in cron In order to improve debugging information, it is good practice to call `mtrace` to log what's going on within a task execution: ```php -class my_task extends \core\task\scheduled_task { - public function execute() { +class my_task extends \core\task\scheduled_task +{ + public function execute() + { mtrace("My task started"); // Do some work. diff --git a/docs/apis/subsystems/task/scheduled.md b/docs/apis/subsystems/task/scheduled.md index b29072d9e..7d286c859 100644 --- a/docs/apis/subsystems/task/scheduled.md +++ b/docs/apis/subsystems/task/scheduled.md @@ -37,21 +37,24 @@ namespace mod_example\task; /** * An example of a scheduled task. */ -class do_something extends \core\task\scheduled_task { +class do_something extends \core\task\scheduled_task +{ /** * Return the task's name as shown in admin screens. * * @return string */ - public function get_name() { + public function get_name() + { return get_string('dosomething', 'mod_example'); } /** * Execute the task. */ - public function execute() { + public function execute() + { // Call your own api } } diff --git a/docs/guides/templates/index.md b/docs/guides/templates/index.md index 83161f69d..c9bcce802 100644 --- a/docs/guides/templates/index.md +++ b/docs/guides/templates/index.md @@ -397,7 +397,8 @@ The following example shows a renderable using the `mywidget.mustache` template * @param renderer_base $output * @return stdClass */ -public function export_for_template(renderer_base $output) { +public function export_for_template(renderer_base $output) +{ $data = new stdClass(); $data->canmanage = $this->canmanage; $data->things = []; @@ -424,7 +425,8 @@ Example of the method added to tell a renderable to use the `mywidget.mustache` * @param renderer_base $output * @return string */ -public function get_template_name(\renderer_base $renderer): string { +public function get_template_name(\renderer_base $renderer): string +{ return 'tool_myplugin/mywidget'; } ``` @@ -445,7 +447,8 @@ The rendering method can now use templates to render the object: * * @return string HTML */ -protected function render_mywidget(mywidget $widget) { +protected function render_mywidget(mywidget $widget) +{ $data = $widget->export_for_template($this); return $this->render_from_template('tool_myplugin/mywidget', $data); } diff --git a/docs/guides/testing/index.md b/docs/guides/testing/index.md index d0dd4ce9d..9b77c112d 100644 --- a/docs/guides/testing/index.md +++ b/docs/guides/testing/index.md @@ -74,8 +74,10 @@ For example: ```php title="mod/myplugin/tests/sample_test.php" namespace mod_myplugin; - class sample_test extends \advanced_testcase { - public function test_adding() { + class sample_test extends \advanced_testcase + { + public function test_adding() + { $this->assertEquals(2, 1+2); } } @@ -101,8 +103,10 @@ If you modify data and _do not_ call `$this->resetAfterTest()` then you will rec ```php title="Demonstration of database reset" namespace mod_myplugin; - class test_something extends \advanced_testcase { - public function test_deleting() { + class test_something extends \advanced_testcase + { + public function test_deleting() + { global $DB; $this->resetAfterTest(true); @@ -110,7 +114,8 @@ If you modify data and _do not_ call `$this->resetAfterTest()` then you will rec $this->assertEmpty($DB->get_records('user')); } - public function test_user_table_was_reset() { + public function test_user_table_was_reset() + { global $DB; $this->assertEquals(2, $DB->count_records('user', array())); @@ -592,12 +597,15 @@ When defining coverage for a specific method under test, it must be either: /** * @coversDefaultClass \mod_myplugin\example */ -class example_test extends \advanced_testcase { +class example_test extends \advanced_testcase +{ /** * This test will cover \mod_myplugin\example::some_method * @covers ::some_method */ - public function test_some_method(): void {} + public function test_some_method(): void + { + } } ``` @@ -711,7 +719,8 @@ However, the following rules should be followed when using dataProviders: * @param int $foor * @param int $bar */ -public function test_foobar(int $foo, int $bar) { +public function test_foobar(int $foo, int $bar) +{ // Perform the tests here. } @@ -720,7 +729,8 @@ public function test_foobar(int $foo, int $bar) { * * @return array List of data sets - (string) data set name => (array) data */ -public function foobar_provider(): \Generator { +public function foobar_provider(): \Generator +{ yield 'Same numbers' => [ 'foo' => 42, 'bar' => 42, diff --git a/docs/guides/upgrade/index.md b/docs/guides/upgrade/index.md index c3658f5b6..59abf5438 100644 --- a/docs/guides/upgrade/index.md +++ b/docs/guides/upgrade/index.md @@ -52,7 +52,8 @@ The following example shows the structure of the upgrade.php file: ```php title="Example upgrade.php file" get_manager(); // Loads ddl manager and xmldb classes. @@ -161,7 +162,8 @@ For example, if you are defining an installation behaviour in the `install.php` new external_value(PARAM_RAW_TRIMMED, 'Name'), ]); } - public static function execute($name) { + public static function execute($name) + { $validatedparams = self::validate_parameters(self::execute_parameters(), compact('name')); [$name] = array_values($validatedparams); return ['message' => "Hello, $name!"]; } - public static function execute_returns(): external_description { + public static function execute_returns(): external_description + { return new external_single_structure([ 'message' => new external_value(PARAM_RAW, 'Message'), ]); @@ -180,7 +186,8 @@ In some situations, you may need to submit dynamic data. This means that field n One challenge with this approach is that Moodle Web Services don't accept dynamic parameters, so we'll need to send them in an array of objects with the field names and values: ```php title="classes/external/submit.php" -public static function execute_parameters(): external_function_parameters { +public static function execute_parameters(): external_function_parameters +{ return new external_single_structure([ 'data' => new external_multiple_structure( new external_single_structure( diff --git a/general/app/development/plugins-development-guide/examples/question-types.md b/general/app/development/plugins-development-guide/examples/question-types.md index 80444a4a3..b17363212 100644 --- a/general/app/development/plugins-development-guide/examples/question-types.md +++ b/general/app/development/plugins-development-guide/examples/question-types.md @@ -35,9 +35,11 @@ $addons = [ ``` ```php title="classes/output/mobile.php" -class mobile { +class mobile +{ - public static function mobile_get_YOURQTYPENAME() { + public static function mobile_get_YOURQTYPENAME() + { global $OUTPUT, $CFG; $html = $OUTPUT->render_from_template('qtype_YOURQTYPENAME/mobileapp/mobile', []); diff --git a/general/app/development/plugins-development-guide/index.md b/general/app/development/plugins-development-guide/index.md index 5b1714b4a..e90c1aa24 100644 --- a/general/app/development/plugins-development-guide/index.md +++ b/general/app/development/plugins-development-guide/index.md @@ -67,9 +67,11 @@ namespace local_hello\output; defined('MOODLE_INTERNAL') || die(); -class mobile { +class mobile +{ - public static function view_hello() { + public static function view_hello() + { return [ 'templates' => [ [ @@ -133,7 +135,8 @@ Most handlers will render some custom UI using the `method` property in their co Templates will be rendered in the app using Angular, but you can still process them using mustache in your PHP code by using `$OUTPUT->render_from_template`. However, keep in mind that the `{{ }}` syntax is also used for interpolating values in Angular. We recommend switching Mustache's interpolation syntax in mobile templates to `<% %>`. This can be achieved by adding `{{=<% %>=}}` at the beginning of the file. Here's an example: ```php title="method in classes/output/mobile.php" -public static function mobile_course_view($args) { +public static function mobile_course_view($args) +{ global $OUTPUT; return [ @@ -286,7 +289,8 @@ You can find which APIs are available in JavaScript in the [Services](./api-refe Here's an example using `templates`, `otherdata`, and custom properties: ```php title="PHP init method" -public static function my_init() { +public static function my_init() +{ return [ 'templates' => [ [ diff --git a/general/development/policies/codingstyle/index.md b/general/development/policies/codingstyle/index.md index 855b1587e..332eadbc2 100644 --- a/general/development/policies/codingstyle/index.md +++ b/general/development/policies/codingstyle/index.md @@ -207,8 +207,10 @@ Class names should always be lower-case English words, separated by underscores: ```php -class some_custom_class { - function class_method() { +class some_custom_class +{ + function class_method() + { echo 'foo'; } } @@ -273,9 +275,11 @@ Verbosity is encouraged: function names should be as illustrative as is practica When writing a method which overrides a method in a parent Class, Interface, or Trait, it is strongly recommended that the `#[\Override]` attribute be used, for example: ```php title="Example of a method which overrides a third-party method" -class example extends \Some\Vendor\ExampleClass { +class example extends \Some\Vendor\ExampleClass +{ #[\Override] - public function makeRequest(): void { + public function makeRequest(): void + { // ... } } @@ -296,7 +300,8 @@ There is no space between the function name and the following (brackets). There ```php -function report_participation_get_overviews(string $action, ?int userid): ?array { +function report_participation_get_overviews(string $action, ?int userid): ?array +{ // Actual function code goes here. } ``` @@ -308,7 +313,8 @@ There is an exception for [activity modules](/docs/apis/plugintypes/mod) that st ```php -function forum_set_display_mode($mode = 0) { +function forum_set_display_mode($mode = 0) +{ global $USER, $CFG; // Actual function code goes here. @@ -430,17 +436,21 @@ The use of a [Frankenstyle prefix on class names](./frankenstyle.md#class-names) // A namespace for the `mod_forum` plugin. namespace mod_forum; -class example { +class example +{ } // A namespace for the `external` subsystem usage in the `mod_forum` plugin. namespace mod_forum\external; -class example { +class example +{ } // A namespace for the `core_user` core subsystem. namespace core_user; -class example {} +class example +{ +} ``` @@ -449,13 +459,16 @@ class example {} ```php title="Incorrect use of namespaces" // Namespaced classes are no longer allowed for new code, except where it is unavoidable. -class mod_forum_example { +class mod_forum_example +{ } -class mod_forum_external_example { +class mod_forum_external_example +{ } -class core_user_example { +class core_user_example +{ } ``` @@ -479,7 +492,8 @@ The use of namespaces must conform to the following rules: namespace mod_porridge\local\equipment; -class spoon { +class spoon +{ // Your code here. } ``` @@ -494,13 +508,15 @@ BAD: @@ -1723,7 +1742,8 @@ All classes must have a complete docblock like this: * @copyright 2008 Kim Bloggs * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class policy_issue { +class policy_issue +{ ``` @@ -1739,7 +1759,8 @@ All properties should have a docblock with the following minimum information: ```php -class example { +class example +{ /** @var string This variable does something */ protected $something; } @@ -1752,7 +1773,8 @@ or ```php -class example { +class example +{ /** * This variable does something and has a very long description which can * wrap on multiple lines @@ -1769,7 +1791,8 @@ Even if there are several properties all sharing something in common, do not use ```php -class zebra { +class zebra +{ /** @var int The number of white stripes */ protected $whitestripes = 0; @@ -1790,7 +1813,8 @@ Class constants should be documented in the following way: ```php -class sam { +class sam +{ /** * This is used when Sam is in a good mood. */ @@ -1832,10 +1856,12 @@ An exception is made for overridden methods which make no change to the meaning ```php -class example implements templatable { +class example implements templatable +{ #[\Override] - public function export_for_template(renderer_base $output) { + public function export_for_template(renderer_base $output) + { return ['foo' => 'bar']; } } @@ -1873,7 +1899,8 @@ The first line of the comment must begin with a capital letter (or a digit, or ' ```php -function forum_get_ratings_mean($postid, $scale, $ratings = null) { +function forum_get_ratings_mean($postid, $scale, $ratings = null) +{ if (!$ratings) { $ratings = []; // Initialize the empty array. diff --git a/general/development/policies/deprecation/icon-deprecation.md b/general/development/policies/deprecation/icon-deprecation.md index b54d52876..6d5c90e03 100644 --- a/general/development/policies/deprecation/icon-deprecation.md +++ b/general/development/policies/deprecation/icon-deprecation.md @@ -39,7 +39,8 @@ If there is no section for the current version in the `get_deprecated_icons()` m ```php title="lib/classes/output/icon_system_fontawesome.php" #[\Override] - public function get_deprecated_icons(): array { + public function get_deprecated_icons(): array + { // Add deprecated core icons to parent deprecated icons. return array_merge( parent::get_deprecated_icons(), @@ -61,7 +62,8 @@ If there is no section for the current version in the `get_deprecated_icons()` m * * @return array with the deprecated key icons. */ - function mod_forum_get_deprecated_icons(): array { + function mod_forum_get_deprecated_icons(): array + { return [ // // Deprecated since Moodle 4.5. diff --git a/general/development/policies/deprecation/index.md b/general/development/policies/deprecation/index.md index ddec33e96..9064ebd1c 100644 --- a/general/development/policies/deprecation/index.md +++ b/general/development/policies/deprecation/index.md @@ -77,7 +77,8 @@ Deprecation affects only the current `main` version, in other words, the depreca ```php #[\core\attribute\deprecated('foobar::blah()', since: '4.4', mdl: 'MDL-XXXXX')] -public function foobar(int $old, array $params): array { +public function foobar(int $old, array $params): array +{ \core\deprecation::emit_deprecation_if_present([$this, __FUNCTION__]); // Call new method if possible or retain existing code. return foobar::blah($old, $params); @@ -153,7 +154,8 @@ The final deprecation policy for Moodle LMS has been updated to align more close mdl: 'MDL-XXXXX', final: true, )] -public function foobar(int $old, array $params): array { +public function foobar(int $old, array $params): array +{ \core\deprecation::emit_deprecation_if_present([self::class, __FUNCTION__]); return []; } diff --git a/general/development/tools/behat/writing.md b/general/development/tools/behat/writing.md index f2e26b538..1d5ec38a5 100644 --- a/general/development/tools/behat/writing.md +++ b/general/development/tools/behat/writing.md @@ -292,7 +292,8 @@ For example: * @param string $state The state of the switch * @throws ElementNotFoundException Thrown by behat_base::find */ - public function i_toggle_admin_switch($element, $state) { + public function i_toggle_admin_switch($element, $state) + { // First check we are running Javascript, otherwise explode. if (!$this->running_javascript()) { throw new \Behat\Mink\Exception\DriverException('Switches are only available with JavaScript enabled'); @@ -371,8 +372,10 @@ Full documentation of this process and all available options can be found in the To begin, you need a [generator](/docs/guides/testing/#generators) in `/*your*/*plugin*/tests/generator/lib.php`. If you are generating a type of entity called "thing", your generator will need a method called create_thing, which accepts an object: ```php -class local_myplugin_generator extends component_generator_base { - public function create_thing($thing) { +class local_myplugin_generator extends component_generator_base +{ + public function create_thing($thing) + { global $DB; $DB->insert_record('local_myplugin_things', $thing); } @@ -382,9 +385,11 @@ class local_myplugin_generator extends component_generator_base { Next, you will need to define your behat generator in `/*your*/*plugin*/tests/generator/behat_*your_plugin*_generator.php`, with the `method get_createable_entitites()` method: ```php -class behat_local_myplugin_generator extends behat_generator_base { +class behat_local_myplugin_generator extends behat_generator_base +{ - protected function get_creatable_entities(): array { + protected function get_creatable_entities(): array + { return [ 'things' => [ 'datagenerator' => 'thing', @@ -426,7 +431,8 @@ To deprecate a step, create a new deprecated steps file in `tests/behat/behat_pl Comment count link" named selector. * @todo Final removal in Moodle 6.0 MDL-82413. */ - public function i_should_see_on_the_column(string $linkdata): void { + public function i_should_see_on_the_column(string $linkdata): void + { $this->deprecated_message("Use '\"{$linkdata}\" \"qbank_comment > Comment count link\" should exist'"); $this->execute('behat_general::should_exist', [$linkdata, 'qbank_comment > Comment count link']); } diff --git a/general/development/tools/phpunit/index.md b/general/development/tools/phpunit/index.md index 665cd6105..595163b3b 100644 --- a/general/development/tools/phpunit/index.md +++ b/general/development/tools/phpunit/index.md @@ -227,7 +227,8 @@ namespace qtype_stack; * Unit tests for {@link stack_cas_keyval} @ qtype/stack/tests/cas_keyval_test.php. * @group qtype_stack */ -class cas_keyval_test extends \basic_testcase { +class cas_keyval_test extends \basic_testcase +{ ``` to all the classes in your plugin, then you can run just the tests for your plugin by doing diff --git a/general/development/tools/phpunit/upgrading-11.md b/general/development/tools/phpunit/upgrading-11.md index 1014210d9..c963f8311 100644 --- a/general/development/tools/phpunit/upgrading-11.md +++ b/general/development/tools/phpunit/upgrading-11.md @@ -135,7 +135,8 @@ PHPUnit has always supported _static_ data providers, but also supported non-sta That is, the following was accepted: ```php -protected function my_data_provider(): array { +protected function my_data_provider(): array +{ return [...]; } ``` @@ -165,7 +166,8 @@ The [moodle-cs](../phpcs.md) coding style rules for phpcs can help you to fix th If you have a data provider such as the following: ```php -public static function my_provider(): array { +public static function my_provider(): array +{ return [ [ 'foo' => 'bar', @@ -181,7 +183,8 @@ Then the test that uses this data provider must have the same parameter names: /** * @dataProvider my_provider */ -public function test_my_test(string $foo, string $baz) { +public function test_my_test(string $foo, string $baz) +{ ... } ``` diff --git a/general/development/tools/xmldb.md b/general/development/tools/xmldb.md index 477b514e3..09ca63ff3 100644 --- a/general/development/tools/xmldb.md +++ b/general/development/tools/xmldb.md @@ -36,7 +36,8 @@ After the initial installation of a plugin, for subsequent updates to the plugin ```php $coursemodule->instance]; @@ -224,7 +226,8 @@ First, the function that adds these controls: * @category completion * @return array List of added element names, or names of wrapping group elements. */ -public function add_completion_rules() { +public function add_completion_rules() +{ $mform = $this->_form; @@ -264,7 +267,8 @@ public function add_completion_rules() { return [$this->get_suffixed_name('completionpostsgroup')]; } -protected function get_suffixed_name(string $fieldname): string { +protected function get_suffixed_name(string $fieldname): string +{ return $fieldname . $this->get_suffix(); } ``` @@ -284,7 +288,8 @@ Next, a function for checking whether the user selected this option: * @param array $data Input data not yet validated. * @return bool True if one or more rules is enabled, false if none are. */ -public function completion_rule_enabled($data) { +public function completion_rule_enabled($data) +{ return (!empty($data[$this->get_suffixed_name('completionpostsenabled')]) && $data[$this->get_suffixed_name('completionposts')] != 0); } @@ -295,7 +300,8 @@ public function completion_rule_enabled($data) { That's all the 'required' functions, but we need to add some extra code to support the checkbox behaviour. I overrode `get_data` so that if there is a value in the edit field, but the checkbox is not ticked, the value counts as zero (the rule will not be enabled). ```php -function get_data() { +function get_data() +{ $data = parent::get_data(); if (!$data) { return $data; @@ -316,7 +322,8 @@ You may have noticed the `completionunlocked` check. When some users have alread Finally, forum already had a `data_preprocessing` function but I added code to this to set up the checkboxes when the form is displayed, and to make the default value of the text fields 1 instead of 0: ```php -function data_preprocessing(&$default_values){ +function data_preprocessing(&$default_values) +{ // [Existing code, not shown] // Set up the completion checkboxes which aren't part of standard data. @@ -360,7 +367,8 @@ Here's the function for forum (simplified to include only the one completion opt * @param bool $type Type of comparison (or/and; can be used as return value if no conditions) * @return bool True if completed, false if not, $type if conditions not set. */ - function forum_get_completion_state($course, $cm, $userid, $type) { + function forum_get_completion_state($course, $cm, $userid, $type) + { global $CFG,$DB; // Get forum details @@ -402,7 +410,8 @@ You need to return an array of strings for each completion rule that is active. * @param cm_info|stdClass $cm object with fields ->completion and ->customdata['customcompletionrules'] * @return array $descriptions the array of descriptions for the custom rules. */ -function mod_forum_get_completion_active_rule_descriptions($cm) { +function mod_forum_get_completion_active_rule_descriptions($cm) +{ // Values will be present in cm_info, and we assume these are up to date. if (empty($cm->customdata['customcompletionrules']) || $cm->completion != COMPLETION_TRACKING_AUTOMATIC) { return []; diff --git a/versioned_docs/version-4.5/apis/core/calendar/index.md b/versioned_docs/version-4.5/apis/core/calendar/index.md index 03ca98f0f..11d7f9903 100644 --- a/versioned_docs/version-4.5/apis/core/calendar/index.md +++ b/versioned_docs/version-4.5/apis/core/calendar/index.md @@ -103,7 +103,8 @@ where '$prioritiesforeventtype1' is an associative array that has the timestamp * @param int $lessonid The lesson ID. * @return array|null Array of group override priorities for open and close times. Null if there are no group overrides. */ -function lesson_get_group_override_priorities($lessonid) { +function lesson_get_group_override_priorities($lessonid) +{ global $DB; // Fetch group overrides. @@ -182,7 +183,8 @@ This callback determines if an event should be visible throughout the site. For * @param calendar_event $event * @return bool Returns true if the event is visible to the current user, false otherwise. */ -function mod_assign_core_calendar_is_event_visible(calendar_event $event) { +function mod_assign_core_calendar_is_event_visible(calendar_event $event) +{ global $CFG, $USER; require_once($CFG->dirroot . '/mod/assign/locallib.php'); @@ -259,7 +261,8 @@ Eg. * @param int $itemcount The item count associated with the action event. * @return bool */ -function mod_assign_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) { +function mod_assign_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) +{ // List of event types where the action event's item count should be shown. $eventtypesshowingitemcount = [ ASSIGN_EVENT_TYPE_GRADINGDUE @@ -320,7 +323,8 @@ This callback handles updating the activity instance based on the changed action Example: ```php -function mod_feedback_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $feedback) { +function mod_feedback_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $feedback) +{ global $CFG, $DB; if (empty($event->instance) || $event->modulename != 'feedback') { @@ -406,7 +410,8 @@ If the calendar event has no valid `timestart` values then the callback should r Example: ```php -function mod_feedback_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $instance) { +function mod_feedback_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $instance) +{ $mindate = null; $maxdate = null; diff --git a/versioned_docs/version-4.5/apis/core/clock/index.md b/versioned_docs/version-4.5/apis/core/clock/index.md index de70bd68b..5528cf4c3 100644 --- a/versioned_docs/version-4.5/apis/core/clock/index.md +++ b/versioned_docs/version-4.5/apis/core/clock/index.md @@ -46,13 +46,15 @@ The recommended approach is to have the Dependency Injector inject into the cons ```php title="Usage in injected classes" namespace mod_example; -class post { +class post +{ public function __construct( protected readonly \core\clock $clock, protected readonly \moodle_database $db, ) - public function create_thing(\stdClass $data): \stdClass { + public function create_thing(\stdClass $data): \stdClass + { $data->timecreated = $this->clock->time(); $data->id = $this->db->insert_record('example_thing', $data); @@ -99,8 +101,10 @@ The incrementing clock increases the time by one second every time it is called. A helper method, `mock_clock_with_incrementing(?int $starttime = null): \core\clock`, is provided within the standard testcase: ```php title="Obtaining the incrementing clock" -class my_test extends \advanced_testcase { - public function test_create_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_create_thing(): void + { // This class inserts data into the database. $this->resetAfterTest(true); @@ -134,8 +138,10 @@ The frozen clock uses a time which does not change, unless manually set. This ca A helper method, `mock_clock_with_frozen(?int $time = null): \core\clock`, is provided within the standard testcase: ```php title="Obtaining and using the frozen clock" -class my_test extends \advanced_testcase { - public function test_create_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_create_thing(): void + { // This class inserts data into the database. $this->resetAfterTest(true); @@ -182,27 +188,33 @@ class my_test extends \advanced_testcase { If the standard cases are not suitable for you, then you can create a custom clock and inject it into the DI container. ```php title="Creating a custom clock" -class my_clock implements \core\clock { +class my_clock implements \core\clock +{ public int $time; - public function __construct() { + public function __construct() + { $this->time = time(); } - public function now(): \DateTimeImmutable { + public function now(): \DateTimeImmutable + { $time = new \DateTimeImmutable('@' . $this->time); $this->time = $this->time += 5; return $time; } - public function time(): int { + public function time(): int + { return $this->now()->getTimestamp(); } } -class my_test extends \advanced_testcase { - public function test_my_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_my_thing(): void + { $clock = new my_clock(); \core\di:set(\core\clock::class, $clock); diff --git a/versioned_docs/version-4.5/apis/core/customfields/index.md b/versioned_docs/version-4.5/apis/core/customfields/index.md index a4644919c..43acc73ad 100644 --- a/versioned_docs/version-4.5/apis/core/customfields/index.md +++ b/versioned_docs/version-4.5/apis/core/customfields/index.md @@ -105,7 +105,8 @@ The list of fields is cached in the handler and these two functions can be calle ::: ```php title="Example code for course custom fields. This function will return all the custom fields for a given courseid" -function get_course_metadata($courseid) { +function get_course_metadata($courseid) +{ $handler = \core_customfield\handler::get_handler('core_course', 'course'); // This is equivalent to the line above. //$handler = \core_course\customfield\course_handler::create(); diff --git a/versioned_docs/version-4.5/apis/core/deprecation/index.md b/versioned_docs/version-4.5/apis/core/deprecation/index.md index 8df0d5dee..2ce423a71 100644 --- a/versioned_docs/version-4.5/apis/core/deprecation/index.md +++ b/versioned_docs/version-4.5/apis/core/deprecation/index.md @@ -40,24 +40,29 @@ The attribute is a Moodle PHP Attribute and can be applied to: ```php title="Example attribute usage" // On a global function: #[\core\attribute\deprecated('random_bytes', since: '4.3')] -function random_bytes_emulate($length) { +function random_bytes_emulate($length) +{ // Replaced by random_bytes since Moodle 4.3. } // On a class: #[\core\attribute\deprecated(replacement: null, since: '4.4', reason: 'This functionality has been removed.')] -class example { +class example +{ #[\core\attribute\deprecated( replacement: '\core\example::do_something', since: '4.3', reason: 'No longer required', mdl: 'MDL-12345', )] - public function do_something(): void {} + public function do_something(): void + { + } } // On an enum case: -enum example { +enum example +{ #[\core\attribute\deprecated('example::OPTION', since: '4.4', final: true)] case OPTION; } @@ -75,7 +80,8 @@ The `\core\deprecation` class contains helper methods to inspect for use of the // A method which has been initially deprecated, and replaced by 'random_bytes'. It should show debugging. /** @deprecated since 4.3 */ #[\core\attribute\deprecated('random_bytes', since: '4.3')] -function random_bytes_emulate($length) { +function random_bytes_emulate($length) +{ \core\deprecation::emit_deprecation_if_present(__FUNCTION__); return random_bytes($length); } @@ -83,7 +89,8 @@ function random_bytes_emulate($length) { // A method which has been finally deprecated and should throw an exception. /** @deprecated since 2.7 */ #[\core\attribute\deprecated(replacement: 'Events API', since: '2.3', final: true)] -function add_to_log() { +function add_to_log() +{ \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } diff --git a/versioned_docs/version-4.5/apis/core/di/index.md b/versioned_docs/version-4.5/apis/core/di/index.md index 0529877c9..0fbcfd8bd 100644 --- a/versioned_docs/version-4.5/apis/core/di/index.md +++ b/versioned_docs/version-4.5/apis/core/di/index.md @@ -21,7 +21,8 @@ Dependencies are stored using a string id attribute, which is typically the clas When accessing dependencies within a class, it is advisable to inject them into the constructor, for example: ```php title="Fetching a instance of the \core\http_client class from within a class" -class my_thing { +class my_thing +{ public function __construct( protected readonly \core\http_client $client, ) { @@ -48,7 +49,8 @@ The use of readonly properties is also highly recommended as it ensures that dep These language features are available in all Moodle versions supporting Dependency Injection. ```php -class example_without_promotion { +class example_without_promotion +{ protected \core\http_client $client; public function __construct( @@ -58,7 +60,8 @@ class example_without_promotion { } } -class example_with_promotion { +class example_with_promotion +{ public function __construct( protected readonly \core\http_client $client, ) { @@ -101,8 +104,10 @@ namespace mod_example; use core\hook\di_configuration; -class hook_listener { - public static function inject_dependencies(di_configuration $hook): void { +class hook_listener +{ + public static function inject_dependencies(di_configuration $hook): void + { $hook->add_definition( id: complex_client::class, definition: function ( @@ -139,8 +144,10 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; use GuzzleHttp\Psr7\Response; -class example_test extends \advanced_testcase { - public function test_the_thing(): void { +class example_test extends \advanced_testcase +{ + public function test_the_thing(): void + { // Mock our responses to the http_client. $handlerstack = HandlerStack::create(new MockHandler([ new Response(200, [], json_encode(['name' => 'Colin'])), @@ -170,13 +177,15 @@ Dependencies can be usually be easily injected into classes which are themselves In most cases in Moodle, this should be via the class constructor, for example: ```php title="Injecting via the constructor" -class thing_manager { +class thing_manager +{ public function __construct( protected readonly \moodle_database $db, ) { } - public function get_things(): array { + public function get_things(): array + { return $this->db->get_records('example_things'); } } @@ -186,13 +195,15 @@ $manager = \core\di::get(thing_manager::class); $things = $manager->get_things(); // Using it in a child class: -class other_thing { +class other_thing +{ public function __construct( protected readonly thing_manager $manager, ) { } - public function manage_things(): void { + public function manage_things(): void + { $this->manager->get_things(); } } diff --git a/versioned_docs/version-4.5/apis/core/dml/ddl.md b/versioned_docs/version-4.5/apis/core/dml/ddl.md index 83534afad..c33184f78 100644 --- a/versioned_docs/version-4.5/apis/core/dml/ddl.md +++ b/versioned_docs/version-4.5/apis/core/dml/ddl.md @@ -24,7 +24,8 @@ Of course, feel free to clarify, complete and add more info to all this document - All the function calls in this page are public methods of the **database manager**, accessible from the $DB global object. You will need to "import" it within the upgrade function of your **upgrade.php** main function using the `global` keyword, for example: ```php -function xmldb_xxxx_upgrade { +function xmldb_xxxx_upgrade +{ global $DB; // Load the DDL manager and xmldb API. diff --git a/versioned_docs/version-4.5/apis/core/dml/index.md b/versioned_docs/version-4.5/apis/core/dml/index.md index 8b63d7dca..d856ea79e 100644 --- a/versioned_docs/version-4.5/apis/core/dml/index.md +++ b/versioned_docs/version-4.5/apis/core/dml/index.md @@ -33,7 +33,8 @@ require(__DIR__ . '/config.php'); ```php title="example.php" \mod_example\local\entitychanges\create_example::class, @@ -156,7 +158,8 @@ namespace mod_activity\hook; #[\core\attribute\label('Hook dispatched at the very end of installation of mod_activity plugin.')] #[\core\attribute\tags('installation')] -final class installation_finished { +final class installation_finished +{ public function __construct( public readonly string $version, ) { @@ -172,17 +175,20 @@ final class installation_finished { dispatch($hook); } @@ -219,7 +226,8 @@ Using DI for dependency injection has the benefit that the hook manager can use ```php title="Mocking a hook listener" // Unit test. -public function test_before_standard_footer_html_hooked(): void { +public function test_before_standard_footer_html_hooked(): void +{ // Load the callback classes. require_once(__DIR__ . '/fixtures/core_renderer/before_standard_footer_html_callbacks.php'); @@ -242,7 +250,8 @@ public function test_before_standard_footer_html_hooked(): void { } // fixtures/core_renderer/before_standard_footer_html_callbacks.php -final class before_standard_footer_html_callbacks { +final class before_standard_footer_html_callbacks +{ public static function before_standard_footer_html( \core\hook\output\before_standard_footer_html $hook, ): void { @@ -312,8 +321,10 @@ a hook as parameter. namespace local_stuff\local; use \mod_activity\hook\installation_finished; -class hook_callbacks { - public static function activity_installation_finished(installation_finished $hook): void { +class hook_callbacks +{ + public static function activity_installation_finished(installation_finished $hook): void + { if (during_initial_install()) { return; } @@ -386,7 +397,8 @@ use core\attribute; #[attribute\label('Hook dispatched at the very end of lib/setup.php')] #[attribute\tags('config')] #[attribute\hook\replaces_callbacks('after_config')] -final class after_config { +final class after_config +{ } ``` @@ -398,16 +410,20 @@ final class after_config { stopped; } - public function stop(): void { + public function stop(): void + { $this->stopped = true; } } @@ -518,8 +537,10 @@ A callback will only be called if the hook was not stopped before-hand. Dependin namespace local_myplugin; -class callbacks { - public static function block_pre_delete(\core\hook\block_delete_pre $hook): void { +class callbacks +{ + public static function block_pre_delete(\core\hook\block_delete_pre $hook): void + { // ... $hook->stop(); } diff --git a/versioned_docs/version-4.5/apis/core/navigation/index.md b/versioned_docs/version-4.5/apis/core/navigation/index.md index 159250ee1..eaae0aa97 100644 --- a/versioned_docs/version-4.5/apis/core/navigation/index.md +++ b/versioned_docs/version-4.5/apis/core/navigation/index.md @@ -235,7 +235,8 @@ function {modulename}_extend_settings_navigation( You may be required to add a node in a specified order within the menu navigation menus. To do this you need to examine the node object as given in the respective parameters in the functions above, then find the key of the child node you wish to place the link before. For example, applying the code below will put a direct link to grade report. ```php -function my_plugin_extend_settings_navigation($settingsnav, $context){ +function my_plugin_extend_settings_navigation($settingsnav, $context) +{ $addnode = $context->contextlevel === 50; $addnode = $addnode && has_capability('gradereport/grader:view', $context); if ($addnode) { diff --git a/versioned_docs/version-4.5/apis/core/reportbuilder/index.md b/versioned_docs/version-4.5/apis/core/reportbuilder/index.md index b5224be88..fe6f73a77 100644 --- a/versioned_docs/version-4.5/apis/core/reportbuilder/index.md +++ b/versioned_docs/version-4.5/apis/core/reportbuilder/index.md @@ -204,7 +204,8 @@ The first method that we need is ***initialise()*** : /** * Initialise report, we need to set the main table, load our entities and set columns/filters */ -protected function initialise(): void { +protected function initialise(): void +{ ``` The initialise method needs to get the main entity, set the main table it needs to use and add the entity to the report: @@ -324,7 +325,8 @@ The first method you need to build is `initialise()` /** * Initialise report, we need to set the main table, load our entities and set columns/filters */ -protected function initialise(): void { +protected function initialise(): void +{ ``` The initialise method needs to get the main entity, set the main table it needs to use and add the entity to the report: @@ -385,7 +387,8 @@ You will need to specify the name that is displayed to the end user for the data * * @return string */ - public static function get_name(): string { + public static function get_name(): string + { return get_string('tasklogs', 'core_admin'); } ``` @@ -400,7 +403,8 @@ Once all entities have been added you need to define which columns it will show * * @return string[] */ -public function get_default_columns(): array { +public function get_default_columns(): array +{ return [ 'task_log:name', 'task_log:starttime', @@ -418,7 +422,8 @@ You may also optionally define the sorting that will be applied to the default r * * @return int[] */ -public function get_default_column_sorting(): array { +public function get_default_column_sorting(): array +{ return [ 'task_log:starttime' => SORT_DESC, ]; @@ -435,7 +440,8 @@ The filters allow the end user of the report to only see a subset of the data th * * @return string[] */ -public function get_default_filters(): array { +public function get_default_filters(): array +{ return [ 'task_log:timestart', 'task_log:result', @@ -453,7 +459,8 @@ The conditions allow the user creating the report to define which data it will r * * @return string[] */ -public function get_default_conditions(): array { +public function get_default_conditions(): array +{ return [ 'task_log:type', 'task_log:timestart', @@ -470,7 +477,8 @@ You may also optionally define the [initial values for any of the default condit * * @return array */ -public function get_default_condition_values(): array { +public function get_default_condition_values(): array +{ return [ 'task_log:type_operator' => select::EQUAL_TO, 'task_log:type_value' => \core\task\database_logger::TYPE_SCHEDULED, @@ -496,7 +504,8 @@ require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php"); * @copyright 2023 Paul Holden * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class categories_test extends core_reportbuilder_testcase { +class categories_test extends core_reportbuilder_testcase +{ ``` The `core_reportbuilder_testcase` will not autoload so we first ensure that it is loaded with the `require_once`. After this there are a few things you should look to test: @@ -514,7 +523,8 @@ For this you want a step that sets up will return enough data allows you test al /** * Test default datasource */ - public function test_datasource_default(): void { + public function test_datasource_default(): void + { $this->resetAfterTest(); $category = $this->getDataGenerator()->create_category(['name' => 'Zoo', 'idnumber' => 'Z01']); @@ -606,7 +616,8 @@ None of these tests checks that the data is what you want, but will ensure that * * In order to execute this test PHPUNIT_LONGTEST should be defined as true in phpunit.xml or directly in config.php */ - public function test_stress_datasource(): void { + public function test_stress_datasource(): void + { if (!PHPUNIT_LONGTEST) { $this->markTestSkipped('PHPUNIT_LONGTEST is not defined'); } diff --git a/versioned_docs/version-4.5/apis/plugintypes/ai/placement.md b/versioned_docs/version-4.5/apis/plugintypes/ai/placement.md index dfa4d6c48..e33e4cfc7 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/ai/placement.md +++ b/versioned_docs/version-4.5/apis/plugintypes/ai/placement.md @@ -39,7 +39,8 @@ They must also implement the following methods: This is the list of Actions that are supported by this Placement, for example the `aiplacement_editor` plugin defines this as: ```php -public function get_action_list(): array { +public function get_action_list(): array +{ return [ \core_ai\aiactions\generate_text::class, \core_ai\aiactions\generate_image::class, diff --git a/versioned_docs/version-4.5/apis/plugintypes/ai/provider.md b/versioned_docs/version-4.5/apis/plugintypes/ai/provider.md index bd0693cc7..7861206b0 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/ai/provider.md +++ b/versioned_docs/version-4.5/apis/plugintypes/ai/provider.md @@ -35,7 +35,8 @@ They must also implement the following methods: This is the list of Actions that are supported by this Provider, for example the `aiprovider_openai` plugin defines this as: ```php -public function get_action_list(): array { +public function get_action_list(): array +{ return [ \core_ai\aiactions\generate_text::class, \core_ai\aiactions\generate_image::class, @@ -56,7 +57,8 @@ For example, the `aiprovider_azureai` provider checks values are set for `$this- the result. ```php -public function is_provider_configured(): bool { +public function is_provider_configured(): bool +{ return !empty($this->apikey) && !empty($this->apiendpoint); } ``` @@ -173,7 +175,8 @@ This should be implemented in a `is_request_allowed()` method in the Provider cl * @param aiactions\base $action The action to check. * @return array|bool True on success, array of error details on failure. */ -public function is_request_allowed(aiactions\base $action): array|bool { +public function is_request_allowed(aiactions\base $action): array|bool +{ $ratelimiter = \core\di::get(rate_limiter::class); $component = \core\component::get_component_from_classname(get_class($this)); diff --git a/versioned_docs/version-4.5/apis/plugintypes/assign/feedback.md b/versioned_docs/version-4.5/apis/plugintypes/assign/feedback.md index 0634bccbf..c77a995f3 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/assign/feedback.md +++ b/versioned_docs/version-4.5/apis/plugintypes/assign/feedback.md @@ -121,7 +121,8 @@ All feedback plugins should include one setting named 'default' to indicate if t This is where all the functionality for this plugin is defined. We will step through this file and describe each part as we go. ```php -class assign_feedback_file extends assign_feedback_plugin { +class assign_feedback_file extends assign_feedback_plugin +{ ``` #### get_name() {/* #get_name */} @@ -129,7 +130,8 @@ class assign_feedback_file extends assign_feedback_plugin { All feedback plugins MUST define a class with the component name of the plugin that extends assign_feedback_plugin. ```php -public function get_name() { +public function get_name() +{ return get_string('file', 'assignfeedback_file'); } ``` @@ -139,7 +141,8 @@ This function is abstract in the parent class (feedback_plugin) and must be defi #### get_settings() {/* #get_settings */} ```php -public function get_settings(MoodleQuickForm $mform) { +public function get_settings(MoodleQuickForm $mform) +{ $mform->addElement( 'assignfeedback_file_fileextensions', get_string('allowedfileextensions', 'assignfeedback_file') @@ -153,7 +156,8 @@ This function is called when building the settings page for the assignment. It a #### save_settings() {/* #save_settings */} ```php -public function save_settings(stdClass $data) { +public function save_settings(stdClass $data) +{ $this->set_config('allowedfileextensions', $data->allowedfileextensions); return true; } @@ -204,7 +208,8 @@ This function is called when building the feedback form. It functions identicall #### is_feedback_modified() {/* #is_feedback_modified */} ```php -public function is_feedback_modified(stdClass $grade, stdClass $data) { +public function is_feedback_modified(stdClass $grade, stdClass $data) +{ $commenttext = ''; if ($grade) { $feedbackcomments = $this->get_feedback_comments($grade->id); @@ -226,7 +231,8 @@ This function is called before feedback is saved. If feedback has not been modif #### save() {/* #save */} ```php -public function save(stdClass $grade, stdClass $data) { +public function save(stdClass $grade, stdClass $data) +{ global $DB; $fileoptions = $this->get_file_options(); @@ -263,7 +269,8 @@ This function is called to save a graders feedback. The parameters are the grade #### view_summary() {/* #view_summary */} ```php -public function view_summary(stdClass $grade, & $showviewlink) { +public function view_summary(stdClass $grade, & $showviewlink) +{ $count = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA); // show a view all link if the number of files is over this limit $showviewlink = $count > ASSIGNFEEDBACK_FILE_MAXSUMMARYFILES; @@ -285,7 +292,8 @@ This function is called to display a summary of the feedback to both markers and #### view() {/* #view */} ```php -public function view(stdClass $grade) { +public function view(stdClass $grade) +{ return $this->assignment->render_area_files( 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, @@ -299,7 +307,8 @@ This function is called to display the entire feedback to both markers and stude #### can_upgrade() {/* #can_upgrade */} ```php -public function can_upgrade($type, $version) { +public function can_upgrade($type, $version) +{ if (($type == 'upload' || $type == 'uploadsingle') && $version >= 2011112900) { return true; @@ -311,7 +320,8 @@ public function can_upgrade($type, $version) { This function is used to identify old "Assignment 2.2" subtypes that can be upgraded by this plugin. This plugin supports upgrades from the old "upload" and "uploadsingle" assignment subtypes. ```php -public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) { +public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) +{ // first upgrade settings (nothing to do) return true; } @@ -360,7 +370,8 @@ This function upgrades a single submission from the old assignment type to the n #### is_empty() {/* #is_empty */} ```php -public function is_empty(stdClass $submission) { +public function is_empty(stdClass $submission) +{ return $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA) == 0; } ``` @@ -370,7 +381,8 @@ If a plugin has no data to show then this function should return true from the ` #### get_file_areas() {/* #get_file_areas */} ```php -public function get_file_areas() { +public function get_file_areas() +{ return [ASSIGNFEEDBACK_FILE_FILEAREA => $this->get_name()]; } ``` @@ -380,7 +392,8 @@ A plugin should implement `get_file_areas` if it supports saving of any files to #### delete_instance() {/* #delete_instance */} ```php -public function delete_instance() { +public function delete_instance() +{ global $DB; // will throw exception on failure $DB->delete_records('assignfeedback_file', [ @@ -396,11 +409,13 @@ This function is called when a plugin is deleted. Note only database records nee #### Gradebook features {/* #gradebook-features */} ```php -public function format_for_gradebook(stdClass $grade) { +public function format_for_gradebook(stdClass $grade) +{ return FORMAT_MOODLE; } -public function text_for_gradebook(stdClass $grade) { +public function text_for_gradebook(stdClass $grade) +{ return ''; } ``` @@ -413,7 +428,8 @@ Only one feedback plugin can push comments to the gradebook. Usually this is the * * @return boolean - True if the plugin supports quickgrading */ -public function supports_quickgrading() { +public function supports_quickgrading() +{ return false; } @@ -424,7 +440,8 @@ public function supports_quickgrading() { * @param mixed $grade grade or null - The grade data. May be null if there are no grades for this user (yet) * @return mixed - A html string containing the html form elements required for quickgrading or false to indicate this plugin does not support quickgrading */ -public function get_quickgrading_html($userid, $grade) { +public function get_quickgrading_html($userid, $grade) +{ return false; } @@ -435,7 +452,8 @@ public function get_quickgrading_html($userid, $grade) { * @param stdClass $grade The grade * @return boolean - true if the quickgrading form element has been modified */ -public function is_quickgrading_modified($userid, $grade) { +public function is_quickgrading_modified($userid, $grade) +{ return false; } @@ -446,7 +464,8 @@ public function is_quickgrading_modified($userid, $grade) { * @param stdClass $grade The grade * @return boolean - true if the grade changes were saved correctly */ -public function save_quickgrading_changes($userid, $grade) { +public function save_quickgrading_changes($userid, $grade) +{ return false; } ``` @@ -457,7 +476,8 @@ These 4 functions can be implemented to allow a plugin to support quick-grading. /** * Run cron for this plugin */ -public static function cron() { +public static function cron() +{ } ``` @@ -471,7 +491,8 @@ A plugin can run code when cron runs by implementing this method. * @return array - An array of action and description strings. * The action will be passed to grading_action. */ -public function get_grading_actions() { +public function get_grading_actions() +{ return []; } @@ -481,7 +502,8 @@ public function get_grading_actions() { * @param string $gradingaction The action chosen from the grading actions menu * @return string The page containing the form */ -public function grading_action($gradingaction) { +public function grading_action($gradingaction) +{ return ''; } ``` @@ -495,7 +517,8 @@ Grading actions appear in the select menu above the grading table and apply to t * @return array - An array of action and description strings. * The action will be passed to grading_batch_operation. */ -public function get_grading_batch_operations() { +public function get_grading_batch_operations() +{ return []; } @@ -506,7 +529,8 @@ public function get_grading_batch_operations() { * @param array $users The list of selected userids * @return string The page containing the form */ -public function grading_batch_operation($action, $users) { +public function grading_batch_operation($action, $users) +{ return ''; } ``` diff --git a/versioned_docs/version-4.5/apis/plugintypes/assign/submission.md b/versioned_docs/version-4.5/apis/plugintypes/assign/submission.md index 060cc28ae..d4e817e1d 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/assign/submission.md +++ b/versioned_docs/version-4.5/apis/plugintypes/assign/submission.md @@ -118,7 +118,8 @@ This example from the submission_file plugin also checks to see if there is a ma This is where all the functionality for this plugin is defined. We will step through this file and describe each part as we go. ```php -class assign_submission_file extends assign_submission_plugin { +class assign_submission_file extends assign_submission_plugin +{ ``` All submission plugins MUST define a class with the component name of the plugin that extends assign_submission_plugin. @@ -126,7 +127,8 @@ All submission plugins MUST define a class with the component name of the plugin #### get_name() {/* #get_name */} ```php -public function get_name() { +public function get_name() +{ return get_string('file', 'assignsubmission_file'); } ``` @@ -136,7 +138,8 @@ Get name is abstract in submission_plugin and must be defined in your new plugin #### get_settings() {/* #get_settings */} ```php -public function get_settings(MoodleQuickForm $mform) { +public function get_settings(MoodleQuickForm $mform) +{ global $CFG, $COURSE; $defaultmaxfilesubmissions = $this->get_config('maxfilesubmissions'); @@ -193,7 +196,8 @@ The "get_settings" function is called when building the settings page for the as #### save_settings() {/* #save_settings */} ```php -public function save_settings(stdClass $data) { +public function save_settings(stdClass $data) +{ $this->set_config('maxfilesubmissions', $data->assignsubmission_file_maxfiles); $this->set_config('maxsubmissionsizebytes', $data->assignsubmission_file_maxsizebytes); return true; @@ -205,7 +209,8 @@ The "save_settings" function is called when the assignment settings page is subm #### get_form_elements() {/* #get_form_elements */} ```php -public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data) { +public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data) +{ if ($this->get_config('maxfilesubmissions') <= 0) { return false; } @@ -240,7 +245,8 @@ The get_form_elements function is called when building the submission form. It f #### save() {/* #save */} ```php -public function save(stdClass $submission, stdClass $data) { +public function save(stdClass $submission, stdClass $data) +{ global $USER, $DB; $fileoptions = $this->get_file_options(); @@ -305,7 +311,8 @@ The "save" function is called to save a user submission. The parameters are the #### get_files() {/* #get_files */} ```php -public function get_files($submission) { +public function get_files($submission) +{ $result = []; $fs = get_file_storage(); @@ -330,7 +337,8 @@ If this submission plugin produces one or more files, it should implement "get_f #### view_summary() {/* #view_summary */} ```php -public function view_summary(stdClass $submission, & $showviewlink) { +public function view_summary(stdClass $submission, & $showviewlink) +{ $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); // Show we show a link to view all files for this plugin. @@ -352,7 +360,8 @@ The view_summary function is called to display a summary of the submission to bo #### view() {/* #view */} ```php -public function view($submission) { +public function view($submission) +{ return $this->assignment->render_area_files( 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, @@ -366,7 +375,8 @@ The view function is called to display the entire submission to both markers and #### can_upgrade() {/* #can_upgrade */} ```php -public function can_upgrade($type, $version) { +public function can_upgrade($type, $version) +{ $uploadsingle_type ='uploadsingle'; $upload_type ='upload'; @@ -382,7 +392,8 @@ The can_upgrade function is used to identify old "Assignment 2.2" subtypes that #### upgrade_settings() {/* #upgrade_settings */} ```php -public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) { +public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) +{ global $DB; if ($oldassignment->assignmenttype == 'uploadsingle') { @@ -424,7 +435,8 @@ This function is called once per assignment instance to upgrade the settings fro #### upgrade() {/* #upgrade */} ```php -public function upgrade($oldcontext, $oldassignment, $oldsubmission, $submission, &$log) { +public function upgrade($oldcontext, $oldassignment, $oldsubmission, $submission, &$log) +{ global $DB; $filesubmission = (object) [ @@ -460,7 +472,8 @@ The "upgrade" function upgrades a single submission from the old assignment type #### get_editor_fields() {/* #get_editor_fields */} ```php -public function () { +public function () +{ return [ 'onlinetext' => get_string('pluginname', 'assignsubmission_comments'), ]; @@ -472,7 +485,8 @@ This example is from assignsubmission_onlinetext. If the plugin uses a text-edit #### get_editor_text() {/* #get_editor_text */} ```php -public function get_editor_text($name, $submissionid) { +public function get_editor_text($name, $submissionid) +{ if ($name == 'onlinetext') { $onlinetextsubmission = $this->get_onlinetext_submission($submissionid); if ($onlinetextsubmission) { @@ -489,7 +503,8 @@ This example is from assignsubmission_onlinetext. If the plugin uses a text-edit #### get_editor_format() {/* #get_editor_format */} ```php -public function get_editor_format($name, $submissionid) { +public function get_editor_format($name, $submissionid) +{ if ($name == 'onlinetext') { $onlinetextsubmission = $this->get_onlinetext_submission($submissionid); if ($onlinetextsubmission) { @@ -506,7 +521,8 @@ This example is from assignsubmission_onlinetext. For the same reason as the pre #### is_empty() {/* #is_empty */} ```php -public function is_empty(stdClass $submission) { +public function is_empty(stdClass $submission) +{ return $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA) == 0; } ``` @@ -516,7 +532,8 @@ If a plugin has no submission data to show - it can return true from the is_empt #### submission_is_empty() {/* #submission_is_empty */} ```php -public function submission_is_empty() { +public function submission_is_empty() +{ global $USER; $fs = get_file_storage(); @@ -539,7 +556,8 @@ Determine if a submission is empty. This is distinct from is_empty() in that it #### get_file_areas() {/* #get_file_areas */} ```php -public function get_file_areas() { +public function get_file_areas() +{ return [ASSIGNSUBMISSION_FILE_FILEAREA=>$this->get_name()]; } ``` @@ -549,7 +567,8 @@ A plugin should implement get_file_areas if it supports saving of any files to m #### copy_submission() {/* #copy_submission */} ```php -public function copy_submission(stdClass $sourcesubmission, stdClass $destsubmission) { +public function copy_submission(stdClass $sourcesubmission, stdClass $destsubmission) +{ global $DB; // Copy the files across. @@ -583,7 +602,8 @@ Since Moodle 2.5 - a students submission can be copied to create a new submissio #### format_for_log() {/* #format_for_log */} ```php -public function format_for_log(stdClass $submission) { +public function format_for_log(stdClass $submission) +{ // Format the information for each submission plugin add_to_log $filecount = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); return ' the number of file(s) : ' . $filecount . " file(s).
"; @@ -595,7 +615,8 @@ The format_for_log function lets a plugin produce a really short summary of a su #### delete_instance() {/* #delete_instance */} ```php -public function delete_instance() { +public function delete_instance() +{ global $DB; // Will throw exception on failure $DB->delete_records('assignsubmission_file', [ diff --git a/versioned_docs/version-4.5/apis/plugintypes/availability/index.md b/versioned_docs/version-4.5/apis/plugintypes/availability/index.md index fe15d4233..19dcc032c 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/availability/index.md +++ b/versioned_docs/version-4.5/apis/plugintypes/availability/index.md @@ -83,12 +83,14 @@ Here's an outline of the code (with standard PHPdoc comments omitted to save spa // You must use the right namespace (matching your plugin component name). namespace availability_name; -class condition extends \core_availability\condition { +class condition extends \core_availability\condition +{ // Any data associated with the condition can be stored in member // variables. Here's an example variable: protected $allow; - public function __construct($structure) { + public function __construct($structure) + { // Retrieve any necessary data from the $structure here. The // structure is extracted from JSON data stored in the database // as part of the tree structure of conditions relating to an @@ -100,7 +102,8 @@ class condition extends \core_availability\condition { // throw a coding_exception if the structure is wrong. } - public function save() { + public function save() + { // Save back the data into a plain array similar to $structure above. return (object)array('type' => 'name', 'allow' => $this->allow); } @@ -142,7 +145,8 @@ class condition extends \core_availability\condition { return $allow ? 'Users are allowed' : 'Users not allowed'; } - protected function get_debug_string() { + protected function get_debug_string() + { // This function is only normally used for unit testing and // stuff like that. Just make a short string representation // of the values of the condition, suitable for developers. @@ -162,9 +166,11 @@ The class is required, but all the functions are theoretically optional; you can ```php namespace availability_name; -class frontend extends \core_availability\frontend { +class frontend extends \core_availability\frontend +{ - protected function get_javascript_strings() { + protected function get_javascript_strings() + { // You can return a list of names within your language file and the // system will include them here. // Should you need strings from another language file, you can also diff --git a/versioned_docs/version-4.5/apis/plugintypes/blocks/index.md b/versioned_docs/version-4.5/apis/plugintypes/blocks/index.md index bc56f7024..b42ddf26f 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/blocks/index.md +++ b/versioned_docs/version-4.5/apis/plugintypes/blocks/index.md @@ -160,7 +160,8 @@ This function is called on your subclass right after an instance is loaded. It i Example of a specialization method using the instance configuration. ```php -function specialization() { +function specialization() +{ if (isset($this->config->title)) { $this->title = format_string($this->config->title, true, ['context' => $this->context]); } else { @@ -180,11 +181,13 @@ In order to get our block to actually display something on screen, we need to ad ```php -class block_pluginname extends block_base { +class block_pluginname extends block_base +{ // (...) - public function get_content() { + public function get_content() + { if ($this->content !== null) { return $this->content; } @@ -202,11 +205,13 @@ class block_pluginname extends block_base { ```php -class block_pluginname extends block_list { +class block_pluginname extends block_list +{ // (...) - public function get_content() { + public function get_content() + { global $OUTPUT; if ($this->content !== null) { return $this->content; @@ -256,7 +261,8 @@ By default, only one instance of each block plugin can be added to a page. Howev
```php -public function instance_allow_multiple() { +public function instance_allow_multiple() +{ return true; } ``` @@ -279,7 +285,8 @@ Using this method each block instance can decide if the standard block header is
```php -public function hide_header() { +public function hide_header() +{ return true; } ``` @@ -298,7 +305,8 @@ By default, each block section in the page will use a standard `block` class and
```php -public function html_attributes() { +public function html_attributes() +{ // Get default values. $attributes = parent::html_attributes(); // Append our class to class attribute. @@ -351,7 +359,8 @@ However, for some cases like the Atto HTML editor, you may want to store them in
```php title="Example of adding data before storing it -public function instance_config_save($data,$nolongerused =false) { +public function instance_config_save($data,$nolongerused =false) +{ // Example of add new data. $data->somenewattribute = 'Some new value'; @@ -393,7 +402,8 @@ While in other Moodle pulgins the existence of a settings.php is enough to enabl
```php" -function has_config() { +function has_config() +{ return true; } ``` @@ -421,7 +431,8 @@ Each page in Moodle can define it's own page type name. However, there are some
```php -public function applicable_formats() { +public function applicable_formats() +{ return [ 'admin' => false, 'site-index' => false, diff --git a/versioned_docs/version-4.5/apis/plugintypes/enrol/index.md b/versioned_docs/version-4.5/apis/plugintypes/enrol/index.md index bd2695079..da1a3c56d 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/enrol/index.md +++ b/versioned_docs/version-4.5/apis/plugintypes/enrol/index.md @@ -151,7 +151,8 @@ By default, all enrolment plugins will have *editing enrolment* and *user unenro * @param stdClass $userenrolment * @return array An array of user_enrolment_actions */ -public function get_user_enrolment_actions(course_enrolment_manager $manager, $userenrolment) { +public function get_user_enrolment_actions(course_enrolment_manager $manager, $userenrolment) +{ $actions = parent::get_user_enrolment_actions($manager, $userenrolment); $context = $manager->get_context(); $instance = $userenrolment->enrolmentinstance; @@ -191,7 +192,8 @@ The unenrol action will allow resetif all following conditions are met:
```php -public function allow_unenrol(stdClass $instance) { +public function allow_unenrol(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -224,7 +226,8 @@ The unenrol action will be displayed if all following conditions are met:
```php -public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) { +public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) +{ // Add any extra validation here. return true; } @@ -241,7 +244,8 @@ It is quite common in enrolment plugins to allow unenrol only if the user enrolm
```php -public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) { +public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) +{ if ($userenrolment->status == ENROL_USER_SUSPENDED) { return true; } @@ -270,7 +274,8 @@ The edit manual enrolment action will be displayed if if all following condition
```php -public function allow_enrol(stdClass $instance) { +public function allow_enrol(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -343,7 +348,8 @@ The edit enrolment action in the participants list will be displayed if if all f
```php -public function allow_manage(stdClass $instance) { +public function allow_manage(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -363,7 +369,8 @@ Enrolment plugins can protect roles from being modified by any other plugin. Ret
```php -public function roles_protected() { +public function roles_protected() +{ // Add any extra validation here if necessary. return false; } @@ -393,7 +400,8 @@ The only exception is *enrol_self* - although it is not possible to uniquely ide
```php -public function find_instance(array $enrolmentdata, int $courseid) : ?stdClass { +public function find_instance(array $enrolmentdata, int $courseid) : ?stdClass +{ global $DB; $instances = enrol_get_instances($courseid, false); diff --git a/versioned_docs/version-4.5/apis/plugintypes/fileconverter/index.md b/versioned_docs/version-4.5/apis/plugintypes/fileconverter/index.md index e2d7464a6..daedef81a 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/fileconverter/index.md +++ b/versioned_docs/version-4.5/apis/plugintypes/fileconverter/index.md @@ -54,7 +54,8 @@ This function informs the File Converter API whether the system requirements of It should be lightweight to call and cache where required. ```php title="Example implementation" -public static function are_requirements_met() { +public static function are_requirements_met() +{ return extension_loaded('my_php_extension'); } ``` @@ -72,9 +73,11 @@ The `start_document_conversion()` function starts a conversion, whilst `poll_con This function allows the plugin to answer whether it supports conversion between two formats. It is typically only used internally by the File Conversion subsystem. ```php title="Example implementation" -class converter implements \core_files\converter_interface { +class converter implements \core_files\converter_interface +{ // ... - public static function supports($from, $to) { + public static function supports($from, $to) + { // This plugin supports conversion from doc and docx to pdf only. if ($from !== 'doc' && $from !== 'docx') { return false; diff --git a/versioned_docs/version-4.5/apis/plugintypes/filter/index.md b/versioned_docs/version-4.5/apis/plugintypes/filter/index.md index 8afd138c5..0c8aaa41b 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/filter/index.md +++ b/versioned_docs/version-4.5/apis/plugintypes/filter/index.md @@ -107,7 +107,8 @@ If a filter uses a special syntax or it is based on an appearance of a substring /** * Example of a filter that uses links in some way. */ -public function filter($text, array $options = []) { +public function filter($text, array $options = []) +{ if (!is_string($text) or empty($text)) { // Non-string data can not be filtered anyway. @@ -138,8 +139,10 @@ To support this behaviour, a filter plugin must provide a `filterlocalsettings.p
```php title="filterlocalsettings.php" -class pluginfile_filter_local_settings_form extends \core_filters\form\local_settings_form { - protected function definition_inner(\MoodleQuickForm $mform) { +class pluginfile_filter_local_settings_form extends \core_filters\form\local_settings_form +{ + protected function definition_inner(\MoodleQuickForm $mform) + { $mform->addElement( 'text', 'word', @@ -164,8 +167,10 @@ All the local configurations can be accessed in the main filter class in the `$t localconfig['word'] ?? 'default'; diff --git a/versioned_docs/version-4.5/apis/plugintypes/format/index.md b/versioned_docs/version-4.5/apis/plugintypes/format/index.md index 722d724dd..61c0fb471 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/format/index.md +++ b/versioned_docs/version-4.5/apis/plugintypes/format/index.md @@ -532,8 +532,10 @@ In the example the extra output classes can look like: dirroot . '/mod/forum/lib.php'); @@ -720,9 +730,11 @@ This feature has been implemented by: ```php title="mod/resource/classes/output/courseformat/activitybadge.php" namespace mod_resource\output\courseformat; - class activitybadge extends \core_courseformat\output\activitybadge { + class activitybadge extends \core_courseformat\output\activitybadge + { - protected function update_content(): void { + protected function update_content(): void + { $options = (object) ['displayoptions' => $this->cminfo->customdata['displayoptions']]; $this->content = resource_get_optional_filetype($options, $this->cminfo); } diff --git a/versioned_docs/version-4.5/apis/plugintypes/mod/_files/lib_description.md b/versioned_docs/version-4.5/apis/plugintypes/mod/_files/lib_description.md index 3e44bd5e5..aa5cb5487 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/mod/_files/lib_description.md +++ b/versioned_docs/version-4.5/apis/plugintypes/mod/_files/lib_description.md @@ -41,7 +41,8 @@ Each feature is identified by a constant, which is defined in the `lib
```php -function [modname]_supports($feature) { +function [modname]_supports($feature) +{ return match ($feature) { FEATURE_GROUPS => true, FEATURE_GROUPINGS => true, @@ -68,7 +69,8 @@ To have your Activity plugin classified in the right Activity category, you must
```php -function [modname]_supports(string $feature) { +function [modname]_supports(string $feature) +{ switch ($feature) { [...] case FEATURE_MOD_PURPOSE: diff --git a/versioned_docs/version-4.5/apis/plugintypes/mod/visibility.md b/versioned_docs/version-4.5/apis/plugintypes/mod/visibility.md index 182e57640..68efc3b24 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/mod/visibility.md +++ b/versioned_docs/version-4.5/apis/plugintypes/mod/visibility.md @@ -37,7 +37,8 @@ The course cache is only updated when somebody edits a module, so it can't be us The function should return a value of class `cached_cm_info`. For example: ```php -function mod_frog_get_coursemodule_info($cm) { +function mod_frog_get_coursemodule_info($cm) +{ $info = new cached_cm_info(); $info->content = '

This will display below the module.

'; return $info; @@ -62,7 +63,8 @@ Don't use renderers in this function (see MDL-41074). If you have data you would You can customise module display dynamically (when the page loads). For example you might want to alter it based on the permissions of the current user. ```php -function mod_frog_cm_info_dynamic(cm_info $cm) { +function mod_frog_cm_info_dynamic(cm_info $cm) +{ $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!has_capability('some/capability', $context)) { $cm->set_user_visible(false); @@ -81,7 +83,8 @@ Most things are set using functions (as above; another example would be `set_con Sometimes you need to display custom information for the current user that appears only on the course view page. For example, the forum module displays unread information on the view page. This information doesn't show on other pages (it isn't included in the navigation, for instance). ```php -function mod_frog_cm_info_view(cm_info $cm) { +function mod_frog_cm_info_view(cm_info $cm) +{ $cm->set_after_link('Last tadpole: 22:17'); } ``` @@ -106,7 +109,8 @@ $cm = $modinfo->get_cm($cmid); The cm_info objects contain additional information that is not present in the course_modules database row, such as the module's name, and the icon and associated content mentioned above. In order to distinguish these from the plain database objects, you can specify the cm_info class in a function definition: ```php -function my_clever_function(cm_info $cm) { +function my_clever_function(cm_info $cm) +{ if (!$cm->uservisible) { // The module is not visible or available to current user, // so do something clever instead. diff --git a/versioned_docs/version-4.5/apis/plugintypes/qbank/filters.md b/versioned_docs/version-4.5/apis/plugintypes/qbank/filters.md index e18f5bc47..7ce87fc7f 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/qbank/filters.md +++ b/versioned_docs/version-4.5/apis/plugintypes/qbank/filters.md @@ -37,7 +37,8 @@ namespace qbank_myplugin; use core_question\local\bank\condition; -class myfilter_condition extends condition { +class myfilter_condition extends condition +{ } ``` @@ -47,8 +48,10 @@ Modify your `plugin_feature` class to return an instance of your condition from ```php title="question/bank/myplugin/classes/plugin_feature.php" namespace qbank_myplugin; -class plugin_feature extends core_question\local\bank\plugin_features_base { - public function get_question_filters(?core_question\local\bank\view $qbank = null): array { +class plugin_feature extends core_question\local\bank\plugin_features_base +{ + public function get_question_filters(?core_question\local\bank\view $qbank = null): array + { return [ new myfilter_condition($qbank), ]; @@ -59,7 +62,8 @@ class plugin_feature extends core_question\local\bank\plugin_features_base { Back in your `condition` class, define the `get_name()` method, which returns the label displayed in the filter UI. ```php title="Define the condition name" -public function get_name(): string { +public function get_name(): string +{ return get_string('myfilter_name', 'myplugin'); } ``` @@ -67,7 +71,8 @@ public function get_name(): string { Define `get_condition_key()`, which returns a unique machine-readable ID for this filter condition, used when passing the filter as a parameter. ```php title="Define the condition key" -public function get_condition_key(): string { +public function get_condition_key(): string +{ return 'myfilter'; } ``` @@ -78,7 +83,8 @@ The `$filter` parameter receives an array with a `'values'` key, containing an a The conditions from each filter are combined with the query in [`core_question\local\bank\view::build_query()`](https://github.com/moodle/moodle/blob/c741492c38b9945abbfc7e90dfe8f943279f8265/question/classes/local/bank/view.php#L733) ```php title="Filter questions" -public function build_query_from_filter(array $filter): array { +public function build_query_from_filter(array $filter): array +{ $andor = ' AND '; $equal = '='; if ($filter['jointype'] === self::JOINTYPE_ANY) { @@ -109,7 +115,8 @@ Following this pattern with your own fields and options will give you a basic fu To define the list of possible filter values, define `get_initial_values()`, which returns an array of `['value', 'title']` for each option. These will then be searchable and selectable in the autocomplete field. ```php title="Define initial filter values" -public function get_initial_values(): string { +public function get_initial_values(): string +{ return [ [ 'value' => 0, @@ -128,7 +135,8 @@ public function get_initial_values(): string { To restrict the possible filter terms to only those returned from `get_initial_values()`, define `allow_custom()` and have it return `false`. ```php title="Disable custom terms" -public function allow_custom(): bool { +public function allow_custom(): bool +{ return false; } ``` @@ -138,7 +146,8 @@ public function allow_custom(): bool { Not all join types are relevant to all filters. If each question will only match one of the selected values, it does not make sense to allow `JOINTYPE_ALL`. Define `get_join_list()` and return an array of the applicable join types. ```php title="Define a restricted list of join types" -public function get_join_list(): array { +public function get_join_list(): array +{ return [ datafilter::JOINTYPE_ANY, datafilter::JOINTYPE_NONE, @@ -152,7 +161,8 @@ By default, conditions allow multiple values to be selected and use the selected If your condition should only allow a single value at a time, override `allow_multiple()` to return false. ```php title="Disable selection of multiple values" -public function allow_multiple(): bool { +public function allow_multiple(): bool +{ return false; } ``` @@ -162,7 +172,8 @@ public function allow_multiple(): bool { By default, conditions can be left empty, and therefore will not be included in the filter. To make it compulsory to select a value for this condition when it is added, override `allow_empty()` to return false. ```php title="Disable empty values" -public function allow_empty(): bool { +public function allow_empty(): bool +{ return false; } ``` @@ -172,7 +183,8 @@ public function allow_empty(): bool { If it is compulsory that your condition is always displayed, override `is_required()` to return true. ```php title="Make the condition compulsory" -public function is_required(): bool { +public function is_required(): bool +{ return true; } ``` @@ -188,7 +200,8 @@ You can either use a different core filter type from `/lib/amd/src/datafilter/fi To tell your filter condition to use a different filter class, override the `get_filter_class()` method to return the namespaced path to your JavaScript class. ```php title="Override the default filter class" -public function get_filter_class(): string { +public function get_filter_class(): string +{ return 'qbank_myplugin/datafilter/filtertype/myfilter'; } ``` diff --git a/versioned_docs/version-4.5/apis/plugintypes/qtype/newquestiondefaults.md b/versioned_docs/version-4.5/apis/plugintypes/qtype/newquestiondefaults.md index c34ce0a02..fb8d4be87 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/qtype/newquestiondefaults.md +++ b/versioned_docs/version-4.5/apis/plugintypes/qtype/newquestiondefaults.md @@ -41,7 +41,8 @@ $mform->setDefault('shuffleanswers', $this->get_default_value('shuffleanswers', Here we need to override the method `save_defaults_for_new_questions` to save the values these settings. For example: ```php - public function save_defaults_for_new_questions(stdClass $fromform): void { + public function save_defaults_for_new_questions(stdClass $fromform): void + { parent::save_defaults_for_new_questions($fromform); $this->set_default_value('shuffleanswers', $fromform->shuffleanswers); } diff --git a/versioned_docs/version-4.5/apis/plugintypes/repository/index.md b/versioned_docs/version-4.5/apis/plugintypes/repository/index.md index 0e940f7ab..c23a86a16 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/repository/index.md +++ b/versioned_docs/version-4.5/apis/plugintypes/repository/index.md @@ -122,7 +122,8 @@ Return any combination of the following values: ```php -function supported_returntypes() { +function supported_returntypes() +{ return FILE_INTERNAL | FILE_EXTERNAL | FILE_REFERENCE | FILE_CONTROLLED_LINK; } ``` @@ -151,7 +152,8 @@ Supported file types can be specified using standard mimetypes (such as `image/g ```php -function supported_filetypes() { +function supported_filetypes() +{ // Allow any kind of file. return '*'; } @@ -161,7 +163,8 @@ function supported_filetypes() { ```php -function supported_filetypes() { +function supported_filetypes() +{ // Example of image mimetypes. return ['image/gif', 'image/jpeg', 'image/png']; } @@ -171,7 +174,8 @@ function supported_filetypes() { ```php -function supported_filetypes() { +function supported_filetypes() +{ // Example of a file group. return ['web_image']; } @@ -204,7 +208,8 @@ Parent function returns an array with a single item - pluginname.
```php -public static function get_type_option_names() { +public static function get_type_option_names() +{ return array_merge(parent::get_type_option_names(), ['rootpath']); } ``` @@ -225,7 +230,8 @@ Optional. This is for modifying the Moodle form displaying the plugin settings. For example, to display the standard repository plugin settings along with the custom ones use: ```php -public static function type_config_form($mform, $classname='repository') { +public static function type_config_form($mform, $classname='repository') +{ parent::type_config_form($mform); $rootpath = get_config('repository_pluginname', 'rootpath'); @@ -244,7 +250,8 @@ This function must be declared static Optional. Use this function if you need to validate some variables submitted by plugin settings form. To use it, check through the associative array of data provided ('settingname' => value) for any errors. Then push the items to $error array in the format ("fieldname" => "human readable error message") to have them highlighted in the form. ```php -public static function type_form_validation($mform, $data, $errors) { +public static function type_form_validation($mform, $data, $errors) +{ if (!is_dir($data['rootpath'])) { $errors['rootpath'] = get_string('invalidrootpath', 'repository_pluginname'); } @@ -271,7 +278,8 @@ Parent function returns an empty array. This is equivalent to **get_type_option_
```php -public static function get_instance_option_names() { +public static function get_instance_option_names() +{ return ['fs_path']; // From repository_filesystem } ``` @@ -292,7 +300,8 @@ Optional. This is for modifying the Moodle form displaying the settings specific For example, to add a required text box called email_address: ```php -public static function get_instance_option_names() { +public static function get_instance_option_names() +{ $mform->addElement( 'text', 'email_address', @@ -318,7 +327,8 @@ This function must be declared static Optional. This allows us to validate what has been submitted in the instance configuration form. This is equivalent to ''type_form_validation($mform, $data, $errors), but for instances. For example: ```php -public static function instance_form_validation($mform, $data, $errors) { +public static function instance_form_validation($mform, $data, $errors) +{ if (empty($data['email_address'])) { $errors['email_address'] = get_string('invalidemailsettingname', 'repository_flickr_public'); } @@ -357,7 +367,8 @@ Firstly the skeleton: * * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ -class repository_flickr_public extends repository { +class repository_flickr_public extends repository +{ } ``` @@ -453,7 +464,8 @@ This function will return a list of files to be displayed to the user, the list * @param string $page * @return array the list of files, including meta information */ -public function get_listing($encodedpath = '', $page = '') { +public function get_listing($encodedpath = '', $page = '') +{ // This methods return [ //this will be used to build navigation bar. @@ -578,7 +590,8 @@ For plugins that do not fully process the login via a popup window, the submitte
```php title="lib/alfresco/lib.php" -public function __construct($repositoryid, $context = SYSCONTEXTID, $options = []) { +public function __construct($repositoryid, $context = SYSCONTEXTID, $options = []) +{ global $SESSION; /* Skipping code that is not relevant to user login */ @@ -618,7 +631,8 @@ Many types include a single element of type 'popup' with the param 'url' pointin
```php title="Code taken from repository_boxnet" -public function print_login() { +public function print_login() +{ $ticket = $this->boxclient->getTicket(); if ($this->options['ajax']) { $loginbtn = (object)[ @@ -652,7 +666,8 @@ This function will return a boolean value to tell Moodle whether the user has lo By default, this function will return true. ```php -public function check_login(): bool { +public function check_login(): bool +{ global $SESSION; return !empty($SESSION->{$this->sessname}); } @@ -663,7 +678,8 @@ public function check_login(): bool { When a user clicks the logout button in file picker, this function will be called. You may clean up the session or disconnect the connection with remote server here. After this the code should return something suitable to display to the user (usually the results of calling **$this->print_login()**): ```php title="lib/alfresco/lib.php" -public function logout() { +public function logout() +{ global $SESSION; unset($SESSION->{$this->sessname}); return $this->print_login(); @@ -689,7 +705,8 @@ For FILE_INTERNAL or FILE_REFERENCE this function is called at the point when th ```php -public function get_file($url, $filename = '') { +public function get_file($url, $filename = '') +{ // Default implementation from the base 'repository' class $path = $this->prepare_file($filename); // Generate a unique temporary filename $curlobject = new curl(); @@ -707,7 +724,8 @@ public function get_file($url, $filename = '') { Slightly extended version taken from repository_equella ```php -public function get_file($reference, $filename = '') { +public function get_file($reference, $filename = '') +{ global $USER; // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference->reference)); @@ -768,7 +786,8 @@ A custom search form must include the following:
```php title="The default implementation in class 'repository'" -public function print_search() { +public function print_search() +{ global $PAGE; $renderer = $PAGE->get_renderer('core', 'files'); return $renderer->repository_default_searchform(); @@ -793,7 +812,8 @@ The return should return an array containing:
```php title="Example from repoistory_googledocs" -public function search($search_text, $page = 0) { +public function search($search_text, $page = 0) +{ $gdocs = new google_docs($this->googleoauth); return [ 'dynload' => true, @@ -822,7 +842,8 @@ Note that external file is synchronised by moodle when UI wants to show the file Return minimum number of seconds before checking for changes to the file (default implementation = 1 day) ```php -public function get_reference_file_lifetime($ref) { +public function get_reference_file_lifetime($ref) +{ return DAYSECS; // One day, 60 * 60 * 24 seconds. } ``` @@ -832,7 +853,8 @@ public function get_reference_file_lifetime($ref) { Called after the file has reached the 'lifetime' specified above to see if it should now be synchronised (default implementation is to return true) ```php -public function sync_individual_file(stored_file $storedfile) { +public function sync_individual_file(stored_file $storedfile) +{ return true; } ``` @@ -851,7 +873,8 @@ This is usually prefixed with the repository name, and a semicolon. For example:
```php title="lib.php" -public function get_reference_details($reference, $filestatus = 0) { +public function get_reference_details($reference, $filestatus = 0) +{ if (!$filestatus) { // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference); @@ -879,7 +902,8 @@ Returns up-to-date information about the original file, only called when the 'li
```php title="/lib.php" -public function get_file_by_reference($reference) { +public function get_file_by_reference($reference) +{ global $USER; // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference->reference)); @@ -946,7 +970,8 @@ It is up to the repository developer to decide whether to actually download the
```php title="/lib.php" -public function send_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) { +public function send_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) +{ // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($stored_file->get_reference())); $url = $this->appendtoken($details->url); diff --git a/versioned_docs/version-4.5/apis/plugintypes/sms/index.md b/versioned_docs/version-4.5/apis/plugintypes/sms/index.md index 1e9235bff..8baec2ec7 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/sms/index.md +++ b/versioned_docs/version-4.5/apis/plugintypes/sms/index.md @@ -65,7 +65,8 @@ namespace smsgateway_aws; use smsgateway_aws\local\service\aws_sns; -class gateway extends \core_sms\gateway { +class gateway extends \core_sms\gateway +{ #[\Override] public function send( message $message, @@ -95,7 +96,8 @@ class gateway extends \core_sms\gateway { ); } - private function get_gateway_service(\stdClass $config): string { + private function get_gateway_service(\stdClass $config): string + { return match ($config->gateway) { 'aws_sns' => aws_sns::class, default => throw new moodle_exception("Unknown Message Handler {$config->gateway}"), @@ -103,7 +105,8 @@ class gateway extends \core_sms\gateway { } #[\Override] - public function get_send_priority(message $message): int { + public function get_send_priority(message $message): int + { return 50; } } @@ -120,7 +123,8 @@ It is necessary for plugins developers to assess these hooks and implement accor This hook will allow plugins to add required form fields to assist users in configuring their SMS gateway. ```php title="Listener method for after_sms_gateway_form_hook" -public static function set_form_definition_for_aws_sms_gateway(after_sms_gateway_form_hook $hook): void { +public static function set_form_definition_for_aws_sms_gateway(after_sms_gateway_form_hook $hook): void +{ if ($hook->plugin !== 'smsgateway_example') { return; } diff --git a/versioned_docs/version-4.5/apis/plugintypes/theme/index.md b/versioned_docs/version-4.5/apis/plugintypes/theme/index.md index 371b703c4..c3cd0b8b0 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/theme/index.md +++ b/versioned_docs/version-4.5/apis/plugintypes/theme/index.md @@ -108,7 +108,8 @@ $THEME->sheets = []; $THEME->editor_sheets = []; $THEME->editor_scss = ['editor']; $THEME->usefallback = true; -$THEME->scss = function($theme) { +$THEME->scss = function($theme) +{ return theme_boost_get_main_scss_content($theme); }; diff --git a/versioned_docs/version-4.5/apis/plugintypes/tiny/index.md b/versioned_docs/version-4.5/apis/plugintypes/tiny/index.md index 831f0cfef..38dbd3cbe 100644 --- a/versioned_docs/version-4.5/apis/plugintypes/tiny/index.md +++ b/versioned_docs/version-4.5/apis/plugintypes/tiny/index.md @@ -398,7 +398,8 @@ use context; use editor_tiny\plugin; use editor_tiny\plugin_with_configuration; -class plugininfo extends plugin implements plugin_with_configuration { +class plugininfo extends plugin implements plugin_with_configuration +{ public static function get_plugin_configuration_for_context( context $context, array $options, diff --git a/versioned_docs/version-4.5/apis/subsystems/access.md b/versioned_docs/version-4.5/apis/subsystems/access.md index 06ea7efeb..d0b39391d 100644 --- a/versioned_docs/version-4.5/apis/subsystems/access.md +++ b/versioned_docs/version-4.5/apis/subsystems/access.md @@ -167,7 +167,8 @@ By default checks the capabilities of the current user, but you can pass a diffe Function require_capability() is very similar, it is throwing access control exception if user does not have the capability. ```php -function require_capability($capability, context $context, $userid = null, $doanything = true, $errormessage = 'nopermissions', $stringfile = _) { +function require_capability($capability, context $context, $userid = null, $doanything = true, $errormessage = 'nopermissions', $stringfile = _) +{ ``` ### Enrolment functions {/* #enrolment-functions */} diff --git a/versioned_docs/version-4.5/apis/subsystems/ai/index.md b/versioned_docs/version-4.5/apis/subsystems/ai/index.md index a9eea0e34..33d989c02 100644 --- a/versioned_docs/version-4.5/apis/subsystems/ai/index.md +++ b/versioned_docs/version-4.5/apis/subsystems/ai/index.md @@ -159,7 +159,8 @@ public function __construct( ```php title="Example: The store() method for the generate_image Action" #[\Override] -public function store(response_base $response): int { +public function store(response_base $response): int +{ global $DB; $responsearr = $response->get_response_data(); @@ -216,7 +217,8 @@ it sets these against class variables so they can be retrieved by the Manager an ```php title="Example: The set_response_data() for the generate_image Action response" #[\Override] - public function set_response_data(array $response): void { + public function set_response_data(array $response): void + { $this->draftfile = $response['draftfile'] ?? null; $this->revisedprompt = $response['revisedprompt'] ?? null; $this->sourceurl = $response['sourceurl'] ?? null; @@ -229,7 +231,8 @@ Returns the set response data. ```php title="Example: The get_response_data() for the generate_image Action response" #[\Override] - public function get_response_data(): array { + public function get_response_data(): array + { return [ 'draftfile' => $this->draftfile, 'revisedprompt' => $this->revisedprompt, diff --git a/versioned_docs/version-4.5/apis/subsystems/analytics/index.md b/versioned_docs/version-4.5/apis/subsystems/analytics/index.md index 1f4c3e3e7..20b1eddc8 100644 --- a/versioned_docs/version-4.5/apis/subsystems/analytics/index.md +++ b/versioned_docs/version-4.5/apis/subsystems/analytics/index.md @@ -378,7 +378,8 @@ You can overwrite a `new one_sample_per_analysable()` method if the analysables * * @return bool */ -public static function one_sample_per_analysable() { +public static function one_sample_per_analysable() +{ return true; } ``` @@ -398,7 +399,8 @@ You can use `required_sample_data` to specify what your indicator needs to be ca * * @return null|string[] Name of the required elements (use the database tablename) */ -public static function required_sample_data() { +public static function required_sample_data() +{ return null; } ``` diff --git a/versioned_docs/version-4.5/apis/subsystems/backup/index.md b/versioned_docs/version-4.5/apis/subsystems/backup/index.md index 95245f909..10089ab62 100644 --- a/versioned_docs/version-4.5/apis/subsystems/backup/index.md +++ b/versioned_docs/version-4.5/apis/subsystems/backup/index.md @@ -95,9 +95,11 @@ Here is a minimalistic task: ```php require_once($CFG->dirroot . '/backup/moodle2/backup_tool_plugin.class.php'); -class backup_tool_foobar_plugin extends backup_tool_plugin { +class backup_tool_foobar_plugin extends backup_tool_plugin +{ - protected function define_course_plugin_structure() { + protected function define_course_plugin_structure() + { $this->step->log('Yay, backup!', backup::LOG_DEBUG); return $plugin; } diff --git a/versioned_docs/version-4.5/apis/subsystems/backup/restore.md b/versioned_docs/version-4.5/apis/subsystems/backup/restore.md index 16aca9f2a..cf5ee2123 100644 --- a/versioned_docs/version-4.5/apis/subsystems/backup/restore.md +++ b/versioned_docs/version-4.5/apis/subsystems/backup/restore.md @@ -41,9 +41,11 @@ Here is a minimalistic task: ```php require_once($CFG->dirroot . '/backup/moodle2/restore_tool_plugin.class.php'); -class restore_tool_foobar_plugin extends restore_tool_plugin { +class restore_tool_foobar_plugin extends restore_tool_plugin +{ - protected function define_course_plugin_structure() { + protected function define_course_plugin_structure() + { $paths = array(); $this->step->log('Yay, restore!', backup::LOG_DEBUG); return $paths; diff --git a/versioned_docs/version-4.5/apis/subsystems/check/index.md b/versioned_docs/version-4.5/apis/subsystems/check/index.md index 51b97ca38..5fbc14021 100644 --- a/versioned_docs/version-4.5/apis/subsystems/check/index.md +++ b/versioned_docs/version-4.5/apis/subsystems/check/index.md @@ -103,14 +103,17 @@ namespace mod_myplugin\check; use core\check\check; use core\check\result; -class foobar extends check { +class foobar extends check +{ - public function get_action_link(): ?\action_link { + public function get_action_link(): ?\action_link + { $url = new \moodle_url('/mod/myplugin/dosomething.php'); return new \action_link($url, get_string('sitepolicies', 'admin')); } - public function get_result(): result { + public function get_result(): result + { if (some_check()) { $status = result::ERROR; $summary = get_string('check_foobar_error', 'mod_myplugin'); @@ -145,7 +148,8 @@ Next decide on what type of check it should be which determines what report it w Implement the right callback in lib.php for the report you want to add it to, and return an array (usually with only 1 item) of check objects: ```php title="/mod/myplugin/lib.php" -function mod_myplugin_security_checks(): array { +function mod_myplugin_security_checks(): array +{ return [new \mod_myplugin\check\foobar()]; } ``` @@ -157,7 +161,8 @@ Checks have been designed to be dynamic so you can return different checks depen If you plan to return multiple instances of a check class, make sure that each instance has a unique id. ```php -function mod_myplugin_security_checks(): array { +function mod_myplugin_security_checks(): array +{ return [ new \mod_myplugin\check\foobar('one'), new \mod_myplugin\check\foobar('two'), @@ -170,14 +175,17 @@ Set the internal id in a way which is unique across all instances in your compon ```php namespace mod_myplugin\check; -class foobar extends \core\check\check { +class foobar extends \core\check\check +{ protected $id = ''; - public function __construct($id) { + public function __construct($id) + { $this->id = "foobar{$id}"; } - public function get_id(): string { + public function get_id(): string + { return $this->id; } ... @@ -197,17 +205,21 @@ Checks can provide details on a check, such as the complete list of bad records. namespace mod_myplugin\check; -class foobar extends \core\check\check { - public function get_result(): result { +class foobar extends \core\check\check +{ + public function get_result(): result + { return new foobar_result(); } } ``` ```php -class foobar_result extends \core\check\result { +class foobar_result extends \core\check\result +{ ... - public function get_details(): string { + public function get_details(): string + { // Do expensive lookups in here. } } diff --git a/versioned_docs/version-4.5/apis/subsystems/communication/index.md b/versioned_docs/version-4.5/apis/subsystems/communication/index.md index b1107afd4..36697cea8 100644 --- a/versioned_docs/version-4.5/apis/subsystems/communication/index.md +++ b/versioned_docs/version-4.5/apis/subsystems/communication/index.md @@ -291,8 +291,10 @@ This method accepts the following parameters: For example, we have a form where we want to have the communication settings, we can use the below code to add the form elements to the form. ```php -class configure_form extends \moodleform { - public function definition() { +class configure_form extends \moodleform +{ + public function definition() + { $mform = $this->_form; $communication = \core_communication\api::load_by_instance( context: $context, diff --git a/versioned_docs/version-4.5/apis/subsystems/external/files.md b/versioned_docs/version-4.5/apis/subsystems/external/files.md index 627d27648..4eb1fbf23 100644 --- a/versioned_docs/version-4.5/apis/subsystems/external/files.md +++ b/versioned_docs/version-4.5/apis/subsystems/external/files.md @@ -119,7 +119,8 @@ $forum->introfiles = external_util::get_area_files($context->id, 'mod_forum', 'i You can also use the `external_files` structure definition in combination with the method to return the most common file fields required by WS clients. ```php -public static function execute_returns(): external_multiple_structure { +public static function execute_returns(): external_multiple_structure +{ return new external_multiple_structure( new external_single_structure([ 'id' => new external_value(PARAM_INT, 'Forum id'), diff --git a/versioned_docs/version-4.5/apis/subsystems/external/functions.md b/versioned_docs/version-4.5/apis/subsystems/external/functions.md index 295a3cca0..617f40ba8 100644 --- a/versioned_docs/version-4.5/apis/subsystems/external/functions.md +++ b/versioned_docs/version-4.5/apis/subsystems/external/functions.md @@ -65,8 +65,10 @@ use core_external\external_multiple_structure; use core_external\external_single_structure; use core_external\external_value; -class create_groups extends \core_external\external_api { - public static function execute_parameters(): external_function_parameters { +class create_groups extends \core_external\external_api +{ + public static function execute_parameters(): external_function_parameters + { return new external_function_parameters([ 'groups' => new external_multiple_structure( new external_single_structure([ @@ -92,7 +94,8 @@ class create_groups extends \core_external\external_api { ]); } - public static function execute(array $groups): array { + public static function execute(array $groups): array + { // Validate all of the parameters. [ 'groups' => $groups, @@ -114,7 +117,8 @@ class create_groups extends \core_external\external_api { ]; } - public static function execute_returns(): external_single_structure { + public static function execute_returns(): external_single_structure + { return new external_single_structure([ 'groups' => new external_multiple_structure([ 'id' => new external_value(PARAM_INT, 'Id of the created user'), diff --git a/versioned_docs/version-4.5/apis/subsystems/external/security.md b/versioned_docs/version-4.5/apis/subsystems/external/security.md index b6c0cc685..2d9a721e3 100644 --- a/versioned_docs/version-4.5/apis/subsystems/external/security.md +++ b/versioned_docs/version-4.5/apis/subsystems/external/security.md @@ -22,7 +22,8 @@ To do so you should call the `validate_parameters()` function, passing in the re The `validate_parameters()` function is defined on the `\core_external\external_api` class, and can be called as follows: ```php title="local/groupmanager/classes/external/create_groups.php" -public static function execute(array $groups): array { +public static function execute(array $groups): array +{ [ 'groups' => $groups, ] = self::validate_parameters(self::execute_parameters(), [ @@ -45,7 +46,8 @@ If your function operates on multiple contexts (like a list of courses), you mus The `validate_context()` function is defined on the `\core_external\external_api` class, and can be called as follows: ```php title="local/groupmanager/classes/external/create_groups.php" -public static function execute(array $groups): array { +public static function execute(array $groups): array +{ // ... foreach ($groups as $group) { $coursecontext = \context_course::instance($group['courseid']); diff --git a/versioned_docs/version-4.5/apis/subsystems/external/testing.md b/versioned_docs/version-4.5/apis/subsystems/external/testing.md index 8277a6dc9..ab5acac24 100644 --- a/versioned_docs/version-4.5/apis/subsystems/external/testing.md +++ b/versioned_docs/version-4.5/apis/subsystems/external/testing.md @@ -57,14 +57,16 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/webservice/tests/helpers.php'); -class get_fruit_test extends externallib_advanced_testcase { +class get_fruit_test extends externallib_advanced_testcase +{ /** * Test the execute function when capabilities are present. * * @covers \mod_fruit\external\get_fruit::execute */ - public function test_capabilities(): void { + public function test_capabilities(): void + { $this->resetAfterTest(true); $course = $this->getDataGenerator()->create_course(); @@ -99,7 +101,8 @@ class get_fruit_test extends externallib_advanced_testcase { * * @covers \mod_fruit\external\get_fruit::execute */ - public function test_capabilities_missing(): void { + public function test_capabilities_missing(): void + { global $USER; $this->resetAfterTest(true); diff --git a/versioned_docs/version-4.5/apis/subsystems/external/writing-a-service.md b/versioned_docs/version-4.5/apis/subsystems/external/writing-a-service.md index ff27b17c1..87aa9a1a3 100644 --- a/versioned_docs/version-4.5/apis/subsystems/external/writing-a-service.md +++ b/versioned_docs/version-4.5/apis/subsystems/external/writing-a-service.md @@ -150,13 +150,15 @@ use core_external\external_multiple_structure; use core_external\external_single_structure; use core_external\external_value; -class create_groups extends \core_external\external_api { +class create_groups extends \core_external\external_api +{ /** * Returns description of method parameters * @return external_function_parameters */ - public static function execute_parameters() { + public static function execute_parameters() + { return new external_function_parameters([ 'groups' => new external_multiple_structure( new external_single_structure([ @@ -187,7 +189,8 @@ A web service function without parameters will have a parameter description func * Returns description of method parameters * @return external_function_parameters */ -public static function execute_parameters(): external_function_parameters { +public static function execute_parameters(): external_function_parameters +{ return new external_function_parameters([ // If this function had any parameters, they would be described here. // This example has no parameters, so the array is empty. @@ -208,7 +211,8 @@ Our `create_groups()` function expects one parameter named `groups`, so we will * Returns description of method parameters * @return external_function_parameters */ -public static function execute_parameters(): external_function_parameters { +public static function execute_parameters(): external_function_parameters +{ return new external_function_parameters([ 'groups' => ... ]); @@ -280,7 +284,8 @@ We add them to the description : It's similar to execute_parameters(), but instead of describing the parameters, it describes the return values. ```php -public static function execute_returns() { +public static function execute_returns() +{ return new external_multiple_structure( new external_single_structure([ 'id' => new external_value(PARAM_INT, 'group record id'), @@ -312,7 +317,8 @@ Because some web service protocols are strict about the number and types of argu ```php -public static function get_biscuit_parameters() { +public static function get_biscuit_parameters() +{ return new external_function_parameters([ 'chocolatechips' => new external_value( PARAM_BOOL, @@ -340,7 +346,8 @@ public static function get_biscuit_parameters() { ```php -public static function get_biscuit_parameters() { +public static function get_biscuit_parameters() +{ return new external_function_parameters([ 'ifeellike' => new external_single_structure([ 'chocolatechips' => new external_value( @@ -379,7 +386,8 @@ We declared our web service function and we defined the external function parame * @param array $groups array of group description arrays (with keys groupname and courseid) * @return array of newly created groups */ - public static function execute($groups) { + public static function execute($groups) + { global $CFG, $DB; require_once("$CFG->dirroot/group/lib.php"); @@ -471,7 +479,8 @@ External functions deprecation process is slightly different from the standard d * Mark the function as deprecated. * @return bool */ - public static function execute_is_deprecated() { + public static function execute_is_deprecated() + { return true; } ``` diff --git a/versioned_docs/version-4.5/apis/subsystems/files/browsing.md b/versioned_docs/version-4.5/apis/subsystems/files/browsing.md index ca758d27a..ba98c974f 100644 --- a/versioned_docs/version-4.5/apis/subsystems/files/browsing.md +++ b/versioned_docs/version-4.5/apis/subsystems/files/browsing.md @@ -12,7 +12,8 @@ The File Browser API is a supplemental API which can be used to fetch informatio This example demonstrates using the `filebrowser` API to fetch the parent folders of a file. ```php -public function get_file_breadcrumbs(\stored_file $file): ?array { +public function get_file_breadcrumbs(\stored_file $file): ?array +{ $browser = get_file_browser(); $context = get_system_context(); diff --git a/versioned_docs/version-4.5/apis/subsystems/form/advanced/checkbox-controller.md b/versioned_docs/version-4.5/apis/subsystems/form/advanced/checkbox-controller.md index 2a212175e..3f7c3961a 100644 --- a/versioned_docs/version-4.5/apis/subsystems/form/advanced/checkbox-controller.md +++ b/versioned_docs/version-4.5/apis/subsystems/form/advanced/checkbox-controller.md @@ -16,7 +16,8 @@ You can add as many groups of checkboxes as you like, as long as they are unique When adding checkboxes, you can add them in _groups_. Each group of checkboxes must have a unique integer name, for example: ```php title="classes/form/example_form.php" -public function definition(): void { +public function definition(): void +{ // These two elements are part of group 1. $mform->addElement('advcheckbox', 'test1', 'Test 1', null, ['group' => 1]); $mform->addElement('advcheckbox', 'test2', 'Test 2', null, ['group' => 1]); diff --git a/versioned_docs/version-4.5/apis/subsystems/form/index.md b/versioned_docs/version-4.5/apis/subsystems/form/index.md index 065b76e6a..6a57843ec 100644 --- a/versioned_docs/version-4.5/apis/subsystems/form/index.md +++ b/versioned_docs/version-4.5/apis/subsystems/form/index.md @@ -41,9 +41,11 @@ namespace [plugintype]_[pluginname]\form; // moodleform is defined in formslib.php require_once("$CFG->libdir/formslib.php"); -class simplehtml_form extends \moodleform { +class simplehtml_form extends \moodleform +{ // Add elements to form. - public function definition() { + public function definition() + { // A reference to the form is stored in $this->form. // A common convention is to store it in a variable, such as `$mform`. $mform = $this->_form; // Don't forget the underscore! @@ -59,7 +61,8 @@ class simplehtml_form extends \moodleform { } // Custom validation should be added here. - function validation($data, $files) { + function validation($data, $files) + { return []; } } @@ -99,12 +102,15 @@ If you wish to use the form within a block then you should consider using the re Note that the render method does the same as the display method, except returning the HTML rather than outputting it to the browser, as with above make sure you've included the file which contains the class for your Moodle form. ```php -class block_yourblock extends block_base { - public function init(){ +class block_yourblock extends block_base +{ + public function init() + { $this->title = 'Your Block'; } - public function get_content(){ + public function get_content() + { $this->content = (object) [ 'text' => '', ]; @@ -237,7 +243,8 @@ public function add_action_buttons( The `add_action_buttons` function is defined on the `moodleform` class, and not a part of `$this->_form`, for example: ```php - public function definition() { + public function definition() + { // Add your form elements here. $this->_form->addElement(...); @@ -296,7 +303,8 @@ In some cases this is not the desired behaviour, in which case the [disable_form For example: ```php -public function definition() { +public function definition() +{ // Your definition goes here. // Disable the form change checker for this form. @@ -313,7 +321,8 @@ Only header names would be accepted and added to `_shownonlyelements` array. Headers included in `_shownonlyelements` will be shown expanded in the form. The rest of the headers will be hidden. ```php -public function filter_shown_headers(array $shownonly): void { +public function filter_shown_headers(array $shownonly): void +{ $this->_shownonlyelements = []; if (empty($shownonly)) { return; diff --git a/versioned_docs/version-4.5/apis/subsystems/form/usage/index.md b/versioned_docs/version-4.5/apis/subsystems/form/usage/index.md index 0369cddb1..f1fc7de14 100644 --- a/versioned_docs/version-4.5/apis/subsystems/form/usage/index.md +++ b/versioned_docs/version-4.5/apis/subsystems/form/usage/index.md @@ -79,7 +79,8 @@ In most cases you can place this in an auto-loadable class, in which case it sho namespace mod_forum\form; -class myform extends \moodleform { +class myform extends \moodleform +{ // ... } ``` @@ -127,8 +128,10 @@ Moodle has a set of standard form elements used by all Activity modules. These a The `standard_coursemodule_elements()` function is used to add these common elements, and it should be called _before_ the standard action elements are added, for example: ```php -class mod_example_mod_form extends \moodleform_mod { - public function definition() { +class mod_example_mod_form extends \moodleform_mod +{ + public function definition() + { // Add the various form elements. $this->_form->addElement( ... ); diff --git a/versioned_docs/version-4.5/apis/subsystems/output/index.md b/versioned_docs/version-4.5/apis/subsystems/output/index.md index efea08e41..d22375db8 100644 --- a/versioned_docs/version-4.5/apis/subsystems/output/index.md +++ b/versioned_docs/version-4.5/apis/subsystems/output/index.md @@ -121,11 +121,13 @@ use renderer_base; use templatable; use stdClass; -class index_page implements renderable, templatable { +class index_page implements renderable, templatable +{ /** @var string $sometext Some text to show how to pass data to a template. */ private $sometext = null; - public function __construct($sometext): void { + public function __construct($sometext): void + { $this->sometext = $sometext; } @@ -134,7 +136,8 @@ class index_page implements renderable, templatable { * * @return stdClass */ - public function export_for_template(renderer_base $output): stdClass { + public function export_for_template(renderer_base $output): stdClass + { $data = new stdClass(); $data->sometext = $this->sometext; return $data; @@ -157,7 +160,8 @@ If you wish to use a specific template to render the content you may specify any * * @return string */ - public function get_template_name(\renderer_base $renderer): string { + public function get_template_name(\renderer_base $renderer): string + { return 'tool_demo/index_page'; } ``` @@ -172,7 +176,8 @@ namespace tool_demo\output; use plugin_renderer_base; -class renderer extends plugin_renderer_base { +class renderer extends plugin_renderer_base +{ /** * Defer to template. * @@ -180,7 +185,8 @@ class renderer extends plugin_renderer_base { * * @return string html for the page */ - public function render_index_page($page): string { + public function render_index_page($page): string + { $data = $page->export_for_template($this); return parent::render_from_template('tool_demo/index_page', $data); } @@ -438,11 +444,13 @@ mtrace('DONE'); Or a scheduled or adhoc task, via a trait. Example: ```php -class stored_progress_scheduled_task_example extends \core\task\scheduled_task { +class stored_progress_scheduled_task_example extends \core\task\scheduled_task +{ use \core\task\stored_progress_task_trait; - public function execute() { + public function execute() + { // This simulates a specific count of iterations the task will do, e.g. x number of courses to loop through and do something. $iterations = 100; diff --git a/versioned_docs/version-4.5/apis/subsystems/output/inplace.md b/versioned_docs/version-4.5/apis/subsystems/output/inplace.md index fa1bfdf99..dc7f5c5f0 100644 --- a/versioned_docs/version-4.5/apis/subsystems/output/inplace.md +++ b/versioned_docs/version-4.5/apis/subsystems/output/inplace.md @@ -17,7 +17,8 @@ The best way is to explain the usage on a simple example. Imagine we have plugin Define a callback in `/admin/tool/mytest/lib.php` that starts with the plugin name and ends with `_inplace_editable`: ```php title="admin/tool/mytest/lib.php" -function tool_mytest_inplace_editable($itemtype, $itemid, $newvalue) { +function tool_mytest_inplace_editable($itemtype, $itemid, $newvalue) +{ global $DB; if ($itemtype === 'mytestname') { @@ -80,13 +81,15 @@ This was a very simplified example, in the real life you will probably want to: ```php title="admin/tool/mytest/classes/local/inplace_edit_text.php" -class inplace_edit_text extends \core\output\inplace_editable { +class inplace_edit_text extends \core\output\inplace_editable +{ /** * Constructor. * * @param object $record */ - public function __construct($record) { + public function __construct($record) + { parent::__construct( component: 'tool_mytest', // The item type as managed your plugin. @@ -119,7 +122,8 @@ class inplace_edit_text extends \core\output\inplace_editable { * @param mixed $newvalue * @return \self */ - public static function update($itemid, $newvalue) { + public static function update($itemid, $newvalue) + { // Clean the new value. $newvalue = clean_param($newvalue, PARAM_INT); @@ -194,13 +198,15 @@ $tmpl->set_type_toggle([0, 1]);
```php title="admin/tool/mytest/classes/local/inplace_edit_select.php" -class inplace_edit_select extends \core\output\inplace_editable { +class inplace_edit_select extends \core\output\inplace_editable +{ /** * Constructor. * * @param \stdClass $record */ - public function __construct($record) { + public function __construct($record) + { // Get the options for inplace_edit select box. // The array needs the format: // $options = [ @@ -241,7 +247,8 @@ class inplace_edit_select extends \core\output\inplace_editable { * @param mixed $newvalue * @return \self */ - public static function update($itemid, $newvalue) { + public static function update($itemid, $newvalue) + { // Clean the new value. $newvalue = clean_param($newvalue, PARAM_INT); diff --git a/versioned_docs/version-4.5/apis/subsystems/privacy/index.md b/versioned_docs/version-4.5/apis/subsystems/privacy/index.md index 83e341479..35c99c1b4 100644 --- a/versioned_docs/version-4.5/apis/subsystems/privacy/index.md +++ b/versioned_docs/version-4.5/apis/subsystems/privacy/index.md @@ -119,7 +119,8 @@ class provider implements * * @return string */ - public static function get_reason(): string { + public static function get_reason(): string + { return 'privacy:metadata'; } } @@ -179,7 +180,8 @@ class provider implements // This plugin does store personal user data. \core_privacy\local\metadata\provider { - public static function get_metadata(collection $collection): collection { + public static function get_metadata(collection $collection): collection + { // Here you will add more items into the collection. @@ -214,7 +216,8 @@ Some subsystems which store user data do not need to be listed: ##### Example {/* #example-2 */} ```php title="mod/forum/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_subsystem_link( 'core_files', @@ -243,7 +246,8 @@ It is a matter of judgement which fields contain user data and which don't. Anyt ##### Example {/* #example-3 */} ```php title="mod/forum/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_database_table( 'forum_discussion_subs', @@ -291,7 +295,8 @@ Any plugin providing user preferences must also implement the `\core_privacy\loc ##### Example {/* #example-4 */} ```php title="admin/tool/usertours/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_user_preference('tool_usertours_tour_completion_time', 'privacy:metadata:preference:tool_usertours_tour_completion_time'); @@ -318,7 +323,8 @@ You can indicate this by calling the `add_external_location_link()` method on th ##### Example {/* #example-5 */} ```php title="mod/lti/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_external_location_link('lti_client', [ 'userid' => 'privacy:metadata:lti_client:userid', 'fullname' => 'privacy:metadata:lti_client:fullname', @@ -385,15 +391,16 @@ if (interface_exists('\core_privacy\local\request\userlist')) { } -class provider implements my_userlist { +class provider implements my_userlist +{ /** * Get the list of users who have data within a context. * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ - public static function get_users_in_context(userlist $userlist) { - + public static function get_users_in_context(userlist $userlist) + { } /** @@ -401,8 +408,8 @@ class provider implements my_userlist { * * @param approved_userlist $userlist The approved context and user information to delete information for. */ - public static function delete_data_for_users(approved_userlist $userlist) { - + public static function delete_data_for_users(approved_userlist $userlist) + { } } @@ -421,7 +428,9 @@ Contexts are retrieved using the `get_contexts_for_userid` function which takes * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist {} +public static function get_contexts_for_userid(int $userid): contextlist +{ +} ``` The function returns a `\core_privacy\local\request\contextlist` which is used to keep a set of contexts together in a fixed fashion. @@ -443,7 +452,8 @@ The following example simply fetches the contextid for all forums where a user h * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist { +public static function get_contexts_for_userid(int $userid): contextlist +{ $contextlist = new \core_privacy\local\request\contextlist(); $sql = "SELECT c.id @@ -490,7 +500,8 @@ In the case of the rating data, this will include any post where the user has ra * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist { +public static function get_contexts_for_userid(int $userid): contextlist +{ $ratingsql = \core_rating\privacy\provider::get_sql_join('rat', 'mod_forum', 'post', 'p.id', $userid); // Fetch all forum discussions, and forum posts. $sql = "SELECT c.id @@ -555,7 +566,9 @@ This method is very similar to the `get_contexts_for_userid` function but has so * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ -public static function get_users_in_context(userlist $userlist) {} +public static function get_users_in_context(userlist $userlist) +{ +} ``` ###### Basic example {/* #basic-example-1 */} @@ -568,8 +581,8 @@ The following example simply fetches the userid for all users in a given forum c * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ -public static function get_users_in_context(userlist $userlist) { - +public static function get_users_in_context(userlist $userlist) +{ $context = $userlist->get_context(); if (!$context instanceof \context_module) { @@ -616,7 +629,9 @@ This is achieved through use of the `export_user_data` function which takes the * * @param approved_contextlist $contextlist The approved contexts to export information for. */ -public static function export_user_data(approved_contextlist $contextlist) {} +public static function export_user_data(approved_contextlist $contextlist) +{ +} ``` The `approved_contextlist` includes both the user record, and a list of contexts, which can be retrieved by either processing it as an Iterator, or by calling `get_contextids()` or `get_contexts()` as required. @@ -642,7 +657,8 @@ You need to provide a description of the value of the user preference. (This des * * @param int $userid The userid of the user whose data is to be exported. */ -public static function export_user_preferences(int $userid) { +public static function export_user_preferences(int $userid) +{ $markasreadonnotification = get_user_preferences('markasreadonnotification', null, $userid); if (null !== $markasreadonnotification) { switch ($markasreadonnotification) { @@ -829,7 +845,8 @@ When expiring content for a high-level context such as a course context, the fun * * @param context $context Context to delete data from. */ -public static function delete_data_for_all_users_in_context(\context $context) { +public static function delete_data_for_all_users_in_context(\context $context) +{ global $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -850,7 +867,8 @@ public static function delete_data_for_all_users_in_context(\context $context) { An *approved_contextlist* is given and user data related to that user should either be completely deleted, or overwritten if a structure needs to be maintained. This will be called when a user has requested the right to be forgotten. All attempts should be made to delete this data where practical while still allowing the plugin to be used by other users. ```php title="mod/choice/classes/privacy/provider.php" -public static function delete_data_for_user(approved_contextlist $contextlist) { +public static function delete_data_for_user(approved_contextlist $contextlist) +{ global $DB; if (empty($contextlist->count())) { @@ -874,7 +892,8 @@ An *approved_userlist* is given and user data related to all users in the specif * * @param approved_userlist $userlist The approved context and user information to delete information for. */ -public static function delete_data_for_users(approved_userlist $userlist) { +public static function delete_data_for_users(approved_userlist $userlist) +{ global $DB; $context = $userlist->get_context(); @@ -915,7 +934,8 @@ class provider implements use \core_privacy\local\legacy_polyfill; // The required methods must be in this format starting with an underscore. - public static function _get_metadata(collection $collection) { + public static function _get_metadata(collection $collection) + { // Code for returning metadata goes here. } ``` @@ -943,12 +963,14 @@ class provider implements use \core_plagiarism\privacy\plagiarism_provider\legacy_polyfill; // The required methods must be in this format starting with an underscore. - public static function _get_metadata(collection $collection) { + public static function _get_metadata(collection $collection) + { // Code for returning metadata goes here. } // This is one of the polyfilled methods from the plagiarism provider. - public static function _export_plagiarism_user_data($userid, \context $context, array $subcontext, array $linkarray) { + public static function _export_plagiarism_user_data($userid, \context $context, array $subcontext, array $linkarray) + { // ... } ``` @@ -969,7 +991,8 @@ if (interface_exists('\core_privacy\local\request\core_userlist_provider')) { interface core_userlist_provider {} } -class provider implements core_userlist_provider { +class provider implements core_userlist_provider +{ ``` ## Tips for development {/* #tips-for-development */} diff --git a/versioned_docs/version-4.5/apis/subsystems/privacy/utils.md b/versioned_docs/version-4.5/apis/subsystems/privacy/utils.md index fdbcfb74f..c47c10086 100644 --- a/versioned_docs/version-4.5/apis/subsystems/privacy/utils.md +++ b/versioned_docs/version-4.5/apis/subsystems/privacy/utils.md @@ -108,7 +108,8 @@ foreach ($list->good as $component) { echo "\n\n== Done ==\n"; -function check_implements($component, $interface) { +function check_implements($component, $interface) +{ $manager = new \core_privacy\manager(); $rc = new \ReflectionClass(\core_privacy\manager::class); $rcm = $rc->getMethod('component_implements'); diff --git a/versioned_docs/version-4.5/apis/subsystems/routing/index.md b/versioned_docs/version-4.5/apis/subsystems/routing/index.md index 38b150921..bce11a503 100644 --- a/versioned_docs/version-4.5/apis/subsystems/routing/index.md +++ b/versioned_docs/version-4.5/apis/subsystems/routing/index.md @@ -54,7 +54,8 @@ use core\router\schema\response\payload_response; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -class example { +class example +{ #[\core\router\route( // Resolves to https://example.com/moodle/api/rest/v2/mod_example/example path: '/example', diff --git a/versioned_docs/version-4.5/apis/subsystems/routing/parameters.md b/versioned_docs/version-4.5/apis/subsystems/routing/parameters.md index 75474757b..b57c1a944 100644 --- a/versioned_docs/version-4.5/apis/subsystems/routing/parameters.md +++ b/versioned_docs/version-4.5/apis/subsystems/routing/parameters.md @@ -36,7 +36,8 @@ use core\param; use core\router\route; use core\router\schema\parameters\path_parameter; -class example { +class example +{ #[route( path: '/users/{username}', pathtypes: [ @@ -70,7 +71,8 @@ use core\param; use core\router\route; use core\router\schema\parameters\path_parameter; -class example { +class example +{ #[route( path: '/users/{username}', pathtypes: [ @@ -533,7 +535,8 @@ class path_course extends \core\router\schema\parameters\path_parameter implemen * @return object * @throws not_found_exception If the course cannot be found */ - protected function get_course_for_value(string $value): mixed { + protected function get_course_for_value(string $value): mixed + { global $DB; $data = false; @@ -572,7 +575,8 @@ class path_course extends \core\router\schema\parameters\path_parameter implemen } #[\Override] - public function get_schema_from_type(param $type): \stdClass { + public function get_schema_from_type(param $type): \stdClass + { $schema = parent::get_schema_from_type($type); $schema->pattern = "^("; diff --git a/versioned_docs/version-4.5/apis/subsystems/routing/responses.md b/versioned_docs/version-4.5/apis/subsystems/routing/responses.md index 64f7c8f50..6118fd23e 100644 --- a/versioned_docs/version-4.5/apis/subsystems/routing/responses.md +++ b/versioned_docs/version-4.5/apis/subsystems/routing/responses.md @@ -49,7 +49,8 @@ use core\router\schema\response\payload_response; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -class example { +class example +{ #[\core\router\route( // Resolves to https://example.com/moodle/api/rest/v2/mod_example/example path: '/example', diff --git a/versioned_docs/version-4.5/apis/subsystems/routing/testing.md b/versioned_docs/version-4.5/apis/subsystems/routing/testing.md index 89cb26326..4e9dbe676 100644 --- a/versioned_docs/version-4.5/apis/subsystems/routing/testing.md +++ b/versioned_docs/version-4.5/apis/subsystems/routing/testing.md @@ -22,8 +22,10 @@ You can quickly and easily create a copy of the Moodle Router using the `route_t This is a fully-configured copy of the Moodle Router, and allows to handle requests directly. ```php -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $router = $this->get_router(); } } @@ -56,8 +58,10 @@ You can easily add existing routes to mocking route loader either individually, To add an individual route, you can use the `\route_testcase::add_route_to_route_loader()` method, for example: ```php title="Adding a single route to the route loader" -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $this->add_route_to_route_loader( my_route::class, 'my_route_method', @@ -71,8 +75,10 @@ final class my_test extends \route_testcase { You can also add all routes in a class to the route loader using the `\route_testcase::add_class_routes_to_route_loader()` method, for example: ```php title="Adding all routes in a class to the route loader" -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $this->add_class_routes_to_route_loader( my_route::class, ); @@ -90,7 +96,8 @@ The `\route_testcase` also includes several methods to simplify generating a Req You can create a request and manually pass it to Router using the `\route_testcase::create_request()` method, for example: ```php title="Creating an example request and processing it" -public function test_example(): void { +public function test_example(): void +{ $this->add_class_routes_to_route_loader( my_route::class, ); @@ -114,7 +121,8 @@ When creating a request the default is to use the Route Group for the REST API, The `\route_testcase::process_request()` and `\route_testcsae::process_api_request()` methods act as a shortcut for creating the request, fetching the router, and the app, and handling the request to return a response. The above example can therefore be simplified to: ```php title="Creating and processing an example request" -public function test_example(): void { +public function test_example(): void +{ $this->add_class_routes_to_route_loader( my_route::class, ); diff --git a/versioned_docs/version-4.5/apis/subsystems/tag/index.md b/versioned_docs/version-4.5/apis/subsystems/tag/index.md index a847586f5..6b5a97652 100644 --- a/versioned_docs/version-4.5/apis/subsystems/tag/index.md +++ b/versioned_docs/version-4.5/apis/subsystems/tag/index.md @@ -151,7 +151,8 @@ If you have created a course activity that uses tags you should also remember to * * @param moodleform $mform */ -function book_reset_course_form_definition(&$mform) { +function book_reset_course_form_definition(&$mform) +{ $mform->addElement('header', 'bookheader', get_string('modulenameplural', 'book')); $mform->addElement('checkbox', 'reset_book_tags', get_string('removeallbooktags', 'book')); } @@ -161,7 +162,8 @@ function book_reset_course_form_definition(&$mform) { * @param $data the data submitted from the reset course. * @return array status array */ -function book_reset_userdata($data) { +function book_reset_userdata($data) +{ global $DB; $status = []; @@ -207,7 +209,8 @@ When you tag contents inside the course the plugin has to hook into backup and r You can choose to backup and restore tags for each item individually (as it is done in mod_wiki) OR backup all tags in the context at once (as it is done in mod_glossary or mod_forum). Second option is preferable for performance reasons. Make sure to take into account `$userinfo` (whether user information is backed up / restored), for example wiki pages is not user information but glossary entries are, tags on them follow the same rule. ```php title="mod/glossary/backup_glossary_stepslib.php" -protected function define_structure() { +protected function define_structure() +{ // ... $tags = new backup_nested_element('entriestags'); $tag = new backup_nested_element('tag', ['id'], ['itemid', 'rawname']); @@ -232,7 +235,8 @@ protected function define_structure() { ``` ```php title="mod/glossary/restore_glossary_stepslib.php" -protected function define_structure() { +protected function define_structure() +{ // ... if ($userinfo) { $paths[] = new restore_path_element('glossary_entry_tag', '/activity/glossary/entriestags/tag'); @@ -240,7 +244,8 @@ protected function define_structure() { // ... } -protected function process_glossary_entry_tag($data) { +protected function process_glossary_entry_tag($data) +{ $data = (object)$data; if (!core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) { // Tags disabled on this site, nothing to process. @@ -265,7 +270,8 @@ Given a user searches for any items tagged with a specified tag, only the items To limit the performance impact of checking user access against items the following class ``core_tag_index_builder()`` can assist with the retrieval and caching of records, especially within both course and activity modules. ```php -function mod_wiki_get_tagged_pages($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0) { +function mod_wiki_get_tagged_pages($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0) +{ // Find items. // Please refer to existing callbacks in core for examples. diff --git a/versioned_docs/version-4.5/apis/subsystems/task/adhoc.md b/versioned_docs/version-4.5/apis/subsystems/task/adhoc.md index 0dd508de0..5d057312d 100644 --- a/versioned_docs/version-4.5/apis/subsystems/task/adhoc.md +++ b/versioned_docs/version-4.5/apis/subsystems/task/adhoc.md @@ -38,12 +38,13 @@ namespace mod_example\task; /** * An example of an adhoc task. */ -class do_something extends \core\task\adhoc_task { - +class do_something extends \core\task\adhoc_task +{ /** * Execute the task. */ - public function execute() { + public function execute() + { // Call your own api } } @@ -62,8 +63,8 @@ It can be fetched using the `get_custom_data(): mixed` method. We recommend only ever calling `set_custom_data()` from within a factory method in the task class itself. ```php -class do_something extends \core\task\adhoc_task { - +class do_something extends \core\task\adhoc_task +{ public static function instance( int $id, string $status, @@ -77,7 +78,8 @@ class do_something extends \core\task\adhoc_task { return $task; } - public function execute() { + public function execute() + { $data = $this->get_custom_data(); mtrace($data->id); mtrace($data->status); @@ -177,7 +179,8 @@ $task->get_attempts_available(); Tasks are retried by default, but this behaviour can be modified by overriding the `retry_until_success()` method in your task class, for example: ```php -public function retry_until_success(): bool { +public function retry_until_success(): bool +{ return false; } ``` diff --git a/versioned_docs/version-4.5/apis/subsystems/task/index.md b/versioned_docs/version-4.5/apis/subsystems/task/index.md index 4689e0e5a..e6d746e05 100644 --- a/versioned_docs/version-4.5/apis/subsystems/task/index.md +++ b/versioned_docs/version-4.5/apis/subsystems/task/index.md @@ -92,8 +92,10 @@ Since Moodle 3.5 it is safe to use the [Output API](../output/index.md) in cron In order to improve debugging information, it is good practice to call `mtrace` to log what's going on within a task execution: ```php -class my_task extends \core\task\scheduled_task { - public function execute() { +class my_task extends \core\task\scheduled_task +{ + public function execute() + { mtrace("My task started"); // Do some work. diff --git a/versioned_docs/version-4.5/apis/subsystems/task/scheduled.md b/versioned_docs/version-4.5/apis/subsystems/task/scheduled.md index b29072d9e..7d286c859 100644 --- a/versioned_docs/version-4.5/apis/subsystems/task/scheduled.md +++ b/versioned_docs/version-4.5/apis/subsystems/task/scheduled.md @@ -37,21 +37,24 @@ namespace mod_example\task; /** * An example of a scheduled task. */ -class do_something extends \core\task\scheduled_task { +class do_something extends \core\task\scheduled_task +{ /** * Return the task's name as shown in admin screens. * * @return string */ - public function get_name() { + public function get_name() + { return get_string('dosomething', 'mod_example'); } /** * Execute the task. */ - public function execute() { + public function execute() + { // Call your own api } } diff --git a/versioned_docs/version-4.5/guides/templates/index.md b/versioned_docs/version-4.5/guides/templates/index.md index bee626cfb..41932dc93 100644 --- a/versioned_docs/version-4.5/guides/templates/index.md +++ b/versioned_docs/version-4.5/guides/templates/index.md @@ -397,7 +397,8 @@ The following example shows a renderable using the `mywidget.mustache` template * @param renderer_base $output * @return stdClass */ -public function export_for_template(renderer_base $output) { +public function export_for_template(renderer_base $output) +{ $data = new stdClass(); $data->canmanage = $this->canmanage; $data->things = []; @@ -424,7 +425,8 @@ Example of the method added to tell a renderable to use the `mywidget.mustache` * @param renderer_base $output * @return string */ -public function get_template_name(\renderer_base $renderer): string { +public function get_template_name(\renderer_base $renderer): string +{ return 'tool_myplugin/mywidget'; } ``` @@ -445,7 +447,8 @@ The rendering method can now use templates to render the object: * * @return string HTML */ -protected function render_mywidget(mywidget $widget) { +protected function render_mywidget(mywidget $widget) +{ $data = $widget->export_for_template($this); return $this->render_from_template('tool_myplugin/mywidget', $data); } diff --git a/versioned_docs/version-4.5/guides/upgrade/index.md b/versioned_docs/version-4.5/guides/upgrade/index.md index c3658f5b6..59abf5438 100644 --- a/versioned_docs/version-4.5/guides/upgrade/index.md +++ b/versioned_docs/version-4.5/guides/upgrade/index.md @@ -52,7 +52,8 @@ The following example shows the structure of the upgrade.php file: ```php title="Example upgrade.php file" get_manager(); // Loads ddl manager and xmldb classes. @@ -161,7 +162,8 @@ For example, if you are defining an installation behaviour in the `install.php` $coursemodule->instance]; @@ -224,7 +226,8 @@ First, the function that adds these controls: * @category completion * @return array List of added element names, or names of wrapping group elements. */ -public function add_completion_rules() { +public function add_completion_rules() +{ $mform = $this->_form; @@ -264,7 +267,8 @@ public function add_completion_rules() { return [$this->get_suffixed_name('completionpostsgroup')]; } -protected function get_suffixed_name(string $fieldname): string { +protected function get_suffixed_name(string $fieldname): string +{ return $fieldname . $this->get_suffix(); } ``` @@ -284,7 +288,8 @@ Next, a function for checking whether the user selected this option: * @param array $data Input data not yet validated. * @return bool True if one or more rules is enabled, false if none are. */ -public function completion_rule_enabled($data) { +public function completion_rule_enabled($data) +{ return (!empty($data[$this->get_suffixed_name('completionpostsenabled')]) && $data[$this->get_suffixed_name('completionposts')] != 0); } @@ -295,7 +300,8 @@ public function completion_rule_enabled($data) { That's all the 'required' functions, but we need to add some extra code to support the checkbox behaviour. I overrode `get_data` so that if there is a value in the edit field, but the checkbox is not ticked, the value counts as zero (the rule will not be enabled). ```php -function get_data() { +function get_data() +{ $data = parent::get_data(); if (!$data) { return $data; @@ -316,7 +322,8 @@ You may have noticed the `completionunlocked` check. When some users have alread Finally, forum already had a `data_preprocessing` function but I added code to this to set up the checkboxes when the form is displayed, and to make the default value of the text fields 1 instead of 0: ```php -function data_preprocessing(&$default_values){ +function data_preprocessing(&$default_values) +{ // [Existing code, not shown] // Set up the completion checkboxes which aren't part of standard data. @@ -360,7 +367,8 @@ Here's the function for forum (simplified to include only the one completion opt * @param bool $type Type of comparison (or/and; can be used as return value if no conditions) * @return bool True if completed, false if not, $type if conditions not set. */ - function forum_get_completion_state($course, $cm, $userid, $type) { + function forum_get_completion_state($course, $cm, $userid, $type) + { global $CFG,$DB; // Get forum details @@ -402,7 +410,8 @@ You need to return an array of strings for each completion rule that is active. * @param cm_info|stdClass $cm object with fields ->completion and ->customdata['customcompletionrules'] * @return array $descriptions the array of descriptions for the custom rules. */ -function mod_forum_get_completion_active_rule_descriptions($cm) { +function mod_forum_get_completion_active_rule_descriptions($cm) +{ // Values will be present in cm_info, and we assume these are up to date. if (empty($cm->customdata['customcompletionrules']) || $cm->completion != COMPLETION_TRACKING_AUTOMATIC) { return []; diff --git a/versioned_docs/version-5.0/apis/core/calendar/index.md b/versioned_docs/version-5.0/apis/core/calendar/index.md index 03ca98f0f..11d7f9903 100644 --- a/versioned_docs/version-5.0/apis/core/calendar/index.md +++ b/versioned_docs/version-5.0/apis/core/calendar/index.md @@ -103,7 +103,8 @@ where '$prioritiesforeventtype1' is an associative array that has the timestamp * @param int $lessonid The lesson ID. * @return array|null Array of group override priorities for open and close times. Null if there are no group overrides. */ -function lesson_get_group_override_priorities($lessonid) { +function lesson_get_group_override_priorities($lessonid) +{ global $DB; // Fetch group overrides. @@ -182,7 +183,8 @@ This callback determines if an event should be visible throughout the site. For * @param calendar_event $event * @return bool Returns true if the event is visible to the current user, false otherwise. */ -function mod_assign_core_calendar_is_event_visible(calendar_event $event) { +function mod_assign_core_calendar_is_event_visible(calendar_event $event) +{ global $CFG, $USER; require_once($CFG->dirroot . '/mod/assign/locallib.php'); @@ -259,7 +261,8 @@ Eg. * @param int $itemcount The item count associated with the action event. * @return bool */ -function mod_assign_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) { +function mod_assign_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) +{ // List of event types where the action event's item count should be shown. $eventtypesshowingitemcount = [ ASSIGN_EVENT_TYPE_GRADINGDUE @@ -320,7 +323,8 @@ This callback handles updating the activity instance based on the changed action Example: ```php -function mod_feedback_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $feedback) { +function mod_feedback_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $feedback) +{ global $CFG, $DB; if (empty($event->instance) || $event->modulename != 'feedback') { @@ -406,7 +410,8 @@ If the calendar event has no valid `timestart` values then the callback should r Example: ```php -function mod_feedback_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $instance) { +function mod_feedback_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $instance) +{ $mindate = null; $maxdate = null; diff --git a/versioned_docs/version-5.0/apis/core/clock/index.md b/versioned_docs/version-5.0/apis/core/clock/index.md index de70bd68b..5528cf4c3 100644 --- a/versioned_docs/version-5.0/apis/core/clock/index.md +++ b/versioned_docs/version-5.0/apis/core/clock/index.md @@ -46,13 +46,15 @@ The recommended approach is to have the Dependency Injector inject into the cons ```php title="Usage in injected classes" namespace mod_example; -class post { +class post +{ public function __construct( protected readonly \core\clock $clock, protected readonly \moodle_database $db, ) - public function create_thing(\stdClass $data): \stdClass { + public function create_thing(\stdClass $data): \stdClass + { $data->timecreated = $this->clock->time(); $data->id = $this->db->insert_record('example_thing', $data); @@ -99,8 +101,10 @@ The incrementing clock increases the time by one second every time it is called. A helper method, `mock_clock_with_incrementing(?int $starttime = null): \core\clock`, is provided within the standard testcase: ```php title="Obtaining the incrementing clock" -class my_test extends \advanced_testcase { - public function test_create_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_create_thing(): void + { // This class inserts data into the database. $this->resetAfterTest(true); @@ -134,8 +138,10 @@ The frozen clock uses a time which does not change, unless manually set. This ca A helper method, `mock_clock_with_frozen(?int $time = null): \core\clock`, is provided within the standard testcase: ```php title="Obtaining and using the frozen clock" -class my_test extends \advanced_testcase { - public function test_create_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_create_thing(): void + { // This class inserts data into the database. $this->resetAfterTest(true); @@ -182,27 +188,33 @@ class my_test extends \advanced_testcase { If the standard cases are not suitable for you, then you can create a custom clock and inject it into the DI container. ```php title="Creating a custom clock" -class my_clock implements \core\clock { +class my_clock implements \core\clock +{ public int $time; - public function __construct() { + public function __construct() + { $this->time = time(); } - public function now(): \DateTimeImmutable { + public function now(): \DateTimeImmutable + { $time = new \DateTimeImmutable('@' . $this->time); $this->time = $this->time += 5; return $time; } - public function time(): int { + public function time(): int + { return $this->now()->getTimestamp(); } } -class my_test extends \advanced_testcase { - public function test_my_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_my_thing(): void + { $clock = new my_clock(); \core\di:set(\core\clock::class, $clock); diff --git a/versioned_docs/version-5.0/apis/core/customfields/index.md b/versioned_docs/version-5.0/apis/core/customfields/index.md index a4644919c..43acc73ad 100644 --- a/versioned_docs/version-5.0/apis/core/customfields/index.md +++ b/versioned_docs/version-5.0/apis/core/customfields/index.md @@ -105,7 +105,8 @@ The list of fields is cached in the handler and these two functions can be calle ::: ```php title="Example code for course custom fields. This function will return all the custom fields for a given courseid" -function get_course_metadata($courseid) { +function get_course_metadata($courseid) +{ $handler = \core_customfield\handler::get_handler('core_course', 'course'); // This is equivalent to the line above. //$handler = \core_course\customfield\course_handler::create(); diff --git a/versioned_docs/version-5.0/apis/core/deprecation/index.md b/versioned_docs/version-5.0/apis/core/deprecation/index.md index 8df0d5dee..2ce423a71 100644 --- a/versioned_docs/version-5.0/apis/core/deprecation/index.md +++ b/versioned_docs/version-5.0/apis/core/deprecation/index.md @@ -40,24 +40,29 @@ The attribute is a Moodle PHP Attribute and can be applied to: ```php title="Example attribute usage" // On a global function: #[\core\attribute\deprecated('random_bytes', since: '4.3')] -function random_bytes_emulate($length) { +function random_bytes_emulate($length) +{ // Replaced by random_bytes since Moodle 4.3. } // On a class: #[\core\attribute\deprecated(replacement: null, since: '4.4', reason: 'This functionality has been removed.')] -class example { +class example +{ #[\core\attribute\deprecated( replacement: '\core\example::do_something', since: '4.3', reason: 'No longer required', mdl: 'MDL-12345', )] - public function do_something(): void {} + public function do_something(): void + { + } } // On an enum case: -enum example { +enum example +{ #[\core\attribute\deprecated('example::OPTION', since: '4.4', final: true)] case OPTION; } @@ -75,7 +80,8 @@ The `\core\deprecation` class contains helper methods to inspect for use of the // A method which has been initially deprecated, and replaced by 'random_bytes'. It should show debugging. /** @deprecated since 4.3 */ #[\core\attribute\deprecated('random_bytes', since: '4.3')] -function random_bytes_emulate($length) { +function random_bytes_emulate($length) +{ \core\deprecation::emit_deprecation_if_present(__FUNCTION__); return random_bytes($length); } @@ -83,7 +89,8 @@ function random_bytes_emulate($length) { // A method which has been finally deprecated and should throw an exception. /** @deprecated since 2.7 */ #[\core\attribute\deprecated(replacement: 'Events API', since: '2.3', final: true)] -function add_to_log() { +function add_to_log() +{ \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } diff --git a/versioned_docs/version-5.0/apis/core/di/index.md b/versioned_docs/version-5.0/apis/core/di/index.md index 0529877c9..0fbcfd8bd 100644 --- a/versioned_docs/version-5.0/apis/core/di/index.md +++ b/versioned_docs/version-5.0/apis/core/di/index.md @@ -21,7 +21,8 @@ Dependencies are stored using a string id attribute, which is typically the clas When accessing dependencies within a class, it is advisable to inject them into the constructor, for example: ```php title="Fetching a instance of the \core\http_client class from within a class" -class my_thing { +class my_thing +{ public function __construct( protected readonly \core\http_client $client, ) { @@ -48,7 +49,8 @@ The use of readonly properties is also highly recommended as it ensures that dep These language features are available in all Moodle versions supporting Dependency Injection. ```php -class example_without_promotion { +class example_without_promotion +{ protected \core\http_client $client; public function __construct( @@ -58,7 +60,8 @@ class example_without_promotion { } } -class example_with_promotion { +class example_with_promotion +{ public function __construct( protected readonly \core\http_client $client, ) { @@ -101,8 +104,10 @@ namespace mod_example; use core\hook\di_configuration; -class hook_listener { - public static function inject_dependencies(di_configuration $hook): void { +class hook_listener +{ + public static function inject_dependencies(di_configuration $hook): void + { $hook->add_definition( id: complex_client::class, definition: function ( @@ -139,8 +144,10 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; use GuzzleHttp\Psr7\Response; -class example_test extends \advanced_testcase { - public function test_the_thing(): void { +class example_test extends \advanced_testcase +{ + public function test_the_thing(): void + { // Mock our responses to the http_client. $handlerstack = HandlerStack::create(new MockHandler([ new Response(200, [], json_encode(['name' => 'Colin'])), @@ -170,13 +177,15 @@ Dependencies can be usually be easily injected into classes which are themselves In most cases in Moodle, this should be via the class constructor, for example: ```php title="Injecting via the constructor" -class thing_manager { +class thing_manager +{ public function __construct( protected readonly \moodle_database $db, ) { } - public function get_things(): array { + public function get_things(): array + { return $this->db->get_records('example_things'); } } @@ -186,13 +195,15 @@ $manager = \core\di::get(thing_manager::class); $things = $manager->get_things(); // Using it in a child class: -class other_thing { +class other_thing +{ public function __construct( protected readonly thing_manager $manager, ) { } - public function manage_things(): void { + public function manage_things(): void + { $this->manager->get_things(); } } diff --git a/versioned_docs/version-5.0/apis/core/dml/ddl.md b/versioned_docs/version-5.0/apis/core/dml/ddl.md index 83534afad..c33184f78 100644 --- a/versioned_docs/version-5.0/apis/core/dml/ddl.md +++ b/versioned_docs/version-5.0/apis/core/dml/ddl.md @@ -24,7 +24,8 @@ Of course, feel free to clarify, complete and add more info to all this document - All the function calls in this page are public methods of the **database manager**, accessible from the $DB global object. You will need to "import" it within the upgrade function of your **upgrade.php** main function using the `global` keyword, for example: ```php -function xmldb_xxxx_upgrade { +function xmldb_xxxx_upgrade +{ global $DB; // Load the DDL manager and xmldb API. diff --git a/versioned_docs/version-5.0/apis/core/dml/index.md b/versioned_docs/version-5.0/apis/core/dml/index.md index 8b63d7dca..d856ea79e 100644 --- a/versioned_docs/version-5.0/apis/core/dml/index.md +++ b/versioned_docs/version-5.0/apis/core/dml/index.md @@ -33,7 +33,8 @@ require(__DIR__ . '/config.php'); ```php title="example.php" \mod_example\local\entitychanges\create_example::class, @@ -156,7 +158,8 @@ namespace mod_activity\hook; #[\core\attribute\label('Hook dispatched at the very end of installation of mod_activity plugin.')] #[\core\attribute\tags('installation')] -final class installation_finished { +final class installation_finished +{ public function __construct( public readonly string $version, ) { @@ -172,17 +175,20 @@ final class installation_finished { dispatch($hook); } @@ -219,7 +226,8 @@ Using DI for dependency injection has the benefit that the hook manager can use ```php title="Mocking a hook listener" // Unit test. -public function test_before_standard_footer_html_hooked(): void { +public function test_before_standard_footer_html_hooked(): void +{ // Load the callback classes. require_once(__DIR__ . '/fixtures/core_renderer/before_standard_footer_html_callbacks.php'); @@ -242,7 +250,8 @@ public function test_before_standard_footer_html_hooked(): void { } // fixtures/core_renderer/before_standard_footer_html_callbacks.php -final class before_standard_footer_html_callbacks { +final class before_standard_footer_html_callbacks +{ public static function before_standard_footer_html( \core\hook\output\before_standard_footer_html $hook, ): void { @@ -314,8 +323,10 @@ a hook as parameter. namespace local_stuff\local; use \mod_activity\hook\installation_finished; -class hook_callbacks { - public static function activity_installation_finished(installation_finished $hook): void { +class hook_callbacks +{ + public static function activity_installation_finished(installation_finished $hook): void + { if (during_initial_install()) { return; } @@ -388,7 +399,8 @@ use core\attribute; #[attribute\label('Hook dispatched at the very end of lib/setup.php')] #[attribute\tags('config')] #[attribute\hook\replaces_callbacks('after_config')] -final class after_config { +final class after_config +{ } ``` @@ -400,16 +412,20 @@ final class after_config { stopped; } - public function stop(): void { + public function stop(): void + { $this->stopped = true; } } @@ -520,8 +539,10 @@ A callback will only be called if the hook was not stopped before-hand. Dependin namespace local_myplugin; -class callbacks { - public static function block_pre_delete(\core\hook\block_delete_pre $hook): void { +class callbacks +{ + public static function block_pre_delete(\core\hook\block_delete_pre $hook): void + { // ... $hook->stop(); } diff --git a/versioned_docs/version-5.0/apis/core/navigation/index.md b/versioned_docs/version-5.0/apis/core/navigation/index.md index 159250ee1..eaae0aa97 100644 --- a/versioned_docs/version-5.0/apis/core/navigation/index.md +++ b/versioned_docs/version-5.0/apis/core/navigation/index.md @@ -235,7 +235,8 @@ function {modulename}_extend_settings_navigation( You may be required to add a node in a specified order within the menu navigation menus. To do this you need to examine the node object as given in the respective parameters in the functions above, then find the key of the child node you wish to place the link before. For example, applying the code below will put a direct link to grade report. ```php -function my_plugin_extend_settings_navigation($settingsnav, $context){ +function my_plugin_extend_settings_navigation($settingsnav, $context) +{ $addnode = $context->contextlevel === 50; $addnode = $addnode && has_capability('gradereport/grader:view', $context); if ($addnode) { diff --git a/versioned_docs/version-5.0/apis/core/reportbuilder/index.md b/versioned_docs/version-5.0/apis/core/reportbuilder/index.md index b7984b9ff..a7ab677d0 100644 --- a/versioned_docs/version-5.0/apis/core/reportbuilder/index.md +++ b/versioned_docs/version-5.0/apis/core/reportbuilder/index.md @@ -216,7 +216,8 @@ The first method that we need is ***initialise()*** : /** * Initialise report, we need to set the main table, load our entities and set columns/filters */ -protected function initialise(): void { +protected function initialise(): void +{ ``` The initialise method needs to get the main entity, set the main table it needs to use and add the entity to the report: @@ -336,7 +337,8 @@ The first method you need to build is `initialise()` /** * Initialise report, we need to set the main table, load our entities and set columns/filters */ -protected function initialise(): void { +protected function initialise(): void +{ ``` The initialise method needs to get the main entity, set the main table it needs to use and add the entity to the report: @@ -397,7 +399,8 @@ You will need to specify the name that is displayed to the end user for the data * * @return string */ - public static function get_name(): string { + public static function get_name(): string + { return get_string('tasklogs', 'core_admin'); } ``` @@ -412,7 +415,8 @@ Once all entities have been added you need to define which columns it will show * * @return string[] */ -public function get_default_columns(): array { +public function get_default_columns(): array +{ return [ 'task_log:name', 'task_log:starttime', @@ -430,7 +434,8 @@ You may also optionally define the sorting that will be applied to the default r * * @return int[] */ -public function get_default_column_sorting(): array { +public function get_default_column_sorting(): array +{ return [ 'task_log:starttime' => SORT_DESC, ]; @@ -447,7 +452,8 @@ The filters allow the end user of the report to only see a subset of the data th * * @return string[] */ -public function get_default_filters(): array { +public function get_default_filters(): array +{ return [ 'task_log:timestart', 'task_log:result', @@ -465,7 +471,8 @@ The conditions allow the user creating the report to define which data it will r * * @return string[] */ -public function get_default_conditions(): array { +public function get_default_conditions(): array +{ return [ 'task_log:type', 'task_log:timestart', @@ -482,7 +489,8 @@ You may also optionally define the [initial values for any of the default condit * * @return array */ -public function get_default_condition_values(): array { +public function get_default_condition_values(): array +{ return [ 'task_log:type_operator' => select::EQUAL_TO, 'task_log:type_value' => \core\task\database_logger::TYPE_SCHEDULED, @@ -508,7 +516,8 @@ require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php"); * @copyright 2023 Paul Holden * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class categories_test extends core_reportbuilder_testcase { +class categories_test extends core_reportbuilder_testcase +{ ``` The `core_reportbuilder_testcase` will not autoload so we first ensure that it is loaded with the `require_once`. After this there are a few things you should look to test: @@ -526,7 +535,8 @@ For this you want a step that sets up will return enough data allows you test al /** * Test default datasource */ - public function test_datasource_default(): void { + public function test_datasource_default(): void + { $this->resetAfterTest(); $category = $this->getDataGenerator()->create_category(['name' => 'Zoo', 'idnumber' => 'Z01']); @@ -618,7 +628,8 @@ None of these tests checks that the data is what you want, but will ensure that * * In order to execute this test PHPUNIT_LONGTEST should be defined as true in phpunit.xml or directly in config.php */ - public function test_stress_datasource(): void { + public function test_stress_datasource(): void + { if (!PHPUNIT_LONGTEST) { $this->markTestSkipped('PHPUNIT_LONGTEST is not defined'); } diff --git a/versioned_docs/version-5.0/apis/plugintypes/ai/placement.md b/versioned_docs/version-5.0/apis/plugintypes/ai/placement.md index dfa4d6c48..e33e4cfc7 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/ai/placement.md +++ b/versioned_docs/version-5.0/apis/plugintypes/ai/placement.md @@ -39,7 +39,8 @@ They must also implement the following methods: This is the list of Actions that are supported by this Placement, for example the `aiplacement_editor` plugin defines this as: ```php -public function get_action_list(): array { +public function get_action_list(): array +{ return [ \core_ai\aiactions\generate_text::class, \core_ai\aiactions\generate_image::class, diff --git a/versioned_docs/version-5.0/apis/plugintypes/ai/provider.md b/versioned_docs/version-5.0/apis/plugintypes/ai/provider.md index c5eaa4c50..0b1e3661c 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/ai/provider.md +++ b/versioned_docs/version-5.0/apis/plugintypes/ai/provider.md @@ -41,7 +41,8 @@ They must also implement the following methods: This is the list of Actions that are supported by this Provider, for example the `aiprovider_openai` plugin defines this as: ```php -public static function get_action_list(): array { +public static function get_action_list(): array +{ return [ \core_ai\aiactions\generate_text::class, \core_ai\aiactions\generate_image::class, @@ -62,7 +63,8 @@ For example, the `aiprovider_azureai` provider checks values are set for `$this- the result. ```php -public function is_provider_configured(): bool { +public function is_provider_configured(): bool +{ return !empty($this->config['apikey']) && !empty($this->config['endpoint']); } ``` @@ -171,14 +173,16 @@ For example, the `aiprovider_openai` plugin defines this: namespace aiprovider_openai; use core_ai\hook\after_ai_provider_form_hook; -class hook_listener { +class hook_listener +{ /** * Hook listener for the Open AI instance setup form. * * @param after_ai_provider_form_hook $hook The hook to add to the AI instance setup. */ - public static function set_form_definition_for_aiprovider_openai(after_ai_provider_form_hook $hook): void { + public static function set_form_definition_for_aiprovider_openai(after_ai_provider_form_hook $hook): void + { if ($hook->plugin !== 'aiprovider_openai') { return; } @@ -260,9 +264,11 @@ These classes should extend the `core_ai\form\action_settings_form` class, and m For example, the `aiprovider_openai` plugin defines this: ```php -class action_generate_text_form extends action_settings_form { +class action_generate_text_form extends action_settings_form +{ #[\Override] - protected function definition() { + protected function definition() + { $mform = $this->_form; $actionconfig = $this->_customdata['actionconfig']['settings'] ?? []; $returnurl = $this->_customdata['returnurl'] ?? null; @@ -302,14 +308,17 @@ namespace aiprovider_openai\aimodel; use core_ai\aimodel\base; use MoodleQuickForm; -class gpt4o extends base implements openai_base { +class gpt4o extends base implements openai_base +{ #[\Override] - public function get_model_name(): string { + public function get_model_name(): string + { return 'gpt-4o'; } #[\Override] - public function get_model_display_name(): string { + public function get_model_display_name(): string + { return 'GPT-4o'; } @@ -325,12 +334,14 @@ To add configurable settings for individual models: ```php #[\Override] - public function has_model_settings(): bool { + public function has_model_settings(): bool + { return true; } #[\Override] - public function add_model_settings(MoodleQuickForm $mform): void { + public function add_model_settings(MoodleQuickForm $mform): void + { $mform->addElement( 'text', 'top_p', @@ -354,13 +365,15 @@ To add configurable settings for individual models: ```php namespace aiprovider_openai; - class helper { + class helper + { /** * Get all model classes. * * @return array Array of model classes */ - public static function get_model_classes(): array { + public static function get_model_classes(): array + { $models = []; $modelclasses = \core_component::get_component_classes_in_namespace('aiprovider_openai', 'aimodel'); foreach ($modelclasses as $class => $path) { @@ -378,7 +391,8 @@ To add configurable settings for individual models: * @param string $modelname The model name * @return \core_ai\aimodel\base|null The model class or null if not found */ - public static function get_model_class(string $modelname): ?\core_ai\aimodel\base { + public static function get_model_class(string $modelname): ?\core_ai\aimodel\base + { foreach (self::get_model_classes() as $modelclass) { $model = new $modelclass(); if ($model->get_model_name() === $modelname) { @@ -399,7 +413,8 @@ For example, the `aiprovider_openai` plugin does these: 1. Create a hook listener that adds model settings to the action form: ```php - public static function set_model_form_definition_for_aiprovider_openai(after_ai_action_settings_form_hook $hook): void { + public static function set_model_form_definition_for_aiprovider_openai(after_ai_action_settings_form_hook $hook): void + { if ($hook->plugin !== 'aiprovider_openai') { return; } diff --git a/versioned_docs/version-5.0/apis/plugintypes/assign/feedback.md b/versioned_docs/version-5.0/apis/plugintypes/assign/feedback.md index 0634bccbf..c77a995f3 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/assign/feedback.md +++ b/versioned_docs/version-5.0/apis/plugintypes/assign/feedback.md @@ -121,7 +121,8 @@ All feedback plugins should include one setting named 'default' to indicate if t This is where all the functionality for this plugin is defined. We will step through this file and describe each part as we go. ```php -class assign_feedback_file extends assign_feedback_plugin { +class assign_feedback_file extends assign_feedback_plugin +{ ``` #### get_name() {/* #get_name */} @@ -129,7 +130,8 @@ class assign_feedback_file extends assign_feedback_plugin { All feedback plugins MUST define a class with the component name of the plugin that extends assign_feedback_plugin. ```php -public function get_name() { +public function get_name() +{ return get_string('file', 'assignfeedback_file'); } ``` @@ -139,7 +141,8 @@ This function is abstract in the parent class (feedback_plugin) and must be defi #### get_settings() {/* #get_settings */} ```php -public function get_settings(MoodleQuickForm $mform) { +public function get_settings(MoodleQuickForm $mform) +{ $mform->addElement( 'assignfeedback_file_fileextensions', get_string('allowedfileextensions', 'assignfeedback_file') @@ -153,7 +156,8 @@ This function is called when building the settings page for the assignment. It a #### save_settings() {/* #save_settings */} ```php -public function save_settings(stdClass $data) { +public function save_settings(stdClass $data) +{ $this->set_config('allowedfileextensions', $data->allowedfileextensions); return true; } @@ -204,7 +208,8 @@ This function is called when building the feedback form. It functions identicall #### is_feedback_modified() {/* #is_feedback_modified */} ```php -public function is_feedback_modified(stdClass $grade, stdClass $data) { +public function is_feedback_modified(stdClass $grade, stdClass $data) +{ $commenttext = ''; if ($grade) { $feedbackcomments = $this->get_feedback_comments($grade->id); @@ -226,7 +231,8 @@ This function is called before feedback is saved. If feedback has not been modif #### save() {/* #save */} ```php -public function save(stdClass $grade, stdClass $data) { +public function save(stdClass $grade, stdClass $data) +{ global $DB; $fileoptions = $this->get_file_options(); @@ -263,7 +269,8 @@ This function is called to save a graders feedback. The parameters are the grade #### view_summary() {/* #view_summary */} ```php -public function view_summary(stdClass $grade, & $showviewlink) { +public function view_summary(stdClass $grade, & $showviewlink) +{ $count = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA); // show a view all link if the number of files is over this limit $showviewlink = $count > ASSIGNFEEDBACK_FILE_MAXSUMMARYFILES; @@ -285,7 +292,8 @@ This function is called to display a summary of the feedback to both markers and #### view() {/* #view */} ```php -public function view(stdClass $grade) { +public function view(stdClass $grade) +{ return $this->assignment->render_area_files( 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, @@ -299,7 +307,8 @@ This function is called to display the entire feedback to both markers and stude #### can_upgrade() {/* #can_upgrade */} ```php -public function can_upgrade($type, $version) { +public function can_upgrade($type, $version) +{ if (($type == 'upload' || $type == 'uploadsingle') && $version >= 2011112900) { return true; @@ -311,7 +320,8 @@ public function can_upgrade($type, $version) { This function is used to identify old "Assignment 2.2" subtypes that can be upgraded by this plugin. This plugin supports upgrades from the old "upload" and "uploadsingle" assignment subtypes. ```php -public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) { +public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) +{ // first upgrade settings (nothing to do) return true; } @@ -360,7 +370,8 @@ This function upgrades a single submission from the old assignment type to the n #### is_empty() {/* #is_empty */} ```php -public function is_empty(stdClass $submission) { +public function is_empty(stdClass $submission) +{ return $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA) == 0; } ``` @@ -370,7 +381,8 @@ If a plugin has no data to show then this function should return true from the ` #### get_file_areas() {/* #get_file_areas */} ```php -public function get_file_areas() { +public function get_file_areas() +{ return [ASSIGNFEEDBACK_FILE_FILEAREA => $this->get_name()]; } ``` @@ -380,7 +392,8 @@ A plugin should implement `get_file_areas` if it supports saving of any files to #### delete_instance() {/* #delete_instance */} ```php -public function delete_instance() { +public function delete_instance() +{ global $DB; // will throw exception on failure $DB->delete_records('assignfeedback_file', [ @@ -396,11 +409,13 @@ This function is called when a plugin is deleted. Note only database records nee #### Gradebook features {/* #gradebook-features */} ```php -public function format_for_gradebook(stdClass $grade) { +public function format_for_gradebook(stdClass $grade) +{ return FORMAT_MOODLE; } -public function text_for_gradebook(stdClass $grade) { +public function text_for_gradebook(stdClass $grade) +{ return ''; } ``` @@ -413,7 +428,8 @@ Only one feedback plugin can push comments to the gradebook. Usually this is the * * @return boolean - True if the plugin supports quickgrading */ -public function supports_quickgrading() { +public function supports_quickgrading() +{ return false; } @@ -424,7 +440,8 @@ public function supports_quickgrading() { * @param mixed $grade grade or null - The grade data. May be null if there are no grades for this user (yet) * @return mixed - A html string containing the html form elements required for quickgrading or false to indicate this plugin does not support quickgrading */ -public function get_quickgrading_html($userid, $grade) { +public function get_quickgrading_html($userid, $grade) +{ return false; } @@ -435,7 +452,8 @@ public function get_quickgrading_html($userid, $grade) { * @param stdClass $grade The grade * @return boolean - true if the quickgrading form element has been modified */ -public function is_quickgrading_modified($userid, $grade) { +public function is_quickgrading_modified($userid, $grade) +{ return false; } @@ -446,7 +464,8 @@ public function is_quickgrading_modified($userid, $grade) { * @param stdClass $grade The grade * @return boolean - true if the grade changes were saved correctly */ -public function save_quickgrading_changes($userid, $grade) { +public function save_quickgrading_changes($userid, $grade) +{ return false; } ``` @@ -457,7 +476,8 @@ These 4 functions can be implemented to allow a plugin to support quick-grading. /** * Run cron for this plugin */ -public static function cron() { +public static function cron() +{ } ``` @@ -471,7 +491,8 @@ A plugin can run code when cron runs by implementing this method. * @return array - An array of action and description strings. * The action will be passed to grading_action. */ -public function get_grading_actions() { +public function get_grading_actions() +{ return []; } @@ -481,7 +502,8 @@ public function get_grading_actions() { * @param string $gradingaction The action chosen from the grading actions menu * @return string The page containing the form */ -public function grading_action($gradingaction) { +public function grading_action($gradingaction) +{ return ''; } ``` @@ -495,7 +517,8 @@ Grading actions appear in the select menu above the grading table and apply to t * @return array - An array of action and description strings. * The action will be passed to grading_batch_operation. */ -public function get_grading_batch_operations() { +public function get_grading_batch_operations() +{ return []; } @@ -506,7 +529,8 @@ public function get_grading_batch_operations() { * @param array $users The list of selected userids * @return string The page containing the form */ -public function grading_batch_operation($action, $users) { +public function grading_batch_operation($action, $users) +{ return ''; } ``` diff --git a/versioned_docs/version-5.0/apis/plugintypes/assign/submission.md b/versioned_docs/version-5.0/apis/plugintypes/assign/submission.md index 785aff2a1..5192c3dc8 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/assign/submission.md +++ b/versioned_docs/version-5.0/apis/plugintypes/assign/submission.md @@ -118,7 +118,8 @@ This example from the submission_file plugin also checks to see if there is a ma This is where all the functionality for this plugin is defined. We will step through this file and describe each part as we go. ```php -class assign_submission_file extends assign_submission_plugin { +class assign_submission_file extends assign_submission_plugin +{ ``` All submission plugins MUST define a class with the component name of the plugin that extends assign_submission_plugin. @@ -126,7 +127,8 @@ All submission plugins MUST define a class with the component name of the plugin #### get_name() {/* #get_name */} ```php -public function get_name() { +public function get_name() +{ return get_string('file', 'assignsubmission_file'); } ``` @@ -136,7 +138,8 @@ Get name is abstract in submission_plugin and must be defined in your new plugin #### get_settings() {/* #get_settings */} ```php -public function get_settings(MoodleQuickForm $mform) { +public function get_settings(MoodleQuickForm $mform) +{ global $CFG, $COURSE; $defaultmaxfilesubmissions = $this->get_config('maxfilesubmissions'); @@ -193,7 +196,8 @@ The "get_settings" function is called when building the settings page for the as #### save_settings() {/* #save_settings */} ```php -public function save_settings(stdClass $data) { +public function save_settings(stdClass $data) +{ $this->set_config('maxfilesubmissions', $data->assignsubmission_file_maxfiles); $this->set_config('maxsubmissionsizebytes', $data->assignsubmission_file_maxsizebytes); return true; @@ -205,7 +209,8 @@ The "save_settings" function is called when the assignment settings page is subm #### get_form_elements() {/* #get_form_elements */} ```php -public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data) { +public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data) +{ if ($this->get_config('maxfilesubmissions') <= 0) { return false; } @@ -240,7 +245,8 @@ The get_form_elements function is called when building the submission form. It f #### save() {/* #save */} ```php -public function save(stdClass $submission, stdClass $data) { +public function save(stdClass $submission, stdClass $data) +{ global $USER, $DB; $fileoptions = $this->get_file_options(); @@ -305,7 +311,8 @@ The "save" function is called to save a user submission. The parameters are the #### get_files() {/* #get_files */} ```php -public function get_files($submission) { +public function get_files($submission) +{ $result = []; $fs = get_file_storage(); @@ -330,7 +337,8 @@ If this submission plugin produces one or more files, it should implement "get_f #### view_summary() {/* #view_summary */} ```php -public function view_summary(stdClass $submission, & $showviewlink) { +public function view_summary(stdClass $submission, & $showviewlink) +{ $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); // Show we show a link to view all files for this plugin. @@ -352,7 +360,8 @@ The view_summary function is called to display a summary of the submission to bo #### view() {/* #view */} ```php -public function view($submission) { +public function view($submission) +{ return $this->assignment->render_area_files( 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, @@ -367,7 +376,8 @@ The view function is called to display the entire submission to both markers and ```php #[\Override] -public function submission_summary_for_messages(stdClass $submission): array { +public function submission_summary_for_messages(stdClass $submission): array +{ global $PAGE; $onlinetextsubmission = $this->get_onlinetext_submission($submission->id); @@ -392,7 +402,8 @@ This method produces a summary of what was submitted, in a form suitable to incl #### can_upgrade() {/* #can_upgrade */} ```php -public function can_upgrade($type, $version) { +public function can_upgrade($type, $version) +{ $uploadsingle_type ='uploadsingle'; $upload_type ='upload'; @@ -408,7 +419,8 @@ The can_upgrade function is used to identify old "Assignment 2.2" subtypes that #### upgrade_settings() {/* #upgrade_settings */} ```php -public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) { +public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) +{ global $DB; if ($oldassignment->assignmenttype == 'uploadsingle') { @@ -450,7 +462,8 @@ This function is called once per assignment instance to upgrade the settings fro #### upgrade() {/* #upgrade */} ```php -public function upgrade($oldcontext, $oldassignment, $oldsubmission, $submission, &$log) { +public function upgrade($oldcontext, $oldassignment, $oldsubmission, $submission, &$log) +{ global $DB; $filesubmission = (object) [ @@ -486,7 +499,8 @@ The "upgrade" function upgrades a single submission from the old assignment type #### get_editor_fields() {/* #get_editor_fields */} ```php -public function () { +public function () +{ return [ 'onlinetext' => get_string('pluginname', 'assignsubmission_comments'), ]; @@ -498,7 +512,8 @@ This example is from assignsubmission_onlinetext. If the plugin uses a text-edit #### get_editor_text() {/* #get_editor_text */} ```php -public function get_editor_text($name, $submissionid) { +public function get_editor_text($name, $submissionid) +{ if ($name == 'onlinetext') { $onlinetextsubmission = $this->get_onlinetext_submission($submissionid); if ($onlinetextsubmission) { @@ -515,7 +530,8 @@ This example is from assignsubmission_onlinetext. If the plugin uses a text-edit #### get_editor_format() {/* #get_editor_format */} ```php -public function get_editor_format($name, $submissionid) { +public function get_editor_format($name, $submissionid) +{ if ($name == 'onlinetext') { $onlinetextsubmission = $this->get_onlinetext_submission($submissionid); if ($onlinetextsubmission) { @@ -532,7 +548,8 @@ This example is from assignsubmission_onlinetext. For the same reason as the pre #### is_empty() {/* #is_empty */} ```php -public function is_empty(stdClass $submission) { +public function is_empty(stdClass $submission) +{ return $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA) == 0; } ``` @@ -542,7 +559,8 @@ If a plugin has no submission data to show - it can return true from the is_empt #### submission_is_empty() {/* #submission_is_empty */} ```php -public function submission_is_empty() { +public function submission_is_empty() +{ global $USER; $fs = get_file_storage(); @@ -565,7 +583,8 @@ Determine if a submission is empty. This is distinct from is_empty() in that it #### get_file_areas() {/* #get_file_areas */} ```php -public function get_file_areas() { +public function get_file_areas() +{ return [ASSIGNSUBMISSION_FILE_FILEAREA=>$this->get_name()]; } ``` @@ -575,7 +594,8 @@ A plugin should implement get_file_areas if it supports saving of any files to m #### copy_submission() {/* #copy_submission */} ```php -public function copy_submission(stdClass $sourcesubmission, stdClass $destsubmission) { +public function copy_submission(stdClass $sourcesubmission, stdClass $destsubmission) +{ global $DB; // Copy the files across. @@ -609,7 +629,8 @@ Since Moodle 2.5 - a students submission can be copied to create a new submissio #### format_for_log() {/* #format_for_log */} ```php -public function format_for_log(stdClass $submission) { +public function format_for_log(stdClass $submission) +{ // Format the information for each submission plugin add_to_log $filecount = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); return ' the number of file(s) : ' . $filecount . " file(s).
"; @@ -621,7 +642,8 @@ The format_for_log function lets a plugin produce a really short summary of a su #### delete_instance() {/* #delete_instance */} ```php -public function delete_instance() { +public function delete_instance() +{ global $DB; // Will throw exception on failure $DB->delete_records('assignsubmission_file', [ diff --git a/versioned_docs/version-5.0/apis/plugintypes/availability/index.md b/versioned_docs/version-5.0/apis/plugintypes/availability/index.md index fe15d4233..19dcc032c 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/availability/index.md +++ b/versioned_docs/version-5.0/apis/plugintypes/availability/index.md @@ -83,12 +83,14 @@ Here's an outline of the code (with standard PHPdoc comments omitted to save spa // You must use the right namespace (matching your plugin component name). namespace availability_name; -class condition extends \core_availability\condition { +class condition extends \core_availability\condition +{ // Any data associated with the condition can be stored in member // variables. Here's an example variable: protected $allow; - public function __construct($structure) { + public function __construct($structure) + { // Retrieve any necessary data from the $structure here. The // structure is extracted from JSON data stored in the database // as part of the tree structure of conditions relating to an @@ -100,7 +102,8 @@ class condition extends \core_availability\condition { // throw a coding_exception if the structure is wrong. } - public function save() { + public function save() + { // Save back the data into a plain array similar to $structure above. return (object)array('type' => 'name', 'allow' => $this->allow); } @@ -142,7 +145,8 @@ class condition extends \core_availability\condition { return $allow ? 'Users are allowed' : 'Users not allowed'; } - protected function get_debug_string() { + protected function get_debug_string() + { // This function is only normally used for unit testing and // stuff like that. Just make a short string representation // of the values of the condition, suitable for developers. @@ -162,9 +166,11 @@ The class is required, but all the functions are theoretically optional; you can ```php namespace availability_name; -class frontend extends \core_availability\frontend { +class frontend extends \core_availability\frontend +{ - protected function get_javascript_strings() { + protected function get_javascript_strings() + { // You can return a list of names within your language file and the // system will include them here. // Should you need strings from another language file, you can also diff --git a/versioned_docs/version-5.0/apis/plugintypes/blocks/index.md b/versioned_docs/version-5.0/apis/plugintypes/blocks/index.md index bc56f7024..b42ddf26f 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/blocks/index.md +++ b/versioned_docs/version-5.0/apis/plugintypes/blocks/index.md @@ -160,7 +160,8 @@ This function is called on your subclass right after an instance is loaded. It i Example of a specialization method using the instance configuration. ```php -function specialization() { +function specialization() +{ if (isset($this->config->title)) { $this->title = format_string($this->config->title, true, ['context' => $this->context]); } else { @@ -180,11 +181,13 @@ In order to get our block to actually display something on screen, we need to ad ```php -class block_pluginname extends block_base { +class block_pluginname extends block_base +{ // (...) - public function get_content() { + public function get_content() + { if ($this->content !== null) { return $this->content; } @@ -202,11 +205,13 @@ class block_pluginname extends block_base { ```php -class block_pluginname extends block_list { +class block_pluginname extends block_list +{ // (...) - public function get_content() { + public function get_content() + { global $OUTPUT; if ($this->content !== null) { return $this->content; @@ -256,7 +261,8 @@ By default, only one instance of each block plugin can be added to a page. Howev
```php -public function instance_allow_multiple() { +public function instance_allow_multiple() +{ return true; } ``` @@ -279,7 +285,8 @@ Using this method each block instance can decide if the standard block header is
```php -public function hide_header() { +public function hide_header() +{ return true; } ``` @@ -298,7 +305,8 @@ By default, each block section in the page will use a standard `block` class and
```php -public function html_attributes() { +public function html_attributes() +{ // Get default values. $attributes = parent::html_attributes(); // Append our class to class attribute. @@ -351,7 +359,8 @@ However, for some cases like the Atto HTML editor, you may want to store them in
```php title="Example of adding data before storing it -public function instance_config_save($data,$nolongerused =false) { +public function instance_config_save($data,$nolongerused =false) +{ // Example of add new data. $data->somenewattribute = 'Some new value'; @@ -393,7 +402,8 @@ While in other Moodle pulgins the existence of a settings.php is enough to enabl
```php" -function has_config() { +function has_config() +{ return true; } ``` @@ -421,7 +431,8 @@ Each page in Moodle can define it's own page type name. However, there are some
```php -public function applicable_formats() { +public function applicable_formats() +{ return [ 'admin' => false, 'site-index' => false, diff --git a/versioned_docs/version-5.0/apis/plugintypes/enrol/index.md b/versioned_docs/version-5.0/apis/plugintypes/enrol/index.md index bd2695079..da1a3c56d 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/enrol/index.md +++ b/versioned_docs/version-5.0/apis/plugintypes/enrol/index.md @@ -151,7 +151,8 @@ By default, all enrolment plugins will have *editing enrolment* and *user unenro * @param stdClass $userenrolment * @return array An array of user_enrolment_actions */ -public function get_user_enrolment_actions(course_enrolment_manager $manager, $userenrolment) { +public function get_user_enrolment_actions(course_enrolment_manager $manager, $userenrolment) +{ $actions = parent::get_user_enrolment_actions($manager, $userenrolment); $context = $manager->get_context(); $instance = $userenrolment->enrolmentinstance; @@ -191,7 +192,8 @@ The unenrol action will allow resetif all following conditions are met:
```php -public function allow_unenrol(stdClass $instance) { +public function allow_unenrol(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -224,7 +226,8 @@ The unenrol action will be displayed if all following conditions are met:
```php -public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) { +public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) +{ // Add any extra validation here. return true; } @@ -241,7 +244,8 @@ It is quite common in enrolment plugins to allow unenrol only if the user enrolm
```php -public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) { +public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) +{ if ($userenrolment->status == ENROL_USER_SUSPENDED) { return true; } @@ -270,7 +274,8 @@ The edit manual enrolment action will be displayed if if all following condition
```php -public function allow_enrol(stdClass $instance) { +public function allow_enrol(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -343,7 +348,8 @@ The edit enrolment action in the participants list will be displayed if if all f
```php -public function allow_manage(stdClass $instance) { +public function allow_manage(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -363,7 +369,8 @@ Enrolment plugins can protect roles from being modified by any other plugin. Ret
```php -public function roles_protected() { +public function roles_protected() +{ // Add any extra validation here if necessary. return false; } @@ -393,7 +400,8 @@ The only exception is *enrol_self* - although it is not possible to uniquely ide
```php -public function find_instance(array $enrolmentdata, int $courseid) : ?stdClass { +public function find_instance(array $enrolmentdata, int $courseid) : ?stdClass +{ global $DB; $instances = enrol_get_instances($courseid, false); diff --git a/versioned_docs/version-5.0/apis/plugintypes/fileconverter/index.md b/versioned_docs/version-5.0/apis/plugintypes/fileconverter/index.md index e2d7464a6..daedef81a 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/fileconverter/index.md +++ b/versioned_docs/version-5.0/apis/plugintypes/fileconverter/index.md @@ -54,7 +54,8 @@ This function informs the File Converter API whether the system requirements of It should be lightweight to call and cache where required. ```php title="Example implementation" -public static function are_requirements_met() { +public static function are_requirements_met() +{ return extension_loaded('my_php_extension'); } ``` @@ -72,9 +73,11 @@ The `start_document_conversion()` function starts a conversion, whilst `poll_con This function allows the plugin to answer whether it supports conversion between two formats. It is typically only used internally by the File Conversion subsystem. ```php title="Example implementation" -class converter implements \core_files\converter_interface { +class converter implements \core_files\converter_interface +{ // ... - public static function supports($from, $to) { + public static function supports($from, $to) + { // This plugin supports conversion from doc and docx to pdf only. if ($from !== 'doc' && $from !== 'docx') { return false; diff --git a/versioned_docs/version-5.0/apis/plugintypes/filter/index.md b/versioned_docs/version-5.0/apis/plugintypes/filter/index.md index 70c2dbbde..81afdeaf7 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/filter/index.md +++ b/versioned_docs/version-5.0/apis/plugintypes/filter/index.md @@ -107,7 +107,8 @@ If a filter uses a special syntax or it is based on an appearance of a substring /** * Example of a filter that uses links in some way. */ -public function filter($text, array $options = []) { +public function filter($text, array $options = []) +{ if (!is_string($text) or empty($text)) { // Non-string data can not be filtered anyway. @@ -138,8 +139,10 @@ To support this behaviour, a filter plugin must provide a `filterlocalsettings.p
```php title="filterlocalsettings.php" -class pluginfile_filter_local_settings_form extends \core_filters\form\local_settings_form { - protected function definition_inner(\MoodleQuickForm $mform) { +class pluginfile_filter_local_settings_form extends \core_filters\form\local_settings_form +{ + protected function definition_inner(\MoodleQuickForm $mform) + { $mform->addElement( 'text', 'word', @@ -164,8 +167,10 @@ All the local configurations can be accessed in the main filter class in the `$t localconfig['word'] ?? 'default'; diff --git a/versioned_docs/version-5.0/apis/plugintypes/format/index.md b/versioned_docs/version-5.0/apis/plugintypes/format/index.md index 35fe81467..642c0fdbd 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/format/index.md +++ b/versioned_docs/version-5.0/apis/plugintypes/format/index.md @@ -532,8 +532,10 @@ In the example the extra output classes can look like: dirroot . '/mod/forum/lib.php'); @@ -804,9 +815,11 @@ This feature has been implemented by: ```php title="mod/resource/classes/output/courseformat/activitybadge.php" namespace mod_resource\output\courseformat; - class activitybadge extends \core_courseformat\output\activitybadge { + class activitybadge extends \core_courseformat\output\activitybadge + { - protected function update_content(): void { + protected function update_content(): void + { $options = (object) ['displayoptions' => $this->cminfo->customdata['displayoptions']]; $this->content = resource_get_optional_filetype($options, $this->cminfo); } diff --git a/versioned_docs/version-5.0/apis/plugintypes/mod/_files/lib_description.md b/versioned_docs/version-5.0/apis/plugintypes/mod/_files/lib_description.md index 3e44bd5e5..aa5cb5487 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/mod/_files/lib_description.md +++ b/versioned_docs/version-5.0/apis/plugintypes/mod/_files/lib_description.md @@ -41,7 +41,8 @@ Each feature is identified by a constant, which is defined in the `lib
```php -function [modname]_supports($feature) { +function [modname]_supports($feature) +{ return match ($feature) { FEATURE_GROUPS => true, FEATURE_GROUPINGS => true, @@ -68,7 +69,8 @@ To have your Activity plugin classified in the right Activity category, you must
```php -function [modname]_supports(string $feature) { +function [modname]_supports(string $feature) +{ switch ($feature) { [...] case FEATURE_MOD_PURPOSE: diff --git a/versioned_docs/version-5.0/apis/plugintypes/mod/courseoverview.md b/versioned_docs/version-5.0/apis/plugintypes/mod/courseoverview.md index 7e9b6f308..b71d78dab 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/mod/courseoverview.md +++ b/versioned_docs/version-5.0/apis/plugintypes/mod/courseoverview.md @@ -30,7 +30,8 @@ namespace mod_PLUGINNAME\courseformat; use core_courseformat\activityoverviewbase; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ // Implement methods here. } ``` @@ -63,9 +64,11 @@ use core_courseformat\activityoverviewbase; use core_courseformat\local\overview\overviewitem; use core\output\pix_icon; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ #[\Override] - public function get_extra_overview_items(): array { + public function get_extra_overview_items(): array + { return [ 'submitted' => $this->get_extra_submitted_overview(), ]; @@ -76,7 +79,8 @@ class overview extends activityoverviewbase { * * @return overviewitem|null */ - private function get_extra_submitted_overview(): ?overviewitem { + private function get_extra_submitted_overview(): ?overviewitem + { // Validate if the user needs this overview information. Return null otherwise. if (!has_capability('mod/PLUGINNAME:complete', $this->context)) { return null; @@ -135,9 +139,11 @@ namespace mod_PLUGINNAME\courseformat; use core_courseformat\activityoverviewbase; use core_courseformat\local\overview\overviewitem; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ #[\Override] - public function get_due_date_overview(): ?overviewitem { + public function get_due_date_overview(): ?overviewitem + { // Implement here how to get the due date of the activity. $duedate = DO_SOMETHING_TO_GET_YOUR_PLUGIN_DUE_DATE(); @@ -175,9 +181,11 @@ use core\output\action_link; use core\output\local\properties\button; use core\output\local\properties\text_align; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ #[\Override] - public function get_actions_overview(): ?overviewitem { + public function get_actions_overview(): ?overviewitem + { // Validate if the user can do the action. Return null otherwise. if (!has_capability('mod/PLUGINNAME:viewreports', $this->context)) { return null; @@ -227,7 +235,8 @@ This is an example of a plugin with two grade items: ```php #[\Override] -protected function get_grade_item_names(array $items): array { +protected function get_grade_item_names(array $items): array +{ // Add some fallback in case some grade item is missing. if (count($items) != 2) { return parent::get_grade_item_names($items); @@ -260,7 +269,8 @@ namespace mod_PLUGINNAME\courseformat; use core_course\activityoverviewbase; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ public function __construct( /** @var cm_info $cm the activity course module. */ cm_info $cm, diff --git a/versioned_docs/version-5.0/apis/plugintypes/mod/visibility.md b/versioned_docs/version-5.0/apis/plugintypes/mod/visibility.md index 182e57640..68efc3b24 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/mod/visibility.md +++ b/versioned_docs/version-5.0/apis/plugintypes/mod/visibility.md @@ -37,7 +37,8 @@ The course cache is only updated when somebody edits a module, so it can't be us The function should return a value of class `cached_cm_info`. For example: ```php -function mod_frog_get_coursemodule_info($cm) { +function mod_frog_get_coursemodule_info($cm) +{ $info = new cached_cm_info(); $info->content = '

This will display below the module.

'; return $info; @@ -62,7 +63,8 @@ Don't use renderers in this function (see MDL-41074). If you have data you would You can customise module display dynamically (when the page loads). For example you might want to alter it based on the permissions of the current user. ```php -function mod_frog_cm_info_dynamic(cm_info $cm) { +function mod_frog_cm_info_dynamic(cm_info $cm) +{ $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!has_capability('some/capability', $context)) { $cm->set_user_visible(false); @@ -81,7 +83,8 @@ Most things are set using functions (as above; another example would be `set_con Sometimes you need to display custom information for the current user that appears only on the course view page. For example, the forum module displays unread information on the view page. This information doesn't show on other pages (it isn't included in the navigation, for instance). ```php -function mod_frog_cm_info_view(cm_info $cm) { +function mod_frog_cm_info_view(cm_info $cm) +{ $cm->set_after_link('Last tadpole: 22:17'); } ``` @@ -106,7 +109,8 @@ $cm = $modinfo->get_cm($cmid); The cm_info objects contain additional information that is not present in the course_modules database row, such as the module's name, and the icon and associated content mentioned above. In order to distinguish these from the plain database objects, you can specify the cm_info class in a function definition: ```php -function my_clever_function(cm_info $cm) { +function my_clever_function(cm_info $cm) +{ if (!$cm->uservisible) { // The module is not visible or available to current user, // so do something clever instead. diff --git a/versioned_docs/version-5.0/apis/plugintypes/qbank/filters.md b/versioned_docs/version-5.0/apis/plugintypes/qbank/filters.md index 340c714e0..036341bdd 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/qbank/filters.md +++ b/versioned_docs/version-5.0/apis/plugintypes/qbank/filters.md @@ -37,7 +37,8 @@ namespace qbank_myplugin; use core_question\local\bank\condition; -class myfilter_condition extends condition { +class myfilter_condition extends condition +{ } ``` @@ -47,8 +48,10 @@ Modify your `plugin_feature` class to return an instance of your condition from ```php title="question/bank/myplugin/classes/plugin_feature.php" namespace qbank_myplugin; -class plugin_feature extends core_question\local\bank\plugin_features_base { - public function get_question_filters(?core_question\local\bank\view $qbank = null): array { +class plugin_feature extends core_question\local\bank\plugin_features_base +{ + public function get_question_filters(?core_question\local\bank\view $qbank = null): array + { return [ new myfilter_condition($qbank), ]; @@ -59,7 +62,8 @@ class plugin_feature extends core_question\local\bank\plugin_features_base { Back in your `condition` class, define the `get_name()` method, which returns the label displayed in the filter UI. ```php title="Define the condition name" -public function get_name(): string { +public function get_name(): string +{ return get_string('myfilter_name', 'myplugin'); } ``` @@ -67,7 +71,8 @@ public function get_name(): string { Define `get_condition_key()`, which returns a unique machine-readable ID for this filter condition, used when passing the filter as a parameter. ```php title="Define the condition key" -public function get_condition_key(): string { +public function get_condition_key(): string +{ return 'myfilter'; } ``` @@ -78,7 +83,8 @@ The `$filter` parameter receives an array with a `'values'` key, containing an a The conditions from each filter are combined with the query in [`core_question\local\bank\view::build_query()`](https://github.com/moodle/moodle/blob/c741492c38b9945abbfc7e90dfe8f943279f8265/question/classes/local/bank/view.php#L733) ```php title="Filter questions" -public function build_query_from_filter(array $filter): array { +public function build_query_from_filter(array $filter): array +{ $andor = ' AND '; $equal = '='; if ($filter['jointype'] === self::JOINTYPE_ANY) { @@ -109,7 +115,8 @@ Following this pattern with your own fields and options will give you a basic fu To define the list of possible filter values, define `get_initial_values()`, which returns an array of `['value', 'title']` for each option. These will then be searchable and selectable in the autocomplete field. ```php title="Define initial filter values" -public function get_initial_values(): string { +public function get_initial_values(): string +{ return [ [ 'value' => 0, @@ -128,7 +135,8 @@ public function get_initial_values(): string { To restrict the possible filter terms to only those returned from `get_initial_values()`, define `allow_custom()` and have it return `false`. ```php title="Disable custom terms" -public function allow_custom(): bool { +public function allow_custom(): bool +{ return false; } ``` @@ -138,7 +146,8 @@ public function allow_custom(): bool { Not all join types are relevant to all filters. If each question will only match one of the selected values, it does not make sense to allow `JOINTYPE_ALL`. Define `get_join_list()` and return an array of the applicable join types. ```php title="Define a restricted list of join types" -public function get_join_list(): array { +public function get_join_list(): array +{ return [ datafilter::JOINTYPE_ANY, datafilter::JOINTYPE_NONE, @@ -152,7 +161,8 @@ By default, conditions allow multiple values to be selected and use the selected If your condition should only allow a single value at a time, override `allow_multiple()` to return false. ```php title="Disable selection of multiple values" -public function allow_multiple(): bool { +public function allow_multiple(): bool +{ return false; } ``` @@ -162,7 +172,8 @@ public function allow_multiple(): bool { By default, conditions can be left empty, and therefore will not be included in the filter. To make it compulsory to select a value for this condition when it is added, override `allow_empty()` to return false. ```php title="Disable empty values" -public function allow_empty(): bool { +public function allow_empty(): bool +{ return false; } ``` @@ -172,7 +183,8 @@ public function allow_empty(): bool { If it is compulsory that your condition is always displayed, override `is_required()` to return true. ```php title="Make the condition compulsory" -public function is_required(): bool { +public function is_required(): bool +{ return true; } ``` @@ -188,7 +200,8 @@ You can either use a different core filter type from `/lib/amd/src/datafilter/fi To tell your filter condition to use a different filter class, override the `get_filter_class()` method to return the namespaced path to your JavaScript class. ```php title="Override the default filter class" -public function get_filter_class(): string { +public function get_filter_class(): string +{ return 'qbank_myplugin/datafilter/filtertype/myfilter'; } ``` diff --git a/versioned_docs/version-5.0/apis/plugintypes/qtype/newquestiondefaults.md b/versioned_docs/version-5.0/apis/plugintypes/qtype/newquestiondefaults.md index c34ce0a02..fb8d4be87 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/qtype/newquestiondefaults.md +++ b/versioned_docs/version-5.0/apis/plugintypes/qtype/newquestiondefaults.md @@ -41,7 +41,8 @@ $mform->setDefault('shuffleanswers', $this->get_default_value('shuffleanswers', Here we need to override the method `save_defaults_for_new_questions` to save the values these settings. For example: ```php - public function save_defaults_for_new_questions(stdClass $fromform): void { + public function save_defaults_for_new_questions(stdClass $fromform): void + { parent::save_defaults_for_new_questions($fromform); $this->set_default_value('shuffleanswers', $fromform->shuffleanswers); } diff --git a/versioned_docs/version-5.0/apis/plugintypes/qtype/restore.md b/versioned_docs/version-5.0/apis/plugintypes/qtype/restore.md index 845357130..ee30b631e 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/qtype/restore.md +++ b/versioned_docs/version-5.0/apis/plugintypes/qtype/restore.md @@ -83,7 +83,8 @@ an array of fields to remove from the `$questiondata` structure. For example, i records with the fields `id`, `questionid` and `data`, you might need to define the following: ```php title="question/type/example/backup/moodle2/restore_qtype_example_plugin.class.php" -protected function define_excluded_identity_hash_fields(): array { +protected function define_excluded_identity_hash_fields(): array +{ return [ '/options/extradata/id', '/options/extradata/questionid', @@ -102,7 +103,8 @@ additional data, then passes `$questiondata` on to the parent method. For exampl setting at `$questiondata->options->pluginconfig`, you might need to define the following: ```php title="question/type/example/backup/moodle2/restore_qtype_example_plugin.class.php" -public static function remove_excluded_question_data(stdClass $questiondata, array $excludefields = []): stdClass { +public static function remove_excluded_question_data(stdClass $questiondata, array $excludefields = []): stdClass +{ if (isset($questiondata->options->pluginconfig)) { unset($questiondata->options->pluginconfig); } diff --git a/versioned_docs/version-5.0/apis/plugintypes/repository/index.md b/versioned_docs/version-5.0/apis/plugintypes/repository/index.md index 0e940f7ab..c23a86a16 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/repository/index.md +++ b/versioned_docs/version-5.0/apis/plugintypes/repository/index.md @@ -122,7 +122,8 @@ Return any combination of the following values: ```php -function supported_returntypes() { +function supported_returntypes() +{ return FILE_INTERNAL | FILE_EXTERNAL | FILE_REFERENCE | FILE_CONTROLLED_LINK; } ``` @@ -151,7 +152,8 @@ Supported file types can be specified using standard mimetypes (such as `image/g ```php -function supported_filetypes() { +function supported_filetypes() +{ // Allow any kind of file. return '*'; } @@ -161,7 +163,8 @@ function supported_filetypes() { ```php -function supported_filetypes() { +function supported_filetypes() +{ // Example of image mimetypes. return ['image/gif', 'image/jpeg', 'image/png']; } @@ -171,7 +174,8 @@ function supported_filetypes() { ```php -function supported_filetypes() { +function supported_filetypes() +{ // Example of a file group. return ['web_image']; } @@ -204,7 +208,8 @@ Parent function returns an array with a single item - pluginname.
```php -public static function get_type_option_names() { +public static function get_type_option_names() +{ return array_merge(parent::get_type_option_names(), ['rootpath']); } ``` @@ -225,7 +230,8 @@ Optional. This is for modifying the Moodle form displaying the plugin settings. For example, to display the standard repository plugin settings along with the custom ones use: ```php -public static function type_config_form($mform, $classname='repository') { +public static function type_config_form($mform, $classname='repository') +{ parent::type_config_form($mform); $rootpath = get_config('repository_pluginname', 'rootpath'); @@ -244,7 +250,8 @@ This function must be declared static Optional. Use this function if you need to validate some variables submitted by plugin settings form. To use it, check through the associative array of data provided ('settingname' => value) for any errors. Then push the items to $error array in the format ("fieldname" => "human readable error message") to have them highlighted in the form. ```php -public static function type_form_validation($mform, $data, $errors) { +public static function type_form_validation($mform, $data, $errors) +{ if (!is_dir($data['rootpath'])) { $errors['rootpath'] = get_string('invalidrootpath', 'repository_pluginname'); } @@ -271,7 +278,8 @@ Parent function returns an empty array. This is equivalent to **get_type_option_
```php -public static function get_instance_option_names() { +public static function get_instance_option_names() +{ return ['fs_path']; // From repository_filesystem } ``` @@ -292,7 +300,8 @@ Optional. This is for modifying the Moodle form displaying the settings specific For example, to add a required text box called email_address: ```php -public static function get_instance_option_names() { +public static function get_instance_option_names() +{ $mform->addElement( 'text', 'email_address', @@ -318,7 +327,8 @@ This function must be declared static Optional. This allows us to validate what has been submitted in the instance configuration form. This is equivalent to ''type_form_validation($mform, $data, $errors), but for instances. For example: ```php -public static function instance_form_validation($mform, $data, $errors) { +public static function instance_form_validation($mform, $data, $errors) +{ if (empty($data['email_address'])) { $errors['email_address'] = get_string('invalidemailsettingname', 'repository_flickr_public'); } @@ -357,7 +367,8 @@ Firstly the skeleton: * * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ -class repository_flickr_public extends repository { +class repository_flickr_public extends repository +{ } ``` @@ -453,7 +464,8 @@ This function will return a list of files to be displayed to the user, the list * @param string $page * @return array the list of files, including meta information */ -public function get_listing($encodedpath = '', $page = '') { +public function get_listing($encodedpath = '', $page = '') +{ // This methods return [ //this will be used to build navigation bar. @@ -578,7 +590,8 @@ For plugins that do not fully process the login via a popup window, the submitte
```php title="lib/alfresco/lib.php" -public function __construct($repositoryid, $context = SYSCONTEXTID, $options = []) { +public function __construct($repositoryid, $context = SYSCONTEXTID, $options = []) +{ global $SESSION; /* Skipping code that is not relevant to user login */ @@ -618,7 +631,8 @@ Many types include a single element of type 'popup' with the param 'url' pointin
```php title="Code taken from repository_boxnet" -public function print_login() { +public function print_login() +{ $ticket = $this->boxclient->getTicket(); if ($this->options['ajax']) { $loginbtn = (object)[ @@ -652,7 +666,8 @@ This function will return a boolean value to tell Moodle whether the user has lo By default, this function will return true. ```php -public function check_login(): bool { +public function check_login(): bool +{ global $SESSION; return !empty($SESSION->{$this->sessname}); } @@ -663,7 +678,8 @@ public function check_login(): bool { When a user clicks the logout button in file picker, this function will be called. You may clean up the session or disconnect the connection with remote server here. After this the code should return something suitable to display to the user (usually the results of calling **$this->print_login()**): ```php title="lib/alfresco/lib.php" -public function logout() { +public function logout() +{ global $SESSION; unset($SESSION->{$this->sessname}); return $this->print_login(); @@ -689,7 +705,8 @@ For FILE_INTERNAL or FILE_REFERENCE this function is called at the point when th ```php -public function get_file($url, $filename = '') { +public function get_file($url, $filename = '') +{ // Default implementation from the base 'repository' class $path = $this->prepare_file($filename); // Generate a unique temporary filename $curlobject = new curl(); @@ -707,7 +724,8 @@ public function get_file($url, $filename = '') { Slightly extended version taken from repository_equella ```php -public function get_file($reference, $filename = '') { +public function get_file($reference, $filename = '') +{ global $USER; // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference->reference)); @@ -768,7 +786,8 @@ A custom search form must include the following:
```php title="The default implementation in class 'repository'" -public function print_search() { +public function print_search() +{ global $PAGE; $renderer = $PAGE->get_renderer('core', 'files'); return $renderer->repository_default_searchform(); @@ -793,7 +812,8 @@ The return should return an array containing:
```php title="Example from repoistory_googledocs" -public function search($search_text, $page = 0) { +public function search($search_text, $page = 0) +{ $gdocs = new google_docs($this->googleoauth); return [ 'dynload' => true, @@ -822,7 +842,8 @@ Note that external file is synchronised by moodle when UI wants to show the file Return minimum number of seconds before checking for changes to the file (default implementation = 1 day) ```php -public function get_reference_file_lifetime($ref) { +public function get_reference_file_lifetime($ref) +{ return DAYSECS; // One day, 60 * 60 * 24 seconds. } ``` @@ -832,7 +853,8 @@ public function get_reference_file_lifetime($ref) { Called after the file has reached the 'lifetime' specified above to see if it should now be synchronised (default implementation is to return true) ```php -public function sync_individual_file(stored_file $storedfile) { +public function sync_individual_file(stored_file $storedfile) +{ return true; } ``` @@ -851,7 +873,8 @@ This is usually prefixed with the repository name, and a semicolon. For example:
```php title="lib.php" -public function get_reference_details($reference, $filestatus = 0) { +public function get_reference_details($reference, $filestatus = 0) +{ if (!$filestatus) { // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference); @@ -879,7 +902,8 @@ Returns up-to-date information about the original file, only called when the 'li
```php title="/lib.php" -public function get_file_by_reference($reference) { +public function get_file_by_reference($reference) +{ global $USER; // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference->reference)); @@ -946,7 +970,8 @@ It is up to the repository developer to decide whether to actually download the
```php title="/lib.php" -public function send_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) { +public function send_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) +{ // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($stored_file->get_reference())); $url = $this->appendtoken($details->url); diff --git a/versioned_docs/version-5.0/apis/plugintypes/sms/index.md b/versioned_docs/version-5.0/apis/plugintypes/sms/index.md index 1e9235bff..8baec2ec7 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/sms/index.md +++ b/versioned_docs/version-5.0/apis/plugintypes/sms/index.md @@ -65,7 +65,8 @@ namespace smsgateway_aws; use smsgateway_aws\local\service\aws_sns; -class gateway extends \core_sms\gateway { +class gateway extends \core_sms\gateway +{ #[\Override] public function send( message $message, @@ -95,7 +96,8 @@ class gateway extends \core_sms\gateway { ); } - private function get_gateway_service(\stdClass $config): string { + private function get_gateway_service(\stdClass $config): string + { return match ($config->gateway) { 'aws_sns' => aws_sns::class, default => throw new moodle_exception("Unknown Message Handler {$config->gateway}"), @@ -103,7 +105,8 @@ class gateway extends \core_sms\gateway { } #[\Override] - public function get_send_priority(message $message): int { + public function get_send_priority(message $message): int + { return 50; } } @@ -120,7 +123,8 @@ It is necessary for plugins developers to assess these hooks and implement accor This hook will allow plugins to add required form fields to assist users in configuring their SMS gateway. ```php title="Listener method for after_sms_gateway_form_hook" -public static function set_form_definition_for_aws_sms_gateway(after_sms_gateway_form_hook $hook): void { +public static function set_form_definition_for_aws_sms_gateway(after_sms_gateway_form_hook $hook): void +{ if ($hook->plugin !== 'smsgateway_example') { return; } diff --git a/versioned_docs/version-5.0/apis/plugintypes/theme/index.md b/versioned_docs/version-5.0/apis/plugintypes/theme/index.md index 371b703c4..c3cd0b8b0 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/theme/index.md +++ b/versioned_docs/version-5.0/apis/plugintypes/theme/index.md @@ -108,7 +108,8 @@ $THEME->sheets = []; $THEME->editor_sheets = []; $THEME->editor_scss = ['editor']; $THEME->usefallback = true; -$THEME->scss = function($theme) { +$THEME->scss = function($theme) +{ return theme_boost_get_main_scss_content($theme); }; diff --git a/versioned_docs/version-5.0/apis/plugintypes/tiny/index.md b/versioned_docs/version-5.0/apis/plugintypes/tiny/index.md index 831f0cfef..38dbd3cbe 100644 --- a/versioned_docs/version-5.0/apis/plugintypes/tiny/index.md +++ b/versioned_docs/version-5.0/apis/plugintypes/tiny/index.md @@ -398,7 +398,8 @@ use context; use editor_tiny\plugin; use editor_tiny\plugin_with_configuration; -class plugininfo extends plugin implements plugin_with_configuration { +class plugininfo extends plugin implements plugin_with_configuration +{ public static function get_plugin_configuration_for_context( context $context, array $options, diff --git a/versioned_docs/version-5.0/apis/subsystems/access.md b/versioned_docs/version-5.0/apis/subsystems/access.md index 06ea7efeb..d0b39391d 100644 --- a/versioned_docs/version-5.0/apis/subsystems/access.md +++ b/versioned_docs/version-5.0/apis/subsystems/access.md @@ -167,7 +167,8 @@ By default checks the capabilities of the current user, but you can pass a diffe Function require_capability() is very similar, it is throwing access control exception if user does not have the capability. ```php -function require_capability($capability, context $context, $userid = null, $doanything = true, $errormessage = 'nopermissions', $stringfile = _) { +function require_capability($capability, context $context, $userid = null, $doanything = true, $errormessage = 'nopermissions', $stringfile = _) +{ ``` ### Enrolment functions {/* #enrolment-functions */} diff --git a/versioned_docs/version-5.0/apis/subsystems/ai/index.md b/versioned_docs/version-5.0/apis/subsystems/ai/index.md index 8f6f7a0cd..d2e63732e 100644 --- a/versioned_docs/version-5.0/apis/subsystems/ai/index.md +++ b/versioned_docs/version-5.0/apis/subsystems/ai/index.md @@ -162,7 +162,8 @@ public function __construct( ```php title="Example: The store() method for the generate_image Action" #[\Override] -public function store(response_base $response): int { +public function store(response_base $response): int +{ global $DB; $responsearr = $response->get_response_data(); @@ -225,7 +226,8 @@ it sets these against class variables so they can be retrieved by the Manager an ```php title="Example: The set_response_data() for the generate_image Action response" #[\Override] - public function set_response_data(array $response): void { + public function set_response_data(array $response): void + { $this->draftfile = $response['draftfile'] ?? null; $this->revisedprompt = $response['revisedprompt'] ?? null; $this->sourceurl = $response['sourceurl'] ?? null; @@ -238,7 +240,8 @@ Returns the set response data. ```php title="Example: The get_response_data() for the generate_image Action response" #[\Override] - public function get_response_data(): array { + public function get_response_data(): array + { return [ 'draftfile' => $this->draftfile, 'revisedprompt' => $this->revisedprompt, diff --git a/versioned_docs/version-5.0/apis/subsystems/analytics/index.md b/versioned_docs/version-5.0/apis/subsystems/analytics/index.md index 1f4c3e3e7..20b1eddc8 100644 --- a/versioned_docs/version-5.0/apis/subsystems/analytics/index.md +++ b/versioned_docs/version-5.0/apis/subsystems/analytics/index.md @@ -378,7 +378,8 @@ You can overwrite a `new one_sample_per_analysable()` method if the analysables * * @return bool */ -public static function one_sample_per_analysable() { +public static function one_sample_per_analysable() +{ return true; } ``` @@ -398,7 +399,8 @@ You can use `required_sample_data` to specify what your indicator needs to be ca * * @return null|string[] Name of the required elements (use the database tablename) */ -public static function required_sample_data() { +public static function required_sample_data() +{ return null; } ``` diff --git a/versioned_docs/version-5.0/apis/subsystems/backup/index.md b/versioned_docs/version-5.0/apis/subsystems/backup/index.md index 95245f909..10089ab62 100644 --- a/versioned_docs/version-5.0/apis/subsystems/backup/index.md +++ b/versioned_docs/version-5.0/apis/subsystems/backup/index.md @@ -95,9 +95,11 @@ Here is a minimalistic task: ```php require_once($CFG->dirroot . '/backup/moodle2/backup_tool_plugin.class.php'); -class backup_tool_foobar_plugin extends backup_tool_plugin { +class backup_tool_foobar_plugin extends backup_tool_plugin +{ - protected function define_course_plugin_structure() { + protected function define_course_plugin_structure() + { $this->step->log('Yay, backup!', backup::LOG_DEBUG); return $plugin; } diff --git a/versioned_docs/version-5.0/apis/subsystems/backup/restore.md b/versioned_docs/version-5.0/apis/subsystems/backup/restore.md index 16aca9f2a..cf5ee2123 100644 --- a/versioned_docs/version-5.0/apis/subsystems/backup/restore.md +++ b/versioned_docs/version-5.0/apis/subsystems/backup/restore.md @@ -41,9 +41,11 @@ Here is a minimalistic task: ```php require_once($CFG->dirroot . '/backup/moodle2/restore_tool_plugin.class.php'); -class restore_tool_foobar_plugin extends restore_tool_plugin { +class restore_tool_foobar_plugin extends restore_tool_plugin +{ - protected function define_course_plugin_structure() { + protected function define_course_plugin_structure() + { $paths = array(); $this->step->log('Yay, restore!', backup::LOG_DEBUG); return $paths; diff --git a/versioned_docs/version-5.0/apis/subsystems/check/index.md b/versioned_docs/version-5.0/apis/subsystems/check/index.md index 51b97ca38..5fbc14021 100644 --- a/versioned_docs/version-5.0/apis/subsystems/check/index.md +++ b/versioned_docs/version-5.0/apis/subsystems/check/index.md @@ -103,14 +103,17 @@ namespace mod_myplugin\check; use core\check\check; use core\check\result; -class foobar extends check { +class foobar extends check +{ - public function get_action_link(): ?\action_link { + public function get_action_link(): ?\action_link + { $url = new \moodle_url('/mod/myplugin/dosomething.php'); return new \action_link($url, get_string('sitepolicies', 'admin')); } - public function get_result(): result { + public function get_result(): result + { if (some_check()) { $status = result::ERROR; $summary = get_string('check_foobar_error', 'mod_myplugin'); @@ -145,7 +148,8 @@ Next decide on what type of check it should be which determines what report it w Implement the right callback in lib.php for the report you want to add it to, and return an array (usually with only 1 item) of check objects: ```php title="/mod/myplugin/lib.php" -function mod_myplugin_security_checks(): array { +function mod_myplugin_security_checks(): array +{ return [new \mod_myplugin\check\foobar()]; } ``` @@ -157,7 +161,8 @@ Checks have been designed to be dynamic so you can return different checks depen If you plan to return multiple instances of a check class, make sure that each instance has a unique id. ```php -function mod_myplugin_security_checks(): array { +function mod_myplugin_security_checks(): array +{ return [ new \mod_myplugin\check\foobar('one'), new \mod_myplugin\check\foobar('two'), @@ -170,14 +175,17 @@ Set the internal id in a way which is unique across all instances in your compon ```php namespace mod_myplugin\check; -class foobar extends \core\check\check { +class foobar extends \core\check\check +{ protected $id = ''; - public function __construct($id) { + public function __construct($id) + { $this->id = "foobar{$id}"; } - public function get_id(): string { + public function get_id(): string + { return $this->id; } ... @@ -197,17 +205,21 @@ Checks can provide details on a check, such as the complete list of bad records. namespace mod_myplugin\check; -class foobar extends \core\check\check { - public function get_result(): result { +class foobar extends \core\check\check +{ + public function get_result(): result + { return new foobar_result(); } } ``` ```php -class foobar_result extends \core\check\result { +class foobar_result extends \core\check\result +{ ... - public function get_details(): string { + public function get_details(): string + { // Do expensive lookups in here. } } diff --git a/versioned_docs/version-5.0/apis/subsystems/communication/index.md b/versioned_docs/version-5.0/apis/subsystems/communication/index.md index b1107afd4..36697cea8 100644 --- a/versioned_docs/version-5.0/apis/subsystems/communication/index.md +++ b/versioned_docs/version-5.0/apis/subsystems/communication/index.md @@ -291,8 +291,10 @@ This method accepts the following parameters: For example, we have a form where we want to have the communication settings, we can use the below code to add the form elements to the form. ```php -class configure_form extends \moodleform { - public function definition() { +class configure_form extends \moodleform +{ + public function definition() + { $mform = $this->_form; $communication = \core_communication\api::load_by_instance( context: $context, diff --git a/versioned_docs/version-5.0/apis/subsystems/external/files.md b/versioned_docs/version-5.0/apis/subsystems/external/files.md index 627d27648..4eb1fbf23 100644 --- a/versioned_docs/version-5.0/apis/subsystems/external/files.md +++ b/versioned_docs/version-5.0/apis/subsystems/external/files.md @@ -119,7 +119,8 @@ $forum->introfiles = external_util::get_area_files($context->id, 'mod_forum', 'i You can also use the `external_files` structure definition in combination with the method to return the most common file fields required by WS clients. ```php -public static function execute_returns(): external_multiple_structure { +public static function execute_returns(): external_multiple_structure +{ return new external_multiple_structure( new external_single_structure([ 'id' => new external_value(PARAM_INT, 'Forum id'), diff --git a/versioned_docs/version-5.0/apis/subsystems/external/functions.md b/versioned_docs/version-5.0/apis/subsystems/external/functions.md index 295a3cca0..617f40ba8 100644 --- a/versioned_docs/version-5.0/apis/subsystems/external/functions.md +++ b/versioned_docs/version-5.0/apis/subsystems/external/functions.md @@ -65,8 +65,10 @@ use core_external\external_multiple_structure; use core_external\external_single_structure; use core_external\external_value; -class create_groups extends \core_external\external_api { - public static function execute_parameters(): external_function_parameters { +class create_groups extends \core_external\external_api +{ + public static function execute_parameters(): external_function_parameters + { return new external_function_parameters([ 'groups' => new external_multiple_structure( new external_single_structure([ @@ -92,7 +94,8 @@ class create_groups extends \core_external\external_api { ]); } - public static function execute(array $groups): array { + public static function execute(array $groups): array + { // Validate all of the parameters. [ 'groups' => $groups, @@ -114,7 +117,8 @@ class create_groups extends \core_external\external_api { ]; } - public static function execute_returns(): external_single_structure { + public static function execute_returns(): external_single_structure + { return new external_single_structure([ 'groups' => new external_multiple_structure([ 'id' => new external_value(PARAM_INT, 'Id of the created user'), diff --git a/versioned_docs/version-5.0/apis/subsystems/external/security.md b/versioned_docs/version-5.0/apis/subsystems/external/security.md index b6c0cc685..2d9a721e3 100644 --- a/versioned_docs/version-5.0/apis/subsystems/external/security.md +++ b/versioned_docs/version-5.0/apis/subsystems/external/security.md @@ -22,7 +22,8 @@ To do so you should call the `validate_parameters()` function, passing in the re The `validate_parameters()` function is defined on the `\core_external\external_api` class, and can be called as follows: ```php title="local/groupmanager/classes/external/create_groups.php" -public static function execute(array $groups): array { +public static function execute(array $groups): array +{ [ 'groups' => $groups, ] = self::validate_parameters(self::execute_parameters(), [ @@ -45,7 +46,8 @@ If your function operates on multiple contexts (like a list of courses), you mus The `validate_context()` function is defined on the `\core_external\external_api` class, and can be called as follows: ```php title="local/groupmanager/classes/external/create_groups.php" -public static function execute(array $groups): array { +public static function execute(array $groups): array +{ // ... foreach ($groups as $group) { $coursecontext = \context_course::instance($group['courseid']); diff --git a/versioned_docs/version-5.0/apis/subsystems/external/testing.md b/versioned_docs/version-5.0/apis/subsystems/external/testing.md index 8277a6dc9..ab5acac24 100644 --- a/versioned_docs/version-5.0/apis/subsystems/external/testing.md +++ b/versioned_docs/version-5.0/apis/subsystems/external/testing.md @@ -57,14 +57,16 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/webservice/tests/helpers.php'); -class get_fruit_test extends externallib_advanced_testcase { +class get_fruit_test extends externallib_advanced_testcase +{ /** * Test the execute function when capabilities are present. * * @covers \mod_fruit\external\get_fruit::execute */ - public function test_capabilities(): void { + public function test_capabilities(): void + { $this->resetAfterTest(true); $course = $this->getDataGenerator()->create_course(); @@ -99,7 +101,8 @@ class get_fruit_test extends externallib_advanced_testcase { * * @covers \mod_fruit\external\get_fruit::execute */ - public function test_capabilities_missing(): void { + public function test_capabilities_missing(): void + { global $USER; $this->resetAfterTest(true); diff --git a/versioned_docs/version-5.0/apis/subsystems/external/writing-a-service.md b/versioned_docs/version-5.0/apis/subsystems/external/writing-a-service.md index ff27b17c1..87aa9a1a3 100644 --- a/versioned_docs/version-5.0/apis/subsystems/external/writing-a-service.md +++ b/versioned_docs/version-5.0/apis/subsystems/external/writing-a-service.md @@ -150,13 +150,15 @@ use core_external\external_multiple_structure; use core_external\external_single_structure; use core_external\external_value; -class create_groups extends \core_external\external_api { +class create_groups extends \core_external\external_api +{ /** * Returns description of method parameters * @return external_function_parameters */ - public static function execute_parameters() { + public static function execute_parameters() + { return new external_function_parameters([ 'groups' => new external_multiple_structure( new external_single_structure([ @@ -187,7 +189,8 @@ A web service function without parameters will have a parameter description func * Returns description of method parameters * @return external_function_parameters */ -public static function execute_parameters(): external_function_parameters { +public static function execute_parameters(): external_function_parameters +{ return new external_function_parameters([ // If this function had any parameters, they would be described here. // This example has no parameters, so the array is empty. @@ -208,7 +211,8 @@ Our `create_groups()` function expects one parameter named `groups`, so we will * Returns description of method parameters * @return external_function_parameters */ -public static function execute_parameters(): external_function_parameters { +public static function execute_parameters(): external_function_parameters +{ return new external_function_parameters([ 'groups' => ... ]); @@ -280,7 +284,8 @@ We add them to the description : It's similar to execute_parameters(), but instead of describing the parameters, it describes the return values. ```php -public static function execute_returns() { +public static function execute_returns() +{ return new external_multiple_structure( new external_single_structure([ 'id' => new external_value(PARAM_INT, 'group record id'), @@ -312,7 +317,8 @@ Because some web service protocols are strict about the number and types of argu ```php -public static function get_biscuit_parameters() { +public static function get_biscuit_parameters() +{ return new external_function_parameters([ 'chocolatechips' => new external_value( PARAM_BOOL, @@ -340,7 +346,8 @@ public static function get_biscuit_parameters() { ```php -public static function get_biscuit_parameters() { +public static function get_biscuit_parameters() +{ return new external_function_parameters([ 'ifeellike' => new external_single_structure([ 'chocolatechips' => new external_value( @@ -379,7 +386,8 @@ We declared our web service function and we defined the external function parame * @param array $groups array of group description arrays (with keys groupname and courseid) * @return array of newly created groups */ - public static function execute($groups) { + public static function execute($groups) + { global $CFG, $DB; require_once("$CFG->dirroot/group/lib.php"); @@ -471,7 +479,8 @@ External functions deprecation process is slightly different from the standard d * Mark the function as deprecated. * @return bool */ - public static function execute_is_deprecated() { + public static function execute_is_deprecated() + { return true; } ``` diff --git a/versioned_docs/version-5.0/apis/subsystems/files/browsing.md b/versioned_docs/version-5.0/apis/subsystems/files/browsing.md index ca758d27a..ba98c974f 100644 --- a/versioned_docs/version-5.0/apis/subsystems/files/browsing.md +++ b/versioned_docs/version-5.0/apis/subsystems/files/browsing.md @@ -12,7 +12,8 @@ The File Browser API is a supplemental API which can be used to fetch informatio This example demonstrates using the `filebrowser` API to fetch the parent folders of a file. ```php -public function get_file_breadcrumbs(\stored_file $file): ?array { +public function get_file_breadcrumbs(\stored_file $file): ?array +{ $browser = get_file_browser(); $context = get_system_context(); diff --git a/versioned_docs/version-5.0/apis/subsystems/form/advanced/checkbox-controller.md b/versioned_docs/version-5.0/apis/subsystems/form/advanced/checkbox-controller.md index 2a212175e..3f7c3961a 100644 --- a/versioned_docs/version-5.0/apis/subsystems/form/advanced/checkbox-controller.md +++ b/versioned_docs/version-5.0/apis/subsystems/form/advanced/checkbox-controller.md @@ -16,7 +16,8 @@ You can add as many groups of checkboxes as you like, as long as they are unique When adding checkboxes, you can add them in _groups_. Each group of checkboxes must have a unique integer name, for example: ```php title="classes/form/example_form.php" -public function definition(): void { +public function definition(): void +{ // These two elements are part of group 1. $mform->addElement('advcheckbox', 'test1', 'Test 1', null, ['group' => 1]); $mform->addElement('advcheckbox', 'test2', 'Test 2', null, ['group' => 1]); diff --git a/versioned_docs/version-5.0/apis/subsystems/form/index.md b/versioned_docs/version-5.0/apis/subsystems/form/index.md index 065b76e6a..6a57843ec 100644 --- a/versioned_docs/version-5.0/apis/subsystems/form/index.md +++ b/versioned_docs/version-5.0/apis/subsystems/form/index.md @@ -41,9 +41,11 @@ namespace [plugintype]_[pluginname]\form; // moodleform is defined in formslib.php require_once("$CFG->libdir/formslib.php"); -class simplehtml_form extends \moodleform { +class simplehtml_form extends \moodleform +{ // Add elements to form. - public function definition() { + public function definition() + { // A reference to the form is stored in $this->form. // A common convention is to store it in a variable, such as `$mform`. $mform = $this->_form; // Don't forget the underscore! @@ -59,7 +61,8 @@ class simplehtml_form extends \moodleform { } // Custom validation should be added here. - function validation($data, $files) { + function validation($data, $files) + { return []; } } @@ -99,12 +102,15 @@ If you wish to use the form within a block then you should consider using the re Note that the render method does the same as the display method, except returning the HTML rather than outputting it to the browser, as with above make sure you've included the file which contains the class for your Moodle form. ```php -class block_yourblock extends block_base { - public function init(){ +class block_yourblock extends block_base +{ + public function init() + { $this->title = 'Your Block'; } - public function get_content(){ + public function get_content() + { $this->content = (object) [ 'text' => '', ]; @@ -237,7 +243,8 @@ public function add_action_buttons( The `add_action_buttons` function is defined on the `moodleform` class, and not a part of `$this->_form`, for example: ```php - public function definition() { + public function definition() + { // Add your form elements here. $this->_form->addElement(...); @@ -296,7 +303,8 @@ In some cases this is not the desired behaviour, in which case the [disable_form For example: ```php -public function definition() { +public function definition() +{ // Your definition goes here. // Disable the form change checker for this form. @@ -313,7 +321,8 @@ Only header names would be accepted and added to `_shownonlyelements` array. Headers included in `_shownonlyelements` will be shown expanded in the form. The rest of the headers will be hidden. ```php -public function filter_shown_headers(array $shownonly): void { +public function filter_shown_headers(array $shownonly): void +{ $this->_shownonlyelements = []; if (empty($shownonly)) { return; diff --git a/versioned_docs/version-5.0/apis/subsystems/form/usage/index.md b/versioned_docs/version-5.0/apis/subsystems/form/usage/index.md index 0369cddb1..f1fc7de14 100644 --- a/versioned_docs/version-5.0/apis/subsystems/form/usage/index.md +++ b/versioned_docs/version-5.0/apis/subsystems/form/usage/index.md @@ -79,7 +79,8 @@ In most cases you can place this in an auto-loadable class, in which case it sho namespace mod_forum\form; -class myform extends \moodleform { +class myform extends \moodleform +{ // ... } ``` @@ -127,8 +128,10 @@ Moodle has a set of standard form elements used by all Activity modules. These a The `standard_coursemodule_elements()` function is used to add these common elements, and it should be called _before_ the standard action elements are added, for example: ```php -class mod_example_mod_form extends \moodleform_mod { - public function definition() { +class mod_example_mod_form extends \moodleform_mod +{ + public function definition() + { // Add the various form elements. $this->_form->addElement( ... ); diff --git a/versioned_docs/version-5.0/apis/subsystems/output/index.md b/versioned_docs/version-5.0/apis/subsystems/output/index.md index 92a93e487..fff86d340 100644 --- a/versioned_docs/version-5.0/apis/subsystems/output/index.md +++ b/versioned_docs/version-5.0/apis/subsystems/output/index.md @@ -115,20 +115,23 @@ In the example above, we used `$PAGE->get_renderer('tool_demo')` to get an insta Instead, you can use the `core\output\renderer_helper` class to get any renderer instance without using the global. This is an example of how to use the `renderer_helper` class to get a renderer instance: ```php -class my_di_example { +class my_di_example +{ public function __construct( /** @var \core\output\renderer_helper $rendererhelper the renderer helper */ protected readonly \core\output\renderer_helper $rendererhelper, ) { } - public function do_something_with_my_renderer() { + public function do_something_with_my_renderer() + { /** @var \tool_demo\output\renderer $renderer */ $renderer = $this->rendererhelper->get_renderer('tool_demo'); // Do something with the renderer. } - public function do_something_with_core_renderer() { + public function do_something_with_core_renderer() + { // For convenience, the renderer helper also provides a method to get the core renderer. $renderer = $this->rendererhelper->get_core_renderer(); // Do something with the core renderer. @@ -157,11 +160,13 @@ use renderer_base; use templatable; use stdClass; -class index_page implements renderable, templatable { +class index_page implements renderable, templatable +{ /** @var string $sometext Some text to show how to pass data to a template. */ private $sometext = null; - public function __construct($sometext): void { + public function __construct($sometext): void + { $this->sometext = $sometext; } @@ -170,7 +175,8 @@ class index_page implements renderable, templatable { * * @return stdClass */ - public function export_for_template(renderer_base $output): stdClass { + public function export_for_template(renderer_base $output): stdClass + { $data = new stdClass(); $data->sometext = $this->sometext; return $data; @@ -193,7 +199,8 @@ If you wish to use a specific template to render the content you may specify any * * @return string */ - public function get_template_name(\renderer_base $renderer): string { + public function get_template_name(\renderer_base $renderer): string + { return 'tool_demo/index_page'; } ``` @@ -208,7 +215,8 @@ namespace tool_demo\output; use plugin_renderer_base; -class renderer extends plugin_renderer_base { +class renderer extends plugin_renderer_base +{ /** * Defer to template. * @@ -216,7 +224,8 @@ class renderer extends plugin_renderer_base { * * @return string html for the page */ - public function render_index_page($page): string { + public function render_index_page($page): string + { $data = $page->export_for_template($this); return parent::render_from_template('tool_demo/index_page', $data); } @@ -474,11 +483,13 @@ mtrace('DONE'); Or a scheduled or adhoc task, via a trait. Example: ```php -class stored_progress_scheduled_task_example extends \core\task\scheduled_task { +class stored_progress_scheduled_task_example extends \core\task\scheduled_task +{ use \core\task\stored_progress_task_trait; - public function execute() { + public function execute() + { // This simulates a specific count of iterations the task will do, e.g. x number of courses to loop through and do something. $iterations = 100; diff --git a/versioned_docs/version-5.0/apis/subsystems/output/inplace.md b/versioned_docs/version-5.0/apis/subsystems/output/inplace.md index fa1bfdf99..dc7f5c5f0 100644 --- a/versioned_docs/version-5.0/apis/subsystems/output/inplace.md +++ b/versioned_docs/version-5.0/apis/subsystems/output/inplace.md @@ -17,7 +17,8 @@ The best way is to explain the usage on a simple example. Imagine we have plugin Define a callback in `/admin/tool/mytest/lib.php` that starts with the plugin name and ends with `_inplace_editable`: ```php title="admin/tool/mytest/lib.php" -function tool_mytest_inplace_editable($itemtype, $itemid, $newvalue) { +function tool_mytest_inplace_editable($itemtype, $itemid, $newvalue) +{ global $DB; if ($itemtype === 'mytestname') { @@ -80,13 +81,15 @@ This was a very simplified example, in the real life you will probably want to: ```php title="admin/tool/mytest/classes/local/inplace_edit_text.php" -class inplace_edit_text extends \core\output\inplace_editable { +class inplace_edit_text extends \core\output\inplace_editable +{ /** * Constructor. * * @param object $record */ - public function __construct($record) { + public function __construct($record) + { parent::__construct( component: 'tool_mytest', // The item type as managed your plugin. @@ -119,7 +122,8 @@ class inplace_edit_text extends \core\output\inplace_editable { * @param mixed $newvalue * @return \self */ - public static function update($itemid, $newvalue) { + public static function update($itemid, $newvalue) + { // Clean the new value. $newvalue = clean_param($newvalue, PARAM_INT); @@ -194,13 +198,15 @@ $tmpl->set_type_toggle([0, 1]);
```php title="admin/tool/mytest/classes/local/inplace_edit_select.php" -class inplace_edit_select extends \core\output\inplace_editable { +class inplace_edit_select extends \core\output\inplace_editable +{ /** * Constructor. * * @param \stdClass $record */ - public function __construct($record) { + public function __construct($record) + { // Get the options for inplace_edit select box. // The array needs the format: // $options = [ @@ -241,7 +247,8 @@ class inplace_edit_select extends \core\output\inplace_editable { * @param mixed $newvalue * @return \self */ - public static function update($itemid, $newvalue) { + public static function update($itemid, $newvalue) + { // Clean the new value. $newvalue = clean_param($newvalue, PARAM_INT); diff --git a/versioned_docs/version-5.0/apis/subsystems/privacy/index.md b/versioned_docs/version-5.0/apis/subsystems/privacy/index.md index 83e341479..35c99c1b4 100644 --- a/versioned_docs/version-5.0/apis/subsystems/privacy/index.md +++ b/versioned_docs/version-5.0/apis/subsystems/privacy/index.md @@ -119,7 +119,8 @@ class provider implements * * @return string */ - public static function get_reason(): string { + public static function get_reason(): string + { return 'privacy:metadata'; } } @@ -179,7 +180,8 @@ class provider implements // This plugin does store personal user data. \core_privacy\local\metadata\provider { - public static function get_metadata(collection $collection): collection { + public static function get_metadata(collection $collection): collection + { // Here you will add more items into the collection. @@ -214,7 +216,8 @@ Some subsystems which store user data do not need to be listed: ##### Example {/* #example-2 */} ```php title="mod/forum/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_subsystem_link( 'core_files', @@ -243,7 +246,8 @@ It is a matter of judgement which fields contain user data and which don't. Anyt ##### Example {/* #example-3 */} ```php title="mod/forum/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_database_table( 'forum_discussion_subs', @@ -291,7 +295,8 @@ Any plugin providing user preferences must also implement the `\core_privacy\loc ##### Example {/* #example-4 */} ```php title="admin/tool/usertours/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_user_preference('tool_usertours_tour_completion_time', 'privacy:metadata:preference:tool_usertours_tour_completion_time'); @@ -318,7 +323,8 @@ You can indicate this by calling the `add_external_location_link()` method on th ##### Example {/* #example-5 */} ```php title="mod/lti/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_external_location_link('lti_client', [ 'userid' => 'privacy:metadata:lti_client:userid', 'fullname' => 'privacy:metadata:lti_client:fullname', @@ -385,15 +391,16 @@ if (interface_exists('\core_privacy\local\request\userlist')) { } -class provider implements my_userlist { +class provider implements my_userlist +{ /** * Get the list of users who have data within a context. * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ - public static function get_users_in_context(userlist $userlist) { - + public static function get_users_in_context(userlist $userlist) + { } /** @@ -401,8 +408,8 @@ class provider implements my_userlist { * * @param approved_userlist $userlist The approved context and user information to delete information for. */ - public static function delete_data_for_users(approved_userlist $userlist) { - + public static function delete_data_for_users(approved_userlist $userlist) + { } } @@ -421,7 +428,9 @@ Contexts are retrieved using the `get_contexts_for_userid` function which takes * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist {} +public static function get_contexts_for_userid(int $userid): contextlist +{ +} ``` The function returns a `\core_privacy\local\request\contextlist` which is used to keep a set of contexts together in a fixed fashion. @@ -443,7 +452,8 @@ The following example simply fetches the contextid for all forums where a user h * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist { +public static function get_contexts_for_userid(int $userid): contextlist +{ $contextlist = new \core_privacy\local\request\contextlist(); $sql = "SELECT c.id @@ -490,7 +500,8 @@ In the case of the rating data, this will include any post where the user has ra * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist { +public static function get_contexts_for_userid(int $userid): contextlist +{ $ratingsql = \core_rating\privacy\provider::get_sql_join('rat', 'mod_forum', 'post', 'p.id', $userid); // Fetch all forum discussions, and forum posts. $sql = "SELECT c.id @@ -555,7 +566,9 @@ This method is very similar to the `get_contexts_for_userid` function but has so * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ -public static function get_users_in_context(userlist $userlist) {} +public static function get_users_in_context(userlist $userlist) +{ +} ``` ###### Basic example {/* #basic-example-1 */} @@ -568,8 +581,8 @@ The following example simply fetches the userid for all users in a given forum c * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ -public static function get_users_in_context(userlist $userlist) { - +public static function get_users_in_context(userlist $userlist) +{ $context = $userlist->get_context(); if (!$context instanceof \context_module) { @@ -616,7 +629,9 @@ This is achieved through use of the `export_user_data` function which takes the * * @param approved_contextlist $contextlist The approved contexts to export information for. */ -public static function export_user_data(approved_contextlist $contextlist) {} +public static function export_user_data(approved_contextlist $contextlist) +{ +} ``` The `approved_contextlist` includes both the user record, and a list of contexts, which can be retrieved by either processing it as an Iterator, or by calling `get_contextids()` or `get_contexts()` as required. @@ -642,7 +657,8 @@ You need to provide a description of the value of the user preference. (This des * * @param int $userid The userid of the user whose data is to be exported. */ -public static function export_user_preferences(int $userid) { +public static function export_user_preferences(int $userid) +{ $markasreadonnotification = get_user_preferences('markasreadonnotification', null, $userid); if (null !== $markasreadonnotification) { switch ($markasreadonnotification) { @@ -829,7 +845,8 @@ When expiring content for a high-level context such as a course context, the fun * * @param context $context Context to delete data from. */ -public static function delete_data_for_all_users_in_context(\context $context) { +public static function delete_data_for_all_users_in_context(\context $context) +{ global $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -850,7 +867,8 @@ public static function delete_data_for_all_users_in_context(\context $context) { An *approved_contextlist* is given and user data related to that user should either be completely deleted, or overwritten if a structure needs to be maintained. This will be called when a user has requested the right to be forgotten. All attempts should be made to delete this data where practical while still allowing the plugin to be used by other users. ```php title="mod/choice/classes/privacy/provider.php" -public static function delete_data_for_user(approved_contextlist $contextlist) { +public static function delete_data_for_user(approved_contextlist $contextlist) +{ global $DB; if (empty($contextlist->count())) { @@ -874,7 +892,8 @@ An *approved_userlist* is given and user data related to all users in the specif * * @param approved_userlist $userlist The approved context and user information to delete information for. */ -public static function delete_data_for_users(approved_userlist $userlist) { +public static function delete_data_for_users(approved_userlist $userlist) +{ global $DB; $context = $userlist->get_context(); @@ -915,7 +934,8 @@ class provider implements use \core_privacy\local\legacy_polyfill; // The required methods must be in this format starting with an underscore. - public static function _get_metadata(collection $collection) { + public static function _get_metadata(collection $collection) + { // Code for returning metadata goes here. } ``` @@ -943,12 +963,14 @@ class provider implements use \core_plagiarism\privacy\plagiarism_provider\legacy_polyfill; // The required methods must be in this format starting with an underscore. - public static function _get_metadata(collection $collection) { + public static function _get_metadata(collection $collection) + { // Code for returning metadata goes here. } // This is one of the polyfilled methods from the plagiarism provider. - public static function _export_plagiarism_user_data($userid, \context $context, array $subcontext, array $linkarray) { + public static function _export_plagiarism_user_data($userid, \context $context, array $subcontext, array $linkarray) + { // ... } ``` @@ -969,7 +991,8 @@ if (interface_exists('\core_privacy\local\request\core_userlist_provider')) { interface core_userlist_provider {} } -class provider implements core_userlist_provider { +class provider implements core_userlist_provider +{ ``` ## Tips for development {/* #tips-for-development */} diff --git a/versioned_docs/version-5.0/apis/subsystems/privacy/utils.md b/versioned_docs/version-5.0/apis/subsystems/privacy/utils.md index fdbcfb74f..c47c10086 100644 --- a/versioned_docs/version-5.0/apis/subsystems/privacy/utils.md +++ b/versioned_docs/version-5.0/apis/subsystems/privacy/utils.md @@ -108,7 +108,8 @@ foreach ($list->good as $component) { echo "\n\n== Done ==\n"; -function check_implements($component, $interface) { +function check_implements($component, $interface) +{ $manager = new \core_privacy\manager(); $rc = new \ReflectionClass(\core_privacy\manager::class); $rcm = $rc->getMethod('component_implements'); diff --git a/versioned_docs/version-5.0/apis/subsystems/routing/index.md b/versioned_docs/version-5.0/apis/subsystems/routing/index.md index 38b150921..bce11a503 100644 --- a/versioned_docs/version-5.0/apis/subsystems/routing/index.md +++ b/versioned_docs/version-5.0/apis/subsystems/routing/index.md @@ -54,7 +54,8 @@ use core\router\schema\response\payload_response; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -class example { +class example +{ #[\core\router\route( // Resolves to https://example.com/moodle/api/rest/v2/mod_example/example path: '/example', diff --git a/versioned_docs/version-5.0/apis/subsystems/routing/parameters.md b/versioned_docs/version-5.0/apis/subsystems/routing/parameters.md index 75474757b..b57c1a944 100644 --- a/versioned_docs/version-5.0/apis/subsystems/routing/parameters.md +++ b/versioned_docs/version-5.0/apis/subsystems/routing/parameters.md @@ -36,7 +36,8 @@ use core\param; use core\router\route; use core\router\schema\parameters\path_parameter; -class example { +class example +{ #[route( path: '/users/{username}', pathtypes: [ @@ -70,7 +71,8 @@ use core\param; use core\router\route; use core\router\schema\parameters\path_parameter; -class example { +class example +{ #[route( path: '/users/{username}', pathtypes: [ @@ -533,7 +535,8 @@ class path_course extends \core\router\schema\parameters\path_parameter implemen * @return object * @throws not_found_exception If the course cannot be found */ - protected function get_course_for_value(string $value): mixed { + protected function get_course_for_value(string $value): mixed + { global $DB; $data = false; @@ -572,7 +575,8 @@ class path_course extends \core\router\schema\parameters\path_parameter implemen } #[\Override] - public function get_schema_from_type(param $type): \stdClass { + public function get_schema_from_type(param $type): \stdClass + { $schema = parent::get_schema_from_type($type); $schema->pattern = "^("; diff --git a/versioned_docs/version-5.0/apis/subsystems/routing/responses.md b/versioned_docs/version-5.0/apis/subsystems/routing/responses.md index 64f7c8f50..6118fd23e 100644 --- a/versioned_docs/version-5.0/apis/subsystems/routing/responses.md +++ b/versioned_docs/version-5.0/apis/subsystems/routing/responses.md @@ -49,7 +49,8 @@ use core\router\schema\response\payload_response; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -class example { +class example +{ #[\core\router\route( // Resolves to https://example.com/moodle/api/rest/v2/mod_example/example path: '/example', diff --git a/versioned_docs/version-5.0/apis/subsystems/routing/testing.md b/versioned_docs/version-5.0/apis/subsystems/routing/testing.md index 89cb26326..4e9dbe676 100644 --- a/versioned_docs/version-5.0/apis/subsystems/routing/testing.md +++ b/versioned_docs/version-5.0/apis/subsystems/routing/testing.md @@ -22,8 +22,10 @@ You can quickly and easily create a copy of the Moodle Router using the `route_t This is a fully-configured copy of the Moodle Router, and allows to handle requests directly. ```php -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $router = $this->get_router(); } } @@ -56,8 +58,10 @@ You can easily add existing routes to mocking route loader either individually, To add an individual route, you can use the `\route_testcase::add_route_to_route_loader()` method, for example: ```php title="Adding a single route to the route loader" -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $this->add_route_to_route_loader( my_route::class, 'my_route_method', @@ -71,8 +75,10 @@ final class my_test extends \route_testcase { You can also add all routes in a class to the route loader using the `\route_testcase::add_class_routes_to_route_loader()` method, for example: ```php title="Adding all routes in a class to the route loader" -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $this->add_class_routes_to_route_loader( my_route::class, ); @@ -90,7 +96,8 @@ The `\route_testcase` also includes several methods to simplify generating a Req You can create a request and manually pass it to Router using the `\route_testcase::create_request()` method, for example: ```php title="Creating an example request and processing it" -public function test_example(): void { +public function test_example(): void +{ $this->add_class_routes_to_route_loader( my_route::class, ); @@ -114,7 +121,8 @@ When creating a request the default is to use the Route Group for the REST API, The `\route_testcase::process_request()` and `\route_testcsae::process_api_request()` methods act as a shortcut for creating the request, fetching the router, and the app, and handling the request to return a response. The above example can therefore be simplified to: ```php title="Creating and processing an example request" -public function test_example(): void { +public function test_example(): void +{ $this->add_class_routes_to_route_loader( my_route::class, ); diff --git a/versioned_docs/version-5.0/apis/subsystems/tag/index.md b/versioned_docs/version-5.0/apis/subsystems/tag/index.md index a847586f5..6b5a97652 100644 --- a/versioned_docs/version-5.0/apis/subsystems/tag/index.md +++ b/versioned_docs/version-5.0/apis/subsystems/tag/index.md @@ -151,7 +151,8 @@ If you have created a course activity that uses tags you should also remember to * * @param moodleform $mform */ -function book_reset_course_form_definition(&$mform) { +function book_reset_course_form_definition(&$mform) +{ $mform->addElement('header', 'bookheader', get_string('modulenameplural', 'book')); $mform->addElement('checkbox', 'reset_book_tags', get_string('removeallbooktags', 'book')); } @@ -161,7 +162,8 @@ function book_reset_course_form_definition(&$mform) { * @param $data the data submitted from the reset course. * @return array status array */ -function book_reset_userdata($data) { +function book_reset_userdata($data) +{ global $DB; $status = []; @@ -207,7 +209,8 @@ When you tag contents inside the course the plugin has to hook into backup and r You can choose to backup and restore tags for each item individually (as it is done in mod_wiki) OR backup all tags in the context at once (as it is done in mod_glossary or mod_forum). Second option is preferable for performance reasons. Make sure to take into account `$userinfo` (whether user information is backed up / restored), for example wiki pages is not user information but glossary entries are, tags on them follow the same rule. ```php title="mod/glossary/backup_glossary_stepslib.php" -protected function define_structure() { +protected function define_structure() +{ // ... $tags = new backup_nested_element('entriestags'); $tag = new backup_nested_element('tag', ['id'], ['itemid', 'rawname']); @@ -232,7 +235,8 @@ protected function define_structure() { ``` ```php title="mod/glossary/restore_glossary_stepslib.php" -protected function define_structure() { +protected function define_structure() +{ // ... if ($userinfo) { $paths[] = new restore_path_element('glossary_entry_tag', '/activity/glossary/entriestags/tag'); @@ -240,7 +244,8 @@ protected function define_structure() { // ... } -protected function process_glossary_entry_tag($data) { +protected function process_glossary_entry_tag($data) +{ $data = (object)$data; if (!core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) { // Tags disabled on this site, nothing to process. @@ -265,7 +270,8 @@ Given a user searches for any items tagged with a specified tag, only the items To limit the performance impact of checking user access against items the following class ``core_tag_index_builder()`` can assist with the retrieval and caching of records, especially within both course and activity modules. ```php -function mod_wiki_get_tagged_pages($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0) { +function mod_wiki_get_tagged_pages($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0) +{ // Find items. // Please refer to existing callbacks in core for examples. diff --git a/versioned_docs/version-5.0/apis/subsystems/task/adhoc.md b/versioned_docs/version-5.0/apis/subsystems/task/adhoc.md index 0dd508de0..5d057312d 100644 --- a/versioned_docs/version-5.0/apis/subsystems/task/adhoc.md +++ b/versioned_docs/version-5.0/apis/subsystems/task/adhoc.md @@ -38,12 +38,13 @@ namespace mod_example\task; /** * An example of an adhoc task. */ -class do_something extends \core\task\adhoc_task { - +class do_something extends \core\task\adhoc_task +{ /** * Execute the task. */ - public function execute() { + public function execute() + { // Call your own api } } @@ -62,8 +63,8 @@ It can be fetched using the `get_custom_data(): mixed` method. We recommend only ever calling `set_custom_data()` from within a factory method in the task class itself. ```php -class do_something extends \core\task\adhoc_task { - +class do_something extends \core\task\adhoc_task +{ public static function instance( int $id, string $status, @@ -77,7 +78,8 @@ class do_something extends \core\task\adhoc_task { return $task; } - public function execute() { + public function execute() + { $data = $this->get_custom_data(); mtrace($data->id); mtrace($data->status); @@ -177,7 +179,8 @@ $task->get_attempts_available(); Tasks are retried by default, but this behaviour can be modified by overriding the `retry_until_success()` method in your task class, for example: ```php -public function retry_until_success(): bool { +public function retry_until_success(): bool +{ return false; } ``` diff --git a/versioned_docs/version-5.0/apis/subsystems/task/index.md b/versioned_docs/version-5.0/apis/subsystems/task/index.md index 4689e0e5a..e6d746e05 100644 --- a/versioned_docs/version-5.0/apis/subsystems/task/index.md +++ b/versioned_docs/version-5.0/apis/subsystems/task/index.md @@ -92,8 +92,10 @@ Since Moodle 3.5 it is safe to use the [Output API](../output/index.md) in cron In order to improve debugging information, it is good practice to call `mtrace` to log what's going on within a task execution: ```php -class my_task extends \core\task\scheduled_task { - public function execute() { +class my_task extends \core\task\scheduled_task +{ + public function execute() + { mtrace("My task started"); // Do some work. diff --git a/versioned_docs/version-5.0/apis/subsystems/task/scheduled.md b/versioned_docs/version-5.0/apis/subsystems/task/scheduled.md index b29072d9e..7d286c859 100644 --- a/versioned_docs/version-5.0/apis/subsystems/task/scheduled.md +++ b/versioned_docs/version-5.0/apis/subsystems/task/scheduled.md @@ -37,21 +37,24 @@ namespace mod_example\task; /** * An example of a scheduled task. */ -class do_something extends \core\task\scheduled_task { +class do_something extends \core\task\scheduled_task +{ /** * Return the task's name as shown in admin screens. * * @return string */ - public function get_name() { + public function get_name() + { return get_string('dosomething', 'mod_example'); } /** * Execute the task. */ - public function execute() { + public function execute() + { // Call your own api } } diff --git a/versioned_docs/version-5.0/guides/templates/index.md b/versioned_docs/version-5.0/guides/templates/index.md index bee626cfb..41932dc93 100644 --- a/versioned_docs/version-5.0/guides/templates/index.md +++ b/versioned_docs/version-5.0/guides/templates/index.md @@ -397,7 +397,8 @@ The following example shows a renderable using the `mywidget.mustache` template * @param renderer_base $output * @return stdClass */ -public function export_for_template(renderer_base $output) { +public function export_for_template(renderer_base $output) +{ $data = new stdClass(); $data->canmanage = $this->canmanage; $data->things = []; @@ -424,7 +425,8 @@ Example of the method added to tell a renderable to use the `mywidget.mustache` * @param renderer_base $output * @return string */ -public function get_template_name(\renderer_base $renderer): string { +public function get_template_name(\renderer_base $renderer): string +{ return 'tool_myplugin/mywidget'; } ``` @@ -445,7 +447,8 @@ The rendering method can now use templates to render the object: * * @return string HTML */ -protected function render_mywidget(mywidget $widget) { +protected function render_mywidget(mywidget $widget) +{ $data = $widget->export_for_template($this); return $this->render_from_template('tool_myplugin/mywidget', $data); } diff --git a/versioned_docs/version-5.0/guides/upgrade/index.md b/versioned_docs/version-5.0/guides/upgrade/index.md index c3658f5b6..59abf5438 100644 --- a/versioned_docs/version-5.0/guides/upgrade/index.md +++ b/versioned_docs/version-5.0/guides/upgrade/index.md @@ -52,7 +52,8 @@ The following example shows the structure of the upgrade.php file: ```php title="Example upgrade.php file" get_manager(); // Loads ddl manager and xmldb classes. @@ -161,7 +162,8 @@ For example, if you are defining an installation behaviour in the `install.php` $coursemodule->instance]; @@ -224,7 +226,8 @@ First, the function that adds these controls: * @category completion * @return array List of added element names, or names of wrapping group elements. */ -public function add_completion_rules() { +public function add_completion_rules() +{ $mform = $this->_form; @@ -264,7 +267,8 @@ public function add_completion_rules() { return [$this->get_suffixed_name('completionpostsgroup')]; } -protected function get_suffixed_name(string $fieldname): string { +protected function get_suffixed_name(string $fieldname): string +{ return $fieldname . $this->get_suffix(); } ``` @@ -284,7 +288,8 @@ Next, a function for checking whether the user selected this option: * @param array $data Input data not yet validated. * @return bool True if one or more rules is enabled, false if none are. */ -public function completion_rule_enabled($data) { +public function completion_rule_enabled($data) +{ return (!empty($data[$this->get_suffixed_name('completionpostsenabled')]) && $data[$this->get_suffixed_name('completionposts')] != 0); } @@ -295,7 +300,8 @@ public function completion_rule_enabled($data) { That's all the 'required' functions, but we need to add some extra code to support the checkbox behaviour. I overrode `get_data` so that if there is a value in the edit field, but the checkbox is not ticked, the value counts as zero (the rule will not be enabled). ```php -function get_data() { +function get_data() +{ $data = parent::get_data(); if (!$data) { return $data; @@ -316,7 +322,8 @@ You may have noticed the `completionunlocked` check. When some users have alread Finally, forum already had a `data_preprocessing` function but I added code to this to set up the checkboxes when the form is displayed, and to make the default value of the text fields 1 instead of 0: ```php -function data_preprocessing(&$default_values){ +function data_preprocessing(&$default_values) +{ // [Existing code, not shown] // Set up the completion checkboxes which aren't part of standard data. @@ -360,7 +367,8 @@ Here's the function for forum (simplified to include only the one completion opt * @param bool $type Type of comparison (or/and; can be used as return value if no conditions) * @return bool True if completed, false if not, $type if conditions not set. */ - function forum_get_completion_state($course, $cm, $userid, $type) { + function forum_get_completion_state($course, $cm, $userid, $type) + { global $CFG,$DB; // Get forum details @@ -402,7 +410,8 @@ You need to return an array of strings for each completion rule that is active. * @param cm_info|stdClass $cm object with fields ->completion and ->customdata['customcompletionrules'] * @return array $descriptions the array of descriptions for the custom rules. */ -function mod_forum_get_completion_active_rule_descriptions($cm) { +function mod_forum_get_completion_active_rule_descriptions($cm) +{ // Values will be present in cm_info, and we assume these are up to date. if (empty($cm->customdata['customcompletionrules']) || $cm->completion != COMPLETION_TRACKING_AUTOMATIC) { return []; diff --git a/versioned_docs/version-5.1/apis/core/calendar/index.md b/versioned_docs/version-5.1/apis/core/calendar/index.md index 03ca98f0f..11d7f9903 100644 --- a/versioned_docs/version-5.1/apis/core/calendar/index.md +++ b/versioned_docs/version-5.1/apis/core/calendar/index.md @@ -103,7 +103,8 @@ where '$prioritiesforeventtype1' is an associative array that has the timestamp * @param int $lessonid The lesson ID. * @return array|null Array of group override priorities for open and close times. Null if there are no group overrides. */ -function lesson_get_group_override_priorities($lessonid) { +function lesson_get_group_override_priorities($lessonid) +{ global $DB; // Fetch group overrides. @@ -182,7 +183,8 @@ This callback determines if an event should be visible throughout the site. For * @param calendar_event $event * @return bool Returns true if the event is visible to the current user, false otherwise. */ -function mod_assign_core_calendar_is_event_visible(calendar_event $event) { +function mod_assign_core_calendar_is_event_visible(calendar_event $event) +{ global $CFG, $USER; require_once($CFG->dirroot . '/mod/assign/locallib.php'); @@ -259,7 +261,8 @@ Eg. * @param int $itemcount The item count associated with the action event. * @return bool */ -function mod_assign_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) { +function mod_assign_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) +{ // List of event types where the action event's item count should be shown. $eventtypesshowingitemcount = [ ASSIGN_EVENT_TYPE_GRADINGDUE @@ -320,7 +323,8 @@ This callback handles updating the activity instance based on the changed action Example: ```php -function mod_feedback_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $feedback) { +function mod_feedback_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $feedback) +{ global $CFG, $DB; if (empty($event->instance) || $event->modulename != 'feedback') { @@ -406,7 +410,8 @@ If the calendar event has no valid `timestart` values then the callback should r Example: ```php -function mod_feedback_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $instance) { +function mod_feedback_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $instance) +{ $mindate = null; $maxdate = null; diff --git a/versioned_docs/version-5.1/apis/core/clock/index.md b/versioned_docs/version-5.1/apis/core/clock/index.md index de70bd68b..5528cf4c3 100644 --- a/versioned_docs/version-5.1/apis/core/clock/index.md +++ b/versioned_docs/version-5.1/apis/core/clock/index.md @@ -46,13 +46,15 @@ The recommended approach is to have the Dependency Injector inject into the cons ```php title="Usage in injected classes" namespace mod_example; -class post { +class post +{ public function __construct( protected readonly \core\clock $clock, protected readonly \moodle_database $db, ) - public function create_thing(\stdClass $data): \stdClass { + public function create_thing(\stdClass $data): \stdClass + { $data->timecreated = $this->clock->time(); $data->id = $this->db->insert_record('example_thing', $data); @@ -99,8 +101,10 @@ The incrementing clock increases the time by one second every time it is called. A helper method, `mock_clock_with_incrementing(?int $starttime = null): \core\clock`, is provided within the standard testcase: ```php title="Obtaining the incrementing clock" -class my_test extends \advanced_testcase { - public function test_create_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_create_thing(): void + { // This class inserts data into the database. $this->resetAfterTest(true); @@ -134,8 +138,10 @@ The frozen clock uses a time which does not change, unless manually set. This ca A helper method, `mock_clock_with_frozen(?int $time = null): \core\clock`, is provided within the standard testcase: ```php title="Obtaining and using the frozen clock" -class my_test extends \advanced_testcase { - public function test_create_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_create_thing(): void + { // This class inserts data into the database. $this->resetAfterTest(true); @@ -182,27 +188,33 @@ class my_test extends \advanced_testcase { If the standard cases are not suitable for you, then you can create a custom clock and inject it into the DI container. ```php title="Creating a custom clock" -class my_clock implements \core\clock { +class my_clock implements \core\clock +{ public int $time; - public function __construct() { + public function __construct() + { $this->time = time(); } - public function now(): \DateTimeImmutable { + public function now(): \DateTimeImmutable + { $time = new \DateTimeImmutable('@' . $this->time); $this->time = $this->time += 5; return $time; } - public function time(): int { + public function time(): int + { return $this->now()->getTimestamp(); } } -class my_test extends \advanced_testcase { - public function test_my_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_my_thing(): void + { $clock = new my_clock(); \core\di:set(\core\clock::class, $clock); diff --git a/versioned_docs/version-5.1/apis/core/comment/index.md b/versioned_docs/version-5.1/apis/core/comment/index.md index adb05cbe0..6a5749381 100644 --- a/versioned_docs/version-5.1/apis/core/comment/index.md +++ b/versioned_docs/version-5.1/apis/core/comment/index.md @@ -94,7 +94,8 @@ This is an example of a possible callback for plugin `mod_myplugin`: * @param stdClass $args * @return boolean */ -function mod_myplugin_comment_display(stdClass $comments, stdClass $args): stdClass { +function mod_myplugin_comment_display(stdClass $comments, stdClass $args): stdClass +{ if ($args->commentarea != 'entry_comments') { throw new comment_exception('invalidcommentarea'); } diff --git a/versioned_docs/version-5.1/apis/core/customfields/index.md b/versioned_docs/version-5.1/apis/core/customfields/index.md index a4644919c..43acc73ad 100644 --- a/versioned_docs/version-5.1/apis/core/customfields/index.md +++ b/versioned_docs/version-5.1/apis/core/customfields/index.md @@ -105,7 +105,8 @@ The list of fields is cached in the handler and these two functions can be calle ::: ```php title="Example code for course custom fields. This function will return all the custom fields for a given courseid" -function get_course_metadata($courseid) { +function get_course_metadata($courseid) +{ $handler = \core_customfield\handler::get_handler('core_course', 'course'); // This is equivalent to the line above. //$handler = \core_course\customfield\course_handler::create(); diff --git a/versioned_docs/version-5.1/apis/core/deprecation/index.md b/versioned_docs/version-5.1/apis/core/deprecation/index.md index 8df0d5dee..2ce423a71 100644 --- a/versioned_docs/version-5.1/apis/core/deprecation/index.md +++ b/versioned_docs/version-5.1/apis/core/deprecation/index.md @@ -40,24 +40,29 @@ The attribute is a Moodle PHP Attribute and can be applied to: ```php title="Example attribute usage" // On a global function: #[\core\attribute\deprecated('random_bytes', since: '4.3')] -function random_bytes_emulate($length) { +function random_bytes_emulate($length) +{ // Replaced by random_bytes since Moodle 4.3. } // On a class: #[\core\attribute\deprecated(replacement: null, since: '4.4', reason: 'This functionality has been removed.')] -class example { +class example +{ #[\core\attribute\deprecated( replacement: '\core\example::do_something', since: '4.3', reason: 'No longer required', mdl: 'MDL-12345', )] - public function do_something(): void {} + public function do_something(): void + { + } } // On an enum case: -enum example { +enum example +{ #[\core\attribute\deprecated('example::OPTION', since: '4.4', final: true)] case OPTION; } @@ -75,7 +80,8 @@ The `\core\deprecation` class contains helper methods to inspect for use of the // A method which has been initially deprecated, and replaced by 'random_bytes'. It should show debugging. /** @deprecated since 4.3 */ #[\core\attribute\deprecated('random_bytes', since: '4.3')] -function random_bytes_emulate($length) { +function random_bytes_emulate($length) +{ \core\deprecation::emit_deprecation_if_present(__FUNCTION__); return random_bytes($length); } @@ -83,7 +89,8 @@ function random_bytes_emulate($length) { // A method which has been finally deprecated and should throw an exception. /** @deprecated since 2.7 */ #[\core\attribute\deprecated(replacement: 'Events API', since: '2.3', final: true)] -function add_to_log() { +function add_to_log() +{ \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } diff --git a/versioned_docs/version-5.1/apis/core/di/index.md b/versioned_docs/version-5.1/apis/core/di/index.md index 0529877c9..0fbcfd8bd 100644 --- a/versioned_docs/version-5.1/apis/core/di/index.md +++ b/versioned_docs/version-5.1/apis/core/di/index.md @@ -21,7 +21,8 @@ Dependencies are stored using a string id attribute, which is typically the clas When accessing dependencies within a class, it is advisable to inject them into the constructor, for example: ```php title="Fetching a instance of the \core\http_client class from within a class" -class my_thing { +class my_thing +{ public function __construct( protected readonly \core\http_client $client, ) { @@ -48,7 +49,8 @@ The use of readonly properties is also highly recommended as it ensures that dep These language features are available in all Moodle versions supporting Dependency Injection. ```php -class example_without_promotion { +class example_without_promotion +{ protected \core\http_client $client; public function __construct( @@ -58,7 +60,8 @@ class example_without_promotion { } } -class example_with_promotion { +class example_with_promotion +{ public function __construct( protected readonly \core\http_client $client, ) { @@ -101,8 +104,10 @@ namespace mod_example; use core\hook\di_configuration; -class hook_listener { - public static function inject_dependencies(di_configuration $hook): void { +class hook_listener +{ + public static function inject_dependencies(di_configuration $hook): void + { $hook->add_definition( id: complex_client::class, definition: function ( @@ -139,8 +144,10 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; use GuzzleHttp\Psr7\Response; -class example_test extends \advanced_testcase { - public function test_the_thing(): void { +class example_test extends \advanced_testcase +{ + public function test_the_thing(): void + { // Mock our responses to the http_client. $handlerstack = HandlerStack::create(new MockHandler([ new Response(200, [], json_encode(['name' => 'Colin'])), @@ -170,13 +177,15 @@ Dependencies can be usually be easily injected into classes which are themselves In most cases in Moodle, this should be via the class constructor, for example: ```php title="Injecting via the constructor" -class thing_manager { +class thing_manager +{ public function __construct( protected readonly \moodle_database $db, ) { } - public function get_things(): array { + public function get_things(): array + { return $this->db->get_records('example_things'); } } @@ -186,13 +195,15 @@ $manager = \core\di::get(thing_manager::class); $things = $manager->get_things(); // Using it in a child class: -class other_thing { +class other_thing +{ public function __construct( protected readonly thing_manager $manager, ) { } - public function manage_things(): void { + public function manage_things(): void + { $this->manager->get_things(); } } diff --git a/versioned_docs/version-5.1/apis/core/dml/ddl.md b/versioned_docs/version-5.1/apis/core/dml/ddl.md index 83534afad..c33184f78 100644 --- a/versioned_docs/version-5.1/apis/core/dml/ddl.md +++ b/versioned_docs/version-5.1/apis/core/dml/ddl.md @@ -24,7 +24,8 @@ Of course, feel free to clarify, complete and add more info to all this document - All the function calls in this page are public methods of the **database manager**, accessible from the $DB global object. You will need to "import" it within the upgrade function of your **upgrade.php** main function using the `global` keyword, for example: ```php -function xmldb_xxxx_upgrade { +function xmldb_xxxx_upgrade +{ global $DB; // Load the DDL manager and xmldb API. diff --git a/versioned_docs/version-5.1/apis/core/dml/index.md b/versioned_docs/version-5.1/apis/core/dml/index.md index 8b63d7dca..d856ea79e 100644 --- a/versioned_docs/version-5.1/apis/core/dml/index.md +++ b/versioned_docs/version-5.1/apis/core/dml/index.md @@ -33,7 +33,8 @@ require(__DIR__ . '/config.php'); ```php title="example.php" \mod_example\local\entitychanges\create_example::class, @@ -156,7 +158,8 @@ namespace mod_activity\hook; #[\core\attribute\label('Hook dispatched at the very end of installation of mod_activity plugin.')] #[\core\attribute\tags('installation')] -final class installation_finished { +final class installation_finished +{ public function __construct( public readonly string $version, ) { @@ -172,17 +175,20 @@ final class installation_finished { dispatch($hook); } @@ -219,7 +226,8 @@ Using DI for dependency injection has the benefit that the hook manager can use ```php title="Mocking a hook listener" // Unit test. -public function test_before_standard_footer_html_hooked(): void { +public function test_before_standard_footer_html_hooked(): void +{ // Load the callback classes. require_once(__DIR__ . '/fixtures/core_renderer/before_standard_footer_html_callbacks.php'); @@ -242,7 +250,8 @@ public function test_before_standard_footer_html_hooked(): void { } // fixtures/core_renderer/before_standard_footer_html_callbacks.php -final class before_standard_footer_html_callbacks { +final class before_standard_footer_html_callbacks +{ public static function before_standard_footer_html( \core\hook\output\before_standard_footer_html $hook, ): void { @@ -314,8 +323,10 @@ a hook as parameter. namespace local_stuff\local; use \mod_activity\hook\installation_finished; -class hook_callbacks { - public static function activity_installation_finished(installation_finished $hook): void { +class hook_callbacks +{ + public static function activity_installation_finished(installation_finished $hook): void + { if (during_initial_install()) { return; } @@ -388,7 +399,8 @@ use core\attribute; #[attribute\label('Hook dispatched at the very end of lib/setup.php')] #[attribute\tags('config')] #[attribute\hook\replaces_callbacks('after_config')] -final class after_config { +final class after_config +{ } ``` @@ -400,16 +412,20 @@ final class after_config { stopped; } - public function stop(): void { + public function stop(): void + { $this->stopped = true; } } @@ -520,8 +539,10 @@ A callback will only be called if the hook was not stopped before-hand. Dependin namespace local_myplugin; -class callbacks { - public static function block_pre_delete(\core\hook\block_delete_pre $hook): void { +class callbacks +{ + public static function block_pre_delete(\core\hook\block_delete_pre $hook): void + { // ... $hook->stop(); } diff --git a/versioned_docs/version-5.1/apis/core/navigation/index.md b/versioned_docs/version-5.1/apis/core/navigation/index.md index 159250ee1..eaae0aa97 100644 --- a/versioned_docs/version-5.1/apis/core/navigation/index.md +++ b/versioned_docs/version-5.1/apis/core/navigation/index.md @@ -235,7 +235,8 @@ function {modulename}_extend_settings_navigation( You may be required to add a node in a specified order within the menu navigation menus. To do this you need to examine the node object as given in the respective parameters in the functions above, then find the key of the child node you wish to place the link before. For example, applying the code below will put a direct link to grade report. ```php -function my_plugin_extend_settings_navigation($settingsnav, $context){ +function my_plugin_extend_settings_navigation($settingsnav, $context) +{ $addnode = $context->contextlevel === 50; $addnode = $addnode && has_capability('gradereport/grader:view', $context); if ($addnode) { diff --git a/versioned_docs/version-5.1/apis/core/reportbuilder/index.md b/versioned_docs/version-5.1/apis/core/reportbuilder/index.md index b7984b9ff..a7ab677d0 100644 --- a/versioned_docs/version-5.1/apis/core/reportbuilder/index.md +++ b/versioned_docs/version-5.1/apis/core/reportbuilder/index.md @@ -216,7 +216,8 @@ The first method that we need is ***initialise()*** : /** * Initialise report, we need to set the main table, load our entities and set columns/filters */ -protected function initialise(): void { +protected function initialise(): void +{ ``` The initialise method needs to get the main entity, set the main table it needs to use and add the entity to the report: @@ -336,7 +337,8 @@ The first method you need to build is `initialise()` /** * Initialise report, we need to set the main table, load our entities and set columns/filters */ -protected function initialise(): void { +protected function initialise(): void +{ ``` The initialise method needs to get the main entity, set the main table it needs to use and add the entity to the report: @@ -397,7 +399,8 @@ You will need to specify the name that is displayed to the end user for the data * * @return string */ - public static function get_name(): string { + public static function get_name(): string + { return get_string('tasklogs', 'core_admin'); } ``` @@ -412,7 +415,8 @@ Once all entities have been added you need to define which columns it will show * * @return string[] */ -public function get_default_columns(): array { +public function get_default_columns(): array +{ return [ 'task_log:name', 'task_log:starttime', @@ -430,7 +434,8 @@ You may also optionally define the sorting that will be applied to the default r * * @return int[] */ -public function get_default_column_sorting(): array { +public function get_default_column_sorting(): array +{ return [ 'task_log:starttime' => SORT_DESC, ]; @@ -447,7 +452,8 @@ The filters allow the end user of the report to only see a subset of the data th * * @return string[] */ -public function get_default_filters(): array { +public function get_default_filters(): array +{ return [ 'task_log:timestart', 'task_log:result', @@ -465,7 +471,8 @@ The conditions allow the user creating the report to define which data it will r * * @return string[] */ -public function get_default_conditions(): array { +public function get_default_conditions(): array +{ return [ 'task_log:type', 'task_log:timestart', @@ -482,7 +489,8 @@ You may also optionally define the [initial values for any of the default condit * * @return array */ -public function get_default_condition_values(): array { +public function get_default_condition_values(): array +{ return [ 'task_log:type_operator' => select::EQUAL_TO, 'task_log:type_value' => \core\task\database_logger::TYPE_SCHEDULED, @@ -508,7 +516,8 @@ require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php"); * @copyright 2023 Paul Holden * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class categories_test extends core_reportbuilder_testcase { +class categories_test extends core_reportbuilder_testcase +{ ``` The `core_reportbuilder_testcase` will not autoload so we first ensure that it is loaded with the `require_once`. After this there are a few things you should look to test: @@ -526,7 +535,8 @@ For this you want a step that sets up will return enough data allows you test al /** * Test default datasource */ - public function test_datasource_default(): void { + public function test_datasource_default(): void + { $this->resetAfterTest(); $category = $this->getDataGenerator()->create_category(['name' => 'Zoo', 'idnumber' => 'Z01']); @@ -618,7 +628,8 @@ None of these tests checks that the data is what you want, but will ensure that * * In order to execute this test PHPUNIT_LONGTEST should be defined as true in phpunit.xml or directly in config.php */ - public function test_stress_datasource(): void { + public function test_stress_datasource(): void + { if (!PHPUNIT_LONGTEST) { $this->markTestSkipped('PHPUNIT_LONGTEST is not defined'); } diff --git a/versioned_docs/version-5.1/apis/plugintypes/ai/placement.md b/versioned_docs/version-5.1/apis/plugintypes/ai/placement.md index dfa4d6c48..e33e4cfc7 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/ai/placement.md +++ b/versioned_docs/version-5.1/apis/plugintypes/ai/placement.md @@ -39,7 +39,8 @@ They must also implement the following methods: This is the list of Actions that are supported by this Placement, for example the `aiplacement_editor` plugin defines this as: ```php -public function get_action_list(): array { +public function get_action_list(): array +{ return [ \core_ai\aiactions\generate_text::class, \core_ai\aiactions\generate_image::class, diff --git a/versioned_docs/version-5.1/apis/plugintypes/ai/provider.md b/versioned_docs/version-5.1/apis/plugintypes/ai/provider.md index c5eaa4c50..0b1e3661c 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/ai/provider.md +++ b/versioned_docs/version-5.1/apis/plugintypes/ai/provider.md @@ -41,7 +41,8 @@ They must also implement the following methods: This is the list of Actions that are supported by this Provider, for example the `aiprovider_openai` plugin defines this as: ```php -public static function get_action_list(): array { +public static function get_action_list(): array +{ return [ \core_ai\aiactions\generate_text::class, \core_ai\aiactions\generate_image::class, @@ -62,7 +63,8 @@ For example, the `aiprovider_azureai` provider checks values are set for `$this- the result. ```php -public function is_provider_configured(): bool { +public function is_provider_configured(): bool +{ return !empty($this->config['apikey']) && !empty($this->config['endpoint']); } ``` @@ -171,14 +173,16 @@ For example, the `aiprovider_openai` plugin defines this: namespace aiprovider_openai; use core_ai\hook\after_ai_provider_form_hook; -class hook_listener { +class hook_listener +{ /** * Hook listener for the Open AI instance setup form. * * @param after_ai_provider_form_hook $hook The hook to add to the AI instance setup. */ - public static function set_form_definition_for_aiprovider_openai(after_ai_provider_form_hook $hook): void { + public static function set_form_definition_for_aiprovider_openai(after_ai_provider_form_hook $hook): void + { if ($hook->plugin !== 'aiprovider_openai') { return; } @@ -260,9 +264,11 @@ These classes should extend the `core_ai\form\action_settings_form` class, and m For example, the `aiprovider_openai` plugin defines this: ```php -class action_generate_text_form extends action_settings_form { +class action_generate_text_form extends action_settings_form +{ #[\Override] - protected function definition() { + protected function definition() + { $mform = $this->_form; $actionconfig = $this->_customdata['actionconfig']['settings'] ?? []; $returnurl = $this->_customdata['returnurl'] ?? null; @@ -302,14 +308,17 @@ namespace aiprovider_openai\aimodel; use core_ai\aimodel\base; use MoodleQuickForm; -class gpt4o extends base implements openai_base { +class gpt4o extends base implements openai_base +{ #[\Override] - public function get_model_name(): string { + public function get_model_name(): string + { return 'gpt-4o'; } #[\Override] - public function get_model_display_name(): string { + public function get_model_display_name(): string + { return 'GPT-4o'; } @@ -325,12 +334,14 @@ To add configurable settings for individual models: ```php #[\Override] - public function has_model_settings(): bool { + public function has_model_settings(): bool + { return true; } #[\Override] - public function add_model_settings(MoodleQuickForm $mform): void { + public function add_model_settings(MoodleQuickForm $mform): void + { $mform->addElement( 'text', 'top_p', @@ -354,13 +365,15 @@ To add configurable settings for individual models: ```php namespace aiprovider_openai; - class helper { + class helper + { /** * Get all model classes. * * @return array Array of model classes */ - public static function get_model_classes(): array { + public static function get_model_classes(): array + { $models = []; $modelclasses = \core_component::get_component_classes_in_namespace('aiprovider_openai', 'aimodel'); foreach ($modelclasses as $class => $path) { @@ -378,7 +391,8 @@ To add configurable settings for individual models: * @param string $modelname The model name * @return \core_ai\aimodel\base|null The model class or null if not found */ - public static function get_model_class(string $modelname): ?\core_ai\aimodel\base { + public static function get_model_class(string $modelname): ?\core_ai\aimodel\base + { foreach (self::get_model_classes() as $modelclass) { $model = new $modelclass(); if ($model->get_model_name() === $modelname) { @@ -399,7 +413,8 @@ For example, the `aiprovider_openai` plugin does these: 1. Create a hook listener that adds model settings to the action form: ```php - public static function set_model_form_definition_for_aiprovider_openai(after_ai_action_settings_form_hook $hook): void { + public static function set_model_form_definition_for_aiprovider_openai(after_ai_action_settings_form_hook $hook): void + { if ($hook->plugin !== 'aiprovider_openai') { return; } diff --git a/versioned_docs/version-5.1/apis/plugintypes/assign/feedback.md b/versioned_docs/version-5.1/apis/plugintypes/assign/feedback.md index 0634bccbf..c77a995f3 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/assign/feedback.md +++ b/versioned_docs/version-5.1/apis/plugintypes/assign/feedback.md @@ -121,7 +121,8 @@ All feedback plugins should include one setting named 'default' to indicate if t This is where all the functionality for this plugin is defined. We will step through this file and describe each part as we go. ```php -class assign_feedback_file extends assign_feedback_plugin { +class assign_feedback_file extends assign_feedback_plugin +{ ``` #### get_name() {/* #get_name */} @@ -129,7 +130,8 @@ class assign_feedback_file extends assign_feedback_plugin { All feedback plugins MUST define a class with the component name of the plugin that extends assign_feedback_plugin. ```php -public function get_name() { +public function get_name() +{ return get_string('file', 'assignfeedback_file'); } ``` @@ -139,7 +141,8 @@ This function is abstract in the parent class (feedback_plugin) and must be defi #### get_settings() {/* #get_settings */} ```php -public function get_settings(MoodleQuickForm $mform) { +public function get_settings(MoodleQuickForm $mform) +{ $mform->addElement( 'assignfeedback_file_fileextensions', get_string('allowedfileextensions', 'assignfeedback_file') @@ -153,7 +156,8 @@ This function is called when building the settings page for the assignment. It a #### save_settings() {/* #save_settings */} ```php -public function save_settings(stdClass $data) { +public function save_settings(stdClass $data) +{ $this->set_config('allowedfileextensions', $data->allowedfileextensions); return true; } @@ -204,7 +208,8 @@ This function is called when building the feedback form. It functions identicall #### is_feedback_modified() {/* #is_feedback_modified */} ```php -public function is_feedback_modified(stdClass $grade, stdClass $data) { +public function is_feedback_modified(stdClass $grade, stdClass $data) +{ $commenttext = ''; if ($grade) { $feedbackcomments = $this->get_feedback_comments($grade->id); @@ -226,7 +231,8 @@ This function is called before feedback is saved. If feedback has not been modif #### save() {/* #save */} ```php -public function save(stdClass $grade, stdClass $data) { +public function save(stdClass $grade, stdClass $data) +{ global $DB; $fileoptions = $this->get_file_options(); @@ -263,7 +269,8 @@ This function is called to save a graders feedback. The parameters are the grade #### view_summary() {/* #view_summary */} ```php -public function view_summary(stdClass $grade, & $showviewlink) { +public function view_summary(stdClass $grade, & $showviewlink) +{ $count = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA); // show a view all link if the number of files is over this limit $showviewlink = $count > ASSIGNFEEDBACK_FILE_MAXSUMMARYFILES; @@ -285,7 +292,8 @@ This function is called to display a summary of the feedback to both markers and #### view() {/* #view */} ```php -public function view(stdClass $grade) { +public function view(stdClass $grade) +{ return $this->assignment->render_area_files( 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, @@ -299,7 +307,8 @@ This function is called to display the entire feedback to both markers and stude #### can_upgrade() {/* #can_upgrade */} ```php -public function can_upgrade($type, $version) { +public function can_upgrade($type, $version) +{ if (($type == 'upload' || $type == 'uploadsingle') && $version >= 2011112900) { return true; @@ -311,7 +320,8 @@ public function can_upgrade($type, $version) { This function is used to identify old "Assignment 2.2" subtypes that can be upgraded by this plugin. This plugin supports upgrades from the old "upload" and "uploadsingle" assignment subtypes. ```php -public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) { +public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) +{ // first upgrade settings (nothing to do) return true; } @@ -360,7 +370,8 @@ This function upgrades a single submission from the old assignment type to the n #### is_empty() {/* #is_empty */} ```php -public function is_empty(stdClass $submission) { +public function is_empty(stdClass $submission) +{ return $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA) == 0; } ``` @@ -370,7 +381,8 @@ If a plugin has no data to show then this function should return true from the ` #### get_file_areas() {/* #get_file_areas */} ```php -public function get_file_areas() { +public function get_file_areas() +{ return [ASSIGNFEEDBACK_FILE_FILEAREA => $this->get_name()]; } ``` @@ -380,7 +392,8 @@ A plugin should implement `get_file_areas` if it supports saving of any files to #### delete_instance() {/* #delete_instance */} ```php -public function delete_instance() { +public function delete_instance() +{ global $DB; // will throw exception on failure $DB->delete_records('assignfeedback_file', [ @@ -396,11 +409,13 @@ This function is called when a plugin is deleted. Note only database records nee #### Gradebook features {/* #gradebook-features */} ```php -public function format_for_gradebook(stdClass $grade) { +public function format_for_gradebook(stdClass $grade) +{ return FORMAT_MOODLE; } -public function text_for_gradebook(stdClass $grade) { +public function text_for_gradebook(stdClass $grade) +{ return ''; } ``` @@ -413,7 +428,8 @@ Only one feedback plugin can push comments to the gradebook. Usually this is the * * @return boolean - True if the plugin supports quickgrading */ -public function supports_quickgrading() { +public function supports_quickgrading() +{ return false; } @@ -424,7 +440,8 @@ public function supports_quickgrading() { * @param mixed $grade grade or null - The grade data. May be null if there are no grades for this user (yet) * @return mixed - A html string containing the html form elements required for quickgrading or false to indicate this plugin does not support quickgrading */ -public function get_quickgrading_html($userid, $grade) { +public function get_quickgrading_html($userid, $grade) +{ return false; } @@ -435,7 +452,8 @@ public function get_quickgrading_html($userid, $grade) { * @param stdClass $grade The grade * @return boolean - true if the quickgrading form element has been modified */ -public function is_quickgrading_modified($userid, $grade) { +public function is_quickgrading_modified($userid, $grade) +{ return false; } @@ -446,7 +464,8 @@ public function is_quickgrading_modified($userid, $grade) { * @param stdClass $grade The grade * @return boolean - true if the grade changes were saved correctly */ -public function save_quickgrading_changes($userid, $grade) { +public function save_quickgrading_changes($userid, $grade) +{ return false; } ``` @@ -457,7 +476,8 @@ These 4 functions can be implemented to allow a plugin to support quick-grading. /** * Run cron for this plugin */ -public static function cron() { +public static function cron() +{ } ``` @@ -471,7 +491,8 @@ A plugin can run code when cron runs by implementing this method. * @return array - An array of action and description strings. * The action will be passed to grading_action. */ -public function get_grading_actions() { +public function get_grading_actions() +{ return []; } @@ -481,7 +502,8 @@ public function get_grading_actions() { * @param string $gradingaction The action chosen from the grading actions menu * @return string The page containing the form */ -public function grading_action($gradingaction) { +public function grading_action($gradingaction) +{ return ''; } ``` @@ -495,7 +517,8 @@ Grading actions appear in the select menu above the grading table and apply to t * @return array - An array of action and description strings. * The action will be passed to grading_batch_operation. */ -public function get_grading_batch_operations() { +public function get_grading_batch_operations() +{ return []; } @@ -506,7 +529,8 @@ public function get_grading_batch_operations() { * @param array $users The list of selected userids * @return string The page containing the form */ -public function grading_batch_operation($action, $users) { +public function grading_batch_operation($action, $users) +{ return ''; } ``` diff --git a/versioned_docs/version-5.1/apis/plugintypes/assign/submission.md b/versioned_docs/version-5.1/apis/plugintypes/assign/submission.md index d4e43f75e..e643dbe16 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/assign/submission.md +++ b/versioned_docs/version-5.1/apis/plugintypes/assign/submission.md @@ -118,7 +118,8 @@ This example from the submission_file plugin also checks to see if there is a ma This is where all the functionality for this plugin is defined. We will step through this file and describe each part as we go. ```php -class assign_submission_file extends assign_submission_plugin { +class assign_submission_file extends assign_submission_plugin +{ ``` All submission plugins MUST define a class with the component name of the plugin that extends assign_submission_plugin. @@ -126,7 +127,8 @@ All submission plugins MUST define a class with the component name of the plugin #### get_name() {/* #get_name */} ```php -public function get_name() { +public function get_name() +{ return get_string('file', 'assignsubmission_file'); } ``` @@ -136,7 +138,8 @@ Get name is abstract in submission_plugin and must be defined in your new plugin #### get_settings() {/* #get_settings */} ```php -public function get_settings(MoodleQuickForm $mform) { +public function get_settings(MoodleQuickForm $mform) +{ global $CFG, $COURSE; $defaultmaxfilesubmissions = $this->get_config('maxfilesubmissions'); @@ -193,7 +196,8 @@ The "get_settings" function is called when building the settings page for the as #### save_settings() {/* #save_settings */} ```php -public function save_settings(stdClass $data) { +public function save_settings(stdClass $data) +{ $this->set_config('maxfilesubmissions', $data->assignsubmission_file_maxfiles); $this->set_config('maxsubmissionsizebytes', $data->assignsubmission_file_maxsizebytes); return true; @@ -205,7 +209,8 @@ The "save_settings" function is called when the assignment settings page is subm #### get_form_elements() {/* #get_form_elements */} ```php -public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data) { +public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data) +{ if ($this->get_config('maxfilesubmissions') <= 0) { return false; } @@ -240,7 +245,8 @@ The get_form_elements function is called when building the submission form. It f #### save() {/* #save */} ```php -public function save(stdClass $submission, stdClass $data) { +public function save(stdClass $submission, stdClass $data) +{ global $USER, $DB; $fileoptions = $this->get_file_options(); @@ -305,7 +311,8 @@ The "save" function is called to save a user submission. The parameters are the #### get_files() {/* #get_files */} ```php -public function get_files($submission) { +public function get_files($submission) +{ $result = []; $fs = get_file_storage(); @@ -330,7 +337,8 @@ If this submission plugin produces one or more files, it should implement "get_f #### view_summary() {/* #view_summary */} ```php -public function view_summary(stdClass $submission, & $showviewlink) { +public function view_summary(stdClass $submission, & $showviewlink) +{ $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); // Show we show a link to view all files for this plugin. @@ -352,7 +360,8 @@ The view_summary function is called to display a summary of the submission to bo #### view() {/* #view */} ```php -public function view($submission) { +public function view($submission) +{ return $this->assignment->render_area_files( 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, @@ -367,7 +376,8 @@ The view function is called to display the entire submission to both markers and ```php #[\Override] -public function submission_summary_for_messages(stdClass $submission): array { +public function submission_summary_for_messages(stdClass $submission): array +{ global $PAGE; $onlinetextsubmission = $this->get_onlinetext_submission($submission->id); @@ -392,7 +402,8 @@ This method produces a summary of what was submitted, in a form suitable to incl #### can_upgrade() {/* #can_upgrade */} ```php -public function can_upgrade($type, $version) { +public function can_upgrade($type, $version) +{ $uploadsingle_type ='uploadsingle'; $upload_type ='upload'; @@ -408,7 +419,8 @@ The can_upgrade function is used to identify old "Assignment 2.2" subtypes that #### upgrade_settings() {/* #upgrade_settings */} ```php -public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) { +public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) +{ global $DB; if ($oldassignment->assignmenttype == 'uploadsingle') { @@ -450,7 +462,8 @@ This function is called once per assignment instance to upgrade the settings fro #### upgrade() {/* #upgrade */} ```php -public function upgrade($oldcontext, $oldassignment, $oldsubmission, $submission, &$log) { +public function upgrade($oldcontext, $oldassignment, $oldsubmission, $submission, &$log) +{ global $DB; $filesubmission = (object) [ @@ -486,7 +499,8 @@ The "upgrade" function upgrades a single submission from the old assignment type #### get_editor_fields() {/* #get_editor_fields */} ```php -public function () { +public function () +{ return [ 'onlinetext' => get_string('pluginname', 'assignsubmission_comments'), ]; @@ -498,7 +512,8 @@ This example is from assignsubmission_onlinetext. If the plugin uses a text-edit #### get_editor_text() {/* #get_editor_text */} ```php -public function get_editor_text($name, $submissionid) { +public function get_editor_text($name, $submissionid) +{ if ($name == 'onlinetext') { $onlinetextsubmission = $this->get_onlinetext_submission($submissionid); if ($onlinetextsubmission) { @@ -515,7 +530,8 @@ This example is from assignsubmission_onlinetext. If the plugin uses a text-edit #### get_editor_format() {/* #get_editor_format */} ```php -public function get_editor_format($name, $submissionid) { +public function get_editor_format($name, $submissionid) +{ if ($name == 'onlinetext') { $onlinetextsubmission = $this->get_onlinetext_submission($submissionid); if ($onlinetextsubmission) { @@ -532,7 +548,8 @@ This example is from assignsubmission_onlinetext. For the same reason as the pre #### is_empty() {/* #is_empty */} ```php -public function is_empty(stdClass $submission) { +public function is_empty(stdClass $submission) +{ return $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA) == 0; } ``` @@ -542,7 +559,8 @@ If a plugin has no submission data to show - it can return true from the is_empt #### submission_is_empty() {/* #submission_is_empty */} ```php -public function submission_is_empty() { +public function submission_is_empty() +{ global $USER; $fs = get_file_storage(); @@ -565,7 +583,8 @@ Determine if a submission is empty. This is distinct from is_empty() in that it #### get_file_areas() {/* #get_file_areas */} ```php -public function get_file_areas() { +public function get_file_areas() +{ return [ASSIGNSUBMISSION_FILE_FILEAREA=>$this->get_name()]; } ``` @@ -575,7 +594,8 @@ A plugin should implement get_file_areas if it supports saving of any files to m #### copy_submission() {/* #copy_submission */} ```php -public function copy_submission(stdClass $sourcesubmission, stdClass $destsubmission) { +public function copy_submission(stdClass $sourcesubmission, stdClass $destsubmission) +{ global $DB; // Copy the files across. @@ -609,7 +629,8 @@ Since Moodle 2.5 - a students submission can be copied to create a new submissio #### format_for_log() {/* #format_for_log */} ```php -public function format_for_log(stdClass $submission) { +public function format_for_log(stdClass $submission) +{ // Format the information for each submission plugin add_to_log $filecount = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); return ' the number of file(s) : ' . $filecount . " file(s).
"; @@ -621,7 +642,8 @@ The format_for_log function lets a plugin produce a really short summary of a su #### delete_instance() {/* #delete_instance */} ```php -public function delete_instance() { +public function delete_instance() +{ global $DB; // Will throw exception on failure $DB->delete_records('assignsubmission_file', [ diff --git a/versioned_docs/version-5.1/apis/plugintypes/availability/index.md b/versioned_docs/version-5.1/apis/plugintypes/availability/index.md index fe15d4233..19dcc032c 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/availability/index.md +++ b/versioned_docs/version-5.1/apis/plugintypes/availability/index.md @@ -83,12 +83,14 @@ Here's an outline of the code (with standard PHPdoc comments omitted to save spa // You must use the right namespace (matching your plugin component name). namespace availability_name; -class condition extends \core_availability\condition { +class condition extends \core_availability\condition +{ // Any data associated with the condition can be stored in member // variables. Here's an example variable: protected $allow; - public function __construct($structure) { + public function __construct($structure) + { // Retrieve any necessary data from the $structure here. The // structure is extracted from JSON data stored in the database // as part of the tree structure of conditions relating to an @@ -100,7 +102,8 @@ class condition extends \core_availability\condition { // throw a coding_exception if the structure is wrong. } - public function save() { + public function save() + { // Save back the data into a plain array similar to $structure above. return (object)array('type' => 'name', 'allow' => $this->allow); } @@ -142,7 +145,8 @@ class condition extends \core_availability\condition { return $allow ? 'Users are allowed' : 'Users not allowed'; } - protected function get_debug_string() { + protected function get_debug_string() + { // This function is only normally used for unit testing and // stuff like that. Just make a short string representation // of the values of the condition, suitable for developers. @@ -162,9 +166,11 @@ The class is required, but all the functions are theoretically optional; you can ```php namespace availability_name; -class frontend extends \core_availability\frontend { +class frontend extends \core_availability\frontend +{ - protected function get_javascript_strings() { + protected function get_javascript_strings() + { // You can return a list of names within your language file and the // system will include them here. // Should you need strings from another language file, you can also diff --git a/versioned_docs/version-5.1/apis/plugintypes/blocks/index.md b/versioned_docs/version-5.1/apis/plugintypes/blocks/index.md index bc56f7024..b42ddf26f 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/blocks/index.md +++ b/versioned_docs/version-5.1/apis/plugintypes/blocks/index.md @@ -160,7 +160,8 @@ This function is called on your subclass right after an instance is loaded. It i Example of a specialization method using the instance configuration. ```php -function specialization() { +function specialization() +{ if (isset($this->config->title)) { $this->title = format_string($this->config->title, true, ['context' => $this->context]); } else { @@ -180,11 +181,13 @@ In order to get our block to actually display something on screen, we need to ad ```php -class block_pluginname extends block_base { +class block_pluginname extends block_base +{ // (...) - public function get_content() { + public function get_content() + { if ($this->content !== null) { return $this->content; } @@ -202,11 +205,13 @@ class block_pluginname extends block_base { ```php -class block_pluginname extends block_list { +class block_pluginname extends block_list +{ // (...) - public function get_content() { + public function get_content() + { global $OUTPUT; if ($this->content !== null) { return $this->content; @@ -256,7 +261,8 @@ By default, only one instance of each block plugin can be added to a page. Howev
```php -public function instance_allow_multiple() { +public function instance_allow_multiple() +{ return true; } ``` @@ -279,7 +285,8 @@ Using this method each block instance can decide if the standard block header is
```php -public function hide_header() { +public function hide_header() +{ return true; } ``` @@ -298,7 +305,8 @@ By default, each block section in the page will use a standard `block` class and
```php -public function html_attributes() { +public function html_attributes() +{ // Get default values. $attributes = parent::html_attributes(); // Append our class to class attribute. @@ -351,7 +359,8 @@ However, for some cases like the Atto HTML editor, you may want to store them in
```php title="Example of adding data before storing it -public function instance_config_save($data,$nolongerused =false) { +public function instance_config_save($data,$nolongerused =false) +{ // Example of add new data. $data->somenewattribute = 'Some new value'; @@ -393,7 +402,8 @@ While in other Moodle pulgins the existence of a settings.php is enough to enabl
```php" -function has_config() { +function has_config() +{ return true; } ``` @@ -421,7 +431,8 @@ Each page in Moodle can define it's own page type name. However, there are some
```php -public function applicable_formats() { +public function applicable_formats() +{ return [ 'admin' => false, 'site-index' => false, diff --git a/versioned_docs/version-5.1/apis/plugintypes/enrol/index.md b/versioned_docs/version-5.1/apis/plugintypes/enrol/index.md index bd2695079..da1a3c56d 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/enrol/index.md +++ b/versioned_docs/version-5.1/apis/plugintypes/enrol/index.md @@ -151,7 +151,8 @@ By default, all enrolment plugins will have *editing enrolment* and *user unenro * @param stdClass $userenrolment * @return array An array of user_enrolment_actions */ -public function get_user_enrolment_actions(course_enrolment_manager $manager, $userenrolment) { +public function get_user_enrolment_actions(course_enrolment_manager $manager, $userenrolment) +{ $actions = parent::get_user_enrolment_actions($manager, $userenrolment); $context = $manager->get_context(); $instance = $userenrolment->enrolmentinstance; @@ -191,7 +192,8 @@ The unenrol action will allow resetif all following conditions are met:
```php -public function allow_unenrol(stdClass $instance) { +public function allow_unenrol(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -224,7 +226,8 @@ The unenrol action will be displayed if all following conditions are met:
```php -public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) { +public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) +{ // Add any extra validation here. return true; } @@ -241,7 +244,8 @@ It is quite common in enrolment plugins to allow unenrol only if the user enrolm
```php -public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) { +public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) +{ if ($userenrolment->status == ENROL_USER_SUSPENDED) { return true; } @@ -270,7 +274,8 @@ The edit manual enrolment action will be displayed if if all following condition
```php -public function allow_enrol(stdClass $instance) { +public function allow_enrol(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -343,7 +348,8 @@ The edit enrolment action in the participants list will be displayed if if all f
```php -public function allow_manage(stdClass $instance) { +public function allow_manage(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -363,7 +369,8 @@ Enrolment plugins can protect roles from being modified by any other plugin. Ret
```php -public function roles_protected() { +public function roles_protected() +{ // Add any extra validation here if necessary. return false; } @@ -393,7 +400,8 @@ The only exception is *enrol_self* - although it is not possible to uniquely ide
```php -public function find_instance(array $enrolmentdata, int $courseid) : ?stdClass { +public function find_instance(array $enrolmentdata, int $courseid) : ?stdClass +{ global $DB; $instances = enrol_get_instances($courseid, false); diff --git a/versioned_docs/version-5.1/apis/plugintypes/fileconverter/index.md b/versioned_docs/version-5.1/apis/plugintypes/fileconverter/index.md index e2d7464a6..daedef81a 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/fileconverter/index.md +++ b/versioned_docs/version-5.1/apis/plugintypes/fileconverter/index.md @@ -54,7 +54,8 @@ This function informs the File Converter API whether the system requirements of It should be lightweight to call and cache where required. ```php title="Example implementation" -public static function are_requirements_met() { +public static function are_requirements_met() +{ return extension_loaded('my_php_extension'); } ``` @@ -72,9 +73,11 @@ The `start_document_conversion()` function starts a conversion, whilst `poll_con This function allows the plugin to answer whether it supports conversion between two formats. It is typically only used internally by the File Conversion subsystem. ```php title="Example implementation" -class converter implements \core_files\converter_interface { +class converter implements \core_files\converter_interface +{ // ... - public static function supports($from, $to) { + public static function supports($from, $to) + { // This plugin supports conversion from doc and docx to pdf only. if ($from !== 'doc' && $from !== 'docx') { return false; diff --git a/versioned_docs/version-5.1/apis/plugintypes/filter/index.md b/versioned_docs/version-5.1/apis/plugintypes/filter/index.md index 70c2dbbde..81afdeaf7 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/filter/index.md +++ b/versioned_docs/version-5.1/apis/plugintypes/filter/index.md @@ -107,7 +107,8 @@ If a filter uses a special syntax or it is based on an appearance of a substring /** * Example of a filter that uses links in some way. */ -public function filter($text, array $options = []) { +public function filter($text, array $options = []) +{ if (!is_string($text) or empty($text)) { // Non-string data can not be filtered anyway. @@ -138,8 +139,10 @@ To support this behaviour, a filter plugin must provide a `filterlocalsettings.p
```php title="filterlocalsettings.php" -class pluginfile_filter_local_settings_form extends \core_filters\form\local_settings_form { - protected function definition_inner(\MoodleQuickForm $mform) { +class pluginfile_filter_local_settings_form extends \core_filters\form\local_settings_form +{ + protected function definition_inner(\MoodleQuickForm $mform) + { $mform->addElement( 'text', 'word', @@ -164,8 +167,10 @@ All the local configurations can be accessed in the main filter class in the `$t localconfig['word'] ?? 'default'; diff --git a/versioned_docs/version-5.1/apis/plugintypes/format/index.md b/versioned_docs/version-5.1/apis/plugintypes/format/index.md index 3778531ea..ac48c35a0 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/format/index.md +++ b/versioned_docs/version-5.1/apis/plugintypes/format/index.md @@ -531,8 +531,10 @@ In the example the extra output classes can look like: dirroot . '/mod/forum/lib.php'); @@ -803,9 +814,11 @@ This feature has been implemented by: ```php title="mod/resource/classes/output/courseformat/activitybadge.php" namespace mod_resource\output\courseformat; - class activitybadge extends \core_courseformat\output\activitybadge { + class activitybadge extends \core_courseformat\output\activitybadge + { - protected function update_content(): void { + protected function update_content(): void + { $options = (object) ['displayoptions' => $this->cminfo->customdata['displayoptions']]; $this->content = resource_get_optional_filetype($options, $this->cminfo); } diff --git a/versioned_docs/version-5.1/apis/plugintypes/mod/_files/lib_description.md b/versioned_docs/version-5.1/apis/plugintypes/mod/_files/lib_description.md index 6615a48be..667d074f2 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/mod/_files/lib_description.md +++ b/versioned_docs/version-5.1/apis/plugintypes/mod/_files/lib_description.md @@ -41,7 +41,8 @@ Each feature is identified by a constant, which is defined in the `lib
```php -function [modname]_supports($feature) { +function [modname]_supports($feature) +{ return match ($feature) { FEATURE_GROUPS => true, FEATURE_GROUPINGS => true, @@ -70,7 +71,8 @@ Optionally, if your plugin fits in a secondary purpose, you should add the `FEAT
```php -function [modname]_supports(string $feature) { +function [modname]_supports(string $feature) +{ return match ($feature) { // The rest of features should be listed here... FEATURE_MOD_PURPOSE => MOD_PURPOSE_COLLABORATION, diff --git a/versioned_docs/version-5.1/apis/plugintypes/mod/courseoverview.md b/versioned_docs/version-5.1/apis/plugintypes/mod/courseoverview.md index 9577a60f8..06ac10b83 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/mod/courseoverview.md +++ b/versioned_docs/version-5.1/apis/plugintypes/mod/courseoverview.md @@ -30,7 +30,8 @@ namespace mod_PLUGINNAME\courseformat; use core_courseformat\activityoverviewbase; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ // Implement methods here. } ``` @@ -65,9 +66,11 @@ use core_courseformat\activityoverviewbase; use core_courseformat\local\overview\overviewitem; use core\output\pix_icon; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ #[\Override] - public function get_extra_overview_items(): array { + public function get_extra_overview_items(): array + { return [ 'submitted' => $this->get_extra_submitted_overview(), ]; @@ -78,7 +81,8 @@ class overview extends activityoverviewbase { * * @return overviewitem|null */ - private function get_extra_submitted_overview(): ?overviewitem { + private function get_extra_submitted_overview(): ?overviewitem + { // Validate if the user needs this overview information. Return null otherwise. if (!has_capability('mod/PLUGINNAME:complete', $this->context)) { return null; @@ -137,9 +141,11 @@ namespace mod_PLUGINNAME\courseformat; use core_courseformat\activityoverviewbase; use core_courseformat\local\overview\overviewitem; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ #[\Override] - public function get_due_date_overview(): ?overviewitem { + public function get_due_date_overview(): ?overviewitem + { // Implement here how to get the due date of the activity. $duedate = DO_SOMETHING_TO_GET_YOUR_PLUGIN_DUE_DATE(); @@ -177,9 +183,11 @@ use core\output\action_link; use core\output\local\properties\button; use core\output\local\properties\text_align; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ #[\Override] - public function get_actions_overview(): ?overviewitem { + public function get_actions_overview(): ?overviewitem + { // Validate if the user can do the action. Return null otherwise. if (!has_capability('mod/PLUGINNAME:viewreports', $this->context)) { return null; @@ -229,7 +237,8 @@ This is an example of a plugin with two grade items: ```php #[\Override] -protected function get_grade_item_names(array $items): array { +protected function get_grade_item_names(array $items): array +{ // Add some fallback in case some grade item is missing. if (count($items) != 2) { return parent::get_grade_item_names($items); @@ -262,7 +271,8 @@ namespace mod_PLUGINNAME\courseformat; use core_course\activityoverviewbase; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ public function __construct( /** @var cm_info $cm the activity course module. */ cm_info $cm, diff --git a/versioned_docs/version-5.1/apis/plugintypes/mod/visibility.md b/versioned_docs/version-5.1/apis/plugintypes/mod/visibility.md index 182e57640..68efc3b24 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/mod/visibility.md +++ b/versioned_docs/version-5.1/apis/plugintypes/mod/visibility.md @@ -37,7 +37,8 @@ The course cache is only updated when somebody edits a module, so it can't be us The function should return a value of class `cached_cm_info`. For example: ```php -function mod_frog_get_coursemodule_info($cm) { +function mod_frog_get_coursemodule_info($cm) +{ $info = new cached_cm_info(); $info->content = '

This will display below the module.

'; return $info; @@ -62,7 +63,8 @@ Don't use renderers in this function (see MDL-41074). If you have data you would You can customise module display dynamically (when the page loads). For example you might want to alter it based on the permissions of the current user. ```php -function mod_frog_cm_info_dynamic(cm_info $cm) { +function mod_frog_cm_info_dynamic(cm_info $cm) +{ $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!has_capability('some/capability', $context)) { $cm->set_user_visible(false); @@ -81,7 +83,8 @@ Most things are set using functions (as above; another example would be `set_con Sometimes you need to display custom information for the current user that appears only on the course view page. For example, the forum module displays unread information on the view page. This information doesn't show on other pages (it isn't included in the navigation, for instance). ```php -function mod_frog_cm_info_view(cm_info $cm) { +function mod_frog_cm_info_view(cm_info $cm) +{ $cm->set_after_link('Last tadpole: 22:17'); } ``` @@ -106,7 +109,8 @@ $cm = $modinfo->get_cm($cmid); The cm_info objects contain additional information that is not present in the course_modules database row, such as the module's name, and the icon and associated content mentioned above. In order to distinguish these from the plain database objects, you can specify the cm_info class in a function definition: ```php -function my_clever_function(cm_info $cm) { +function my_clever_function(cm_info $cm) +{ if (!$cm->uservisible) { // The module is not visible or available to current user, // so do something clever instead. diff --git a/versioned_docs/version-5.1/apis/plugintypes/qbank/filters.md b/versioned_docs/version-5.1/apis/plugintypes/qbank/filters.md index 340c714e0..036341bdd 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/qbank/filters.md +++ b/versioned_docs/version-5.1/apis/plugintypes/qbank/filters.md @@ -37,7 +37,8 @@ namespace qbank_myplugin; use core_question\local\bank\condition; -class myfilter_condition extends condition { +class myfilter_condition extends condition +{ } ``` @@ -47,8 +48,10 @@ Modify your `plugin_feature` class to return an instance of your condition from ```php title="question/bank/myplugin/classes/plugin_feature.php" namespace qbank_myplugin; -class plugin_feature extends core_question\local\bank\plugin_features_base { - public function get_question_filters(?core_question\local\bank\view $qbank = null): array { +class plugin_feature extends core_question\local\bank\plugin_features_base +{ + public function get_question_filters(?core_question\local\bank\view $qbank = null): array + { return [ new myfilter_condition($qbank), ]; @@ -59,7 +62,8 @@ class plugin_feature extends core_question\local\bank\plugin_features_base { Back in your `condition` class, define the `get_name()` method, which returns the label displayed in the filter UI. ```php title="Define the condition name" -public function get_name(): string { +public function get_name(): string +{ return get_string('myfilter_name', 'myplugin'); } ``` @@ -67,7 +71,8 @@ public function get_name(): string { Define `get_condition_key()`, which returns a unique machine-readable ID for this filter condition, used when passing the filter as a parameter. ```php title="Define the condition key" -public function get_condition_key(): string { +public function get_condition_key(): string +{ return 'myfilter'; } ``` @@ -78,7 +83,8 @@ The `$filter` parameter receives an array with a `'values'` key, containing an a The conditions from each filter are combined with the query in [`core_question\local\bank\view::build_query()`](https://github.com/moodle/moodle/blob/c741492c38b9945abbfc7e90dfe8f943279f8265/question/classes/local/bank/view.php#L733) ```php title="Filter questions" -public function build_query_from_filter(array $filter): array { +public function build_query_from_filter(array $filter): array +{ $andor = ' AND '; $equal = '='; if ($filter['jointype'] === self::JOINTYPE_ANY) { @@ -109,7 +115,8 @@ Following this pattern with your own fields and options will give you a basic fu To define the list of possible filter values, define `get_initial_values()`, which returns an array of `['value', 'title']` for each option. These will then be searchable and selectable in the autocomplete field. ```php title="Define initial filter values" -public function get_initial_values(): string { +public function get_initial_values(): string +{ return [ [ 'value' => 0, @@ -128,7 +135,8 @@ public function get_initial_values(): string { To restrict the possible filter terms to only those returned from `get_initial_values()`, define `allow_custom()` and have it return `false`. ```php title="Disable custom terms" -public function allow_custom(): bool { +public function allow_custom(): bool +{ return false; } ``` @@ -138,7 +146,8 @@ public function allow_custom(): bool { Not all join types are relevant to all filters. If each question will only match one of the selected values, it does not make sense to allow `JOINTYPE_ALL`. Define `get_join_list()` and return an array of the applicable join types. ```php title="Define a restricted list of join types" -public function get_join_list(): array { +public function get_join_list(): array +{ return [ datafilter::JOINTYPE_ANY, datafilter::JOINTYPE_NONE, @@ -152,7 +161,8 @@ By default, conditions allow multiple values to be selected and use the selected If your condition should only allow a single value at a time, override `allow_multiple()` to return false. ```php title="Disable selection of multiple values" -public function allow_multiple(): bool { +public function allow_multiple(): bool +{ return false; } ``` @@ -162,7 +172,8 @@ public function allow_multiple(): bool { By default, conditions can be left empty, and therefore will not be included in the filter. To make it compulsory to select a value for this condition when it is added, override `allow_empty()` to return false. ```php title="Disable empty values" -public function allow_empty(): bool { +public function allow_empty(): bool +{ return false; } ``` @@ -172,7 +183,8 @@ public function allow_empty(): bool { If it is compulsory that your condition is always displayed, override `is_required()` to return true. ```php title="Make the condition compulsory" -public function is_required(): bool { +public function is_required(): bool +{ return true; } ``` @@ -188,7 +200,8 @@ You can either use a different core filter type from `/lib/amd/src/datafilter/fi To tell your filter condition to use a different filter class, override the `get_filter_class()` method to return the namespaced path to your JavaScript class. ```php title="Override the default filter class" -public function get_filter_class(): string { +public function get_filter_class(): string +{ return 'qbank_myplugin/datafilter/filtertype/myfilter'; } ``` diff --git a/versioned_docs/version-5.1/apis/plugintypes/qtype/newquestiondefaults.md b/versioned_docs/version-5.1/apis/plugintypes/qtype/newquestiondefaults.md index c34ce0a02..fb8d4be87 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/qtype/newquestiondefaults.md +++ b/versioned_docs/version-5.1/apis/plugintypes/qtype/newquestiondefaults.md @@ -41,7 +41,8 @@ $mform->setDefault('shuffleanswers', $this->get_default_value('shuffleanswers', Here we need to override the method `save_defaults_for_new_questions` to save the values these settings. For example: ```php - public function save_defaults_for_new_questions(stdClass $fromform): void { + public function save_defaults_for_new_questions(stdClass $fromform): void + { parent::save_defaults_for_new_questions($fromform); $this->set_default_value('shuffleanswers', $fromform->shuffleanswers); } diff --git a/versioned_docs/version-5.1/apis/plugintypes/qtype/restore.md b/versioned_docs/version-5.1/apis/plugintypes/qtype/restore.md index 845357130..ee30b631e 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/qtype/restore.md +++ b/versioned_docs/version-5.1/apis/plugintypes/qtype/restore.md @@ -83,7 +83,8 @@ an array of fields to remove from the `$questiondata` structure. For example, i records with the fields `id`, `questionid` and `data`, you might need to define the following: ```php title="question/type/example/backup/moodle2/restore_qtype_example_plugin.class.php" -protected function define_excluded_identity_hash_fields(): array { +protected function define_excluded_identity_hash_fields(): array +{ return [ '/options/extradata/id', '/options/extradata/questionid', @@ -102,7 +103,8 @@ additional data, then passes `$questiondata` on to the parent method. For exampl setting at `$questiondata->options->pluginconfig`, you might need to define the following: ```php title="question/type/example/backup/moodle2/restore_qtype_example_plugin.class.php" -public static function remove_excluded_question_data(stdClass $questiondata, array $excludefields = []): stdClass { +public static function remove_excluded_question_data(stdClass $questiondata, array $excludefields = []): stdClass +{ if (isset($questiondata->options->pluginconfig)) { unset($questiondata->options->pluginconfig); } diff --git a/versioned_docs/version-5.1/apis/plugintypes/repository/index.md b/versioned_docs/version-5.1/apis/plugintypes/repository/index.md index 0e940f7ab..c23a86a16 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/repository/index.md +++ b/versioned_docs/version-5.1/apis/plugintypes/repository/index.md @@ -122,7 +122,8 @@ Return any combination of the following values: ```php -function supported_returntypes() { +function supported_returntypes() +{ return FILE_INTERNAL | FILE_EXTERNAL | FILE_REFERENCE | FILE_CONTROLLED_LINK; } ``` @@ -151,7 +152,8 @@ Supported file types can be specified using standard mimetypes (such as `image/g ```php -function supported_filetypes() { +function supported_filetypes() +{ // Allow any kind of file. return '*'; } @@ -161,7 +163,8 @@ function supported_filetypes() { ```php -function supported_filetypes() { +function supported_filetypes() +{ // Example of image mimetypes. return ['image/gif', 'image/jpeg', 'image/png']; } @@ -171,7 +174,8 @@ function supported_filetypes() { ```php -function supported_filetypes() { +function supported_filetypes() +{ // Example of a file group. return ['web_image']; } @@ -204,7 +208,8 @@ Parent function returns an array with a single item - pluginname.
```php -public static function get_type_option_names() { +public static function get_type_option_names() +{ return array_merge(parent::get_type_option_names(), ['rootpath']); } ``` @@ -225,7 +230,8 @@ Optional. This is for modifying the Moodle form displaying the plugin settings. For example, to display the standard repository plugin settings along with the custom ones use: ```php -public static function type_config_form($mform, $classname='repository') { +public static function type_config_form($mform, $classname='repository') +{ parent::type_config_form($mform); $rootpath = get_config('repository_pluginname', 'rootpath'); @@ -244,7 +250,8 @@ This function must be declared static Optional. Use this function if you need to validate some variables submitted by plugin settings form. To use it, check through the associative array of data provided ('settingname' => value) for any errors. Then push the items to $error array in the format ("fieldname" => "human readable error message") to have them highlighted in the form. ```php -public static function type_form_validation($mform, $data, $errors) { +public static function type_form_validation($mform, $data, $errors) +{ if (!is_dir($data['rootpath'])) { $errors['rootpath'] = get_string('invalidrootpath', 'repository_pluginname'); } @@ -271,7 +278,8 @@ Parent function returns an empty array. This is equivalent to **get_type_option_
```php -public static function get_instance_option_names() { +public static function get_instance_option_names() +{ return ['fs_path']; // From repository_filesystem } ``` @@ -292,7 +300,8 @@ Optional. This is for modifying the Moodle form displaying the settings specific For example, to add a required text box called email_address: ```php -public static function get_instance_option_names() { +public static function get_instance_option_names() +{ $mform->addElement( 'text', 'email_address', @@ -318,7 +327,8 @@ This function must be declared static Optional. This allows us to validate what has been submitted in the instance configuration form. This is equivalent to ''type_form_validation($mform, $data, $errors), but for instances. For example: ```php -public static function instance_form_validation($mform, $data, $errors) { +public static function instance_form_validation($mform, $data, $errors) +{ if (empty($data['email_address'])) { $errors['email_address'] = get_string('invalidemailsettingname', 'repository_flickr_public'); } @@ -357,7 +367,8 @@ Firstly the skeleton: * * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ -class repository_flickr_public extends repository { +class repository_flickr_public extends repository +{ } ``` @@ -453,7 +464,8 @@ This function will return a list of files to be displayed to the user, the list * @param string $page * @return array the list of files, including meta information */ -public function get_listing($encodedpath = '', $page = '') { +public function get_listing($encodedpath = '', $page = '') +{ // This methods return [ //this will be used to build navigation bar. @@ -578,7 +590,8 @@ For plugins that do not fully process the login via a popup window, the submitte
```php title="lib/alfresco/lib.php" -public function __construct($repositoryid, $context = SYSCONTEXTID, $options = []) { +public function __construct($repositoryid, $context = SYSCONTEXTID, $options = []) +{ global $SESSION; /* Skipping code that is not relevant to user login */ @@ -618,7 +631,8 @@ Many types include a single element of type 'popup' with the param 'url' pointin
```php title="Code taken from repository_boxnet" -public function print_login() { +public function print_login() +{ $ticket = $this->boxclient->getTicket(); if ($this->options['ajax']) { $loginbtn = (object)[ @@ -652,7 +666,8 @@ This function will return a boolean value to tell Moodle whether the user has lo By default, this function will return true. ```php -public function check_login(): bool { +public function check_login(): bool +{ global $SESSION; return !empty($SESSION->{$this->sessname}); } @@ -663,7 +678,8 @@ public function check_login(): bool { When a user clicks the logout button in file picker, this function will be called. You may clean up the session or disconnect the connection with remote server here. After this the code should return something suitable to display to the user (usually the results of calling **$this->print_login()**): ```php title="lib/alfresco/lib.php" -public function logout() { +public function logout() +{ global $SESSION; unset($SESSION->{$this->sessname}); return $this->print_login(); @@ -689,7 +705,8 @@ For FILE_INTERNAL or FILE_REFERENCE this function is called at the point when th ```php -public function get_file($url, $filename = '') { +public function get_file($url, $filename = '') +{ // Default implementation from the base 'repository' class $path = $this->prepare_file($filename); // Generate a unique temporary filename $curlobject = new curl(); @@ -707,7 +724,8 @@ public function get_file($url, $filename = '') { Slightly extended version taken from repository_equella ```php -public function get_file($reference, $filename = '') { +public function get_file($reference, $filename = '') +{ global $USER; // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference->reference)); @@ -768,7 +786,8 @@ A custom search form must include the following:
```php title="The default implementation in class 'repository'" -public function print_search() { +public function print_search() +{ global $PAGE; $renderer = $PAGE->get_renderer('core', 'files'); return $renderer->repository_default_searchform(); @@ -793,7 +812,8 @@ The return should return an array containing:
```php title="Example from repoistory_googledocs" -public function search($search_text, $page = 0) { +public function search($search_text, $page = 0) +{ $gdocs = new google_docs($this->googleoauth); return [ 'dynload' => true, @@ -822,7 +842,8 @@ Note that external file is synchronised by moodle when UI wants to show the file Return minimum number of seconds before checking for changes to the file (default implementation = 1 day) ```php -public function get_reference_file_lifetime($ref) { +public function get_reference_file_lifetime($ref) +{ return DAYSECS; // One day, 60 * 60 * 24 seconds. } ``` @@ -832,7 +853,8 @@ public function get_reference_file_lifetime($ref) { Called after the file has reached the 'lifetime' specified above to see if it should now be synchronised (default implementation is to return true) ```php -public function sync_individual_file(stored_file $storedfile) { +public function sync_individual_file(stored_file $storedfile) +{ return true; } ``` @@ -851,7 +873,8 @@ This is usually prefixed with the repository name, and a semicolon. For example:
```php title="lib.php" -public function get_reference_details($reference, $filestatus = 0) { +public function get_reference_details($reference, $filestatus = 0) +{ if (!$filestatus) { // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference); @@ -879,7 +902,8 @@ Returns up-to-date information about the original file, only called when the 'li
```php title="/lib.php" -public function get_file_by_reference($reference) { +public function get_file_by_reference($reference) +{ global $USER; // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference->reference)); @@ -946,7 +970,8 @@ It is up to the repository developer to decide whether to actually download the
```php title="/lib.php" -public function send_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) { +public function send_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) +{ // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($stored_file->get_reference())); $url = $this->appendtoken($details->url); diff --git a/versioned_docs/version-5.1/apis/plugintypes/sms/index.md b/versioned_docs/version-5.1/apis/plugintypes/sms/index.md index 1e9235bff..8baec2ec7 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/sms/index.md +++ b/versioned_docs/version-5.1/apis/plugintypes/sms/index.md @@ -65,7 +65,8 @@ namespace smsgateway_aws; use smsgateway_aws\local\service\aws_sns; -class gateway extends \core_sms\gateway { +class gateway extends \core_sms\gateway +{ #[\Override] public function send( message $message, @@ -95,7 +96,8 @@ class gateway extends \core_sms\gateway { ); } - private function get_gateway_service(\stdClass $config): string { + private function get_gateway_service(\stdClass $config): string + { return match ($config->gateway) { 'aws_sns' => aws_sns::class, default => throw new moodle_exception("Unknown Message Handler {$config->gateway}"), @@ -103,7 +105,8 @@ class gateway extends \core_sms\gateway { } #[\Override] - public function get_send_priority(message $message): int { + public function get_send_priority(message $message): int + { return 50; } } @@ -120,7 +123,8 @@ It is necessary for plugins developers to assess these hooks and implement accor This hook will allow plugins to add required form fields to assist users in configuring their SMS gateway. ```php title="Listener method for after_sms_gateway_form_hook" -public static function set_form_definition_for_aws_sms_gateway(after_sms_gateway_form_hook $hook): void { +public static function set_form_definition_for_aws_sms_gateway(after_sms_gateway_form_hook $hook): void +{ if ($hook->plugin !== 'smsgateway_example') { return; } diff --git a/versioned_docs/version-5.1/apis/plugintypes/theme/index.md b/versioned_docs/version-5.1/apis/plugintypes/theme/index.md index 371b703c4..c3cd0b8b0 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/theme/index.md +++ b/versioned_docs/version-5.1/apis/plugintypes/theme/index.md @@ -108,7 +108,8 @@ $THEME->sheets = []; $THEME->editor_sheets = []; $THEME->editor_scss = ['editor']; $THEME->usefallback = true; -$THEME->scss = function($theme) { +$THEME->scss = function($theme) +{ return theme_boost_get_main_scss_content($theme); }; diff --git a/versioned_docs/version-5.1/apis/plugintypes/tiny/index.md b/versioned_docs/version-5.1/apis/plugintypes/tiny/index.md index 831f0cfef..38dbd3cbe 100644 --- a/versioned_docs/version-5.1/apis/plugintypes/tiny/index.md +++ b/versioned_docs/version-5.1/apis/plugintypes/tiny/index.md @@ -398,7 +398,8 @@ use context; use editor_tiny\plugin; use editor_tiny\plugin_with_configuration; -class plugininfo extends plugin implements plugin_with_configuration { +class plugininfo extends plugin implements plugin_with_configuration +{ public static function get_plugin_configuration_for_context( context $context, array $options, diff --git a/versioned_docs/version-5.1/apis/subsystems/access.md b/versioned_docs/version-5.1/apis/subsystems/access.md index 06ea7efeb..d0b39391d 100644 --- a/versioned_docs/version-5.1/apis/subsystems/access.md +++ b/versioned_docs/version-5.1/apis/subsystems/access.md @@ -167,7 +167,8 @@ By default checks the capabilities of the current user, but you can pass a diffe Function require_capability() is very similar, it is throwing access control exception if user does not have the capability. ```php -function require_capability($capability, context $context, $userid = null, $doanything = true, $errormessage = 'nopermissions', $stringfile = _) { +function require_capability($capability, context $context, $userid = null, $doanything = true, $errormessage = 'nopermissions', $stringfile = _) +{ ``` ### Enrolment functions {/* #enrolment-functions */} diff --git a/versioned_docs/version-5.1/apis/subsystems/ai/index.md b/versioned_docs/version-5.1/apis/subsystems/ai/index.md index 8f6f7a0cd..d2e63732e 100644 --- a/versioned_docs/version-5.1/apis/subsystems/ai/index.md +++ b/versioned_docs/version-5.1/apis/subsystems/ai/index.md @@ -162,7 +162,8 @@ public function __construct( ```php title="Example: The store() method for the generate_image Action" #[\Override] -public function store(response_base $response): int { +public function store(response_base $response): int +{ global $DB; $responsearr = $response->get_response_data(); @@ -225,7 +226,8 @@ it sets these against class variables so they can be retrieved by the Manager an ```php title="Example: The set_response_data() for the generate_image Action response" #[\Override] - public function set_response_data(array $response): void { + public function set_response_data(array $response): void + { $this->draftfile = $response['draftfile'] ?? null; $this->revisedprompt = $response['revisedprompt'] ?? null; $this->sourceurl = $response['sourceurl'] ?? null; @@ -238,7 +240,8 @@ Returns the set response data. ```php title="Example: The get_response_data() for the generate_image Action response" #[\Override] - public function get_response_data(): array { + public function get_response_data(): array + { return [ 'draftfile' => $this->draftfile, 'revisedprompt' => $this->revisedprompt, diff --git a/versioned_docs/version-5.1/apis/subsystems/analytics/index.md b/versioned_docs/version-5.1/apis/subsystems/analytics/index.md index 1f4c3e3e7..20b1eddc8 100644 --- a/versioned_docs/version-5.1/apis/subsystems/analytics/index.md +++ b/versioned_docs/version-5.1/apis/subsystems/analytics/index.md @@ -378,7 +378,8 @@ You can overwrite a `new one_sample_per_analysable()` method if the analysables * * @return bool */ -public static function one_sample_per_analysable() { +public static function one_sample_per_analysable() +{ return true; } ``` @@ -398,7 +399,8 @@ You can use `required_sample_data` to specify what your indicator needs to be ca * * @return null|string[] Name of the required elements (use the database tablename) */ -public static function required_sample_data() { +public static function required_sample_data() +{ return null; } ``` diff --git a/versioned_docs/version-5.1/apis/subsystems/backup/index.md b/versioned_docs/version-5.1/apis/subsystems/backup/index.md index 95245f909..10089ab62 100644 --- a/versioned_docs/version-5.1/apis/subsystems/backup/index.md +++ b/versioned_docs/version-5.1/apis/subsystems/backup/index.md @@ -95,9 +95,11 @@ Here is a minimalistic task: ```php require_once($CFG->dirroot . '/backup/moodle2/backup_tool_plugin.class.php'); -class backup_tool_foobar_plugin extends backup_tool_plugin { +class backup_tool_foobar_plugin extends backup_tool_plugin +{ - protected function define_course_plugin_structure() { + protected function define_course_plugin_structure() + { $this->step->log('Yay, backup!', backup::LOG_DEBUG); return $plugin; } diff --git a/versioned_docs/version-5.1/apis/subsystems/backup/restore.md b/versioned_docs/version-5.1/apis/subsystems/backup/restore.md index 16aca9f2a..cf5ee2123 100644 --- a/versioned_docs/version-5.1/apis/subsystems/backup/restore.md +++ b/versioned_docs/version-5.1/apis/subsystems/backup/restore.md @@ -41,9 +41,11 @@ Here is a minimalistic task: ```php require_once($CFG->dirroot . '/backup/moodle2/restore_tool_plugin.class.php'); -class restore_tool_foobar_plugin extends restore_tool_plugin { +class restore_tool_foobar_plugin extends restore_tool_plugin +{ - protected function define_course_plugin_structure() { + protected function define_course_plugin_structure() + { $paths = array(); $this->step->log('Yay, restore!', backup::LOG_DEBUG); return $paths; diff --git a/versioned_docs/version-5.1/apis/subsystems/check/index.md b/versioned_docs/version-5.1/apis/subsystems/check/index.md index 51b97ca38..5fbc14021 100644 --- a/versioned_docs/version-5.1/apis/subsystems/check/index.md +++ b/versioned_docs/version-5.1/apis/subsystems/check/index.md @@ -103,14 +103,17 @@ namespace mod_myplugin\check; use core\check\check; use core\check\result; -class foobar extends check { +class foobar extends check +{ - public function get_action_link(): ?\action_link { + public function get_action_link(): ?\action_link + { $url = new \moodle_url('/mod/myplugin/dosomething.php'); return new \action_link($url, get_string('sitepolicies', 'admin')); } - public function get_result(): result { + public function get_result(): result + { if (some_check()) { $status = result::ERROR; $summary = get_string('check_foobar_error', 'mod_myplugin'); @@ -145,7 +148,8 @@ Next decide on what type of check it should be which determines what report it w Implement the right callback in lib.php for the report you want to add it to, and return an array (usually with only 1 item) of check objects: ```php title="/mod/myplugin/lib.php" -function mod_myplugin_security_checks(): array { +function mod_myplugin_security_checks(): array +{ return [new \mod_myplugin\check\foobar()]; } ``` @@ -157,7 +161,8 @@ Checks have been designed to be dynamic so you can return different checks depen If you plan to return multiple instances of a check class, make sure that each instance has a unique id. ```php -function mod_myplugin_security_checks(): array { +function mod_myplugin_security_checks(): array +{ return [ new \mod_myplugin\check\foobar('one'), new \mod_myplugin\check\foobar('two'), @@ -170,14 +175,17 @@ Set the internal id in a way which is unique across all instances in your compon ```php namespace mod_myplugin\check; -class foobar extends \core\check\check { +class foobar extends \core\check\check +{ protected $id = ''; - public function __construct($id) { + public function __construct($id) + { $this->id = "foobar{$id}"; } - public function get_id(): string { + public function get_id(): string + { return $this->id; } ... @@ -197,17 +205,21 @@ Checks can provide details on a check, such as the complete list of bad records. namespace mod_myplugin\check; -class foobar extends \core\check\check { - public function get_result(): result { +class foobar extends \core\check\check +{ + public function get_result(): result + { return new foobar_result(); } } ``` ```php -class foobar_result extends \core\check\result { +class foobar_result extends \core\check\result +{ ... - public function get_details(): string { + public function get_details(): string + { // Do expensive lookups in here. } } diff --git a/versioned_docs/version-5.1/apis/subsystems/communication/index.md b/versioned_docs/version-5.1/apis/subsystems/communication/index.md index b1107afd4..36697cea8 100644 --- a/versioned_docs/version-5.1/apis/subsystems/communication/index.md +++ b/versioned_docs/version-5.1/apis/subsystems/communication/index.md @@ -291,8 +291,10 @@ This method accepts the following parameters: For example, we have a form where we want to have the communication settings, we can use the below code to add the form elements to the form. ```php -class configure_form extends \moodleform { - public function definition() { +class configure_form extends \moodleform +{ + public function definition() + { $mform = $this->_form; $communication = \core_communication\api::load_by_instance( context: $context, diff --git a/versioned_docs/version-5.1/apis/subsystems/external/files.md b/versioned_docs/version-5.1/apis/subsystems/external/files.md index 627d27648..4eb1fbf23 100644 --- a/versioned_docs/version-5.1/apis/subsystems/external/files.md +++ b/versioned_docs/version-5.1/apis/subsystems/external/files.md @@ -119,7 +119,8 @@ $forum->introfiles = external_util::get_area_files($context->id, 'mod_forum', 'i You can also use the `external_files` structure definition in combination with the method to return the most common file fields required by WS clients. ```php -public static function execute_returns(): external_multiple_structure { +public static function execute_returns(): external_multiple_structure +{ return new external_multiple_structure( new external_single_structure([ 'id' => new external_value(PARAM_INT, 'Forum id'), diff --git a/versioned_docs/version-5.1/apis/subsystems/external/functions.md b/versioned_docs/version-5.1/apis/subsystems/external/functions.md index 295a3cca0..617f40ba8 100644 --- a/versioned_docs/version-5.1/apis/subsystems/external/functions.md +++ b/versioned_docs/version-5.1/apis/subsystems/external/functions.md @@ -65,8 +65,10 @@ use core_external\external_multiple_structure; use core_external\external_single_structure; use core_external\external_value; -class create_groups extends \core_external\external_api { - public static function execute_parameters(): external_function_parameters { +class create_groups extends \core_external\external_api +{ + public static function execute_parameters(): external_function_parameters + { return new external_function_parameters([ 'groups' => new external_multiple_structure( new external_single_structure([ @@ -92,7 +94,8 @@ class create_groups extends \core_external\external_api { ]); } - public static function execute(array $groups): array { + public static function execute(array $groups): array + { // Validate all of the parameters. [ 'groups' => $groups, @@ -114,7 +117,8 @@ class create_groups extends \core_external\external_api { ]; } - public static function execute_returns(): external_single_structure { + public static function execute_returns(): external_single_structure + { return new external_single_structure([ 'groups' => new external_multiple_structure([ 'id' => new external_value(PARAM_INT, 'Id of the created user'), diff --git a/versioned_docs/version-5.1/apis/subsystems/external/security.md b/versioned_docs/version-5.1/apis/subsystems/external/security.md index b6c0cc685..2d9a721e3 100644 --- a/versioned_docs/version-5.1/apis/subsystems/external/security.md +++ b/versioned_docs/version-5.1/apis/subsystems/external/security.md @@ -22,7 +22,8 @@ To do so you should call the `validate_parameters()` function, passing in the re The `validate_parameters()` function is defined on the `\core_external\external_api` class, and can be called as follows: ```php title="local/groupmanager/classes/external/create_groups.php" -public static function execute(array $groups): array { +public static function execute(array $groups): array +{ [ 'groups' => $groups, ] = self::validate_parameters(self::execute_parameters(), [ @@ -45,7 +46,8 @@ If your function operates on multiple contexts (like a list of courses), you mus The `validate_context()` function is defined on the `\core_external\external_api` class, and can be called as follows: ```php title="local/groupmanager/classes/external/create_groups.php" -public static function execute(array $groups): array { +public static function execute(array $groups): array +{ // ... foreach ($groups as $group) { $coursecontext = \context_course::instance($group['courseid']); diff --git a/versioned_docs/version-5.1/apis/subsystems/external/testing.md b/versioned_docs/version-5.1/apis/subsystems/external/testing.md index 8277a6dc9..ab5acac24 100644 --- a/versioned_docs/version-5.1/apis/subsystems/external/testing.md +++ b/versioned_docs/version-5.1/apis/subsystems/external/testing.md @@ -57,14 +57,16 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/webservice/tests/helpers.php'); -class get_fruit_test extends externallib_advanced_testcase { +class get_fruit_test extends externallib_advanced_testcase +{ /** * Test the execute function when capabilities are present. * * @covers \mod_fruit\external\get_fruit::execute */ - public function test_capabilities(): void { + public function test_capabilities(): void + { $this->resetAfterTest(true); $course = $this->getDataGenerator()->create_course(); @@ -99,7 +101,8 @@ class get_fruit_test extends externallib_advanced_testcase { * * @covers \mod_fruit\external\get_fruit::execute */ - public function test_capabilities_missing(): void { + public function test_capabilities_missing(): void + { global $USER; $this->resetAfterTest(true); diff --git a/versioned_docs/version-5.1/apis/subsystems/external/writing-a-service.md b/versioned_docs/version-5.1/apis/subsystems/external/writing-a-service.md index ff27b17c1..87aa9a1a3 100644 --- a/versioned_docs/version-5.1/apis/subsystems/external/writing-a-service.md +++ b/versioned_docs/version-5.1/apis/subsystems/external/writing-a-service.md @@ -150,13 +150,15 @@ use core_external\external_multiple_structure; use core_external\external_single_structure; use core_external\external_value; -class create_groups extends \core_external\external_api { +class create_groups extends \core_external\external_api +{ /** * Returns description of method parameters * @return external_function_parameters */ - public static function execute_parameters() { + public static function execute_parameters() + { return new external_function_parameters([ 'groups' => new external_multiple_structure( new external_single_structure([ @@ -187,7 +189,8 @@ A web service function without parameters will have a parameter description func * Returns description of method parameters * @return external_function_parameters */ -public static function execute_parameters(): external_function_parameters { +public static function execute_parameters(): external_function_parameters +{ return new external_function_parameters([ // If this function had any parameters, they would be described here. // This example has no parameters, so the array is empty. @@ -208,7 +211,8 @@ Our `create_groups()` function expects one parameter named `groups`, so we will * Returns description of method parameters * @return external_function_parameters */ -public static function execute_parameters(): external_function_parameters { +public static function execute_parameters(): external_function_parameters +{ return new external_function_parameters([ 'groups' => ... ]); @@ -280,7 +284,8 @@ We add them to the description : It's similar to execute_parameters(), but instead of describing the parameters, it describes the return values. ```php -public static function execute_returns() { +public static function execute_returns() +{ return new external_multiple_structure( new external_single_structure([ 'id' => new external_value(PARAM_INT, 'group record id'), @@ -312,7 +317,8 @@ Because some web service protocols are strict about the number and types of argu ```php -public static function get_biscuit_parameters() { +public static function get_biscuit_parameters() +{ return new external_function_parameters([ 'chocolatechips' => new external_value( PARAM_BOOL, @@ -340,7 +346,8 @@ public static function get_biscuit_parameters() { ```php -public static function get_biscuit_parameters() { +public static function get_biscuit_parameters() +{ return new external_function_parameters([ 'ifeellike' => new external_single_structure([ 'chocolatechips' => new external_value( @@ -379,7 +386,8 @@ We declared our web service function and we defined the external function parame * @param array $groups array of group description arrays (with keys groupname and courseid) * @return array of newly created groups */ - public static function execute($groups) { + public static function execute($groups) + { global $CFG, $DB; require_once("$CFG->dirroot/group/lib.php"); @@ -471,7 +479,8 @@ External functions deprecation process is slightly different from the standard d * Mark the function as deprecated. * @return bool */ - public static function execute_is_deprecated() { + public static function execute_is_deprecated() + { return true; } ``` diff --git a/versioned_docs/version-5.1/apis/subsystems/files/browsing.md b/versioned_docs/version-5.1/apis/subsystems/files/browsing.md index ca758d27a..ba98c974f 100644 --- a/versioned_docs/version-5.1/apis/subsystems/files/browsing.md +++ b/versioned_docs/version-5.1/apis/subsystems/files/browsing.md @@ -12,7 +12,8 @@ The File Browser API is a supplemental API which can be used to fetch informatio This example demonstrates using the `filebrowser` API to fetch the parent folders of a file. ```php -public function get_file_breadcrumbs(\stored_file $file): ?array { +public function get_file_breadcrumbs(\stored_file $file): ?array +{ $browser = get_file_browser(); $context = get_system_context(); diff --git a/versioned_docs/version-5.1/apis/subsystems/form/advanced/checkbox-controller.md b/versioned_docs/version-5.1/apis/subsystems/form/advanced/checkbox-controller.md index 2a212175e..3f7c3961a 100644 --- a/versioned_docs/version-5.1/apis/subsystems/form/advanced/checkbox-controller.md +++ b/versioned_docs/version-5.1/apis/subsystems/form/advanced/checkbox-controller.md @@ -16,7 +16,8 @@ You can add as many groups of checkboxes as you like, as long as they are unique When adding checkboxes, you can add them in _groups_. Each group of checkboxes must have a unique integer name, for example: ```php title="classes/form/example_form.php" -public function definition(): void { +public function definition(): void +{ // These two elements are part of group 1. $mform->addElement('advcheckbox', 'test1', 'Test 1', null, ['group' => 1]); $mform->addElement('advcheckbox', 'test2', 'Test 2', null, ['group' => 1]); diff --git a/versioned_docs/version-5.1/apis/subsystems/form/index.md b/versioned_docs/version-5.1/apis/subsystems/form/index.md index 065b76e6a..6a57843ec 100644 --- a/versioned_docs/version-5.1/apis/subsystems/form/index.md +++ b/versioned_docs/version-5.1/apis/subsystems/form/index.md @@ -41,9 +41,11 @@ namespace [plugintype]_[pluginname]\form; // moodleform is defined in formslib.php require_once("$CFG->libdir/formslib.php"); -class simplehtml_form extends \moodleform { +class simplehtml_form extends \moodleform +{ // Add elements to form. - public function definition() { + public function definition() + { // A reference to the form is stored in $this->form. // A common convention is to store it in a variable, such as `$mform`. $mform = $this->_form; // Don't forget the underscore! @@ -59,7 +61,8 @@ class simplehtml_form extends \moodleform { } // Custom validation should be added here. - function validation($data, $files) { + function validation($data, $files) + { return []; } } @@ -99,12 +102,15 @@ If you wish to use the form within a block then you should consider using the re Note that the render method does the same as the display method, except returning the HTML rather than outputting it to the browser, as with above make sure you've included the file which contains the class for your Moodle form. ```php -class block_yourblock extends block_base { - public function init(){ +class block_yourblock extends block_base +{ + public function init() + { $this->title = 'Your Block'; } - public function get_content(){ + public function get_content() + { $this->content = (object) [ 'text' => '', ]; @@ -237,7 +243,8 @@ public function add_action_buttons( The `add_action_buttons` function is defined on the `moodleform` class, and not a part of `$this->_form`, for example: ```php - public function definition() { + public function definition() + { // Add your form elements here. $this->_form->addElement(...); @@ -296,7 +303,8 @@ In some cases this is not the desired behaviour, in which case the [disable_form For example: ```php -public function definition() { +public function definition() +{ // Your definition goes here. // Disable the form change checker for this form. @@ -313,7 +321,8 @@ Only header names would be accepted and added to `_shownonlyelements` array. Headers included in `_shownonlyelements` will be shown expanded in the form. The rest of the headers will be hidden. ```php -public function filter_shown_headers(array $shownonly): void { +public function filter_shown_headers(array $shownonly): void +{ $this->_shownonlyelements = []; if (empty($shownonly)) { return; diff --git a/versioned_docs/version-5.1/apis/subsystems/form/usage/index.md b/versioned_docs/version-5.1/apis/subsystems/form/usage/index.md index 0369cddb1..f1fc7de14 100644 --- a/versioned_docs/version-5.1/apis/subsystems/form/usage/index.md +++ b/versioned_docs/version-5.1/apis/subsystems/form/usage/index.md @@ -79,7 +79,8 @@ In most cases you can place this in an auto-loadable class, in which case it sho namespace mod_forum\form; -class myform extends \moodleform { +class myform extends \moodleform +{ // ... } ``` @@ -127,8 +128,10 @@ Moodle has a set of standard form elements used by all Activity modules. These a The `standard_coursemodule_elements()` function is used to add these common elements, and it should be called _before_ the standard action elements are added, for example: ```php -class mod_example_mod_form extends \moodleform_mod { - public function definition() { +class mod_example_mod_form extends \moodleform_mod +{ + public function definition() + { // Add the various form elements. $this->_form->addElement( ... ); diff --git a/versioned_docs/version-5.1/apis/subsystems/output/index.md b/versioned_docs/version-5.1/apis/subsystems/output/index.md index af2615519..acd8b8fb2 100644 --- a/versioned_docs/version-5.1/apis/subsystems/output/index.md +++ b/versioned_docs/version-5.1/apis/subsystems/output/index.md @@ -115,20 +115,23 @@ In the example above, we used `$PAGE->get_renderer('tool_demo')` to get an insta Instead, you can use the `core\output\renderer_helper` class to get any renderer instance without using the global. This is an example of how to use the `renderer_helper` class to get a renderer instance: ```php -class my_di_example { +class my_di_example +{ public function __construct( /** @var \core\output\renderer_helper $rendererhelper the renderer helper */ protected readonly \core\output\renderer_helper $rendererhelper, ) { } - public function do_something_with_my_renderer() { + public function do_something_with_my_renderer() + { /** @var \tool_demo\output\renderer $renderer */ $renderer = $this->rendererhelper->get_renderer('tool_demo'); // Do something with the renderer. } - public function do_something_with_core_renderer() { + public function do_something_with_core_renderer() + { // For convenience, the renderer helper also provides a method to get the core renderer. $renderer = $this->rendererhelper->get_core_renderer(); // Do something with the core renderer. @@ -157,11 +160,13 @@ use renderer_base; use templatable; use stdClass; -class index_page implements renderable, templatable { +class index_page implements renderable, templatable +{ /** @var string $sometext Some text to show how to pass data to a template. */ private $sometext = null; - public function __construct($sometext): void { + public function __construct($sometext): void + { $this->sometext = $sometext; } @@ -170,7 +175,8 @@ class index_page implements renderable, templatable { * * @return stdClass */ - public function export_for_template(renderer_base $output): stdClass { + public function export_for_template(renderer_base $output): stdClass + { $data = new stdClass(); $data->sometext = $this->sometext; return $data; @@ -193,7 +199,8 @@ If you wish to use a specific template to render the content you may specify any * * @return string */ - public function get_template_name(\renderer_base $renderer): string { + public function get_template_name(\renderer_base $renderer): string + { return 'tool_demo/index_page'; } ``` @@ -208,7 +215,8 @@ namespace tool_demo\output; use plugin_renderer_base; -class renderer extends plugin_renderer_base { +class renderer extends plugin_renderer_base +{ /** * Defer to template. * @@ -216,7 +224,8 @@ class renderer extends plugin_renderer_base { * * @return string html for the page */ - public function render_index_page($page): string { + public function render_index_page($page): string + { $data = $page->export_for_template($this); return parent::render_from_template('tool_demo/index_page', $data); } @@ -474,11 +483,13 @@ mtrace('DONE'); Or a scheduled or adhoc task, via a trait. Example: ```php -class stored_progress_scheduled_task_example extends \core\task\scheduled_task { +class stored_progress_scheduled_task_example extends \core\task\scheduled_task +{ use \core\task\stored_progress_task_trait; - public function execute() { + public function execute() + { // This simulates a specific count of iterations the task will do, e.g. x number of courses to loop through and do something. $iterations = 100; @@ -537,7 +548,8 @@ use core_courseformat\base as course_format; use mod_MYPLUGIN\external\myname_exporter; use stdClass; -class myname implements externable, named_templatable, renderable { +class myname implements externable, named_templatable, renderable +{ public function __construct( /** @var cm_info The course module. */ public cm_info $cm, @@ -545,7 +557,8 @@ class myname implements externable, named_templatable, renderable { } #[\Override] - public function export_for_template(renderer_base $output): stdClass { + public function export_for_template(renderer_base $output): stdClass + { // This method is used to prepare data for rendering in a template. // It is related to the `templatable` interface and could return an object or array. $cm = $this->cm; @@ -562,14 +575,16 @@ class myname implements externable, named_templatable, renderable { } #[\Override] - public function get_template_name(renderer_base $renderer): string { + public function get_template_name(renderer_base $renderer): string + { // This method is used to specify the template name for rendering. // It is not used for webservice clients, but it is required by the named_templatable interface. return 'core_courseformat/local/overview/activityname'; } #[\Override] - public function get_exporter(?\core\context $context = null): myname_exporter { + public function get_exporter(?\core\context $context = null): myname_exporter + { $context = $context ?? \core\context\system::instance(); return new myname_exporter($this, ['context' => $context]); } @@ -583,7 +598,8 @@ class myname implements externable, named_templatable, renderable { } #[\Override] - public static function read_properties_definition(): array { + public static function read_properties_definition(): array + { return myname_exporter::read_properties_definition(); } @@ -614,7 +630,8 @@ namespace mod_MYPLUGIN\external; use core\external\exporter; use mod_MYPLUGIN\output\myname; -class myname_exporter extends exporter { +class myname_exporter extends exporter +{ /** * Constructor with parameter type hints. * @@ -629,12 +646,14 @@ class myname_exporter extends exporter { } #[\Override] - protected static function define_properties(): array { + protected static function define_properties(): array + { return []; } #[\Override] - protected static function define_related() { + protected static function define_related() + { // Most exporter need to define the context as related data to parse texts. return [ 'context' => 'context', @@ -642,7 +661,8 @@ class myname_exporter extends exporter { } #[\Override] - protected static function define_other_properties() { + protected static function define_other_properties() + { return [ 'activityname' => [ 'type' => PARAM_TEXT, @@ -663,7 +683,8 @@ class myname_exporter extends exporter { } #[\Override] - protected function get_other_values(\renderer_base $output) { + protected function get_other_values(\renderer_base $output) + { /** @var \cm_info $cm */ $cm = $this->data->cm; @@ -694,14 +715,17 @@ use core\output\renderer_helper; use mod_MYPLUGIN\output\myname; use stdClass; -class get_my_name extends external_api { - public static function execute_parameters(): external_function_parameters { +class get_my_name extends external_api +{ + public static function execute_parameters(): external_function_parameters + { return new external_function_parameters([ 'cmid' => new external_value(PARAM_INT, 'Course module id', VALUE_REQUIRED), ]); } - public static function execute(int $cmid): stdClass { + public static function execute(int $cmid): stdClass + { [ 'cmid' => $cmid, ] = external_api::validate_parameters(self::execute_parameters(), [ @@ -727,7 +751,8 @@ class get_my_name extends external_api { * * @return external_single_structure */ - public static function execute_returns(): external_single_structure { + public static function execute_returns(): external_single_structure + { return myname::get_read_structure(); } } diff --git a/versioned_docs/version-5.1/apis/subsystems/output/inplace.md b/versioned_docs/version-5.1/apis/subsystems/output/inplace.md index fa1bfdf99..dc7f5c5f0 100644 --- a/versioned_docs/version-5.1/apis/subsystems/output/inplace.md +++ b/versioned_docs/version-5.1/apis/subsystems/output/inplace.md @@ -17,7 +17,8 @@ The best way is to explain the usage on a simple example. Imagine we have plugin Define a callback in `/admin/tool/mytest/lib.php` that starts with the plugin name and ends with `_inplace_editable`: ```php title="admin/tool/mytest/lib.php" -function tool_mytest_inplace_editable($itemtype, $itemid, $newvalue) { +function tool_mytest_inplace_editable($itemtype, $itemid, $newvalue) +{ global $DB; if ($itemtype === 'mytestname') { @@ -80,13 +81,15 @@ This was a very simplified example, in the real life you will probably want to: ```php title="admin/tool/mytest/classes/local/inplace_edit_text.php" -class inplace_edit_text extends \core\output\inplace_editable { +class inplace_edit_text extends \core\output\inplace_editable +{ /** * Constructor. * * @param object $record */ - public function __construct($record) { + public function __construct($record) + { parent::__construct( component: 'tool_mytest', // The item type as managed your plugin. @@ -119,7 +122,8 @@ class inplace_edit_text extends \core\output\inplace_editable { * @param mixed $newvalue * @return \self */ - public static function update($itemid, $newvalue) { + public static function update($itemid, $newvalue) + { // Clean the new value. $newvalue = clean_param($newvalue, PARAM_INT); @@ -194,13 +198,15 @@ $tmpl->set_type_toggle([0, 1]);
```php title="admin/tool/mytest/classes/local/inplace_edit_select.php" -class inplace_edit_select extends \core\output\inplace_editable { +class inplace_edit_select extends \core\output\inplace_editable +{ /** * Constructor. * * @param \stdClass $record */ - public function __construct($record) { + public function __construct($record) + { // Get the options for inplace_edit select box. // The array needs the format: // $options = [ @@ -241,7 +247,8 @@ class inplace_edit_select extends \core\output\inplace_editable { * @param mixed $newvalue * @return \self */ - public static function update($itemid, $newvalue) { + public static function update($itemid, $newvalue) + { // Clean the new value. $newvalue = clean_param($newvalue, PARAM_INT); diff --git a/versioned_docs/version-5.1/apis/subsystems/privacy/index.md b/versioned_docs/version-5.1/apis/subsystems/privacy/index.md index 83e341479..35c99c1b4 100644 --- a/versioned_docs/version-5.1/apis/subsystems/privacy/index.md +++ b/versioned_docs/version-5.1/apis/subsystems/privacy/index.md @@ -119,7 +119,8 @@ class provider implements * * @return string */ - public static function get_reason(): string { + public static function get_reason(): string + { return 'privacy:metadata'; } } @@ -179,7 +180,8 @@ class provider implements // This plugin does store personal user data. \core_privacy\local\metadata\provider { - public static function get_metadata(collection $collection): collection { + public static function get_metadata(collection $collection): collection + { // Here you will add more items into the collection. @@ -214,7 +216,8 @@ Some subsystems which store user data do not need to be listed: ##### Example {/* #example-2 */} ```php title="mod/forum/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_subsystem_link( 'core_files', @@ -243,7 +246,8 @@ It is a matter of judgement which fields contain user data and which don't. Anyt ##### Example {/* #example-3 */} ```php title="mod/forum/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_database_table( 'forum_discussion_subs', @@ -291,7 +295,8 @@ Any plugin providing user preferences must also implement the `\core_privacy\loc ##### Example {/* #example-4 */} ```php title="admin/tool/usertours/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_user_preference('tool_usertours_tour_completion_time', 'privacy:metadata:preference:tool_usertours_tour_completion_time'); @@ -318,7 +323,8 @@ You can indicate this by calling the `add_external_location_link()` method on th ##### Example {/* #example-5 */} ```php title="mod/lti/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_external_location_link('lti_client', [ 'userid' => 'privacy:metadata:lti_client:userid', 'fullname' => 'privacy:metadata:lti_client:fullname', @@ -385,15 +391,16 @@ if (interface_exists('\core_privacy\local\request\userlist')) { } -class provider implements my_userlist { +class provider implements my_userlist +{ /** * Get the list of users who have data within a context. * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ - public static function get_users_in_context(userlist $userlist) { - + public static function get_users_in_context(userlist $userlist) + { } /** @@ -401,8 +408,8 @@ class provider implements my_userlist { * * @param approved_userlist $userlist The approved context and user information to delete information for. */ - public static function delete_data_for_users(approved_userlist $userlist) { - + public static function delete_data_for_users(approved_userlist $userlist) + { } } @@ -421,7 +428,9 @@ Contexts are retrieved using the `get_contexts_for_userid` function which takes * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist {} +public static function get_contexts_for_userid(int $userid): contextlist +{ +} ``` The function returns a `\core_privacy\local\request\contextlist` which is used to keep a set of contexts together in a fixed fashion. @@ -443,7 +452,8 @@ The following example simply fetches the contextid for all forums where a user h * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist { +public static function get_contexts_for_userid(int $userid): contextlist +{ $contextlist = new \core_privacy\local\request\contextlist(); $sql = "SELECT c.id @@ -490,7 +500,8 @@ In the case of the rating data, this will include any post where the user has ra * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist { +public static function get_contexts_for_userid(int $userid): contextlist +{ $ratingsql = \core_rating\privacy\provider::get_sql_join('rat', 'mod_forum', 'post', 'p.id', $userid); // Fetch all forum discussions, and forum posts. $sql = "SELECT c.id @@ -555,7 +566,9 @@ This method is very similar to the `get_contexts_for_userid` function but has so * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ -public static function get_users_in_context(userlist $userlist) {} +public static function get_users_in_context(userlist $userlist) +{ +} ``` ###### Basic example {/* #basic-example-1 */} @@ -568,8 +581,8 @@ The following example simply fetches the userid for all users in a given forum c * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ -public static function get_users_in_context(userlist $userlist) { - +public static function get_users_in_context(userlist $userlist) +{ $context = $userlist->get_context(); if (!$context instanceof \context_module) { @@ -616,7 +629,9 @@ This is achieved through use of the `export_user_data` function which takes the * * @param approved_contextlist $contextlist The approved contexts to export information for. */ -public static function export_user_data(approved_contextlist $contextlist) {} +public static function export_user_data(approved_contextlist $contextlist) +{ +} ``` The `approved_contextlist` includes both the user record, and a list of contexts, which can be retrieved by either processing it as an Iterator, or by calling `get_contextids()` or `get_contexts()` as required. @@ -642,7 +657,8 @@ You need to provide a description of the value of the user preference. (This des * * @param int $userid The userid of the user whose data is to be exported. */ -public static function export_user_preferences(int $userid) { +public static function export_user_preferences(int $userid) +{ $markasreadonnotification = get_user_preferences('markasreadonnotification', null, $userid); if (null !== $markasreadonnotification) { switch ($markasreadonnotification) { @@ -829,7 +845,8 @@ When expiring content for a high-level context such as a course context, the fun * * @param context $context Context to delete data from. */ -public static function delete_data_for_all_users_in_context(\context $context) { +public static function delete_data_for_all_users_in_context(\context $context) +{ global $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -850,7 +867,8 @@ public static function delete_data_for_all_users_in_context(\context $context) { An *approved_contextlist* is given and user data related to that user should either be completely deleted, or overwritten if a structure needs to be maintained. This will be called when a user has requested the right to be forgotten. All attempts should be made to delete this data where practical while still allowing the plugin to be used by other users. ```php title="mod/choice/classes/privacy/provider.php" -public static function delete_data_for_user(approved_contextlist $contextlist) { +public static function delete_data_for_user(approved_contextlist $contextlist) +{ global $DB; if (empty($contextlist->count())) { @@ -874,7 +892,8 @@ An *approved_userlist* is given and user data related to all users in the specif * * @param approved_userlist $userlist The approved context and user information to delete information for. */ -public static function delete_data_for_users(approved_userlist $userlist) { +public static function delete_data_for_users(approved_userlist $userlist) +{ global $DB; $context = $userlist->get_context(); @@ -915,7 +934,8 @@ class provider implements use \core_privacy\local\legacy_polyfill; // The required methods must be in this format starting with an underscore. - public static function _get_metadata(collection $collection) { + public static function _get_metadata(collection $collection) + { // Code for returning metadata goes here. } ``` @@ -943,12 +963,14 @@ class provider implements use \core_plagiarism\privacy\plagiarism_provider\legacy_polyfill; // The required methods must be in this format starting with an underscore. - public static function _get_metadata(collection $collection) { + public static function _get_metadata(collection $collection) + { // Code for returning metadata goes here. } // This is one of the polyfilled methods from the plagiarism provider. - public static function _export_plagiarism_user_data($userid, \context $context, array $subcontext, array $linkarray) { + public static function _export_plagiarism_user_data($userid, \context $context, array $subcontext, array $linkarray) + { // ... } ``` @@ -969,7 +991,8 @@ if (interface_exists('\core_privacy\local\request\core_userlist_provider')) { interface core_userlist_provider {} } -class provider implements core_userlist_provider { +class provider implements core_userlist_provider +{ ``` ## Tips for development {/* #tips-for-development */} diff --git a/versioned_docs/version-5.1/apis/subsystems/privacy/utils.md b/versioned_docs/version-5.1/apis/subsystems/privacy/utils.md index fdbcfb74f..c47c10086 100644 --- a/versioned_docs/version-5.1/apis/subsystems/privacy/utils.md +++ b/versioned_docs/version-5.1/apis/subsystems/privacy/utils.md @@ -108,7 +108,8 @@ foreach ($list->good as $component) { echo "\n\n== Done ==\n"; -function check_implements($component, $interface) { +function check_implements($component, $interface) +{ $manager = new \core_privacy\manager(); $rc = new \ReflectionClass(\core_privacy\manager::class); $rcm = $rc->getMethod('component_implements'); diff --git a/versioned_docs/version-5.1/apis/subsystems/routing/index.md b/versioned_docs/version-5.1/apis/subsystems/routing/index.md index 38b150921..bce11a503 100644 --- a/versioned_docs/version-5.1/apis/subsystems/routing/index.md +++ b/versioned_docs/version-5.1/apis/subsystems/routing/index.md @@ -54,7 +54,8 @@ use core\router\schema\response\payload_response; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -class example { +class example +{ #[\core\router\route( // Resolves to https://example.com/moodle/api/rest/v2/mod_example/example path: '/example', diff --git a/versioned_docs/version-5.1/apis/subsystems/routing/parameters.md b/versioned_docs/version-5.1/apis/subsystems/routing/parameters.md index 75474757b..b57c1a944 100644 --- a/versioned_docs/version-5.1/apis/subsystems/routing/parameters.md +++ b/versioned_docs/version-5.1/apis/subsystems/routing/parameters.md @@ -36,7 +36,8 @@ use core\param; use core\router\route; use core\router\schema\parameters\path_parameter; -class example { +class example +{ #[route( path: '/users/{username}', pathtypes: [ @@ -70,7 +71,8 @@ use core\param; use core\router\route; use core\router\schema\parameters\path_parameter; -class example { +class example +{ #[route( path: '/users/{username}', pathtypes: [ @@ -533,7 +535,8 @@ class path_course extends \core\router\schema\parameters\path_parameter implemen * @return object * @throws not_found_exception If the course cannot be found */ - protected function get_course_for_value(string $value): mixed { + protected function get_course_for_value(string $value): mixed + { global $DB; $data = false; @@ -572,7 +575,8 @@ class path_course extends \core\router\schema\parameters\path_parameter implemen } #[\Override] - public function get_schema_from_type(param $type): \stdClass { + public function get_schema_from_type(param $type): \stdClass + { $schema = parent::get_schema_from_type($type); $schema->pattern = "^("; diff --git a/versioned_docs/version-5.1/apis/subsystems/routing/responses.md b/versioned_docs/version-5.1/apis/subsystems/routing/responses.md index 64f7c8f50..6118fd23e 100644 --- a/versioned_docs/version-5.1/apis/subsystems/routing/responses.md +++ b/versioned_docs/version-5.1/apis/subsystems/routing/responses.md @@ -49,7 +49,8 @@ use core\router\schema\response\payload_response; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -class example { +class example +{ #[\core\router\route( // Resolves to https://example.com/moodle/api/rest/v2/mod_example/example path: '/example', diff --git a/versioned_docs/version-5.1/apis/subsystems/routing/shortlinks.md b/versioned_docs/version-5.1/apis/subsystems/routing/shortlinks.md index bd90f632c..af7202bad 100644 --- a/versioned_docs/version-5.1/apis/subsystems/routing/shortlinks.md +++ b/versioned_docs/version-5.1/apis/subsystems/routing/shortlinks.md @@ -76,9 +76,11 @@ Each component using shortlinks will need to have a `shortlink_handler` class. T - `process_shortlink()` ```php -class shortlink_handler implements shortlink_handler_interface { +class shortlink_handler implements shortlink_handler_interface +{ #[\Override] - public function get_valid_linktypes(): array { + public function get_valid_linktypes(): array + { return [ 'view', ]; diff --git a/versioned_docs/version-5.1/apis/subsystems/routing/testing.md b/versioned_docs/version-5.1/apis/subsystems/routing/testing.md index 89cb26326..4e9dbe676 100644 --- a/versioned_docs/version-5.1/apis/subsystems/routing/testing.md +++ b/versioned_docs/version-5.1/apis/subsystems/routing/testing.md @@ -22,8 +22,10 @@ You can quickly and easily create a copy of the Moodle Router using the `route_t This is a fully-configured copy of the Moodle Router, and allows to handle requests directly. ```php -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $router = $this->get_router(); } } @@ -56,8 +58,10 @@ You can easily add existing routes to mocking route loader either individually, To add an individual route, you can use the `\route_testcase::add_route_to_route_loader()` method, for example: ```php title="Adding a single route to the route loader" -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $this->add_route_to_route_loader( my_route::class, 'my_route_method', @@ -71,8 +75,10 @@ final class my_test extends \route_testcase { You can also add all routes in a class to the route loader using the `\route_testcase::add_class_routes_to_route_loader()` method, for example: ```php title="Adding all routes in a class to the route loader" -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $this->add_class_routes_to_route_loader( my_route::class, ); @@ -90,7 +96,8 @@ The `\route_testcase` also includes several methods to simplify generating a Req You can create a request and manually pass it to Router using the `\route_testcase::create_request()` method, for example: ```php title="Creating an example request and processing it" -public function test_example(): void { +public function test_example(): void +{ $this->add_class_routes_to_route_loader( my_route::class, ); @@ -114,7 +121,8 @@ When creating a request the default is to use the Route Group for the REST API, The `\route_testcase::process_request()` and `\route_testcsae::process_api_request()` methods act as a shortcut for creating the request, fetching the router, and the app, and handling the request to return a response. The above example can therefore be simplified to: ```php title="Creating and processing an example request" -public function test_example(): void { +public function test_example(): void +{ $this->add_class_routes_to_route_loader( my_route::class, ); diff --git a/versioned_docs/version-5.1/apis/subsystems/tag/index.md b/versioned_docs/version-5.1/apis/subsystems/tag/index.md index a847586f5..6b5a97652 100644 --- a/versioned_docs/version-5.1/apis/subsystems/tag/index.md +++ b/versioned_docs/version-5.1/apis/subsystems/tag/index.md @@ -151,7 +151,8 @@ If you have created a course activity that uses tags you should also remember to * * @param moodleform $mform */ -function book_reset_course_form_definition(&$mform) { +function book_reset_course_form_definition(&$mform) +{ $mform->addElement('header', 'bookheader', get_string('modulenameplural', 'book')); $mform->addElement('checkbox', 'reset_book_tags', get_string('removeallbooktags', 'book')); } @@ -161,7 +162,8 @@ function book_reset_course_form_definition(&$mform) { * @param $data the data submitted from the reset course. * @return array status array */ -function book_reset_userdata($data) { +function book_reset_userdata($data) +{ global $DB; $status = []; @@ -207,7 +209,8 @@ When you tag contents inside the course the plugin has to hook into backup and r You can choose to backup and restore tags for each item individually (as it is done in mod_wiki) OR backup all tags in the context at once (as it is done in mod_glossary or mod_forum). Second option is preferable for performance reasons. Make sure to take into account `$userinfo` (whether user information is backed up / restored), for example wiki pages is not user information but glossary entries are, tags on them follow the same rule. ```php title="mod/glossary/backup_glossary_stepslib.php" -protected function define_structure() { +protected function define_structure() +{ // ... $tags = new backup_nested_element('entriestags'); $tag = new backup_nested_element('tag', ['id'], ['itemid', 'rawname']); @@ -232,7 +235,8 @@ protected function define_structure() { ``` ```php title="mod/glossary/restore_glossary_stepslib.php" -protected function define_structure() { +protected function define_structure() +{ // ... if ($userinfo) { $paths[] = new restore_path_element('glossary_entry_tag', '/activity/glossary/entriestags/tag'); @@ -240,7 +244,8 @@ protected function define_structure() { // ... } -protected function process_glossary_entry_tag($data) { +protected function process_glossary_entry_tag($data) +{ $data = (object)$data; if (!core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) { // Tags disabled on this site, nothing to process. @@ -265,7 +270,8 @@ Given a user searches for any items tagged with a specified tag, only the items To limit the performance impact of checking user access against items the following class ``core_tag_index_builder()`` can assist with the retrieval and caching of records, especially within both course and activity modules. ```php -function mod_wiki_get_tagged_pages($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0) { +function mod_wiki_get_tagged_pages($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0) +{ // Find items. // Please refer to existing callbacks in core for examples. diff --git a/versioned_docs/version-5.1/apis/subsystems/task/adhoc.md b/versioned_docs/version-5.1/apis/subsystems/task/adhoc.md index 0dd508de0..5d057312d 100644 --- a/versioned_docs/version-5.1/apis/subsystems/task/adhoc.md +++ b/versioned_docs/version-5.1/apis/subsystems/task/adhoc.md @@ -38,12 +38,13 @@ namespace mod_example\task; /** * An example of an adhoc task. */ -class do_something extends \core\task\adhoc_task { - +class do_something extends \core\task\adhoc_task +{ /** * Execute the task. */ - public function execute() { + public function execute() + { // Call your own api } } @@ -62,8 +63,8 @@ It can be fetched using the `get_custom_data(): mixed` method. We recommend only ever calling `set_custom_data()` from within a factory method in the task class itself. ```php -class do_something extends \core\task\adhoc_task { - +class do_something extends \core\task\adhoc_task +{ public static function instance( int $id, string $status, @@ -77,7 +78,8 @@ class do_something extends \core\task\adhoc_task { return $task; } - public function execute() { + public function execute() + { $data = $this->get_custom_data(); mtrace($data->id); mtrace($data->status); @@ -177,7 +179,8 @@ $task->get_attempts_available(); Tasks are retried by default, but this behaviour can be modified by overriding the `retry_until_success()` method in your task class, for example: ```php -public function retry_until_success(): bool { +public function retry_until_success(): bool +{ return false; } ``` diff --git a/versioned_docs/version-5.1/apis/subsystems/task/index.md b/versioned_docs/version-5.1/apis/subsystems/task/index.md index 4689e0e5a..e6d746e05 100644 --- a/versioned_docs/version-5.1/apis/subsystems/task/index.md +++ b/versioned_docs/version-5.1/apis/subsystems/task/index.md @@ -92,8 +92,10 @@ Since Moodle 3.5 it is safe to use the [Output API](../output/index.md) in cron In order to improve debugging information, it is good practice to call `mtrace` to log what's going on within a task execution: ```php -class my_task extends \core\task\scheduled_task { - public function execute() { +class my_task extends \core\task\scheduled_task +{ + public function execute() + { mtrace("My task started"); // Do some work. diff --git a/versioned_docs/version-5.1/apis/subsystems/task/scheduled.md b/versioned_docs/version-5.1/apis/subsystems/task/scheduled.md index b29072d9e..7d286c859 100644 --- a/versioned_docs/version-5.1/apis/subsystems/task/scheduled.md +++ b/versioned_docs/version-5.1/apis/subsystems/task/scheduled.md @@ -37,21 +37,24 @@ namespace mod_example\task; /** * An example of a scheduled task. */ -class do_something extends \core\task\scheduled_task { +class do_something extends \core\task\scheduled_task +{ /** * Return the task's name as shown in admin screens. * * @return string */ - public function get_name() { + public function get_name() + { return get_string('dosomething', 'mod_example'); } /** * Execute the task. */ - public function execute() { + public function execute() + { // Call your own api } } diff --git a/versioned_docs/version-5.1/guides/templates/index.md b/versioned_docs/version-5.1/guides/templates/index.md index 83161f69d..c9bcce802 100644 --- a/versioned_docs/version-5.1/guides/templates/index.md +++ b/versioned_docs/version-5.1/guides/templates/index.md @@ -397,7 +397,8 @@ The following example shows a renderable using the `mywidget.mustache` template * @param renderer_base $output * @return stdClass */ -public function export_for_template(renderer_base $output) { +public function export_for_template(renderer_base $output) +{ $data = new stdClass(); $data->canmanage = $this->canmanage; $data->things = []; @@ -424,7 +425,8 @@ Example of the method added to tell a renderable to use the `mywidget.mustache` * @param renderer_base $output * @return string */ -public function get_template_name(\renderer_base $renderer): string { +public function get_template_name(\renderer_base $renderer): string +{ return 'tool_myplugin/mywidget'; } ``` @@ -445,7 +447,8 @@ The rendering method can now use templates to render the object: * * @return string HTML */ -protected function render_mywidget(mywidget $widget) { +protected function render_mywidget(mywidget $widget) +{ $data = $widget->export_for_template($this); return $this->render_from_template('tool_myplugin/mywidget', $data); } diff --git a/versioned_docs/version-5.1/guides/testing/index.md b/versioned_docs/version-5.1/guides/testing/index.md index 552f340a7..41c66aea1 100644 --- a/versioned_docs/version-5.1/guides/testing/index.md +++ b/versioned_docs/version-5.1/guides/testing/index.md @@ -74,8 +74,10 @@ For example: ```php title="mod/myplugin/tests/sample_test.php" namespace mod_myplugin; - class sample_test extends \advanced_testcase { - public function test_adding() { + class sample_test extends \advanced_testcase + { + public function test_adding() + { $this->assertEquals(2, 1+2); } } @@ -101,8 +103,10 @@ If you modify data and _do not_ call `$this->resetAfterTest()` then you will rec ```php title="Demonstration of database reset" namespace mod_myplugin; - class test_something extends \advanced_testcase { - public function test_deleting() { + class test_something extends \advanced_testcase + { + public function test_deleting() + { global $DB; $this->resetAfterTest(true); @@ -110,7 +114,8 @@ If you modify data and _do not_ call `$this->resetAfterTest()` then you will rec $this->assertEmpty($DB->get_records('user')); } - public function test_user_table_was_reset() { + public function test_user_table_was_reset() + { global $DB; $this->assertEquals(2, $DB->count_records('user', array())); @@ -592,12 +597,15 @@ When defining coverage for a specific method under test, it must be either: /** * @coversDefaultClass \mod_myplugin\example */ -class example_test extends \advanced_testcase { +class example_test extends \advanced_testcase +{ /** * This test will cover \mod_myplugin\example::some_method * @covers ::some_method */ - public function test_some_method(): void {} + public function test_some_method(): void + { + } } ``` @@ -711,7 +719,8 @@ However, the following rules should be followed when using dataProviders: * @param int $foor * @param int $bar */ -public function test_foobar(int $foo, int $bar) { +public function test_foobar(int $foo, int $bar) +{ // Perform the tests here. } @@ -720,7 +729,8 @@ public function test_foobar(int $foo, int $bar) { * * @return array List of data sets - (string) data set name => (array) data */ -public function foobar_provider(): \Generator { +public function foobar_provider(): \Generator +{ yield 'Same numbers' => [ 'foo' => 42, 'bar' => 42, diff --git a/versioned_docs/version-5.1/guides/upgrade/index.md b/versioned_docs/version-5.1/guides/upgrade/index.md index c3658f5b6..59abf5438 100644 --- a/versioned_docs/version-5.1/guides/upgrade/index.md +++ b/versioned_docs/version-5.1/guides/upgrade/index.md @@ -52,7 +52,8 @@ The following example shows the structure of the upgrade.php file: ```php title="Example upgrade.php file" get_manager(); // Loads ddl manager and xmldb classes. @@ -161,7 +162,8 @@ For example, if you are defining an installation behaviour in the `install.php` $coursemodule->instance]; @@ -224,7 +226,8 @@ First, the function that adds these controls: * @category completion * @return array List of added element names, or names of wrapping group elements. */ -public function add_completion_rules() { +public function add_completion_rules() +{ $mform = $this->_form; @@ -264,7 +267,8 @@ public function add_completion_rules() { return [$this->get_suffixed_name('completionpostsgroup')]; } -protected function get_suffixed_name(string $fieldname): string { +protected function get_suffixed_name(string $fieldname): string +{ return $fieldname . $this->get_suffix(); } ``` @@ -284,7 +288,8 @@ Next, a function for checking whether the user selected this option: * @param array $data Input data not yet validated. * @return bool True if one or more rules is enabled, false if none are. */ -public function completion_rule_enabled($data) { +public function completion_rule_enabled($data) +{ return (!empty($data[$this->get_suffixed_name('completionpostsenabled')]) && $data[$this->get_suffixed_name('completionposts')] != 0); } @@ -295,7 +300,8 @@ public function completion_rule_enabled($data) { That's all the 'required' functions, but we need to add some extra code to support the checkbox behaviour. I overrode `get_data` so that if there is a value in the edit field, but the checkbox is not ticked, the value counts as zero (the rule will not be enabled). ```php -function get_data() { +function get_data() +{ $data = parent::get_data(); if (!$data) { return $data; @@ -316,7 +322,8 @@ You may have noticed the `completionunlocked` check. When some users have alread Finally, forum already had a `data_preprocessing` function but I added code to this to set up the checkboxes when the form is displayed, and to make the default value of the text fields 1 instead of 0: ```php -function data_preprocessing(&$default_values){ +function data_preprocessing(&$default_values) +{ // [Existing code, not shown] // Set up the completion checkboxes which aren't part of standard data. @@ -360,7 +367,8 @@ Here's the function for forum (simplified to include only the one completion opt * @param bool $type Type of comparison (or/and; can be used as return value if no conditions) * @return bool True if completed, false if not, $type if conditions not set. */ - function forum_get_completion_state($course, $cm, $userid, $type) { + function forum_get_completion_state($course, $cm, $userid, $type) + { global $CFG,$DB; // Get forum details @@ -402,7 +410,8 @@ You need to return an array of strings for each completion rule that is active. * @param cm_info|stdClass $cm object with fields ->completion and ->customdata['customcompletionrules'] * @return array $descriptions the array of descriptions for the custom rules. */ -function mod_forum_get_completion_active_rule_descriptions($cm) { +function mod_forum_get_completion_active_rule_descriptions($cm) +{ // Values will be present in cm_info, and we assume these are up to date. if (empty($cm->customdata['customcompletionrules']) || $cm->completion != COMPLETION_TRACKING_AUTOMATIC) { return []; diff --git a/versioned_docs/version-5.2/apis/core/calendar/index.md b/versioned_docs/version-5.2/apis/core/calendar/index.md index 03ca98f0f..11d7f9903 100644 --- a/versioned_docs/version-5.2/apis/core/calendar/index.md +++ b/versioned_docs/version-5.2/apis/core/calendar/index.md @@ -103,7 +103,8 @@ where '$prioritiesforeventtype1' is an associative array that has the timestamp * @param int $lessonid The lesson ID. * @return array|null Array of group override priorities for open and close times. Null if there are no group overrides. */ -function lesson_get_group_override_priorities($lessonid) { +function lesson_get_group_override_priorities($lessonid) +{ global $DB; // Fetch group overrides. @@ -182,7 +183,8 @@ This callback determines if an event should be visible throughout the site. For * @param calendar_event $event * @return bool Returns true if the event is visible to the current user, false otherwise. */ -function mod_assign_core_calendar_is_event_visible(calendar_event $event) { +function mod_assign_core_calendar_is_event_visible(calendar_event $event) +{ global $CFG, $USER; require_once($CFG->dirroot . '/mod/assign/locallib.php'); @@ -259,7 +261,8 @@ Eg. * @param int $itemcount The item count associated with the action event. * @return bool */ -function mod_assign_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) { +function mod_assign_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) +{ // List of event types where the action event's item count should be shown. $eventtypesshowingitemcount = [ ASSIGN_EVENT_TYPE_GRADINGDUE @@ -320,7 +323,8 @@ This callback handles updating the activity instance based on the changed action Example: ```php -function mod_feedback_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $feedback) { +function mod_feedback_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $feedback) +{ global $CFG, $DB; if (empty($event->instance) || $event->modulename != 'feedback') { @@ -406,7 +410,8 @@ If the calendar event has no valid `timestart` values then the callback should r Example: ```php -function mod_feedback_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $instance) { +function mod_feedback_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $instance) +{ $mindate = null; $maxdate = null; diff --git a/versioned_docs/version-5.2/apis/core/clock/index.md b/versioned_docs/version-5.2/apis/core/clock/index.md index de70bd68b..5528cf4c3 100644 --- a/versioned_docs/version-5.2/apis/core/clock/index.md +++ b/versioned_docs/version-5.2/apis/core/clock/index.md @@ -46,13 +46,15 @@ The recommended approach is to have the Dependency Injector inject into the cons ```php title="Usage in injected classes" namespace mod_example; -class post { +class post +{ public function __construct( protected readonly \core\clock $clock, protected readonly \moodle_database $db, ) - public function create_thing(\stdClass $data): \stdClass { + public function create_thing(\stdClass $data): \stdClass + { $data->timecreated = $this->clock->time(); $data->id = $this->db->insert_record('example_thing', $data); @@ -99,8 +101,10 @@ The incrementing clock increases the time by one second every time it is called. A helper method, `mock_clock_with_incrementing(?int $starttime = null): \core\clock`, is provided within the standard testcase: ```php title="Obtaining the incrementing clock" -class my_test extends \advanced_testcase { - public function test_create_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_create_thing(): void + { // This class inserts data into the database. $this->resetAfterTest(true); @@ -134,8 +138,10 @@ The frozen clock uses a time which does not change, unless manually set. This ca A helper method, `mock_clock_with_frozen(?int $time = null): \core\clock`, is provided within the standard testcase: ```php title="Obtaining and using the frozen clock" -class my_test extends \advanced_testcase { - public function test_create_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_create_thing(): void + { // This class inserts data into the database. $this->resetAfterTest(true); @@ -182,27 +188,33 @@ class my_test extends \advanced_testcase { If the standard cases are not suitable for you, then you can create a custom clock and inject it into the DI container. ```php title="Creating a custom clock" -class my_clock implements \core\clock { +class my_clock implements \core\clock +{ public int $time; - public function __construct() { + public function __construct() + { $this->time = time(); } - public function now(): \DateTimeImmutable { + public function now(): \DateTimeImmutable + { $time = new \DateTimeImmutable('@' . $this->time); $this->time = $this->time += 5; return $time; } - public function time(): int { + public function time(): int + { return $this->now()->getTimestamp(); } } -class my_test extends \advanced_testcase { - public function test_my_thing(): void { +class my_test extends \advanced_testcase +{ + public function test_my_thing(): void + { $clock = new my_clock(); \core\di:set(\core\clock::class, $clock); diff --git a/versioned_docs/version-5.2/apis/core/comment/index.md b/versioned_docs/version-5.2/apis/core/comment/index.md index adb05cbe0..6a5749381 100644 --- a/versioned_docs/version-5.2/apis/core/comment/index.md +++ b/versioned_docs/version-5.2/apis/core/comment/index.md @@ -94,7 +94,8 @@ This is an example of a possible callback for plugin `mod_myplugin`: * @param stdClass $args * @return boolean */ -function mod_myplugin_comment_display(stdClass $comments, stdClass $args): stdClass { +function mod_myplugin_comment_display(stdClass $comments, stdClass $args): stdClass +{ if ($args->commentarea != 'entry_comments') { throw new comment_exception('invalidcommentarea'); } diff --git a/versioned_docs/version-5.2/apis/core/customfields/index.md b/versioned_docs/version-5.2/apis/core/customfields/index.md index a4644919c..43acc73ad 100644 --- a/versioned_docs/version-5.2/apis/core/customfields/index.md +++ b/versioned_docs/version-5.2/apis/core/customfields/index.md @@ -105,7 +105,8 @@ The list of fields is cached in the handler and these two functions can be calle ::: ```php title="Example code for course custom fields. This function will return all the custom fields for a given courseid" -function get_course_metadata($courseid) { +function get_course_metadata($courseid) +{ $handler = \core_customfield\handler::get_handler('core_course', 'course'); // This is equivalent to the line above. //$handler = \core_course\customfield\course_handler::create(); diff --git a/versioned_docs/version-5.2/apis/core/deprecation/index.md b/versioned_docs/version-5.2/apis/core/deprecation/index.md index 8df0d5dee..2ce423a71 100644 --- a/versioned_docs/version-5.2/apis/core/deprecation/index.md +++ b/versioned_docs/version-5.2/apis/core/deprecation/index.md @@ -40,24 +40,29 @@ The attribute is a Moodle PHP Attribute and can be applied to: ```php title="Example attribute usage" // On a global function: #[\core\attribute\deprecated('random_bytes', since: '4.3')] -function random_bytes_emulate($length) { +function random_bytes_emulate($length) +{ // Replaced by random_bytes since Moodle 4.3. } // On a class: #[\core\attribute\deprecated(replacement: null, since: '4.4', reason: 'This functionality has been removed.')] -class example { +class example +{ #[\core\attribute\deprecated( replacement: '\core\example::do_something', since: '4.3', reason: 'No longer required', mdl: 'MDL-12345', )] - public function do_something(): void {} + public function do_something(): void + { + } } // On an enum case: -enum example { +enum example +{ #[\core\attribute\deprecated('example::OPTION', since: '4.4', final: true)] case OPTION; } @@ -75,7 +80,8 @@ The `\core\deprecation` class contains helper methods to inspect for use of the // A method which has been initially deprecated, and replaced by 'random_bytes'. It should show debugging. /** @deprecated since 4.3 */ #[\core\attribute\deprecated('random_bytes', since: '4.3')] -function random_bytes_emulate($length) { +function random_bytes_emulate($length) +{ \core\deprecation::emit_deprecation_if_present(__FUNCTION__); return random_bytes($length); } @@ -83,7 +89,8 @@ function random_bytes_emulate($length) { // A method which has been finally deprecated and should throw an exception. /** @deprecated since 2.7 */ #[\core\attribute\deprecated(replacement: 'Events API', since: '2.3', final: true)] -function add_to_log() { +function add_to_log() +{ \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } diff --git a/versioned_docs/version-5.2/apis/core/di/index.md b/versioned_docs/version-5.2/apis/core/di/index.md index 0529877c9..0fbcfd8bd 100644 --- a/versioned_docs/version-5.2/apis/core/di/index.md +++ b/versioned_docs/version-5.2/apis/core/di/index.md @@ -21,7 +21,8 @@ Dependencies are stored using a string id attribute, which is typically the clas When accessing dependencies within a class, it is advisable to inject them into the constructor, for example: ```php title="Fetching a instance of the \core\http_client class from within a class" -class my_thing { +class my_thing +{ public function __construct( protected readonly \core\http_client $client, ) { @@ -48,7 +49,8 @@ The use of readonly properties is also highly recommended as it ensures that dep These language features are available in all Moodle versions supporting Dependency Injection. ```php -class example_without_promotion { +class example_without_promotion +{ protected \core\http_client $client; public function __construct( @@ -58,7 +60,8 @@ class example_without_promotion { } } -class example_with_promotion { +class example_with_promotion +{ public function __construct( protected readonly \core\http_client $client, ) { @@ -101,8 +104,10 @@ namespace mod_example; use core\hook\di_configuration; -class hook_listener { - public static function inject_dependencies(di_configuration $hook): void { +class hook_listener +{ + public static function inject_dependencies(di_configuration $hook): void + { $hook->add_definition( id: complex_client::class, definition: function ( @@ -139,8 +144,10 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; use GuzzleHttp\Psr7\Response; -class example_test extends \advanced_testcase { - public function test_the_thing(): void { +class example_test extends \advanced_testcase +{ + public function test_the_thing(): void + { // Mock our responses to the http_client. $handlerstack = HandlerStack::create(new MockHandler([ new Response(200, [], json_encode(['name' => 'Colin'])), @@ -170,13 +177,15 @@ Dependencies can be usually be easily injected into classes which are themselves In most cases in Moodle, this should be via the class constructor, for example: ```php title="Injecting via the constructor" -class thing_manager { +class thing_manager +{ public function __construct( protected readonly \moodle_database $db, ) { } - public function get_things(): array { + public function get_things(): array + { return $this->db->get_records('example_things'); } } @@ -186,13 +195,15 @@ $manager = \core\di::get(thing_manager::class); $things = $manager->get_things(); // Using it in a child class: -class other_thing { +class other_thing +{ public function __construct( protected readonly thing_manager $manager, ) { } - public function manage_things(): void { + public function manage_things(): void + { $this->manager->get_things(); } } diff --git a/versioned_docs/version-5.2/apis/core/dml/ddl.md b/versioned_docs/version-5.2/apis/core/dml/ddl.md index 83534afad..c33184f78 100644 --- a/versioned_docs/version-5.2/apis/core/dml/ddl.md +++ b/versioned_docs/version-5.2/apis/core/dml/ddl.md @@ -24,7 +24,8 @@ Of course, feel free to clarify, complete and add more info to all this document - All the function calls in this page are public methods of the **database manager**, accessible from the $DB global object. You will need to "import" it within the upgrade function of your **upgrade.php** main function using the `global` keyword, for example: ```php -function xmldb_xxxx_upgrade { +function xmldb_xxxx_upgrade +{ global $DB; // Load the DDL manager and xmldb API. diff --git a/versioned_docs/version-5.2/apis/core/dml/index.md b/versioned_docs/version-5.2/apis/core/dml/index.md index 8b63d7dca..d856ea79e 100644 --- a/versioned_docs/version-5.2/apis/core/dml/index.md +++ b/versioned_docs/version-5.2/apis/core/dml/index.md @@ -33,7 +33,8 @@ require(__DIR__ . '/config.php'); ```php title="example.php" \mod_example\local\entitychanges\create_example::class, @@ -156,7 +158,8 @@ namespace mod_activity\hook; #[\core\attribute\label('Hook dispatched at the very end of installation of mod_activity plugin.')] #[\core\attribute\tags('installation')] -final class installation_finished { +final class installation_finished +{ public function __construct( public readonly string $version, ) { @@ -172,17 +175,20 @@ final class installation_finished { dispatch($hook); } @@ -219,7 +226,8 @@ Using DI for dependency injection has the benefit that the hook manager can use ```php title="Mocking a hook listener" // Unit test. -public function test_before_standard_footer_html_hooked(): void { +public function test_before_standard_footer_html_hooked(): void +{ // Load the callback classes. require_once(__DIR__ . '/fixtures/core_renderer/before_standard_footer_html_callbacks.php'); @@ -242,7 +250,8 @@ public function test_before_standard_footer_html_hooked(): void { } // fixtures/core_renderer/before_standard_footer_html_callbacks.php -final class before_standard_footer_html_callbacks { +final class before_standard_footer_html_callbacks +{ public static function before_standard_footer_html( \core\hook\output\before_standard_footer_html $hook, ): void { @@ -321,8 +330,10 @@ a hook as parameter. namespace local_stuff\local; use \mod_activity\hook\installation_finished; -class hook_callbacks { - public static function activity_installation_finished(installation_finished $hook): void { +class hook_callbacks +{ + public static function activity_installation_finished(installation_finished $hook): void + { if (during_initial_install()) { return; } @@ -395,7 +406,8 @@ use core\attribute; #[attribute\label('Hook dispatched at the very end of lib/setup.php')] #[attribute\tags('config')] #[attribute\hook\replaces_callbacks('after_config')] -final class after_config { +final class after_config +{ } ``` @@ -407,16 +419,20 @@ final class after_config { stopped; } - public function stop(): void { + public function stop(): void + { $this->stopped = true; } } @@ -527,8 +546,10 @@ A callback will only be called if the hook was not stopped before-hand. Dependin namespace local_myplugin; -class callbacks { - public static function block_pre_delete(\core\hook\block_delete_pre $hook): void { +class callbacks +{ + public static function block_pre_delete(\core\hook\block_delete_pre $hook): void + { // ... $hook->stop(); } diff --git a/versioned_docs/version-5.2/apis/core/navigation/index.md b/versioned_docs/version-5.2/apis/core/navigation/index.md index 159250ee1..eaae0aa97 100644 --- a/versioned_docs/version-5.2/apis/core/navigation/index.md +++ b/versioned_docs/version-5.2/apis/core/navigation/index.md @@ -235,7 +235,8 @@ function {modulename}_extend_settings_navigation( You may be required to add a node in a specified order within the menu navigation menus. To do this you need to examine the node object as given in the respective parameters in the functions above, then find the key of the child node you wish to place the link before. For example, applying the code below will put a direct link to grade report. ```php -function my_plugin_extend_settings_navigation($settingsnav, $context){ +function my_plugin_extend_settings_navigation($settingsnav, $context) +{ $addnode = $context->contextlevel === 50; $addnode = $addnode && has_capability('gradereport/grader:view', $context); if ($addnode) { diff --git a/versioned_docs/version-5.2/apis/core/reportbuilder/index.md b/versioned_docs/version-5.2/apis/core/reportbuilder/index.md index b7984b9ff..a7ab677d0 100644 --- a/versioned_docs/version-5.2/apis/core/reportbuilder/index.md +++ b/versioned_docs/version-5.2/apis/core/reportbuilder/index.md @@ -216,7 +216,8 @@ The first method that we need is ***initialise()*** : /** * Initialise report, we need to set the main table, load our entities and set columns/filters */ -protected function initialise(): void { +protected function initialise(): void +{ ``` The initialise method needs to get the main entity, set the main table it needs to use and add the entity to the report: @@ -336,7 +337,8 @@ The first method you need to build is `initialise()` /** * Initialise report, we need to set the main table, load our entities and set columns/filters */ -protected function initialise(): void { +protected function initialise(): void +{ ``` The initialise method needs to get the main entity, set the main table it needs to use and add the entity to the report: @@ -397,7 +399,8 @@ You will need to specify the name that is displayed to the end user for the data * * @return string */ - public static function get_name(): string { + public static function get_name(): string + { return get_string('tasklogs', 'core_admin'); } ``` @@ -412,7 +415,8 @@ Once all entities have been added you need to define which columns it will show * * @return string[] */ -public function get_default_columns(): array { +public function get_default_columns(): array +{ return [ 'task_log:name', 'task_log:starttime', @@ -430,7 +434,8 @@ You may also optionally define the sorting that will be applied to the default r * * @return int[] */ -public function get_default_column_sorting(): array { +public function get_default_column_sorting(): array +{ return [ 'task_log:starttime' => SORT_DESC, ]; @@ -447,7 +452,8 @@ The filters allow the end user of the report to only see a subset of the data th * * @return string[] */ -public function get_default_filters(): array { +public function get_default_filters(): array +{ return [ 'task_log:timestart', 'task_log:result', @@ -465,7 +471,8 @@ The conditions allow the user creating the report to define which data it will r * * @return string[] */ -public function get_default_conditions(): array { +public function get_default_conditions(): array +{ return [ 'task_log:type', 'task_log:timestart', @@ -482,7 +489,8 @@ You may also optionally define the [initial values for any of the default condit * * @return array */ -public function get_default_condition_values(): array { +public function get_default_condition_values(): array +{ return [ 'task_log:type_operator' => select::EQUAL_TO, 'task_log:type_value' => \core\task\database_logger::TYPE_SCHEDULED, @@ -508,7 +516,8 @@ require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php"); * @copyright 2023 Paul Holden * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class categories_test extends core_reportbuilder_testcase { +class categories_test extends core_reportbuilder_testcase +{ ``` The `core_reportbuilder_testcase` will not autoload so we first ensure that it is loaded with the `require_once`. After this there are a few things you should look to test: @@ -526,7 +535,8 @@ For this you want a step that sets up will return enough data allows you test al /** * Test default datasource */ - public function test_datasource_default(): void { + public function test_datasource_default(): void + { $this->resetAfterTest(); $category = $this->getDataGenerator()->create_category(['name' => 'Zoo', 'idnumber' => 'Z01']); @@ -618,7 +628,8 @@ None of these tests checks that the data is what you want, but will ensure that * * In order to execute this test PHPUNIT_LONGTEST should be defined as true in phpunit.xml or directly in config.php */ - public function test_stress_datasource(): void { + public function test_stress_datasource(): void + { if (!PHPUNIT_LONGTEST) { $this->markTestSkipped('PHPUNIT_LONGTEST is not defined'); } diff --git a/versioned_docs/version-5.2/apis/plugintypes/ai/placement.md b/versioned_docs/version-5.2/apis/plugintypes/ai/placement.md index dfa4d6c48..e33e4cfc7 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/ai/placement.md +++ b/versioned_docs/version-5.2/apis/plugintypes/ai/placement.md @@ -39,7 +39,8 @@ They must also implement the following methods: This is the list of Actions that are supported by this Placement, for example the `aiplacement_editor` plugin defines this as: ```php -public function get_action_list(): array { +public function get_action_list(): array +{ return [ \core_ai\aiactions\generate_text::class, \core_ai\aiactions\generate_image::class, diff --git a/versioned_docs/version-5.2/apis/plugintypes/ai/provider.md b/versioned_docs/version-5.2/apis/plugintypes/ai/provider.md index c5eaa4c50..0b1e3661c 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/ai/provider.md +++ b/versioned_docs/version-5.2/apis/plugintypes/ai/provider.md @@ -41,7 +41,8 @@ They must also implement the following methods: This is the list of Actions that are supported by this Provider, for example the `aiprovider_openai` plugin defines this as: ```php -public static function get_action_list(): array { +public static function get_action_list(): array +{ return [ \core_ai\aiactions\generate_text::class, \core_ai\aiactions\generate_image::class, @@ -62,7 +63,8 @@ For example, the `aiprovider_azureai` provider checks values are set for `$this- the result. ```php -public function is_provider_configured(): bool { +public function is_provider_configured(): bool +{ return !empty($this->config['apikey']) && !empty($this->config['endpoint']); } ``` @@ -171,14 +173,16 @@ For example, the `aiprovider_openai` plugin defines this: namespace aiprovider_openai; use core_ai\hook\after_ai_provider_form_hook; -class hook_listener { +class hook_listener +{ /** * Hook listener for the Open AI instance setup form. * * @param after_ai_provider_form_hook $hook The hook to add to the AI instance setup. */ - public static function set_form_definition_for_aiprovider_openai(after_ai_provider_form_hook $hook): void { + public static function set_form_definition_for_aiprovider_openai(after_ai_provider_form_hook $hook): void + { if ($hook->plugin !== 'aiprovider_openai') { return; } @@ -260,9 +264,11 @@ These classes should extend the `core_ai\form\action_settings_form` class, and m For example, the `aiprovider_openai` plugin defines this: ```php -class action_generate_text_form extends action_settings_form { +class action_generate_text_form extends action_settings_form +{ #[\Override] - protected function definition() { + protected function definition() + { $mform = $this->_form; $actionconfig = $this->_customdata['actionconfig']['settings'] ?? []; $returnurl = $this->_customdata['returnurl'] ?? null; @@ -302,14 +308,17 @@ namespace aiprovider_openai\aimodel; use core_ai\aimodel\base; use MoodleQuickForm; -class gpt4o extends base implements openai_base { +class gpt4o extends base implements openai_base +{ #[\Override] - public function get_model_name(): string { + public function get_model_name(): string + { return 'gpt-4o'; } #[\Override] - public function get_model_display_name(): string { + public function get_model_display_name(): string + { return 'GPT-4o'; } @@ -325,12 +334,14 @@ To add configurable settings for individual models: ```php #[\Override] - public function has_model_settings(): bool { + public function has_model_settings(): bool + { return true; } #[\Override] - public function add_model_settings(MoodleQuickForm $mform): void { + public function add_model_settings(MoodleQuickForm $mform): void + { $mform->addElement( 'text', 'top_p', @@ -354,13 +365,15 @@ To add configurable settings for individual models: ```php namespace aiprovider_openai; - class helper { + class helper + { /** * Get all model classes. * * @return array Array of model classes */ - public static function get_model_classes(): array { + public static function get_model_classes(): array + { $models = []; $modelclasses = \core_component::get_component_classes_in_namespace('aiprovider_openai', 'aimodel'); foreach ($modelclasses as $class => $path) { @@ -378,7 +391,8 @@ To add configurable settings for individual models: * @param string $modelname The model name * @return \core_ai\aimodel\base|null The model class or null if not found */ - public static function get_model_class(string $modelname): ?\core_ai\aimodel\base { + public static function get_model_class(string $modelname): ?\core_ai\aimodel\base + { foreach (self::get_model_classes() as $modelclass) { $model = new $modelclass(); if ($model->get_model_name() === $modelname) { @@ -399,7 +413,8 @@ For example, the `aiprovider_openai` plugin does these: 1. Create a hook listener that adds model settings to the action form: ```php - public static function set_model_form_definition_for_aiprovider_openai(after_ai_action_settings_form_hook $hook): void { + public static function set_model_form_definition_for_aiprovider_openai(after_ai_action_settings_form_hook $hook): void + { if ($hook->plugin !== 'aiprovider_openai') { return; } diff --git a/versioned_docs/version-5.2/apis/plugintypes/assign/feedback.md b/versioned_docs/version-5.2/apis/plugintypes/assign/feedback.md index 0634bccbf..c77a995f3 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/assign/feedback.md +++ b/versioned_docs/version-5.2/apis/plugintypes/assign/feedback.md @@ -121,7 +121,8 @@ All feedback plugins should include one setting named 'default' to indicate if t This is where all the functionality for this plugin is defined. We will step through this file and describe each part as we go. ```php -class assign_feedback_file extends assign_feedback_plugin { +class assign_feedback_file extends assign_feedback_plugin +{ ``` #### get_name() {/* #get_name */} @@ -129,7 +130,8 @@ class assign_feedback_file extends assign_feedback_plugin { All feedback plugins MUST define a class with the component name of the plugin that extends assign_feedback_plugin. ```php -public function get_name() { +public function get_name() +{ return get_string('file', 'assignfeedback_file'); } ``` @@ -139,7 +141,8 @@ This function is abstract in the parent class (feedback_plugin) and must be defi #### get_settings() {/* #get_settings */} ```php -public function get_settings(MoodleQuickForm $mform) { +public function get_settings(MoodleQuickForm $mform) +{ $mform->addElement( 'assignfeedback_file_fileextensions', get_string('allowedfileextensions', 'assignfeedback_file') @@ -153,7 +156,8 @@ This function is called when building the settings page for the assignment. It a #### save_settings() {/* #save_settings */} ```php -public function save_settings(stdClass $data) { +public function save_settings(stdClass $data) +{ $this->set_config('allowedfileextensions', $data->allowedfileextensions); return true; } @@ -204,7 +208,8 @@ This function is called when building the feedback form. It functions identicall #### is_feedback_modified() {/* #is_feedback_modified */} ```php -public function is_feedback_modified(stdClass $grade, stdClass $data) { +public function is_feedback_modified(stdClass $grade, stdClass $data) +{ $commenttext = ''; if ($grade) { $feedbackcomments = $this->get_feedback_comments($grade->id); @@ -226,7 +231,8 @@ This function is called before feedback is saved. If feedback has not been modif #### save() {/* #save */} ```php -public function save(stdClass $grade, stdClass $data) { +public function save(stdClass $grade, stdClass $data) +{ global $DB; $fileoptions = $this->get_file_options(); @@ -263,7 +269,8 @@ This function is called to save a graders feedback. The parameters are the grade #### view_summary() {/* #view_summary */} ```php -public function view_summary(stdClass $grade, & $showviewlink) { +public function view_summary(stdClass $grade, & $showviewlink) +{ $count = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA); // show a view all link if the number of files is over this limit $showviewlink = $count > ASSIGNFEEDBACK_FILE_MAXSUMMARYFILES; @@ -285,7 +292,8 @@ This function is called to display a summary of the feedback to both markers and #### view() {/* #view */} ```php -public function view(stdClass $grade) { +public function view(stdClass $grade) +{ return $this->assignment->render_area_files( 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, @@ -299,7 +307,8 @@ This function is called to display the entire feedback to both markers and stude #### can_upgrade() {/* #can_upgrade */} ```php -public function can_upgrade($type, $version) { +public function can_upgrade($type, $version) +{ if (($type == 'upload' || $type == 'uploadsingle') && $version >= 2011112900) { return true; @@ -311,7 +320,8 @@ public function can_upgrade($type, $version) { This function is used to identify old "Assignment 2.2" subtypes that can be upgraded by this plugin. This plugin supports upgrades from the old "upload" and "uploadsingle" assignment subtypes. ```php -public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) { +public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) +{ // first upgrade settings (nothing to do) return true; } @@ -360,7 +370,8 @@ This function upgrades a single submission from the old assignment type to the n #### is_empty() {/* #is_empty */} ```php -public function is_empty(stdClass $submission) { +public function is_empty(stdClass $submission) +{ return $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA) == 0; } ``` @@ -370,7 +381,8 @@ If a plugin has no data to show then this function should return true from the ` #### get_file_areas() {/* #get_file_areas */} ```php -public function get_file_areas() { +public function get_file_areas() +{ return [ASSIGNFEEDBACK_FILE_FILEAREA => $this->get_name()]; } ``` @@ -380,7 +392,8 @@ A plugin should implement `get_file_areas` if it supports saving of any files to #### delete_instance() {/* #delete_instance */} ```php -public function delete_instance() { +public function delete_instance() +{ global $DB; // will throw exception on failure $DB->delete_records('assignfeedback_file', [ @@ -396,11 +409,13 @@ This function is called when a plugin is deleted. Note only database records nee #### Gradebook features {/* #gradebook-features */} ```php -public function format_for_gradebook(stdClass $grade) { +public function format_for_gradebook(stdClass $grade) +{ return FORMAT_MOODLE; } -public function text_for_gradebook(stdClass $grade) { +public function text_for_gradebook(stdClass $grade) +{ return ''; } ``` @@ -413,7 +428,8 @@ Only one feedback plugin can push comments to the gradebook. Usually this is the * * @return boolean - True if the plugin supports quickgrading */ -public function supports_quickgrading() { +public function supports_quickgrading() +{ return false; } @@ -424,7 +440,8 @@ public function supports_quickgrading() { * @param mixed $grade grade or null - The grade data. May be null if there are no grades for this user (yet) * @return mixed - A html string containing the html form elements required for quickgrading or false to indicate this plugin does not support quickgrading */ -public function get_quickgrading_html($userid, $grade) { +public function get_quickgrading_html($userid, $grade) +{ return false; } @@ -435,7 +452,8 @@ public function get_quickgrading_html($userid, $grade) { * @param stdClass $grade The grade * @return boolean - true if the quickgrading form element has been modified */ -public function is_quickgrading_modified($userid, $grade) { +public function is_quickgrading_modified($userid, $grade) +{ return false; } @@ -446,7 +464,8 @@ public function is_quickgrading_modified($userid, $grade) { * @param stdClass $grade The grade * @return boolean - true if the grade changes were saved correctly */ -public function save_quickgrading_changes($userid, $grade) { +public function save_quickgrading_changes($userid, $grade) +{ return false; } ``` @@ -457,7 +476,8 @@ These 4 functions can be implemented to allow a plugin to support quick-grading. /** * Run cron for this plugin */ -public static function cron() { +public static function cron() +{ } ``` @@ -471,7 +491,8 @@ A plugin can run code when cron runs by implementing this method. * @return array - An array of action and description strings. * The action will be passed to grading_action. */ -public function get_grading_actions() { +public function get_grading_actions() +{ return []; } @@ -481,7 +502,8 @@ public function get_grading_actions() { * @param string $gradingaction The action chosen from the grading actions menu * @return string The page containing the form */ -public function grading_action($gradingaction) { +public function grading_action($gradingaction) +{ return ''; } ``` @@ -495,7 +517,8 @@ Grading actions appear in the select menu above the grading table and apply to t * @return array - An array of action and description strings. * The action will be passed to grading_batch_operation. */ -public function get_grading_batch_operations() { +public function get_grading_batch_operations() +{ return []; } @@ -506,7 +529,8 @@ public function get_grading_batch_operations() { * @param array $users The list of selected userids * @return string The page containing the form */ -public function grading_batch_operation($action, $users) { +public function grading_batch_operation($action, $users) +{ return ''; } ``` diff --git a/versioned_docs/version-5.2/apis/plugintypes/assign/submission.md b/versioned_docs/version-5.2/apis/plugintypes/assign/submission.md index d4e43f75e..e643dbe16 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/assign/submission.md +++ b/versioned_docs/version-5.2/apis/plugintypes/assign/submission.md @@ -118,7 +118,8 @@ This example from the submission_file plugin also checks to see if there is a ma This is where all the functionality for this plugin is defined. We will step through this file and describe each part as we go. ```php -class assign_submission_file extends assign_submission_plugin { +class assign_submission_file extends assign_submission_plugin +{ ``` All submission plugins MUST define a class with the component name of the plugin that extends assign_submission_plugin. @@ -126,7 +127,8 @@ All submission plugins MUST define a class with the component name of the plugin #### get_name() {/* #get_name */} ```php -public function get_name() { +public function get_name() +{ return get_string('file', 'assignsubmission_file'); } ``` @@ -136,7 +138,8 @@ Get name is abstract in submission_plugin and must be defined in your new plugin #### get_settings() {/* #get_settings */} ```php -public function get_settings(MoodleQuickForm $mform) { +public function get_settings(MoodleQuickForm $mform) +{ global $CFG, $COURSE; $defaultmaxfilesubmissions = $this->get_config('maxfilesubmissions'); @@ -193,7 +196,8 @@ The "get_settings" function is called when building the settings page for the as #### save_settings() {/* #save_settings */} ```php -public function save_settings(stdClass $data) { +public function save_settings(stdClass $data) +{ $this->set_config('maxfilesubmissions', $data->assignsubmission_file_maxfiles); $this->set_config('maxsubmissionsizebytes', $data->assignsubmission_file_maxsizebytes); return true; @@ -205,7 +209,8 @@ The "save_settings" function is called when the assignment settings page is subm #### get_form_elements() {/* #get_form_elements */} ```php -public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data) { +public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data) +{ if ($this->get_config('maxfilesubmissions') <= 0) { return false; } @@ -240,7 +245,8 @@ The get_form_elements function is called when building the submission form. It f #### save() {/* #save */} ```php -public function save(stdClass $submission, stdClass $data) { +public function save(stdClass $submission, stdClass $data) +{ global $USER, $DB; $fileoptions = $this->get_file_options(); @@ -305,7 +311,8 @@ The "save" function is called to save a user submission. The parameters are the #### get_files() {/* #get_files */} ```php -public function get_files($submission) { +public function get_files($submission) +{ $result = []; $fs = get_file_storage(); @@ -330,7 +337,8 @@ If this submission plugin produces one or more files, it should implement "get_f #### view_summary() {/* #view_summary */} ```php -public function view_summary(stdClass $submission, & $showviewlink) { +public function view_summary(stdClass $submission, & $showviewlink) +{ $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); // Show we show a link to view all files for this plugin. @@ -352,7 +360,8 @@ The view_summary function is called to display a summary of the submission to bo #### view() {/* #view */} ```php -public function view($submission) { +public function view($submission) +{ return $this->assignment->render_area_files( 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, @@ -367,7 +376,8 @@ The view function is called to display the entire submission to both markers and ```php #[\Override] -public function submission_summary_for_messages(stdClass $submission): array { +public function submission_summary_for_messages(stdClass $submission): array +{ global $PAGE; $onlinetextsubmission = $this->get_onlinetext_submission($submission->id); @@ -392,7 +402,8 @@ This method produces a summary of what was submitted, in a form suitable to incl #### can_upgrade() {/* #can_upgrade */} ```php -public function can_upgrade($type, $version) { +public function can_upgrade($type, $version) +{ $uploadsingle_type ='uploadsingle'; $upload_type ='upload'; @@ -408,7 +419,8 @@ The can_upgrade function is used to identify old "Assignment 2.2" subtypes that #### upgrade_settings() {/* #upgrade_settings */} ```php -public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) { +public function upgrade_settings(context $oldcontext, stdClass $oldassignment, &$log) +{ global $DB; if ($oldassignment->assignmenttype == 'uploadsingle') { @@ -450,7 +462,8 @@ This function is called once per assignment instance to upgrade the settings fro #### upgrade() {/* #upgrade */} ```php -public function upgrade($oldcontext, $oldassignment, $oldsubmission, $submission, &$log) { +public function upgrade($oldcontext, $oldassignment, $oldsubmission, $submission, &$log) +{ global $DB; $filesubmission = (object) [ @@ -486,7 +499,8 @@ The "upgrade" function upgrades a single submission from the old assignment type #### get_editor_fields() {/* #get_editor_fields */} ```php -public function () { +public function () +{ return [ 'onlinetext' => get_string('pluginname', 'assignsubmission_comments'), ]; @@ -498,7 +512,8 @@ This example is from assignsubmission_onlinetext. If the plugin uses a text-edit #### get_editor_text() {/* #get_editor_text */} ```php -public function get_editor_text($name, $submissionid) { +public function get_editor_text($name, $submissionid) +{ if ($name == 'onlinetext') { $onlinetextsubmission = $this->get_onlinetext_submission($submissionid); if ($onlinetextsubmission) { @@ -515,7 +530,8 @@ This example is from assignsubmission_onlinetext. If the plugin uses a text-edit #### get_editor_format() {/* #get_editor_format */} ```php -public function get_editor_format($name, $submissionid) { +public function get_editor_format($name, $submissionid) +{ if ($name == 'onlinetext') { $onlinetextsubmission = $this->get_onlinetext_submission($submissionid); if ($onlinetextsubmission) { @@ -532,7 +548,8 @@ This example is from assignsubmission_onlinetext. For the same reason as the pre #### is_empty() {/* #is_empty */} ```php -public function is_empty(stdClass $submission) { +public function is_empty(stdClass $submission) +{ return $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA) == 0; } ``` @@ -542,7 +559,8 @@ If a plugin has no submission data to show - it can return true from the is_empt #### submission_is_empty() {/* #submission_is_empty */} ```php -public function submission_is_empty() { +public function submission_is_empty() +{ global $USER; $fs = get_file_storage(); @@ -565,7 +583,8 @@ Determine if a submission is empty. This is distinct from is_empty() in that it #### get_file_areas() {/* #get_file_areas */} ```php -public function get_file_areas() { +public function get_file_areas() +{ return [ASSIGNSUBMISSION_FILE_FILEAREA=>$this->get_name()]; } ``` @@ -575,7 +594,8 @@ A plugin should implement get_file_areas if it supports saving of any files to m #### copy_submission() {/* #copy_submission */} ```php -public function copy_submission(stdClass $sourcesubmission, stdClass $destsubmission) { +public function copy_submission(stdClass $sourcesubmission, stdClass $destsubmission) +{ global $DB; // Copy the files across. @@ -609,7 +629,8 @@ Since Moodle 2.5 - a students submission can be copied to create a new submissio #### format_for_log() {/* #format_for_log */} ```php -public function format_for_log(stdClass $submission) { +public function format_for_log(stdClass $submission) +{ // Format the information for each submission plugin add_to_log $filecount = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); return ' the number of file(s) : ' . $filecount . " file(s).
"; @@ -621,7 +642,8 @@ The format_for_log function lets a plugin produce a really short summary of a su #### delete_instance() {/* #delete_instance */} ```php -public function delete_instance() { +public function delete_instance() +{ global $DB; // Will throw exception on failure $DB->delete_records('assignsubmission_file', [ diff --git a/versioned_docs/version-5.2/apis/plugintypes/availability/index.md b/versioned_docs/version-5.2/apis/plugintypes/availability/index.md index fe15d4233..19dcc032c 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/availability/index.md +++ b/versioned_docs/version-5.2/apis/plugintypes/availability/index.md @@ -83,12 +83,14 @@ Here's an outline of the code (with standard PHPdoc comments omitted to save spa // You must use the right namespace (matching your plugin component name). namespace availability_name; -class condition extends \core_availability\condition { +class condition extends \core_availability\condition +{ // Any data associated with the condition can be stored in member // variables. Here's an example variable: protected $allow; - public function __construct($structure) { + public function __construct($structure) + { // Retrieve any necessary data from the $structure here. The // structure is extracted from JSON data stored in the database // as part of the tree structure of conditions relating to an @@ -100,7 +102,8 @@ class condition extends \core_availability\condition { // throw a coding_exception if the structure is wrong. } - public function save() { + public function save() + { // Save back the data into a plain array similar to $structure above. return (object)array('type' => 'name', 'allow' => $this->allow); } @@ -142,7 +145,8 @@ class condition extends \core_availability\condition { return $allow ? 'Users are allowed' : 'Users not allowed'; } - protected function get_debug_string() { + protected function get_debug_string() + { // This function is only normally used for unit testing and // stuff like that. Just make a short string representation // of the values of the condition, suitable for developers. @@ -162,9 +166,11 @@ The class is required, but all the functions are theoretically optional; you can ```php namespace availability_name; -class frontend extends \core_availability\frontend { +class frontend extends \core_availability\frontend +{ - protected function get_javascript_strings() { + protected function get_javascript_strings() + { // You can return a list of names within your language file and the // system will include them here. // Should you need strings from another language file, you can also diff --git a/versioned_docs/version-5.2/apis/plugintypes/blocks/index.md b/versioned_docs/version-5.2/apis/plugintypes/blocks/index.md index bc56f7024..b42ddf26f 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/blocks/index.md +++ b/versioned_docs/version-5.2/apis/plugintypes/blocks/index.md @@ -160,7 +160,8 @@ This function is called on your subclass right after an instance is loaded. It i Example of a specialization method using the instance configuration. ```php -function specialization() { +function specialization() +{ if (isset($this->config->title)) { $this->title = format_string($this->config->title, true, ['context' => $this->context]); } else { @@ -180,11 +181,13 @@ In order to get our block to actually display something on screen, we need to ad ```php -class block_pluginname extends block_base { +class block_pluginname extends block_base +{ // (...) - public function get_content() { + public function get_content() + { if ($this->content !== null) { return $this->content; } @@ -202,11 +205,13 @@ class block_pluginname extends block_base { ```php -class block_pluginname extends block_list { +class block_pluginname extends block_list +{ // (...) - public function get_content() { + public function get_content() + { global $OUTPUT; if ($this->content !== null) { return $this->content; @@ -256,7 +261,8 @@ By default, only one instance of each block plugin can be added to a page. Howev
```php -public function instance_allow_multiple() { +public function instance_allow_multiple() +{ return true; } ``` @@ -279,7 +285,8 @@ Using this method each block instance can decide if the standard block header is
```php -public function hide_header() { +public function hide_header() +{ return true; } ``` @@ -298,7 +305,8 @@ By default, each block section in the page will use a standard `block` class and
```php -public function html_attributes() { +public function html_attributes() +{ // Get default values. $attributes = parent::html_attributes(); // Append our class to class attribute. @@ -351,7 +359,8 @@ However, for some cases like the Atto HTML editor, you may want to store them in
```php title="Example of adding data before storing it -public function instance_config_save($data,$nolongerused =false) { +public function instance_config_save($data,$nolongerused =false) +{ // Example of add new data. $data->somenewattribute = 'Some new value'; @@ -393,7 +402,8 @@ While in other Moodle pulgins the existence of a settings.php is enough to enabl
```php" -function has_config() { +function has_config() +{ return true; } ``` @@ -421,7 +431,8 @@ Each page in Moodle can define it's own page type name. However, there are some
```php -public function applicable_formats() { +public function applicable_formats() +{ return [ 'admin' => false, 'site-index' => false, diff --git a/versioned_docs/version-5.2/apis/plugintypes/enrol/index.md b/versioned_docs/version-5.2/apis/plugintypes/enrol/index.md index bd2695079..da1a3c56d 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/enrol/index.md +++ b/versioned_docs/version-5.2/apis/plugintypes/enrol/index.md @@ -151,7 +151,8 @@ By default, all enrolment plugins will have *editing enrolment* and *user unenro * @param stdClass $userenrolment * @return array An array of user_enrolment_actions */ -public function get_user_enrolment_actions(course_enrolment_manager $manager, $userenrolment) { +public function get_user_enrolment_actions(course_enrolment_manager $manager, $userenrolment) +{ $actions = parent::get_user_enrolment_actions($manager, $userenrolment); $context = $manager->get_context(); $instance = $userenrolment->enrolmentinstance; @@ -191,7 +192,8 @@ The unenrol action will allow resetif all following conditions are met:
```php -public function allow_unenrol(stdClass $instance) { +public function allow_unenrol(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -224,7 +226,8 @@ The unenrol action will be displayed if all following conditions are met:
```php -public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) { +public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) +{ // Add any extra validation here. return true; } @@ -241,7 +244,8 @@ It is quite common in enrolment plugins to allow unenrol only if the user enrolm
```php -public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) { +public function allow_unenrol_user(stdClass $instance, stdClass $userenrolment) +{ if ($userenrolment->status == ENROL_USER_SUSPENDED) { return true; } @@ -270,7 +274,8 @@ The edit manual enrolment action will be displayed if if all following condition
```php -public function allow_enrol(stdClass $instance) { +public function allow_enrol(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -343,7 +348,8 @@ The edit enrolment action in the participants list will be displayed if if all f
```php -public function allow_manage(stdClass $instance) { +public function allow_manage(stdClass $instance) +{ // Add any extra validation here. return true; } @@ -363,7 +369,8 @@ Enrolment plugins can protect roles from being modified by any other plugin. Ret
```php -public function roles_protected() { +public function roles_protected() +{ // Add any extra validation here if necessary. return false; } @@ -393,7 +400,8 @@ The only exception is *enrol_self* - although it is not possible to uniquely ide
```php -public function find_instance(array $enrolmentdata, int $courseid) : ?stdClass { +public function find_instance(array $enrolmentdata, int $courseid) : ?stdClass +{ global $DB; $instances = enrol_get_instances($courseid, false); diff --git a/versioned_docs/version-5.2/apis/plugintypes/fileconverter/index.md b/versioned_docs/version-5.2/apis/plugintypes/fileconverter/index.md index e2d7464a6..daedef81a 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/fileconverter/index.md +++ b/versioned_docs/version-5.2/apis/plugintypes/fileconverter/index.md @@ -54,7 +54,8 @@ This function informs the File Converter API whether the system requirements of It should be lightweight to call and cache where required. ```php title="Example implementation" -public static function are_requirements_met() { +public static function are_requirements_met() +{ return extension_loaded('my_php_extension'); } ``` @@ -72,9 +73,11 @@ The `start_document_conversion()` function starts a conversion, whilst `poll_con This function allows the plugin to answer whether it supports conversion between two formats. It is typically only used internally by the File Conversion subsystem. ```php title="Example implementation" -class converter implements \core_files\converter_interface { +class converter implements \core_files\converter_interface +{ // ... - public static function supports($from, $to) { + public static function supports($from, $to) + { // This plugin supports conversion from doc and docx to pdf only. if ($from !== 'doc' && $from !== 'docx') { return false; diff --git a/versioned_docs/version-5.2/apis/plugintypes/filter/index.md b/versioned_docs/version-5.2/apis/plugintypes/filter/index.md index 70c2dbbde..81afdeaf7 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/filter/index.md +++ b/versioned_docs/version-5.2/apis/plugintypes/filter/index.md @@ -107,7 +107,8 @@ If a filter uses a special syntax or it is based on an appearance of a substring /** * Example of a filter that uses links in some way. */ -public function filter($text, array $options = []) { +public function filter($text, array $options = []) +{ if (!is_string($text) or empty($text)) { // Non-string data can not be filtered anyway. @@ -138,8 +139,10 @@ To support this behaviour, a filter plugin must provide a `filterlocalsettings.p
```php title="filterlocalsettings.php" -class pluginfile_filter_local_settings_form extends \core_filters\form\local_settings_form { - protected function definition_inner(\MoodleQuickForm $mform) { +class pluginfile_filter_local_settings_form extends \core_filters\form\local_settings_form +{ + protected function definition_inner(\MoodleQuickForm $mform) + { $mform->addElement( 'text', 'word', @@ -164,8 +167,10 @@ All the local configurations can be accessed in the main filter class in the `$t localconfig['word'] ?? 'default'; diff --git a/versioned_docs/version-5.2/apis/plugintypes/format/index.md b/versioned_docs/version-5.2/apis/plugintypes/format/index.md index 3778531ea..ac48c35a0 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/format/index.md +++ b/versioned_docs/version-5.2/apis/plugintypes/format/index.md @@ -531,8 +531,10 @@ In the example the extra output classes can look like: dirroot . '/mod/forum/lib.php'); @@ -803,9 +814,11 @@ This feature has been implemented by: ```php title="mod/resource/classes/output/courseformat/activitybadge.php" namespace mod_resource\output\courseformat; - class activitybadge extends \core_courseformat\output\activitybadge { + class activitybadge extends \core_courseformat\output\activitybadge + { - protected function update_content(): void { + protected function update_content(): void + { $options = (object) ['displayoptions' => $this->cminfo->customdata['displayoptions']]; $this->content = resource_get_optional_filetype($options, $this->cminfo); } diff --git a/versioned_docs/version-5.2/apis/plugintypes/mod/_files/lib_description.md b/versioned_docs/version-5.2/apis/plugintypes/mod/_files/lib_description.md index 6615a48be..667d074f2 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/mod/_files/lib_description.md +++ b/versioned_docs/version-5.2/apis/plugintypes/mod/_files/lib_description.md @@ -41,7 +41,8 @@ Each feature is identified by a constant, which is defined in the `lib
```php -function [modname]_supports($feature) { +function [modname]_supports($feature) +{ return match ($feature) { FEATURE_GROUPS => true, FEATURE_GROUPINGS => true, @@ -70,7 +71,8 @@ Optionally, if your plugin fits in a secondary purpose, you should add the `FEAT
```php -function [modname]_supports(string $feature) { +function [modname]_supports(string $feature) +{ return match ($feature) { // The rest of features should be listed here... FEATURE_MOD_PURPOSE => MOD_PURPOSE_COLLABORATION, diff --git a/versioned_docs/version-5.2/apis/plugintypes/mod/courseoverview.md b/versioned_docs/version-5.2/apis/plugintypes/mod/courseoverview.md index 9577a60f8..06ac10b83 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/mod/courseoverview.md +++ b/versioned_docs/version-5.2/apis/plugintypes/mod/courseoverview.md @@ -30,7 +30,8 @@ namespace mod_PLUGINNAME\courseformat; use core_courseformat\activityoverviewbase; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ // Implement methods here. } ``` @@ -65,9 +66,11 @@ use core_courseformat\activityoverviewbase; use core_courseformat\local\overview\overviewitem; use core\output\pix_icon; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ #[\Override] - public function get_extra_overview_items(): array { + public function get_extra_overview_items(): array + { return [ 'submitted' => $this->get_extra_submitted_overview(), ]; @@ -78,7 +81,8 @@ class overview extends activityoverviewbase { * * @return overviewitem|null */ - private function get_extra_submitted_overview(): ?overviewitem { + private function get_extra_submitted_overview(): ?overviewitem + { // Validate if the user needs this overview information. Return null otherwise. if (!has_capability('mod/PLUGINNAME:complete', $this->context)) { return null; @@ -137,9 +141,11 @@ namespace mod_PLUGINNAME\courseformat; use core_courseformat\activityoverviewbase; use core_courseformat\local\overview\overviewitem; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ #[\Override] - public function get_due_date_overview(): ?overviewitem { + public function get_due_date_overview(): ?overviewitem + { // Implement here how to get the due date of the activity. $duedate = DO_SOMETHING_TO_GET_YOUR_PLUGIN_DUE_DATE(); @@ -177,9 +183,11 @@ use core\output\action_link; use core\output\local\properties\button; use core\output\local\properties\text_align; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ #[\Override] - public function get_actions_overview(): ?overviewitem { + public function get_actions_overview(): ?overviewitem + { // Validate if the user can do the action. Return null otherwise. if (!has_capability('mod/PLUGINNAME:viewreports', $this->context)) { return null; @@ -229,7 +237,8 @@ This is an example of a plugin with two grade items: ```php #[\Override] -protected function get_grade_item_names(array $items): array { +protected function get_grade_item_names(array $items): array +{ // Add some fallback in case some grade item is missing. if (count($items) != 2) { return parent::get_grade_item_names($items); @@ -262,7 +271,8 @@ namespace mod_PLUGINNAME\courseformat; use core_course\activityoverviewbase; -class overview extends activityoverviewbase { +class overview extends activityoverviewbase +{ public function __construct( /** @var cm_info $cm the activity course module. */ cm_info $cm, diff --git a/versioned_docs/version-5.2/apis/plugintypes/mod/visibility.md b/versioned_docs/version-5.2/apis/plugintypes/mod/visibility.md index 182e57640..68efc3b24 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/mod/visibility.md +++ b/versioned_docs/version-5.2/apis/plugintypes/mod/visibility.md @@ -37,7 +37,8 @@ The course cache is only updated when somebody edits a module, so it can't be us The function should return a value of class `cached_cm_info`. For example: ```php -function mod_frog_get_coursemodule_info($cm) { +function mod_frog_get_coursemodule_info($cm) +{ $info = new cached_cm_info(); $info->content = '

This will display below the module.

'; return $info; @@ -62,7 +63,8 @@ Don't use renderers in this function (see MDL-41074). If you have data you would You can customise module display dynamically (when the page loads). For example you might want to alter it based on the permissions of the current user. ```php -function mod_frog_cm_info_dynamic(cm_info $cm) { +function mod_frog_cm_info_dynamic(cm_info $cm) +{ $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!has_capability('some/capability', $context)) { $cm->set_user_visible(false); @@ -81,7 +83,8 @@ Most things are set using functions (as above; another example would be `set_con Sometimes you need to display custom information for the current user that appears only on the course view page. For example, the forum module displays unread information on the view page. This information doesn't show on other pages (it isn't included in the navigation, for instance). ```php -function mod_frog_cm_info_view(cm_info $cm) { +function mod_frog_cm_info_view(cm_info $cm) +{ $cm->set_after_link('Last tadpole: 22:17'); } ``` @@ -106,7 +109,8 @@ $cm = $modinfo->get_cm($cmid); The cm_info objects contain additional information that is not present in the course_modules database row, such as the module's name, and the icon and associated content mentioned above. In order to distinguish these from the plain database objects, you can specify the cm_info class in a function definition: ```php -function my_clever_function(cm_info $cm) { +function my_clever_function(cm_info $cm) +{ if (!$cm->uservisible) { // The module is not visible or available to current user, // so do something clever instead. diff --git a/versioned_docs/version-5.2/apis/plugintypes/qbank/filters.md b/versioned_docs/version-5.2/apis/plugintypes/qbank/filters.md index 340c714e0..036341bdd 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/qbank/filters.md +++ b/versioned_docs/version-5.2/apis/plugintypes/qbank/filters.md @@ -37,7 +37,8 @@ namespace qbank_myplugin; use core_question\local\bank\condition; -class myfilter_condition extends condition { +class myfilter_condition extends condition +{ } ``` @@ -47,8 +48,10 @@ Modify your `plugin_feature` class to return an instance of your condition from ```php title="question/bank/myplugin/classes/plugin_feature.php" namespace qbank_myplugin; -class plugin_feature extends core_question\local\bank\plugin_features_base { - public function get_question_filters(?core_question\local\bank\view $qbank = null): array { +class plugin_feature extends core_question\local\bank\plugin_features_base +{ + public function get_question_filters(?core_question\local\bank\view $qbank = null): array + { return [ new myfilter_condition($qbank), ]; @@ -59,7 +62,8 @@ class plugin_feature extends core_question\local\bank\plugin_features_base { Back in your `condition` class, define the `get_name()` method, which returns the label displayed in the filter UI. ```php title="Define the condition name" -public function get_name(): string { +public function get_name(): string +{ return get_string('myfilter_name', 'myplugin'); } ``` @@ -67,7 +71,8 @@ public function get_name(): string { Define `get_condition_key()`, which returns a unique machine-readable ID for this filter condition, used when passing the filter as a parameter. ```php title="Define the condition key" -public function get_condition_key(): string { +public function get_condition_key(): string +{ return 'myfilter'; } ``` @@ -78,7 +83,8 @@ The `$filter` parameter receives an array with a `'values'` key, containing an a The conditions from each filter are combined with the query in [`core_question\local\bank\view::build_query()`](https://github.com/moodle/moodle/blob/c741492c38b9945abbfc7e90dfe8f943279f8265/question/classes/local/bank/view.php#L733) ```php title="Filter questions" -public function build_query_from_filter(array $filter): array { +public function build_query_from_filter(array $filter): array +{ $andor = ' AND '; $equal = '='; if ($filter['jointype'] === self::JOINTYPE_ANY) { @@ -109,7 +115,8 @@ Following this pattern with your own fields and options will give you a basic fu To define the list of possible filter values, define `get_initial_values()`, which returns an array of `['value', 'title']` for each option. These will then be searchable and selectable in the autocomplete field. ```php title="Define initial filter values" -public function get_initial_values(): string { +public function get_initial_values(): string +{ return [ [ 'value' => 0, @@ -128,7 +135,8 @@ public function get_initial_values(): string { To restrict the possible filter terms to only those returned from `get_initial_values()`, define `allow_custom()` and have it return `false`. ```php title="Disable custom terms" -public function allow_custom(): bool { +public function allow_custom(): bool +{ return false; } ``` @@ -138,7 +146,8 @@ public function allow_custom(): bool { Not all join types are relevant to all filters. If each question will only match one of the selected values, it does not make sense to allow `JOINTYPE_ALL`. Define `get_join_list()` and return an array of the applicable join types. ```php title="Define a restricted list of join types" -public function get_join_list(): array { +public function get_join_list(): array +{ return [ datafilter::JOINTYPE_ANY, datafilter::JOINTYPE_NONE, @@ -152,7 +161,8 @@ By default, conditions allow multiple values to be selected and use the selected If your condition should only allow a single value at a time, override `allow_multiple()` to return false. ```php title="Disable selection of multiple values" -public function allow_multiple(): bool { +public function allow_multiple(): bool +{ return false; } ``` @@ -162,7 +172,8 @@ public function allow_multiple(): bool { By default, conditions can be left empty, and therefore will not be included in the filter. To make it compulsory to select a value for this condition when it is added, override `allow_empty()` to return false. ```php title="Disable empty values" -public function allow_empty(): bool { +public function allow_empty(): bool +{ return false; } ``` @@ -172,7 +183,8 @@ public function allow_empty(): bool { If it is compulsory that your condition is always displayed, override `is_required()` to return true. ```php title="Make the condition compulsory" -public function is_required(): bool { +public function is_required(): bool +{ return true; } ``` @@ -188,7 +200,8 @@ You can either use a different core filter type from `/lib/amd/src/datafilter/fi To tell your filter condition to use a different filter class, override the `get_filter_class()` method to return the namespaced path to your JavaScript class. ```php title="Override the default filter class" -public function get_filter_class(): string { +public function get_filter_class(): string +{ return 'qbank_myplugin/datafilter/filtertype/myfilter'; } ``` diff --git a/versioned_docs/version-5.2/apis/plugintypes/qtype/newquestiondefaults.md b/versioned_docs/version-5.2/apis/plugintypes/qtype/newquestiondefaults.md index c34ce0a02..fb8d4be87 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/qtype/newquestiondefaults.md +++ b/versioned_docs/version-5.2/apis/plugintypes/qtype/newquestiondefaults.md @@ -41,7 +41,8 @@ $mform->setDefault('shuffleanswers', $this->get_default_value('shuffleanswers', Here we need to override the method `save_defaults_for_new_questions` to save the values these settings. For example: ```php - public function save_defaults_for_new_questions(stdClass $fromform): void { + public function save_defaults_for_new_questions(stdClass $fromform): void + { parent::save_defaults_for_new_questions($fromform); $this->set_default_value('shuffleanswers', $fromform->shuffleanswers); } diff --git a/versioned_docs/version-5.2/apis/plugintypes/qtype/restore.md b/versioned_docs/version-5.2/apis/plugintypes/qtype/restore.md index 845357130..ee30b631e 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/qtype/restore.md +++ b/versioned_docs/version-5.2/apis/plugintypes/qtype/restore.md @@ -83,7 +83,8 @@ an array of fields to remove from the `$questiondata` structure. For example, i records with the fields `id`, `questionid` and `data`, you might need to define the following: ```php title="question/type/example/backup/moodle2/restore_qtype_example_plugin.class.php" -protected function define_excluded_identity_hash_fields(): array { +protected function define_excluded_identity_hash_fields(): array +{ return [ '/options/extradata/id', '/options/extradata/questionid', @@ -102,7 +103,8 @@ additional data, then passes `$questiondata` on to the parent method. For exampl setting at `$questiondata->options->pluginconfig`, you might need to define the following: ```php title="question/type/example/backup/moodle2/restore_qtype_example_plugin.class.php" -public static function remove_excluded_question_data(stdClass $questiondata, array $excludefields = []): stdClass { +public static function remove_excluded_question_data(stdClass $questiondata, array $excludefields = []): stdClass +{ if (isset($questiondata->options->pluginconfig)) { unset($questiondata->options->pluginconfig); } diff --git a/versioned_docs/version-5.2/apis/plugintypes/repository/index.md b/versioned_docs/version-5.2/apis/plugintypes/repository/index.md index 0e940f7ab..c23a86a16 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/repository/index.md +++ b/versioned_docs/version-5.2/apis/plugintypes/repository/index.md @@ -122,7 +122,8 @@ Return any combination of the following values: ```php -function supported_returntypes() { +function supported_returntypes() +{ return FILE_INTERNAL | FILE_EXTERNAL | FILE_REFERENCE | FILE_CONTROLLED_LINK; } ``` @@ -151,7 +152,8 @@ Supported file types can be specified using standard mimetypes (such as `image/g ```php -function supported_filetypes() { +function supported_filetypes() +{ // Allow any kind of file. return '*'; } @@ -161,7 +163,8 @@ function supported_filetypes() { ```php -function supported_filetypes() { +function supported_filetypes() +{ // Example of image mimetypes. return ['image/gif', 'image/jpeg', 'image/png']; } @@ -171,7 +174,8 @@ function supported_filetypes() { ```php -function supported_filetypes() { +function supported_filetypes() +{ // Example of a file group. return ['web_image']; } @@ -204,7 +208,8 @@ Parent function returns an array with a single item - pluginname.
```php -public static function get_type_option_names() { +public static function get_type_option_names() +{ return array_merge(parent::get_type_option_names(), ['rootpath']); } ``` @@ -225,7 +230,8 @@ Optional. This is for modifying the Moodle form displaying the plugin settings. For example, to display the standard repository plugin settings along with the custom ones use: ```php -public static function type_config_form($mform, $classname='repository') { +public static function type_config_form($mform, $classname='repository') +{ parent::type_config_form($mform); $rootpath = get_config('repository_pluginname', 'rootpath'); @@ -244,7 +250,8 @@ This function must be declared static Optional. Use this function if you need to validate some variables submitted by plugin settings form. To use it, check through the associative array of data provided ('settingname' => value) for any errors. Then push the items to $error array in the format ("fieldname" => "human readable error message") to have them highlighted in the form. ```php -public static function type_form_validation($mform, $data, $errors) { +public static function type_form_validation($mform, $data, $errors) +{ if (!is_dir($data['rootpath'])) { $errors['rootpath'] = get_string('invalidrootpath', 'repository_pluginname'); } @@ -271,7 +278,8 @@ Parent function returns an empty array. This is equivalent to **get_type_option_
```php -public static function get_instance_option_names() { +public static function get_instance_option_names() +{ return ['fs_path']; // From repository_filesystem } ``` @@ -292,7 +300,8 @@ Optional. This is for modifying the Moodle form displaying the settings specific For example, to add a required text box called email_address: ```php -public static function get_instance_option_names() { +public static function get_instance_option_names() +{ $mform->addElement( 'text', 'email_address', @@ -318,7 +327,8 @@ This function must be declared static Optional. This allows us to validate what has been submitted in the instance configuration form. This is equivalent to ''type_form_validation($mform, $data, $errors), but for instances. For example: ```php -public static function instance_form_validation($mform, $data, $errors) { +public static function instance_form_validation($mform, $data, $errors) +{ if (empty($data['email_address'])) { $errors['email_address'] = get_string('invalidemailsettingname', 'repository_flickr_public'); } @@ -357,7 +367,8 @@ Firstly the skeleton: * * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ -class repository_flickr_public extends repository { +class repository_flickr_public extends repository +{ } ``` @@ -453,7 +464,8 @@ This function will return a list of files to be displayed to the user, the list * @param string $page * @return array the list of files, including meta information */ -public function get_listing($encodedpath = '', $page = '') { +public function get_listing($encodedpath = '', $page = '') +{ // This methods return [ //this will be used to build navigation bar. @@ -578,7 +590,8 @@ For plugins that do not fully process the login via a popup window, the submitte
```php title="lib/alfresco/lib.php" -public function __construct($repositoryid, $context = SYSCONTEXTID, $options = []) { +public function __construct($repositoryid, $context = SYSCONTEXTID, $options = []) +{ global $SESSION; /* Skipping code that is not relevant to user login */ @@ -618,7 +631,8 @@ Many types include a single element of type 'popup' with the param 'url' pointin
```php title="Code taken from repository_boxnet" -public function print_login() { +public function print_login() +{ $ticket = $this->boxclient->getTicket(); if ($this->options['ajax']) { $loginbtn = (object)[ @@ -652,7 +666,8 @@ This function will return a boolean value to tell Moodle whether the user has lo By default, this function will return true. ```php -public function check_login(): bool { +public function check_login(): bool +{ global $SESSION; return !empty($SESSION->{$this->sessname}); } @@ -663,7 +678,8 @@ public function check_login(): bool { When a user clicks the logout button in file picker, this function will be called. You may clean up the session or disconnect the connection with remote server here. After this the code should return something suitable to display to the user (usually the results of calling **$this->print_login()**): ```php title="lib/alfresco/lib.php" -public function logout() { +public function logout() +{ global $SESSION; unset($SESSION->{$this->sessname}); return $this->print_login(); @@ -689,7 +705,8 @@ For FILE_INTERNAL or FILE_REFERENCE this function is called at the point when th ```php -public function get_file($url, $filename = '') { +public function get_file($url, $filename = '') +{ // Default implementation from the base 'repository' class $path = $this->prepare_file($filename); // Generate a unique temporary filename $curlobject = new curl(); @@ -707,7 +724,8 @@ public function get_file($url, $filename = '') { Slightly extended version taken from repository_equella ```php -public function get_file($reference, $filename = '') { +public function get_file($reference, $filename = '') +{ global $USER; // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference->reference)); @@ -768,7 +786,8 @@ A custom search form must include the following:
```php title="The default implementation in class 'repository'" -public function print_search() { +public function print_search() +{ global $PAGE; $renderer = $PAGE->get_renderer('core', 'files'); return $renderer->repository_default_searchform(); @@ -793,7 +812,8 @@ The return should return an array containing:
```php title="Example from repoistory_googledocs" -public function search($search_text, $page = 0) { +public function search($search_text, $page = 0) +{ $gdocs = new google_docs($this->googleoauth); return [ 'dynload' => true, @@ -822,7 +842,8 @@ Note that external file is synchronised by moodle when UI wants to show the file Return minimum number of seconds before checking for changes to the file (default implementation = 1 day) ```php -public function get_reference_file_lifetime($ref) { +public function get_reference_file_lifetime($ref) +{ return DAYSECS; // One day, 60 * 60 * 24 seconds. } ``` @@ -832,7 +853,8 @@ public function get_reference_file_lifetime($ref) { Called after the file has reached the 'lifetime' specified above to see if it should now be synchronised (default implementation is to return true) ```php -public function sync_individual_file(stored_file $storedfile) { +public function sync_individual_file(stored_file $storedfile) +{ return true; } ``` @@ -851,7 +873,8 @@ This is usually prefixed with the repository name, and a semicolon. For example:
```php title="lib.php" -public function get_reference_details($reference, $filestatus = 0) { +public function get_reference_details($reference, $filestatus = 0) +{ if (!$filestatus) { // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference); @@ -879,7 +902,8 @@ Returns up-to-date information about the original file, only called when the 'li
```php title="/lib.php" -public function get_file_by_reference($reference) { +public function get_file_by_reference($reference) +{ global $USER; // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($reference->reference)); @@ -946,7 +970,8 @@ It is up to the repository developer to decide whether to actually download the
```php title="/lib.php" -public function send_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) { +public function send_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, array $options = null) +{ // Replace the line below by any method your plugin have to check a reference. $details = example_external_server::get_details_by_reference($stored_file->get_reference())); $url = $this->appendtoken($details->url); diff --git a/versioned_docs/version-5.2/apis/plugintypes/sms/index.md b/versioned_docs/version-5.2/apis/plugintypes/sms/index.md index 1e9235bff..8baec2ec7 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/sms/index.md +++ b/versioned_docs/version-5.2/apis/plugintypes/sms/index.md @@ -65,7 +65,8 @@ namespace smsgateway_aws; use smsgateway_aws\local\service\aws_sns; -class gateway extends \core_sms\gateway { +class gateway extends \core_sms\gateway +{ #[\Override] public function send( message $message, @@ -95,7 +96,8 @@ class gateway extends \core_sms\gateway { ); } - private function get_gateway_service(\stdClass $config): string { + private function get_gateway_service(\stdClass $config): string + { return match ($config->gateway) { 'aws_sns' => aws_sns::class, default => throw new moodle_exception("Unknown Message Handler {$config->gateway}"), @@ -103,7 +105,8 @@ class gateway extends \core_sms\gateway { } #[\Override] - public function get_send_priority(message $message): int { + public function get_send_priority(message $message): int + { return 50; } } @@ -120,7 +123,8 @@ It is necessary for plugins developers to assess these hooks and implement accor This hook will allow plugins to add required form fields to assist users in configuring their SMS gateway. ```php title="Listener method for after_sms_gateway_form_hook" -public static function set_form_definition_for_aws_sms_gateway(after_sms_gateway_form_hook $hook): void { +public static function set_form_definition_for_aws_sms_gateway(after_sms_gateway_form_hook $hook): void +{ if ($hook->plugin !== 'smsgateway_example') { return; } diff --git a/versioned_docs/version-5.2/apis/plugintypes/theme/index.md b/versioned_docs/version-5.2/apis/plugintypes/theme/index.md index 371b703c4..c3cd0b8b0 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/theme/index.md +++ b/versioned_docs/version-5.2/apis/plugintypes/theme/index.md @@ -108,7 +108,8 @@ $THEME->sheets = []; $THEME->editor_sheets = []; $THEME->editor_scss = ['editor']; $THEME->usefallback = true; -$THEME->scss = function($theme) { +$THEME->scss = function($theme) +{ return theme_boost_get_main_scss_content($theme); }; diff --git a/versioned_docs/version-5.2/apis/plugintypes/tiny/index.md b/versioned_docs/version-5.2/apis/plugintypes/tiny/index.md index 831f0cfef..38dbd3cbe 100644 --- a/versioned_docs/version-5.2/apis/plugintypes/tiny/index.md +++ b/versioned_docs/version-5.2/apis/plugintypes/tiny/index.md @@ -398,7 +398,8 @@ use context; use editor_tiny\plugin; use editor_tiny\plugin_with_configuration; -class plugininfo extends plugin implements plugin_with_configuration { +class plugininfo extends plugin implements plugin_with_configuration +{ public static function get_plugin_configuration_for_context( context $context, array $options, diff --git a/versioned_docs/version-5.2/apis/subsystems/access.md b/versioned_docs/version-5.2/apis/subsystems/access.md index 06ea7efeb..d0b39391d 100644 --- a/versioned_docs/version-5.2/apis/subsystems/access.md +++ b/versioned_docs/version-5.2/apis/subsystems/access.md @@ -167,7 +167,8 @@ By default checks the capabilities of the current user, but you can pass a diffe Function require_capability() is very similar, it is throwing access control exception if user does not have the capability. ```php -function require_capability($capability, context $context, $userid = null, $doanything = true, $errormessage = 'nopermissions', $stringfile = _) { +function require_capability($capability, context $context, $userid = null, $doanything = true, $errormessage = 'nopermissions', $stringfile = _) +{ ``` ### Enrolment functions {/* #enrolment-functions */} diff --git a/versioned_docs/version-5.2/apis/subsystems/ai/index.md b/versioned_docs/version-5.2/apis/subsystems/ai/index.md index 8f6f7a0cd..d2e63732e 100644 --- a/versioned_docs/version-5.2/apis/subsystems/ai/index.md +++ b/versioned_docs/version-5.2/apis/subsystems/ai/index.md @@ -162,7 +162,8 @@ public function __construct( ```php title="Example: The store() method for the generate_image Action" #[\Override] -public function store(response_base $response): int { +public function store(response_base $response): int +{ global $DB; $responsearr = $response->get_response_data(); @@ -225,7 +226,8 @@ it sets these against class variables so they can be retrieved by the Manager an ```php title="Example: The set_response_data() for the generate_image Action response" #[\Override] - public function set_response_data(array $response): void { + public function set_response_data(array $response): void + { $this->draftfile = $response['draftfile'] ?? null; $this->revisedprompt = $response['revisedprompt'] ?? null; $this->sourceurl = $response['sourceurl'] ?? null; @@ -238,7 +240,8 @@ Returns the set response data. ```php title="Example: The get_response_data() for the generate_image Action response" #[\Override] - public function get_response_data(): array { + public function get_response_data(): array + { return [ 'draftfile' => $this->draftfile, 'revisedprompt' => $this->revisedprompt, diff --git a/versioned_docs/version-5.2/apis/subsystems/analytics/index.md b/versioned_docs/version-5.2/apis/subsystems/analytics/index.md index 1f4c3e3e7..20b1eddc8 100644 --- a/versioned_docs/version-5.2/apis/subsystems/analytics/index.md +++ b/versioned_docs/version-5.2/apis/subsystems/analytics/index.md @@ -378,7 +378,8 @@ You can overwrite a `new one_sample_per_analysable()` method if the analysables * * @return bool */ -public static function one_sample_per_analysable() { +public static function one_sample_per_analysable() +{ return true; } ``` @@ -398,7 +399,8 @@ You can use `required_sample_data` to specify what your indicator needs to be ca * * @return null|string[] Name of the required elements (use the database tablename) */ -public static function required_sample_data() { +public static function required_sample_data() +{ return null; } ``` diff --git a/versioned_docs/version-5.2/apis/subsystems/backup/index.md b/versioned_docs/version-5.2/apis/subsystems/backup/index.md index 95245f909..10089ab62 100644 --- a/versioned_docs/version-5.2/apis/subsystems/backup/index.md +++ b/versioned_docs/version-5.2/apis/subsystems/backup/index.md @@ -95,9 +95,11 @@ Here is a minimalistic task: ```php require_once($CFG->dirroot . '/backup/moodle2/backup_tool_plugin.class.php'); -class backup_tool_foobar_plugin extends backup_tool_plugin { +class backup_tool_foobar_plugin extends backup_tool_plugin +{ - protected function define_course_plugin_structure() { + protected function define_course_plugin_structure() + { $this->step->log('Yay, backup!', backup::LOG_DEBUG); return $plugin; } diff --git a/versioned_docs/version-5.2/apis/subsystems/backup/restore.md b/versioned_docs/version-5.2/apis/subsystems/backup/restore.md index 16aca9f2a..cf5ee2123 100644 --- a/versioned_docs/version-5.2/apis/subsystems/backup/restore.md +++ b/versioned_docs/version-5.2/apis/subsystems/backup/restore.md @@ -41,9 +41,11 @@ Here is a minimalistic task: ```php require_once($CFG->dirroot . '/backup/moodle2/restore_tool_plugin.class.php'); -class restore_tool_foobar_plugin extends restore_tool_plugin { +class restore_tool_foobar_plugin extends restore_tool_plugin +{ - protected function define_course_plugin_structure() { + protected function define_course_plugin_structure() + { $paths = array(); $this->step->log('Yay, restore!', backup::LOG_DEBUG); return $paths; diff --git a/versioned_docs/version-5.2/apis/subsystems/check/index.md b/versioned_docs/version-5.2/apis/subsystems/check/index.md index 51b97ca38..5fbc14021 100644 --- a/versioned_docs/version-5.2/apis/subsystems/check/index.md +++ b/versioned_docs/version-5.2/apis/subsystems/check/index.md @@ -103,14 +103,17 @@ namespace mod_myplugin\check; use core\check\check; use core\check\result; -class foobar extends check { +class foobar extends check +{ - public function get_action_link(): ?\action_link { + public function get_action_link(): ?\action_link + { $url = new \moodle_url('/mod/myplugin/dosomething.php'); return new \action_link($url, get_string('sitepolicies', 'admin')); } - public function get_result(): result { + public function get_result(): result + { if (some_check()) { $status = result::ERROR; $summary = get_string('check_foobar_error', 'mod_myplugin'); @@ -145,7 +148,8 @@ Next decide on what type of check it should be which determines what report it w Implement the right callback in lib.php for the report you want to add it to, and return an array (usually with only 1 item) of check objects: ```php title="/mod/myplugin/lib.php" -function mod_myplugin_security_checks(): array { +function mod_myplugin_security_checks(): array +{ return [new \mod_myplugin\check\foobar()]; } ``` @@ -157,7 +161,8 @@ Checks have been designed to be dynamic so you can return different checks depen If you plan to return multiple instances of a check class, make sure that each instance has a unique id. ```php -function mod_myplugin_security_checks(): array { +function mod_myplugin_security_checks(): array +{ return [ new \mod_myplugin\check\foobar('one'), new \mod_myplugin\check\foobar('two'), @@ -170,14 +175,17 @@ Set the internal id in a way which is unique across all instances in your compon ```php namespace mod_myplugin\check; -class foobar extends \core\check\check { +class foobar extends \core\check\check +{ protected $id = ''; - public function __construct($id) { + public function __construct($id) + { $this->id = "foobar{$id}"; } - public function get_id(): string { + public function get_id(): string + { return $this->id; } ... @@ -197,17 +205,21 @@ Checks can provide details on a check, such as the complete list of bad records. namespace mod_myplugin\check; -class foobar extends \core\check\check { - public function get_result(): result { +class foobar extends \core\check\check +{ + public function get_result(): result + { return new foobar_result(); } } ``` ```php -class foobar_result extends \core\check\result { +class foobar_result extends \core\check\result +{ ... - public function get_details(): string { + public function get_details(): string + { // Do expensive lookups in here. } } diff --git a/versioned_docs/version-5.2/apis/subsystems/communication/index.md b/versioned_docs/version-5.2/apis/subsystems/communication/index.md index b1107afd4..36697cea8 100644 --- a/versioned_docs/version-5.2/apis/subsystems/communication/index.md +++ b/versioned_docs/version-5.2/apis/subsystems/communication/index.md @@ -291,8 +291,10 @@ This method accepts the following parameters: For example, we have a form where we want to have the communication settings, we can use the below code to add the form elements to the form. ```php -class configure_form extends \moodleform { - public function definition() { +class configure_form extends \moodleform +{ + public function definition() + { $mform = $this->_form; $communication = \core_communication\api::load_by_instance( context: $context, diff --git a/versioned_docs/version-5.2/apis/subsystems/external/files.md b/versioned_docs/version-5.2/apis/subsystems/external/files.md index 627d27648..4eb1fbf23 100644 --- a/versioned_docs/version-5.2/apis/subsystems/external/files.md +++ b/versioned_docs/version-5.2/apis/subsystems/external/files.md @@ -119,7 +119,8 @@ $forum->introfiles = external_util::get_area_files($context->id, 'mod_forum', 'i You can also use the `external_files` structure definition in combination with the method to return the most common file fields required by WS clients. ```php -public static function execute_returns(): external_multiple_structure { +public static function execute_returns(): external_multiple_structure +{ return new external_multiple_structure( new external_single_structure([ 'id' => new external_value(PARAM_INT, 'Forum id'), diff --git a/versioned_docs/version-5.2/apis/subsystems/external/functions.md b/versioned_docs/version-5.2/apis/subsystems/external/functions.md index 295a3cca0..617f40ba8 100644 --- a/versioned_docs/version-5.2/apis/subsystems/external/functions.md +++ b/versioned_docs/version-5.2/apis/subsystems/external/functions.md @@ -65,8 +65,10 @@ use core_external\external_multiple_structure; use core_external\external_single_structure; use core_external\external_value; -class create_groups extends \core_external\external_api { - public static function execute_parameters(): external_function_parameters { +class create_groups extends \core_external\external_api +{ + public static function execute_parameters(): external_function_parameters + { return new external_function_parameters([ 'groups' => new external_multiple_structure( new external_single_structure([ @@ -92,7 +94,8 @@ class create_groups extends \core_external\external_api { ]); } - public static function execute(array $groups): array { + public static function execute(array $groups): array + { // Validate all of the parameters. [ 'groups' => $groups, @@ -114,7 +117,8 @@ class create_groups extends \core_external\external_api { ]; } - public static function execute_returns(): external_single_structure { + public static function execute_returns(): external_single_structure + { return new external_single_structure([ 'groups' => new external_multiple_structure([ 'id' => new external_value(PARAM_INT, 'Id of the created user'), diff --git a/versioned_docs/version-5.2/apis/subsystems/external/security.md b/versioned_docs/version-5.2/apis/subsystems/external/security.md index b6c0cc685..2d9a721e3 100644 --- a/versioned_docs/version-5.2/apis/subsystems/external/security.md +++ b/versioned_docs/version-5.2/apis/subsystems/external/security.md @@ -22,7 +22,8 @@ To do so you should call the `validate_parameters()` function, passing in the re The `validate_parameters()` function is defined on the `\core_external\external_api` class, and can be called as follows: ```php title="local/groupmanager/classes/external/create_groups.php" -public static function execute(array $groups): array { +public static function execute(array $groups): array +{ [ 'groups' => $groups, ] = self::validate_parameters(self::execute_parameters(), [ @@ -45,7 +46,8 @@ If your function operates on multiple contexts (like a list of courses), you mus The `validate_context()` function is defined on the `\core_external\external_api` class, and can be called as follows: ```php title="local/groupmanager/classes/external/create_groups.php" -public static function execute(array $groups): array { +public static function execute(array $groups): array +{ // ... foreach ($groups as $group) { $coursecontext = \context_course::instance($group['courseid']); diff --git a/versioned_docs/version-5.2/apis/subsystems/external/testing.md b/versioned_docs/version-5.2/apis/subsystems/external/testing.md index 8277a6dc9..ab5acac24 100644 --- a/versioned_docs/version-5.2/apis/subsystems/external/testing.md +++ b/versioned_docs/version-5.2/apis/subsystems/external/testing.md @@ -57,14 +57,16 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/webservice/tests/helpers.php'); -class get_fruit_test extends externallib_advanced_testcase { +class get_fruit_test extends externallib_advanced_testcase +{ /** * Test the execute function when capabilities are present. * * @covers \mod_fruit\external\get_fruit::execute */ - public function test_capabilities(): void { + public function test_capabilities(): void + { $this->resetAfterTest(true); $course = $this->getDataGenerator()->create_course(); @@ -99,7 +101,8 @@ class get_fruit_test extends externallib_advanced_testcase { * * @covers \mod_fruit\external\get_fruit::execute */ - public function test_capabilities_missing(): void { + public function test_capabilities_missing(): void + { global $USER; $this->resetAfterTest(true); diff --git a/versioned_docs/version-5.2/apis/subsystems/external/writing-a-service.md b/versioned_docs/version-5.2/apis/subsystems/external/writing-a-service.md index ff27b17c1..87aa9a1a3 100644 --- a/versioned_docs/version-5.2/apis/subsystems/external/writing-a-service.md +++ b/versioned_docs/version-5.2/apis/subsystems/external/writing-a-service.md @@ -150,13 +150,15 @@ use core_external\external_multiple_structure; use core_external\external_single_structure; use core_external\external_value; -class create_groups extends \core_external\external_api { +class create_groups extends \core_external\external_api +{ /** * Returns description of method parameters * @return external_function_parameters */ - public static function execute_parameters() { + public static function execute_parameters() + { return new external_function_parameters([ 'groups' => new external_multiple_structure( new external_single_structure([ @@ -187,7 +189,8 @@ A web service function without parameters will have a parameter description func * Returns description of method parameters * @return external_function_parameters */ -public static function execute_parameters(): external_function_parameters { +public static function execute_parameters(): external_function_parameters +{ return new external_function_parameters([ // If this function had any parameters, they would be described here. // This example has no parameters, so the array is empty. @@ -208,7 +211,8 @@ Our `create_groups()` function expects one parameter named `groups`, so we will * Returns description of method parameters * @return external_function_parameters */ -public static function execute_parameters(): external_function_parameters { +public static function execute_parameters(): external_function_parameters +{ return new external_function_parameters([ 'groups' => ... ]); @@ -280,7 +284,8 @@ We add them to the description : It's similar to execute_parameters(), but instead of describing the parameters, it describes the return values. ```php -public static function execute_returns() { +public static function execute_returns() +{ return new external_multiple_structure( new external_single_structure([ 'id' => new external_value(PARAM_INT, 'group record id'), @@ -312,7 +317,8 @@ Because some web service protocols are strict about the number and types of argu ```php -public static function get_biscuit_parameters() { +public static function get_biscuit_parameters() +{ return new external_function_parameters([ 'chocolatechips' => new external_value( PARAM_BOOL, @@ -340,7 +346,8 @@ public static function get_biscuit_parameters() { ```php -public static function get_biscuit_parameters() { +public static function get_biscuit_parameters() +{ return new external_function_parameters([ 'ifeellike' => new external_single_structure([ 'chocolatechips' => new external_value( @@ -379,7 +386,8 @@ We declared our web service function and we defined the external function parame * @param array $groups array of group description arrays (with keys groupname and courseid) * @return array of newly created groups */ - public static function execute($groups) { + public static function execute($groups) + { global $CFG, $DB; require_once("$CFG->dirroot/group/lib.php"); @@ -471,7 +479,8 @@ External functions deprecation process is slightly different from the standard d * Mark the function as deprecated. * @return bool */ - public static function execute_is_deprecated() { + public static function execute_is_deprecated() + { return true; } ``` diff --git a/versioned_docs/version-5.2/apis/subsystems/files/browsing.md b/versioned_docs/version-5.2/apis/subsystems/files/browsing.md index ca758d27a..ba98c974f 100644 --- a/versioned_docs/version-5.2/apis/subsystems/files/browsing.md +++ b/versioned_docs/version-5.2/apis/subsystems/files/browsing.md @@ -12,7 +12,8 @@ The File Browser API is a supplemental API which can be used to fetch informatio This example demonstrates using the `filebrowser` API to fetch the parent folders of a file. ```php -public function get_file_breadcrumbs(\stored_file $file): ?array { +public function get_file_breadcrumbs(\stored_file $file): ?array +{ $browser = get_file_browser(); $context = get_system_context(); diff --git a/versioned_docs/version-5.2/apis/subsystems/form/advanced/checkbox-controller.md b/versioned_docs/version-5.2/apis/subsystems/form/advanced/checkbox-controller.md index 2a212175e..3f7c3961a 100644 --- a/versioned_docs/version-5.2/apis/subsystems/form/advanced/checkbox-controller.md +++ b/versioned_docs/version-5.2/apis/subsystems/form/advanced/checkbox-controller.md @@ -16,7 +16,8 @@ You can add as many groups of checkboxes as you like, as long as they are unique When adding checkboxes, you can add them in _groups_. Each group of checkboxes must have a unique integer name, for example: ```php title="classes/form/example_form.php" -public function definition(): void { +public function definition(): void +{ // These two elements are part of group 1. $mform->addElement('advcheckbox', 'test1', 'Test 1', null, ['group' => 1]); $mform->addElement('advcheckbox', 'test2', 'Test 2', null, ['group' => 1]); diff --git a/versioned_docs/version-5.2/apis/subsystems/form/index.md b/versioned_docs/version-5.2/apis/subsystems/form/index.md index 065b76e6a..6a57843ec 100644 --- a/versioned_docs/version-5.2/apis/subsystems/form/index.md +++ b/versioned_docs/version-5.2/apis/subsystems/form/index.md @@ -41,9 +41,11 @@ namespace [plugintype]_[pluginname]\form; // moodleform is defined in formslib.php require_once("$CFG->libdir/formslib.php"); -class simplehtml_form extends \moodleform { +class simplehtml_form extends \moodleform +{ // Add elements to form. - public function definition() { + public function definition() + { // A reference to the form is stored in $this->form. // A common convention is to store it in a variable, such as `$mform`. $mform = $this->_form; // Don't forget the underscore! @@ -59,7 +61,8 @@ class simplehtml_form extends \moodleform { } // Custom validation should be added here. - function validation($data, $files) { + function validation($data, $files) + { return []; } } @@ -99,12 +102,15 @@ If you wish to use the form within a block then you should consider using the re Note that the render method does the same as the display method, except returning the HTML rather than outputting it to the browser, as with above make sure you've included the file which contains the class for your Moodle form. ```php -class block_yourblock extends block_base { - public function init(){ +class block_yourblock extends block_base +{ + public function init() + { $this->title = 'Your Block'; } - public function get_content(){ + public function get_content() + { $this->content = (object) [ 'text' => '', ]; @@ -237,7 +243,8 @@ public function add_action_buttons( The `add_action_buttons` function is defined on the `moodleform` class, and not a part of `$this->_form`, for example: ```php - public function definition() { + public function definition() + { // Add your form elements here. $this->_form->addElement(...); @@ -296,7 +303,8 @@ In some cases this is not the desired behaviour, in which case the [disable_form For example: ```php -public function definition() { +public function definition() +{ // Your definition goes here. // Disable the form change checker for this form. @@ -313,7 +321,8 @@ Only header names would be accepted and added to `_shownonlyelements` array. Headers included in `_shownonlyelements` will be shown expanded in the form. The rest of the headers will be hidden. ```php -public function filter_shown_headers(array $shownonly): void { +public function filter_shown_headers(array $shownonly): void +{ $this->_shownonlyelements = []; if (empty($shownonly)) { return; diff --git a/versioned_docs/version-5.2/apis/subsystems/form/usage/index.md b/versioned_docs/version-5.2/apis/subsystems/form/usage/index.md index 0369cddb1..f1fc7de14 100644 --- a/versioned_docs/version-5.2/apis/subsystems/form/usage/index.md +++ b/versioned_docs/version-5.2/apis/subsystems/form/usage/index.md @@ -79,7 +79,8 @@ In most cases you can place this in an auto-loadable class, in which case it sho namespace mod_forum\form; -class myform extends \moodleform { +class myform extends \moodleform +{ // ... } ``` @@ -127,8 +128,10 @@ Moodle has a set of standard form elements used by all Activity modules. These a The `standard_coursemodule_elements()` function is used to add these common elements, and it should be called _before_ the standard action elements are added, for example: ```php -class mod_example_mod_form extends \moodleform_mod { - public function definition() { +class mod_example_mod_form extends \moodleform_mod +{ + public function definition() + { // Add the various form elements. $this->_form->addElement( ... ); diff --git a/versioned_docs/version-5.2/apis/subsystems/output/index.md b/versioned_docs/version-5.2/apis/subsystems/output/index.md index af2615519..acd8b8fb2 100644 --- a/versioned_docs/version-5.2/apis/subsystems/output/index.md +++ b/versioned_docs/version-5.2/apis/subsystems/output/index.md @@ -115,20 +115,23 @@ In the example above, we used `$PAGE->get_renderer('tool_demo')` to get an insta Instead, you can use the `core\output\renderer_helper` class to get any renderer instance without using the global. This is an example of how to use the `renderer_helper` class to get a renderer instance: ```php -class my_di_example { +class my_di_example +{ public function __construct( /** @var \core\output\renderer_helper $rendererhelper the renderer helper */ protected readonly \core\output\renderer_helper $rendererhelper, ) { } - public function do_something_with_my_renderer() { + public function do_something_with_my_renderer() + { /** @var \tool_demo\output\renderer $renderer */ $renderer = $this->rendererhelper->get_renderer('tool_demo'); // Do something with the renderer. } - public function do_something_with_core_renderer() { + public function do_something_with_core_renderer() + { // For convenience, the renderer helper also provides a method to get the core renderer. $renderer = $this->rendererhelper->get_core_renderer(); // Do something with the core renderer. @@ -157,11 +160,13 @@ use renderer_base; use templatable; use stdClass; -class index_page implements renderable, templatable { +class index_page implements renderable, templatable +{ /** @var string $sometext Some text to show how to pass data to a template. */ private $sometext = null; - public function __construct($sometext): void { + public function __construct($sometext): void + { $this->sometext = $sometext; } @@ -170,7 +175,8 @@ class index_page implements renderable, templatable { * * @return stdClass */ - public function export_for_template(renderer_base $output): stdClass { + public function export_for_template(renderer_base $output): stdClass + { $data = new stdClass(); $data->sometext = $this->sometext; return $data; @@ -193,7 +199,8 @@ If you wish to use a specific template to render the content you may specify any * * @return string */ - public function get_template_name(\renderer_base $renderer): string { + public function get_template_name(\renderer_base $renderer): string + { return 'tool_demo/index_page'; } ``` @@ -208,7 +215,8 @@ namespace tool_demo\output; use plugin_renderer_base; -class renderer extends plugin_renderer_base { +class renderer extends plugin_renderer_base +{ /** * Defer to template. * @@ -216,7 +224,8 @@ class renderer extends plugin_renderer_base { * * @return string html for the page */ - public function render_index_page($page): string { + public function render_index_page($page): string + { $data = $page->export_for_template($this); return parent::render_from_template('tool_demo/index_page', $data); } @@ -474,11 +483,13 @@ mtrace('DONE'); Or a scheduled or adhoc task, via a trait. Example: ```php -class stored_progress_scheduled_task_example extends \core\task\scheduled_task { +class stored_progress_scheduled_task_example extends \core\task\scheduled_task +{ use \core\task\stored_progress_task_trait; - public function execute() { + public function execute() + { // This simulates a specific count of iterations the task will do, e.g. x number of courses to loop through and do something. $iterations = 100; @@ -537,7 +548,8 @@ use core_courseformat\base as course_format; use mod_MYPLUGIN\external\myname_exporter; use stdClass; -class myname implements externable, named_templatable, renderable { +class myname implements externable, named_templatable, renderable +{ public function __construct( /** @var cm_info The course module. */ public cm_info $cm, @@ -545,7 +557,8 @@ class myname implements externable, named_templatable, renderable { } #[\Override] - public function export_for_template(renderer_base $output): stdClass { + public function export_for_template(renderer_base $output): stdClass + { // This method is used to prepare data for rendering in a template. // It is related to the `templatable` interface and could return an object or array. $cm = $this->cm; @@ -562,14 +575,16 @@ class myname implements externable, named_templatable, renderable { } #[\Override] - public function get_template_name(renderer_base $renderer): string { + public function get_template_name(renderer_base $renderer): string + { // This method is used to specify the template name for rendering. // It is not used for webservice clients, but it is required by the named_templatable interface. return 'core_courseformat/local/overview/activityname'; } #[\Override] - public function get_exporter(?\core\context $context = null): myname_exporter { + public function get_exporter(?\core\context $context = null): myname_exporter + { $context = $context ?? \core\context\system::instance(); return new myname_exporter($this, ['context' => $context]); } @@ -583,7 +598,8 @@ class myname implements externable, named_templatable, renderable { } #[\Override] - public static function read_properties_definition(): array { + public static function read_properties_definition(): array + { return myname_exporter::read_properties_definition(); } @@ -614,7 +630,8 @@ namespace mod_MYPLUGIN\external; use core\external\exporter; use mod_MYPLUGIN\output\myname; -class myname_exporter extends exporter { +class myname_exporter extends exporter +{ /** * Constructor with parameter type hints. * @@ -629,12 +646,14 @@ class myname_exporter extends exporter { } #[\Override] - protected static function define_properties(): array { + protected static function define_properties(): array + { return []; } #[\Override] - protected static function define_related() { + protected static function define_related() + { // Most exporter need to define the context as related data to parse texts. return [ 'context' => 'context', @@ -642,7 +661,8 @@ class myname_exporter extends exporter { } #[\Override] - protected static function define_other_properties() { + protected static function define_other_properties() + { return [ 'activityname' => [ 'type' => PARAM_TEXT, @@ -663,7 +683,8 @@ class myname_exporter extends exporter { } #[\Override] - protected function get_other_values(\renderer_base $output) { + protected function get_other_values(\renderer_base $output) + { /** @var \cm_info $cm */ $cm = $this->data->cm; @@ -694,14 +715,17 @@ use core\output\renderer_helper; use mod_MYPLUGIN\output\myname; use stdClass; -class get_my_name extends external_api { - public static function execute_parameters(): external_function_parameters { +class get_my_name extends external_api +{ + public static function execute_parameters(): external_function_parameters + { return new external_function_parameters([ 'cmid' => new external_value(PARAM_INT, 'Course module id', VALUE_REQUIRED), ]); } - public static function execute(int $cmid): stdClass { + public static function execute(int $cmid): stdClass + { [ 'cmid' => $cmid, ] = external_api::validate_parameters(self::execute_parameters(), [ @@ -727,7 +751,8 @@ class get_my_name extends external_api { * * @return external_single_structure */ - public static function execute_returns(): external_single_structure { + public static function execute_returns(): external_single_structure + { return myname::get_read_structure(); } } diff --git a/versioned_docs/version-5.2/apis/subsystems/output/inplace.md b/versioned_docs/version-5.2/apis/subsystems/output/inplace.md index fa1bfdf99..dc7f5c5f0 100644 --- a/versioned_docs/version-5.2/apis/subsystems/output/inplace.md +++ b/versioned_docs/version-5.2/apis/subsystems/output/inplace.md @@ -17,7 +17,8 @@ The best way is to explain the usage on a simple example. Imagine we have plugin Define a callback in `/admin/tool/mytest/lib.php` that starts with the plugin name and ends with `_inplace_editable`: ```php title="admin/tool/mytest/lib.php" -function tool_mytest_inplace_editable($itemtype, $itemid, $newvalue) { +function tool_mytest_inplace_editable($itemtype, $itemid, $newvalue) +{ global $DB; if ($itemtype === 'mytestname') { @@ -80,13 +81,15 @@ This was a very simplified example, in the real life you will probably want to: ```php title="admin/tool/mytest/classes/local/inplace_edit_text.php" -class inplace_edit_text extends \core\output\inplace_editable { +class inplace_edit_text extends \core\output\inplace_editable +{ /** * Constructor. * * @param object $record */ - public function __construct($record) { + public function __construct($record) + { parent::__construct( component: 'tool_mytest', // The item type as managed your plugin. @@ -119,7 +122,8 @@ class inplace_edit_text extends \core\output\inplace_editable { * @param mixed $newvalue * @return \self */ - public static function update($itemid, $newvalue) { + public static function update($itemid, $newvalue) + { // Clean the new value. $newvalue = clean_param($newvalue, PARAM_INT); @@ -194,13 +198,15 @@ $tmpl->set_type_toggle([0, 1]);
```php title="admin/tool/mytest/classes/local/inplace_edit_select.php" -class inplace_edit_select extends \core\output\inplace_editable { +class inplace_edit_select extends \core\output\inplace_editable +{ /** * Constructor. * * @param \stdClass $record */ - public function __construct($record) { + public function __construct($record) + { // Get the options for inplace_edit select box. // The array needs the format: // $options = [ @@ -241,7 +247,8 @@ class inplace_edit_select extends \core\output\inplace_editable { * @param mixed $newvalue * @return \self */ - public static function update($itemid, $newvalue) { + public static function update($itemid, $newvalue) + { // Clean the new value. $newvalue = clean_param($newvalue, PARAM_INT); diff --git a/versioned_docs/version-5.2/apis/subsystems/privacy/index.md b/versioned_docs/version-5.2/apis/subsystems/privacy/index.md index 83e341479..35c99c1b4 100644 --- a/versioned_docs/version-5.2/apis/subsystems/privacy/index.md +++ b/versioned_docs/version-5.2/apis/subsystems/privacy/index.md @@ -119,7 +119,8 @@ class provider implements * * @return string */ - public static function get_reason(): string { + public static function get_reason(): string + { return 'privacy:metadata'; } } @@ -179,7 +180,8 @@ class provider implements // This plugin does store personal user data. \core_privacy\local\metadata\provider { - public static function get_metadata(collection $collection): collection { + public static function get_metadata(collection $collection): collection + { // Here you will add more items into the collection. @@ -214,7 +216,8 @@ Some subsystems which store user data do not need to be listed: ##### Example {/* #example-2 */} ```php title="mod/forum/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_subsystem_link( 'core_files', @@ -243,7 +246,8 @@ It is a matter of judgement which fields contain user data and which don't. Anyt ##### Example {/* #example-3 */} ```php title="mod/forum/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_database_table( 'forum_discussion_subs', @@ -291,7 +295,8 @@ Any plugin providing user preferences must also implement the `\core_privacy\loc ##### Example {/* #example-4 */} ```php title="admin/tool/usertours/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_user_preference('tool_usertours_tour_completion_time', 'privacy:metadata:preference:tool_usertours_tour_completion_time'); @@ -318,7 +323,8 @@ You can indicate this by calling the `add_external_location_link()` method on th ##### Example {/* #example-5 */} ```php title="mod/lti/classes/privacy/provider.php" -public static function get_metadata(collection $collection): collection { +public static function get_metadata(collection $collection): collection +{ $collection->add_external_location_link('lti_client', [ 'userid' => 'privacy:metadata:lti_client:userid', 'fullname' => 'privacy:metadata:lti_client:fullname', @@ -385,15 +391,16 @@ if (interface_exists('\core_privacy\local\request\userlist')) { } -class provider implements my_userlist { +class provider implements my_userlist +{ /** * Get the list of users who have data within a context. * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ - public static function get_users_in_context(userlist $userlist) { - + public static function get_users_in_context(userlist $userlist) + { } /** @@ -401,8 +408,8 @@ class provider implements my_userlist { * * @param approved_userlist $userlist The approved context and user information to delete information for. */ - public static function delete_data_for_users(approved_userlist $userlist) { - + public static function delete_data_for_users(approved_userlist $userlist) + { } } @@ -421,7 +428,9 @@ Contexts are retrieved using the `get_contexts_for_userid` function which takes * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist {} +public static function get_contexts_for_userid(int $userid): contextlist +{ +} ``` The function returns a `\core_privacy\local\request\contextlist` which is used to keep a set of contexts together in a fixed fashion. @@ -443,7 +452,8 @@ The following example simply fetches the contextid for all forums where a user h * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist { +public static function get_contexts_for_userid(int $userid): contextlist +{ $contextlist = new \core_privacy\local\request\contextlist(); $sql = "SELECT c.id @@ -490,7 +500,8 @@ In the case of the rating data, this will include any post where the user has ra * @param int $userid The user to search. * @return contextlist $contextlist The list of contexts used in this plugin. */ -public static function get_contexts_for_userid(int $userid): contextlist { +public static function get_contexts_for_userid(int $userid): contextlist +{ $ratingsql = \core_rating\privacy\provider::get_sql_join('rat', 'mod_forum', 'post', 'p.id', $userid); // Fetch all forum discussions, and forum posts. $sql = "SELECT c.id @@ -555,7 +566,9 @@ This method is very similar to the `get_contexts_for_userid` function but has so * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ -public static function get_users_in_context(userlist $userlist) {} +public static function get_users_in_context(userlist $userlist) +{ +} ``` ###### Basic example {/* #basic-example-1 */} @@ -568,8 +581,8 @@ The following example simply fetches the userid for all users in a given forum c * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ -public static function get_users_in_context(userlist $userlist) { - +public static function get_users_in_context(userlist $userlist) +{ $context = $userlist->get_context(); if (!$context instanceof \context_module) { @@ -616,7 +629,9 @@ This is achieved through use of the `export_user_data` function which takes the * * @param approved_contextlist $contextlist The approved contexts to export information for. */ -public static function export_user_data(approved_contextlist $contextlist) {} +public static function export_user_data(approved_contextlist $contextlist) +{ +} ``` The `approved_contextlist` includes both the user record, and a list of contexts, which can be retrieved by either processing it as an Iterator, or by calling `get_contextids()` or `get_contexts()` as required. @@ -642,7 +657,8 @@ You need to provide a description of the value of the user preference. (This des * * @param int $userid The userid of the user whose data is to be exported. */ -public static function export_user_preferences(int $userid) { +public static function export_user_preferences(int $userid) +{ $markasreadonnotification = get_user_preferences('markasreadonnotification', null, $userid); if (null !== $markasreadonnotification) { switch ($markasreadonnotification) { @@ -829,7 +845,8 @@ When expiring content for a high-level context such as a course context, the fun * * @param context $context Context to delete data from. */ -public static function delete_data_for_all_users_in_context(\context $context) { +public static function delete_data_for_all_users_in_context(\context $context) +{ global $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -850,7 +867,8 @@ public static function delete_data_for_all_users_in_context(\context $context) { An *approved_contextlist* is given and user data related to that user should either be completely deleted, or overwritten if a structure needs to be maintained. This will be called when a user has requested the right to be forgotten. All attempts should be made to delete this data where practical while still allowing the plugin to be used by other users. ```php title="mod/choice/classes/privacy/provider.php" -public static function delete_data_for_user(approved_contextlist $contextlist) { +public static function delete_data_for_user(approved_contextlist $contextlist) +{ global $DB; if (empty($contextlist->count())) { @@ -874,7 +892,8 @@ An *approved_userlist* is given and user data related to all users in the specif * * @param approved_userlist $userlist The approved context and user information to delete information for. */ -public static function delete_data_for_users(approved_userlist $userlist) { +public static function delete_data_for_users(approved_userlist $userlist) +{ global $DB; $context = $userlist->get_context(); @@ -915,7 +934,8 @@ class provider implements use \core_privacy\local\legacy_polyfill; // The required methods must be in this format starting with an underscore. - public static function _get_metadata(collection $collection) { + public static function _get_metadata(collection $collection) + { // Code for returning metadata goes here. } ``` @@ -943,12 +963,14 @@ class provider implements use \core_plagiarism\privacy\plagiarism_provider\legacy_polyfill; // The required methods must be in this format starting with an underscore. - public static function _get_metadata(collection $collection) { + public static function _get_metadata(collection $collection) + { // Code for returning metadata goes here. } // This is one of the polyfilled methods from the plagiarism provider. - public static function _export_plagiarism_user_data($userid, \context $context, array $subcontext, array $linkarray) { + public static function _export_plagiarism_user_data($userid, \context $context, array $subcontext, array $linkarray) + { // ... } ``` @@ -969,7 +991,8 @@ if (interface_exists('\core_privacy\local\request\core_userlist_provider')) { interface core_userlist_provider {} } -class provider implements core_userlist_provider { +class provider implements core_userlist_provider +{ ``` ## Tips for development {/* #tips-for-development */} diff --git a/versioned_docs/version-5.2/apis/subsystems/privacy/utils.md b/versioned_docs/version-5.2/apis/subsystems/privacy/utils.md index fdbcfb74f..c47c10086 100644 --- a/versioned_docs/version-5.2/apis/subsystems/privacy/utils.md +++ b/versioned_docs/version-5.2/apis/subsystems/privacy/utils.md @@ -108,7 +108,8 @@ foreach ($list->good as $component) { echo "\n\n== Done ==\n"; -function check_implements($component, $interface) { +function check_implements($component, $interface) +{ $manager = new \core_privacy\manager(); $rc = new \ReflectionClass(\core_privacy\manager::class); $rcm = $rc->getMethod('component_implements'); diff --git a/versioned_docs/version-5.2/apis/subsystems/routing/index.md b/versioned_docs/version-5.2/apis/subsystems/routing/index.md index 38b150921..bce11a503 100644 --- a/versioned_docs/version-5.2/apis/subsystems/routing/index.md +++ b/versioned_docs/version-5.2/apis/subsystems/routing/index.md @@ -54,7 +54,8 @@ use core\router\schema\response\payload_response; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -class example { +class example +{ #[\core\router\route( // Resolves to https://example.com/moodle/api/rest/v2/mod_example/example path: '/example', diff --git a/versioned_docs/version-5.2/apis/subsystems/routing/parameters.md b/versioned_docs/version-5.2/apis/subsystems/routing/parameters.md index 75474757b..b57c1a944 100644 --- a/versioned_docs/version-5.2/apis/subsystems/routing/parameters.md +++ b/versioned_docs/version-5.2/apis/subsystems/routing/parameters.md @@ -36,7 +36,8 @@ use core\param; use core\router\route; use core\router\schema\parameters\path_parameter; -class example { +class example +{ #[route( path: '/users/{username}', pathtypes: [ @@ -70,7 +71,8 @@ use core\param; use core\router\route; use core\router\schema\parameters\path_parameter; -class example { +class example +{ #[route( path: '/users/{username}', pathtypes: [ @@ -533,7 +535,8 @@ class path_course extends \core\router\schema\parameters\path_parameter implemen * @return object * @throws not_found_exception If the course cannot be found */ - protected function get_course_for_value(string $value): mixed { + protected function get_course_for_value(string $value): mixed + { global $DB; $data = false; @@ -572,7 +575,8 @@ class path_course extends \core\router\schema\parameters\path_parameter implemen } #[\Override] - public function get_schema_from_type(param $type): \stdClass { + public function get_schema_from_type(param $type): \stdClass + { $schema = parent::get_schema_from_type($type); $schema->pattern = "^("; diff --git a/versioned_docs/version-5.2/apis/subsystems/routing/responses.md b/versioned_docs/version-5.2/apis/subsystems/routing/responses.md index 64f7c8f50..6118fd23e 100644 --- a/versioned_docs/version-5.2/apis/subsystems/routing/responses.md +++ b/versioned_docs/version-5.2/apis/subsystems/routing/responses.md @@ -49,7 +49,8 @@ use core\router\schema\response\payload_response; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -class example { +class example +{ #[\core\router\route( // Resolves to https://example.com/moodle/api/rest/v2/mod_example/example path: '/example', diff --git a/versioned_docs/version-5.2/apis/subsystems/routing/shortlinks.md b/versioned_docs/version-5.2/apis/subsystems/routing/shortlinks.md index bd90f632c..af7202bad 100644 --- a/versioned_docs/version-5.2/apis/subsystems/routing/shortlinks.md +++ b/versioned_docs/version-5.2/apis/subsystems/routing/shortlinks.md @@ -76,9 +76,11 @@ Each component using shortlinks will need to have a `shortlink_handler` class. T - `process_shortlink()` ```php -class shortlink_handler implements shortlink_handler_interface { +class shortlink_handler implements shortlink_handler_interface +{ #[\Override] - public function get_valid_linktypes(): array { + public function get_valid_linktypes(): array + { return [ 'view', ]; diff --git a/versioned_docs/version-5.2/apis/subsystems/routing/testing.md b/versioned_docs/version-5.2/apis/subsystems/routing/testing.md index a698b1c51..79f248815 100644 --- a/versioned_docs/version-5.2/apis/subsystems/routing/testing.md +++ b/versioned_docs/version-5.2/apis/subsystems/routing/testing.md @@ -22,8 +22,10 @@ You can quickly and easily create a copy of the Moodle Router using the `route_t This is a fully-configured copy of the Moodle Router, and allows to handle requests directly. ```php -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $router = $this->get_router(); } } @@ -56,8 +58,10 @@ You can easily add existing routes to mocking route loader either individually, To add an individual route, you can use the `\route_testcase::add_route_to_route_loader()` method, for example: ```php title="Adding a single route to the route loader" -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $this->add_route_to_route_loader( my_route::class, 'my_route_method', @@ -71,8 +75,10 @@ final class my_test extends \route_testcase { You can also add all routes in a class to the route loader using the `\route_testcase::add_class_routes_to_route_loader()` method, for example: ```php title="Adding all routes in a class to the route loader" -final class my_test extends \route_testcase { - public function test_example(): void { +final class my_test extends \route_testcase +{ + public function test_example(): void + { $this->add_class_routes_to_route_loader( my_route::class, ); @@ -90,7 +96,8 @@ The `\route_testcase` also includes several methods to simplify generating a Req You can create a request and manually pass it to Router using the `\route_testcase::create_request()` method, for example: ```php title="Creating an example request and processing it" -public function test_example(): void { +public function test_example(): void +{ $this->add_class_routes_to_route_loader( my_route::class, ); @@ -114,7 +121,8 @@ When creating a request the default is to use the Route Group for the REST API, The `\route_testcase::process_request()` and `\route_testcsae::process_api_request()` methods act as a shortcut for creating the request, fetching the router, and the app, and handling the request to return a response. The above example can therefore be simplified to: ```php title="Creating and processing an example request" -public function test_example(): void { +public function test_example(): void +{ $this->add_class_routes_to_route_loader( my_route::class, ); @@ -131,7 +139,8 @@ All of these methods also accept: As an example, to call the route `/api/rest/v2/question/bank/{course}/question_counts`, you would do the following: ```php title="Creating and processing a question_counts request" -public function test_question_counts(): void { +public function test_question_counts(): void +{ $this->resetAfterTest(); $course = self::getDataGenerator()->create_course(); diff --git a/versioned_docs/version-5.2/apis/subsystems/tag/index.md b/versioned_docs/version-5.2/apis/subsystems/tag/index.md index a847586f5..6b5a97652 100644 --- a/versioned_docs/version-5.2/apis/subsystems/tag/index.md +++ b/versioned_docs/version-5.2/apis/subsystems/tag/index.md @@ -151,7 +151,8 @@ If you have created a course activity that uses tags you should also remember to * * @param moodleform $mform */ -function book_reset_course_form_definition(&$mform) { +function book_reset_course_form_definition(&$mform) +{ $mform->addElement('header', 'bookheader', get_string('modulenameplural', 'book')); $mform->addElement('checkbox', 'reset_book_tags', get_string('removeallbooktags', 'book')); } @@ -161,7 +162,8 @@ function book_reset_course_form_definition(&$mform) { * @param $data the data submitted from the reset course. * @return array status array */ -function book_reset_userdata($data) { +function book_reset_userdata($data) +{ global $DB; $status = []; @@ -207,7 +209,8 @@ When you tag contents inside the course the plugin has to hook into backup and r You can choose to backup and restore tags for each item individually (as it is done in mod_wiki) OR backup all tags in the context at once (as it is done in mod_glossary or mod_forum). Second option is preferable for performance reasons. Make sure to take into account `$userinfo` (whether user information is backed up / restored), for example wiki pages is not user information but glossary entries are, tags on them follow the same rule. ```php title="mod/glossary/backup_glossary_stepslib.php" -protected function define_structure() { +protected function define_structure() +{ // ... $tags = new backup_nested_element('entriestags'); $tag = new backup_nested_element('tag', ['id'], ['itemid', 'rawname']); @@ -232,7 +235,8 @@ protected function define_structure() { ``` ```php title="mod/glossary/restore_glossary_stepslib.php" -protected function define_structure() { +protected function define_structure() +{ // ... if ($userinfo) { $paths[] = new restore_path_element('glossary_entry_tag', '/activity/glossary/entriestags/tag'); @@ -240,7 +244,8 @@ protected function define_structure() { // ... } -protected function process_glossary_entry_tag($data) { +protected function process_glossary_entry_tag($data) +{ $data = (object)$data; if (!core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) { // Tags disabled on this site, nothing to process. @@ -265,7 +270,8 @@ Given a user searches for any items tagged with a specified tag, only the items To limit the performance impact of checking user access against items the following class ``core_tag_index_builder()`` can assist with the retrieval and caching of records, especially within both course and activity modules. ```php -function mod_wiki_get_tagged_pages($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0) { +function mod_wiki_get_tagged_pages($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0) +{ // Find items. // Please refer to existing callbacks in core for examples. diff --git a/versioned_docs/version-5.2/apis/subsystems/task/adhoc.md b/versioned_docs/version-5.2/apis/subsystems/task/adhoc.md index 0dd508de0..5d057312d 100644 --- a/versioned_docs/version-5.2/apis/subsystems/task/adhoc.md +++ b/versioned_docs/version-5.2/apis/subsystems/task/adhoc.md @@ -38,12 +38,13 @@ namespace mod_example\task; /** * An example of an adhoc task. */ -class do_something extends \core\task\adhoc_task { - +class do_something extends \core\task\adhoc_task +{ /** * Execute the task. */ - public function execute() { + public function execute() + { // Call your own api } } @@ -62,8 +63,8 @@ It can be fetched using the `get_custom_data(): mixed` method. We recommend only ever calling `set_custom_data()` from within a factory method in the task class itself. ```php -class do_something extends \core\task\adhoc_task { - +class do_something extends \core\task\adhoc_task +{ public static function instance( int $id, string $status, @@ -77,7 +78,8 @@ class do_something extends \core\task\adhoc_task { return $task; } - public function execute() { + public function execute() + { $data = $this->get_custom_data(); mtrace($data->id); mtrace($data->status); @@ -177,7 +179,8 @@ $task->get_attempts_available(); Tasks are retried by default, but this behaviour can be modified by overriding the `retry_until_success()` method in your task class, for example: ```php -public function retry_until_success(): bool { +public function retry_until_success(): bool +{ return false; } ``` diff --git a/versioned_docs/version-5.2/apis/subsystems/task/index.md b/versioned_docs/version-5.2/apis/subsystems/task/index.md index 4689e0e5a..e6d746e05 100644 --- a/versioned_docs/version-5.2/apis/subsystems/task/index.md +++ b/versioned_docs/version-5.2/apis/subsystems/task/index.md @@ -92,8 +92,10 @@ Since Moodle 3.5 it is safe to use the [Output API](../output/index.md) in cron In order to improve debugging information, it is good practice to call `mtrace` to log what's going on within a task execution: ```php -class my_task extends \core\task\scheduled_task { - public function execute() { +class my_task extends \core\task\scheduled_task +{ + public function execute() + { mtrace("My task started"); // Do some work. diff --git a/versioned_docs/version-5.2/apis/subsystems/task/scheduled.md b/versioned_docs/version-5.2/apis/subsystems/task/scheduled.md index b29072d9e..7d286c859 100644 --- a/versioned_docs/version-5.2/apis/subsystems/task/scheduled.md +++ b/versioned_docs/version-5.2/apis/subsystems/task/scheduled.md @@ -37,21 +37,24 @@ namespace mod_example\task; /** * An example of a scheduled task. */ -class do_something extends \core\task\scheduled_task { +class do_something extends \core\task\scheduled_task +{ /** * Return the task's name as shown in admin screens. * * @return string */ - public function get_name() { + public function get_name() + { return get_string('dosomething', 'mod_example'); } /** * Execute the task. */ - public function execute() { + public function execute() + { // Call your own api } } diff --git a/versioned_docs/version-5.2/guides/templates/index.md b/versioned_docs/version-5.2/guides/templates/index.md index 83161f69d..c9bcce802 100644 --- a/versioned_docs/version-5.2/guides/templates/index.md +++ b/versioned_docs/version-5.2/guides/templates/index.md @@ -397,7 +397,8 @@ The following example shows a renderable using the `mywidget.mustache` template * @param renderer_base $output * @return stdClass */ -public function export_for_template(renderer_base $output) { +public function export_for_template(renderer_base $output) +{ $data = new stdClass(); $data->canmanage = $this->canmanage; $data->things = []; @@ -424,7 +425,8 @@ Example of the method added to tell a renderable to use the `mywidget.mustache` * @param renderer_base $output * @return string */ -public function get_template_name(\renderer_base $renderer): string { +public function get_template_name(\renderer_base $renderer): string +{ return 'tool_myplugin/mywidget'; } ``` @@ -445,7 +447,8 @@ The rendering method can now use templates to render the object: * * @return string HTML */ -protected function render_mywidget(mywidget $widget) { +protected function render_mywidget(mywidget $widget) +{ $data = $widget->export_for_template($this); return $this->render_from_template('tool_myplugin/mywidget', $data); } diff --git a/versioned_docs/version-5.2/guides/testing/index.md b/versioned_docs/version-5.2/guides/testing/index.md index 552f340a7..41c66aea1 100644 --- a/versioned_docs/version-5.2/guides/testing/index.md +++ b/versioned_docs/version-5.2/guides/testing/index.md @@ -74,8 +74,10 @@ For example: ```php title="mod/myplugin/tests/sample_test.php" namespace mod_myplugin; - class sample_test extends \advanced_testcase { - public function test_adding() { + class sample_test extends \advanced_testcase + { + public function test_adding() + { $this->assertEquals(2, 1+2); } } @@ -101,8 +103,10 @@ If you modify data and _do not_ call `$this->resetAfterTest()` then you will rec ```php title="Demonstration of database reset" namespace mod_myplugin; - class test_something extends \advanced_testcase { - public function test_deleting() { + class test_something extends \advanced_testcase + { + public function test_deleting() + { global $DB; $this->resetAfterTest(true); @@ -110,7 +114,8 @@ If you modify data and _do not_ call `$this->resetAfterTest()` then you will rec $this->assertEmpty($DB->get_records('user')); } - public function test_user_table_was_reset() { + public function test_user_table_was_reset() + { global $DB; $this->assertEquals(2, $DB->count_records('user', array())); @@ -592,12 +597,15 @@ When defining coverage for a specific method under test, it must be either: /** * @coversDefaultClass \mod_myplugin\example */ -class example_test extends \advanced_testcase { +class example_test extends \advanced_testcase +{ /** * This test will cover \mod_myplugin\example::some_method * @covers ::some_method */ - public function test_some_method(): void {} + public function test_some_method(): void + { + } } ``` @@ -711,7 +719,8 @@ However, the following rules should be followed when using dataProviders: * @param int $foor * @param int $bar */ -public function test_foobar(int $foo, int $bar) { +public function test_foobar(int $foo, int $bar) +{ // Perform the tests here. } @@ -720,7 +729,8 @@ public function test_foobar(int $foo, int $bar) { * * @return array List of data sets - (string) data set name => (array) data */ -public function foobar_provider(): \Generator { +public function foobar_provider(): \Generator +{ yield 'Same numbers' => [ 'foo' => 42, 'bar' => 42, diff --git a/versioned_docs/version-5.2/guides/upgrade/index.md b/versioned_docs/version-5.2/guides/upgrade/index.md index c3658f5b6..59abf5438 100644 --- a/versioned_docs/version-5.2/guides/upgrade/index.md +++ b/versioned_docs/version-5.2/guides/upgrade/index.md @@ -52,7 +52,8 @@ The following example shows the structure of the upgrade.php file: ```php title="Example upgrade.php file" get_manager(); // Loads ddl manager and xmldb classes. @@ -161,7 +162,8 @@ For example, if you are defining an installation behaviour in the `install.php`