Changeset View
Changeset View
Standalone View
Standalone View
src/applications/nuance/query/NuanceSourceQuery.php
| Show All 28 Lines | public function withIsDisabled($disabled) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withHasImportCursors($has_cursors) { | public function withHasImportCursors($has_cursors) { | ||||
| $this->hasCursors = $has_cursors; | $this->hasCursors = $has_cursors; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withNameNgrams($ngrams) { | |||||
| return $this->withNgramsConstraint( | |||||
| new NuanceSourceNameNgrams(), | |||||
| $ngrams); | |||||
| } | |||||
| public function newResultObject() { | public function newResultObject() { | ||||
| return new NuanceSource(); | return new NuanceSource(); | ||||
| } | } | ||||
| protected function getPrimaryTableAlias() { | |||||
| return 'source'; | |||||
| } | |||||
| protected function loadPage() { | protected function loadPage() { | ||||
| return $this->loadStandardPage($this->newResultObject()); | return $this->loadStandardPage($this->newResultObject()); | ||||
| } | } | ||||
| protected function willFilterPage(array $sources) { | protected function willFilterPage(array $sources) { | ||||
| $all_types = NuanceSourceDefinition::getAllDefinitions(); | $all_types = NuanceSourceDefinition::getAllDefinitions(); | ||||
| foreach ($sources as $key => $source) { | foreach ($sources as $key => $source) { | ||||
| Show All 11 Lines | final class NuanceSourceQuery | ||||
| protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $where = parent::buildWhereClauseParts($conn); | $where = parent::buildWhereClauseParts($conn); | ||||
| if ($this->types !== null) { | if ($this->types !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'type IN (%Ls)', | 'source.type IN (%Ls)', | ||||
| $this->types); | $this->types); | ||||
| } | } | ||||
| if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'id IN (%Ld)', | 'source.id IN (%Ld)', | ||||
| $this->ids); | $this->ids); | ||||
| } | } | ||||
| if ($this->phids !== null) { | if ($this->phids !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'phid IN (%Ls)', | 'source.phid IN (%Ls)', | ||||
| $this->phids); | $this->phids); | ||||
| } | } | ||||
| if ($this->isDisabled !== null) { | if ($this->isDisabled !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'isDisabled = %d', | 'source.isDisabled = %d', | ||||
| (int)$this->isDisabled); | (int)$this->isDisabled); | ||||
| } | } | ||||
| if ($this->hasCursors !== null) { | if ($this->hasCursors !== null) { | ||||
| $cursor_types = array(); | $cursor_types = array(); | ||||
| $definitions = NuanceSourceDefinition::getAllDefinitions(); | $definitions = NuanceSourceDefinition::getAllDefinitions(); | ||||
| foreach ($definitions as $key => $definition) { | foreach ($definitions as $key => $definition) { | ||||
| if ($definition->hasImportCursors()) { | if ($definition->hasImportCursors()) { | ||||
| $cursor_types[] = $key; | $cursor_types[] = $key; | ||||
| } | } | ||||
| } | } | ||||
| if ($this->hasCursors) { | if ($this->hasCursors) { | ||||
| if (!$cursor_types) { | if (!$cursor_types) { | ||||
| throw new PhabricatorEmptyQueryException(); | throw new PhabricatorEmptyQueryException(); | ||||
| } else { | } else { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'type IN (%Ls)', | 'source.type IN (%Ls)', | ||||
| $cursor_types); | $cursor_types); | ||||
| } | } | ||||
| } else { | } else { | ||||
| if (!$cursor_types) { | if (!$cursor_types) { | ||||
| // Apply no constraint. | // Apply no constraint. | ||||
| } else { | } else { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'type NOT IN (%Ls)', | 'source.type NOT IN (%Ls)', | ||||
| $cursor_types); | $cursor_types); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return $where; | return $where; | ||||
| } | } | ||||
| } | } | ||||