login/members: order by full name
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 2 Aug 2018 03:41:25 +0000 (05:41 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 4 Aug 2018 22:05:02 +0000 (00:05 +0200)
Login may not match in which case visible results appear random.
Support sort by any ?order column, assuming anything besides seen date
is alphanumeric.

auth.inc.php
login/list.php
login/members/index.html

index 772e256129c89abfbc01710fbd195ee8ba82b8d2..631bf8b06cccb33f6e64bce65d217c29cdb50acf 100644 (file)
@@ -14,10 +14,14 @@ class User
                return $this->$col = $this->$col();  # run method and cache
        }
 
+       function rawname()
+       {
+               return @file_get_contents("{$this->dir}/name.txt");
+       }
+
        function name()
        {
-               $name = @file_get_contents("{$this->dir}/name.txt");
-               return htmlspecialchars(implode(' & ', explode("\n", $name)));
+               return htmlspecialchars(implode(' & ', explode("\n", $this->rawname)));
        }
 
        function admin()
index 0d9eec2a73240a414961fe378dba12c09ab6eda8..7872bd64f32838dbeb3e3b92ca93b47ca219d788 100644 (file)
@@ -8,11 +8,19 @@ foreach ($users as $col => $userdir) {
        $users[$col] = new User($userdir);
 }
 
-if (@$Place['order'] == 'seen') {
-       $order = array_map(function ($col) { return $col->seen; }, $users);
-#      $order = array_column($users, 'seen');  #TODO php7 simplification
-       array_multisort($order, SORT_DESC, SORT_NUMERIC, $users);
-       $users = array_intersect_key($users, array_filter($order));
+if (isset($Place['order'])) {
+       $ordercol = $Place['order'];
+       $order = array_map(function ($row) use ($ordercol) {
+               return $row->$ordercol;
+       }, $users);
+#      $order = array_column($users, $ordercol);  #TODO php7 simplification
+       if ($ordercol == 'seen') {
+               array_multisort($order, SORT_DESC, SORT_NUMERIC, $users);
+               $users = array_intersect_key($users, array_filter($order));
+       }
+       else {
+               array_multisort($order, SORT_ASC, SORT_NATURAL, $users);
+       }
 }
 
 if (isset($Place['n'])) {
index 149c62fd673cac1aefe52578b09d38dec77275b3..8ad05dae9725a03184f781efd0126d707b9e9dc0 100644 (file)
@@ -1,7 +1,7 @@
 <h2>Ledenlijst</h2>
 
 <div id="members">
-[[login/list view=visit]]
+[[login/list view=visit order=name]]
 </div>
 
 <script>