Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-82941

Modernise section moving

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 5.0
    • Course
    • MOODLE_500_STABLE
    • mdl-82941_main
    • Hide
      1. Add a new Custom sections course with 5 sections (not including the General section).
      2. Rename the sections: General, A, B, C, D, E.
      3. Move section B after section D.
      4. Verify that the section order is now: General, A, C, D, B, E.
      5. Move section B before section C.
      6. Verify that the section order is now: General, A, B, C, D, E.
      7. Highlight section B.
      8. Move section B after section E.
      9. Verify that the section order is now: General, A, C, D, E, B, and section B is highlighted.
      10. Move section B before section A.
      11. Verify that the section order is now: General, B, A, C, D, E, and section B is highlighted.
      12. Move section D before section B.
      13. Verify that the section order is now: General, D, B, A, C, E, and section B is highlighted.
      14. Move section D after section B.
      15. Verify that the section order is now: General, B, D, A, C, E, and section B is highlighted.
      16. Enable bulk edit mode.
      17. Select sections B and D.
      18. Move the selected sections after section C.
      19. Verify that the section order is now: General, A, C, B, D, E, and section B is highlighted.  (Fails before the change.)
      20. Refresh the page.
      21. Delete section A.
      22. Verify that the section order is now: General, C, B, D, E, and section B is highlighted.
      23. Delete section E.
      24. Verify that the section order is now: General, C, B, D, and section B is highlighted.
      25. Add a section after the General section.
      26. Verify that the section order is now: General, New section, C, B, D, and section B is highlighted.
      27. Add a section after section D.
      28. Verify that the section order is now: General, New section, C, B, D, New section, and section B is highlighted.
      29. Delete section B.
      30. Verify that the section order is now: General, New section, C, D, New section, and no section is highlighted.
      Show
      Add a new Custom sections course with 5 sections (not including the General section). Rename the sections: General, A, B, C, D, E. Move section B after section D. Verify that the section order is now: General, A, C, D, B, E. Move section B before section C. Verify that the section order is now: General, A, B, C, D, E. Highlight section B. Move section B after section E. Verify that the section order is now: General, A, C, D, E, B, and section B is highlighted. Move section B before section A. Verify that the section order is now: General, B, A, C, D, E, and section B is highlighted. Move section D before section B. Verify that the section order is now: General, D, B, A, C, E, and section B is highlighted. Move section D after section B. Verify that the section order is now: General, B, D, A, C, E, and section B is highlighted. Enable bulk edit mode. Select sections B and D. Move the selected sections after section C. Verify that the section order is now: General, A, C, B, D, E, and section B is highlighted.  (Fails before the change.) Refresh the page. Delete section A. Verify that the section order is now: General, C, B, D, E, and section B is highlighted. Delete section E. Verify that the section order is now: General, C, B, D, and section B is highlighted. Add a section after the General section. Verify that the section order is now: General, New section, C, B, D, and section B is highlighted. Add a section after section D. Verify that the section order is now: General, New section, C, B, D, New section, and section B is highlighted. Delete section B. Verify that the section order is now: General, New section, C, D, New section, and no section is highlighted.
    • Hide

      Code verified against automated checks.

      Checked MDL-82941 using repository: https://github.com/james-cnz/moodle

      More information about this report

      Built on: Wed Apr 23 05:09:54 UTC 2025

      Show
      Code verified against automated checks. Checked MDL-82941 using repository: https://github.com/james-cnz/moodle main (0 errors / 0 warnings) [branch: mdl-82941_main | CI Job ] More information about this report Built on: Wed Apr 23 05:09:54 UTC 2025

      Section moving is modernised for current requirements:

      • Uses the new formatactions system.
      • Supports specifying section IDs instead of section numbers.  (Most parts of the Moodle code now work with section IDs, I think.)
      • Supports moving multiple sections at once, with a single database transaction.  (Useful for bulk edit actions.)
      • Supports moving to the end of regular (non-delegated) sections.  (Useful for when creating sections.)
      • Returns array of objects specifying section numbers for the moved section(s).  (Useful for when creating sections.)
      • Throws exceptions instead of returning false for failure.  (Probably good, because the return value of the existing method often isn't checked.)
      • Uses an interface that could be extended by format plugins.  (e.g. Flexible sections and Multitopic use parent section id when moving.)

      Existing functionality is maintained:

      • Continues to support moving by section numbers.  (It isn't very efficient using section numbers, but I think it's mainly only used when adding sections now, and I assume this will be replaced at some stage, aside from non-AJAX stuff, which I don't think is really used any more.)
      • Continues the same support for numsections.  (Still used by the Grid format at least.)

      The interface is:
      \core_courseformat\formatactions::section($courseorid)->move_sections_to($origins, $destination, $include)

      $origins is an array of objects specifying sections to be moved by their id or number.
      $destination is an object specifying where the sections are to be moved to, by previd, nextid, or section number.
      $include specifies which kinds of sections are to be considered, 0 regular only, 1 also orphan, 2 also delegated.

      e.g.

      move_sections_to([(object)['id' => 5], (object)['id' => 8]], (object)['previd' => 7], 1)
      The sections with ids 5 and 8 are moved so that the section before them is that with id 7, which must not be a delegated section.

      move_section_to([(object)['id' => 7]], (object)['nextid' => null], 2)
      The section with id 7 is moved to the end of all sections, including delegated ones (useful for when deleting sections).

      move_section_to([(object)['section' => 3]], (object)['section' => 5], 0)
      The section with number 3 is moved so its new position is number 5, which must not be outside numsections (useful for old code / code requiring numsections support).

      Moving to the end of non-orphan sections with nextid => null, include = 0 isn't supported, as numsection support is only given for backwards compatibility, this wasn't a feature previously available, and I'm not sure it would even be useful.

      Other changes:

      Existing move tests are copied and adapted.

      Existing move methods are deprecated.  (And a note on reorder_sections is removed, because it was just wrong.)  I've written the deprecation notices assuming this is targeted for Moodle 5.0.

      Various methods are converted to use the new move sections method.

      sectionactions calculate_positions() is removed.  It was a private helper method for create_from_object(), but I think it's clearer just to incorporate the needed functionality now.

      (There was a bug fix in here, that's now done by MDL-83046.)

            james-cnz James E. Calder
            james-cnz James E. Calder
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.