2013-04-03 17:31:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorSearchHovercardController
|
|
|
|
extends PhabricatorSearchBaseController {
|
|
|
|
|
2014-10-17 02:40:12 +02:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-05 23:20:25 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
2013-04-03 17:31:27 +02:00
|
|
|
$phids = $request->getArr('phids');
|
|
|
|
|
2013-09-11 21:27:28 +02:00
|
|
|
$handles = id(new PhabricatorHandleQuery())
|
2015-06-05 23:20:25 +02:00
|
|
|
->setViewer($viewer)
|
2013-09-11 21:27:28 +02:00
|
|
|
->withPHIDs($phids)
|
|
|
|
->execute();
|
2015-12-24 20:20:18 +01:00
|
|
|
|
2013-09-11 21:27:28 +02:00
|
|
|
$objects = id(new PhabricatorObjectQuery())
|
2015-06-05 23:20:25 +02:00
|
|
|
->setViewer($viewer)
|
2013-09-11 21:27:28 +02:00
|
|
|
->withPHIDs($phids)
|
|
|
|
->execute();
|
2015-12-24 20:20:18 +01:00
|
|
|
$objects = mpull($objects, null, 'getPHID');
|
2013-04-03 17:31:27 +02:00
|
|
|
|
2015-12-24 20:20:18 +01:00
|
|
|
$extensions =
|
|
|
|
PhabricatorHovercardEngineExtension::getAllEnabledExtensions();
|
|
|
|
|
|
|
|
$extension_maps = array();
|
|
|
|
foreach ($extensions as $key => $extension) {
|
|
|
|
$extension->setViewer($viewer);
|
|
|
|
|
|
|
|
$extension_phids = array();
|
|
|
|
foreach ($objects as $phid => $object) {
|
|
|
|
if ($extension->canRenderObjectHovercard($object)) {
|
|
|
|
$extension_phids[$phid] = $phid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$extension_maps[$key] = $extension_phids;
|
|
|
|
}
|
|
|
|
|
|
|
|
$extension_data = array();
|
|
|
|
foreach ($extensions as $key => $extension) {
|
|
|
|
$extension_phids = $extension_maps[$key];
|
|
|
|
if (!$extension_phids) {
|
|
|
|
unset($extensions[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
2013-04-03 17:31:27 +02:00
|
|
|
|
2015-12-24 20:20:18 +01:00
|
|
|
$extension_data[$key] = $extension->willRenderHovercards(
|
|
|
|
array_select_keys($objects, $extension_phids));
|
|
|
|
}
|
|
|
|
|
|
|
|
$cards = array();
|
2013-04-03 17:31:27 +02:00
|
|
|
foreach ($phids as $phid) {
|
|
|
|
$handle = $handles[$phid];
|
2015-06-05 23:20:25 +02:00
|
|
|
$object = $objects[$phid];
|
2013-04-03 17:31:27 +02:00
|
|
|
|
2015-06-05 23:20:25 +02:00
|
|
|
$hovercard = id(new PhabricatorHovercardView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObjectHandle($handle);
|
|
|
|
|
|
|
|
if ($object) {
|
|
|
|
$hovercard->setObject($object);
|
2013-04-03 17:31:27 +02:00
|
|
|
|
2015-12-24 20:20:18 +01:00
|
|
|
foreach ($extension_maps as $key => $extension_phids) {
|
|
|
|
if (isset($extension_phids[$phid])) {
|
|
|
|
$extensions[$key]->renderHovercard(
|
|
|
|
$hovercard,
|
|
|
|
$handle,
|
|
|
|
$object,
|
|
|
|
$extension_data[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-03 17:31:27 +02:00
|
|
|
|
|
|
|
$cards[$phid] = $hovercard;
|
|
|
|
}
|
|
|
|
|
2015-12-24 20:20:18 +01:00
|
|
|
if ($request->isAjax()) {
|
2013-04-03 23:20:39 +02:00
|
|
|
return id(new AphrontAjaxResponse())->setContent(
|
|
|
|
array(
|
|
|
|
'cards' => $cards,
|
|
|
|
));
|
2013-04-03 17:31:27 +02:00
|
|
|
}
|
2015-12-24 20:20:18 +01:00
|
|
|
|
|
|
|
foreach ($cards as $key => $hovercard) {
|
|
|
|
$cards[$key] = phutil_tag('div',
|
|
|
|
array(
|
|
|
|
'class' => 'ml',
|
|
|
|
),
|
|
|
|
$hovercard);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->newPage()
|
|
|
|
->appendChild($cards)
|
|
|
|
->setShowFooter(false);
|
2013-04-03 17:31:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|