-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayUserController
64 lines (59 loc) · 2.64 KB
/
DisplayUserController
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
public class DisplayUserController {
@AuraEnabled
public static User[] getUsers() {
Set<id> resultIds = getCommunityUsers();
List<User> u = [SELECT Id, Name,email,FullPhotoUrl,Title from User where isactive=true and Id in :resultIds order by lastname,firstname];
Return u;
}
@AuraEnabled
Public static NetworkMember[] getMembers(){
//find the current community
Id netID = Network.getnetworkId();
List<NetworkMember> nw = [select MemberId, Member.Name, Member.FullPhotoUrl,Network.UrlPathPrefix from NetworkMember where Networkid=:netID and Member.isActive=true];
return nw;
}
public static Set<Id> getCommunityUsers(){
//get a list of users in the current community
Id netID = Network.getnetworkId();
List<NetworkMember> netUsers = [select MemberId from NetworkMember where NetworkID = :netID];
Set<Id> resultIds = new Set<Id>();
For (NetworkMember nm : netUsers){
resultIds.add(nm.MemberId);
}
return resultIds;
}
@AuraEnabled
public static String getURLPrefix(){
//find the URL prefix of the community
Id netID = Network.getnetworkId();
Network n = [select id, UrlPathPrefix from Network where id=:netId];
string urlprefix = n.UrlPathPrefix;
system.debug(urlprefix);
return urlprefix;
}
@AuraEnabled
public static User[] findbyName(String searchKey){
//this is the original search option - by name
Set<id> resultIds = getCommunityUsers();
String name = '%' + searchkey + '%';
List<User> u = [SELECT Id, Name,email,FullPhotoUrl,Title from User where isactive=true and Id in :resultIds and name like :name order by lastname,firstname];
Return u;
}
@AuraEnabled
public static User[] searchProfile(String searchKey){
//Uses SOSL to search the profile - limited to users in the current community
Set<id> resultIds = getCommunityUsers();
String name = String.escapeSingleQuotes(searchKey).trim().toLowerCase();
String soqlquery = 'FIND \'' + name + '\' ';
soqlquery += 'IN ALL FIELDS ';
soqlquery += 'RETURNING User (Id,Name,Email,FullPhotoUrl,Title WHERE isactive=true and Id in :resultIds)';
try {
List<List<sObject>> soqlresults = Search.query(soqlquery);
return soqlresults[0];
}
catch (System.SearchException e) {
List<User> u = [SELECT Id, Name,email,FullPhotoUrl,Title from User where isactive=true and Id in :resultIds order by lastname,firstname];
Return u;
}
}
}