3 final class DrydockBlueprintQuery
extends DrydockQuery
{
7 private $blueprintClasses;
8 private $datasourceQuery;
10 private $authorizedPHIDs;
12 public function withIDs(array $ids) {
17 public function withPHIDs(array $phids) {
18 $this->phids
= $phids;
22 public function withBlueprintClasses(array $classes) {
23 $this->blueprintClasses
= $classes;
27 public function withDatasourceQuery($query) {
28 $this->datasourceQuery
= $query;
32 public function withDisabled($disabled) {
33 $this->disabled
= $disabled;
37 public function withAuthorizedPHIDs(array $phids) {
38 $this->authorizedPHIDs
= $phids;
42 public function withNameNgrams($ngrams) {
43 return $this->withNgramsConstraint(
44 new DrydockBlueprintNameNgrams(),
48 public function newResultObject() {
49 return new DrydockBlueprint();
52 protected function getPrimaryTableAlias() {
56 protected function loadPage() {
57 return $this->loadStandardPage($this->newResultObject());
60 protected function willFilterPage(array $blueprints) {
61 $impls = DrydockBlueprintImplementation
::getAllBlueprintImplementations();
62 foreach ($blueprints as $key => $blueprint) {
63 $impl = idx($impls, $blueprint->getClassName());
65 $this->didRejectResult($blueprint);
66 unset($blueprints[$key]);
70 $blueprint->attachImplementation($impl);
76 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
77 $where = parent
::buildWhereClauseParts($conn);
79 if ($this->ids
!== null) {
82 'blueprint.id IN (%Ld)',
86 if ($this->phids
!== null) {
89 'blueprint.phid IN (%Ls)',
93 if ($this->datasourceQuery
!== null) {
96 'blueprint.blueprintName LIKE %>',
97 $this->datasourceQuery
);
100 if ($this->blueprintClasses
!== null) {
103 'blueprint.className IN (%Ls)',
104 $this->blueprintClasses
);
107 if ($this->disabled
!== null) {
110 'blueprint.isDisabled = %d',
111 (int)$this->disabled
);
117 protected function shouldGroupQueryResultRows() {
118 if ($this->authorizedPHIDs
!== null) {
121 return parent
::shouldGroupQueryResultRows();
124 protected function buildJoinClauseParts(AphrontDatabaseConnection
$conn) {
125 $joins = parent
::buildJoinClauseParts($conn);
127 if ($this->authorizedPHIDs
!== null) {
130 'JOIN %T authorization
131 ON authorization.blueprintPHID = blueprint.phid
132 AND authorization.objectPHID IN (%Ls)
133 AND authorization.objectAuthorizationState = %s
134 AND authorization.blueprintAuthorizationState = %s',
135 id(new DrydockAuthorization())->getTableName(),
136 $this->authorizedPHIDs
,
137 DrydockAuthorization
::OBJECTAUTH_ACTIVE
,
138 DrydockAuthorization
::BLUEPRINTAUTH_AUTHORIZED
);