1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-12 00:26:13 +01:00
phorge-phorge/src/applications/feed/builder/PhabricatorFeedBuilder.php
Joshua Spence b6d745b666 Extend from Phobject
Summary: All classes should extend from some other class. See D13275 for some explanation.

Test Plan: `arc unit`

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D13283
2015-06-15 18:02:27 +10:00

103 lines
2.5 KiB
PHP

<?php
final class PhabricatorFeedBuilder extends Phobject {
private $stories;
private $framed;
private $hovercards = false;
private $noDataString;
public function __construct(array $stories) {
assert_instances_of($stories, 'PhabricatorFeedStory');
$this->stories = $stories;
}
public function setFramed($framed) {
$this->framed = $framed;
return $this;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function setShowHovercards($hover) {
$this->hovercards = $hover;
return $this;
}
public function setNoDataString($string) {
$this->noDataString = $string;
return $this;
}
public function buildView() {
if (!$this->user) {
throw new PhutilInvalidStateException('setUser');
}
$user = $this->user;
$stories = $this->stories;
$null_view = new AphrontNullView();
require_celerity_resource('phabricator-feed-css');
$last_date = null;
foreach ($stories as $story) {
$story->setFramed($this->framed);
$story->setHovercard($this->hovercards);
$date = ucfirst(phabricator_relative_date($story->getEpoch(), $user));
if ($date !== $last_date) {
if ($last_date !== null) {
$null_view->appendChild(
phutil_tag_div('phabricator-feed-story-date-separator'));
}
$last_date = $date;
$header = new PHUIActionHeaderView();
$header->setHeaderTitle($date);
$null_view->appendChild($header);
}
try {
$view = $story->renderView();
$view->setUser($user);
$view = $view->render();
} catch (Exception $ex) {
// If rendering failed for any reason, don't fail the entire feed,
// just this one story.
$view = id(new PHUIFeedStoryView())
->setUser($user)
->setChronologicalKey($story->getChronologicalKey())
->setEpoch($story->getEpoch())
->setTitle(
pht('Feed Story Failed to Render (%s)', get_class($story)))
->appendChild(pht('%s: %s', get_class($ex), $ex->getMessage()));
}
$null_view->appendChild($view);
}
if (empty($stories)) {
$nodatastring = pht('No Stories.');
if ($this->noDataString) {
$nodatastring = $this->noDataString;
}
$view = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NODATA)
->appendChild($nodatastring);
$null_view->appendChild($view);
}
return id(new AphrontNullView())
->appendChild($null_view->render());
}
}