[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/fund/controller/ -> FundInitiativeViewController.php (source)

   1  <?php
   2  
   3  final class FundInitiativeViewController
   4    extends FundController {
   5  
   6    private $id;
   7  
   8    public function shouldAllowPublic() {
   9      return true;
  10    }
  11  
  12    public function willProcessRequest(array $data) {
  13      $this->id = $data['id'];
  14    }
  15  
  16    public function processRequest() {
  17      $request = $this->getRequest();
  18      $viewer = $request->getUser();
  19  
  20      $initiative = id(new FundInitiativeQuery())
  21        ->setViewer($viewer)
  22        ->withIDs(array($this->id))
  23        ->executeOne();
  24      if (!$initiative) {
  25        return new Aphront404Response();
  26      }
  27  
  28      $crumbs = $this->buildApplicationCrumbs();
  29      $crumbs->addTextCrumb($initiative->getMonogram());
  30  
  31      $title = pht(
  32        '%s %s',
  33        $initiative->getMonogram(),
  34        $initiative->getName());
  35  
  36      if ($initiative->isClosed()) {
  37        $status_icon = 'fa-times';
  38        $status_color = 'bluegrey';
  39      } else {
  40        $status_icon = 'fa-check';
  41        $status_color = 'bluegrey';
  42      }
  43      $status_name = idx(
  44        FundInitiative::getStatusNameMap(),
  45        $initiative->getStatus());
  46  
  47      $header = id(new PHUIHeaderView())
  48        ->setObjectName($initiative->getMonogram())
  49        ->setHeader($initiative->getName())
  50        ->setUser($viewer)
  51        ->setPolicyObject($initiative)
  52        ->setStatus($status_icon, $status_color, $status_name);
  53  
  54      $properties = $this->buildPropertyListView($initiative);
  55      $actions = $this->buildActionListView($initiative);
  56      $properties->setActionList($actions);
  57      $crumbs->setActionList($actions);
  58  
  59      $box = id(new PHUIObjectBoxView())
  60        ->setHeader($header)
  61        ->appendChild($properties);
  62  
  63      $xactions = id(new FundInitiativeTransactionQuery())
  64        ->setViewer($viewer)
  65        ->withObjectPHIDs(array($initiative->getPHID()))
  66        ->execute();
  67  
  68      $timeline = id(new PhabricatorApplicationTransactionView())
  69        ->setUser($viewer)
  70        ->setObjectPHID($initiative->getPHID())
  71        ->setTransactions($xactions)
  72        ->setShouldTerminate(true);
  73  
  74      return $this->buildApplicationPage(
  75        array(
  76          $crumbs,
  77          $box,
  78          $timeline,
  79        ),
  80        array(
  81          'title' => $title,
  82          'pageObjects' => array($initiative->getPHID()),
  83        ));
  84    }
  85  
  86    private function buildPropertyListView(FundInitiative $initiative) {
  87      $viewer = $this->getRequest()->getUser();
  88  
  89      $view = id(new PHUIPropertyListView())
  90        ->setUser($viewer)
  91        ->setObject($initiative);
  92  
  93      $owner_phid = $initiative->getOwnerPHID();
  94      $merchant_phid = $initiative->getMerchantPHID();
  95      $this->loadHandles(
  96        array(
  97          $owner_phid,
  98          $merchant_phid,
  99        ));
 100  
 101      $view->addProperty(
 102        pht('Owner'),
 103        $this->getHandle($owner_phid)->renderLink());
 104  
 105      $view->addProperty(
 106        pht('Payable to Merchant'),
 107        $this->getHandle($merchant_phid)->renderLink());
 108  
 109      $view->addProperty(
 110        pht('Total Funding'),
 111        $initiative->getTotalAsCurrency()->formatForDisplay());
 112  
 113      $view->invokeWillRenderEvent();
 114  
 115      $description = $initiative->getDescription();
 116      if (strlen($description)) {
 117        $description = PhabricatorMarkupEngine::renderOneObject(
 118          id(new PhabricatorMarkupOneOff())->setContent($description),
 119          'default',
 120          $viewer);
 121  
 122        $view->addSectionHeader(pht('Description'));
 123        $view->addTextContent($description);
 124      }
 125  
 126      $risks = $initiative->getRisks();
 127      if (strlen($risks)) {
 128        $risks = PhabricatorMarkupEngine::renderOneObject(
 129          id(new PhabricatorMarkupOneOff())->setContent($risks),
 130          'default',
 131          $viewer);
 132  
 133        $view->addSectionHeader(pht('Risks/Challenges'));
 134        $view->addTextContent($risks);
 135      }
 136  
 137      return $view;
 138    }
 139  
 140    private function buildActionListView(FundInitiative $initiative) {
 141      $viewer = $this->getRequest()->getUser();
 142      $id = $initiative->getID();
 143  
 144      $can_edit = PhabricatorPolicyFilter::hasCapability(
 145        $viewer,
 146        $initiative,
 147        PhabricatorPolicyCapability::CAN_EDIT);
 148  
 149      $view = id(new PhabricatorActionListView())
 150        ->setUser($viewer)
 151        ->setObject($initiative);
 152  
 153      $view->addAction(
 154        id(new PhabricatorActionView())
 155          ->setName(pht('Edit Initiative'))
 156          ->setIcon('fa-pencil')
 157          ->setDisabled(!$can_edit)
 158          ->setWorkflow(!$can_edit)
 159          ->setHref($this->getApplicationURI("/edit/{$id}/")));
 160  
 161      if ($initiative->isClosed()) {
 162        $close_name = pht('Reopen Initiative');
 163        $close_icon = 'fa-check';
 164      } else {
 165        $close_name = pht('Close Initiative');
 166        $close_icon = 'fa-times';
 167      }
 168  
 169      $view->addAction(
 170        id(new PhabricatorActionView())
 171          ->setName($close_name)
 172          ->setIcon($close_icon)
 173          ->setDisabled(!$can_edit)
 174          ->setWorkflow(true)
 175          ->setHref($this->getApplicationURI("/close/{$id}/")));
 176  
 177      $view->addAction(
 178        id(new PhabricatorActionView())
 179          ->setName(pht('Back Initiative'))
 180          ->setIcon('fa-money')
 181          ->setDisabled($initiative->isClosed())
 182          ->setWorkflow(true)
 183          ->setHref($this->getApplicationURI("/back/{$id}/")));
 184  
 185      $view->addAction(
 186        id(new PhabricatorActionView())
 187          ->setName(pht('View Backers'))
 188          ->setIcon('fa-bank')
 189          ->setHref($this->getApplicationURI("/backers/{$id}/")));
 190  
 191      return $view;
 192    }
 193  
 194  }


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