* @param IDatabase|null $db Optional database connection
* @return array Associative array of (group name => UserGroupMembership object)
*/
- public static function getMembershipsForUser( $userId, $db = null ) {
+ public static function getMembershipsForUser( $userId, IDatabase $db = null ) {
if ( !$db ) {
$db = wfGetDB( DB_REPLICA );
}
* @return array
*/
function getGroups() {
- $res = $this->db->select( 'user_groups',
- [ 'ug_group' ],
- [ 'ug_user' => $this->id ],
- __METHOD__ );
- $groups = [];
- foreach ( $res as $row ) {
- $groups[] = $row->ug_group;
- }
- return $groups;
+ return array_keys( self::getGroupMemberships() );
}
/**
* @since 1.29
*/
function getGroupMemberships() {
- $res = $this->db->select( 'user_groups',
- UserGroupMembership::selectFields(),
- [ 'ug_user' => $this->id ],
- __METHOD__ );
- $ugms = [];
- foreach ( $res as $row ) {
- $ugms[$row->ug_group] = UserGroupMembership::newFromRow( $row );
- }
- return $ugms;
+ return UserGroupMembership::getMembershipsForUser( $this->id, $this->db );
}
/**