Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / differential / query / DifferentialChangesetSearchEngine.php
blobb6279ec339f0fe796d730eaed11cd9589f3c659b
1 <?php
3 final class DifferentialChangesetSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 private $diff;
8 public function setDiff(DifferentialDiff $diff) {
9 $this->diff = $diff;
10 return $this;
13 public function getDiff() {
14 return $this->diff;
17 public function getResultTypeDescription() {
18 return pht('Differential Changesets');
21 public function getApplicationClassName() {
22 return 'PhabricatorDifferentialApplication';
25 public function canUseInPanelContext() {
26 return false;
29 public function newQuery() {
30 $query = id(new DifferentialChangesetQuery());
32 if ($this->diff) {
33 $query->withDiffs(array($this->diff));
36 return $query;
39 protected function buildQueryFromParameters(array $map) {
40 $query = $this->newQuery();
42 if ($map['diffPHIDs']) {
43 $query->withDiffPHIDs($map['diffPHIDs']);
46 return $query;
49 protected function buildCustomSearchFields() {
50 return array(
51 id(new PhabricatorPHIDsSearchField())
52 ->setLabel(pht('Diffs'))
53 ->setKey('diffPHIDs')
54 ->setAliases(array('diff', 'diffs', 'diffPHID'))
55 ->setDescription(
56 pht('Find changesets attached to a particular diff.')),
60 protected function getURI($path) {
61 $diff = $this->getDiff();
62 if ($diff) {
63 return '/differential/diff/'.$diff->getID().'/changesets/'.$path;
66 throw new PhutilMethodNotImplementedException();
69 protected function getBuiltinQueryNames() {
70 $names = array();
71 $names['all'] = pht('All Changesets');
72 return $names;
75 public function buildSavedQueryFromBuiltin($query_key) {
76 $query = $this->newSavedQuery();
77 $query->setQueryKey($query_key);
79 $viewer = $this->requireViewer();
81 switch ($query_key) {
82 case 'all':
83 return $query->setParameter('order', 'oldest');
86 return parent::buildSavedQueryFromBuiltin($query_key);
89 protected function renderResultList(
90 array $changesets,
91 PhabricatorSavedQuery $query,
92 array $handles) {
94 assert_instances_of($changesets, 'DifferentialChangeset');
95 $viewer = $this->requireViewer();
97 $rows = array();
98 foreach ($changesets as $changeset) {
99 $link = phutil_tag(
100 'a',
101 array(
102 'href' => '/differential/changeset/?ref='.$changeset->getID(),
104 $changeset->getDisplayFilename());
106 $type = $changeset->getChangeType();
108 $title = DifferentialChangeType::getFullNameForChangeType($type);
110 $add_lines = $changeset->getAddLines();
111 if (!$add_lines) {
112 $add_lines = null;
113 } else {
114 $add_lines = '+'.$add_lines;
117 $rem_lines = $changeset->getDelLines();
118 if (!$rem_lines) {
119 $rem_lines = null;
120 } else {
121 $rem_lines = '-'.$rem_lines;
124 $rows[] = array(
125 $changeset->newFileTreeIcon(),
126 $title,
127 $link,
131 $table = id(new AphrontTableView($rows))
132 ->setHeaders(
133 array(
134 null,
135 pht('Change'),
136 pht('Path'),
138 ->setColumnClasses(
139 array(
140 null,
141 null,
142 'pri wide',
145 return id(new PhabricatorApplicationSearchResultView())
146 ->setTable($table);