Path: blob/master/src/applications/nuance/query/NuanceSourceQuery.php
12256 views
<?php12final class NuanceSourceQuery3extends NuanceQuery {45private $ids;6private $phids;7private $types;8private $isDisabled;9private $hasCursors;1011public function withIDs(array $ids) {12$this->ids = $ids;13return $this;14}1516public function withPHIDs(array $phids) {17$this->phids = $phids;18return $this;19}2021public function withTypes($types) {22$this->types = $types;23return $this;24}2526public function withIsDisabled($disabled) {27$this->isDisabled = $disabled;28return $this;29}3031public function withHasImportCursors($has_cursors) {32$this->hasCursors = $has_cursors;33return $this;34}3536public function withNameNgrams($ngrams) {37return $this->withNgramsConstraint(38new NuanceSourceNameNgrams(),39$ngrams);40}4142public function newResultObject() {43return new NuanceSource();44}4546protected function getPrimaryTableAlias() {47return 'source';48}4950protected function willFilterPage(array $sources) {51$all_types = NuanceSourceDefinition::getAllDefinitions();5253foreach ($sources as $key => $source) {54$definition = idx($all_types, $source->getType());55if (!$definition) {56$this->didRejectResult($source);57unset($sources[$key]);58continue;59}60$source->attachDefinition($definition);61}6263return $sources;64}656667protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {68$where = parent::buildWhereClauseParts($conn);6970if ($this->types !== null) {71$where[] = qsprintf(72$conn,73'source.type IN (%Ls)',74$this->types);75}7677if ($this->ids !== null) {78$where[] = qsprintf(79$conn,80'source.id IN (%Ld)',81$this->ids);82}8384if ($this->phids !== null) {85$where[] = qsprintf(86$conn,87'source.phid IN (%Ls)',88$this->phids);89}9091if ($this->isDisabled !== null) {92$where[] = qsprintf(93$conn,94'source.isDisabled = %d',95(int)$this->isDisabled);96}9798if ($this->hasCursors !== null) {99$cursor_types = array();100101$definitions = NuanceSourceDefinition::getAllDefinitions();102foreach ($definitions as $key => $definition) {103if ($definition->hasImportCursors()) {104$cursor_types[] = $key;105}106}107108if ($this->hasCursors) {109if (!$cursor_types) {110throw new PhabricatorEmptyQueryException();111} else {112$where[] = qsprintf(113$conn,114'source.type IN (%Ls)',115$cursor_types);116}117} else {118if (!$cursor_types) {119// Apply no constraint.120} else {121$where[] = qsprintf(122$conn,123'source.type NOT IN (%Ls)',124$cursor_types);125}126}127}128129return $where;130}131132}133134135