3 final class PhabricatorFeedBuilder
extends Phobject
{
7 private $hovercards = false;
10 public function __construct(array $stories) {
11 assert_instances_of($stories, 'PhabricatorFeedStory');
12 $this->stories
= $stories;
15 public function setUser(PhabricatorUser
$user) {
20 public function setShowHovercards($hover) {
21 $this->hovercards
= $hover;
25 public function setNoDataString($string) {
26 $this->noDataString
= $string;
30 public function buildView() {
32 throw new PhutilInvalidStateException('setUser');
36 $stories = $this->stories
;
38 $null_view = new AphrontNullView();
40 require_celerity_resource('phabricator-feed-css');
43 foreach ($stories as $story) {
44 $story->setHovercard($this->hovercards
);
46 $date = ucfirst(phabricator_relative_date($story->getEpoch(), $user));
48 if ($date !== $last_date) {
49 if ($last_date !== null) {
50 $null_view->appendChild(
51 phutil_tag_div('phabricator-feed-story-date-separator'));
54 $header = new PHUIHeaderView();
55 $header->setHeader($date);
56 $header->setHeaderIcon('fa-calendar msr');
58 $null_view->appendChild($header);
62 $view = $story->renderView();
63 $view->setUser($user);
64 $view = $view->render();
65 } catch (Exception
$ex) {
66 // If rendering failed for any reason, don't fail the entire feed,
67 // just this one story.
68 $view = id(new PHUIFeedStoryView())
70 ->setChronologicalKey($story->getChronologicalKey())
71 ->setEpoch($story->getEpoch())
73 pht('Feed Story Failed to Render (%s)', get_class($story)))
74 ->appendChild(pht('%s: %s', get_class($ex), $ex->getMessage()));
77 $null_view->appendChild($view);
80 $box = id(new PHUIObjectBoxView())
81 ->appendChild($null_view);
83 if (empty($stories)) {
84 $nodatastring = pht('No Stories.');
85 if ($this->noDataString
) {
86 $nodatastring = $this->noDataString
;
89 $view = id(new PHUIBoxView())
90 ->addClass('mlt mlb msr msl')
91 ->appendChild($nodatastring);
92 $box->appendChild($view);