ProjectBoardTaskCard.php 6.52 KB
Newer Older
1 2
<?php

Joshua Spence's avatar
Joshua Spence committed
3
final class ProjectBoardTaskCard extends Phobject {
4 5

  private $viewer;
6
  private $projectHandles;
7 8
  private $task;
  private $owner;
9
  private $showEditControls;
10
  private $canEdit;
11
  private $coverImageFile;
12
  private $hideArchivedProjects;
13 14 15 16 17 18 19 20 21

  public function setViewer(PhabricatorUser $viewer) {
    $this->viewer = $viewer;
    return $this;
  }
  public function getViewer() {
    return $this->viewer;
  }

22 23
  public function setProjectHandles(array $handles) {
    $this->projectHandles = $handles;
24 25
    return $this;
  }
26 27 28

  public function getProjectHandles() {
    return $this->projectHandles;
29 30
  }

31 32 33 34 35 36 37 38 39
  public function setCoverImageFile(PhabricatorFile $cover_image_file) {
    $this->coverImageFile = $cover_image_file;
    return $this;
  }

  public function getCoverImageFile() {
    return $this->coverImageFile;
  }

40 41 42 43 44 45 46 47 48
  public function setHideArchivedProjects($hide_archived_projects) {
    $this->hideArchivedProjects = $hide_archived_projects;
    return $this;
  }

  public function getHideArchivedProjects() {
    return $this->hideArchivedProjects;
  }

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  public function setTask(ManiphestTask $task) {
    $this->task = $task;
    return $this;
  }
  public function getTask() {
    return $this->task;
  }

  public function setOwner(PhabricatorObjectHandle $owner = null) {
    $this->owner = $owner;
    return $this;
  }
  public function getOwner() {
    return $this->owner;
  }

  public function setCanEdit($can_edit) {
    $this->canEdit = $can_edit;
    return $this;
  }
69

70 71 72 73
  public function getCanEdit() {
    return $this->canEdit;
  }

74 75 76 77 78 79 80 81 82
  public function setShowEditControls($show_edit_controls) {
    $this->showEditControls = $show_edit_controls;
    return $this;
  }

  public function getShowEditControls() {
    return $this->showEditControls;
  }

83 84 85 86
  public function getItem() {
    $task = $this->getTask();
    $owner = $this->getOwner();
    $can_edit = $this->getCanEdit();
87
    $viewer = $this->getViewer();
88 89 90 91 92

    $color_map = ManiphestTaskPriority::getColorMap();
    $bar_color = idx($color_map, $task->getPriority(), 'grey');

    $card = id(new PHUIObjectItemView())
epriestley's avatar
epriestley committed
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 101
      ->setBarColor($bar_color);

102 103 104 105 106 107 108 109 110 111 112 113
    if ($this->getShowEditControls()) {
      if ($can_edit) {
        $card
          ->addSigil('draggable-card')
          ->addClass('draggable-card');
        $edit_icon = 'fa-pencil';
      } else {
        $card
          ->addClass('not-editable')
          ->addClass('undraggable-card');
        $edit_icon = 'fa-lock red';
      }
114

115 116 117 118 119 120 121
      $card->addAction(
        id(new PHUIListItemView())
          ->setName(pht('Edit'))
          ->setIcon($edit_icon)
          ->addSigil('edit-project-card')
          ->setHref('/maniphest/task/edit/'.$task->getID().'/'));
    }
122 123

    if ($owner) {
124
      $card->addHandleIcon($owner, $owner->getName());
125 126
    }

127 128 129 130 131
    $cover_file = $this->getCoverImageFile();
    if ($cover_file) {
      $card->setCoverImage($cover_file->getBestURI());
    }

epriestley's avatar
epriestley committed
132 133 134 135 136
    if (ManiphestTaskPoints::getIsEnabled()) {
      $points = $task->getPoints();
      if ($points !== null) {
        $points_tag = id(new PHUITagView())
          ->setType(PHUITagView::TYPE_SHADE)
137
          ->setColor(PHUITagView::COLOR_GREY)
138
          ->setSlimShady(true)
139 140
          ->setName($points)
          ->addClass('phui-workcard-points');
epriestley's avatar
epriestley committed
141 142 143 144
        $card->addAttribute($points_tag);
      }
    }

145 146 147 148 149 150 151
    $subtype = $task->newSubtypeObject();
    if ($subtype && $subtype->hasTagView()) {
      $subtype_tag = $subtype->newTagView()
        ->setSlimShady(true);
      $card->addAttribute($subtype_tag);
    }

152 153 154 155 156 157
    $status = $task->getStatus();
    $status_icon = ManiphestTaskStatus::getStatusIcon($status);
    if (ManiphestTaskStatus::isClosedStatus($status)) {
      $status_color = 'grey';
    } else {
      $status_color = 'dark';
158
    }
159
    $card->setStatusIcon($status_icon.' '.$status_color);
160

161 162 163 164 165 166 167 168 169
    $review_status = $task->getReviewIcon($viewer);
    if ($review_status) {
      $review_tag = id(new PHUITagView())
        ->setType(PHUITagView::TYPE_OBJECT)
        ->setBackgroundColor(null)
        ->setIcon($review_status);
      $card->addAttribute($review_tag);
    }

170
    $project_handles = $this->getProjectHandles();
171

172 173 174 175 176 177 178
    // Remove any archived or hidden projects from the list.
    if ($project_handles) {
      foreach ($project_handles as $key => $handle) {
        if ($handle->getPolicyFiltered() ||
	    ($this->hideArchivedProjects &&
	     $handle->getStatus() == PhabricatorObjectHandle::STATUS_CLOSED)) {
          unset($project_handles[$key]);
179 180 181 182
        }
      }
    }

183
    if ($project_handles) {
184
      $project_handles = array_reverse($project_handles);
epriestley's avatar
epriestley committed
185 186
      $tag_list = id(new PHUIHandleTagListView())
        ->setSlim(true)
187
        ->setHandles($project_handles);
188 189 190
      $card->addAttribute($tag_list);
    }

191 192
    $card->addClass('phui-workcard');

193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
    // CCU: display the RAG indicator and progress bar in the task card
    $rag_status = $task->getRAGStatus();
    if ($rag_status) {
      $rag_icon = id(new PHUITagView())
        ->setType(PHUITagView::TYPE_OBJECT)
        ->setBackgroundColor(null)
        ->setIcon('fa-circle ' . $rag_status);
      $card->addAttribute($rag_icon);

      $task_progress = $task->getTaskProgress($viewer);
      if ($task_progress['total_points'] > 0) {
        $bar = id(new PHUISegmentBarView())
          ->setLabel(pht(
            'Progress: %s/%s points',
            new PhutilNumber($task_progress['completed_points']),
            new PhutilNumber($task_progress['total_points'])
          ));

        $bar->newSegment()
          ->setWidth($task_progress['completed_points'] / $task_progress['total_points'])
          ->setColor('blue')
          ->setTooltip(pht(
            '%s/%s complete',
            new PhutilNumber($task_progress['completed_points']),
            new PhutilNumber($task_progress['total_points']))
          );

          $bar->newSegment()
          ->setWidth($task_progress['in_progress'] / $task_progress['total_points'])
          ->setColor('lightblue')
          ->setTooltip(pht(
            '%s/%s in progress',
            new PhutilNumber($task_progress['in_progress']),
            new PhutilNumber($task_progress['total_points']))
          );

        $bar = phutil_tag(
          'div',
          array(
            'class' => 'phui-profile-segment-bar',
          ),
          $bar);
        $card->addAttribute($bar);
      }
    }


240 241 242 243
    return $card;
  }

}