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
9 changes: 7 additions & 2 deletions lbplanner/classes/helpers/course_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,18 @@ public static function get_lbplanner_course(int $courseid, int $userid): course

/**
* Get all current courses.
* @param bool $onlyenrolled whether to include only courses in which the current user is enrolled in
* @return course[] all courses of the current year
*/
public static function get_all_lbplanner_courses(): array {
public static function get_all_lbplanner_courses(bool $onlyenrolled=true): array {
global $DB, $USER;
$userid = $USER->id;

$mdlcourses = enrol_get_my_courses();
if ($onlyenrolled) {
$mdlcourses = enrol_get_my_courses();
} else {
$mdlcourses = get_courses();
}
// Remove Duplicates.
$mdlcourses = array_unique($mdlcourses, SORT_REGULAR);
$results = [];
Expand Down
12 changes: 11 additions & 1 deletion lbplanner/db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@
'classname' => 'local_lbplanner_services\courses_get_all_courses',
'methodname' => 'get_all_courses',
'classpath' => 'local/lbplanner/services/courses/get_all_courses.php',
'description' => 'Get all the courses of the current year',
'description' => 'Get all courses',
'type' => 'read',
'capabilities' => 'local/lb_planner:slotmaster',
'ajax' => true,
],
'local_lbplanner_courses_get_my_courses' => [
'classname' => 'local_lbplanner_services\courses_get_my_courses',
'methodname' => 'get_my_courses',
'classpath' => 'local/lbplanner/services/courses/get_my_courses.php',
'description' => 'Get courses that belong to the user',
'type' => 'read',
'capabilities' => 'local/lb_planner:student',
'ajax' => true,
Expand Down Expand Up @@ -395,6 +404,7 @@
'local_lbplanner_user_get_all_users',
'local_lbplanner_user_update_user',
'local_lbplanner_courses_get_all_courses',
'local_lbplanner_courses_get_my_courses',
'local_lbplanner_courses_update_course',
'local_lbplanner_modules_get_all_course_modules',
'local_lbplanner_modules_get_all_modules',
Expand Down
17 changes: 12 additions & 5 deletions lbplanner/services/courses/get_all_courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
namespace local_lbplanner_services;

use core_external\{external_function_parameters, external_multiple_structure};

use local_lbplanner\enums\CAPABILITY_FLAG;
use local_lbplanner\helpers\course_helper;
use local_lbplanner\model\course;
use local_lbplanner\model\user;

/**
* Get all the courses of the current year.
* Get ALL courses. Slotmaster only.
*
* @package local_lbplanner
* @subpackage services_courses
* @copyright 2024 necodeIT
* @copyright 2025 necodeIT
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later
*/
class courses_get_all_courses extends \core_external\external_api {
Expand All @@ -40,10 +41,16 @@ public static function get_all_courses_parameters(): external_function_parameter
}

/**
* Get all the courses of the current year.
* Get ALL courses.
*/
public static function get_all_courses(): array {
$courses = course_helper::get_all_lbplanner_courses();
global $USER;
$user = user::from_mdlobj($USER);
if (!($user->get_capabilitybitmask() & CAPABILITY_FLAG::SLOTMASTER)) {
throw new \moodle_exception('access denied: must be slotmaster');
}

$courses = course_helper::get_all_lbplanner_courses(false);
$results = [];
foreach ($courses as $course) {
array_push($results, $course->prepare_for_api());
Expand Down
63 changes: 63 additions & 0 deletions lbplanner/services/courses/get_my_courses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?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_function_parameters, external_multiple_structure};

use local_lbplanner\helpers\course_helper;
use local_lbplanner\model\course;

/**
* Get all the courses of the current year.
*
* @package local_lbplanner
* @subpackage services_courses
* @copyright 2025 necodeIT
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later
*/
class courses_get_my_courses extends \core_external\external_api {

/**
* Has no Parameters
* @return external_function_parameters
*/
public static function get_my_courses_parameters(): external_function_parameters {
return new external_function_parameters([]);
}

/**
* Get all the courses of the current year.
*/
public static function get_my_courses(): array {
$courses = course_helper::get_all_lbplanner_courses(true);
$results = [];
foreach ($courses as $course) {
array_push($results, $course->prepare_for_api());
}
return $results;
}

/**
* Returns description of method result value
* @return external_multiple_structure description of method result value
*/
public static function get_my_courses_returns(): external_multiple_structure {
return new external_multiple_structure(
course::api_structure()
);
}
}
2 changes: 1 addition & 1 deletion lbplanner/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

$plugin->component = 'local_lbplanner';
$plugin->release = 'Alpha v.'.$release;
$plugin->version = 2025012400;
$plugin->version = 2025012800;
$plugin->dependencies = [
// Depend upon version 2023110600 of local_modcustomfields.
'local_modcustomfields' => 2023110600,
Expand Down
Loading