Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / badges / controller / PhabricatorBadgesViewController.php
bloba5390ea5f452b035f3bd6968cbd1d684ac609255
1 <?php
3 final class PhabricatorBadgesViewController
4 extends PhabricatorBadgesProfileController {
6 public function shouldAllowPublic() {
7 return true;
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $request->getViewer();
12 $id = $request->getURIData('id');
14 $badge = id(new PhabricatorBadgesQuery())
15 ->setViewer($viewer)
16 ->withIDs(array($id))
17 ->executeOne();
18 if (!$badge) {
19 return new Aphront404Response();
22 $this->setBadge($badge);
24 $crumbs = $this->buildApplicationCrumbs();
25 $title = $badge->getName();
27 $header = $this->buildHeaderView();
28 $curtain = $this->buildCurtain($badge);
29 $details = $this->buildDetailsView($badge);
31 $timeline = $this->buildTransactionTimeline(
32 $badge,
33 new PhabricatorBadgesTransactionQuery());
35 $comment_view = id(new PhabricatorBadgesEditEngine())
36 ->setViewer($viewer)
37 ->buildEditEngineCommentView($badge);
39 $view = id(new PHUITwoColumnView())
40 ->setHeader($header)
41 ->setCurtain($curtain)
42 ->setMainColumn(array(
43 $timeline,
44 $comment_view,
46 ->addPropertySection(pht('Description'), $details);
48 $navigation = $this->buildSideNavView('view');
50 return $this->newPage()
51 ->setTitle($title)
52 ->setCrumbs($crumbs)
53 ->setPageObjectPHIDs(array($badge->getPHID()))
54 ->setNavigation($navigation)
55 ->appendChild($view);
58 private function buildDetailsView(
59 PhabricatorBadgesBadge $badge) {
60 $viewer = $this->getViewer();
62 $view = id(new PHUIPropertyListView())
63 ->setUser($viewer);
65 $description = $badge->getDescription();
66 if (strlen($description)) {
67 $view->addTextContent(
68 new PHUIRemarkupView($viewer, $description));
71 $badge = id(new PHUIBadgeView())
72 ->setIcon($badge->getIcon())
73 ->setHeader($badge->getName())
74 ->setSubhead($badge->getFlavor())
75 ->setQuality($badge->getQuality());
77 $view->addTextContent($badge);
79 return $view;
82 private function buildCurtain(PhabricatorBadgesBadge $badge) {
83 $viewer = $this->getViewer();
85 $can_edit = PhabricatorPolicyFilter::hasCapability(
86 $viewer,
87 $badge,
88 PhabricatorPolicyCapability::CAN_EDIT);
90 $id = $badge->getID();
91 $edit_uri = $this->getApplicationURI("/edit/{$id}/");
92 $archive_uri = $this->getApplicationURI("/archive/{$id}/");
94 $curtain = $this->newCurtainView($badge);
96 $curtain->addAction(
97 id(new PhabricatorActionView())
98 ->setName(pht('Edit Badge'))
99 ->setIcon('fa-pencil')
100 ->setDisabled(!$can_edit)
101 ->setHref($edit_uri));
103 if ($badge->isArchived()) {
104 $curtain->addAction(
105 id(new PhabricatorActionView())
106 ->setName(pht('Activate Badge'))
107 ->setIcon('fa-check')
108 ->setDisabled(!$can_edit)
109 ->setWorkflow($can_edit)
110 ->setHref($archive_uri));
111 } else {
112 $curtain->addAction(
113 id(new PhabricatorActionView())
114 ->setName(pht('Archive Badge'))
115 ->setIcon('fa-ban')
116 ->setDisabled(!$can_edit)
117 ->setWorkflow($can_edit)
118 ->setHref($archive_uri));
121 return $curtain;