Path: blob/master/src/applications/notification/query/PhabricatorNotificationSearchEngine.php
12256 views
<?php12final class PhabricatorNotificationSearchEngine3extends PhabricatorApplicationSearchEngine {45public function getResultTypeDescription() {6return pht('Notifications');7}89public function getApplicationClassName() {10return 'PhabricatorNotificationsApplication';11}1213public function buildSavedQueryFromRequest(AphrontRequest $request) {14$saved = new PhabricatorSavedQuery();1516$saved->setParameter(17'unread',18$this->readBoolFromRequest($request, 'unread'));1920return $saved;21}2223public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {24$query = id(new PhabricatorNotificationQuery())25->withUserPHIDs(array($this->requireViewer()->getPHID()));2627if ($saved->getParameter('unread')) {28$query->withUnread(true);29}3031return $query;32}3334public function buildSearchForm(35AphrontFormView $form,36PhabricatorSavedQuery $saved) {3738$unread = $saved->getParameter('unread');3940$form->appendChild(41id(new AphrontFormCheckboxControl())42->setLabel(pht('Unread'))43->addCheckbox(44'unread',451,46pht('Show only unread notifications.'),47$unread));48}4950protected function getURI($path) {51return '/notification/'.$path;52}5354protected function getBuiltinQueryNames() {5556$names = array(57'all' => pht('All Notifications'),58'unread' => pht('Unread Notifications'),59);6061return $names;62}6364public function buildSavedQueryFromBuiltin($query_key) {65$query = $this->newSavedQuery();66$query->setQueryKey($query_key);6768switch ($query_key) {69case 'all':70return $query;71case 'unread':72return $query->setParameter('unread', true);73}7475return parent::buildSavedQueryFromBuiltin($query_key);76}7778protected function renderResultList(79array $notifications,80PhabricatorSavedQuery $query,81array $handles) {82assert_instances_of($notifications, 'PhabricatorFeedStory');8384$viewer = $this->requireViewer();8586$image = id(new PHUIIconView())87->setIcon('fa-bell-o');8889$button = id(new PHUIButtonView())90->setTag('a')91->addSigil('workflow')92->setColor(PHUIButtonView::GREY)93->setIcon($image)94->setText(pht('Mark All Read'));9596switch ($query->getQueryKey()) {97case 'unread':98$header = pht('Unread Notifications');99$no_data = pht('You have no unread notifications.');100break;101default:102$header = pht('Notifications');103$no_data = pht('You have no notifications.');104break;105}106107$clear_uri = id(new PhutilURI('/notification/clear/'));108if ($notifications) {109$builder = id(new PhabricatorNotificationBuilder($notifications))110->setUser($viewer);111112$view = $builder->buildView();113$clear_uri->replaceQueryParam(114'chronoKey',115head($notifications)->getChronologicalKey());116} else {117$view = phutil_tag_div(118'phabricator-notification no-notifications',119$no_data);120$button->setDisabled(true);121}122$button->setHref((string)$clear_uri);123124$view = id(new PHUIBoxView())125->addPadding(PHUI::PADDING_MEDIUM)126->addClass('phabricator-notification-list')127->appendChild($view);128129$result = new PhabricatorApplicationSearchResultView();130$result->addAction($button);131$result->setContent($view);132133return $result;134}135136}137138139