1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

getUsersInClass() now accepts extended user field names - just prefix those fields with "ue.".

This commit is contained in:
Cameron
2020-01-23 14:59:01 -08:00
parent c18edcac43
commit 48ae6455a4
2 changed files with 27 additions and 5 deletions

View File

@@ -1143,7 +1143,7 @@ class user_class
* *
* Could potentially be verrrrryyyy slow - has to scan the whole user database at present. * Could potentially be verrrrryyyy slow - has to scan the whole user database at present.
* @param string $$classes - comma separated list of classes * @param string $$classes - comma separated list of classes
* @param string $fields - comma separated list of fields to be returned. `user_id` is always returned as the key of the array entry * @param string $fields - comma separated list of fields to be returned. `user_id` is always returned as the key of the array entry, prefix with 'ue.' to retrieve extended user fields.
* @param boolean $includeAncestors - if TRUE, also looks for classes in the hierarchy; otherwise checks exactly the classes passed * @param boolean $includeAncestors - if TRUE, also looks for classes in the hierarchy; otherwise checks exactly the classes passed
* @param string $orderBy - optional field name to define the order of entries in the results array * @param string $orderBy - optional field name to define the order of entries in the results array
* @return array indexed by user_id, each element is an array (database row) containing the requested fields * @return array indexed by user_id, each element is an array (database row) containing the requested fields
@@ -1203,7 +1203,9 @@ class user_class
$ret = array(); $ret = array();
$query = "SELECT user_id,{$fields} FROM `#user` WHERE ".implode(" OR ",$qry)." ORDER BY ".$orderBy; $lj = strpos($fields,'ue.') !== false ? "LEFT JOIN `#user_extended` AS ue ON user_id = ue.user_extended_id " : "";
$query = "SELECT user_id,{$fields} FROM `#user` ".$lj." WHERE ".implode(" OR ",$qry)." ORDER BY ".$orderBy;
if ($sql->gen($query)) if ($sql->gen($query))
{ {
@@ -1212,6 +1214,7 @@ class user_class
$row['user_id'] = (int) $row['user_id']; $row['user_id'] = (int) $row['user_id'];
$ret[$row['user_id']] = $row; $ret[$row['user_id']] = $row;
} }
} }
return $ret; return $ret;

View File

@@ -88,9 +88,10 @@
{ {
$result = $this->uc->getUsersInClass(e_UC_MEMBER); $result = $this->uc->getUsersInClass(e_UC_MEMBER);
$expected = [ $expected = [
'user_id' => '1', 'user_id' => 1,
'user_name' => 'e107', 'user_name' => 'e107',
'user_loginname' => 'e107', 'user_loginname' => 'e107',
]; ];
$passed = false; $passed = false;
@@ -102,7 +103,7 @@
$result = $this->uc->getUsersInClass(e_UC_ADMIN . ",5,4,3", 'user_perms'); $result = $this->uc->getUsersInClass(e_UC_ADMIN . ",5,4,3", 'user_perms');
$expected = [ $expected = [
'user_id' => '1', 'user_id' => 1,
'user_perms' => '0', 'user_perms' => '0',
]; ];
@@ -115,7 +116,7 @@
$result = $this->uc->getUsersInClass(e_UC_MAINADMIN); $result = $this->uc->getUsersInClass(e_UC_MAINADMIN);
$expected = [ $expected = [
'user_id' => '1', 'user_id' => 1,
'user_name' => 'e107', 'user_name' => 'e107',
'user_loginname' => 'e107', 'user_loginname' => 'e107',
]; ];
@@ -126,6 +127,24 @@
if ($user == $expected) $passed = true; if ($user == $expected) $passed = true;
} }
$this->assertTrue($passed, "Expected user not found"); $this->assertTrue($passed, "Expected user not found");
// Test returning extended user fields.
$result = $this->uc->getUsersInClass(e_UC_MAINADMIN,'user_perms,ue.user_extended_id');
$expected = [
'user_id' => 1,
'user_perms' => '0',
'user_extended_id' => '1'
];
$passed = false;
foreach ($result as $user)
{
if ($user == $expected) $passed = true;
}
$this->assertTrue($passed, "Expected user not found:".print_r($result,true));
} }
/* /*
public function testGet_editable_classes() public function testGet_editable_classes()