Differential D21554 Diff 51306 src/applications/search/controller/PhabricatorSearchHovercardController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/controller/PhabricatorSearchHovercardController.php
| Show All 26 Lines | if ($names) { | ||||
| $cards[] = array( | $cards[] = array( | ||||
| 'objectPHID' => $object->getPHID(), | 'objectPHID' => $object->getPHID(), | ||||
| ); | ); | ||||
| } | } | ||||
| } | } | ||||
| $object_phids = array(); | $object_phids = array(); | ||||
| $handle_phids = array(); | $handle_phids = array(); | ||||
| $context_phids = array(); | |||||
| foreach ($cards as $card) { | foreach ($cards as $card) { | ||||
| $object_phid = idx($card, 'objectPHID'); | $object_phid = idx($card, 'objectPHID'); | ||||
| $handle_phids[] = $object_phid; | $handle_phids[] = $object_phid; | ||||
| $object_phids[] = $object_phid; | $object_phids[] = $object_phid; | ||||
| $context_phid = idx($card, 'contextPHID'); | |||||
| if ($context_phid) { | |||||
| $object_phids[] = $context_phid; | |||||
| $context_phids[] = $context_phid; | |||||
| } | |||||
| } | } | ||||
| $handles = id(new PhabricatorHandleQuery()) | $handles = id(new PhabricatorHandleQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withPHIDs($handle_phids) | ->withPHIDs($handle_phids) | ||||
| ->execute(); | ->execute(); | ||||
| $objects = id(new PhabricatorObjectQuery()) | $objects = id(new PhabricatorObjectQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withPHIDs($object_phids) | ->withPHIDs($object_phids) | ||||
| ->execute(); | ->execute(); | ||||
| $objects = mpull($objects, null, 'getPHID'); | $objects = mpull($objects, null, 'getPHID'); | ||||
| $context_objects = array_select_keys($objects, $context_phids); | |||||
| if ($context_objects) { | |||||
| PhabricatorPolicyFilterSet::loadHandleViewCapabilities( | |||||
| $viewer, | |||||
| $handles, | |||||
| $context_objects); | |||||
| } | |||||
| $extensions = | $extensions = | ||||
| PhabricatorHovercardEngineExtension::getAllEnabledExtensions(); | PhabricatorHovercardEngineExtension::getAllEnabledExtensions(); | ||||
| $extension_maps = array(); | $extension_maps = array(); | ||||
| foreach ($extensions as $key => $extension) { | foreach ($extensions as $extension_key => $extension) { | ||||
| $extension->setViewer($viewer); | $extension->setViewer($viewer); | ||||
| $extension_phids = array(); | $extension_phids = array(); | ||||
| foreach ($objects as $phid => $object) { | foreach ($objects as $phid => $object) { | ||||
| if ($extension->canRenderObjectHovercard($object)) { | if ($extension->canRenderObjectHovercard($object)) { | ||||
| $extension_phids[$phid] = $phid; | $extension_phids[$phid] = $phid; | ||||
| } | } | ||||
| } | } | ||||
| $extension_maps[$key] = $extension_phids; | $extension_maps[$extension_key] = $extension_phids; | ||||
| } | } | ||||
| $extension_data = array(); | $extension_data = array(); | ||||
| foreach ($extensions as $key => $extension) { | foreach ($extensions as $extension_key => $extension) { | ||||
| $extension_phids = $extension_maps[$key]; | $extension_phids = $extension_maps[$extension_key]; | ||||
| if (!$extension_phids) { | if (!$extension_phids) { | ||||
| unset($extensions[$key]); | unset($extensions[$extension_key]); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $extension_data[$key] = $extension->willRenderHovercards( | $extension_data[$extension_key] = $extension->willRenderHovercards( | ||||
| array_select_keys($objects, $extension_phids)); | array_select_keys($objects, $extension_phids)); | ||||
| } | } | ||||
| $results = array(); | $results = array(); | ||||
| foreach ($cards as $card_key => $card) { | foreach ($cards as $card_key => $card) { | ||||
| $object_phid = $card['objectPHID']; | $object_phid = $card['objectPHID']; | ||||
| $handle = $handles[$object_phid]; | $handle = $handles[$object_phid]; | ||||
| $object = idx($objects, $object_phid); | $object = idx($objects, $object_phid); | ||||
| $context_phid = idx($card, 'contextPHID'); | |||||
| if ($context_phid) { | |||||
| $context_object = idx($context_objects, $context_phid); | |||||
| } else { | |||||
| $context_object = null; | |||||
| } | |||||
| $hovercard = id(new PHUIHovercardView()) | $hovercard = id(new PHUIHovercardView()) | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setObjectHandle($handle); | ->setObjectHandle($handle); | ||||
| if ($context_object) { | |||||
| if ($handle->hasCapabilities()) { | |||||
| if (!$handle->hasViewCapability($context_object)) { | |||||
| $hovercard->setIsExiled(true); | |||||
| } | |||||
| } | |||||
| } | |||||
| if ($object) { | if ($object) { | ||||
| $hovercard->setObject($object); | $hovercard->setObject($object); | ||||
| foreach ($extension_maps as $key => $extension_phids) { | foreach ($extension_maps as $extension_key => $extension_phids) { | ||||
| if (isset($extension_phids[$phid])) { | if (isset($extension_phids[$object_phid])) { | ||||
| $extensions[$key]->renderHovercard( | $extensions[$extension_key]->renderHovercard( | ||||
| $hovercard, | $hovercard, | ||||
| $handle, | $handle, | ||||
| $object, | $object, | ||||
| $extension_data[$key]); | $extension_data[$extension_key]); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| $results[$card_key] = $hovercard; | $results[$card_key] = $hovercard; | ||||
| } | } | ||||
| if ($request->isAjax()) { | if ($request->isAjax()) { | ||||
| return id(new AphrontAjaxResponse())->setContent( | return id(new AphrontAjaxResponse())->setContent( | ||||
| array( | array( | ||||
| 'cards' => $results, | 'cards' => $results, | ||||
| )); | )); | ||||
| } | } | ||||
| foreach ($results as $key => $hovercard) { | foreach ($results as $result_key => $hovercard) { | ||||
| $results[$key] = phutil_tag('div', | $results[$result_key] = phutil_tag('div', | ||||
| array( | array( | ||||
| 'class' => 'ml', | 'class' => 'ml', | ||||
| ), | ), | ||||
| $hovercard); | $hovercard); | ||||
| } | } | ||||
| return $this->newPage() | return $this->newPage() | ||||
| ->appendChild($results) | ->appendChild($results) | ||||
| ->setShowFooter(false); | ->setShowFooter(false); | ||||
| } | } | ||||
| } | } | ||||