Something went wrong. Try again.
@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
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103<?php
final class AphrontGlyphBarView extends AphrontBarView {
const BLACK_STAR = "\xE2\x98\x85"; const WHITE_STAR = "\xE2\x98\x86";
private $value; private $max = 100; private $numGlyphs = 5; private $fgGlyph; private $bgGlyph;
protected function getDefaultColor() { return parent::COLOR_AUTO_GOODNESS; }
public function setValue($value) { $this->value = $value; return $this; }
public function setMax($max) { $this->max = $max; return $this; }
public function setNumGlyphs($nn) { $this->numGlyphs = $nn; return $this; }
public function setGlyph(PhutilSafeHTML $fg_glyph) { $this->fgGlyph = $fg_glyph; return $this; }
public function setBackgroundGlyph(PhutilSafeHTML $bg_glyph) { $this->bgGlyph = $bg_glyph; return $this; }
protected function getRatio() { return min($this->value, $this->max) / $this->max; }
public function render() { require_celerity_resource('aphront-bars'); $ratio = $this->getRatio(); $percentage = 100 * $ratio;
$is_star = false; if ($this->fgGlyph) { $fg_glyph = $this->fgGlyph; if ($this->bgGlyph) { $bg_glyph = $this->bgGlyph; } else { $bg_glyph = $fg_glyph; } } else { $is_star = true; $fg_glyph = self::BLACK_STAR; $bg_glyph = self::WHITE_STAR; }
$fg_glyphs = array_fill(0, $this->numGlyphs, $fg_glyph); $bg_glyphs = array_fill(0, $this->numGlyphs, $bg_glyph);
$color = $this->getColor();
return phutil_tag( 'div', array( 'class' => "aphront-bar glyph color-{$color}", ), array( phutil_tag( 'div', array( 'class' => 'glyphs'.($is_star ? ' starstar' : ''), ), array( phutil_tag( 'div', array( 'class' => 'fg', 'style' => "width: {$percentage}%;", ), $fg_glyphs), phutil_tag( 'div', array(), $bg_glyphs), )), phutil_tag( 'div', array('class' => 'caption'), $this->getCaption()), )); }
}