Remove product literal strings in "pht()", part 25
[phabricator.git] / src / applications / releeph / query / ReleephBranchSearchEngine.php
blob441f70e9920f5162da838bf076597f77817bf75a
1 <?php
3 final class ReleephBranchSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 private $product;
8 public function getResultTypeDescription() {
9 return pht('Releeph Branches');
12 public function canUseInPanelContext() {
13 return false;
16 public function getApplicationClassName() {
17 return 'PhabricatorReleephApplication';
20 public function setProduct(ReleephProject $product) {
21 $this->product = $product;
22 return $this;
25 public function getProduct() {
26 return $this->product;
29 public function buildSavedQueryFromRequest(AphrontRequest $request) {
30 $saved = new PhabricatorSavedQuery();
32 $saved->setParameter('active', $request->getStr('active'));
34 return $saved;
37 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
38 $query = id(new ReleephBranchQuery())
39 ->needCutPointCommits(true)
40 ->withProductPHIDs(array($this->getProduct()->getPHID()));
42 $active = $saved->getParameter('active');
43 $value = idx($this->getActiveValues(), $active);
44 if ($value !== null) {
45 $query->withStatus($value);
48 return $query;
51 public function buildSearchForm(
52 AphrontFormView $form,
53 PhabricatorSavedQuery $saved_query) {
55 $form->appendChild(
56 id(new AphrontFormSelectControl())
57 ->setName('active')
58 ->setLabel(pht('Show Branches'))
59 ->setValue($saved_query->getParameter('active'))
60 ->setOptions($this->getActiveOptions()));
63 protected function getURI($path) {
64 return '/releeph/product/'.$this->getProduct()->getID().'/'.$path;
67 protected function getBuiltinQueryNames() {
68 $names = array(
69 'open' => pht('Open'),
70 'all' => pht('All'),
73 return $names;
76 public function buildSavedQueryFromBuiltin($query_key) {
78 $query = $this->newSavedQuery();
79 $query->setQueryKey($query_key);
81 switch ($query_key) {
82 case 'open':
83 return $query
84 ->setParameter('active', 'open');
85 case 'all':
86 return $query;
89 return parent::buildSavedQueryFromBuiltin($query_key);
92 private function getActiveOptions() {
93 return array(
94 'open' => pht('Open Branches'),
95 'all' => pht('Open and Closed Branches'),
99 private function getActiveValues() {
100 return array(
101 'open' => ReleephBranchQuery::STATUS_OPEN,
102 'all' => ReleephBranchQuery::STATUS_ALL,
106 protected function renderResultList(
107 array $branches,
108 PhabricatorSavedQuery $query,
109 array $handles) {
112 assert_instances_of($branches, 'ReleephBranch');
114 $viewer = $this->getRequest()->getUser();
116 $products = mpull($branches, 'getProduct');
117 $repo_phids = mpull($products, 'getRepositoryPHID');
119 if ($repo_phids) {
120 $repos = id(new PhabricatorRepositoryQuery())
121 ->setViewer($viewer)
122 ->withPHIDs($repo_phids)
123 ->execute();
124 $repos = mpull($repos, null, 'getPHID');
125 } else {
126 $repos = array();
129 $requests = array();
130 if ($branches) {
131 $requests = id(new ReleephRequestQuery())
132 ->setViewer($viewer)
133 ->withBranchIDs(mpull($branches, 'getID'))
134 ->withStatus(ReleephRequestQuery::STATUS_OPEN)
135 ->execute();
136 $requests = mgroup($requests, 'getBranchID');
139 $list = id(new PHUIObjectItemListView())
140 ->setUser($viewer);
141 foreach ($branches as $branch) {
142 $diffusion_href = null;
143 $repo = idx($repos, $branch->getProduct()->getRepositoryPHID());
144 if ($repo) {
145 $drequest = DiffusionRequest::newFromDictionary(
146 array(
147 'user' => $viewer,
148 'repository' => $repo,
151 $diffusion_href = $drequest->generateURI(
152 array(
153 'action' => 'branch',
154 'branch' => $branch->getName(),
158 $branch_link = $branch->getName();
159 if ($diffusion_href) {
160 $branch_link = phutil_tag(
161 'a',
162 array(
163 'href' => $diffusion_href,
165 $branch_link);
168 $item = id(new PHUIObjectItemView())
169 ->setHeader($branch->getDisplayName())
170 ->setHref($this->getApplicationURI('branch/'.$branch->getID().'/'))
171 ->addAttribute($branch_link);
173 if (!$branch->getIsActive()) {
174 $item->setDisabled(true);
177 $commit = $branch->getCutPointCommit();
178 if ($commit) {
179 $item->addIcon(
180 'none',
181 phabricator_datetime($commit->getEpoch(), $viewer));
184 $open_count = count(idx($requests, $branch->getID(), array()));
185 if ($open_count) {
186 $item->setStatusIcon('fa-code-fork orange');
187 $item->addIcon(
188 'fa-code-fork',
189 pht(
190 '%s Open Pull Request(s)',
191 new PhutilNumber($open_count)));
194 $list->addItem($item);
197 return id(new PhabricatorApplicationSearchResultView())
198 ->setObjectList($list);