Path: blob/master/src/applications/feed/query/PhabricatorFeedTransactionSearchEngine.php
12242 views
<?php12final class PhabricatorFeedTransactionSearchEngine3extends PhabricatorApplicationSearchEngine {45public function getResultTypeDescription() {6return pht('Transactions');7}89public function getApplicationClassName() {10return 'PhabricatorFeedApplication';11}1213public function newQuery() {14return new PhabricatorFeedTransactionQuery();15}1617protected function buildCustomSearchFields() {18return array(19id(new PhabricatorUsersSearchField())20->setLabel(pht('Authors'))21->setKey('authorPHIDs')22->setAliases(array('author', 'authors')),23id(new PhabricatorSearchDatasourceField())24->setLabel(pht('Object Types'))25->setKey('objectTypes')26->setAliases(array('objectType'))27->setDatasource(new PhabricatorTransactionsObjectTypeDatasource()),28id(new PhabricatorSearchDateField())29->setLabel(pht('Created After'))30->setKey('createdStart'),31id(new PhabricatorSearchDateField())32->setLabel(pht('Created Before'))33->setKey('createdEnd'),34);35}3637protected function buildQueryFromParameters(array $map) {38$query = $this->newQuery();3940if ($map['authorPHIDs']) {41$query->withAuthorPHIDs($map['authorPHIDs']);42}4344if ($map['objectTypes']) {45$query->withObjectTypes($map['objectTypes']);46}4748$created_min = $map['createdStart'];49$created_max = $map['createdEnd'];5051if ($created_min && $created_max) {52if ($created_min > $created_max) {53throw new PhabricatorSearchConstraintException(54pht(55'The specified "Created Before" date is earlier in time than the '.56'specified "Created After" date, so this query can never match '.57'any results.'));58}59}6061if ($created_min || $created_max) {62$query->withDateCreatedBetween($created_min, $created_max);63}6465return $query;66}6768protected function getURI($path) {69return '/feed/transactions/'.$path;70}7172protected function getBuiltinQueryNames() {73$names = array(74'all' => pht('All Transactions'),75);7677return $names;78}7980public function buildSavedQueryFromBuiltin($query_key) {81$query = $this->newSavedQuery()82->setQueryKey($query_key);8384switch ($query_key) {85case 'all':86return $query;87}8889return parent::buildSavedQueryFromBuiltin($query_key);90}9192protected function renderResultList(93array $objects,94PhabricatorSavedQuery $query,95array $handles) {96assert_instances_of($objects, 'PhabricatorApplicationTransaction');9798$viewer = $this->requireViewer();99100$handle_phids = array();101foreach ($objects as $object) {102$author_phid = $object->getAuthorPHID();103if ($author_phid !== null) {104$handle_phids[] = $author_phid;105}106$object_phid = $object->getObjectPHID();107if ($object_phid !== null) {108$handle_phids[] = $object_phid;109}110}111112$handles = $viewer->loadHandles($handle_phids);113114$rows = array();115foreach ($objects as $object) {116$author_phid = $object->getAuthorPHID();117$object_phid = $object->getObjectPHID();118119try {120$title = $object->getTitle();121} catch (Exception $ex) {122$title = null;123}124125$rows[] = array(126$handles[$author_phid]->renderLink(),127$handles[$object_phid]->renderLink(),128AphrontTableView::renderSingleDisplayLine($title),129phabricator_datetime($object->getDateCreated(), $viewer),130);131}132133$table = id(new AphrontTableView($rows))134->setHeaders(135array(136pht('Author'),137pht('Object'),138pht('Transaction'),139pht('Date'),140))141->setColumnClasses(142array(143null,144null,145'wide',146'right',147));148149return id(new PhabricatorApplicationSearchResultView())150->setTable($table);151}152153protected function newExportFields() {154$fields = array(155id(new PhabricatorPHIDExportField())156->setKey('authorPHID')157->setLabel(pht('Author PHID')),158id(new PhabricatorStringExportField())159->setKey('author')160->setLabel(pht('Author')),161id(new PhabricatorStringExportField())162->setKey('objectType')163->setLabel(pht('Object Type')),164id(new PhabricatorPHIDExportField())165->setKey('objectPHID')166->setLabel(pht('Object PHID')),167id(new PhabricatorStringExportField())168->setKey('objectName')169->setLabel(pht('Object Name')),170id(new PhabricatorStringExportField())171->setKey('description')172->setLabel(pht('Description')),173);174175return $fields;176}177178protected function newExportData(array $xactions) {179$viewer = $this->requireViewer();180181$phids = array();182foreach ($xactions as $xaction) {183$phids[] = $xaction->getAuthorPHID();184$phids[] = $xaction->getObjectPHID();185}186$handles = $viewer->loadHandles($phids);187188$export = array();189foreach ($xactions as $xaction) {190$xaction_phid = $xaction->getPHID();191192$author_phid = $xaction->getAuthorPHID();193if ($author_phid) {194$author_name = $handles[$author_phid]->getName();195} else {196$author_name = null;197}198199$object_phid = $xaction->getObjectPHID();200if ($object_phid) {201$object_name = $handles[$object_phid]->getName();202} else {203$object_name = null;204}205206$old_target = $xaction->getRenderingTarget();207try {208$description = $xaction209->setRenderingTarget(PhabricatorApplicationTransaction::TARGET_TEXT)210->getTitle();211} catch (Exception $ex) {212$description = null;213}214$xaction->setRenderingTarget($old_target);215216$export[] = array(217'authorPHID' => $author_phid,218'author' => $author_name,219'objectType' => phid_get_subtype($xaction_phid),220'objectPHID' => $object_phid,221'objectName' => $object_name,222'description' => $description,223);224}225226return $export;227}228229}230231232