Path: blob/master/src/view/widget/bars/AphrontGlyphBarView.php
12256 views
<?php12final class AphrontGlyphBarView extends AphrontBarView {34const BLACK_STAR = "\xE2\x98\x85";5const WHITE_STAR = "\xE2\x98\x86";67private $value;8private $max = 100;9private $numGlyphs = 5;10private $fgGlyph;11private $bgGlyph;1213protected function getDefaultColor() {14return parent::COLOR_AUTO_GOODNESS;15}1617public function setValue($value) {18$this->value = $value;19return $this;20}2122public function setMax($max) {23$this->max = $max;24return $this;25}2627public function setNumGlyphs($nn) {28$this->numGlyphs = $nn;29return $this;30}3132public function setGlyph(PhutilSafeHTML $fg_glyph) {33$this->fgGlyph = $fg_glyph;34return $this;35}3637public function setBackgroundGlyph(PhutilSafeHTML $bg_glyph) {38$this->bgGlyph = $bg_glyph;39return $this;40}4142protected function getRatio() {43return min($this->value, $this->max) / $this->max;44}4546public function render() {47require_celerity_resource('aphront-bars');48$ratio = $this->getRatio();49$percentage = 100 * $ratio;5051$is_star = false;52if ($this->fgGlyph) {53$fg_glyph = $this->fgGlyph;54if ($this->bgGlyph) {55$bg_glyph = $this->bgGlyph;56} else {57$bg_glyph = $fg_glyph;58}59} else {60$is_star = true;61$fg_glyph = self::BLACK_STAR;62$bg_glyph = self::WHITE_STAR;63}6465$fg_glyphs = array_fill(0, $this->numGlyphs, $fg_glyph);66$bg_glyphs = array_fill(0, $this->numGlyphs, $bg_glyph);6768$color = $this->getColor();6970return phutil_tag(71'div',72array(73'class' => "aphront-bar glyph color-{$color}",74),75array(76phutil_tag(77'div',78array(79'class' => 'glyphs'.($is_star ? ' starstar' : ''),80),81array(82phutil_tag(83'div',84array(85'class' => 'fg',86'style' => "width: {$percentage}%;",87),88$fg_glyphs),89phutil_tag(90'div',91array(),92$bg_glyphs),93)),94phutil_tag(95'div',96array('class' => 'caption'),97$this->getCaption()),98));99}100101}102103104