diff --git a/.kateproject b/.kateproject index 18da774c..ca3bca28 100644 --- a/.kateproject +++ b/.kateproject @@ -1,4 +1,5 @@ { + "name": "lbplanner-plugin", "lspclient": { "servers": { "php" : { diff --git a/lbplanner/classes/helpers/config_helper.php b/lbplanner/classes/helpers/config_helper.php index f29417bd..47e7a8e0 100644 --- a/lbplanner/classes/helpers/config_helper.php +++ b/lbplanner/classes/helpers/config_helper.php @@ -58,17 +58,13 @@ public static function set_default_active_year() { } /** - * Adds a customfield to moodle for each activity where teachers can select GK EK or both. - * - * Default value is GK. - * @throws \coding_exception - * @throws \moodle_exception - * @throws \coding_exception + * Adds a customfield to moodle for each activity where teachers can select GK EK Test or M. + * Default value is empty. */ public static function add_customfield(): void { // Check if the category is already created and only create it if it doesn't exist. // Check if plugin "modcustomfields" is installed and create the category and the custom field. - if (!get_config('local_lbplanner', 'categoryid')) { + if (self::get_category_id() === -1) { if (array_key_exists('modcustomfields', core_component::get_plugin_list('local'))) { @@ -100,16 +96,28 @@ public static function add_customfield(): void { } } } + /** + * Adds a customfield to moodle for each activity where teachers can select GK EK or both. + * + * @throws \coding_exception + * @throws \moodle_exception + */ + public static function remove_customfield(): void { + $handler = mod_handler::create(); + $catcontroller = category_controller::create(self::get_category_id(), null, $handler); + $handler->delete_category($catcontroller); + } /** * Get the category id from the config * @return int the category id if it is set, -1 otherwise */ public static function get_category_id(): int { - if (!get_config('local_lbplanner', 'categoryid')) { + $catid = get_config('local_lbplanner', 'categoryid'); + if ($catid === false) { return -1; } else { - return intval(get_config('local_lbplanner', 'categoryid')); + return intval($catid); } } } diff --git a/lbplanner/db/uninstall.php b/lbplanner/db/uninstall.php new file mode 100644 index 00000000..52003a1e --- /dev/null +++ b/lbplanner/db/uninstall.php @@ -0,0 +1,36 @@ +. + +/** + * Contains some stuff for when the plugin gets uninstalled. + * Upgrading the plugin shouldn't trigger this code. + * + * @package local_lbplanner + * @subpackage db + * @copyright 2024 NecodeIT + * @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later + */ + +use local_lbplanner\helpers\config_helper; + + +/** + * Runs when plugin is uninstalled + */ +function xmldb_local_lbplanner_uninstall() { + config_helper::remove_customfield(); +} +