Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / search / field / PhabricatorSearchTokenizerField.php
blob9da7f9908cd4fbe175e426b8f2aa91a08b0c33c1
1 <?php
3 abstract class PhabricatorSearchTokenizerField
4 extends PhabricatorSearchField {
6 protected function getDefaultValue() {
7 return array();
10 protected function getValueFromRequest(AphrontRequest $request, $key) {
11 return $this->getListFromRequest($request, $key);
14 public function getValueForQuery($value) {
15 return $this->newDatasource()
16 ->setViewer($this->getViewer())
17 ->evaluateTokens($value);
20 protected function newControl() {
21 return id(new AphrontFormTokenizerControl())
22 ->setDatasource($this->newDatasource());
26 abstract protected function newDatasource();
29 protected function getUsersFromRequest(
30 AphrontRequest $request,
31 $key,
32 array $allow_types = array()) {
33 $list = $this->getListFromRequest($request, $key);
35 $phids = array();
36 $names = array();
37 $allow_types = array_fuse($allow_types);
38 $user_type = PhabricatorPeopleUserPHIDType::TYPECONST;
39 foreach ($list as $item) {
40 $type = phid_get_type($item);
41 if ($type == $user_type) {
42 $phids[] = $item;
43 } else if (isset($allow_types[$type])) {
44 $phids[] = $item;
45 } else {
46 if (PhabricatorTypeaheadDatasource::isFunctionToken($item)) {
47 // If this is a function, pass it through unchanged; we'll evaluate
48 // it later.
49 $phids[] = $item;
50 } else {
51 $names[] = $item;
56 if ($names) {
57 $users = id(new PhabricatorPeopleQuery())
58 ->setViewer($this->getViewer())
59 ->withUsernames($names)
60 ->execute();
61 foreach ($users as $user) {
62 $phids[] = $user->getPHID();
64 $phids = array_unique($phids);
67 return $phids;