@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 ProjectBoardTaskCard extends Phobject {
4
5 private $viewer;
6 private $projectHandles;
7 private $task;
8 private $owner;
9 private $showEditControls;
10 private $canEdit;
11 private $coverImageFile;
12 private $hideArchivedProjects;
13
14 public function setViewer(PhabricatorUser $viewer) {
15 $this->viewer = $viewer;
16 return $this;
17 }
18 public function getViewer() {
19 return $this->viewer;
20 }
21
22 public function setProjectHandles(array $handles) {
23 $this->projectHandles = $handles;
24 return $this;
25 }
26
27 public function getProjectHandles() {
28 return $this->projectHandles;
29 }
30
31 public function setCoverImageFile(PhabricatorFile $cover_image_file) {
32 $this->coverImageFile = $cover_image_file;
33 return $this;
34 }
35
36 public function getCoverImageFile() {
37 return $this->coverImageFile;
38 }
39
40 public function setHideArchivedProjects($hide_archived_projects) {
41 $this->hideArchivedProjects = $hide_archived_projects;
42 return $this;
43 }
44
45 public function getHideArchivedProjects() {
46 return $this->hideArchivedProjects;
47 }
48
49 public function setTask(ManiphestTask $task) {
50 $this->task = $task;
51 return $this;
52 }
53 public function getTask() {
54 return $this->task;
55 }
56
57 public function setOwner(?PhabricatorObjectHandle $owner = null) {
58 $this->owner = $owner;
59 return $this;
60 }
61 public function getOwner() {
62 return $this->owner;
63 }
64
65 public function setCanEdit($can_edit) {
66 $this->canEdit = $can_edit;
67 return $this;
68 }
69
70 public function getCanEdit() {
71 return $this->canEdit;
72 }
73
74 public function setShowEditControls($show_edit_controls) {
75 $this->showEditControls = $show_edit_controls;
76 return $this;
77 }
78
79 public function getShowEditControls() {
80 return $this->showEditControls;
81 }
82
83 public function getItem() {
84 $task = $this->getTask();
85 $owner = $this->getOwner();
86 $can_edit = $this->getCanEdit();
87 $viewer = $this->getViewer();
88
89 $color_map = ManiphestTaskPriority::getColorMap();
90 $bar_color = idx($color_map, $task->getPriority(), 'grey');
91
92 $card = id(new PHUIObjectItemView())
93 ->setObject($task)
94 ->setViewer($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);
101
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';
113 }
114
115 $card->addAction(
116 id(new PHUIListItemView())
117 ->setName(pht('Edit'))
118 ->setIcon($edit_icon)
119 ->addSigil('edit-project-card')
120 ->setAriaLabel(pht('Edit Task'))
121 ->setHref('/maniphest/task/edit/'.$task->getID().'/'));
122 }
123
124 if ($owner) {
125 $card->addHandleIcon($owner, $owner->getName());
126 }
127
128 $cover_file = $this->getCoverImageFile();
129 if ($cover_file) {
130 $card->setCoverImage($cover_file->getBestURI());
131 }
132
133 if (ManiphestTaskPoints::getIsEnabled()) {
134 $points = $task->getPoints();
135 if ($points !== null) {
136 $points_tag = id(new PHUITagView())
137 ->setType(PHUITagView::TYPE_SHADE)
138 ->setColor(PHUITagView::COLOR_GREY)
139 ->setSlimShady(true)
140 ->setName($points)
141 ->addClass('phui-workcard-points');
142 $card->addAttribute($points_tag);
143 }
144 }
145
146 $subtype = $task->newSubtypeObject();
147 if ($subtype && $subtype->hasTagView()) {
148 $subtype_tag = $subtype->newTagView()
149 ->setSlimShady(true);
150 $card->addAttribute($subtype_tag);
151 }
152
153 if ($task->isClosed()) {
154 $icon = ManiphestTaskStatus::getStatusIcon($task->getStatus());
155 $icon = id(new PHUIIconView())
156 ->setIcon($icon.' grey');
157 $card->addAttribute($icon);
158 $card->setBarColor('grey');
159 }
160
161 $project_handles = $this->getProjectHandles();
162
163 // Remove any archived projects from the list.
164 if ($this->hideArchivedProjects) {
165 if ($project_handles) {
166 foreach ($project_handles as $key => $handle) {
167 if ($handle->getStatus() == PhabricatorObjectHandle::STATUS_CLOSED) {
168 unset($project_handles[$key]);
169 }
170 }
171 }
172 }
173
174 if ($project_handles) {
175 $project_handles = array_reverse($project_handles);
176 $tag_list = id(new PHUIHandleTagListView())
177 ->setSlim(true)
178 ->setHandles($project_handles);
179 $card->addAttribute($tag_list);
180 }
181
182 $card->addClass('phui-workcard');
183
184 return $card;
185 }
186
187}