From 504556d310acbdd3ad8c0d4eab6b406e4911df9c Mon Sep 17 00:00:00 2001 From: Riedler Date: Sun, 12 Oct 2025 20:18:49 +0200 Subject: [PATCH 1/4] fix: only show visible modules --- lbplanner/classes/helpers/modules_helper.php | 9 +++------ lbplanner/classes/model/module.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index bfa1743a..ed0f4c82 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -190,15 +190,12 @@ public static function get_module_status(module $module, int $userid, ?int $plan public static function get_all_modules_by_course(int $courseid, bool $ekenabled): array { global $DB; - $assignments = $DB->get_records(self::ASSIGN_TABLE, ['course' => $courseid]); + $cmodules = $DB->get_records(self::COURSE_MODULES_TABLE, ['course' => $courseid, 'visible' => 1]); $modules = []; - foreach ($assignments as $assign) { - if ($assign === null) { - throw new coding_exception("what the fuck? 1 {$courseid} {$ekenabled}"); - } - $module = module::from_assignobj($assign); + foreach ($cmodules as $cm) { + $module = module::from_cmobj($cm); if ((!$ekenabled) && $module->get_type() === MODULE_TYPE::EK) { continue; } diff --git a/lbplanner/classes/model/module.php b/lbplanner/classes/model/module.php index f534d46e..7a787c59 100644 --- a/lbplanner/classes/model/module.php +++ b/lbplanner/classes/model/module.php @@ -117,6 +117,18 @@ public static function from_cmid(int $id): self { return $obj; } + /** + * Creates a module object from the course-module object. + * @param \stdClass $cmobj the course-module object from moodle's DB + * @return module a module object with filled-in course-module object + */ + public static function from_cmobj(\stdClass $cmobj): self { + $obj = new self(); + $obj->cmobj = $cmobj; + $obj->cmid = $cmobj->id; + return $obj; + } + /** * Fetches the necessary caches and returns the assignment ID * @return int assign ID From 7b412b36c97b437f3a951f447a6c44823b4b2255 Mon Sep 17 00:00:00 2001 From: Riedler Date: Sun, 12 Oct 2025 20:34:39 +0200 Subject: [PATCH 2/4] fix: there are TWO different visibility settings --- lbplanner/classes/helpers/modules_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index ed0f4c82..efa91aed 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -190,7 +190,7 @@ public static function get_module_status(module $module, int $userid, ?int $plan public static function get_all_modules_by_course(int $courseid, bool $ekenabled): array { global $DB; - $cmodules = $DB->get_records(self::COURSE_MODULES_TABLE, ['course' => $courseid, 'visible' => 1]); + $cmodules = $DB->get_records(self::COURSE_MODULES_TABLE, ['course' => $courseid, 'visible' => 1, 'visibleoncoursepage' => 1]); $modules = []; From f56cab994b5f3440109a454208ac4ecf8f2f1089 Mon Sep 17 00:00:00 2001 From: Riedler Date: Sun, 12 Oct 2025 21:59:30 +0200 Subject: [PATCH 3/4] fix: minor refactors for how course-modules are queried --- lbplanner/classes/helpers/modules_helper.php | 26 +++++++++++++++++++- lbplanner/classes/model/module.php | 9 ++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index efa91aed..db2e3287 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -71,6 +71,22 @@ class modules_helper { */ const SUBMISSION_STATUS_SUBMITTED = 'submitted'; + /** + * For caching {@see get_assign_module_id()} + */ + private static ?int $assignmoduleid = null; + + /** + * Gets the ID of the module type "assign" (as opposed to "forum", "quiz", etc.) + */ + public static function get_assign_module_id(): int { + global $DB; + if (self::$assignmoduleid === null) { + self::$assignmoduleid = $DB->get_field('modules', 'id', ['name' => 'assign'], MUST_EXIST); + } + return self::$assignmoduleid; + } + /** * Determins the enum value for a grade. * TODO: this is bullshit. @@ -190,7 +206,15 @@ public static function get_module_status(module $module, int $userid, ?int $plan public static function get_all_modules_by_course(int $courseid, bool $ekenabled): array { global $DB; - $cmodules = $DB->get_records(self::COURSE_MODULES_TABLE, ['course' => $courseid, 'visible' => 1, 'visibleoncoursepage' => 1]); + $cmodules = $DB->get_records( + self::COURSE_MODULES_TABLE, + [ + 'course' => $courseid, + 'visible' => 1, + 'visibleoncoursepage' => 1, + 'module' => self::get_assign_module_id(), // Must be assign, not forum or other types of modules. + ] + ); $modules = []; diff --git a/lbplanner/classes/model/module.php b/lbplanner/classes/model/module.php index 7a787c59..ed8a4814 100644 --- a/lbplanner/classes/model/module.php +++ b/lbplanner/classes/model/module.php @@ -126,6 +126,7 @@ public static function from_cmobj(\stdClass $cmobj): self { $obj = new self(); $obj->cmobj = $cmobj; $obj->cmid = $cmobj->id; + $obj->assignid = $cmobj->instance; return $obj; } @@ -136,9 +137,9 @@ public static function from_cmobj(\stdClass $cmobj): self { public function get_assignid(): int { if ($this->assignid === null) { if ($this->cmid !== null) { - $this->assignid = $this->get_cmobj()['instance']; + $this->assignid = $this->get_cmobj()->instance; } else { - throw new \coding_exception('requested assignid, but no assignid'); + throw new \coding_exception('requested assignid, but no cmid'); } } return $this->assignid; @@ -181,7 +182,7 @@ public function get_cmobj(): \stdClass { if ($this->cmid !== null) { $res = $DB->get_record( modules_helper::COURSE_MODULES_TABLE, - ['id' => $this->cmid] + ['id' => $this->cmid, 'module' => modules_helper::get_assign_module_id()] ); if ($res === false) { throw new \moodle_exception("couldn't get course module with cmid {$this->cmid}"); @@ -196,7 +197,7 @@ public function get_cmobj(): \stdClass { [ 'course' => $courseid, 'instance' => $this->assignid, - 'module' => 1, + 'module' => modules_helper::get_assign_module_id(), ] ); if ($res === false) { From 66e453c3986442bf090c0e6bb9e6da384a0af9e1 Mon Sep 17 00:00:00 2001 From: Riedler Date: Sun, 12 Oct 2025 22:03:42 +0200 Subject: [PATCH 4/4] chore: pacify moodle code checker --- lbplanner/classes/helpers/modules_helper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index db2e3287..33db49ef 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -73,6 +73,7 @@ class modules_helper { /** * For caching {@see get_assign_module_id()} + * @var ?int $assignmoduleid {@see get_assign_module_id()} */ private static ?int $assignmoduleid = null;