@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 195 lines 4.2 kB view raw
1<?php 2 3/** 4 * @extends NuanceQuery<NuanceItem> 5 */ 6final class NuanceItemQuery 7 extends NuanceQuery { 8 9 private $ids; 10 private $phids; 11 private $sourcePHIDs; 12 private $queuePHIDs; 13 private $itemTypes; 14 private $itemKeys; 15 private $containerKeys; 16 private $statuses; 17 18 public function withIDs(array $ids) { 19 $this->ids = $ids; 20 return $this; 21 } 22 23 public function withPHIDs(array $phids) { 24 $this->phids = $phids; 25 return $this; 26 } 27 28 public function withSourcePHIDs(array $source_phids) { 29 $this->sourcePHIDs = $source_phids; 30 return $this; 31 } 32 33 public function withQueuePHIDs(array $queue_phids) { 34 $this->queuePHIDs = $queue_phids; 35 return $this; 36 } 37 38 public function withItemTypes(array $item_types) { 39 $this->itemTypes = $item_types; 40 return $this; 41 } 42 43 public function withItemKeys(array $item_keys) { 44 $this->itemKeys = $item_keys; 45 return $this; 46 } 47 48 public function withStatuses(array $statuses) { 49 $this->statuses = $statuses; 50 return $this; 51 } 52 53 public function withItemContainerKeys(array $container_keys) { 54 $this->containerKeys = $container_keys; 55 return $this; 56 } 57 58 public function newResultObject() { 59 return new NuanceItem(); 60 } 61 62 protected function willFilterPage(array $items) { 63 $viewer = $this->getViewer(); 64 $source_phids = mpull($items, 'getSourcePHID'); 65 66 $sources = id(new NuanceSourceQuery()) 67 ->setViewer($viewer) 68 ->withPHIDs($source_phids) 69 ->execute(); 70 $sources = mpull($sources, null, 'getPHID'); 71 72 foreach ($items as $key => $item) { 73 $source = idx($sources, $item->getSourcePHID()); 74 if (!$source) { 75 $this->didRejectResult($items[$key]); 76 unset($items[$key]); 77 continue; 78 } 79 $item->attachSource($source); 80 } 81 82 $type_map = NuanceItemType::getAllItemTypes(); 83 foreach ($items as $key => $item) { 84 $type = idx($type_map, $item->getItemType()); 85 if (!$type) { 86 $this->didRejectResult($items[$key]); 87 unset($items[$key]); 88 continue; 89 } 90 $item->attachImplementation($type); 91 } 92 93 $queue_phids = array(); 94 foreach ($items as $item) { 95 $queue_phid = $item->getQueuePHID(); 96 if ($queue_phid) { 97 $queue_phids[$queue_phid] = $queue_phid; 98 } 99 } 100 101 if ($queue_phids) { 102 $queues = id(new NuanceQueueQuery()) 103 ->setViewer($viewer) 104 ->withPHIDs($queue_phids) 105 ->execute(); 106 $queues = mpull($queues, null, 'getPHID'); 107 } else { 108 $queues = array(); 109 } 110 111 foreach ($items as $key => $item) { 112 $queue_phid = $item->getQueuePHID(); 113 114 if (!$queue_phid) { 115 $item->attachQueue(null); 116 continue; 117 } 118 119 $queue = idx($queues, $queue_phid); 120 121 if (!$queue) { 122 unset($items[$key]); 123 $this->didRejectResult($item); 124 continue; 125 } 126 127 $item->attachQueue($queue); 128 } 129 130 return $items; 131 } 132 133 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 134 $where = parent::buildWhereClauseParts($conn); 135 136 if ($this->sourcePHIDs !== null) { 137 $where[] = qsprintf( 138 $conn, 139 'sourcePHID IN (%Ls)', 140 $this->sourcePHIDs); 141 } 142 143 if ($this->queuePHIDs !== null) { 144 $where[] = qsprintf( 145 $conn, 146 'queuePHID IN (%Ls)', 147 $this->queuePHIDs); 148 } 149 150 if ($this->ids !== null) { 151 $where[] = qsprintf( 152 $conn, 153 'id IN (%Ld)', 154 $this->ids); 155 } 156 157 if ($this->phids !== null) { 158 $where[] = qsprintf( 159 $conn, 160 'phid IN (%Ls)', 161 $this->phids); 162 } 163 164 if ($this->statuses !== null) { 165 $where[] = qsprintf( 166 $conn, 167 'status IN (%Ls)', 168 $this->statuses); 169 } 170 171 if ($this->itemTypes !== null) { 172 $where[] = qsprintf( 173 $conn, 174 'itemType IN (%Ls)', 175 $this->itemTypes); 176 } 177 178 if ($this->itemKeys !== null) { 179 $where[] = qsprintf( 180 $conn, 181 'itemKey IN (%Ls)', 182 $this->itemKeys); 183 } 184 185 if ($this->containerKeys !== null) { 186 $where[] = qsprintf( 187 $conn, 188 'itemContainerKey IN (%Ls)', 189 $this->containerKeys); 190 } 191 192 return $where; 193 } 194 195}