Changeset View
Changeset View
Standalone View
Standalone View
src/applications/macro/controller/PhabricatorMacroListController.php
<?php | <?php | ||||
final class PhabricatorMacroListController extends PhabricatorMacroController | final class PhabricatorMacroListController extends PhabricatorMacroController { | ||||
implements PhabricatorApplicationSearchResultsControllerInterface { | |||||
private $key; | private $key; | ||||
public function shouldAllowPublic() { | public function shouldAllowPublic() { | ||||
return true; | return true; | ||||
} | } | ||||
public function willProcessRequest(array $data) { | public function willProcessRequest(array $data) { | ||||
$this->key = idx($data, 'key'); | $this->key = idx($data, 'key'); | ||||
} | } | ||||
public function processRequest() { | public function processRequest() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$controller = id(new PhabricatorApplicationSearchController($request)) | $controller = id(new PhabricatorApplicationSearchController($request)) | ||||
->setQueryKey($this->key) | ->setQueryKey($this->key) | ||||
->setSearchEngine(new PhabricatorMacroSearchEngine()) | ->setSearchEngine(new PhabricatorMacroSearchEngine()) | ||||
->setNavigation($this->buildSideNavView()); | ->setNavigation($this->buildSideNavView()); | ||||
return $this->delegateToController($controller); | return $this->delegateToController($controller); | ||||
} | } | ||||
public function renderResultsList( | |||||
array $macros, | |||||
PhabricatorSavedQuery $query) { | |||||
assert_instances_of($macros, 'PhabricatorFileImageMacro'); | |||||
$viewer = $this->getRequest()->getUser(); | |||||
$author_phids = mpull($macros, 'getAuthorPHID', 'getAuthorPHID'); | |||||
$this->loadHandles($author_phids); | |||||
$author_handles = array_select_keys( | |||||
$this->getLoadedHandles(), | |||||
$author_phids); | |||||
$pinboard = new PHUIPinboardView(); | |||||
foreach ($macros as $macro) { | |||||
$file = $macro->getFile(); | |||||
$item = new PHUIPinboardItemView(); | |||||
if ($file) { | |||||
$item->setImageURI($file->getThumb280x210URI()); | |||||
$item->setImageSize(280, 210); | |||||
} | |||||
if ($macro->getDateCreated()) { | |||||
$datetime = phabricator_date($macro->getDateCreated(), $viewer); | |||||
$item->appendChild( | |||||
phutil_tag( | |||||
'div', | |||||
array(), | |||||
pht('Created on %s', $datetime))); | |||||
} else { | |||||
// Very old macros don't have a creation date. Rendering something | |||||
// keeps all the pins at the same height and avoids flow issues. | |||||
$item->appendChild( | |||||
phutil_tag( | |||||
'div', | |||||
array(), | |||||
pht('Created in ages long past'))); | |||||
} | |||||
if ($macro->getAuthorPHID()) { | |||||
$author_handle = $this->getHandle($macro->getAuthorPHID()); | |||||
$item->appendChild( | |||||
pht('Created by %s', $author_handle->renderLink())); | |||||
} | |||||
$item->setURI($this->getApplicationURI('/view/'.$macro->getID().'/')); | |||||
$name = $macro->getName(); | |||||
if ($macro->getIsDisabled()) { | |||||
$name = pht('%s (Disabled)', $name); | |||||
} | |||||
$item->setHeader($name); | |||||
$pinboard->addItem($item); | |||||
} | |||||
return $pinboard; | |||||
} | |||||
} | } |