From d026ed516d675d39f8b574b6f45ec1a6e4fa9943 Mon Sep 17 00:00:00 2001 From: Michael Milette Date: Mon, 14 Oct 2024 16:06:08 -0400 Subject: [PATCH] Refactorig code. --- CHANGELOG.md | 1 + README.md | 1 + lib.php | 37 +++++++++++++++++++++++-------------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28bf829..fc0e0e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## [2.2.2] - 2024-10-13 +- Added option to automatically add instance to new courses. ### Updated - Fixed support for plain text tag called {$a->userfullname}. - Fixed deprecation notice running on PHP 8.3. diff --git a/README.md b/README.md index dc093af..6e38043 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,7 @@ Michael Milette - Author and Lead Developer Big thank you to the following contributors. (Please let me know if I forgot to include you in the list): +* Phillip Fickl (phillipfickl) - Add instance to new coures by default. (2023) * MSVermet - Case insensitive comparison between invitation email and user email. (2023) * [Jerome Mouneyrac](http://www.moodleitandme.com) for his work on the original [invitation enrollment plug-in](https://github.com/mouneyrac/moodle-enrol_invitation) in which this one is based upon. * The staff, faculty, and students at the University of California, Los Angeles (UCLA) that were involved in creating the additional use cases, development, and refinement to this tool. diff --git a/lib.php b/lib.php index c867b8f..95516b2 100755 --- a/lib.php +++ b/lib.php @@ -114,26 +114,35 @@ public function add_instance($course, ?array $fields = null) { return parent::add_instance($course, $fields); } + /** + * Returns defaults for new instances. + * + * @return array + */ + public function get_instance_defaults() { + $fields = []; + $fields['status'] = $this->get_config('status'); + $fields['name'] = ''; + $fields['customint1'] = 0; + $fields['customint2'] = 3; + $fields['customint3'] = 0; + $fields['customint4'] = 0; + $fields['customint5'] = 0; + $fields['customint6'] = 0; + $fields['customchar1'] = get_string('default_subject', 'enrol_invitation', getcoursesubject($course)); + $fields['customtext1'] = ''; + + return $fields; + } + /** * Add new instance of enrol plugin with default settings. * * @param stdClass $course * @return int id of new instance */ - public function add_default_instance($course) - { - $fields = [ - 'status' => $this->get_config('status'), - 'name' => '', - 'customint1' => 0, - 'customint2' => 3, - 'customint3' => 0, - 'customint4' => 0, - 'customint5' => 0, - 'customint6' => 0, - 'customchar1' => get_string('default_subject', 'enrol_invitation', getcoursesubject($course)), - 'customtext1' => '', - ]; + public function add_default_instance($course) { + $fields = $this->get_instance_defaults(); return $this->add_instance($course, $fields); }