[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class AphrontGlyphBarView extends AphrontBarView { 4 5 const BLACK_STAR = "\xE2\x98\x85"; 6 const WHITE_STAR = "\xE2\x98\x86"; 7 8 private $value; 9 private $max = 100; 10 private $numGlyphs = 5; 11 private $fgGlyph; 12 private $bgGlyph; 13 14 public function getDefaultColor() { 15 return AphrontBarView::COLOR_AUTO_GOODNESS; 16 } 17 18 public function setValue($value) { 19 $this->value = $value; 20 return $this; 21 } 22 23 public function setMax($max) { 24 $this->max = $max; 25 return $this; 26 } 27 28 public function setNumGlyphs($nn) { 29 $this->numGlyphs = $nn; 30 return $this; 31 } 32 33 public function setGlyph(PhutilSafeHTML $fg_glyph) { 34 $this->fgGlyph = $fg_glyph; 35 return $this; 36 } 37 38 public function setBackgroundGlyph(PhutilSafeHTML $bg_glyph) { 39 $this->bgGlyph = $bg_glyph; 40 return $this; 41 } 42 43 protected function getRatio() { 44 return min($this->value, $this->max) / $this->max; 45 } 46 47 public function render() { 48 require_celerity_resource('aphront-bars'); 49 $ratio = $this->getRatio(); 50 $percentage = 100 * $ratio; 51 52 $is_star = false; 53 if ($this->fgGlyph) { 54 $fg_glyph = $this->fgGlyph; 55 if ($this->bgGlyph) { 56 $bg_glyph = $this->bgGlyph; 57 } else { 58 $bg_glyph = $fg_glyph; 59 } 60 } else { 61 $is_star = true; 62 $fg_glyph = self::BLACK_STAR; 63 $bg_glyph = self::WHITE_STAR; 64 } 65 66 $fg_glyphs = array_fill(0, $this->numGlyphs, $fg_glyph); 67 $bg_glyphs = array_fill(0, $this->numGlyphs, $bg_glyph); 68 69 $color = $this->getColor(); 70 71 return phutil_tag( 72 'div', 73 array( 74 'class' => "aphront-bar glyph color-{$color}", 75 ), 76 array( 77 phutil_tag( 78 'div', 79 array( 80 'class' => 'glyphs'.($is_star ? ' starstar' : ''), 81 ), 82 array( 83 phutil_tag( 84 'div', 85 array( 86 'class' => 'fg', 87 'style' => "width: {$percentage}%;", 88 ), 89 $fg_glyphs), 90 phutil_tag( 91 'div', 92 array(), 93 $bg_glyphs), 94 )), 95 phutil_tag( 96 'div', 97 array('class' => 'caption'), 98 $this->getCaption()), 99 )); 100 } 101 102 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |