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

Change sort order of names in Choice lists

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9.4
    • Fix Version/s: 1.9.5
    • Component/s: Choice
    • Labels:
      None
    • Environment:
      All
    • Database:
      Any
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      In Choice activities, users who have not answered are listed alphabetically by first name only (without respect to last name). Users who have responded are listed in no particular order. Personally, I prefer the names to be sorted by "lastname, firstname" in each column, but any predictable order is better than no order.

      Changing the sort order turns out to be easy, but not obvious.

      In mod/choice/lib.php, near the bottom of function choice_get_response_data() - just before the final "return $allresponses;" statement, add the following:

      foreach(array_keys($allresponses) as $aKey)

      { uasort($allresponses[$aKey], "nameCmp"); }

      and just after the end of function choice_get_response_data() , add a comparison function:

      /**

      • used to sort responses by name in function choice_get_response_data()
      • – a different set of arguments to strcmp() can change the ordering.
        */
        function nameCmp($a, $b)
        {
        return strcmp($a->lastname.$a->firstname,
        $b->lastname.$b->firstname);
        }

        Attachments

          Activity

            People

            Assignee:
            danmarsden Dan Marsden
            Reporter:
            bgray Brian Gray
            Tester:
            Petr Skoda
            Participants:
            Component watchers:
            Dan Marsden, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              13/May/09