@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorProjectListView extends AphrontView {
4
5 private $projects;
6 private $showMember;
7 private $showWatching;
8 private $noDataString;
9
10 public function setProjects(array $projects) {
11 $this->projects = $projects;
12 return $this;
13 }
14
15 public function getProjects() {
16 return $this->projects;
17 }
18
19 public function setShowWatching($watching) {
20 $this->showWatching = $watching;
21 return $this;
22 }
23
24 public function setShowMember($member) {
25 $this->showMember = $member;
26 return $this;
27 }
28
29 public function setNoDataString($text) {
30 $this->noDataString = $text;
31 return $this;
32 }
33
34 public function renderList() {
35 $viewer = $this->getUser();
36 $viewer_phid = $viewer->getPHID();
37 $projects = $this->getProjects();
38
39 $handles = $viewer->loadHandles(mpull($projects, 'getPHID'));
40
41 $no_data = pht('No projects found.');
42 if ($this->noDataString) {
43 $no_data = $this->noDataString;
44 }
45
46 $list = id(new PHUIObjectItemListView())
47 ->setViewer($viewer)
48 ->setNoDataString($no_data);
49
50 foreach ($projects as $key => $project) {
51 $id = $project->getID();
52
53 $icon = $project->getDisplayIconIcon();
54 $icon_icon = id(new PHUIIconView())
55 ->setIcon($icon);
56
57 $icon_name = $project->getDisplayIconName();
58
59 $item = id(new PHUIObjectItemView())
60 ->setObject($project)
61 ->setHeader($project->getName())
62 ->setHref("/project/view/{$id}/")
63 ->setImageURI($project->getProfileImageURI())
64 ->addAttribute(
65 array(
66 $icon_icon,
67 ' ',
68 $icon_name,
69 ));
70
71 if ($project->getStatus() == PhabricatorProjectStatus::STATUS_ARCHIVED) {
72 $item->addIcon('fa-ban', pht('Archived'));
73 $item->setDisabled(true);
74 }
75
76 if ($this->showMember) {
77 $is_member = $project->isUserMember($viewer_phid);
78 if ($is_member) {
79 $item->addIcon('fa-user', pht('Member'));
80 }
81 }
82
83 if ($this->showWatching) {
84 $is_watcher = $project->isUserWatcher($viewer_phid);
85 if ($is_watcher) {
86 $item->addIcon('fa-eye', pht('Watching'));
87 }
88 }
89
90 $subtype = $project->newSubtypeObject();
91 if ($subtype && $subtype->hasTagView()) {
92 $subtype_tag = $subtype->newTagView()
93 ->setSlimShady(true);
94 $item->addAttribute($subtype_tag);
95 }
96
97 $list->addItem($item);
98 }
99
100 return $list;
101 }
102
103 public function render() {
104 return $this->renderList();
105 }
106
107}