Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .kateproject
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "lbplanner-plugin",
"lspclient": {
"servers": {
"php" : {
Expand Down
26 changes: 17 additions & 9 deletions lbplanner/classes/helpers/config_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))) {

Expand Down Expand Up @@ -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);
}
}
}
36 changes: 36 additions & 0 deletions lbplanner/db/uninstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
// This file is part of local_lbplanner.
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* 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();
}

Loading