Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / project / view / PhabricatorProjectUserListView.php
blobdd3e084c6e92624f1dc0ca96dc5af0997aa7a732
1 <?php
3 abstract class PhabricatorProjectUserListView
4 extends AphrontView {
6 private $project;
7 private $userPHIDs;
8 private $limit;
9 private $background;
10 private $showNote;
12 public function setProject(PhabricatorProject $project) {
13 $this->project = $project;
14 return $this;
17 public function getProject() {
18 return $this->project;
21 public function setUserPHIDs(array $user_phids) {
22 $this->userPHIDs = $user_phids;
23 return $this;
26 public function getUserPHIDs() {
27 return $this->userPHIDs;
30 public function setLimit($limit) {
31 $this->limit = $limit;
32 return $this;
35 public function getLimit() {
36 return $this->limit;
39 public function setBackground($color) {
40 $this->background = $color;
41 return $this;
44 public function setShowNote($show) {
45 $this->showNote = $show;
46 return $this;
49 abstract protected function canEditList();
50 abstract protected function getNoDataString();
51 abstract protected function getRemoveURI($phid);
52 abstract protected function getHeaderText();
53 abstract protected function getMembershipNote();
55 public function render() {
56 $viewer = $this->getViewer();
57 $project = $this->getProject();
58 $user_phids = $this->getUserPHIDs();
60 $can_edit = $this->canEditList();
61 $supports_edit = $project->supportsEditMembers();
62 $no_data = $this->getNoDataString();
64 $list = id(new PHUIObjectItemListView())
65 ->setNoDataString($no_data);
67 $limit = $this->getLimit();
68 $is_panel = (bool)$limit;
70 $handles = $viewer->loadHandles($user_phids);
72 // Reorder users in display order. We're going to put the viewer first
73 // if they're a member, then enabled users, then disabled/invalid users.
75 $phid_map = array();
76 foreach ($user_phids as $user_phid) {
77 $handle = $handles[$user_phid];
79 $is_viewer = ($user_phid === $viewer->getPHID());
80 $is_enabled = ($handle->isComplete() && !$handle->isDisabled());
82 // If we're showing the main member list, show oldest to newest. If we're
83 // showing only a slice in a panel, show newest to oldest.
84 if ($limit) {
85 $order_scalar = 1;
86 } else {
87 $order_scalar = -1;
90 $phid_map[$user_phid] = id(new PhutilSortVector())
91 ->addInt($is_viewer ? 0 : 1)
92 ->addInt($is_enabled ? 0 : 1)
93 ->addInt($order_scalar * count($phid_map));
95 $phid_map = msortv($phid_map, 'getSelf');
97 $handles = iterator_to_array($handles);
98 $handles = array_select_keys($handles, array_keys($phid_map));
100 if ($limit) {
101 $handles = array_slice($handles, 0, $limit);
104 foreach ($handles as $user_phid => $handle) {
105 $item = id(new PHUIObjectItemView())
106 ->setHeader($handle->getFullName())
107 ->setHref($handle->getURI())
108 ->setImageURI($handle->getImageURI());
110 if ($handle->isDisabled()) {
111 if ($is_panel) {
112 // Don't show disabled users in the panel view at all.
113 continue;
116 $item
117 ->setDisabled(true)
118 ->addAttribute(pht('Disabled'));
119 } else {
120 $icon = id(new PHUIIconView())
121 ->setIcon($handle->getIcon());
123 $subtitle = $handle->getSubtitle();
125 $item->addAttribute(array($icon, ' ', $subtitle));
128 if ($supports_edit && !$is_panel) {
129 $remove_uri = $this->getRemoveURI($user_phid);
131 $item->addAction(
132 id(new PHUIListItemView())
133 ->setIcon('fa-times')
134 ->setName(pht('Remove'))
135 ->setHref($remove_uri)
136 ->setDisabled(!$can_edit)
137 ->setWorkflow(true));
140 $list->addItem($item);
143 if ($user_phids) {
144 $header_text = pht(
145 '%s (%s)',
146 $this->getHeaderText(),
147 phutil_count($user_phids));
148 } else {
149 $header_text = $this->getHeaderText();
152 $id = $project->getID();
154 $header = id(new PHUIHeaderView())
155 ->setHeader($header_text);
157 if ($limit) {
158 $list->newTailButton()
159 ->setText(pht('View All'))
160 ->setHref("/project/members/{$id}/");
163 $box = id(new PHUIObjectBoxView())
164 ->setHeader($header)
165 ->setObjectList($list);
167 if ($this->showNote) {
168 if ($this->getMembershipNote()) {
169 $info = id(new PHUIInfoView())
170 ->setSeverity(PHUIInfoView::SEVERITY_PLAIN)
171 ->appendChild($this->getMembershipNote());
172 $box->setInfoView($info);
176 if ($this->background) {
177 $box->setBackground($this->background);
180 return $box;