Changeset View
Changeset View
Standalone View
Standalone View
src/applications/nuance/query/NuanceItemQuery.php
| <?php | <?php | ||||
| final class NuanceItemQuery | final class NuanceItemQuery | ||||
| extends NuanceQuery { | extends NuanceQuery { | ||||
| private $ids; | private $ids; | ||||
| private $phids; | private $phids; | ||||
| private $sourcePHIDs; | private $sourcePHIDs; | ||||
| private $queuePHIDs; | |||||
| private $itemTypes; | private $itemTypes; | ||||
| private $itemKeys; | private $itemKeys; | ||||
| private $containerKeys; | private $containerKeys; | ||||
| private $statuses; | |||||
| public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
| $this->ids = $ids; | $this->ids = $ids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
| $this->phids = $phids; | $this->phids = $phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withSourcePHIDs(array $source_phids) { | public function withSourcePHIDs(array $source_phids) { | ||||
| $this->sourcePHIDs = $source_phids; | $this->sourcePHIDs = $source_phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withQueuePHIDs(array $queue_phids) { | |||||
| $this->queuePHIDs = $queue_phids; | |||||
| return $this; | |||||
| } | |||||
| public function withItemTypes(array $item_types) { | public function withItemTypes(array $item_types) { | ||||
| $this->itemTypes = $item_types; | $this->itemTypes = $item_types; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withItemKeys(array $item_keys) { | public function withItemKeys(array $item_keys) { | ||||
| $this->itemKeys = $item_keys; | $this->itemKeys = $item_keys; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withStatuses(array $statuses) { | |||||
| $this->statuses = $statuses; | |||||
| return $this; | |||||
| } | |||||
| public function withItemContainerKeys(array $container_keys) { | public function withItemContainerKeys(array $container_keys) { | ||||
| $this->containerKeys = $container_keys; | $this->containerKeys = $container_keys; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function newResultObject() { | public function newResultObject() { | ||||
| return new NuanceItem(); | return new NuanceItem(); | ||||
| } | } | ||||
| protected function loadPage() { | protected function loadPage() { | ||||
| return $this->loadStandardPage($this->newResultObject()); | return $this->loadStandardPage($this->newResultObject()); | ||||
| } | } | ||||
| protected function willFilterPage(array $items) { | protected function willFilterPage(array $items) { | ||||
| $viewer = $this->getViewer(); | |||||
| $source_phids = mpull($items, 'getSourcePHID'); | $source_phids = mpull($items, 'getSourcePHID'); | ||||
| // NOTE: We always load sources, even if the viewer can't formally see | |||||
| // them. If they can see the item, they're allowed to be aware of the | |||||
| // source in some sense. | |||||
| $sources = id(new NuanceSourceQuery()) | $sources = id(new NuanceSourceQuery()) | ||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer($viewer) | ||||
epriestley: I've removed this weird rule for now in hope that we won't need it, since there's no clear… | |||||
| ->withPHIDs($source_phids) | ->withPHIDs($source_phids) | ||||
| ->execute(); | ->execute(); | ||||
| $sources = mpull($sources, null, 'getPHID'); | $sources = mpull($sources, null, 'getPHID'); | ||||
| foreach ($items as $key => $item) { | foreach ($items as $key => $item) { | ||||
| $source = idx($sources, $item->getSourcePHID()); | $source = idx($sources, $item->getSourcePHID()); | ||||
| if (!$source) { | if (!$source) { | ||||
| $this->didRejectResult($items[$key]); | $this->didRejectResult($items[$key]); | ||||
| Show All 9 Lines | foreach ($items as $key => $item) { | ||||
| if (!$type) { | if (!$type) { | ||||
| $this->didRejectResult($items[$key]); | $this->didRejectResult($items[$key]); | ||||
| unset($items[$key]); | unset($items[$key]); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $item->attachImplementation($type); | $item->attachImplementation($type); | ||||
| } | } | ||||
| $queue_phids = array(); | |||||
| foreach ($items as $item) { | |||||
| $queue_phid = $item->getQueuePHID(); | |||||
| if ($queue_phid) { | |||||
| $queue_phids[$queue_phid] = $queue_phid; | |||||
| } | |||||
| } | |||||
| if ($queue_phids) { | |||||
| $queues = id(new NuanceQueueQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withPHIDs($queue_phids) | |||||
| ->execute(); | |||||
| $queues = mpull($queues, null, 'getPHID'); | |||||
| } else { | |||||
| $queues = array(); | |||||
| } | |||||
| foreach ($items as $key => $item) { | |||||
| $queue_phid = $item->getQueuePHID(); | |||||
| if (!$queue_phid) { | |||||
| $item->attachQueue(null); | |||||
| continue; | |||||
| } | |||||
| $queue = idx($queues, $queue_phid); | |||||
| if (!$queue) { | |||||
| unset($items[$key]); | |||||
| $this->didRejectResult($item); | |||||
| continue; | |||||
| } | |||||
| $item->attachQueue($queue); | |||||
| } | |||||
| return $items; | return $items; | ||||
| } | } | ||||
| protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $where = parent::buildWhereClauseParts($conn); | $where = parent::buildWhereClauseParts($conn); | ||||
| if ($this->sourcePHIDs !== null) { | if ($this->sourcePHIDs !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'sourcePHID IN (%Ls)', | 'sourcePHID IN (%Ls)', | ||||
| $this->sourcePHIDs); | $this->sourcePHIDs); | ||||
| } | } | ||||
| if ($this->queuePHIDs !== null) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'queuePHID IN (%Ls)', | |||||
| $this->queuePHIDs); | |||||
| } | |||||
| if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'id IN (%Ld)', | 'id IN (%Ld)', | ||||
| $this->ids); | $this->ids); | ||||
| } | } | ||||
| if ($this->phids !== null) { | if ($this->phids !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'phid IN (%Ls)', | 'phid IN (%Ls)', | ||||
| $this->phids); | $this->phids); | ||||
| } | } | ||||
| if ($this->statuses !== null) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'status IN (%Ls)', | |||||
| $this->statuses); | |||||
| } | |||||
| if ($this->itemTypes !== null) { | if ($this->itemTypes !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'itemType IN (%Ls)', | 'itemType IN (%Ls)', | ||||
| $this->itemTypes); | $this->itemTypes); | ||||
| } | } | ||||
| if ($this->itemKeys !== null) { | if ($this->itemKeys !== null) { | ||||
| Show All 17 Lines | |||||
I've removed this weird rule for now in hope that we won't need it, since there's no clear reason that we have to have it right now and less weird rules = more better.