Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / project / view / ProjectBoardTaskCard.php
blobd102ac1b11085d78b66f90ecbd37e8369427ff40
1 <?php
3 final class ProjectBoardTaskCard extends Phobject {
5 private $viewer;
6 private $projectHandles;
7 private $task;
8 private $owner;
9 private $showEditControls;
10 private $canEdit;
11 private $coverImageFile;
12 private $hideArchivedProjects;
14 public function setViewer(PhabricatorUser $viewer) {
15 $this->viewer = $viewer;
16 return $this;
18 public function getViewer() {
19 return $this->viewer;
22 public function setProjectHandles(array $handles) {
23 $this->projectHandles = $handles;
24 return $this;
27 public function getProjectHandles() {
28 return $this->projectHandles;
31 public function setCoverImageFile(PhabricatorFile $cover_image_file) {
32 $this->coverImageFile = $cover_image_file;
33 return $this;
36 public function getCoverImageFile() {
37 return $this->coverImageFile;
40 public function setHideArchivedProjects($hide_archived_projects) {
41 $this->hideArchivedProjects = $hide_archived_projects;
42 return $this;
45 public function getHideArchivedProjects() {
46 return $this->hideArchivedProjects;
49 public function setTask(ManiphestTask $task) {
50 $this->task = $task;
51 return $this;
53 public function getTask() {
54 return $this->task;
57 public function setOwner(PhabricatorObjectHandle $owner = null) {
58 $this->owner = $owner;
59 return $this;
61 public function getOwner() {
62 return $this->owner;
65 public function setCanEdit($can_edit) {
66 $this->canEdit = $can_edit;
67 return $this;
70 public function getCanEdit() {
71 return $this->canEdit;
74 public function setShowEditControls($show_edit_controls) {
75 $this->showEditControls = $show_edit_controls;
76 return $this;
79 public function getShowEditControls() {
80 return $this->showEditControls;
83 public function getItem() {
84 $task = $this->getTask();
85 $owner = $this->getOwner();
86 $can_edit = $this->getCanEdit();
87 $viewer = $this->getViewer();
89 $color_map = ManiphestTaskPriority::getColorMap();
90 $bar_color = idx($color_map, $task->getPriority(), 'grey');
92 $card = id(new PHUIObjectItemView())
93 ->setObject($task)
94 ->setUser($viewer)
95 ->setObjectName($task->getMonogram())
96 ->setHeader($task->getTitle())
97 ->setHref($task->getURI())
98 ->addSigil('project-card')
99 ->setDisabled($task->isClosed())
100 ->setBarColor($bar_color);
102 if ($this->getShowEditControls()) {
103 if ($can_edit) {
104 $card
105 ->addSigil('draggable-card')
106 ->addClass('draggable-card');
107 $edit_icon = 'fa-pencil';
108 } else {
109 $card
110 ->addClass('not-editable')
111 ->addClass('undraggable-card');
112 $edit_icon = 'fa-lock red';
115 $card->addAction(
116 id(new PHUIListItemView())
117 ->setName(pht('Edit'))
118 ->setIcon($edit_icon)
119 ->addSigil('edit-project-card')
120 ->setHref('/maniphest/task/edit/'.$task->getID().'/'));
123 if ($owner) {
124 $card->addHandleIcon($owner, $owner->getName());
127 $cover_file = $this->getCoverImageFile();
128 if ($cover_file) {
129 $card->setCoverImage($cover_file->getBestURI());
132 if (ManiphestTaskPoints::getIsEnabled()) {
133 $points = $task->getPoints();
134 if ($points !== null) {
135 $points_tag = id(new PHUITagView())
136 ->setType(PHUITagView::TYPE_SHADE)
137 ->setColor(PHUITagView::COLOR_GREY)
138 ->setSlimShady(true)
139 ->setName($points)
140 ->addClass('phui-workcard-points');
141 $card->addAttribute($points_tag);
145 $subtype = $task->newSubtypeObject();
146 if ($subtype && $subtype->hasTagView()) {
147 $subtype_tag = $subtype->newTagView()
148 ->setSlimShady(true);
149 $card->addAttribute($subtype_tag);
152 if ($task->isClosed()) {
153 $icon = ManiphestTaskStatus::getStatusIcon($task->getStatus());
154 $icon = id(new PHUIIconView())
155 ->setIcon($icon.' grey');
156 $card->addAttribute($icon);
157 $card->setBarColor('grey');
160 $project_handles = $this->getProjectHandles();
162 // Remove any archived projects from the list.
163 if ($this->hideArchivedProjects) {
164 if ($project_handles) {
165 foreach ($project_handles as $key => $handle) {
166 if ($handle->getStatus() == PhabricatorObjectHandle::STATUS_CLOSED) {
167 unset($project_handles[$key]);
173 if ($project_handles) {
174 $project_handles = array_reverse($project_handles);
175 $tag_list = id(new PHUIHandleTagListView())
176 ->setSlim(true)
177 ->setHandles($project_handles);
178 $card->addAttribute($tag_list);
181 $card->addClass('phui-workcard');
183 return $card;