Path: blob/master/src/applications/countdown/query/PhabricatorCountdownSearchEngine.php
12256 views
<?php12final class PhabricatorCountdownSearchEngine3extends PhabricatorApplicationSearchEngine {45public function getResultTypeDescription() {6return pht('Countdowns');7}89public function getApplicationClassName() {10return 'PhabricatorCountdownApplication';11}1213public function newQuery() {14return new PhabricatorCountdownQuery();15}1617protected function buildQueryFromParameters(array $map) {18$query = $this->newQuery();1920if ($map['authorPHIDs']) {21$query->withAuthorPHIDs($map['authorPHIDs']);22}2324if ($map['upcoming'] && $map['upcoming'][0] == 'upcoming') {25$query->withUpcoming();26}2728return $query;29}3031protected function buildCustomSearchFields() {32return array(33id(new PhabricatorUsersSearchField())34->setLabel(pht('Authors'))35->setKey('authorPHIDs')36->setAliases(array('author', 'authors')),37id(new PhabricatorSearchCheckboxesField())38->setKey('upcoming')39->setOptions(40array(41'upcoming' => pht('Show only upcoming countdowns.'),42)),43);44}4546protected function getURI($path) {47return '/countdown/'.$path;48}4950protected function getBuiltinQueryNames() {51$names = array(52'upcoming' => pht('Upcoming'),53'all' => pht('All'),54);5556if ($this->requireViewer()->getPHID()) {57$names['authored'] = pht('Authored');58}5960return $names;61}6263public function buildSavedQueryFromBuiltin($query_key) {64$query = $this->newSavedQuery();65$query->setQueryKey($query_key);6667switch ($query_key) {68case 'all':69return $query;70case 'authored':71return $query->setParameter(72'authorPHIDs',73array($this->requireViewer()->getPHID()));74case 'upcoming':75return $query->setParameter('upcoming', array('upcoming'));76}7778return parent::buildSavedQueryFromBuiltin($query_key);79}8081protected function getRequiredHandlePHIDsForResultList(82array $countdowns,83PhabricatorSavedQuery $query) {8485return mpull($countdowns, 'getAuthorPHID');86}8788protected function renderResultList(89array $countdowns,90PhabricatorSavedQuery $query,91array $handles) {9293assert_instances_of($countdowns, 'PhabricatorCountdown');9495$viewer = $this->requireViewer();9697$list = new PHUIObjectItemListView();98$list->setUser($viewer);99foreach ($countdowns as $countdown) {100$id = $countdown->getID();101$ended = false;102$epoch = $countdown->getEpoch();103if ($epoch <= PhabricatorTime::getNow()) {104$ended = true;105}106107$item = id(new PHUIObjectItemView())108->setUser($viewer)109->setObject($countdown)110->setObjectName($countdown->getMonogram())111->setHeader($countdown->getTitle())112->setHref($countdown->getURI())113->addByline(114pht(115'Created by %s',116$handles[$countdown->getAuthorPHID()]->renderLink()));117118if ($ended) {119$item->addAttribute(120pht('Launched on %s', phabricator_datetime($epoch, $viewer)));121$item->setDisabled(true);122} else {123$time_left = ($epoch - PhabricatorTime::getNow());124$num = round($time_left / (60 * 60 * 24));125$noun = pht('Days');126if ($num < 1) {127$num = round($time_left / (60 * 60), 1);128$noun = pht('Hours');129}130$item->setCountdown($num, $noun);131$item->addAttribute(132phabricator_datetime($epoch, $viewer));133}134135$list->addItem($item);136}137138$result = new PhabricatorApplicationSearchResultView();139$result->setObjectList($list);140$result->setNoDataString(pht('No countdowns found.'));141142return $result;143}144145protected function getNewUserBody() {146$create_button = id(new PHUIButtonView())147->setTag('a')148->setText(pht('Create a Countdown'))149->setHref('/countdown/edit/')150->setColor(PHUIButtonView::GREEN);151152$icon = $this->getApplication()->getIcon();153$app_name = $this->getApplication()->getName();154$view = id(new PHUIBigInfoView())155->setIcon($icon)156->setTitle(pht('Welcome to %s', $app_name))157->setDescription(158pht('Keep track of upcoming launch dates with '.159'embeddable counters.'))160->addAction($create_button);161162return $view;163}164165}166167168