Differential D10982 Diff 26376 src/applications/almanac/conduit/AlmanacQueryServicesConduitAPIMethod.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/conduit/AlmanacQueryServicesConduitAPIMethod.php
| Show All 25 Lines | final class AlmanacQueryServicesConduitAPIMethod | ||||
| public function defineErrorTypes() { | public function defineErrorTypes() { | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| protected function execute(ConduitAPIRequest $request) { | protected function execute(ConduitAPIRequest $request) { | ||||
| $viewer = $request->getUser(); | $viewer = $request->getUser(); | ||||
| $query = id(new AlmanacServiceQuery()) | $query = id(new AlmanacServiceQuery()) | ||||
| ->setViewer($viewer); | ->setViewer($viewer) | ||||
| ->needBindings(true); | |||||
| $ids = $request->getValue('ids'); | $ids = $request->getValue('ids'); | ||||
| if ($ids !== null) { | if ($ids !== null) { | ||||
| $query->withIDs($ids); | $query->withIDs($ids); | ||||
| } | } | ||||
| $phids = $request->getValue('phids'); | $phids = $request->getValue('phids'); | ||||
| if ($phids !== null) { | if ($phids !== null) { | ||||
| $query->withPHIDs($phids); | $query->withPHIDs($phids); | ||||
| } | } | ||||
| $names = $request->getValue('names'); | $names = $request->getValue('names'); | ||||
| if ($names !== null) { | if ($names !== null) { | ||||
| $query->withNames($names); | $query->withNames($names); | ||||
| } | } | ||||
| $pager = $this->newPager($request); | $pager = $this->newPager($request); | ||||
| $services = $query->executeWithCursorPager($pager); | $services = $query->executeWithCursorPager($pager); | ||||
| if ($services) { | |||||
| $bindings = id(new AlmanacBindingQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withServicePHIDs(mpull($services, 'getPHID')) | |||||
| ->execute(); | |||||
| $bindings = mgroup($bindings, 'getServicePHID'); | |||||
| } else { | |||||
| $bindings = array(); | |||||
| } | |||||
| $data = array(); | $data = array(); | ||||
| foreach ($services as $service) { | foreach ($services as $service) { | ||||
| $phid = $service->getPHID(); | $phid = $service->getPHID(); | ||||
| $properties = $service->getAlmanacProperties(); | $properties = $service->getAlmanacProperties(); | ||||
| $properties = mpull($properties, 'getFieldValue', 'getFieldName'); | $properties = mpull($properties, 'getFieldValue', 'getFieldName'); | ||||
| $service_bindings = idx($bindings, $phid, array()); | $service_bindings = $service->getBindings(); | ||||
| $service_bindings = array_values($service_bindings); | $service_bindings = array_values($service_bindings); | ||||
| foreach ($service_bindings as $key => $service_binding) { | foreach ($service_bindings as $key => $service_binding) { | ||||
| $service_bindings[$key] = $this->getBindingDictionary($service_binding); | $service_bindings[$key] = $this->getBindingDictionary($service_binding); | ||||
| } | } | ||||
| $data[] = $this->getServiceDictionary($service) + array( | $data[] = $this->getServiceDictionary($service) + array( | ||||
| 'bindings' => $service_bindings, | 'bindings' => $service_bindings, | ||||
| ); | ); | ||||
| ▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines | |||||