mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 12:48:24 +01:00
getUsersInClass() now accepts extended user field names - just prefix those fields with "ue.".
This commit is contained in:
parent
c18edcac43
commit
48ae6455a4
@ -1143,7 +1143,7 @@ class user_class
|
||||
*
|
||||
* Could potentially be verrrrryyyy slow - has to scan the whole user database at present.
|
||||
* @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 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
|
||||
@ -1203,7 +1203,9 @@ class user_class
|
||||
|
||||
$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))
|
||||
{
|
||||
@ -1212,6 +1214,7 @@ class user_class
|
||||
$row['user_id'] = (int) $row['user_id'];
|
||||
$ret[$row['user_id']] = $row;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
@ -88,9 +88,10 @@
|
||||
{
|
||||
$result = $this->uc->getUsersInClass(e_UC_MEMBER);
|
||||
$expected = [
|
||||
'user_id' => '1',
|
||||
'user_id' => 1,
|
||||
'user_name' => 'e107',
|
||||
'user_loginname' => 'e107',
|
||||
|
||||
];
|
||||
|
||||
$passed = false;
|
||||
@ -102,7 +103,7 @@
|
||||
|
||||
$result = $this->uc->getUsersInClass(e_UC_ADMIN . ",5,4,3", 'user_perms');
|
||||
$expected = [
|
||||
'user_id' => '1',
|
||||
'user_id' => 1,
|
||||
'user_perms' => '0',
|
||||
];
|
||||
|
||||
@ -115,7 +116,7 @@
|
||||
|
||||
$result = $this->uc->getUsersInClass(e_UC_MAINADMIN);
|
||||
$expected = [
|
||||
'user_id' => '1',
|
||||
'user_id' => 1,
|
||||
'user_name' => 'e107',
|
||||
'user_loginname' => 'e107',
|
||||
];
|
||||
@ -126,6 +127,24 @@
|
||||
if ($user == $expected) $passed = true;
|
||||
}
|
||||
$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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user