mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-10 23:01:04 +01:00
Add more application query capabilities
Summary: Make the application query a little more flexible, and formalize the PHID type. Test Plan: See next diffs. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D7201
This commit is contained in:
parent
eb548f5af7
commit
461fc3dadf
4 changed files with 90 additions and 2 deletions
|
@ -840,6 +840,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorApplicationManiphest' => 'applications/maniphest/application/PhabricatorApplicationManiphest.php',
|
||||
'PhabricatorApplicationMetaMTA' => 'applications/metamta/application/PhabricatorApplicationMetaMTA.php',
|
||||
'PhabricatorApplicationOwners' => 'applications/owners/application/PhabricatorApplicationOwners.php',
|
||||
'PhabricatorApplicationPHIDTypeApplication' => 'applications/meta/phid/PhabricatorApplicationPHIDTypeApplication.php',
|
||||
'PhabricatorApplicationPHPAST' => 'applications/phpast/application/PhabricatorApplicationPHPAST.php',
|
||||
'PhabricatorApplicationPaste' => 'applications/paste/application/PhabricatorApplicationPaste.php',
|
||||
'PhabricatorApplicationPeople' => 'applications/people/application/PhabricatorApplicationPeople.php',
|
||||
|
@ -2948,6 +2949,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorApplicationManiphest' => 'PhabricatorApplication',
|
||||
'PhabricatorApplicationMetaMTA' => 'PhabricatorApplication',
|
||||
'PhabricatorApplicationOwners' => 'PhabricatorApplication',
|
||||
'PhabricatorApplicationPHIDTypeApplication' => 'PhabricatorPHIDType',
|
||||
'PhabricatorApplicationPHPAST' => 'PhabricatorApplication',
|
||||
'PhabricatorApplicationPaste' => 'PhabricatorApplication',
|
||||
'PhabricatorApplicationPeople' => 'PhabricatorApplication',
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorApplicationPHIDTypeApplication
|
||||
extends PhabricatorPHIDType {
|
||||
|
||||
const TYPECONST = 'APPS';
|
||||
|
||||
public function getTypeConstant() {
|
||||
return self::TYPECONST;
|
||||
}
|
||||
|
||||
public function getTypeName() {
|
||||
return pht('Application');
|
||||
}
|
||||
|
||||
public function newObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function loadObjects(
|
||||
PhabricatorObjectQuery $query,
|
||||
array $phids) {
|
||||
|
||||
return id(new PhabricatorApplicationQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
||||
public function loadHandles(
|
||||
PhabricatorHandleQuery $query,
|
||||
array $handles,
|
||||
array $objects) {
|
||||
|
||||
foreach ($handles as $phid => $handle) {
|
||||
$application = $objects[$phid];
|
||||
|
||||
$handle->setName($application->getName());
|
||||
$handle->setURI($application->getApplicationURI());
|
||||
}
|
||||
}
|
||||
|
||||
public function canLoadNamedObject($name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,8 @@ final class PhabricatorAppSearchEngine
|
|||
}
|
||||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$query = id(new PhabricatorApplicationQuery());
|
||||
$query = id(new PhabricatorApplicationQuery())
|
||||
->setOrder(PhabricatorApplicationQuery::ORDER_NAME);
|
||||
|
||||
$name = $saved->getParameter('name');
|
||||
if (strlen($name)) {
|
||||
|
|
|
@ -8,6 +8,12 @@ final class PhabricatorApplicationQuery
|
|||
private $firstParty;
|
||||
private $nameContains;
|
||||
private $classes;
|
||||
private $phids;
|
||||
|
||||
const ORDER_APPLICATION = 'order:application';
|
||||
const ORDER_NAME = 'order:name';
|
||||
|
||||
private $order = self::ORDER_APPLICATION;
|
||||
|
||||
public function withNameContains($name_contains) {
|
||||
$this->nameContains = $name_contains;
|
||||
|
@ -34,6 +40,16 @@ final class PhabricatorApplicationQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withPHIDs(array $phids) {
|
||||
$this->phids = $phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOrder($order) {
|
||||
$this->order = $order;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function loadPage() {
|
||||
$apps = PhabricatorApplication::getAllApplications();
|
||||
|
||||
|
@ -46,6 +62,15 @@ final class PhabricatorApplicationQuery
|
|||
}
|
||||
}
|
||||
|
||||
if ($this->phids) {
|
||||
$phids = array_fuse($this->phids);
|
||||
foreach ($apps as $key => $app) {
|
||||
if (empty($phids[$app->getPHID()])) {
|
||||
unset($apps[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen($this->nameContains)) {
|
||||
foreach ($apps as $key => $app) {
|
||||
if (stripos($app->getName(), $this->nameContains) === false) {
|
||||
|
@ -78,7 +103,19 @@ final class PhabricatorApplicationQuery
|
|||
}
|
||||
}
|
||||
|
||||
return msort($apps, 'getName');
|
||||
switch ($this->order) {
|
||||
case self::ORDER_NAME:
|
||||
$apps = msort($apps, 'getName');
|
||||
break;
|
||||
case self::ORDER_APPLICATION:
|
||||
$apps = $apps;
|
||||
break;
|
||||
default:
|
||||
throw new Exception(
|
||||
pht('Unknown order "%s"!', $this->order));
|
||||
}
|
||||
|
||||
return $apps;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue