[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/uiexample/examples/ -> PhabricatorAphrontBarExample.php (source)

   1  <?php
   2  
   3  final class PhabricatorAphrontBarExample extends PhabricatorUIExample {
   4  
   5    public function getName() {
   6      return 'Bars';
   7    }
   8  
   9    public function getDescription() {
  10      return 'Like fractions, but more horizontal.';
  11    }
  12  
  13    public function renderExample() {
  14      $out = '';
  15      $out .= $this->renderTestThings('AphrontProgressBarView', 13, 10);
  16      $out .= $this->renderTestThings('AphrontGlyphBarView', 13, 10);
  17      $out .= $this->renderWeirdOrderGlyphBars();
  18      $out .= $this->renderAsciiStarBar();
  19      return phutil_safe_html($out);
  20    }
  21  
  22    private function wrap($title, $thing) {
  23      return id(new AphrontPanelView())
  24        ->setHeader($title)
  25        ->appendChild($thing)
  26        ->render();
  27    }
  28  
  29    private function renderTestThings($class, $max, $incr) {
  30      $bars = array();
  31      for ($ii = 0; $ii <= $max; $ii++) {
  32        $bars[] = newv($class, array())
  33          ->setValue($ii * $incr)
  34          ->setMax($max * $incr)
  35          ->setCaption("{$ii} outta {$max} ain't bad!");
  36      }
  37      return $this->wrap(
  38        "Test {$class}",
  39        phutil_implode_html('', mpull($bars, 'render')));
  40    }
  41  
  42    private function renderWeirdOrderGlyphBars() {
  43      $views = array();
  44      $indices = array(1, 3, 7, 4, 2, 8, 9, 5, 10, 6);
  45      $max = count($indices);
  46      foreach ($indices as $index) {
  47        $views[] = id(new AphrontGlyphBarView())
  48          ->setValue($index)
  49          ->setMax($max)
  50          ->setNumGlyphs(5)
  51          ->setCaption("Lol score is {$index}/{$max}")
  52          ->setGlyph(hsprintf('%s', 'LOL!'))
  53          ->setBackgroundGlyph(hsprintf('%s', '____'))
  54          ->render();
  55        $views[] = hsprintf('<div style="clear:both;"></div>');
  56      }
  57  
  58      return $this->wrap(
  59        'Glyph bars in weird order',
  60        phutil_implode_html('', $views));
  61    }
  62  
  63    private function renderAsciiStarBar() {
  64      return $this->wrap(
  65        'Ascii star glyph bar',
  66        id(new AphrontGlyphBarView())
  67          ->setValue(50)
  68          ->setMax(100)
  69          ->setCaption('Glyphs!')
  70          ->setNumGlyphs(10)
  71          ->setGlyph(hsprintf('%s', '*'))
  72          ->render());
  73    }
  74  
  75  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1