forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhragmentBrowseController.php
97 lines (83 loc) · 2.67 KB
/
PhragmentBrowseController.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
final class PhragmentBrowseController extends PhragmentController {
private $dblob;
public function shouldAllowPublic() {
return true;
}
public function willProcessRequest(array $data) {
$this->dblob = idx($data, "dblob", "");
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$parents = $this->loadParentFragments($this->dblob);
if ($parents === null) {
return new Aphront404Response();
}
$current = nonempty(last($parents), null);
$path = '';
if ($current !== null) {
$path = $current->getPath();
}
$crumbs = $this->buildApplicationCrumbsWithPath($parents);
if ($this->hasApplicationCapability(
PhragmentCapabilityCanCreate::CAPABILITY)) {
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('Create Fragment'))
->setHref($this->getApplicationURI('/create/'.$path))
->setIcon('create'));
}
$current_box = $this->createCurrentFragmentView($current, false);
$list = id(new PHUIObjectItemListView())
->setUser($viewer);
$fragments = null;
if ($current === null) {
// Find all root fragments.
$fragments = id(new PhragmentFragmentQuery())
->setViewer($this->getRequest()->getUser())
->needLatestVersion(true)
->withDepths(array(1))
->execute();
} else {
// Find all child fragments.
$fragments = id(new PhragmentFragmentQuery())
->setViewer($this->getRequest()->getUser())
->needLatestVersion(true)
->withLeadingPath($current->getPath().'/')
->withDepths(array($current->getDepth() + 1))
->execute();
}
foreach ($fragments as $fragment) {
$item = id(new PHUIObjectItemView());
$item->setHeader($fragment->getName());
$item->setHref($fragment->getURI());
if (!$fragment->isDirectory()) {
$item->addAttribute(pht(
'Last Updated %s',
phabricator_datetime(
$fragment->getLatestVersion()->getDateCreated(),
$viewer)));
$item->addAttribute(pht(
'Latest Version %s',
$fragment->getLatestVersion()->getSequence()));
if ($fragment->isDeleted()) {
$item->setDisabled(true);
$item->addAttribute(pht('Deleted'));
}
} else {
$item->addAttribute('Directory');
}
$list->addItem($item);
}
return $this->buildApplicationPage(
array(
$crumbs,
$this->renderConfigurationWarningIfRequired(),
$current_box,
$list),
array(
'title' => pht('Browse Fragments'),
'device' => true));
}
}