Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / maniphest / view / ManiphestTaskListView.php
blobf9ad9e6046198ff5e79bbc0f0192dccc724080b1
1 <?php
3 final class ManiphestTaskListView extends ManiphestView {
5 private $tasks;
6 private $handles;
7 private $showBatchControls;
8 private $noDataString;
10 public function setTasks(array $tasks) {
11 assert_instances_of($tasks, 'ManiphestTask');
12 $this->tasks = $tasks;
13 return $this;
16 public function setHandles(array $handles) {
17 assert_instances_of($handles, 'PhabricatorObjectHandle');
18 $this->handles = $handles;
19 return $this;
22 public function setShowBatchControls($show_batch_controls) {
23 $this->showBatchControls = $show_batch_controls;
24 return $this;
27 public function setNoDataString($text) {
28 $this->noDataString = $text;
29 return $this;
32 public function render() {
33 $handles = $this->handles;
35 require_celerity_resource('maniphest-task-summary-css');
37 $list = new PHUIObjectItemListView();
39 if ($this->noDataString) {
40 $list->setNoDataString($this->noDataString);
41 } else {
42 $list->setNoDataString(pht('No tasks.'));
45 $status_map = ManiphestTaskStatus::getTaskStatusMap();
46 $color_map = ManiphestTaskPriority::getColorMap();
47 $priority_map = ManiphestTaskPriority::getTaskPriorityMap();
49 if ($this->showBatchControls) {
50 Javelin::initBehavior('maniphest-list-editor');
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());
61 if ($task->getOwnerPHID()) {
62 $owner = $handles[$task->getOwnerPHID()];
63 $item->addByline(pht('Assigned: %s', $owner->renderLink()));
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);
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';
78 $item->setStatusIcon($icon.' '.$color, $tooltip);
80 if ($task->isClosed()) {
81 $closed_epoch = $task->getClosedEpoch();
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();
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()));
99 if ($this->showBatchControls) {
100 $item->addSigil('maniphest-task');
103 $subtype = $task->newSubtypeObject();
104 if ($subtype && $subtype->hasTagView()) {
105 $subtype_tag = $subtype->newTagView()
106 ->setSlimShady(true);
107 $item->addAttribute($subtype_tag);
110 $project_handles = array_select_keys(
111 $handles,
112 array_reverse($task->getProjectPHIDs()));
114 $item->addAttribute(
115 id(new PHUIHandleTagListView())
116 ->setLimit(4)
117 ->setNoDataString(pht('No Projects'))
118 ->setSlim(true)
119 ->setHandles($project_handles));
121 $item->setMetadata(
122 array(
123 'taskID' => $task->getID(),
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));
135 $list->addItem($item);
138 return $list;
141 public static function loadTaskHandles(
142 PhabricatorUser $viewer,
143 array $tasks) {
144 assert_instances_of($tasks, 'ManiphestTask');
146 $phids = array();
147 foreach ($tasks as $task) {
148 $assigned_phid = $task->getOwnerPHID();
149 if ($assigned_phid) {
150 $phids[] = $assigned_phid;
152 foreach ($task->getProjectPHIDs() as $project_phid) {
153 $phids[] = $project_phid;
157 if (!$phids) {
158 return array();
161 return id(new PhabricatorHandleQuery())
162 ->setViewer($viewer)
163 ->withPHIDs($phids)
164 ->execute();