Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/maniphest/view/ManiphestTaskListView.php
12256 views
1
<?php
2
3
final class ManiphestTaskListView extends ManiphestView {
4
5
private $tasks;
6
private $handles;
7
private $showBatchControls;
8
private $noDataString;
9
10
public function setTasks(array $tasks) {
11
assert_instances_of($tasks, 'ManiphestTask');
12
$this->tasks = $tasks;
13
return $this;
14
}
15
16
public function setHandles(array $handles) {
17
assert_instances_of($handles, 'PhabricatorObjectHandle');
18
$this->handles = $handles;
19
return $this;
20
}
21
22
public function setShowBatchControls($show_batch_controls) {
23
$this->showBatchControls = $show_batch_controls;
24
return $this;
25
}
26
27
public function setNoDataString($text) {
28
$this->noDataString = $text;
29
return $this;
30
}
31
32
public function render() {
33
$handles = $this->handles;
34
35
require_celerity_resource('maniphest-task-summary-css');
36
37
$list = new PHUIObjectItemListView();
38
39
if ($this->noDataString) {
40
$list->setNoDataString($this->noDataString);
41
} else {
42
$list->setNoDataString(pht('No tasks.'));
43
}
44
45
$status_map = ManiphestTaskStatus::getTaskStatusMap();
46
$color_map = ManiphestTaskPriority::getColorMap();
47
$priority_map = ManiphestTaskPriority::getTaskPriorityMap();
48
49
if ($this->showBatchControls) {
50
Javelin::initBehavior('maniphest-list-editor');
51
}
52
53
foreach ($this->tasks as $task) {
54
$item = id(new PHUIObjectItemView())
55
->setUser($this->getUser())
56
->setObject($task)
57
->setObjectName('T'.$task->getID())
58
->setHeader($task->getTitle())
59
->setHref('/T'.$task->getID());
60
61
if ($task->getOwnerPHID()) {
62
$owner = $handles[$task->getOwnerPHID()];
63
$item->addByline(pht('Assigned: %s', $owner->renderLink()));
64
}
65
66
$status = $task->getStatus();
67
$pri = idx($priority_map, $task->getPriority());
68
$status_name = idx($status_map, $task->getStatus());
69
$tooltip = pht('%s, %s', $status_name, $pri);
70
71
$icon = ManiphestTaskStatus::getStatusIcon($task->getStatus());
72
$color = idx($color_map, $task->getPriority(), 'grey');
73
if ($task->isClosed()) {
74
$item->setDisabled(true);
75
$color = 'grey';
76
}
77
78
$item->setStatusIcon($icon.' '.$color, $tooltip);
79
80
if ($task->isClosed()) {
81
$closed_epoch = $task->getClosedEpoch();
82
83
// We don't expect a task to be closed without a closed epoch, but
84
// recover if we find one. This can happen with older objects or with
85
// lipsum test data.
86
if (!$closed_epoch) {
87
$closed_epoch = $task->getDateModified();
88
}
89
90
$item->addIcon(
91
'fa-check-square-o grey',
92
phabricator_datetime($closed_epoch, $this->getUser()));
93
} else {
94
$item->addIcon(
95
'none',
96
phabricator_datetime($task->getDateModified(), $this->getUser()));
97
}
98
99
if ($this->showBatchControls) {
100
$item->addSigil('maniphest-task');
101
}
102
103
$subtype = $task->newSubtypeObject();
104
if ($subtype && $subtype->hasTagView()) {
105
$subtype_tag = $subtype->newTagView()
106
->setSlimShady(true);
107
$item->addAttribute($subtype_tag);
108
}
109
110
$project_handles = array_select_keys(
111
$handles,
112
array_reverse($task->getProjectPHIDs()));
113
114
$item->addAttribute(
115
id(new PHUIHandleTagListView())
116
->setLimit(4)
117
->setNoDataString(pht('No Projects'))
118
->setSlim(true)
119
->setHandles($project_handles));
120
121
$item->setMetadata(
122
array(
123
'taskID' => $task->getID(),
124
));
125
126
if ($this->showBatchControls) {
127
$href = new PhutilURI('/maniphest/task/edit/'.$task->getID().'/');
128
$item->addAction(
129
id(new PHUIListItemView())
130
->setIcon('fa-pencil')
131
->addSigil('maniphest-edit-task')
132
->setHref($href));
133
}
134
135
$list->addItem($item);
136
}
137
138
return $list;
139
}
140
141
public static function loadTaskHandles(
142
PhabricatorUser $viewer,
143
array $tasks) {
144
assert_instances_of($tasks, 'ManiphestTask');
145
146
$phids = array();
147
foreach ($tasks as $task) {
148
$assigned_phid = $task->getOwnerPHID();
149
if ($assigned_phid) {
150
$phids[] = $assigned_phid;
151
}
152
foreach ($task->getProjectPHIDs() as $project_phid) {
153
$phids[] = $project_phid;
154
}
155
}
156
157
if (!$phids) {
158
return array();
159
}
160
161
return id(new PhabricatorHandleQuery())
162
->setViewer($viewer)
163
->withPHIDs($phids)
164
->execute();
165
}
166
167
}
168
169