2011-12-17 15:50:37 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorFeedBuilder {
|
|
|
|
|
|
|
|
private $stories;
|
2012-01-30 04:12:15 -08:00
|
|
|
private $framed;
|
2013-08-14 13:20:25 -07:00
|
|
|
private $hovercards = false;
|
2011-12-17 15:50:37 -08:00
|
|
|
|
|
|
|
public function __construct(array $stories) {
|
2012-04-03 12:10:45 -07:00
|
|
|
assert_instances_of($stories, 'PhabricatorFeedStory');
|
2011-12-17 15:50:37 -08:00
|
|
|
$this->stories = $stories;
|
|
|
|
}
|
|
|
|
|
2012-01-30 04:12:15 -08:00
|
|
|
public function setFramed($framed) {
|
|
|
|
$this->framed = $framed;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-12-17 15:50:37 -08:00
|
|
|
public function setUser(PhabricatorUser $user) {
|
|
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-08-14 13:20:25 -07:00
|
|
|
public function setShowHovercards($hover) {
|
|
|
|
$this->hovercards = $hover;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-12-17 15:50:37 -08:00
|
|
|
public function buildView() {
|
|
|
|
if (!$this->user) {
|
|
|
|
throw new Exception('Call setUser() before buildView()!');
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = $this->user;
|
|
|
|
$stories = $this->stories;
|
|
|
|
|
|
|
|
$null_view = new AphrontNullView();
|
|
|
|
|
2011-12-22 08:22:07 -08:00
|
|
|
require_celerity_resource('phabricator-feed-css');
|
|
|
|
|
|
|
|
$last_date = null;
|
2011-12-17 15:50:37 -08:00
|
|
|
foreach ($stories as $story) {
|
2012-01-30 04:12:15 -08:00
|
|
|
$story->setFramed($this->framed);
|
2013-08-14 13:20:25 -07:00
|
|
|
$story->setHovercard($this->hovercards);
|
2011-12-17 15:50:37 -08:00
|
|
|
|
2012-03-27 18:16:59 -07:00
|
|
|
$date = ucfirst(phabricator_relative_date($story->getEpoch(), $user));
|
2011-12-22 08:22:07 -08:00
|
|
|
|
|
|
|
if ($date !== $last_date) {
|
|
|
|
if ($last_date !== null) {
|
2013-11-11 09:23:23 -08:00
|
|
|
$null_view->appendChild(
|
|
|
|
phutil_tag_div('phabricator-feed-story-date-separator'));
|
2011-12-22 08:22:07 -08:00
|
|
|
}
|
|
|
|
$last_date = $date;
|
2013-04-13 09:09:42 -07:00
|
|
|
$header = new PhabricatorActionHeaderView();
|
|
|
|
$header->setHeaderTitle($date);
|
|
|
|
|
|
|
|
$null_view->appendChild($header);
|
2011-12-22 08:22:07 -08:00
|
|
|
}
|
|
|
|
|
2011-12-17 15:50:37 -08:00
|
|
|
$view = $story->renderView();
|
2012-12-21 13:59:27 -08:00
|
|
|
$view->setUser($user);
|
2011-12-17 15:50:37 -08:00
|
|
|
|
|
|
|
$null_view->appendChild($view);
|
|
|
|
}
|
|
|
|
|
2013-04-15 13:07:54 -07:00
|
|
|
return id(new AphrontNullView())
|
|
|
|
->appendChild($null_view->render());
|
2011-12-17 15:50:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|