Skip to content

Recalculate parent sections when necessary#151

Open
james-cnz wants to merge 2 commits into
davidherney:masterfrom
james-cnz:recalculate_parent_sections
Open

Recalculate parent sections when necessary#151
james-cnz wants to merge 2 commits into
davidherney:masterfrom
james-cnz:recalculate_parent_sections

Conversation

@james-cnz

Copy link
Copy Markdown
Contributor

I found problems with my course format when I added AJAX delete recently. I don't think it affects Onetopic currently, but maybe this change will avoid problems in the future.

@james-cnz

Copy link
Copy Markdown
Contributor Author

Another issue was found with my code here: james-cnz/moodle-format_multitopic#50 .
It may be a niche use case, but may as well be fixed.

@davidherney

Copy link
Copy Markdown
Owner

Hi @james-cnz ...

Do you know how I can replicate the case in Onetopic so I can test the change? It's a very ambiguous change, and I wouldn't want to implement it if I can't test it before and after the code change.

Saludos

@james-cnz

Copy link
Copy Markdown
Contributor Author

Hi @davidherney,

I don't know if the first part affects Onetopic at the moment, so I'm not sure there's a way to test it. It caused an issue for my format when I added AJAX delete. The problem is, in AJAX actions, the modinfo can change, then the parent sections list needs to be changed too. To do this, when the parent sections are calculated, a link to the modinfo is saved. Then when the parent sections are fetched again, the saved modinfo link is compared to the current modinfo. If it's different, the parent sections list needs to be recalculated.

The second part could be tested, but the only way I know is complicated. The problem is that, in obscure cases, the modinfo that should be checked isn't the modinfo for the current user, but for a different user. There's a note about it in course/format/classes/base.php function section_get_available_hook():
* Note: affected user can be retrieved as: $section->modinfo->userid
The only way I know to test it requires this patch that just landed in Moodle main:
moodle/moodle@92b2ccc
And the steps to follow would be similar to the ones in https://moodle.atlassian.net/browse/MDL-85036 (not the ones under the Original ticket's description, but the ones further down the page under Testing Instructions). Instead of Custom sections, use Onetopic, of course. And instead of hiding the activity directly, place the activity in a child tab, and hide its parent tab.

@james-cnz james-cnz force-pushed the recalculate_parent_sections branch from ced7a77 to 91f594c Compare April 19, 2026 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants