Path: blob/master/src/applications/feed/builder/PhabricatorFeedBuilder.php
12241 views
<?php12final class PhabricatorFeedBuilder extends Phobject {34private $user;5private $stories;6private $hovercards = false;7private $noDataString;89public function __construct(array $stories) {10assert_instances_of($stories, 'PhabricatorFeedStory');11$this->stories = $stories;12}1314public function setUser(PhabricatorUser $user) {15$this->user = $user;16return $this;17}1819public function setShowHovercards($hover) {20$this->hovercards = $hover;21return $this;22}2324public function setNoDataString($string) {25$this->noDataString = $string;26return $this;27}2829public function buildView() {30if (!$this->user) {31throw new PhutilInvalidStateException('setUser');32}3334$user = $this->user;35$stories = $this->stories;3637$null_view = new AphrontNullView();3839require_celerity_resource('phabricator-feed-css');4041$last_date = null;42foreach ($stories as $story) {43$story->setHovercard($this->hovercards);4445$date = ucfirst(phabricator_relative_date($story->getEpoch(), $user));4647if ($date !== $last_date) {48if ($last_date !== null) {49$null_view->appendChild(50phutil_tag_div('phabricator-feed-story-date-separator'));51}52$last_date = $date;53$header = new PHUIHeaderView();54$header->setHeader($date);55$header->setHeaderIcon('fa-calendar msr');5657$null_view->appendChild($header);58}5960try {61$view = $story->renderView();62$view->setUser($user);63$view = $view->render();64} catch (Exception $ex) {65// If rendering failed for any reason, don't fail the entire feed,66// just this one story.67$view = id(new PHUIFeedStoryView())68->setUser($user)69->setChronologicalKey($story->getChronologicalKey())70->setEpoch($story->getEpoch())71->setTitle(72pht('Feed Story Failed to Render (%s)', get_class($story)))73->appendChild(pht('%s: %s', get_class($ex), $ex->getMessage()));74}7576$null_view->appendChild($view);77}7879$box = id(new PHUIObjectBoxView())80->appendChild($null_view);8182if (empty($stories)) {83$nodatastring = pht('No Stories.');84if ($this->noDataString) {85$nodatastring = $this->noDataString;86}8788$view = id(new PHUIBoxView())89->addClass('mlt mlb msr msl')90->appendChild($nodatastring);91$box->appendChild($view);92}9394return $box;9596}9798}99100101