Browse Source

Optimize user list

leosw 8 months ago
parent
commit
250aff13e5
3 changed files with 6 additions and 12 deletions
  1. 0 7
      controllers/d.users.php
  2. 5 4
      models/d.users.php
  3. 1 1
      views/d.user.member_list.html

+ 0 - 7
controllers/d.users.php

@@ -205,13 +205,6 @@ if(isset($controller->splitted_url[1])) {
 
 				$users->list_users($page*$rows_per_pages,$rows_per_pages,$orderby,$order);
 
-				$i = 0;
-				foreach ($users->ids as $row) {
-					$user_list[$i] = new User();
-					$user_list[$i]->checkID($row);
-					$i++;
-				}
-
 				$first = $page*$rows_per_pages+1;
 				$last = (($page+1)*$rows_per_pages > $users->number ? $users->number : ($page+1)*$rows_per_pages);
 				

+ 5 - 4
models/d.users.php

@@ -383,7 +383,7 @@ function randomPassword() {
 
 class Users
 {
-	public $ids = array();
+	public $objs = array();
 	public $number = NULL;
 
 	/*****
@@ -421,9 +421,9 @@ class Users
 		$orderbysafe=$orders[$key];
 
 		if ($order == 'ASC')
-			$query = "SELECT id FROM users ORDER BY $orderbysafe ASC LIMIT $1 OFFSET $2";
+			$query = "SELECT * FROM users ORDER BY $orderbysafe ASC LIMIT $1 OFFSET $2";
 		else
-			$query = "SELECT id FROM users ORDER BY $orderbysafe DESC LIMIT $1 OFFSET $2";
+			$query = "SELECT * FROM users ORDER BY $orderbysafe DESC LIMIT $1 OFFSET $2";
 		
 
 		pg_prepare($con, "prepare1", $query) 
@@ -435,7 +435,8 @@ class Users
 
 		for($i = 0; $i < pg_num_rows($result); $i++) {
 			$row = pg_fetch_assoc($result, $i);
-			$this->ids[$i] = $row['id'];
+			$this->objs[$i] = new User;
+			$this->objs[$i]->populate($row);
 		}
 	}
 }

+ 1 - 1
views/d.user.member_list.html

@@ -34,7 +34,7 @@
 						<?=$orderby=='website'?$order=='ASC'?'<i class="fas fa-caret-down" aria-hidden="true"></i>':'<i class="fas fa-caret-up" aria-hidden="true"></i>':''?>
 					</th>
 				</tr>
-			<? foreach ($user_list as $row) { ?>
+			<? foreach ($users->objs as $row) { ?>
 				<tr>
 					<td>
 						<? if ($row->is_avatar_present=='t') { ?>