2015-06-05 11:21:08 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
abstract class PhabricatorSearchTokenizerField
|
|
|
|
extends PhabricatorSearchField {
|
|
|
|
|
|
|
|
protected function getDefaultValue() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getValueFromRequest(AphrontRequest $request, $key) {
|
|
|
|
return $this->getListFromRequest($request, $key);
|
|
|
|
}
|
|
|
|
|
2015-06-05 11:21:22 -07:00
|
|
|
public function getValueForQuery($value) {
|
|
|
|
return $this->newDatasource()
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->evaluateTokens($value);
|
|
|
|
}
|
|
|
|
|
2015-06-05 11:21:08 -07:00
|
|
|
protected function newControl() {
|
|
|
|
return id(new AphrontFormTokenizerControl())
|
|
|
|
->setDatasource($this->newDatasource());
|
|
|
|
}
|
|
|
|
|
2015-06-05 11:21:22 -07:00
|
|
|
|
2015-06-05 11:21:08 -07:00
|
|
|
abstract protected function newDatasource();
|
|
|
|
|
2015-06-08 12:20:16 -07:00
|
|
|
|
|
|
|
protected function getUsersFromRequest(AphrontRequest $request, $key) {
|
|
|
|
$list = $this->getListFromRequest($request, $key);
|
|
|
|
$allow_types = array();
|
|
|
|
|
|
|
|
$phids = array();
|
|
|
|
$names = array();
|
|
|
|
$allow_types = array_fuse($allow_types);
|
|
|
|
$user_type = PhabricatorPeopleUserPHIDType::TYPECONST;
|
|
|
|
foreach ($list as $item) {
|
|
|
|
$type = phid_get_type($item);
|
|
|
|
if ($type == $user_type) {
|
|
|
|
$phids[] = $item;
|
|
|
|
} else if (isset($allow_types[$type])) {
|
|
|
|
$phids[] = $item;
|
|
|
|
} else {
|
|
|
|
if (PhabricatorTypeaheadDatasource::isFunctionToken($item)) {
|
|
|
|
// If this is a function, pass it through unchanged; we'll evaluate
|
|
|
|
// it later.
|
|
|
|
$phids[] = $item;
|
|
|
|
} else {
|
|
|
|
$names[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($names) {
|
|
|
|
$users = id(new PhabricatorPeopleQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withUsernames($names)
|
|
|
|
->execute();
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$phids[] = $user->getPHID();
|
|
|
|
}
|
|
|
|
$phids = array_unique($phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $phids;
|
|
|
|
}
|
|
|
|
|
2015-06-05 11:21:08 -07:00
|
|
|
}
|