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
10 changes: 10 additions & 0 deletions lbplanner/db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,15 @@
'capabilities' => 'local/lb_planner:teacher',
'ajax' => true,
],
'local_lbplanner_slots_remove_slot_supervisor' => [
'classname' => 'local_lbplanner_services\slots_remove_slot_supervisor',
'methodname' => 'remove_slot_supervisor',
'classpath' => 'local/lbplanner/services/slots/remove_slot_supervisor.php',
'description' => 'Removes supervisor from a slot',
'type' => 'write',
'capabilities' => 'local/lb_planner:teacher',
'ajax' => true,
],
'local_lbplanner_slots_add_slot_filter' => [
'classname' => 'local_lbplanner_services\slots_add_slot_filter',
'methodname' => 'add_slot_filter',
Expand Down Expand Up @@ -408,6 +417,7 @@
'local_lbplanner_slots_get_slot_filters',
'local_lbplanner_slots_get_student_slots',
'local_lbplanner_slots_get_supervisor_slots',
'local_lbplanner_slots_remove_slot_supervisor',
],
'restrictedusers' => 0,
'enabled' => 1,
Expand Down
86 changes: 86 additions & 0 deletions lbplanner/services/slots/remove_slot_supervisor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?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/>.

namespace local_lbplanner_services;

use core_external\{external_api, external_function_parameters, external_value};

use local_lbplanner\helpers\slot_helper;

/**
* Removes a supervisor from a slot
*
* @package local_lbplanner
* @subpackage services_slots
* @copyright 2025 necodeIT
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later
*/
class slots_remove_slot_supervisor extends external_api {
/**
* Parameters for remove_slot_supervisor.
* @return external_function_parameters
*/
public static function remove_slot_supervisor_parameters(): external_function_parameters {
return new external_function_parameters([
'userid' => new external_value(
PARAM_INT,
'ID of the user to be removed as a supervisor',
VALUE_REQUIRED,
null,
NULL_NOT_ALLOWED
),
'slotid' => new external_value(
PARAM_INT,
'ID of the slot',
VALUE_REQUIRED,
null,
NULL_NOT_ALLOWED
),
]);
}

/**
* Removes a supervisor from a slot
* @param int $userid ID of the user to be demoted
* @param int $slotid ID of the slot
*/
public static function remove_slot_supervisor(int $userid, int $slotid): void {
global $USER, $DB;
self::validate_parameters(
self::remove_slot_supervisor_parameters(),
[
'userid' => $userid,
'slotid' => $slotid,
]
);

// Check if current user is supervisor for this slot, throw error if not.
slot_helper::assert_slot_supervisor($USER->id, $slotid);

$DB->delete_records(
slot_helper::TABLE_SUPERVISORS,
['id' => $userid, 'slotid' => $slotid]
);
}

/**
* Return structure of remove_slot_supervisor
* @return null
*/
public static function remove_slot_supervisor_returns() {
return null;
}
}
Loading