3 final class DrydockResourceQuery
extends DrydockQuery
{
9 private $blueprintPHIDs;
10 private $datasourceQuery;
11 private $needUnconsumedCommands;
13 public function withIDs(array $ids) {
18 public function withPHIDs(array $phids) {
19 $this->phids
= $phids;
23 public function withTypes(array $types) {
24 $this->types
= $types;
28 public function withStatuses(array $statuses) {
29 $this->statuses
= $statuses;
33 public function withBlueprintPHIDs(array $blueprint_phids) {
34 $this->blueprintPHIDs
= $blueprint_phids;
38 public function withDatasourceQuery($query) {
39 $this->datasourceQuery
= $query;
43 public function needUnconsumedCommands($need) {
44 $this->needUnconsumedCommands
= $need;
48 public function newResultObject() {
49 return new DrydockResource();
52 protected function loadPage() {
53 return $this->loadStandardPage($this->newResultObject());
56 protected function willFilterPage(array $resources) {
57 $blueprint_phids = mpull($resources, 'getBlueprintPHID');
59 $blueprints = id(new DrydockBlueprintQuery())
60 ->setViewer($this->getViewer())
61 ->withPHIDs($blueprint_phids)
63 $blueprints = mpull($blueprints, null, 'getPHID');
65 foreach ($resources as $key => $resource) {
66 $blueprint = idx($blueprints, $resource->getBlueprintPHID());
68 $this->didRejectResult($resource);
69 unset($resources[$key]);
72 $resource->attachBlueprint($blueprint);
78 protected function didFilterPage(array $resources) {
79 if ($this->needUnconsumedCommands
) {
80 $commands = id(new DrydockCommandQuery())
81 ->setViewer($this->getViewer())
82 ->setParentQuery($this)
83 ->withTargetPHIDs(mpull($resources, 'getPHID'))
86 $commands = mgroup($commands, 'getTargetPHID');
88 foreach ($resources as $resource) {
89 $list = idx($commands, $resource->getPHID(), array());
90 $resource->attachUnconsumedCommands($list);
97 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
98 $where = parent
::buildWhereClauseParts($conn);
100 if ($this->ids
!== null) {
103 'resource.id IN (%Ld)',
107 if ($this->phids
!== null) {
110 'resource.phid IN (%Ls)',
114 if ($this->types
!== null) {
117 'resource.type IN (%Ls)',
121 if ($this->statuses
!== null) {
124 'resource.status IN (%Ls)',
128 if ($this->blueprintPHIDs
!== null) {
131 'resource.blueprintPHID IN (%Ls)',
132 $this->blueprintPHIDs
);
135 if ($this->datasourceQuery
!== null) {
138 'resource.name LIKE %>',
139 $this->datasourceQuery
);
145 protected function getPrimaryTableAlias() {