Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/macro/conduit/MacroQueryConduitAPIMethod.php
13441 views
1
<?php
2
3
final class MacroQueryConduitAPIMethod extends MacroConduitAPIMethod {
4
5
public function getAPIMethodName() {
6
return 'macro.query';
7
}
8
9
public function getMethodDescription() {
10
return pht('Retrieve image macro information.');
11
}
12
13
protected function defineParamTypes() {
14
return array(
15
'authorPHIDs' => 'optional list<phid>',
16
'phids' => 'optional list<phid>',
17
'ids' => 'optional list<id>',
18
'names' => 'optional list<string>',
19
'nameLike' => 'optional string',
20
);
21
}
22
23
protected function defineReturnType() {
24
return 'list<dict>';
25
}
26
27
protected function execute(ConduitAPIRequest $request) {
28
$query = id(new PhabricatorMacroQuery())
29
->setViewer($request->getUser())
30
->needFiles(true);
31
32
$author_phids = $request->getValue('authorPHIDs');
33
$phids = $request->getValue('phids');
34
$ids = $request->getValue('ids');
35
$name_like = $request->getValue('nameLike');
36
$names = $request->getValue('names');
37
38
if ($author_phids) {
39
$query->withAuthorPHIDs($author_phids);
40
}
41
42
if ($phids) {
43
$query->withPHIDs($phids);
44
}
45
46
if ($ids) {
47
$query->withIDs($ids);
48
}
49
50
if ($name_like) {
51
$query->withNameLike($name_like);
52
}
53
54
if ($names) {
55
$query->withNames($names);
56
}
57
58
$macros = $query->execute();
59
60
if (!$macros) {
61
return array();
62
}
63
64
$results = array();
65
foreach ($macros as $macro) {
66
$file = $macro->getFile();
67
$results[$macro->getName()] = array(
68
'uri' => $file->getBestURI(),
69
'phid' => $macro->getPHID(),
70
'authorPHID' => $file->getAuthorPHID(),
71
'dateCreated' => $file->getDateCreated(),
72
'filePHID' => $file->getPHID(),
73
);
74
}
75
76
return $results;
77
}
78
79
}
80
81