[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/fact/controller/ -> PhabricatorFactHomeController.php (source)

   1  <?php
   2  
   3  final class PhabricatorFactHomeController extends PhabricatorFactController {
   4  
   5    public function shouldAllowPublic() {
   6      return true;
   7    }
   8  
   9    public function processRequest() {
  10      $request = $this->getRequest();
  11      $user = $request->getUser();
  12  
  13      if ($request->isFormPost()) {
  14        $uri = new PhutilURI('/fact/chart/');
  15        $uri->setQueryParam('y1', $request->getStr('y1'));
  16        return id(new AphrontRedirectResponse())->setURI($uri);
  17      }
  18  
  19      $types = array(
  20        '+N:*',
  21        '+N:DREV',
  22        'updated',
  23      );
  24  
  25      $engines = PhabricatorFactEngine::loadAllEngines();
  26      $specs = PhabricatorFactSpec::newSpecsForFactTypes($engines, $types);
  27  
  28      $facts = id(new PhabricatorFactAggregate())->loadAllWhere(
  29        'factType IN (%Ls)',
  30        $types);
  31  
  32      $rows = array();
  33      foreach ($facts as $fact) {
  34        $spec = $specs[$fact->getFactType()];
  35  
  36        $name = $spec->getName();
  37        $value = $spec->formatValueForDisplay($user, $fact->getValueX());
  38  
  39        $rows[] = array($name, $value);
  40      }
  41  
  42      $table = new AphrontTableView($rows);
  43      $table->setHeaders(
  44        array(
  45          'Fact',
  46          'Value',
  47        ));
  48      $table->setColumnClasses(
  49        array(
  50          'wide',
  51          'n',
  52        ));
  53  
  54      $panel = new AphrontPanelView();
  55      $panel->setHeader('Facts!');
  56      $panel->appendChild($table);
  57  
  58      $chart_form = $this->buildChartForm();
  59  
  60      $crumbs = $this->buildApplicationCrumbs();
  61      $crumbs->addTextCrumb(pht('Home'));
  62  
  63      return $this->buildApplicationPage(
  64        array(
  65          $crumbs,
  66          $chart_form,
  67          $panel,
  68        ),
  69        array(
  70          'title' => 'Facts',
  71          'device' => false,
  72        ));
  73    }
  74  
  75    private function buildChartForm() {
  76      $request = $this->getRequest();
  77      $user = $request->getUser();
  78  
  79      $table = new PhabricatorFactRaw();
  80      $conn_r = $table->establishConnection('r');
  81      $table_name = $table->getTableName();
  82  
  83      $facts = queryfx_all(
  84        $conn_r,
  85        'SELECT DISTINCT factType from %T',
  86        $table_name);
  87  
  88      $specs = PhabricatorFactSpec::newSpecsForFactTypes(
  89        PhabricatorFactEngine::loadAllEngines(),
  90        ipull($facts, 'factType'));
  91  
  92      $options = array();
  93      foreach ($specs as $spec) {
  94        if ($spec->getUnit() == PhabricatorFactSpec::UNIT_COUNT) {
  95          $options[$spec->getType()] = $spec->getName();
  96        }
  97      }
  98  
  99      if (!$options) {
 100        return id(new AphrontErrorView())
 101          ->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
 102          ->setTitle(pht('No Chartable Facts'))
 103          ->appendChild(phutil_tag(
 104            'p',
 105            array(),
 106            pht('There are no facts that can be plotted yet.')));
 107      }
 108  
 109      $form = id(new AphrontFormView())
 110        ->setUser($user)
 111        ->appendChild(
 112          id(new AphrontFormSelectControl())
 113            ->setLabel('Y-Axis')
 114            ->setName('y1')
 115            ->setOptions($options))
 116        ->appendChild(
 117          id(new AphrontFormSubmitControl())
 118            ->setValue('Plot Chart'));
 119  
 120      $panel = new AphrontPanelView();
 121      $panel->appendChild($form);
 122      $panel->setWidth(AphrontPanelView::WIDTH_FORM);
 123      $panel->setHeader('Plot Chart');
 124  
 125      return $panel;
 126    }
 127  
 128  }


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