From a991e2caa3391f86f43090b99bb03a01eeffe5c5 Mon Sep 17 00:00:00 2001 From: Andreas Schenkel Date: Thu, 29 Jan 2026 22:18:51 +0100 Subject: [PATCH 1/5] WIP: add feature to optionally support label by a new added setting --- backup/moodle2/backup_checklist_stepslib.php | 2 +- db/install.xml | 3 +++ db/upgrade.php | 22 ++++++++++++++++++++ lang/en/checklist.php | 1 + locallib.php | 5 +++-- mod_form.php | 3 +++ 6 files changed, 33 insertions(+), 3 deletions(-) diff --git a/backup/moodle2/backup_checklist_stepslib.php b/backup/moodle2/backup_checklist_stepslib.php index 5bc7c2f..9494ae0 100644 --- a/backup/moodle2/backup_checklist_stepslib.php +++ b/backup/moodle2/backup_checklist_stepslib.php @@ -45,7 +45,7 @@ protected function define_structure() { $checklist = new backup_nested_element('checklist', ['id'], [ 'name', 'intro', 'introformat', 'timecreated', 'timemodified', 'useritemsallowed', 'studentcomments', 'teacheredit', 'theme', 'duedatesoncalendar', 'teachercomments', 'maxgrade', - 'autopopulate', 'autoupdate', 'completionpercent', 'completionpercenttype', 'emailoncomplete', 'lockteachermarks', + 'autopopulate', 'supportlabel', 'autoupdate', 'completionpercent', 'completionpercenttype', 'emailoncomplete', 'lockteachermarks', ]); $items = new backup_nested_element('items'); diff --git a/db/install.xml b/db/install.xml index 54f1bd9..b81da7d 100644 --- a/db/install.xml +++ b/db/install.xml @@ -21,6 +21,9 @@ + + + diff --git a/db/upgrade.php b/db/upgrade.php index 9f20c07..d495bdc 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -441,5 +441,27 @@ function xmldb_checklist_upgrade($oldversion = 0) { upgrade_mod_savepoint(true, 2022052801, 'checklist'); } + + + if ($oldversion < 2026010100) { + $table = new xmldb_table('checklist'); + $field = new xmldb_field('supportlabel', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Switch all 'hidden headings' to being headings & hidden. + $sql = 'UPDATE {checklist} '; + $sql .= 'SET supportlabel=0 '; + $DB->execute($sql); + + // Checklist savepoint reached. + upgrade_mod_savepoint(true, 2026010100, 'checklist'); + + } + + + + return $result; } diff --git a/lang/en/checklist.php b/lang/en/checklist.php index 47a6621..c1889bb 100644 --- a/lang/en/checklist.php +++ b/lang/en/checklist.php @@ -193,6 +193,7 @@ $string['student_comment_updated'] = 'Student comment updated'; $string['student_comment_updated_desc'] = 'The user with id {$a->userid} has updated a comment in the checklist with course module id {$a->cmid} to have text \'{$a->commenttext}\''; $string['studentcomments'] = 'User can add their own comments to checklist items'; +$string['supportlabel'] = 'Should label be supported'; $string['teacheralongsidecheck'] = 'Student and teacher'; $string['teachercomments'] = 'Teachers can add comments'; $string['teacherdate'] = 'Date a teacher last updated this item'; diff --git a/locallib.php b/locallib.php index edb1a08..fbddbbe 100644 --- a/locallib.php +++ b/locallib.php @@ -482,12 +482,13 @@ protected function update_items_from_course() { $nextpos = $this->items[$sectionheading]->position + 1; } + $supportlabel = $this->checklist->supportlabel; foreach ($sections[$section] as $cmid) { if ($this->cm->id == $cmid) { continue; // Do not include this checklist in the list of modules. } - if ($mods->get_cm($cmid)->modname === 'label') { - continue; // Ignore any labels. + if ($mods->get_cm($cmid)->modname === 'label' && !$supportlabel) { + continue; // Ignore any labels. } if (isset($mods->get_cm($cmid)->deletioninprogress) && $mods->get_cm($cmid)->deletioninprogress) { continue; // M3.2 onwards - if cm is in the recycle bin, being deleted, then skip it. diff --git a/mod_form.php b/mod_form.php index 54d5d6e..bdc7513 100644 --- a/mod_form.php +++ b/mod_form.php @@ -94,6 +94,9 @@ public function definition() { $mform->setDefault('autopopulate', 0); $mform->addHelpButton('autopopulate', 'autopopulate', 'checklist'); + $mform->addElement('select', 'supportlabel', get_string('supportlabel', 'checklist'), $ynoptions); + $mform->setDefault('supportlabel', 0); + $checkdisable = true; $str = 'autoupdate'; if (get_config('mod_checklist', 'linkcourses')) { From 03981ce05a77efc3a67c339a82909a321ddb3970 Mon Sep 17 00:00:00 2001 From: Andreas Schenkel Date: Fri, 30 Jan 2026 16:56:19 +0100 Subject: [PATCH 2/5] WIP: add helptext to form, add setter and getter for setting --- classes/local/output_status.php | 18 ++++++++++++++++++ db/install.xml | 2 -- lang/en/checklist.php | 4 +++- mod_form.php | 1 + tests/generator/lib.php | 1 + version.php | 4 ++-- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/classes/local/output_status.php b/classes/local/output_status.php index 61c8ffd..d699014 100644 --- a/classes/local/output_status.php +++ b/classes/local/output_status.php @@ -78,6 +78,8 @@ class output_status { protected $itemid = null; /** @var bool */ protected $autopopulate = false; + /** @var bool */ + protected $supportlabel = false; /** @var string|null */ protected $autoupdatewarning = null; /** @var bool */ @@ -405,6 +407,22 @@ public function set_autopopulate($autopopulate) { $this->autopopulate = $autopopulate; } + /** + * Is label support enabled for this instance? + * @return boolean + */ + public function is_supportlabel() { + return $this->supportlabel; + } + + /** + * Set as label support enabled + * @param boolean $supportlabel + */ + public function set_supportlabel($supportlabel) { + $this->supportlabel = $supportlabel; + } + /** * Should the autoupdate warning be shown and, if so, what type? * @return int|null diff --git a/db/install.xml b/db/install.xml index b81da7d..23ccaa8 100644 --- a/db/install.xml +++ b/db/install.xml @@ -21,9 +21,7 @@ - - diff --git a/lang/en/checklist.php b/lang/en/checklist.php index c1889bb..c86585f 100644 --- a/lang/en/checklist.php +++ b/lang/en/checklist.php @@ -193,7 +193,9 @@ $string['student_comment_updated'] = 'Student comment updated'; $string['student_comment_updated_desc'] = 'The user with id {$a->userid} has updated a comment in the checklist with course module id {$a->cmid} to have text \'{$a->commenttext}\''; $string['studentcomments'] = 'User can add their own comments to checklist items'; -$string['supportlabel'] = 'Should label be supported'; +$string['supportlabel'] = 'Support label'; +$string['supportlabel_help'] = 'By default label are not supported because in many cases the checklist would be very large.
+If you whant also to use label in checklist, then you can activate it with this setting.'; $string['teacheralongsidecheck'] = 'Student and teacher'; $string['teachercomments'] = 'Teachers can add comments'; $string['teacherdate'] = 'Date a teacher last updated this item'; diff --git a/mod_form.php b/mod_form.php index bdc7513..f91ea09 100644 --- a/mod_form.php +++ b/mod_form.php @@ -96,6 +96,7 @@ public function definition() { $mform->addElement('select', 'supportlabel', get_string('supportlabel', 'checklist'), $ynoptions); $mform->setDefault('supportlabel', 0); + $mform->addHelpButton('supportlabel', 'supportlabel', 'checklist'); $checkdisable = true; $str = 'autoupdate'; diff --git a/tests/generator/lib.php b/tests/generator/lib.php index cff60bc..21af0ea 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -49,6 +49,7 @@ public function create_instance($record = null, ?array $options = null) { 'teachercomments' => 1, 'maxgrade' => 100, 'autopopulate' => CHECKLIST_AUTOPOPULATE_NO, + 'supportlabel' => 0, 'autoupdate' => CHECKLIST_AUTOUPDATE_YES, 'completionpercent' => 0, 'emailoncomplete' => 0, diff --git a/version.php b/version.php index 589cccf..7f4b227 100644 --- a/version.php +++ b/version.php @@ -24,9 +24,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2025101800; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2026010100; // The current module version (Date: YYYYMMDDXX). $plugin->maturity = MATURITY_STABLE; -$plugin->release = '4.1.0.7'; +$plugin->release = '4.1.0.8'; $plugin->requires = 2022112800; // Moodle 4.1.0. $plugin->component = 'mod_checklist'; $plugin->supported = [401, 501]; From 2dbe20b4530b2b6ac42bc8653702d219f897da49 Mon Sep 17 00:00:00 2001 From: Andreas Schenkel Date: Fri, 30 Jan 2026 17:22:34 +0100 Subject: [PATCH 3/5] fix comment in upgrade.php --- db/upgrade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/upgrade.php b/db/upgrade.php index d495bdc..49992d5 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -450,7 +450,7 @@ function xmldb_checklist_upgrade($oldversion = 0) { $dbman->add_field($table, $field); } - // Switch all 'hidden headings' to being headings & hidden. + // Set the new field supportlabel in all existing instances of checklist to the new default value 0. $sql = 'UPDATE {checklist} '; $sql .= 'SET supportlabel=0 '; $DB->execute($sql); From 19ed59524187fa3c3d4dff7bba8321e5a93f5474 Mon Sep 17 00:00:00 2001 From: Andreas Schenkel Date: Fri, 30 Jan 2026 17:34:17 +0100 Subject: [PATCH 4/5] fix: default of the new supportlabel field should not be 1 --- db/install.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/install.xml b/db/install.xml index 23ccaa8..2ece0c1 100644 --- a/db/install.xml +++ b/db/install.xml @@ -21,7 +21,7 @@ - + From fa78f60ef105f408ec03a52e66c164d200945383 Mon Sep 17 00:00:00 2001 From: Andreas Schenkel Date: Fri, 30 Jan 2026 19:10:25 +0100 Subject: [PATCH 5/5] remove sql in upgrade.php because default is already set to 0 --- db/upgrade.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/db/upgrade.php b/db/upgrade.php index 49992d5..a866711 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -441,8 +441,6 @@ function xmldb_checklist_upgrade($oldversion = 0) { upgrade_mod_savepoint(true, 2022052801, 'checklist'); } - - if ($oldversion < 2026010100) { $table = new xmldb_table('checklist'); $field = new xmldb_field('supportlabel', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0'); @@ -450,18 +448,10 @@ function xmldb_checklist_upgrade($oldversion = 0) { $dbman->add_field($table, $field); } - // Set the new field supportlabel in all existing instances of checklist to the new default value 0. - $sql = 'UPDATE {checklist} '; - $sql .= 'SET supportlabel=0 '; - $DB->execute($sql); - // Checklist savepoint reached. upgrade_mod_savepoint(true, 2026010100, 'checklist'); } - - - return $result; }