@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 177 lines 4.1 kB view raw
1<?php 2 3final class PhabricatorProjectPointsProfileMenuItem 4 extends PhabricatorProfileMenuItem { 5 6 const MENUITEMKEY = 'project.points'; 7 8 public function getMenuItemTypeName() { 9 return pht('Project Points'); 10 } 11 12 private function getDefaultName() { 13 return pht('Points Bar'); 14 } 15 16 public function shouldEnableForObject($object) { 17 $viewer = $this->getViewer(); 18 19 // Only render this element for milestones. 20 if (!$object->isMilestone()) { 21 return false; 22 } 23 24 // Don't show if points aren't configured. 25 if (!ManiphestTaskPoints::getIsEnabled()) { 26 return false; 27 } 28 29 // Points are only available if Maniphest is enabled. 30 $class = PhabricatorManiphestApplication::class; 31 if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { 32 return false; 33 } 34 35 return true; 36 } 37 38 public function getDisplayName( 39 PhabricatorProfileMenuItemConfiguration $config) { 40 return $this->getDefaultName(); 41 } 42 43 public function buildEditEngineFields( 44 PhabricatorProfileMenuItemConfiguration $config) { 45 return array( 46 id(new PhabricatorInstructionsEditField()) 47 ->setValue( 48 pht( 49 'This is a progress bar which shows how many points of work '. 50 'are complete within the milestone. It has no configurable '. 51 'settings.')), 52 ); 53 } 54 55 protected function newMenuItemViewList( 56 PhabricatorProfileMenuItemConfiguration $config) { 57 $viewer = $this->getViewer(); 58 $project = $config->getProfileObject(); 59 60 $limit = 250; 61 62 $tasks = id(new ManiphestTaskQuery()) 63 ->setViewer($viewer) 64 ->withEdgeLogicPHIDs( 65 PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, 66 PhabricatorQueryConstraint::OPERATOR_AND, 67 array($project->getPHID())) 68 ->setLimit($limit + 1) 69 ->execute(); 70 71 $error = array(); 72 if (count($tasks) > $limit) { 73 $error[] = 74 pht( 75 'Too many tasks (%s).', 76 new PhutilNumber($limit)); 77 } 78 79 if (!$tasks) { 80 $error[] = pht('This milestone has no tasks.'); 81 } 82 83 $statuses = array(); 84 $points_done = 0; 85 $points_total = 0; 86 $no_points = 0; 87 foreach ($tasks as $task) { 88 $points = $task->getPoints(); 89 90 if ($points === null) { 91 $no_points++; 92 continue; 93 } 94 95 if (!$points) { 96 continue; 97 } 98 99 $status = $task->getStatus(); 100 if (empty($statuses[$status])) { 101 $statuses[$status] = 0; 102 } 103 $statuses[$status] += $points; 104 105 if (ManiphestTaskStatus::isClosedStatus($status)) { 106 $points_done += $points; 107 } 108 109 $points_total += $points; 110 } 111 112 if ($no_points == count($tasks)) { 113 $error[] = pht('No tasks have points assigned.'); 114 } 115 116 if (!$points_total) { 117 $error[] = pht('No tasks have positive points.'); 118 } 119 120 $label = pht( 121 '%s of %s %s', 122 new PhutilNumber($points_done), 123 new PhutilNumber($points_total), 124 ManiphestTaskPoints::getPointsLabel()); 125 126 $bar = id(new PHUISegmentBarView()) 127 ->setLabel($label); 128 129 $map = ManiphestTaskStatus::getTaskStatusMap(); 130 $statuses = array_select_keys($statuses, array_keys($map)); 131 132 foreach ($statuses as $status => $points) { 133 if (!$points) { 134 continue; 135 } 136 137 if (!ManiphestTaskStatus::isClosedStatus($status)) { 138 continue; 139 } 140 141 $color = ManiphestTaskStatus::getStatusColor($status); 142 if (!$color) { 143 $color = 'sky'; 144 } 145 146 $tooltip = pht( 147 '%s %s', 148 new PhutilNumber($points), 149 ManiphestTaskStatus::getTaskStatusName($status)); 150 151 $bar->newSegment() 152 ->setWidth($points / $points_total) 153 ->setColor($color) 154 ->setTooltip($tooltip); 155 } 156 157 if ($error) { 158 $bar->setLabel(head($error)); 159 } 160 161 $bar = phutil_tag( 162 'div', 163 array( 164 'class' => 'phui-profile-segment-bar', 165 ), 166 $bar); 167 168 $item = $this->newItemView(); 169 170 $item->newProgressBar($bar); 171 172 return array( 173 $item, 174 ); 175 } 176 177}