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

Nasty code in admin/user.php

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.4.1
    • Fix Version/s: DEV backlog
    • Component/s: Libraries
    • Labels:
    • Affected Branches:
      MOODLE_24_STABLE

      Description

      The code that is changed here was, and sill is, horrible: https://github.com/abgreeve/moodle/commit/1a1919412196174c7d967d3e5ba6037fe05147ee

      There are two problems:

      First, the way that the code is written duplicates complex logic that should be encapsulated in the fullname() function. I think a better approach would be:

      $dummyuser = new stdClass();
      $dummyuser->firstname = 'F';
      $dummyuser->lastname = 'L';
      $order = fullname($dummyuser);
      if ($order[0] = 'F') {
          // Firstname displayed first.
      } else {
          // Lastname displayed first.
      }
      

      And that code should probably be in a function in moodlelib.php next to fullname(), not inline in admin/user.php.

      Second, what the code is doing is problematic. Sorting of users is meant to be controlled by users_order_by_sql in datalib.php, so it is consistent. So, parhaps admin/user.php should be using that function, and maybe that function should be talking note of the fullname setting, or maybe we should have a separate setting (on the same admin screen as the fullname setting) for default user sort order.

      (In English, one would normally display Firstname Lastname, but sort on Lastname.)

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              moodle.com moodle.com
              Reporter:
              timhunt Tim Hunt
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: