Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/feed/builder/PhabricatorFeedBuilder.php
12241 views
1
<?php
2
3
final class PhabricatorFeedBuilder extends Phobject {
4
5
private $user;
6
private $stories;
7
private $hovercards = false;
8
private $noDataString;
9
10
public function __construct(array $stories) {
11
assert_instances_of($stories, 'PhabricatorFeedStory');
12
$this->stories = $stories;
13
}
14
15
public function setUser(PhabricatorUser $user) {
16
$this->user = $user;
17
return $this;
18
}
19
20
public function setShowHovercards($hover) {
21
$this->hovercards = $hover;
22
return $this;
23
}
24
25
public function setNoDataString($string) {
26
$this->noDataString = $string;
27
return $this;
28
}
29
30
public function buildView() {
31
if (!$this->user) {
32
throw new PhutilInvalidStateException('setUser');
33
}
34
35
$user = $this->user;
36
$stories = $this->stories;
37
38
$null_view = new AphrontNullView();
39
40
require_celerity_resource('phabricator-feed-css');
41
42
$last_date = null;
43
foreach ($stories as $story) {
44
$story->setHovercard($this->hovercards);
45
46
$date = ucfirst(phabricator_relative_date($story->getEpoch(), $user));
47
48
if ($date !== $last_date) {
49
if ($last_date !== null) {
50
$null_view->appendChild(
51
phutil_tag_div('phabricator-feed-story-date-separator'));
52
}
53
$last_date = $date;
54
$header = new PHUIHeaderView();
55
$header->setHeader($date);
56
$header->setHeaderIcon('fa-calendar msr');
57
58
$null_view->appendChild($header);
59
}
60
61
try {
62
$view = $story->renderView();
63
$view->setUser($user);
64
$view = $view->render();
65
} catch (Exception $ex) {
66
// If rendering failed for any reason, don't fail the entire feed,
67
// just this one story.
68
$view = id(new PHUIFeedStoryView())
69
->setUser($user)
70
->setChronologicalKey($story->getChronologicalKey())
71
->setEpoch($story->getEpoch())
72
->setTitle(
73
pht('Feed Story Failed to Render (%s)', get_class($story)))
74
->appendChild(pht('%s: %s', get_class($ex), $ex->getMessage()));
75
}
76
77
$null_view->appendChild($view);
78
}
79
80
$box = id(new PHUIObjectBoxView())
81
->appendChild($null_view);
82
83
if (empty($stories)) {
84
$nodatastring = pht('No Stories.');
85
if ($this->noDataString) {
86
$nodatastring = $this->noDataString;
87
}
88
89
$view = id(new PHUIBoxView())
90
->addClass('mlt mlb msr msl')
91
->appendChild($nodatastring);
92
$box->appendChild($view);
93
}
94
95
return $box;
96
97
}
98
99
}
100
101