[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class FeedQueryConduitAPIMethod extends FeedConduitAPIMethod { 4 5 public function getAPIMethodName() { 6 return 'feed.query'; 7 } 8 9 public function getMethodStatus() { 10 return self::METHOD_STATUS_UNSTABLE; 11 } 12 13 public function getMethodDescription() { 14 return 'Query the feed for stories'; 15 } 16 17 private function getDefaultLimit() { 18 return 100; 19 } 20 21 public function defineParamTypes() { 22 return array( 23 'filterPHIDs' => 'optional list <phid>', 24 'limit' => 'optional int (default '.$this->getDefaultLimit().')', 25 'after' => 'optional int', 26 'before' => 'optional int', 27 'view' => 'optional string (data, html, html-summary, text)', 28 ); 29 } 30 31 private function getSupportedViewTypes() { 32 return array( 33 'html' => 'Full HTML presentation of story', 34 'data' => 'Dictionary with various data of the story', 35 'html-summary' => 'Story contains only the title of the story', 36 'text' => 'Simple one-line plain text representation of story', 37 ); 38 } 39 40 public function defineErrorTypes() { 41 42 $view_types = array_keys($this->getSupportedViewTypes()); 43 $view_types = implode(', ', $view_types); 44 45 return array( 46 'ERR-UNKNOWN-TYPE' => 47 'Unsupported view type, possibles are: '.$view_types, 48 ); 49 } 50 51 public function defineReturnType() { 52 return 'nonempty dict'; 53 } 54 55 protected function execute(ConduitAPIRequest $request) { 56 $results = array(); 57 $user = $request->getUser(); 58 59 $view_type = $request->getValue('view'); 60 if (!$view_type) { 61 $view_type = 'data'; 62 } 63 64 $limit = $request->getValue('limit'); 65 if (!$limit) { 66 $limit = $this->getDefaultLimit(); 67 } 68 $filter_phids = $request->getValue('filterPHIDs'); 69 if (!$filter_phids) { 70 $filter_phids = array(); 71 } 72 73 $query = id(new PhabricatorFeedQuery()) 74 ->setLimit($limit) 75 ->setFilterPHIDs($filter_phids) 76 ->setViewer($user); 77 78 $after = $request->getValue('after'); 79 if (strlen($after)) { 80 $query->setAfterID($after); 81 } 82 83 $before = $request->getValue('before'); 84 if (strlen($before)) { 85 $query->setBeforeID($before); 86 } 87 88 $stories = $query->execute(); 89 90 if ($stories) { 91 foreach ($stories as $story) { 92 93 $story_data = $story->getStoryData(); 94 95 $data = null; 96 97 try { 98 $view = $story->renderView(); 99 } catch (Exception $ex) { 100 // When stories fail to render, just fail that story. 101 phlog($ex); 102 continue; 103 } 104 105 $view->setEpoch($story->getEpoch()); 106 $view->setUser($user); 107 108 switch ($view_type) { 109 case 'html': 110 $data = $view->render(); 111 break; 112 case 'html-summary': 113 $data = $view->render(); 114 break; 115 case 'data': 116 $data = array( 117 'class' => $story_data->getStoryType(), 118 'epoch' => $story_data->getEpoch(), 119 'authorPHID' => $story_data->getAuthorPHID(), 120 'chronologicalKey' => $story_data->getChronologicalKey(), 121 'data' => $story_data->getStoryData(), 122 ); 123 break; 124 case 'text': 125 $data = array( 126 'class' => $story_data->getStoryType(), 127 'epoch' => $story_data->getEpoch(), 128 'authorPHID' => $story_data->getAuthorPHID(), 129 'chronologicalKey' => $story_data->getChronologicalKey(), 130 'objectPHID' => $story->getPrimaryObjectPHID(), 131 'text' => $story->renderText(), 132 ); 133 break; 134 default: 135 throw new ConduitException('ERR-UNKNOWN-TYPE'); 136 } 137 138 $results[$story_data->getPHID()] = $data; 139 } 140 } 141 142 return $results; 143 } 144 145 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |