@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<?php
2
3final class AphrontProgressBarView extends AphrontBarView {
4
5 const WIDTH = 100;
6
7 private $value;
8 private $max = 100;
9 private $alt = '';
10
11 protected function getDefaultColor() {
12 return parent::COLOR_AUTO_BADNESS;
13 }
14
15 public function setValue($value) {
16 $this->value = $value;
17 return $this;
18 }
19
20 public function setMax($max) {
21 $this->max = $max;
22 return $this;
23 }
24
25 public function setAlt($text) {
26 $this->alt = $text;
27 return $this;
28 }
29
30 protected function getRatio() {
31 return min($this->value, $this->max) / $this->max;
32 }
33
34 public function render() {
35 require_celerity_resource('aphront-bars');
36 $ratio = $this->getRatio();
37 $width = self::WIDTH * $ratio;
38
39 $color = $this->getColor();
40
41 return phutil_tag_div(
42 "aphront-bar progress color-{$color}",
43 array(
44 phutil_tag(
45 'div',
46 array('title' => $this->alt),
47 phutil_tag(
48 'div',
49 array('style' => "width: {$width}px;"),
50 '')),
51 phutil_tag(
52 'span',
53 array(),
54 $this->getCaption()),
55 ));
56 }
57
58}