Path: blob/master/src/applications/maniphest/view/ManiphestTaskListView.php
12256 views
<?php12final class ManiphestTaskListView extends ManiphestView {34private $tasks;5private $handles;6private $showBatchControls;7private $noDataString;89public function setTasks(array $tasks) {10assert_instances_of($tasks, 'ManiphestTask');11$this->tasks = $tasks;12return $this;13}1415public function setHandles(array $handles) {16assert_instances_of($handles, 'PhabricatorObjectHandle');17$this->handles = $handles;18return $this;19}2021public function setShowBatchControls($show_batch_controls) {22$this->showBatchControls = $show_batch_controls;23return $this;24}2526public function setNoDataString($text) {27$this->noDataString = $text;28return $this;29}3031public function render() {32$handles = $this->handles;3334require_celerity_resource('maniphest-task-summary-css');3536$list = new PHUIObjectItemListView();3738if ($this->noDataString) {39$list->setNoDataString($this->noDataString);40} else {41$list->setNoDataString(pht('No tasks.'));42}4344$status_map = ManiphestTaskStatus::getTaskStatusMap();45$color_map = ManiphestTaskPriority::getColorMap();46$priority_map = ManiphestTaskPriority::getTaskPriorityMap();4748if ($this->showBatchControls) {49Javelin::initBehavior('maniphest-list-editor');50}5152foreach ($this->tasks as $task) {53$item = id(new PHUIObjectItemView())54->setUser($this->getUser())55->setObject($task)56->setObjectName('T'.$task->getID())57->setHeader($task->getTitle())58->setHref('/T'.$task->getID());5960if ($task->getOwnerPHID()) {61$owner = $handles[$task->getOwnerPHID()];62$item->addByline(pht('Assigned: %s', $owner->renderLink()));63}6465$status = $task->getStatus();66$pri = idx($priority_map, $task->getPriority());67$status_name = idx($status_map, $task->getStatus());68$tooltip = pht('%s, %s', $status_name, $pri);6970$icon = ManiphestTaskStatus::getStatusIcon($task->getStatus());71$color = idx($color_map, $task->getPriority(), 'grey');72if ($task->isClosed()) {73$item->setDisabled(true);74$color = 'grey';75}7677$item->setStatusIcon($icon.' '.$color, $tooltip);7879if ($task->isClosed()) {80$closed_epoch = $task->getClosedEpoch();8182// We don't expect a task to be closed without a closed epoch, but83// recover if we find one. This can happen with older objects or with84// lipsum test data.85if (!$closed_epoch) {86$closed_epoch = $task->getDateModified();87}8889$item->addIcon(90'fa-check-square-o grey',91phabricator_datetime($closed_epoch, $this->getUser()));92} else {93$item->addIcon(94'none',95phabricator_datetime($task->getDateModified(), $this->getUser()));96}9798if ($this->showBatchControls) {99$item->addSigil('maniphest-task');100}101102$subtype = $task->newSubtypeObject();103if ($subtype && $subtype->hasTagView()) {104$subtype_tag = $subtype->newTagView()105->setSlimShady(true);106$item->addAttribute($subtype_tag);107}108109$project_handles = array_select_keys(110$handles,111array_reverse($task->getProjectPHIDs()));112113$item->addAttribute(114id(new PHUIHandleTagListView())115->setLimit(4)116->setNoDataString(pht('No Projects'))117->setSlim(true)118->setHandles($project_handles));119120$item->setMetadata(121array(122'taskID' => $task->getID(),123));124125if ($this->showBatchControls) {126$href = new PhutilURI('/maniphest/task/edit/'.$task->getID().'/');127$item->addAction(128id(new PHUIListItemView())129->setIcon('fa-pencil')130->addSigil('maniphest-edit-task')131->setHref($href));132}133134$list->addItem($item);135}136137return $list;138}139140public static function loadTaskHandles(141PhabricatorUser $viewer,142array $tasks) {143assert_instances_of($tasks, 'ManiphestTask');144145$phids = array();146foreach ($tasks as $task) {147$assigned_phid = $task->getOwnerPHID();148if ($assigned_phid) {149$phids[] = $assigned_phid;150}151foreach ($task->getProjectPHIDs() as $project_phid) {152$phids[] = $project_phid;153}154}155156if (!$phids) {157return array();158}159160return id(new PhabricatorHandleQuery())161->setViewer($viewer)162->withPHIDs($phids)163->execute();164}165166}167168169