Three-state logic
Introduction
When I first implemented the setting reset functionality of Collapsed Topics (CT), it allowed you to reset the settings of the course to the defaults as set by the administrator at the time. The reset functionality applies to the current course or can be applied to all courses by the administrator if desired. But this has the downside that when the defaults change then whole groups of settings need to be ‘reset’. What if you wanted to be able to only have one setting track the default? This is where ‘three-state’ logic comes in.
Disclaimers
Moodle™ is a registered trademark of ‘Martin Dougiamas’ – moodle.com/trademarks.
Other names / logos can be trademarks of their respective owners. Please review their website for details.
I am independent from the organisations listed above and am in no way writing for or endorsed by them.
Abbreviations
CT – Collapsed Topics – moodle.org/plugins/format_topcoll
Theory
Two state logic or ‘binary’ where a variable is in one of two states, say ‘Yes’ / ‘No’ or ‘On’ / ‘Off’ can represent a setting for functionality that is either there or not. With three-state logic, there is a third state that refers to an intermediate state between the two, a situation where the setting is neither on or off but something else. That ‘else’ in the case of the new setting functionality in CT means ‘be the state of the default’.
Practice
Having that ‘third state’ for all the settings now means that the user can choose to set a setting to be what they want it to be or pass that decision onto the administrator. If they do that, then when ever the administrator changes the default value of the setting, then the course automatically updates and changes.
In effect, when the page loads, the code in CT looks at the value of each setting and if it’s the ‘default’ one then it then goes off and fetches the value to use from the administrator set default.
But what about the reset functionality?
That functionality is still there, but what it does is set all of the settings that a reset action affects to be ‘default’, so ‘go and get the administrator set default’ rather than setting the value of the setting to what the default is now as the functionality previously did.
Confused?
Sometimes, words are not enough, so please go to this post: moodle.org/mod/forum/discuss.php?d=416553 which has two videos embedded in it that demonstrate the new functionality.
Conclusion
Use of ‘three-state’ logic in this way I consider has made a good improvement to the usability of Collapsed Topics and I hope I’ll get a moment and implement the same principle in the Grid format (moodle.org/plugins/format_grid) as it has the same ‘reset’ functionality as CT did.
What do you think? Please let me know in the comments.
- Added value – 16th September 2024
- What is a developer? – 16th August 2024
- A little boost – 16th July 2024