[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/view/phui/ -> PHUIInfoPanelView.php (source)

   1  <?php
   2  
   3  final class PHUIInfoPanelView extends AphrontView {
   4  
   5    private $header;
   6    private $progress = null;
   7    private $columns = 3;
   8    private $infoblock = array();
   9  
  10    protected function canAppendChild() {
  11      return false;
  12    }
  13  
  14    public function setHeader(PHUIHeaderView $header) {
  15      $this->header = $header;
  16      return $this;
  17    }
  18  
  19    public function setProgress($progress) {
  20      $this->progress = $progress;
  21      return $this;
  22    }
  23  
  24    public function setColumns($columns) {
  25      $this->columns = $columns;
  26      return $this;
  27    }
  28  
  29    public function addInfoblock($num, $text) {
  30      $this->infoblock[] = array($num, $text);
  31      return $this;
  32    }
  33  
  34    public function render() {
  35      require_celerity_resource('phui-info-panel-css');
  36  
  37      $trs = array();
  38      $rows = ceil(count($this->infoblock) / $this->columns);
  39      for ($i = 0; $i < $rows; $i++) {
  40        $tds = array();
  41        $ii = 1;
  42        foreach ($this->infoblock as $key => $cell) {
  43          $tds[] = $this->renderCell($cell);
  44          unset($this->infoblock[$key]);
  45          $ii++;
  46          if ($ii > $this->columns) break;
  47        }
  48        $trs[] = phutil_tag(
  49          'tr',
  50          array(
  51            'class' => 'phui-info-panel-table-row',
  52          ),
  53          $tds);
  54      }
  55  
  56      $table = phutil_tag(
  57        'table',
  58        array(
  59          'class' => 'phui-info-panel-table',
  60        ),
  61        $trs);
  62  
  63      $table = id(new PHUIBoxView())
  64        ->addPadding(PHUI::PADDING_MEDIUM)
  65        ->appendChild($table);
  66  
  67      $progress = null;
  68      if ($this->progress) {
  69        $progress = phutil_tag(
  70          'div',
  71          array(
  72            'class' => 'phui-info-panel-progress',
  73            'style' => 'width: '.(int)$this->progress.'%;',
  74          ),
  75          null);
  76      }
  77  
  78      $box = id(new PHUIObjectBoxView())
  79        ->setHeader($this->header)
  80        ->appendChild($table)
  81        ->appendChild($progress);
  82  
  83      return phutil_tag(
  84        'div',
  85        array(
  86          'class' => 'phui-info-panel',
  87        ),
  88        $box);
  89    }
  90  
  91    private function renderCell($cell) {
  92      $number = phutil_tag(
  93        'div',
  94        array(
  95          'class' => 'phui-info-panel-number',
  96        ),
  97        $cell[0]);
  98  
  99      $text = phutil_tag(
 100        'div',
 101        array(
 102          'class' => 'phui-info-panel-text',
 103        ),
 104        $cell[1]);
 105  
 106      return phutil_tag(
 107        'td',
 108        array(
 109          'class' => 'phui-info-panel-table-cell',
 110          'align' => 'center',
 111          'width' => floor(100 / $this->columns).'%',
 112        ),
 113        array(
 114          $number,
 115          $text,
 116        ));
 117    }
 118  }


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