2011-12-18 00:50:37 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorFeedBuilder {
|
|
|
|
|
|
|
|
private $stories;
|
2012-01-30 13:12:15 +01:00
|
|
|
private $framed;
|
2011-12-18 00:50:37 +01:00
|
|
|
|
|
|
|
public function __construct(array $stories) {
|
2012-04-03 21:10:45 +02:00
|
|
|
assert_instances_of($stories, 'PhabricatorFeedStory');
|
2011-12-18 00:50:37 +01:00
|
|
|
$this->stories = $stories;
|
|
|
|
}
|
|
|
|
|
2012-01-30 13:12:15 +01:00
|
|
|
public function setFramed($framed) {
|
|
|
|
$this->framed = $framed;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-12-18 00:50:37 +01:00
|
|
|
public function setUser(PhabricatorUser $user) {
|
|
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 17:22:07 +01:00
|
|
|
require_celerity_resource('phabricator-feed-css');
|
|
|
|
|
|
|
|
$last_date = null;
|
2011-12-18 00:50:37 +01:00
|
|
|
foreach ($stories as $story) {
|
2012-01-30 13:12:15 +01:00
|
|
|
$story->setFramed($this->framed);
|
2011-12-18 00:50:37 +01:00
|
|
|
|
2012-03-28 03:16:59 +02:00
|
|
|
$date = ucfirst(phabricator_relative_date($story->getEpoch(), $user));
|
2011-12-22 17:22:07 +01:00
|
|
|
|
|
|
|
if ($date !== $last_date) {
|
|
|
|
if ($last_date !== null) {
|
|
|
|
$null_view->appendChild(
|
|
|
|
'<div class="phabricator-feed-story-date-separator"></div>');
|
|
|
|
}
|
|
|
|
$last_date = $date;
|
|
|
|
$null_view->appendChild(
|
2013-01-18 03:43:35 +01:00
|
|
|
phutil_tag(
|
2011-12-22 17:22:07 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-feed-story-date',
|
|
|
|
),
|
2013-01-18 03:43:35 +01:00
|
|
|
$date));
|
2011-12-22 17:22:07 +01:00
|
|
|
}
|
|
|
|
|
2011-12-18 00:50:37 +01:00
|
|
|
$view = $story->renderView();
|
2012-12-21 22:59:27 +01:00
|
|
|
$view->setUser($user);
|
2011-12-18 00:50:37 +01:00
|
|
|
|
|
|
|
$null_view->appendChild($view);
|
|
|
|
}
|
|
|
|
|
2011-12-22 17:22:07 +01:00
|
|
|
return id(new AphrontNullView())->appendChild(
|
|
|
|
'<div class="phabricator-feed-frame">'.
|
|
|
|
$null_view->render().
|
|
|
|
'</div>');
|
2011-12-18 00:50:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|