Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / drydock / query / DrydockBlueprintQuery.php
blob6c92927bb8caa487825955fd1bdfcff74bd588a8
1 <?php
3 final class DrydockBlueprintQuery extends DrydockQuery {
5 private $ids;
6 private $phids;
7 private $blueprintClasses;
8 private $datasourceQuery;
9 private $disabled;
10 private $authorizedPHIDs;
12 public function withIDs(array $ids) {
13 $this->ids = $ids;
14 return $this;
17 public function withPHIDs(array $phids) {
18 $this->phids = $phids;
19 return $this;
22 public function withBlueprintClasses(array $classes) {
23 $this->blueprintClasses = $classes;
24 return $this;
27 public function withDatasourceQuery($query) {
28 $this->datasourceQuery = $query;
29 return $this;
32 public function withDisabled($disabled) {
33 $this->disabled = $disabled;
34 return $this;
37 public function withAuthorizedPHIDs(array $phids) {
38 $this->authorizedPHIDs = $phids;
39 return $this;
42 public function withNameNgrams($ngrams) {
43 return $this->withNgramsConstraint(
44 new DrydockBlueprintNameNgrams(),
45 $ngrams);
48 public function newResultObject() {
49 return new DrydockBlueprint();
52 protected function getPrimaryTableAlias() {
53 return 'blueprint';
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());
64 if (!$impl) {
65 $this->didRejectResult($blueprint);
66 unset($blueprints[$key]);
67 continue;
69 $impl = clone $impl;
70 $blueprint->attachImplementation($impl);
73 return $blueprints;
76 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
77 $where = parent::buildWhereClauseParts($conn);
79 if ($this->ids !== null) {
80 $where[] = qsprintf(
81 $conn,
82 'blueprint.id IN (%Ld)',
83 $this->ids);
86 if ($this->phids !== null) {
87 $where[] = qsprintf(
88 $conn,
89 'blueprint.phid IN (%Ls)',
90 $this->phids);
93 if ($this->datasourceQuery !== null) {
94 $where[] = qsprintf(
95 $conn,
96 'blueprint.blueprintName LIKE %>',
97 $this->datasourceQuery);
100 if ($this->blueprintClasses !== null) {
101 $where[] = qsprintf(
102 $conn,
103 'blueprint.className IN (%Ls)',
104 $this->blueprintClasses);
107 if ($this->disabled !== null) {
108 $where[] = qsprintf(
109 $conn,
110 'blueprint.isDisabled = %d',
111 (int)$this->disabled);
114 return $where;
117 protected function shouldGroupQueryResultRows() {
118 if ($this->authorizedPHIDs !== null) {
119 return true;
121 return parent::shouldGroupQueryResultRows();
124 protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
125 $joins = parent::buildJoinClauseParts($conn);
127 if ($this->authorizedPHIDs !== null) {
128 $joins[] = qsprintf(
129 $conn,
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);
141 return $joins;