Path: blob/master/src/applications/nuance/query/NuanceItemQuery.php
12256 views
<?php12final class NuanceItemQuery3extends NuanceQuery {45private $ids;6private $phids;7private $sourcePHIDs;8private $queuePHIDs;9private $itemTypes;10private $itemKeys;11private $containerKeys;12private $statuses;1314public function withIDs(array $ids) {15$this->ids = $ids;16return $this;17}1819public function withPHIDs(array $phids) {20$this->phids = $phids;21return $this;22}2324public function withSourcePHIDs(array $source_phids) {25$this->sourcePHIDs = $source_phids;26return $this;27}2829public function withQueuePHIDs(array $queue_phids) {30$this->queuePHIDs = $queue_phids;31return $this;32}3334public function withItemTypes(array $item_types) {35$this->itemTypes = $item_types;36return $this;37}3839public function withItemKeys(array $item_keys) {40$this->itemKeys = $item_keys;41return $this;42}4344public function withStatuses(array $statuses) {45$this->statuses = $statuses;46return $this;47}4849public function withItemContainerKeys(array $container_keys) {50$this->containerKeys = $container_keys;51return $this;52}5354public function newResultObject() {55return new NuanceItem();56}5758protected function willFilterPage(array $items) {59$viewer = $this->getViewer();60$source_phids = mpull($items, 'getSourcePHID');6162$sources = id(new NuanceSourceQuery())63->setViewer($viewer)64->withPHIDs($source_phids)65->execute();66$sources = mpull($sources, null, 'getPHID');6768foreach ($items as $key => $item) {69$source = idx($sources, $item->getSourcePHID());70if (!$source) {71$this->didRejectResult($items[$key]);72unset($items[$key]);73continue;74}75$item->attachSource($source);76}7778$type_map = NuanceItemType::getAllItemTypes();79foreach ($items as $key => $item) {80$type = idx($type_map, $item->getItemType());81if (!$type) {82$this->didRejectResult($items[$key]);83unset($items[$key]);84continue;85}86$item->attachImplementation($type);87}8889$queue_phids = array();90foreach ($items as $item) {91$queue_phid = $item->getQueuePHID();92if ($queue_phid) {93$queue_phids[$queue_phid] = $queue_phid;94}95}9697if ($queue_phids) {98$queues = id(new NuanceQueueQuery())99->setViewer($viewer)100->withPHIDs($queue_phids)101->execute();102$queues = mpull($queues, null, 'getPHID');103} else {104$queues = array();105}106107foreach ($items as $key => $item) {108$queue_phid = $item->getQueuePHID();109110if (!$queue_phid) {111$item->attachQueue(null);112continue;113}114115$queue = idx($queues, $queue_phid);116117if (!$queue) {118unset($items[$key]);119$this->didRejectResult($item);120continue;121}122123$item->attachQueue($queue);124}125126return $items;127}128129protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {130$where = parent::buildWhereClauseParts($conn);131132if ($this->sourcePHIDs !== null) {133$where[] = qsprintf(134$conn,135'sourcePHID IN (%Ls)',136$this->sourcePHIDs);137}138139if ($this->queuePHIDs !== null) {140$where[] = qsprintf(141$conn,142'queuePHID IN (%Ls)',143$this->queuePHIDs);144}145146if ($this->ids !== null) {147$where[] = qsprintf(148$conn,149'id IN (%Ld)',150$this->ids);151}152153if ($this->phids !== null) {154$where[] = qsprintf(155$conn,156'phid IN (%Ls)',157$this->phids);158}159160if ($this->statuses !== null) {161$where[] = qsprintf(162$conn,163'status IN (%Ls)',164$this->statuses);165}166167if ($this->itemTypes !== null) {168$where[] = qsprintf(169$conn,170'itemType IN (%Ls)',171$this->itemTypes);172}173174if ($this->itemKeys !== null) {175$where[] = qsprintf(176$conn,177'itemKey IN (%Ls)',178$this->itemKeys);179}180181if ($this->containerKeys !== null) {182$where[] = qsprintf(183$conn,184'itemContainerKey IN (%Ls)',185$this->containerKeys);186}187188return $where;189}190191}192193194