Repository navigation
Exercise: Sort the learner tests list by title across pages - #9278
Merged
ywarnier merged 2 commits intoOct 20, 2026
Merged
Conversation
…amilo#1416 The learner list was paginated by the database without an ORDER BY, so only the rows of the current page were sorted and the order across pages was whatever the database returned. Load the learner list whole and run it through the same natural, case-insensitive title sort and array_slice pagination as the teacher list, so both views show the tests in exactly the same order.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9278 +/- ##
============================================
+ Coverage 17.13% 17.20% +0.06%
- Complexity 62160 62176 +16
============================================
Files 2522 2522
Lines 233279 233319 +40
============================================
+ Hits 39981 40150 +169
+ Misses 193298 193169 -129 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exercise: Sort the learner tests list by title across pages
Summary
Since #7450 (75ca0a1), the teacher's tests list in
Exercise::exerciseGridResource()loads all tests, sorts them by title withstrnatcasecmp()(natural and case-insensitive, so "Quiz 2" comes before "Quiz 10"), and then paginates witharray_slice().The learner list was still paginated by the database (
setFirstResult/setMaxResults) without an ORDER BY. Only the 20 rows of the current page were sorted. With more than 20 tests, which tests ended up on which page depended on the order the database returned them in.This PR moves the existing teacher sort and pagination out of the teacher-only branch, so both branches use them unchanged:
usort(... strnatcasecmp ...),array_slice($from, $limit)andcount().The learner list now has exactly the same order as the teacher list. A database
ORDER BY titlewould not give that, because it sorts "Quiz 10" before "Quiz 2".Side effects for the learner list:
getCount()is no longer used.setMaxResults()is no longer applied to a query that fetch-joins collections (links, files). Before, a test with several resource links could take up more than one of the 20 SQL rows. The total also came from a non-DISTINCTCOUNTover the joined rows.The manual re-ordering of tests that #1416 also asks for is not part of this PR.
Tests
New
tests/CoreBundle/Legacy/ExerciseGridResourceTest.php. It creates 25 tests titledQuiz 1toQuiz 25, with no zero-padding, in reverse order. So neither the insertion order nor an alphabetical order ("Quiz 1", "Quiz 10", ...) is the natural one. Then:Quiz 1toQuiz 25in natural order.I ran the same flow against a MariaDB 11.8 dev database. Each run was inside a transaction that was rolled back afterwards:
ONLY_FULL_GROUP_BYORDER BY title)Quiz 10–Quiz 25land on page 1 ahead ofQuiz 5Quiz 6–Quiz 25, page 2 =Quiz 1–Quiz 5Static checks:
exercise.class.phphas the same 191 errors as before; the new test has none.exercise.class.php. It crashes the same way on the unmodified master file.Security
orderBy()was added, so there is no SQL injection risk.isVisible()for the course and session) still runs, unchanged, on each displayed row.Known limitations
These predate this PR. It neither fixes nor worsens them.
Exercise::read()for every test on every page view, or duplicating the visibility checks ahead of the loop. That is left for a follow-up.SortableTableon the rendered, tag-stripped title. That title is natural and lowercased, but long titles are cut. So two titles that differ only after the cut point can swap places within a page. This happens the same way for teachers and learners.Refs #1416