3 final class AlmanacInterfaceQuery
12 public function withIDs(array $ids) {
17 public function withPHIDs(array $phids) {
18 $this->phids
= $phids;
22 public function withNetworkPHIDs(array $phids) {
23 $this->networkPHIDs
= $phids;
27 public function withDevicePHIDs(array $phids) {
28 $this->devicePHIDs
= $phids;
32 public function withAddresses(array $addresses) {
33 $this->addresses
= $addresses;
37 public function newResultObject() {
38 return new AlmanacInterface();
41 protected function loadPage() {
42 return $this->loadStandardPage($this->newResultObject());
45 protected function willFilterPage(array $interfaces) {
46 $network_phids = mpull($interfaces, 'getNetworkPHID');
47 $device_phids = mpull($interfaces, 'getDevicePHID');
49 $networks = id(new AlmanacNetworkQuery())
50 ->setParentQuery($this)
51 ->setViewer($this->getViewer())
52 ->withPHIDs($network_phids)
53 ->needProperties($this->getNeedProperties())
55 $networks = mpull($networks, null, 'getPHID');
57 $devices = id(new AlmanacDeviceQuery())
58 ->setParentQuery($this)
59 ->setViewer($this->getViewer())
60 ->withPHIDs($device_phids)
61 ->needProperties($this->getNeedProperties())
63 $devices = mpull($devices, null, 'getPHID');
65 foreach ($interfaces as $key => $interface) {
66 $network = idx($networks, $interface->getNetworkPHID());
67 $device = idx($devices, $interface->getDevicePHID());
68 if (!$network ||
!$device) {
69 $this->didRejectResult($interface);
70 unset($interfaces[$key]);
74 $interface->attachNetwork($network);
75 $interface->attachDevice($device);
81 protected function buildSelectClauseParts(AphrontDatabaseConnection
$conn) {
82 $select = parent
::buildSelectClauseParts($conn);
84 if ($this->shouldJoinDeviceTable()) {
85 $select[] = qsprintf($conn, 'device.name');
91 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
92 $where = parent
::buildWhereClauseParts($conn);
94 if ($this->ids
!== null) {
97 'interface.id IN (%Ld)',
101 if ($this->phids
!== null) {
104 'interface.phid IN (%Ls)',
108 if ($this->networkPHIDs
!== null) {
111 'interface.networkPHID IN (%Ls)',
112 $this->networkPHIDs
);
115 if ($this->devicePHIDs
!== null) {
118 'interface.devicePHID IN (%Ls)',
122 if ($this->addresses
!== null) {
124 foreach ($this->addresses
as $address) {
127 '(interface.networkPHID = %s '.
128 'AND interface.address = %s '.
129 'AND interface.port = %d)',
130 $address->getNetworkPHID(),
131 $address->getAddress(),
132 $address->getPort());
134 $where[] = qsprintf($conn, '%LO', $parts);
140 protected function buildJoinClauseParts(AphrontDatabaseConnection
$conn) {
141 $joins = parent
::buildJoinClauseParts($conn);
143 if ($this->shouldJoinDeviceTable()) {
146 'JOIN %T device ON device.phid = interface.devicePHID',
147 id(new AlmanacDevice())->getTableName());
153 protected function shouldGroupQueryResultRows() {
154 if ($this->shouldJoinDeviceTable()) {
158 return parent
::shouldGroupQueryResultRows();
161 private function shouldJoinDeviceTable() {
162 $vector = $this->getOrderVector();
164 if ($vector->containsKey('name')) {
171 protected function getPrimaryTableAlias() {
175 public function getQueryApplicationClass() {
176 return 'PhabricatorAlmanacApplication';
179 public function getBuiltinOrders() {
182 'vector' => array('name', 'id'),
183 'name' => pht('Device Name'),
185 ) + parent
::getBuiltinOrders();
188 public function getOrderableColumns() {
189 return parent
::getOrderableColumns() +
array(
199 protected function newPagingMapFromCursorObject(
200 PhabricatorQueryCursor
$cursor,
203 $interface = $cursor->getObject();
206 'id' => (int)$interface->getID(),
207 'name' => $cursor->getRawRowProperty('device.name'),