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

Sorting of user lists is not locale-aware

    XMLWordPrintable

    Details

    • Affected Branches:
      MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_400_STABLE

      Description

      Steps to reproduce the problem:
      Our environment is Linux, PHP 7.4, PostgreSQL 10.

      • Use PostgreSQL database. To illustrate this problem use en_AU.UTF-8, en_US.UTF-8 collation or any collation that differs from fi_FI.UTF-8.
      • In Moodle, install Finnish language pack.
      • Create Users with following lastnames: Aijala, Otso, Åström, Äijälä, Öytti.
      • Create a course and enrol the users.
      • Change language to finnish
      • Sort by last name and check the course's participants list (user/index.php)

      Expected behaviour:
      When sorting by users' first and last names, the list is sorted according to the language in use. In our case the language is Finnish, with the following sort order:
      A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S/Š, T, U, V, W, X, Y, Z/Ž, Å, Ä, Ö
      We would expect the last names to be sorted in the order:
      Aijala
      Otso
      Åström
      Äijälä
      Öytti

      Observed behaviour:
      The list is not sorted according to the language in use.
      The names are sorted in this order:
      Aijala
      Äijälä
      Åström
      Otso
      Öytti

      In this sort order, names starting with Å, Ä and Ö are not separate, but part of A and O respectively. This is the common sorting order for most locales, but not for Finnish.
      The sorting order appears to default to the database collation, in our case en_US:
      A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z

      We have noticed that sorting of users is not locale-aware in many different places.
      The wrong sort order confuses teachers for example in the course participants view where the user list can stretch over many pages.
      Course participants (user/index.php)
      Course participants (user/index.php), download table data as

      Other places with the similar problems include:
      Site Users (admin/user.php)
      Course Assignment grading (mod/assign/view.php)
      Group members (group/members.php)
      Assign roles (admin/roles/assign.php)
      Grader report (grade/report/grader/index.php)

      Sorting should be handled by Moodle according to the language pack's locale. This is especially important for multilingual sites.
      Here is some previous discussion related to the topic.
      https://docs.moodle.org/dev/Database_collation_issue
      https://moodle.org/mod/forum/discuss.php?d=214564

      Locale-aware sorting could be done either on the database side using SELECT with COLLATION (PostgreSQL) or COLLATE (MySQL), or in Moodle's code using PHP sorting classes like intl-module's Collate.
      There is a Moodle core class core_collator in lib/classes/collator.php making use of php-intl's Collator for setting the collation to the language pack's locale string as specified in langconfig.php.
      This class is used widely in Moodle already. For some reason locale-aware sorting has not been implemented for user lists.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              schach Heiko Schach
              Participants:
              Component watchers:
              Andrew Nicols, Dongsheng Cai, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan, Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan, David Mudrák (@mudrd8mz), Helen Foster, Víctor Déniz Falcón, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona), Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              3 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: