~ubuntu-branches/ubuntu/wily/phabricator/wily

« back to all changes in this revision

Viewing changes to phabricator/src/applications/search/field/PhabricatorSearchTokenizerField.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2015-06-13 10:52:10 UTC
  • mfrom: (0.30.1) (0.29.1) (0.17.4) (2.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20150613105210-5uirr7tvnk0n6e6y
Tags: 0~git20150613-1
* New snapshot release (closes: #787805)
* fixed typo in logrotate script (closes: #787645)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
abstract class PhabricatorSearchTokenizerField
 
4
  extends PhabricatorSearchField {
 
5
 
 
6
  protected function getDefaultValue() {
 
7
    return array();
 
8
  }
 
9
 
 
10
  protected function getValueFromRequest(AphrontRequest $request, $key) {
 
11
    return $this->getListFromRequest($request, $key);
 
12
  }
 
13
 
 
14
  public function getValueForQuery($value) {
 
15
    return $this->newDatasource()
 
16
      ->setViewer($this->getViewer())
 
17
      ->evaluateTokens($value);
 
18
  }
 
19
 
 
20
  protected function newControl() {
 
21
    return id(new AphrontFormTokenizerControl())
 
22
      ->setDatasource($this->newDatasource());
 
23
  }
 
24
 
 
25
 
 
26
  abstract protected function newDatasource();
 
27
 
 
28
 
 
29
  protected function getUsersFromRequest(
 
30
    AphrontRequest $request,
 
31
    $key,
 
32
    array $allow_types = array()) {
 
33
    $list = $this->getListFromRequest($request, $key);
 
34
 
 
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;
 
52
        }
 
53
      }
 
54
    }
 
55
 
 
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();
 
63
      }
 
64
      $phids = array_unique($phids);
 
65
    }
 
66
 
 
67
    return $phids;
 
68
  }
 
69
 
 
70
}