Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / notification / query / PhabricatorNotificationSearchEngine.php
blob4b56c5f5a1dd65e1898c2fa44fbb4f54a6935f9e
1 <?php
3 final class PhabricatorNotificationSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 public function getResultTypeDescription() {
7 return pht('Notifications');
10 public function getApplicationClassName() {
11 return 'PhabricatorNotificationsApplication';
14 public function buildSavedQueryFromRequest(AphrontRequest $request) {
15 $saved = new PhabricatorSavedQuery();
17 $saved->setParameter(
18 'unread',
19 $this->readBoolFromRequest($request, 'unread'));
21 return $saved;
24 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
25 $query = id(new PhabricatorNotificationQuery())
26 ->withUserPHIDs(array($this->requireViewer()->getPHID()));
28 if ($saved->getParameter('unread')) {
29 $query->withUnread(true);
32 return $query;
35 public function buildSearchForm(
36 AphrontFormView $form,
37 PhabricatorSavedQuery $saved) {
39 $unread = $saved->getParameter('unread');
41 $form->appendChild(
42 id(new AphrontFormCheckboxControl())
43 ->setLabel(pht('Unread'))
44 ->addCheckbox(
45 'unread',
47 pht('Show only unread notifications.'),
48 $unread));
51 protected function getURI($path) {
52 return '/notification/'.$path;
55 protected function getBuiltinQueryNames() {
57 $names = array(
58 'all' => pht('All Notifications'),
59 'unread' => pht('Unread Notifications'),
62 return $names;
65 public function buildSavedQueryFromBuiltin($query_key) {
66 $query = $this->newSavedQuery();
67 $query->setQueryKey($query_key);
69 switch ($query_key) {
70 case 'all':
71 return $query;
72 case 'unread':
73 return $query->setParameter('unread', true);
76 return parent::buildSavedQueryFromBuiltin($query_key);
79 protected function renderResultList(
80 array $notifications,
81 PhabricatorSavedQuery $query,
82 array $handles) {
83 assert_instances_of($notifications, 'PhabricatorFeedStory');
85 $viewer = $this->requireViewer();
87 $image = id(new PHUIIconView())
88 ->setIcon('fa-bell-o');
90 $button = id(new PHUIButtonView())
91 ->setTag('a')
92 ->addSigil('workflow')
93 ->setColor(PHUIButtonView::GREY)
94 ->setIcon($image)
95 ->setText(pht('Mark All Read'));
97 switch ($query->getQueryKey()) {
98 case 'unread':
99 $header = pht('Unread Notifications');
100 $no_data = pht('You have no unread notifications.');
101 break;
102 default:
103 $header = pht('Notifications');
104 $no_data = pht('You have no notifications.');
105 break;
108 $clear_uri = id(new PhutilURI('/notification/clear/'));
109 if ($notifications) {
110 $builder = id(new PhabricatorNotificationBuilder($notifications))
111 ->setUser($viewer);
113 $view = $builder->buildView();
114 $clear_uri->replaceQueryParam(
115 'chronoKey',
116 head($notifications)->getChronologicalKey());
117 } else {
118 $view = phutil_tag_div(
119 'phabricator-notification no-notifications',
120 $no_data);
121 $button->setDisabled(true);
123 $button->setHref((string)$clear_uri);
125 $view = id(new PHUIBoxView())
126 ->addPadding(PHUI::PADDING_MEDIUM)
127 ->addClass('phabricator-notification-list')
128 ->appendChild($view);
130 $result = new PhabricatorApplicationSearchResultView();
131 $result->addAction($button);
132 $result->setContent($view);
134 return $result;