1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-15 19:32:40 +01:00
phorge-phorge/src/applications/search/controller/PhabricatorSearchHovercardController.php
epriestley bdc517485c Modernize Hovercard implementation
Summary:
Ref T8980. Move away from events to EngineExtensions.

This also simplifies hovercards a bit:

  - Removes tasks from revision cards.
  - Removes blockers/blocked from task cards.
  - Removes "Send Message" from user cards.

These mostly felt cluttery to me. Open to arguments to retain them. I think we can make better use of the space, though (e.g., flags, projects + board columns).

Test Plan:
  - Viewed people, task, revision, commit and project hovercards.

{F1043256}

{F1043257}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T8980

Differential Revision: https://secure.phabricator.com/D14878
2015-12-24 12:18:28 -08:00

100 lines
2.4 KiB
PHP

<?php
final class PhabricatorSearchHovercardController
extends PhabricatorSearchBaseController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$phids = $request->getArr('phids');
$handles = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs($phids)
->execute();
$objects = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs($phids)
->execute();
$objects = mpull($objects, null, 'getPHID');
$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;
}
$extension_data[$key] = $extension->willRenderHovercards(
array_select_keys($objects, $extension_phids));
}
$cards = array();
foreach ($phids as $phid) {
$handle = $handles[$phid];
$object = $objects[$phid];
$hovercard = id(new PhabricatorHovercardView())
->setUser($viewer)
->setObjectHandle($handle);
if ($object) {
$hovercard->setObject($object);
foreach ($extension_maps as $key => $extension_phids) {
if (isset($extension_phids[$phid])) {
$extensions[$key]->renderHovercard(
$hovercard,
$handle,
$object,
$extension_data[$key]);
}
}
}
$cards[$phid] = $hovercard;
}
if ($request->isAjax()) {
return id(new AphrontAjaxResponse())->setContent(
array(
'cards' => $cards,
));
}
foreach ($cards as $key => $hovercard) {
$cards[$key] = phutil_tag('div',
array(
'class' => 'ml',
),
$hovercard);
}
return $this->newPage()
->appendChild($cards)
->setShowFooter(false);
}
}