Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / project / menuitem / PhabricatorProjectPointsProfileMenuItem.php
blob20c8d2985beddb7f1d86faa3619e3a0e04c22039
1 <?php
3 final class PhabricatorProjectPointsProfileMenuItem
4 extends PhabricatorProfileMenuItem {
6 const MENUITEMKEY = 'project.points';
8 public function getMenuItemTypeName() {
9 return pht('Project Points');
12 private function getDefaultName() {
13 return pht('Points Bar');
16 public function shouldEnableForObject($object) {
17 $viewer = $this->getViewer();
19 // Only render this element for milestones.
20 if (!$object->isMilestone()) {
21 return false;
24 // Don't show if points aren't configured.
25 if (!ManiphestTaskPoints::getIsEnabled()) {
26 return false;
29 // Points are only available if Maniphest is installed.
30 $class = 'PhabricatorManiphestApplication';
31 if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
32 return false;
35 return true;
38 public function getDisplayName(
39 PhabricatorProfileMenuItemConfiguration $config) {
40 return $this->getDefaultName();
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.')),
55 protected function newMenuItemViewList(
56 PhabricatorProfileMenuItemConfiguration $config) {
57 $viewer = $this->getViewer();
58 $project = $config->getProfileObject();
60 $limit = 250;
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();
71 $error = array();
72 if (count($tasks) > $limit) {
73 $error[] =
74 pht(
75 'Too many tasks (%s).',
76 new PhutilNumber($limit));
79 if (!$tasks) {
80 $error[] = pht('This milestone has no tasks.');
83 $statuses = array();
84 $points_done = 0;
85 $points_total = 0;
86 $no_points = 0;
87 foreach ($tasks as $task) {
88 $points = $task->getPoints();
90 if ($points === null) {
91 $no_points++;
92 continue;
95 if (!$points) {
96 continue;
99 $status = $task->getStatus();
100 if (empty($statuses[$status])) {
101 $statuses[$status] = 0;
103 $statuses[$status] += $points;
105 if (ManiphestTaskStatus::isClosedStatus($status)) {
106 $points_done += $points;
109 $points_total += $points;
112 if ($no_points == count($tasks)) {
113 $error[] = pht('No tasks have points assigned.');
116 if (!$points_total) {
117 $error[] = pht('No tasks have positive points.');
120 $label = pht(
121 '%s of %s %s',
122 new PhutilNumber($points_done),
123 new PhutilNumber($points_total),
124 ManiphestTaskPoints::getPointsLabel());
126 $bar = id(new PHUISegmentBarView())
127 ->setLabel($label);
129 $map = ManiphestTaskStatus::getTaskStatusMap();
130 $statuses = array_select_keys($statuses, array_keys($map));
132 foreach ($statuses as $status => $points) {
133 if (!$points) {
134 continue;
137 if (!ManiphestTaskStatus::isClosedStatus($status)) {
138 continue;
141 $color = ManiphestTaskStatus::getStatusColor($status);
142 if (!$color) {
143 $color = 'sky';
146 $tooltip = pht(
147 '%s %s',
148 new PhutilNumber($points),
149 ManiphestTaskStatus::getTaskStatusName($status));
151 $bar->newSegment()
152 ->setWidth($points / $points_total)
153 ->setColor($color)
154 ->setTooltip($tooltip);
157 if ($error) {
158 $bar->setLabel(head($error));
161 $bar = phutil_tag(
162 'div',
163 array(
164 'class' => 'phui-profile-segment-bar',
166 $bar);
168 $item = $this->newItemView();
170 $item->newProgressBar($bar);
172 return array(
173 $item,