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 willFilterPage(array $interfaces) {
42 $network_phids = mpull($interfaces, 'getNetworkPHID');
43 $device_phids = mpull($interfaces, 'getDevicePHID');
45 $networks = id(new AlmanacNetworkQuery())
46 ->setParentQuery($this)
47 ->setViewer($this->getViewer())
48 ->withPHIDs($network_phids)
49 ->needProperties($this->getNeedProperties())
51 $networks = mpull($networks, null, 'getPHID');
53 $devices = id(new AlmanacDeviceQuery())
54 ->setParentQuery($this)
55 ->setViewer($this->getViewer())
56 ->withPHIDs($device_phids)
57 ->needProperties($this->getNeedProperties())
59 $devices = mpull($devices, null, 'getPHID');
61 foreach ($interfaces as $key => $interface) {
62 $network = idx($networks, $interface->getNetworkPHID());
63 $device = idx($devices, $interface->getDevicePHID());
64 if (!$network ||
!$device) {
65 $this->didRejectResult($interface);
66 unset($interfaces[$key]);
70 $interface->attachNetwork($network);
71 $interface->attachDevice($device);
77 protected function buildSelectClauseParts(AphrontDatabaseConnection
$conn) {
78 $select = parent
::buildSelectClauseParts($conn);
80 if ($this->shouldJoinDeviceTable()) {
81 $select[] = qsprintf($conn, 'device.name');
87 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
88 $where = parent
::buildWhereClauseParts($conn);
90 if ($this->ids
!== null) {
93 'interface.id IN (%Ld)',
97 if ($this->phids
!== null) {
100 'interface.phid IN (%Ls)',
104 if ($this->networkPHIDs
!== null) {
107 'interface.networkPHID IN (%Ls)',
108 $this->networkPHIDs
);
111 if ($this->devicePHIDs
!== null) {
114 'interface.devicePHID IN (%Ls)',
118 if ($this->addresses
!== null) {
120 foreach ($this->addresses
as $address) {
123 '(interface.networkPHID = %s '.
124 'AND interface.address = %s '.
125 'AND interface.port = %d)',
126 $address->getNetworkPHID(),
127 $address->getAddress(),
128 $address->getPort());
130 $where[] = qsprintf($conn, '%LO', $parts);
136 protected function buildJoinClauseParts(AphrontDatabaseConnection
$conn) {
137 $joins = parent
::buildJoinClauseParts($conn);
139 if ($this->shouldJoinDeviceTable()) {
142 'JOIN %T device ON device.phid = interface.devicePHID',
143 id(new AlmanacDevice())->getTableName());
149 protected function shouldGroupQueryResultRows() {
150 if ($this->shouldJoinDeviceTable()) {
154 return parent
::shouldGroupQueryResultRows();
157 private function shouldJoinDeviceTable() {
158 $vector = $this->getOrderVector();
160 if ($vector->containsKey('name')) {
167 protected function getPrimaryTableAlias() {
171 public function getQueryApplicationClass() {
172 return 'PhabricatorAlmanacApplication';
175 public function getBuiltinOrders() {
178 'vector' => array('name', 'id'),
179 'name' => pht('Device Name'),
181 ) + parent
::getBuiltinOrders();
184 public function getOrderableColumns() {
185 return parent
::getOrderableColumns() +
array(
195 protected function newPagingMapFromCursorObject(
196 PhabricatorQueryCursor
$cursor,
199 $interface = $cursor->getObject();
202 'id' => (int)$interface->getID(),
203 'name' => $cursor->getRawRowProperty('device.name'),