UserModel::getMeta PHP Method

getMeta() public static method

This method takes a $UserID or array of $UserIDs, and a $Key. It converts the $Key to fully qualified format and then queries for the associated value(s). $Key can contain SQL wildcards, in which case multiple results can be returned. If $UserID is an array, the return value will be a multi dimensional array with the first axis containing UserIDs and the second containing fully qualified UserMetaKeys, associated with their values. If $UserID is a scalar, the return value will be a single dimensional array of $UserMetaKey => $Value pairs.
public static getMeta ( integer $UserID, string $Key, string $Prefix = '', string $Default = '' ) : array
$UserID integer UserID or array of UserIDs.
$Key string Relative user meta key.
$Prefix string
$Default string
return array results or $Default
    public static function getMeta($UserID, $Key, $Prefix = '', $Default = '')
    {
        $Sql = Gdn::sql()->select('*')->from('UserMeta u');
        if (is_array($UserID)) {
            $Sql->whereIn('u.UserID', $UserID);
        } else {
            $Sql->where('u.UserID', $UserID);
        }
        if (strpos($Key, '%') !== false) {
            $Sql->like('u.Name', $Key, 'none');
        } else {
            $Sql->where('u.Name', $Key);
        }
        $Data = $Sql->get()->resultArray();
        if (is_array($UserID)) {
            $Result = array_fill_keys($UserID, []);
        } else {
            if (strpos($Key, '%') === false) {
                $Result = [stringBeginsWith($Key, $Prefix, false, true) => $Default];
            } else {
                $Result = [];
            }
        }
        foreach ($Data as $Row) {
            $Name = stringBeginsWith($Row['Name'], $Prefix, false, true);
            if (is_array($UserID)) {
                $Result[$Row['UserID']][$Name] = $Row['Value'];
            } else {
                $Result[$Name] = $Row['Value'];
            }
        }
        return $Result;
    }
UserModel