@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at upstream/main 158 lines 4.3 kB view raw
1<?php 2 3final class PholioMockSearchEngine extends PhabricatorApplicationSearchEngine { 4 5 public function getResultTypeDescription() { 6 return pht('Pholio Mocks'); 7 } 8 9 public function getApplicationClassName() { 10 return PhabricatorPholioApplication::class; 11 } 12 13 public function newQuery() { 14 return id(new PholioMockQuery()) 15 ->needCoverFiles(true) 16 ->needImages(true) 17 ->needTokenCounts(true); 18 } 19 20 protected function buildCustomSearchFields() { 21 return array( 22 id(new PhabricatorUsersSearchField()) 23 ->setKey('authorPHIDs') 24 ->setAliases(array('authors')) 25 ->setLabel(pht('Authors')), 26 id(new PhabricatorSearchCheckboxesField()) 27 ->setKey('statuses') 28 ->setLabel(pht('Status')) 29 ->setOptions( 30 id(new PholioMock()) 31 ->getStatuses()), 32 ); 33 } 34 35 protected function buildQueryFromParameters(array $map) { 36 $query = $this->newQuery(); 37 38 if ($map['authorPHIDs']) { 39 $query->withAuthorPHIDs($map['authorPHIDs']); 40 } 41 42 if ($map['statuses']) { 43 $query->withStatuses($map['statuses']); 44 } 45 46 return $query; 47 } 48 49 protected function getURI($path) { 50 return '/pholio/'.$path; 51 } 52 53 protected function getBuiltinQueryNames() { 54 $names = array( 55 'open' => pht('Open Mocks'), 56 'all' => pht('All Mocks'), 57 ); 58 59 if ($this->requireViewer()->isLoggedIn()) { 60 $names['authored'] = pht('Authored'); 61 } 62 63 return $names; 64 } 65 66 public function buildSavedQueryFromBuiltin($query_key) { 67 $query = $this->newSavedQuery(); 68 $query->setQueryKey($query_key); 69 70 switch ($query_key) { 71 case 'open': 72 return $query->setParameter( 73 'statuses', 74 array('open')); 75 case 'all': 76 return $query; 77 case 'authored': 78 return $query->setParameter( 79 'authorPHIDs', 80 array($this->requireViewer()->getPHID())); 81 } 82 83 return parent::buildSavedQueryFromBuiltin($query_key); 84 } 85 86 /** 87 * @param array<PholioMock> $mocks 88 * @param PhabricatorSavedQuery $query 89 * @param array<PhabricatorObjectHandle> $handles 90 */ 91 protected function renderResultList( 92 array $mocks, 93 PhabricatorSavedQuery $query, 94 array $handles) { 95 assert_instances_of($mocks, PholioMock::class); 96 97 $viewer = $this->requireViewer(); 98 $handles = $viewer->loadHandles(mpull($mocks, 'getAuthorPHID')); 99 100 $xform = PhabricatorFileTransform::getTransformByKey( 101 PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD); 102 103 $board = new PHUIPinboardView(); 104 foreach ($mocks as $mock) { 105 106 $image = $mock->getCoverFile(); 107 $image_uri = $image->getURIForTransform($xform); 108 list($x, $y) = $xform->getTransformedDimensions($image); 109 110 $header = 'M'.$mock->getID().' '.$mock->getName(); 111 $item = id(new PHUIPinboardItemView()) 112 ->setViewer($viewer) 113 ->setHeader($header) 114 ->setObject($mock) 115 ->setURI('/M'.$mock->getID()) 116 ->setImageURI($image_uri) 117 ->setImageSize($x, $y) 118 ->setDisabled($mock->isClosed()) 119 ->addIconCount('fa-picture-o', count($mock->getActiveImages())) 120 ->addIconCount('fa-trophy', $mock->getTokenCount()); 121 122 if ($mock->getAuthorPHID()) { 123 $author_handle = $handles[$mock->getAuthorPHID()]; 124 $datetime = phabricator_date($mock->getDateCreated(), $viewer); 125 $item->appendChild( 126 pht('By %s on %s', $author_handle->renderLink(), $datetime)); 127 } 128 129 $board->addItem($item); 130 } 131 132 $result = new PhabricatorApplicationSearchResultView(); 133 $result->setContent($board); 134 135 return $result; 136 } 137 138 protected function getNewUserBody() { 139 $create_button = id(new PHUIButtonView()) 140 ->setTag('a') 141 ->setText(pht('Create a Mock')) 142 ->setHref('/pholio/create/') 143 ->setColor(PHUIButtonView::GREEN); 144 145 $icon = $this->getApplication()->getIcon(); 146 $app_name = $this->getApplication()->getName(); 147 $view = id(new PHUIBigInfoView()) 148 ->setIcon($icon) 149 ->setTitle(pht('Welcome to %s', $app_name)) 150 ->setDescription( 151 pht('Upload sets of images for review with revision history and '. 152 'inline comments.')) 153 ->addAction($create_button); 154 155 return $view; 156 } 157 158}