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

Nasty code in admin/user.php

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Minor Minor
    • None
    • 2.4.1
    • Libraries
    • MOODLE_24_STABLE

      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.)

            moodle.com Moodle HQ
            timhunt Tim Hunt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

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