forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorFeedBuilder.php
63 lines (46 loc) · 1.41 KB
/
PhabricatorFeedBuilder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
final class PhabricatorFeedBuilder {
private $stories;
private $framed;
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 buildView() {
if (!$this->user) {
throw new Exception('Call setUser() before buildView()!');
}
$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);
$date = ucfirst(phabricator_relative_date($story->getEpoch(), $user));
if ($date !== $last_date) {
if ($last_date !== null) {
$null_view->appendChild(hsprintf(
'<div class="phabricator-feed-story-date-separator"></div>'));
}
$last_date = $date;
$header = new PhabricatorActionHeaderView();
$header->setHeaderTitle($date);
$null_view->appendChild($header);
}
$view = $story->renderView();
$view->setUser($user);
$null_view->appendChild($view);
}
return id(new AphrontNullView())
->appendChild($null_view->render());
}
}