From 01d140049bf6d9907bcd17e7fcaac83899d22574 Mon Sep 17 00:00:00 2001 From: Muhi Date: Tue, 21 Nov 2023 15:41:38 +0100 Subject: [PATCH 01/15] Removed moodle-DB tables. Currently looking for moodle Functions, which returns the desired values --- lbplanner/classes/helpers/modules_helper.php | 31 -------------------- lbplanner/services/modules/get_module.php | 26 ++++++++-------- 2 files changed, 13 insertions(+), 44 deletions(-) diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index 99cb0278..f87fee19 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -26,37 +26,6 @@ * Contains helper functions for working with modules. */ class modules_helper { - - /** - * Table where modules are stored. - */ - const ASSIGN_TABLE = 'assign'; - - /** - * Table where max. and min. grades of the modules are stored. - */ - const GRADE_ITEMS_TABLE = 'grade_items'; - - /** - * Table where course modules are stored. - */ - const COURSE_MODULES_TABLE = 'course_modules'; - - /** - * Table where grades of the modules are stored. - */ - const GRADES_TABLE = 'assign_grades'; - - /** - * Table where grading scales are stored. - */ - const SCALE_TABLE = 'scale'; - - /** - * Table where submissions of the modules are stored. - */ - const SUBMISSIONS_TABLE = 'assign_submission'; - /** * Submitted status name of a submission. */ diff --git a/lbplanner/services/modules/get_module.php b/lbplanner/services/modules/get_module.php index d225e5f9..368794c6 100644 --- a/lbplanner/services/modules/get_module.php +++ b/lbplanner/services/modules/get_module.php @@ -16,36 +16,36 @@ namespace local_lbplanner_services; +use core\context\user; use external_api; use external_function_parameters; use external_value; use local_lbplanner\helpers\modules_helper; -use local_lbplanner\helpers\plan_helper; -use local_lbplanner\helpers\user_helper; +use context_module; +use course_modinfo; /** * Get the data for a module. */ class modules_get_module extends external_api { public static function get_module_parameters() { - return new external_function_parameters(array( + return new external_function_parameters([ 'moduleid' => new external_value(PARAM_INT, 'The id of the module', VALUE_REQUIRED, null, NULL_NOT_ALLOWED), - 'userid' => new external_value(PARAM_INT, 'The id of the user', VALUE_REQUIRED, null, NULL_NOT_ALLOWED), - )); + ]); } - public static function get_module($moduleid, $userid) { - global $DB; + public static function get_module($moduleid) { + global $DB, $USER, $CFG; + require_once($CFG->dirroot . '/mod/assign/lib.php'); - self::validate_parameters(self::get_module_parameters(), array('moduleid' => $moduleid, 'userid' => $userid)); + self::validate_parameters(self::get_module_parameters(), ['moduleid' => $moduleid]); + var_dump(assign_get_coursemodule_info($moduleid)); - user_helper::assert_access($userid); - - if (!$DB->record_exists(modules_helper::MDL_ASSIGN_TABLE, array('id' => $moduleid))) { + /*if (!$DB->record_exists(modules_helper::MDL_ASSIGN_TABLE, array('id' => $moduleid))) { throw new \moodle_exception('Module not found'); - } + }*/ - return modules_helper::get_module($moduleid, $userid); + return null; } public static function get_module_returns() { From ec0ab8445d6cf5a906d895490e7a088d3acf51c0 Mon Sep 17 00:00:00 2001 From: muhi Date: Wed, 28 Feb 2024 11:05:53 +0100 Subject: [PATCH 02/15] test multiple ways to retrieve mod information get_array_of_activities is currently the best but is not possible until a config variable is changed of the moodle instance --- lbplanner/classes/helpers/modules_helper.php | 20 +++++++-------- lbplanner/db/upgrade.php | 10 +++++--- .../modules/get_all_course_modules.php | 25 ++++++------------- lbplanner/services/modules/get_module.php | 15 +++-------- lbplanner/services/user/delete_user.php | 3 ++- lbplanner/version.php | 2 +- 6 files changed, 31 insertions(+), 44 deletions(-) diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index c8474fbc..c67b63ca 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -32,8 +32,6 @@ use external_value; use moodle_url; -use local_lbplanner\polyfill\Enum; - // TODO: revert to native enums once we migrate to php8. @@ -102,11 +100,11 @@ class MODULE_TYPE extends Enum { */ const TEST = 2; /** - * TODO: ??? + * Mitarbeit. */ const M = 3; /** - * TODO: ??? + * No type. */ const NONE = 4; } @@ -125,7 +123,7 @@ class modules_helper { * * @return external_single_structure The structure of a module. */ - public static function structure() : external_single_structure { + public static function structure(): external_single_structure { return new external_single_structure( [ 'moduleid' => new external_value(PARAM_INT, 'Module ID'), @@ -149,7 +147,7 @@ public static function structure() : external_single_structure { * @param int $gradepass The grade to pass the module. * @return integer The enum value for the grade. */ - public static function determin_uinified_grade(int $grade, int $maxgrade, int $mingrade, int $gradepass) : int { + public static function determin_uinified_grade(int $grade, int $maxgrade, int $mingrade, int $gradepass): int { if ($grade < $gradepass) { return MODULE_GRADE::RIP; } @@ -179,7 +177,7 @@ public static function determin_uinified_grade(int $grade, int $maxgrade, int $m * @param bool $late Whether the module is late. * @return integer The enum value for the module status. */ - public static function map_status(bool $submitted, bool $done, bool $late) : int { + public static function map_status(bool $submitted, bool $done, bool $late): int { if ($done) { return MODULE_STATUS::DONE; } else if ($submitted) { @@ -197,7 +195,7 @@ public static function map_status(bool $submitted, bool $done, bool $late) : int * @param string $modulename The name of the module. * @return integer The enum value for the module type. */ - public static function determin_type(string $modulename) : int { + public static function determin_type(string $modulename): int { // Convert module name to uppercase. $modulename = strtoupper($modulename); @@ -231,7 +229,7 @@ public static function determin_type(string $modulename) : int { * @param int $courseid The id of the course. * @return string The url of the module. */ - public static function get_module_url(int $moduleid, int $courseid) : string { + public static function get_module_url(int $moduleid, int $courseid): string { global $DB; $view = $DB->get_record( @@ -249,7 +247,7 @@ public static function get_module_url(int $moduleid, int $courseid) : string { * @param int $userid The id of the user. * @return array The module. */ - public static function get_module(int $moduleid, int $userid) : array { + public static function get_module(int $moduleid, int $userid): array { global $DB; date_default_timezone_set('UTC'); @@ -334,7 +332,7 @@ public static function get_module(int $moduleid, int $userid) : array { * @param bool $ekenabled Whether EK modules should be included. * @return array The modules. */ - public static function get_all_course_modules(int $courseid, int $userid, bool $ekenabled) : array { + public static function get_all_course_modules(int $courseid, int $userid, bool $ekenabled): array { global $DB; $mdlmodules = $DB->get_records(self::ASSIGN_TABLE, ['course' => $courseid]); diff --git a/lbplanner/db/upgrade.php b/lbplanner/db/upgrade.php index ee29a436..927f4783 100644 --- a/lbplanner/db/upgrade.php +++ b/lbplanner/db/upgrade.php @@ -26,15 +26,19 @@ /** * Upgrades the DB version - * right now it only sets the default active year + * This function does anything necessary to upgrade the plugin from an old version to the current version. * * @param mixed $oldversion (unused) the previous version to upgrade from * @return bool true */ function xmldb_local_lbplanner_upgrade($oldversion): bool { - if ($oldversion < 2024022700) { + if ($oldversion < 2024022703) { config_helper::set_default_active_year(); - config_helper::add_customfield(); + try { + config_helper::add_customfield(); + } catch (coding_exception $e) { + new moodle_exception('error_adding_customfield', 'local_lbplanner', '', $e->getMessage()); + } } return true; } diff --git a/lbplanner/services/modules/get_all_course_modules.php b/lbplanner/services/modules/get_all_course_modules.php index b53ec82d..f0add890 100644 --- a/lbplanner/services/modules/get_all_course_modules.php +++ b/lbplanner/services/modules/get_all_course_modules.php @@ -16,6 +16,7 @@ namespace local_lbplanner_services; +use course_modinfo; use external_api; use external_function_parameters; use external_multiple_structure; @@ -38,36 +39,26 @@ class modules_get_all_course_modules extends external_api { */ public static function get_all_course_modules_parameters(): external_function_parameters { return new external_function_parameters([ - 'courseid' => new external_value(PARAM_INT, 'The id of the course', VALUE_REQUIRED, null, NULL_NOT_ALLOWED), - 'userid' => new external_value(PARAM_INT, 'The id of the user', VALUE_REQUIRED, null, NULL_NOT_ALLOWED), - 'ekenabled' => new external_value( - PARAM_BOOL, - 'Whether or not to include ek modules', - VALUE_REQUIRED, - false, - NULL_NOT_ALLOWED), - ]); + 'courseid' => new external_value(PARAM_INT, 'The id of the course', VALUE_REQUIRED, null, NULL_NOT_ALLOWED)]); } /** * Returns all the modules inside a course. * * @param int $courseid The ID of the course - * @param int $userid The ID of the user * @param bool $ekenabled whether or not to include ek modules * @return array the modules */ - public static function get_all_course_modules(int $courseid, int $userid, bool $ekenabled): array { - global $DB; + public static function get_all_course_modules(int $courseid): array { + global $DB, $USER; self::validate_parameters( self::get_all_course_modules_parameters(), - ['courseid' => $courseid, 'userid' => $userid, 'ekenabled' => $ekenabled] + ['courseid' => $courseid] ); - - user_helper::assert_access($userid); - - return modules_helper::get_all_course_modules($courseid, $userid, $ekenabled); + var_dump(get_course($courseid)); + die(var_dump(course_modinfo::get_array_of_activities(get_course($courseid)))); + return modules_helper::get_all_course_modules($courseid); } /** diff --git a/lbplanner/services/modules/get_module.php b/lbplanner/services/modules/get_module.php index a57c33d4..842d6de3 100644 --- a/lbplanner/services/modules/get_module.php +++ b/lbplanner/services/modules/get_module.php @@ -20,6 +20,7 @@ use external_function_parameters; use external_single_structure; use external_value; +use local_lbplanner\helpers\course_helper; use local_lbplanner\helpers\modules_helper; use local_lbplanner\helpers\plan_helper; use local_lbplanner\helpers\user_helper; @@ -40,7 +41,6 @@ class modules_get_module extends external_api { public static function get_module_parameters(): external_function_parameters { return new external_function_parameters([ 'moduleid' => new external_value(PARAM_INT, 'The id of the module', VALUE_REQUIRED, null, NULL_NOT_ALLOWED), - 'userid' => new external_value(PARAM_INT, 'The id of the user', VALUE_REQUIRED, null, NULL_NOT_ALLOWED), ]); } @@ -48,21 +48,14 @@ public static function get_module_parameters(): external_function_parameters { * Returns the data for a module * * @param int $moduleid The ID of the course - * @param int $userid The ID of the user * @return array the module */ - public static function get_module(int $moduleid, int $userid): array { + public static function get_module(int $moduleid): array { global $DB; - self::validate_parameters(self::get_module_parameters(), ['moduleid' => $moduleid, 'userid' => $userid]); + self::validate_parameters(self::get_module_parameters(), ['moduleid' => $moduleid]); - user_helper::assert_access($userid); - - if (!$DB->record_exists(modules_helper::MDL_ASSIGN_TABLE, ['id' => $moduleid])) { - throw new \moodle_exception('Module not found'); - } - - return modules_helper::get_module($moduleid, $userid); + return modules_helper::get_module($moduleid); } /** diff --git a/lbplanner/services/user/delete_user.php b/lbplanner/services/user/delete_user.php index 9a7b9dd0..dfb7ddb9 100644 --- a/lbplanner/services/user/delete_user.php +++ b/lbplanner/services/user/delete_user.php @@ -25,6 +25,7 @@ use local_lbplanner\helpers\plan_helper; use local_lbplanner\helpers\course_helper; use local_lbplanner\helpers\notifications_helper; +use local_lbplanner\helpers\PLAN_ACCESS_TYPE; use moodle_exception; /** @@ -81,7 +82,7 @@ public static function delete_user($userid) { if ( !(count(plan_helper::get_plan_members($planid)) == 1 ) && - !(plan_helper::get_access_type($planid, $userid) == plan_helper::ACCESS_TYPE_OWNER)) { + !(plan_helper::get_access_type($planid, $userid) == PLAN_ACCESS_TYPE::OWNER)) { self::call_external_function('local_lbplanner_plan_leave_plan', ['userid' => $userid, 'planid' => $planid]); } $DB->delete_records(plan_helper::DEADLINES_TABLE, ['planid' => $planid]); diff --git a/lbplanner/version.php b/lbplanner/version.php index d3e51d99..347810cd 100644 --- a/lbplanner/version.php +++ b/lbplanner/version.php @@ -27,7 +27,7 @@ $plugin->component = 'local_lbplanner'; $plugin->release = 'Alpha v.'.$release; -$plugin->version = 2024022700; +$plugin->version = 2024022703; $plugin->dependencies = [ // Depend upon version 2023110600 of local_modcustomfields. 'local_modcustomfields' => 2023110600, From ef9e6e60fce8e3b8b760bc61dab9918a06173d84 Mon Sep 17 00:00:00 2001 From: muhi Date: Mon, 4 Mar 2024 15:45:19 +0100 Subject: [PATCH 03/15] backup of progress --- lbplanner/classes/helpers/modules_helper.php | 20 +++++++++++++++++++ .../modules/get_all_course_modules.php | 11 +++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index c67b63ca..52974ffe 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -352,3 +352,23 @@ public static function get_all_course_modules(int $courseid, int $userid, bool $ return $modules; } } +class module { + public $moduleid; + public $name; + public $courseid; + public $status; + public $type; + public $url; + public $grade; + public $deadline; + public function __construct($moduleid, $name, $courseid, $status, $type, $url, $grade, $deadline) { + $this->moduleid = $moduleid; + $this->name = $name; + $this->courseid = $courseid; + $this->status = $status; + $this->type = $type; + $this->url = $url; + $this->grade = $grade; + $this->deadline = $deadline; + } +} diff --git a/lbplanner/services/modules/get_all_course_modules.php b/lbplanner/services/modules/get_all_course_modules.php index f0add890..52ee1e73 100644 --- a/lbplanner/services/modules/get_all_course_modules.php +++ b/lbplanner/services/modules/get_all_course_modules.php @@ -23,6 +23,7 @@ use external_value; use local_lbplanner\helpers\modules_helper; use local_lbplanner\helpers\user_helper; +use local_lbplanner\helpers\module; /** * Get all the modules of the given course. @@ -50,14 +51,18 @@ public static function get_all_course_modules_parameters(): external_function_pa * @return array the modules */ public static function get_all_course_modules(int $courseid): array { - global $DB, $USER; + global $DB, $USER, $CFG; + require_once($CFG->dirroot . '/course/lib.php'); self::validate_parameters( self::get_all_course_modules_parameters(), ['courseid' => $courseid] ); - var_dump(get_course($courseid)); - die(var_dump(course_modinfo::get_array_of_activities(get_course($courseid)))); + $activities = course_modinfo::get_array_of_activities(get_course($courseid)); + $modules = []; + foreach ($activities as $activity) { + new module() + } return modules_helper::get_all_course_modules($courseid); } From c242f07ff45680223ef7653686e7fc2f9a6b8e28 Mon Sep 17 00:00:00 2001 From: RiedleroD Date: Tue, 12 Mar 2024 15:22:50 +0100 Subject: [PATCH 04/15] moved enums into their own files (plus EnumCase too) --- lbplanner/classes/enums/NOTIF_STATUS.php | 45 +++++++++++++ lbplanner/classes/enums/NOTIF_TRIGGER.php | 61 ++++++++++++++++++ lbplanner/classes/enums/PLAN_ACCESS_TYPE.php | 53 +++++++++++++++ lbplanner/classes/enums/PLAN_EK.php | 45 +++++++++++++ lbplanner/classes/enums/PLAN_INVITE_STATE.php | 53 +++++++++++++++ .../classes/helpers/notifications_helper.php | 49 +------------- lbplanner/classes/helpers/plan_helper.php | 64 +------------------ .../classes/polyfill/{enum.php => Enum.php} | 23 +------ lbplanner/classes/polyfill/EnumCase.php | 49 ++++++++++++++ lbplanner/services/plan/accept_invite.php | 4 +- lbplanner/services/plan/decline_invite.php | 3 +- lbplanner/services/plan/invite_user.php | 3 +- lbplanner/services/plan/leave_plan.php | 4 +- lbplanner/services/plan/update_access.php | 2 +- lbplanner/services/user/delete_user.php | 9 +-- lbplanner/services/user/register_user.php | 8 +-- lbplanner/version.php | 2 +- 17 files changed, 322 insertions(+), 155 deletions(-) create mode 100644 lbplanner/classes/enums/NOTIF_STATUS.php create mode 100644 lbplanner/classes/enums/NOTIF_TRIGGER.php create mode 100644 lbplanner/classes/enums/PLAN_ACCESS_TYPE.php create mode 100644 lbplanner/classes/enums/PLAN_EK.php create mode 100644 lbplanner/classes/enums/PLAN_INVITE_STATE.php rename lbplanner/classes/polyfill/{enum.php => Enum.php} (84%) create mode 100644 lbplanner/classes/polyfill/EnumCase.php diff --git a/lbplanner/classes/enums/NOTIF_STATUS.php b/lbplanner/classes/enums/NOTIF_STATUS.php new file mode 100644 index 00000000..16f2051c --- /dev/null +++ b/lbplanner/classes/enums/NOTIF_STATUS.php @@ -0,0 +1,45 @@ +. +/** + * enum for notif status + * + * @package local_lbplanner + * @subpackage enums + * @copyright 2024 NecodeIT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_lbplanner\enums; + +defined('MOODLE_INTERNAL') || die(); + +// TODO: revert to native enums once we migrate to php8. + +use local_lbplanner\polyfill\Enum; + +/** + * Stati a notification can be in + */ +class NOTIF_STATUS extends Enum { + /** + * unread notification + */ + const UNREAD = 0; + /** + * read notification + */ + const READ = 1; +} \ No newline at end of file diff --git a/lbplanner/classes/enums/NOTIF_TRIGGER.php b/lbplanner/classes/enums/NOTIF_TRIGGER.php new file mode 100644 index 00000000..f45859fb --- /dev/null +++ b/lbplanner/classes/enums/NOTIF_TRIGGER.php @@ -0,0 +1,61 @@ +. +/** + * enum for notif trigger + * + * @package local_lbplanner + * @subpackage enums + * @copyright 2024 NecodeIT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_lbplanner\enums; + +defined('MOODLE_INTERNAL') || die(); + +// TODO: revert to native enums once we migrate to php8. + +use local_lbplanner\polyfill\Enum; + +/** + * Possible triggers for sending a notification + */ +class NOTIF_TRIGGER extends Enum { + /** + * Invitation sent + */ + const INVITE = 0; + /** + * Invitation accepted + */ + const INVITE_ACCEPTED = 1; + /** + * Invitation declined + */ + const INVITE_DECLINED = 2; + /** + * User left the plan + */ + const PLAN_LEFT = 3; + /** + * User got removed from the plan + */ + const PLAN_REMOVED = 4; + /** + * User registered + */ + const USER_REGISTERED = 5; +} \ No newline at end of file diff --git a/lbplanner/classes/enums/PLAN_ACCESS_TYPE.php b/lbplanner/classes/enums/PLAN_ACCESS_TYPE.php new file mode 100644 index 00000000..d2af279a --- /dev/null +++ b/lbplanner/classes/enums/PLAN_ACCESS_TYPE.php @@ -0,0 +1,53 @@ +. +/** + * enum for plan access type + * + * @package local_lbplanner + * @subpackage enums + * @copyright 2024 NecodeIT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_lbplanner\enums; + +defined('MOODLE_INTERNAL') || die(); + +// TODO: revert to native enums once we migrate to php8. + +use local_lbplanner\polyfill\Enum; + +/** + * Levels of access that a user can have for a plan + */ +class PLAN_ACCESS_TYPE extends Enum { + /** + * owning the plan + */ + const OWNER = 0; + /** + * allowed to modify the plan + */ + const WRITE = 1; + /** + * allowed to look at the plan + */ + const READ = 2; + /** + * disallowed + */ + const NONE = -1; +} \ No newline at end of file diff --git a/lbplanner/classes/enums/PLAN_EK.php b/lbplanner/classes/enums/PLAN_EK.php new file mode 100644 index 00000000..1ecb9174 --- /dev/null +++ b/lbplanner/classes/enums/PLAN_EK.php @@ -0,0 +1,45 @@ +. +/** + * enum for plan EK + * + * @package local_lbplanner + * @subpackage enums + * @copyright 2024 NecodeIT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_lbplanner\enums; + +defined('MOODLE_INTERNAL') || die(); + +// TODO: revert to native enums once we migrate to php8. + +use local_lbplanner\polyfill\Enum; + +/** + * Whether EK modules are enabled inside the planner + */ +class PLAN_EK extends Enum { + /** + * EK hidden + */ + const DISABLED = 0; + /** + * EK visible + */ + const ENABLED = 1; +} \ No newline at end of file diff --git a/lbplanner/classes/enums/PLAN_INVITE_STATE.php b/lbplanner/classes/enums/PLAN_INVITE_STATE.php new file mode 100644 index 00000000..e640c804 --- /dev/null +++ b/lbplanner/classes/enums/PLAN_INVITE_STATE.php @@ -0,0 +1,53 @@ +. +/** + * enum for plan invite state + * + * @package local_lbplanner + * @subpackage enums + * @copyright 2024 NecodeIT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_lbplanner\enums; + +defined('MOODLE_INTERNAL') || die(); + +// TODO: revert to native enums once we migrate to php8. + +use local_lbplanner\polyfill\Enum; + +/** + * States an invite can be in + */ +class PLAN_INVITE_STATE extends Enum { + /** + * pending invite + */ + const PENDING = 0; + /** + * accepted invite + */ + const ACCEPTED = 1; + /** + * declined invite + */ + const DECLINED = 2; + /** + * expired invite + */ + const EXPIRED = 3; +} \ No newline at end of file diff --git a/lbplanner/classes/helpers/notifications_helper.php b/lbplanner/classes/helpers/notifications_helper.php index 9cddb1d4..6b017cc1 100644 --- a/lbplanner/classes/helpers/notifications_helper.php +++ b/lbplanner/classes/helpers/notifications_helper.php @@ -28,54 +28,7 @@ use external_single_structure; use external_value; - -// TODO: revert to native enums once we migrate to php8. - -use local_lbplanner\polyfill\Enum; - -/** - * Stati a notification can be in - */ -class NOTIF_STATUS extends Enum { - /** - * unread notification - */ - const UNREAD = 0; - /** - * read notification - */ - const READ = 1; -} - -/** - * Possible triggers for sending a notification - */ -class NOTIF_TRIGGER extends Enum { - /** - * Invitation sent - */ - const INVITE = 0; - /** - * Invitation accepted - */ - const INVITE_ACCEPTED = 1; - /** - * Invitation declined - */ - const INVITE_DECLINED = 2; - /** - * User left the plan - */ - const PLAN_LEFT = 3; - /** - * User got removed from the plan - */ - const PLAN_REMOVED = 4; - /** - * User registered - */ - const USER_REGISTERED = 5; -} +use local_lbplanner\enums\{NOTIF_STATUS,NOTIF_TRIGGER}; /** * Provides helper methods for notification related stuff diff --git a/lbplanner/classes/helpers/plan_helper.php b/lbplanner/classes/helpers/plan_helper.php index 04a4606d..f4ebb539 100644 --- a/lbplanner/classes/helpers/plan_helper.php +++ b/lbplanner/classes/helpers/plan_helper.php @@ -29,67 +29,7 @@ use external_single_structure; use external_value; use external_multiple_structure; -use local_lbplanner\polyfill\Enum; - -// TODO: revert to native enums once we migrate to php8. - -/** - * Levels of access that a user can have for a plan - */ -class PLAN_ACCESS_TYPE extends Enum { - /** - * owning the plan - */ - const OWNER = 0; - /** - * allowed to modify the plan - */ - const WRITE = 1; - /** - * allowed to look at the plan - */ - const READ = 2; - /** - * disallowed - */ - const NONE = -1; -} - -/** - * Whether EK modules are enabled inside the planner - */ -class PLAN_EK extends Enum { - /** - * EK hidden - */ - const DISABLED = 0; - /** - * EK visible - */ - const ENABLED = 1; -} - -/** - * States an invite can be in - */ -class PLAN_INVITE_STATE extends Enum { - /** - * pending invite - */ - const PENDING = 0; - /** - * accepted invite - */ - const ACCEPTED = 1; - /** - * declined invite - */ - const DECLINED = 2; - /** - * expired invite - */ - const EXPIRED = 3; -} +use local_lbplanner\enums\PLAN_ACCESS_TYPE; /** * Provides helper methods for any tables related with the planning function of the app @@ -294,7 +234,7 @@ public static function plan_structure(): external_single_structure { public static function copy_plan(int $planid, int $userid): int { global $DB; - $user = user_helper::get_mdl_user_info($userid); + $user = user_helper::get_mdl_user_info($userid); # TODO: get_mdl_user_info doesn't exist anymore $plan = $DB->get_record(self::TABLE, ['id' => $planid]); $plan->name = $plan->name . ' (' . $user->username . ')'; diff --git a/lbplanner/classes/polyfill/enum.php b/lbplanner/classes/polyfill/Enum.php similarity index 84% rename from lbplanner/classes/polyfill/enum.php rename to lbplanner/classes/polyfill/Enum.php index 9978de2a..40d85790 100644 --- a/lbplanner/classes/polyfill/enum.php +++ b/lbplanner/classes/polyfill/Enum.php @@ -28,11 +28,12 @@ use ReflectionClass; use ValueError; +use lb_planner_local\polyfill\EnumCase; /** * Class which is meant to serve as a substitute for native enums. */ -abstract class Enum { +class Enum { /** * tries to match the passed value to one of the enum values * @param mixed $value the value to be matched @@ -89,23 +90,3 @@ public static function format(): string { return $result; } } - -/** - * This represents a single case within an Enum - */ -class EnumCase { - /** @var string the name of the case */ - public string $name; - /** @var string the value of the case */ - public mixed $value; - /** - * Constructs an EnumCase - * - * @param string $name the name of the case - * @param mixed $value the value of the case - */ - public function __construct(string $name, mixed $value) { - $this->name = $name; - $this->value = $value; - } -} diff --git a/lbplanner/classes/polyfill/EnumCase.php b/lbplanner/classes/polyfill/EnumCase.php new file mode 100644 index 00000000..ee64dbe9 --- /dev/null +++ b/lbplanner/classes/polyfill/EnumCase.php @@ -0,0 +1,49 @@ +. +/** + * case for enums + * + * @package local_lbplanner + * @subpackage polyfill + * @copyright 2024 NecodeIT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace lb_planner_local\polyfill; + +defined('MOODLE_INTERNAL') || die(); + +// TODO: revert to native enums once we migrate to php8. + +/** + * This represents a single case within an Enum + */ +class EnumCase { + /** @var string the name of the case */ + public string $name; + /** @var string the value of the case */ + public mixed $value; + /** + * Constructs an EnumCase + * + * @param string $name the name of the case + * @param mixed $value the value of the case + */ + public function __construct(string $name, mixed $value) { + $this->name = $name; + $this->value = $value; + } +}; \ No newline at end of file diff --git a/lbplanner/services/plan/accept_invite.php b/lbplanner/services/plan/accept_invite.php index b148e092..15ee7148 100644 --- a/lbplanner/services/plan/accept_invite.php +++ b/lbplanner/services/plan/accept_invite.php @@ -21,9 +21,7 @@ use external_value; use local_lbplanner\helpers\plan_helper; use local_lbplanner\helpers\notifications_helper; -use local_lbplanner\helpers\PLAN_ACCESS_TYPE; -use local_lbplanner\helpers\PLAN_INVITE_STATE; -use local_lbplanner\helpers\NOTIF_TRIGGER; +use local_lbplanner\enums\{PLAN_ACCESS_TYPE,PLAN_INVITE_STATE,NOTIF_TRIGGER}; /** * Accept an invite to the plan. diff --git a/lbplanner/services/plan/decline_invite.php b/lbplanner/services/plan/decline_invite.php index 59191871..af25d7dd 100644 --- a/lbplanner/services/plan/decline_invite.php +++ b/lbplanner/services/plan/decline_invite.php @@ -19,10 +19,9 @@ use external_api; use external_function_parameters; use external_value; -use local_lbplanner\helpers\NOTIF_TRIGGER; use local_lbplanner\helpers\plan_helper; use local_lbplanner\helpers\notifications_helper; -use local_lbplanner\helpers\PLAN_INVITE_STATE; +use local_lbplanner\enums\{NOTIF_TRIGGER,PLAN_INVITE_STATE}; /** * Decline an invite from the plan. diff --git a/lbplanner/services/plan/invite_user.php b/lbplanner/services/plan/invite_user.php index 41b3469c..3584e7a3 100644 --- a/lbplanner/services/plan/invite_user.php +++ b/lbplanner/services/plan/invite_user.php @@ -21,10 +21,9 @@ use external_single_structure; use external_value; use local_lbplanner\helpers\invite_helper; -use local_lbplanner\helpers\NOTIF_TRIGGER; use local_lbplanner\helpers\plan_helper; use local_lbplanner\helpers\notifications_helper; -use local_lbplanner\helpers\PLAN_INVITE_STATE; +use local_lbplanner\enums\{NOTIF_TRIGGER,PLAN_INVITE_STATE}; /** * Invite a user to the current user's plan diff --git a/lbplanner/services/plan/leave_plan.php b/lbplanner/services/plan/leave_plan.php index b7600e36..c4cb7e6c 100644 --- a/lbplanner/services/plan/leave_plan.php +++ b/lbplanner/services/plan/leave_plan.php @@ -18,11 +18,9 @@ use external_api; use external_function_parameters; -use local_lbplanner\helpers\NOTIF_TRIGGER; use local_lbplanner\helpers\plan_helper; use local_lbplanner\helpers\notifications_helper; -use local_lbplanner\helpers\PLAN_ACCESS_TYPE; -use local_lbplanner\helpers\PLAN_INVITE_STATE; +use local_lbplanner\enums\{NOTIF_TRIGGER,PLAN_ACCESS_TYPE,PLAN_INVITE_STATE}; /** * Leave your plan diff --git a/lbplanner/services/plan/update_access.php b/lbplanner/services/plan/update_access.php index b4a79e86..a9ddd3ea 100644 --- a/lbplanner/services/plan/update_access.php +++ b/lbplanner/services/plan/update_access.php @@ -19,7 +19,7 @@ use external_api; use external_function_parameters; use external_value; -use local_lbplanner\helpers\PLAN_ACCESS_TYPE; +use local_lbplanner\enums\PLAN_ACCESS_TYPE; use local_lbplanner\helpers\plan_helper; /** diff --git a/lbplanner/services/user/delete_user.php b/lbplanner/services/user/delete_user.php index 9a7b9dd0..aee10072 100644 --- a/lbplanner/services/user/delete_user.php +++ b/lbplanner/services/user/delete_user.php @@ -19,12 +19,9 @@ use dml_exception; use external_api; use external_function_parameters; -use external_single_structure; use external_value; -use local_lbplanner\helpers\user_helper; -use local_lbplanner\helpers\plan_helper; -use local_lbplanner\helpers\course_helper; -use local_lbplanner\helpers\notifications_helper; +use local_lbplanner\helpers\{user_helper,plan_helper,course_helper,notifications_helper}; +use local_lbplanner\enums\{PLAN_INVITE_STATE,PLAN_ACCESS_TYPE}; use moodle_exception; /** @@ -81,7 +78,7 @@ public static function delete_user($userid) { if ( !(count(plan_helper::get_plan_members($planid)) == 1 ) && - !(plan_helper::get_access_type($planid, $userid) == plan_helper::ACCESS_TYPE_OWNER)) { + !(plan_helper::get_access_type($planid, $userid) == PLAN_ACCESS_TYPE::OWNER)) { self::call_external_function('local_lbplanner_plan_leave_plan', ['userid' => $userid, 'planid' => $planid]); } $DB->delete_records(plan_helper::DEADLINES_TABLE, ['planid' => $planid]); diff --git a/lbplanner/services/user/register_user.php b/lbplanner/services/user/register_user.php index aed07f2d..6eadd153 100644 --- a/lbplanner/services/user/register_user.php +++ b/lbplanner/services/user/register_user.php @@ -22,12 +22,8 @@ use external_single_structure; use external_value; use invalid_parameter_exception; -use local_lbplanner\helpers\NOTIF_TRIGGER; -use local_lbplanner\helpers\PLAN_ACCESS_TYPE; -use local_lbplanner\helpers\PLAN_EK; -use local_lbplanner\helpers\user_helper; -use local_lbplanner\helpers\plan_helper; -use local_lbplanner\helpers\notifications_helper; +use local_lbplanner\helpers\{user_helper,plan_helper,notifications_helper}; +use local_lbplanner\enums\{NOTIF_TRIGGER,PLAN_ACCESS_TYPE,PLAN_EK}; use moodle_exception; use stdClass; diff --git a/lbplanner/version.php b/lbplanner/version.php index d3e51d99..caab6006 100644 --- a/lbplanner/version.php +++ b/lbplanner/version.php @@ -27,7 +27,7 @@ $plugin->component = 'local_lbplanner'; $plugin->release = 'Alpha v.'.$release; -$plugin->version = 2024022700; +$plugin->version = 2024031200; $plugin->dependencies = [ // Depend upon version 2023110600 of local_modcustomfields. 'local_modcustomfields' => 2023110600, From 03b36dd323533129c29494304066a83e7c0077b8 Mon Sep 17 00:00:00 2001 From: Muhi Date: Tue, 12 Mar 2024 15:35:31 +0100 Subject: [PATCH 05/15] IT WORKS, kinda --- lbplanner/classes/model/activity.php | 47 +++++++++++++++++++ .../modules/get_all_course_modules.php | 29 +++++++----- 2 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 lbplanner/classes/model/activity.php diff --git a/lbplanner/classes/model/activity.php b/lbplanner/classes/model/activity.php new file mode 100644 index 00000000..4325e521 --- /dev/null +++ b/lbplanner/classes/model/activity.php @@ -0,0 +1,47 @@ +. +/** + * Collection of helper classes for handling modules + * + * @package local_lbplanner + * @subpackage helpers + * @copyright 2024 NecodeIT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_lbplanner\model; + +class activity { + public $moduleid; + public $name; + public $courseid; + public $status; + public $type; + public $url; + public $grade; + public $deadline; + public function __construct($moduleid, $name, $courseid, $status, $type, $url, $grade, $deadline) { + $this->moduleid = $moduleid; + $this->name = $name; + $this->courseid = $courseid; + $this->status = $status; + $this->type = $type; + $this->url = $url; + $this->grade = $grade; + $this->deadline = $deadline; + } +} + diff --git a/lbplanner/services/modules/get_all_course_modules.php b/lbplanner/services/modules/get_all_course_modules.php index 52ee1e73..23ec08e4 100644 --- a/lbplanner/services/modules/get_all_course_modules.php +++ b/lbplanner/services/modules/get_all_course_modules.php @@ -16,14 +16,16 @@ namespace local_lbplanner_services; + +use core_external\external_single_structure; use course_modinfo; use external_api; use external_function_parameters; use external_multiple_structure; use external_value; use local_lbplanner\helpers\modules_helper; -use local_lbplanner\helpers\user_helper; -use local_lbplanner\helpers\module; +use local_lbplanner\model\activity; +use moodle_url; /** * Get all the modules of the given course. @@ -48,12 +50,12 @@ public static function get_all_course_modules_parameters(): external_function_pa * * @param int $courseid The ID of the course * @param bool $ekenabled whether or not to include ek modules - * @return array the modules + * @return array|null the modules */ - public static function get_all_course_modules(int $courseid): array { + public static function get_all_course_modules(int $courseid): ?array { global $DB, $USER, $CFG; require_once($CFG->dirroot . '/course/lib.php'); - + // path to the module class which is in this plugin self::validate_parameters( self::get_all_course_modules_parameters(), ['courseid' => $courseid] @@ -61,18 +63,23 @@ public static function get_all_course_modules(int $courseid): array { $activities = course_modinfo::get_array_of_activities(get_course($courseid)); $modules = []; foreach ($activities as $activity) { - new module() + $type = $activity->mod; + $id = $activity->id; + $deadline = $activity->duedate; + $name = $activity->name; + $cmid = $activity->cm; + $url = new moodle_url('/mod/'.$type.'/view.php', ['id' => $cmid]); + $modules[] = new activity($id, $name, $courseid , null, $type, $url->out(false), null, $deadline); } - return modules_helper::get_all_course_modules($courseid); + die(var_dump($modules)); + return $type; } /** * Returns the structure of the module array. * @return external_multiple_structure */ - public static function get_all_course_modules_returns(): external_multiple_structure { - return new external_multiple_structure( - modules_helper::structure(), - ); + public static function get_all_course_modules_returns() { + new external_value(PARAM_INT, 'Module ID'); } } From bd73bf41bc0104abd44c897dfb43591162072814 Mon Sep 17 00:00:00 2001 From: RiedleroD Date: Tue, 12 Mar 2024 15:37:30 +0100 Subject: [PATCH 06/15] removed unneeded moodle internal checks --- lbplanner/classes/enums/NOTIF_STATUS.php | 2 -- lbplanner/classes/enums/NOTIF_TRIGGER.php | 2 -- lbplanner/classes/enums/PLAN_ACCESS_TYPE.php | 2 -- lbplanner/classes/enums/PLAN_EK.php | 2 -- lbplanner/classes/enums/PLAN_INVITE_STATE.php | 2 -- lbplanner/classes/helpers/notifications_helper.php | 2 -- lbplanner/classes/helpers/plan_helper.php | 2 -- lbplanner/classes/polyfill/Enum.php | 2 -- lbplanner/classes/polyfill/EnumCase.php | 2 -- 9 files changed, 18 deletions(-) diff --git a/lbplanner/classes/enums/NOTIF_STATUS.php b/lbplanner/classes/enums/NOTIF_STATUS.php index 16f2051c..547fb050 100644 --- a/lbplanner/classes/enums/NOTIF_STATUS.php +++ b/lbplanner/classes/enums/NOTIF_STATUS.php @@ -24,8 +24,6 @@ namespace local_lbplanner\enums; -defined('MOODLE_INTERNAL') || die(); - // TODO: revert to native enums once we migrate to php8. use local_lbplanner\polyfill\Enum; diff --git a/lbplanner/classes/enums/NOTIF_TRIGGER.php b/lbplanner/classes/enums/NOTIF_TRIGGER.php index f45859fb..e098a1a3 100644 --- a/lbplanner/classes/enums/NOTIF_TRIGGER.php +++ b/lbplanner/classes/enums/NOTIF_TRIGGER.php @@ -24,8 +24,6 @@ namespace local_lbplanner\enums; -defined('MOODLE_INTERNAL') || die(); - // TODO: revert to native enums once we migrate to php8. use local_lbplanner\polyfill\Enum; diff --git a/lbplanner/classes/enums/PLAN_ACCESS_TYPE.php b/lbplanner/classes/enums/PLAN_ACCESS_TYPE.php index d2af279a..3a30f540 100644 --- a/lbplanner/classes/enums/PLAN_ACCESS_TYPE.php +++ b/lbplanner/classes/enums/PLAN_ACCESS_TYPE.php @@ -24,8 +24,6 @@ namespace local_lbplanner\enums; -defined('MOODLE_INTERNAL') || die(); - // TODO: revert to native enums once we migrate to php8. use local_lbplanner\polyfill\Enum; diff --git a/lbplanner/classes/enums/PLAN_EK.php b/lbplanner/classes/enums/PLAN_EK.php index 1ecb9174..2b4ea015 100644 --- a/lbplanner/classes/enums/PLAN_EK.php +++ b/lbplanner/classes/enums/PLAN_EK.php @@ -24,8 +24,6 @@ namespace local_lbplanner\enums; -defined('MOODLE_INTERNAL') || die(); - // TODO: revert to native enums once we migrate to php8. use local_lbplanner\polyfill\Enum; diff --git a/lbplanner/classes/enums/PLAN_INVITE_STATE.php b/lbplanner/classes/enums/PLAN_INVITE_STATE.php index e640c804..ad60c949 100644 --- a/lbplanner/classes/enums/PLAN_INVITE_STATE.php +++ b/lbplanner/classes/enums/PLAN_INVITE_STATE.php @@ -24,8 +24,6 @@ namespace local_lbplanner\enums; -defined('MOODLE_INTERNAL') || die(); - // TODO: revert to native enums once we migrate to php8. use local_lbplanner\polyfill\Enum; diff --git a/lbplanner/classes/helpers/notifications_helper.php b/lbplanner/classes/helpers/notifications_helper.php index 6b017cc1..e3ac19c5 100644 --- a/lbplanner/classes/helpers/notifications_helper.php +++ b/lbplanner/classes/helpers/notifications_helper.php @@ -24,8 +24,6 @@ namespace local_lbplanner\helpers; -defined('MOODLE_INTERNAL') || die(); - use external_single_structure; use external_value; use local_lbplanner\enums\{NOTIF_STATUS,NOTIF_TRIGGER}; diff --git a/lbplanner/classes/helpers/plan_helper.php b/lbplanner/classes/helpers/plan_helper.php index f4ebb539..ed9c79f8 100644 --- a/lbplanner/classes/helpers/plan_helper.php +++ b/lbplanner/classes/helpers/plan_helper.php @@ -24,8 +24,6 @@ namespace local_lbplanner\helpers; -defined('MOODLE_INTERNAL') || die(); - use external_single_structure; use external_value; use external_multiple_structure; diff --git a/lbplanner/classes/polyfill/Enum.php b/lbplanner/classes/polyfill/Enum.php index 40d85790..1d8b7b19 100644 --- a/lbplanner/classes/polyfill/Enum.php +++ b/lbplanner/classes/polyfill/Enum.php @@ -24,8 +24,6 @@ namespace local_lbplanner\polyfill; -defined('MOODLE_INTERNAL') || die(); - use ReflectionClass; use ValueError; use lb_planner_local\polyfill\EnumCase; diff --git a/lbplanner/classes/polyfill/EnumCase.php b/lbplanner/classes/polyfill/EnumCase.php index ee64dbe9..392d1c25 100644 --- a/lbplanner/classes/polyfill/EnumCase.php +++ b/lbplanner/classes/polyfill/EnumCase.php @@ -24,8 +24,6 @@ namespace lb_planner_local\polyfill; -defined('MOODLE_INTERNAL') || die(); - // TODO: revert to native enums once we migrate to php8. /** From 837cf7e2c076f2a94d2d0da8e0ce14b937e2cb1d Mon Sep 17 00:00:00 2001 From: RiedleroD Date: Tue, 12 Mar 2024 15:38:04 +0100 Subject: [PATCH 07/15] fixed accidental tab indents --- lbplanner/classes/polyfill/EnumCase.php | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lbplanner/classes/polyfill/EnumCase.php b/lbplanner/classes/polyfill/EnumCase.php index 392d1c25..73ef0739 100644 --- a/lbplanner/classes/polyfill/EnumCase.php +++ b/lbplanner/classes/polyfill/EnumCase.php @@ -30,18 +30,18 @@ * This represents a single case within an Enum */ class EnumCase { - /** @var string the name of the case */ - public string $name; - /** @var string the value of the case */ - public mixed $value; - /** - * Constructs an EnumCase - * - * @param string $name the name of the case - * @param mixed $value the value of the case - */ - public function __construct(string $name, mixed $value) { - $this->name = $name; - $this->value = $value; - } + /** @var string the name of the case */ + public string $name; + /** @var string the value of the case */ + public mixed $value; + /** + * Constructs an EnumCase + * + * @param string $name the name of the case + * @param mixed $value the value of the case + */ + public function __construct(string $name, mixed $value) { + $this->name = $name; + $this->value = $value; + } }; \ No newline at end of file From 96d21f34ae83fe2f6ae1291b0b13cf7725014179 Mon Sep 17 00:00:00 2001 From: RiedleroD Date: Tue, 12 Mar 2024 15:43:00 +0100 Subject: [PATCH 08/15] moved more enums out of modules_helper --- lbplanner/classes/enums/MODULE_GRADE.php | 55 +++++++++++++ lbplanner/classes/enums/MODULE_STATUS.php | 51 ++++++++++++ lbplanner/classes/enums/MODULE_TYPE.php | 55 +++++++++++++ lbplanner/classes/helpers/modules_helper.php | 82 +------------------- 4 files changed, 162 insertions(+), 81 deletions(-) create mode 100644 lbplanner/classes/enums/MODULE_GRADE.php create mode 100644 lbplanner/classes/enums/MODULE_STATUS.php create mode 100644 lbplanner/classes/enums/MODULE_TYPE.php diff --git a/lbplanner/classes/enums/MODULE_GRADE.php b/lbplanner/classes/enums/MODULE_GRADE.php new file mode 100644 index 00000000..1a56a8e3 --- /dev/null +++ b/lbplanner/classes/enums/MODULE_GRADE.php @@ -0,0 +1,55 @@ +. +/** + * enum for module grade + * + * @package local_lbplanner + * @subpackage enums + * @copyright 2024 NecodeIT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_lbplanner\enums; + +// TODO: revert to native enums once we migrate to php8. + +use local_lbplanner\polyfill\Enum; + +/** + * Grades a module can receive + */ +class MODULE_GRADE extends Enum { + /** + * Erweiterte Kompetenz vollständig. + */ + const EKV = 0; + /** + * Erweiterte Kompetenz überwiegend. + */ + const EK = 1; + /** + * Grundlegende Kompetenz vollständig. + */ + const GKV = 2; + /** + * Grundlegende Kompetenz überwiegend. + */ + const GK = 3; + /** + * Negative grade. + */ + const RIP = 4; +} \ No newline at end of file diff --git a/lbplanner/classes/enums/MODULE_STATUS.php b/lbplanner/classes/enums/MODULE_STATUS.php new file mode 100644 index 00000000..0b704c01 --- /dev/null +++ b/lbplanner/classes/enums/MODULE_STATUS.php @@ -0,0 +1,51 @@ +. +/** + * enum for module status + * + * @package local_lbplanner + * @subpackage enums + * @copyright 2024 NecodeIT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_lbplanner\enums; + +// TODO: revert to native enums once we migrate to php8. + +use local_lbplanner\polyfill\Enum; + +/** + * Stati a module can be in + */ +class MODULE_STATUS extends Enum { + /** + * Finished module. + */ + const DONE = 0; + /** + * Uploaded module. + */ + const UPLOADED = 1; + /** + * Overdue module. + */ + const LATE = 2; + /** + * Todo module. + */ + const PENDING = 3; +} \ No newline at end of file diff --git a/lbplanner/classes/enums/MODULE_TYPE.php b/lbplanner/classes/enums/MODULE_TYPE.php new file mode 100644 index 00000000..c5525d9b --- /dev/null +++ b/lbplanner/classes/enums/MODULE_TYPE.php @@ -0,0 +1,55 @@ +. +/** + * enum for module type + * + * @package local_lbplanner + * @subpackage enums + * @copyright 2024 NecodeIT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_lbplanner\enums; + +// TODO: revert to native enums once we migrate to php8. + +use local_lbplanner\polyfill\Enum; + +/** + * Module Types + */ +class MODULE_TYPE extends Enum { + /** + * Grundlegende Kompetenz. + */ + const GK = 0; + /** + * Erweiterte Kompetenz. + */ + const EK = 1; + /** + * Test i.e. exam. + */ + const TEST = 2; + /** + * TODO: ??? + */ + const M = 3; + /** + * TODO: ??? + */ + const NONE = 4; +} \ No newline at end of file diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index aa0c2179..d93d3ed6 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -24,92 +24,12 @@ namespace local_lbplanner\helpers; -defined('MOODLE_INTERNAL') || die(); - use block_accessreview\external\get_module_data; use external_function_parameters; use external_single_structure; use external_value; use moodle_url; - -use local_lbplanner\polyfill\Enum; - - -// TODO: revert to native enums once we migrate to php8. - -/** - * Stati a module can be in - */ -class MODULE_STATUS extends Enum { - /** - * Finished module. - */ - const DONE = 0; - /** - * Uploaded module. - */ - const UPLOADED = 1; - /** - * Overdue module. - */ - const LATE = 2; - /** - * Todo module. - */ - const PENDING = 3; -} - -/** - * Grades a module can receive - */ -class MODULE_GRADE extends Enum { - /** - * Erweiterte Kompetenz vollständig. - */ - const EKV = 0; - /** - * Erweiterte Kompetenz überwiegend. - */ - const EK = 1; - /** - * Grundlegende Kompetenz vollständig. - */ - const GKV = 2; - /** - * Grundlegende Kompetenz überwiegend. - */ - const GK = 3; - /** - * Negative grade. - */ - const RIP = 4; -} - -/** - * Module Types - */ -class MODULE_TYPE extends Enum { - /** - * Grundlegende Kompetenz. - */ - const GK = 0; - /** - * Erweiterte Kompetenz. - */ - const EK = 1; - /** - * Test i.e. exam. - */ - const TEST = 2; - /** - * TODO: ??? - */ - const M = 3; - /** - * TODO: ??? - */ - const NONE = 4; -} +use local_lbplanner\enums\{MODULE_STATUS,MODULE_GRADE,MODULE_TYPE}; /** * Contains helper functions for working with modules. From f059d50046bd0fee1e5b3fcbe3d82557554aa714 Mon Sep 17 00:00:00 2001 From: RiedleroD Date: Tue, 12 Mar 2024 15:48:09 +0100 Subject: [PATCH 09/15] lots of smaller formatting and CI fixes --- lbplanner/classes/enums/MODULE_GRADE.php | 2 +- lbplanner/classes/enums/MODULE_STATUS.php | 2 +- lbplanner/classes/enums/MODULE_TYPE.php | 2 +- lbplanner/classes/enums/NOTIF_STATUS.php | 2 +- lbplanner/classes/enums/NOTIF_TRIGGER.php | 2 +- lbplanner/classes/enums/PLAN_ACCESS_TYPE.php | 2 +- lbplanner/classes/enums/PLAN_EK.php | 2 +- lbplanner/classes/enums/PLAN_INVITE_STATE.php | 2 +- lbplanner/classes/helpers/notifications_helper.php | 2 +- lbplanner/classes/helpers/plan_helper.php | 2 +- lbplanner/classes/polyfill/EnumCase.php | 4 +++- lbplanner/services/plan/accept_invite.php | 2 +- lbplanner/services/plan/decline_invite.php | 2 +- lbplanner/services/plan/invite_user.php | 2 +- lbplanner/services/plan/leave_plan.php | 2 +- lbplanner/services/user/delete_user.php | 2 +- lbplanner/services/user/register_user.php | 2 +- 17 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lbplanner/classes/enums/MODULE_GRADE.php b/lbplanner/classes/enums/MODULE_GRADE.php index 1a56a8e3..4cbe7a47 100644 --- a/lbplanner/classes/enums/MODULE_GRADE.php +++ b/lbplanner/classes/enums/MODULE_GRADE.php @@ -52,4 +52,4 @@ class MODULE_GRADE extends Enum { * Negative grade. */ const RIP = 4; -} \ No newline at end of file +} diff --git a/lbplanner/classes/enums/MODULE_STATUS.php b/lbplanner/classes/enums/MODULE_STATUS.php index 0b704c01..7f0d87b1 100644 --- a/lbplanner/classes/enums/MODULE_STATUS.php +++ b/lbplanner/classes/enums/MODULE_STATUS.php @@ -48,4 +48,4 @@ class MODULE_STATUS extends Enum { * Todo module. */ const PENDING = 3; -} \ No newline at end of file +} diff --git a/lbplanner/classes/enums/MODULE_TYPE.php b/lbplanner/classes/enums/MODULE_TYPE.php index c5525d9b..47de6a0f 100644 --- a/lbplanner/classes/enums/MODULE_TYPE.php +++ b/lbplanner/classes/enums/MODULE_TYPE.php @@ -52,4 +52,4 @@ class MODULE_TYPE extends Enum { * TODO: ??? */ const NONE = 4; -} \ No newline at end of file +} diff --git a/lbplanner/classes/enums/NOTIF_STATUS.php b/lbplanner/classes/enums/NOTIF_STATUS.php index 547fb050..aef9d02f 100644 --- a/lbplanner/classes/enums/NOTIF_STATUS.php +++ b/lbplanner/classes/enums/NOTIF_STATUS.php @@ -40,4 +40,4 @@ class NOTIF_STATUS extends Enum { * read notification */ const READ = 1; -} \ No newline at end of file +} diff --git a/lbplanner/classes/enums/NOTIF_TRIGGER.php b/lbplanner/classes/enums/NOTIF_TRIGGER.php index e098a1a3..3b1be9fd 100644 --- a/lbplanner/classes/enums/NOTIF_TRIGGER.php +++ b/lbplanner/classes/enums/NOTIF_TRIGGER.php @@ -56,4 +56,4 @@ class NOTIF_TRIGGER extends Enum { * User registered */ const USER_REGISTERED = 5; -} \ No newline at end of file +} diff --git a/lbplanner/classes/enums/PLAN_ACCESS_TYPE.php b/lbplanner/classes/enums/PLAN_ACCESS_TYPE.php index 3a30f540..3b8b07f1 100644 --- a/lbplanner/classes/enums/PLAN_ACCESS_TYPE.php +++ b/lbplanner/classes/enums/PLAN_ACCESS_TYPE.php @@ -48,4 +48,4 @@ class PLAN_ACCESS_TYPE extends Enum { * disallowed */ const NONE = -1; -} \ No newline at end of file +} diff --git a/lbplanner/classes/enums/PLAN_EK.php b/lbplanner/classes/enums/PLAN_EK.php index 2b4ea015..302ecdb1 100644 --- a/lbplanner/classes/enums/PLAN_EK.php +++ b/lbplanner/classes/enums/PLAN_EK.php @@ -40,4 +40,4 @@ class PLAN_EK extends Enum { * EK visible */ const ENABLED = 1; -} \ No newline at end of file +} diff --git a/lbplanner/classes/enums/PLAN_INVITE_STATE.php b/lbplanner/classes/enums/PLAN_INVITE_STATE.php index ad60c949..58a4f569 100644 --- a/lbplanner/classes/enums/PLAN_INVITE_STATE.php +++ b/lbplanner/classes/enums/PLAN_INVITE_STATE.php @@ -48,4 +48,4 @@ class PLAN_INVITE_STATE extends Enum { * expired invite */ const EXPIRED = 3; -} \ No newline at end of file +} diff --git a/lbplanner/classes/helpers/notifications_helper.php b/lbplanner/classes/helpers/notifications_helper.php index e3ac19c5..adf1c50d 100644 --- a/lbplanner/classes/helpers/notifications_helper.php +++ b/lbplanner/classes/helpers/notifications_helper.php @@ -26,7 +26,7 @@ use external_single_structure; use external_value; -use local_lbplanner\enums\{NOTIF_STATUS,NOTIF_TRIGGER}; +use local_lbplanner\enums\{NOTIF_STATUS, NOTIF_TRIGGER}; /** * Provides helper methods for notification related stuff diff --git a/lbplanner/classes/helpers/plan_helper.php b/lbplanner/classes/helpers/plan_helper.php index ed9c79f8..52065195 100644 --- a/lbplanner/classes/helpers/plan_helper.php +++ b/lbplanner/classes/helpers/plan_helper.php @@ -232,7 +232,7 @@ public static function plan_structure(): external_single_structure { public static function copy_plan(int $planid, int $userid): int { global $DB; - $user = user_helper::get_mdl_user_info($userid); # TODO: get_mdl_user_info doesn't exist anymore + $user = user_helper::get_mdl_user_info($userid); // TODO: get_mdl_user_info doesn't exist anymore $plan = $DB->get_record(self::TABLE, ['id' => $planid]); $plan->name = $plan->name . ' (' . $user->username . ')'; diff --git a/lbplanner/classes/polyfill/EnumCase.php b/lbplanner/classes/polyfill/EnumCase.php index 73ef0739..f5e35750 100644 --- a/lbplanner/classes/polyfill/EnumCase.php +++ b/lbplanner/classes/polyfill/EnumCase.php @@ -24,6 +24,8 @@ namespace lb_planner_local\polyfill; +defined('MOODLE_INTERNAL') || die(); + // TODO: revert to native enums once we migrate to php8. /** @@ -44,4 +46,4 @@ public function __construct(string $name, mixed $value) { $this->name = $name; $this->value = $value; } -}; \ No newline at end of file +}; diff --git a/lbplanner/services/plan/accept_invite.php b/lbplanner/services/plan/accept_invite.php index 15ee7148..e3c8893c 100644 --- a/lbplanner/services/plan/accept_invite.php +++ b/lbplanner/services/plan/accept_invite.php @@ -21,7 +21,7 @@ use external_value; use local_lbplanner\helpers\plan_helper; use local_lbplanner\helpers\notifications_helper; -use local_lbplanner\enums\{PLAN_ACCESS_TYPE,PLAN_INVITE_STATE,NOTIF_TRIGGER}; +use local_lbplanner\enums\{PLAN_ACCESS_TYPE, PLAN_INVITE_STATE, NOTIF_TRIGGER}; /** * Accept an invite to the plan. diff --git a/lbplanner/services/plan/decline_invite.php b/lbplanner/services/plan/decline_invite.php index af25d7dd..044672e9 100644 --- a/lbplanner/services/plan/decline_invite.php +++ b/lbplanner/services/plan/decline_invite.php @@ -21,7 +21,7 @@ use external_value; use local_lbplanner\helpers\plan_helper; use local_lbplanner\helpers\notifications_helper; -use local_lbplanner\enums\{NOTIF_TRIGGER,PLAN_INVITE_STATE}; +use local_lbplanner\enums\{NOTIF_TRIGGER, PLAN_INVITE_STATE}; /** * Decline an invite from the plan. diff --git a/lbplanner/services/plan/invite_user.php b/lbplanner/services/plan/invite_user.php index 3584e7a3..e572fdf1 100644 --- a/lbplanner/services/plan/invite_user.php +++ b/lbplanner/services/plan/invite_user.php @@ -23,7 +23,7 @@ use local_lbplanner\helpers\invite_helper; use local_lbplanner\helpers\plan_helper; use local_lbplanner\helpers\notifications_helper; -use local_lbplanner\enums\{NOTIF_TRIGGER,PLAN_INVITE_STATE}; +use local_lbplanner\enums\{NOTIF_TRIGGER, PLAN_INVITE_STATE}; /** * Invite a user to the current user's plan diff --git a/lbplanner/services/plan/leave_plan.php b/lbplanner/services/plan/leave_plan.php index c4cb7e6c..5a7e9b28 100644 --- a/lbplanner/services/plan/leave_plan.php +++ b/lbplanner/services/plan/leave_plan.php @@ -20,7 +20,7 @@ use external_function_parameters; use local_lbplanner\helpers\plan_helper; use local_lbplanner\helpers\notifications_helper; -use local_lbplanner\enums\{NOTIF_TRIGGER,PLAN_ACCESS_TYPE,PLAN_INVITE_STATE}; +use local_lbplanner\enums\{NOTIF_TRIGGER, PLAN_ACCESS_TYPE, PLAN_INVITE_STATE}; /** * Leave your plan diff --git a/lbplanner/services/user/delete_user.php b/lbplanner/services/user/delete_user.php index aee10072..d8d6f87e 100644 --- a/lbplanner/services/user/delete_user.php +++ b/lbplanner/services/user/delete_user.php @@ -21,7 +21,7 @@ use external_function_parameters; use external_value; use local_lbplanner\helpers\{user_helper,plan_helper,course_helper,notifications_helper}; -use local_lbplanner\enums\{PLAN_INVITE_STATE,PLAN_ACCESS_TYPE}; +use local_lbplanner\enums\{PLAN_INVITE_STATE, PLAN_ACCESS_TYPE}; use moodle_exception; /** diff --git a/lbplanner/services/user/register_user.php b/lbplanner/services/user/register_user.php index 6eadd153..f2cae9d4 100644 --- a/lbplanner/services/user/register_user.php +++ b/lbplanner/services/user/register_user.php @@ -23,7 +23,7 @@ use external_value; use invalid_parameter_exception; use local_lbplanner\helpers\{user_helper,plan_helper,notifications_helper}; -use local_lbplanner\enums\{NOTIF_TRIGGER,PLAN_ACCESS_TYPE,PLAN_EK}; +use local_lbplanner\enums\{NOTIF_TRIGGER, PLAN_ACCESS_TYPE, PLAN_EK}; use moodle_exception; use stdClass; From da8439838add987ab08bde7dd08e0a2fc3f1bd5b Mon Sep 17 00:00:00 2001 From: RiedleroD Date: Tue, 12 Mar 2024 15:52:29 +0100 Subject: [PATCH 10/15] more CI fixes --- lbplanner/classes/helpers/modules_helper.php | 2 +- lbplanner/classes/helpers/plan_helper.php | 2 +- lbplanner/services/user/delete_user.php | 2 +- lbplanner/services/user/register_user.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index d93d3ed6..51b06eed 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -29,7 +29,7 @@ use external_single_structure; use external_value; use moodle_url; -use local_lbplanner\enums\{MODULE_STATUS,MODULE_GRADE,MODULE_TYPE}; +use local_lbplanner\enums\{MODULE_STATUS, MODULE_GRADE, MODULE_TYPE}; /** * Contains helper functions for working with modules. diff --git a/lbplanner/classes/helpers/plan_helper.php b/lbplanner/classes/helpers/plan_helper.php index 52065195..d7a79648 100644 --- a/lbplanner/classes/helpers/plan_helper.php +++ b/lbplanner/classes/helpers/plan_helper.php @@ -232,7 +232,7 @@ public static function plan_structure(): external_single_structure { public static function copy_plan(int $planid, int $userid): int { global $DB; - $user = user_helper::get_mdl_user_info($userid); // TODO: get_mdl_user_info doesn't exist anymore + $user = user_helper::get_mdl_user_info($userid); // TODO: get_mdl_user_info doesn't exist anymore. $plan = $DB->get_record(self::TABLE, ['id' => $planid]); $plan->name = $plan->name . ' (' . $user->username . ')'; diff --git a/lbplanner/services/user/delete_user.php b/lbplanner/services/user/delete_user.php index d8d6f87e..01c90bfc 100644 --- a/lbplanner/services/user/delete_user.php +++ b/lbplanner/services/user/delete_user.php @@ -20,7 +20,7 @@ use external_api; use external_function_parameters; use external_value; -use local_lbplanner\helpers\{user_helper,plan_helper,course_helper,notifications_helper}; +use local_lbplanner\helpers\{user_helper, plan_helper, course_helper, notifications_helper}; use local_lbplanner\enums\{PLAN_INVITE_STATE, PLAN_ACCESS_TYPE}; use moodle_exception; diff --git a/lbplanner/services/user/register_user.php b/lbplanner/services/user/register_user.php index f2cae9d4..67e0562f 100644 --- a/lbplanner/services/user/register_user.php +++ b/lbplanner/services/user/register_user.php @@ -22,7 +22,7 @@ use external_single_structure; use external_value; use invalid_parameter_exception; -use local_lbplanner\helpers\{user_helper,plan_helper,notifications_helper}; +use local_lbplanner\helpers\{user_helper, plan_helper, notifications_helper}; use local_lbplanner\enums\{NOTIF_TRIGGER, PLAN_ACCESS_TYPE, PLAN_EK}; use moodle_exception; use stdClass; From c409c6f738f1118260ceaba9a19fd26f343ef0e9 Mon Sep 17 00:00:00 2001 From: Muhi Date: Tue, 12 Mar 2024 21:30:14 +0100 Subject: [PATCH 11/15] added url check --- lbplanner/classes/helpers/modules_helper.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index 52974ffe..ca83d89a 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -229,15 +229,9 @@ public static function determin_type(string $modulename): int { * @param int $courseid The id of the course. * @return string The url of the module. */ - public static function get_module_url(int $moduleid, int $courseid): string { - global $DB; - - $view = $DB->get_record( - self::COURSE_MODULES_TABLE, - ['course' => $courseid, 'instance' => $moduleid, 'module' => 1] - ); - - return strval(new moodle_url('/mod/assign/view.php?id='.$view->id)); + public static function get_module_url(string $type, int $cmid): string { + $url = new moodle_url('/mod/'.$type.'/view.php', ['id' => $cmid]); + return $url->out(false); } /** From c5b6d863d3dae0459d43ed90e5e4f31b6f10c781 Mon Sep 17 00:00:00 2001 From: Muhi Date: Tue, 12 Mar 2024 22:55:24 +0100 Subject: [PATCH 12/15] Tried to read from custom data --- lbplanner/classes/helpers/config_helper.php | 5 +- lbplanner/classes/helpers/modules_helper.php | 123 ++++-------------- lbplanner/classes/model/activity.php | 4 +- .../modules/get_all_course_modules.php | 14 +- 4 files changed, 39 insertions(+), 107 deletions(-) diff --git a/lbplanner/classes/helpers/config_helper.php b/lbplanner/classes/helpers/config_helper.php index 57c65be4..868ca930 100644 --- a/lbplanner/classes/helpers/config_helper.php +++ b/lbplanner/classes/helpers/config_helper.php @@ -67,9 +67,10 @@ public static function set_default_active_year() { */ 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. + // TODO: When the plugin gets uninstalled, the category should be deleted as well. + // TODO: Or check if it is already there when reinstalling. if (!get_config('local_lbplanner', 'categoryid')) { - + // Check if plugin "modcustomfields" is installed and create the category and the custom field. if (array_key_exists('modcustomfields', core_component::get_plugin_list('local'))) { $handler = mod_handler::create(); diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index ca83d89a..8de16337 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -26,89 +26,15 @@ defined('MOODLE_INTERNAL') || die(); -use block_accessreview\external\get_module_data; -use external_function_parameters; +use core_customfield\category; +use local_lbplanner\helpers\config_helper; +use core_customfield\category_controller; +use customfield_select\data_controller; +use customfield_select\field_controller; use external_single_structure; use external_value; use moodle_url; - -// TODO: revert to native enums once we migrate to php8. - -/** - * Stati a module can be in - */ -class MODULE_STATUS extends Enum { - /** - * Finished module. - */ - const DONE = 0; - /** - * Uploaded module. - */ - const UPLOADED = 1; - /** - * Overdue module. - */ - const LATE = 2; - /** - * Todo module. - */ - const PENDING = 3; -} - -/** - * Grades a module can receive - */ -class MODULE_GRADE extends Enum { - /** - * Erweiterte Kompetenz vollständig. - */ - const EKV = 0; - /** - * Erweiterte Kompetenz überwiegend. - */ - const EK = 1; - /** - * Grundlegende Kompetenz vollständig. - */ - const GKV = 2; - /** - * Grundlegende Kompetenz überwiegend. - */ - const GK = 3; - /** - * Negative grade. - */ - const RIP = 4; -} - -/** - * Module Types - */ -class MODULE_TYPE extends Enum { - /** - * Grundlegende Kompetenz. - */ - const GK = 0; - /** - * Erweiterte Kompetenz. - */ - const EK = 1; - /** - * Test i.e. exam. - */ - const TEST = 2; - /** - * Mitarbeit. - */ - const M = 3; - /** - * No type. - */ - const NONE = 4; -} - /** * Contains helper functions for working with modules. */ @@ -193,9 +119,10 @@ public static function map_status(bool $submitted, bool $done, bool $late): int * Maps the given name to a module type. * * @param string $modulename The name of the module. + * @param int $cmid The coursemodule id of the module. * @return integer The enum value for the module type. */ - public static function determin_type(string $modulename): int { + public static function determin_type(string $modulename, int $cmid): int { // Convert module name to uppercase. $modulename = strtoupper($modulename); @@ -217,6 +144,22 @@ public static function determin_type(string $modulename): int { if (strpos($modulename, '[M]') !== false) { return MODULE_TYPE::M; } + $categorycontroller = category_controller::create(config_helper::get_category_id()); + $datacontroller = $categorycontroller->get_handler()->get_instance_data($cmid)[0]; + $type = intval($datacontroller->get('value')); + if ($type == 1) { + return MODULE_TYPE::GK; + } else if ($type == 2) { + return MODULE_TYPE::EK; + } else if ($type == 3) { + return MODULE_TYPE::GK_EK; + } else if ($type == 4) { + return MODULE_TYPE::TEST; + } else if ($type == 5) { + return MODULE_TYPE::SA; + } else if ($type == 6) { + return MODULE_TYPE::M; + } // Return TYPE_NONE elswise. return MODULE_TYPE::NONE; @@ -346,23 +289,3 @@ public static function get_all_course_modules(int $courseid, int $userid, bool $ return $modules; } } -class module { - public $moduleid; - public $name; - public $courseid; - public $status; - public $type; - public $url; - public $grade; - public $deadline; - public function __construct($moduleid, $name, $courseid, $status, $type, $url, $grade, $deadline) { - $this->moduleid = $moduleid; - $this->name = $name; - $this->courseid = $courseid; - $this->status = $status; - $this->type = $type; - $this->url = $url; - $this->grade = $grade; - $this->deadline = $deadline; - } -} diff --git a/lbplanner/classes/model/activity.php b/lbplanner/classes/model/activity.php index 4325e521..c1cc9cd7 100644 --- a/lbplanner/classes/model/activity.php +++ b/lbplanner/classes/model/activity.php @@ -33,7 +33,9 @@ class activity { public $url; public $grade; public $deadline; - public function __construct($moduleid, $name, $courseid, $status, $type, $url, $grade, $deadline) { + public $modtype; + public function __construct($moduleid, $name, $courseid, $status, $modtype, $type, $url, $grade, $deadline) { + $this->modtype = $modtype; $this->moduleid = $moduleid; $this->name = $name; $this->courseid = $courseid; diff --git a/lbplanner/services/modules/get_all_course_modules.php b/lbplanner/services/modules/get_all_course_modules.php index 23ec08e4..519c42d6 100644 --- a/lbplanner/services/modules/get_all_course_modules.php +++ b/lbplanner/services/modules/get_all_course_modules.php @@ -17,14 +17,18 @@ namespace local_lbplanner_services; +use core_customfield\category_controller; use core_external\external_single_structure; use course_modinfo; +use customfield_select\data_controller; +use customfield_select\field_controller; use external_api; use external_function_parameters; use external_multiple_structure; use external_value; use local_lbplanner\helpers\modules_helper; use local_lbplanner\model\activity; +use local_lbplanner\helpers\config_helper; use moodle_url; /** @@ -63,15 +67,17 @@ public static function get_all_course_modules(int $courseid): ?array { $activities = course_modinfo::get_array_of_activities(get_course($courseid)); $modules = []; foreach ($activities as $activity) { - $type = $activity->mod; + $modtype = $activity->mod; $id = $activity->id; $deadline = $activity->duedate; $name = $activity->name; $cmid = $activity->cm; - $url = new moodle_url('/mod/'.$type.'/view.php', ['id' => $cmid]); - $modules[] = new activity($id, $name, $courseid , null, $type, $url->out(false), null, $deadline); + $url = modules_helper::get_module_url($modtype, $cmid); + $modules[] = new activity($id, $name, $courseid , $modtype, null, $url, null, $deadline); } - die(var_dump($modules)); + $categorycontroller = category_controller::create(config_helper::get_category_id()); + $datacontrollers[] = $categorycontroller->get_handler()->get_instance_data(392); + die(var_dump($datacontrollers)); return $type; } From b90f7d153f40aa522a858f858c8a51b416c3c049 Mon Sep 17 00:00:00 2001 From: Muhi Date: Tue, 12 Mar 2024 23:11:33 +0100 Subject: [PATCH 13/15] added stuff --- lbplanner/classes/helpers/modules_helper.php | 4 ++-- .../services/modules/get_all_course_modules.php | 14 +++++++++++--- lbplanner/version.php | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index 0693315e..59c4d490 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -156,11 +156,11 @@ public static function determin_type(string $modulename, int $cmid): int { } else if ($type == 2) { return MODULE_TYPE::EK; } else if ($type == 3) { - return MODULE_TYPE::GK_EK; + return MODULE_TYPE::GK; } else if ($type == 4) { return MODULE_TYPE::TEST; } else if ($type == 5) { - return MODULE_TYPE::SA; + return MODULE_TYPE::TEST; } else if ($type == 6) { return MODULE_TYPE::M; } diff --git a/lbplanner/services/modules/get_all_course_modules.php b/lbplanner/services/modules/get_all_course_modules.php index 519c42d6..fc379be5 100644 --- a/lbplanner/services/modules/get_all_course_modules.php +++ b/lbplanner/services/modules/get_all_course_modules.php @@ -21,13 +21,12 @@ use core_external\external_single_structure; use course_modinfo; use customfield_select\data_controller; -use customfield_select\field_controller; use external_api; use external_function_parameters; use external_multiple_structure; use external_value; -use local_lbplanner\helpers\modules_helper; use local_lbplanner\model\activity; +use local_lbplanner\helpers\modules_helper; use local_lbplanner\helpers\config_helper; use moodle_url; @@ -73,7 +72,16 @@ public static function get_all_course_modules(int $courseid): ?array { $name = $activity->name; $cmid = $activity->cm; $url = modules_helper::get_module_url($modtype, $cmid); - $modules[] = new activity($id, $name, $courseid , $modtype, null, $url, null, $deadline); + $modules[] = new activity($id, + $name, + $courseid, + modules_helper::determin_type($name, $cmid), + $modtype, + 1, + $url, + null, + $deadline + ); } $categorycontroller = category_controller::create(config_helper::get_category_id()); $datacontrollers[] = $categorycontroller->get_handler()->get_instance_data(392); diff --git a/lbplanner/version.php b/lbplanner/version.php index caab6006..c66c682c 100644 --- a/lbplanner/version.php +++ b/lbplanner/version.php @@ -27,7 +27,7 @@ $plugin->component = 'local_lbplanner'; $plugin->release = 'Alpha v.'.$release; -$plugin->version = 2024031200; +$plugin->version = 2024031201; $plugin->dependencies = [ // Depend upon version 2023110600 of local_modcustomfields. 'local_modcustomfields' => 2023110600, From 905520937c2889042d716bf1c3d40af34cbfad48 Mon Sep 17 00:00:00 2001 From: Muhi Date: Wed, 13 Mar 2024 09:30:04 +0100 Subject: [PATCH 14/15] tried stuff --- lbplanner/classes/helpers/modules_helper.php | 9 ++------- .../modules/get_all_course_modules.php | 19 +++++++++++-------- lbplanner/version.php | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index 8c9250c7..3fd53cea 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -40,17 +40,12 @@ * Contains helper functions for working with modules. */ class modules_helper { - /** - * Submitted status name of a submission. - */ - const SUBMISSION_STATUS_SUBMITTED = 'submitted'; - /** * The return structure of a module. * * @return external_single_structure The structure of a module. */ - public static function structure() : external_single_structure { + public static function structure(): external_single_structure { return new external_single_structure( [ 'moduleid' => new external_value(PARAM_INT, 'Module ID'), @@ -74,7 +69,7 @@ public static function structure() : external_single_structure { * @param int $gradepass The grade to pass the module. * @return integer The enum value for the grade. */ - public static function determin_uinified_grade(int $grade, int $maxgrade, int $mingrade, int $gradepass) : int { + public static function determin_uinified_grade(int $grade, int $maxgrade, int $mingrade, int $gradepass): int { if ($grade < $gradepass) { return MODULE_GRADE::RIP; } diff --git a/lbplanner/services/modules/get_all_course_modules.php b/lbplanner/services/modules/get_all_course_modules.php index fc379be5..72a407be 100644 --- a/lbplanner/services/modules/get_all_course_modules.php +++ b/lbplanner/services/modules/get_all_course_modules.php @@ -17,6 +17,7 @@ namespace local_lbplanner_services; +use core_completion\cm_completion_details; use core_customfield\category_controller; use core_external\external_single_structure; use course_modinfo; @@ -28,6 +29,7 @@ use local_lbplanner\model\activity; use local_lbplanner\helpers\modules_helper; use local_lbplanner\helpers\config_helper; +use cm_info; use moodle_url; /** @@ -72,20 +74,21 @@ public static function get_all_course_modules(int $courseid): ?array { $name = $activity->name; $cmid = $activity->cm; $url = modules_helper::get_module_url($modtype, $cmid); - $modules[] = new activity($id, + $modules[] = new activity( + $id, $name, $courseid, - modules_helper::determin_type($name, $cmid), - $modtype, 1, + $modtype, + modules_helper::determin_type($name, $cmid), $url, - null, + 1, $deadline ); - } - $categorycontroller = category_controller::create(config_helper::get_category_id()); - $datacontrollers[] = $categorycontroller->get_handler()->get_instance_data(392); - die(var_dump($datacontrollers)); + + cm_info::cr} + course_modinfo::instance($courseid)->get_ + die(var_dump(cm_completion_details::get_instance(get_fast_modinfo($courseid, $USER->id))->get_details())); return $type; } diff --git a/lbplanner/version.php b/lbplanner/version.php index caab6006..8acc347a 100644 --- a/lbplanner/version.php +++ b/lbplanner/version.php @@ -27,7 +27,7 @@ $plugin->component = 'local_lbplanner'; $plugin->release = 'Alpha v.'.$release; -$plugin->version = 2024031200; +$plugin->version = 2024031301; $plugin->dependencies = [ // Depend upon version 2023110600 of local_modcustomfields. 'local_modcustomfields' => 2023110600, From d710582ca1d106e158cbb4d4a10d1a54d560934d Mon Sep 17 00:00:00 2001 From: Muhi Date: Wed, 13 Mar 2024 21:02:22 +0100 Subject: [PATCH 15/15] I tried different approaches to access the grad and submission state of the course And its kinda frustrating that many people just say "use the DB acces" I CANT --- .../modules/get_all_course_modules.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lbplanner/services/modules/get_all_course_modules.php b/lbplanner/services/modules/get_all_course_modules.php index 72a407be..ce4b5aec 100644 --- a/lbplanner/services/modules/get_all_course_modules.php +++ b/lbplanner/services/modules/get_all_course_modules.php @@ -20,6 +20,7 @@ use core_completion\cm_completion_details; use core_customfield\category_controller; use core_external\external_single_structure; +use core_h5p\core; use course_modinfo; use customfield_select\data_controller; use external_api; @@ -28,9 +29,7 @@ use external_value; use local_lbplanner\model\activity; use local_lbplanner\helpers\modules_helper; -use local_lbplanner\helpers\config_helper; -use cm_info; -use moodle_url; +use stdClass; /** * Get all the modules of the given course. @@ -69,6 +68,9 @@ public static function get_all_course_modules(int $courseid): ?array { $modules = []; foreach ($activities as $activity) { $modtype = $activity->mod; + if ($modtype !== 'assign' || $modtype !== 'quiz') { + continue; + } $id = $activity->id; $deadline = $activity->duedate; $name = $activity->name; @@ -85,9 +87,14 @@ public static function get_all_course_modules(int $courseid): ?array { 1, $deadline ); - - cm_info::cr} - course_modinfo::instance($courseid)->get_ + } + die(var_dump()); + $test = new stdClass(); + $test->id = 392; + die(var_dump(assign_get_user_grades($test, $USER->id))); + $completion = new \completion_info(get_course($courseid)); + $courseandcm = get_course_and_cm_from_cmid(392, null, $courseid, $USER->id); + die(var_dump(get_course_and_cm_from_cmid(392, null, $courseid, $USER->id))); die(var_dump(cm_completion_details::get_instance(get_fast_modinfo($courseid, $USER->id))->get_details())); return $type; }