Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/people/conduit/UserQueryConduitAPIMethod.php
12256 views
1
<?php
2
3
final class UserQueryConduitAPIMethod extends UserConduitAPIMethod {
4
5
public function getAPIMethodName() {
6
return 'user.query';
7
}
8
9
public function getMethodDescription() {
10
return pht('Query users.');
11
}
12
13
public function getMethodStatus() {
14
return self::METHOD_STATUS_FROZEN;
15
}
16
17
public function getMethodStatusDescription() {
18
return pht(
19
'This method is frozen and will eventually be deprecated. New code '.
20
'should use "user.search" instead.');
21
}
22
23
protected function defineParamTypes() {
24
return array(
25
'usernames' => 'optional list<string>',
26
'emails' => 'optional list<string>',
27
'realnames' => 'optional list<string>',
28
'phids' => 'optional list<phid>',
29
'ids' => 'optional list<uint>',
30
'offset' => 'optional int',
31
'limit' => 'optional int (default = 100)',
32
);
33
}
34
35
protected function defineReturnType() {
36
return 'list<dict>';
37
}
38
39
protected function defineErrorTypes() {
40
return array(
41
'ERR-INVALID-PARAMETER' => pht('Missing or malformed parameter.'),
42
);
43
}
44
45
protected function execute(ConduitAPIRequest $request) {
46
$usernames = $request->getValue('usernames', array());
47
$emails = $request->getValue('emails', array());
48
$realnames = $request->getValue('realnames', array());
49
$phids = $request->getValue('phids', array());
50
$ids = $request->getValue('ids', array());
51
$offset = $request->getValue('offset', 0);
52
$limit = $request->getValue('limit', 100);
53
54
$query = id(new PhabricatorPeopleQuery())
55
->setViewer($request->getUser())
56
->needProfileImage(true)
57
->needAvailability(true);
58
59
if ($usernames) {
60
$query->withUsernames($usernames);
61
}
62
if ($emails) {
63
$query->withEmails($emails);
64
}
65
if ($realnames) {
66
$query->withRealnames($realnames);
67
}
68
if ($phids) {
69
$query->withPHIDs($phids);
70
}
71
if ($ids) {
72
$query->withIDs($ids);
73
}
74
if ($limit) {
75
$query->setLimit($limit);
76
}
77
if ($offset) {
78
$query->setOffset($offset);
79
}
80
$users = $query->execute();
81
82
$results = array();
83
foreach ($users as $user) {
84
$results[] = $this->buildUserInformationDictionary(
85
$user,
86
$with_email = false,
87
$with_availability = true);
88
}
89
return $results;
90
}
91
92
}
93
94