Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / feed / conduit / FeedQueryConduitAPIMethod.php
blob53f3fe8f39a926788c1b4e10f6c444791f38e654
1 <?php
3 final class FeedQueryConduitAPIMethod extends FeedConduitAPIMethod {
5 public function getAPIMethodName() {
6 return 'feed.query';
9 public function getMethodStatus() {
10 return self::METHOD_STATUS_UNSTABLE;
13 public function getMethodDescription() {
14 return pht('Query the feed for stories');
17 private function getDefaultLimit() {
18 return 100;
21 protected 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)',
31 private function getSupportedViewTypes() {
32 return array(
33 'html' => pht('Full HTML presentation of story'),
34 'data' => pht('Dictionary with various data of the story'),
35 'html-summary' => pht('Story contains only the title of the story'),
36 'text' => pht('Simple one-line plain text representation of story'),
40 protected function defineErrorTypes() {
42 $view_types = array_keys($this->getSupportedViewTypes());
43 $view_types = implode(', ', $view_types);
45 return array(
46 'ERR-UNKNOWN-TYPE' =>
47 pht(
48 'Unsupported view type, possibles are: %s',
49 $view_types),
53 protected function defineReturnType() {
54 return 'nonempty dict';
57 protected function execute(ConduitAPIRequest $request) {
58 $results = array();
59 $user = $request->getUser();
61 $view_type = $request->getValue('view');
62 if (!$view_type) {
63 $view_type = 'data';
66 $query = id(new PhabricatorFeedQuery())
67 ->setViewer($user);
69 $filter_phids = $request->getValue('filterPHIDs');
70 if ($filter_phids) {
71 $query->withFilterPHIDs($filter_phids);
74 $limit = $request->getValue('limit');
75 if (!$limit) {
76 $limit = $this->getDefaultLimit();
79 $pager = id(new AphrontCursorPagerView())
80 ->setPageSize($limit);
82 $after = $request->getValue('after');
83 if (strlen($after)) {
84 $pager->setAfterID($after);
87 $before = $request->getValue('before');
88 if (strlen($before)) {
89 $pager->setBeforeID($before);
92 $stories = $query->executeWithCursorPager($pager);
94 if ($stories) {
95 foreach ($stories as $story) {
97 $story_data = $story->getStoryData();
99 $data = null;
101 try {
102 $view = $story->renderView();
103 } catch (Exception $ex) {
104 // When stories fail to render, just fail that story.
105 phlog($ex);
106 continue;
109 $view->setEpoch($story->getEpoch());
110 $view->setUser($user);
112 switch ($view_type) {
113 case 'html':
114 $data = $view->render();
115 break;
116 case 'html-summary':
117 $data = $view->render();
118 break;
119 case 'data':
120 $data = array(
121 'class' => $story_data->getStoryType(),
122 'epoch' => $story_data->getEpoch(),
123 'authorPHID' => $story_data->getAuthorPHID(),
124 'chronologicalKey' => $story_data->getChronologicalKey(),
125 'data' => $story_data->getStoryData(),
127 break;
128 case 'text':
129 $data = array(
130 'class' => $story_data->getStoryType(),
131 'epoch' => $story_data->getEpoch(),
132 'authorPHID' => $story_data->getAuthorPHID(),
133 'chronologicalKey' => $story_data->getChronologicalKey(),
134 'objectPHID' => $story->getPrimaryObjectPHID(),
135 'text' => $story->renderText(),
137 break;
138 default:
139 throw new ConduitException('ERR-UNKNOWN-TYPE');
142 $results[$story_data->getPHID()] = $data;
146 return $results;